1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (C) 2013 - Virtual Open Systems
4 * Author: Antonios Motakis <a.motakis@virtualopensystems.com>
5 */
6
7 #define dev_fmt(fmt) "VFIO: " fmt
8
9 #include <linux/device.h>
10 #include <linux/acpi.h>
11 #include <linux/iommu.h>
12 #include <linux/module.h>
13 #include <linux/mutex.h>
14 #include <linux/pm_runtime.h>
15 #include <linux/slab.h>
16 #include <linux/types.h>
17 #include <linux/uaccess.h>
18 #include <linux/vfio.h>
19
20 #include "vfio_platform_private.h"
21
22 #define DRIVER_VERSION "0.10"
23 #define DRIVER_AUTHOR "Antonios Motakis <a.motakis@virtualopensystems.com>"
24 #define DRIVER_DESC "VFIO platform base module"
25
26 #define VFIO_PLATFORM_IS_ACPI(vdev) ((vdev)->acpihid != NULL)
27
28 static LIST_HEAD(reset_list);
29 static DEFINE_MUTEX(driver_lock);
30
vfio_platform_lookup_reset(const char *compat, struct module **module)31 static vfio_platform_reset_fn_t vfio_platform_lookup_reset(const char *compat,
32 struct module **module)
33 {
34 struct vfio_platform_reset_node *iter;
35 vfio_platform_reset_fn_t reset_fn = NULL;
36
37 mutex_lock(&driver_lock);
38 list_for_each_entry(iter, &reset_list, link) {
39 if (!strcmp(iter->compat, compat) &&
40 try_module_get(iter->owner)) {
41 *module = iter->owner;
42 reset_fn = iter->of_reset;
43 break;
44 }
45 }
46 mutex_unlock(&driver_lock);
47 return reset_fn;
48 }
49
vfio_platform_acpi_probe(struct vfio_platform_device *vdev, struct device *dev)50 static int vfio_platform_acpi_probe(struct vfio_platform_device *vdev,
51 struct device *dev)
52 {
53 struct acpi_device *adev;
54
55 if (acpi_disabled)
56 return -ENOENT;
57
58 adev = ACPI_COMPANION(dev);
59 if (!adev) {
60 dev_err(dev, "ACPI companion device not found for %s\n",
61 vdev->name);
62 return -ENODEV;
63 }
64
65 #ifdef CONFIG_ACPI
66 vdev->acpihid = acpi_device_hid(adev);
67 #endif
68 return WARN_ON(!vdev->acpihid) ? -EINVAL : 0;
69 }
70
vfio_platform_acpi_call_reset(struct vfio_platform_device *vdev, const char **extra_dbg)71 static int vfio_platform_acpi_call_reset(struct vfio_platform_device *vdev,
72 const char **extra_dbg)
73 {
74 #ifdef CONFIG_ACPI
75 struct device *dev = vdev->device;
76 acpi_handle handle = ACPI_HANDLE(dev);
77 acpi_status acpi_ret;
78
79 acpi_ret = acpi_evaluate_object(handle, "_RST", NULL, NULL);
80 if (ACPI_FAILURE(acpi_ret)) {
81 if (extra_dbg)
82 *extra_dbg = acpi_format_exception(acpi_ret);
83 return -EINVAL;
84 }
85
86 return 0;
87 #else
88 return -ENOENT;
89 #endif
90 }
91
vfio_platform_acpi_has_reset(struct vfio_platform_device *vdev)92 static bool vfio_platform_acpi_has_reset(struct vfio_platform_device *vdev)
93 {
94 #ifdef CONFIG_ACPI
95 struct device *dev = vdev->device;
96 acpi_handle handle = ACPI_HANDLE(dev);
97
98 return acpi_has_method(handle, "_RST");
99 #else
100 return false;
101 #endif
102 }
103
vfio_platform_has_reset(struct vfio_platform_device *vdev)104 static bool vfio_platform_has_reset(struct vfio_platform_device *vdev)
105 {
106 if (VFIO_PLATFORM_IS_ACPI(vdev))
107 return vfio_platform_acpi_has_reset(vdev);
108
109 return vdev->of_reset ? true : false;
110 }
111
vfio_platform_get_reset(struct vfio_platform_device *vdev)112 static int vfio_platform_get_reset(struct vfio_platform_device *vdev)
113 {
114 if (VFIO_PLATFORM_IS_ACPI(vdev))
115 return vfio_platform_acpi_has_reset(vdev) ? 0 : -ENOENT;
116
117 vdev->of_reset = vfio_platform_lookup_reset(vdev->compat,
118 &vdev->reset_module);
119 if (!vdev->of_reset) {
120 request_module("vfio-reset:%s", vdev->compat);
121 vdev->of_reset = vfio_platform_lookup_reset(vdev->compat,
122 &vdev->reset_module);
123 }
124
125 return vdev->of_reset ? 0 : -ENOENT;
126 }
127
vfio_platform_put_reset(struct vfio_platform_device *vdev)128 static void vfio_platform_put_reset(struct vfio_platform_device *vdev)
129 {
130 if (VFIO_PLATFORM_IS_ACPI(vdev))
131 return;
132
133 if (vdev->of_reset)
134 module_put(vdev->reset_module);
135 }
136
vfio_platform_regions_init(struct vfio_platform_device *vdev)137 static int vfio_platform_regions_init(struct vfio_platform_device *vdev)
138 {
139 int cnt = 0, i;
140
141 while (vdev->get_resource(vdev, cnt))
142 cnt++;
143
144 vdev->regions = kcalloc(cnt, sizeof(struct vfio_platform_region),
145 GFP_KERNEL);
146 if (!vdev->regions)
147 return -ENOMEM;
148
149 for (i = 0; i < cnt; i++) {
150 struct resource *res =
151 vdev->get_resource(vdev, i);
152
153 if (!res)
154 goto err;
155
156 vdev->regions[i].addr = res->start;
157 vdev->regions[i].size = resource_size(res);
158 vdev->regions[i].flags = 0;
159
160 switch (resource_type(res)) {
161 case IORESOURCE_MEM:
162 vdev->regions[i].type = VFIO_PLATFORM_REGION_TYPE_MMIO;
163 vdev->regions[i].flags |= VFIO_REGION_INFO_FLAG_READ;
164 if (!(res->flags & IORESOURCE_READONLY))
165 vdev->regions[i].flags |=
166 VFIO_REGION_INFO_FLAG_WRITE;
167
168 /*
169 * Only regions addressed with PAGE granularity may be
170 * MMAPed securely.
171 */
172 if (!(vdev->regions[i].addr & ~PAGE_MASK) &&
173 !(vdev->regions[i].size & ~PAGE_MASK))
174 vdev->regions[i].flags |=
175 VFIO_REGION_INFO_FLAG_MMAP;
176
177 break;
178 case IORESOURCE_IO:
179 vdev->regions[i].type = VFIO_PLATFORM_REGION_TYPE_PIO;
180 break;
181 default:
182 goto err;
183 }
184 }
185
186 vdev->num_regions = cnt;
187
188 return 0;
189 err:
190 kfree(vdev->regions);
191 return -EINVAL;
192 }
193
vfio_platform_regions_cleanup(struct vfio_platform_device *vdev)194 static void vfio_platform_regions_cleanup(struct vfio_platform_device *vdev)
195 {
196 int i;
197
198 for (i = 0; i < vdev->num_regions; i++)
199 iounmap(vdev->regions[i].ioaddr);
200
201 vdev->num_regions = 0;
202 kfree(vdev->regions);
203 }
204
vfio_platform_call_reset(struct vfio_platform_device *vdev, const char **extra_dbg)205 static int vfio_platform_call_reset(struct vfio_platform_device *vdev,
206 const char **extra_dbg)
207 {
208 if (VFIO_PLATFORM_IS_ACPI(vdev)) {
209 dev_info(vdev->device, "reset\n");
210 return vfio_platform_acpi_call_reset(vdev, extra_dbg);
211 } else if (vdev->of_reset) {
212 dev_info(vdev->device, "reset\n");
213 return vdev->of_reset(vdev);
214 }
215
216 dev_warn(vdev->device, "no reset function found!\n");
217 return -EINVAL;
218 }
219
vfio_platform_release(void *device_data)220 static void vfio_platform_release(void *device_data)
221 {
222 struct vfio_platform_device *vdev = device_data;
223
224 mutex_lock(&driver_lock);
225
226 if (!(--vdev->refcnt)) {
227 const char *extra_dbg = NULL;
228 int ret;
229
230 ret = vfio_platform_call_reset(vdev, &extra_dbg);
231 if (ret && vdev->reset_required) {
232 dev_warn(vdev->device, "reset driver is required and reset call failed in release (%d) %s\n",
233 ret, extra_dbg ? extra_dbg : "");
234 WARN_ON(1);
235 }
236 pm_runtime_put(vdev->device);
237 vfio_platform_regions_cleanup(vdev);
238 vfio_platform_irq_cleanup(vdev);
239 }
240
241 mutex_unlock(&driver_lock);
242
243 module_put(vdev->parent_module);
244 }
245
vfio_platform_open(void *device_data)246 static int vfio_platform_open(void *device_data)
247 {
248 struct vfio_platform_device *vdev = device_data;
249 int ret;
250
251 if (!try_module_get(vdev->parent_module))
252 return -ENODEV;
253
254 mutex_lock(&driver_lock);
255
256 if (!vdev->refcnt) {
257 const char *extra_dbg = NULL;
258
259 ret = vfio_platform_regions_init(vdev);
260 if (ret)
261 goto err_reg;
262
263 ret = vfio_platform_irq_init(vdev);
264 if (ret)
265 goto err_irq;
266
267 ret = pm_runtime_get_sync(vdev->device);
268 if (ret < 0)
269 goto err_rst;
270
271 ret = vfio_platform_call_reset(vdev, &extra_dbg);
272 if (ret && vdev->reset_required) {
273 dev_warn(vdev->device, "reset driver is required and reset call failed in open (%d) %s\n",
274 ret, extra_dbg ? extra_dbg : "");
275 goto err_rst;
276 }
277 }
278
279 vdev->refcnt++;
280
281 mutex_unlock(&driver_lock);
282 return 0;
283
284 err_rst:
285 pm_runtime_put(vdev->device);
286 vfio_platform_irq_cleanup(vdev);
287 err_irq:
288 vfio_platform_regions_cleanup(vdev);
289 err_reg:
290 mutex_unlock(&driver_lock);
291 module_put(vdev->parent_module);
292 return ret;
293 }
294
vfio_platform_ioctl(void *device_data, unsigned int cmd, unsigned long arg)295 static long vfio_platform_ioctl(void *device_data,
296 unsigned int cmd, unsigned long arg)
297 {
298 struct vfio_platform_device *vdev = device_data;
299 unsigned long minsz;
300
301 if (cmd == VFIO_DEVICE_GET_INFO) {
302 struct vfio_device_info info;
303
304 minsz = offsetofend(struct vfio_device_info, num_irqs);
305
306 if (copy_from_user(&info, (void __user *)arg, minsz))
307 return -EFAULT;
308
309 if (info.argsz < minsz)
310 return -EINVAL;
311
312 if (vfio_platform_has_reset(vdev))
313 vdev->flags |= VFIO_DEVICE_FLAGS_RESET;
314 info.flags = vdev->flags;
315 info.num_regions = vdev->num_regions;
316 info.num_irqs = vdev->num_irqs;
317
318 return copy_to_user((void __user *)arg, &info, minsz) ?
319 -EFAULT : 0;
320
321 } else if (cmd == VFIO_DEVICE_GET_REGION_INFO) {
322 struct vfio_region_info info;
323
324 minsz = offsetofend(struct vfio_region_info, offset);
325
326 if (copy_from_user(&info, (void __user *)arg, minsz))
327 return -EFAULT;
328
329 if (info.argsz < minsz)
330 return -EINVAL;
331
332 if (info.index >= vdev->num_regions)
333 return -EINVAL;
334
335 /* map offset to the physical address */
336 info.offset = VFIO_PLATFORM_INDEX_TO_OFFSET(info.index);
337 info.size = vdev->regions[info.index].size;
338 info.flags = vdev->regions[info.index].flags;
339
340 return copy_to_user((void __user *)arg, &info, minsz) ?
341 -EFAULT : 0;
342
343 } else if (cmd == VFIO_DEVICE_GET_IRQ_INFO) {
344 struct vfio_irq_info info;
345
346 minsz = offsetofend(struct vfio_irq_info, count);
347
348 if (copy_from_user(&info, (void __user *)arg, minsz))
349 return -EFAULT;
350
351 if (info.argsz < minsz)
352 return -EINVAL;
353
354 if (info.index >= vdev->num_irqs)
355 return -EINVAL;
356
357 info.flags = vdev->irqs[info.index].flags;
358 info.count = vdev->irqs[info.index].count;
359
360 return copy_to_user((void __user *)arg, &info, minsz) ?
361 -EFAULT : 0;
362
363 } else if (cmd == VFIO_DEVICE_SET_IRQS) {
364 struct vfio_irq_set hdr;
365 u8 *data = NULL;
366 int ret = 0;
367 size_t data_size = 0;
368
369 minsz = offsetofend(struct vfio_irq_set, count);
370
371 if (copy_from_user(&hdr, (void __user *)arg, minsz))
372 return -EFAULT;
373
374 ret = vfio_set_irqs_validate_and_prepare(&hdr, vdev->num_irqs,
375 vdev->num_irqs, &data_size);
376 if (ret)
377 return ret;
378
379 if (data_size) {
380 data = memdup_user((void __user *)(arg + minsz),
381 data_size);
382 if (IS_ERR(data))
383 return PTR_ERR(data);
384 }
385
386 mutex_lock(&vdev->igate);
387
388 ret = vfio_platform_set_irqs_ioctl(vdev, hdr.flags, hdr.index,
389 hdr.start, hdr.count, data);
390 mutex_unlock(&vdev->igate);
391 kfree(data);
392
393 return ret;
394
395 } else if (cmd == VFIO_DEVICE_RESET) {
396 return vfio_platform_call_reset(vdev, NULL);
397 }
398
399 return -ENOTTY;
400 }
401
vfio_platform_read_mmio(struct vfio_platform_region *reg, char __user *buf, size_t count, loff_t off)402 static ssize_t vfio_platform_read_mmio(struct vfio_platform_region *reg,
403 char __user *buf, size_t count,
404 loff_t off)
405 {
406 unsigned int done = 0;
407
408 if (!reg->ioaddr) {
409 reg->ioaddr =
410 ioremap(reg->addr, reg->size);
411
412 if (!reg->ioaddr)
413 return -ENOMEM;
414 }
415
416 while (count) {
417 size_t filled;
418
419 if (count >= 4 && !(off % 4)) {
420 u32 val;
421
422 val = ioread32(reg->ioaddr + off);
423 if (copy_to_user(buf, &val, 4))
424 goto err;
425
426 filled = 4;
427 } else if (count >= 2 && !(off % 2)) {
428 u16 val;
429
430 val = ioread16(reg->ioaddr + off);
431 if (copy_to_user(buf, &val, 2))
432 goto err;
433
434 filled = 2;
435 } else {
436 u8 val;
437
438 val = ioread8(reg->ioaddr + off);
439 if (copy_to_user(buf, &val, 1))
440 goto err;
441
442 filled = 1;
443 }
444
445
446 count -= filled;
447 done += filled;
448 off += filled;
449 buf += filled;
450 }
451
452 return done;
453 err:
454 return -EFAULT;
455 }
456
vfio_platform_read(void *device_data, char __user *buf, size_t count, loff_t *ppos)457 static ssize_t vfio_platform_read(void *device_data, char __user *buf,
458 size_t count, loff_t *ppos)
459 {
460 struct vfio_platform_device *vdev = device_data;
461 unsigned int index = VFIO_PLATFORM_OFFSET_TO_INDEX(*ppos);
462 loff_t off = *ppos & VFIO_PLATFORM_OFFSET_MASK;
463
464 if (index >= vdev->num_regions)
465 return -EINVAL;
466
467 if (!(vdev->regions[index].flags & VFIO_REGION_INFO_FLAG_READ))
468 return -EINVAL;
469
470 if (vdev->regions[index].type & VFIO_PLATFORM_REGION_TYPE_MMIO)
471 return vfio_platform_read_mmio(&vdev->regions[index],
472 buf, count, off);
473 else if (vdev->regions[index].type & VFIO_PLATFORM_REGION_TYPE_PIO)
474 return -EINVAL; /* not implemented */
475
476 return -EINVAL;
477 }
478
vfio_platform_write_mmio(struct vfio_platform_region *reg, const char __user *buf, size_t count, loff_t off)479 static ssize_t vfio_platform_write_mmio(struct vfio_platform_region *reg,
480 const char __user *buf, size_t count,
481 loff_t off)
482 {
483 unsigned int done = 0;
484
485 if (!reg->ioaddr) {
486 reg->ioaddr =
487 ioremap(reg->addr, reg->size);
488
489 if (!reg->ioaddr)
490 return -ENOMEM;
491 }
492
493 while (count) {
494 size_t filled;
495
496 if (count >= 4 && !(off % 4)) {
497 u32 val;
498
499 if (copy_from_user(&val, buf, 4))
500 goto err;
501 iowrite32(val, reg->ioaddr + off);
502
503 filled = 4;
504 } else if (count >= 2 && !(off % 2)) {
505 u16 val;
506
507 if (copy_from_user(&val, buf, 2))
508 goto err;
509 iowrite16(val, reg->ioaddr + off);
510
511 filled = 2;
512 } else {
513 u8 val;
514
515 if (copy_from_user(&val, buf, 1))
516 goto err;
517 iowrite8(val, reg->ioaddr + off);
518
519 filled = 1;
520 }
521
522 count -= filled;
523 done += filled;
524 off += filled;
525 buf += filled;
526 }
527
528 return done;
529 err:
530 return -EFAULT;
531 }
532
vfio_platform_write(void *device_data, const char __user *buf, size_t count, loff_t *ppos)533 static ssize_t vfio_platform_write(void *device_data, const char __user *buf,
534 size_t count, loff_t *ppos)
535 {
536 struct vfio_platform_device *vdev = device_data;
537 unsigned int index = VFIO_PLATFORM_OFFSET_TO_INDEX(*ppos);
538 loff_t off = *ppos & VFIO_PLATFORM_OFFSET_MASK;
539
540 if (index >= vdev->num_regions)
541 return -EINVAL;
542
543 if (!(vdev->regions[index].flags & VFIO_REGION_INFO_FLAG_WRITE))
544 return -EINVAL;
545
546 if (vdev->regions[index].type & VFIO_PLATFORM_REGION_TYPE_MMIO)
547 return vfio_platform_write_mmio(&vdev->regions[index],
548 buf, count, off);
549 else if (vdev->regions[index].type & VFIO_PLATFORM_REGION_TYPE_PIO)
550 return -EINVAL; /* not implemented */
551
552 return -EINVAL;
553 }
554
vfio_platform_mmap_mmio(struct vfio_platform_region region, struct vm_area_struct *vma)555 static int vfio_platform_mmap_mmio(struct vfio_platform_region region,
556 struct vm_area_struct *vma)
557 {
558 u64 req_len, pgoff, req_start;
559
560 req_len = vma->vm_end - vma->vm_start;
561 pgoff = vma->vm_pgoff &
562 ((1U << (VFIO_PLATFORM_OFFSET_SHIFT - PAGE_SHIFT)) - 1);
563 req_start = pgoff << PAGE_SHIFT;
564
565 if (region.size < PAGE_SIZE || req_start + req_len > region.size)
566 return -EINVAL;
567
568 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
569 vma->vm_pgoff = (region.addr >> PAGE_SHIFT) + pgoff;
570
571 return remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff,
572 req_len, vma->vm_page_prot);
573 }
574
vfio_platform_mmap(void *device_data, struct vm_area_struct *vma)575 static int vfio_platform_mmap(void *device_data, struct vm_area_struct *vma)
576 {
577 struct vfio_platform_device *vdev = device_data;
578 unsigned int index;
579
580 index = vma->vm_pgoff >> (VFIO_PLATFORM_OFFSET_SHIFT - PAGE_SHIFT);
581
582 if (vma->vm_end < vma->vm_start)
583 return -EINVAL;
584 if (!(vma->vm_flags & VM_SHARED))
585 return -EINVAL;
586 if (index >= vdev->num_regions)
587 return -EINVAL;
588 if (vma->vm_start & ~PAGE_MASK)
589 return -EINVAL;
590 if (vma->vm_end & ~PAGE_MASK)
591 return -EINVAL;
592
593 if (!(vdev->regions[index].flags & VFIO_REGION_INFO_FLAG_MMAP))
594 return -EINVAL;
595
596 if (!(vdev->regions[index].flags & VFIO_REGION_INFO_FLAG_READ)
597 && (vma->vm_flags & VM_READ))
598 return -EINVAL;
599
600 if (!(vdev->regions[index].flags & VFIO_REGION_INFO_FLAG_WRITE)
601 && (vma->vm_flags & VM_WRITE))
602 return -EINVAL;
603
604 vma->vm_private_data = vdev;
605
606 if (vdev->regions[index].type & VFIO_PLATFORM_REGION_TYPE_MMIO)
607 return vfio_platform_mmap_mmio(vdev->regions[index], vma);
608
609 else if (vdev->regions[index].type & VFIO_PLATFORM_REGION_TYPE_PIO)
610 return -EINVAL; /* not implemented */
611
612 return -EINVAL;
613 }
614
615 static const struct vfio_device_ops vfio_platform_ops = {
616 .name = "vfio-platform",
617 .open = vfio_platform_open,
618 .release = vfio_platform_release,
619 .ioctl = vfio_platform_ioctl,
620 .read = vfio_platform_read,
621 .write = vfio_platform_write,
622 .mmap = vfio_platform_mmap,
623 };
624
vfio_platform_of_probe(struct vfio_platform_device *vdev, struct device *dev)625 static int vfio_platform_of_probe(struct vfio_platform_device *vdev,
626 struct device *dev)
627 {
628 int ret;
629
630 ret = device_property_read_string(dev, "compatible",
631 &vdev->compat);
632 if (ret)
633 dev_err(dev, "Cannot retrieve compat for %s\n", vdev->name);
634
635 return ret;
636 }
637
638 /*
639 * There can be two kernel build combinations. One build where
640 * ACPI is not selected in Kconfig and another one with the ACPI Kconfig.
641 *
642 * In the first case, vfio_platform_acpi_probe will return since
643 * acpi_disabled is 1. DT user will not see any kind of messages from
644 * ACPI.
645 *
646 * In the second case, both DT and ACPI is compiled in but the system is
647 * booting with any of these combinations.
648 *
649 * If the firmware is DT type, then acpi_disabled is 1. The ACPI probe routine
650 * terminates immediately without any messages.
651 *
652 * If the firmware is ACPI type, then acpi_disabled is 0. All other checks are
653 * valid checks. We cannot claim that this system is DT.
654 */
vfio_platform_probe_common(struct vfio_platform_device *vdev, struct device *dev)655 int vfio_platform_probe_common(struct vfio_platform_device *vdev,
656 struct device *dev)
657 {
658 struct iommu_group *group;
659 int ret;
660
661 if (!vdev)
662 return -EINVAL;
663
664 ret = vfio_platform_acpi_probe(vdev, dev);
665 if (ret)
666 ret = vfio_platform_of_probe(vdev, dev);
667
668 if (ret)
669 return ret;
670
671 vdev->device = dev;
672
673 ret = vfio_platform_get_reset(vdev);
674 if (ret && vdev->reset_required) {
675 dev_err(dev, "No reset function found for device %s\n",
676 vdev->name);
677 return ret;
678 }
679
680 group = vfio_iommu_group_get(dev);
681 if (!group) {
682 dev_err(dev, "No IOMMU group for device %s\n", vdev->name);
683 ret = -EINVAL;
684 goto put_reset;
685 }
686
687 ret = vfio_add_group_dev(dev, &vfio_platform_ops, vdev);
688 if (ret)
689 goto put_iommu;
690
691 mutex_init(&vdev->igate);
692
693 pm_runtime_enable(vdev->device);
694 return 0;
695
696 put_iommu:
697 vfio_iommu_group_put(group, dev);
698 put_reset:
699 vfio_platform_put_reset(vdev);
700 return ret;
701 }
702 EXPORT_SYMBOL_GPL(vfio_platform_probe_common);
703
vfio_platform_remove_common(struct device *dev)704 struct vfio_platform_device *vfio_platform_remove_common(struct device *dev)
705 {
706 struct vfio_platform_device *vdev;
707
708 vdev = vfio_del_group_dev(dev);
709
710 if (vdev) {
711 pm_runtime_disable(vdev->device);
712 vfio_platform_put_reset(vdev);
713 vfio_iommu_group_put(dev->iommu_group, dev);
714 }
715
716 return vdev;
717 }
718 EXPORT_SYMBOL_GPL(vfio_platform_remove_common);
719
__vfio_platform_register_reset(struct vfio_platform_reset_node *node)720 void __vfio_platform_register_reset(struct vfio_platform_reset_node *node)
721 {
722 mutex_lock(&driver_lock);
723 list_add(&node->link, &reset_list);
724 mutex_unlock(&driver_lock);
725 }
726 EXPORT_SYMBOL_GPL(__vfio_platform_register_reset);
727
vfio_platform_unregister_reset(const char *compat, vfio_platform_reset_fn_t fn)728 void vfio_platform_unregister_reset(const char *compat,
729 vfio_platform_reset_fn_t fn)
730 {
731 struct vfio_platform_reset_node *iter, *temp;
732
733 mutex_lock(&driver_lock);
734 list_for_each_entry_safe(iter, temp, &reset_list, link) {
735 if (!strcmp(iter->compat, compat) && (iter->of_reset == fn)) {
736 list_del(&iter->link);
737 break;
738 }
739 }
740
741 mutex_unlock(&driver_lock);
742
743 }
744 EXPORT_SYMBOL_GPL(vfio_platform_unregister_reset);
745
746 MODULE_VERSION(DRIVER_VERSION);
747 MODULE_LICENSE("GPL v2");
748 MODULE_AUTHOR(DRIVER_AUTHOR);
749 MODULE_DESCRIPTION(DRIVER_DESC);
750