Alexandru Gagniuc | 67f556c | 2012-08-10 03:55:42 -0500 | [diff] [blame] | 1 | /* |
| 2 | * viatool - dump all registers on an Intel CPU + chipset based system. |
| 3 | * |
| 4 | * Copyright (C) 2008-2010 by coresystems GmbH |
| 5 | * Copyright (C) 2009 Carl-Daniel Hailfinger |
| 6 | * Copyright (C) 2013 Alexandru Gagniuc |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; version 2 of the License. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
Alexandru Gagniuc | 67f556c | 2012-08-10 03:55:42 -0500 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | #include <stdint.h> |
| 19 | |
| 20 | #ifndef _VIATOOL_H |
| 21 | #define _VIATOOL_H |
| 22 | |
| 23 | #if defined(__GLIBC__) |
| 24 | #include <sys/io.h> |
| 25 | #endif |
| 26 | #if (defined(__MACH__) && defined(__APPLE__)) |
| 27 | /* DirectHW is available here: http://www.coreboot.org/DirectHW */ |
| 28 | #define __DARWIN__ |
| 29 | #include <DirectHW/DirectHW.h> |
| 30 | #endif |
Andrey Korolyov | 0ff8f90 | 2016-01-05 20:09:02 +0300 | [diff] [blame] | 31 | #ifdef __NetBSD__ |
| 32 | #include <pciutils/pci.h> |
| 33 | #else |
Alexandru Gagniuc | 67f556c | 2012-08-10 03:55:42 -0500 | [diff] [blame] | 34 | #include <pci/pci.h> |
Andrey Korolyov | 0ff8f90 | 2016-01-05 20:09:02 +0300 | [diff] [blame] | 35 | #endif |
Alexandru Gagniuc | 67f556c | 2012-08-10 03:55:42 -0500 | [diff] [blame] | 36 | |
| 37 | /* This #include is needed for freebsd_{rd,wr}msr. */ |
| 38 | #if defined(__FreeBSD__) |
| 39 | #include <machine/cpufunc.h> |
| 40 | #endif |
| 41 | |
Andrey Korolyov | 0ff8f90 | 2016-01-05 20:09:02 +0300 | [diff] [blame] | 42 | #ifdef __NetBSD__ |
| 43 | static inline uint8_t inb(unsigned port) |
| 44 | { |
| 45 | uint8_t data; |
| 46 | __asm volatile("inb %w1,%0" : "=a" (data) : "d" (port)); |
| 47 | return data; |
| 48 | } |
| 49 | static inline uint16_t inw(unsigned port) |
| 50 | { |
| 51 | uint16_t data; |
| 52 | __asm volatile("inw %w1,%0": "=a" (data) : "d" (port)); |
| 53 | return data; |
| 54 | } |
| 55 | static inline uint32_t inl(unsigned port) |
| 56 | { |
| 57 | uint32_t data; |
| 58 | __asm volatile("inl %w1,%0": "=a" (data) : "d" (port)); |
| 59 | return data; |
| 60 | } |
| 61 | #endif |
| 62 | |
Alexandru Gagniuc | 67f556c | 2012-08-10 03:55:42 -0500 | [diff] [blame] | 63 | #include <stdlib.h> |
| 64 | |
| 65 | #define VIATOOL_VERSION "1.0" |
| 66 | |
| 67 | /* Tested chipsets: */ |
| 68 | #define PCI_VENDOR_ID_VIA 0x1106 |
| 69 | #define PCI_DEVICE_ID_VIA_VX900 0x0410 |
| 70 | #define PCI_DEVICE_ID_VIA_VX900_SATA 0x9001 |
| 71 | #define PCI_DEVICE_ID_VIA_VX900_LPC 0x8410 |
| 72 | |
| 73 | |
| 74 | #define ARRAY_SIZE(a) ((int)(sizeof(a) / sizeof((a)[0]))) |
| 75 | |
| 76 | #if !defined(__DARWIN__) && !defined(__FreeBSD__) |
| 77 | typedef struct { uint32_t hi, lo; } msr_t; |
| 78 | #endif |
| 79 | #if defined (__FreeBSD__) |
| 80 | /* FreeBSD already has conflicting definitions for wrmsr/rdmsr. */ |
| 81 | #undef rdmsr |
| 82 | #undef wrmsr |
| 83 | #define rdmsr freebsd_rdmsr |
| 84 | #define wrmsr freebsd_wrmsr |
| 85 | typedef struct { uint32_t hi, lo; } msr_t; |
| 86 | msr_t freebsd_rdmsr(int addr); |
| 87 | int freebsd_wrmsr(int addr, msr_t msr); |
| 88 | #endif |
| 89 | typedef struct { uint16_t addr; int size; char *name; } io_register_t; |
| 90 | |
| 91 | void *map_physical(uint64_t phys_addr, size_t len); |
| 92 | void unmap_physical(void *virt_addr, size_t len); |
| 93 | |
| 94 | unsigned int cpuid(unsigned int op); |
| 95 | int print_intel_core_msrs(void); |
| 96 | int print_quirks_north(struct pci_dev *nb, struct pci_access *pacc); |
| 97 | int print_quirks_south(struct pci_dev *sb, struct pci_access *pacc); |
| 98 | |
| 99 | #endif /* _VIATOOL_H */ |