1 /* $OpenBSD: ppb.c,v 1.11 2002/03/14 01:26:59 millert Exp $ */
2 /* $NetBSD: ppb.c,v 1.16 1997/06/06 23:48:05 thorpej Exp $ */
3
4 /*
5 * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Christopher G. Demetriou
18 * for the NetBSD Project.
19 * 4. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 /*
35 * XXX NOTE:
36 * XXX PROPER OPERATION OF DEVICES BEHIND PPB'S WHICH USE INTERRUPTS
37 * XXX ON SYSTEMS OTHER THAN THE i386 IS NOT POSSIBLE AT THIS TIME.
38 * XXX There needs to be some support for 'swizzling' the interrupt
39 * XXX pin. In general, pci_map_int() has to have a different
40 * XXX interface.
41 */
42
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/kernel.h>
46 #include <sys/device.h>
47
48 #include <dev/pci/pcireg.h>
49 #include <dev/pci/pcivar.h>
50 #include <dev/pci/pcidevs.h>
51 #include <dev/pci/ppbreg.h>
52
53 int ppbmatch(struct device *, void *, void *);
54 void ppbattach(struct device *, struct device *, void *);
55
56 struct cfattach ppb_ca = {
57 sizeof(struct device), ppbmatch, ppbattach
58 };
59
60 struct cfdriver ppb_cd = {
61 NULL, "ppb", DV_DULL
62 };
63
64 int ppbprint(void *, const char *pnp);
65
66 int
ppbmatch(parent,match,aux)67 ppbmatch(parent, match, aux)
68 struct device *parent;
69 void *match, *aux;
70 {
71 struct pci_attach_args *pa = aux;
72
73 /*
74 * This device is mislabeled. It is not a PCI bridge.
75 */
76 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_VIATECH &&
77 PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_VIATECH_VT82C586_PWR)
78 return (0);
79 /*
80 * Check the ID register to see that it's a PCI bridge.
81 * If it is, we assume that we can deal with it; it _should_
82 * work in a standardized way...
83 */
84 if (PCI_CLASS(pa->pa_class) == PCI_CLASS_BRIDGE &&
85 PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_BRIDGE_PCI)
86 return (1);
87
88 return (0);
89 }
90
91 void
ppbattach(parent,self,aux)92 ppbattach(parent, self, aux)
93 struct device *parent, *self;
94 void *aux;
95 {
96 struct pci_attach_args *pa = aux;
97 pci_chipset_tag_t pc = pa->pa_pc;
98 struct pcibus_attach_args pba;
99 pcireg_t busdata;
100
101 printf("\n");
102
103 busdata = pci_conf_read(pc, pa->pa_tag, PPB_REG_BUSINFO);
104
105 if (PPB_BUSINFO_SECONDARY(busdata) == 0) {
106 printf("%s: not configured by system firmware\n",
107 self->dv_xname);
108 return;
109 }
110
111 #if 0
112 /*
113 * XXX can't do this, because we're not given our bus number
114 * (we shouldn't need it), and because we've no way to
115 * decompose our tag.
116 */
117 /* sanity check. */
118 if (pa->pa_bus != PPB_BUSINFO_PRIMARY(busdata))
119 panic("ppbattach: bus in tag (%d) != bus in reg (%d)",
120 pa->pa_bus, PPB_BUSINFO_PRIMARY(busdata));
121 #endif
122
123 /*
124 * Attach the PCI bus than hangs off of it.
125 */
126 pba.pba_busname = "pci";
127 pba.pba_iot = pa->pa_iot;
128 pba.pba_memt = pa->pa_memt;
129 pba.pba_dmat = pa->pa_dmat;
130 pba.pba_pc = pc;
131 pba.pba_bus = PPB_BUSINFO_SECONDARY(busdata);
132 pba.pba_intrswiz = pa->pa_intrswiz;
133 pba.pba_intrtag = pa->pa_intrtag;
134
135 config_found(self, &pba, ppbprint);
136 }
137
138 int
ppbprint(aux,pnp)139 ppbprint(aux, pnp)
140 void *aux;
141 const char *pnp;
142 {
143 struct pcibus_attach_args *pba = aux;
144
145 /* only PCIs can attach to PPBs; easy. */
146 if (pnp)
147 printf("pci at %s", pnp);
148 printf(" bus %d", pba->pba_bus);
149 return (UNCONF);
150 }
151