1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-28 07:23:43 +02:00

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>
This commit is contained in:
Thomas Heijligen 2022-03-16 09:19:19 +01:00 committed by Nico Huber
parent 82604bd738
commit 4bd41e6bb5
4 changed files with 64 additions and 61 deletions

View File

@ -1310,10 +1310,10 @@ static int board_artecgroup_dbe6x(void)
unsigned long boot_loc; unsigned long boot_loc;
/* Geode only has a single core */ /* Geode only has a single core */
if (setup_cpu_msr(0)) if (msr_setup(0))
return -1; return -1;
msr = rdmsr(DBE6x_MSR_DIVIL_BALL_OPTS); msr = msr_read(DBE6x_MSR_DIVIL_BALL_OPTS);
if ((msr.lo & (DBE6x_BOOT_OP_LATCHED)) == if ((msr.lo & (DBE6x_BOOT_OP_LATCHED)) ==
(DBE6x_BOOT_LOC_FWHUB << DBE6x_BOOT_OP_LATCHED_SHIFT)) (DBE6x_BOOT_LOC_FWHUB << DBE6x_BOOT_OP_LATCHED_SHIFT))
@ -1325,9 +1325,9 @@ static int board_artecgroup_dbe6x(void)
msr.lo |= ((boot_loc << DBE6x_PRI_BOOT_LOC_SHIFT) | msr.lo |= ((boot_loc << DBE6x_PRI_BOOT_LOC_SHIFT) |
(boot_loc << DBE6x_SEC_BOOT_LOC_SHIFT)); (boot_loc << DBE6x_SEC_BOOT_LOC_SHIFT));
wrmsr(DBE6x_MSR_DIVIL_BALL_OPTS, msr); msr_write(DBE6x_MSR_DIVIL_BALL_OPTS, msr);
cleanup_cpu_msr(); msr_cleanup();
return 0; return 0;
} }

View File

@ -1264,21 +1264,21 @@ static int enable_flash_cs5536(struct pci_dev *dev, const char *name)
msr_t msr; msr_t msr;
/* Geode only has a single core */ /* Geode only has a single core */
if (setup_cpu_msr(0)) if (msr_setup(0))
return -1; return -1;
msr = rdmsr(MSR_RCONF_DEFAULT); msr = msr_read(MSR_RCONF_DEFAULT);
if ((msr.hi >> 24) != 0x22) { if ((msr.hi >> 24) != 0x22) {
msr.hi &= 0xfbffffff; msr.hi &= 0xfbffffff;
wrmsr(MSR_RCONF_DEFAULT, msr); msr_write(MSR_RCONF_DEFAULT, msr);
} }
msr = rdmsr(MSR_NORF_CTL); msr = msr_read(MSR_NORF_CTL);
/* Raise WE_CS3 bit. */ /* Raise WE_CS3 bit. */
msr.lo |= 0x08; msr.lo |= 0x08;
wrmsr(MSR_NORF_CTL, msr); msr_write(MSR_NORF_CTL, msr);
cleanup_cpu_msr(); msr_cleanup();
#undef MSR_RCONF_DEFAULT #undef MSR_RCONF_DEFAULT
#undef MSR_NORF_CTL #undef MSR_NORF_CTL

View File

