xref: /openbmc/linux/arch/x86/boot/msr.h (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
1*176db622SMichael Roth /* SPDX-License-Identifier: GPL-2.0-only */
2*176db622SMichael Roth /*
3*176db622SMichael Roth  * Helpers/definitions related to MSR access.
4*176db622SMichael Roth  */
5*176db622SMichael Roth 
6*176db622SMichael Roth #ifndef BOOT_MSR_H
7*176db622SMichael Roth #define BOOT_MSR_H
8*176db622SMichael Roth 
9*176db622SMichael Roth #include <asm/shared/msr.h>
10*176db622SMichael Roth 
11*176db622SMichael Roth /*
12*176db622SMichael Roth  * The kernel proper already defines rdmsr()/wrmsr(), but they are not for the
13*176db622SMichael Roth  * boot kernel since they rely on tracepoint/exception handling infrastructure
14*176db622SMichael Roth  * that's not available here.
15*176db622SMichael Roth  */
boot_rdmsr(unsigned int reg,struct msr * m)16*176db622SMichael Roth static inline void boot_rdmsr(unsigned int reg, struct msr *m)
17*176db622SMichael Roth {
18*176db622SMichael Roth 	asm volatile("rdmsr" : "=a" (m->l), "=d" (m->h) : "c" (reg));
19*176db622SMichael Roth }
20*176db622SMichael Roth 
boot_wrmsr(unsigned int reg,const struct msr * m)21*176db622SMichael Roth static inline void boot_wrmsr(unsigned int reg, const struct msr *m)
22*176db622SMichael Roth {
23*176db622SMichael Roth 	asm volatile("wrmsr" : : "c" (reg), "a"(m->l), "d" (m->h) : "memory");
24*176db622SMichael Roth }
25*176db622SMichael Roth 
26*176db622SMichael Roth #endif /* BOOT_MSR_H */
27