Deleted Added
full compact
34c34
< __FBSDID("$FreeBSD: stable/10/sys/sparc64/pci/psycho.c 266020 2014-05-14 14:17:51Z ian $");
---
> __FBSDID("$FreeBSD: stable/10/sys/sparc64/pci/psycho.c 292789 2015-12-27 19:37:47Z marius $");
60d59
< #include <dev/ofw/ofw_pci.h>
113d111
< static bus_read_ivar_t psycho_read_ivar;
116,118d113
< static bus_activate_resource_t psycho_activate_resource;
< static bus_adjust_resource_t psycho_adjust_resource;
< static bus_get_dma_tag_t psycho_get_dma_tag;
123d117
< static ofw_bus_get_node_t psycho_get_node;
135c129
< DEVMETHOD(bus_read_ivar, psycho_read_ivar),
---
> DEVMETHOD(bus_read_ivar, ofw_pci_read_ivar),
139c133
< DEVMETHOD(bus_activate_resource, psycho_activate_resource),
---
> DEVMETHOD(bus_activate_resource, ofw_pci_activate_resource),
141c135
< DEVMETHOD(bus_adjust_resource, psycho_adjust_resource),
---
> DEVMETHOD(bus_adjust_resource, ofw_pci_adjust_resource),
143c137
< DEVMETHOD(bus_get_dma_tag, psycho_get_dma_tag),
---
> DEVMETHOD(bus_get_dma_tag, ofw_pci_get_dma_tag),
152c146
< DEVMETHOD(ofw_bus_get_node, psycho_get_node),
---
> DEVMETHOD(ofw_bus_get_node, ofw_pci_get_node),
291d284
< struct ofw_pci_ranges *range;
293a287
> bus_dma_tag_t dmat;
296c290
< uint32_t dvmabase, prop, prop_array[2];
---
> uint32_t dvmabase, prop;
304d297
< sc->sc_node = node;
369a363
> SLIST_INSERT_HEAD(&psycho_softcs, sc, sc_link);
438,450d431
< /* Initialize memory and I/O rmans. */
< sc->sc_pci_io_rman.rm_type = RMAN_ARRAY;
< sc->sc_pci_io_rman.rm_descr = "Psycho PCI I/O Ports";
< if (rman_init(&sc->sc_pci_io_rman) != 0 ||
< rman_manage_region(&sc->sc_pci_io_rman, 0, PSYCHO_IO_SIZE) != 0)
< panic("%s: failed to set up I/O rman", __func__);
< sc->sc_pci_mem_rman.rm_type = RMAN_ARRAY;
< sc->sc_pci_mem_rman.rm_descr = "Psycho PCI Memory";
< if (rman_init(&sc->sc_pci_mem_rman) != 0 ||
< rman_manage_region(&sc->sc_pci_mem_rman, 0, PSYCHO_MEM_SIZE) != 0)
< panic("%s: failed to set up memory rman", __func__);
<
< i = OF_getprop_alloc(node, "ranges", sizeof(*range), (void **)&range);
452,475d432
< * Make sure that the expected ranges are present. The
< * OFW_PCI_CS_MEM64 one is not currently used though.
< */
< if (i != PSYCHO_NRANGE)
< panic("%s: unsupported number of ranges", __func__);
< /*
< * Find the addresses of the various bus spaces.
< * There should not be multiple ones of one kind.
< * The physical start addresses of the ranges are the configuration,
< * memory and I/O handles.
< */
< for (i = 0; i < PSYCHO_NRANGE; i++) {
< j = OFW_PCI_RANGE_CS(&range[i]);
< if (sc->sc_pci_bh[j] != 0)
< panic("%s: duplicate range for space %d",
< __func__, j);
< sc->sc_pci_bh[j] = OFW_PCI_RANGE_PHYS(&range[i]);
< }
< free(range, M_OFWPROP);
<
< /* Register the softc, this is needed for paired Psychos. */
< SLIST_INSERT_HEAD(&psycho_softcs, sc, sc_link);
<
< /*
575,584c532
< /* Allocate our tags. */
< sc->sc_pci_iot = sparc64_alloc_bus_tag(NULL, rman_get_bustag(
< sc->sc_mem_res), PCI_IO_BUS_SPACE, NULL);
< if (sc->sc_pci_iot == NULL)
< panic("%s: could not allocate PCI I/O tag", __func__);
< sc->sc_pci_cfgt = sparc64_alloc_bus_tag(NULL, rman_get_bustag(
< sc->sc_mem_res), PCI_CONFIG_BUS_SPACE, NULL);
< if (sc->sc_pci_cfgt == NULL)
< panic("%s: could not allocate PCI configuration space tag",
< __func__);
---
> /* Create our DMA tag. */
587c535
< 0xff, 0xffffffff, 0, NULL, NULL, &sc->sc_pci_dmat) != 0)
---
> 0xff, 0xffffffff, 0, NULL, NULL, &dmat) != 0)
589,591c537,538
< /* Customize the tag. */
< sc->sc_pci_dmat->dt_cookie = sc->sc_is;
< sc->sc_pci_dmat->dt_mt = sc->sc_dma_methods;
---
> dmat->dt_cookie = sc->sc_is;
> dmat->dt_mt = sc->sc_dma_methods;
593,603c540,542
< i = OF_getprop(node, "bus-range", (void *)prop_array,
< sizeof(prop_array));
< if (i == -1)
< panic("%s: could not get bus-range", __func__);
< if (i != sizeof(prop_array))
< panic("%s: broken bus-range (%d)", __func__, i);
< sc->sc_pci_secbus = prop_array[0];
< sc->sc_pci_subbus = prop_array[1];
< if (bootverbose)
< device_printf(dev, "bus range %u to %u; PCI bus %d\n",
< sc->sc_pci_secbus, sc->sc_pci_subbus, sc->sc_pci_secbus);
---
> if (ofw_pci_attach_common(dev, dmat, PSYCHO_IO_SIZE,
> PSYCHO_MEM_SIZE) != 0)
> panic("%s: ofw_pci_attach_common() failed", __func__);
606,607c545,546
< PCIB_WRITE_CONFIG(dev, sc->sc_pci_secbus, PCS_DEVICE, PCS_FUNC,
< PCIR_STATUS, PCIB_READ_CONFIG(dev, sc->sc_pci_secbus,
---
> PCIB_WRITE_CONFIG(dev, sc->sc_ops.sc_pci_secbus, PCS_DEVICE, PCS_FUNC,
> PCIR_STATUS, PCIB_READ_CONFIG(dev, sc->sc_ops.sc_pci_secbus,
670c609
< PCIB_WRITE_CONFIG(dev, sc->sc_pci_secbus, PCS_DEVICE, PCS_FUNC,
---
> PCIB_WRITE_CONFIG(dev, sc->sc_ops.sc_pci_secbus, PCS_DEVICE, PCS_FUNC,
674,676c613,616
< le16enc(&sc->sc_pci_hpbcfg[i], bus_space_read_2(
< sc->sc_pci_cfgt, sc->sc_pci_bh[OFW_PCI_CS_CONFIG],
< PSYCHO_CONF_OFF(sc->sc_pci_secbus, PCS_DEVICE,
---
> le16enc(&sc->sc_pci_hpbcfg[i],
> bus_space_read_2(sc->sc_ops.sc_pci_cfgt,
> sc->sc_ops.sc_pci_bh[OFW_PCI_CS_CONFIG],
> PSYCHO_CONF_OFF(sc->sc_ops.sc_pci_secbus, PCS_DEVICE,
679,681c619,621
< sc->sc_pci_hpbcfg[i] = bus_space_read_1(sc->sc_pci_cfgt,
< sc->sc_pci_bh[OFW_PCI_CS_CONFIG], PSYCHO_CONF_OFF(
< sc->sc_pci_secbus, PCS_DEVICE, PCS_FUNC, i));
---
> sc->sc_pci_hpbcfg[i] = bus_space_read_1(sc->sc_ops.sc_pci_cfgt,
> sc->sc_ops.sc_pci_bh[OFW_PCI_CS_CONFIG], PSYCHO_CONF_OFF(
> sc->sc_ops.sc_pci_secbus, PCS_DEVICE, PCS_FUNC, i));
683d622
< ofw_bus_setup_iinfo(node, &sc->sc_pci_iinfo, sizeof(ofw_pci_intr_t));
694,696c633,635
< sc->sc_pci_iinfo.opi_imapmsk != NULL)
< *(ofw_pci_intr_t *)(&sc->sc_pci_iinfo.opi_imapmsk[
< sc->sc_pci_iinfo.opi_addrc]) = INTMAP_INO_MASK;
---
> sc->sc_ops.sc_pci_iinfo.opi_imapmsk != NULL)
> *(ofw_pci_intr_t *)(&sc->sc_ops.sc_pci_iinfo.opi_imapmsk[
> sc->sc_ops.sc_pci_iinfo.opi_addrc]) = INTMAP_INO_MASK;
930,935d868
< bus_space_handle_t bh;
< u_long offset = 0;
< uint8_t byte;
< uint16_t shrt;
< uint32_t r, wrd;
< int i;
938,943d870
< if (bus < sc->sc_pci_secbus || bus > sc->sc_pci_subbus ||
< slot > PCI_SLOTMAX || func > PCI_FUNCMAX || reg > PCI_REGMAX)
< return (-1);
<
< bh = sc->sc_pci_bh[OFW_PCI_CS_CONFIG];
<
959c886
< if (bus == sc->sc_pci_secbus && slot == PCS_DEVICE &&
---
> if (bus == sc->sc_ops.sc_pci_secbus && slot == PCS_DEVICE &&
961c888
< if (offset % width != 0)
---
> if (reg % width != 0)
970,971c897,899
< bus_space_read_2(sc->sc_pci_cfgt, bh,
< PSYCHO_CONF_OFF(sc->sc_pci_secbus,
---
> bus_space_read_2(sc->sc_ops.sc_pci_cfgt,
> sc->sc_ops.sc_pci_bh[OFW_PCI_CS_CONFIG],
> PSYCHO_CONF_OFF(sc->sc_ops.sc_pci_secbus,
984,1010c912,914
< offset = PSYCHO_CONF_OFF(bus, slot, func, reg);
< switch (width) {
< case 1:
< i = bus_space_peek_1(sc->sc_pci_cfgt, bh, offset, &byte);
< r = byte;
< break;
< case 2:
< i = bus_space_peek_2(sc->sc_pci_cfgt, bh, offset, &shrt);
< r = shrt;
< break;
< case 4:
< i = bus_space_peek_4(sc->sc_pci_cfgt, bh, offset, &wrd);
< r = wrd;
< break;
< default:
< panic("%s: bad width", __func__);
< /* NOTREACHED */
< }
<
< if (i) {
< #ifdef PSYCHO_DEBUG
< printf("%s: read data error reading: %d.%d.%d: 0x%x\n",
< __func__, bus, slot, func, reg);
< #endif
< r = -1;
< }
< return (r);
---
> return (ofw_pci_read_config_common(dev, PCI_REGMAX,
> PSYCHO_CONF_OFF(bus, slot, func, reg), bus, slot, func, reg,
> width));
1017,1019d920
< struct psycho_softc *sc;
< bus_space_handle_t bh;
< u_long offset = 0;
1021,1041c922,923
< sc = device_get_softc(dev);
< if (bus < sc->sc_pci_secbus || bus > sc->sc_pci_subbus ||
< slot > PCI_SLOTMAX || func > PCI_FUNCMAX || reg > PCI_REGMAX)
< return;
<
< offset = PSYCHO_CONF_OFF(bus, slot, func, reg);
< bh = sc->sc_pci_bh[OFW_PCI_CS_CONFIG];
< switch (width) {
< case 1:
< bus_space_write_1(sc->sc_pci_cfgt, bh, offset, val);
< break;
< case 2:
< bus_space_write_2(sc->sc_pci_cfgt, bh, offset, val);
< break;
< case 4:
< bus_space_write_4(sc->sc_pci_cfgt, bh, offset, val);
< break;
< default:
< panic("%s: bad width", __func__);
< /* NOTREACHED */
< }
---
> ofw_pci_write_config_common(dev, PCI_REGMAX, PSYCHO_CONF_OFF(bus,
> slot, func, reg), bus, slot, func, reg, val, width);
1048d929
< struct ofw_pci_register reg;
1050c931
< ofw_pci_intr_t pintr, mintr;
---
> ofw_pci_intr_t mintr;
1052,1056c933,934
< sc = device_get_softc(bridge);
< pintr = pin;
< if (ofw_bus_lookup_imap(ofw_bus_get_node(dev), &sc->sc_pci_iinfo,
< &reg, sizeof(reg), &pintr, sizeof(pintr), &mintr, sizeof(mintr),
< NULL))
---
> mintr = ofw_pci_route_interrupt_common(bridge, dev, pin);
> if (PCI_INTERRUPT_VALID(mintr))
1074a953
> sc = device_get_softc(dev);
1084,1100d962
< static int
< psycho_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
< {
< struct psycho_softc *sc;
<
< sc = device_get_softc(dev);
< switch (which) {
< case PCIB_IVAR_DOMAIN:
< *result = device_get_unit(dev);
< return (0);
< case PCIB_IVAR_BUS:
< *result = sc->sc_pci_secbus;
< return (0);
< }
< return (ENOENT);
< }
<
1183,1184d1044
< struct resource *rv;
< struct rman *rm;
1186,1197c1046,1047
< sc = device_get_softc(bus);
< switch (type) {
< case SYS_RES_IRQ:
< /*
< * XXX: Don't accept blank ranges for now, only single
< * interrupts. The other case should not happen with
< * the MI PCI code...
< * XXX: This may return a resource that is out of the
< * range that was specified. Is this correct...?
< */
< if (start != end)
< panic("%s: XXX: interrupt range", __func__);
---
> if (type == SYS_RES_IRQ) {
> sc = device_get_softc(bus);
1199,1208d1048
< return (bus_generic_alloc_resource(bus, child, type, rid,
< start, end, count, flags));
< case SYS_RES_MEMORY:
< rm = &sc->sc_pci_mem_rman;
< break;
< case SYS_RES_IOPORT:
< rm = &sc->sc_pci_io_rman;
< break;
< default:
< return (NULL);
1210,1222c1050,1051
<
< rv = rman_reserve_resource(rm, start, end, count, flags & ~RF_ACTIVE,
< child);
< if (rv == NULL)
< return (NULL);
< rman_set_rid(rv, *rid);
<
< if ((flags & RF_ACTIVE) != 0 && bus_activate_resource(child, type,
< *rid, rv) != 0) {
< rman_release_resource(rv);
< return (NULL);
< }
< return (rv);
---
> return (ofw_pci_alloc_resource(bus, child, type, rid, start, end,
> count, flags));
1225,1299d1053
< static int
< psycho_activate_resource(device_t bus, device_t child, int type, int rid,
< struct resource *r)
< {
< struct psycho_softc *sc;
< struct bus_space_tag *tag;
<
< sc = device_get_softc(bus);
< switch (type) {
< case SYS_RES_IRQ:
< return (bus_generic_activate_resource(bus, child, type, rid,
< r));
< case SYS_RES_MEMORY:
< tag = sparc64_alloc_bus_tag(r, rman_get_bustag(
< sc->sc_mem_res), PCI_MEMORY_BUS_SPACE, NULL);
< if (tag == NULL)
< return (ENOMEM);
< rman_set_bustag(r, tag);
< rman_set_bushandle(r, sc->sc_pci_bh[OFW_PCI_CS_MEM32] +
< rman_get_start(r));
< break;
< case SYS_RES_IOPORT:
< rman_set_bustag(r, sc->sc_pci_iot);
< rman_set_bushandle(r, sc->sc_pci_bh[OFW_PCI_CS_IO] +
< rman_get_start(r));
< break;
< }
< return (rman_activate_resource(r));
< }
<
< static int
< psycho_adjust_resource(device_t bus, device_t child, int type,
< struct resource *r, u_long start, u_long end)
< {
< struct psycho_softc *sc;
< struct rman *rm;
<
< sc = device_get_softc(bus);
< switch (type) {
< case SYS_RES_IRQ:
< return (bus_generic_adjust_resource(bus, child, type, r,
< start, end));
< case SYS_RES_MEMORY:
< rm = &sc->sc_pci_mem_rman;
< break;
< case SYS_RES_IOPORT:
< rm = &sc->sc_pci_io_rman;
< break;
< default:
< return (EINVAL);
< }
< if (rman_is_region_manager(r, rm) == 0)
< return (EINVAL);
< return (rman_adjust_resource(r, start, end));
< }
<
< static bus_dma_tag_t
< psycho_get_dma_tag(device_t bus, device_t child __unused)
< {
< struct psycho_softc *sc;
<
< sc = device_get_softc(bus);
< return (sc->sc_pci_dmat);
< }
<
< static phandle_t
< psycho_get_node(device_t bus, device_t child __unused)
< {
< struct psycho_softc *sc;
<
< sc = device_get_softc(bus);
< /* We only have one child, the PCI bus, which needs our own node. */
< return (sc->sc_node);
< }
<