k10temp: fix for erratum 688 returned

git-svn-id: svn://kolibrios.org@9152 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
turbocat 2021-08-24 19:57:13 +00:00
parent 389c2bc6c3
commit b5fd9c29dc
4 changed files with 66 additions and 5 deletions

View File

@ -14,7 +14,7 @@
#include <linux/spinlock.h>
#include <linux/pci_ids.h>
#include <asm/amd_nb.h>
#include <asm/msr.h>
#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. */

61
drivers/sensors/e_msr.c Normal file
View File

@ -0,0 +1,61 @@
#include <ddk.h>
#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);
}

View File

@ -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

View File

@ -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"}