From a639f78832edd8a24cb683d66752f028545c0213 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Mon, 9 Jan 2017 14:00:48 -0800 Subject: [PATCH] acpi - Incidental MPSAFE * Make ACPI devices MPSAFE (use a private token). * Make the ACPI interupt MPSAFE. --- sys/dev/acpica/Osd/OsdInterrupt.c | 6 +++--- sys/dev/acpica/Osd/OsdSchedule.c | 5 ++--- sys/dev/acpica/acpi.c | 19 +++++++++++++++---- sys/dev/acpica/acpi_dock/acpi_dock.c | 9 ++++----- sys/dev/acpica/acpi_hp/acpi_hp.c | 2 +- sys/dev/acpica/acpi_thermal.c | 11 +++++------ sys/dev/acpica/acpi_wmi/acpi_wmi.c | 2 +- sys/dev/acpica/acpivar.h | 1 + 8 files changed, 32 insertions(+), 23 deletions(-) diff --git a/sys/dev/acpica/Osd/OsdInterrupt.c b/sys/dev/acpica/Osd/OsdInterrupt.c index 1cc529642c..9529321544 100644 --- a/sys/dev/acpica/Osd/OsdInterrupt.c +++ b/sys/dev/acpica/Osd/OsdInterrupt.c @@ -101,7 +101,7 @@ AcpiOsInstallInterruptHandler(UINT32 InterruptNumber, device_printf(sc->acpi_dev, "could not allocate interrupt\n"); goto error; } - if (bus_setup_intr(sc->acpi_dev, sc->acpi_irq, 0, + if (bus_setup_intr(sc->acpi_dev, sc->acpi_irq, INTR_MPSAFE, InterruptWrapper, Context, &sc->acpi_irq_handle, NULL)) { device_printf(sc->acpi_dev, "could not set up interrupt\n"); goto error; @@ -154,7 +154,7 @@ AcpiOsRemoveInterruptHandler(UINT32 InterruptNumber, ACPI_OSD_HANDLER ServiceRou static void InterruptWrapper(void *arg) { - crit_enter(); + lwkt_gettoken(&acpi_token); InterruptHandler(arg); - crit_exit(); + lwkt_reltoken(&acpi_token); } diff --git a/sys/dev/acpica/Osd/OsdSchedule.c b/sys/dev/acpica/Osd/OsdSchedule.c index 4ada46ae54..62f311bfae 100644 --- a/sys/dev/acpica/Osd/OsdSchedule.c +++ b/sys/dev/acpica/Osd/OsdSchedule.c @@ -46,7 +46,6 @@ #include #include -#include #include "acpi.h" #include "accommon.h" @@ -103,14 +102,14 @@ acpi_task_thread(void *arg) ACPI_OSD_EXEC_CALLBACK func; struct acpi_task *at; - get_mplock(); + lwkt_gettoken(&acpi_token); for (;;) { at = (void *)lwkt_waitport(&curthread->td_msgport, 0); func = at->at_function; func(at->at_context); lwkt_replymsg(&at->at_msg, 0); } - rel_mplock(); + lwkt_reltoken(&acpi_token); } /* diff --git a/sys/dev/acpica/acpi.c b/sys/dev/acpica/acpi.c index 29f628cb45..d6c4bca19e 100644 --- a/sys/dev/acpica/acpi.c +++ b/sys/dev/acpica/acpi.c @@ -79,7 +79,7 @@ static d_close_t acpiclose; static d_ioctl_t acpiioctl; static struct dev_ops acpi_ops = { - { "acpi", 0, 0 }, + { "acpi", 0, D_MPSAFE }, .d_open = acpiopen, .d_close = acpiclose, .d_ioctl = acpiioctl @@ -92,6 +92,7 @@ struct acpi_interface { /* Global mutex for locking access to the ACPI subsystem. */ struct lock acpi_lock; +struct lwkt_token acpi_token = LWKT_TOKEN_INITIALIZER(acpi_token); /* Bitmap of device quirks. */ int acpi_quirks; @@ -2475,6 +2476,7 @@ acpi_EnterSleepState(struct acpi_softc *sc, int state) * drivers need this. */ //get_mplock(); + slp_state = ACPI_SS_NONE; switch (state) { case ACPI_STATE_S1: @@ -2582,6 +2584,7 @@ acpi_EnterSleepState(struct acpi_softc *sc, int state) acpi_UserNotify("Resume", ACPI_ROOT_OBJECT, state); //rel_mplock(); + return_ACPI_STATUS (status); } @@ -3173,6 +3176,7 @@ acpiioctl(struct dev_ioctl_args *ap) /* * Scan the list of registered ioctls, looking for handlers. */ + lwkt_gettoken(&acpi_token); ACPI_LOCK(acpi); if (acpi_ioctl_hooks_initted) TAILQ_FOREACH(hp, &acpi_ioctl_hooks, link) { @@ -3180,16 +3184,21 @@ acpiioctl(struct dev_ioctl_args *ap) break; } ACPI_UNLOCK(acpi); - if (hp) - return (hp->fn(ap->a_cmd, ap->a_data, hp->arg)); + if (hp) { + error = hp->fn(ap->a_cmd, ap->a_data, hp->arg); + lwkt_reltoken(&acpi_token); + return error; + } /* * Core ioctls are not permitted for non-writable user. * Currently, other ioctls just fetch information. * Not changing system behavior. */ - if ((ap->a_fflag & FWRITE) == 0) + if ((ap->a_fflag & FWRITE) == 0) { + lwkt_reltoken(&acpi_token); return (EPERM); + } /* Core system ioctls. */ switch (ap->a_cmd) { @@ -3263,6 +3272,8 @@ acpiioctl(struct dev_ioctl_args *ap) error = ENXIO; break; } + lwkt_reltoken(&acpi_token); + return (error); } diff --git a/sys/dev/acpica/acpi_dock/acpi_dock.c b/sys/dev/acpica/acpi_dock/acpi_dock.c index 25f86d27c4..9430d4a3e6 100644 --- a/sys/dev/acpica/acpi_dock/acpi_dock.c +++ b/sys/dev/acpica/acpi_dock/acpi_dock.c @@ -31,7 +31,6 @@ #include #include #include -#include #include #include @@ -192,9 +191,9 @@ acpi_dock_attach_later(void *context) if (!device_is_enabled(dev)) device_enable(dev); - get_mplock(); + lwkt_gettoken(&acpi_token); device_probe_and_attach(dev); - rel_mplock(); + lwkt_reltoken(&acpi_token); } static ACPI_STATUS @@ -299,9 +298,9 @@ acpi_dock_eject_child(ACPI_HANDLE handle, UINT32 level, void *context, dev = acpi_get_device(handle); if (dev != NULL && device_is_attached(dev)) { - get_mplock(); + lwkt_gettoken(&acpi_token); device_detach(dev); - rel_mplock(); + lwkt_reltoken(&acpi_token); } acpi_SetInteger(handle, "_EJ0", 0); diff --git a/sys/dev/acpica/acpi_hp/acpi_hp.c b/sys/dev/acpica/acpi_hp/acpi_hp.c index c510d91af2..8a44a4424a 100644 --- a/sys/dev/acpica/acpi_hp/acpi_hp.c +++ b/sys/dev/acpica/acpi_hp/acpi_hp.c @@ -312,7 +312,7 @@ static d_read_t acpi_hp_hpcmi_read; /* handler /dev/hpcmi device */ static struct dev_ops hpcmi_ops = { - { .name = "hpcmi" }, + { "hpcmi", 0, D_MPSAFE }, .d_open = acpi_hp_hpcmi_open, .d_close = acpi_hp_hpcmi_close, .d_read = acpi_hp_hpcmi_read, diff --git a/sys/dev/acpica/acpi_thermal.c b/sys/dev/acpica/acpi_thermal.c index 17084db534..e6093f83ef 100644 --- a/sys/dev/acpica/acpi_thermal.c +++ b/sys/dev/acpica/acpi_thermal.c @@ -41,8 +41,6 @@ #include #include -#include - #include "acpi.h" #include "accommon.h" @@ -1015,8 +1013,8 @@ acpi_tz_thread(void *arg) devs = NULL; devcount = 0; sc = NULL; - get_mplock(); + lwkt_gettoken(&acpi_token); for (;;) { /* If the number of devices has changed, re-evaluate. */ if (devclass_get_count(acpi_tz_devclass) != devcount) { @@ -1059,7 +1057,7 @@ acpi_tz_thread(void *arg) ACPI_UNLOCK(thermal); } } - rel_mplock(); + lwkt_reltoken(&acpi_token); } #ifdef __FreeBSD__ @@ -1201,7 +1199,7 @@ acpi_tz_cooling_thread(void *arg) ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__); sc = (struct acpi_tz_softc *)arg; - get_mplock(); + lwkt_gettoken(&acpi_token); prev_temp = sc->tz_temperature; while (sc->tz_cooling_enabled) { @@ -1245,7 +1243,8 @@ acpi_tz_cooling_thread(void *arg) ACPI_LOCK(thermal); sc->tz_cooling_proc_running = FALSE; ACPI_UNLOCK(thermal); - rel_mplock(); + + lwkt_reltoken(&acpi_token); } /* diff --git a/sys/dev/acpica/acpi_wmi/acpi_wmi.c b/sys/dev/acpica/acpi_wmi/acpi_wmi.c index e7f0e924e5..ad7e07c528 100644 --- a/sys/dev/acpica/acpi_wmi/acpi_wmi.c +++ b/sys/dev/acpica/acpi_wmi/acpi_wmi.c @@ -158,7 +158,7 @@ static d_read_t acpi_wmi_wmistat_read; /* handler /dev/wmistat device */ static struct dev_ops wmistat_ops = { - { .name = "wmistat" }, + { "wmistat", 0, D_MPSAFE }, .d_open = acpi_wmi_wmistat_open, .d_close = acpi_wmi_wmistat_close, .d_read = acpi_wmi_wmistat_read, diff --git a/sys/dev/acpica/acpivar.h b/sys/dev/acpica/acpivar.h index 760ac49b62..b683eb34df 100644 --- a/sys/dev/acpica/acpivar.h +++ b/sys/dev/acpica/acpivar.h @@ -154,6 +154,7 @@ struct acpi_prw_data { * GPE -> EC runs _Qxx -> _Qxx reads EC space -> GPE */ extern struct lock acpi_lock; +extern struct lwkt_token acpi_token; /* acpi_thermal does lock recurs on purpose */ /* I bet I should use some other locks here */ #define ACPI_LOCK(sys) lockmgr(&sys##_lock, LK_EXCLUSIVE|LK_RETRY|LK_CANRECURSE) -- 2.11.4.GIT