mainboard/dell: Add new mainboard XPS 8300 (Sandy Bridge)
[coreboot.git] / util / intelmetool / msr.c
blob1a5ead9737dcf7d39a4b17de855badb67945e951
1 /* intelmetool */
2 /* SPDX-License-Identifier: GPL-2.0-or-later */
4 #include <fcntl.h>
5 #include <unistd.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <errno.h>
11 #include "msr.h"
13 #ifndef __DARWIN__
14 static int fd_msr = 0;
16 static int rdmsr(int addr, uint64_t *msr)
18 if (lseek(fd_msr, (off_t) addr, SEEK_SET) == -1) {
19 perror("Could not lseek() to MSR");
20 close(fd_msr);
21 return -1;
24 if (read(fd_msr, msr, 8) == 8) {
25 close(fd_msr);
26 return 0;
29 if (errno == EIO) {
30 perror("IO error couldn't read MSR.");
31 close(fd_msr);
32 /* On older platforms the MSR might not exists */
33 return -2;
36 perror("Couldn't read() MSR");
37 close(fd_msr);
38 return -1;
40 #endif
42 int msr_bootguard(uint64_t *msr)
45 #ifndef __DARWIN__
46 fd_msr = open("/dev/cpu/0/msr", O_RDONLY);
47 if (fd_msr < 0) {
48 perror("Error while opening /dev/cpu/0/msr");
49 printf("Did you run 'modprobe msr'?\n");
50 return -1;
53 if (rdmsr(MSR_BOOTGUARD, msr) < 0)
54 return -1;
55 #endif
57 return 0;