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. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
Paul Menzel | a46a712 | 2013-02-23 18:37:27 +0100 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Stefan Reinauer | 37f3935 | 2009-09-01 10:03:01 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #include <sys/types.h> |
| 21 | #include <sys/stat.h> |
| 22 | #include <fcntl.h> |
| 23 | #include <unistd.h> |
| 24 | #include <string.h> |
| 25 | #include <errno.h> |
| 26 | |
| 27 | #include "msrtool.h" |
| 28 | |
Stefan Reinauer | 9018b6e | 2011-03-14 09:08:27 +0000 | [diff] [blame] | 29 | /* This Darwin support requires DirectHW, which is available at |
| 30 | * http://www.coreboot.org/DirectHW |
Peter Stuge | 34b876c | 2009-11-16 17:29:22 +0000 | [diff] [blame] | 31 | */ |
| 32 | |
Stefan Reinauer | 37f3935 | 2009-09-01 10:03:01 +0000 | [diff] [blame] | 33 | int darwin_probe(const struct sysdef *system) |
| 34 | { |
| 35 | #ifdef __DARWIN__ |
| 36 | return iopl(3) == 0; |
| 37 | #else |
| 38 | return 0; |
| 39 | #endif |
| 40 | } |
| 41 | |
| 42 | int darwin_open(uint8_t cpu, enum SysModes mode) |
| 43 | { |
Stefan Reinauer | 84d69f7 | 2009-10-05 10:23:36 +0000 | [diff] [blame] | 44 | #ifdef __DARWIN__ |
Stefan Reinauer | 37f3935 | 2009-09-01 10:03:01 +0000 | [diff] [blame] | 45 | if (cpu > 0) { |
| 46 | fprintf(stderr, "%s: only core 0 is supported on Mac OS X right now.\n", __func__); |
| 47 | return 0; |
| 48 | } |
| 49 | return 1; |
Stefan Reinauer | 84d69f7 | 2009-10-05 10:23:36 +0000 | [diff] [blame] | 50 | #else |
| 51 | return 0; |
| 52 | #endif |
Stefan Reinauer | 37f3935 | 2009-09-01 10:03:01 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | int darwin_close(uint8_t cpu) |
| 56 | { |
| 57 | return 1; |
| 58 | } |
| 59 | |
| 60 | int darwin_rdmsr(uint8_t cpu, uint32_t addr, struct msr *val) |
| 61 | { |
Stefan Reinauer | 84d69f7 | 2009-10-05 10:23:36 +0000 | [diff] [blame] | 62 | #ifdef __DARWIN__ |
Stefan Reinauer | 37f3935 | 2009-09-01 10:03:01 +0000 | [diff] [blame] | 63 | msr_t msr; |
| 64 | |
| 65 | msr = rdmsr(addr); |
| 66 | |
| 67 | val->hi = msr.lo; |
| 68 | val->lo = msr.hi; |
| 69 | return 1; |
Stefan Reinauer | 84d69f7 | 2009-10-05 10:23:36 +0000 | [diff] [blame] | 70 | #else |
| 71 | return 0; |
| 72 | #endif |
Stefan Reinauer | 37f3935 | 2009-09-01 10:03:01 +0000 | [diff] [blame] | 73 | } |