Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

vfio: platform: add support for ACPI probe

The code is using the compatible DT string to associate a reset driver
with the actual device itself. The compatible string does not exist on
ACPI based systems. HID is the unique identifier for a device driver
instead.

Signed-off-by: Sinan Kaya <okaya@codeaurora.org>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

authored by

Sinan Kaya and committed by
Alex Williamson
a12a9368 dc5542fb

+60 -5
+59 -5
drivers/vfio/platform/vfio_platform_common.c
··· 13 13 */ 14 14 15 15 #include <linux/device.h> 16 + #include <linux/acpi.h> 16 17 #include <linux/iommu.h> 17 18 #include <linux/module.h> 18 19 #include <linux/mutex.h> ··· 48 47 } 49 48 mutex_unlock(&driver_lock); 50 49 return reset_fn; 50 + } 51 + 52 + static int vfio_platform_acpi_probe(struct vfio_platform_device *vdev, 53 + struct device *dev) 54 + { 55 + struct acpi_device *adev; 56 + 57 + if (acpi_disabled) 58 + return -ENOENT; 59 + 60 + adev = ACPI_COMPANION(dev); 61 + if (!adev) { 62 + pr_err("VFIO: ACPI companion device not found for %s\n", 63 + vdev->name); 64 + return -ENODEV; 65 + } 66 + 67 + #ifdef CONFIG_ACPI 68 + vdev->acpihid = acpi_device_hid(adev); 69 + #endif 70 + return WARN_ON(!vdev->acpihid) ? -EINVAL : 0; 51 71 } 52 72 53 73 static bool vfio_platform_has_reset(struct vfio_platform_device *vdev) ··· 569 547 .mmap = vfio_platform_mmap, 570 548 }; 571 549 550 + int vfio_platform_of_probe(struct vfio_platform_device *vdev, 551 + struct device *dev) 552 + { 553 + int ret; 554 + 555 + ret = device_property_read_string(dev, "compatible", 556 + &vdev->compat); 557 + if (ret) 558 + pr_err("VFIO: cannot retrieve compat for %s\n", 559 + vdev->name); 560 + 561 + return ret; 562 + } 563 + 564 + /* 565 + * There can be two kernel build combinations. One build where 566 + * ACPI is not selected in Kconfig and another one with the ACPI Kconfig. 567 + * 568 + * In the first case, vfio_platform_acpi_probe will return since 569 + * acpi_disabled is 1. DT user will not see any kind of messages from 570 + * ACPI. 571 + * 572 + * In the second case, both DT and ACPI is compiled in but the system is 573 + * booting with any of these combinations. 574 + * 575 + * If the firmware is DT type, then acpi_disabled is 1. The ACPI probe routine 576 + * terminates immediately without any messages. 577 + * 578 + * If the firmware is ACPI type, then acpi_disabled is 0. All other checks are 579 + * valid checks. We cannot claim that this system is DT. 580 + */ 572 581 int vfio_platform_probe_common(struct vfio_platform_device *vdev, 573 582 struct device *dev) 574 583 { ··· 609 556 if (!vdev) 610 557 return -EINVAL; 611 558 612 - ret = device_property_read_string(dev, "compatible", &vdev->compat); 613 - if (ret) { 614 - pr_err("VFIO: cannot retrieve compat for %s\n", vdev->name); 615 - return -EINVAL; 616 - } 559 + ret = vfio_platform_acpi_probe(vdev, dev); 560 + if (ret) 561 + ret = vfio_platform_of_probe(vdev, dev); 562 + 563 + if (ret) 564 + return ret; 617 565 618 566 vdev->device = dev; 619 567
+1
drivers/vfio/platform/vfio_platform_private.h
··· 58 58 struct mutex igate; 59 59 struct module *parent_module; 60 60 const char *compat; 61 + const char *acpihid; 61 62 struct module *reset_module; 62 63 struct device *device; 63 64