Stefan Reinauer | 37f3935 | 2009-09-01 10:03:01 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of msrtool. |
| 3 | * |
| 4 | * Copyright (c) 2009 coresystems GmbH |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Stefan Reinauer | 37f3935 | 2009-09-01 10:03:01 +0000 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <sys/types.h> |
| 17 | #include <sys/stat.h> |
| 18 | #include <fcntl.h> |
| 19 | #include <unistd.h> |
| 20 | #include <string.h> |
| 21 | #include <errno.h> |
| 22 | |
| 23 | #include "msrtool.h" |
| 24 | |
Stefan Reinauer | 9018b6e | 2011-03-14 09:08:27 +0000 | [diff] [blame] | 25 | /* This Darwin support requires DirectHW, which is available at |
| 26 | * http://www.coreboot.org/DirectHW |
Peter Stuge | 34b876c | 2009-11-16 17:29:22 +0000 | [diff] [blame] | 27 | */ |
| 28 | |
Stefan Reinauer | 37f3935 | 2009-09-01 10:03:01 +0000 | [diff] [blame] | 29 | int darwin_probe(const struct sysdef *system) |
| 30 | { |
| 31 | #ifdef __DARWIN__ |
| 32 | return iopl(3) == 0; |
| 33 | #else |
| 34 | return 0; |
| 35 | #endif |
| 36 | } |
| 37 | |
| 38 | int darwin_open(uint8_t cpu, enum SysModes mode) |
| 39 | { |
Stefan Reinauer | 84d69f7 | 2009-10-05 10:23:36 +0000 | [diff] [blame] | 40 | #ifdef __DARWIN__ |
Stefan Reinauer | 37f3935 | 2009-09-01 10:03:01 +0000 | [diff] [blame] | 41 | if (cpu > 0) { |
| 42 | fprintf(stderr, "%s: only core 0 is supported on Mac OS X right now.\n", __func__); |
| 43 | return 0; |
| 44 | } |
| 45 | return 1; |
Stefan Reinauer | 84d69f7 | 2009-10-05 10:23:36 +0000 | [diff] [blame] | 46 | #else |
| 47 | return 0; |
| 48 | #endif |
Stefan Reinauer | 37f3935 | 2009-09-01 10:03:01 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | int darwin_close(uint8_t cpu) |
| 52 | { |
| 53 | return 1; |
| 54 | } |
| 55 | |
| 56 | int darwin_rdmsr(uint8_t cpu, uint32_t addr, struct msr *val) |
| 57 | { |
Stefan Reinauer | 84d69f7 | 2009-10-05 10:23:36 +0000 | [diff] [blame] | 58 | #ifdef __DARWIN__ |
Stefan Reinauer | 37f3935 | 2009-09-01 10:03:01 +0000 | [diff] [blame] | 59 | msr_t msr; |
| 60 | |
| 61 | msr = rdmsr(addr); |
| 62 | |
| 63 | val->hi = msr.lo; |
| 64 | val->lo = msr.hi; |
| 65 | return 1; |
Stefan Reinauer | 84d69f7 | 2009-10-05 10:23:36 +0000 | [diff] [blame] | 66 | #else |
| 67 | return 0; |
| 68 | #endif |
Stefan Reinauer | 37f3935 | 2009-09-01 10:03:01 +0000 | [diff] [blame] | 69 | } |