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