p5pb.c revision 1.14 1 /* $NetBSD: p5pb.c,v 1.14 2015/10/02 05:22:49 msaitoh Exp $ */
2
3 /*-
4 * Copyright (c) 2011, 2012 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Radoslaw Kujawa.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include <sys/types.h>
33 #include <sys/param.h>
34 #include <sys/time.h>
35 #include <sys/systm.h>
36 #include <sys/errno.h>
37 #include <sys/device.h>
38 #include <sys/malloc.h>
39 #include <sys/kmem.h>
40 #include <sys/extent.h>
41
42 #include <uvm/uvm_extern.h>
43
44 #define _M68K_BUS_DMA_PRIVATE
45 #include <machine/bus.h>
46 #include <machine/cpu.h>
47
48 #include <m68k/bus_dma.h>
49 #include <amiga/dev/zbusvar.h>
50 #include <amiga/dev/p5busvar.h>
51 #include <amiga/pci/p5pbreg.h>
52 #include <amiga/pci/p5pbvar.h>
53 #include <amiga/pci/p5membarvar.h>
54
55 #include <dev/pci/pcivar.h>
56 #include <dev/pci/pcireg.h>
57 #include <dev/pci/pcidevs.h>
58 #ifdef PCI_NETBSD_CONFIGURE
59 #include <dev/pci/pciconf.h>
60 #endif /* PCI_NETBSD_CONFIGURE */
61
62 #include "opt_p5pb.h"
63 #include "opt_pci.h"
64
65 /* Initial CVPPC/BVPPC resolution as configured by the firmware */
66 #define P5GFX_WIDTH 640
67 #define P5GFX_HEIGHT 480
68 #define P5GFX_DEPTH 8
69 #define P5GFX_LINEBYTES 640
70
71 struct m68k_bus_dma_tag p5pb_bus_dma_tag = {
72 0,
73 0,
74 _bus_dmamap_create,
75 _bus_dmamap_destroy,
76 _bus_dmamap_load_direct,
77 _bus_dmamap_load_mbuf_direct,
78 _bus_dmamap_load_uio_direct,
79 _bus_dmamap_load_raw_direct,
80 _bus_dmamap_unload,
81 _bus_dmamap_sync,
82 _bus_dmamem_alloc,
83 _bus_dmamem_free,
84 _bus_dmamem_map,
85 _bus_dmamem_unmap,
86 _bus_dmamem_mmap
87 };
88
89 static int p5pb_match(device_t, cfdata_t, void *);
90 static void p5pb_attach(device_t, device_t, void *);
91 void p5pb_set_props(struct p5pb_softc *);
92 pcireg_t p5pb_pci_conf_read(pci_chipset_tag_t, pcitag_t, int);
93 void p5pb_pci_conf_write(pci_chipset_tag_t, pcitag_t, int, pcireg_t);
94 int p5pb_pci_bus_maxdevs_cvppc(pci_chipset_tag_t, int);
95 int p5pb_pci_bus_maxdevs_grex1200(pci_chipset_tag_t, int);
96 int p5pb_pci_bus_maxdevs_grex4000(pci_chipset_tag_t, int);
97 int p5pb_pci_conf_hook(pci_chipset_tag_t, int, int, int, pcireg_t);
98 void p5pb_pci_attach_hook (device_t, device_t,
99 struct pcibus_attach_args *);
100 pcitag_t p5pb_pci_make_tag(pci_chipset_tag_t, int, int, int);
101 void p5pb_pci_decompose_tag(pci_chipset_tag_t, pcitag_t,
102 int *, int *, int *);
103 int p5pb_pci_intr_map(const struct pci_attach_args *,
104 pci_intr_handle_t *);
105 bool p5pb_bus_map_memio(struct p5pb_softc *);
106 bool p5pb_bus_map_conf(struct p5pb_softc *);
107 uint8_t p5pb_find_resources(struct p5pb_softc *);
108 static bool p5pb_identify_bridge(struct p5pb_softc *);
109 void p5pb_membar_grex(struct p5pb_softc *);
110 static bool p5pb_cvppc_probe(struct p5pb_softc *);
111 #ifdef PCI_NETBSD_CONFIGURE
112 bool p5pb_bus_reconfigure(struct p5pb_softc *);
113 #endif /* PCI_NETBSD_CONFIGURE */
114 #ifdef P5PB_DEBUG
115 void p5pb_usable_ranges(struct p5pb_softc *);
116 void p5pb_badaddr_range(struct p5pb_softc *, bus_space_tag_t,
117 bus_addr_t, size_t);
118 void p5pb_conf_search(struct p5pb_softc *, uint16_t);
119 #endif /* P5PB_DEBUG */
120
121 CFATTACH_DECL_NEW(p5pb, sizeof(struct p5pb_softc),
122 p5pb_match, p5pb_attach, NULL, NULL);
123
124 static int
125 p5pb_match(device_t parent, cfdata_t cf, void *aux)
126 {
127 struct p5bus_attach_args *p5baa;
128
129 p5baa = (struct p5bus_attach_args *) aux;
130
131 if (strcmp(p5baa->p5baa_name, "p5pb") == 0)
132 return 1;
133
134 return 0;
135 }
136
137 static void
138 p5pb_attach(device_t parent, device_t self, void *aux)
139 {
140 struct p5pb_softc *sc;
141 struct pcibus_attach_args pba;
142
143 sc = device_private(self);
144 sc->sc_dev = self;
145 sc->p5baa = (struct p5bus_attach_args *) aux;
146
147 pci_chipset_tag_t pc = &sc->apc;
148
149 if (!p5pb_bus_map_conf(sc)) {
150 aprint_error_dev(self,
151 "couldn't map PCI configuration space\n");
152 return;
153 }
154
155 if (!p5pb_identify_bridge(sc)) {
156 return;
157 }
158
159 if (sc->bridge_type == P5PB_BRIDGE_CVPPC) {
160 sc->pci_mem_lowest = P5BUS_PCI_MEM_BASE;
161 sc->pci_mem_highest = P5BUS_PCI_MEM_BASE + P5BUS_PCI_MEM_SIZE;
162 } else {
163 p5pb_membar_grex(sc);
164 }
165
166 if (!p5pb_bus_map_memio(sc)) {
167 aprint_error_dev(self,
168 "couldn't map PCI I/O and memory space\n");
169 return;
170 }
171
172 #ifdef P5PB_DEBUG
173 aprint_normal("p5pb: map conf %x -> %x, io %x -> %x, mem %x -> %x\n",
174 kvtop((void*) sc->pci_conf_area.base), sc->pci_conf_area.base,
175 kvtop((void*) sc->pci_io_area.base), sc->pci_io_area.base,
176 kvtop((void*) sc->pci_mem_area.base), sc->pci_mem_area.base );
177 #endif
178
179 /* Initialize the PCI chipset tag. */
180
181 if (sc->bridge_type == P5PB_BRIDGE_GREX1200)
182 sc->apc.pc_bus_maxdevs = p5pb_pci_bus_maxdevs_grex1200;
183 else if (sc->bridge_type == P5PB_BRIDGE_GREX4000)
184 sc->apc.pc_bus_maxdevs = p5pb_pci_bus_maxdevs_grex4000;
185 else
186 sc->apc.pc_bus_maxdevs = p5pb_pci_bus_maxdevs_cvppc;
187
188 sc->apc.pc_conf_v = (void*) pc;
189 sc->apc.pc_make_tag = amiga_pci_make_tag;
190 sc->apc.pc_decompose_tag = amiga_pci_decompose_tag;
191 sc->apc.pc_conf_read = p5pb_pci_conf_read;
192 sc->apc.pc_conf_write = p5pb_pci_conf_write;
193 sc->apc.pc_conf_hook = p5pb_pci_conf_hook;
194 sc->apc.pc_conf_interrupt = amiga_pci_conf_interrupt;
195 sc->apc.pc_attach_hook = p5pb_pci_attach_hook;
196
197 sc->apc.pc_intr_map = p5pb_pci_intr_map;
198 sc->apc.pc_intr_string = amiga_pci_intr_string;
199 sc->apc.pc_intr_establish = amiga_pci_intr_establish;
200 sc->apc.pc_intr_disestablish = amiga_pci_intr_disestablish;
201
202 #ifdef PCI_NETBSD_CONFIGURE
203 /* Never reconfigure the bus on CVPPC/BVPPC, avoid the fb breakage. */
204 if (sc->bridge_type != P5PB_BRIDGE_CVPPC) {
205 p5pb_bus_reconfigure(sc);
206 }
207 #endif /* PCI_NETBSD_CONFIGURE */
208
209 /* Initialize the bus attachment structure. */
210
211 pba.pba_iot = &(sc->pci_io_area);
212 pba.pba_memt = &(sc->pci_mem_area);
213 pba.pba_dmat = &p5pb_bus_dma_tag;
214 pba.pba_dmat64 = NULL;
215 pba.pba_pc = pc;
216 pba.pba_flags = PCI_FLAGS_MEM_OKAY | PCI_FLAGS_IO_OKAY;
217 pba.pba_bus = 0;
218 pba.pba_bridgetag = NULL;
219
220 p5pb_set_props(sc);
221
222 config_found_ia(self, "pcibus", &pba, pcibusprint);
223 }
224
225 /*
226 * Try to detect what kind of bridge are we dealing with.
227 */
228 static bool
229 p5pb_identify_bridge(struct p5pb_softc *sc)
230 {
231 int pcires_count; /* Number of AutoConfig(TM) PCI resources */
232
233 pcires_count = p5pb_find_resources(sc);
234
235 switch (pcires_count) {
236 case 0:
237 /*
238 * Zero AutoConfig(TM) PCI resources, means that there's nothing
239 * OR there's a CVPPC/BVPPC with a pre-44.69 firmware.
240 */
241 if (p5pb_cvppc_probe(sc)) {
242 sc->bridge_type = P5PB_BRIDGE_CVPPC;
243 aprint_normal(": Phase5 CVPPC/BVPPC PCI bridge\n");
244 } else {
245 aprint_normal(": no PCI bridges detected\n");
246 return false;
247 }
248 break;
249 case 6:
250 /*
251 * We have a slight possibility, that there's a CVPPC/BVPPC with
252 * the new firmware. So check for it first.
253 */
254 if (p5pb_cvppc_probe(sc)) {
255 /* New firmware, treat as one-slot GREX. */
256 sc->bridge_type = P5PB_BRIDGE_CVPPC;
257 aprint_normal(
258 ": Phase5 CVPPC/BVPPC PCI bridge (44.69/44.71)\n");
259 break;
260 }
261 default:
262 /* We have a G-REX surely. */
263
264 if (sc->p5baa->p5baa_cardtype == P5_CARDTYPE_CS) {
265 sc->bridge_type = P5PB_BRIDGE_GREX4000;
266 aprint_normal(": DCE G-REX 4000 PCI bridge\n");
267 } else {
268 sc->bridge_type = P5PB_BRIDGE_GREX1200;
269 aprint_normal(": DCE G-REX 1200 PCI bridge\n");
270 }
271 break;
272 }
273 return true;
274 }
275
276 /*
277 * Find AutoConfig(TM) resuorces (for boards running G-REX firmware). Return the
278 * total number of found resources.
279 */
280 uint8_t
281 p5pb_find_resources(struct p5pb_softc *sc)
282 {
283 uint8_t i, rv;
284 struct p5pb_autoconf_entry *auto_entry;
285 struct p5membar_softc *membar_sc;
286 device_t p5membar_dev;
287
288 rv = 0;
289
290 TAILQ_INIT(&sc->auto_bars);
291
292 /* 255 should be enough for everybody */
293 for(i = 0; i < 255; i++) {
294
295 if ((p5membar_dev =
296 device_find_by_driver_unit("p5membar", i)) != NULL) {
297
298 rv++;
299
300 membar_sc = device_private(p5membar_dev);
301 if (membar_sc->sc_type == P5MEMBAR_TYPE_INTERNAL)
302 continue;
303
304 auto_entry =
305 kmem_alloc(sizeof(struct p5pb_autoconf_entry),
306 KM_SLEEP);
307
308 auto_entry->base = membar_sc->sc_base;
309 auto_entry->size = membar_sc->sc_size;
310
311 TAILQ_INSERT_TAIL(&sc->auto_bars, auto_entry, entries);
312 }
313 }
314 return rv;
315 }
316
317 /*
318 * Set properties needed to support fb driver. These are read later during
319 * autoconfg in device_register(). Needed for CVPPC/BVPPC.
320 */
321 void
322 p5pb_set_props(struct p5pb_softc *sc)
323 {
324 #if NGENFB > 0
325 prop_dictionary_t dict;
326 device_t dev;
327
328 dev = sc->sc_dev;
329 dict = device_properties(dev);
330
331 /* genfb needs additional properties, like virtual, physical address */
332 /* XXX: currently genfb is supported only on CVPPC/BVPPC */
333 prop_dictionary_set_uint64(dict, "virtual_address",
334 sc->pci_mem_area.base);
335 prop_dictionary_set_uint64(dict, "address",
336 kvtop((void*) sc->pci_mem_area.base));
337 #endif
338 }
339
340 pcireg_t
341 p5pb_pci_conf_read(pci_chipset_tag_t pc, pcitag_t tag, int reg)
342 {
343 uint32_t data;
344 uint32_t bus, dev, func;
345 uint32_t offset;
346
347 if ((unsigned int)reg >= PCI_CONF_SIZE)
348 return 0xFFFFFFFF;
349
350 pci_decompose_tag(pc, tag, &bus, &dev, &func);
351
352 offset = (OFF_PCI_DEVICE << dev) + reg;
353
354 if(func == 0) /* ugly, ugly hack */
355 offset += 0;
356 else if(func == 1)
357 offset += OFF_PCI_FUNCTION;
358 else
359 return 0xFFFFFFFF;
360
361 if(badaddr((void *)__UNVOLATILE(((uint32_t)
362 bus_space_vaddr(pc->pci_conf_datat, pc->pci_conf_datah)
363 + offset))))
364 return 0xFFFFFFFF;
365
366 data = bus_space_read_4(pc->pci_conf_datat, pc->pci_conf_datah,
367 offset);
368 #ifdef P5PB_DEBUG_CONF
369 aprint_normal("p5pb conf read va: %lx, bus: %d, dev: %d, "
370 "func: %d, reg: %d -r-> data %x\n",
371 pc->pci_conf_datah, bus, dev, func, reg, data);
372 #endif
373 return data;
374 }
375
376 void
377 p5pb_pci_conf_write(pci_chipset_tag_t pc, pcitag_t tag, int reg, pcireg_t val)
378 {
379 uint32_t bus, dev, func;
380 uint32_t offset;
381
382 if ((unsigned int)reg >= PCI_CONF_SIZE)
383 return;
384
385 pci_decompose_tag(pc, tag, &bus, &dev, &func);
386
387 offset = (OFF_PCI_DEVICE << dev) + reg;
388
389 if(func == 0) /* ugly, ugly hack */
390 offset += 0;
391 else if(func == 1)
392 offset += OFF_PCI_FUNCTION;
393 else
394 return;
395
396 if(badaddr((void *)__UNVOLATILE(((uint32_t)
397 bus_space_vaddr(pc->pci_conf_datat, pc->pci_conf_datah)
398 + offset))))
399 return;
400
401 bus_space_write_4(pc->pci_conf_datat, pc->pci_conf_datah,
402 offset, val);
403 #ifdef P5PB_DEBUG_CONF
404 aprint_normal("p5pb conf write va: %lx, bus: %d, dev: %d, "
405 "func: %d, reg: %d -w-> data %x\n",
406 pc->pci_conf_datah, bus, dev, func, reg, val);
407 #endif
408
409 }
410
411 int
412 p5pb_pci_bus_maxdevs_cvppc(pci_chipset_tag_t pc, int busno)
413 {
414 /* CVPPC/BVPPC has only 1 "slot". */
415 return 1;
416 }
417
418 int
419 p5pb_pci_bus_maxdevs_grex4000(pci_chipset_tag_t pc, int busno)
420 {
421 /* G-REX 4000 has 4, G-REX 4000T has 3 slots? */
422 return 4;
423 }
424
425 int
426 p5pb_pci_bus_maxdevs_grex1200(pci_chipset_tag_t pc, int busno)
427 {
428 /* G-REX 1200 has 5 slots. */
429 return 4; /* XXX: 5 not yet! */
430 }
431
432 void
433 p5pb_pci_attach_hook(device_t parent, device_t self,
434 struct pcibus_attach_args *pba)
435 {
436 }
437
438 int
439 p5pb_pci_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
440 {
441 /* TODO: add sanity checking */
442
443 *ihp = 2;
444 return 0;
445 }
446
447 /* Probe for CVPPC/BVPPC. */
448 static bool
449 p5pb_cvppc_probe(struct p5pb_softc *sc)
450 {
451 bus_space_handle_t probe_h;
452 uint16_t prodid, manid;
453 void* data;
454 bool rv;
455
456 manid = 0; prodid = 0;
457 rv = false;
458
459 if (bus_space_map(sc->apc.pci_conf_datat, 0, 4, 0, &probe_h))
460 return rv;
461
462 data = bus_space_vaddr(sc->apc.pci_conf_datat, probe_h);
463
464 if (badaddr((void *)__UNVOLATILE((uint32_t) data))) {
465 #ifdef P5PB_DEBUG_PROBE
466 aprint_normal("p5pb: CVPPC configuration space not usable!\n");
467 #endif /* P5PB_DEBUG_PROBE */
468 } else {
469 prodid = bus_space_read_2(sc->apc.pci_conf_datat, probe_h, 0);
470 manid = bus_space_read_2(sc->apc.pci_conf_datat, probe_h, 2);
471
472 if ((prodid == P5PB_PM2_PRODUCT_ID) &&
473 (manid == P5PB_PM2_VENDOR_ID))
474 rv = true;
475 }
476
477 #ifdef P5PB_DEBUG_PROBE
478 aprint_normal("p5pb: CVPPC probe for PCI ID: %x, %x returns %d\n",
479 manid, prodid, (int) rv);
480 #endif /* P5PB_DEBUG_PROBE */
481
482 bus_space_unmap(sc->apc.pci_conf_datat, probe_h, 4);
483 return rv;
484 }
485
486 #ifdef PCI_NETBSD_CONFIGURE
487 /* Reconfigure the bus. */
488 bool
489 p5pb_bus_reconfigure(struct p5pb_softc *sc)
490 {
491 struct extent *ioext, *memext;
492 pci_chipset_tag_t pc;
493
494 pc = &sc->apc;
495
496 ioext = extent_create("p5pbio", 0, P5BUS_PCI_IO_SIZE, NULL, 0,
497 EX_NOWAIT);
498
499 memext = extent_create("p5pbmem", sc->pci_mem_lowest,
500 sc->pci_mem_highest - 1, NULL, 0, EX_NOWAIT);
501
502 if ( (!ioext) || (!memext) )
503 return false;
504
505 #ifdef P5PB_DEBUG
506 aprint_normal("p5pb: reconfiguring the bus!\n");
507 #endif /* P5PB_DEBUG */
508 pci_configure_bus(pc, ioext, memext, NULL, 0, CACHELINE_SIZE);
509
510 extent_destroy(ioext);
511 extent_destroy(memext);
512
513 return true; /* TODO: better error handling */
514 }
515 #endif /* PCI_NETBSD_CONFIGURE */
516
517 /* Determine the PCI memory space (done G-REX-style). */
518 void
519 p5pb_membar_grex(struct p5pb_softc *sc)
520 {
521 struct p5pb_autoconf_entry *membar_entry;
522 uint32_t bar_address;
523
524 sc->pci_mem_lowest = 0xFFFFFFFF;
525 sc->pci_mem_highest = 0;
526
527 /* Iterate over membar entries to find lowest and highest address. */
528 TAILQ_FOREACH(membar_entry, &sc->auto_bars, entries) {
529
530 bar_address = (uint32_t) membar_entry->base;
531 if ((bar_address + membar_entry->size) > sc->pci_mem_highest)
532 sc->pci_mem_highest = bar_address + membar_entry->size;
533 if (bar_address < sc->pci_mem_lowest)
534 sc->pci_mem_lowest = bar_address;
535
536 #ifdef P5PB_DEBUG_BAR
537 aprint_normal("p5pb: %d kB mem BAR at %p, hi = %x, lo = %x\n",
538 membar_entry->size / 1024, membar_entry->base,
539 sc->pci_mem_highest, sc->pci_mem_lowest);
540 #endif /* P5PB_DEBUG_BAR */
541 }
542
543 aprint_normal("p5pb: %d kB PCI memory space (%8p to %8p)\n",
544 (sc->pci_mem_highest - sc->pci_mem_lowest) / 1024,
545 (void*) sc->pci_mem_lowest, (void*) sc->pci_mem_highest);
546
547 }
548
549 bool
550 p5pb_bus_map_conf(struct p5pb_softc *sc)
551 {
552 sc->pci_conf_area.base = (bus_addr_t) zbusmap(
553 (void *) P5BUS_PCI_CONF_BASE, P5BUS_PCI_CONF_SIZE);
554 sc->pci_conf_area.absm = &amiga_bus_stride_1;
555
556 sc->apc.pci_conf_datat = &(sc->pci_conf_area);
557
558 if (bus_space_map(sc->apc.pci_conf_datat, OFF_PCI_CONF_DATA,
559 P5BUS_PCI_CONF_SIZE, 0, &sc->apc.pci_conf_datah))
560 return false;
561
562 return true;
563 }
564
565 /* Map I/O and memory space. */
566 bool
567 p5pb_bus_map_memio(struct p5pb_softc *sc)
568 {
569 sc->pci_io_area.base = (bus_addr_t) zbusmap(
570 (void *) P5BUS_PCI_IO_BASE, P5BUS_PCI_IO_SIZE);
571 sc->pci_io_area.absm = &amiga_bus_stride_1swap;
572
573 sc->pci_mem_area.base = (bus_addr_t) zbusmap(
574 (void *) sc->pci_mem_lowest,
575 sc->pci_mem_highest - sc->pci_mem_lowest);
576 sc->pci_mem_area.absm = &amiga_bus_stride_1swap_abs;
577
578 return true;
579 }
580
581 int
582 p5pb_pci_conf_hook(pci_chipset_tag_t pct, int bus, int dev,
583 int func, pcireg_t id)
584 {
585 /* XXX: What should we do on CVPPC/BVPPC? It breaks genfb. */
586
587 return PCI_CONF_DEFAULT;
588 }
589
590 #ifdef P5PB_DEBUG
591 /* Check which config and I/O ranges are usable. */
592 void
593 p5pb_usable_ranges(struct p5pb_softc *sc)
594 {
595 p5pb_badaddr_range(sc, &(sc->pci_conf_area), 0, P5BUS_PCI_CONF_SIZE);
596 p5pb_badaddr_range(sc, &(sc->pci_io_area), 0, P5BUS_PCI_IO_SIZE);
597 }
598
599 void
600 p5pb_badaddr_range(struct p5pb_softc *sc, bus_space_tag_t bust, bus_addr_t base,
601 size_t len)
602 {
603 int i, state, prev_state;
604 bus_space_handle_t bush;
605 volatile void *data;
606
607 state = -1;
608 prev_state = -1;
609
610 bus_space_map(bust, base, len, 0, &bush);
611
612 aprint_normal("p5pb: badaddr range check from %x (%x) to %x (%x)\n",
613 (bus_addr_t) bush, /* start VA */
614 (bus_addr_t) kvtop((void*) bush), /* start PA */
615 (bus_addr_t) bush + len, /* end VA */
616 (bus_addr_t) kvtop((void*) (bush + len)));/* end PA */
617
618 data = bus_space_vaddr(bust, bush);
619
620 for(i = 0; i < len; i++) {
621 state = badaddr((void *)__UNVOLATILE(((uint32_t) data + i)));
622 if(state != prev_state) {
623 aprint_normal("p5pb: badaddr %p (%x) : %d\n",
624 (void*) ((uint32_t) data + i),
625 (bus_addr_t) kvtop((void*) ((uint32_t) data + i)),
626 state);
627 prev_state = state;
628 }
629
630 }
631
632 bus_space_unmap(bust, bush, len);
633 }
634
635 /* Search for 16-bit value in the configuration space. */
636 void
637 p5pb_conf_search(struct p5pb_softc *sc, uint16_t val)
638 {
639 int i, state;
640 uint16_t readv;
641 void *va;
642
643 va = bus_space_vaddr(sc->apc.pci_conf_datat, sc->apc.pci_conf_datah);
644
645 for (i = 0; i < P5BUS_PCI_CONF_SIZE; i++) {
646 state = badaddr((void *)__UNVOLATILE(((uint32_t) va + i)));
647 if(state == 0) {
648 readv = bus_space_read_2(sc->apc.pci_conf_datat,
649 sc->apc.pci_conf_datah, i);
650 if(readv == val)
651 aprint_normal("p5pb: found val %x @ %x (%x)\n",
652 readv, (uint32_t) sc->apc.pci_conf_datah
653 + i, (bus_addr_t) kvtop((void*)
654 ((uint32_t) sc->apc.pci_conf_datah + i)));
655 }
656 }
657 }
658
659 #endif /* P5PB_DEBUG */
660
661 #ifdef P5PB_CONSOLE
662 void
663 p5pb_device_register(device_t dev, void *aux)
664 {
665 prop_dictionary_t dict, parent_dict;
666 struct pci_attach_args *pa = aux;
667
668 if (device_parent(dev) && device_is_a(device_parent(dev), "pci")) {
669
670 dict = device_properties(dev);
671
672 if (PCI_CLASS(pa->pa_class) == PCI_CLASS_DISPLAY) {
673
674 /* Handle the CVPPC/BVPPC card... */
675 if ( ((PCI_VENDOR(pa->pa_id) == PCI_VENDOR_TI)
676 && (PCI_PRODUCT(pa->pa_id) ==
677 PCI_PRODUCT_TI_TVP4020) ) ||
678 /* ...and 3Dfx Voodoo 3 in G-REX. */
679 ((PCI_VENDOR(pa->pa_id) == PCI_VENDOR_3DFX)
680 && (PCI_PRODUCT(pa->pa_id) ==
681 PCI_PRODUCT_3DFX_VOODOO3) )) {
682
683 parent_dict = device_properties(
684 device_parent(device_parent(dev)));
685
686 prop_dictionary_set_uint32(dict, "width",
687 P5GFX_WIDTH);
688
689 prop_dictionary_set_uint32(dict, "height",
690 P5GFX_HEIGHT);
691
692 prop_dictionary_set_uint32(dict, "depth",
693 P5GFX_DEPTH);
694
695 #if (NGENFB > 0)
696 prop_dictionary_set_uint32(dict, "linebytes",
697 P5GFX_LINEBYTES);
698
699 prop_dictionary_set(dict, "address",
700 prop_dictionary_get(parent_dict,
701 "address"));
702 prop_dictionary_set(dict, "virtual_address",
703 prop_dictionary_get(parent_dict,
704 "virtual_address"));
705 #endif
706 prop_dictionary_set_bool(dict, "is_console",
707 true);
708 }
709 }
710 }
711 }
712 #endif /* P5PB_CONSOLE */
713