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