aboutsummaryrefslogtreecommitdiffstats
path: root/hwaccess_x86_msr.c
diff options
context:
space:
mode:
authorThomas Heijligen <thomas.heijligen@secunet.com>2022-03-16 09:19:19 +0100
committerNico Huber <nico.h@gmx.de>2022-04-13 11:25:35 +0000
commit4bd41e6bb5b96d7f71bebc03be93c7f7b433569e (patch)
tree1985d3d76aeb336bea700abb267d12910185686b /hwaccess_x86_msr.c
parent82604bd738ce34f37a1e0c679930ae27fa10ffc0 (diff)
downloadflashrom-4bd41e6bb5b96d7f71bebc03be93c7f7b433569e.tar.gz
flashrom-4bd41e6bb5b96d7f71bebc03be93c7f7b433569e.tar.bz2
flashrom-4bd41e6bb5b96d7f71bebc03be93c7f7b433569e.zip
hwaccess_x86_msr: rename msr function to msr_xxx
This eliminates the need to redefine the rdmsr and wrmsr symbols, resulting in more understandable code. The common prefix clarify the relation between the functions. Change-Id: Ie5ad54d198312578e0a1ee719eec67b37d2bf6a4 Signed-off-by: Thomas Heijligen <thomas.heijligen@secunet.com> Reviewed-on: https://review.coreboot.org/c/flashrom/+/62851 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Nico Huber <nico.h@gmx.de>
Diffstat (limited to 'hwaccess_x86_msr.c')
-rw-r--r--hwaccess_x86_msr.c73
1 files changed, 50 insertions, 23 deletions
diff --git a/hwaccess_x86_msr.c b/hwaccess_x86_msr.c
index 79cf2f82..1fbfa9e9 100644
--- a/hwaccess_x86_msr.c
+++ b/hwaccess_x86_msr.c
@@ -41,7 +41,7 @@
static int fd_msr = -1;
-msr_t rdmsr(int addr)
+msr_t msr_read(int addr)
{
uint32_t buf[2];
msr_t msr = { 0xffffffff, 0xffffffff };
@@ -68,7 +68,7 @@ msr_t rdmsr(int addr)
return msr;
}
-int wrmsr(int addr, msr_t msr)
+int msr_write(int addr, msr_t msr)
{
uint32_t buf[2];
buf[0] = msr.lo;
@@ -93,7 +93,7 @@ int wrmsr(int addr, msr_t msr)
return 0;
}
-int setup_cpu_msr(int cpu)
+int msr_setup(int cpu)
{
char msrfilename[64] = { 0 };
snprintf(msrfilename, sizeof(msrfilename), "/dev/cpu/%d/msr", cpu);
@@ -114,7 +114,7 @@ int setup_cpu_msr(int cpu)
return 0;
}
-void cleanup_cpu_msr(void)
+void msr_cleanup(void)
{
if (fd_msr == -1) {
msg_pinfo("No MSR initialized.\n");
@@ -127,14 +127,19 @@ void cleanup_cpu_msr(void)
fd_msr = -1;
}
#elif defined(__OpenBSD__) && defined (__i386__) /* This does only work for certain AMD Geode LX systems see amdmsr(4). */
+#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <unistd.h>
#include <sys/ioctl.h>
#include <machine/amdmsr.h>
static int fd_msr = -1;
-msr_t rdmsr(int addr)
+msr_t msr_read(int addr)
{
struct amdmsr_req args;
@@ -154,7 +159,7 @@ msr_t rdmsr(int addr)
return msr;
}
-int wrmsr(int addr, msr_t msr)
+int msr_write(int addr, msr_t msr)
{
struct amdmsr_req args;
@@ -170,7 +175,7 @@ int wrmsr(int addr, msr_t msr)
return 0;
}
-int setup_cpu_msr(int cpu)
+int msr_setup(int cpu)
{
char msrfilename[64] = { 0 };
snprintf(msrfilename, sizeof(msrfilename), "/dev/amdmsr");
@@ -190,7 +195,7 @@ int setup_cpu_msr(int cpu)
return 0;
}
-void cleanup_cpu_msr(void)
+void msr_cleanup(void)
{
if (fd_msr == -1) {
msg_pinfo("No MSR initialized.\n");
@@ -222,7 +227,7 @@ typedef struct {
static int fd_msr = -1;
-msr_t rdmsr(int addr)
+msr_t msr_read(int addr)
{
cpu_msr_args_t args;
@@ -242,7 +247,7 @@ msr_t rdmsr(int addr)
return msr;
}
-int wrmsr(int addr, msr_t msr)
+int msr_write(int addr, msr_t msr)
{
cpu_msr_args_t args;
@@ -258,7 +263,7 @@ int wrmsr(int addr, msr_t msr)
return 0;
}
-int setup_cpu_msr(int cpu)
+int msr_setup(int cpu)
{
char msrfilename[64] = { 0 };
snprintf(msrfilename, sizeof(msrfilename), "/dev/cpu%d", cpu);
@@ -279,7 +284,7 @@ int setup_cpu_msr(int cpu)
return 0;
}
-void cleanup_cpu_msr(void)
+void msr_cleanup(void)
{
if (fd_msr == -1) {
msg_pinfo("No MSR initialized.\n");
@@ -293,19 +298,41 @@ void cleanup_cpu_msr(void)
}
#elif defined(__MACH__) && defined(__APPLE__)
-/* rdmsr() and wrmsr() are provided by DirectHW which needs neither setup nor cleanup. */
-int setup_cpu_msr(int cpu)
+/*
+ * DirectHW has identical, but conflicting typedef for msr_t. We redefine msr_t
+ * to directhw_msr_t for DirectHW.
+ * rdmsr() and wrmsr() are provided by DirectHW and need neither setup nor cleanup.
+ */
+#define msr_t directhw_msr_t
+#include <DirectHW/DirectHW.h>
+#undef msr_t
+
+msr_t msr_read(int addr)
+{
+ directhw_msr_t msr;
+ msr = rdmsr(addr);
+ return (msr_t){msr.hi, msr.lo};
+}
+
+int msr_write(int addr, msr_t msr)
+{
+ return wrmsr(addr, (directhw_msr_t){msr.hi, msr.lo});
+}
+
+int msr_setup(int cpu)
{
// Always succeed for now
return 0;
}
-void cleanup_cpu_msr(void)
+void msr_cleanup(void)
{
// Nothing, yet.
}
#elif defined(__LIBPAYLOAD__)
-msr_t libpayload_rdmsr(int addr)
+#include <arch/msr.h>
+
+msr_t msr_read(int addr)
{
msr_t msr;
unsigned long long val = _rdmsr(addr);
@@ -314,41 +341,41 @@ msr_t libpayload_rdmsr(int addr)
return msr;
}
-int libpayload_wrmsr(int addr, msr_t msr)
+int msr_write(int addr, msr_t msr)
{
_wrmsr(addr, msr.lo | ((unsigned long long)msr.hi << 32));
return 0;
}
-int setup_cpu_msr(int cpu)
+int msr_setup(int cpu)
{
return 0;
}
-void cleanup_cpu_msr(void)
+void msr_cleanup(void)
{
}
#else
/* default MSR implementation */
-msr_t rdmsr(int addr)
+msr_t msr_read(int addr)
{
msr_t ret = { 0xffffffff, 0xffffffff };
return ret;
}
-int wrmsr(int addr, msr_t msr)
+int msr_write(int addr, msr_t msr)
{
return -1;
}
-int setup_cpu_msr(int cpu)
+int msr_setup(int cpu)
{
msg_pinfo("No MSR support for your OS yet.\n");
return -1;
}
-void cleanup_cpu_msr(void)
+void msr_cleanup(void)
{
// Nothing, yet.
}