This needs /dev/cpu0 from ports/sysutils
It's untested and probably won't even compile..
Stefan
On 12.08.2009 20:44, Stefan Reinauer wrote:
This needs /dev/cpu0 from ports/sysutils
It's untested and probably won't even compile..
Here's an updated version which could even compile. It does compile on Linux. Stefan, since the original patch is from you, you may want to add your Signoff here as well.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Index: flashrom-rdmsr_freebsd/flash.h =================================================================== --- flashrom-rdmsr_freebsd/flash.h (Revision 683) +++ flashrom-rdmsr_freebsd/flash.h (Arbeitskopie) @@ -311,8 +311,11 @@ void cleanup_cpu_msr(void); #ifndef __DARWIN__ typedef struct { uint32_t hi, lo; } msr_t; -msr_t rdmsr(int addr); -int wrmsr(int addr, msr_t msr); +msr_t RDMSR(int addr); +int WRMSR(int addr, msr_t msr); +#else +#define RDMSR rdmsr +#define WRMSR wrmsr #endif
/* internal.c */ Index: flashrom-rdmsr_freebsd/physmap.c =================================================================== --- flashrom-rdmsr_freebsd/physmap.c (Revision 683) +++ flashrom-rdmsr_freebsd/physmap.c (Arbeitskopie) @@ -131,7 +131,7 @@
static int fd_msr = -1;
-msr_t rdmsr(int addr) +msr_t RDMSR(int addr) { uint8_t buf[8]; msr_t msr = { 0xffffffff, 0xffffffff }; @@ -159,7 +159,7 @@ return msr; }
-int wrmsr(int addr, msr_t msr) +int WRMSR(int addr, msr_t msr) { if (lseek(fd_msr, (off_t) addr, SEEK_SET) == -1) { perror("Could not lseek() to MSR"); @@ -215,6 +215,90 @@ fd_msr = -1; } #else +#if defined(__FreeBSD__) || defined(__DragonFly__) + +typedef struct { + int msr; + uint64_t data; +} cpu_msr_args_t; +#define CPU_RDMSR _IOWR('c', 1, cpu_msr_args_t) +#define CPU_WRMSR _IOWR('c', 2, cpu_msr_args_t) + +static int fd_msr = -1; + +msr_t RDMSR(int addr) +{ + cpu_msr_args_t args; + + msr_t msr = { 0xffffffff, 0xffffffff }; + + args.msr = addr; + + if (ioctl(fd_msr, CPU_RDMSR, &args) < 0) { + perror("CPU_RDMSR"); + close(fd_msr); + exit(1); + } + + msr.lo = data & 0xffffffff; + msr.hi = data >> 32; + + return msr; +} + +int WRMSR(int addr, msr_t msr) +{ + cpu_msr_args_t args; + + args.msr = addr; + args.data = (((uint64_t)msr.hi) << 32) | msr.lo; + + if (ioctl(fd_msr, CPU_WRMSR, &args) < 0) { + perror("CPU_WRMSR"); + close(fd_msr); + exit(1); + } + + return 0; +} + +int setup_cpu_msr(int cpu) +{ + char msrfilename[64]; + memset(msrfilename, 0, 64); + sprintf(msrfilename, "/dev/cpu%d", cpu); + + if (fd_msr != -1) { + printf("MSR was already initialized\n"); + return -1; + } + + fd_msr = open(msrfilename, O_RDWR); + + if (fd_msr < 0) { + perror("Error while opening /dev/cpu0"); + printf("Did you install ports/sysutils/devcpu?\n"); + return -1; + } + + return 0; +} + +void cleanup_cpu_msr(void) +{ + if (fd_msr == -1) { + printf("No MSR initialized.\n"); + return; + } + + close(fd_msr); + + /* Clear MSR file descriptor */ + fd_msr = -1; +} + +#else + #ifdef __DARWIN__ int setup_cpu_msr(int cpu) { @@ -227,14 +311,14 @@ // Nothing, yet. } #else -msr_t rdmsr(int addr) +msr_t RDMSR(int addr) { msr_t ret = { 0xffffffff, 0xffffffff };
return ret; }
-int wrmsr(int addr, msr_t msr) +int WRMSR(int addr, msr_t msr) { return -1; } @@ -251,4 +335,5 @@ } #endif #endif +#endif
Index: flashrom-rdmsr_freebsd/chipset_enable.c =================================================================== --- flashrom-rdmsr_freebsd/chipset_enable.c (Revision 683) +++ flashrom-rdmsr_freebsd/chipset_enable.c (Arbeitskopie) @@ -544,16 +544,16 @@ if (setup_cpu_msr(0)) return -1;
- msr = rdmsr(MSR_RCONF_DEFAULT); + msr = RDMSR(MSR_RCONF_DEFAULT); if ((msr.hi >> 24) != 0x22) { msr.hi &= 0xfbffffff; - wrmsr(MSR_RCONF_DEFAULT, msr); + WRMSR(MSR_RCONF_DEFAULT, msr); }
- msr = rdmsr(MSR_NORF_CTL); + msr = RDMSR(MSR_NORF_CTL); /* Raise WE_CS3 bit. */ msr.lo |= 0x08; - wrmsr(MSR_NORF_CTL, msr); + WRMSR(MSR_NORF_CTL, msr);
cleanup_cpu_msr();
Index: flashrom-rdmsr_freebsd/board_enable.c =================================================================== --- flashrom-rdmsr_freebsd/board_enable.c (Revision 683) +++ flashrom-rdmsr_freebsd/board_enable.c (Arbeitskopie) @@ -502,7 +502,7 @@ if (setup_cpu_msr(0)) return -1;
- msr = rdmsr(DBE6x_MSR_DIVIL_BALL_OPTS); + msr = RDMSR(DBE6x_MSR_DIVIL_BALL_OPTS);
if ((msr.lo & (DBE6x_BOOT_OP_LATCHED)) == (DBE6x_BOOT_LOC_FWHUB << DBE6x_BOOT_OP_LATCHED_SHIFT)) @@ -514,7 +514,7 @@ msr.lo |= ((boot_loc << DBE6x_PRI_BOOT_LOC_SHIFT) | (boot_loc << DBE6x_SEC_BOOT_LOC_SHIFT));
- wrmsr(DBE6x_MSR_DIVIL_BALL_OPTS, msr); + WRMSR(DBE6x_MSR_DIVIL_BALL_OPTS, msr);
cleanup_cpu_msr();
On 13.08.2009 00:19, Carl-Daniel Hailfinger wrote:
On 12.08.2009 20:44, Stefan Reinauer wrote:
This needs /dev/cpu0 from ports/sysutils
It's untested and probably won't even compile..
Here's an updated version which could even compile. It does compile on Linux. Stefan, since the original patch is from you, you may want to add your Signoff here as well.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Next try.
Index: flashrom-rdmsr_freebsd/flash.h =================================================================== --- flashrom-rdmsr_freebsd/flash.h (Revision 683) +++ flashrom-rdmsr_freebsd/flash.h (Arbeitskopie) @@ -311,8 +311,11 @@ void cleanup_cpu_msr(void); #ifndef __DARWIN__ typedef struct { uint32_t hi, lo; } msr_t; -msr_t rdmsr(int addr); -int wrmsr(int addr, msr_t msr); +msr_t RDMSR(int addr); +int WRMSR(int addr, msr_t msr); +#else +#define RDMSR rdmsr +#define WRMSR wrmsr #endif
/* internal.c */ Index: flashrom-rdmsr_freebsd/physmap.c =================================================================== --- flashrom-rdmsr_freebsd/physmap.c (Revision 683) +++ flashrom-rdmsr_freebsd/physmap.c (Arbeitskopie) @@ -131,7 +131,7 @@
static int fd_msr = -1;
-msr_t rdmsr(int addr) +msr_t RDMSR(int addr) { uint8_t buf[8]; msr_t msr = { 0xffffffff, 0xffffffff }; @@ -159,7 +159,7 @@ return msr; }
-int wrmsr(int addr, msr_t msr) +int WRMSR(int addr, msr_t msr) { if (lseek(fd_msr, (off_t) addr, SEEK_SET) == -1) { perror("Could not lseek() to MSR"); @@ -215,6 +215,91 @@ fd_msr = -1; } #else +#if defined(__FreeBSD__) || defined(__DragonFly__) +#include <sys/ioctl.h> + +typedef struct { + int msr; + uint64_t data; +} cpu_msr_args_t; +#define CPU_RDMSR _IOWR('c', 1, cpu_msr_args_t) +#define CPU_WRMSR _IOWR('c', 2, cpu_msr_args_t) + +static int fd_msr = -1; + +msr_t RDMSR(int addr) +{ + cpu_msr_args_t args; + + msr_t msr = { 0xffffffff, 0xffffffff }; + + args.msr = addr; + + if (ioctl(fd_msr, CPU_RDMSR, &args) < 0) { + perror("CPU_RDMSR"); + close(fd_msr); + exit(1); + } + + msr.lo = data & 0xffffffff; + msr.hi = data >> 32; + + return msr; +} + +int WRMSR(int addr, msr_t msr) +{ + cpu_msr_args_t args; + + args.msr = addr; + args.data = (((uint64_t)msr.hi) << 32) | msr.lo; + + if (ioctl(fd_msr, CPU_WRMSR, &args) < 0) { + perror("CPU_WRMSR"); + close(fd_msr); + exit(1); + } + + return 0; +} + +int setup_cpu_msr(int cpu) +{ + char msrfilename[64]; + memset(msrfilename, 0, 64); + sprintf(msrfilename, "/dev/cpu%d", cpu); + + if (fd_msr != -1) { + printf("MSR was already initialized\n"); + return -1; + } + + fd_msr = open(msrfilename, O_RDWR); + + if (fd_msr < 0) { + perror("Error while opening /dev/cpu0"); + printf("Did you install ports/sysutils/devcpu?\n"); + return -1; + } + + return 0; +} + +void cleanup_cpu_msr(void) +{ + if (fd_msr == -1) { + printf("No MSR initialized.\n"); + return; + } + + close(fd_msr); + + /* Clear MSR file descriptor */ + fd_msr = -1; +} + +#else + #ifdef __DARWIN__ int setup_cpu_msr(int cpu) { @@ -227,14 +312,14 @@ // Nothing, yet. } #else -msr_t rdmsr(int addr) +msr_t RDMSR(int addr) { msr_t ret = { 0xffffffff, 0xffffffff };
return ret; }
-int wrmsr(int addr, msr_t msr) +int WRMSR(int addr, msr_t msr) { return -1; } @@ -251,4 +336,5 @@ } #endif #endif +#endif
Index: flashrom-rdmsr_freebsd/chipset_enable.c =================================================================== --- flashrom-rdmsr_freebsd/chipset_enable.c (Revision 683) +++ flashrom-rdmsr_freebsd/chipset_enable.c (Arbeitskopie) @@ -544,16 +544,16 @@ if (setup_cpu_msr(0)) return -1;
- msr = rdmsr(MSR_RCONF_DEFAULT); + msr = RDMSR(MSR_RCONF_DEFAULT); if ((msr.hi >> 24) != 0x22) { msr.hi &= 0xfbffffff; - wrmsr(MSR_RCONF_DEFAULT, msr); + WRMSR(MSR_RCONF_DEFAULT, msr); }
- msr = rdmsr(MSR_NORF_CTL); + msr = RDMSR(MSR_NORF_CTL); /* Raise WE_CS3 bit. */ msr.lo |= 0x08; - wrmsr(MSR_NORF_CTL, msr); + WRMSR(MSR_NORF_CTL, msr);
cleanup_cpu_msr();
Index: flashrom-rdmsr_freebsd/board_enable.c =================================================================== --- flashrom-rdmsr_freebsd/board_enable.c (Revision 683) +++ flashrom-rdmsr_freebsd/board_enable.c (Arbeitskopie) @@ -502,7 +502,7 @@ if (setup_cpu_msr(0)) return -1;
- msr = rdmsr(DBE6x_MSR_DIVIL_BALL_OPTS); + msr = RDMSR(DBE6x_MSR_DIVIL_BALL_OPTS);
if ((msr.lo & (DBE6x_BOOT_OP_LATCHED)) == (DBE6x_BOOT_LOC_FWHUB << DBE6x_BOOT_OP_LATCHED_SHIFT)) @@ -514,7 +514,7 @@ msr.lo |= ((boot_loc << DBE6x_PRI_BOOT_LOC_SHIFT) | (boot_loc << DBE6x_SEC_BOOT_LOC_SHIFT));
- wrmsr(DBE6x_MSR_DIVIL_BALL_OPTS, msr); + WRMSR(DBE6x_MSR_DIVIL_BALL_OPTS, msr);
cleanup_cpu_msr();
On 13.08.2009 00:43, Carl-Daniel Hailfinger wrote:
On 13.08.2009 00:19, Carl-Daniel Hailfinger wrote:
On 12.08.2009 20:44, Stefan Reinauer wrote:
This needs /dev/cpu0 from ports/sysutils
Stefan, since the original patch is from you, you may want to add your Signoff here as well.
Compiles on FreeBSD and Linux and is the least invasive solution I could come up with.
This is 0.9.1 material.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Index: flashrom-rdmsr_freebsd/flash.h =================================================================== --- flashrom-rdmsr_freebsd/flash.h (Revision 685) +++ flashrom-rdmsr_freebsd/flash.h (Arbeitskopie) @@ -309,11 +309,21 @@ void physunmap(void *virt_addr, size_t len); int setup_cpu_msr(int cpu); void cleanup_cpu_msr(void); -#ifndef __DARWIN__ +#if !defined(__DARWIN__) && !defined(__FreeBSD__) && !defined(__DragonFly__) 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(__DragonFly__) +/* FreeBSD already has conflicting definitions for wrmsr/rdmsr. */ +#undef rdmsr +#undef wrmsr +#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
/* internal.c */ struct pci_dev *pci_dev_find_filter(struct pci_filter filter); Index: flashrom-rdmsr_freebsd/physmap.c =================================================================== --- flashrom-rdmsr_freebsd/physmap.c (Revision 685) +++ flashrom-rdmsr_freebsd/physmap.c (Arbeitskopie) @@ -215,6 +215,91 @@ fd_msr = -1; } #else +#if defined(__FreeBSD__) || defined(__DragonFly__) +#include <sys/ioctl.h> + +typedef struct { + int msr; + uint64_t data; +} cpu_msr_args_t; +#define CPU_RDMSR _IOWR('c', 1, cpu_msr_args_t) +#define CPU_WRMSR _IOWR('c', 2, cpu_msr_args_t) + +static int fd_msr = -1; + +msr_t rdmsr(int addr) +{ + cpu_msr_args_t args; + + msr_t msr = { 0xffffffff, 0xffffffff }; + + args.msr = addr; + + if (ioctl(fd_msr, CPU_RDMSR, &args) < 0) { + perror("CPU_RDMSR"); + close(fd_msr); + exit(1); + } + + msr.lo = args.data & 0xffffffff; + msr.hi = args.data >> 32; + + return msr; +} + +int wrmsr(int addr, msr_t msr) +{ + cpu_msr_args_t args; + + args.msr = addr; + args.data = (((uint64_t)msr.hi) << 32) | msr.lo; + + if (ioctl(fd_msr, CPU_WRMSR, &args) < 0) { + perror("CPU_WRMSR"); + close(fd_msr); + exit(1); + } + + return 0; +} + +int setup_cpu_msr(int cpu) +{ + char msrfilename[64]; + memset(msrfilename, 0, 64); + sprintf(msrfilename, "/dev/cpu%d", cpu); + + if (fd_msr != -1) { + printf("MSR was already initialized\n"); + return -1; + } + + fd_msr = open(msrfilename, O_RDWR); + + if (fd_msr < 0) { + perror("Error while opening /dev/cpu0"); + printf("Did you install ports/sysutils/devcpu?\n"); + return -1; + } + + return 0; +} + +void cleanup_cpu_msr(void) +{ + if (fd_msr == -1) { + printf("No MSR initialized.\n"); + return; + } + + close(fd_msr); + + /* Clear MSR file descriptor */ + fd_msr = -1; +} + +#else + #ifdef __DARWIN__ int setup_cpu_msr(int cpu) { @@ -251,4 +336,5 @@ } #endif #endif +#endif
acked-by: idlogin putlinuxonit@gmail.com
2009/8/17 Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
On 13.08.2009 00:43, Carl-Daniel Hailfinger wrote:
On 13.08.2009 00:19, Carl-Daniel Hailfinger wrote:
On 12.08.2009 20:44, Stefan Reinauer wrote:
This needs /dev/cpu0 from ports/sysutils
Stefan, since the original patch is from you, you may want to add your Signoff here as well.
Compiles on FreeBSD and Linux and is the least invasive solution I could come up with.
This is 0.9.1 material.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Index: flashrom-rdmsr_freebsd/flash.h
--- flashrom-rdmsr_freebsd/flash.h (Revision 685) +++ flashrom-rdmsr_freebsd/flash.h (Arbeitskopie) @@ -309,11 +309,21 @@ void physunmap(void *virt_addr, size_t len); int setup_cpu_msr(int cpu); void cleanup_cpu_msr(void); -#ifndef __DARWIN__ +#if !defined(__DARWIN__) && !defined(__FreeBSD__) && !defined(__DragonFly__) 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(__DragonFly__) +/* FreeBSD already has conflicting definitions for wrmsr/rdmsr. */ +#undef rdmsr +#undef wrmsr +#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
/* internal.c */ struct pci_dev *pci_dev_find_filter(struct pci_filter filter); Index: flashrom-rdmsr_freebsd/physmap.c =================================================================== --- flashrom-rdmsr_freebsd/physmap.c (Revision 685) +++ flashrom-rdmsr_freebsd/physmap.c (Arbeitskopie) @@ -215,6 +215,91 @@ fd_msr = -1; } #else +#if defined(__FreeBSD__) || defined(__DragonFly__) +#include <sys/ioctl.h>
+typedef struct {
int msr;
uint64_t data;
+} cpu_msr_args_t; +#define CPU_RDMSR _IOWR('c', 1, cpu_msr_args_t) +#define CPU_WRMSR _IOWR('c', 2, cpu_msr_args_t)
+static int fd_msr = -1;
+msr_t rdmsr(int addr) +{
cpu_msr_args_t args;
msr_t msr = { 0xffffffff, 0xffffffff };
args.msr = addr;
if (ioctl(fd_msr, CPU_RDMSR, &args) < 0) {
perror("CPU_RDMSR");
close(fd_msr);
exit(1);
}
msr.lo = args.data & 0xffffffff;
msr.hi = args.data >> 32;
return msr;
+}
+int wrmsr(int addr, msr_t msr) +{
cpu_msr_args_t args;
args.msr = addr;
args.data = (((uint64_t)msr.hi) << 32) | msr.lo;
if (ioctl(fd_msr, CPU_WRMSR, &args) < 0) {
perror("CPU_WRMSR");
close(fd_msr);
exit(1);
}
return 0;
+}
+int setup_cpu_msr(int cpu) +{
char msrfilename[64];
memset(msrfilename, 0, 64);
sprintf(msrfilename, "/dev/cpu%d", cpu);
if (fd_msr != -1) {
printf("MSR was already initialized\n");
return -1;
}
fd_msr = open(msrfilename, O_RDWR);
if (fd_msr < 0) {
perror("Error while opening /dev/cpu0");
printf("Did you install ports/sysutils/devcpu?\n");
return -1;
}
return 0;
+}
+void cleanup_cpu_msr(void) +{
if (fd_msr == -1) {
printf("No MSR initialized.\n");
return;
}
close(fd_msr);
/* Clear MSR file descriptor */
fd_msr = -1;
+}
+#else
#ifdef __DARWIN__ int setup_cpu_msr(int cpu) { @@ -251,4 +336,5 @@ } #endif #endif +#endif
flashrom mailing list flashrom@flashrom.org http://www.flashrom.org/mailman/listinfo/flashrom
2009/8/17 Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
On 13.08.2009 00:43, Carl-Daniel Hailfinger wrote:
On 13.08.2009 00:19, Carl-Daniel Hailfinger wrote:
On 12.08.2009 20:44, Stefan Reinauer wrote:
This needs /dev/cpu0 from ports/sysutils
Stefan, since the original patch is from you, you may want to add your Signoff here as well.
Compiles on FreeBSD and Linux and is the least invasive solution I could come up with.
This is 0.9.1 material.
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Having sysutils/devcpu installed doesn't look necessary to me (patch compiles/flashrom ELF runs without errors). No, I don't own GeodeLX hardware.
Acked-by: Idwer Vollering vidwer@gmail.com
Index: flashrom-rdmsr_freebsd/flash.h
--- flashrom-rdmsr_freebsd/flash.h (Revision 685) +++ flashrom-rdmsr_freebsd/flash.h (Arbeitskopie) @@ -309,11 +309,21 @@ void physunmap(void *virt_addr, size_t len); int setup_cpu_msr(int cpu); void cleanup_cpu_msr(void); -#ifndef __DARWIN__ +#if !defined(__DARWIN__) && !defined(__FreeBSD__) && !defined(__DragonFly__) 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(__DragonFly__) +/* FreeBSD already has conflicting definitions for wrmsr/rdmsr. */ +#undef rdmsr +#undef wrmsr +#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
/* internal.c */ struct pci_dev *pci_dev_find_filter(struct pci_filter filter); Index: flashrom-rdmsr_freebsd/physmap.c =================================================================== --- flashrom-rdmsr_freebsd/physmap.c (Revision 685) +++ flashrom-rdmsr_freebsd/physmap.c (Arbeitskopie) @@ -215,6 +215,91 @@ fd_msr = -1; } #else +#if defined(__FreeBSD__) || defined(__DragonFly__) +#include <sys/ioctl.h>
+typedef struct {
int msr;
uint64_t data;
+} cpu_msr_args_t; +#define CPU_RDMSR _IOWR('c', 1, cpu_msr_args_t) +#define CPU_WRMSR _IOWR('c', 2, cpu_msr_args_t)
+static int fd_msr = -1;
+msr_t rdmsr(int addr) +{
cpu_msr_args_t args;
msr_t msr = { 0xffffffff, 0xffffffff };
args.msr = addr;
if (ioctl(fd_msr, CPU_RDMSR, &args) < 0) {
perror("CPU_RDMSR");
close(fd_msr);
exit(1);
}
msr.lo = args.data & 0xffffffff;
msr.hi = args.data >> 32;
return msr;
+}
+int wrmsr(int addr, msr_t msr) +{
cpu_msr_args_t args;
args.msr = addr;
args.data = (((uint64_t)msr.hi) << 32) | msr.lo;
if (ioctl(fd_msr, CPU_WRMSR, &args) < 0) {
perror("CPU_WRMSR");
close(fd_msr);
exit(1);
}
return 0;
+}
+int setup_cpu_msr(int cpu) +{
char msrfilename[64];
memset(msrfilename, 0, 64);
sprintf(msrfilename, "/dev/cpu%d", cpu);
if (fd_msr != -1) {
printf("MSR was already initialized\n");
return -1;
}
fd_msr = open(msrfilename, O_RDWR);
if (fd_msr < 0) {
perror("Error while opening /dev/cpu0");
printf("Did you install ports/sysutils/devcpu?\n");
return -1;
}
return 0;
+}
+void cleanup_cpu_msr(void) +{
if (fd_msr == -1) {
printf("No MSR initialized.\n");
return;
}
close(fd_msr);
/* Clear MSR file descriptor */
fd_msr = -1;
+}
+#else
#ifdef __DARWIN__ int setup_cpu_msr(int cpu) { @@ -251,4 +336,5 @@ } #endif #endif +#endif
flashrom mailing list flashrom@flashrom.org http://www.flashrom.org/mailman/listinfo/flashrom
On 8/19/09 3:36 AM, Idwer Vollering wrote:
2009/8/17 Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net mailto:c-d.hailfinger.devel.2006@gmx.net>
On 13.08.2009 00:43, Carl-Daniel Hailfinger wrote: > On 13.08.2009 00:19, Carl-Daniel Hailfinger wrote: > >> On 12.08.2009 20:44, Stefan Reinauer wrote: >> >> >>> This needs /dev/cpu0 from ports/sysutils >>> >>> >> Stefan, since the original patch is from you, you may want to add >> your Signoff here as well. >> Compiles on FreeBSD and Linux and is the least invasive solution I could come up with. This is 0.9.1 material.
Signed-off-by: Stefan Reinauer stepan@coresystems.de
Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net <mailto:c-d.hailfinger.devel.2006@gmx.net>>
Having sysutils/devcpu installed doesn't look necessary to me (patch compiles/flashrom ELF runs without errors). No, I don't own GeodeLX hardware.
Acked-by: Idwer Vollering <vidwer@gmail.com mailto:vidwer@gmail.com>
Index: flashrom-rdmsr_freebsd/flash.h =================================================================== --- flashrom-rdmsr_freebsd/flash.h (Revision 685) +++ flashrom-rdmsr_freebsd/flash.h (Arbeitskopie) @@ -309,11 +309,21 @@ void physunmap(void *virt_addr, size_t len); int setup_cpu_msr(int cpu); void cleanup_cpu_msr(void); -#ifndef __DARWIN__ +#if !defined(__DARWIN__) && !defined(__FreeBSD__) && !defined(__DragonFly__) 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(__DragonFly__) +/* FreeBSD already has conflicting definitions for wrmsr/rdmsr. */ +#undef rdmsr +#undef wrmsr +#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 /* internal.c */ struct pci_dev *pci_dev_find_filter(struct pci_filter filter); Index: flashrom-rdmsr_freebsd/physmap.c =================================================================== --- flashrom-rdmsr_freebsd/physmap.c (Revision 685) +++ flashrom-rdmsr_freebsd/physmap.c (Arbeitskopie) @@ -215,6 +215,91 @@ fd_msr = -1; } #else +#if defined(__FreeBSD__) || defined(__DragonFly__) +#include <sys/ioctl.h> + +typedef struct { + int msr; + uint64_t data; +} cpu_msr_args_t; +#define CPU_RDMSR _IOWR('c', 1, cpu_msr_args_t) +#define CPU_WRMSR _IOWR('c', 2, cpu_msr_args_t) + +static int fd_msr = -1; + +msr_t rdmsr(int addr) +{ + cpu_msr_args_t args; + + msr_t msr = { 0xffffffff, 0xffffffff }; + + args.msr = addr; + + if (ioctl(fd_msr, CPU_RDMSR, &args) < 0) { + perror("CPU_RDMSR"); + close(fd_msr); + exit(1); + } + + msr.lo = args.data & 0xffffffff; + msr.hi = args.data >> 32; + + return msr; +} + +int wrmsr(int addr, msr_t msr) +{ + cpu_msr_args_t args; + + args.msr = addr; + args.data = (((uint64_t)msr.hi) << 32) | msr.lo; + + if (ioctl(fd_msr, CPU_WRMSR, &args) < 0) { + perror("CPU_WRMSR"); + close(fd_msr); + exit(1); + } + + return 0; +} + +int setup_cpu_msr(int cpu) +{ + char msrfilename[64]; + memset(msrfilename, 0, 64); + sprintf(msrfilename, "/dev/cpu%d", cpu); + + if (fd_msr != -1) { + printf("MSR was already initialized\n"); + return -1; + } + + fd_msr = open(msrfilename, O_RDWR); + + if (fd_msr < 0) { + perror("Error while opening /dev/cpu0"); + printf("Did you install ports/sysutils/devcpu?\n"); + return -1; + } + + return 0; +} + +void cleanup_cpu_msr(void) +{ + if (fd_msr == -1) { + printf("No MSR initialized.\n"); + return; + } + + close(fd_msr); + + /* Clear MSR file descriptor */ + fd_msr = -1; +} + +#else + #ifdef __DARWIN__ int setup_cpu_msr(int cpu) { @@ -251,4 +336,5 @@ } #endif #endif +#endif -- http://www.hailfinger.org/ _______________________________________________ flashrom mailing list flashrom@flashrom.org <mailto:flashrom@flashrom.org> http://www.flashrom.org/mailman/listinfo/flashrom
On 19.08.2009 12:24, Stefan Reinauer wrote:
On 8/19/09 3:36 AM, Idwer Vollering wrote:
Signed-off-by: Stefan Reinauer stepan@coresystems.de
Signed-off-by: Carl-Daniel Hailfinger c-d.hailfinger.devel.2006@gmx.net
Acked-by: Idwer Vollering vidwer@gmail.com
Thanks, committed in r690.
Regards, Carl-Daniel