1/* 2 * Copyright (c) 1999, 2000 Matthew R. Green 3 * All rights reserved. 4 * Copyright 2001 by Thomas Moestl <tmm@FreeBSD.org>. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 14 unchanged lines hidden (view full) --- 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 24 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * from: NetBSD: psycho.c,v 1.39 2001/10/07 20:30:41 eeh Exp 30 * |
31 * $FreeBSD: head/sys/sparc64/pci/psycho.c 98148 2002-06-12 19:20:57Z tmm $ |
32 */ 33 34/* 35 * Support for `psycho' and `psycho+' UPA to PCI bridge and 36 * UltraSPARC IIi and IIe `sabre' PCI controllers. 37 */ 38 39#include "opt_psycho.h" --- 49 unchanged lines hidden (view full) --- 89static void psycho_bus_b(void *); 90static void psycho_powerfail(void *); 91#ifdef PSYCHO_MAP_WAKEUP 92static void psycho_wakeup(void *); 93#endif 94 95/* IOMMU support */ 96static void psycho_iommu_init(struct psycho_softc *, int); |
97static ofw_pci_binit_t psycho_binit; |
98 99/* 100 * bus space and bus dma support for UltraSPARC `psycho'. note that most 101 * of the bus dma support is provided by the iommu dvma controller. 102 */ 103static int psycho_dmamap_create(bus_dma_tag_t, bus_dma_tag_t, int, 104 bus_dmamap_t *); 105static int psycho_dmamap_destroy(bus_dma_tag_t, bus_dma_tag_t, bus_dmamap_t); --- 178 unchanged lines hidden (view full) --- 284 */ 285static int 286psycho_attach(device_t dev) 287{ 288 struct psycho_softc *sc; 289 struct psycho_softc *osc = NULL; 290 struct psycho_softc *asc; 291 struct upa_regs *reg; |
292 struct ofw_pci_bdesc obd; |
293 char compat[32]; 294 char *model; 295 phandle_t node; 296 u_int64_t csr; 297 u_long pcictl_offs, mlen; 298 int psycho_br[2]; 299 int n, i, nreg, rid; 300#if defined(PSYCHO_DEBUG) || defined(PSYCHO_STRAY) --- 112 unchanged lines hidden (view full) --- 413 * Setup the PCI control register 414 */ 415 csr = PCICTL_READ8(sc, PCR_CS); 416 csr |= PCICTL_MRLM | PCICTL_ARB_PARK | PCICTL_ERRINTEN | PCICTL_4ENABLE; 417 csr &= ~(PCICTL_SERR | PCICTL_CPU_PRIO | PCICTL_ARB_PRIO | 418 PCICTL_RTRYWAIT); 419 PCICTL_WRITE8(sc, PCR_CS, csr); 420 |
421 /* Grab the psycho ranges */ |
422 psycho_get_ranges(sc->sc_node, &sc->sc_range, &sc->sc_nrange); 423 |
424 /* Initialize memory and i/o rmans */ 425 sc->sc_io_rman.rm_type = RMAN_ARRAY; 426 sc->sc_io_rman.rm_descr = "Psycho PCI I/O Ports"; 427 if (rman_init(&sc->sc_io_rman) != 0 || 428 rman_manage_region(&sc->sc_io_rman, 0, PSYCHO_IO_SIZE) != 0) 429 panic("psycho_probe: failed to set up i/o rman"); 430 sc->sc_mem_rman.rm_type = RMAN_ARRAY; 431 sc->sc_mem_rman.rm_descr = "Psycho PCI Memory"; --- 159 unchanged lines hidden (view full) --- 591 psycho_intr_stray, sclr); 592 } 593#endif 594 PSYCHO_WRITE8(sc, map, mr | INTMAP_V); 595 } 596#endif 597 598 /* |
599 * Get the bus range from the firmware; it is used solely for obtaining 600 * the inital bus number, and cannot be trusted on all machines. 601 */ 602 n = OF_getprop(node, "bus-range", (void *)psycho_br, sizeof(psycho_br)); 603 if (n == -1) 604 panic("could not get psycho bus-range"); 605 if (n != sizeof(psycho_br)) 606 panic("broken psycho bus-range (%d)", n); 607 608 sc->sc_busno = ofw_pci_alloc_busno(sc->sc_node); 609 obd.obd_bus = psycho_br[0]; 610 obd.obd_secbus = obd.obd_subbus = sc->sc_busno; 611 obd.obd_slot = PCS_DEVICE; 612 obd.obd_func = PCS_FUNC; 613 obd.obd_init = psycho_binit; 614 obd.obd_super = NULL; 615 /* Initial setup. */ 616 psycho_binit(dev, &obd); 617 /* Update the bus number to what was just programmed. */ 618 obd.obd_bus = obd.obd_secbus; 619 /* |
620 * Initialize the interrupt registers of all devices hanging from 621 * the host bridge directly or indirectly via PCI-PCI bridges. 622 * The MI code (and the PCI spec) assume that this is done during 623 * system initialization, however the firmware does not do this 624 * at least on some models, and we probably shouldn't trust that 625 * the firmware uses the same model as this driver if it does. |
626 * Additionally, set up the bus numbers and ranges. |
627 */ |
628 ofw_pci_init(dev, sc->sc_node, &obd); |
629 630 device_add_child(dev, "pci", device_get_unit(dev)); 631 return (bus_generic_attach(dev)); 632} 633 634static void 635psycho_set_intr(struct psycho_softc *sc, int index, 636 device_t dev, bus_addr_t map, int iflags, driver_intr_t handler) --- 207 unchanged lines hidden (view full) --- 844 name = (char *)malloc(32, M_DEVBUF, M_NOWAIT); 845 if (name == 0) 846 panic("couldn't malloc iommu name"); 847 snprintf(name, 32, "%s dvma", device_get_name(sc->sc_dev)); 848 849 iommu_init(name, is, tsbsize, iobase); 850} 851 |
852static void 853psycho_binit(device_t busdev, struct ofw_pci_bdesc *obd) 854{ 855 856#ifdef PSYCHO_DEBUG 857 printf("psycho at %u/%u/%u: setting bus #s to %u/%u/%u\n", 858 obd->obd_bus, obd->obd_slot, obd->obd_func, obd->obd_bus, 859 obd->obd_secbus, obd->obd_subbus); 860#endif /* PSYCHO_DEBUG */ 861 /* 862 * NOTE: this must be kept in this order, since the last write will 863 * change the config space address of the psycho. 864 */ 865 PCIB_WRITE_CONFIG(busdev, obd->obd_bus, obd->obd_slot, obd->obd_func, 866 PCSR_SUBBUS, obd->obd_subbus, 1); 867 PCIB_WRITE_CONFIG(busdev, obd->obd_bus, obd->obd_slot, obd->obd_func, 868 PCSR_SECBUS, obd->obd_secbus, 1); 869} 870 |
871static int 872psycho_maxslots(device_t dev) 873{ 874 875 /* 876 * XXX: is this correct? At any rate, a number that is too high 877 * shouldn't do any harm, if only because of the way things are 878 * handled in psycho_read_config. --- 108 unchanged lines hidden (view full) --- 987 default: 988 panic("psycho_write_config: bad width"); 989 } 990} 991 992static int 993psycho_route_interrupt(device_t bus, device_t dev, int pin) 994{ |
995 996 /* 997 * XXX: ugly loathsome hack: 998 * We can't use ofw_pci_route_intr() here; the device passed may be 999 * the one of a bridge, so the original device can't be recovered. 1000 * 1001 * We need to use the firmware to route interrupts, however it has 1002 * no interface which could be used to interpret intpins; instead, --- 381 unchanged lines hidden --- |