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