|
5 | 5 | * Copyright IBM Corp. 2018 |
6 | 6 | * |
7 | 7 | * Author(s): Tony Krowiak <[email protected]> |
| 8 | + * Pierre Morel <[email protected]> |
8 | 9 | */ |
9 | 10 |
|
10 | 11 | #include <linux/module.h> |
@@ -40,14 +41,45 @@ static struct ap_device_id ap_queue_ids[] = { |
40 | 41 |
|
41 | 42 | MODULE_DEVICE_TABLE(vfio_ap, ap_queue_ids); |
42 | 43 |
|
| 44 | +/** |
| 45 | + * vfio_ap_queue_dev_probe: |
| 46 | + * |
| 47 | + * Allocate a vfio_ap_queue structure and associate it |
| 48 | + * with the device as driver_data. |
| 49 | + */ |
43 | 50 | static int vfio_ap_queue_dev_probe(struct ap_device *apdev) |
44 | 51 | { |
| 52 | + struct vfio_ap_queue *q; |
| 53 | + |
| 54 | + q = kzalloc(sizeof(*q), GFP_KERNEL); |
| 55 | + if (!q) |
| 56 | + return -ENOMEM; |
| 57 | + dev_set_drvdata(&apdev->device, q); |
| 58 | + q->apqn = to_ap_queue(&apdev->device)->qid; |
| 59 | + q->saved_isc = VFIO_AP_ISC_INVALID; |
45 | 60 | return 0; |
46 | 61 | } |
47 | 62 |
|
| 63 | +/** |
| 64 | + * vfio_ap_queue_dev_remove: |
| 65 | + * |
| 66 | + * Takes the matrix lock to avoid actions on this device while removing |
| 67 | + * Free the associated vfio_ap_queue structure |
| 68 | + */ |
48 | 69 | static void vfio_ap_queue_dev_remove(struct ap_device *apdev) |
49 | 70 | { |
50 | | - /* Nothing to do yet */ |
| 71 | + struct vfio_ap_queue *q; |
| 72 | + int apid, apqi; |
| 73 | + |
| 74 | + mutex_lock(&matrix_dev->lock); |
| 75 | + q = dev_get_drvdata(&apdev->device); |
| 76 | + dev_set_drvdata(&apdev->device, NULL); |
| 77 | + apid = AP_QID_CARD(q->apqn); |
| 78 | + apqi = AP_QID_QUEUE(q->apqn); |
| 79 | + vfio_ap_mdev_reset_queue(apid, apqi, 1); |
| 80 | + vfio_ap_irq_disable(q); |
| 81 | + kfree(q); |
| 82 | + mutex_unlock(&matrix_dev->lock); |
51 | 83 | } |
52 | 84 |
|
53 | 85 | static void vfio_ap_matrix_dev_release(struct device *dev) |
|
0 commit comments