diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2014-04-26 21:45:51 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2014-04-26 21:45:51 +0000 |
commit | 608671b33d50b5d89a06e3ead14e8e59631c4825 (patch) | |
tree | 44428393932d16242dcffaf769e11ac73f9f1d51 | |
parent | 55e7e178be2be63872d020ffa963c99cc4885450 (diff) |
Get rid of duplication of the global lock code. Allow recursion in all
code paths.
ok pirofti@
-rw-r--r-- | sys/dev/acpi/dsdt.c | 70 |
1 files changed, 28 insertions, 42 deletions
diff --git a/sys/dev/acpi/dsdt.c b/sys/dev/acpi/dsdt.c index 10c2f74ab6f..6c29cd1078d 100644 --- a/sys/dev/acpi/dsdt.c +++ b/sys/dev/acpi/dsdt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dsdt.c,v 1.206 2014/03/13 18:52:38 brynet Exp $ */ +/* $OpenBSD: dsdt.c,v 1.207 2014/04/26 21:45:50 kettenis Exp $ */ /* * Copyright (c) 2005 Jordan Hargrave <jordan@openbsd.org> * @@ -736,72 +736,58 @@ static long global_lock_count = 0; void acpi_glk_enter(void) { - acpi_acquire_glk(&acpi_softc->sc_facs->global_lock); -} - -void -acpi_glk_leave(void) -{ - int x; - - if (acpi_release_glk(&acpi_softc->sc_facs->global_lock)) { - /* - * If pending, notify the BIOS that the lock was released - * by the OSPM. No locking is needed because nobody outside - * the ACPI thread is touching this register. - */ - x = acpi_read_pmreg(acpi_softc, ACPIREG_PM1_CNT, 0); - x |= ACPI_PM1_GBL_RLS; - acpi_write_pmreg(acpi_softc, ACPIREG_PM1_CNT, 0, x); - } -} - -void -aml_lockfield(struct aml_scope *scope, struct aml_value *field) -{ int st = 0; - if (AML_FIELD_LOCK(field->v_field.flags) != AML_FIELD_LOCK_ON) - return; - - /* If lock is already ours, just continue */ + /* If lock is already ours, just continue. */ if (global_lock_count++) return; - /* Spin to acquire lock */ + /* Spin to acquire the lock. */ while (!st) { st = acpi_acquire_glk(&acpi_softc->sc_facs->global_lock); /* XXX - yield/delay? */ } - - return; } void -aml_unlockfield(struct aml_scope *scope, struct aml_value *field) +acpi_glk_leave(void) { - int st, x, s; + int st, x; - if (AML_FIELD_LOCK(field->v_field.flags) != AML_FIELD_LOCK_ON) - return; - - /* If we are the last ones, turn out the lights */ + /* If we are the last one, turn out the lights. */ if (--global_lock_count) return; - /* Release lock */ st = acpi_release_glk(&acpi_softc->sc_facs->global_lock); if (!st) return; - /* Signal others if someone waiting */ - s = spltty(); + /* + * If pending, notify the BIOS that the lock was released by + * OSPM. No locking is needed because nobody outside the ACPI + * thread is supposed to touch this register. + */ x = acpi_read_pmreg(acpi_softc, ACPIREG_PM1_CNT, 0); x |= ACPI_PM1_GBL_RLS; acpi_write_pmreg(acpi_softc, ACPIREG_PM1_CNT, 0, x); - splx(s); +} + +void +aml_lockfield(struct aml_scope *scope, struct aml_value *field) +{ + if (AML_FIELD_LOCK(field->v_field.flags) != AML_FIELD_LOCK_ON) + return; + + acpi_glk_enter(); +} + +void +aml_unlockfield(struct aml_scope *scope, struct aml_value *field) +{ + if (AML_FIELD_LOCK(field->v_field.flags) != AML_FIELD_LOCK_ON) + return; - return; + acpi_glk_leave(); } /* |