TPM: Reduce buffer size to fix stack overflow
[coreboot.git] / util / superiotool / via.c
bloba08231683fd78e26bb2f32e3dbbbcd76900f6285
1 /*
2 * This file is part of the superiotool project.
4 * Copyright (C) 2009 Carl-Daniel Hailfinger
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; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "superiotool.h"
23 #define DEVICE_ID_VT82C686_REG 0xe0
24 #define DEVICE_REV_VT82C686_REG 0xe1
26 static const struct superio_registers reg_table[] = {
27 {0x3c, "VT82C686A/VT82C686B", {
28 {EOT}}},
29 {EOT}
32 static uint8_t vt82c686_conf = 0;
34 static int enter_conf_mode_via_vt82c686(void)
36 struct pci_dev *dev;
38 dev = pci_dev_find(0x1106, 0x0686);
39 if (!dev) {
40 if (verbose)
41 printf(" PCI device 1106:0686 not found.\n");
42 return 1;
45 vt82c686_conf = pci_read_byte(dev, 0x85);
46 if (verbose)
47 printf(" Super I/O %sabled, Super I/O configuration %sabled\n",
48 (vt82c686_conf & (1 << 0)) ? "en" : "dis",
49 (vt82c686_conf & (1 << 1)) ? "en" : "dis");
51 /* If the Super I/O is not enabled, skip it. */
52 if (!(vt82c686_conf & (1 << 0)))
53 return 1;
55 /* Enable Super I/O configuration mode. */
56 pci_write_byte(dev, 0x85, vt82c686_conf | (1 << 1));
58 return 0;
61 static void exit_conf_mode_via_vt82c686(void)
63 struct pci_dev *dev;
65 dev = pci_dev_find(0x1106, 0x0686);
66 if (!dev) {
67 printf("Bug: PCI device 1106:0686 not found during shutdown.\n"
68 "Please report to coreboot@coreboot.org.\n");
69 return;
72 /* Restore (disable?) Super I/O configuration mode setting. */
73 pci_write_byte(dev, 0x85, vt82c686_conf);
76 void probe_idregs_via(uint16_t port)
78 uint16_t id;
79 uint8_t rev;
81 probing_for("VIA", "", port);
83 if (enter_conf_mode_via_vt82c686())
84 return;
86 id = regval(port, DEVICE_ID_VT82C686_REG);
87 rev = regval(port, DEVICE_REV_VT82C686_REG);
89 if (superio_unknown(reg_table, id)) {
90 if (verbose)
91 printf(NOTFOUND "id=0x%04x, rev=0x%02x\n", id, rev);
92 exit_conf_mode_via_vt82c686();
93 return;
96 printf("Found VIA %s (id=0x%04x, rev=0x%02x) at 0x%x\n",
97 get_superio_name(reg_table, id), id, rev, port);
98 chip_found = 1;
100 exit_conf_mode_via_vt82c686();
103 void print_via_chips(void)
105 print_vendor_chips("VIA", reg_table);