correctly mark code segments as code in SELF
[coreboot.git] / util / superiotool / via.c
1 /*
2  * This file is part of the superiotool 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; either version 2 of the License, or
9  * (at your option) any later version.
10  *
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.
15  *
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
19  */
20
21 #include "superiotool.h"
22
23 #define DEVICE_ID_VT82C686_REG  0xe0
24 #define DEVICE_REV_VT82C686_REG 0xe1
25
26 static const struct superio_registers reg_table[] = {
27         {0x3c, "VT82C686A/VT82C686B", {
28                 {EOT}}},
29         {EOT}
30 };
31
32 static uint8_t vt82c686_conf = 0;
33
34 static int enter_conf_mode_via_vt82c686(void)
35 {
36         struct pci_dev *dev;
37
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;
43         }
44
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");
50
51         /* If the Super I/O is not enabled, skip it. */
52         if (!(vt82c686_conf & (1 << 0)))
53                 return 1;
54
55         /* Enable Super I/O configuration mode. */
56         pci_write_byte(dev, 0x85, vt82c686_conf | (1 << 1));
57
58         return 0;
59 }
60
61 static void exit_conf_mode_via_vt82c686(void)
62 {
63         struct pci_dev *dev;
64
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;
70         }
71
72         /* Restore (disable?) Super I/O configuration mode setting. */
73         pci_write_byte(dev, 0x85, vt82c686_conf);
74 }
75
76 void probe_idregs_via(uint16_t port)
77 {
78         uint16_t id;
79         uint8_t rev;
80
81         probing_for("VIA", "", port);
82
83         if (enter_conf_mode_via_vt82c686())
84                 return;
85
86         id = regval(port, DEVICE_ID_VT82C686_REG);
87         rev = regval(port, DEVICE_REV_VT82C686_REG);
88
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;
94         }
95
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;
99
100         exit_conf_mode_via_vt82c686();
101 }
102
103 void print_via_chips(void)
104 {
105         print_vendor_chips("VIA", reg_table);
106 }