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

TOMOYO Linux Cross Reference
Linux/arch/x86/lib/msr.c

Version: ~ [ linux-6.6-rc1 ] ~ [ linux-6.5.2 ] ~ [ linux-6.4.15 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.52 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.131 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.194 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.256 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.294 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.325 ] ~ [ 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 #include <linux/export.h>
  2 #include <linux/percpu.h>
  3 #include <linux/preempt.h>
  4 #include <asm/msr.h>
  5 #define CREATE_TRACE_POINTS
  6 #include <asm/msr-trace.h>
  7 
  8 struct msr *msrs_alloc(void)
  9 {
 10         struct msr *msrs = NULL;
 11 
 12         msrs = alloc_percpu(struct msr);
 13         if (!msrs) {
 14                 pr_warn("%s: error allocating msrs\n", __func__);
 15                 return NULL;
 16         }
 17 
 18         return msrs;
 19 }
 20 EXPORT_SYMBOL(msrs_alloc);
 21 
 22 void msrs_free(struct msr *msrs)
 23 {
 24         free_percpu(msrs);
 25 }
 26 EXPORT_SYMBOL(msrs_free);
 27 
 28 /**
 29  * Read an MSR with error handling
 30  *
 31  * @msr: MSR to read
 32  * @m: value to read into
 33  *
 34  * It returns read data only on success, otherwise it doesn't change the output
 35  * argument @m.
 36  *
 37  */
 38 int msr_read(u32 msr, struct msr *m)
 39 {
 40         int err;
 41         u64 val;
 42 
 43         err = rdmsrl_safe(msr, &val);
 44         if (!err)
 45                 m->q = val;
 46 
 47         return err;
 48 }
 49 
 50 /**
 51  * Write an MSR with error handling
 52  *
 53  * @msr: MSR to write
 54  * @m: value to write
 55  */
 56 int msr_write(u32 msr, struct msr *m)
 57 {
 58         return wrmsrl_safe(msr, m->q);
 59 }
 60 
 61 static inline int __flip_bit(u32 msr, u8 bit, bool set)
 62 {
 63         struct msr m, m1;
 64         int err = -EINVAL;
 65 
 66         if (bit > 63)
 67                 return err;
 68 
 69         err = msr_read(msr, &m);
 70         if (err)
 71                 return err;
 72 
 73         m1 = m;
 74         if (set)
 75                 m1.q |=  BIT_64(bit);
 76         else
 77                 m1.q &= ~BIT_64(bit);
 78 
 79         if (m1.q == m.q)
 80                 return 0;
 81 
 82         err = msr_write(msr, &m1);
 83         if (err)
 84                 return err;
 85 
 86         return 1;
 87 }
 88 
 89 /**
 90  * Set @bit in a MSR @msr.
 91  *
 92  * Retval:
 93  * < 0: An error was encountered.
 94  * = 0: Bit was already set.
 95  * > 0: Hardware accepted the MSR write.
 96  */
 97 int msr_set_bit(u32 msr, u8 bit)
 98 {
 99         return __flip_bit(msr, bit, true);
100 }
101 
102 /**
103  * Clear @bit in a MSR @msr.
104  *
105  * Retval:
106  * < 0: An error was encountered.
107  * = 0: Bit was already cleared.
108  * > 0: Hardware accepted the MSR write.
109  */
110 int msr_clear_bit(u32 msr, u8 bit)
111 {
112         return __flip_bit(msr, bit, false);
113 }
114 
115 #ifdef CONFIG_TRACEPOINTS
116 void do_trace_write_msr(unsigned msr, u64 val, int failed)
117 {
118         trace_write_msr(msr, val, failed);
119 }
120 EXPORT_SYMBOL(do_trace_write_msr);
121 EXPORT_TRACEPOINT_SYMBOL(write_msr);
122 
123 void do_trace_read_msr(unsigned msr, u64 val, int failed)
124 {
125         trace_read_msr(msr, val, failed);
126 }
127 EXPORT_SYMBOL(do_trace_read_msr);
128 EXPORT_TRACEPOINT_SYMBOL(read_msr);
129 
130 void do_trace_rdpmc(unsigned counter, u64 val, int failed)
131 {
132         trace_rdpmc(counter, val, failed);
133 }
134 EXPORT_SYMBOL(do_trace_rdpmc);
135 EXPORT_TRACEPOINT_SYMBOL(rdpmc);
136 
137 #endif
138 

~ [ 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.

osdn.jp