diff options
author | Alex Williamson <alex.williamson@redhat.com> | 2015-04-07 13:14:43 -0400 |
---|---|---|
committer | Alex Williamson <alex.williamson@redhat.com> | 2015-04-07 13:14:43 -0400 |
commit | 80c7e8cc2aaa36944acdfbce46f373101b9f21ff (patch) | |
tree | 4e0703332bd19c261fed8e44f61172ffee9b065b /drivers/vfio | |
parent | ecaa1f6a01544604de5f9531379a303eee886162 (diff) |
vfio-pci: Allow PCI IDs to be specified as module options
This copies the same support from pci-stub for exactly the same
purpose, enabling a set of PCI IDs to be automatically added to the
driver's dynamic ID table at module load time. The code here is
pretty simple and both vfio-pci and pci-stub are fairly unique in
being meta drivers, capable of attaching to any device, so there's no
attempt made to generalize the code into pci-core.
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Diffstat (limited to 'drivers/vfio')
-rw-r--r-- | drivers/vfio/pci/vfio_pci.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c index 25aef05b8692..43517ce930f2 100644 --- a/drivers/vfio/pci/vfio_pci.c +++ b/drivers/vfio/pci/vfio_pci.c | |||
@@ -11,6 +11,8 @@ | |||
11 | * Author: Tom Lyon, pugs@cisco.com | 11 | * Author: Tom Lyon, pugs@cisco.com |
12 | */ | 12 | */ |
13 | 13 | ||
14 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
15 | |||
14 | #include <linux/device.h> | 16 | #include <linux/device.h> |
15 | #include <linux/eventfd.h> | 17 | #include <linux/eventfd.h> |
16 | #include <linux/file.h> | 18 | #include <linux/file.h> |
@@ -33,6 +35,10 @@ | |||
33 | #define DRIVER_AUTHOR "Alex Williamson <alex.williamson@redhat.com>" | 35 | #define DRIVER_AUTHOR "Alex Williamson <alex.williamson@redhat.com>" |
34 | #define DRIVER_DESC "VFIO PCI - User Level meta-driver" | 36 | #define DRIVER_DESC "VFIO PCI - User Level meta-driver" |
35 | 37 | ||
38 | static char ids[1024] __initdata; | ||
39 | module_param_string(ids, ids, sizeof(ids), 0); | ||
40 | MODULE_PARM_DESC(ids, "Initial PCI IDs to add to the vfio driver, format is \"vendor:device[:subvendor[:subdevice[:class[:class_mask]]]]\" and multiple comma separated entries can be specified"); | ||
41 | |||
36 | static bool nointxmask; | 42 | static bool nointxmask; |
37 | module_param_named(nointxmask, nointxmask, bool, S_IRUGO | S_IWUSR); | 43 | module_param_named(nointxmask, nointxmask, bool, S_IRUGO | S_IWUSR); |
38 | MODULE_PARM_DESC(nointxmask, | 44 | MODULE_PARM_DESC(nointxmask, |
@@ -1105,6 +1111,47 @@ static void __exit vfio_pci_cleanup(void) | |||
1105 | vfio_pci_uninit_perm_bits(); | 1111 | vfio_pci_uninit_perm_bits(); |
1106 | } | 1112 | } |
1107 | 1113 | ||
1114 | static void __init vfio_pci_fill_ids(void) | ||
1115 | { | ||
1116 | char *p, *id; | ||
1117 | int rc; | ||
1118 | |||
1119 | /* no ids passed actually */ | ||
1120 | if (ids[0] == '\0') | ||
1121 | return; | ||
1122 | |||
1123 | /* add ids specified in the module parameter */ | ||
1124 | p = ids; | ||
1125 | while ((id = strsep(&p, ","))) { | ||
1126 | unsigned int vendor, device, subvendor = PCI_ANY_ID, | ||
1127 | subdevice = PCI_ANY_ID, class = 0, class_mask = 0; | ||
1128 | int fields; | ||
1129 | |||
1130 | if (!strlen(id)) | ||
1131 | continue; | ||
1132 | |||
1133 | fields = sscanf(id, "%x:%x:%x:%x:%x:%x", | ||
1134 | &vendor, &device, &subvendor, &subdevice, | ||
1135 | &class, &class_mask); | ||
1136 | |||
1137 | if (fields < 2) { | ||
1138 | pr_warn("invalid id string \"%s\"\n", id); | ||
1139 | continue; | ||
1140 | } | ||
1141 | |||
1142 | rc = pci_add_dynid(&vfio_pci_driver, vendor, device, | ||
1143 | subvendor, subdevice, class, class_mask, 0); | ||
1144 | if (rc) | ||
1145 | pr_warn("failed to add dynamic id [%04hx:%04hx[%04hx:%04hx]] class %#08x/%08x (%d)\n", | ||
1146 | vendor, device, subvendor, subdevice, | ||
1147 | class, class_mask, rc); | ||
1148 | else | ||
1149 | pr_info("add [%04hx:%04hx[%04hx:%04hx]] class %#08x/%08x\n", | ||
1150 | vendor, device, subvendor, subdevice, | ||
1151 | class, class_mask); | ||
1152 | } | ||
1153 | } | ||
1154 | |||
1108 | static int __init vfio_pci_init(void) | 1155 | static int __init vfio_pci_init(void) |
1109 | { | 1156 | { |
1110 | int ret; | 1157 | int ret; |
@@ -1119,6 +1166,8 @@ static int __init vfio_pci_init(void) | |||
1119 | if (ret) | 1166 | if (ret) |
1120 | goto out_driver; | 1167 | goto out_driver; |
1121 | 1168 | ||
1169 | vfio_pci_fill_ids(); | ||
1170 | |||
1122 | return 0; | 1171 | return 0; |
1123 | 1172 | ||
1124 | out_driver: | 1173 | out_driver: |