~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/powerpc/include/asm/dcr-native.h

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0-or-later */
  2 /*
  3  * (c) Copyright 2006 Benjamin Herrenschmidt, IBM Corp.
  4  *                    <benh@kernel.crashing.org>
  5  */
  6 
  7 #ifndef _ASM_POWERPC_DCR_NATIVE_H
  8 #define _ASM_POWERPC_DCR_NATIVE_H
  9 #ifdef __KERNEL__
 10 #ifndef __ASSEMBLY__
 11 
 12 #include <linux/spinlock.h>
 13 #include <asm/cputable.h>
 14 #include <asm/cpu_has_feature.h>
 15 #include <linux/stringify.h>
 16 
 17 typedef struct {
 18         unsigned int base;
 19 } dcr_host_native_t;
 20 
 21 static inline bool dcr_map_ok_native(dcr_host_native_t host)
 22 {
 23         return true;
 24 }
 25 
 26 #define dcr_map_native(dev, dcr_n, dcr_c) \
 27         ((dcr_host_native_t){ .base = (dcr_n) })
 28 #define dcr_unmap_native(host, dcr_c)           do {} while (0)
 29 #define dcr_read_native(host, dcr_n)            mfdcr(dcr_n + host.base)
 30 #define dcr_write_native(host, dcr_n, value)    mtdcr(dcr_n + host.base, value)
 31 
 32 /* Table based DCR accessors */
 33 extern void __mtdcr(unsigned int reg, unsigned int val);
 34 extern unsigned int __mfdcr(unsigned int reg);
 35 
 36 /* mfdcrx/mtdcrx instruction based accessors. We hand code
 37  * the opcodes in order not to depend on newer binutils
 38  */
 39 static inline unsigned int mfdcrx(unsigned int reg)
 40 {
 41         unsigned int ret;
 42         asm volatile(".long 0x7c000206 | (%0 << 21) | (%1 << 16)"
 43                      : "=r" (ret) : "r" (reg));
 44         return ret;
 45 }
 46 
 47 static inline void mtdcrx(unsigned int reg, unsigned int val)
 48 {
 49         asm volatile(".long 0x7c000306 | (%0 << 21) | (%1 << 16)"
 50                      : : "r" (val), "r" (reg));
 51 }
 52 
 53 #define mfdcr(rn)                                               \
 54         ({unsigned int rval;                                    \
 55         if (__builtin_constant_p(rn) && rn < 1024)              \
 56                 asm volatile("mfdcr %0, %1" : "=r" (rval)       \
 57                               : "n" (rn));                      \
 58         else if (likely(cpu_has_feature(CPU_FTR_INDEXED_DCR)))  \
 59                 rval = mfdcrx(rn);                              \
 60         else                                                    \
 61                 rval = __mfdcr(rn);                             \
 62         rval;})
 63 
 64 #define mtdcr(rn, v)                                            \
 65 do {                                                            \
 66         if (__builtin_constant_p(rn) && rn < 1024)              \
 67                 asm volatile("mtdcr %0, %1"                     \
 68                               : : "n" (rn), "r" (v));           \
 69         else if (likely(cpu_has_feature(CPU_FTR_INDEXED_DCR)))  \
 70                 mtdcrx(rn, v);                                  \
 71         else                                                    \
 72                 __mtdcr(rn, v);                                 \
 73 } while (0)
 74 
 75 /* R/W of indirect DCRs make use of standard naming conventions for DCRs */
 76 extern spinlock_t dcr_ind_lock;
 77 
 78 static inline unsigned __mfdcri(int base_addr, int base_data, int reg)
 79 {
 80         unsigned long flags;
 81         unsigned int val;
 82 
 83         spin_lock_irqsave(&dcr_ind_lock, flags);
 84         if (cpu_has_feature(CPU_FTR_INDEXED_DCR)) {
 85                 mtdcrx(base_addr, reg);
 86                 val = mfdcrx(base_data);
 87         } else {
 88                 __mtdcr(base_addr, reg);
 89                 val = __mfdcr(base_data);
 90         }
 91         spin_unlock_irqrestore(&dcr_ind_lock, flags);
 92         return val;
 93 }
 94 
 95 static inline void __mtdcri(int base_addr, int base_data, int reg,
 96                             unsigned val)
 97 {
 98         unsigned long flags;
 99 
100         spin_lock_irqsave(&dcr_ind_lock, flags);
101         if (cpu_has_feature(CPU_FTR_INDEXED_DCR)) {
102                 mtdcrx(base_addr, reg);
103                 mtdcrx(base_data, val);
104         } else {
105                 __mtdcr(base_addr, reg);
106                 __mtdcr(base_data, val);
107         }
108         spin_unlock_irqrestore(&dcr_ind_lock, flags);
109 }
110 
111 static inline void __dcri_clrset(int base_addr, int base_data, int reg,
112                                  unsigned clr, unsigned set)
113 {
114         unsigned long flags;
115         unsigned int val;
116 
117         spin_lock_irqsave(&dcr_ind_lock, flags);
118         if (cpu_has_feature(CPU_FTR_INDEXED_DCR)) {
119                 mtdcrx(base_addr, reg);
120                 val = (mfdcrx(base_data) & ~clr) | set;
121                 mtdcrx(base_data, val);
122         } else {
123                 __mtdcr(base_addr, reg);
124                 val = (__mfdcr(base_data) & ~clr) | set;
125                 __mtdcr(base_data, val);
126         }
127         spin_unlock_irqrestore(&dcr_ind_lock, flags);
128 }
129 
130 #define mfdcri(base, reg)       __mfdcri(DCRN_ ## base ## _CONFIG_ADDR, \
131                                          DCRN_ ## base ## _CONFIG_DATA, \
132                                          reg)
133 
134 #define mtdcri(base, reg, data) __mtdcri(DCRN_ ## base ## _CONFIG_ADDR, \
135                                          DCRN_ ## base ## _CONFIG_DATA, \
136                                          reg, data)
137 
138 #define dcri_clrset(base, reg, clr, set)        __dcri_clrset(DCRN_ ## base ## _CONFIG_ADDR,    \
139                                                               DCRN_ ## base ## _CONFIG_DATA,    \
140                                                               reg, clr, set)
141 
142 #endif /* __ASSEMBLY__ */
143 #endif /* __KERNEL__ */
144 #endif /* _ASM_POWERPC_DCR_NATIVE_H */
145 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php