diff options
author | Jordan Crouse <jordan.crouse@amd.com> | 2008-03-11 15:43:00 -0600 |
---|---|---|
committer | Jordan Crouse <jordan.crouse@amd.com> | 2008-03-14 14:16:42 -0600 |
commit | ec8edd1393f482ca42b401463f0f09580aa263a0 (patch) | |
tree | 62892967de07f4db2d66f98e4d4c1001262dce9c /src/geode_msr.c | |
parent | a7bc1a7f6b439419fc27b669d9d7f99f882d83fe (diff) |
First stage of the rename process - get rid of all amd_ prefixes -
change either to geode_ or just to lx_ or gx_ depending on the processor.
Change the name in the Makefiles and other collateral
Diffstat (limited to 'src/geode_msr.c')
-rw-r--r-- | src/geode_msr.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/geode_msr.c b/src/geode_msr.c new file mode 100644 index 0000000..12b9f73 --- /dev/null +++ b/src/geode_msr.c @@ -0,0 +1,65 @@ +#define _LARGEFILE64_SOURCE +#include <stdio.h> +#include <unistd.h> +#include <fcntl.h> +#include <sys/types.h> +#include <sys/errno.h> +#include "os.h" + +static int _msr_open(void) +{ + static int msrfd = 0; + + if (msrfd == 0) { + msrfd = open("/dev/cpu/0/msr", O_RDWR); + if (msrfd == -1) + ErrorF("Unable to open /dev/cpu/0/msr: %d\n", errno); + } + + return msrfd; +} + +int GeodeReadMSR(unsigned long addr, unsigned long *lo, unsigned long *hi) +{ + unsigned int data[2]; + int fd = _msr_open(); + int ret; + + if (fd == -1) + return -1; + + ret = lseek64(fd, (off64_t) addr, SEEK_SET); + + if (ret == -1) + return -1; + + ret = read(fd, (void *) data, sizeof(data)); + + if (ret != 8) + return -1; + + *hi = data[1]; + *lo = data[0]; + + return 0; +} + +int GeodeWriteMSR(unsigned long addr, unsigned long lo, unsigned long hi) +{ + unsigned int data[2]; + int fd = _msr_open(); + + if (fd == -1) + return - 1; + + if (lseek64(fd, (off64_t) addr, SEEK_SET) == -1) + return -1; + + data[0] = lo; + data[1] = hi; + + if (write(fd, (void *) data, 8) != 8) + return -1; + + return 0; +} |