Home | History | Annotate | Line # | Download | only in include
spr.h revision 1.51
      1  1.51  macallan /*	$NetBSD: spr.h,v 1.51 2018/03/22 15:18:05 macallan Exp $	*/
      2  1.48    simonb 
      3  1.48    simonb /*
      4  1.48    simonb  * Copyright (c) 2001, The NetBSD Foundation, Inc.
      5  1.48    simonb  * All rights reserved.
      6  1.48    simonb  *
      7  1.48    simonb  * Redistribution and use in source and binary forms, with or without
      8  1.48    simonb  * modification, are permitted provided that the following conditions
      9  1.48    simonb  * are met:
     10  1.48    simonb  * 1. Redistributions of source code must retain the above copyright
     11  1.48    simonb  *    notice, this list of conditions and the following disclaimer.
     12  1.48    simonb  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.48    simonb  *    notice, this list of conditions and the following disclaimer in the
     14  1.48    simonb  *    documentation and/or other materials provided with the distribution.
     15  1.48    simonb  *
     16  1.48    simonb  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  1.48    simonb  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  1.48    simonb  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  1.48    simonb  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  1.48    simonb  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21  1.48    simonb  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22  1.48    simonb  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23  1.48    simonb  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24  1.48    simonb  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25  1.48    simonb  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26  1.48    simonb  */
     27  1.21       chs 
     28   1.4      matt #ifndef _POWERPC_SPR_H_
     29   1.4      matt #define	_POWERPC_SPR_H_
     30   1.1    simonb 
     31  1.50       mrg #if !defined(_LOCORE) && defined(_KERNEL)
     32  1.46  macallan 
     33  1.49       mrg #include <powerpc/oea/cpufeat.h>
     34  1.49       mrg 
     35  1.49       mrg #if defined(PPC_OEA64_BRIDGE) || defined (_ARCH_PPC64)
     36  1.46  macallan static inline uint64_t
     37  1.49       mrg mfspr64(int reg)
     38  1.46  macallan {
     39  1.46  macallan 	uint64_t ret;
     40  1.51  macallan 	register_t hi, l;
     41  1.49       mrg 
     42  1.49       mrg 	__asm volatile( "mfspr %0,%2;"
     43  1.49       mrg 			"srdi %1,%0,32;"
     44  1.51  macallan 			 : "=r"(l), "=r"(hi) : "K"(reg));
     45  1.51  macallan 	ret = ((uint64_t)hi << 32) | l;
     46  1.46  macallan 	return ret;
     47  1.46  macallan }
     48  1.46  macallan 
     49  1.49       mrg /* This as an inline breaks as 'reg' ends up not being an immediate */
     50  1.49       mrg #define mtspr64(reg, v)						\
     51  1.49       mrg ( {								\
     52  1.51  macallan 	volatile register_t hi, l;				\
     53  1.49       mrg 								\
     54  1.49       mrg 	uint64_t val = v;					\
     55  1.51  macallan 	hi = (val >> 32);					\
     56  1.49       mrg 	l = val & 0xffffffff;					\
     57  1.49       mrg 	__asm volatile(	"sldi %2,%2,32;"			\
     58  1.49       mrg 			"or %2,%2,%1;"				\
     59  1.49       mrg 			"sync;"					\
     60  1.49       mrg 			"mtspr %0,%2;"				\
     61  1.49       mrg 			"mfspr %2,%0;"				\
     62  1.49       mrg 			"mfspr %2,%0;"				\
     63  1.49       mrg 			"mfspr %2,%0;"				\
     64  1.49       mrg 			"mfspr %2,%0;"				\
     65  1.49       mrg 			"mfspr %2,%0;"				\
     66  1.49       mrg 			"mfspr %2,%0;"				\
     67  1.51  macallan 			 : : "K"(reg), "r"(l), "r"(hi));		\
     68  1.46  macallan } )
     69  1.49       mrg #endif /* PPC_OEA64_BRIDGE || _ARCH_PPC64 */
     70  1.49       mrg 
     71  1.49       mrg static inline uint64_t
     72  1.49       mrg mfspr32(int reg)
     73  1.49       mrg {
     74  1.49       mrg 	register_t val;
     75  1.46  macallan 
     76  1.49       mrg 	__asm volatile("mfspr %0,%1" : "=r"(val) : "K"(reg));
     77  1.49       mrg 	return val;
     78  1.49       mrg }
     79  1.49       mrg 
     80  1.49       mrg static inline void
     81  1.49       mrg mtspr32(int reg, uint32_t val)
     82  1.49       mrg {
     83  1.49       mrg 
     84  1.49       mrg 	__asm volatile("mtspr %0,%1" : : "K"(reg), "r"(val));
     85  1.49       mrg }
     86  1.49       mrg 
     87  1.49       mrg #if (defined(PPC_OEA) + defined(PPC_OEA64) + defined(PPC_OEA64_BRIDGE)) > 1
     88  1.49       mrg static inline uint64_t
     89  1.49       mrg mfspr(int reg)
     90  1.49       mrg {
     91  1.50       mrg 	if ((oeacpufeat & (OEACPU_64_BRIDGE|OEACPU_64)) != 0)
     92  1.49       mrg 		return mfspr64(reg);
     93  1.49       mrg 	return mfspr32(reg);
     94  1.49       mrg }
     95  1.49       mrg 
     96  1.49       mrg /* This as an inline breaks as 'reg' ends up not being an immediate */
     97  1.49       mrg #define mtspr(reg, val)						\
     98  1.49       mrg ( {								\
     99  1.50       mrg 	if ((oeacpufeat & (OEACPU_64_BRIDGE|OEACPU_64)) != 0)	\
    100  1.49       mrg 		mtspr64(reg, (uint64_t)val);			\
    101  1.49       mrg 	else							\
    102  1.49       mrg 		mtspr32(reg, val);				\
    103  1.49       mrg } )
    104  1.49       mrg #else /* PPC_OEA + PPC_OEA64 + PPC_OEA64_BRIDGE != 1 */
    105  1.49       mrg 
    106  1.50       mrg #if defined(PPC_OEA64) || defined(PPC_OEA64_BRIDGE)
    107  1.50       mrg #define mfspr(r) mfspr64(r)
    108  1.50       mrg #define mtspr(r,v) mtspr64(r,v)
    109  1.50       mrg #else
    110  1.49       mrg #define mfspr(r) mfspr32(r)
    111  1.49       mrg #define mtspr(r,v) mtspr32(r,v)
    112  1.27      matt #endif
    113  1.49       mrg 
    114  1.49       mrg #endif /* PPC_OEA + PPC_OEA64 + PPC_OEA64_BRIDGE > 1 */
    115  1.49       mrg 
    116  1.50       mrg #endif /* !_LOCORE && _KERNEL */
    117   1.1    simonb 
    118   1.1    simonb /*
    119   1.1    simonb  * Special Purpose Register declarations.
    120   1.1    simonb  *
    121  1.45      matt  * The first column in the comments indicates which PowerPC architectures the
    122  1.45      matt  * SPR is valid on - E for BookE series, 4 for 4xx series,
    123  1.45      matt  * 6 for 6xx/7xx series and 8 for 8xx and 8xxx (but not 85xx) series.
    124   1.1    simonb  */
    125   1.1    simonb 
    126  1.45      matt #define	SPR_XER			0x001	/* E468 Fixed Point Exception Register */
    127  1.45      matt #define	SPR_LR			0x008	/* E468 Link Register */
    128  1.45      matt #define	SPR_CTR			0x009	/* E468 Count Register */
    129  1.45      matt #define	SPR_DEC			0x016	/* E468 DECrementer register */
    130  1.45      matt #define	SPR_SRR0		0x01a	/* E468 Save/Restore Register 0 */
    131  1.45      matt #define	SPR_SRR1		0x01b	/* E468 Save/Restore Register 1 */
    132  1.45      matt #define	SPR_SPRG0		0x110	/* E468 SPR General 0 */
    133  1.45      matt #define	SPR_SPRG1		0x111	/* E468 SPR General 1 */
    134  1.45      matt #define	SPR_SPRG2		0x112	/* E468 SPR General 2 */
    135  1.45      matt #define	SPR_SPRG3		0x113	/* E468 SPR General 3 */
    136  1.45      matt #define	SPR_SPRG4		0x114	/* E4.. SPR General 4 */
    137  1.45      matt #define	SPR_SPRG5		0x115	/* E4.. SPR General 5 */
    138  1.45      matt #define	SPR_SPRG6		0x116	/* E4.. SPR General 6 */
    139  1.45      matt #define	SPR_SPRG7		0x117	/* E4.. SPR General 7 */
    140  1.45      matt #define	SPR_TBL			0x11c	/* E468 Time Base Lower */
    141  1.45      matt #define	SPR_TBU			0x11d	/* E468 Time Base Upper */
    142  1.45      matt #define	SPR_PVR			0x11f	/* E468 Processor Version Register */
    143   1.1    simonb 
    144   1.1    simonb /* Time Base Register declarations */
    145  1.45      matt #define	TBR_TBL			0x10c	/* E468 Time Base Lower */
    146  1.45      matt #define	TBR_TBU			0x10d	/* E468 Time Base Upper */
    147  1.40   sanjayl 
    148   1.4      matt #endif /* !_POWERPC_SPR_H_ */
    149