Lines Matching refs:vdev
26 #define VFIO_PLATFORM_IS_ACPI(vdev) ((vdev)->acpihid != NULL) argument
50 static int vfio_platform_acpi_probe(struct vfio_platform_device *vdev, in vfio_platform_acpi_probe() argument
61 vdev->name); in vfio_platform_acpi_probe()
66 vdev->acpihid = acpi_device_hid(adev); in vfio_platform_acpi_probe()
68 return WARN_ON(!vdev->acpihid) ? -EINVAL : 0; in vfio_platform_acpi_probe()
71 static int vfio_platform_acpi_call_reset(struct vfio_platform_device *vdev, in vfio_platform_acpi_call_reset() argument
76 struct device *dev = vdev->device; in vfio_platform_acpi_call_reset()
93 static bool vfio_platform_acpi_has_reset(struct vfio_platform_device *vdev) in vfio_platform_acpi_has_reset() argument
96 struct device *dev = vdev->device; in vfio_platform_acpi_has_reset()
105 static bool vfio_platform_has_reset(struct vfio_platform_device *vdev) in vfio_platform_has_reset() argument
107 if (VFIO_PLATFORM_IS_ACPI(vdev)) in vfio_platform_has_reset()
108 return vfio_platform_acpi_has_reset(vdev); in vfio_platform_has_reset()
110 return vdev->of_reset ? true : false; in vfio_platform_has_reset()
113 static int vfio_platform_get_reset(struct vfio_platform_device *vdev) in vfio_platform_get_reset() argument
115 if (VFIO_PLATFORM_IS_ACPI(vdev)) in vfio_platform_get_reset()
116 return vfio_platform_acpi_has_reset(vdev) ? 0 : -ENOENT; in vfio_platform_get_reset()
118 vdev->of_reset = vfio_platform_lookup_reset(vdev->compat, in vfio_platform_get_reset()
119 &vdev->reset_module); in vfio_platform_get_reset()
120 if (!vdev->of_reset) { in vfio_platform_get_reset()
121 request_module("vfio-reset:%s", vdev->compat); in vfio_platform_get_reset()
122 vdev->of_reset = vfio_platform_lookup_reset(vdev->compat, in vfio_platform_get_reset()
123 &vdev->reset_module); in vfio_platform_get_reset()
126 return vdev->of_reset ? 0 : -ENOENT; in vfio_platform_get_reset()
129 static void vfio_platform_put_reset(struct vfio_platform_device *vdev) in vfio_platform_put_reset() argument
131 if (VFIO_PLATFORM_IS_ACPI(vdev)) in vfio_platform_put_reset()
134 if (vdev->of_reset) in vfio_platform_put_reset()
135 module_put(vdev->reset_module); in vfio_platform_put_reset()
138 static int vfio_platform_regions_init(struct vfio_platform_device *vdev) in vfio_platform_regions_init() argument
142 while (vdev->get_resource(vdev, cnt)) in vfio_platform_regions_init()
145 vdev->regions = kcalloc(cnt, sizeof(struct vfio_platform_region), in vfio_platform_regions_init()
147 if (!vdev->regions) in vfio_platform_regions_init()
152 vdev->get_resource(vdev, i); in vfio_platform_regions_init()
157 vdev->regions[i].addr = res->start; in vfio_platform_regions_init()
158 vdev->regions[i].size = resource_size(res); in vfio_platform_regions_init()
159 vdev->regions[i].flags = 0; in vfio_platform_regions_init()
163 vdev->regions[i].type = VFIO_PLATFORM_REGION_TYPE_MMIO; in vfio_platform_regions_init()
164 vdev->regions[i].flags |= VFIO_REGION_INFO_FLAG_READ; in vfio_platform_regions_init()
166 vdev->regions[i].flags |= in vfio_platform_regions_init()
173 if (!(vdev->regions[i].addr & ~PAGE_MASK) && in vfio_platform_regions_init()
174 !(vdev->regions[i].size & ~PAGE_MASK)) in vfio_platform_regions_init()
175 vdev->regions[i].flags |= in vfio_platform_regions_init()
180 vdev->regions[i].type = VFIO_PLATFORM_REGION_TYPE_PIO; in vfio_platform_regions_init()
187 vdev->num_regions = cnt; in vfio_platform_regions_init()
191 kfree(vdev->regions); in vfio_platform_regions_init()
195 static void vfio_platform_regions_cleanup(struct vfio_platform_device *vdev) in vfio_platform_regions_cleanup() argument
199 for (i = 0; i < vdev->num_regions; i++) in vfio_platform_regions_cleanup()
200 iounmap(vdev->regions[i].ioaddr); in vfio_platform_regions_cleanup()
202 vdev->num_regions = 0; in vfio_platform_regions_cleanup()
203 kfree(vdev->regions); in vfio_platform_regions_cleanup()
206 static int vfio_platform_call_reset(struct vfio_platform_device *vdev, in vfio_platform_call_reset() argument
209 if (VFIO_PLATFORM_IS_ACPI(vdev)) { in vfio_platform_call_reset()
210 dev_info(vdev->device, "reset\n"); in vfio_platform_call_reset()
211 return vfio_platform_acpi_call_reset(vdev, extra_dbg); in vfio_platform_call_reset()
212 } else if (vdev->of_reset) { in vfio_platform_call_reset()
213 dev_info(vdev->device, "reset\n"); in vfio_platform_call_reset()
214 return vdev->of_reset(vdev); in vfio_platform_call_reset()
217 dev_warn(vdev->device, "no reset function found!\n"); in vfio_platform_call_reset()
223 struct vfio_platform_device *vdev = device_data; in vfio_platform_release() local
227 if (!(--vdev->refcnt)) { in vfio_platform_release()
231 ret = vfio_platform_call_reset(vdev, &extra_dbg); in vfio_platform_release()
232 if (ret && vdev->reset_required) { in vfio_platform_release()
233 dev_warn(vdev->device, "reset driver is required and reset call failed in release (%d) %s\n", in vfio_platform_release()
237 pm_runtime_put(vdev->device); in vfio_platform_release()
238 vfio_platform_regions_cleanup(vdev); in vfio_platform_release()
239 vfio_platform_irq_cleanup(vdev); in vfio_platform_release()
244 module_put(vdev->parent_module); in vfio_platform_release()
249 struct vfio_platform_device *vdev = device_data; in vfio_platform_open() local
252 if (!try_module_get(vdev->parent_module)) in vfio_platform_open()
257 if (!vdev->refcnt) { in vfio_platform_open()
260 ret = vfio_platform_regions_init(vdev); in vfio_platform_open()
264 ret = vfio_platform_irq_init(vdev); in vfio_platform_open()
268 ret = pm_runtime_get_sync(vdev->device); in vfio_platform_open()
272 ret = vfio_platform_call_reset(vdev, &extra_dbg); in vfio_platform_open()
273 if (ret && vdev->reset_required) { in vfio_platform_open()
274 dev_warn(vdev->device, "reset driver is required and reset call failed in open (%d) %s\n", in vfio_platform_open()
280 vdev->refcnt++; in vfio_platform_open()
286 pm_runtime_put(vdev->device); in vfio_platform_open()
288 vfio_platform_irq_cleanup(vdev); in vfio_platform_open()
290 vfio_platform_regions_cleanup(vdev); in vfio_platform_open()
300 struct vfio_platform_device *vdev = device_data; in vfio_platform_ioctl() local
314 if (vfio_platform_has_reset(vdev)) in vfio_platform_ioctl()
315 vdev->flags |= VFIO_DEVICE_FLAGS_RESET; in vfio_platform_ioctl()
316 info.flags = vdev->flags; in vfio_platform_ioctl()
317 info.num_regions = vdev->num_regions; in vfio_platform_ioctl()
318 info.num_irqs = vdev->num_irqs; in vfio_platform_ioctl()
334 if (info.index >= vdev->num_regions) in vfio_platform_ioctl()
339 info.size = vdev->regions[info.index].size; in vfio_platform_ioctl()
340 info.flags = vdev->regions[info.index].flags; in vfio_platform_ioctl()
356 if (info.index >= vdev->num_irqs) in vfio_platform_ioctl()
359 info.flags = vdev->irqs[info.index].flags; in vfio_platform_ioctl()
360 info.count = vdev->irqs[info.index].count; in vfio_platform_ioctl()
376 ret = vfio_set_irqs_validate_and_prepare(&hdr, vdev->num_irqs, in vfio_platform_ioctl()
377 vdev->num_irqs, &data_size); in vfio_platform_ioctl()
388 mutex_lock(&vdev->igate); in vfio_platform_ioctl()
390 ret = vfio_platform_set_irqs_ioctl(vdev, hdr.flags, hdr.index, in vfio_platform_ioctl()
392 mutex_unlock(&vdev->igate); in vfio_platform_ioctl()
398 return vfio_platform_call_reset(vdev, NULL); in vfio_platform_ioctl()
462 struct vfio_platform_device *vdev = device_data; in vfio_platform_read() local
466 if (index >= vdev->num_regions) in vfio_platform_read()
469 if (!(vdev->regions[index].flags & VFIO_REGION_INFO_FLAG_READ)) in vfio_platform_read()
472 if (vdev->regions[index].type & VFIO_PLATFORM_REGION_TYPE_MMIO) in vfio_platform_read()
473 return vfio_platform_read_mmio(&vdev->regions[index], in vfio_platform_read()
475 else if (vdev->regions[index].type & VFIO_PLATFORM_REGION_TYPE_PIO) in vfio_platform_read()
538 struct vfio_platform_device *vdev = device_data; in vfio_platform_write() local
542 if (index >= vdev->num_regions) in vfio_platform_write()
545 if (!(vdev->regions[index].flags & VFIO_REGION_INFO_FLAG_WRITE)) in vfio_platform_write()
548 if (vdev->regions[index].type & VFIO_PLATFORM_REGION_TYPE_MMIO) in vfio_platform_write()
549 return vfio_platform_write_mmio(&vdev->regions[index], in vfio_platform_write()
551 else if (vdev->regions[index].type & VFIO_PLATFORM_REGION_TYPE_PIO) in vfio_platform_write()
579 struct vfio_platform_device *vdev = device_data; in vfio_platform_mmap() local
588 if (index >= vdev->num_regions) in vfio_platform_mmap()
595 if (!(vdev->regions[index].flags & VFIO_REGION_INFO_FLAG_MMAP)) in vfio_platform_mmap()
598 if (!(vdev->regions[index].flags & VFIO_REGION_INFO_FLAG_READ) in vfio_platform_mmap()
602 if (!(vdev->regions[index].flags & VFIO_REGION_INFO_FLAG_WRITE) in vfio_platform_mmap()
606 vma->vm_private_data = vdev; in vfio_platform_mmap()
608 if (vdev->regions[index].type & VFIO_PLATFORM_REGION_TYPE_MMIO) in vfio_platform_mmap()
609 return vfio_platform_mmap_mmio(vdev->regions[index], vma); in vfio_platform_mmap()
611 else if (vdev->regions[index].type & VFIO_PLATFORM_REGION_TYPE_PIO) in vfio_platform_mmap()
627 static int vfio_platform_of_probe(struct vfio_platform_device *vdev, in vfio_platform_of_probe() argument
633 &vdev->compat); in vfio_platform_of_probe()
635 dev_err(dev, "Cannot retrieve compat for %s\n", vdev->name); in vfio_platform_of_probe()
657 int vfio_platform_probe_common(struct vfio_platform_device *vdev, in vfio_platform_probe_common() argument
663 if (!vdev) in vfio_platform_probe_common()
666 ret = vfio_platform_acpi_probe(vdev, dev); in vfio_platform_probe_common()
668 ret = vfio_platform_of_probe(vdev, dev); in vfio_platform_probe_common()
673 vdev->device = dev; in vfio_platform_probe_common()
675 ret = vfio_platform_get_reset(vdev); in vfio_platform_probe_common()
676 if (ret && vdev->reset_required) { in vfio_platform_probe_common()
678 vdev->name); in vfio_platform_probe_common()
684 dev_err(dev, "No IOMMU group for device %s\n", vdev->name); in vfio_platform_probe_common()
689 ret = vfio_add_group_dev(dev, &vfio_platform_ops, vdev); in vfio_platform_probe_common()
693 mutex_init(&vdev->igate); in vfio_platform_probe_common()
695 pm_runtime_enable(vdev->device); in vfio_platform_probe_common()
701 vfio_platform_put_reset(vdev); in vfio_platform_probe_common()
708 struct vfio_platform_device *vdev; in vfio_platform_remove_common() local
710 vdev = vfio_del_group_dev(dev); in vfio_platform_remove_common()
712 if (vdev) { in vfio_platform_remove_common()
713 pm_runtime_disable(vdev->device); in vfio_platform_remove_common()
714 vfio_platform_put_reset(vdev); in vfio_platform_remove_common()
718 return vdev; in vfio_platform_remove_common()