pci.c revision 1.5 1 /* $NetBSD: pci.c,v 1.5 1994/11/03 22:27:16 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("%s bus %d device %d", pci ? pci : "", pa->pa_bus,
58 pa->pa_device);
59 if (pci)
60 printf(": identifier %08x class %08x", pa->pa_id,
61 pa->pa_class);
62 return UNCONF;
63 }
64
65 void
66 pciattach(parent, self, aux)
67 struct device *parent, *self;
68 void *aux;
69 {
70 int bus, device;
71
72 #ifdef i386
73 printf(": configuration mode %d\n", pci_mode);
74 #else
75 printf("\n");
76 #endif
77
78 #if 0
79 for (bus = 0; bus <= 255; bus++) {
80 #else
81 /*
82 * XXX
83 * Some current chipsets do wacky things with bus numbers > 0.
84 * This seems like a violation of protocol, but the PCI BIOS does
85 * allow one to query the maximum bus number, and eventually we
86 * should do so.
87 */
88 for (bus = 0; bus <= 0; bus++) {
89 #endif
90 #ifdef i386
91 for (device = 0; device <= (pci_mode == 2 ? 15 : 31);
92 device++) {
93 #else
94 for (device = 0; device <= 31; device++) {
95 #endif
96 pcitag_t tag = pci_make_tag(bus, device, 0);
97 pcireg_t id = pci_conf_read(tag, PCI_ID_REG),
98 class = pci_conf_read(tag, PCI_CLASS_REG);
99 struct pci_attach_args pa;
100
101 if (id == 0 || id == 0xffffffff)
102 continue;
103
104 pa.pa_bus = bus;
105 pa.pa_device = device;
106 pa.pa_tag = tag;
107 pa.pa_id = id;
108 pa.pa_class = class;
109
110 (void)config_found(self, (void *)&pa, pciprint);
111 }
112 }
113 }
114
115 int
116 pci_targmatch(cf, pa)
117 struct cfdata *cf;
118 struct pci_attach_args *pa;
119 {
120
121 if (cf->cf_loc[0] != -1 && cf->cf_loc[0] != pa->pa_bus)
122 return 0;
123 if (cf->cf_loc[1] != -1 && cf->cf_loc[1] != pa->pa_device)
124 return 0;
125 return 1;
126 }
127