Carl-Daniel Hailfinger | 5d5c072 | 2009-12-14 03:32:24 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the flashrom project. |
| 3 | * |
| 4 | * Copyright (C) 2009 Carl-Daniel Hailfinger |
| 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 as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 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 |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | * |
| 19 | * |
| 20 | * Header file for hardware access and OS abstraction. Included from flash.h. |
| 21 | */ |
| 22 | |
| 23 | #ifndef __HWACCESS_H__ |
| 24 | #define __HWACCESS_H__ 1 |
| 25 | |
| 26 | #if defined(__GLIBC__) |
| 27 | #include <sys/io.h> |
| 28 | #endif |
| 29 | #if NEED_PCI == 1 |
| 30 | #include <pci/pci.h> |
| 31 | #endif |
| 32 | |
| 33 | /* for iopl and outb under Solaris */ |
| 34 | #if defined (__sun) && (defined(__i386) || defined(__amd64)) |
| 35 | #include <strings.h> |
| 36 | #include <sys/sysi86.h> |
| 37 | #include <sys/psw.h> |
| 38 | #include <asm/sunddi.h> |
| 39 | #endif |
| 40 | |
| 41 | #if (defined(__MACH__) && defined(__APPLE__)) |
| 42 | #define __DARWIN__ |
| 43 | #endif |
| 44 | |
| 45 | #if defined(__FreeBSD__) || defined(__DragonFly__) |
| 46 | #include <machine/cpufunc.h> |
| 47 | #define off64_t off_t |
| 48 | #define lseek64 lseek |
| 49 | #define OUTB(x, y) do { u_int tmp = (y); outb(tmp, (x)); } while (0) |
| 50 | #define OUTW(x, y) do { u_int tmp = (y); outw(tmp, (x)); } while (0) |
| 51 | #define OUTL(x, y) do { u_int tmp = (y); outl(tmp, (x)); } while (0) |
| 52 | #define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); }) |
| 53 | #define INW(x) __extension__ ({ u_int tmp = (x); inw(tmp); }) |
| 54 | #define INL(x) __extension__ ({ u_int tmp = (x); inl(tmp); }) |
| 55 | #else |
| 56 | #if defined(__DARWIN__) |
| 57 | #include <DirectIO/darwinio.h> |
| 58 | #define off64_t off_t |
| 59 | #define lseek64 lseek |
| 60 | #endif |
| 61 | #if defined (__sun) && (defined(__i386) || defined(__amd64)) |
| 62 | /* Note different order for outb */ |
| 63 | #define OUTB(x,y) outb(y, x) |
| 64 | #define OUTW(x,y) outw(y, x) |
| 65 | #define OUTL(x,y) outl(y, x) |
| 66 | #define INB inb |
| 67 | #define INW inw |
| 68 | #define INL inl |
| 69 | #else |
| 70 | #define OUTB outb |
| 71 | #define OUTW outw |
| 72 | #define OUTL outl |
| 73 | #define INB inb |
| 74 | #define INW inw |
| 75 | #define INL inl |
| 76 | #endif |
| 77 | #endif |
| 78 | |
| 79 | #if defined(__FreeBSD__) || defined(__DragonFly__) |
| 80 | extern int io_fd; |
| 81 | #endif |
| 82 | |
| 83 | #if !defined(__DARWIN__) && !defined(__FreeBSD__) && !defined(__DragonFly__) |
| 84 | typedef struct { uint32_t hi, lo; } msr_t; |
| 85 | msr_t rdmsr(int addr); |
| 86 | int wrmsr(int addr, msr_t msr); |
| 87 | #endif |
| 88 | #if defined(__FreeBSD__) || defined(__DragonFly__) |
| 89 | /* FreeBSD already has conflicting definitions for wrmsr/rdmsr. */ |
| 90 | #undef rdmsr |
| 91 | #undef wrmsr |
| 92 | #define rdmsr freebsd_rdmsr |
| 93 | #define wrmsr freebsd_wrmsr |
| 94 | typedef struct { uint32_t hi, lo; } msr_t; |
| 95 | msr_t freebsd_rdmsr(int addr); |
| 96 | int freebsd_wrmsr(int addr, msr_t msr); |
| 97 | #endif |
| 98 | |
| 99 | #endif /* !__HWACCESS_H__ */ |