From b5fd9c29dc79bf5eb0e4db09ea98260f1e322733 Mon Sep 17 00:00:00 2001 From: turbocat Date: Tue, 24 Aug 2021 19:57:13 +0000 Subject: [PATCH] k10temp: fix for erratum 688 returned git-svn-id: svn://kolibrios.org@9152 a494cfbc-eb01-0410-851d-a64ba20cac60 --- drivers/sensors/amd_nb.c | 6 +-- drivers/sensors/e_msr.c | 61 +++++++++++++++++++++++++++++ drivers/sensors/k10temp/Makefile | 2 +- drivers/sensors/k10temp/Tupfile.lua | 2 +- 4 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 drivers/sensors/e_msr.c 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"}