svn commit: r348599 - in head/sys/dev/virtio: . balloon block console network random scsi
Conrad Meyer
cem at FreeBSD.org
Tue Jun 4 02:37:14 UTC 2019
Author: cem
Date: Tue Jun 4 02:37:11 2019
New Revision: 348599
URL: https://svnweb.freebsd.org/changeset/base/348599
Log:
virtio(4): Add PNP match metadata for virtio devices
Register MODULE_PNP_INFO for virtio devices using the newbus PNP information
provided by the previous commit. Matching can be quite simple; existing
probe routines only matched on bus (implicit) and device_type. The same
matching criteria are retained exactly, but is now also available to
devmatch(8).
Reviewed by: bryanv, markj; imp (earlier version)
Differential Revision: https://reviews.freebsd.org/D20407
Modified:
head/sys/dev/virtio/balloon/virtio_balloon.c
head/sys/dev/virtio/block/virtio_blk.c
head/sys/dev/virtio/console/virtio_console.c
head/sys/dev/virtio/network/if_vtnet.c
head/sys/dev/virtio/random/virtio_random.c
head/sys/dev/virtio/scsi/virtio_scsi.c
head/sys/dev/virtio/virtio.h
Modified: head/sys/dev/virtio/balloon/virtio_balloon.c
==============================================================================
--- head/sys/dev/virtio/balloon/virtio_balloon.c Tue Jun 4 02:34:59 2019 (r348598)
+++ head/sys/dev/virtio/balloon/virtio_balloon.c Tue Jun 4 02:37:11 2019 (r348599)
@@ -158,16 +158,14 @@ DRIVER_MODULE(virtio_balloon, virtio_pci, vtballoon_dr
MODULE_VERSION(virtio_balloon, 1);
MODULE_DEPEND(virtio_balloon, virtio, 1, 1, 1);
+VIRTIO_SIMPLE_PNPTABLE(virtio_balloon, VIRTIO_ID_BALLOON,
+ "VirtIO Balloon Adapter");
+VIRTIO_SIMPLE_PNPINFO(virtio_pci, virtio_balloon);
+
static int
vtballoon_probe(device_t dev)
{
-
- if (virtio_get_device_type(dev) != VIRTIO_ID_BALLOON)
- return (ENXIO);
-
- device_set_desc(dev, "VirtIO Balloon Adapter");
-
- return (BUS_PROBE_DEFAULT);
+ return (VIRTIO_SIMPLE_PROBE(dev, virtio_balloon));
}
static int
Modified: head/sys/dev/virtio/block/virtio_blk.c
==============================================================================
--- head/sys/dev/virtio/block/virtio_blk.c Tue Jun 4 02:34:59 2019 (r348598)
+++ head/sys/dev/virtio/block/virtio_blk.c Tue Jun 4 02:37:11 2019 (r348599)
@@ -261,6 +261,10 @@ DRIVER_MODULE(virtio_blk, virtio_pci, vtblk_driver, vt
MODULE_VERSION(virtio_blk, 1);
MODULE_DEPEND(virtio_blk, virtio, 1, 1, 1);
+VIRTIO_SIMPLE_PNPTABLE(virtio_blk, VIRTIO_ID_BLOCK, "VirtIO Block Adapter");
+VIRTIO_SIMPLE_PNPINFO(virtio_mmio, virtio_blk);
+VIRTIO_SIMPLE_PNPINFO(virtio_pci, virtio_blk);
+
static int
vtblk_modevent(module_t mod, int type, void *unused)
{
@@ -285,13 +289,7 @@ vtblk_modevent(module_t mod, int type, void *unused)
static int
vtblk_probe(device_t dev)
{
-
- if (virtio_get_device_type(dev) != VIRTIO_ID_BLOCK)
- return (ENXIO);
-
- device_set_desc(dev, "VirtIO Block Adapter");
-
- return (BUS_PROBE_DEFAULT);
+ return (VIRTIO_SIMPLE_PROBE(dev, virtio_blk));
}
static int
Modified: head/sys/dev/virtio/console/virtio_console.c
==============================================================================
--- head/sys/dev/virtio/console/virtio_console.c Tue Jun 4 02:34:59 2019 (r348598)
+++ head/sys/dev/virtio/console/virtio_console.c Tue Jun 4 02:37:11 2019 (r348599)
@@ -261,6 +261,10 @@ DRIVER_MODULE(virtio_console, virtio_pci, vtcon_driver
MODULE_VERSION(virtio_console, 1);
MODULE_DEPEND(virtio_console, virtio, 1, 1, 1);
+VIRTIO_SIMPLE_PNPTABLE(virtio_console, VIRTIO_ID_CONSOLE,
+ "VirtIO Console Adapter");
+VIRTIO_SIMPLE_PNPINFO(virtio_pci, virtio_console);
+
static int
vtcon_modevent(module_t mod, int type, void *unused)
{
@@ -305,13 +309,7 @@ vtcon_drain_all(void)
static int
vtcon_probe(device_t dev)
{
-
- if (virtio_get_device_type(dev) != VIRTIO_ID_CONSOLE)
- return (ENXIO);
-
- device_set_desc(dev, "VirtIO Console Adapter");
-
- return (BUS_PROBE_DEFAULT);
+ return (VIRTIO_SIMPLE_PROBE(dev, virtio_console));
}
static int
Modified: head/sys/dev/virtio/network/if_vtnet.c
==============================================================================
--- head/sys/dev/virtio/network/if_vtnet.c Tue Jun 4 02:34:59 2019 (r348598)
+++ head/sys/dev/virtio/network/if_vtnet.c Tue Jun 4 02:37:11 2019 (r348599)
@@ -325,6 +325,10 @@ MODULE_DEPEND(vtnet, virtio, 1, 1, 1);
MODULE_DEPEND(vtnet, netmap, 1, 1, 1);
#endif /* DEV_NETMAP */
+VIRTIO_SIMPLE_PNPTABLE(vtnet, VIRTIO_ID_NETWORK, "VirtIO Networking Adapter");
+VIRTIO_SIMPLE_PNPINFO(virtio_mmio, vtnet);
+VIRTIO_SIMPLE_PNPINFO(virtio_pci, vtnet);
+
static int
vtnet_modevent(module_t mod, int type, void *unused)
{
@@ -361,13 +365,7 @@ vtnet_modevent(module_t mod, int type, void *unused)
static int
vtnet_probe(device_t dev)
{
-
- if (virtio_get_device_type(dev) != VIRTIO_ID_NETWORK)
- return (ENXIO);
-
- device_set_desc(dev, "VirtIO Networking Adapter");
-
- return (BUS_PROBE_DEFAULT);
+ return (VIRTIO_SIMPLE_PROBE(dev, vtnet));
}
static int
Modified: head/sys/dev/virtio/random/virtio_random.c
==============================================================================
--- head/sys/dev/virtio/random/virtio_random.c Tue Jun 4 02:34:59 2019 (r348598)
+++ head/sys/dev/virtio/random/virtio_random.c Tue Jun 4 02:37:11 2019 (r348599)
@@ -102,6 +102,10 @@ MODULE_VERSION(virtio_random, 1);
MODULE_DEPEND(virtio_random, virtio, 1, 1, 1);
MODULE_DEPEND(virtio_random, random_device, 1, 1, 1);
+VIRTIO_SIMPLE_PNPTABLE(virtio_random, VIRTIO_ID_ENTROPY,
+ "VirtIO Entropy Adapter");
+VIRTIO_SIMPLE_PNPINFO(virtio_pci, virtio_random);
+
static int
vtrnd_modevent(module_t mod, int type, void *unused)
{
@@ -125,13 +129,7 @@ vtrnd_modevent(module_t mod, int type, void *unused)
static int
vtrnd_probe(device_t dev)
{
-
- if (virtio_get_device_type(dev) != VIRTIO_ID_ENTROPY)
- return (ENXIO);
-
- device_set_desc(dev, "VirtIO Entropy Adapter");
-
- return (BUS_PROBE_DEFAULT);
+ return (VIRTIO_SIMPLE_PROBE(dev, virtio_random));
}
static int
Modified: head/sys/dev/virtio/scsi/virtio_scsi.c
==============================================================================
--- head/sys/dev/virtio/scsi/virtio_scsi.c Tue Jun 4 02:34:59 2019 (r348598)
+++ head/sys/dev/virtio/scsi/virtio_scsi.c Tue Jun 4 02:37:11 2019 (r348599)
@@ -233,6 +233,9 @@ MODULE_VERSION(virtio_scsi, 1);
MODULE_DEPEND(virtio_scsi, virtio, 1, 1, 1);
MODULE_DEPEND(virtio_scsi, cam, 1, 1, 1);
+VIRTIO_SIMPLE_PNPTABLE(virtio_scsi, VIRTIO_ID_SCSI, "VirtIO SCSI Adapter");
+VIRTIO_SIMPLE_PNPINFO(virtio_pci, virtio_scsi);
+
static int
vtscsi_modevent(module_t mod, int type, void *unused)
{
@@ -256,13 +259,7 @@ vtscsi_modevent(module_t mod, int type, void *unused)
static int
vtscsi_probe(device_t dev)
{
-
- if (virtio_get_device_type(dev) != VIRTIO_ID_SCSI)
- return (ENXIO);
-
- device_set_desc(dev, "VirtIO SCSI Adapter");
-
- return (BUS_PROBE_DEFAULT);
+ return (VIRTIO_SIMPLE_PROBE(dev, virtio_scsi));
}
static int
Modified: head/sys/dev/virtio/virtio.h
==============================================================================
--- head/sys/dev/virtio/virtio.h Tue Jun 4 02:34:59 2019 (r348598)
+++ head/sys/dev/virtio/virtio.h Tue Jun 4 02:37:11 2019 (r348599)
@@ -63,6 +63,21 @@ struct virtio_feature_desc {
const char *vfd_str;
};
+struct virtio_pnp_match {
+ uint32_t device_type;
+ const char *description;
+};
+#define VIRTIO_SIMPLE_PNPTABLE(driver, devtype, desc) \
+ static const struct virtio_pnp_match driver ## _match = { \
+ .device_type = devtype, \
+ .description = desc, \
+ }
+#define VIRTIO_SIMPLE_PNPINFO(bus, driver) \
+ MODULE_PNP_INFO("U32:device_type;D:#", bus, driver, \
+ &driver ## _match, 1)
+#define VIRTIO_SIMPLE_PROBE(dev, driver) \
+ (virtio_simple_probe(dev, &driver ## _match))
+
const char *virtio_device_name(uint16_t devid);
void virtio_describe(device_t dev, const char *msg,
uint64_t features, struct virtio_feature_desc *feature_desc);
@@ -145,5 +160,15 @@ __CONCAT(virtio_set_,name)(device_t dev, void *val)
VIRTIO_WRITE_IVAR(feature_desc, VIRTIO_IVAR_FEATURE_DESC);
#undef VIRTIO_WRITE_IVAR
+
+static inline int
+virtio_simple_probe(device_t dev, const struct virtio_pnp_match *match)
+{
+
+ if (virtio_get_device_type(dev) != match->device_type)
+ return (ENXIO);
+ device_set_desc(dev, match->description);
+ return (BUS_PROBE_DEFAULT);
+}
#endif /* _VIRTIO_H_ */
More information about the svn-src-all
mailing list