diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2007-10-21 21:03:39 -0400 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2007-10-23 01:49:55 -0400 |
commit | b01d9f2863349b0e041b90c3c86a998ee0fed2b0 (patch) | |
tree | 8789a06631a0ee502c58388d12c230eb4a2059b2 | |
parent | 31610434bc3523c0b01a10917a1185096a03c4c8 (diff) |
Module autoprobing support for virtio drivers.
This adds the logic to convert the virtio ids into module aliases, and
includes a modalias entry in sysfs and the env var to make probing work.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
-rw-r--r-- | drivers/virtio/virtio.c | 18 | ||||
-rw-r--r-- | scripts/mod/file2alias.c | 18 |
2 files changed, 36 insertions, 0 deletions
diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c index f640e0b732b7..15d7787dea87 100644 --- a/drivers/virtio/virtio.c +++ b/drivers/virtio/virtio.c | |||
@@ -20,10 +20,19 @@ static ssize_t status_show(struct device *_d, | |||
20 | struct virtio_device *dev = container_of(_d,struct virtio_device,dev); | 20 | struct virtio_device *dev = container_of(_d,struct virtio_device,dev); |
21 | return sprintf(buf, "0x%08x", dev->config->get_status(dev)); | 21 | return sprintf(buf, "0x%08x", dev->config->get_status(dev)); |
22 | } | 22 | } |
23 | static ssize_t modalias_show(struct device *_d, | ||
24 | struct device_attribute *attr, char *buf) | ||
25 | { | ||
26 | struct virtio_device *dev = container_of(_d,struct virtio_device,dev); | ||
27 | |||
28 | return sprintf(buf, "virtio:d%08Xv%08X\n", | ||
29 | dev->id.device, dev->id.vendor); | ||
30 | } | ||
23 | static struct device_attribute virtio_dev_attrs[] = { | 31 | static struct device_attribute virtio_dev_attrs[] = { |
24 | __ATTR_RO(device), | 32 | __ATTR_RO(device), |
25 | __ATTR_RO(vendor), | 33 | __ATTR_RO(vendor), |
26 | __ATTR_RO(status), | 34 | __ATTR_RO(status), |
35 | __ATTR_RO(modalias), | ||
27 | __ATTR_NULL | 36 | __ATTR_NULL |
28 | }; | 37 | }; |
29 | 38 | ||
@@ -51,10 +60,19 @@ static int virtio_dev_match(struct device *_dv, struct device_driver *_dr) | |||
51 | return 0; | 60 | return 0; |
52 | } | 61 | } |
53 | 62 | ||
63 | static int virtio_uevent(struct device *_dv, struct kobj_uevent_env *env) | ||
64 | { | ||
65 | struct virtio_device *dev = container_of(_dv,struct virtio_device,dev); | ||
66 | |||
67 | return add_uevent_var(env, "MODALIAS=virtio:d%08Xv%08X", | ||
68 | dev->id.device, dev->id.vendor); | ||
69 | } | ||
70 | |||
54 | static struct bus_type virtio_bus = { | 71 | static struct bus_type virtio_bus = { |
55 | .name = "virtio", | 72 | .name = "virtio", |
56 | .match = virtio_dev_match, | 73 | .match = virtio_dev_match, |
57 | .dev_attrs = virtio_dev_attrs, | 74 | .dev_attrs = virtio_dev_attrs, |
75 | .uevent = virtio_uevent, | ||
58 | }; | 76 | }; |
59 | 77 | ||
60 | static void add_status(struct virtio_device *dev, unsigned status) | 78 | static void add_status(struct virtio_device *dev, unsigned status) |
diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c index 91c15da2680b..d802b5afae89 100644 --- a/scripts/mod/file2alias.c +++ b/scripts/mod/file2alias.c | |||
@@ -525,6 +525,20 @@ static int do_ssb_entry(const char *filename, | |||
525 | return 1; | 525 | return 1; |
526 | } | 526 | } |
527 | 527 | ||
528 | /* Looks like: virtio:dNvN */ | ||
529 | static int do_virtio_entry(const char *filename, struct virtio_device_id *id, | ||
530 | char *alias) | ||
531 | { | ||
532 | id->device = TO_NATIVE(id->device); | ||
533 | id->vendor = TO_NATIVE(id->vendor); | ||
534 | |||
535 | strcpy(alias, "virtio:"); | ||
536 | ADD(alias, "d", 1, id->device); | ||
537 | ADD(alias, "v", id->vendor != VIRTIO_DEV_ANY_ID, id->vendor); | ||
538 | |||
539 | return 1; | ||
540 | } | ||
541 | |||
528 | /* Ignore any prefix, eg. v850 prepends _ */ | 542 | /* Ignore any prefix, eg. v850 prepends _ */ |
529 | static inline int sym_is(const char *symbol, const char *name) | 543 | static inline int sym_is(const char *symbol, const char *name) |
530 | { | 544 | { |
@@ -651,6 +665,10 @@ void handle_moddevtable(struct module *mod, struct elf_info *info, | |||
651 | do_table(symval, sym->st_size, | 665 | do_table(symval, sym->st_size, |
652 | sizeof(struct ssb_device_id), "ssb", | 666 | sizeof(struct ssb_device_id), "ssb", |
653 | do_ssb_entry, mod); | 667 | do_ssb_entry, mod); |
668 | else if (sym_is(symname, "__mod_virtio_device_table")) | ||
669 | do_table(symval, sym->st_size, | ||
670 | sizeof(struct virtio_device_id), "virtio", | ||
671 | do_virtio_entry, mod); | ||
654 | free(zeros); | 672 | free(zeros); |
655 | } | 673 | } |
656 | 674 | ||