Path: blob/main/sys/powerpc/pseries/plpar_pcibus.c
39507 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2011 Nathan Whitehorn4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND16* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE18* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE19* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL20* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS21* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)22* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT23* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY24* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF25* SUCH DAMAGE.26*/2728#include <sys/param.h>29#include <sys/bus.h>30#include <sys/kernel.h>31#include <sys/libkern.h>32#include <sys/module.h>33#include <sys/pciio.h>3435#include <dev/ofw/openfirm.h>3637#include <dev/pci/pcivar.h>38#include <dev/pci/pcireg.h>39#include <dev/pci/pci_private.h>4041#include <machine/bus.h>42#include <machine/rtas.h>4344#include <powerpc/ofw/ofw_pcibus.h>45#include <powerpc/pseries/plpar_iommu.h>4647#include "pci_if.h"48#include "iommu_if.h"4950static int plpar_pcibus_probe(device_t);51static bus_dma_tag_t plpar_pcibus_get_dma_tag(device_t dev, device_t child);5253/*54* Driver methods.55*/56static device_method_t plpar_pcibus_methods[] = {57/* Device interface */58DEVMETHOD(device_probe, plpar_pcibus_probe),5960/* IOMMU functions */61DEVMETHOD(bus_get_dma_tag, plpar_pcibus_get_dma_tag),62DEVMETHOD(iommu_map, phyp_iommu_map),63DEVMETHOD(iommu_unmap, phyp_iommu_unmap),6465DEVMETHOD_END66};6768DEFINE_CLASS_1(pci, plpar_pcibus_driver, plpar_pcibus_methods,69sizeof(struct pci_softc), ofw_pcibus_driver);70DRIVER_MODULE(plpar_pcibus, pcib, plpar_pcibus_driver, 0, 0);7172static int73plpar_pcibus_probe(device_t dev)74{75phandle_t rtas;7677if (ofw_bus_get_node(dev) == -1 || !rtas_exists())78return (ENXIO);7980rtas = OF_finddevice("/rtas");81if (!OF_hasprop(rtas, "ibm,hypertas-functions"))82return (ENXIO);8384device_set_desc(dev, "POWER Hypervisor PCI bus");8586return (BUS_PROBE_SPECIFIC);87}8889static bus_dma_tag_t90plpar_pcibus_get_dma_tag(device_t dev, device_t child)91{92struct ofw_pcibus_devinfo *dinfo;9394while (device_get_parent(child) != dev)95child = device_get_parent(child);9697dinfo = device_get_ivars(child);9899if (dinfo->opd_dma_tag != NULL)100return (dinfo->opd_dma_tag);101102bus_dma_tag_create(bus_get_dma_tag(dev),1031, 0, BUS_SPACE_MAXADDR, BUS_SPACE_MAXADDR,104NULL, NULL, BUS_SPACE_MAXSIZE, BUS_SPACE_UNRESTRICTED,105BUS_SPACE_MAXSIZE, 0, NULL, NULL, &dinfo->opd_dma_tag);106phyp_iommu_set_dma_tag(dev, child, dinfo->opd_dma_tag);107108return (dinfo->opd_dma_tag);109}110111112