evxfevnt.c revision 217365
167754Smsmith/****************************************************************************** 267754Smsmith * 367754Smsmith * Module Name: evxfevnt - External Interfaces, ACPI event disable/enable 467754Smsmith * 567754Smsmith *****************************************************************************/ 667754Smsmith 7217365Sjkim/* 8217365Sjkim * Copyright (C) 2000 - 2011, 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 4467754Smsmith 4567754Smsmith#define __EVXFEVNT_C__ 4667754Smsmith 47193341Sjkim#include <contrib/dev/acpica/include/acpi.h> 48193341Sjkim#include <contrib/dev/acpica/include/accommon.h> 49193341Sjkim#include <contrib/dev/acpica/include/actables.h> 5067754Smsmith 5177424Smsmith#define _COMPONENT ACPI_EVENTS 5291116Smsmith ACPI_MODULE_NAME ("evxfevnt") 5367754Smsmith 5467754Smsmith 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 79167802Sjkim if (!AcpiTbTablesLoaded ()) 8067754Smsmith { 8167754Smsmith return_ACPI_STATUS (AE_NO_ACPI_TABLES); 8267754Smsmith } 8367754Smsmith 84167802Sjkim /* Check current mode */ 85167802Sjkim 86102550Siwasaki if (AcpiHwGetMode() == ACPI_SYS_MODE_ACPI) 8767754Smsmith { 88114237Snjl ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "System is already in ACPI mode\n")); 8967754Smsmith } 9087031Smsmith else 9187031Smsmith { 9287031Smsmith /* Transition to ACPI mode */ 9367754Smsmith 9491116Smsmith Status = AcpiHwSetMode (ACPI_SYS_MODE_ACPI); 9587031Smsmith if (ACPI_FAILURE (Status)) 9687031Smsmith { 97167802Sjkim ACPI_ERROR ((AE_INFO, "Could not transition to ACPI mode")); 9887031Smsmith return_ACPI_STATUS (Status); 9987031Smsmith } 10087031Smsmith 101151937Sjkim ACPI_DEBUG_PRINT ((ACPI_DB_INIT, 102151937Sjkim "Transition to ACPI mode successful\n")); 10367754Smsmith } 10467754Smsmith 10567754Smsmith return_ACPI_STATUS (Status); 10667754Smsmith} 10767754Smsmith 108167802SjkimACPI_EXPORT_SYMBOL (AcpiEnable) 10967754Smsmith 110167802Sjkim 11177424Smsmith/******************************************************************************* 11267754Smsmith * 11367754Smsmith * FUNCTION: AcpiDisable 11467754Smsmith * 11567754Smsmith * PARAMETERS: None 11667754Smsmith * 11767754Smsmith * RETURN: Status 11867754Smsmith * 119151937Sjkim * DESCRIPTION: Transfers the system into LEGACY (non-ACPI) mode. 12067754Smsmith * 12177424Smsmith ******************************************************************************/ 12267754Smsmith 12367754SmsmithACPI_STATUS 124151937SjkimAcpiDisable ( 125151937Sjkim void) 12667754Smsmith{ 12787031Smsmith ACPI_STATUS Status = AE_OK; 12867754Smsmith 12967754Smsmith 130167802Sjkim ACPI_FUNCTION_TRACE (AcpiDisable); 13167754Smsmith 132117521Snjl 133102550Siwasaki if (AcpiHwGetMode() == ACPI_SYS_MODE_LEGACY) 13467754Smsmith { 135151937Sjkim ACPI_DEBUG_PRINT ((ACPI_DB_INIT, 136151937Sjkim "System is already in legacy (non-ACPI) mode\n")); 137102550Siwasaki } 138102550Siwasaki else 139102550Siwasaki { 140102550Siwasaki /* Transition to LEGACY mode */ 141114237Snjl 142102550Siwasaki Status = AcpiHwSetMode (ACPI_SYS_MODE_LEGACY); 14391116Smsmith 14487031Smsmith if (ACPI_FAILURE (Status)) 14587031Smsmith { 146167802Sjkim ACPI_ERROR ((AE_INFO, 147151937Sjkim "Could not exit ACPI mode to legacy mode")); 14887031Smsmith return_ACPI_STATUS (Status); 14987031Smsmith } 150102550Siwasaki 151114237Snjl ACPI_DEBUG_PRINT ((ACPI_DB_INIT, "ACPI mode disabled\n")); 15267754Smsmith } 15367754Smsmith 15467754Smsmith return_ACPI_STATUS (Status); 15567754Smsmith} 15667754Smsmith 157167802SjkimACPI_EXPORT_SYMBOL (AcpiDisable) 15867754Smsmith 159167802Sjkim 16077424Smsmith/******************************************************************************* 16167754Smsmith * 16267754Smsmith * FUNCTION: AcpiEnableEvent 16367754Smsmith * 164117521Snjl * PARAMETERS: Event - The fixed eventto be enabled 165117521Snjl * Flags - Reserved 16667754Smsmith * 16767754Smsmith * RETURN: Status 16867754Smsmith * 169117521Snjl * DESCRIPTION: Enable an ACPI event (fixed) 17067754Smsmith * 17167754Smsmith ******************************************************************************/ 17267754Smsmith 17367754SmsmithACPI_STATUS 17467754SmsmithAcpiEnableEvent ( 17567754Smsmith UINT32 Event, 17684491Smsmith UINT32 Flags) 17767754Smsmith{ 17867754Smsmith ACPI_STATUS Status = AE_OK; 17999679Siwasaki UINT32 Value; 18067754Smsmith 18167754Smsmith 182167802Sjkim ACPI_FUNCTION_TRACE (AcpiEnableEvent); 18367754Smsmith 18467754Smsmith 185117521Snjl /* Decode the Fixed Event */ 18667754Smsmith 187117521Snjl if (Event > ACPI_EVENT_MAX) 18867754Smsmith { 189117521Snjl return_ACPI_STATUS (AE_BAD_PARAMETER); 190117521Snjl } 19167754Smsmith 192117521Snjl /* 193193267Sjkim * Enable the requested fixed event (by writing a one to the enable 194193267Sjkim * register bit) 195117521Snjl */ 196193267Sjkim Status = AcpiWriteBitRegister ( 197193267Sjkim AcpiGbl_FixedEventInfo[Event].EnableRegisterId, 198193267Sjkim ACPI_ENABLE_EVENT); 199117521Snjl if (ACPI_FAILURE (Status)) 200117521Snjl { 201117521Snjl return_ACPI_STATUS (Status); 202117521Snjl } 20367754Smsmith 204117521Snjl /* Make sure that the hardware responded */ 20567754Smsmith 206193267Sjkim Status = AcpiReadBitRegister ( 207193267Sjkim AcpiGbl_FixedEventInfo[Event].EnableRegisterId, &Value); 208117521Snjl if (ACPI_FAILURE (Status)) 209117521Snjl { 210117521Snjl return_ACPI_STATUS (Status); 211117521Snjl } 21269450Smsmith 213117521Snjl if (Value != 1) 214117521Snjl { 215167802Sjkim ACPI_ERROR ((AE_INFO, 216167802Sjkim "Could not enable %s event", AcpiUtGetEventName (Event))); 217117521Snjl return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE); 218117521Snjl } 21991116Smsmith 220117521Snjl return_ACPI_STATUS (Status); 221117521Snjl} 22299679Siwasaki 223167802SjkimACPI_EXPORT_SYMBOL (AcpiEnableEvent) 22467754Smsmith 225167802Sjkim 226117521Snjl/******************************************************************************* 227117521Snjl * 228129684Snjl * FUNCTION: AcpiDisableEvent 229129684Snjl * 230216471Sjkim * PARAMETERS: Event - The fixed event to be disabled 231129684Snjl * Flags - Reserved 232129684Snjl * 233129684Snjl * RETURN: Status 234129684Snjl * 235129684Snjl * DESCRIPTION: Disable an ACPI event (fixed) 236129684Snjl * 237129684Snjl ******************************************************************************/ 238129684Snjl 239129684SnjlACPI_STATUS 240129684SnjlAcpiDisableEvent ( 241129684Snjl UINT32 Event, 242129684Snjl UINT32 Flags) 243129684Snjl{ 244129684Snjl ACPI_STATUS Status = AE_OK; 245129684Snjl UINT32 Value; 246129684Snjl 247129684Snjl 248167802Sjkim ACPI_FUNCTION_TRACE (AcpiDisableEvent); 249129684Snjl 250129684Snjl 251129684Snjl /* Decode the Fixed Event */ 252129684Snjl 253129684Snjl if (Event > ACPI_EVENT_MAX) 254129684Snjl { 255129684Snjl return_ACPI_STATUS (AE_BAD_PARAMETER); 256129684Snjl } 257129684Snjl 258117521Snjl /* 259193267Sjkim * Disable the requested fixed event (by writing a zero to the enable 260193267Sjkim * register bit) 261117521Snjl */ 262193267Sjkim Status = AcpiWriteBitRegister ( 263193267Sjkim AcpiGbl_FixedEventInfo[Event].EnableRegisterId, 264193267Sjkim ACPI_DISABLE_EVENT); 265129684Snjl if (ACPI_FAILURE (Status)) 266117521Snjl { 267129684Snjl return_ACPI_STATUS (Status); 268117521Snjl } 269129684Snjl 270193267Sjkim Status = AcpiReadBitRegister ( 271193267Sjkim AcpiGbl_FixedEventInfo[Event].EnableRegisterId, &Value); 272129684Snjl if (ACPI_FAILURE (Status)) 273117521Snjl { 274129684Snjl return_ACPI_STATUS (Status); 275117521Snjl } 276117521Snjl 277129684Snjl if (Value != 0) 278117521Snjl { 279167802Sjkim ACPI_ERROR ((AE_INFO, 280167802Sjkim "Could not disable %s events", AcpiUtGetEventName (Event))); 281129684Snjl return_ACPI_STATUS (AE_NO_HARDWARE_RESPONSE); 282117521Snjl } 283129684Snjl 28467754Smsmith return_ACPI_STATUS (Status); 28567754Smsmith} 28667754Smsmith 287167802SjkimACPI_EXPORT_SYMBOL (AcpiDisableEvent) 28867754Smsmith 289167802Sjkim 29077424Smsmith/******************************************************************************* 29167754Smsmith * 29267754Smsmith * FUNCTION: AcpiClearEvent 29367754Smsmith * 294117521Snjl * PARAMETERS: Event - The fixed event to be cleared 29567754Smsmith * 29667754Smsmith * RETURN: Status 29767754Smsmith * 298117521Snjl * DESCRIPTION: Clear an ACPI event (fixed) 29967754Smsmith * 30067754Smsmith ******************************************************************************/ 30167754Smsmith 30267754SmsmithACPI_STATUS 30367754SmsmithAcpiClearEvent ( 304117521Snjl UINT32 Event) 30567754Smsmith{ 30667754Smsmith ACPI_STATUS Status = AE_OK; 30767754Smsmith 30867754Smsmith 309167802Sjkim ACPI_FUNCTION_TRACE (AcpiClearEvent); 31067754Smsmith 31167754Smsmith 312117521Snjl /* Decode the Fixed Event */ 31367754Smsmith 314117521Snjl if (Event > ACPI_EVENT_MAX) 31567754Smsmith { 316117521Snjl return_ACPI_STATUS (AE_BAD_PARAMETER); 317117521Snjl } 31867754Smsmith 319117521Snjl /* 320193267Sjkim * Clear the requested fixed event (By writing a one to the status 321193267Sjkim * register bit) 322117521Snjl */ 323193267Sjkim Status = AcpiWriteBitRegister ( 324193267Sjkim AcpiGbl_FixedEventInfo[Event].StatusRegisterId, 325193267Sjkim ACPI_CLEAR_STATUS); 32667754Smsmith 327117521Snjl return_ACPI_STATUS (Status); 328117521Snjl} 32967754Smsmith 330167802SjkimACPI_EXPORT_SYMBOL (AcpiClearEvent) 33167754Smsmith 332167802Sjkim 333117521Snjl/******************************************************************************* 334117521Snjl * 33567754Smsmith * FUNCTION: AcpiGetEventStatus 33667754Smsmith * 337117521Snjl * PARAMETERS: Event - The fixed event 338151937Sjkim * EventStatus - Where the current status of the event will 33967754Smsmith * be returned 34067754Smsmith * 34167754Smsmith * RETURN: Status 34267754Smsmith * 34367754Smsmith * DESCRIPTION: Obtains and returns the current status of the event 34467754Smsmith * 34567754Smsmith ******************************************************************************/ 34667754Smsmith 34767754SmsmithACPI_STATUS 34867754SmsmithAcpiGetEventStatus ( 34967754Smsmith UINT32 Event, 35067754Smsmith ACPI_EVENT_STATUS *EventStatus) 35167754Smsmith{ 35267754Smsmith ACPI_STATUS Status = AE_OK; 35367754Smsmith 35467754Smsmith 355167802Sjkim ACPI_FUNCTION_TRACE (AcpiGetEventStatus); 35667754Smsmith 35767754Smsmith 35867754Smsmith if (!EventStatus) 35967754Smsmith { 36067754Smsmith return_ACPI_STATUS (AE_BAD_PARAMETER); 36167754Smsmith } 36267754Smsmith 363117521Snjl /* Decode the Fixed Event */ 36467754Smsmith 365117521Snjl if (Event > ACPI_EVENT_MAX) 36667754Smsmith { 367117521Snjl return_ACPI_STATUS (AE_BAD_PARAMETER); 368117521Snjl } 36967754Smsmith 370117521Snjl /* Get the status of the requested fixed event */ 37167754Smsmith 372193267Sjkim Status = AcpiReadBitRegister ( 373193267Sjkim AcpiGbl_FixedEventInfo[Event].StatusRegisterId, EventStatus); 374117521Snjl 375117521Snjl return_ACPI_STATUS (Status); 376117521Snjl} 377117521Snjl 378167802SjkimACPI_EXPORT_SYMBOL (AcpiGetEventStatus) 379117521Snjl 380167802Sjkim 381