Improve error handling and make RCONF_DEFAULT_MSR address be a constant.
Signed-off-by: Mart Raudsepp mart.raudsepp@artecdesign.ee --- chipset_enable.c | 42 +++++++++++++++++++++++++++++++++++------- 1 files changed, 35 insertions(+), 7 deletions(-)
diff --git a/chipset_enable.c b/chipset_enable.c index d6ef92e..f5a6612 100644 --- a/chipset_enable.c +++ b/chipset_enable.c @@ -228,11 +228,11 @@ static int enable_flash_cs5530(struct pci_dev *dev, const char *name)
static int enable_flash_cs5536(struct pci_dev *dev, const char *name) { - #define MSR_NORF_CTL 0x51400018 + #define MSR_RCONF_DEFAULT 0x1808 + #define MSR_NORF_CTL 0x51400018
int fd_msr; unsigned char buf[8]; - unsigned int addr = 0x1808;
/* Geode systems write protect the BIOS via RCONFs (cache * settings similar to MTRRs). To unlock, change MSR 0x1808 @@ -258,41 +258,69 @@ static int enable_flash_cs5536(struct pci_dev *dev, const char *name) perror("open msr"); return -1; } - lseek64(fd_msr, (off64_t) addr, SEEK_SET); - read(fd_msr, buf, 8); + + if (lseek64(fd_msr, (off64_t) MSR_RCONF_DEFAULT, SEEK_SET) == -1) { + perror("lseek64"); + close(fd_msr); + return -1; + } + + if (read(fd_msr, buf, 8) != 8) { + perror("read"); + close(fd_msr); + return -1; + }
printf("Enabling Geode MSR to write to flash.\n");
if (buf[7] != 0x22) { buf[7] &= 0xFB; - lseek64(fd_msr, (off64_t) addr, SEEK_SET); + if (lseek64(fd_msr, (off64_t) MSR_RCONF_DEFAULT, SEEK_SET) == -1) { + perror("lseek64"); + close(fd_msr); + return -1; + } + if (write(fd_msr, buf, 8) < 0) { perror("msr write"); printf ("Cannot write to MSR. Make sure the msr kernel module is loaded: 'modprobe msr'\n"); + close(fd_msr); return -1; } }
- lseek64(fd_msr, (off64_t) MSR_NORF_CTL, SEEK_SET); + if (lseek64(fd_msr, (off64_t) MSR_NORF_CTL, SEEK_SET) == -1) { + perror("lseek64"); + close(fd_msr); + return -1; + } + if (read(fd_msr, buf, 8) != 8) { perror("read msr"); + close(fd_msr); return -1; }
/* Raise WE_CS3 bit */ buf[0] |= 0x08;
- lseek64(fd_msr, (off64_t) MSR_NORF_CTL, SEEK_SET); + if (lseek64(fd_msr, (off64_t) MSR_NORF_CTL, SEEK_SET) == -1) { + perror("lseek64"); + close(fd_msr); + return -1; + } if (write(fd_msr, buf, 8) < 0) { perror("msr write"); printf ("Cannot write to MSR. Make sure the msr kernel module is loaded: 'modprobe msr'\n"); + close(fd_msr); return -1; }
close(fd_msr);
+ #undef MSR_RCONF_DEFAULT #undef MSR_NORF_CTL return 0; }