From dc67d3948a01038ceb2836368391c984b516ba10 Mon Sep 17 00:00:00 2001 From: kettenis Date: Sat, 26 Apr 2014 21:45:50 +0000 Subject: [PATCH] Get rid of duplication of the global lock code. Allow recursion in all code paths. ok pirofti@ --- sys/dev/acpi/dsdt.c | 70 ++++++++++++++++++--------------------------- 1 file 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 * @@ -735,73 +735,59 @@ 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(); } /* -- 2.20.1