pnpbus.c revision 1.1.2.2 1 1.1.2.2 yamt /* $NetBSD: pnpbus.c,v 1.1.2.2 2006/03/13 09:06:59 yamt Exp $ */
2 1.1.2.2 yamt
3 1.1.2.2 yamt /*-
4 1.1.2.2 yamt * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.1.2.2 yamt * All rights reserved.
6 1.1.2.2 yamt *
7 1.1.2.2 yamt * This code is derived from software contributed to The NetBSD Foundation
8 1.1.2.2 yamt * by Tim Rightnour
9 1.1.2.2 yamt *
10 1.1.2.2 yamt * Redistribution and use in source and binary forms, with or without
11 1.1.2.2 yamt * modification, are permitted provided that the following conditions
12 1.1.2.2 yamt * are met:
13 1.1.2.2 yamt * 1. Redistributions of source code must retain the above copyright
14 1.1.2.2 yamt * notice, this list of conditions and the following disclaimer.
15 1.1.2.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.2.2 yamt * notice, this list of conditions and the following disclaimer in the
17 1.1.2.2 yamt * documentation and/or other materials provided with the distribution.
18 1.1.2.2 yamt * 3. All advertising materials mentioning features or use of this software
19 1.1.2.2 yamt * must display the following acknowledgement:
20 1.1.2.2 yamt * This product includes software developed by the NetBSD
21 1.1.2.2 yamt * Foundation, Inc. and its contributors.
22 1.1.2.2 yamt * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1.2.2 yamt * contributors may be used to endorse or promote products derived
24 1.1.2.2 yamt * from this software without specific prior written permission.
25 1.1.2.2 yamt *
26 1.1.2.2 yamt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1.2.2 yamt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1.2.2 yamt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1.2.2 yamt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1.2.2 yamt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1.2.2 yamt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1.2.2 yamt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1.2.2 yamt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1.2.2 yamt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1.2.2 yamt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1.2.2 yamt * POSSIBILITY OF SUCH DAMAGE.
37 1.1.2.2 yamt */
38 1.1.2.2 yamt
39 1.1.2.2 yamt #include <sys/cdefs.h>
40 1.1.2.2 yamt __KERNEL_RCSID(0, "$NetBSD: pnpbus.c,v 1.1.2.2 2006/03/13 09:06:59 yamt Exp $");
41 1.1.2.2 yamt
42 1.1.2.2 yamt #include <sys/param.h>
43 1.1.2.2 yamt #include <sys/systm.h>
44 1.1.2.2 yamt #include <sys/device.h>
45 1.1.2.2 yamt #include <sys/extent.h>
46 1.1.2.2 yamt #include <sys/malloc.h>
47 1.1.2.2 yamt
48 1.1.2.2 yamt #include <machine/bus.h>
49 1.1.2.2 yamt #include <machine/pio.h>
50 1.1.2.2 yamt #include <machine/intr.h>
51 1.1.2.2 yamt #include <machine/platform.h>
52 1.1.2.2 yamt #include <machine/residual.h>
53 1.1.2.2 yamt #include <machine/pnp.h>
54 1.1.2.2 yamt #include <machine/isa_machdep.h>
55 1.1.2.2 yamt
56 1.1.2.2 yamt #include <dev/isa/isareg.h>
57 1.1.2.2 yamt
58 1.1.2.2 yamt #include <prep/pnpbus/pnpbusvar.h>
59 1.1.2.2 yamt
60 1.1.2.2 yamt static int pnpbus_match(struct device *, struct cfdata *, void *);
61 1.1.2.2 yamt static void pnpbus_attach(struct device *, struct device *, void *);
62 1.1.2.2 yamt static int pnpbus_print(void *, const char *);
63 1.1.2.2 yamt static int pnpbus_search(struct device *, struct cfdata *,
64 1.1.2.2 yamt const int *, void *);
65 1.1.2.2 yamt
66 1.1.2.2 yamt CFATTACH_DECL(pnpbus, sizeof(struct pnpbus_softc),
67 1.1.2.2 yamt pnpbus_match, pnpbus_attach, NULL, NULL);
68 1.1.2.2 yamt
69 1.1.2.2 yamt struct pnpbus_softc *pnpbus_softc;
70 1.1.2.2 yamt extern struct cfdriver pnpbus_cd;
71 1.1.2.2 yamt
72 1.1.2.2 yamt static int
73 1.1.2.2 yamt pnpbus_match(struct device *parent, struct cfdata *cf, void *aux)
74 1.1.2.2 yamt {
75 1.1.2.2 yamt return 1;
76 1.1.2.2 yamt }
77 1.1.2.2 yamt
78 1.1.2.2 yamt static void
79 1.1.2.2 yamt pnpbus_attach(struct device *parent, struct device *self, void *aux)
80 1.1.2.2 yamt {
81 1.1.2.2 yamt struct pnpbus_softc *sc = (struct pnpbus_softc *)self;
82 1.1.2.2 yamt struct pnpbus_attach_args *paa = aux;
83 1.1.2.2 yamt
84 1.1.2.2 yamt printf("\n");
85 1.1.2.2 yamt
86 1.1.2.2 yamt pnpbus_softc = sc;
87 1.1.2.2 yamt sc->sc_ic = paa->paa_ic;
88 1.1.2.2 yamt sc->sc_iot = paa->paa_iot;
89 1.1.2.2 yamt sc->sc_memt = paa->paa_memt;
90 1.1.2.2 yamt
91 1.1.2.2 yamt (void)config_search_ia(pnpbus_search, self, "pnpbus", aux);
92 1.1.2.2 yamt }
93 1.1.2.2 yamt
94 1.1.2.2 yamt static int
95 1.1.2.2 yamt pnp_newirq(void *v, struct pnpresources *r, int size)
96 1.1.2.2 yamt {
97 1.1.2.2 yamt struct _S4_Pack *p = v;
98 1.1.2.2 yamt struct pnpbus_irq *irq;
99 1.1.2.2 yamt
100 1.1.2.2 yamt irq = malloc(sizeof(struct pnpbus_irq), M_DEVBUF, M_NOWAIT);
101 1.1.2.2 yamt
102 1.1.2.2 yamt irq->mask = le16dec(&p->IRQMask[0]);
103 1.1.2.2 yamt if (size > 2)
104 1.1.2.2 yamt irq->flags = p->IRQInfo;
105 1.1.2.2 yamt else
106 1.1.2.2 yamt irq->flags = 0x01;
107 1.1.2.2 yamt
108 1.1.2.2 yamt SIMPLEQ_INSERT_TAIL(&r->irq, irq, next);
109 1.1.2.2 yamt r->numirq++;
110 1.1.2.2 yamt
111 1.1.2.2 yamt return 0;
112 1.1.2.2 yamt }
113 1.1.2.2 yamt
114 1.1.2.2 yamt static int
115 1.1.2.2 yamt pnp_newdma(void *v, struct pnpresources *r, int size)
116 1.1.2.2 yamt {
117 1.1.2.2 yamt struct _S5_Pack *p = v;
118 1.1.2.2 yamt struct pnpbus_dma *dma;
119 1.1.2.2 yamt
120 1.1.2.2 yamt dma = malloc(sizeof(struct pnpbus_dma), M_DEVBUF, M_NOWAIT);
121 1.1.2.2 yamt
122 1.1.2.2 yamt dma->mask = le16dec(&p->DMAMask);
123 1.1.2.2 yamt if (size > 2)
124 1.1.2.2 yamt dma->flags = p->DMAInfo;
125 1.1.2.2 yamt else
126 1.1.2.2 yamt dma->flags = 0x01;
127 1.1.2.2 yamt
128 1.1.2.2 yamt SIMPLEQ_INSERT_TAIL(&r->dma, dma, next);
129 1.1.2.2 yamt r->numdma++;
130 1.1.2.2 yamt
131 1.1.2.2 yamt return 0;
132 1.1.2.2 yamt }
133 1.1.2.2 yamt
134 1.1.2.2 yamt static int
135 1.1.2.2 yamt pnp_newioport(void *v, struct pnpresources *r, int size)
136 1.1.2.2 yamt {
137 1.1.2.2 yamt struct _S8_Pack *p = v;
138 1.1.2.2 yamt struct pnpbus_io *io;
139 1.1.2.2 yamt uint16_t mask;
140 1.1.2.2 yamt
141 1.1.2.2 yamt io = malloc(sizeof(struct pnpbus_io), M_DEVBUF, M_NOWAIT);
142 1.1.2.2 yamt mask = p->IOInfo & ISAAddr16bit ? 0xffff : 0x03ff;
143 1.1.2.2 yamt io->minbase = (p->RangeMin[0] | (p->RangeMin[1] << 8)) & mask;
144 1.1.2.2 yamt io->maxbase = (p->RangeMax[0] | (p->RangeMax[1] << 8)) & mask;
145 1.1.2.2 yamt io->align = p->IOAlign;
146 1.1.2.2 yamt io->len = p->IONum;
147 1.1.2.2 yamt io->flags = p->IOInfo;
148 1.1.2.2 yamt
149 1.1.2.2 yamt SIMPLEQ_INSERT_TAIL(&r->io, io, next);
150 1.1.2.2 yamt r->numio++;
151 1.1.2.2 yamt
152 1.1.2.2 yamt return 0;
153 1.1.2.2 yamt }
154 1.1.2.2 yamt
155 1.1.2.2 yamt static int
156 1.1.2.2 yamt pnp_newaddr(void *v, struct pnpresources *r, int size)
157 1.1.2.2 yamt {
158 1.1.2.2 yamt struct pnpbus_io *io;
159 1.1.2.2 yamt struct pnpbus_mem *mem;
160 1.1.2.2 yamt struct _L4_Pack *pack = v;
161 1.1.2.2 yamt struct _L4_PPCPack *p = &pack->L4_Data.L4_PPCPack;
162 1.1.2.2 yamt
163 1.1.2.2 yamt if (p->PPCData[0] == 1) {/* type IO */
164 1.1.2.2 yamt io = malloc(sizeof(struct pnpbus_io), M_DEVBUF, M_NOWAIT);
165 1.1.2.2 yamt io->minbase = (uint16_t)le64dec(&p->PPCData[4]);
166 1.1.2.2 yamt io->maxbase = -1;
167 1.1.2.2 yamt io->align = p->PPCData[1];
168 1.1.2.2 yamt io->len = (uint16_t)le64dec(&p->PPCData[12]);
169 1.1.2.2 yamt io->flags = 0;
170 1.1.2.2 yamt SIMPLEQ_INSERT_TAIL(&r->io, io, next);
171 1.1.2.2 yamt r->numio++;
172 1.1.2.2 yamt
173 1.1.2.2 yamt return 0;
174 1.1.2.2 yamt } else if (p->PPCData[0] == 2) {
175 1.1.2.2 yamt mem = malloc(sizeof(struct pnpbus_mem), M_DEVBUF, M_NOWAIT);
176 1.1.2.2 yamt mem->minbase = (uint32_t)le64dec(&p->PPCData[4]);
177 1.1.2.2 yamt mem->maxbase = -1;
178 1.1.2.2 yamt mem->align = p->PPCData[1];
179 1.1.2.2 yamt mem->len = (uint32_t)le64dec(&p->PPCData[12]);
180 1.1.2.2 yamt mem->flags = 0;
181 1.1.2.2 yamt SIMPLEQ_INSERT_TAIL(&r->mem, mem, next);
182 1.1.2.2 yamt r->nummem++;
183 1.1.2.2 yamt
184 1.1.2.2 yamt return 0;
185 1.1.2.2 yamt } else
186 1.1.2.2 yamt return -1;
187 1.1.2.2 yamt }
188 1.1.2.2 yamt
189 1.1.2.2 yamt static int
190 1.1.2.2 yamt pnp_newcompatid(void *v, struct pnpresources *r, int size)
191 1.1.2.2 yamt {
192 1.1.2.2 yamt struct _S3_Pack *p = v;
193 1.1.2.2 yamt struct pnpbus_compatid *id;
194 1.1.2.2 yamt uint32_t cid;
195 1.1.2.2 yamt
196 1.1.2.2 yamt id = malloc(sizeof(*id), M_DEVBUF, M_NOWAIT);
197 1.1.2.2 yamt cid = le32dec(p->CompatId);
198 1.1.2.2 yamt pnp_devid_to_string(cid, id->idstr);
199 1.1.2.2 yamt id->next = r->compatids;
200 1.1.2.2 yamt r->compatids = id;
201 1.1.2.2 yamt
202 1.1.2.2 yamt return 0;
203 1.1.2.2 yamt }
204 1.1.2.2 yamt
205 1.1.2.2 yamt /*
206 1.1.2.2 yamt * Call if match succeeds. This way we don't allocate lots of ram
207 1.1.2.2 yamt * for structures we never use if the device isn't attached.
208 1.1.2.2 yamt */
209 1.1.2.2 yamt
210 1.1.2.2 yamt int
211 1.1.2.2 yamt pnpbus_scan(struct pnpbus_dev_attach_args *pna, PPC_DEVICE *dev)
212 1.1.2.2 yamt {
213 1.1.2.2 yamt struct pnpresources *r = &pna->pna_res;
214 1.1.2.2 yamt uint32_t l;
215 1.1.2.2 yamt uint8_t *p, *q;
216 1.1.2.2 yamt void *v;
217 1.1.2.2 yamt int tag, size, item;
218 1.1.2.2 yamt
219 1.1.2.2 yamt l = be32toh(dev->AllocatedOffset);
220 1.1.2.2 yamt p = res->DevicePnPHeap + l;
221 1.1.2.2 yamt
222 1.1.2.2 yamt if (p == NULL)
223 1.1.2.2 yamt return -1;
224 1.1.2.2 yamt
225 1.1.2.2 yamt for (; p[0] != END_TAG; p += size) {
226 1.1.2.2 yamt tag = *p;
227 1.1.2.2 yamt v = p;
228 1.1.2.2 yamt if (tag_type(p[0]) == PNP_SMALL) {
229 1.1.2.2 yamt size = tag_small_count(tag) + 1;
230 1.1.2.2 yamt item = tag_small_item_name(tag);
231 1.1.2.2 yamt switch (item) {
232 1.1.2.2 yamt case IRQFormat:
233 1.1.2.2 yamt pnp_newirq(v, r, size);
234 1.1.2.2 yamt break;
235 1.1.2.2 yamt case DMAFormat:
236 1.1.2.2 yamt pnp_newdma(v, r, size);
237 1.1.2.2 yamt break;
238 1.1.2.2 yamt case IOPort:
239 1.1.2.2 yamt pnp_newioport(v, r, size);
240 1.1.2.2 yamt break;
241 1.1.2.2 yamt }
242 1.1.2.2 yamt } else {
243 1.1.2.2 yamt struct _L4_Pack *pack = v;
244 1.1.2.2 yamt struct _L4_PPCPack *pa = &pack->L4_Data.L4_PPCPack;
245 1.1.2.2 yamt
246 1.1.2.2 yamt q = p;
247 1.1.2.2 yamt size = (q[1] | (q[2] << 8)) + 3 /* tag + length */;
248 1.1.2.2 yamt item = tag_large_item_name(tag);
249 1.1.2.2 yamt printf("large vi item %d, %d\n", item, pa->Type);
250 1.1.2.2 yamt if (item == LargeVendorItem &&
251 1.1.2.2 yamt pa->Type == LV_GenericAddress)
252 1.1.2.2 yamt pnp_newaddr(v, r, size);
253 1.1.2.2 yamt }
254 1.1.2.2 yamt }
255 1.1.2.2 yamt
256 1.1.2.2 yamt /* scan for compatid's */
257 1.1.2.2 yamt
258 1.1.2.2 yamt l = be32toh(dev->CompatibleOffset);
259 1.1.2.2 yamt p = res->DevicePnPHeap + l;
260 1.1.2.2 yamt
261 1.1.2.2 yamt if (p == NULL)
262 1.1.2.2 yamt return -1;
263 1.1.2.2 yamt
264 1.1.2.2 yamt for (; p[0] != END_TAG; p += size) {
265 1.1.2.2 yamt tag = *p;
266 1.1.2.2 yamt v = p;
267 1.1.2.2 yamt if (tag_type(p[0]) == PNP_SMALL) {
268 1.1.2.2 yamt size = tag_small_count(tag) + 1;
269 1.1.2.2 yamt item = tag_small_item_name(tag);
270 1.1.2.2 yamt switch (item) {
271 1.1.2.2 yamt case CompatibleDevice:
272 1.1.2.2 yamt pnp_newcompatid(v, r, size);
273 1.1.2.2 yamt break;
274 1.1.2.2 yamt }
275 1.1.2.2 yamt } else {
276 1.1.2.2 yamt q = p;
277 1.1.2.2 yamt size = (q[1] | (q[2] << 8)) + 3 /* tag + length */;
278 1.1.2.2 yamt }
279 1.1.2.2 yamt }
280 1.1.2.2 yamt return 0;
281 1.1.2.2 yamt }
282 1.1.2.2 yamt
283 1.1.2.2 yamt /*
284 1.1.2.2 yamt * Setup the basic pna structure.
285 1.1.2.2 yamt */
286 1.1.2.2 yamt
287 1.1.2.2 yamt static void
288 1.1.2.2 yamt pnp_getpna(struct pnpbus_dev_attach_args *pna, struct pnpbus_attach_args *paa,
289 1.1.2.2 yamt PPC_DEVICE *dev)
290 1.1.2.2 yamt {
291 1.1.2.2 yamt uint32_t l;
292 1.1.2.2 yamt DEVICE_ID *id = &dev->DeviceId;
293 1.1.2.2 yamt struct pnpresources *r = &pna->pna_res;
294 1.1.2.2 yamt
295 1.1.2.2 yamt l = be32toh(dev->AllocatedOffset);
296 1.1.2.2 yamt
297 1.1.2.2 yamt pna->pna_iot = paa->paa_iot;
298 1.1.2.2 yamt pna->pna_memt = paa->paa_memt;
299 1.1.2.2 yamt pna->pna_ic = paa->paa_ic;
300 1.1.2.2 yamt pnp_devid_to_string(id->DevId, pna->pna_devid);
301 1.1.2.2 yamt pna->pna_ppc_dev = dev;
302 1.1.2.2 yamt memset(r, 0, sizeof(*r));
303 1.1.2.2 yamt SIMPLEQ_INIT(&r->mem);
304 1.1.2.2 yamt SIMPLEQ_INIT(&r->io);
305 1.1.2.2 yamt SIMPLEQ_INIT(&r->irq);
306 1.1.2.2 yamt SIMPLEQ_INIT(&r->dma);
307 1.1.2.2 yamt }
308 1.1.2.2 yamt
309 1.1.2.2 yamt static int
310 1.1.2.2 yamt pnpbus_search(struct device *parent, struct cfdata *cf,
311 1.1.2.2 yamt const int *ldesc, void *aux)
312 1.1.2.2 yamt {
313 1.1.2.2 yamt struct pnpbus_dev_attach_args pna;
314 1.1.2.2 yamt struct pnpbus_attach_args *paa = aux;
315 1.1.2.2 yamt PPC_DEVICE *ppc_dev;
316 1.1.2.2 yamt int i;
317 1.1.2.2 yamt uint32_t ndev;
318 1.1.2.2 yamt
319 1.1.2.2 yamt ndev = be32toh(res->ActualNumDevices);
320 1.1.2.2 yamt ppc_dev = res->Devices;
321 1.1.2.2 yamt
322 1.1.2.2 yamt for (i = 0; i < ((ndev > MAX_DEVICES) ? MAX_DEVICES : ndev); i++) {
323 1.1.2.2 yamt pnp_getpna(&pna, paa, &ppc_dev[i]);
324 1.1.2.2 yamt if (config_match(parent, cf, &pna) > 0)
325 1.1.2.2 yamt config_attach(parent, cf, &pna, pnpbus_print);
326 1.1.2.2 yamt }
327 1.1.2.2 yamt
328 1.1.2.2 yamt return 0;
329 1.1.2.2 yamt }
330 1.1.2.2 yamt
331 1.1.2.2 yamt static void
332 1.1.2.2 yamt pnpbus_printres(struct pnpresources *r)
333 1.1.2.2 yamt {
334 1.1.2.2 yamt struct pnpbus_io *io;
335 1.1.2.2 yamt struct pnpbus_mem *mem;
336 1.1.2.2 yamt struct pnpbus_irq *irq;
337 1.1.2.2 yamt struct pnpbus_dma *dma;
338 1.1.2.2 yamt int p = 0;
339 1.1.2.2 yamt
340 1.1.2.2 yamt if (!SIMPLEQ_EMPTY(&r->mem)) {
341 1.1.2.2 yamt aprint_normal("mem");
342 1.1.2.2 yamt SIMPLEQ_FOREACH(mem, &r->mem, next) {
343 1.1.2.2 yamt aprint_normal(" 0x%x", mem->minbase);
344 1.1.2.2 yamt if (mem->len > 1)
345 1.1.2.2 yamt aprint_normal("-0x%x",
346 1.1.2.2 yamt mem->minbase + mem->len - 1);
347 1.1.2.2 yamt }
348 1.1.2.2 yamt p++;
349 1.1.2.2 yamt }
350 1.1.2.2 yamt if (!SIMPLEQ_EMPTY(&r->io)) {
351 1.1.2.2 yamt if (p++)
352 1.1.2.2 yamt aprint_normal(", ");
353 1.1.2.2 yamt aprint_normal("port");
354 1.1.2.2 yamt SIMPLEQ_FOREACH(io, &r->io, next) {
355 1.1.2.2 yamt aprint_normal(" 0x%x", io->minbase);
356 1.1.2.2 yamt if (io->len > 1)
357 1.1.2.2 yamt aprint_normal("-0x%x",
358 1.1.2.2 yamt io->minbase + io->len - 1);
359 1.1.2.2 yamt }
360 1.1.2.2 yamt }
361 1.1.2.2 yamt if (!SIMPLEQ_EMPTY(&r->irq)) {
362 1.1.2.2 yamt if (p++)
363 1.1.2.2 yamt aprint_normal(", ");
364 1.1.2.2 yamt aprint_normal("irq");
365 1.1.2.2 yamt SIMPLEQ_FOREACH(irq, &r->irq, next) {
366 1.1.2.2 yamt aprint_normal(" %d", ffs(irq->mask) - 1);
367 1.1.2.2 yamt }
368 1.1.2.2 yamt }
369 1.1.2.2 yamt if (!SIMPLEQ_EMPTY(&r->dma)) {
370 1.1.2.2 yamt if (p++)
371 1.1.2.2 yamt aprint_normal(", ");
372 1.1.2.2 yamt aprint_normal("DMA");
373 1.1.2.2 yamt SIMPLEQ_FOREACH(dma, &r->dma, next) {
374 1.1.2.2 yamt aprint_normal(" %d", ffs(dma->mask) - 1);
375 1.1.2.2 yamt }
376 1.1.2.2 yamt }
377 1.1.2.2 yamt }
378 1.1.2.2 yamt
379 1.1.2.2 yamt static int
380 1.1.2.2 yamt pnpbus_print(void *args, const char *name)
381 1.1.2.2 yamt {
382 1.1.2.2 yamt struct pnpbus_dev_attach_args *pna = args;
383 1.1.2.2 yamt
384 1.1.2.2 yamt pnpbus_printres(&pna->pna_res);
385 1.1.2.2 yamt
386 1.1.2.2 yamt return (UNCONF);
387 1.1.2.2 yamt }
388 1.1.2.2 yamt
389 1.1.2.2 yamt void
390 1.1.2.2 yamt pnpbus_print_devres(struct pnpbus_dev_attach_args *pna)
391 1.1.2.2 yamt {
392 1.1.2.2 yamt aprint_normal(" ");
393 1.1.2.2 yamt pnpbus_printres(&pna->pna_res);
394 1.1.2.2 yamt aprint_normal("\n");
395 1.1.2.2 yamt }
396 1.1.2.2 yamt
397 1.1.2.2 yamt /*
398 1.1.2.2 yamt * Set up an interrupt handler to start being called.
399 1.1.2.2 yamt */
400 1.1.2.2 yamt void *
401 1.1.2.2 yamt pnpbus_intr_establish(int idx, int level, int (*ih_fun)(void *),
402 1.1.2.2 yamt void *ih_arg, struct pnpresources *r)
403 1.1.2.2 yamt {
404 1.1.2.2 yamt struct pnpbus_irq *irq;
405 1.1.2.2 yamt int irqnum, type;
406 1.1.2.2 yamt
407 1.1.2.2 yamt if (idx >= r->numirq)
408 1.1.2.2 yamt return 0;
409 1.1.2.2 yamt
410 1.1.2.2 yamt irq = SIMPLEQ_FIRST(&r->irq);
411 1.1.2.2 yamt while (idx--)
412 1.1.2.2 yamt irq = SIMPLEQ_NEXT(irq, next);
413 1.1.2.2 yamt
414 1.1.2.2 yamt irqnum = ffs(irq->mask) - 1;
415 1.1.2.2 yamt type = (irq->flags & 0x0c) ? IST_LEVEL : IST_EDGE;
416 1.1.2.2 yamt
417 1.1.2.2 yamt return (void *)intr_establish(irqnum, type, level, ih_fun, ih_arg);
418 1.1.2.2 yamt }
419 1.1.2.2 yamt
420 1.1.2.2 yamt /*
421 1.1.2.2 yamt * Deregister an interrupt handler.
422 1.1.2.2 yamt */
423 1.1.2.2 yamt void
424 1.1.2.2 yamt pnpbus_intr_disestablish(void *arg)
425 1.1.2.2 yamt {
426 1.1.2.2 yamt
427 1.1.2.2 yamt intr_disestablish(arg);
428 1.1.2.2 yamt }
429 1.1.2.2 yamt
430 1.1.2.2 yamt int
431 1.1.2.2 yamt pnpbus_getirqnum(struct pnpresources *r, int idx, int *irqp, int *istp)
432 1.1.2.2 yamt {
433 1.1.2.2 yamt struct pnpbus_irq *irq;
434 1.1.2.2 yamt
435 1.1.2.2 yamt if (idx >= r->numirq)
436 1.1.2.2 yamt return EINVAL;
437 1.1.2.2 yamt
438 1.1.2.2 yamt irq = SIMPLEQ_FIRST(&r->irq);
439 1.1.2.2 yamt while (idx--)
440 1.1.2.2 yamt irq = SIMPLEQ_NEXT(irq, next);
441 1.1.2.2 yamt
442 1.1.2.2 yamt if (irqp != NULL)
443 1.1.2.2 yamt *irqp = ffs(irq->mask) - 1;
444 1.1.2.2 yamt if (istp != NULL)
445 1.1.2.2 yamt *istp = (irq->flags &0x0c) ? IST_LEVEL : IST_EDGE;
446 1.1.2.2 yamt return 0;
447 1.1.2.2 yamt }
448 1.1.2.2 yamt
449 1.1.2.2 yamt int
450 1.1.2.2 yamt pnpbus_getdmachan(struct pnpresources *r, int idx, int *chanp)
451 1.1.2.2 yamt {
452 1.1.2.2 yamt struct pnpbus_dma *dma;
453 1.1.2.2 yamt
454 1.1.2.2 yamt if (idx >= r->numdma)
455 1.1.2.2 yamt return EINVAL;
456 1.1.2.2 yamt
457 1.1.2.2 yamt dma = SIMPLEQ_FIRST(&r->dma);
458 1.1.2.2 yamt while (idx--)
459 1.1.2.2 yamt dma = SIMPLEQ_NEXT(dma, next);
460 1.1.2.2 yamt
461 1.1.2.2 yamt if (chanp != NULL)
462 1.1.2.2 yamt *chanp = ffs(dma->mask) - 1;
463 1.1.2.2 yamt return 0;
464 1.1.2.2 yamt }
465 1.1.2.2 yamt
466 1.1.2.2 yamt int
467 1.1.2.2 yamt pnpbus_getioport(struct pnpresources *r, int idx, int *basep, int *sizep)
468 1.1.2.2 yamt {
469 1.1.2.2 yamt struct pnpbus_io *io;
470 1.1.2.2 yamt
471 1.1.2.2 yamt if (idx >= r->numio)
472 1.1.2.2 yamt return EINVAL;
473 1.1.2.2 yamt
474 1.1.2.2 yamt io = SIMPLEQ_FIRST(&r->io);
475 1.1.2.2 yamt while (idx--)
476 1.1.2.2 yamt io = SIMPLEQ_NEXT(io, next);
477 1.1.2.2 yamt
478 1.1.2.2 yamt if (basep)
479 1.1.2.2 yamt *basep = io->minbase;
480 1.1.2.2 yamt if (sizep)
481 1.1.2.2 yamt *sizep = io->len;
482 1.1.2.2 yamt return 0;
483 1.1.2.2 yamt }
484 1.1.2.2 yamt
485 1.1.2.2 yamt int
486 1.1.2.2 yamt pnpbus_io_map(struct pnpresources *r, int idx, bus_space_tag_t *tagp,
487 1.1.2.2 yamt bus_space_handle_t *hdlp)
488 1.1.2.2 yamt {
489 1.1.2.2 yamt struct pnpbus_io *io;
490 1.1.2.2 yamt
491 1.1.2.2 yamt if (idx >= r->numio)
492 1.1.2.2 yamt return EINVAL;
493 1.1.2.2 yamt
494 1.1.2.2 yamt io = SIMPLEQ_FIRST(&r->io);
495 1.1.2.2 yamt while (idx--)
496 1.1.2.2 yamt io = SIMPLEQ_NEXT(io, next);
497 1.1.2.2 yamt
498 1.1.2.2 yamt *tagp = &prep_isa_io_space_tag;
499 1.1.2.2 yamt return (bus_space_map(&prep_isa_io_space_tag, io->minbase, io->len,
500 1.1.2.2 yamt 0, hdlp));
501 1.1.2.2 yamt }
502 1.1.2.2 yamt
503 1.1.2.2 yamt void
504 1.1.2.2 yamt pnpbus_io_unmap(struct pnpresources *r, int idx, bus_space_tag_t tag,
505 1.1.2.2 yamt bus_space_handle_t hdl)
506 1.1.2.2 yamt {
507 1.1.2.2 yamt struct pnpbus_io *io;
508 1.1.2.2 yamt
509 1.1.2.2 yamt if (idx >= r->numio)
510 1.1.2.2 yamt return;
511 1.1.2.2 yamt
512 1.1.2.2 yamt io = SIMPLEQ_FIRST(&r->io);
513 1.1.2.2 yamt while (idx--)
514 1.1.2.2 yamt io = SIMPLEQ_NEXT(io, next);
515 1.1.2.2 yamt
516 1.1.2.2 yamt bus_space_unmap(tag, hdl, io->len);
517 1.1.2.2 yamt }
518