obio.c revision 1.3 1 /* $NetBSD: obio.c,v 1.3 1998/07/13 19:37:28 tsubai Exp $ */
2
3 /*-
4 * Copyright (C) 1998 Internet Research Institute, Inc.
5 * 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
18 * Internet Research Institute, Inc.
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
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #include <sys/types.h>
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/kernel.h>
38 #include <sys/device.h>
39
40 #include <dev/pci/pcivar.h>
41 #include <dev/pci/pcidevs.h>
42
43 #include <dev/ofw/openfirm.h>
44
45 #include <machine/autoconf.h>
46
47 static void obio_attach __P((struct device *, struct device *, void *));
48 static int obio_match __P((struct device *, struct cfdata *, void *));
49 static int obio_print __P((void *, const char *));
50
51 struct obio_softc {
52 struct device sc_dev;
53 int sc_node;
54 };
55
56
57 struct cfattach obio_ca = {
58 sizeof(struct obio_softc), obio_match, obio_attach
59 };
60
61 int
62 obio_match(parent, cf, aux)
63 struct device *parent;
64 struct cfdata *cf;
65 void *aux;
66 {
67 struct pci_attach_args *pa = aux;
68
69 if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_APPLE)
70 switch (PCI_PRODUCT(pa->pa_id)) {
71
72 case 0x02: /* gc */
73 case 0x07: /* ohare */
74 case 0x10: /* mac-io */
75 return 1;
76 }
77
78 return 0;
79 }
80
81 /*
82 * Attach all the sub-devices we can find
83 */
84 void
85 obio_attach(parent, self, aux)
86 struct device *parent, *self;
87 void *aux;
88 {
89 struct obio_softc *sc = (struct obio_softc *)self;
90 struct pci_attach_args *pa = aux;
91 struct confargs ca;
92 int node, child, namelen;
93 u_int reg[20];
94 int intr[5];
95 char name[32];
96
97 switch (PCI_PRODUCT(pa->pa_id)) {
98
99 case 0x02:
100 node = OF_finddevice("/bandit/gc");
101 break;
102
103 case 0x07:
104 node = OF_finddevice("/bandit/ohare");
105 break;
106
107 case 0x10:
108 node = OF_finddevice("/pci/mac-io");
109 break;
110
111 default:
112 printf("obio_attach: unknown obio controller\n");
113 return;
114 }
115
116 sc->sc_node = node;
117
118 if (OF_getprop(node, "assigned-addresses", reg, sizeof(reg)) < 12)
119 return;
120 ca.ca_baseaddr = reg[2];
121
122 printf(": addr 0x%x\n", ca.ca_baseaddr);
123
124 for (child = OF_child(node); child; child = OF_peer(child)) {
125 namelen = OF_getprop(child, "name", name, sizeof(name));
126 if (namelen < 0)
127 continue;
128 if (namelen >= sizeof(name))
129 continue;
130
131 name[namelen] = 0;
132 ca.ca_name = name;
133 ca.ca_node = child;
134
135 ca.ca_nreg = OF_getprop(child, "reg", reg, sizeof(reg));
136 ca.ca_nintr = OF_getprop(child, "AAPL,interrupts", intr,
137 sizeof(intr));
138 ca.ca_reg = reg;
139 ca.ca_intr = intr;
140
141 config_found(self, &ca, obio_print);
142 }
143 }
144
145 int
146 obio_print(aux, obio)
147 void *aux;
148 const char *obio;
149 {
150 struct confargs *ca = aux;
151
152 if (obio)
153 printf("%s at %s", ca->ca_name, obio);
154
155 if (ca->ca_nreg > 0)
156 printf(" offset 0x%x", ca->ca_reg[0]);
157
158 return UNCONF;
159 }
160