diff --git a/sys/dev/vmd/vmd_bus.c b/sys/dev/vmd/vmd_bus.c index 5eed6176630f..28ce14c63128 100644 --- a/sys/dev/vmd/vmd_bus.c +++ b/sys/dev/vmd/vmd_bus.c @@ -1,220 +1,220 @@ /*- * SPDX-License-Identifier: BSD-2-Clause * * Copyright 2019 Cisco Systems, Inc. * 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 __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "pcib_if.h" #include "pci_if.h" static int vmd_bus_probe(device_t dev) { device_set_desc(dev, "VMD bus"); return (-1000); } /* PCI interface. */ static int vmd_bus_attach(device_t dev) { struct vmd_softc *sc; struct pci_devinfo *dinfo; rman_res_t start, end; int b, s, f; int found; sc = device_get_softc(device_get_parent(dev)); /* * Start at max PCI vmd_domain and work down. Only VMD * starting bus is connect to VMD device directly. Scan al * lslots and function connected to starting bus. */ b = sc->vmd_bus_start; found = 0; for (s = 0; s < PCI_SLOTMAX; s++) { for (f = 0; f < PCI_FUNCMAX; f++) { dinfo = pci_read_device(device_get_parent(dev), dev, PCI_DOMAINMAX - device_get_unit( device_get_parent(dev)), b, s, f); if (dinfo != NULL) { found = 1; pci_add_child(dev, dinfo); start = rman_get_start(sc->vmd_regs_resource[1]); end = rman_get_end(sc->vmd_regs_resource[1]); resource_list_add_next(&dinfo->resources, SYS_RES_MEMORY, start, end, end - start + 1); start = rman_get_start(sc->vmd_io_resource); end = rman_get_end(sc->vmd_io_resource); resource_list_add_next(&dinfo->resources, SYS_RES_IOPORT, start, end, end - start + 1); } } } if (found) { bus_generic_attach(dev); } return (0); } static int vmd_bus_detach(device_t dev) { struct vmd_softc *sc; struct pci_devinfo *dinfo; int b, s, f; device_delete_children(dev); sc = device_get_softc(device_get_parent(dev)); b = sc->vmd_bus_start; for (s = 0; s < PCI_SLOTMAX; s++) { for (f = 0; f < PCI_FUNCMAX; f++) { dinfo = pci_read_device(device_get_parent(dev), dev, PCI_DOMAINMAX - device_get_unit( device_get_parent(dev)), b, s, f); if (dinfo != NULL) resource_list_free(&dinfo->resources); } } return (0); } static int vmd_bus_adjust_resource(device_t dev, device_t child, int type, struct resource *r, rman_res_t start, rman_res_t end) { struct resource *res = r; if (type == SYS_RES_MEMORY) { /* VMD device controls this */ return (0); } return (bus_generic_adjust_resource(dev, child, type, res, start, end)); } static int vmd_bus_release_resource(device_t dev, device_t child, int type, int rid, struct resource *r) { if (type == SYS_RES_MEMORY) { /* VMD device controls this */ return (0); } return (pci_release_resource(dev, child, type, rid, r)); } static struct resource * vmd_bus_alloc_resource(device_t dev, device_t child, int type, int *rid, rman_res_t start, rman_res_t end, rman_res_t count, u_int flags) { struct vmd_softc *sc; sc = device_get_softc(device_get_parent(dev)); if (type == SYS_RES_MEMORY) { /* remap to VMD resources */ if (*rid == PCIR_MEMBASE_1) { return (sc->vmd_regs_resource[1]); } else if (*rid == PCIR_PMBASEL_1) { return (sc->vmd_regs_resource[2]); } else { return (sc->vmd_regs_resource[2]); } } return (pci_alloc_resource(dev, child, type, rid, start, end, count, flags)); } static int vmd_bus_shutdown(device_t dev) { return (0); } static device_method_t vmd_bus_pci_methods[] = { /* Device interface */ DEVMETHOD(device_probe, vmd_bus_probe), DEVMETHOD(device_attach, vmd_bus_attach), DEVMETHOD(device_detach, vmd_bus_detach), DEVMETHOD(device_shutdown, vmd_bus_shutdown), /* Bus interface */ DEVMETHOD(bus_alloc_resource, vmd_bus_alloc_resource), DEVMETHOD(bus_adjust_resource, vmd_bus_adjust_resource), DEVMETHOD(bus_release_resource, vmd_bus_release_resource), /* pci interface */ DEVMETHOD(pci_read_config, pci_read_config_method), DEVMETHOD(pci_write_config, pci_write_config_method), DEVMETHOD(pci_alloc_devinfo, pci_alloc_devinfo_method), DEVMETHOD_END }; static devclass_t vmd_bus_devclass; -DEFINE_CLASS_1(vmd_bus, vmd_bus_pci_driver, vmd_bus_pci_methods, +DEFINE_CLASS_1(pci, vmd_bus_pci_driver, vmd_bus_pci_methods, sizeof(struct pci_softc), pci_driver); -DRIVER_MODULE(vmd_bus, vmd, vmd_bus_pci_driver, vmd_bus_devclass, NULL, NULL); +DRIVER_MODULE(pci, vmd, vmd_bus_pci_driver, vmd_bus_devclass, NULL, NULL); MODULE_VERSION(vmd_bus, 1);