Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/virtio/pci/virtio_pci_legacy.c
Show First 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | |||||
#include "virtio_bus_if.h" | #include "virtio_bus_if.h" | ||||
#include "virtio_pci_if.h" | #include "virtio_pci_if.h" | ||||
#include "virtio_if.h" | #include "virtio_if.h" | ||||
struct vtpci_legacy_softc { | struct vtpci_legacy_softc { | ||||
device_t vtpci_dev; | device_t vtpci_dev; | ||||
struct vtpci_common vtpci_common; | struct vtpci_common vtpci_common; | ||||
int vtpci_res_type; | |||||
struct resource *vtpci_res; | struct resource *vtpci_res; | ||||
struct resource *vtpci_msix_table_res; | struct resource *vtpci_msix_table_res; | ||||
struct resource *vtpci_msix_pba_res; | struct resource *vtpci_msix_pba_res; | ||||
}; | }; | ||||
static int vtpci_legacy_probe(device_t); | static int vtpci_legacy_probe(device_t); | ||||
static int vtpci_legacy_attach(device_t); | static int vtpci_legacy_attach(device_t); | ||||
static int vtpci_legacy_detach(device_t); | static int vtpci_legacy_detach(device_t); | ||||
▲ Show 20 Lines • Show All 156 Lines • ▼ Show 20 Lines | vtpci_legacy_attach(device_t dev) | ||||
int error; | int error; | ||||
sc = device_get_softc(dev); | sc = device_get_softc(dev); | ||||
sc->vtpci_dev = dev; | sc->vtpci_dev = dev; | ||||
vtpci_init(&sc->vtpci_common, dev, false); | vtpci_init(&sc->vtpci_common, dev, false); | ||||
error = vtpci_legacy_alloc_resources(sc); | error = vtpci_legacy_alloc_resources(sc); | ||||
if (error) { | if (error) { | ||||
device_printf(dev, "cannot map I/O space\n"); | device_printf(dev, "cannot map I/O space nor memory space\n"); | ||||
return (error); | return (error); | ||||
} | } | ||||
if (vtpci_is_msix_available(&sc->vtpci_common) && | if (vtpci_is_msix_available(&sc->vtpci_common) && | ||||
!vtpci_legacy_setup_msix(sc)) { | !vtpci_legacy_setup_msix(sc)) { | ||||
device_printf(dev, "cannot setup MSI-x resources\n"); | device_printf(dev, "cannot setup MSI-x resources\n"); | ||||
error = ENXIO; | error = ENXIO; | ||||
goto fail; | goto fail; | ||||
▲ Show 20 Lines • Show All 353 Lines • ▼ Show 20 Lines | bus_release_resource(dev, SYS_RES_MEMORY, | ||||
sc->vtpci_msix_table_res); | sc->vtpci_msix_table_res); | ||||
sc->vtpci_msix_table_res = NULL; | sc->vtpci_msix_table_res = NULL; | ||||
} | } | ||||
} | } | ||||
static int | static int | ||||
vtpci_legacy_alloc_resources(struct vtpci_legacy_softc *sc) | vtpci_legacy_alloc_resources(struct vtpci_legacy_softc *sc) | ||||
{ | { | ||||
const int res_types[] = { SYS_RES_IOPORT, SYS_RES_MEMORY }; | |||||
device_t dev; | device_t dev; | ||||
int rid; | int rid, i; | ||||
dev = sc->vtpci_dev; | dev = sc->vtpci_dev; | ||||
/* | |||||
* Most hypervisors export the common configuration structure in IO | |||||
* space, but some use memory space; try both. | |||||
*/ | |||||
for (i = 0; nitems(res_types); i++) { | |||||
rid = PCIR_BAR(0); | rid = PCIR_BAR(0); | ||||
if ((sc->vtpci_res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, | sc->vtpci_res_type = res_types[i]; | ||||
&rid, RF_ACTIVE)) == NULL) | sc->vtpci_res = bus_alloc_resource_any(dev, res_types[i], &rid, | ||||
RF_ACTIVE); | |||||
if (sc->vtpci_res != NULL) | |||||
break; | |||||
} | |||||
if (sc->vtpci_res == NULL) | |||||
return (ENXIO); | return (ENXIO); | ||||
return (0); | return (0); | ||||
} | } | ||||
static void | static void | ||||
vtpci_legacy_free_resources(struct vtpci_legacy_softc *sc) | vtpci_legacy_free_resources(struct vtpci_legacy_softc *sc) | ||||
{ | { | ||||
device_t dev; | device_t dev; | ||||
dev = sc->vtpci_dev; | dev = sc->vtpci_dev; | ||||
if (sc->vtpci_res != NULL) { | if (sc->vtpci_res != NULL) { | ||||
bus_release_resource(dev, SYS_RES_IOPORT, PCIR_BAR(0), | bus_release_resource(dev, sc->vtpci_res_type, PCIR_BAR(0), | ||||
sc->vtpci_res); | sc->vtpci_res); | ||||
sc->vtpci_res = NULL; | sc->vtpci_res = NULL; | ||||
} | } | ||||
} | } | ||||
static void | static void | ||||
vtpci_legacy_probe_and_attach_child(struct vtpci_legacy_softc *sc) | vtpci_legacy_probe_and_attach_child(struct vtpci_legacy_softc *sc) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 146 Lines • Show Last 20 Lines |