Date: Tue, 12 Nov 2013 16:15:09 +0000 (UTC) From: Nathan Whitehorn <nwhitehorn@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r258052 - in head/sys: conf powerpc/ofw powerpc/pseries Message-ID: <201311121615.rACGF9BD007524@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: nwhitehorn Date: Tue Nov 12 16:15:09 2013 New Revision: 258052 URL: http://svnweb.freebsd.org/changeset/base/258052 Log: 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. Added: head/sys/powerpc/ofw/ofw_pcibus.h - copied, changed from r257990, head/sys/powerpc/ofw/ofw_pci.h head/sys/powerpc/pseries/plpar_pcibus.c (contents, props changed) Modified: head/sys/conf/files.powerpc head/sys/powerpc/ofw/ofw_pcibus.c head/sys/powerpc/pseries/rtas_pci.c Modified: head/sys/conf/files.powerpc ============================================================================== --- head/sys/conf/files.powerpc Tue Nov 12 16:14:45 2013 (r258051) +++ head/sys/conf/files.powerpc Tue Nov 12 16:15:09 2013 (r258052) @@ -227,6 +227,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: head/sys/powerpc/ofw/ofw_pcibus.c ============================================================================== --- head/sys/powerpc/ofw/ofw_pcibus.c Tue Nov 12 16:14:45 2013 (r258051) +++ head/sys/powerpc/ofw/ofw_pcibus.c Tue Nov 12 16:15:09 2013 (r258052) @@ -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); /* @@ -272,6 +269,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 and modified: head/sys/powerpc/ofw/ofw_pcibus.h (from r257990, head/sys/powerpc/ofw/ofw_pci.h) ============================================================================== --- head/sys/powerpc/ofw/ofw_pci.h Mon Nov 11 14:08:25 2013 (r257990, copy source) +++ head/sys/powerpc/ofw/ofw_pcibus.h Tue Nov 12 16:15:09 2013 (r258052) @@ -26,51 +26,26 @@ * $FreeBSD$ */ -#ifndef POWERPC_OFW_OFW_PCI_H -#define POWERPC_OFW_OFW_PCI_H +#ifndef POWERPC_OFW_OFW_PCIBUS_H +#define POWERPC_OFW_OFW_PCIBUS_H -/* - * Export class definition for inheritance purposes - */ -DECLARE_CLASS(ofw_pci_driver); +#include <sys/bus.h> +#include <sys/pciio.h> -struct ofw_pci_range { - uint32_t pci_hi; - uint64_t pci; - uint64_t host; - uint64_t size; -}; +#include <dev/ofw/ofw_bus.h> +#include <dev/ofw/ofw_pci.h> +#include <dev/pci/pcivar.h> /* - * Quirks for some adapters + * Export class definition for inheritance purposes */ -enum { - OFW_PCI_QUIRK_RANGES_ON_CHILDREN = 1, -}; +DECLARE_CLASS(ofw_pcibus_driver); /* PCI Bus Enumerators */ -struct ofw_pci_softc { - device_t sc_dev; - phandle_t sc_node; - int sc_bus; - int sc_initialized; - - int sc_quirks; - - struct ofw_pci_register sc_pcir; - - 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; +struct ofw_pcibus_devinfo { + struct pci_devinfo opd_dinfo; + struct ofw_bus_devinfo opd_obdinfo; + bus_dma_tag_t opd_dma_tag; }; -int ofw_pci_init(device_t dev); -int ofw_pci_attach(device_t dev); - -#endif // POWERPC_OFW_OFW_PCI_H +#endif // POWERPC_OFW_OFW_PCIBUS_H Added: head/sys/powerpc/pseries/plpar_pcibus.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/sys/powerpc/pseries/plpar_pcibus.c Tue Nov 12 16:15:09 2013 (r258052) @@ -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: head/sys/powerpc/pseries/rtas_pci.c ============================================================================== --- head/sys/powerpc/pseries/rtas_pci.c Tue Nov 12 16:14:45 2013 (r258051) +++ head/sys/powerpc/pseries/rtas_pci.c Tue Nov 12 16:15:09 2013 (r258052) @@ -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); -} -
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201311121615.rACGF9BD007524>