Home | History | Annotate | Line # | Download | only in include
spr.h revision 1.56
      1  1.56       rin /*	$NetBSD: spr.h,v 1.56 2022/05/07 09:02:19 rin 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.53       rin #ifdef _KERNEL_OPT
     34  1.53       rin #include "opt_ppcarch.h"
     35  1.53       rin #endif
     36  1.53       rin 
     37  1.49       mrg #include <powerpc/oea/cpufeat.h>
     38  1.49       mrg 
     39  1.49       mrg #if defined(PPC_OEA64_BRIDGE) || defined (_ARCH_PPC64)
     40  1.52  christos static __inline uint64_t
     41  1.49       mrg mfspr64(int reg)
     42  1.46  macallan {
     43  1.46  macallan 	uint64_t ret;
     44  1.51  macallan 	register_t hi, l;
     45  1.49       mrg 
     46  1.49       mrg 	__asm volatile( "mfspr %0,%2;"
     47  1.49       mrg 			"srdi %1,%0,32;"
     48  1.51  macallan 			 : "=r"(l), "=r"(hi) : "K"(reg));
     49  1.51  macallan 	ret = ((uint64_t)hi << 32) | l;
     50  1.46  macallan 	return ret;
     51  1.46  macallan }
     52  1.46  macallan 
     53  1.49       mrg /* This as an inline breaks as 'reg' ends up not being an immediate */
     54  1.49       mrg #define mtspr64(reg, v)						\
     55  1.49       mrg ( {								\
     56  1.51  macallan 	volatile register_t hi, l;				\
     57  1.49       mrg 								\
     58  1.49       mrg 	uint64_t val = v;					\
     59  1.51  macallan 	hi = (val >> 32);					\
     60  1.49       mrg 	l = val & 0xffffffff;					\
     61  1.49       mrg 	__asm volatile(	"sldi %2,%2,32;"			\
     62  1.49       mrg 			"or %2,%2,%1;"				\
     63  1.49       mrg 			"sync;"					\
     64  1.49       mrg 			"mtspr %0,%2;"				\
     65  1.49       mrg 			"mfspr %2,%0;"				\
     66  1.49       mrg 			"mfspr %2,%0;"				\
     67  1.49       mrg 			"mfspr %2,%0;"				\
     68  1.49       mrg 			"mfspr %2,%0;"				\
     69  1.49       mrg 			"mfspr %2,%0;"				\
     70  1.49       mrg 			"mfspr %2,%0;"				\
     71  1.51  macallan 			 : : "K"(reg), "r"(l), "r"(hi));		\
     72  1.46  macallan } )
     73  1.49       mrg #endif /* PPC_OEA64_BRIDGE || _ARCH_PPC64 */
     74  1.49       mrg 
     75  1.54       ryo static __inline __always_inline uint64_t
     76  1.54       ryo mfspr32(const int reg)
     77  1.49       mrg {
     78  1.49       mrg 	register_t val;
     79  1.46  macallan 
     80  1.49       mrg 	__asm volatile("mfspr %0,%1" : "=r"(val) : "K"(reg));
     81  1.49       mrg 	return val;
     82  1.49       mrg }
     83  1.49       mrg 
     84  1.54       ryo static __inline __always_inline void
     85  1.54       ryo mtspr32(const int reg, uint32_t val)
     86  1.49       mrg {
     87  1.49       mrg 
     88  1.49       mrg 	__asm volatile("mtspr %0,%1" : : "K"(reg), "r"(val));
     89  1.49       mrg }
     90  1.49       mrg 
     91  1.49       mrg #if (defined(PPC_OEA) + defined(PPC_OEA64) + defined(PPC_OEA64_BRIDGE)) > 1
     92  1.52  christos static __inline uint64_t
     93  1.49       mrg mfspr(int reg)
     94  1.49       mrg {
     95  1.50       mrg 	if ((oeacpufeat & (OEACPU_64_BRIDGE|OEACPU_64)) != 0)
     96  1.49       mrg 		return mfspr64(reg);
     97  1.49       mrg 	return mfspr32(reg);
     98  1.49       mrg }
     99  1.49       mrg 
    100  1.49       mrg /* This as an inline breaks as 'reg' ends up not being an immediate */
    101  1.49       mrg #define mtspr(reg, val)						\
    102  1.49       mrg ( {								\
    103  1.50       mrg 	if ((oeacpufeat & (OEACPU_64_BRIDGE|OEACPU_64)) != 0)	\
    104  1.49       mrg 		mtspr64(reg, (uint64_t)val);			\
    105  1.49       mrg 	else							\
    106  1.49       mrg 		mtspr32(reg, val);				\
    107  1.49       mrg } )
    108  1.49       mrg #else /* PPC_OEA + PPC_OEA64 + PPC_OEA64_BRIDGE != 1 */
    109  1.49       mrg 
    110  1.50       mrg #if defined(PPC_OEA64) || defined(PPC_OEA64_BRIDGE)
    111  1.50       mrg #define mfspr(r) mfspr64(r)
    112  1.50       mrg #define mtspr(r,v) mtspr64(r,v)
    113  1.50       mrg #else
    114  1.49       mrg #define mfspr(r) mfspr32(r)
    115  1.49       mrg #define mtspr(r,v) mtspr32(r,v)
    116  1.27      matt #endif
    117  1.49       mrg 
    118  1.49       mrg #endif /* PPC_OEA + PPC_OEA64 + PPC_OEA64_BRIDGE > 1 */
    119  1.49       mrg 
    120  1.50       mrg #endif /* !_LOCORE && _KERNEL */
    121   1.1    simonb 
    122   1.1    simonb /*
    123   1.1    simonb  * Special Purpose Register declarations.
    124   1.1    simonb  *
    125  1.45      matt  * The first column in the comments indicates which PowerPC architectures the
    126  1.45      matt  * SPR is valid on - E for BookE series, 4 for 4xx series,
    127  1.45      matt  * 6 for 6xx/7xx series and 8 for 8xx and 8xxx (but not 85xx) series.
    128   1.1    simonb  */
    129   1.1    simonb 
    130  1.45      matt #define	SPR_XER			0x001	/* E468 Fixed Point Exception Register */
    131  1.45      matt #define	SPR_LR			0x008	/* E468 Link Register */
    132  1.45      matt #define	SPR_CTR			0x009	/* E468 Count Register */
    133  1.45      matt #define	SPR_DEC			0x016	/* E468 DECrementer register */
    134  1.45      matt #define	SPR_SRR0		0x01a	/* E468 Save/Restore Register 0 */
    135  1.45      matt #define	SPR_SRR1		0x01b	/* E468 Save/Restore Register 1 */
    136  1.45      matt #define	SPR_SPRG0		0x110	/* E468 SPR General 0 */
    137  1.45      matt #define	SPR_SPRG1		0x111	/* E468 SPR General 1 */
    138  1.45      matt #define	SPR_SPRG2		0x112	/* E468 SPR General 2 */
    139  1.45      matt #define	SPR_SPRG3		0x113	/* E468 SPR General 3 */
    140  1.45      matt #define	SPR_SPRG4		0x114	/* E4.. SPR General 4 */
    141  1.45      matt #define	SPR_SPRG5		0x115	/* E4.. SPR General 5 */
    142  1.45      matt #define	SPR_SPRG6		0x116	/* E4.. SPR General 6 */
    143  1.45      matt #define	SPR_SPRG7		0x117	/* E4.. SPR General 7 */
    144  1.45      matt #define	SPR_TBL			0x11c	/* E468 Time Base Lower */
    145  1.45      matt #define	SPR_TBU			0x11d	/* E468 Time Base Upper */
    146  1.45      matt #define	SPR_PVR			0x11f	/* E468 Processor Version Register */
    147   1.1    simonb 
    148   1.1    simonb /* Time Base Register declarations */
    149  1.45      matt #define	TBR_TBL			0x10c	/* E468 Time Base Lower */
    150  1.45      matt #define	TBR_TBU			0x10d	/* E468 Time Base Upper */
    151  1.40   sanjayl 
    152   1.4      matt #endif /* !_POWERPC_SPR_H_ */
    153