Home | History | Annotate | Line # | Download | only in events
evxfregn.c revision 1.1.1.13
      1       1.1    jruoho /******************************************************************************
      2       1.1    jruoho  *
      3       1.1    jruoho  * Module Name: evxfregn - External Interfaces, ACPI Operation Regions and
      4       1.1    jruoho  *                         Address Spaces.
      5       1.1    jruoho  *
      6       1.1    jruoho  *****************************************************************************/
      7       1.1    jruoho 
      8   1.1.1.2    jruoho /*
      9  1.1.1.13  christos  * Copyright (C) 2000 - 2021, Intel Corp.
     10       1.1    jruoho  * All rights reserved.
     11       1.1    jruoho  *
     12   1.1.1.2    jruoho  * Redistribution and use in source and binary forms, with or without
     13   1.1.1.2    jruoho  * modification, are permitted provided that the following conditions
     14   1.1.1.2    jruoho  * are met:
     15   1.1.1.2    jruoho  * 1. Redistributions of source code must retain the above copyright
     16   1.1.1.2    jruoho  *    notice, this list of conditions, and the following disclaimer,
     17   1.1.1.2    jruoho  *    without modification.
     18   1.1.1.2    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     19   1.1.1.2    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     20   1.1.1.2    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     21   1.1.1.2    jruoho  *    including a substantially similar Disclaimer requirement for further
     22   1.1.1.2    jruoho  *    binary redistribution.
     23   1.1.1.2    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     24   1.1.1.2    jruoho  *    of any contributors may be used to endorse or promote products derived
     25   1.1.1.2    jruoho  *    from this software without specific prior written permission.
     26   1.1.1.2    jruoho  *
     27   1.1.1.2    jruoho  * Alternatively, this software may be distributed under the terms of the
     28   1.1.1.2    jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     29   1.1.1.2    jruoho  * Software Foundation.
     30   1.1.1.2    jruoho  *
     31   1.1.1.2    jruoho  * NO WARRANTY
     32   1.1.1.2    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     33   1.1.1.2    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     34  1.1.1.13  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     35   1.1.1.2    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     36   1.1.1.2    jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     37   1.1.1.2    jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     38   1.1.1.2    jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     39   1.1.1.2    jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     40   1.1.1.2    jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     41   1.1.1.2    jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     42   1.1.1.2    jruoho  * POSSIBILITY OF SUCH DAMAGES.
     43   1.1.1.2    jruoho  */
     44       1.1    jruoho 
     45   1.1.1.4  christos #define EXPORT_ACPI_INTERFACES
     46       1.1    jruoho 
     47       1.1    jruoho #include "acpi.h"
     48       1.1    jruoho #include "accommon.h"
     49       1.1    jruoho #include "acnamesp.h"
     50       1.1    jruoho #include "acevents.h"
     51       1.1    jruoho 
     52       1.1    jruoho #define _COMPONENT          ACPI_EVENTS
     53       1.1    jruoho         ACPI_MODULE_NAME    ("evxfregn")
     54       1.1    jruoho 
     55       1.1    jruoho 
     56       1.1    jruoho /*******************************************************************************
     57       1.1    jruoho  *
     58       1.1    jruoho  * FUNCTION:    AcpiInstallAddressSpaceHandler
     59       1.1    jruoho  *
     60       1.1    jruoho  * PARAMETERS:  Device          - Handle for the device
     61       1.1    jruoho  *              SpaceId         - The address space ID
     62       1.1    jruoho  *              Handler         - Address of the handler
     63       1.1    jruoho  *              Setup           - Address of the setup function
     64       1.1    jruoho  *              Context         - Value passed to the handler on each access
     65       1.1    jruoho  *
     66       1.1    jruoho  * RETURN:      Status
     67       1.1    jruoho  *
     68       1.1    jruoho  * DESCRIPTION: Install a handler for all OpRegions of a given SpaceId.
     69       1.1    jruoho  *
     70   1.1.1.2    jruoho  * NOTE: This function should only be called after AcpiEnableSubsystem has
     71   1.1.1.2    jruoho  * been called. This is because any _REG methods associated with the Space ID
     72   1.1.1.2    jruoho  * are executed here, and these methods can only be safely executed after
     73   1.1.1.2    jruoho  * the default handlers have been installed and the hardware has been
     74   1.1.1.2    jruoho  * initialized (via AcpiEnableSubsystem.)
     75   1.1.1.2    jruoho  *
     76       1.1    jruoho  ******************************************************************************/
     77       1.1    jruoho 
     78       1.1    jruoho ACPI_STATUS
     79       1.1    jruoho AcpiInstallAddressSpaceHandler (
     80       1.1    jruoho     ACPI_HANDLE             Device,
     81       1.1    jruoho     ACPI_ADR_SPACE_TYPE     SpaceId,
     82       1.1    jruoho     ACPI_ADR_SPACE_HANDLER  Handler,
     83       1.1    jruoho     ACPI_ADR_SPACE_SETUP    Setup,
     84       1.1    jruoho     void                    *Context)
     85       1.1    jruoho {
     86       1.1    jruoho     ACPI_NAMESPACE_NODE     *Node;
     87       1.1    jruoho     ACPI_STATUS             Status;
     88       1.1    jruoho 
     89       1.1    jruoho 
     90       1.1    jruoho     ACPI_FUNCTION_TRACE (AcpiInstallAddressSpaceHandler);
     91       1.1    jruoho 
     92       1.1    jruoho 
     93       1.1    jruoho     /* Parameter validation */
     94       1.1    jruoho 
     95       1.1    jruoho     if (!Device)
     96       1.1    jruoho     {
     97       1.1    jruoho         return_ACPI_STATUS (AE_BAD_PARAMETER);
     98       1.1    jruoho     }
     99       1.1    jruoho 
    100       1.1    jruoho     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
    101       1.1    jruoho     if (ACPI_FAILURE (Status))
    102       1.1    jruoho     {
    103       1.1    jruoho         return_ACPI_STATUS (Status);
    104       1.1    jruoho     }
    105       1.1    jruoho 
    106       1.1    jruoho     /* Convert and validate the device handle */
    107       1.1    jruoho 
    108       1.1    jruoho     Node = AcpiNsValidateHandle (Device);
    109       1.1    jruoho     if (!Node)
    110       1.1    jruoho     {
    111       1.1    jruoho         Status = AE_BAD_PARAMETER;
    112       1.1    jruoho         goto UnlockAndExit;
    113       1.1    jruoho     }
    114       1.1    jruoho 
    115       1.1    jruoho     /* Install the handler for all Regions for this Space ID */
    116       1.1    jruoho 
    117   1.1.1.7  christos     Status = AcpiEvInstallSpaceHandler (
    118   1.1.1.7  christos         Node, SpaceId, Handler, Setup, Context);
    119       1.1    jruoho     if (ACPI_FAILURE (Status))
    120       1.1    jruoho     {
    121       1.1    jruoho         goto UnlockAndExit;
    122       1.1    jruoho     }
    123       1.1    jruoho 
    124   1.1.1.3    jruoho     /* Run all _REG methods for this address space */
    125   1.1.1.3    jruoho 
    126   1.1.1.7  christos     AcpiEvExecuteRegMethods (Node, SpaceId, ACPI_REG_CONNECT);
    127   1.1.1.3    jruoho 
    128       1.1    jruoho 
    129       1.1    jruoho UnlockAndExit:
    130       1.1    jruoho     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
    131       1.1    jruoho     return_ACPI_STATUS (Status);
    132       1.1    jruoho }
    133       1.1    jruoho 
    134       1.1    jruoho ACPI_EXPORT_SYMBOL (AcpiInstallAddressSpaceHandler)
    135       1.1    jruoho 
    136       1.1    jruoho 
    137       1.1    jruoho /*******************************************************************************
    138       1.1    jruoho  *
    139       1.1    jruoho  * FUNCTION:    AcpiRemoveAddressSpaceHandler
    140       1.1    jruoho  *
    141       1.1    jruoho  * PARAMETERS:  Device          - Handle for the device
    142       1.1    jruoho  *              SpaceId         - The address space ID
    143       1.1    jruoho  *              Handler         - Address of the handler
    144       1.1    jruoho  *
    145       1.1    jruoho  * RETURN:      Status
    146       1.1    jruoho  *
    147       1.1    jruoho  * DESCRIPTION: Remove a previously installed handler.
    148       1.1    jruoho  *
    149       1.1    jruoho  ******************************************************************************/
    150       1.1    jruoho 
    151       1.1    jruoho ACPI_STATUS
    152       1.1    jruoho AcpiRemoveAddressSpaceHandler (
    153       1.1    jruoho     ACPI_HANDLE             Device,
    154       1.1    jruoho     ACPI_ADR_SPACE_TYPE     SpaceId,
    155       1.1    jruoho     ACPI_ADR_SPACE_HANDLER  Handler)
    156       1.1    jruoho {
    157       1.1    jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
    158       1.1    jruoho     ACPI_OPERAND_OBJECT     *HandlerObj;
    159       1.1    jruoho     ACPI_OPERAND_OBJECT     *RegionObj;
    160       1.1    jruoho     ACPI_OPERAND_OBJECT     **LastObjPtr;
    161       1.1    jruoho     ACPI_NAMESPACE_NODE     *Node;
    162       1.1    jruoho     ACPI_STATUS             Status;
    163       1.1    jruoho 
    164       1.1    jruoho 
    165       1.1    jruoho     ACPI_FUNCTION_TRACE (AcpiRemoveAddressSpaceHandler);
    166       1.1    jruoho 
    167       1.1    jruoho 
    168       1.1    jruoho     /* Parameter validation */
    169       1.1    jruoho 
    170       1.1    jruoho     if (!Device)
    171       1.1    jruoho     {
    172       1.1    jruoho         return_ACPI_STATUS (AE_BAD_PARAMETER);
    173       1.1    jruoho     }
    174       1.1    jruoho 
    175       1.1    jruoho     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
    176       1.1    jruoho     if (ACPI_FAILURE (Status))
    177       1.1    jruoho     {
    178       1.1    jruoho         return_ACPI_STATUS (Status);
    179       1.1    jruoho     }
    180       1.1    jruoho 
    181       1.1    jruoho     /* Convert and validate the device handle */
    182       1.1    jruoho 
    183       1.1    jruoho     Node = AcpiNsValidateHandle (Device);
    184       1.1    jruoho     if (!Node ||
    185       1.1    jruoho         ((Node->Type != ACPI_TYPE_DEVICE)    &&
    186       1.1    jruoho          (Node->Type != ACPI_TYPE_PROCESSOR) &&
    187       1.1    jruoho          (Node->Type != ACPI_TYPE_THERMAL)   &&
    188       1.1    jruoho          (Node != AcpiGbl_RootNode)))
    189       1.1    jruoho     {
    190       1.1    jruoho         Status = AE_BAD_PARAMETER;
    191       1.1    jruoho         goto UnlockAndExit;
    192       1.1    jruoho     }
    193       1.1    jruoho 
    194       1.1    jruoho     /* Make sure the internal object exists */
    195       1.1    jruoho 
    196       1.1    jruoho     ObjDesc = AcpiNsGetAttachedObject (Node);
    197       1.1    jruoho     if (!ObjDesc)
    198       1.1    jruoho     {
    199       1.1    jruoho         Status = AE_NOT_EXIST;
    200       1.1    jruoho         goto UnlockAndExit;
    201       1.1    jruoho     }
    202       1.1    jruoho 
    203       1.1    jruoho     /* Find the address handler the user requested */
    204       1.1    jruoho 
    205   1.1.1.7  christos     HandlerObj = ObjDesc->CommonNotify.Handler;
    206   1.1.1.7  christos     LastObjPtr = &ObjDesc->CommonNotify.Handler;
    207       1.1    jruoho     while (HandlerObj)
    208       1.1    jruoho     {
    209       1.1    jruoho         /* We have a handler, see if user requested this one */
    210       1.1    jruoho 
    211       1.1    jruoho         if (HandlerObj->AddressSpace.SpaceId == SpaceId)
    212       1.1    jruoho         {
    213       1.1    jruoho             /* Handler must be the same as the installed handler */
    214       1.1    jruoho 
    215       1.1    jruoho             if (HandlerObj->AddressSpace.Handler != Handler)
    216       1.1    jruoho             {
    217       1.1    jruoho                 Status = AE_BAD_PARAMETER;
    218       1.1    jruoho                 goto UnlockAndExit;
    219       1.1    jruoho             }
    220       1.1    jruoho 
    221       1.1    jruoho             /* Matched SpaceId, first dereference this in the Regions */
    222       1.1    jruoho 
    223       1.1    jruoho             ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
    224       1.1    jruoho                 "Removing address handler %p(%p) for region %s "
    225       1.1    jruoho                 "on Device %p(%p)\n",
    226       1.1    jruoho                 HandlerObj, Handler, AcpiUtGetRegionName (SpaceId),
    227       1.1    jruoho                 Node, ObjDesc));
    228       1.1    jruoho 
    229       1.1    jruoho             RegionObj = HandlerObj->AddressSpace.RegionList;
    230       1.1    jruoho 
    231       1.1    jruoho             /* Walk the handler's region list */
    232       1.1    jruoho 
    233       1.1    jruoho             while (RegionObj)
    234       1.1    jruoho             {
    235       1.1    jruoho                 /*
    236       1.1    jruoho                  * First disassociate the handler from the region.
    237       1.1    jruoho                  *
    238       1.1    jruoho                  * NOTE: this doesn't mean that the region goes away
    239       1.1    jruoho                  * The region is just inaccessible as indicated to
    240       1.1    jruoho                  * the _REG method
    241       1.1    jruoho                  */
    242       1.1    jruoho                 AcpiEvDetachRegion (RegionObj, TRUE);
    243       1.1    jruoho 
    244       1.1    jruoho                 /*
    245       1.1    jruoho                  * Walk the list: Just grab the head because the
    246       1.1    jruoho                  * DetachRegion removed the previous head.
    247       1.1    jruoho                  */
    248       1.1    jruoho                 RegionObj = HandlerObj->AddressSpace.RegionList;
    249       1.1    jruoho             }
    250       1.1    jruoho 
    251       1.1    jruoho             /* Remove this Handler object from the list */
    252       1.1    jruoho 
    253       1.1    jruoho             *LastObjPtr = HandlerObj->AddressSpace.Next;
    254       1.1    jruoho 
    255       1.1    jruoho             /* Now we can delete the handler object */
    256       1.1    jruoho 
    257  1.1.1.13  christos             AcpiOsReleaseMutex (HandlerObj->AddressSpace.ContextMutex);
    258       1.1    jruoho             AcpiUtRemoveReference (HandlerObj);
    259       1.1    jruoho             goto UnlockAndExit;
    260       1.1    jruoho         }
    261       1.1    jruoho 
    262       1.1    jruoho         /* Walk the linked list of handlers */
    263       1.1    jruoho 
    264       1.1    jruoho         LastObjPtr = &HandlerObj->AddressSpace.Next;
    265       1.1    jruoho         HandlerObj = HandlerObj->AddressSpace.Next;
    266       1.1    jruoho     }
    267       1.1    jruoho 
    268       1.1    jruoho     /* The handler does not exist */
    269       1.1    jruoho 
    270       1.1    jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_OPREGION,
    271       1.1    jruoho         "Unable to remove address handler %p for %s(%X), DevNode %p, obj %p\n",
    272       1.1    jruoho         Handler, AcpiUtGetRegionName (SpaceId), SpaceId, Node, ObjDesc));
    273       1.1    jruoho 
    274       1.1    jruoho     Status = AE_NOT_EXIST;
    275       1.1    jruoho 
    276       1.1    jruoho UnlockAndExit:
    277       1.1    jruoho     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
    278       1.1    jruoho     return_ACPI_STATUS (Status);
    279       1.1    jruoho }
    280       1.1    jruoho 
    281       1.1    jruoho ACPI_EXPORT_SYMBOL (AcpiRemoveAddressSpaceHandler)
    282