physmap.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  1. /*
  2. * This file is part of the flashrom project.
  3. *
  4. * Copyright (C) 2009 Peter Stuge <peter@stuge.se>
  5. * Copyright (C) 2009 coresystems GmbH
  6. * Copyright (C) 2010 Carl-Daniel Hailfinger
  7. * Copyright (C) 2010 Rudolf Marek <r.marek@assembler.cz>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; version 2 of the License.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #include <unistd.h>
  23. #include <stdbool.h>
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <string.h>
  27. #include <errno.h>
  28. #include "flash.h"
  29. #include "programmer.h"
  30. #include "hwaccess.h"
  31. #if !defined(__DJGPP__) && !defined(__LIBPAYLOAD__)
  32. /* No file access needed/possible to get mmap access permissions or access MSR. */
  33. #include <sys/stat.h>
  34. #include <fcntl.h>
  35. #endif
  36. #ifdef __DJGPP__
  37. #include <dpmi.h>
  38. #include <sys/nearptr.h>
  39. #define MEM_DEV "dpmi"
  40. static void *realmem_map;
  41. static void *map_first_meg(uintptr_t phys_addr, size_t len)
  42. {
  43. if (realmem_map)
  44. return realmem_map + phys_addr;
  45. realmem_map = valloc(1024 * 1024);
  46. if (!realmem_map)
  47. return ERROR_PTR;
  48. if (__djgpp_map_physical_memory(realmem_map, (1024 * 1024), 0)) {
  49. free(realmem_map);
  50. realmem_map = NULL;
  51. return ERROR_PTR;
  52. }
  53. return realmem_map + phys_addr;
  54. }
  55. static void *sys_physmap(uintptr_t phys_addr, size_t len)
  56. {
  57. int ret;
  58. __dpmi_meminfo mi;
  59. /* Enable 4GB limit on DS descriptor. */
  60. if (!__djgpp_nearptr_enable())
  61. return ERROR_PTR;
  62. if ((phys_addr + len - 1) < (1024 * 1024)) {
  63. /* We need to use another method to map first 1MB. */
  64. return map_first_meg(phys_addr, len);
  65. }
  66. mi.address = phys_addr;
  67. mi.size = len;
  68. ret = __dpmi_physical_address_mapping(&mi);
  69. if (ret != 0)
  70. return ERROR_PTR;
  71. return (void *) mi.address + __djgpp_conventional_base;
  72. }
  73. #define sys_physmap_rw_uncached sys_physmap
  74. #define sys_physmap_ro_cached sys_physmap
  75. void sys_physunmap_unaligned(void *virt_addr, size_t len)
  76. {
  77. __dpmi_meminfo mi;
  78. /* There is no known way to unmap the first 1 MB. The DPMI server will
  79. * do this for us on exit.
  80. */
  81. if ((virt_addr >= realmem_map) &&
  82. ((virt_addr + len) <= (realmem_map + (1024 * 1024)))) {
  83. return;
  84. }
  85. mi.address = (unsigned long) virt_addr;
  86. __dpmi_free_physical_address_mapping(&mi);
  87. }
  88. #elif defined(__LIBPAYLOAD__)
  89. #include <arch/virtual.h>
  90. #define MEM_DEV ""
  91. void *sys_physmap(uintptr_t phys_addr, size_t len)
  92. {
  93. return (void *)phys_to_virt(phys_addr);
  94. }
  95. #define sys_physmap_rw_uncached sys_physmap
  96. #define sys_physmap_ro_cached sys_physmap
  97. void sys_physunmap_unaligned(void *virt_addr, size_t len)
  98. {
  99. }
  100. #elif defined(__MACH__) && defined(__APPLE__)
  101. #define MEM_DEV "DirectHW"
  102. static void *sys_physmap(uintptr_t phys_addr, size_t len)
  103. {
  104. /* The short form of ?: is a GNU extension.
  105. * FIXME: map_physical returns NULL both for errors and for success
  106. * if the region is mapped at virtual address zero. If in doubt, report
  107. * an error until a better interface exists.
  108. */
  109. return map_physical(phys_addr, len) ? : ERROR_PTR;
  110. }
  111. /* The OS X driver does not differentiate between mapping types. */
  112. #define sys_physmap_rw_uncached sys_physmap
  113. #define sys_physmap_ro_cached sys_physmap
  114. void sys_physunmap_unaligned(void *virt_addr, size_t len)
  115. {
  116. unmap_physical(virt_addr, len);
  117. }
  118. #else
  119. #include <sys/mman.h>
  120. #if defined (__sun) && (defined(__i386) || defined(__amd64))
  121. # define MEM_DEV "/dev/xsvc"
  122. #else
  123. # define MEM_DEV "/dev/mem"
  124. #endif
  125. static int fd_mem = -1;
  126. static int fd_mem_cached = -1;
  127. /* For MMIO access. Must be uncached, doesn't make sense to restrict to ro. */
  128. static void *sys_physmap_rw_uncached(uintptr_t phys_addr, size_t len)
  129. {
  130. void *virt_addr;
  131. if (-1 == fd_mem) {
  132. /* Open the memory device UNCACHED. Important for MMIO. */
  133. if (-1 == (fd_mem = open(MEM_DEV, O_RDWR | O_SYNC))) {
  134. msg_perr("Critical error: open(" MEM_DEV "): %s\n", strerror(errno));
  135. return ERROR_PTR;
  136. }
  137. }
  138. virt_addr = mmap(NULL, len, PROT_WRITE | PROT_READ, MAP_SHARED, fd_mem, (off_t)phys_addr);
  139. return MAP_FAILED == virt_addr ? ERROR_PTR : virt_addr;
  140. }
  141. /* For reading DMI/coreboot/whatever tables. We should never write, and we
  142. * do not care about caching.
  143. */
  144. static void *sys_physmap_ro_cached(uintptr_t phys_addr, size_t len)
  145. {
  146. void *virt_addr;
  147. if (-1 == fd_mem_cached) {
  148. /* Open the memory device CACHED. */
  149. if (-1 == (fd_mem_cached = open(MEM_DEV, O_RDWR))) {
  150. msg_perr("Critical error: open(" MEM_DEV "): %s\n", strerror(errno));
  151. return ERROR_PTR;
  152. }
  153. }
  154. virt_addr = mmap(NULL, len, PROT_READ, MAP_SHARED, fd_mem_cached, (off_t)phys_addr);
  155. return MAP_FAILED == virt_addr ? ERROR_PTR : virt_addr;
  156. }
  157. void sys_physunmap_unaligned(void *virt_addr, size_t len)
  158. {
  159. munmap(virt_addr, len);
  160. }
  161. #endif
  162. #define PHYSM_RW 0
  163. #define PHYSM_RO 1
  164. #define PHYSM_NOCLEANUP 0
  165. #define PHYSM_CLEANUP 1
  166. #define PHYSM_EXACT 0
  167. #define PHYSM_ROUND 1
  168. /* Round start to nearest page boundary below and set len so that the resulting address range ends at the lowest
  169. * possible page boundary where the original address range is still entirely contained. It returns the
  170. * difference between the rounded start address and the original start address. */
  171. static uintptr_t round_to_page_boundaries(uintptr_t *start, size_t *len)
  172. {
  173. uintptr_t page_size = getpagesize();
  174. uintptr_t page_mask = ~(page_size-1);
  175. uintptr_t end = *start + *len;
  176. uintptr_t old_start = *start;
  177. msg_gspew("page_size=%" PRIxPTR "\n", page_size);
  178. msg_gspew("pre-rounding: start=0x%0*" PRIxPTR ", len=0x%zx, end=0x%0*" PRIxPTR "\n",
  179. PRIxPTR_WIDTH, *start, *len, PRIxPTR_WIDTH, end);
  180. *start = *start & page_mask;
  181. end = (end + page_size - 1) & page_mask;
  182. *len = end - *start;
  183. msg_gspew("post-rounding: start=0x%0*" PRIxPTR ", len=0x%zx, end=0x%0*" PRIxPTR "\n",
  184. PRIxPTR_WIDTH, *start, *len, PRIxPTR_WIDTH, *start + *len);
  185. return old_start - *start;
  186. }
  187. struct undo_physmap_data {
  188. void *virt_addr;
  189. size_t len;
  190. };
  191. static int undo_physmap(void *data)
  192. {
  193. if (data == NULL) {
  194. msg_perr("%s: tried to physunmap without valid data!\n", __func__);
  195. return 1;
  196. }
  197. struct undo_physmap_data *d = data;
  198. physunmap_unaligned(d->virt_addr, d->len);
  199. free(data);
  200. return 0;
  201. }
  202. static void *physmap_common(const char *descr, uintptr_t phys_addr, size_t len, bool readonly, bool autocleanup,
  203. bool round)
  204. {
  205. void *virt_addr;
  206. uintptr_t offset = 0;
  207. if (len == 0) {
  208. msg_pspew("Not mapping %s, zero size at 0x%0*" PRIxPTR ".\n", descr, PRIxPTR_WIDTH, phys_addr);
  209. return ERROR_PTR;
  210. }
  211. if (round)
  212. offset = round_to_page_boundaries(&phys_addr, &len);
  213. if (readonly)
  214. virt_addr = sys_physmap_ro_cached(phys_addr, len);
  215. else
  216. virt_addr = sys_physmap_rw_uncached(phys_addr, len);
  217. if (ERROR_PTR == virt_addr) {
  218. if (NULL == descr)
  219. descr = "memory";
  220. msg_perr("Error accessing %s, 0x%zx bytes at 0x%0*" PRIxPTR "\n",
  221. descr, len, PRIxPTR_WIDTH, phys_addr);
  222. msg_perr(MEM_DEV " mmap failed: %s\n", strerror(errno));
  223. #ifdef __linux__
  224. if (EINVAL == errno) {
  225. msg_perr("In Linux this error can be caused by the CONFIG_NONPROMISC_DEVMEM (<2.6.27),\n");
  226. msg_perr("CONFIG_STRICT_DEVMEM (>=2.6.27) and CONFIG_X86_PAT kernel options.\n");
  227. msg_perr("Please check if either is enabled in your kernel before reporting a failure.\n");
  228. msg_perr("You can override CONFIG_X86_PAT at boot with the nopat kernel parameter but\n");
  229. msg_perr("disabling the other option unfortunately requires a kernel recompile. Sorry!\n");
  230. }
  231. #elif defined (__OpenBSD__)
  232. msg_perr("Please set securelevel=-1 in /etc/rc.securelevel "
  233. "and reboot, or reboot into\n"
  234. "single user mode.\n");
  235. #endif
  236. return ERROR_PTR;
  237. }
  238. if (autocleanup) {
  239. struct undo_physmap_data *d = malloc(sizeof(struct undo_physmap_data));
  240. if (d == NULL) {
  241. msg_perr("%s: Out of memory!\n", __func__);
  242. physunmap_unaligned(virt_addr, len);
  243. return ERROR_PTR;
  244. }
  245. d->virt_addr = virt_addr;
  246. d->len = len;
  247. if (register_shutdown(undo_physmap, d) != 0) {
  248. msg_perr("%s: Could not register shutdown function!\n", __func__);
  249. physunmap_unaligned(virt_addr, len);
  250. return ERROR_PTR;
  251. }
  252. }
  253. return virt_addr + offset;
  254. }
  255. void physunmap_unaligned(void *virt_addr, size_t len)
  256. {
  257. /* No need to check for zero size, such mappings would have yielded ERROR_PTR. */
  258. if (virt_addr == ERROR_PTR) {
  259. msg_perr("Trying to unmap a nonexisting mapping!\n"
  260. "Please report a bug at flashrom@flashrom.org\n");
  261. return;
  262. }
  263. sys_physunmap_unaligned(virt_addr, len);
  264. }
  265. void physunmap(void *virt_addr, size_t len)
  266. {
  267. uintptr_t tmp;
  268. /* No need to check for zero size, such mappings would have yielded ERROR_PTR. */
  269. if (virt_addr == ERROR_PTR) {
  270. msg_perr("Trying to unmap a nonexisting mapping!\n"
  271. "Please report a bug at flashrom@flashrom.org\n");
  272. return;
  273. }
  274. tmp = (uintptr_t)virt_addr;
  275. /* We assume that the virtual address of a page-aligned physical address is page-aligned as well. By
  276. * extension, rounding a virtual unaligned address as returned by physmap should yield the same offset
  277. * between rounded and original virtual address as between rounded and original physical address.
  278. */
  279. round_to_page_boundaries(&tmp, &len);
  280. virt_addr = (void *)tmp;
  281. physunmap_unaligned(virt_addr, len);
  282. }
  283. void *physmap(const char *descr, uintptr_t phys_addr, size_t len)
  284. {
  285. return physmap_common(descr, phys_addr, len, PHYSM_RW, PHYSM_NOCLEANUP, PHYSM_ROUND);
  286. }
  287. void *rphysmap(const char *descr, uintptr_t phys_addr, size_t len)
  288. {
  289. return physmap_common(descr, phys_addr, len, PHYSM_RW, PHYSM_CLEANUP, PHYSM_ROUND);
  290. }
  291. void *physmap_ro(const char *descr, uintptr_t phys_addr, size_t len)
  292. {
  293. return physmap_common(descr, phys_addr, len, PHYSM_RO, PHYSM_NOCLEANUP, PHYSM_ROUND);
  294. }
  295. void *physmap_ro_unaligned(const char *descr, uintptr_t phys_addr, size_t len)
  296. {
  297. return physmap_common(descr, phys_addr, len, PHYSM_RO, PHYSM_NOCLEANUP, PHYSM_EXACT);
  298. }
  299. /* MSR abstraction implementations for Linux, OpenBSD, FreeBSD/Dragonfly, OSX, libpayload
  300. * and a non-working default implemenation on the bottom. See also hwaccess.h for some (re)declarations. */
  301. #if defined(__i386__) || defined(__x86_64__)
  302. #ifdef __linux__
  303. /*
  304. * Reading and writing to MSRs, however requires instructions rdmsr/wrmsr,
  305. * which are ring0 privileged instructions so only the kernel can do the
  306. * read/write. This function, therefore, requires that the msr kernel module
  307. * be loaded to access these instructions from user space using device
  308. * /dev/cpu/0/msr.
  309. */
  310. static int fd_msr = -1;
  311. msr_t rdmsr(int addr)
  312. {
  313. uint32_t buf[2];
  314. msr_t msr = { 0xffffffff, 0xffffffff };
  315. if (lseek(fd_msr, (off_t) addr, SEEK_SET) == -1) {
  316. msg_perr("Could not lseek() MSR: %s\n", strerror(errno));
  317. close(fd_msr);
  318. exit(1);
  319. }
  320. if (read(fd_msr, buf, 8) == 8) {
  321. msr.lo = buf[0];
  322. msr.hi = buf[1];
  323. return msr;
  324. }
  325. if (errno != EIO) {
  326. // A severe error.
  327. msg_perr("Could not read() MSR: %s\n", strerror(errno));
  328. close(fd_msr);
  329. exit(1);
  330. }
  331. return msr;
  332. }
  333. int wrmsr(int addr, msr_t msr)
  334. {
  335. uint32_t buf[2];
  336. buf[0] = msr.lo;
  337. buf[1] = msr.hi;
  338. if (lseek(fd_msr, (off_t) addr, SEEK_SET) == -1) {
  339. msg_perr("Could not lseek() MSR: %s\n", strerror(errno));
  340. close(fd_msr);
  341. exit(1);
  342. }
  343. if (write(fd_msr, buf, 8) != 8 && errno != EIO) {
  344. msg_perr("Could not write() MSR: %s\n", strerror(errno));
  345. close(fd_msr);
  346. exit(1);
  347. }
  348. /* Some MSRs must not be written. */
  349. if (errno == EIO)
  350. return -1;
  351. return 0;
  352. }
  353. int setup_cpu_msr(int cpu)
  354. {
  355. char msrfilename[64];
  356. memset(msrfilename, 0, sizeof(msrfilename));
  357. snprintf(msrfilename, sizeof(msrfilename), "/dev/cpu/%d/msr", cpu);
  358. if (fd_msr != -1) {
  359. msg_pinfo("MSR was already initialized\n");
  360. return -1;
  361. }
  362. fd_msr = open(msrfilename, O_RDWR);
  363. if (fd_msr < 0) {
  364. msg_perr("Error while opening %s: %s\n", msrfilename, strerror(errno));
  365. msg_pinfo("Did you run 'modprobe msr'?\n");
  366. return -1;
  367. }
  368. return 0;
  369. }
  370. void cleanup_cpu_msr(void)
  371. {
  372. if (fd_msr == -1) {
  373. msg_pinfo("No MSR initialized.\n");
  374. return;
  375. }
  376. close(fd_msr);
  377. /* Clear MSR file descriptor. */
  378. fd_msr = -1;
  379. }
  380. #elif defined(__OpenBSD__) && defined (__i386__) /* This does only work for certain AMD Geode LX systems see amdmsr(4). */
  381. #include <sys/ioctl.h>
  382. #include <machine/amdmsr.h>
  383. static int fd_msr = -1;
  384. msr_t rdmsr(int addr)
  385. {
  386. struct amdmsr_req args;
  387. msr_t msr = { 0xffffffff, 0xffffffff };
  388. args.addr = (uint32_t)addr;
  389. if (ioctl(fd_msr, RDMSR, &args) < 0) {
  390. msg_perr("Error while executing RDMSR ioctl: %s\n", strerror(errno));
  391. close(fd_msr);
  392. exit(1);
  393. }
  394. msr.lo = args.val & 0xffffffff;
  395. msr.hi = args.val >> 32;
  396. return msr;
  397. }
  398. int wrmsr(int addr, msr_t msr)
  399. {
  400. struct amdmsr_req args;
  401. args.addr = addr;
  402. args.val = (((uint64_t)msr.hi) << 32) | msr.lo;
  403. if (ioctl(fd_msr, WRMSR, &args) < 0) {
  404. msg_perr("Error while executing WRMSR ioctl: %s\n", strerror(errno));
  405. close(fd_msr);
  406. exit(1);
  407. }
  408. return 0;
  409. }
  410. int setup_cpu_msr(int cpu)
  411. {
  412. char msrfilename[64];
  413. memset(msrfilename, 0, sizeof(msrfilename));
  414. snprintf(msrfilename, sizeof(msrfilename), "/dev/amdmsr");
  415. if (fd_msr != -1) {
  416. msg_pinfo("MSR was already initialized\n");
  417. return -1;
  418. }
  419. fd_msr = open(msrfilename, O_RDWR);
  420. if (fd_msr < 0) {
  421. msg_perr("Error while opening %s: %s\n", msrfilename, strerror(errno));
  422. return -1;
  423. }
  424. return 0;
  425. }
  426. void cleanup_cpu_msr(void)
  427. {
  428. if (fd_msr == -1) {
  429. msg_pinfo("No MSR initialized.\n");
  430. return;
  431. }
  432. close(fd_msr);
  433. /* Clear MSR file descriptor. */
  434. fd_msr = -1;
  435. }
  436. #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
  437. #include <sys/ioctl.h>
  438. typedef struct {
  439. int msr;
  440. uint64_t data;
  441. } cpu_msr_args_t;
  442. #define CPU_RDMSR _IOWR('c', 1, cpu_msr_args_t)
  443. #define CPU_WRMSR _IOWR('c', 2, cpu_msr_args_t)
  444. static int fd_msr = -1;
  445. msr_t rdmsr(int addr)
  446. {
  447. cpu_msr_args_t args;
  448. msr_t msr = { 0xffffffff, 0xffffffff };
  449. args.msr = addr;
  450. if (ioctl(fd_msr, CPU_RDMSR, &args) < 0) {
  451. msg_perr("Error while executing CPU_RDMSR ioctl: %s\n", strerror(errno));
  452. close(fd_msr);
  453. exit(1);
  454. }
  455. msr.lo = args.data & 0xffffffff;
  456. msr.hi = args.data >> 32;
  457. return msr;
  458. }
  459. int wrmsr(int addr, msr_t msr)
  460. {
  461. cpu_msr_args_t args;
  462. args.msr = addr;
  463. args.data = (((uint64_t)msr.hi) << 32) | msr.lo;
  464. if (ioctl(fd_msr, CPU_WRMSR, &args) < 0) {
  465. msg_perr("Error while executing CPU_WRMSR ioctl: %s\n", strerror(errno));
  466. close(fd_msr);
  467. exit(1);
  468. }
  469. return 0;
  470. }
  471. int setup_cpu_msr(int cpu)
  472. {
  473. char msrfilename[64];
  474. memset(msrfilename, 0, sizeof(msrfilename));
  475. snprintf(msrfilename, sizeof(msrfilename), "/dev/cpu%d", cpu);
  476. if (fd_msr != -1) {
  477. msg_pinfo("MSR was already initialized\n");
  478. return -1;
  479. }
  480. fd_msr = open(msrfilename, O_RDWR);
  481. if (fd_msr < 0) {
  482. msg_perr("Error while opening %s: %s\n", msrfilename, strerror(errno));
  483. msg_pinfo("Did you install ports/sysutils/devcpu?\n");
  484. return -1;
  485. }
  486. return 0;
  487. }
  488. void cleanup_cpu_msr(void)
  489. {
  490. if (fd_msr == -1) {
  491. msg_pinfo("No MSR initialized.\n");
  492. return;
  493. }
  494. close(fd_msr);
  495. /* Clear MSR file descriptor. */
  496. fd_msr = -1;
  497. }
  498. #elif defined(__MACH__) && defined(__APPLE__)
  499. /* rdmsr() and wrmsr() are provided by DirectHW which needs neither setup nor cleanup. */
  500. int setup_cpu_msr(int cpu)
  501. {
  502. // Always succeed for now
  503. return 0;
  504. }
  505. void cleanup_cpu_msr(void)
  506. {
  507. // Nothing, yet.
  508. }
  509. #elif defined(__LIBPAYLOAD__)
  510. msr_t libpayload_rdmsr(int addr)
  511. {
  512. msr_t msr;
  513. unsigned long long val = _rdmsr(addr);
  514. msr.lo = val & 0xffffffff;
  515. msr.hi = val >> 32;
  516. return msr;
  517. }
  518. int libpayload_wrmsr(int addr, msr_t msr)
  519. {
  520. _wrmsr(addr, msr.lo | ((unsigned long long)msr.hi << 32));
  521. return 0;
  522. }
  523. int setup_cpu_msr(int cpu)
  524. {
  525. return 0;
  526. }
  527. void cleanup_cpu_msr(void)
  528. {
  529. }
  530. #else
  531. /* default MSR implementation */
  532. msr_t rdmsr(int addr)
  533. {
  534. msr_t ret = { 0xffffffff, 0xffffffff };
  535. return ret;
  536. }
  537. int wrmsr(int addr, msr_t msr)
  538. {
  539. return -1;
  540. }
  541. int setup_cpu_msr(int cpu)
  542. {
  543. msg_pinfo("No MSR support for your OS yet.\n");
  544. return -1;
  545. }
  546. void cleanup_cpu_msr(void)
  547. {
  548. // Nothing, yet.
  549. }
  550. #endif // OS switches for MSR code
  551. #else // x86
  552. /* Does MSR exist on non-x86 architectures? */
  553. #endif // arch switches for MSR code