pci.c revision 1.6 1 /* $NetBSD: pci.c,v 1.6 1994/11/04 09:42:22 mycroft Exp $ */
2
3 /*
4 * Copyright (c) 1994 Charles Hannum. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Charles Hannum.
17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 /*
33 * PCI autoconfiguration support
34 */
35
36 #include <sys/types.h>
37 #include <sys/param.h>
38 #include <sys/device.h>
39
40 #include <i386/pci/pcivar.h>
41 #include <i386/pci/pcireg.h>
42
43 int pcimatch __P((struct device *, void *, void *));
44 void pciattach __P((struct device *, struct device *, void *));
45
46 struct cfdriver pcicd = {
47 NULL, "pci", pcimatch, pciattach, DV_DULL, sizeof(struct device)
48 };
49
50 int
51 pciprint(aux, pci)
52 void *aux;
53 char *pci;
54 {
55 register struct pci_attach_args *pa = aux;
56
57 printf(" bus %d device %d", pa->pa_bus, pa->pa_device);
58 return (UNCONF);
59 }
60
61 int
62 pcisubmatch(parent, match, aux)
63 struct device *parent;
64 void *match, *aux;
65 {
66 struct cfdata *cf = match;
67 struct pci_attach_args *pa = aux;
68
69 if (cf->cf_loc[0] != -1 && cf->cf_loc[0] != pa->pa_bus)
70 return 0;
71 if (cf->cf_loc[1] != -1 && cf->cf_loc[1] != pa->pa_device)
72 return 0;
73 return ((*cf->cf_driver->cd_match)(parent, match, aux));
74 }
75
76 void
77 pciattach(parent, self, aux)
78 struct device *parent, *self;
79 void *aux;
80 {
81 int bus, device;
82
83 #ifdef i386
84 printf(": configuration mode %d\n", pci_mode);
85 #else
86 printf("\n");
87 #endif
88
89 #if 0
90 for (bus = 0; bus <= 255; bus++) {
91 #else
92 /*
93 * XXX
94 * Some current chipsets do wacky things with bus numbers > 0.
95 * This seems like a violation of protocol, but the PCI BIOS does
96 * allow one to query the maximum bus number, and eventually we
97 * should do so.
98 */
99 for (bus = 0; bus <= 0; bus++) {
100 #endif
101 #ifdef i386
102 for (device = 0; device <= (pci_mode == 2 ? 15 : 31);
103 device++) {
104 #else
105 for (device = 0; device <= 31; device++) {
106 #endif
107 pcitag_t tag = pci_make_tag(bus, device, 0);
108 pcireg_t id = pci_conf_read(tag, PCI_ID_REG),
109 class = pci_conf_read(tag, PCI_CLASS_REG);
110 struct pci_attach_args pa;
111 struct cfdata *cf;
112
113 if (id == 0 || id == 0xffffffff)
114 continue;
115
116 pa.pa_bus = bus;
117 pa.pa_device = device;
118 pa.pa_tag = tag;
119 pa.pa_id = id;
120 pa.pa_class = class;
121
122 if ((cf = config_search(pcisubmatch, self, &pa)) != NULL)
123 config_attach(self, cf, &pa, pciprint);
124 else
125 printf("%s bus %d device %d: identifier %08x class %08x%s",
126 self->dv_xname, bus, device, id, class,
127 " not configured\n");
128 }
129 }
130 }
131