blob: a95547a169868a3564407e5953590459421da6fa [file] [log] [blame]
Alexandru Gagniuc67f556c2012-08-10 03:55:42 -05001/*
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 Gagniuc67f556c2012-08-10 03:55:42 -050016 */
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__))
Paul Menzela8843de2017-06-05 12:33:23 +020027/* DirectHW is available here: https://www.coreboot.org/DirectHW */
Alexandru Gagniuc67f556c2012-08-10 03:55:42 -050028#define __DARWIN__
29#include <DirectHW/DirectHW.h>
30#endif
Andrey Korolyov0ff8f902016-01-05 20:09:02 +030031#ifdef __NetBSD__
32#include <pciutils/pci.h>
33#else
Alexandru Gagniuc67f556c2012-08-10 03:55:42 -050034#include <pci/pci.h>
Andrey Korolyov0ff8f902016-01-05 20:09:02 +030035#endif
Alexandru Gagniuc67f556c2012-08-10 03:55:42 -050036
37/* This #include is needed for freebsd_{rd,wr}msr. */
38#if defined(__FreeBSD__)
39#include <machine/cpufunc.h>
40#endif
41
Andrey Korolyov0ff8f902016-01-05 20:09:02 +030042#ifdef __NetBSD__
43static 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}
49static 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}
55static 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 Gagniuc67f556c2012-08-10 03:55:42 -050063#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__)
77typedef 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
85typedef struct { uint32_t hi, lo; } msr_t;
86msr_t freebsd_rdmsr(int addr);
87int freebsd_wrmsr(int addr, msr_t msr);
88#endif
89typedef struct { uint16_t addr; int size; char *name; } io_register_t;
90
91void *map_physical(uint64_t phys_addr, size_t len);
92void unmap_physical(void *virt_addr, size_t len);
93
94unsigned int cpuid(unsigned int op);
95int print_intel_core_msrs(void);
96int print_quirks_north(struct pci_dev *nb, struct pci_access *pacc);
97int print_quirks_south(struct pci_dev *sb, struct pci_access *pacc);
98
99#endif /* _VIATOOL_H */