summaryrefslogtreecommitdiffstats
path: root/sys/powerpc/pseries
diff options
context:
space:
mode:
authorandreast <andreast@FreeBSD.org>2013-12-12 12:36:40 +0000
committerandreast <andreast@FreeBSD.org>2013-12-12 12:36:40 +0000
commitcaaf223f40bd53798c5077103a428622dc515976 (patch)
tree0733c3f67a5952b5b85fe3a78e1a42b9959c8270 /sys/powerpc/pseries
parent14be275758a03b869f8d32806e726b95cbdd119d (diff)
downloadFreeBSD-src-caaf223f40bd53798c5077103a428622dc515976.zip
FreeBSD-src-caaf223f40bd53798c5077103a428622dc515976.tar.gz
MFC: r258051, r258052
r258052: Following the approach with ACPI DMAR on x86, split IOMMU handling into a variant PCI bus instead of trying to shoehorn it into the PCI host bridge adapter. Besides matching better the architecture on other platforms, this also allows systems with multiple partitionable endpoints per PCI host bridge to work correctly. r258051: Actually add IOMMU domain to the list of known mappings. This fixes a bug where multiple devices in the same IOMMU domain would be allocated conflicting mappings unless they also shared a DMA tag.
Diffstat (limited to 'sys/powerpc/pseries')
-rw-r--r--sys/powerpc/pseries/plpar_iommu.c3
-rw-r--r--sys/powerpc/pseries/plpar_pcibus.c113
-rw-r--r--sys/powerpc/pseries/rtas_pci.c31
3 files changed, 116 insertions, 31 deletions
diff --git a/sys/powerpc/pseries/plpar_iommu.c b/sys/powerpc/pseries/plpar_iommu.c
index 3b67a38..c95d170 100644
--- a/sys/powerpc/pseries/plpar_iommu.c
+++ b/sys/powerpc/pseries/plpar_iommu.c
@@ -115,6 +115,8 @@ phyp_iommu_set_dma_tag(device_t dev, device_t child, bus_dma_tag_t tag)
(((uint64_t)(dmawindow[dma_acells + 1]) << 32) |
dmawindow[dma_acells + 2]);
+ if (bootverbose)
+ device_printf(dev, "Mapping IOMMU domain %#x\n", dmawindow[0]);
window->map = NULL;
SLIST_FOREACH(i, &iommu_map_head, entries) {
if (i->iobn == dmawindow[0]) {
@@ -134,6 +136,7 @@ phyp_iommu_set_dma_tag(device_t dev, device_t child, bus_dma_tag_t tag)
window->map->vmem = vmem_create("IOMMU mappings", PAGE_SIZE,
trunc_page(VMEM_ADDR_MAX) - PAGE_SIZE, PAGE_SIZE, 0,
M_BESTFIT | M_NOWAIT);
+ SLIST_INSERT_HEAD(&iommu_map_head, window->map, entries);
}
/*
diff --git a/sys/powerpc/pseries/plpar_pcibus.c b/sys/powerpc/pseries/plpar_pcibus.c
new file mode 100644
index 0000000..640212f
--- /dev/null
+++ b/sys/powerpc/pseries/plpar_pcibus.c
@@ -0,0 +1,113 @@
+/*-
+ * 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/bus.h>
+#include <sys/kernel.h>
+#include <sys/libkern.h>
+#include <sys/module.h>
+#include <sys/pciio.h>
+
+#include <dev/ofw/openfirm.h>
+
+#include <dev/pci/pcivar.h>
+#include <dev/pci/pcireg.h>
+#include <dev/pci/pci_private.h>
+
+#include <machine/bus.h>
+#include <machine/rtas.h>
+
+#include <powerpc/ofw/ofw_pcibus.h>
+#include <powerpc/pseries/plpar_iommu.h>
+
+#include "pci_if.h"
+#include "iommu_if.h"
+
+static int plpar_pcibus_probe(device_t);
+static bus_dma_tag_t plpar_pcibus_get_dma_tag(device_t dev, device_t child);
+
+/*
+ * Driver methods.
+ */
+static device_method_t plpar_pcibus_methods[] = {
+ /* Device interface */
+ DEVMETHOD(device_probe, plpar_pcibus_probe),
+
+ /* IOMMU functions */
+ DEVMETHOD(bus_get_dma_tag, plpar_pcibus_get_dma_tag),
+ DEVMETHOD(iommu_map, phyp_iommu_map),
+ DEVMETHOD(iommu_unmap, phyp_iommu_unmap),
+
+ DEVMETHOD_END
+};
+
+static devclass_t pci_devclass;
+DEFINE_CLASS_1(pci, plpar_pcibus_driver, plpar_pcibus_methods,
+ sizeof(struct pci_softc), ofw_pcibus_driver);
+DRIVER_MODULE(plpar_pcibus, pcib, plpar_pcibus_driver, pci_devclass, 0, 0);
+
+static int
+plpar_pcibus_probe(device_t dev)
+{
+ phandle_t rtas;
+
+ if (ofw_bus_get_node(dev) == -1 || !rtas_exists())
+ return (ENXIO);
+
+ rtas = OF_finddevice("/rtas");
+ if (!OF_hasprop(rtas, "ibm,hypertas-functions"))
+ return (ENXIO);
+
+ device_set_desc(dev, "POWER Hypervisor PCI bus");
+
+ return (BUS_PROBE_SPECIFIC);
+}
+
+static bus_dma_tag_t
+plpar_pcibus_get_dma_tag(device_t dev, device_t child)
+{
+ struct ofw_pcibus_devinfo *dinfo;
+
+ while (device_get_parent(child) != dev)
+ child = device_get_parent(child);
+
+ dinfo = device_get_ivars(child);
+
+ if (dinfo->opd_dma_tag != NULL)
+ return (dinfo->opd_dma_tag);
+
+ bus_dma_tag_create(bus_get_dma_tag(dev),
+ 1, 0, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
+ NULL, NULL, BUS_SPACE_MAXSIZE, BUS_SPACE_UNRESTRICTED,
+ BUS_SPACE_MAXSIZE, 0, NULL, NULL, &dinfo->opd_dma_tag);
+ phyp_iommu_set_dma_tag(dev, child, dinfo->opd_dma_tag);
+
+ return (dinfo->opd_dma_tag);
+}
+
diff --git a/sys/powerpc/pseries/rtas_pci.c b/sys/powerpc/pseries/rtas_pci.c
index f3e9a29..0835a27 100644
--- a/sys/powerpc/pseries/rtas_pci.c
+++ b/sys/powerpc/pseries/rtas_pci.c
@@ -74,11 +74,6 @@ static void rtaspci_write_config(device_t, u_int, u_int, u_int,
u_int, u_int32_t, int);
/*
- * IOMMU LPAR interface
- */
-static bus_dma_tag_t rtaspci_get_dma_tag(device_t dev, device_t child);
-
-/*
* Driver methods.
*/
static device_method_t rtaspci_methods[] = {
@@ -90,19 +85,11 @@ static device_method_t rtaspci_methods[] = {
DEVMETHOD(pcib_read_config, rtaspci_read_config),
DEVMETHOD(pcib_write_config, rtaspci_write_config),
- /* IOMMU functions */
- DEVMETHOD(bus_get_dma_tag, rtaspci_get_dma_tag),
-#ifdef __powerpc64__
- DEVMETHOD(iommu_map, phyp_iommu_map),
- DEVMETHOD(iommu_unmap, phyp_iommu_unmap),
-#endif
-
DEVMETHOD_END
};
struct rtaspci_softc {
struct ofw_pci_softc pci_sc;
- bus_dma_tag_t dma_tag;
cell_t read_pci_config, write_pci_config;
cell_t ex_read_pci_config, ex_write_pci_config;
@@ -149,15 +136,6 @@ rtaspci_attach(device_t dev)
OF_getprop(ofw_bus_get_node(dev), "ibm,pci-config-space-type",
&sc->sc_extended_config, sizeof(sc->sc_extended_config));
- bus_dma_tag_create(bus_get_dma_tag(dev),
- 1, 0, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,
- NULL, NULL, BUS_SPACE_MAXSIZE, BUS_SPACE_UNRESTRICTED,
- BUS_SPACE_MAXSIZE, 0, NULL, NULL, &sc->dma_tag);
-#ifdef __powerpc64__
- if (!(mfmsr() & PSL_HV))
- phyp_iommu_set_dma_tag(dev, dev, sc->dma_tag);
-#endif
-
return (ofw_pci_attach(dev));
}
@@ -225,12 +203,3 @@ rtaspci_write_config(device_t dev, u_int bus, u_int slot, u_int func,
width, val, &pcierror);
}
-static bus_dma_tag_t
-rtaspci_get_dma_tag(device_t dev, device_t child)
-{
- struct rtaspci_softc *sc;
-
- sc = device_get_softc(dev);
- return (sc->dma_tag);
-}
-
OpenPOWER on IntegriCloud