Lines Matching full: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
75 struct device *dev = vdev->device; in vfio_platform_acpi_call_reset()
92 static bool vfio_platform_acpi_has_reset(struct vfio_platform_device *vdev) in vfio_platform_acpi_has_reset() argument
95 struct device *dev = vdev->device; in vfio_platform_acpi_has_reset()
104 static bool vfio_platform_has_reset(struct vfio_platform_device *vdev) in vfio_platform_has_reset() argument
106 if (VFIO_PLATFORM_IS_ACPI(vdev)) in vfio_platform_has_reset()
107 return vfio_platform_acpi_has_reset(vdev); in vfio_platform_has_reset()
109 return vdev->of_reset ? true : false; in vfio_platform_has_reset()
112 static int vfio_platform_get_reset(struct vfio_platform_device *vdev) in vfio_platform_get_reset() argument
114 if (VFIO_PLATFORM_IS_ACPI(vdev)) in vfio_platform_get_reset()
115 return vfio_platform_acpi_has_reset(vdev) ? 0 : -ENOENT; in vfio_platform_get_reset()
117 vdev->of_reset = vfio_platform_lookup_reset(vdev->compat, in vfio_platform_get_reset()
118 &vdev->reset_module); in vfio_platform_get_reset()
119 if (!vdev->of_reset) { in vfio_platform_get_reset()
120 request_module("vfio-reset:%s", vdev->compat); in vfio_platform_get_reset()
121 vdev->of_reset = vfio_platform_lookup_reset(vdev->compat, in vfio_platform_get_reset()
122 &vdev->reset_module); in vfio_platform_get_reset()
125 return vdev->of_reset ? 0 : -ENOENT; in vfio_platform_get_reset()
128 static void vfio_platform_put_reset(struct vfio_platform_device *vdev) in vfio_platform_put_reset() argument
130 if (VFIO_PLATFORM_IS_ACPI(vdev)) in vfio_platform_put_reset()
133 if (vdev->of_reset) in vfio_platform_put_reset()
134 module_put(vdev->reset_module); in vfio_platform_put_reset()
137 static int vfio_platform_regions_init(struct vfio_platform_device *vdev) in vfio_platform_regions_init() argument
141 while (vdev->get_resource(vdev, cnt)) in vfio_platform_regions_init()
144 vdev->regions = kcalloc(cnt, sizeof(struct vfio_platform_region), in vfio_platform_regions_init()
146 if (!vdev->regions) in vfio_platform_regions_init()
151 vdev->get_resource(vdev, i); in vfio_platform_regions_init()
153 vdev->regions[i].addr = res->start; in vfio_platform_regions_init()
154 vdev->regions[i].size = resource_size(res); in vfio_platform_regions_init()
155 vdev->regions[i].flags = 0; in vfio_platform_regions_init()
159 vdev->regions[i].type = VFIO_PLATFORM_REGION_TYPE_MMIO; in vfio_platform_regions_init()
160 vdev->regions[i].flags |= VFIO_REGION_INFO_FLAG_READ; in vfio_platform_regions_init()
162 vdev->regions[i].flags |= in vfio_platform_regions_init()
169 if (!(vdev->regions[i].addr & ~PAGE_MASK) && in vfio_platform_regions_init()
170 !(vdev->regions[i].size & ~PAGE_MASK)) in vfio_platform_regions_init()
171 vdev->regions[i].flags |= in vfio_platform_regions_init()
176 vdev->regions[i].type = VFIO_PLATFORM_REGION_TYPE_PIO; in vfio_platform_regions_init()
183 vdev->num_regions = cnt; in vfio_platform_regions_init()
187 kfree(vdev->regions); in vfio_platform_regions_init()
191 static void vfio_platform_regions_cleanup(struct vfio_platform_device *vdev) in vfio_platform_regions_cleanup() argument
195 for (i = 0; i < vdev->num_regions; i++) in vfio_platform_regions_cleanup()
196 iounmap(vdev->regions[i].ioaddr); in vfio_platform_regions_cleanup()
198 vdev->num_regions = 0; in vfio_platform_regions_cleanup()
199 kfree(vdev->regions); in vfio_platform_regions_cleanup()
202 static int vfio_platform_call_reset(struct vfio_platform_device *vdev, in vfio_platform_call_reset() argument
205 if (VFIO_PLATFORM_IS_ACPI(vdev)) { in vfio_platform_call_reset()
206 dev_info(vdev->device, "reset\n"); in vfio_platform_call_reset()
207 return vfio_platform_acpi_call_reset(vdev, extra_dbg); in vfio_platform_call_reset()
208 } else if (vdev->of_reset) { in vfio_platform_call_reset()
209 dev_info(vdev->device, "reset\n"); in vfio_platform_call_reset()
210 return vdev->of_reset(vdev); in vfio_platform_call_reset()
213 dev_warn(vdev->device, "no reset function found!\n"); in vfio_platform_call_reset()
219 struct vfio_platform_device *vdev = in vfio_platform_close_device() local
220 container_of(core_vdev, struct vfio_platform_device, vdev); in vfio_platform_close_device()
224 ret = vfio_platform_call_reset(vdev, &extra_dbg); in vfio_platform_close_device()
225 if (WARN_ON(ret && vdev->reset_required)) { in vfio_platform_close_device()
227 vdev->device, in vfio_platform_close_device()
231 pm_runtime_put(vdev->device); in vfio_platform_close_device()
232 vfio_platform_regions_cleanup(vdev); in vfio_platform_close_device()
233 vfio_platform_irq_cleanup(vdev); in vfio_platform_close_device()
239 struct vfio_platform_device *vdev = in vfio_platform_open_device() local
240 container_of(core_vdev, struct vfio_platform_device, vdev); in vfio_platform_open_device()
244 ret = vfio_platform_regions_init(vdev); in vfio_platform_open_device()
248 ret = vfio_platform_irq_init(vdev); in vfio_platform_open_device()
252 ret = pm_runtime_get_sync(vdev->device); in vfio_platform_open_device()
256 ret = vfio_platform_call_reset(vdev, &extra_dbg); in vfio_platform_open_device()
257 if (ret && vdev->reset_required) { in vfio_platform_open_device()
259 vdev->device, in vfio_platform_open_device()
267 pm_runtime_put(vdev->device); in vfio_platform_open_device()
268 vfio_platform_irq_cleanup(vdev); in vfio_platform_open_device()
270 vfio_platform_regions_cleanup(vdev); in vfio_platform_open_device()
278 struct vfio_platform_device *vdev = in vfio_platform_ioctl() local
279 container_of(core_vdev, struct vfio_platform_device, vdev); in vfio_platform_ioctl()
294 if (vfio_platform_has_reset(vdev)) in vfio_platform_ioctl()
295 vdev->flags |= VFIO_DEVICE_FLAGS_RESET; in vfio_platform_ioctl()
296 info.flags = vdev->flags; in vfio_platform_ioctl()
297 info.num_regions = vdev->num_regions; in vfio_platform_ioctl()
298 info.num_irqs = vdev->num_irqs; in vfio_platform_ioctl()
314 if (info.index >= vdev->num_regions) in vfio_platform_ioctl()
319 info.size = vdev->regions[info.index].size; in vfio_platform_ioctl()
320 info.flags = vdev->regions[info.index].flags; in vfio_platform_ioctl()
336 if (info.index >= vdev->num_irqs) in vfio_platform_ioctl()
339 info.flags = vdev->irqs[info.index].flags; in vfio_platform_ioctl()
340 info.count = vdev->irqs[info.index].count; in vfio_platform_ioctl()
356 ret = vfio_set_irqs_validate_and_prepare(&hdr, vdev->num_irqs, in vfio_platform_ioctl()
357 vdev->num_irqs, &data_size); in vfio_platform_ioctl()
368 mutex_lock(&vdev->igate); in vfio_platform_ioctl()
370 ret = vfio_platform_set_irqs_ioctl(vdev, hdr.flags, hdr.index, in vfio_platform_ioctl()
372 mutex_unlock(&vdev->igate); in vfio_platform_ioctl()
378 return vfio_platform_call_reset(vdev, NULL); in vfio_platform_ioctl()
443 struct vfio_platform_device *vdev = in vfio_platform_read() local
444 container_of(core_vdev, struct vfio_platform_device, vdev); in vfio_platform_read()
448 if (index >= vdev->num_regions) in vfio_platform_read()
451 if (!(vdev->regions[index].flags & VFIO_REGION_INFO_FLAG_READ)) in vfio_platform_read()
454 if (vdev->regions[index].type & VFIO_PLATFORM_REGION_TYPE_MMIO) in vfio_platform_read()
455 return vfio_platform_read_mmio(&vdev->regions[index], in vfio_platform_read()
457 else if (vdev->regions[index].type & VFIO_PLATFORM_REGION_TYPE_PIO) in vfio_platform_read()
521 struct vfio_platform_device *vdev = in vfio_platform_write() local
522 container_of(core_vdev, struct vfio_platform_device, vdev); in vfio_platform_write()
526 if (index >= vdev->num_regions) in vfio_platform_write()
529 if (!(vdev->regions[index].flags & VFIO_REGION_INFO_FLAG_WRITE)) in vfio_platform_write()
532 if (vdev->regions[index].type & VFIO_PLATFORM_REGION_TYPE_MMIO) in vfio_platform_write()
533 return vfio_platform_write_mmio(&vdev->regions[index], in vfio_platform_write()
535 else if (vdev->regions[index].type & VFIO_PLATFORM_REGION_TYPE_PIO) in vfio_platform_write()
564 struct vfio_platform_device *vdev = in vfio_platform_mmap() local
565 container_of(core_vdev, struct vfio_platform_device, vdev); in vfio_platform_mmap()
574 if (index >= vdev->num_regions) in vfio_platform_mmap()
581 if (!(vdev->regions[index].flags & VFIO_REGION_INFO_FLAG_MMAP)) in vfio_platform_mmap()
584 if (!(vdev->regions[index].flags & VFIO_REGION_INFO_FLAG_READ) in vfio_platform_mmap()
588 if (!(vdev->regions[index].flags & VFIO_REGION_INFO_FLAG_WRITE) in vfio_platform_mmap()
592 vma->vm_private_data = vdev; in vfio_platform_mmap()
594 if (vdev->regions[index].type & VFIO_PLATFORM_REGION_TYPE_MMIO) in vfio_platform_mmap()
595 return vfio_platform_mmap_mmio(vdev->regions[index], vma); in vfio_platform_mmap()
597 else if (vdev->regions[index].type & VFIO_PLATFORM_REGION_TYPE_PIO) in vfio_platform_mmap()
604 static int vfio_platform_of_probe(struct vfio_platform_device *vdev, in vfio_platform_of_probe() argument
610 &vdev->compat); in vfio_platform_of_probe()
612 dev_err(dev, "Cannot retrieve compat for %s\n", vdev->name); in vfio_platform_of_probe()
634 int vfio_platform_init_common(struct vfio_platform_device *vdev) in vfio_platform_init_common() argument
637 struct device *dev = vdev->vdev.dev; in vfio_platform_init_common()
639 ret = vfio_platform_acpi_probe(vdev, dev); in vfio_platform_init_common()
641 ret = vfio_platform_of_probe(vdev, dev); in vfio_platform_init_common()
646 vdev->device = dev; in vfio_platform_init_common()
647 mutex_init(&vdev->igate); in vfio_platform_init_common()
649 ret = vfio_platform_get_reset(vdev); in vfio_platform_init_common()
650 if (ret && vdev->reset_required) { in vfio_platform_init_common()
652 vdev->name); in vfio_platform_init_common()
660 void vfio_platform_release_common(struct vfio_platform_device *vdev) in vfio_platform_release_common() argument
662 vfio_platform_put_reset(vdev); in vfio_platform_release_common()