Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/virtio/mmio/virtio_mmio.c
Show First 20 Lines • Show All 165 Lines • ▼ Show 20 Lines | static device_method_t vtmmio_methods[] = { | ||||
DEVMETHOD_END | DEVMETHOD_END | ||||
}; | }; | ||||
DEFINE_CLASS_0(virtio_mmio, vtmmio_driver, vtmmio_methods, | DEFINE_CLASS_0(virtio_mmio, vtmmio_driver, vtmmio_methods, | ||||
sizeof(struct vtmmio_softc)); | sizeof(struct vtmmio_softc)); | ||||
MODULE_VERSION(virtio_mmio, 1); | MODULE_VERSION(virtio_mmio, 1); | ||||
int | |||||
vtmmio_probe(device_t dev) | |||||
{ | |||||
struct vtmmio_softc *sc; | |||||
int rid; | |||||
uint32_t magic, version; | |||||
sc = device_get_softc(dev); | |||||
rid = 0; | |||||
sc->res[0] = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, | |||||
RF_ACTIVE); | |||||
if (!sc->res[0]) { | |||||
bryanv: Nit: style prefers it, and used elsewhere in this driver: explicitly compare this to NULL | |||||
jrtc27AuthorUnsubmitted Done Inline ActionsThanks; blindly copied from vtmmio_attach without thinking. Will fix that at the same time as committing this (though in a separate commit). jrtc27: Thanks; blindly copied from vtmmio_attach without thinking. Will fix that at the same time as… | |||||
device_printf(dev, "Cannot allocate memory window.\n"); | |||||
return (ENXIO); | |||||
} | |||||
magic = vtmmio_read_config_4(sc, VIRTIO_MMIO_MAGIC_VALUE); | |||||
if (magic != VIRTIO_MMIO_MAGIC_VIRT) { | |||||
device_printf(dev, "Bad magic value %#x\n", magic); | |||||
bus_release_resource(dev, SYS_RES_MEMORY, rid, sc->res[0]); | |||||
return (ENXIO); | |||||
} | |||||
version = vtmmio_read_config_4(sc, VIRTIO_MMIO_VERSION); | |||||
if (version < 1 || version > 2) { | |||||
device_printf(dev, "Unsupported version: %#x\n", version); | |||||
bus_release_resource(dev, SYS_RES_MEMORY, rid, sc->res[0]); | |||||
return (ENXIO); | |||||
} | |||||
if (vtmmio_read_config_4(sc, VIRTIO_MMIO_DEVICE_ID) == 0) { | |||||
bus_release_resource(dev, SYS_RES_MEMORY, rid, sc->res[0]); | |||||
return (ENXIO); | |||||
} | |||||
bus_release_resource(dev, SYS_RES_MEMORY, rid, sc->res[0]); | |||||
device_set_desc(dev, "VirtIO MMIO adapter"); | |||||
return (BUS_PROBE_DEFAULT); | |||||
} | |||||
static int | static int | ||||
vtmmio_setup_intr(device_t dev, enum intr_type type) | vtmmio_setup_intr(device_t dev, enum intr_type type) | ||||
{ | { | ||||
struct vtmmio_softc *sc; | struct vtmmio_softc *sc; | ||||
int rid; | int rid; | ||||
int err; | int err; | ||||
sc = device_get_softc(dev); | sc = device_get_softc(dev); | ||||
Show All 38 Lines | vtmmio_attach(device_t dev) | ||||
sc->res[0] = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, | sc->res[0] = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &rid, | ||||
RF_ACTIVE); | RF_ACTIVE); | ||||
if (!sc->res[0]) { | if (!sc->res[0]) { | ||||
device_printf(dev, "Cannot allocate memory window.\n"); | device_printf(dev, "Cannot allocate memory window.\n"); | ||||
return (ENXIO); | return (ENXIO); | ||||
} | } | ||||
sc->vtmmio_version = vtmmio_read_config_4(sc, VIRTIO_MMIO_VERSION); | sc->vtmmio_version = vtmmio_read_config_4(sc, VIRTIO_MMIO_VERSION); | ||||
if (sc->vtmmio_version < 1 || sc->vtmmio_version > 2) { | |||||
device_printf(dev, "Unsupported version: %x\n", | |||||
sc->vtmmio_version); | |||||
bus_release_resource(dev, SYS_RES_MEMORY, 0, | |||||
sc->res[0]); | |||||
sc->res[0] = NULL; | |||||
return (ENXIO); | |||||
} | |||||
vtmmio_reset(sc); | vtmmio_reset(sc); | ||||
/* Tell the host we've noticed this device. */ | /* Tell the host we've noticed this device. */ | ||||
vtmmio_set_status(dev, VIRTIO_CONFIG_STATUS_ACK); | vtmmio_set_status(dev, VIRTIO_CONFIG_STATUS_ACK); | ||||
if ((child = device_add_child(dev, NULL, -1)) == NULL) { | if ((child = device_add_child(dev, NULL, -1)) == NULL) { | ||||
device_printf(dev, "Cannot create child device.\n"); | device_printf(dev, "Cannot create child device.\n"); | ||||
▲ Show 20 Lines • Show All 673 Lines • Show Last 20 Lines |
Nit: style prefers it, and used elsewhere in this driver: explicitly compare this to NULL