diff options
author | Alex Williamson <alex.williamson@redhat.com> | 2016-12-30 10:13:44 -0500 |
---|---|---|
committer | Alex Williamson <alex.williamson@redhat.com> | 2016-12-30 10:13:44 -0500 |
commit | 99e3123e3d72616a829dad6d25aa005ef1ef9b13 (patch) | |
tree | 691b36439a737eb0679e3544e3401335d7efda4e | |
parent | 9372e6feaafb65d88f667ffb5b7b425f8568344f (diff) |
vfio-mdev: Make mdev_device private and abstract interfaces
Abstract access to mdev_device so that we can define which interfaces
are public rather than relying on comments in the structure.
Cc: Zhenyu Wang <zhenyuw@linux.intel.com>
Cc: Zhi Wang <zhi.a.wang@intel.com>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Reviewed-by: Jike Song <jike.song@intel.com>
Reviewed by: Kirti Wankhede <kwankhede@nvidia.com>
-rw-r--r-- | drivers/gpu/drm/i915/gvt/kvmgt.c | 18 | ||||
-rw-r--r-- | drivers/vfio/mdev/mdev_core.c | 30 | ||||
-rw-r--r-- | drivers/vfio/mdev/mdev_private.h | 13 | ||||
-rw-r--r-- | include/linux/mdev.h | 31 | ||||
-rw-r--r-- | samples/vfio-mdev/mtty.c | 24 |
5 files changed, 71 insertions, 45 deletions
diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kvmgt.c index 38500329aa92..f8021a01df63 100644 --- a/drivers/gpu/drm/i915/gvt/kvmgt.c +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c | |||
@@ -166,7 +166,7 @@ static void __gvt_cache_remove_entry(struct intel_vgpu *vgpu, | |||
166 | 166 | ||
167 | static void gvt_cache_remove(struct intel_vgpu *vgpu, gfn_t gfn) | 167 | static void gvt_cache_remove(struct intel_vgpu *vgpu, gfn_t gfn) |
168 | { | 168 | { |
169 | struct device *dev = &vgpu->vdev.mdev->dev; | 169 | struct device *dev = mdev_dev(vgpu->vdev.mdev); |
170 | struct gvt_dma *this; | 170 | struct gvt_dma *this; |
171 | unsigned long g1; | 171 | unsigned long g1; |
172 | int rc; | 172 | int rc; |
@@ -195,7 +195,7 @@ static void gvt_cache_destroy(struct intel_vgpu *vgpu) | |||
195 | { | 195 | { |
196 | struct gvt_dma *dma; | 196 | struct gvt_dma *dma; |
197 | struct rb_node *node = NULL; | 197 | struct rb_node *node = NULL; |
198 | struct device *dev = &vgpu->vdev.mdev->dev; | 198 | struct device *dev = mdev_dev(vgpu->vdev.mdev); |
199 | unsigned long gfn; | 199 | unsigned long gfn; |
200 | 200 | ||
201 | mutex_lock(&vgpu->vdev.cache_lock); | 201 | mutex_lock(&vgpu->vdev.cache_lock); |
@@ -418,7 +418,7 @@ static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev) | |||
418 | mdev_set_drvdata(mdev, vgpu); | 418 | mdev_set_drvdata(mdev, vgpu); |
419 | 419 | ||
420 | gvt_dbg_core("intel_vgpu_create succeeded for mdev: %s\n", | 420 | gvt_dbg_core("intel_vgpu_create succeeded for mdev: %s\n", |
421 | dev_name(&mdev->dev)); | 421 | dev_name(mdev_dev(mdev))); |
422 | return 0; | 422 | return 0; |
423 | } | 423 | } |
424 | 424 | ||
@@ -482,7 +482,7 @@ static int intel_vgpu_open(struct mdev_device *mdev) | |||
482 | vgpu->vdev.group_notifier.notifier_call = intel_vgpu_group_notifier; | 482 | vgpu->vdev.group_notifier.notifier_call = intel_vgpu_group_notifier; |
483 | 483 | ||
484 | events = VFIO_IOMMU_NOTIFY_DMA_UNMAP; | 484 | events = VFIO_IOMMU_NOTIFY_DMA_UNMAP; |
485 | ret = vfio_register_notifier(&mdev->dev, VFIO_IOMMU_NOTIFY, &events, | 485 | ret = vfio_register_notifier(mdev_dev(mdev), VFIO_IOMMU_NOTIFY, &events, |
486 | &vgpu->vdev.iommu_notifier); | 486 | &vgpu->vdev.iommu_notifier); |
487 | if (ret != 0) { | 487 | if (ret != 0) { |
488 | gvt_err("vfio_register_notifier for iommu failed: %d\n", ret); | 488 | gvt_err("vfio_register_notifier for iommu failed: %d\n", ret); |
@@ -490,7 +490,7 @@ static int intel_vgpu_open(struct mdev_device *mdev) | |||
490 | } | 490 | } |
491 | 491 | ||
492 | events = VFIO_GROUP_NOTIFY_SET_KVM; | 492 | events = VFIO_GROUP_NOTIFY_SET_KVM; |
493 | ret = vfio_register_notifier(&mdev->dev, VFIO_GROUP_NOTIFY, &events, | 493 | ret = vfio_register_notifier(mdev_dev(mdev), VFIO_GROUP_NOTIFY, &events, |
494 | &vgpu->vdev.group_notifier); | 494 | &vgpu->vdev.group_notifier); |
495 | if (ret != 0) { | 495 | if (ret != 0) { |
496 | gvt_err("vfio_register_notifier for group failed: %d\n", ret); | 496 | gvt_err("vfio_register_notifier for group failed: %d\n", ret); |
@@ -500,7 +500,7 @@ static int intel_vgpu_open(struct mdev_device *mdev) | |||
500 | return kvmgt_guest_init(mdev); | 500 | return kvmgt_guest_init(mdev); |
501 | 501 | ||
502 | undo_iommu: | 502 | undo_iommu: |
503 | vfio_unregister_notifier(&mdev->dev, VFIO_IOMMU_NOTIFY, | 503 | vfio_unregister_notifier(mdev_dev(mdev), VFIO_IOMMU_NOTIFY, |
504 | &vgpu->vdev.iommu_notifier); | 504 | &vgpu->vdev.iommu_notifier); |
505 | out: | 505 | out: |
506 | return ret; | 506 | return ret; |
@@ -513,9 +513,9 @@ static void __intel_vgpu_release(struct intel_vgpu *vgpu) | |||
513 | if (!handle_valid(vgpu->handle)) | 513 | if (!handle_valid(vgpu->handle)) |
514 | return; | 514 | return; |
515 | 515 | ||
516 | vfio_unregister_notifier(&vgpu->vdev.mdev->dev, VFIO_IOMMU_NOTIFY, | 516 | vfio_unregister_notifier(mdev_dev(vgpu->vdev.mdev), VFIO_IOMMU_NOTIFY, |
517 | &vgpu->vdev.iommu_notifier); | 517 | &vgpu->vdev.iommu_notifier); |
518 | vfio_unregister_notifier(&vgpu->vdev.mdev->dev, VFIO_GROUP_NOTIFY, | 518 | vfio_unregister_notifier(mdev_dev(vgpu->vdev.mdev), VFIO_GROUP_NOTIFY, |
519 | &vgpu->vdev.group_notifier); | 519 | &vgpu->vdev.group_notifier); |
520 | 520 | ||
521 | info = (struct kvmgt_guest_info *)vgpu->handle; | 521 | info = (struct kvmgt_guest_info *)vgpu->handle; |
@@ -1372,7 +1372,7 @@ static unsigned long kvmgt_gfn_to_pfn(unsigned long handle, unsigned long gfn) | |||
1372 | return pfn; | 1372 | return pfn; |
1373 | 1373 | ||
1374 | pfn = INTEL_GVT_INVALID_ADDR; | 1374 | pfn = INTEL_GVT_INVALID_ADDR; |
1375 | dev = &info->vgpu->vdev.mdev->dev; | 1375 | dev = mdev_dev(info->vgpu->vdev.mdev); |
1376 | rc = vfio_pin_pages(dev, &gfn, 1, IOMMU_READ | IOMMU_WRITE, &pfn); | 1376 | rc = vfio_pin_pages(dev, &gfn, 1, IOMMU_READ | IOMMU_WRITE, &pfn); |
1377 | if (rc != 1) { | 1377 | if (rc != 1) { |
1378 | gvt_err("vfio_pin_pages failed for gfn 0x%lx: %d\n", gfn, rc); | 1378 | gvt_err("vfio_pin_pages failed for gfn 0x%lx: %d\n", gfn, rc); |
diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c index 30d05304241e..36d75c367d22 100644 --- a/drivers/vfio/mdev/mdev_core.c +++ b/drivers/vfio/mdev/mdev_core.c | |||
@@ -36,6 +36,36 @@ struct device *mdev_parent_dev(struct mdev_device *mdev) | |||
36 | } | 36 | } |
37 | EXPORT_SYMBOL(mdev_parent_dev); | 37 | EXPORT_SYMBOL(mdev_parent_dev); |
38 | 38 | ||
39 | void *mdev_get_drvdata(struct mdev_device *mdev) | ||
40 | { | ||
41 | return mdev->driver_data; | ||
42 | } | ||
43 | EXPORT_SYMBOL(mdev_get_drvdata); | ||
44 | |||
45 | void mdev_set_drvdata(struct mdev_device *mdev, void *data) | ||
46 | { | ||
47 | mdev->driver_data = data; | ||
48 | } | ||
49 | EXPORT_SYMBOL(mdev_set_drvdata); | ||
50 | |||
51 | struct device *mdev_dev(struct mdev_device *mdev) | ||
52 | { | ||
53 | return &mdev->dev; | ||
54 | } | ||
55 | EXPORT_SYMBOL(mdev_dev); | ||
56 | |||
57 | struct mdev_device *mdev_from_dev(struct device *dev) | ||
58 | { | ||
59 | return dev_is_mdev(dev) ? to_mdev_device(dev) : NULL; | ||
60 | } | ||
61 | EXPORT_SYMBOL(mdev_from_dev); | ||
62 | |||
63 | uuid_le mdev_uuid(struct mdev_device *mdev) | ||
64 | { | ||
65 | return mdev->uuid; | ||
66 | } | ||
67 | EXPORT_SYMBOL(mdev_uuid); | ||
68 | |||
39 | static int _find_mdev_device(struct device *dev, void *data) | 69 | static int _find_mdev_device(struct device *dev, void *data) |
40 | { | 70 | { |
41 | struct mdev_device *mdev; | 71 | struct mdev_device *mdev; |
diff --git a/drivers/vfio/mdev/mdev_private.h b/drivers/vfio/mdev/mdev_private.h index b05dd22fc9a6..a9cefd70a705 100644 --- a/drivers/vfio/mdev/mdev_private.h +++ b/drivers/vfio/mdev/mdev_private.h | |||
@@ -26,6 +26,19 @@ struct mdev_parent { | |||
26 | struct list_head type_list; | 26 | struct list_head type_list; |
27 | }; | 27 | }; |
28 | 28 | ||
29 | struct mdev_device { | ||
30 | struct device dev; | ||
31 | struct mdev_parent *parent; | ||
32 | uuid_le uuid; | ||
33 | void *driver_data; | ||
34 | struct kref ref; | ||
35 | struct list_head next; | ||
36 | struct kobject *type_kobj; | ||
37 | }; | ||
38 | |||
39 | #define to_mdev_device(dev) container_of(dev, struct mdev_device, dev) | ||
40 | #define dev_is_mdev(d) ((d)->bus == &mdev_bus_type) | ||
41 | |||
29 | struct mdev_type { | 42 | struct mdev_type { |
30 | struct kobject kobj; | 43 | struct kobject kobj; |
31 | struct kobject *devices_kobj; | 44 | struct kobject *devices_kobj; |
diff --git a/include/linux/mdev.h b/include/linux/mdev.h index f586222b6c25..3ee44b8d2bb3 100644 --- a/include/linux/mdev.h +++ b/include/linux/mdev.h | |||
@@ -13,18 +13,7 @@ | |||
13 | #ifndef MDEV_H | 13 | #ifndef MDEV_H |
14 | #define MDEV_H | 14 | #define MDEV_H |
15 | 15 | ||
16 | /* Mediated device */ | 16 | struct mdev_device; |
17 | struct mdev_device { | ||
18 | struct device dev; | ||
19 | struct mdev_parent *parent; | ||
20 | uuid_le uuid; | ||
21 | void *driver_data; | ||
22 | |||
23 | /* internal */ | ||
24 | struct kref ref; | ||
25 | struct list_head next; | ||
26 | struct kobject *type_kobj; | ||
27 | }; | ||
28 | 17 | ||
29 | /** | 18 | /** |
30 | * struct mdev_parent_ops - Structure to be registered for each parent device to | 19 | * struct mdev_parent_ops - Structure to be registered for each parent device to |
@@ -75,7 +64,6 @@ struct mdev_device { | |||
75 | * Parent device that support mediated device should be registered with mdev | 64 | * Parent device that support mediated device should be registered with mdev |
76 | * module with mdev_parent_ops structure. | 65 | * module with mdev_parent_ops structure. |
77 | **/ | 66 | **/ |
78 | |||
79 | struct mdev_parent_ops { | 67 | struct mdev_parent_ops { |
80 | struct module *owner; | 68 | struct module *owner; |
81 | const struct attribute_group **dev_attr_groups; | 69 | const struct attribute_group **dev_attr_groups; |
@@ -129,22 +117,13 @@ struct mdev_driver { | |||
129 | }; | 117 | }; |
130 | 118 | ||
131 | #define to_mdev_driver(drv) container_of(drv, struct mdev_driver, driver) | 119 | #define to_mdev_driver(drv) container_of(drv, struct mdev_driver, driver) |
132 | #define to_mdev_device(dev) container_of(dev, struct mdev_device, dev) | ||
133 | 120 | ||
134 | static inline void *mdev_get_drvdata(struct mdev_device *mdev) | 121 | extern void *mdev_get_drvdata(struct mdev_device *mdev); |
135 | { | 122 | extern void mdev_set_drvdata(struct mdev_device *mdev, void *data); |
136 | return mdev->driver_data; | 123 | extern uuid_le mdev_uuid(struct mdev_device *mdev); |
137 | } | ||
138 | |||
139 | static inline void mdev_set_drvdata(struct mdev_device *mdev, void *data) | ||
140 | { | ||
141 | mdev->driver_data = data; | ||
142 | } | ||
143 | 124 | ||
144 | extern struct bus_type mdev_bus_type; | 125 | extern struct bus_type mdev_bus_type; |
145 | 126 | ||
146 | #define dev_is_mdev(d) ((d)->bus == &mdev_bus_type) | ||
147 | |||
148 | extern int mdev_register_device(struct device *dev, | 127 | extern int mdev_register_device(struct device *dev, |
149 | const struct mdev_parent_ops *ops); | 128 | const struct mdev_parent_ops *ops); |
150 | extern void mdev_unregister_device(struct device *dev); | 129 | extern void mdev_unregister_device(struct device *dev); |
@@ -153,5 +132,7 @@ extern int mdev_register_driver(struct mdev_driver *drv, struct module *owner); | |||
153 | extern void mdev_unregister_driver(struct mdev_driver *drv); | 132 | extern void mdev_unregister_driver(struct mdev_driver *drv); |
154 | 133 | ||
155 | extern struct device *mdev_parent_dev(struct mdev_device *mdev); | 134 | extern struct device *mdev_parent_dev(struct mdev_device *mdev); |
135 | extern struct device *mdev_dev(struct mdev_device *mdev); | ||
136 | extern struct mdev_device *mdev_from_dev(struct device *dev); | ||
156 | 137 | ||
157 | #endif /* MDEV_H */ | 138 | #endif /* MDEV_H */ |
diff --git a/samples/vfio-mdev/mtty.c b/samples/vfio-mdev/mtty.c index 5e13efc62bad..919c10d5b12e 100644 --- a/samples/vfio-mdev/mtty.c +++ b/samples/vfio-mdev/mtty.c | |||
@@ -164,7 +164,7 @@ static struct mdev_state *find_mdev_state_by_uuid(uuid_le uuid) | |||
164 | struct mdev_state *mds; | 164 | struct mdev_state *mds; |
165 | 165 | ||
166 | list_for_each_entry(mds, &mdev_devices_list, next) { | 166 | list_for_each_entry(mds, &mdev_devices_list, next) { |
167 | if (uuid_le_cmp(mds->mdev->uuid, uuid) == 0) | 167 | if (uuid_le_cmp(mdev_uuid(mds->mdev), uuid) == 0) |
168 | return mds; | 168 | return mds; |
169 | } | 169 | } |
170 | 170 | ||
@@ -341,7 +341,8 @@ static void handle_bar_write(unsigned int index, struct mdev_state *mdev_state, | |||
341 | pr_err("Serial port %d: Fifo level trigger\n", | 341 | pr_err("Serial port %d: Fifo level trigger\n", |
342 | index); | 342 | index); |
343 | #endif | 343 | #endif |
344 | mtty_trigger_interrupt(mdev_state->mdev->uuid); | 344 | mtty_trigger_interrupt( |
345 | mdev_uuid(mdev_state->mdev)); | ||
345 | } | 346 | } |
346 | } else { | 347 | } else { |
347 | #if defined(DEBUG_INTR) | 348 | #if defined(DEBUG_INTR) |
@@ -355,7 +356,8 @@ static void handle_bar_write(unsigned int index, struct mdev_state *mdev_state, | |||
355 | */ | 356 | */ |
356 | if (mdev_state->s[index].uart_reg[UART_IER] & | 357 | if (mdev_state->s[index].uart_reg[UART_IER] & |
357 | UART_IER_RLSI) | 358 | UART_IER_RLSI) |
358 | mtty_trigger_interrupt(mdev_state->mdev->uuid); | 359 | mtty_trigger_interrupt( |
360 | mdev_uuid(mdev_state->mdev)); | ||
359 | } | 361 | } |
360 | mutex_unlock(&mdev_state->rxtx_lock); | 362 | mutex_unlock(&mdev_state->rxtx_lock); |
361 | break; | 363 | break; |
@@ -374,7 +376,8 @@ static void handle_bar_write(unsigned int index, struct mdev_state *mdev_state, | |||
374 | pr_err("Serial port %d: IER_THRI write\n", | 376 | pr_err("Serial port %d: IER_THRI write\n", |
375 | index); | 377 | index); |
376 | #endif | 378 | #endif |
377 | mtty_trigger_interrupt(mdev_state->mdev->uuid); | 379 | mtty_trigger_interrupt( |
380 | mdev_uuid(mdev_state->mdev)); | ||
378 | } | 381 | } |
379 | 382 | ||
380 | mutex_unlock(&mdev_state->rxtx_lock); | 383 | mutex_unlock(&mdev_state->rxtx_lock); |
@@ -445,7 +448,7 @@ static void handle_bar_write(unsigned int index, struct mdev_state *mdev_state, | |||
445 | #if defined(DEBUG_INTR) | 448 | #if defined(DEBUG_INTR) |
446 | pr_err("Serial port %d: MCR_OUT2 write\n", index); | 449 | pr_err("Serial port %d: MCR_OUT2 write\n", index); |
447 | #endif | 450 | #endif |
448 | mtty_trigger_interrupt(mdev_state->mdev->uuid); | 451 | mtty_trigger_interrupt(mdev_uuid(mdev_state->mdev)); |
449 | } | 452 | } |
450 | 453 | ||
451 | if ((mdev_state->s[index].uart_reg[UART_IER] & UART_IER_MSI) && | 454 | if ((mdev_state->s[index].uart_reg[UART_IER] & UART_IER_MSI) && |
@@ -453,7 +456,7 @@ static void handle_bar_write(unsigned int index, struct mdev_state *mdev_state, | |||
453 | #if defined(DEBUG_INTR) | 456 | #if defined(DEBUG_INTR) |
454 | pr_err("Serial port %d: MCR RTS/DTR write\n", index); | 457 | pr_err("Serial port %d: MCR RTS/DTR write\n", index); |
455 | #endif | 458 | #endif |
456 | mtty_trigger_interrupt(mdev_state->mdev->uuid); | 459 | mtty_trigger_interrupt(mdev_uuid(mdev_state->mdev)); |
457 | } | 460 | } |
458 | break; | 461 | break; |
459 | 462 | ||
@@ -504,7 +507,8 @@ static void handle_bar_read(unsigned int index, struct mdev_state *mdev_state, | |||
504 | #endif | 507 | #endif |
505 | if (mdev_state->s[index].uart_reg[UART_IER] & | 508 | if (mdev_state->s[index].uart_reg[UART_IER] & |
506 | UART_IER_THRI) | 509 | UART_IER_THRI) |
507 | mtty_trigger_interrupt(mdev_state->mdev->uuid); | 510 | mtty_trigger_interrupt( |
511 | mdev_uuid(mdev_state->mdev)); | ||
508 | } | 512 | } |
509 | mutex_unlock(&mdev_state->rxtx_lock); | 513 | mutex_unlock(&mdev_state->rxtx_lock); |
510 | 514 | ||
@@ -1298,10 +1302,8 @@ static ssize_t | |||
1298 | sample_mdev_dev_show(struct device *dev, struct device_attribute *attr, | 1302 | sample_mdev_dev_show(struct device *dev, struct device_attribute *attr, |
1299 | char *buf) | 1303 | char *buf) |
1300 | { | 1304 | { |
1301 | struct mdev_device *mdev = to_mdev_device(dev); | 1305 | if (mdev_from_dev(dev)) |
1302 | 1306 | return sprintf(buf, "This is MDEV %s\n", dev_name(dev)); | |
1303 | if (mdev) | ||
1304 | return sprintf(buf, "This is MDEV %s\n", dev_name(&mdev->dev)); | ||
1305 | 1307 | ||
1306 | return sprintf(buf, "\n"); | 1308 | return sprintf(buf, "\n"); |
1307 | } | 1309 | } |