Skip to content

Commit d30daa3

Browse files
Sinan Kayaawilliam
Sinan Kaya
authored andcommitted
vfio: platform: call _RST method when using ACPI
The device tree code checks for the presence of a reset driver and calls the of_reset function pointer by looking up the reset driver as a module. ACPI defines _RST method to perform device level reset. After the _RST method is executed, the OS can resume using the device. _RST method is expected to stop DMA transfers and IRQs. This patch introduces two functions as vfio_platform_acpi_has_reset and vfio_platform_acpi_call_reset. The has reset method is used to declare reset capability via the ioctl flag VFIO_DEVICE_FLAGS_RESET. The call reset function is used to execute the _RST ACPI method. Signed-off-by: Sinan Kaya <[email protected]> Signed-off-by: Alex Williamson <[email protected]>
1 parent 5afec27 commit d30daa3

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

drivers/vfio/platform/vfio_platform_common.c

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#define DRIVER_AUTHOR "Antonios Motakis <[email protected]>"
2929
#define DRIVER_DESC "VFIO platform base module"
3030

31+
#define VFIO_PLATFORM_IS_ACPI(vdev) ((vdev)->acpihid != NULL)
32+
3133
static LIST_HEAD(reset_list);
3234
static DEFINE_MUTEX(driver_lock);
3335

@@ -71,13 +73,53 @@ static int vfio_platform_acpi_probe(struct vfio_platform_device *vdev,
7173
return WARN_ON(!vdev->acpihid) ? -EINVAL : 0;
7274
}
7375

76+
int vfio_platform_acpi_call_reset(struct vfio_platform_device *vdev,
77+
const char **extra_dbg)
78+
{
79+
#ifdef CONFIG_ACPI
80+
struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
81+
struct device *dev = vdev->device;
82+
acpi_handle handle = ACPI_HANDLE(dev);
83+
acpi_status acpi_ret;
84+
85+
acpi_ret = acpi_evaluate_object(handle, "_RST", NULL, &buffer);
86+
if (ACPI_FAILURE(acpi_ret)) {
87+
if (extra_dbg)
88+
*extra_dbg = acpi_format_exception(acpi_ret);
89+
return -EINVAL;
90+
}
91+
92+
return 0;
93+
#else
94+
return -ENOENT;
95+
#endif
96+
}
97+
98+
bool vfio_platform_acpi_has_reset(struct vfio_platform_device *vdev)
99+
{
100+
#ifdef CONFIG_ACPI
101+
struct device *dev = vdev->device;
102+
acpi_handle handle = ACPI_HANDLE(dev);
103+
104+
return acpi_has_method(handle, "_RST");
105+
#else
106+
return false;
107+
#endif
108+
}
109+
74110
static bool vfio_platform_has_reset(struct vfio_platform_device *vdev)
75111
{
112+
if (VFIO_PLATFORM_IS_ACPI(vdev))
113+
return vfio_platform_acpi_has_reset(vdev);
114+
76115
return vdev->of_reset ? true : false;
77116
}
78117

79118
static void vfio_platform_get_reset(struct vfio_platform_device *vdev)
80119
{
120+
if (VFIO_PLATFORM_IS_ACPI(vdev))
121+
return;
122+
81123
vdev->of_reset = vfio_platform_lookup_reset(vdev->compat,
82124
&vdev->reset_module);
83125
if (!vdev->of_reset) {
@@ -89,6 +131,9 @@ static void vfio_platform_get_reset(struct vfio_platform_device *vdev)
89131

90132
static void vfio_platform_put_reset(struct vfio_platform_device *vdev)
91133
{
134+
if (VFIO_PLATFORM_IS_ACPI(vdev))
135+
return;
136+
92137
if (vdev->of_reset)
93138
module_put(vdev->reset_module);
94139
}
@@ -164,7 +209,10 @@ static void vfio_platform_regions_cleanup(struct vfio_platform_device *vdev)
164209
static int vfio_platform_call_reset(struct vfio_platform_device *vdev,
165210
const char **extra_dbg)
166211
{
167-
if (vdev->of_reset) {
212+
if (VFIO_PLATFORM_IS_ACPI(vdev)) {
213+
dev_info(vdev->device, "reset\n");
214+
return vfio_platform_acpi_call_reset(vdev, extra_dbg);
215+
} else if (vdev->of_reset) {
168216
dev_info(vdev->device, "reset\n");
169217
return vdev->of_reset(vdev);
170218
}

0 commit comments

Comments
 (0)