@ -41,7 +41,7 @@
static int fd_msr = -1; static int fd_msr = -1;
msr_t rdmsr(int addr) msr_t msr_read(int addr)
{ {
uint32_t buf[2]; uint32_t buf[2];
msr_t msr = { 0xffffffff, 0xffffffff }; msr_t msr = { 0xffffffff, 0xffffffff };
@ -68,7 +68,7 @@ msr_t rdmsr(int addr)
return msr; return msr;
} }
int wrmsr(int addr, msr_t msr) int msr_write(int addr, msr_t msr)
{ {
uint32_t buf[2]; uint32_t buf[2];
buf[0] = msr.lo; buf[0] = msr.lo;
@ -93,7 +93,7 @@ int wrmsr(int addr, msr_t msr)
return 0; return 0;
} }
int setup_cpu_msr(int cpu) int msr_setup(int cpu)
{ {
char msrfilename[64] = { 0 }; char msrfilename[64] = { 0 };
snprintf(msrfilename, sizeof(msrfilename), "/dev/cpu/%d/msr", cpu); snprintf(msrfilename, sizeof(msrfilename), "/dev/cpu/%d/msr", cpu);
@ -114,7 +114,7 @@ int setup_cpu_msr(int cpu)
return 0; return 0;
} }
void cleanup_cpu_msr(void) void msr_cleanup(void)
{ {
if (fd_msr == -1) { if (fd_msr == -1) {
msg_pinfo("No MSR initialized.\n"); msg_pinfo("No MSR initialized.\n");
@ -127,14 +127,19 @@ void cleanup_cpu_msr(void)
fd_msr = -1; fd_msr = -1;
} }
#elif defined(__OpenBSD__) && defined (__i386__) /* This does only work for certain AMD Geode LX systems see amdmsr(4). */ #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 <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <machine/amdmsr.h> #include <machine/amdmsr.h>
static int fd_msr = -1; static int fd_msr = -1;
msr_t rdmsr(int addr) msr_t msr_read(int addr)
{ {
struct amdmsr_req args; struct amdmsr_req args;
@ -154,7 +159,7 @@ msr_t rdmsr(int addr)
return msr; return msr;
} }
int wrmsr(int addr, msr_t msr) int msr_write(int addr, msr_t msr)
{ {
struct amdmsr_req args; struct amdmsr_req args;
@ -170,7 +175,7 @@ int wrmsr(int addr, msr_t msr)
return 0; return 0;
} }
int setup_cpu_msr(int cpu) int msr_setup(int cpu)
{ {
char msrfilename[64] = { 0 }; char msrfilename[64] = { 0 };
snprintf(msrfilename, sizeof(msrfilename), "/dev/amdmsr"); snprintf(msrfilename, sizeof(msrfilename), "/dev/amdmsr");
@ -190,7 +195,7 @@ int setup_cpu_msr(int cpu)
return 0; return 0;
} }
void cleanup_cpu_msr(void) void msr_cleanup(void)
{ {
if (fd_msr == -1) { if (fd_msr == -1) {
msg_pinfo("No MSR initialized.\n"); msg_pinfo("No MSR initialized.\n");
@ -222,7 +227,7 @@ typedef struct {
static int fd_msr = -1; static int fd_msr = -1;
msr_t rdmsr(int addr) msr_t msr_read(int addr)
{ {
cpu_msr_args_t args; cpu_msr_args_t args;
@ -242,7 +247,7 @@ msr_t rdmsr(int addr)
return msr; return msr;
} }
int wrmsr(int addr, msr_t msr) int msr_write(int addr, msr_t msr)
{ {
cpu_msr_args_t args; cpu_msr_args_t args;
@ -258,7 +263,7 @@ int wrmsr(int addr, msr_t msr)
return 0; return 0;
} }
int setup_cpu_msr(int cpu) int msr_setup(int cpu)
{ {
char msrfilename[64] = { 0 }; char msrfilename[64] = { 0 };
snprintf(msrfilename, sizeof(msrfilename), "/dev/cpu%d", cpu); snprintf(msrfilename, sizeof(msrfilename), "/dev/cpu%d", cpu);
@ -279,7 +284,7 @@ int setup_cpu_msr(int cpu)
return 0; return 0;
} }
void cleanup_cpu_msr(void) void msr_cleanup(void)
{ {
if (fd_msr == -1) { if (fd_msr == -1) {
msg_pinfo("No MSR initialized.\n"); msg_pinfo("No MSR initialized.\n");
@ -293,19 +298,41 @@ void cleanup_cpu_msr(void)
} }
#elif defined(__MACH__) && defined(__APPLE__) #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 // Always succeed for now
return 0; return 0;
} }
void cleanup_cpu_msr(void) void msr_cleanup(void)
{ {
// Nothing, yet. // Nothing, yet.
} }
#elif defined(__LIBPAYLOAD__) #elif defined(__LIBPAYLOAD__)
msr_t libpayload_rdmsr(int addr) #include <arch/msr.h>
msr_t msr_read(int addr)
{ {
msr_t msr; msr_t msr;
unsigned long long val = _rdmsr(addr); unsigned long long val = _rdmsr(addr);
@ -314,41 +341,41 @@ msr_t libpayload_rdmsr(int addr)
return msr; 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)); _wrmsr(addr, msr.lo | ((unsigned long long)msr.hi << 32));
return 0; return 0;
} }
int setup_cpu_msr(int cpu) int msr_setup(int cpu)
{ {
return 0; return 0;
} }
void cleanup_cpu_msr(void) void msr_cleanup(void)
{ {
} }
#else #else
/* default MSR implementation */ /* default MSR implementation */
msr_t rdmsr(int addr) msr_t msr_read(int addr)
{ {
msr_t ret = { 0xffffffff, 0xffffffff }; msr_t ret = { 0xffffffff, 0xffffffff };
return ret; return ret;
} }
int wrmsr(int addr, msr_t msr) int msr_write(int addr, msr_t msr)
{ {
return -1; return -1;
} }
int setup_cpu_msr(int cpu) int msr_setup(int cpu)
{ {
msg_pinfo("No MSR support for your OS yet.\n"); msg_pinfo("No MSR support for your OS yet.\n");
return -1; return -1;
} }
void cleanup_cpu_msr(void) void msr_cleanup(void)
{ {
// Nothing, yet. // Nothing, yet.
} }

View File

@ -18,35 +18,11 @@
#include <stdint.h> #include <stdint.h>
#if !(defined(__MACH__) && defined(__APPLE__)) && !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) && !defined(__DragonFly__) && !defined(__LIBPAYLOAD__)
typedef struct { uint32_t hi, lo; } msr_t; typedef struct { uint32_t hi, lo; } msr_t;
msr_t rdmsr(int addr);
int wrmsr(int addr, msr_t msr);
#endif
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) msr_t msr_read(int addr);
/* FreeBSD already has conflicting definitions for wrmsr/rdmsr. */ int msr_write(int addr, msr_t msr);
#undef rdmsr int msr_setup(int cpu);
#undef wrmsr void msr_cleanup(void);
#define rdmsr freebsd_rdmsr
#define wrmsr freebsd_wrmsr
typedef struct { uint32_t hi, lo; } msr_t;
msr_t freebsd_rdmsr(int addr);
int freebsd_wrmsr(int addr, msr_t msr);
#endif
#if defined(__LIBPAYLOAD__)
#include <arch/io.h>
#include <arch/msr.h>
typedef struct { uint32_t hi, lo; } msr_t;
msr_t libpayload_rdmsr(int addr);
int libpayload_wrmsr(int addr, msr_t msr);
#undef rdmsr
#define rdmsr libpayload_rdmsr
#define wrmsr libpayload_wrmsr
#endif
int setup_cpu_msr(int cpu);
void cleanup_cpu_msr(void);
#endif /* __HWACCESS_X86_MSR_H__ */ #endif /* __HWACCESS_X86_MSR_H__ */