svn commit: r259257 - in stable/10/sys: conf powerpc/ofw powerpc/pseries
Andreas Tobler
andreast at FreeBSD.org
Thu Dec 12 12:36:42 UTC 2013
Author: andreast
Date: Thu Dec 12 12:36:40 2013
New Revision: 259257
URL: http://svnweb.freebsd.org/changeset/base/259257
Log:
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.
Added:
stable/10/sys/powerpc/ofw/ofw_pcibus.h
- copied unchanged from r258052, head/sys/powerpc/ofw/ofw_pcibus.h
stable/10/sys/powerpc/pseries/plpar_pcibus.c
- copied unchanged from r258052, head/sys/powerpc/pseries/plpar_pcibus.c
Modified:
stable/10/sys/conf/files.powerpc
stable/10/sys/powerpc/ofw/ofw_pcibus.c
stable/10/sys/powerpc/pseries/plpar_iommu.c
stable/10/sys/powerpc/pseries/rtas_pci.c
Directory Properties:
stable/10/ (props changed)
Modified: stable/10/sys/conf/files.powerpc
==============================================================================
--- stable/10/sys/conf/files.powerpc Thu Dec 12 12:29:35 2013 (r259256)
+++ stable/10/sys/conf/files.powerpc Thu Dec 12 12:36:40 2013 (r259257)
@@ -232,6 +232,7 @@ powerpc/pseries/phyp_llan.c optional lla
powerpc/pseries/phyp_vscsi.c optional pseries powerpc64 scbus
powerpc/pseries/platform_chrp.c optional pseries
powerpc/pseries/plpar_iommu.c optional pseries powerpc64
+powerpc/pseries/plpar_pcibus.c optional pseries powerpc64 pci
powerpc/pseries/rtas_dev.c optional pseries
powerpc/pseries/rtas_pci.c optional pseries pci
powerpc/pseries/vdevice.c optional pseries powerpc64
Modified: stable/10/sys/powerpc/ofw/ofw_pcibus.c
==============================================================================
--- stable/10/sys/powerpc/ofw/ofw_pcibus.c Thu Dec 12 12:29:35 2013 (r259256)
+++ stable/10/sys/powerpc/ofw/ofw_pcibus.c Thu Dec 12 12:36:40 2013 (r259257)
@@ -50,6 +50,7 @@ __FBSDID("$FreeBSD$");
#include <dev/pci/pcivar.h>
#include <dev/pci/pci_private.h>
+#include "ofw_pcibus.h"
#include "pcib_if.h"
#include "pci_if.h"
@@ -85,12 +86,7 @@ static device_method_t ofw_pcibus_method
DEVMETHOD(ofw_bus_get_node, ofw_bus_gen_get_node),
DEVMETHOD(ofw_bus_get_type, ofw_bus_gen_get_type),
- { 0, 0 }
-};
-
-struct ofw_pcibus_devinfo {
- struct pci_devinfo opd_dinfo;
- struct ofw_bus_devinfo opd_obdinfo;
+ DEVMETHOD_END
};
static devclass_t pci_devclass;
@@ -195,6 +191,7 @@ ofw_pcibus_enum_devtree(device_t dev, u_
pci_freecfg((struct pci_devinfo *)dinfo);
continue;
}
+ dinfo->opd_dma_tag = NULL;
pci_add_child(dev, (struct pci_devinfo *)dinfo);
/*
@@ -274,6 +271,7 @@ ofw_pcibus_enum_bus(device_t dev, u_int
if (dinfo == NULL)
continue;
+ dinfo->opd_dma_tag = NULL;
dinfo->opd_obdinfo.obd_node = -1;
dinfo->opd_obdinfo.obd_name = NULL;
Copied: stable/10/sys/powerpc/ofw/ofw_pcibus.h (from r258052, head/sys/powerpc/ofw/ofw_pcibus.h)
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ stable/10/sys/powerpc/ofw/ofw_pcibus.h Thu Dec 12 12:36:40 2013 (r259257, copy of r258052, head/sys/powerpc/ofw/ofw_pcibus.h)
@@ -0,0 +1,51 @@
+/*-
+ * 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_PCIBUS_H
+#define POWERPC_OFW_OFW_PCIBUS_H
+
+#include <sys/bus.h>
+#include <sys/pciio.h>
+
+#include <dev/ofw/ofw_bus.h>
+#include <dev/ofw/ofw_pci.h>
+#include <dev/pci/pcivar.h>
+
+/*
+ * Export class definition for inheritance purposes
+ */
+DECLARE_CLASS(ofw_pcibus_driver); /* PCI Bus Enumerators */
+
+struct ofw_pcibus_devinfo {
+ struct pci_devinfo opd_dinfo;
+ struct ofw_bus_devinfo opd_obdinfo;
+ bus_dma_tag_t opd_dma_tag;
+};
+
+#endif // POWERPC_OFW_OFW_PCIBUS_H
+
Modified: stable/10/sys/powerpc/pseries/plpar_iommu.c
==============================================================================
--- stable/10/sys/powerpc/pseries/plpar_iommu.c Thu Dec 12 12:29:35 2013 (r259256)
+++ stable/10/sys/powerpc/pseries/plpar_iommu.c Thu Dec 12 12:36:40 2013 (r259257)
@@ -115,6 +115,8 @@ phyp_iommu_set_dma_tag(device_t dev, dev
(((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, dev
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);
}
/*
Copied: stable/10/sys/powerpc/pseries/plpar_pcibus.c (from r258052, head/sys/powerpc/pseries/plpar_pcibus.c)
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ stable/10/sys/powerpc/pseries/plpar_pcibus.c Thu Dec 12 12:36:40 2013 (r259257, copy of r258052, head/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);
+}
+
Modified: stable/10/sys/powerpc/pseries/rtas_pci.c
==============================================================================
--- stable/10/sys/powerpc/pseries/rtas_pci.c Thu Dec 12 12:29:35 2013 (r259256)
+++ stable/10/sys/powerpc/pseries/rtas_pci.c Thu Dec 12 12:36:40 2013 (r259257)
@@ -74,11 +74,6 @@ static void rtaspci_write_config(device
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
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);
-}
-
More information about the svn-src-stable-10
mailing list