pci_mace.c revision 1.8 1 /* $NetBSD: pci_mace.c,v 1.8 2006/08/30 23:35:10 rumble Exp $ */
2
3 /*
4 * Copyright (c) 2001,2003 Christopher Sekiya
5 * Copyright (c) 2000 Soren S. Jorvang
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed for the
19 * NetBSD Project. See http://www.NetBSD.org/ for
20 * information about NetBSD.
21 * 4. The name of the author may not be used to endorse or promote products
22 * derived from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: pci_mace.c,v 1.8 2006/08/30 23:35:10 rumble Exp $");
38
39 #include "opt_pci.h"
40 #include "pci.h"
41
42 #include <sys/param.h>
43 #include <sys/device.h>
44 #include <sys/systm.h>
45
46 #include <machine/cpu.h>
47 #include <machine/locore.h>
48 #include <machine/autoconf.h>
49 #include <machine/vmparam.h>
50 #include <machine/bus.h>
51 #include <machine/machtype.h>
52
53 #include <mips/cache.h>
54
55 #include <dev/pci/pcivar.h>
56 #include <dev/pci/pcireg.h>
57 #include <dev/pci/pcidevs.h>
58
59 #ifdef PCI_NETBSD_CONFIGURE
60 #include <sys/extent.h>
61 #include <sys/malloc.h>
62 #include <dev/pci/pciconf.h>
63 #endif
64
65 #include <sgimips/mace/macereg.h>
66 #include <sgimips/mace/macevar.h>
67
68 #include <sgimips/mace/pcireg_mace.h>
69 #ifndef PCI_NETBSD_CONFIGURE
70 #include <sgimips/pci/pci_addr_fixup.h>
71
72 #define PCIBIOS_PRINTV(arg) \
73 do { \
74 printf arg; \
75 } while (0)
76 #define PCIBIOS_PRINTVN(n, arg) \
77 do { \
78 printf arg; \
79 } while (0)
80
81
82 #define PAGE_ALIGN(x) (((x) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
83 #define MEG_ALIGN(x) (((x) + 0x100000 - 1) & ~(0x100000 - 1))
84 #endif
85
86 struct macepci_softc {
87 struct device sc_dev;
88
89 struct sgimips_pci_chipset sc_pc;
90 };
91
92 static int macepci_match(struct device *, struct cfdata *, void *);
93 static void macepci_attach(struct device *, struct device *, void *);
94 static int macepci_bus_maxdevs(pci_chipset_tag_t, int);
95 static pcireg_t macepci_conf_read(pci_chipset_tag_t, pcitag_t, int);
96 static void macepci_conf_write(pci_chipset_tag_t, pcitag_t, int, pcireg_t);
97 static int macepci_intr_map(struct pci_attach_args *, pci_intr_handle_t *);
98 static const char *
99 macepci_intr_string(pci_chipset_tag_t, pci_intr_handle_t);
100 static int macepci_intr(void *);
101
102 #ifndef PCI_NETBSD_CONFIGURE
103 struct pciaddr pciaddr;
104
105 int pciaddr_do_resource_allocate(pci_chipset_tag_t pc, pcitag_t tag, int mapreg, void *ctx, int type, bus_addr_t *addr, bus_size_t size);
106
107 unsigned int ioaddr_base = 0x1000;
108 unsigned int memaddr_base = 0x80100000;
109 #endif
110
111 CFATTACH_DECL(macepci, sizeof(struct macepci_softc),
112 macepci_match, macepci_attach, NULL, NULL);
113
114 static int
115 macepci_match(struct device *parent, struct cfdata *match, void *aux)
116 {
117
118 return (1);
119 }
120
121 static void
122 macepci_attach(struct device *parent, struct device *self, void *aux)
123 {
124 struct macepci_softc *sc = (struct macepci_softc *)self;
125 pci_chipset_tag_t pc = &sc->sc_pc;
126 struct mace_attach_args *maa = aux;
127 struct pcibus_attach_args pba;
128 u_int32_t control;
129 int rev;
130 #ifndef PCI_NETBSD_CONFIGURE
131 pcitag_t devtag;
132 int device;
133 #endif
134
135 if (bus_space_subregion(maa->maa_st, maa->maa_sh,
136 maa->maa_offset, 0, &pc->ioh) )
137 panic("macepci_attach: couldn't map");
138
139 pc->iot = maa->maa_st;
140
141 rev = bus_space_read_4(pc->iot, pc->ioh, MACEPCI_REVISION);
142 printf(": rev %d\n", rev);
143
144 pc->pc_bus_maxdevs = macepci_bus_maxdevs;
145 pc->pc_conf_read = macepci_conf_read;
146 pc->pc_conf_write = macepci_conf_write;
147 pc->pc_intr_map = macepci_intr_map;
148 pc->pc_intr_string = macepci_intr_string;
149 pc->intr_establish = mace_intr_establish;
150 pc->intr_disestablish = mace_intr_disestablish;
151
152 bus_space_write_4(pc->iot, pc->ioh, MACE_PCI_ERROR_ADDR, 0);
153 bus_space_write_4(pc->iot, pc->ioh, MACE_PCI_ERROR_FLAGS, 0);
154
155 /* Turn on PCI error interrupts */
156 bus_space_write_4(pc->iot, pc->ioh, MACE_PCI_CONTROL,
157 MACE_PCI_CONTROL_SERR_ENA |
158 MACE_PCI_CONTROL_PARITY_ERR |
159 MACE_PCI_CONTROL_PARK_LIU |
160 MACE_PCI_CONTROL_OVERRUN_INT |
161 MACE_PCI_CONTROL_PARITY_INT |
162 MACE_PCI_CONTROL_SERR_INT |
163 MACE_PCI_CONTROL_IT_INT |
164 MACE_PCI_CONTROL_RE_INT |
165 MACE_PCI_CONTROL_DPED_INT |
166 MACE_PCI_CONTROL_TAR_INT |
167 MACE_PCI_CONTROL_MAR_INT);
168
169 #ifndef PCI_NETBSD_CONFIGURE
170 /* Must fix up all PCI devices, ahc_pci expects proper i/o mapping */
171 for (device = 1; device < 4; device++) {
172 const struct pci_quirkdata *qd;
173 int function, nfuncs;
174 pcireg_t bhlcr, id;
175
176 devtag = pci_make_tag(pc, 0, device, 0);
177 id = pci_conf_read(pc, devtag, PCI_ID_REG);
178
179 /* Invalid vendor ID value? */
180 if (PCI_VENDOR(id) == PCI_VENDOR_INVALID)
181 continue;
182 /* XXX Not invalid, but we've done this ~forever. */
183 if (PCI_VENDOR(id) == 0)
184 continue;
185
186 qd = pci_lookup_quirkdata(PCI_VENDOR(id), PCI_PRODUCT(id));
187 bhlcr = pci_conf_read(pc, devtag, PCI_BHLC_REG);
188
189 if (PCI_HDRTYPE_MULTIFN(bhlcr) ||
190 (qd != NULL &&
191 (qd->quirks & PCI_QUIRK_MULTIFUNCTION) != 0))
192 nfuncs = 8;
193 else
194 nfuncs = 1;
195
196 for (function = 0; function < nfuncs; function++) {
197 devtag = pci_make_tag(pc, 0, device, function);
198 id = pci_conf_read(pc, devtag, PCI_ID_REG);
199
200 /* Invalid vendor ID value? */
201 if (PCI_VENDOR(id) == PCI_VENDOR_INVALID)
202 continue;
203 /* Not invalid, but we've done this ~forever */
204 if (PCI_VENDOR(id) == 0)
205 continue;
206
207 pciaddr_resource_manage(pc, devtag, NULL, NULL);
208 }
209 }
210 #endif
211
212 /*
213 * Enable all MACE PCI interrupts. They will be masked by
214 * the CRIME code.
215 */
216 control = bus_space_read_4(pc->iot, pc->ioh, MACEPCI_CONTROL);
217 control |= CONTROL_INT_MASK;
218 bus_space_write_4(pc->iot, pc->ioh, MACEPCI_CONTROL, control);
219
220 #if NPCI > 0
221 #ifdef PCI_NETBSD_CONFIGURE
222 pc->pc_ioext = extent_create("macepciio", 0x00001000, 0x01ffffff,
223 M_DEVBUF, NULL, 0, EX_NOWAIT);
224 pc->pc_memext = extent_create("macepcimem", 0x80100000, 0x81ffffff,
225 M_DEVBUF, NULL, 0, EX_NOWAIT);
226 pci_configure_bus(pc, pc->pc_ioext, pc->pc_memext, NULL, 0,
227 mips_dcache_align);
228 #endif
229 memset(&pba, 0, sizeof pba);
230 /*XXX*/ pba.pba_iot = SGIMIPS_BUS_SPACE_IO;
231 /*XXX*/ pba.pba_memt = SGIMIPS_BUS_SPACE_MEM;
232 pba.pba_dmat = &pci_bus_dma_tag;
233 pba.pba_dmat64 = NULL;
234 pba.pba_bus = 0;
235 pba.pba_bridgetag = NULL;
236 pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED |
237 PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY;
238 pba.pba_pc = pc;
239
240 #ifdef MACEPCI_IO_WAS_BUGGY
241 if (rev == 0)
242 pba.pba_flags &= ~PCI_FLAGS_IO_ENABLED; /* Buggy? */
243 #endif
244
245 cpu_intr_establish(maa->maa_intr, IPL_NONE, macepci_intr, sc);
246
247 config_found_ia(self, "pcibus", &pba, pcibusprint);
248 #endif
249 }
250
251 int
252 macepci_bus_maxdevs(pci_chipset_tag_t pc, int busno)
253 {
254
255 if (busno == 0)
256 return 5; /* 2 on-board SCSI chips, slots 0, 1 and 2 */
257 else
258 return 0; /* XXX */
259 }
260
261 pcireg_t
262 macepci_conf_read(pci_chipset_tag_t pc, pcitag_t tag, int reg)
263 {
264 pcireg_t data;
265
266 bus_space_write_4(pc->iot, pc->ioh, MACE_PCI_CONFIG_ADDR, (tag | reg));
267 data = bus_space_read_4(pc->iot, pc->ioh, MACE_PCI_CONFIG_DATA);
268 bus_space_write_4(pc->iot, pc->ioh, MACE_PCI_CONFIG_ADDR, 0);
269
270 return data;
271 }
272
273 void
274 macepci_conf_write(pci_chipset_tag_t pc, pcitag_t tag, int reg, pcireg_t data)
275 {
276 /* XXX O2 soren */
277 if (tag == 0)
278 return;
279
280 bus_space_write_4(pc->iot, pc->ioh, MACE_PCI_CONFIG_ADDR, (tag | reg));
281 bus_space_write_4(pc->iot, pc->ioh, MACE_PCI_CONFIG_DATA, data);
282 bus_space_write_4(pc->iot, pc->ioh, MACE_PCI_CONFIG_ADDR, 0);
283 }
284
285 int
286 macepci_intr_map(struct pci_attach_args *pa, pci_intr_handle_t *ihp)
287 {
288 pci_chipset_tag_t pc = pa->pa_pc;
289 pcitag_t intrtag = pa->pa_intrtag;
290 int pin = pa->pa_intrpin;
291 int bus, dev, func, start;
292
293 pci_decompose_tag(pc, intrtag, &bus, &dev, &func);
294
295 if (dev < 3 && pin != PCI_INTERRUPT_PIN_A)
296 panic("SCSI0 and SCSI1 must be hardwired!");
297
298 switch (pin) {
299 default:
300 case PCI_INTERRUPT_PIN_NONE:
301 return -1;
302
303 case PCI_INTERRUPT_PIN_A:
304 /*
305 * Each of SCSI{0,1}, & slots 0 - 2 has dedicated interrupt
306 * for pin A?
307 */
308 *ihp = dev + 7;
309 return 0;
310
311 case PCI_INTERRUPT_PIN_B:
312 start = 0;
313 break;
314 case PCI_INTERRUPT_PIN_C:
315 start = 1;
316 break;
317 case PCI_INTERRUPT_PIN_D:
318 start = 2;
319 break;
320 }
321
322 /* Pins B,C,D are mapped to PCI_SHARED0 - PCI_SHARED2 interrupts */
323 *ihp = 13 /* PCI_SHARED0 */ + (start + dev - 3) % 3;
324 return 0;
325 }
326
327 const char *
328 macepci_intr_string(pci_chipset_tag_t pc, pci_intr_handle_t ih)
329 {
330 static char irqstr[32];
331
332 sprintf(irqstr, "crime interrupt %d", ih);
333 return irqstr;
334 }
335
336
337 /*
338 * Handle PCI error interrupts.
339 */
340 int
341 macepci_intr(void *arg)
342 {
343 struct macepci_softc *sc = (struct macepci_softc *)arg;
344 pci_chipset_tag_t pc = &sc->sc_pc;
345 u_int32_t error, address;
346
347 error = bus_space_read_4(pc->iot, pc->ioh, MACE_PCI_ERROR_FLAGS);
348 address = bus_space_read_4(pc->iot, pc->ioh, MACE_PCI_ERROR_ADDR);
349 while (error & 0xffc00000) {
350 if (error & MACE_PERR_MASTER_ABORT) {
351 /*
352 * this seems to be a more-or-less normal error
353 * condition (e.g., "pcictl pci0 list" generates
354 * a _lot_ of these errors, so no message for now
355 * while I figure out if I missed a trick somewhere.
356 */
357 error &= ~MACE_PERR_MASTER_ABORT;
358 bus_space_write_4(pc->iot, pc->ioh,
359 MACE_PCI_ERROR_FLAGS, error);
360 }
361
362 if (error & MACE_PERR_TARGET_ABORT) {
363 printf("mace: target abort at %x\n", address);
364 error &= ~MACE_PERR_TARGET_ABORT;
365 bus_space_write_4(pc->iot, pc->ioh,
366 MACE_PCI_ERROR_FLAGS, error);
367 }
368
369 if (error & MACE_PERR_DATA_PARITY_ERR) {
370 printf("mace: parity error at %x\n", address);
371 error &= ~MACE_PERR_DATA_PARITY_ERR;
372 bus_space_write_4(pc->iot, pc->ioh,
373 MACE_PCI_ERROR_FLAGS, error);
374 }
375
376 if (error & MACE_PERR_RETRY_ERR) {
377 printf("mace: retry error at %x\n", address);
378 error &= ~MACE_PERR_RETRY_ERR;
379 bus_space_write_4(pc->iot, pc->ioh,
380 MACE_PCI_ERROR_FLAGS, error);
381 }
382
383 if (error & MACE_PERR_ILLEGAL_CMD) {
384 printf("mace: illegal command at %x\n", address);
385 error &= ~MACE_PERR_ILLEGAL_CMD;
386 bus_space_write_4(pc->iot, pc->ioh,
387 MACE_PCI_ERROR_FLAGS, error);
388 }
389
390 if (error & MACE_PERR_SYSTEM_ERR) {
391 printf("mace: system error at %x\n", address);
392 error &= ~MACE_PERR_SYSTEM_ERR;
393 bus_space_write_4(pc->iot, pc->ioh,
394 MACE_PCI_ERROR_FLAGS, error);
395 }
396
397 if (error & MACE_PERR_INTERRUPT_TEST) {
398 printf("mace: interrupt test at %x\n", address);
399 error &= ~MACE_PERR_INTERRUPT_TEST;
400 bus_space_write_4(pc->iot, pc->ioh,
401 MACE_PCI_ERROR_FLAGS, error);
402 }
403
404 if (error & MACE_PERR_PARITY_ERR) {
405 printf("mace: parity error at %x\n", address);
406 error &= ~MACE_PERR_PARITY_ERR;
407 bus_space_write_4(pc->iot, pc->ioh,
408 MACE_PCI_ERROR_FLAGS, error);
409 }
410
411 if (error & MACE_PERR_RSVD) {
412 printf("mace: reserved condition at %x\n", address);
413 error &= ~MACE_PERR_RSVD;
414 bus_space_write_4(pc->iot, pc->ioh,
415 MACE_PCI_ERROR_FLAGS, error);
416 }
417
418 if (error & MACE_PERR_OVERRUN) {
419 printf("mace: overrun at %x\n", address);
420 error &= ~MACE_PERR_OVERRUN;
421 bus_space_write_4(pc->iot, pc->ioh,
422 MACE_PCI_ERROR_FLAGS, error);
423 }
424 }
425 return 0;
426 }
427
428 #ifndef PCI_NETBSD_CONFIGURE
429 /* PCI Address fixup routines */
430
431 void
432 pciaddr_resource_manage(pci_chipset_tag_t pc, pcitag_t tag,
433 pciaddr_resource_manage_func_t func, void *ctx)
434 {
435 pcireg_t val, mask;
436 bus_addr_t addr;
437 bus_size_t size;
438 int error, mapreg, type, reg_start, reg_end, width;
439
440 val = macepci_conf_read(pc, tag, PCI_BHLC_REG);
441 switch (PCI_HDRTYPE_TYPE(val)) {
442 default:
443 printf("WARNING: unknown PCI device header.");
444 pciaddr.nbogus++;
445 return;
446 case 0:
447 reg_start = PCI_MAPREG_START;
448 reg_end = PCI_MAPREG_END;
449 break;
450 case 1: /* PCI-PCI bridge */
451 reg_start = PCI_MAPREG_START;
452 reg_end = PCI_MAPREG_PPB_END;
453 break;
454 case 2: /* PCI-CardBus bridge */
455 reg_start = PCI_MAPREG_START;
456 reg_end = PCI_MAPREG_PCB_END;
457 break;
458 }
459 error = 0;
460
461 for (mapreg = reg_start; mapreg < reg_end; mapreg += width) {
462 /* inquire PCI device bus space requirement */
463 val = macepci_conf_read(pc, tag, mapreg);
464 macepci_conf_write(pc, tag, mapreg, ~0);
465
466 mask = macepci_conf_read(pc, tag, mapreg);
467 macepci_conf_write(pc, tag, mapreg, val);
468
469 type = PCI_MAPREG_TYPE(val);
470 width = 4;
471
472 if (type == PCI_MAPREG_TYPE_MEM) {
473 size = PCI_MAPREG_MEM_SIZE(mask);
474
475 /*
476 * XXXrkb: for MEM64 BARs, to be totally kosher
477 * about the requested size, need to read mask
478 * from top 32bits of BAR and stir that into the
479 * size calculation, like so:
480 *
481 * case PCI_MAPREG_MEM_TYPE_64BIT:
482 * bar64 = pci_conf_read(pb->pc, tag, br + 4);
483 * pci_conf_write(pb->pc, tag, br + 4, 0xffffffff);
484 * mask64 = pci_conf_read(pb->pc, tag, br + 4);
485 * pci_conf_write(pb->pc, tag, br + 4, bar64);
486 * size = (u_int64_t) PCI_MAPREG_MEM64_SIZE(
487 * (((u_int64_t) mask64) << 32) | mask);
488 * width = 8;
489 *
490 * Fortunately, anything with all-zeros mask in the
491 * lower 32-bits will have size no less than 1 << 32,
492 * which we're not prepared to deal with, so I don't
493 * feel bad punting on it...
494 */
495 if (PCI_MAPREG_MEM_TYPE(val) ==
496 PCI_MAPREG_MEM_TYPE_64BIT) {
497 /*
498 * XXX We could examine the upper 32 bits
499 * XXX of the BAR here, but we are totally
500 * XXX unprepared to handle a non-zero value,
501 * XXX either here or anywhere else in the
502 * XXX sgimips code (not sure about MI code).
503 * XXX
504 * XXX So just arrange to skip the top 32
505 * XXX bits of the BAR and zero then out
506 * XXX if the BAR is in use.
507 */
508 width = 8;
509
510 if (size != 0)
511 macepci_conf_write(pc, tag,
512 mapreg + 4, 0);
513 }
514 } else {
515 /*
516 * Upper 16 bits must be one. Devices may hardwire
517 * them to zero, though, per PCI 2.2, 6.2.5.1, p 203.
518 */
519 mask |= 0xffff0000;
520 size = PCI_MAPREG_IO_SIZE(mask);
521 }
522
523 if (size == 0) /* unused register */
524 continue;
525
526 addr = pciaddr_ioaddr(val);
527
528 /* reservation/allocation phase */
529 error += pciaddr_do_resource_allocate(pc, tag, mapreg,
530 ctx, type, &addr, size);
531
532 #if 0
533 PCIBIOS_PRINTV(("\n\t%02xh %s 0x%08x 0x%08x",
534 mapreg, type ? "port" : "mem ",
535 (unsigned int)addr, (unsigned int)size));
536 #endif
537 }
538
539 /* enable/disable PCI device */
540 val = macepci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG);
541
542 if (error == 0)
543 val |= (PCI_COMMAND_IO_ENABLE |
544 PCI_COMMAND_MEM_ENABLE |
545 PCI_COMMAND_MASTER_ENABLE |
546 PCI_COMMAND_SPECIAL_ENABLE |
547 PCI_COMMAND_INVALIDATE_ENABLE |
548 PCI_COMMAND_PARITY_ENABLE);
549 else
550 val &= ~(PCI_COMMAND_IO_ENABLE |
551 PCI_COMMAND_MEM_ENABLE |
552 PCI_COMMAND_MASTER_ENABLE);
553
554 macepci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG, val);
555
556 if (error)
557 pciaddr.nbogus++;
558 }
559
560 bus_addr_t
561 pciaddr_ioaddr(u_int32_t val)
562 {
563
564 return ((PCI_MAPREG_TYPE(val) == PCI_MAPREG_TYPE_MEM) ?
565 PCI_MAPREG_MEM_ADDR(val) : PCI_MAPREG_IO_ADDR(val));
566 }
567
568 int
569 pciaddr_do_resource_allocate(pci_chipset_tag_t pc, pcitag_t tag, int mapreg,
570 void *ctx, int type, bus_addr_t *addr, bus_size_t size)
571 {
572
573 switch (type) {
574 case PCI_MAPREG_TYPE_IO:
575 *addr = ioaddr_base;
576 ioaddr_base += PAGE_ALIGN(size);
577 break;
578
579 case PCI_MAPREG_TYPE_MEM:
580 *addr = memaddr_base;
581 memaddr_base += MEG_ALIGN(size);
582 break;
583
584 default:
585 PCIBIOS_PRINTV(("attempt to remap unknown region (addr 0x%lx, "
586 "size 0x%lx, type %d)\n", *addr, size, type));
587 return 0;
588 }
589
590
591 /* write new address to PCI device configuration header */
592 macepci_conf_write(pc, tag, mapreg, *addr);
593
594 /* check */
595 #ifdef PCIBIOSVERBOSE
596 if (!pcibiosverbose)
597 #endif
598 {
599 printf("pci_addr_fixup: ");
600 pciaddr_print_devid(pc, tag);
601 }
602 if (pciaddr_ioaddr(macepci_conf_read(pc, tag, mapreg)) != *addr) {
603 macepci_conf_write(pc, tag, mapreg, 0); /* clear */
604 printf("fixup failed. (new address=%#x)\n", (unsigned)*addr);
605 return (1);
606 }
607 #ifdef PCIBIOSVERBOSE
608 if (!pcibiosverbose)
609 #endif
610 printf("new address 0x%08x (size 0x%x)\n", (unsigned)*addr,
611 (unsigned)size);
612
613 return (0);
614 }
615
616 void
617 pciaddr_print_devid(pci_chipset_tag_t pc, pcitag_t tag)
618 {
619 int bus, device, function;
620 pcireg_t id;
621
622 id = macepci_conf_read(pc, tag, PCI_ID_REG);
623 pci_decompose_tag(pc, tag, &bus, &device, &function);
624 printf("%03d:%02d:%d 0x%04x 0x%04x ", bus, device, function,
625 PCI_VENDOR(id), PCI_PRODUCT(id));
626 }
627 #endif
628