ReactOS  0.4.14-dev-297-g23e575c
evgpeinit.c File Reference
#include "acpi.h"
#include "accommon.h"
#include "acevents.h"
#include "acnamesp.h"
Include dependency graph for evgpeinit.c:

Go to the source code of this file.

Macros

#define _COMPONENT   ACPI_EVENTS
 

Functions

ACPI_STATUS AcpiEvGpeInitialize (void)
 
void AcpiEvUpdateGpes (ACPI_OWNER_ID TableOwnerId)
 
ACPI_STATUS AcpiEvMatchGpeMethod (ACPI_HANDLE ObjHandle, UINT32 Level, void *Context, void **ReturnValue)
 

Macro Definition Documentation

◆ _COMPONENT

#define _COMPONENT   ACPI_EVENTS

Definition at line 49 of file evgpeinit.c.

Function Documentation

◆ AcpiEvGpeInitialize()

ACPI_STATUS AcpiEvGpeInitialize ( void  )

Definition at line 84 of file evgpeinit.c.

86 {
87  UINT32 RegisterCount0 = 0;
88  UINT32 RegisterCount1 = 0;
89  UINT32 GpeNumberMax = 0;
91 
92 
93  ACPI_FUNCTION_TRACE (EvGpeInitialize);
94 
95 
97  "Initializing General Purpose Events (GPEs):\n"));
98 
100  if (ACPI_FAILURE (Status))
101  {
103  }
104 
105  /*
106  * Initialize the GPE Block(s) defined in the FADT
107  *
108  * Why the GPE register block lengths are divided by 2: From the ACPI
109  * Spec, section "General-Purpose Event Registers", we have:
110  *
111  * "Each register block contains two registers of equal length
112  * GPEx_STS and GPEx_EN (where x is 0 or 1). The length of the
113  * GPE0_STS and GPE0_EN registers is equal to half the GPE0_LEN
114  * The length of the GPE1_STS and GPE1_EN registers is equal to
115  * half the GPE1_LEN. If a generic register block is not supported
116  * then its respective block pointer and block length values in the
117  * FADT table contain zeros. The GPE0_LEN and GPE1_LEN do not need
118  * to be the same size."
119  */
120 
121  /*
122  * Determine the maximum GPE number for this machine.
123  *
124  * Note: both GPE0 and GPE1 are optional, and either can exist without
125  * the other.
126  *
127  * If EITHER the register length OR the block address are zero, then that
128  * particular block is not supported.
129  */
130  if (AcpiGbl_FADT.Gpe0BlockLength &&
131  AcpiGbl_FADT.XGpe0Block.Address)
132  {
133  /* GPE block 0 exists (has both length and address > 0) */
134 
135  RegisterCount0 = (UINT16) (AcpiGbl_FADT.Gpe0BlockLength / 2);
136  GpeNumberMax = (RegisterCount0 * ACPI_GPE_REGISTER_WIDTH) - 1;
137 
138  /* Install GPE Block 0 */
139 
140  Status = AcpiEvCreateGpeBlock (AcpiGbl_FadtGpeDevice,
141  AcpiGbl_FADT.XGpe0Block.Address,
142  AcpiGbl_FADT.XGpe0Block.SpaceId,
143  RegisterCount0, 0,
144  AcpiGbl_FADT.SciInterrupt, &AcpiGbl_GpeFadtBlocks[0]);
145 
146  if (ACPI_FAILURE (Status))
147  {
149  "Could not create GPE Block 0"));
150  }
151  }
152 
153  if (AcpiGbl_FADT.Gpe1BlockLength &&
154  AcpiGbl_FADT.XGpe1Block.Address)
155  {
156  /* GPE block 1 exists (has both length and address > 0) */
157 
158  RegisterCount1 = (UINT16) (AcpiGbl_FADT.Gpe1BlockLength / 2);
159 
160  /* Check for GPE0/GPE1 overlap (if both banks exist) */
161 
162  if ((RegisterCount0) &&
163  (GpeNumberMax >= AcpiGbl_FADT.Gpe1Base))
164  {
166  "GPE0 block (GPE 0 to %u) overlaps the GPE1 block "
167  "(GPE %u to %u) - Ignoring GPE1",
168  GpeNumberMax, AcpiGbl_FADT.Gpe1Base,
169  AcpiGbl_FADT.Gpe1Base +
170  ((RegisterCount1 * ACPI_GPE_REGISTER_WIDTH) - 1)));
171 
172  /* Ignore GPE1 block by setting the register count to zero */
173 
174  RegisterCount1 = 0;
175  }
176  else
177  {
178  /* Install GPE Block 1 */
179 
180  Status = AcpiEvCreateGpeBlock (AcpiGbl_FadtGpeDevice,
181  AcpiGbl_FADT.XGpe1Block.Address,
182  AcpiGbl_FADT.XGpe1Block.SpaceId,
183  RegisterCount1,
184  AcpiGbl_FADT.Gpe1Base,
185  AcpiGbl_FADT.SciInterrupt, &AcpiGbl_GpeFadtBlocks[1]);
186 
187  if (ACPI_FAILURE (Status))
188  {
190  "Could not create GPE Block 1"));
191  }
192 
193  /*
194  * GPE0 and GPE1 do not have to be contiguous in the GPE number
195  * space. However, GPE0 always starts at GPE number zero.
196  */
197  GpeNumberMax = AcpiGbl_FADT.Gpe1Base +
198  ((RegisterCount1 * ACPI_GPE_REGISTER_WIDTH) - 1);
199  }
200  }
201 
202  /* Exit if there are no GPE registers */
203 
204  if ((RegisterCount0 + RegisterCount1) == 0)
205  {
206  /* GPEs are not required by ACPI, this is OK */
207 
209  "There are no GPE blocks defined in the FADT\n"));
210  Status = AE_OK;
211  goto Cleanup;
212  }
213 
214 
215 Cleanup:
218 }
#define ACPI_EXCEPTION(plist)
Definition: acoutput.h:239
#define ACPI_DEBUG_PRINT_RAW(pl)
Definition: acoutput.h:476
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
ACPI_STATUS AcpiEvCreateGpeBlock(ACPI_NAMESPACE_NODE *GpeDevice, UINT64 Address, UINT8 SpaceId, UINT32 RegisterCount, UINT16 GpeBlockBaseNumber, UINT32 InterruptNumber, ACPI_GPE_BLOCK_INFO **ReturnGpeBlock)
Definition: evgpeblk.c:367
UINT32 ACPI_STATUS
Definition: actypes.h:460
#define ACPI_FAILURE(a)
Definition: acexcep.h:95
ACPI_STATUS AcpiUtReleaseMutex(ACPI_MUTEX_HANDLE MutexId)
Definition: utmutex.c:348
ACPI_STATUS AcpiUtAcquireMutex(ACPI_MUTEX_HANDLE MutexId)
Definition: utmutex.c:256
unsigned int UINT32
#define AE_INFO
Definition: acoutput.h:230
#define ACPI_DEBUG_PRINT(pl)
Definition: acoutput.h:475
static const WCHAR Cleanup[]
Definition: register.c:80
Status
Definition: gdiplustypes.h:24
#define ACPI_DB_INIT
Definition: acoutput.h:151
#define return_ACPI_STATUS(s)
Definition: acoutput.h:496
#define ACPI_FUNCTION_TRACE(a)
Definition: acoutput.h:480
unsigned short UINT16
#define ACPI_ERROR(plist)
Definition: acoutput.h:240
#define ACPI_MTX_NAMESPACE
Definition: aclocal.h:85
#define ACPI_GPE_REGISTER_WIDTH
Definition: actypes.h:407
#define AE_OK
Definition: acexcep.h:97

