167754Smsmith/****************************************************************************** 267754Smsmith * 367754Smsmith * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable 467754Smsmith * 567754Smsmith *****************************************************************************/ 667754Smsmith 7217365Sjkim/* 8306536Sjkim * Copyright (C) 2000 - 2016, Intel Corp. 970243Smsmith * All rights reserved. 1067754Smsmith * 11217365Sjkim * Redistribution and use in source and binary forms, with or without 12217365Sjkim * modification, are permitted provided that the following conditions 13217365Sjkim * are met: 14217365Sjkim * 1. Redistributions of source code must retain the above copyright 15217365Sjkim * notice, this list of conditions, and the following disclaimer, 16217365Sjkim * without modification. 17217365Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18217365Sjkim * substantially similar to the "NO WARRANTY" disclaimer below 19217365Sjkim * ("Disclaimer") and any redistribution must be conditioned upon 20217365Sjkim * including a substantially similar Disclaimer requirement for further 21217365Sjkim * binary redistribution. 22217365Sjkim * 3. Neither the names of the above-listed copyright holders nor the names 23217365Sjkim * of any contributors may be used to endorse or promote products derived 24217365Sjkim * from this software without specific prior written permission. 2567754Smsmith * 26217365Sjkim * Alternatively, this software may be distributed under the terms of the 27217365Sjkim * GNU General Public License ("GPL") version 2 as published by the Free 28217365Sjkim * Software Foundation. 2967754Smsmith * 30217365Sjkim * NO WARRANTY 31217365Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32217365Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33217365Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34217365Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35217365Sjkim * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36217365Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37217365Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38217365Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39217365Sjkim * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40217365Sjkim * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41217365Sjkim * POSSIBILITY OF SUCH DAMAGES. 42217365Sjkim */ 4367754Smsmith 44281075Sdim#define EXPORT_ACPI_INTERFACES 4567754Smsmith 46193341Sjkim#include <contrib/dev/acpica/include/acpi.h> 47193341Sjkim#include <contrib/dev/acpica/include/accommon.h> 48193341Sjkim#include <contrib/dev/acpica/include/actables.h> 4967754Smsmith 5077424Smsmith#define _COMPONENT ACPI_EVENTS 5191116Smsmith ACPI_MODULE_NAME ("evxfevnt") 5267754Smsmith 5367754Smsmith 54231844Sjkim#if (!ACPI_REDUCED_HARDWARE) /* Entire module */ 5577424Smsmith/******************************************************************************* 5667754Smsmith * 5767754Smsmith * FUNCTION: AcpiEnable 5867754Smsmith * 5967754Smsmith * PARAMETERS: None 6067754Smsmith * 6167754Smsmith * RETURN: Status 6267754Smsmith * 6367754Smsmith * DESCRIPTION: Transfers the system into ACPI mode. 6467754Smsmith * 6577424Smsmith ******************************************************************************/ 6667754Smsmith 6767754SmsmithACPI_STATUS 68151937SjkimAcpiEnable ( 69151937Sjkim void) 7067754Smsmith{ 7187031Smsmith ACPI_STATUS Status = AE_OK; 7267754Smsmith 7367754Smsmith 74167802Sjkim ACPI_FUNCTION_TRACE (AcpiEnable); 7567754Smsmith 7667754Smsmith 77167802Sjkim /* ACPI tables must be present */ 7867754Smsmith 79306536Sjkim if (AcpiGbl_FadtIndex == ACPI_INVALID_TABLE_INDEX) 8067754Smsmith { 8167754Smsmith return_ACPI_STATUS (AE_NO_ACPI_TABLES); 8267754Smsmith } 8367754Smsmith 84246849Sjkim /* If the Hardware Reduced flag is set, machine is always in acpi mode */ 85246849Sjkim 86246849Sjkim if (AcpiGbl_ReducedHardware) 87246849Sjkim { 88246849Sjkim return_ACPI_STATUS (AE_OK); 89246849Sjkim } 90246849Sjkim 91167802Sjkim /* Check current mode */ 92167802Sjkim 93102550Siwasaki if (AcpiHwGetMode() == ACPI_SYS_MODE_ACPI) 9467754Smsmith { 95306536Sjkim ACPI_DEBUG_PRINT ((ACPI_DB_INIT, 96306536Sjkim "System is already in ACPI mode\n")); 9767754Smsmith } 9887031Smsmith else 9987031Smsmith { 10087031Smsmith /* Transition to ACPI mode */ 10167754Smsmith 10291116Smsmith Status = AcpiHwSetMode (ACPI_SYS_MODE_ACPI); 10387031Smsmith if (ACPI_FAILURE (Status)) 10487031Smsmith { 105167802Sjkim ACPI_ERROR ((AE_INFO, "Could not transition to ACPI mode")); 10687031Smsmith return_ACPI_STATUS (Status); 10787031Smsmith } 10887031Smsmith 109151937Sjkim ACPI_DEBUG_PRINT ((ACPI_DB_INIT, 110151937Sjkim "Transition to ACPI mode successful\n")); 11167754Smsmith } 11267754Smsmith 11367754Smsmith return_ACPI_STATUS (Status); 11467754Smsmith} 11567754Smsmith 116167802SjkimACPI_EXPORT_SYMBOL (AcpiEnable) 11767754Smsmith 118167802Sjkim 11977424Smsmith/******************************************************************************* 12067754Smsmith * 12167754Smsmith * FUNCTION: AcpiDisable 12267754Smsmith * 12367754Smsmith * PARAMETERS: None 12467754Smsmith * 12567754Smsmith * RETURN: Status 12667754Smsmith * 127151937Sjkim * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode. 12867754Smsmith * 12977424Smsmith ******************************************************************************/ 13067754Smsmith 13167754SmsmithACPI_STATUS 132151937SjkimAcpiDisable ( 133151937Sjkim void) 13467754Smsmith{ 13587031Smsmith ACPI_STATUS Status = AE_OK; 13667754Smsmith 13767754Smsmith 138167802Sjkim ACPI_FUNCTION_TRACE (AcpiDisable); 13967754Smsmith 140117521Snjl 141246849Sjkim /* If the Hardware Reduced flag is set, machine is always in acpi mode */ 142246849Sjkim 143246849Sjkim if (AcpiGbl_ReducedHardware) 144246849Sjkim { 145246849Sjkim return_ACPI_STATUS (AE_OK); 146246849Sjkim } 147246849Sjkim 148102550Siwasaki if (AcpiHwGetMode() == ACPI_SYS_MODE_LEGACY) 14967754Smsmith { 150151937Sjkim ACPI_DEBUG_PRINT ((ACPI_DB_INIT, 151151937Sjkim "System is already in legacy (non-ACPI) mode\n")); 152102550Siwasaki } 153102550Siwasaki else 154102550Siwasaki { 155102550Siwasaki /* Transition to LEGACY mode */ 156114237Snjl 157102550Siwasaki Status = AcpiHwSetMode (ACPI_SYS_MODE_LEGACY); 15891116Smsmith 15987031Smsmith if (ACPI_FAILURE (Status)) 16087031Smsmith { 161167802Sjkim ACPI_ERROR ((AE_INFO, 162151937Sjkim "Could not exit ACPI mode to legacy mode")); 16387031Smsmith return_ACPI_STATUS (Status); 16487031Smsmith } 165102550Siwasaki 166306536Sjkim ACPI_DEBUG_PRINT ((ACPI_DB_INIT, 167306536Sjkim "ACPI mode disabled\n")); 16867754Smsmith } 16967754Smsmith 17067754Smsmith return_ACPI_STATUS (Status); 17167754Smsmith} 17267754Smsmith 173167802SjkimACPI_EXPORT_SYMBOL (AcpiDisable) 17467754Smsmith 175167802Sjkim 17677424Smsmith/******************************************************************************* 17767754Smsmith * 17867754Smsmith * FUNCTION: AcpiEnableEvent 17967754Smsmith * 180117521Snjl * PARAMETERS: Event - The fixed eventto be enabled 181117521Snjl * Flags - Reserved 18267754Smsmith * 18367754Smsmith * RETURN: Status 18467754Smsmith * 185117521Snjl * DESCRIPTION: Enable an ACPI event (fixed) 18667754Smsmith * 18767754Smsmith ******************************************************************************/ 18867754Smsmith 18967754SmsmithACPI_STATUS 19067754SmsmithAcpiEnableEvent ( 19167754Smsmith UINT32 Event, 19284491Smsmith UINT32 Flags) 19367754Smsmith{ 19467754Smsmith ACPI_STATUS Status = AE_OK; 19599679Siwasaki UINT32 Value; 19667754Smsmith 19767754Smsmith 198167802Sjkim ACPI_FUNCTION_TRACE (AcpiEnableEvent); 19967754Smsmith 20067754Smsmith 201117521Snjl /* Decode the Fixed Event */ 20267754Smsmith 203117521Snjl if (Event > ACPI_EVENT_MAX) 20467754Smsmith { 205117521Snjl return_ACPI_STATUS (AE_BAD_PARAMETER); 206117521Snjl } 20767754Smsmith 208117521Snjl /* 209193267Sjkim * Enable the requested fixed event (by writing a one to the enable 210193267Sjkim * register bit) 211117521Snjl */ 212193267Sjkim Status = AcpiWriteBitRegister ( 213306536Sjkim AcpiGbl_FixedEventInfo[Event].EnableRegisterId, 214306536Sjkim ACPI_ENABLE_EVENT); 215117521Snjl if (ACPI_FAILURE (Status)) 216117521Snjl { 217117521Snjl return_ACPI_STATUS (Status); 218117521Snjl } 21967754Smsmith 220117521Snjl /* Make sure that the hardware responded */ 22167754Smsmith 222193267Sjkim Status = AcpiReadBitRegister ( 223306536Sjkim AcpiGbl_FixedEventInfo[Event].EnableRegisterId, &Value); 224117521Snjl if (ACPI_FAILURE (Status)) 225117521Snjl { 226117521Snjl return_ACPI_STATUS (Status); 227117521Snjl } 22869450Smsmith 229117521Snjl if (Value != 1) 230117521Snjl { 231167802Sjkim ACPI_ERROR ((AE_INFO, 232167802Sjkim "Could not enable %s event", AcpiUtGetEventName (Event))); 233117521Snjl return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE); 234117521Snjl } 23591116Smsmith 236117521Snjl return_ACPI_STATUS (Status); 237117521Snjl} 23899679Siwasaki 239167802SjkimACPI_EXPORT_SYMBOL (AcpiEnableEvent) 24067754Smsmith 241167802Sjkim 242117521Snjl/******************************************************************************* 243117521Snjl * 244129684Snjl * FUNCTION: AcpiDisableEvent 245129684Snjl * 246216471Sjkim * PARAMETERS: Event - The fixed event to be disabled 247129684Snjl * Flags - Reserved 248129684Snjl * 249129684Snjl * RETURN: Status 250129684Snjl * 251129684Snjl * DESCRIPTION: Disable an ACPI event (fixed) 252129684Snjl * 253129684Snjl ******************************************************************************/ 254129684Snjl 255129684SnjlACPI_STATUS 256129684SnjlAcpiDisableEvent ( 257129684Snjl UINT32 Event, 258129684Snjl UINT32 Flags) 259129684Snjl{ 260129684Snjl ACPI_STATUS Status = AE_OK; 261129684Snjl UINT32 Value; 262129684Snjl 263129684Snjl 264167802Sjkim ACPI_FUNCTION_TRACE (AcpiDisableEvent); 265129684Snjl 266129684Snjl 267129684Snjl /* Decode the Fixed Event */ 268129684Snjl 269129684Snjl if (Event > ACPI_EVENT_MAX) 270129684Snjl { 271129684Snjl return_ACPI_STATUS (AE_BAD_PARAMETER); 272129684Snjl } 273129684Snjl 274117521Snjl /* 275193267Sjkim * Disable the requested fixed event (by writing a zero to the enable 276193267Sjkim * register bit) 277117521Snjl */ 278193267Sjkim Status = AcpiWriteBitRegister ( 279306536Sjkim AcpiGbl_FixedEventInfo[Event].EnableRegisterId, 280306536Sjkim ACPI_DISABLE_EVENT); 281129684Snjl if (ACPI_FAILURE (Status)) 282117521Snjl { 283129684Snjl return_ACPI_STATUS (Status); 284117521Snjl } 285129684Snjl 286193267Sjkim Status = AcpiReadBitRegister ( 287306536Sjkim AcpiGbl_FixedEventInfo[Event].EnableRegisterId, &Value); 288129684Snjl if (ACPI_FAILURE (Status)) 289117521Snjl { 290129684Snjl return_ACPI_STATUS (Status); 291117521Snjl } 292117521Snjl 293129684Snjl if (Value != 0) 294117521Snjl { 295167802Sjkim ACPI_ERROR ((AE_INFO, 296167802Sjkim "Could not disable %s events", AcpiUtGetEventName (Event))); 297129684Snjl return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE); 298117521Snjl } 299129684Snjl 30067754Smsmith return_ACPI_STATUS (Status); 30167754Smsmith} 30267754Smsmith 303167802SjkimACPI_EXPORT_SYMBOL (AcpiDisableEvent) 30467754Smsmith 305167802Sjkim 30677424Smsmith/******************************************************************************* 30767754Smsmith * 30867754Smsmith * FUNCTION: AcpiClearEvent 30967754Smsmith * 310117521Snjl * PARAMETERS: Event - The fixed event to be cleared 31167754Smsmith * 31267754Smsmith * RETURN: Status 31367754Smsmith * 314117521Snjl * DESCRIPTION: Clear an ACPI event (fixed) 31567754Smsmith * 31667754Smsmith ******************************************************************************/ 31767754Smsmith 31867754SmsmithACPI_STATUS 31967754SmsmithAcpiClearEvent ( 320117521Snjl UINT32 Event) 32167754Smsmith{ 32267754Smsmith ACPI_STATUS Status = AE_OK; 32367754Smsmith 32467754Smsmith 325167802Sjkim ACPI_FUNCTION_TRACE (AcpiClearEvent); 32667754Smsmith 32767754Smsmith 328117521Snjl /* Decode the Fixed Event */ 32967754Smsmith 330117521Snjl if (Event > ACPI_EVENT_MAX) 33167754Smsmith { 332117521Snjl return_ACPI_STATUS (AE_BAD_PARAMETER); 333117521Snjl } 33467754Smsmith 335117521Snjl /* 336193267Sjkim * Clear the requested fixed event (By writing a one to the status 337193267Sjkim * register bit) 338117521Snjl */ 339193267Sjkim Status = AcpiWriteBitRegister ( 340306536Sjkim AcpiGbl_FixedEventInfo[Event].StatusRegisterId, 341306536Sjkim ACPI_CLEAR_STATUS); 34267754Smsmith 343117521Snjl return_ACPI_STATUS (Status); 344117521Snjl} 34567754Smsmith 346167802SjkimACPI_EXPORT_SYMBOL (AcpiClearEvent) 34767754Smsmith 348167802Sjkim 349117521Snjl/******************************************************************************* 350117521Snjl * 35167754Smsmith * FUNCTION: AcpiGetEventStatus 35267754Smsmith * 353117521Snjl * PARAMETERS: Event - The fixed event 354151937Sjkim * EventStatus - Where the current status of the event will 35567754Smsmith * be returned 35667754Smsmith * 35767754Smsmith * RETURN: Status 35867754Smsmith * 35967754Smsmith * DESCRIPTION: Obtains and returns the current status of the event 36067754Smsmith * 36167754Smsmith ******************************************************************************/ 36267754Smsmith 36367754SmsmithACPI_STATUS 36467754SmsmithAcpiGetEventStatus ( 36567754Smsmith UINT32 Event, 36667754Smsmith ACPI_EVENT_STATUS *EventStatus) 36767754Smsmith{ 368281075Sdim ACPI_STATUS Status; 369281075Sdim ACPI_EVENT_STATUS LocalEventStatus = 0; 370281075Sdim UINT32 InByte; 37167754Smsmith 37267754Smsmith 373167802Sjkim ACPI_FUNCTION_TRACE (AcpiGetEventStatus); 37467754Smsmith 37567754Smsmith 37667754Smsmith if (!EventStatus) 37767754Smsmith { 37867754Smsmith return_ACPI_STATUS (AE_BAD_PARAMETER); 37967754Smsmith } 38067754Smsmith 381117521Snjl /* Decode the Fixed Event */ 38267754Smsmith 383117521Snjl if (Event > ACPI_EVENT_MAX) 38467754Smsmith { 385117521Snjl return_ACPI_STATUS (AE_BAD_PARAMETER); 386117521Snjl } 38767754Smsmith 388281075Sdim /* Fixed event currently can be dispatched? */ 38967754Smsmith 390281075Sdim if (AcpiGbl_FixedEventHandlers[Event].Handler) 391281075Sdim { 392281075Sdim LocalEventStatus |= ACPI_EVENT_FLAG_HAS_HANDLER; 393281075Sdim } 394281075Sdim 395281075Sdim /* Fixed event currently enabled? */ 396281075Sdim 397193267Sjkim Status = AcpiReadBitRegister ( 398306536Sjkim AcpiGbl_FixedEventInfo[Event].EnableRegisterId, &InByte); 399281075Sdim if (ACPI_FAILURE (Status)) 400281075Sdim { 401281075Sdim return_ACPI_STATUS (Status); 402281075Sdim } 403117521Snjl 404281075Sdim if (InByte) 405281075Sdim { 406281687Sjkim LocalEventStatus |= 407281687Sjkim (ACPI_EVENT_FLAG_ENABLED | ACPI_EVENT_FLAG_ENABLE_SET); 408281075Sdim } 409281075Sdim 410281075Sdim /* Fixed event currently active? */ 411281075Sdim 412281075Sdim Status = AcpiReadBitRegister ( 413306536Sjkim AcpiGbl_FixedEventInfo[Event].StatusRegisterId, &InByte); 414281075Sdim if (ACPI_FAILURE (Status)) 415281075Sdim { 416281075Sdim return_ACPI_STATUS (Status); 417281075Sdim } 418281075Sdim 419281075Sdim if (InByte) 420281075Sdim { 421281687Sjkim LocalEventStatus |= ACPI_EVENT_FLAG_STATUS_SET; 422281075Sdim } 423281075Sdim 424281075Sdim (*EventStatus) = LocalEventStatus; 425281075Sdim return_ACPI_STATUS (AE_OK); 426117521Snjl} 427117521Snjl 428167802SjkimACPI_EXPORT_SYMBOL (AcpiGetEventStatus) 429117521Snjl 430231844Sjkim#endif /* !ACPI_REDUCED_HARDWARE */ 431