2 * Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
31 * PnP enumerator using the PCI BIOS.
35 #include <machine/stdarg.h>
36 #include <bootstrap.h>
42 * Stupid PCI BIOS interface doesn't let you simply enumerate everything
43 * that's there, instead you have to ask it if it has something.
45 * So we have to scan by class code, subclass code and sometimes programming
55 static struct pci_progif progif_null[] = {
60 static struct pci_progif progif_display[] = {
66 static struct pci_progif progif_ide[] = {
102 static struct pci_progif progif_serial[] = {
109 static struct pci_progif progif_parallel[] = {
111 {0x1, "Bidirectional"},
116 static struct pci_progif progif_firewire[] = {
125 struct pci_progif *ps_progif; /* if set, use for programming interface value(s) */
128 static struct pci_subclass subclass_old[] = {
129 {0x0, "Old non-VGA", progif_null},
130 {0x1, "Old VGA", progif_null},
134 static struct pci_subclass subclass_mass[] = {
135 {0x0, "SCSI", progif_null},
136 {0x1, "IDE", progif_ide},
137 {0x2, "Floppy disk", progif_null},
138 {0x3, "IPI", progif_null},
139 {0x4, "RAID", progif_null},
140 {0x80, "mass storage", progif_null},
144 static struct pci_subclass subclass_net[] = {
145 {0x0, "Ethernet", progif_null},
146 {0x1, "Token ring", progif_null},
147 {0x2, "FDDI", progif_null},
148 {0x3, "ATM", progif_null},
149 {0x80, "network", progif_null},
153 static struct pci_subclass subclass_display[] = {
154 {0x0, NULL, progif_display},
155 {0x1, "XGA", progif_null},
156 {0x80, "other", progif_null},
160 static struct pci_subclass subclass_comms[] = {
161 {0x0, "serial", progif_serial},
162 {0x1, "parallel", progif_parallel},
163 {0x80, "communications", progif_null},
167 static struct pci_subclass subclass_serial[] = {
168 {0x0, "FireWire", progif_firewire},
169 {0x1, "ACCESS.bus", progif_null},
170 {0x2, "SSA", progif_null},
171 {0x3, "USB", progif_null},
172 {0x4, "Fibrechannel", progif_null},
176 static struct pci_class
180 struct pci_subclass *pc_subclass;
182 {0x0, "device", subclass_old},
183 {0x1, "controller", subclass_mass},
184 {0x2, "controller", subclass_net},
185 {0x3, "display", subclass_display},
186 {0x7, "controller", subclass_comms},
187 {0xc, "controller", subclass_serial},
192 static void biospci_enumerate(void);
193 static void biospci_addinfo(int devid, struct pci_class *pc, struct pci_subclass *psc, struct pci_progif *ppi);
195 static int biospci_version;
196 static int biospci_hwcap;
198 struct pnphandler biospcihandler =
205 biospci_enumerate(void)
207 int device_index, err;
208 uint32_t locator, devid;
209 struct pci_class *pc;
210 struct pci_subclass *psc;
211 struct pci_progif *ppi;
213 /* Find the PCI BIOS */
220 /* Check for OK response */
221 if ((v86.efl & 1) || ((v86.eax & 0xff00) != 0) || (v86.edx != 0x20494350))
224 biospci_version = v86.ebx & 0xffff;
225 biospci_hwcap = v86.eax & 0xff;
227 printf("PCI BIOS %d.%d%s%s\n",
228 bcd2bin((biospci_version >> 8) & 0xf), bcd2bin(biospci_version & 0xf),
229 (biospci_hwcap & 1) ? " config1" : "", (biospci_hwcap & 2) ? " config2" : "");
231 /* Iterate over known classes */
232 for (pc = pci_classes; pc->pc_class >= 0; pc++) {
233 /* Iterate over subclasses */
234 for (psc = pc->pc_subclass; psc->ps_subclass >= 0; psc++) {
235 /* Iterate over programming interfaces */
236 for (ppi = psc->ps_progif; ppi->pi_code >= 0; ppi++) {
238 /* Scan for matches */
239 for (device_index = 0; ; device_index++) {
240 /* Look for a match */
241 err = biospci_find_devclass((pc->pc_class << 16)
242 + (psc->ps_subclass << 8) + ppi->pi_code,
243 device_index, &locator);
247 /* Read the device identifier from the nominated device */
248 err = biospci_read_config(locator, 0, 2, &devid);
252 /* We have the device ID, create a PnP object and save everything */
253 biospci_addinfo(devid, pc, psc, ppi);
261 biospci_addinfo(int devid, struct pci_class *pc, struct pci_subclass *psc, struct pci_progif *ppi)
267 /* build the description */
269 if (ppi->pi_name != NULL) {
270 strcat(desc, ppi->pi_name);
273 if (psc->ps_name != NULL) {
274 strcat(desc, psc->ps_name);
277 if (pc->pc_name != NULL)
278 strcat(desc, pc->pc_name);
280 pi = pnp_allocinfo();
281 pi->pi_desc = strdup(desc);
282 sprintf(desc,"0x%08x", devid);
283 pnp_addident(pi, desc);
288 biospci_find_devclass(uint32_t class, int index, uint32_t *locator)
298 if ((v86.efl & 1) || (v86.eax & 0xff00))
305 * Configuration space access methods.
306 * width = 0(byte), 1(word) or 2(dword).
309 biospci_write_config(uint32_t locator, int offset, int width, uint32_t val)
313 v86.eax = 0xb10b + width;
320 if ((v86.efl & 1) || (v86.eax & 0xff00))
327 biospci_read_config(uint32_t locator, int offset, int width, uint32_t *val)
331 v86.eax = 0xb108 + width;
337 if ((v86.efl & 1) || (v86.eax & 0xff00))