Page MenuHomeFreeBSD

D4879.id13933.diff
No OneTemporary

D4879.id13933.diff

Index: sys/conf/files.arm
===================================================================
--- sys/conf/files.arm
+++ sys/conf/files.arm
@@ -103,6 +103,7 @@
dev/hwpmc/hwpmc_armv7.c optional hwpmc armv6
dev/iicbus/twsi/twsi.c optional twsi
dev/ofw/ofw_cpu.c optional fdt
+dev/ofw/ofw_pci.c optional pci fdt
dev/psci/psci.c optional psci
dev/psci/psci_arm.S optional psci
dev/syscons/scgfbrndr.c optional sc
Index: sys/conf/files.arm64
===================================================================
--- sys/conf/files.arm64
+++ sys/conf/files.arm64
@@ -66,6 +66,7 @@
dev/mmc/host/dwmmc.c optional dwmmc
dev/mmc/host/dwmmc_hisi.c optional dwmmc soc_hisi_hi6220
dev/ofw/ofw_cpu.c optional fdt
+dev/ofw/ofw_pci.c optional pci fdt
dev/pci/pci_host_generic.c optional pci fdt
dev/psci/psci.c optional psci
dev/psci/psci_arm64.S optional psci
Index: sys/conf/files.i386
===================================================================
--- sys/conf/files.i386
+++ sys/conf/files.i386
@@ -285,6 +285,7 @@
dev/nvme/nvme_test.c optional nvme
dev/nvme/nvme_util.c optional nvme
dev/nvram/nvram.c optional nvram isa
+dev/ofw/ofw_pci.c optional pci fdt
dev/pcf/pcf_isa.c optional pcf
dev/random/ivy.c optional rdrand_rng
dev/random/nehemiah.c optional padlock_rng
Index: sys/conf/files.mips
===================================================================
--- sys/conf/files.mips
+++ sys/conf/files.mips
@@ -92,3 +92,6 @@
dev/hwpmc/hwpmc_mips.c optional hwpmc
dev/hwpmc/hwpmc_mips24k.c optional hwpmc_mips24k
dev/hwpmc/hwpmc_mips74k.c optional hwpmc_mips74k
+
+# ofw support
+dev/ofw/ofw_pci.c optional pci fdt
Index: sys/conf/files.powerpc
===================================================================
--- sys/conf/files.powerpc
+++ sys/conf/files.powerpc
@@ -57,6 +57,7 @@
dev/ofw/ofw_disk.c optional ofwd aim
dev/ofw/ofw_iicbus.c optional iicbus aim
dev/ofw/ofwbus.c optional aim | fdt
+dev/ofw/ofw_pci.c optional pci fdt
dev/ofw/ofw_standard.c optional aim powerpc
dev/ofw/ofw_subr.c optional aim powerpc
dev/powermac_nvram/powermac_nvram.c optional powermac_nvram powermac
@@ -145,7 +146,6 @@
powerpc/mpc85xx/pci_mpc85xx_pcib.c optional pci mpc85xx | pci qoriq_dpaa
powerpc/mpc85xx/qoriq_gpio.c optional mpc85xx gpio | qoriq_dpaa gpio
powerpc/ofw/ofw_machdep.c standard
-powerpc/ofw/ofw_pci.c optional pci
powerpc/ofw/ofw_pcibus.c optional pci
powerpc/ofw/ofw_pcib_pci.c optional pci
powerpc/ofw/ofw_real.c optional aim
Index: sys/conf/files.sparc64
===================================================================
--- sys/conf/files.sparc64
+++ sys/conf/files.sparc64
@@ -47,6 +47,7 @@
dev/ofw/ofw_bus_subr.c standard
dev/ofw/ofw_console.c optional ofw_console
dev/ofw/ofw_if.m standard
+dev/ofw/ofw_pci.c optional pci
dev/ofw/ofw_standard.c standard
dev/ofw/openfirm.c standard
dev/ofw/openfirmio.c standard
@@ -82,7 +83,7 @@
sparc64/isa/ofw_isa.c optional ebus | isa
sparc64/pci/apb.c optional pci
sparc64/pci/fire.c optional pci
-sparc64/pci/ofw_pci.c optional pci
+sparc64/pci/sparc64_ofw_pci.c optional pci
sparc64/pci/ofw_pcib.c optional pci
sparc64/pci/ofw_pcib_subr.c optional pci
sparc64/pci/ofw_pcibus.c optional pci
Index: sys/dev/ofw/ofw_pci.h
===================================================================
--- sys/dev/ofw/ofw_pci.h
+++ sys/dev/ofw/ofw_pci.h
@@ -89,6 +89,47 @@
#define OFW_PCI_PHYS_HI_FUNCTION(hi) \
(((hi) & OFW_PCI_PHYS_HI_FUNCTIONMASK) >> OFW_PCI_PHYS_HI_FUNCTIONSHIFT)
+#define OFW_PCI_SPACE_NUM 4
+
+/*
+ * Export class definition for inheritance purposes
+ */
+DECLARE_CLASS(ofw_pci_driver);
+
+typedef uint32_t ofw_pci_intr_t;
+
+/* OFW device types */
+#define OFW_TYPE_PCI "pci"
+#define OFW_TYPE_PCIE "pciex"
+
+struct ofw_pci_msi_addr_ranges {
+ uint32_t addr32_hi;
+ uint32_t addr32_lo;
+ uint32_t addr32_sz;
+ uint32_t addr64_hi;
+ uint32_t addr64_lo;
+ uint32_t addr64_sz;
+};
+
+#define OFW_PCI_MSI_ADDR_RANGE_32(r) \
+ (((uint64_t)(r)->addr32_hi << 32) | (uint64_t)(r)->addr32_lo)
+#define OFW_PCI_MSI_ADDR_RANGE_64(r) \
+ (((uint64_t)(r)->addr64_hi << 32) | (uint64_t)(r)->addr64_lo)
+
+struct ofw_pci_msi_eq_to_devino {
+ uint32_t eq_first;
+ uint32_t eq_count;
+ uint32_t devino_first;
+};
+
+struct ofw_pci_msi_ranges {
+ uint32_t first;
+ uint32_t count;
+};
+
+/* default values */
+#define OFW_PCI_LATENCY 64
+
/*
* This has the 3 32bit cell values, plus 2 more to make up a 64-bit size.
*/
@@ -100,4 +141,87 @@
u_int32_t size_lo;
};
+struct ofw_pci_cell_info {
+ pcell_t host_address_cells;
+ pcell_t pci_address_cell;
+ pcell_t size_cells;
+ };
+
+struct ofw_pci_range {
+ uint32_t pci_hi;
+ uint64_t pci;
+ uint64_t host;
+ uint64_t size;
+};
+
+/*
+ * Quirks for some adapters
+ */
+enum {
+ OFW_PCI_QUIRK_RANGES_ON_CHILDREN = 1,
+};
+
+/*
+ * Index into the sc_bh[] array, it is
+ * corresponding to the PCI space ranges type
+ */
+enum ofw_pci_ranges_type {
+ OFW_PCI_CONFIG = 0,
+ OFW_PCI_IO,
+ OFW_PCI_MEM32,
+ OFW_PCI_MEM64
+};
+
+struct ofw_pci_softc {
+ device_t sc_dev;
+ phandle_t sc_node;
+ int sc_bus;
+ int sc_initialized;
+ int sc_quirks;
+ uint8_t sc_secbus;
+ uint8_t sc_subbus;
+
+ struct ofw_pci_range *sc_range;
+ int sc_nrange;
+ struct ofw_pci_cell_info *sc_cell_info;
+
+ struct rman sc_io_rman;
+ struct rman sc_mem_rman;
+ bus_space_tag_t sc_memt;
+ bus_space_tag_t sc_cfgt;
+ bus_space_tag_t sc_iot;
+ bus_dma_tag_t sc_dmat;
+ bus_space_handle_t sc_bh[OFW_PCI_SPACE_NUM];
+
+ struct ofw_bus_iinfo sc_pci_iinfo;
+};
+
+int ofw_pci_init(device_t);
+int ofw_pci_attach(device_t);
+int ofw_pci_read_ivar(device_t, device_t, int, uintptr_t *);
+int ofw_pci_write_ivar(device_t, device_t, int, uintptr_t);
+int ofw_pci_route_interrupt(device_t, device_t, int);
+int ofw_pci_nranges(phandle_t, struct ofw_pci_cell_info *);
+int ofw_pci_fill_ranges(phandle_t, struct ofw_pci_range *);
+
+int ofw_pci_adjust_resource(device_t, device_t, int,
+ struct resource *, u_long, u_long);
+struct resource * ofw_pci_alloc_resource(device_t, device_t,
+ int, int *, u_long, u_long, u_long, u_int);
+int sparc64_ofw_pci_activate_resource(device_t, device_t, int, int,
+ struct resource *);
+int sparc64_ofw_pci_deactivate_resource(device_t, device_t, int, int,
+ struct resource *);
+
+int ofw_pci_attach_common(device_t, bus_dma_tag_t, u_long, u_long);
+uint32_t ofw_pci_read_config_common(device_t, u_int, u_long, u_int, u_int,
+ u_int, u_int, int);
+void ofw_pci_write_config_common(device_t, u_int, u_long, u_int, u_int,
+ u_int, u_int, uint32_t, int);
+ofw_pci_intr_t ofw_pci_route_interrupt_common(device_t, device_t, int);
+void ofw_pci_dmamap_sync_stst_order_common(void);
+
+ofw_bus_get_node_t ofw_pci_get_node;
+bus_get_dma_tag_t ofw_pci_get_dma_tag;
+
#endif /* _DEV_OFW_OFW_PCI_H_ */
Index: sys/dev/ofw/ofw_pci.c
===================================================================
--- /dev/null
+++ sys/dev/ofw/ofw_pci.c
@@ -0,0 +1,635 @@
+/*-
+ * Copyright (c) 2011 Nathan Whitehorn
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/module.h>
+#include <sys/bus.h>
+#include <sys/conf.h>
+#include <sys/kernel.h>
+#include <sys/rman.h>
+
+#include <dev/ofw/openfirm.h>
+#include <dev/ofw/ofw_bus.h>
+#include <dev/ofw/ofw_bus_subr.h>
+#include <dev/ofw/ofw_pci.h>
+
+#include <dev/pci/pcivar.h>
+#include <dev/pci/pcireg.h>
+
+#include <machine/bus.h>
+#include <machine/md_var.h>
+#include <machine/resource.h>
+
+#include <vm/vm.h>
+#include <vm/pmap.h>
+
+#include "pcib_if.h"
+
+/*
+ * If it is necessary to set another value of this for
+ * some platforms it should be set at fdt.h file
+ */
+#ifndef PCI_MAP_INTR
+#define PCI_MAP_INTR 4
+#endif
+
+#define PCI_INTR_PINS 4
+
+/*
+ * bus interface.
+ */
+static int ofw_pci_activate_resource(device_t, device_t, int, int,
+ struct resource *);
+static int ofw_pci_release_resource(device_t, device_t, int, int,
+ struct resource *);
+static int ofw_pci_deactivate_resource(device_t, device_t, int, int,
+ struct resource *);
+
+#ifdef __powerpc__
+static bus_space_tag_t ofw_pci_bus_get_bus_tag(device_t, device_t);
+#endif
+
+/*
+ * pcib interface
+ */
+static int ofw_pci_maxslots(device_t);
+
+/*
+ * Driver methods.
+ */
+static device_method_t ofw_pci_methods[] = {
+
+ /* Device interface */
+ DEVMETHOD(device_attach, ofw_pci_attach),
+
+ /* Bus interface */
+ DEVMETHOD(bus_print_child, bus_generic_print_child),
+ DEVMETHOD(bus_read_ivar, ofw_pci_read_ivar),
+ DEVMETHOD(bus_write_ivar, ofw_pci_write_ivar),
+ DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
+ DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
+ DEVMETHOD(bus_alloc_resource, ofw_pci_alloc_resource),
+ DEVMETHOD(bus_release_resource, ofw_pci_release_resource),
+ DEVMETHOD(bus_activate_resource, ofw_pci_activate_resource),
+ DEVMETHOD(bus_deactivate_resource, ofw_pci_deactivate_resource),
+ DEVMETHOD(bus_adjust_resource, ofw_pci_adjust_resource),
+#ifdef __powerpc__
+ DEVMETHOD(bus_get_bus_tag, ofw_pci_bus_get_bus_tag),
+#endif
+
+ /* pcib interface */
+ DEVMETHOD(pcib_maxslots, ofw_pci_maxslots),
+ DEVMETHOD(pcib_route_interrupt, ofw_pci_route_interrupt),
+
+ /* ofw_bus interface */
+ DEVMETHOD(ofw_bus_get_node, ofw_pci_get_node),
+
+ DEVMETHOD_END
+};
+
+DEFINE_CLASS_0(ofw_pci, ofw_pci_driver, ofw_pci_methods, sizeof(struct ofw_pci_softc));
+
+int
+ofw_pci_init(device_t dev)
+{
+ struct ofw_pci_softc *sc;
+ phandle_t node;
+ u_int32_t busrange[2];
+ struct ofw_pci_range *rp;
+ int error;
+ struct ofw_pci_cell_info *cell_info;
+
+ node = ofw_bus_get_node(dev);
+ sc = device_get_softc(dev);
+ sc->sc_initialized = 1;
+ sc->sc_range = NULL;
+
+ cell_info = (struct ofw_pci_cell_info *)malloc(sizeof(*cell_info),
+ M_DEVBUF, M_WAITOK | M_ZERO);
+
+ sc->sc_cell_info = cell_info;
+
+ if (OF_getencprop(node, "bus-range", busrange, sizeof(busrange)) != 8)
+ busrange[0] = 0;
+
+ sc->sc_dev = dev;
+ sc->sc_node = node;
+ sc->sc_bus = busrange[0];
+
+ if (sc->sc_quirks & OFW_PCI_QUIRK_RANGES_ON_CHILDREN) {
+ phandle_t c;
+ int n, i;
+
+ sc->sc_nrange = 0;
+ for (c = OF_child(node); c != 0; c = OF_peer(c)) {
+ n = ofw_pci_nranges(c, cell_info);
+ if (n > 0)
+ sc->sc_nrange += n;
+ }
+ if (sc->sc_nrange == 0) {
+ error = ENXIO;
+ goto out;
+ }
+ sc->sc_range = malloc(sc->sc_nrange * sizeof(sc->sc_range[0]),
+ M_DEVBUF, M_WAITOK);
+ i = 0;
+ for (c = OF_child(node); c != 0; c = OF_peer(c)) {
+ n = ofw_pci_fill_ranges(c, &sc->sc_range[i]);
+ if (n > 0)
+ i += n;
+ }
+ KASSERT(i == sc->sc_nrange, ("range count mismatch"));
+ } else {
+ sc->sc_nrange = ofw_pci_nranges(node, cell_info);
+ if (sc->sc_nrange <= 0) {
+ device_printf(dev, "could not getranges\n");
+ error = ENXIO;
+ goto out;
+ }
+ sc->sc_range = malloc(sc->sc_nrange * sizeof(sc->sc_range[0]),
+ M_DEVBUF, M_WAITOK);
+ ofw_pci_fill_ranges(node, sc->sc_range);
+ }
+
+ sc->sc_io_rman.rm_type = RMAN_ARRAY;
+ sc->sc_io_rman.rm_descr = "PCI I/O Ports";
+ error = rman_init(&sc->sc_io_rman);
+ if (error) {
+ device_printf(dev, "rman_init() failed. error = %d\n", error);
+ goto out;
+ }
+
+ sc->sc_mem_rman.rm_type = RMAN_ARRAY;
+ sc->sc_mem_rman.rm_descr = "PCI Memory";
+ error = rman_init(&sc->sc_mem_rman);
+ if (error) {
+ device_printf(dev, "rman_init() failed. error = %d\n", error);
+ goto out;
+ }
+
+ for (rp = sc->sc_range; rp < sc->sc_range + sc->sc_nrange &&
+ rp->pci_hi != 0; rp++) {
+ error = 0;
+
+ switch (rp->pci_hi & OFW_PCI_PHYS_HI_SPACEMASK) {
+ case OFW_PCI_PHYS_HI_SPACE_CONFIG:
+ break;
+ case OFW_PCI_PHYS_HI_SPACE_IO:
+ error = rman_manage_region(&sc->sc_io_rman, rp->pci,
+ rp->pci + rp->size - 1);
+ break;
+ case OFW_PCI_PHYS_HI_SPACE_MEM32:
+ case OFW_PCI_PHYS_HI_SPACE_MEM64:
+ error = rman_manage_region(&sc->sc_mem_rman, rp->pci,
+ rp->pci + rp->size - 1);
+ break;
+ }
+
+ if (error) {
+ device_printf(dev,
+ "rman_manage_region(%x, %#jx, %#jx) failed. "
+ "error = %d\n", rp->pci_hi &
+ OFW_PCI_PHYS_HI_SPACEMASK, rp->pci,
+ rp->pci + rp->size - 1, error);
+ goto out;
+ }
+ }
+
+ ofw_bus_setup_iinfo(node, &sc->sc_pci_iinfo, sizeof(cell_t));
+
+out:
+ free(cell_info, M_DEVBUF);
+ free(sc->sc_range, M_DEVBUF);
+ rman_fini(&sc->sc_io_rman);
+ rman_fini(&sc->sc_mem_rman);
+
+ return (error);
+}
+
+int
+ofw_pci_attach(device_t dev)
+{
+ struct ofw_pci_softc *sc;
+ int error;
+
+ sc = device_get_softc(dev);
+ if (!sc->sc_initialized) {
+ error = ofw_pci_init(dev);
+ if (error)
+ return (error);
+ }
+
+ device_add_child(dev, "pci", -1);
+ return (bus_generic_attach(dev));
+}
+
+static int
+ofw_pci_maxslots(device_t dev)
+{
+
+ return (PCI_SLOTMAX);
+}
+
+int
+ofw_pci_route_interrupt(device_t bus, device_t dev, int pin)
+{
+ struct ofw_pci_softc *sc;
+ struct ofw_pci_register reg;
+ uint32_t pintr, mintr[PCI_MAP_INTR];
+ int intrcells;
+ phandle_t iparent;
+
+ sc = device_get_softc(bus);
+ pintr = pin;
+
+ /* Fabricate imap information in case this isn't an OFW device */
+ bzero(&reg, sizeof(reg));
+ reg.phys_hi = (pci_get_bus(dev) << OFW_PCI_PHYS_HI_BUSSHIFT) |
+ (pci_get_slot(dev) << OFW_PCI_PHYS_HI_DEVICESHIFT) |
+ (pci_get_function(dev) << OFW_PCI_PHYS_HI_FUNCTIONSHIFT);
+
+ intrcells = ofw_bus_lookup_imap(ofw_bus_get_node(dev),
+ &sc->sc_pci_iinfo, &reg, sizeof(reg), &pintr, sizeof(pintr),
+ mintr, sizeof(mintr), &iparent);
+ if (intrcells != 0) {
+ pintr = ofw_bus_map_intr(dev, iparent, intrcells, mintr);
+ return (pintr);
+ }
+
+ /*
+ * Maybe it's a real interrupt, not an intpin
+ */
+ if (pin > PCI_INTR_PINS)
+ return (pin);
+
+ device_printf(bus, "could not route pin %d for device %d.%d\n",
+ pin, pci_get_slot(dev), pci_get_function(dev));
+ return (PCI_INVALID_IRQ);
+}
+
+int
+ofw_pci_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
+{
+ struct ofw_pci_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_bus;
+ return (0);
+ default:
+ break;
+ }
+
+ return (ENOENT);
+}
+
+int
+ofw_pci_write_ivar(device_t dev, device_t child, int which, uintptr_t value)
+{
+ struct ofw_pci_softc *sc;
+
+ sc = device_get_softc(dev);
+
+ switch (which) {
+ case PCIB_IVAR_BUS:
+ sc->sc_bus = value;
+ return (0);
+ default:
+ break;
+ }
+
+ return (ENOENT);
+}
+
+int
+ofw_pci_nranges(phandle_t node, struct ofw_pci_cell_info *info)
+{
+ ssize_t nbase_ranges;
+
+ if (info == NULL)
+ return (-1);
+
+ info->host_address_cells = 1;
+ info->size_cells = 2;
+ info->pci_address_cell = 3;
+
+ OF_getencprop(OF_parent(node), "#address-cells",
+ &(info->host_address_cells), sizeof(info->host_address_cells));
+ OF_getencprop(node, "#address-cells",
+ &(info->pci_address_cell), sizeof(info->pci_address_cell));
+ OF_getencprop(node, "#size-cells", &(info->size_cells),
+ sizeof(info->size_cells));
+
+ nbase_ranges = OF_getproplen(node, "ranges");
+ if (nbase_ranges <= 0)
+ return (-1);
+
+ return (nbase_ranges / sizeof(cell_t) /
+ (info->pci_address_cell + info->host_address_cells +
+ info->size_cells));
+}
+
+struct resource *
+ofw_pci_alloc_resource(device_t bus, device_t child, int type, int *rid,
+ rman_res_t start, rman_res_t end, rman_res_t count, u_int flags)
+{
+ struct ofw_pci_softc *sc;
+ struct resource *rv;
+ struct rman *rm;
+ int needactivate;
+
+ needactivate = flags & RF_ACTIVE;
+ flags &= ~RF_ACTIVE;
+
+ sc = device_get_softc(bus);
+
+ switch (type) {
+ case SYS_RES_MEMORY:
+ rm = &sc->sc_mem_rman;
+ break;
+
+ case SYS_RES_IOPORT:
+ rm = &sc->sc_io_rman;
+ break;
+
+ case SYS_RES_IRQ:
+
+#ifdef __sparc64__
+ if (start != end)
+ panic("%s: XXX: interrupt range", __func__);
+ return (bus_generic_alloc_resource(bus, child, type, rid, start,
+ end, count, flags));
+#else
+ return (bus_alloc_resource(bus, type, rid, start, end, count,
+ flags));
+#endif
+
+ default:
+ device_printf(bus, "unknown resource request from %s\n",
+ device_get_nameunit(child));
+ return (NULL);
+ }
+
+ rv = rman_reserve_resource(rm, start, end, count, flags, child);
+ if (rv == NULL) {
+ device_printf(bus, "failed to reserve resource for %s\n",
+ device_get_nameunit(child));
+ return (NULL);
+ }
+
+ rman_set_rid(rv, *rid);
+
+ if (needactivate) {
+ if (bus_activate_resource(child, type, *rid, rv) != 0) {
+ device_printf(bus,
+ "failed to activate resource for %s\n",
+ device_get_nameunit(child));
+ rman_release_resource(rv);
+ return (NULL);
+ }
+ }
+
+ return (rv);
+}
+
+static int
+ofw_pci_release_resource(device_t bus, device_t child, int type, int rid,
+ struct resource *res)
+{
+
+ if (rman_get_flags(res) & RF_ACTIVE) {
+ int error = bus_deactivate_resource(child, type, rid, res);
+ if (error)
+ return error;
+ }
+
+ return (rman_release_resource(res));
+}
+
+static int
+ofw_pci_activate_resource(device_t bus, device_t child, int type, int rid,
+ struct resource *res)
+{
+ struct ofw_pci_softc *sc;
+ bus_space_handle_t handle;
+ bus_space_tag_t tag;
+ int rv;
+
+ sc = device_get_softc(bus);
+
+ if (type == SYS_RES_IRQ) {
+ return (bus_activate_resource(bus, type, rid, res));
+ }
+ if (type == SYS_RES_MEMORY || type == SYS_RES_IOPORT) {
+ struct ofw_pci_range *rp;
+ vm_offset_t start;
+ int space;
+
+ start = (vm_offset_t)rman_get_start(res);
+
+ /*
+ * Map this through the ranges list
+ */
+ for (rp = sc->sc_range; rp < sc->sc_range + sc->sc_nrange &&
+ rp->pci_hi != 0; rp++) {
+ if (start < rp->pci || start >= rp->pci + rp->size)
+ continue;
+
+ switch (rp->pci_hi & OFW_PCI_PHYS_HI_SPACEMASK) {
+ case OFW_PCI_PHYS_HI_SPACE_IO:
+ space = SYS_RES_IOPORT;
+ break;
+ case OFW_PCI_PHYS_HI_SPACE_MEM32:
+ case OFW_PCI_PHYS_HI_SPACE_MEM64:
+ space = SYS_RES_MEMORY;
+ break;
+ default:
+ space = -1;
+ }
+
+ if (type == space) {
+ start += (rp->host - rp->pci);
+ break;
+ }
+ }
+
+ if (bootverbose)
+ printf("ofw_pci mapdev: start %zx, len %ld\n", start,
+ rman_get_size(res));
+
+ tag = BUS_GET_BUS_TAG(child, child);
+ if (tag == NULL)
+ return (ENOMEM);
+
+ rman_set_bustag(res, tag);
+ rv = bus_space_map(tag, start,
+ rman_get_size(res), 0, &handle);
+ if (rv != 0)
+ return (ENOMEM);
+
+ rman_set_bushandle(res, handle);
+ rman_set_virtual(res, (void *)handle); /* XXX for powerpc only ? */
+ }
+
+ return (rman_activate_resource(res));
+}
+
+#ifdef __powerpc__
+static bus_space_tag_t
+ofw_pci_bus_get_bus_tag(device_t bus, device_t child)
+{
+
+ return (&bs_le_tag);
+}
+#endif
+
+static int
+ofw_pci_deactivate_resource(device_t bus, device_t child, int type, int rid,
+ struct resource *res)
+{
+
+ /*
+ * If this is a memory resource, unmap it.
+ */
+ if ((type == SYS_RES_MEMORY) || (type == SYS_RES_IOPORT)) {
+ u_int32_t psize;
+
+ psize = rman_get_size(res);
+
+ /*
+ * XXX: The implementation is machine-dependent and
+ * sparc64 uses a different function signature as well.
+ */
+#ifndef __sparc64__
+ pmap_unmapdev((vm_offset_t)rman_get_virtual(res), psize);
+#endif
+ }
+
+ return (rman_deactivate_resource(res));
+}
+
+int
+ofw_pci_adjust_resource(device_t bus, device_t child, int type,
+ struct resource *res, rman_res_t start, rman_res_t end)
+{
+ struct rman *rm = NULL;
+ struct ofw_pci_softc *sc = device_get_softc(bus);
+
+ KASSERT(!(rman_get_flags(res) & RF_ACTIVE),
+ ("active resources cannot be adjusted"));
+ if (rman_get_flags(res) & RF_ACTIVE)
+ return (EINVAL);
+
+ switch (type) {
+ case SYS_RES_MEMORY:
+ rm = &sc->sc_mem_rman;
+ break;
+ case SYS_RES_IOPORT:
+ rm = &sc->sc_io_rman;
+ break;
+ case SYS_RES_IRQ:
+ return (bus_generic_adjust_resource(bus, child, type, res,
+ start, end));
+ default:
+ return (ENXIO);
+ }
+
+ if (!rman_is_region_manager(res, rm))
+ return (EINVAL);
+
+ return (rman_adjust_resource(res, start, end));
+}
+
+phandle_t
+ofw_pci_get_node(device_t bus, device_t dev)
+{
+ struct ofw_pci_softc *sc;
+
+ sc = device_get_softc(bus);
+ /* We only have one child, the PCI bus, which needs our own node. */
+
+ return (sc->sc_node);
+}
+
+bus_dma_tag_t
+ofw_pci_get_dma_tag(device_t bus, device_t child __unused)
+{
+ struct ofw_pci_softc *sc;
+
+ sc = device_get_softc(bus);
+ return (sc->sc_dmat);
+}
+
+int
+ofw_pci_fill_ranges(phandle_t node, struct ofw_pci_range *ranges)
+{
+ struct ofw_pci_cell_info *cell_info;
+ pcell_t *base_ranges;
+ ssize_t nbase_ranges;
+ int nranges;
+ int i, j, k;
+
+ cell_info = (struct ofw_pci_cell_info *)malloc(sizeof(*cell_info),
+ M_DEVBUF, M_WAITOK | M_ZERO);
+
+ nranges = ofw_pci_nranges(node, cell_info);
+
+ nbase_ranges = OF_getproplen(node, "ranges");
+ if (nbase_ranges <= 0)
+ return (-1);
+ base_ranges = malloc(nbase_ranges, M_DEVBUF, M_WAITOK);
+ OF_getencprop(node, "ranges", base_ranges, nbase_ranges);
+
+ for (i = 0, j = 0; i < nranges; i++) {
+ ranges[i].pci_hi = base_ranges[j++];
+ ranges[i].pci = 0;
+ for (k = 0; k < cell_info->pci_address_cell - 1; k++) {
+ ranges[i].pci <<= 32;
+ ranges[i].pci |= base_ranges[j++];
+ }
+ ranges[i].host = 0;
+ for (k = 0; k < cell_info->host_address_cells; k++) {
+ ranges[i].host <<= 32;
+ ranges[i].host |= base_ranges[j++];
+ }
+ ranges[i].size = 0;
+ for (k = 0; k < cell_info->size_cells; k++) {
+ ranges[i].size <<= 32;
+ ranges[i].size |= base_ranges[j++];
+ }
+ }
+
+ free(base_ranges, M_DEVBUF);
+ return (nranges);
+}
Index: sys/dev/ofw/ofw_subr.c
===================================================================
--- sys/dev/ofw/ofw_subr.c
+++ sys/dev/ofw/ofw_subr.c
@@ -39,8 +39,9 @@
#include <machine/bus.h>
#include <dev/ofw/openfirm.h>
-#include <dev/ofw/ofw_pci.h>
#include <dev/ofw/ofw_subr.h>
+#include <dev/ofw/ofw_bus_subr.h>
+#include <dev/ofw/ofw_pci.h>
static void
get_addr_props(phandle_t node, uint32_t *addrp, uint32_t *sizep, int *pcip)
Index: sys/dev/vt/hw/ofwfb/ofwfb.c
===================================================================
--- sys/dev/vt/hw/ofwfb/ofwfb.c
+++ sys/dev/vt/hw/ofwfb/ofwfb.c
@@ -31,6 +31,7 @@
#include <sys/kernel.h>
#include <sys/systm.h>
#include <sys/fbio.h>
+#include <sys/rman.h>
#include <dev/vt/vt.h>
#include <dev/vt/hw/fb/vt_fb.h>
@@ -46,6 +47,7 @@
#include <dev/ofw/openfirm.h>
#include <dev/ofw/ofw_bus.h>
+#include <dev/ofw/ofw_bus_subr.h>
#include <dev/ofw/ofw_pci.h>
struct ofwfb_softc {
Index: sys/powerpc/mpc85xx/pci_mpc85xx.c
===================================================================
--- sys/powerpc/mpc85xx/pci_mpc85xx.c
+++ sys/powerpc/mpc85xx/pci_mpc85xx.c
@@ -55,15 +55,13 @@
#include <vm/vm.h>
#include <vm/pmap.h>
-#include <dev/ofw/ofw_pci.h>
#include <dev/ofw/ofw_bus.h>
#include <dev/ofw/ofw_bus_subr.h>
+#include <dev/ofw/ofw_pci.h>
#include <dev/pci/pcivar.h>
#include <dev/pci/pcireg.h>
#include <dev/pci/pcib_private.h>
-#include <powerpc/ofw/ofw_pci.h>
-
#include "ofw_bus_if.h"
#include "pcib_if.h"
Index: sys/powerpc/ofw/ofw_machdep.c
===================================================================
--- sys/powerpc/ofw/ofw_machdep.c
+++ sys/powerpc/ofw/ofw_machdep.c
@@ -50,6 +50,7 @@
#include <dev/fdt/fdt_common.h>
#include <dev/ofw/openfirm.h>
+#include <dev/ofw/ofw_bus_subr.h>
#include <dev/ofw/ofw_pci.h>
#include <dev/ofw/ofw_bus.h>
#include <dev/ofw/ofw_subr.h>
Index: sys/powerpc/ofw/ofw_pci.h
===================================================================
--- sys/powerpc/ofw/ofw_pci.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/*-
- * Copyright (c) 2011 Nathan Whitehorn
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * $FreeBSD$
- */
-
-#ifndef POWERPC_OFW_OFW_PCI_H
-#define POWERPC_OFW_OFW_PCI_H
-
-/*
- * Export class definition for inheritance purposes
- */
-DECLARE_CLASS(ofw_pci_driver);
-
-struct ofw_pci_range {
- uint32_t pci_hi;
- uint64_t pci;
- uint64_t host;
- uint64_t size;
-};
-
-/*
- * Quirks for some adapters
- */
-enum {
- OFW_PCI_QUIRK_RANGES_ON_CHILDREN = 1,
-};
-
-struct ofw_pci_softc {
- device_t sc_dev;
- phandle_t sc_node;
- int sc_bus;
- int sc_initialized;
-
- int sc_quirks;
-
- struct ofw_pci_range *sc_range;
- int sc_nrange;
-
- struct rman sc_io_rman;
- struct rman sc_mem_rman;
- bus_space_tag_t sc_memt;
- bus_dma_tag_t sc_dmat;
-
- struct ofw_bus_iinfo sc_pci_iinfo;
-};
-
-int ofw_pci_init(device_t dev);
-int ofw_pci_attach(device_t dev);
-
-#endif // POWERPC_OFW_OFW_PCI_H
-
Index: sys/powerpc/ofw/ofw_pci.c
===================================================================
--- sys/powerpc/ofw/ofw_pci.c
+++ /dev/null
@@ -1,558 +0,0 @@
-/*-
- * Copyright (c) 2011 Nathan Whitehorn
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/module.h>
-#include <sys/bus.h>
-#include <sys/conf.h>
-#include <sys/kernel.h>
-
-#include <dev/ofw/openfirm.h>
-#include <dev/ofw/ofw_pci.h>
-#include <dev/ofw/ofw_bus.h>
-#include <dev/ofw/ofw_bus_subr.h>
-
-#include <dev/pci/pcivar.h>
-#include <dev/pci/pcireg.h>
-
-#include <machine/bus.h>
-#include <machine/intr_machdep.h>
-#include <machine/md_var.h>
-#include <machine/pio.h>
-#include <machine/resource.h>
-
-#include <sys/rman.h>
-
-#include <vm/vm.h>
-#include <vm/pmap.h>
-
-#include <powerpc/ofw/ofw_pci.h>
-
-#include "pcib_if.h"
-
-/*
- * Bus interface.
- */
-static int ofw_pci_read_ivar(device_t, device_t, int,
- uintptr_t *);
-static struct resource * ofw_pci_alloc_resource(device_t bus,
- device_t child, int type, int *rid, rman_res_t start,
- rman_res_t end, rman_res_t count, u_int flags);
-static int ofw_pci_release_resource(device_t bus, device_t child,
- int type, int rid, struct resource *res);
-static int ofw_pci_activate_resource(device_t bus, device_t child,
- int type, int rid, struct resource *res);
-static int ofw_pci_deactivate_resource(device_t bus,
- device_t child, int type, int rid,
- struct resource *res);
-static int ofw_pci_adjust_resource(device_t bus, device_t child,
- int type, struct resource *res, rman_res_t start,
- rman_res_t end);
-
-/*
- * pcib interface.
- */
-static int ofw_pci_maxslots(device_t);
-static int ofw_pci_route_interrupt(device_t, device_t, int);
-
-/*
- * ofw_bus interface
- */
-static phandle_t ofw_pci_get_node(device_t bus, device_t dev);
-
-/*
- * local methods
- */
-
-static int ofw_pci_nranges(phandle_t node);
-static int ofw_pci_fill_ranges(phandle_t node, struct ofw_pci_range *ranges);
-
-/*
- * Driver methods.
- */
-static device_method_t ofw_pci_methods[] = {
- /* Device interface */
- DEVMETHOD(device_attach, ofw_pci_attach),
-
- /* Bus interface */
- DEVMETHOD(bus_print_child, bus_generic_print_child),
- DEVMETHOD(bus_read_ivar, ofw_pci_read_ivar),
- DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
- DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
- DEVMETHOD(bus_alloc_resource, ofw_pci_alloc_resource),
- DEVMETHOD(bus_release_resource, ofw_pci_release_resource),
- DEVMETHOD(bus_activate_resource, ofw_pci_activate_resource),
- DEVMETHOD(bus_deactivate_resource, ofw_pci_deactivate_resource),
- DEVMETHOD(bus_adjust_resource, ofw_pci_adjust_resource),
-
- /* pcib interface */
- DEVMETHOD(pcib_maxslots, ofw_pci_maxslots),
- DEVMETHOD(pcib_route_interrupt, ofw_pci_route_interrupt),
-
- /* ofw_bus interface */
- DEVMETHOD(ofw_bus_get_node, ofw_pci_get_node),
-
- DEVMETHOD_END
-};
-
-DEFINE_CLASS_0(ofw_pci, ofw_pci_driver, ofw_pci_methods, 0);
-
-int
-ofw_pci_init(device_t dev)
-{
- struct ofw_pci_softc *sc;
- phandle_t node;
- u_int32_t busrange[2];
- struct ofw_pci_range *rp;
- int error;
-
- node = ofw_bus_get_node(dev);
- sc = device_get_softc(dev);
- sc->sc_initialized = 1;
-
- if (OF_getencprop(node, "bus-range", busrange, sizeof(busrange)) != 8)
- busrange[0] = 0;
-
- sc->sc_dev = dev;
- sc->sc_node = node;
- sc->sc_bus = busrange[0];
-
- if (sc->sc_quirks & OFW_PCI_QUIRK_RANGES_ON_CHILDREN) {
- phandle_t c;
- int n, i;
-
- sc->sc_nrange = 0;
- for (c = OF_child(node); c != 0; c = OF_peer(c)) {
- n = ofw_pci_nranges(c);
- if (n > 0)
- sc->sc_nrange += n;
- }
- if (sc->sc_nrange == 0)
- return (ENXIO);
- sc->sc_range = malloc(sc->sc_nrange * sizeof(sc->sc_range[0]),
- M_DEVBUF, M_WAITOK);
- i = 0;
- for (c = OF_child(node); c != 0; c = OF_peer(c)) {
- n = ofw_pci_fill_ranges(c, &sc->sc_range[i]);
- if (n > 0)
- i += n;
- }
- KASSERT(i == sc->sc_nrange, ("range count mismatch"));
- } else {
- sc->sc_nrange = ofw_pci_nranges(node);
- if (sc->sc_nrange <= 0) {
- device_printf(dev, "could not get ranges\n");
- return (ENXIO);
- }
- sc->sc_range = malloc(sc->sc_nrange * sizeof(sc->sc_range[0]),
- M_DEVBUF, M_WAITOK);
- ofw_pci_fill_ranges(node, sc->sc_range);
- }
-
- sc->sc_io_rman.rm_type = RMAN_ARRAY;
- sc->sc_io_rman.rm_descr = "PCI I/O Ports";
- error = rman_init(&sc->sc_io_rman);
- if (error) {
- device_printf(dev, "rman_init() failed. error = %d\n", error);
- return (error);
- }
-
- sc->sc_mem_rman.rm_type = RMAN_ARRAY;
- sc->sc_mem_rman.rm_descr = "PCI Memory";
- error = rman_init(&sc->sc_mem_rman);
- if (error) {
- device_printf(dev, "rman_init() failed. error = %d\n", error);
- return (error);
- }
-
- for (rp = sc->sc_range; rp < sc->sc_range + sc->sc_nrange &&
- rp->pci_hi != 0; rp++) {
- error = 0;
-
- switch (rp->pci_hi & OFW_PCI_PHYS_HI_SPACEMASK) {
- case OFW_PCI_PHYS_HI_SPACE_CONFIG:
- break;
- case OFW_PCI_PHYS_HI_SPACE_IO:
- error = rman_manage_region(&sc->sc_io_rman, rp->pci,
- rp->pci + rp->size - 1);
- break;
- case OFW_PCI_PHYS_HI_SPACE_MEM32:
- case OFW_PCI_PHYS_HI_SPACE_MEM64:
- error = rman_manage_region(&sc->sc_mem_rman, rp->pci,
- rp->pci + rp->size - 1);
- break;
- }
-
- if (error) {
- device_printf(dev,
- "rman_manage_region(%x, %#jx, %#jx) failed. "
- "error = %d\n", rp->pci_hi &
- OFW_PCI_PHYS_HI_SPACEMASK, rp->pci,
- rp->pci + rp->size - 1, error);
- return (error);
- }
- }
-
- ofw_bus_setup_iinfo(node, &sc->sc_pci_iinfo, sizeof(cell_t));
-
- return (error);
-}
-
-int
-ofw_pci_attach(device_t dev)
-{
- struct ofw_pci_softc *sc;
- int error;
-
- sc = device_get_softc(dev);
- if (!sc->sc_initialized) {
- error = ofw_pci_init(dev);
- if (error)
- return (error);
- }
-
- device_add_child(dev, "pci", -1);
- return (bus_generic_attach(dev));
-}
-
-static int
-ofw_pci_maxslots(device_t dev)
-{
-
- return (PCI_SLOTMAX);
-}
-
-static int
-ofw_pci_route_interrupt(device_t bus, device_t dev, int pin)
-{
- struct ofw_pci_softc *sc;
- struct ofw_pci_register reg;
- uint32_t pintr, mintr[2];
- int intrcells;
- phandle_t iparent;
-
- sc = device_get_softc(bus);
- pintr = pin;
-
- /* Fabricate imap information in case this isn't an OFW device */
- bzero(&reg, sizeof(reg));
- reg.phys_hi = (pci_get_bus(dev) << OFW_PCI_PHYS_HI_BUSSHIFT) |
- (pci_get_slot(dev) << OFW_PCI_PHYS_HI_DEVICESHIFT) |
- (pci_get_function(dev) << OFW_PCI_PHYS_HI_FUNCTIONSHIFT);
-
- intrcells = ofw_bus_lookup_imap(ofw_bus_get_node(dev),
- &sc->sc_pci_iinfo, &reg, sizeof(reg), &pintr, sizeof(pintr),
- mintr, sizeof(mintr), &iparent);
- if (intrcells) {
- pintr = ofw_bus_map_intr(dev, iparent, intrcells, mintr);
- return (pintr);
- }
-
- /* Maybe it's a real interrupt, not an intpin */
- if (pin > 4)
- return (pin);
-
- device_printf(bus, "could not route pin %d for device %d.%d\n",
- pin, pci_get_slot(dev), pci_get_function(dev));
- return (PCI_INVALID_IRQ);
-}
-
-static int
-ofw_pci_read_ivar(device_t dev, device_t child, int which, uintptr_t *result)
-{
- struct ofw_pci_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_bus;
- return (0);
- }
-
- return (ENOENT);
-}
-
-static struct resource *
-ofw_pci_alloc_resource(device_t bus, device_t child, int type, int *rid,
- rman_res_t start, rman_res_t end, rman_res_t count, u_int flags)
-{
- struct ofw_pci_softc *sc;
- struct resource *rv;
- struct rman *rm;
- int needactivate;
-
- needactivate = flags & RF_ACTIVE;
- flags &= ~RF_ACTIVE;
-
- sc = device_get_softc(bus);
-
- switch (type) {
- case SYS_RES_MEMORY:
- rm = &sc->sc_mem_rman;
- break;
-
- case SYS_RES_IOPORT:
- rm = &sc->sc_io_rman;
- break;
-
- case SYS_RES_IRQ:
- return (bus_alloc_resource(bus, type, rid, start, end, count,
- flags));
-
- default:
- device_printf(bus, "unknown resource request from %s\n",
- device_get_nameunit(child));
- return (NULL);
- }
-
- rv = rman_reserve_resource(rm, start, end, count, flags, child);
- if (rv == NULL) {
- device_printf(bus, "failed to reserve resource for %s\n",
- device_get_nameunit(child));
- return (NULL);
- }
-
- rman_set_rid(rv, *rid);
-
- if (needactivate) {
- if (bus_activate_resource(child, type, *rid, rv) != 0) {
- device_printf(bus,
- "failed to activate resource for %s\n",
- device_get_nameunit(child));
- rman_release_resource(rv);
- return (NULL);
- }
- }
-
- return (rv);
-}
-
-static int
-ofw_pci_release_resource(device_t bus, device_t child, int type, int rid,
- struct resource *res)
-{
- if (rman_get_flags(res) & RF_ACTIVE) {
- int error = bus_deactivate_resource(child, type, rid, res);
- if (error)
- return error;
- }
-
- return (rman_release_resource(res));
-}
-
-static int
-ofw_pci_activate_resource(device_t bus, device_t child, int type, int rid,
- struct resource *res)
-{
- struct ofw_pci_softc *sc;
- void *p;
-
- sc = device_get_softc(bus);
-
- if (type == SYS_RES_IRQ) {
- return (bus_activate_resource(bus, type, rid, res));
- }
- if (type == SYS_RES_MEMORY || type == SYS_RES_IOPORT) {
- struct ofw_pci_range *rp;
- vm_offset_t start;
- int space;
-
- start = (vm_offset_t)rman_get_start(res);
-
- /*
- * Map this through the ranges list
- */
- for (rp = sc->sc_range; rp < sc->sc_range + sc->sc_nrange &&
- rp->pci_hi != 0; rp++) {
- if (start < rp->pci || start >= rp->pci + rp->size)
- continue;
-
- switch (rp->pci_hi & OFW_PCI_PHYS_HI_SPACEMASK) {
- case OFW_PCI_PHYS_HI_SPACE_IO:
- space = SYS_RES_IOPORT;
- break;
- case OFW_PCI_PHYS_HI_SPACE_MEM32:
- case OFW_PCI_PHYS_HI_SPACE_MEM64:
- space = SYS_RES_MEMORY;
- break;
- default:
- space = -1;
- }
-
- if (type == space) {
- start += (rp->host - rp->pci);
- break;
- }
- }
-
- if (bootverbose)
- printf("ofw_pci mapdev: start %zx, len %ld\n", start,
- rman_get_size(res));
-
- p = pmap_mapdev(start, (vm_size_t)rman_get_size(res));
- if (p == NULL)
- return (ENOMEM);
-
- rman_set_virtual(res, p);
- rman_set_bustag(res, &bs_le_tag);
- rman_set_bushandle(res, (u_long)p);
- }
-
- return (rman_activate_resource(res));
-}
-
-static int
-ofw_pci_deactivate_resource(device_t bus, device_t child, int type, int rid,
- struct resource *res)
-{
- /*
- * If this is a memory resource, unmap it.
- */
- if ((type == SYS_RES_MEMORY) || (type == SYS_RES_IOPORT)) {
- u_int32_t psize;
-
- psize = rman_get_size(res);
- pmap_unmapdev((vm_offset_t)rman_get_virtual(res), psize);
- }
-
- return (rman_deactivate_resource(res));
-}
-
-static int
-ofw_pci_adjust_resource(device_t bus, device_t child, int type,
- struct resource *res, rman_res_t start, rman_res_t end)
-{
- struct rman *rm = NULL;
- struct ofw_pci_softc *sc = device_get_softc(bus);
-
- KASSERT(!(rman_get_flags(res) & RF_ACTIVE),
- ("active resources cannot be adjusted"));
- if (rman_get_flags(res) & RF_ACTIVE)
- return (EINVAL);
-
- switch (type) {
- case SYS_RES_MEMORY:
- rm = &sc->sc_mem_rman;
- break;
- case SYS_RES_IOPORT:
- rm = &sc->sc_io_rman;
- break;
- default:
- return (ENXIO);
- }
-
- if (!rman_is_region_manager(res, rm))
- return (EINVAL);
-
- return (rman_adjust_resource(res, start, end));
-}
-
-
-static phandle_t
-ofw_pci_get_node(device_t bus, device_t dev)
-{
- struct ofw_pci_softc *sc;
-
- sc = device_get_softc(bus);
- /* We only have one child, the PCI bus, which needs our own node. */
-
- return (sc->sc_node);
-}
-
-static int
-ofw_pci_nranges(phandle_t node)
-{
- int host_address_cells = 1, pci_address_cells = 3, size_cells = 2;
- ssize_t nbase_ranges;
-
- OF_getencprop(OF_parent(node), "#address-cells", &host_address_cells,
- sizeof(host_address_cells));
- OF_getencprop(node, "#address-cells", &pci_address_cells,
- sizeof(pci_address_cells));
- OF_getencprop(node, "#size-cells", &size_cells, sizeof(size_cells));
-
- nbase_ranges = OF_getproplen(node, "ranges");
- if (nbase_ranges <= 0)
- return (-1);
-
- return (nbase_ranges / sizeof(cell_t) /
- (pci_address_cells + host_address_cells + size_cells));
-}
-
-static int
-ofw_pci_fill_ranges(phandle_t node, struct ofw_pci_range *ranges)
-{
- int host_address_cells = 1, pci_address_cells = 3, size_cells = 2;
- cell_t *base_ranges;
- ssize_t nbase_ranges;
- int nranges;
- int i, j, k;
-
- OF_getencprop(OF_parent(node), "#address-cells", &host_address_cells,
- sizeof(host_address_cells));
- OF_getencprop(node, "#address-cells", &pci_address_cells,
- sizeof(pci_address_cells));
- OF_getencprop(node, "#size-cells", &size_cells, sizeof(size_cells));
-
- nbase_ranges = OF_getproplen(node, "ranges");
- if (nbase_ranges <= 0)
- return (-1);
- nranges = nbase_ranges / sizeof(cell_t) /
- (pci_address_cells + host_address_cells + size_cells);
-
- base_ranges = malloc(nbase_ranges, M_DEVBUF, M_WAITOK);
- OF_getencprop(node, "ranges", base_ranges, nbase_ranges);
-
- for (i = 0, j = 0; i < nranges; i++) {
- ranges[i].pci_hi = base_ranges[j++];
- ranges[i].pci = 0;
- for (k = 0; k < pci_address_cells - 1; k++) {
- ranges[i].pci <<= 32;
- ranges[i].pci |= base_ranges[j++];
- }
- ranges[i].host = 0;
- for (k = 0; k < host_address_cells; k++) {
- ranges[i].host <<= 32;
- ranges[i].host |= base_ranges[j++];
- }
- ranges[i].size = 0;
- for (k = 0; k < size_cells; k++) {
- ranges[i].size <<= 32;
- ranges[i].size |= base_ranges[j++];
- }
- }
-
- free(base_ranges, M_DEVBUF);
- return (nranges);
-}
-
Index: sys/powerpc/ofw/ofw_pcib_pci.c
===================================================================
--- sys/powerpc/ofw/ofw_pcib_pci.c
+++ sys/powerpc/ofw/ofw_pcib_pci.c
@@ -36,9 +36,9 @@
#include <sys/kernel.h>
#include <dev/ofw/openfirm.h>
-#include <dev/ofw/ofw_pci.h>
#include <dev/ofw/ofw_bus.h>
#include <dev/ofw/ofw_bus_subr.h>
+#include <dev/ofw/ofw_pci.h>
#include <dev/pci/pcivar.h>
#include <dev/pci/pcireg.h>
Index: sys/powerpc/ofw/ofw_pcibus.h
===================================================================
--- sys/powerpc/ofw/ofw_pcibus.h
+++ sys/powerpc/ofw/ofw_pcibus.h
@@ -33,6 +33,7 @@
#include <sys/pciio.h>
#include <dev/ofw/ofw_bus.h>
+#include <dev/ofw/ofw_bus_subr.h>
#include <dev/ofw/ofw_pci.h>
#include <dev/pci/pcivar.h>
Index: sys/powerpc/ofw/ofw_pcibus.c
===================================================================
--- sys/powerpc/ofw/ofw_pcibus.c
+++ sys/powerpc/ofw/ofw_pcibus.c
@@ -54,8 +54,6 @@
#include "pcib_if.h"
#include "pci_if.h"
-typedef uint32_t ofw_pci_intr_t;
-
/* Methods */
static device_probe_t ofw_pcibus_probe;
static device_attach_t ofw_pcibus_attach;
Index: sys/powerpc/ofw/ofw_syscons.c
===================================================================
--- sys/powerpc/ofw/ofw_syscons.c
+++ sys/powerpc/ofw/ofw_syscons.c
@@ -53,6 +53,7 @@
#include <dev/ofw/openfirm.h>
#include <dev/ofw/ofw_bus.h>
+#include <dev/ofw/ofw_bus_subr.h>
#include <dev/ofw/ofw_pci.h>
#include <powerpc/ofw/ofw_syscons.h>
Index: sys/powerpc/powermac/cpcht.c
===================================================================
--- sys/powerpc/powermac/cpcht.c
+++ sys/powerpc/powermac/cpcht.c
@@ -36,7 +36,6 @@
#include <sys/rman.h>
#include <dev/ofw/openfirm.h>
-#include <dev/ofw/ofw_pci.h>
#include <dev/pci/pcivar.h>
#include <dev/pci/pcireg.h>
@@ -51,7 +50,7 @@
#include <dev/ofw/ofw_bus.h>
#include <dev/ofw/ofw_bus_subr.h>
-#include <powerpc/ofw/ofw_pci.h>
+#include <dev/ofw/ofw_pci.h>
#include <vm/vm.h>
#include <vm/pmap.h>
Index: sys/powerpc/powermac/grackle.c
===================================================================
--- sys/powerpc/powermac/grackle.c
+++ sys/powerpc/powermac/grackle.c
@@ -37,9 +37,9 @@
#include <sys/proc.h>
#include <dev/ofw/openfirm.h>
-#include <dev/ofw/ofw_pci.h>
#include <dev/ofw/ofw_bus.h>
#include <dev/ofw/ofw_bus_subr.h>
+#include <dev/ofw/ofw_pci.h>
#include <dev/pci/pcivar.h>
#include <dev/pci/pcireg.h>
@@ -52,7 +52,6 @@
#include <sys/rman.h>
-#include <powerpc/ofw/ofw_pci.h>
#include <powerpc/powermac/gracklevar.h>
#include <vm/vm.h>
Index: sys/powerpc/powermac/uninorth.c
===================================================================
--- sys/powerpc/powermac/uninorth.c
+++ sys/powerpc/powermac/uninorth.c
@@ -33,9 +33,9 @@
#include <sys/kernel.h>
#include <dev/ofw/openfirm.h>
-#include <dev/ofw/ofw_pci.h>
#include <dev/ofw/ofw_bus.h>
#include <dev/ofw/ofw_bus_subr.h>
+#include <dev/ofw/ofw_pci.h>
#include <dev/pci/pcivar.h>
#include <dev/pci/pcireg.h>
Index: sys/powerpc/powermac/uninorthpci.c
===================================================================
--- sys/powerpc/powermac/uninorthpci.c
+++ sys/powerpc/powermac/uninorthpci.c
@@ -34,9 +34,9 @@
#include <sys/kernel.h>
#include <dev/ofw/openfirm.h>
-#include <dev/ofw/ofw_pci.h>
#include <dev/ofw/ofw_bus.h>
#include <dev/ofw/ofw_bus_subr.h>
+#include <dev/ofw/ofw_pci.h>
#include <dev/pci/pcivar.h>
#include <dev/pci/pcireg.h>
@@ -49,7 +49,6 @@
#include <sys/rman.h>
-#include <powerpc/ofw/ofw_pci.h>
#include <powerpc/powermac/uninorthvar.h>
#include <vm/vm.h>
Index: sys/powerpc/powermac/uninorthvar.h
===================================================================
--- sys/powerpc/powermac/uninorthvar.h
+++ sys/powerpc/powermac/uninorthvar.h
@@ -30,7 +30,6 @@
#include <dev/ofw/ofw_bus_subr.h>
#include <dev/ofw/ofw_pci.h>
-#include <powerpc/ofw/ofw_pci.h>
struct uninorth_softc {
struct ofw_pci_softc pci_sc;
Index: sys/powerpc/pseries/rtas_pci.c
===================================================================
--- sys/powerpc/pseries/rtas_pci.c
+++ sys/powerpc/pseries/rtas_pci.c
@@ -34,9 +34,9 @@
#include <sys/kernel.h>
#include <dev/ofw/openfirm.h>
-#include <dev/ofw/ofw_pci.h>
#include <dev/ofw/ofw_bus.h>
#include <dev/ofw/ofw_bus_subr.h>
+#include <dev/ofw/ofw_pci.h>
#include <dev/pci/pcivar.h>
#include <dev/pci/pcireg.h>
@@ -53,7 +53,6 @@
#include <vm/vm.h>
#include <vm/pmap.h>
-#include <powerpc/ofw/ofw_pci.h>
#include <powerpc/pseries/plpar_iommu.h>
#include "pcib_if.h"
Index: sys/sparc64/ebus/ebus.c
===================================================================
--- sys/sparc64/ebus/ebus.c
+++ sys/sparc64/ebus/ebus.c
@@ -74,6 +74,7 @@
#include <dev/ofw/ofw_bus.h>
#include <dev/ofw/ofw_bus_subr.h>
#include <dev/ofw/openfirm.h>
+#include <dev/ofw/ofw_pci.h>
#include <machine/bus.h>
#ifndef SUN4V
@@ -85,8 +86,6 @@
#include <dev/pci/pcireg.h>
#include <dev/pci/pcivar.h>
-#include <sparc64/pci/ofw_pci.h>
-
/*
* The register, interrupt map and for the PCI variant also the ranges
* properties are identical to the ISA ones.
Index: sys/sparc64/isa/isa.c
===================================================================
--- sys/sparc64/isa/isa.c
+++ sys/sparc64/isa/isa.c
@@ -44,13 +44,14 @@
#include <dev/ofw/ofw_bus.h>
#include <dev/ofw/openfirm.h>
+#include <dev/ofw/ofw_bus_subr.h>
+#include <dev/ofw/ofw_pci.h>
#include <machine/resource.h>
#include <dev/pci/pcireg.h>
#include <dev/pci/pcivar.h>
-#include <sparc64/pci/ofw_pci.h>
#include <sparc64/isa/ofw_isa.h>
/* There can be only one ISA bus, so it is safe to use globals. */
Index: sys/sparc64/isa/ofw_isa.c
===================================================================
--- sys/sparc64/isa/ofw_isa.c
+++ sys/sparc64/isa/ofw_isa.c
@@ -65,14 +65,15 @@
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/bus.h>
+#include <sys/rman.h>
#include <dev/ofw/ofw_bus_subr.h>
#include <dev/ofw/openfirm.h>
+#include <dev/ofw/ofw_pci.h>
#include <machine/bus.h>
#include <machine/resource.h>
-#include <sparc64/pci/ofw_pci.h>
#include <sparc64/isa/ofw_isa.h>
#include "pcib_if.h"
@@ -83,9 +84,9 @@
int ps = ISA_RANGE_PS(range);
switch (ps) {
- case OFW_PCI_CS_IO:
+ case OFW_PCI_IO:
return (SYS_RES_IOPORT);
- case OFW_PCI_CS_MEM32:
+ case OFW_PCI_MEM32:
return (SYS_RES_MEMORY);
default:
panic("ofw_isa_range_restype: illegal space %x", ps);
Index: sys/sparc64/pci/apb.c
===================================================================
--- sys/sparc64/pci/apb.c
+++ sys/sparc64/pci/apb.c
@@ -53,6 +53,8 @@
#include <dev/ofw/ofw_bus.h>
#include <dev/ofw/openfirm.h>
+#include <dev/ofw/ofw_bus_subr.h>
+#include <dev/ofw/ofw_pci.h>
#include <machine/bus.h>
#include <machine/resource.h>
@@ -63,7 +65,6 @@
#include "pcib_if.h"
-#include <sparc64/pci/ofw_pci.h>
#include <sparc64/pci/ofw_pcib_subr.h>
/*
Index: sys/sparc64/pci/fire.c
===================================================================
--- sys/sparc64/pci/fire.c
+++ sys/sparc64/pci/fire.c
@@ -60,6 +60,8 @@
#include <dev/ofw/ofw_bus.h>
#include <dev/ofw/openfirm.h>
+#include <dev/ofw/ofw_bus_subr.h>
+#include <dev/ofw/ofw_pci.h>
#include <vm/vm.h>
#include <vm/pmap.h>
@@ -74,7 +76,6 @@
#include <dev/pci/pcireg.h>
#include <dev/pci/pcivar.h>
-#include <sparc64/pci/ofw_pci.h>
#include <sparc64/pci/firereg.h>
#include <sparc64/pci/firevar.h>
@@ -136,8 +137,8 @@
DEVMETHOD(bus_setup_intr, fire_setup_intr),
DEVMETHOD(bus_teardown_intr, fire_teardown_intr),
DEVMETHOD(bus_alloc_resource, fire_alloc_resource),
- DEVMETHOD(bus_activate_resource, ofw_pci_activate_resource),
- DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
+ DEVMETHOD(bus_activate_resource, sparc64_ofw_pci_activate_resource),
+ DEVMETHOD(bus_deactivate_resource, sparc64_ofw_pci_deactivate_resource),
DEVMETHOD(bus_adjust_resource, ofw_pci_adjust_resource),
DEVMETHOD(bus_release_resource, bus_generic_release_resource),
DEVMETHOD(bus_get_dma_tag, ofw_pci_get_dma_tag),
Index: sys/sparc64/pci/ofw_pci.h
===================================================================
--- sys/sparc64/pci/ofw_pci.h
+++ /dev/null
@@ -1,170 +0,0 @@
-/*-
- * Copyright (c) 1999, 2000 Matthew R. Green
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*-
- * Copyright (c) 1998, 1999 Eduardo E. Horvath
- * Copyright (c) 2001, 2003 by Thomas Moestl <tmm@FreeBSD.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * from: NetBSD: psychoreg.h,v 1.14 2008/05/30 02:29:37 mrg Exp
- *
- * $FreeBSD$
- */
-
-#ifndef _SPARC64_PCI_OFW_PCI_H_
-#define _SPARC64_PCI_OFW_PCI_H_
-
-#include <sys/rman.h>
-
-#include <dev/ofw/ofw_bus_subr.h>
-
-#include "ofw_pci_if.h"
-
-typedef uint32_t ofw_pci_intr_t;
-
-/* PCI range child spaces. XXX: are these MI? */
-#define OFW_PCI_CS_CONFIG 0x00
-#define OFW_PCI_CS_IO 0x01
-#define OFW_PCI_CS_MEM32 0x02
-#define OFW_PCI_CS_MEM64 0x03
-#define OFW_PCI_NUM_CS 4
-
-/* OFW device types */
-#define OFW_TYPE_PCI "pci"
-#define OFW_TYPE_PCIE "pciex"
-
-struct ofw_pci_msi_addr_ranges {
- uint32_t addr32_hi;
- uint32_t addr32_lo;
- uint32_t addr32_sz;
- uint32_t addr64_hi;
- uint32_t addr64_lo;
- uint32_t addr64_sz;
-};
-
-#define OFW_PCI_MSI_ADDR_RANGE_32(r) \
- (((uint64_t)(r)->addr32_hi << 32) | (uint64_t)(r)->addr32_lo)
-#define OFW_PCI_MSI_ADDR_RANGE_64(r) \
- (((uint64_t)(r)->addr64_hi << 32) | (uint64_t)(r)->addr64_lo)
-
-struct ofw_pci_msi_eq_to_devino {
- uint32_t eq_first;
- uint32_t eq_count;
- uint32_t devino_first;
-};
-
-struct ofw_pci_msi_ranges {
- uint32_t first;
- uint32_t count;
-};
-
-struct ofw_pci_ranges {
- uint32_t cspace;
- uint32_t child_hi;
- uint32_t child_lo;
- uint32_t phys_hi;
- uint32_t phys_lo;
- uint32_t size_hi;
- uint32_t size_lo;
-};
-
-#define OFW_PCI_RANGE_CHILD(r) \
- (((uint64_t)(r)->child_hi << 32) | (uint64_t)(r)->child_lo)
-#define OFW_PCI_RANGE_PHYS(r) \
- (((uint64_t)(r)->phys_hi << 32) | (uint64_t)(r)->phys_lo)
-#define OFW_PCI_RANGE_SIZE(r) \
- (((uint64_t)(r)->size_hi << 32) | (uint64_t)(r)->size_lo)
-#define OFW_PCI_RANGE_CS(r) (((r)->cspace >> 24) & 0x03)
-
-/* default values */
-#define OFW_PCI_LATENCY 64
-
-/*
- * Common and generic parts of host-PCI-bridge support
- */
-
-struct ofw_pci_softc {
- struct rman sc_pci_mem_rman;
- struct rman sc_pci_io_rman;
-
- bus_space_handle_t sc_pci_bh[OFW_PCI_NUM_CS];
- bus_space_tag_t sc_pci_cfgt;
- bus_space_tag_t sc_pci_iot;
- bus_dma_tag_t sc_pci_dmat;
-
- struct ofw_bus_iinfo sc_pci_iinfo;
-
- phandle_t sc_node;
-
- uint8_t sc_pci_secbus;
- uint8_t sc_pci_subbus;
-};
-
-int ofw_pci_attach_common(device_t dev, bus_dma_tag_t dmat, u_long iosize,
- u_long memsize);
-uint32_t ofw_pci_read_config_common(device_t dev, u_int regmax, u_long offset,
- u_int bus, u_int slot, u_int func, u_int reg, int width);
-void ofw_pci_write_config_common(device_t dev, u_int regmax, u_long offset,
- u_int bus, u_int slot, u_int func, u_int reg, uint32_t val, int width);
-ofw_pci_intr_t ofw_pci_route_interrupt_common(device_t bridge, device_t dev,
- int pin);
-
-void ofw_pci_dmamap_sync_stst_order_common(void);
-
-bus_activate_resource_t ofw_pci_activate_resource;
-bus_adjust_resource_t ofw_pci_adjust_resource;
-bus_alloc_resource_t ofw_pci_alloc_resource;
-bus_get_dma_tag_t ofw_pci_get_dma_tag;
-bus_read_ivar_t ofw_pci_read_ivar;
-
-ofw_bus_get_node_t ofw_pci_get_node;
-
-#endif /* ! _SPARC64_PCI_OFW_PCI_H_ */
Index: sys/sparc64/pci/ofw_pci.c
===================================================================
--- sys/sparc64/pci/ofw_pci.c
+++ /dev/null
@@ -1,406 +0,0 @@
-/*-
- * Copyright (c) 1999, 2000 Matthew R. Green
- * Copyright (c) 2001 - 2003 by Thomas Moestl <tmm@FreeBSD.org>
- * Copyright (c) 2005 - 2015 by Marius Strobl <marius@FreeBSD.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * from: NetBSD: psycho.c,v 1.35 2001/09/10 16:17:06 eeh Exp
- */
-
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
-#include "opt_ofw_pci.h"
-
-#include <sys/param.h>
-#include <sys/systm.h>
-#include <sys/bus.h>
-#include <sys/kernel.h>
-#include <sys/rman.h>
-
-#include <dev/ofw/ofw_bus.h>
-#include <dev/ofw/ofw_pci.h>
-#include <dev/ofw/openfirm.h>
-
-#include <dev/pci/pcireg.h>
-#include <dev/pci/pcivar.h>
-
-#include <machine/asi.h>
-#include <machine/bus.h>
-#include <machine/bus_private.h>
-#include <machine/cpufunc.h>
-#include <machine/fsr.h>
-#include <machine/resource.h>
-
-#include <sparc64/pci/ofw_pci.h>
-
-int
-ofw_pci_attach_common(device_t dev, bus_dma_tag_t dmat, u_long iosize,
- u_long memsize)
-{
- struct ofw_pci_softc *sc;
- struct ofw_pci_ranges *range;
- phandle_t node;
- uint32_t prop_array[2];
- u_int i, j, nrange;
-
- sc = device_get_softc(dev);
- node = ofw_bus_get_node(dev);
- sc->sc_node = node;
- sc->sc_pci_dmat = dmat;
-
- /* Initialize memory and I/O rmans. */
- sc->sc_pci_io_rman.rm_type = RMAN_ARRAY;
- sc->sc_pci_io_rman.rm_descr = "PCI I/O Ports";
- if (rman_init(&sc->sc_pci_io_rman) != 0 ||
- rman_manage_region(&sc->sc_pci_io_rman, 0, iosize) != 0) {
- device_printf(dev, "failed to set up I/O rman\n");
- return (ENXIO);
- }
- sc->sc_pci_mem_rman.rm_type = RMAN_ARRAY;
- sc->sc_pci_mem_rman.rm_descr = "PCI Memory";
- if (rman_init(&sc->sc_pci_mem_rman) != 0 ||
- rman_manage_region(&sc->sc_pci_mem_rman, 0, memsize) != 0) {
- device_printf(dev, "failed to set up memory rman\n");
- return (ENXIO);
- }
-
- /*
- * Find the addresses of the various bus spaces. The physical
- * start addresses of the ranges are the configuration, I/O and
- * memory handles. There should not be multiple ones of one kind.
- */
- nrange = OF_getprop_alloc(node, "ranges", sizeof(*range),
- (void **)&range);
- for (i = 0; i < nrange; i++) {
- j = OFW_PCI_RANGE_CS(&range[i]);
- if (sc->sc_pci_bh[j] != 0) {
- device_printf(dev, "duplicate range for space %d\n",
- j);
- free(range, M_OFWPROP);
- return (EINVAL);
- }
- sc->sc_pci_bh[j] = OFW_PCI_RANGE_PHYS(&range[i]);
- }
- free(range, M_OFWPROP);
-
- /*
- * Make sure that the expected ranges are actually present.
- * The OFW_PCI_CS_MEM64 one is not currently used.
- */
- if (sc->sc_pci_bh[OFW_PCI_CS_CONFIG] == 0) {
- device_printf(dev, "missing CONFIG range\n");
- return (ENXIO);
- }
- if (sc->sc_pci_bh[OFW_PCI_CS_IO] == 0) {
- device_printf(dev, "missing IO range\n");
- return (ENXIO);
- }
- if (sc->sc_pci_bh[OFW_PCI_CS_MEM32] == 0) {
- device_printf(dev, "missing MEM32 range\n");
- return (ENXIO);
- }
-
- /* Allocate our tags. */
- sc->sc_pci_iot = sparc64_alloc_bus_tag(NULL, PCI_IO_BUS_SPACE);
- if (sc->sc_pci_iot == NULL) {
- device_printf(dev, "could not allocate PCI I/O tag\n");
- return (ENXIO);
- }
- sc->sc_pci_cfgt = sparc64_alloc_bus_tag(NULL, PCI_CONFIG_BUS_SPACE);
- if (sc->sc_pci_cfgt == NULL) {
- device_printf(dev,
- "could not allocate PCI configuration space tag\n");
- return (ENXIO);
- }
-
- /*
- * Get the bus range from the firmware.
- */
- i = OF_getprop(node, "bus-range", (void *)prop_array,
- sizeof(prop_array));
- if (i == -1) {
- device_printf(dev, "could not get bus-range\n");
- return (ENXIO);
- }
- if (i != sizeof(prop_array)) {
- device_printf(dev, "broken bus-range (%d)", i);
- return (EINVAL);
- }
- sc->sc_pci_secbus = prop_array[0];
- sc->sc_pci_subbus = prop_array[1];
- if (bootverbose != 0)
- device_printf(dev, "bus range %u to %u; PCI bus %d\n",
- sc->sc_pci_secbus, sc->sc_pci_subbus, sc->sc_pci_secbus);
-
- ofw_bus_setup_iinfo(node, &sc->sc_pci_iinfo, sizeof(ofw_pci_intr_t));
-
- return (0);
-}
-
-uint32_t
-ofw_pci_read_config_common(device_t dev, u_int regmax, u_long offset,
- u_int bus, u_int slot, u_int func, u_int reg, int width)
-{
- struct ofw_pci_softc *sc;
- bus_space_handle_t bh;
- uint32_t r, wrd;
- int i;
- uint16_t shrt;
- uint8_t byte;
-
- sc = device_get_softc(dev);
- if (bus < sc->sc_pci_secbus || bus > sc->sc_pci_subbus ||
- slot > PCI_SLOTMAX || func > PCI_FUNCMAX || reg > regmax)
- return (-1);
-
- bh = sc->sc_pci_bh[OFW_PCI_CS_CONFIG];
- 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 %d", __func__, width);
- /* NOTREACHED */
- }
-
- if (i) {
-#ifdef OFW_PCI_DEBUG
- printf("%s: read data error reading: %d.%d.%d: 0x%x\n",
- __func__, bus, slot, func, reg);
-#endif
- r = -1;
- }
- return (r);
-}
-
-void
-ofw_pci_write_config_common(device_t dev, u_int regmax, u_long offset,
- u_int bus, u_int slot, u_int func, u_int reg, uint32_t val, int width)
-{
- struct ofw_pci_softc *sc;
- bus_space_handle_t bh;
-
- sc = device_get_softc(dev);
- if (bus < sc->sc_pci_secbus || bus > sc->sc_pci_subbus ||
- slot > PCI_SLOTMAX || func > PCI_FUNCMAX || reg > regmax)
- return;
-
- 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 %d", __func__, width);
- /* NOTREACHED */
- }
-}
-
-ofw_pci_intr_t
-ofw_pci_route_interrupt_common(device_t bridge, device_t dev, int pin)
-{
- struct ofw_pci_softc *sc;
- struct ofw_pci_register reg;
- ofw_pci_intr_t pintr, mintr;
-
- 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) != 0)
- return (mintr);
- return (PCI_INVALID_IRQ);
-}
-
-void
-ofw_pci_dmamap_sync_stst_order_common(void)
-{
- static u_char buf[VIS_BLOCKSIZE] __aligned(VIS_BLOCKSIZE);
- register_t reg, s;
-
- s = intr_disable();
- reg = rd(fprs);
- wr(fprs, reg | FPRS_FEF, 0);
- __asm __volatile("stda %%f0, [%0] %1"
- : : "r" (buf), "n" (ASI_BLK_COMMIT_S));
- membar(Sync);
- wr(fprs, reg, 0);
- intr_restore(s);
-}
-
-int
-ofw_pci_read_ivar(device_t dev, device_t child __unused, int which,
- uintptr_t *result)
-{
- struct ofw_pci_softc *sc;
-
- switch (which) {
- case PCIB_IVAR_DOMAIN:
- *result = device_get_unit(dev);
- return (0);
- case PCIB_IVAR_BUS:
- sc = device_get_softc(dev);
- *result = sc->sc_pci_secbus;
- return (0);
- }
- return (ENOENT);
-}
-
-struct resource *
-ofw_pci_alloc_resource(device_t bus, device_t child, int type, int *rid,
- rman_res_t start, rman_res_t end, rman_res_t count, u_int flags)
-{
- struct ofw_pci_softc *sc;
- struct resource *rv;
- struct rman *rm;
-
- 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__);
- 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);
- }
-
- 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);
-}
-
-int
-ofw_pci_activate_resource(device_t bus, device_t child, int type, int rid,
- struct resource *r)
-{
- struct ofw_pci_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, PCI_MEMORY_BUS_SPACE);
- 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));
-}
-
-int
-ofw_pci_adjust_resource(device_t bus, device_t child, int type,
- struct resource *r, rman_res_t start, rman_res_t end)
-{
- struct ofw_pci_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));
-}
-
-bus_dma_tag_t
-ofw_pci_get_dma_tag(device_t bus, device_t child __unused)
-{
- struct ofw_pci_softc *sc;
-
- sc = device_get_softc(bus);
- return (sc->sc_pci_dmat);
-}
-
-phandle_t
-ofw_pci_get_node(device_t bus, device_t child __unused)
-{
- struct ofw_pci_softc *sc;
-
- sc = device_get_softc(bus);
- /* We only have one child, the PCI bus, which needs our own node. */
- return (sc->sc_node);
-}
Index: sys/sparc64/pci/ofw_pcib.c
===================================================================
--- sys/sparc64/pci/ofw_pcib.c
+++ sys/sparc64/pci/ofw_pcib.c
@@ -46,14 +46,16 @@
#include <dev/ofw/ofw_bus.h>
#include <dev/ofw/openfirm.h>
+#include <dev/ofw/ofw_bus_subr.h>
+#include <dev/ofw/ofw_pci.h>
#include <dev/pci/pcireg.h>
#include <dev/pci/pcivar.h>
#include <dev/pci/pcib_private.h>
#include "pcib_if.h"
+#include "ofw_pci_if.h"
-#include <sparc64/pci/ofw_pci.h>
#include <sparc64/pci/ofw_pcib_subr.h>
#define PCI_DEVID_ALI_M5249 0x524910b9
Index: sys/sparc64/pci/ofw_pcib_subr.c
===================================================================
--- sys/sparc64/pci/ofw_pcib_subr.c
+++ sys/sparc64/pci/ofw_pcib_subr.c
@@ -34,8 +34,9 @@
#include <sys/rman.h>
#include <dev/ofw/ofw_bus.h>
-#include <dev/ofw/ofw_pci.h>
#include <dev/ofw/openfirm.h>
+#include <dev/ofw/ofw_bus_subr.h>
+#include <dev/ofw/ofw_pci.h>
#include <machine/bus.h>
@@ -45,7 +46,6 @@
#include "pcib_if.h"
-#include <sparc64/pci/ofw_pci.h>
#include <sparc64/pci/ofw_pcib_subr.h>
void
Index: sys/sparc64/pci/ofw_pcibus.c
===================================================================
--- sys/sparc64/pci/ofw_pcibus.c
+++ sys/sparc64/pci/ofw_pcibus.c
@@ -39,10 +39,12 @@
#include <sys/libkern.h>
#include <sys/module.h>
#include <sys/pciio.h>
+#include <sys/rman.h>
#include <dev/ofw/ofw_bus.h>
-#include <dev/ofw/ofw_pci.h>
#include <dev/ofw/openfirm.h>
+#include <dev/ofw/ofw_bus_subr.h>
+#include <dev/ofw/ofw_pci.h>
#include <machine/bus.h>
#ifndef SUN4V
@@ -55,10 +57,9 @@
#include <dev/pci/pcivar.h>
#include <dev/pci/pci_private.h>
-#include <sparc64/pci/ofw_pci.h>
-
#include "pcib_if.h"
#include "pci_if.h"
+#include "ofw_pci_if.h"
/* Helper functions */
static void ofw_pcibus_setup_device(device_t bridge, uint32_t clock,
Index: sys/sparc64/pci/psycho.c
===================================================================
--- sys/sparc64/pci/psycho.c
+++ sys/sparc64/pci/psycho.c
@@ -58,6 +58,8 @@
#include <dev/ofw/ofw_bus.h>
#include <dev/ofw/openfirm.h>
+#include <dev/ofw/ofw_bus_subr.h>
+#include <dev/ofw/ofw_pci.h>
#include <machine/bus.h>
#include <machine/bus_common.h>
@@ -70,11 +72,11 @@
#include <dev/pci/pcireg.h>
#include <dev/pci/pcivar.h>
-#include <sparc64/pci/ofw_pci.h>
#include <sparc64/pci/psychoreg.h>
#include <sparc64/pci/psychovar.h>
#include "pcib_if.h"
+#include "ofw_pci_if.h"
static const struct psycho_desc *psycho_find_desc(const struct psycho_desc *,
const char *);
@@ -130,8 +132,8 @@
DEVMETHOD(bus_setup_intr, psycho_setup_intr),
DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
DEVMETHOD(bus_alloc_resource, psycho_alloc_resource),
- DEVMETHOD(bus_activate_resource, ofw_pci_activate_resource),
- DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
+ DEVMETHOD(bus_activate_resource, sparc64_ofw_pci_activate_resource),
+ DEVMETHOD(bus_deactivate_resource, sparc64_ofw_pci_deactivate_resource),
DEVMETHOD(bus_adjust_resource, ofw_pci_adjust_resource),
DEVMETHOD(bus_release_resource, bus_generic_release_resource),
DEVMETHOD(bus_get_dma_tag, ofw_pci_get_dma_tag),
@@ -541,8 +543,8 @@
panic("%s: ofw_pci_attach_common() failed", __func__);
/* Clear any pending PCI error bits. */
- 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,
+ PCIB_WRITE_CONFIG(dev, sc->sc_ops.sc_secbus, PCS_DEVICE, PCS_FUNC,
+ PCIR_STATUS, PCIB_READ_CONFIG(dev, sc->sc_ops.sc_secbus,
PCS_DEVICE, PCS_FUNC, PCIR_STATUS, 2), 2);
PCICTL_WRITE8(sc, PCR_CS, PCICTL_READ8(sc, PCR_CS));
PCICTL_WRITE8(sc, PCR_AFS, PCICTL_READ8(sc, PCR_AFS));
@@ -605,19 +607,19 @@
* Set the latency timer register as this isn't always done by the
* firmware.
*/
- PCIB_WRITE_CONFIG(dev, sc->sc_ops.sc_pci_secbus, PCS_DEVICE, PCS_FUNC,
+ PCIB_WRITE_CONFIG(dev, sc->sc_ops.sc_secbus, PCS_DEVICE, PCS_FUNC,
PCIR_LATTIMER, OFW_PCI_LATENCY, 1);
for (i = PCIR_VENDOR; i < PCIR_STATUS; i += sizeof(uint16_t))
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,
+ bus_space_read_2(sc->sc_ops.sc_cfgt,
+ sc->sc_ops.sc_bh[OFW_PCI_CONFIG],
+ PSYCHO_CONF_OFF(sc->sc_ops.sc_secbus, PCS_DEVICE,
PCS_FUNC, i)));
for (i = PCIR_REVID; i <= PCIR_BIST; i += sizeof(uint8_t))
- 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));
+ sc->sc_pci_hpbcfg[i] = bus_space_read_1(sc->sc_ops.sc_cfgt,
+ sc->sc_ops.sc_bh[OFW_PCI_CONFIG], PSYCHO_CONF_OFF(
+ sc->sc_ops.sc_secbus, PCS_DEVICE, PCS_FUNC, i));
/*
* On E250 the interrupt map entry for the EBus bridge is wrong,
@@ -882,7 +884,7 @@
* The Psycho bridges contain a dupe of their header at 0x80
* which we nullify that way also.
*/
- if (bus == sc->sc_ops.sc_pci_secbus && slot == PCS_DEVICE &&
+ if (bus == sc->sc_ops.sc_secbus && slot == PCS_DEVICE &&
func == PCS_FUNC) {
if (reg % width != 0)
return (-1);
@@ -893,9 +895,9 @@
if ((reg < PCIR_STATUS && reg + width > PCIR_STATUS) ||
reg == PCIR_STATUS || reg == PCIR_STATUS + 1)
le16enc(&sc->sc_pci_hpbcfg[PCIR_STATUS],
- 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,
+ bus_space_read_2(sc->sc_ops.sc_cfgt,
+ sc->sc_ops.sc_bh[OFW_PCI_CONFIG],
+ PSYCHO_CONF_OFF(sc->sc_ops.sc_secbus,
PCS_DEVICE, PCS_FUNC, PCIR_STATUS)));
switch (width) {
Index: sys/sparc64/pci/schizo.c
===================================================================
--- sys/sparc64/pci/schizo.c
+++ sys/sparc64/pci/schizo.c
@@ -58,6 +58,8 @@
#include <dev/ofw/ofw_bus.h>
#include <dev/ofw/openfirm.h>
+#include <dev/ofw/ofw_bus_subr.h>
+#include <dev/ofw/ofw_pci.h>
#include <machine/bus.h>
#include <machine/bus_common.h>
@@ -69,11 +71,11 @@
#include <dev/pci/pcireg.h>
#include <dev/pci/pcivar.h>
-#include <sparc64/pci/ofw_pci.h>
#include <sparc64/pci/schizoreg.h>
#include <sparc64/pci/schizovar.h>
#include "pcib_if.h"
+#include "ofw_pci_if.h"
static const struct schizo_desc *schizo_get_desc(device_t);
static void schizo_set_intr(struct schizo_softc *, u_int, u_int,
@@ -127,8 +129,8 @@
DEVMETHOD(bus_setup_intr, schizo_setup_intr),
DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
DEVMETHOD(bus_alloc_resource, schizo_alloc_resource),
- DEVMETHOD(bus_activate_resource, ofw_pci_activate_resource),
- DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
+ DEVMETHOD(bus_activate_resource, sparc64_ofw_pci_activate_resource),
+ DEVMETHOD(bus_deactivate_resource, sparc64_ofw_pci_deactivate_resource),
DEVMETHOD(bus_adjust_resource, ofw_pci_adjust_resource),
DEVMETHOD(bus_release_resource, bus_generic_release_resource),
DEVMETHOD(bus_get_dma_tag, ofw_pci_get_dma_tag),
@@ -548,9 +550,9 @@
panic("%s: ofw_pci_attach_common() failed", __func__);
/* Clear any pending PCI error bits. */
- PCIB_WRITE_CONFIG(dev, sc->sc_ops.sc_pci_secbus, STX_CS_DEVICE,
+ PCIB_WRITE_CONFIG(dev, sc->sc_ops.sc_secbus, STX_CS_DEVICE,
STX_CS_FUNC, PCIR_STATUS, PCIB_READ_CONFIG(dev,
- sc->sc_ops.sc_pci_secbus, STX_CS_DEVICE, STX_CS_FUNC, PCIR_STATUS,
+ sc->sc_ops.sc_secbus, STX_CS_DEVICE, STX_CS_FUNC, PCIR_STATUS,
2), 2);
SCHIZO_PCI_SET(sc, STX_PCI_CTRL, SCHIZO_PCI_READ_8(sc, STX_PCI_CTRL));
SCHIZO_PCI_SET(sc, STX_PCI_AFSR, SCHIZO_PCI_READ_8(sc, STX_PCI_AFSR));
@@ -679,7 +681,7 @@
* Set the latency timer register as this isn't always done by the
* firmware.
*/
- PCIB_WRITE_CONFIG(dev, sc->sc_ops.sc_pci_secbus, STX_CS_DEVICE,
+ PCIB_WRITE_CONFIG(dev, sc->sc_ops.sc_secbus, STX_CS_DEVICE,
STX_CS_FUNC, PCIR_LATTIMER, OFW_PCI_LATENCY, 1);
#define SCHIZO_SYSCTL_ADD_UINT(name, arg, desc) \
@@ -804,7 +806,7 @@
xstat = SCHIZO_PCI_READ_8(sc, XMS_PCI_X_ERR_STAT);
else
xstat = 0;
- status = PCIB_READ_CONFIG(sc->sc_dev, sc->sc_ops.sc_pci_secbus,
+ status = PCIB_READ_CONFIG(sc->sc_dev, sc->sc_ops.sc_secbus,
STX_CS_DEVICE, STX_CS_FUNC, PCIR_STATUS, 2);
/*
@@ -845,7 +847,7 @@
(unsigned long long)iommu, (unsigned long long)xstat, status);
/* Clear the error bits that we caught. */
- PCIB_WRITE_CONFIG(sc->sc_dev, sc->sc_ops.sc_pci_secbus, STX_CS_DEVICE,
+ PCIB_WRITE_CONFIG(sc->sc_dev, sc->sc_ops.sc_secbus, STX_CS_DEVICE,
STX_CS_FUNC, PCIR_STATUS, status, 2);
SCHIZO_PCI_WRITE_8(sc, STX_PCI_CTRL, csr);
SCHIZO_PCI_WRITE_8(sc, STX_PCI_AFSR, afsr);
@@ -972,7 +974,7 @@
* The Schizo bridges contain a dupe of their header at 0x80.
*/
if (sc->sc_mode == SCHIZO_MODE_SCZ &&
- bus == sc->sc_ops.sc_pci_secbus && slot == STX_CS_DEVICE &&
+ bus == sc->sc_ops.sc_secbus && slot == STX_CS_DEVICE &&
func == STX_CS_FUNC && reg + width > 0x80)
return (0);
Index: sys/sparc64/pci/sparc64_ofw_pci.c
===================================================================
--- /dev/null
+++ sys/sparc64/pci/sparc64_ofw_pci.c
@@ -0,0 +1,317 @@
+/*-
+ * Copyright (c) 1999, 2000 Matthew R. Green
+ * Copyright (c) 2001 - 2003 by Thomas Moestl <tmm@FreeBSD.org>
+ * Copyright (c) 2005 - 2015 by Marius Strobl <marius@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * from: NetBSD: psycho.c,v 1.35 2001/09/10 16:17:06 eeh Exp
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "opt_ofw_pci.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/bus.h>
+#include <sys/kernel.h>
+#include <sys/rman.h>
+
+#include <dev/ofw/openfirm.h>
+#include <dev/ofw/ofw_bus.h>
+#include <dev/ofw/ofw_bus_subr.h>
+#include <dev/ofw/ofw_pci.h>
+
+#include <dev/pci/pcireg.h>
+#include <dev/pci/pcivar.h>
+
+#include <machine/asi.h>
+#include <machine/bus.h>
+#include <machine/bus_private.h>
+#include <machine/cpufunc.h>
+#include <machine/fsr.h>
+#include <machine/resource.h>
+
+#include "ofw_pci_if.h"
+
+static device_method_t sparc64_ofw_pci_methods[] = {
+
+ DEVMETHOD(bus_activate_resource, sparc64_ofw_pci_activate_resource),
+ DEVMETHOD(bus_deactivate_resource, sparc64_ofw_pci_deactivate_resource),
+
+ DEVMETHOD_END
+};
+
+DEFINE_CLASS_1(ofw_pci, sparc64_ofw_pci_driver, sparc64_ofw_pci_methods,
+ sizeof(struct ofw_pci_softc), ofw_pci_driver);
+
+int
+ofw_pci_attach_common(device_t dev, bus_dma_tag_t dmat, u_long iosize,
+ u_long memsize)
+{
+ struct ofw_pci_softc *sc;
+ struct ofw_pci_range *ranges;
+ phandle_t node;
+ uint32_t prop_array[2];
+ u_int i, j, nrange;
+
+ sc = device_get_softc(dev);
+ node = ofw_bus_get_node(dev);
+ sc->sc_node = node;
+ sc->sc_dmat = dmat;
+
+ /* Initialize memory and I/O rmans. */
+ sc->sc_io_rman.rm_type = RMAN_ARRAY;
+ sc->sc_io_rman.rm_descr = "PCI I/O Ports";
+ if (rman_init(&sc->sc_io_rman) != 0 ||
+ rman_manage_region(&sc->sc_io_rman, 0, iosize) != 0) {
+ device_printf(dev, "failed to set up I/O rman\n");
+ return (ENXIO);
+ }
+ sc->sc_mem_rman.rm_type = RMAN_ARRAY;
+ sc->sc_mem_rman.rm_descr = "PCI Memory";
+ if (rman_init(&sc->sc_mem_rman) != 0 ||
+ rman_manage_region(&sc->sc_mem_rman, 0, memsize) != 0) {
+ device_printf(dev, "failed to set up memory rman\n");
+ return (ENXIO);
+ }
+
+ /*
+ * Find the addresses of the various bus spaces. The physical
+ * start addresses of the ranges are the configuration, I/O and
+ * memory handles. There should not be multiple ones of one kind.
+ */
+ nrange = OF_getencprop_alloc(node, "ranges", sizeof(*ranges),
+ (void **)&ranges);
+ for (i = 0; i < nrange; i++) {
+ j = ranges[i].pci_hi & OFW_PCI_PHYS_HI_SPACEMASK;
+ if (sc->sc_bh[j] != 0) {
+ device_printf(dev, "duplicate range for space %d\n",
+ j);
+ free(ranges, M_OFWPROP);
+ return (EINVAL);
+ }
+ sc->sc_bh[j] = ranges[i].host;
+ }
+ free(ranges, M_OFWPROP);
+
+ /*
+ * Make sure that the expected ranges are actually present.
+ * The OFW_PCI_MEM64 one is not currently used.
+ */
+ if (sc->sc_bh[OFW_PCI_CONFIG] == 0) {
+ device_printf(dev, "missing CONFIG range\n");
+ return (ENXIO);
+ }
+ if (sc->sc_bh[OFW_PCI_IO] == 0) {
+ device_printf(dev, "missing IO range\n");
+ return (ENXIO);
+ }
+ if (sc->sc_bh[OFW_PCI_MEM32] == 0) {
+ device_printf(dev, "missing MEM32 range\n");
+ return (ENXIO);
+ }
+
+ /* Allocate our tags. */
+ sc->sc_iot = sparc64_alloc_bus_tag(NULL, PCI_IO_BUS_SPACE);
+ if (sc->sc_iot == NULL) {
+ device_printf(dev, "could not allocate PCI I/O tag\n");
+ return (ENXIO);
+ }
+ sc->sc_cfgt = sparc64_alloc_bus_tag(NULL, PCI_CONFIG_BUS_SPACE);
+ if (sc->sc_cfgt == NULL) {
+ device_printf(dev,
+ "could not allocate PCI configuration space tag\n");
+ return (ENXIO);
+ }
+
+ /*
+ * Get the bus range from the firmware.
+ */
+ i = OF_getprop(node, "bus-range", (void *)prop_array,
+ sizeof(prop_array));
+ if (i == -1) {
+ device_printf(dev, "could not get bus-range\n");
+ return (ENXIO);
+ }
+ if (i != sizeof(prop_array)) {
+ device_printf(dev, "broken bus-range (%d)", i);
+ return (EINVAL);
+ }
+ sc->sc_secbus = prop_array[0];
+ sc->sc_subbus = prop_array[1];
+ if (bootverbose != 0)
+ device_printf(dev, "bus range %u to %u; PCI bus %d\n",
+ sc->sc_secbus, sc->sc_subbus, sc->sc_secbus);
+
+ ofw_bus_setup_iinfo(node, &sc->sc_pci_iinfo, sizeof(ofw_pci_intr_t));
+
+ return (0);
+}
+
+uint32_t
+ofw_pci_read_config_common(device_t dev, u_int regmax, u_long offset,
+ u_int bus, u_int slot, u_int func, u_int reg, int width)
+{
+ struct ofw_pci_softc *sc;
+ bus_space_handle_t bh;
+ uint32_t r, wrd;
+ int i;
+ uint16_t shrt;
+ uint8_t byte;
+
+ sc = device_get_softc(dev);
+ if (bus < sc->sc_secbus || bus > sc->sc_subbus ||
+ slot > PCI_SLOTMAX || func > PCI_FUNCMAX || reg > regmax)
+ return (-1);
+
+ bh = sc->sc_bh[OFW_PCI_CONFIG];
+ switch (width) {
+ case 1:
+ i = bus_space_peek_1(sc->sc_cfgt, bh, offset, &byte);
+ r = byte;
+ break;
+ case 2:
+ i = bus_space_peek_2(sc->sc_cfgt, bh, offset, &shrt);
+ r = shrt;
+ break;
+ case 4:
+ i = bus_space_peek_4(sc->sc_cfgt, bh, offset, &wrd);
+ r = wrd;
+ break;
+ default:
+ panic("%s: bad width %d", __func__, width);
+ /* NOTREACHED */
+ }
+
+ if (i) {
+#ifdef OFW_PCI_DEBUG
+ printf("%s: read data error reading: %d.%d.%d: 0x%x\n",
+ __func__, bus, slot, func, reg);
+#endif
+ r = -1;
+ }
+ return (r);
+}
+
+void
+ofw_pci_write_config_common(device_t dev, u_int regmax, u_long offset,
+ u_int bus, u_int slot, u_int func, u_int reg, uint32_t val, int width)
+{
+ struct ofw_pci_softc *sc;
+ bus_space_handle_t bh;
+
+ sc = device_get_softc(dev);
+ if (bus < sc->sc_secbus || bus > sc->sc_subbus ||
+ slot > PCI_SLOTMAX || func > PCI_FUNCMAX || reg > regmax)
+ return;
+
+ bh = sc->sc_bh[OFW_PCI_CONFIG];
+ switch (width) {
+ case 1:
+ bus_space_write_1(sc->sc_cfgt, bh, offset, val);
+ break;
+ case 2:
+ bus_space_write_2(sc->sc_cfgt, bh, offset, val);
+ break;
+ case 4:
+ bus_space_write_4(sc->sc_cfgt, bh, offset, val);
+ break;
+ default:
+ panic("%s: bad width %d", __func__, width);
+ /* NOTREACHED */
+ }
+}
+
+ofw_pci_intr_t
+ofw_pci_route_interrupt_common(device_t bridge, device_t dev, int pin)
+{
+ struct ofw_pci_softc *sc;
+ struct ofw_pci_register reg;
+ ofw_pci_intr_t pintr, mintr;
+
+ 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) != 0)
+ return (mintr);
+ return (PCI_INVALID_IRQ);
+}
+
+void
+ofw_pci_dmamap_sync_stst_order_common(void)
+{
+ static u_char buf[VIS_BLOCKSIZE] __aligned(VIS_BLOCKSIZE);
+ register_t reg, s;
+
+ s = intr_disable();
+ reg = rd(fprs);
+ wr(fprs, reg | FPRS_FEF, 0);
+ __asm __volatile("stda %%f0, [%0] %1"
+ : : "r" (buf), "n" (ASI_BLK_COMMIT_S));
+ membar(Sync);
+ wr(fprs, reg, 0);
+ intr_restore(s);
+}
+
+int
+sparc64_ofw_pci_activate_resource(device_t bus, device_t child, int type, int rid,
+ struct resource *r)
+{
+ struct ofw_pci_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, PCI_MEMORY_BUS_SPACE);
+ if (tag == NULL)
+ return (ENOMEM);
+ rman_set_bustag(r, tag);
+ rman_set_bushandle(r, sc->sc_bh[OFW_PCI_MEM32] +
+ rman_get_start(r));
+ break;
+ case SYS_RES_IOPORT:
+ rman_set_bustag(r, sc->sc_iot);
+ rman_set_bushandle(r, sc->sc_bh[OFW_PCI_IO] +
+ rman_get_start(r));
+ break;
+ }
+ return (rman_activate_resource(r));
+}
+
+int
+sparc64_ofw_pci_deactivate_resource(device_t bus, device_t child,
+ int type, int rid, struct resource *r)
+{
+
+ return (bus_generic_deactivate_resource(bus, child, type, rid, r));
+}
Index: sys/sparc64/sparc64/jbusppm.c
===================================================================
--- sys/sparc64/sparc64/jbusppm.c
+++ sys/sparc64/sparc64/jbusppm.c
@@ -35,13 +35,14 @@
#include <sys/resource.h>
#include <sys/rman.h>
+#include <dev/ofw/ofw_bus_subr.h>
#include <dev/ofw/ofw_bus.h>
#include <machine/bus.h>
#include <machine/resource.h>
#if 1
-#include <sparc64/pci/ofw_pci.h>
+#include <dev/ofw/ofw_pci.h>
#endif
#define JBUSPPM_NREG 2
Index: sys/sparc64/sparc64/ofw_machdep.c
===================================================================
--- sys/sparc64/sparc64/ofw_machdep.c
+++ sys/sparc64/sparc64/ofw_machdep.c
@@ -34,12 +34,14 @@
#include <sys/param.h>
#include <sys/bus.h>
#include <sys/systm.h>
+#include <sys/rman.h>
#include <net/ethernet.h>
+#include <dev/ofw/openfirm.h>
#include <dev/ofw/ofw_bus.h>
+#include <dev/ofw/ofw_bus_subr.h>
#include <dev/ofw/ofw_pci.h>
-#include <dev/ofw/openfirm.h>
#include <machine/bus.h>
#include <machine/idprom.h>

File Metadata

Mime Type
text/plain
Expires
Sun, Apr 19, 4:08 PM (15 h, 50 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31782088
Default Alt Text
D4879.id13933.diff (85 KB)

Event Timeline