Referenced by AcpiEvInitializeEvents().

◆ AcpiEvMatchGpeMethod()

ACPI_STATUS AcpiEvMatchGpeMethod ( ACPI_HANDLE  ObjHandle,
UINT32  Level,
void Context,
void **  ReturnValue 
)

Definition at line 330 of file evgpeinit.c.

335 {
336  ACPI_NAMESPACE_NODE *MethodNode = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, ObjHandle);
341  UINT8 TempGpeNumber;
342  char Name[ACPI_NAMESEG_SIZE + 1];
343  UINT8 Type;
344 
345 
346  ACPI_FUNCTION_TRACE (EvMatchGpeMethod);
347 
348 
349  /* Check if requested OwnerId matches this OwnerId */
350 
351  if ((WalkInfo->ExecuteByOwnerId) &&
352  (MethodNode->OwnerId != WalkInfo->OwnerId))
353  {
355  }
356 
357  /*
358  * Match and decode the _Lxx and _Exx GPE method names
359  *
360  * 1) Extract the method name and null terminate it
361  */
362  ACPI_MOVE_32_TO_32 (Name, &MethodNode->Name.Integer);
363  Name[ACPI_NAMESEG_SIZE] = 0;
364 
365  /* 2) Name must begin with an underscore */
366 
367  if (Name[0] != '_')
368  {
369  return_ACPI_STATUS (AE_OK); /* Ignore this method */
370  }
371 
372  /*
373  * 3) Edge/Level determination is based on the 2nd character
374  * of the method name
375  */
376  switch (Name[1])
377  {
378  case 'L':
379 
381  break;
382 
383  case 'E':
384 
386  break;
387 
388  default:
389 
390  /* Unknown method type, just ignore it */
391 
393  "Ignoring unknown GPE method type: %s "
394  "(name not of form _Lxx or _Exx)", Name));
396  }
397 
398  /* 4) The last two characters of the name are the hex GPE Number */
399 
400  Status = AcpiUtAsciiToHexByte (&Name[2], &TempGpeNumber);
401  if (ACPI_FAILURE (Status))
402  {
403  /* Conversion failed; invalid method, just ignore it */
404 
406  "Could not extract GPE number from name: %s "
407  "(name is not of form _Lxx or _Exx)", Name));
409  }
410 
411  /* Ensure that we have a valid GPE number for this GPE block */
412 
413  GpeNumber = (UINT32) TempGpeNumber;
415  if (!GpeEventInfo)
416  {
417  /*
418  * This GpeNumber is not valid for this GPE block, just ignore it.
419  * However, it may be valid for a different GPE block, since GPE0
420  * and GPE1 methods both appear under \_GPE.
421  */
423  }
424 
429  {
430  /* If there is already a handler, ignore this GPE method */
431 
433  }
434 
437  {
438  /*
439  * If there is already a method, ignore this method. But check
440  * for a type mismatch (if both the _Lxx AND _Exx exist)
441  */
443  {
445  "For GPE 0x%.2X, found both _L%2.2X and _E%2.2X methods",
447  }
449  }
450 
451  /* Disable the GPE in case it's been enabled already. */
452 
454 
455  /*
456  * Add the GPE information from above to the GpeEventInfo block for
457  * use during dispatch of this GPE.
458  */
461  GpeEventInfo->Dispatch.MethodNode = MethodNode;
462 
464  "Registered GPE method %s as GPE number 0x%.2X\n",
465  Name, GpeNumber));
467 }
UINT32 Integer
Definition: actbl.h:393
#define ACPI_DB_LOAD
Definition: acoutput.h:164
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
ACPI_OWNER_ID OwnerId
Definition: aclocal.h:614
Type
Definition: Type.h:6
#define ACPI_GPE_DISPATCH_TYPE(flags)
Definition: actypes.h:815
ACPI_GPE_EVENT_INFO * GpeEventInfo
Definition: acevents.h:195
ACPI_GPE_BLOCK_INFO * GpeBlock
Definition: aclocal.h:612
UINT32 ACPI_STATUS
Definition: actypes.h:460
#define ACPI_GPE_DISPATCH_RAW_HANDLER
Definition: actypes.h:813
#define ACPI_FAILURE(a)
Definition: acexcep.h:95
unsigned int UINT32
union acpi_gpe_dispatch_info Dispatch
Definition: aclocal.h:554
#define ACPI_GPE_DISPATCH_HANDLER
Definition: actypes.h:811
ACPI_GPE_EVENT_INFO * AcpiEvLowGetGpeInfo(UINT32 GpeNumber, ACPI_GPE_BLOCK_INFO *GpeBlock)
Definition: evgpe.c:327
#define ACPI_GPE_DISPATCH_METHOD
Definition: actypes.h:810
#define AE_INFO
Definition: acoutput.h:230
ACPI_NAME_UNION Name
Definition: aclocal.h:191
BOOLEAN ExecuteByOwnerId
Definition: aclocal.h:615
#define ACPI_GPE_XRUPT_TYPE_MASK
Definition: actypes.h:819
#define ACPI_DEBUG_PRINT(pl)
Definition: acoutput.h:475
ACPI_OWNER_ID OwnerId
Definition: aclocal.h:195
#define ACPI_GPE_LEVEL_TRIGGERED
Definition: actypes.h:817
ACPI_GPE_EVENT_INFO UINT32 GpeNumber
Definition: acevents.h:195
#define ACPI_MOVE_32_TO_32(d, s)
Definition: acmacros.h:148
#define ACPI_GPE_DISPATCH_MASK
Definition: actypes.h:814
Status
Definition: gdiplustypes.h:24
#define return_ACPI_STATUS(s)
Definition: acoutput.h:496
#define ACPI_FUNCTION_TRACE(a)
Definition: acoutput.h:480
ACPI_STATUS AcpiUtAsciiToHexByte(char *TwoAsciiChars, UINT8 *ReturnByte)
Definition: uthex.c:100
#define ACPI_ERROR(plist)
Definition: acoutput.h:240
#define ACPI_GPE_DISABLE
Definition: actypes.h:794
#define ACPI_GPE_EDGE_TRIGGERED
Definition: actypes.h:818
ACPI_NAMESPACE_NODE * MethodNode
Definition: aclocal.h:542
#define ACPI_NAMESEG_SIZE
Definition: actypes.h:415
#define ACPI_CAST_PTR(t, p)
Definition: actypes.h:544
unsigned char UINT8
#define AE_OK
Definition: acexcep.h:97
ACPI_STATUS AcpiHwLowSetGpe(ACPI_GPE_EVENT_INFO *GpeEventInfo, UINT32 Action)
Definition: hwgpe.c:106

