diff --git a/drivers/sensors/amd_nb.c b/drivers/sensors/amd_nb.c index a45dda2e64..45fb591591 100644 --- a/drivers/sensors/amd_nb.c +++ b/drivers/sensors/amd_nb.c @@ -14,7 +14,7 @@ #include #include #include -#include + #define PCI_DEVICE_ID_AMD_17H_ROOT 0x1450 #define PCI_DEVICE_ID_AMD_17H_M10H_ROOT 0x15d0 @@ -535,8 +535,8 @@ EXPORT_SYMBOL_GPL(amd_flush_garts); static void __fix_erratum_688(void *info) { #define MSR_AMD64_IC_CFG 0xC0011021 -// msr_set_bit(MSR_AMD64_IC_CFG, 3); -// msr_set_bit(MSR_AMD64_IC_CFG, 14); + e_msr_set_bit(MSR_AMD64_IC_CFG, 3); + e_msr_set_bit(MSR_AMD64_IC_CFG, 14); } /* Apply erratum 688 fix so machines without a BIOS fix work. */ diff --git a/drivers/sensors/e_msr.c b/drivers/sensors/e_msr.c new file mode 100644 index 0000000000..6478b128d4 --- /dev/null +++ b/drivers/sensors/e_msr.c @@ -0,0 +1,61 @@ +#include + +#define U64_C(x) x ## ULL +#define BIT_64(n) (U64_C(1) << (n)) + +struct e_msr { + union { + struct { + u32 l; + u32 h; + }; + u64 q; + }; +}; + +static void _msr_read(u32 msr, struct e_msr *m) +{ + __asm__ __volatile__( + "rdmsr" + :"=a"(m->l), "=d"(m->h) + :"c"(msr) + :"memory" + ); +} + +static void _msr_write(u32 msr, struct e_msr *m) +{ + __asm__ __volatile__( + "wrmsr" + ::"a"(m->l), "d"(m->h), "c"(msr) + :"memory" + ); +} + +static int __flip_bit(u32 msr, u8 bit, bool set) +{ + struct e_msr m, m1; + if (bit > 63) + return EINVAL; + + _msr_read(msr, &m); + + m1 = m; + + if (set) + m1.q |= BIT_64(bit); + else + m1.q &= ~BIT_64(bit); + + if (m1.q == m.q) + return 0; + + _msr_write(msr, &m1); + return 1; +} + + +int e_msr_set_bit(u32 msr, u8 bit) +{ + return __flip_bit(msr, bit, true); +} \ No newline at end of file diff --git a/drivers/sensors/k10temp/Makefile b/drivers/sensors/k10temp/Makefile index 7a838a1bd7..5a1a248e3d 100644 --- a/drivers/sensors/k10temp/Makefile +++ b/drivers/sensors/k10temp/Makefile @@ -28,7 +28,7 @@ LDFLAGS = -nostdlib -shared -s --major-os-version 0 --minor-os-version 7 \ --major-subsystem-version 0 --minor-subsystem-version 5 --subsystem native \ --image-base 0 --file-alignment 512 --section-alignment 4096 -OBJS = k10temp.o ../pci.o ../amd_nb.o ../cpu_detect.o +OBJS = k10temp.o ../pci.o ../amd_nb.o ../cpu_detect.o ../e_msr.o all: $(OBJS) $(NAME).sys diff --git a/drivers/sensors/k10temp/Tupfile.lua b/drivers/sensors/k10temp/Tupfile.lua index 167c3f0ff3..3015328ec8 100644 --- a/drivers/sensors/k10temp/Tupfile.lua +++ b/drivers/sensors/k10temp/Tupfile.lua @@ -13,7 +13,7 @@ LDFLAGS = " -nostdlib -shared -s --major-os-version 0 --minor-os-version 7 --maj LIBS = " -lddk -lcore -lgcc " compile_gcc{ - "k10temp.c", "../pci.c", "../amd_nb.c", "../cpu_detect.c" + "k10temp.c", "../pci.c", "../amd_nb.c", "../cpu_detect.c", "../e_msr.c" } OBJS.extra_inputs = {"../../ddk/libcore.a", "../../ddk/libddk.a"}