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