Referenced by AcpiEvCreateGpeBlock(), and AcpiEvUpdateGpes().

◆ AcpiEvUpdateGpes()

void AcpiEvUpdateGpes ( ACPI_OWNER_ID  TableOwnerId)

Definition at line 236 of file evgpeinit.c.

238 {
239  ACPI_GPE_XRUPT_INFO *GpeXruptInfo;
240  ACPI_GPE_BLOCK_INFO *GpeBlock;
241  ACPI_GPE_WALK_INFO WalkInfo;
243 
244 
245  /*
246  * Find any _Lxx/_Exx GPE methods that have just been loaded.
247  *
248  * Any GPEs that correspond to new _Lxx/_Exx methods are immediately
249  * enabled.
250  *
251  * Examine the namespace underneath each GpeDevice within the
252  * GpeBlock lists.
253  */
255  if (ACPI_FAILURE (Status))
256  {
257  return;
258  }
259 
260  WalkInfo.Count = 0;
261  WalkInfo.OwnerId = TableOwnerId;
262  WalkInfo.ExecuteByOwnerId = TRUE;
263 
264  /* Walk the interrupt level descriptor list */
265 
266  GpeXruptInfo = AcpiGbl_GpeXruptListHead;
267  while (GpeXruptInfo)
268  {
269  /* Walk all Gpe Blocks attached to this interrupt level */
270 
271  GpeBlock = GpeXruptInfo->GpeBlockListHead;
272  while (GpeBlock)
273  {
274  WalkInfo.GpeBlock = GpeBlock;
275  WalkInfo.GpeDevice = GpeBlock->Node;
276 
278  WalkInfo.GpeDevice, ACPI_UINT32_MAX,
280  NULL, &WalkInfo, NULL);
281  if (ACPI_FAILURE (Status))
282  {
284  "While decoding _Lxx/_Exx methods"));
285  }
286 
287  GpeBlock = GpeBlock->Next;
288  }
289 
290  GpeXruptInfo = GpeXruptInfo->Next;
291  }
292 
293  if (WalkInfo.Count)
294  {
295  ACPI_INFO (("Enabled %u new GPEs", WalkInfo.Count));
296  }
297 
299  return;
300 }
#define ACPI_EXCEPTION(plist)
Definition: acoutput.h:239
struct acpi_gpe_block_info * Next
Definition: aclocal.h:585
#define TRUE
Definition: types.h:120
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
ACPI_OWNER_ID OwnerId
Definition: aclocal.h:614
struct acpi_gpe_xrupt_info * Next
Definition: aclocal.h:603
ACPI_GPE_BLOCK_INFO * GpeBlock
Definition: aclocal.h:612
#define ACPI_NS_WALK_NO_UNLOCK
Definition: acnamesp.h:76
UINT32 ACPI_STATUS
Definition: actypes.h:460
ACPI_STATUS AcpiNsWalkNamespace(ACPI_OBJECT_TYPE Type, ACPI_HANDLE StartObject, UINT32 MaxDepth, UINT32 Flags, ACPI_WALK_CALLBACK DescendingCallback, ACPI_WALK_CALLBACK AscendingCallback, void *Context, void **ReturnValue)
Definition: nswalk.c:190
#define ACPI_FAILURE(a)
Definition: acexcep.h:95
ACPI_STATUS AcpiUtReleaseMutex(ACPI_MUTEX_HANDLE MutexId)
Definition: utmutex.c:348
ACPI_STATUS AcpiUtAcquireMutex(ACPI_MUTEX_HANDLE MutexId)
Definition: utmutex.c:256
#define AE_INFO
Definition: acoutput.h:230
smooth NULL
Definition: ftsmooth.c:416
ACPI_NAMESPACE_NODE * GpeDevice
Definition: aclocal.h:611
#define ACPI_TYPE_METHOD
Definition: actypes.h:686
BOOLEAN ExecuteByOwnerId
Definition: aclocal.h:615
#define ACPI_UINT32_MAX
Definition: actypes.h:66
ACPI_GPE_BLOCK_INFO * GpeBlockListHead
Definition: aclocal.h:604
#define ACPI_INFO(plist)
Definition: acoutput.h:237
Status
Definition: gdiplustypes.h:24
#define ACPI_MTX_EVENTS
Definition: aclocal.h:87
ACPI_STATUS AcpiEvMatchGpeMethod(ACPI_HANDLE ObjHandle, UINT32 Level, void *Context, void **ReturnValue)
Definition: evgpeinit.c:330
#define AE_OK
Definition: acexcep.h:97
ACPI_NAMESPACE_NODE * Node
Definition: aclocal.h:583

Referenced by AcpiTbLoadTable().