1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/zsl588-OpenCorePkg

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Клонировать/Скачать
AcpiParser.c 48 КБ
Копировать Редактировать Исходные данные Просмотреть построчно История
vit9696 Отправлено 4 лет назад 1864609
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047
/** @file
Copyright (c) 2020-2021, Ubsefor & koralexa. All rights reserved.
Copyright (c) 2021, vit9696. All rights reserved.
SPDX-License-Identifier: BSD-3-Clause
**/
#include <Uefi.h>
#include <IndustryStandard/Acpi62.h>
#include <Library/OcAcpiLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiLib.h>
#include <Library/UefiApplicationEntryPoint.h>
#include <Library/UefiBootServicesTableLib.h>
#include <IndustryStandard/AcpiAml.h>
#include "AcpiParser.h"
/**
Parses identifier or path (several identifiers). Returns info about
the identifier / path if necessary.
@param[in, out] Context Structure containing the parser context.
@param[in, out] NamePathStart Pointer to first opcode of identifier / path.
@param[in, out] PathLength Quantity of identifiers in path.
@param[in, out] IsRootPath 1 if parsed path was a root path, 0 otherwise.
@retval EFI_SUCCESS Name was parsed successfuly.
@retval EFI_DEVICE_ERROR Error occured during parsing.
@retval EFI_OUT_OF_RESOURCES Nesting limit has been reached.
**/
STATIC
EFI_STATUS
ParseNameString (
IN OUT ACPI_PARSER_CONTEXT *Context,
IN OUT UINT8 **NamePathStart OPTIONAL,
IN OUT UINT8 *PathLength OPTIONAL,
IN OUT UINT8 *IsRootPath OPTIONAL
)
{
CONTEXT_ENTER (Context, "NameString");
CONTEXT_HAS_WORK (Context);
CONTEXT_INCREASE_NESTING (Context);
if (IsRootPath != NULL) {
*IsRootPath = 0;
}
while (Context->CurrentOpcode[0] == AML_ROOT_CHAR || Context->CurrentOpcode[0] == AML_PARENT_PREFIX_CHAR) {
if (Context->CurrentOpcode[0] == AML_ROOT_CHAR && IsRootPath != NULL) {
*IsRootPath = 1;
}
CONTEXT_ADVANCE_OPCODE (Context);
}
switch (Context->CurrentOpcode[0]) {
case AML_ZERO_OP:
if (NamePathStart != NULL) {
*PathLength = 0;
*NamePathStart = NULL;
}
Context->CurrentOpcode += 1;
break;
case AML_DUAL_NAME_PREFIX:
CONTEXT_ADVANCE_OPCODE (Context);
CONTEXT_PEEK_BYTES (Context, 2 * IDENT_LEN);
if (NamePathStart != NULL) {
*PathLength = 2;
*NamePathStart = Context->CurrentOpcode;
}
Context->CurrentOpcode += 2 * IDENT_LEN;
break;
case AML_MULTI_NAME_PREFIX:
CONTEXT_ADVANCE_OPCODE (Context);
CONTEXT_PEEK_BYTES (Context, 1 + Context->CurrentOpcode[0] * IDENT_LEN);
if (NamePathStart != NULL) {
*PathLength = Context->CurrentOpcode[0];
*NamePathStart = Context->CurrentOpcode + 1;
}
Context->CurrentOpcode += 1 + Context->CurrentOpcode[0] * IDENT_LEN;
break;
default:
CONTEXT_PEEK_BYTES (Context, IDENT_LEN);
if (NamePathStart != NULL) {
*PathLength = 1;
*NamePathStart = Context->CurrentOpcode;
}
Context->CurrentOpcode += IDENT_LEN;
}
if (NamePathStart != NULL) {
PRINT_ACPI_NAME ("Read name", *NamePathStart, *PathLength);
}
CONTEXT_DECREASE_NESTING (Context);
return EFI_SUCCESS;
}
/**
Parses package length (length of current section).
@param[in, out] Context Structure containing the parser context.
@param[out] PkgLength Total length of section.
@retval EFI_SUCCESS Length was parsed successfuly.
@retval EFI_DEVICE_ERROR Error occured during parsing length.
@retval EFI_OUT_OF_RESOURCES Nesting limit has been reached.
**/
STATIC
EFI_STATUS
ParsePkgLength (
IN OUT ACPI_PARSER_CONTEXT *Context,
OUT UINT32 *PkgLength
)
{
UINT8 LeadByte;
UINT8 ByteCount;
UINT32 TotalSize;
UINT32 Index;
CONTEXT_ENTER (Context, "PkgLength");
CONTEXT_HAS_WORK (Context);
CONTEXT_INCREASE_NESTING (Context);
LeadByte = Context->CurrentOpcode[0];
TotalSize = 0;
ByteCount = (LeadByte & 0xC0) >> 6;
CONTEXT_CONSUME_BYTES (Context, 1);
if (ByteCount > 0) {
CONTEXT_PEEK_BYTES (Context, ByteCount);
for (Index = 0; Index < ByteCount; Index++) {
TotalSize |= (UINT32) Context->CurrentOpcode[Index] << (Index * 8U + 4);
}
TotalSize |= LeadByte & 0x0F;
*PkgLength = TotalSize;
CONTEXT_CONSUME_BYTES (Context, ByteCount);
} else {
*PkgLength = (UINT32) LeadByte;
}
CONTEXT_DECREASE_NESTING (Context);
return EFI_SUCCESS;
}
/**
Parses alias section to skip it correctly.
@param[in, out] Context Structure containing the parser context.
@retval EFI_NOT_FOUND Alias was parsed and skipped successfuly.
@retval EFI_DEVICE_ERROR Error occured during parsing alias.
@retval EFI_OUT_OF_RESOURCES Nesting limit has been reached.
**/
STATIC
EFI_STATUS
ParseAlias (
IN OUT ACPI_PARSER_CONTEXT *Context
)
{
CONTEXT_ENTER (Context, "Alias");
CONTEXT_HAS_WORK (Context);
CONTEXT_INCREASE_NESTING (Context);
if (ParseNameString (
Context,
NULL,
NULL,
NULL
) != EFI_SUCCESS) {
return EFI_DEVICE_ERROR;
}
CONTEXT_PEEK_BYTES (Context, 1);
if (ParseNameString (
Context,
NULL,
NULL,
NULL
) != EFI_SUCCESS) {
return EFI_DEVICE_ERROR;
}
CONTEXT_DECREASE_NESTING (Context);
return EFI_NOT_FOUND;
}
/**
Parses scope or device section. In case it's name is suitable parses
elements inside it, or returns pointer to it's opcode if this scope / device
was sought. Otherwise skips this section.
@param[in, out] Context Structure containing the parser context.
@param[out] Result Pointer to sought opcode if required entry was found.
@retval EFI_SUCCESS Required entry was found.
@retval EFI_NOT_FOUND Scope / device was parsed and skipped successfuly.
@retval EFI_DEVICE_ERROR Error occured during parsing scope / device.
@retval EFI_OUT_OF_RESOURCES Nesting limit has been reached.
**/
STATIC
EFI_STATUS
ParseScopeOrDevice (
IN OUT ACPI_PARSER_CONTEXT *Context,
OUT UINT8 **Result
)
{
UINT32 PkgLength;
UINT8 *ScopeStart;
UINT32 *CurrentPath;
UINT8 *ScopeEnd;
UINT8 *ScopeName;
UINT8 *ScopeNameStart;
UINT8 ScopeNameLength;
UINT8 IsRootPath;
EFI_STATUS Status;
UINT8 Index;
UINT8 Index2;
BOOLEAN Breakout;
CONTEXT_ENTER (Context, "Scope / Device");
CONTEXT_HAS_WORK (Context);
CONTEXT_INCREASE_NESTING (Context);
ScopeStart = Context->CurrentOpcode;
CurrentPath = Context->CurrentIdentifier;
if (ParsePkgLength (
Context,
&PkgLength
) != EFI_SUCCESS) {
return EFI_DEVICE_ERROR;
}
if ((UINT32) (Context->TableEnd - ScopeStart) < PkgLength) {
return EFI_DEVICE_ERROR;
}
ScopeEnd = ScopeStart + PkgLength;
CONTEXT_PEEK_BYTES (Context, 1);
if (ParseNameString (
Context,
&ScopeName,
&ScopeNameLength,
&IsRootPath
) != EFI_SUCCESS) {
return EFI_DEVICE_ERROR;
}
ScopeNameStart = ScopeName;
if (Context->CurrentOpcode > ScopeEnd) {
return EFI_DEVICE_ERROR;
}
if (IsRootPath) {
Context->CurrentIdentifier = Context->PathStart;
}
//
// Both exit conditions in these loops are for cases when there can be
// root-relative scopes within the current scope that does not match ours at all.
//
Breakout = FALSE;
for (Index = 0; Index < ScopeNameLength; ++Index) {
if (Context->CurrentIdentifier == Context->PathEnd) {
Context->CurrentIdentifier = Context->PathStart;
break;
}
for (Index2 = 0; Index2 < IDENT_LEN; ++Index2) {
if (*(ScopeName + Index2) != *((UINT8 *)Context->CurrentIdentifier + (IDENT_LEN - Index2 - 1))) {
Context->CurrentIdentifier = Context->PathStart;
Breakout = TRUE;
break;
}
}
if (Breakout) {
break;
}
Context->CurrentIdentifier += 1;
ScopeName += 4;
}
if (Context->CurrentIdentifier == Context->PathEnd) {
Context->EntriesFound += 1;
if (Context->EntriesFound == Context->RequiredEntry) {
*Result = ScopeStart - 1;
return EFI_SUCCESS;
}
//
// Same issue with root-relative scopes. Retry search.
//
Context->CurrentIdentifier = Context->PathStart;
}
PRINT_ACPI_NAME ("Entered scope", ScopeNameStart, ScopeNameLength);
while (Context->CurrentOpcode < ScopeEnd) {
Status = InternalAcpiParseTerm (
Context,
Result
);
if (Status != EFI_NOT_FOUND) {
return Status;
}
}
PRINT_ACPI_NAME ("Left scope", ScopeNameStart, ScopeNameLength);
Context->CurrentIdentifier = CurrentPath;
CONTEXT_DECREASE_NESTING (Context);
return EFI_NOT_FOUND;
}
/**
Parses name section to correctly skip it.
@param[in, out] Context Structure containing the parser context.
@retval EFI_NOT_FOUND Name was parsed and skipped successfuly.
@retval EFI_DEVICE_ERROR Error occured during parsing name.
@retval EFI_OUT_OF_RESOURCES Nesting limit has been reached.
**/
STATIC
EFI_STATUS
ParseName (
IN OUT ACPI_PARSER_CONTEXT *Context
)
{
UINT32 PkgLength;
UINT8 *CurrentOpcode;
CONTEXT_ENTER (Context, "Name");
CONTEXT_HAS_WORK (Context);
CONTEXT_INCREASE_NESTING (Context);
if (ParseNameString (
Context,
NULL,
NULL,
NULL
) != EFI_SUCCESS) {
return EFI_DEVICE_ERROR;
}
CONTEXT_PEEK_BYTES (Context, 1);
switch (Context->CurrentOpcode[0]) {
case AML_BYTE_PREFIX:
CONTEXT_CONSUME_BYTES (Context, 2);
break;
case AML_WORD_PREFIX:
CONTEXT_CONSUME_BYTES (Context, 3);
break;
case AML_DWORD_PREFIX:
CONTEXT_CONSUME_BYTES (Context, 5);
break;
case AML_QWORD_PREFIX:
CONTEXT_CONSUME_BYTES (Context, 9);
break;
case AML_STRING_PREFIX:
do {
CONTEXT_ADVANCE_OPCODE (Context);
} while (Context->CurrentOpcode[0] >= 0x01 && Context->CurrentOpcode[0] <= 0x7f);
if (Context->CurrentOpcode[0] != AML_ZERO_OP) {
return EFI_DEVICE_ERROR;
}
CONTEXT_CONSUME_BYTES (Context, 1);
break;
case AML_ZERO_OP:
case AML_ONE_OP:
case AML_ONES_OP:
CONTEXT_CONSUME_BYTES (Context, 1);
break;
case AML_EXT_OP:
CONTEXT_CONSUME_BYTES (Context, 2);
break;
case AML_BUFFER_OP:
case AML_PACKAGE_OP:
case AML_VAR_PACKAGE_OP:
CONTEXT_ADVANCE_OPCODE (Context);
CurrentOpcode = Context->CurrentOpcode;
if (ParsePkgLength (
Context,
&PkgLength
) != EFI_SUCCESS) {
return EFI_DEVICE_ERROR;
}
Context->CurrentOpcode = CurrentOpcode;
CONTEXT_CONSUME_BYTES (Context, PkgLength);
break;
default:
return EFI_DEVICE_ERROR;
}
CONTEXT_DECREASE_NESTING (Context);
return EFI_NOT_FOUND;
}
/**
Parses bank field section. In case it's name is suitable returns
pointer to it's opcode. Otherwise skips this section.
@param[in, out] Context Structure containing the parser context.
@param[out] Result Pointer to sought opcode if required entry was found.
@retval EFI_SUCCESS Required entry was found.
@retval EFI_NOT_FOUND Bank field was parsed and skipped successfuly.
@retval EFI_DEVICE_ERROR Error occured during parsing bank field.
@retval EFI_OUT_OF_RESOURCES Nesting limit has been reached.
**/
STATIC
EFI_STATUS
ParseBankField (
IN OUT ACPI_PARSER_CONTEXT *Context,
OUT UINT8 **Result
)
{
UINT32 PkgLength;
UINT8 *BankStart;
UINT8 *BankEnd;
UINT8 *Name;
UINT8 NameLength;
UINT8 Index;
CONTEXT_ENTER (Context, "BankField");
CONTEXT_HAS_WORK (Context);
CONTEXT_INCREASE_NESTING (Context);
BankStart = Context->CurrentOpcode;
if (ParsePkgLength (
Context,
&PkgLength
) != EFI_SUCCESS) {
return EFI_DEVICE_ERROR;
}
if ((UINT32) (Context->TableEnd - BankStart) < PkgLength) {
return EFI_DEVICE_ERROR;
}
BankEnd = BankStart + PkgLength;
CONTEXT_PEEK_BYTES (Context, 1);
if (ParseNameString (
Context,
&Name,
&NameLength,
NULL
) != EFI_SUCCESS) {
return EFI_DEVICE_ERROR;
}
if (Context->CurrentOpcode >= BankEnd) {
return EFI_DEVICE_ERROR;
}
if (NameLength != 1) {
return EFI_DEVICE_ERROR;
}
for (Index = 0; Index < IDENT_LEN; ++Index) {
if (*(Name + Index) != *((UINT8 *)Context->CurrentIdentifier + (IDENT_LEN - Index - 1))) {
Context->CurrentOpcode = BankEnd;
CONTEXT_DECREASE_NESTING (Context);
return EFI_NOT_FOUND;
}
}
Context->CurrentIdentifier += 1;
CONTEXT_PEEK_BYTES (Context, 1);
if (Context->CurrentIdentifier == Context->PathEnd) {
//
// FIXME: This looks weird. If it is a match, should not it return success?
//
Context->CurrentIdentifier -= 1;
if (ParseNameString (
Context,
&Name,
&NameLength,
NULL
) != EFI_SUCCESS) {
return EFI_DEVICE_ERROR;
}
Context->CurrentOpcode = BankEnd;
CONTEXT_DECREASE_NESTING (Context);
return EFI_NOT_FOUND;
}
if (ParseNameString (
Context,
&Name,
&NameLength,
NULL
) != EFI_SUCCESS) {
return EFI_DEVICE_ERROR;
}
if (Context->CurrentOpcode > BankEnd) {
return EFI_DEVICE_ERROR;
}
if (NameLength != 1) {
return EFI_DEVICE_ERROR;
}
for (Index = 0; Index < IDENT_LEN; ++Index) {
if (*(Name + Index) != *((UINT8 *)Context->CurrentIdentifier + (IDENT_LEN - Index - 1))) {
Context->CurrentOpcode = BankEnd;
Context->CurrentIdentifier -= 1;
CONTEXT_DECREASE_NESTING (Context);
return EFI_NOT_FOUND;
}
}
if (Context->CurrentIdentifier + 1 != Context->PathEnd) {
Context->CurrentOpcode = BankEnd;
Context->CurrentIdentifier -= 1;
CONTEXT_DECREASE_NESTING (Context);
return EFI_NOT_FOUND;
}
Context->EntriesFound += 1;
if (Context->EntriesFound != Context->RequiredEntry) {
Context->CurrentOpcode = BankEnd;
Context->CurrentIdentifier -= 1;
CONTEXT_DECREASE_NESTING (Context);
return EFI_NOT_FOUND;
}
*Result = BankStart - 1;
return EFI_SUCCESS;
}
/**
Parses create field section (any of CreateDwordField, CreateWordField,
CreateByteField, CreateBitField, CreateQWordField, CreateField sections).
In case it's name is suitable returns pointer to it's opcode.
Otherwise skips this section.
@param[in, out] Context Structure containing the parser context.
@param[out] Result Pointer to sought opcode if required entry was found.
@retval EFI_SUCCESS Required entry was found.
@retval EFI_NOT_FOUND Field was parsed and skipped successfuly.
@retval EFI_DEVICE_ERROR Error occured during parsing field.
@retval EFI_OUT_OF_RESOURCES Nesting limit has been reached.
**/
STATIC
EFI_STATUS
ParseCreateField (
IN OUT ACPI_PARSER_CONTEXT *Context,
OUT UINT8 **Result
)
{
UINT8 *FieldStart;
UINT8 *FieldOpcode;
UINT8 *Name;
UINT8 NameLength;
UINT8 Index;
BOOLEAN Matched;
CONTEXT_ENTER (Context, "CreateField");
CONTEXT_HAS_WORK (Context);
CONTEXT_INCREASE_NESTING (Context);
FieldStart = Context->CurrentOpcode;
FieldOpcode = Context->CurrentOpcode - 1;
switch (Context->CurrentOpcode[0]) {
case AML_ARG0:
case AML_ARG1:
case AML_ARG2:
case AML_ARG3:
case AML_ARG4:
case AML_ARG5:
case AML_ARG6:
CONTEXT_CONSUME_BYTES (Context, 5);
if (*FieldOpcode == AML_EXT_CREATE_FIELD_OP) {
CONTEXT_CONSUME_BYTES (Context, 4);
}
CONTEXT_PEEK_BYTES (Context, 1);
if (ParseNameString (
Context,
NULL,
NULL,
NULL
) != EFI_SUCCESS) {
return EFI_DEVICE_ERROR;
}
CONTEXT_DECREASE_NESTING (Context);
return EFI_NOT_FOUND;
default:
if (ParseNameString (
Context,
&Name,
&NameLength,
NULL
) != EFI_SUCCESS) {
return EFI_DEVICE_ERROR;
}
if (NameLength != 1) {
return EFI_DEVICE_ERROR;
}
Matched = TRUE;
for (Index = 0; Index < IDENT_LEN; Index++) {
if (*(Name + Index) != *((UINT8 *)Context->CurrentIdentifier + (IDENT_LEN - Index - 1))) {
Matched = FALSE;
break;
}
}
CONTEXT_PEEK_BYTES (Context, 1);
switch (Context->CurrentOpcode[0]) {
case AML_ZERO_OP:
case AML_ONE_OP:
CONTEXT_CONSUME_BYTES (Context, 1);
break;
case AML_BYTE_PREFIX:
CONTEXT_CONSUME_BYTES (Context, 2);
break;
case AML_WORD_PREFIX:
CONTEXT_CONSUME_BYTES (Context, 3);
break;
case AML_DWORD_PREFIX:
CONTEXT_CONSUME_BYTES (Context, 5);
break;
case AML_QWORD_PREFIX:
CONTEXT_CONSUME_BYTES (Context, 9);
break;
}
if (*FieldOpcode == AML_EXT_CREATE_FIELD_OP) {
CONTEXT_CONSUME_BYTES (Context, 1);
}
CONTEXT_PEEK_BYTES (Context, 1);
if (ParseNameString (
Context,
&Name,
&NameLength,
NULL
) != EFI_SUCCESS) {
return EFI_DEVICE_ERROR;
}
if (NameLength != 1) {
return EFI_DEVICE_ERROR;
}
if (!Matched) {
CONTEXT_DECREASE_NESTING (Context);
return EFI_NOT_FOUND;
}
Context->CurrentIdentifier += 1;
for (Index = 0; Index < IDENT_LEN; Index++) {
if (*(Name + Index) != *((UINT8 *)Context->CurrentIdentifier + (IDENT_LEN - Index - 1))) {
CONTEXT_DECREASE_NESTING (Context);
Context->CurrentIdentifier--;
return EFI_NOT_FOUND;
}
}
Context->CurrentIdentifier += 1;
if (Context->CurrentIdentifier != Context->PathEnd) {
CONTEXT_DECREASE_NESTING (Context);
Context->CurrentIdentifier -= 2;
return EFI_NOT_FOUND;
}
Context->EntriesFound += 1;
if (Context->EntriesFound != Context->RequiredEntry) {
CONTEXT_DECREASE_NESTING (Context);
Context->CurrentIdentifier -= 2;
return EFI_NOT_FOUND;
}
*Result = FieldStart - 1;
return EFI_SUCCESS;
}
}
/**
Parses external section to correctly skip it.
@param[in, out] Context Structure containing the parser context.
@retval EFI_NOT_FOUND External was parsed and skipped successfuly.
@retval EFI_DEVICE_ERROR Error occured during parsing external.
@retval EFI_OUT_OF_RESOURCES Nesting limit has been reached.
**/
STATIC
EFI_STATUS
ParseExternal (
IN OUT ACPI_PARSER_CONTEXT *Context
)
{
CONTEXT_ENTER (Context, "External");
CONTEXT_HAS_WORK (Context);
CONTEXT_INCREASE_NESTING (Context);
if (ParseNameString (
Context,
NULL,
NULL,
NULL
) != EFI_SUCCESS) {
return EFI_DEVICE_ERROR;
}
CONTEXT_CONSUME_BYTES (Context, 2);
CONTEXT_DECREASE_NESTING (Context);
return EFI_NOT_FOUND;
}
/**
Parses operation region to skip it correctly.
@param[in, out] Context Structure containing the parser context.
@retval EFI_NOT_FOUND OpRegion was parsed and skipped successfuly.
@retval EFI_DEVICE_ERROR Error occured during parsing OpRegion.
@retval EFI_OUT_OF_RESOURCES Nesting limit has been reached.
**/
STATIC
EFI_STATUS
ParseOpRegion (
IN OUT ACPI_PARSER_CONTEXT *Context
)
{
CONTEXT_ENTER (Context, "OpRegion");
CONTEXT_HAS_WORK (Context);
CONTEXT_INCREASE_NESTING (Context);
if (ParseNameString (
Context,
NULL,
NULL,
NULL
) != EFI_SUCCESS) {
return EFI_DEVICE_ERROR;
}
CONTEXT_ADVANCE_OPCODE (Context);
switch (Context->CurrentOpcode[0]) {
case AML_ZERO_OP:
case AML_ONE_OP:
CONTEXT_CONSUME_BYTES (Context, 1);
break;
case AML_BYTE_PREFIX:
CONTEXT_CONSUME_BYTES (Context, 2);
break;
case AML_WORD_PREFIX:
CONTEXT_CONSUME_BYTES (Context, 3);
break;
case AML_DWORD_PREFIX:
CONTEXT_CONSUME_BYTES (Context, 5);
break;
case AML_QWORD_PREFIX:
CONTEXT_CONSUME_BYTES (Context, 9);
break;
case AML_ADD_OP:
case AML_SUBTRACT_OP:
CONTEXT_ADVANCE_OPCODE (Context);
switch (Context->CurrentOpcode[0]) {
case AML_ZERO_OP:
case AML_ONE_OP:
CONTEXT_CONSUME_BYTES (Context, 1);
break;
case AML_BYTE_PREFIX:
CONTEXT_CONSUME_BYTES (Context, 2);
break;
case AML_WORD_PREFIX:
CONTEXT_CONSUME_BYTES (Context, 3);
break;
case AML_DWORD_PREFIX:
CONTEXT_CONSUME_BYTES (Context, 5);
break;
case AML_QWORD_PREFIX:
CONTEXT_CONSUME_BYTES (Context, 9);
break;
default:
if (ParseNameString (
Context,
NULL,
NULL,
NULL
) != EFI_SUCCESS) {
return EFI_DEVICE_ERROR;
}
break;
}
CONTEXT_PEEK_BYTES (Context, 1);
switch (Context->CurrentOpcode[0]) {
case AML_ZERO_OP:
case AML_ONE_OP:
CONTEXT_CONSUME_BYTES (Context, 1);
break;
case AML_BYTE_PREFIX:
CONTEXT_CONSUME_BYTES (Context, 2);
break;
case AML_WORD_PREFIX:
CONTEXT_CONSUME_BYTES (Context, 3);
break;
case AML_DWORD_PREFIX:
CONTEXT_CONSUME_BYTES (Context, 5);
break;
case AML_QWORD_PREFIX:
CONTEXT_CONSUME_BYTES (Context, 9);
break;
default:
if (ParseNameString (
Context,
NULL,
NULL,
NULL
) != EFI_SUCCESS) {
return EFI_DEVICE_ERROR;
}
break;
}
CONTEXT_PEEK_BYTES (Context, 1);
/* Fallthrough */
default:
if (ParseNameString (
Context,
NULL,
NULL,
NULL
) != EFI_SUCCESS) {
return EFI_DEVICE_ERROR;
}
break;
}
CONTEXT_PEEK_BYTES (Context, 1);
switch (Context->CurrentOpcode[0]) {
case AML_ZERO_OP:
case AML_ONE_OP:
CONTEXT_CONSUME_BYTES (Context, 1);
break;
case AML_BYTE_PREFIX:
CONTEXT_CONSUME_BYTES (Context, 2);
break;
case AML_WORD_PREFIX:
CONTEXT_CONSUME_BYTES (Context, 3);
break;
case AML_DWORD_PREFIX:
CONTEXT_CONSUME_BYTES (Context, 5);
break;
case AML_QWORD_PREFIX:
CONTEXT_CONSUME_BYTES (Context, 9);
break;
case AML_ADD_OP:
case AML_SUBTRACT_OP:
CONTEXT_ADVANCE_OPCODE (Context);
switch (Context->CurrentOpcode[0]) {
case AML_ZERO_OP:
case AML_ONE_OP:
CONTEXT_CONSUME_BYTES (Context, 1);
break;
case AML_BYTE_PREFIX:
CONTEXT_CONSUME_BYTES (Context, 2);
break;
case AML_WORD_PREFIX:
CONTEXT_CONSUME_BYTES (Context, 3);
break;
case AML_DWORD_PREFIX:
CONTEXT_CONSUME_BYTES (Context, 5);
break;
case AML_QWORD_PREFIX:
CONTEXT_CONSUME_BYTES (Context, 9);
break;
default:
if (ParseNameString (
Context,
NULL,
NULL,
NULL
) != EFI_SUCCESS) {
return EFI_DEVICE_ERROR;
}
break;
}
CONTEXT_PEEK_BYTES (Context, 1);
switch (Context->CurrentOpcode[0]) {
case AML_ZERO_OP:
case AML_ONE_OP:
CONTEXT_CONSUME_BYTES (Context, 1);
break;
case AML_BYTE_PREFIX:
CONTEXT_CONSUME_BYTES (Context, 2);
break;
case AML_WORD_PREFIX:
CONTEXT_CONSUME_BYTES (Context, 3);
break;
case AML_DWORD_PREFIX:
CONTEXT_CONSUME_BYTES (Context, 5);
break;
case AML_QWORD_PREFIX:
CONTEXT_CONSUME_BYTES (Context, 9);
break;
default:
if (ParseNameString (
Context,
NULL,
NULL,
NULL
) != EFI_SUCCESS) {
return EFI_DEVICE_ERROR;
}
break;
}
CONTEXT_PEEK_BYTES (Context, 1);
/* Fallthrough */
default:
if (ParseNameString (
Context,
NULL,
NULL,
NULL
) != EFI_SUCCESS) {
return EFI_DEVICE_ERROR;
}
break;
}
CONTEXT_DECREASE_NESTING (Context);
return EFI_NOT_FOUND;
}
/**
Parses PowerRes to skip it correctly.
@param[in, out] Context Structure containing the parser context.
@retval EFI_NOT_FOUND PowerRes was parsed and skipped successfuly.
@retval EFI_DEVICE_ERROR Error occured during parsing PowerRes.
@retval EFI_OUT_OF_RESOURCES Nesting limit has been reached.
**/
STATIC
EFI_STATUS
ParsePowerRes (
IN OUT ACPI_PARSER_CONTEXT *Context
)
{
UINT32 PkgLength;
UINT8 *CurrentOpcode;
CONTEXT_ENTER (Context, "PowerRes");
CONTEXT_HAS_WORK (Context);
CONTEXT_INCREASE_NESTING (Context);
CurrentOpcode = Context->CurrentOpcode;
if (ParsePkgLength (
Context,
&PkgLength
) != EFI_SUCCESS) {
return EFI_DEVICE_ERROR;
}
Context->CurrentOpcode = CurrentOpcode;
CONTEXT_CONSUME_BYTES (Context, PkgLength);
CONTEXT_DECREASE_NESTING (Context);
return EFI_NOT_FOUND;
}
/**
Parses processor section to skip it correctly.
@param[in, out] Context Structure containing the parser context.
@retval EFI_NOT_FOUND Processor was parsed and skipped successfuly.
@retval EFI_DEVICE_ERROR Error occured during parsing processor.
@retval EFI_OUT_OF_RESOURCES Nesting limit has been reached.
**/
STATIC
EFI_STATUS
ParseProcessor (
IN OUT ACPI_PARSER_CONTEXT *Context
)
{
UINT8 *CurrentOpcode;
UINT32 PkgLength;
CONTEXT_ENTER (Context, "Processor");
CONTEXT_HAS_WORK (Context);
CONTEXT_INCREASE_NESTING (Context);
CurrentOpcode = Context->CurrentOpcode;
if (ParsePkgLength (
Context,
&PkgLength
) != EFI_SUCCESS) {
return EFI_DEVICE_ERROR;
}
Context->CurrentOpcode = CurrentOpcode;
CONTEXT_CONSUME_BYTES (Context, PkgLength);
CONTEXT_DECREASE_NESTING (Context);
return EFI_NOT_FOUND;
}
/**
Parses thermal zone to skip it correctly.
@param[in, out] Context Structure containing the parser context.
@retval EFI_NOT_FOUND Processor was parsed and skipped successfuly.
@retval EFI_DEVICE_ERROR Error occured during parsing processor.
@retval EFI_OUT_OF_RESOURCES Nesting limit has been reached.
**/
STATIC
EFI_STATUS
ParseThermalZone (
IN OUT ACPI_PARSER_CONTEXT *Context
)
{
UINT8 *CurrentOpcode;
UINT32 PkgLength;
CONTEXT_ENTER (Context, "ThermalZone");
CONTEXT_HAS_WORK (Context);
CONTEXT_INCREASE_NESTING (Context);
CurrentOpcode = Context->CurrentOpcode;
if (ParsePkgLength (
Context,
&PkgLength
) != EFI_SUCCESS) {
return EFI_DEVICE_ERROR;
}
Context->CurrentOpcode = CurrentOpcode;
CONTEXT_CONSUME_BYTES (Context, PkgLength);
CONTEXT_DECREASE_NESTING (Context);
return EFI_NOT_FOUND;
}
/**
Parses method section.
In case it's name is suitable returns pointer to it's opcode.
Otherwise skips this section.
@param[in, out] Context Structure containing the parser context.
@param[out] Result Pointer to sought opcode if required entry was found.
@retval EFI_SUCCESS Required entry was found.
@retval EFI_NOT_FOUND Method was parsed and skipped successfuly.
@retval EFI_DEVICE_ERROR Error occured during parsing method.
@retval EFI_OUT_OF_RESOURCES Nesting limit has been reached.
**/
STATIC
EFI_STATUS
ParseMethod (
IN OUT ACPI_PARSER_CONTEXT *Context,
OUT UINT8 **Result
)
{
UINT8 *MethodStart;
UINT32 *CurrentPath;
UINT32 PkgLength;
UINT8 *MethodEnd;
UINT8 *MethodName;
UINT8 MethodNameLength;
UINT8 Index;
UINT8 Index2;
CONTEXT_ENTER (Context, "Method");
CONTEXT_HAS_WORK (Context);
CONTEXT_INCREASE_NESTING (Context);
MethodStart = Context->CurrentOpcode;
CurrentPath = Context->CurrentIdentifier;
if (ParsePkgLength (
Context,
&PkgLength
) != EFI_SUCCESS) {
return EFI_DEVICE_ERROR;
}
if ((UINT32) (Context->TableEnd - MethodStart) < PkgLength) {
return EFI_DEVICE_ERROR;
}
MethodEnd = MethodStart + PkgLength;
if (Context->CurrentOpcode >= MethodEnd) {
return EFI_DEVICE_ERROR;
}
if (ParseNameString (
Context,
&MethodName,
&MethodNameLength,
NULL
) != EFI_SUCCESS) {
return EFI_DEVICE_ERROR;
}
if (Context->CurrentOpcode > MethodEnd) {
return EFI_DEVICE_ERROR;
}
for (Index = 0; Index < MethodNameLength; ++Index) {
//
// If the method is within our lookup path but not at it, this is not a match.
//
if (Context->CurrentIdentifier == Context->PathEnd) {
Context->CurrentOpcode = MethodEnd;
Context->CurrentIdentifier = CurrentPath;
CONTEXT_DECREASE_NESTING (Context);
return EFI_NOT_FOUND;
}
for (Index2 = 0; Index2 < IDENT_LEN; Index2++) {
if (*(MethodName + Index2) != *((UINT8 *)Context->CurrentIdentifier + (IDENT_LEN - Index2 - 1))) {
Context->CurrentOpcode = MethodEnd;
Context->CurrentIdentifier = CurrentPath;
CONTEXT_DECREASE_NESTING (Context);
return EFI_NOT_FOUND;
}
}
Context->CurrentIdentifier += 1;
MethodName += 4;
}
if (Context->CurrentIdentifier != Context->PathEnd) {
Context->CurrentOpcode = MethodEnd;
Context->CurrentIdentifier = CurrentPath;
CONTEXT_DECREASE_NESTING (Context);
return EFI_NOT_FOUND;
}
Context->EntriesFound += 1;
if (Context->EntriesFound != Context->RequiredEntry) {
Context->CurrentOpcode = MethodEnd;
Context->CurrentIdentifier = CurrentPath;
CONTEXT_DECREASE_NESTING (Context);
return EFI_NOT_FOUND;
}
*Result = MethodStart - 1;
return EFI_SUCCESS;
}
/**
Parses if-else section. Looks for other sections inside it.
@param[in, out] Context Structure containing the parser context.
@param[out] Result Pointer to sought opcode if required entry was found.
@retval EFI_SUCCESS Required entry was found.
@retval EFI_NOT_FOUND If-else section was parsed and skipped successfuly.
@retval EFI_DEVICE_ERROR Error occured during parsing if-else section.
@retval EFI_OUT_OF_RESOURCES Nesting limit has been reached.
**/
STATIC
EFI_STATUS
ParseIfElse (
IN OUT ACPI_PARSER_CONTEXT *Context,
OUT UINT8 **Result
)
{
UINT32 PkgLength;
UINT8 *IfStart;
UINT32 *CurrentPath;
UINT8 *IfEnd;
EFI_STATUS Status;
CONTEXT_ENTER (Context, "IfElse");
CONTEXT_HAS_WORK (Context);
CONTEXT_INCREASE_NESTING (Context);
IfStart = Context->CurrentOpcode;
CurrentPath = Context->CurrentIdentifier;
if (ParsePkgLength (
Context,
&PkgLength
) != EFI_SUCCESS) {
return EFI_DEVICE_ERROR;
}
if ((UINT32) (Context->TableEnd - IfStart) < PkgLength) {
return EFI_DEVICE_ERROR;
}
IfEnd = IfStart + PkgLength;
//
// FIXME: This is broken like hell.
//
Status = EFI_NOT_FOUND;
while (Status != EFI_SUCCESS && Context->CurrentOpcode < IfEnd) {
Status = InternalAcpiParseTerm (Context, Result);
if (Status == EFI_DEVICE_ERROR) {
Context->CurrentOpcode += 1;
}
}
if (Status == EFI_DEVICE_ERROR) {
return EFI_DEVICE_ERROR;
}
if (Status == EFI_SUCCESS) {
CONTEXT_DECREASE_NESTING (Context);
return EFI_SUCCESS;
}
if (Context->CurrentOpcode > IfEnd) {
Context->CurrentOpcode = IfEnd;
}
Context->CurrentIdentifier = CurrentPath;
CONTEXT_PEEK_BYTES (Context, 1);
if (Context->CurrentOpcode[0] == AML_ELSE_OP) {
CONTEXT_ADVANCE_OPCODE (Context);
IfStart = Context->CurrentOpcode;
if (ParsePkgLength (
Context,
&PkgLength
) != EFI_SUCCESS) {
return EFI_DEVICE_ERROR;
}
if ((UINT32) (Context->TableEnd - IfStart) < PkgLength) {
return EFI_DEVICE_ERROR;
}
IfEnd = IfStart + PkgLength;
//
// FIXME: This is broken like hell.
//
Status = EFI_NOT_FOUND;
while (Status != EFI_SUCCESS && Context->CurrentOpcode < IfEnd) {
Status = InternalAcpiParseTerm (Context, Result);
if (Status == EFI_DEVICE_ERROR) {
Context->CurrentOpcode += 1;
}
}
if (Context->CurrentOpcode > IfEnd || Status == EFI_DEVICE_ERROR) {
return EFI_DEVICE_ERROR;
}
if (Status == EFI_SUCCESS) {
CONTEXT_DECREASE_NESTING (Context);
return EFI_SUCCESS;
}
Context->CurrentIdentifier = CurrentPath;
}
CONTEXT_DECREASE_NESTING (Context);
return EFI_NOT_FOUND;
}
/**
Parses event section to skip it correctly.
@param[in, out] Context Structure containing the parser context.
@retval EFI_NOT_FOUND Event was parsed and skipped successfuly.
@retval EFI_DEVICE_ERROR Error occured during parsing event.
@retval EFI_OUT_OF_RESOURCES Nesting limit has been reached.
**/
STATIC
EFI_STATUS
ParseEvent (
IN OUT ACPI_PARSER_CONTEXT *Context
)
{
CONTEXT_ENTER (Context, "Event");
CONTEXT_HAS_WORK (Context);
CONTEXT_INCREASE_NESTING (Context);
if (ParseNameString (
Context,
NULL,
NULL,
NULL
) != EFI_SUCCESS) {
return EFI_DEVICE_ERROR;
}
CONTEXT_DECREASE_NESTING (Context);
return EFI_NOT_FOUND;
}
/**
Parses field section.
In case it's name is suitable returns pointer to it's opcode.
Otherwise skips this section.
@param[in, out] Context Structure containing the parser context.
@param[out] Result Pointer to sought opcode if required entry was found.
@retval EFI_SUCCESS Required entry was found.
@retval EFI_NOT_FOUND Field was parsed and skipped successfuly.
@retval EFI_DEVICE_ERROR Error occured during parsing field.
@retval EFI_OUT_OF_RESOURCES Nesting limit has been reached.
**/
STATIC
EFI_STATUS
ParseField (
IN OUT ACPI_PARSER_CONTEXT *Context,
OUT UINT8 **Result
)
{
UINT8 *FieldStart;
UINT32 PkgLength;
UINT8 *FieldEnd;
UINT8 *FieldName;
UINT8 FieldNameLength;
UINT32 *CurrentPath;
UINT8 Index;
UINT8 Index2;
CONTEXT_ENTER (Context, "Field");
CONTEXT_HAS_WORK (Context);
CONTEXT_INCREASE_NESTING (Context);
FieldStart = Context->CurrentOpcode;
if (ParsePkgLength (
Context,
&PkgLength
) != EFI_SUCCESS) {
return EFI_DEVICE_ERROR;
}
if ((UINT32) (Context->TableEnd - FieldStart) < PkgLength) {
return EFI_DEVICE_ERROR;
}
FieldEnd = FieldStart + PkgLength;
if (Context->CurrentOpcode >= FieldEnd) {
return EFI_DEVICE_ERROR;
}
if (ParseNameString (
Context,
&FieldName,
&FieldNameLength,
NULL
) != EFI_SUCCESS) {
return EFI_DEVICE_ERROR;
}
if (Context->CurrentOpcode > FieldEnd) {
return EFI_DEVICE_ERROR;
}
CurrentPath = Context->CurrentIdentifier;
for (Index = 0; Index < FieldNameLength; Index++) {
if (Context->CurrentIdentifier == Context->PathEnd) {
Context->CurrentOpcode = FieldEnd;
Context->CurrentIdentifier = CurrentPath;
CONTEXT_DECREASE_NESTING (Context);
return EFI_NOT_FOUND;
}
for (Index2 = 0; Index2 < IDENT_LEN; Index2++) {
if (*(FieldName + Index2) != *((UINT8 *)Context->CurrentIdentifier + (IDENT_LEN - Index2 - 1))) {
Context->CurrentOpcode = FieldEnd;
Context->CurrentIdentifier = CurrentPath;
CONTEXT_DECREASE_NESTING (Context);
return EFI_NOT_FOUND;
}
}
Context->CurrentIdentifier += 1;
FieldName += 4;
}
if (Context->CurrentIdentifier != Context->PathEnd) {
Context->CurrentOpcode = FieldEnd;
Context->CurrentIdentifier = CurrentPath;
CONTEXT_DECREASE_NESTING (Context);
return EFI_NOT_FOUND;
}
Context->EntriesFound += 1;
if (Context->EntriesFound != Context->RequiredEntry) {
Context->CurrentOpcode = FieldEnd;
Context->CurrentIdentifier = CurrentPath;
CONTEXT_DECREASE_NESTING (Context);
return EFI_NOT_FOUND;
}
*Result = FieldStart - 1;
return EFI_SUCCESS;
}
/**
Parses mutex to correctly skip it.
@param[in, out] Context Structure containing the parser context.
@retval EFI_NOT_FOUND Mutex was parsed and skipped successfuly.
@retval EFI_DEVICE_ERROR Error occured during parsing mutex.
@retval EFI_OUT_OF_RESOURCES Nesting limit has been reached.
**/
STATIC
EFI_STATUS
ParseMutex (
IN OUT ACPI_PARSER_CONTEXT *Context
)
{
CONTEXT_ENTER (Context, "Mutex");
CONTEXT_HAS_WORK (Context);
CONTEXT_INCREASE_NESTING (Context);
if (ParseNameString (
Context,
NULL,
NULL,
NULL
) != EFI_SUCCESS) {
return EFI_DEVICE_ERROR;
}
CONTEXT_CONSUME_BYTES (Context, 1);
CONTEXT_DECREASE_NESTING (Context);
return EFI_NOT_FOUND;
}
/**
Parses index field section.
In case it's name is suitable returns pointer to it's opcode.
Otherwise skips this section.
@param[in, out] Context Structure containing the parser context.
@param[out] Result Pointer to sought opcode if required entry was found.
@retval EFI_SUCCESS Required entry was found.
@retval EFI_NOT_FOUND Index field was parsed and skipped successfuly.
@retval EFI_DEVICE_ERROR Error occured during parsing index field.
@retval EFI_OUT_OF_RESOURCES Nesting limit has been reached.
**/
STATIC
EFI_STATUS
ParseIndexField (
IN OUT ACPI_PARSER_CONTEXT *Context,
OUT UINT8 **Result
)
{
UINT8 *FieldStart;
UINT32 PkgLength;
UINT8 *FieldEnd;
UINT8 *FieldName;
UINT8 FieldNameLength;
UINT8 Index;
CONTEXT_ENTER (Context, "IndexField");
CONTEXT_HAS_WORK (Context);
CONTEXT_INCREASE_NESTING (Context);
FieldStart = Context->CurrentOpcode;
if (ParsePkgLength (
Context,
&PkgLength
) != EFI_SUCCESS) {
return EFI_DEVICE_ERROR;
}
if ((UINT32) (Context->TableEnd - FieldStart) < PkgLength) {
return EFI_DEVICE_ERROR;
}
FieldEnd = FieldStart + PkgLength;
if (Context->CurrentOpcode >= FieldEnd) {
return EFI_DEVICE_ERROR;
}
if (ParseNameString (
Context,
&FieldName,
&FieldNameLength,
NULL
) != EFI_SUCCESS) {
return EFI_DEVICE_ERROR;
}
if (Context->CurrentOpcode >= FieldEnd) {
return EFI_DEVICE_ERROR;
}
if (FieldNameLength != 1) {
return EFI_DEVICE_ERROR;
}
for (Index = 0; Index < IDENT_LEN; ++Index) {
if (*(FieldName + Index) != *((UINT8 *)Context->CurrentIdentifier + (IDENT_LEN - Index - 1))) {
if (ParseNameString (
Context,
&FieldName,
&FieldNameLength,
NULL
) != EFI_SUCCESS) {
return EFI_DEVICE_ERROR;
}
Context->CurrentOpcode = FieldEnd;
CONTEXT_DECREASE_NESTING (Context);
return EFI_NOT_FOUND;
}
}
Context->CurrentIdentifier += 1;
//
// FIXME: Not sure what to do.
//
if (Context->CurrentIdentifier == Context->PathEnd) {
return EFI_DEVICE_ERROR;
}
CONTEXT_PEEK_BYTES (Context, 1);
if (ParseNameString (
Context,
&FieldName,
&FieldNameLength,
NULL
) != EFI_SUCCESS) {
return EFI_DEVICE_ERROR;
}
if (Context->CurrentOpcode >= FieldEnd) {
return EFI_DEVICE_ERROR;
}
if (FieldNameLength != 1) {
return EFI_DEVICE_ERROR;
}
for (Index = 0; Index < IDENT_LEN; Index++) {
if (*(FieldName + Index) != *((UINT8 *)Context->CurrentIdentifier + (IDENT_LEN - Index - 1))) {
Context->CurrentOpcode = FieldEnd;
Context->CurrentIdentifier -= 1;
CONTEXT_DECREASE_NESTING (Context);
return EFI_NOT_FOUND;
}
}
if (Context->CurrentIdentifier + 1 != Context->PathEnd) {
Context->CurrentOpcode = FieldEnd;
Context->CurrentIdentifier -= 1;
CONTEXT_DECREASE_NESTING (Context);
return EFI_NOT_FOUND;
}
Context->EntriesFound += 1;
if (Context->EntriesFound != Context->RequiredEntry) {
Context->CurrentOpcode = FieldEnd;
Context->CurrentIdentifier -= 1;
CONTEXT_DECREASE_NESTING (Context);
return EFI_NOT_FOUND;
}
*Result = FieldStart - 1;
return EFI_SUCCESS;
}
EFI_STATUS
InternalAcpiParseTerm (
IN OUT ACPI_PARSER_CONTEXT *Context,
OUT UINT8 **Result
)
{
EFI_STATUS Status;
CONTEXT_ENTER (Context, "Term");
CONTEXT_HAS_WORK (Context);
ASSERT (Result != NULL);
CONTEXT_INCREASE_NESTING (Context);
DEBUG ((DEBUG_VERBOSE, "Opcode: %x\n", Context->CurrentOpcode[0]));
switch (Context->CurrentOpcode[0]) {
case AML_ALIAS_OP: // Alias
CONTEXT_ADVANCE_OPCODE (Context);
Status = ParseAlias (Context);
break;
case AML_SCOPE_OP: // Scope
CONTEXT_ADVANCE_OPCODE (Context);
Status = ParseScopeOrDevice (Context, Result);
break;
case AML_NAME_OP: // Name
CONTEXT_ADVANCE_OPCODE (Context);
Status = ParseName (Context);
break;
case AML_ZERO_OP: // ZeroOp
case AML_EXT_OP: // ExtOpPrefix
CONTEXT_ADVANCE_OPCODE (Context);
Status = EFI_NOT_FOUND;
break;
case AML_EXT_BANK_FIELD_OP: // BankField
CONTEXT_ADVANCE_OPCODE (Context);
Status = ParseBankField (Context, Result);
break;
case AML_CREATE_DWORD_FIELD_OP: // CreateDwordField
case AML_CREATE_WORD_FIELD_OP: // CreateWordField
case AML_CREATE_BYTE_FIELD_OP: // CreateByteField
case AML_CREATE_BIT_FIELD_OP: // CreateBitField
case AML_CREATE_QWORD_FIELD_OP: // CreateQWordField
case AML_EXT_CREATE_FIELD_OP: // CreateField
CONTEXT_ADVANCE_OPCODE (Context);
Status = ParseCreateField (Context, Result);
break;
case AML_EXTERNAL_OP: // External
CONTEXT_ADVANCE_OPCODE (Context);
Status = ParseExternal (Context);
break;
case AML_EXT_REGION_OP: // OpRegion
CONTEXT_ADVANCE_OPCODE (Context);
Status = ParseOpRegion (Context);
break;
case AML_EXT_POWER_RES_OP: // PowerRes
CONTEXT_ADVANCE_OPCODE (Context);
Status = ParsePowerRes (Context);
break;
case AML_EXT_PROCESSOR_OP: // Processor
CONTEXT_ADVANCE_OPCODE (Context);
Status = ParseProcessor (Context);
break;
case AML_EXT_THERMAL_ZONE_OP: // ThermalZone
CONTEXT_ADVANCE_OPCODE (Context);
Status = ParseThermalZone (Context);
break;
case AML_METHOD_OP: // Method
CONTEXT_ADVANCE_OPCODE (Context);
Status = ParseMethod (Context, Result);
break;
case AML_IF_OP: // IfElse
CONTEXT_ADVANCE_OPCODE (Context);
Status = ParseIfElse (Context, Result);
break;
case AML_EXT_DEVICE_OP: // Device
CONTEXT_ADVANCE_OPCODE (Context);
Status = ParseScopeOrDevice (Context, Result);
break;
case AML_EXT_EVENT_OP: // Event
CONTEXT_ADVANCE_OPCODE (Context);
Status = ParseEvent (Context);
break;
case AML_EXT_FIELD_OP: // Field
CONTEXT_ADVANCE_OPCODE (Context);
Status = ParseField (Context, Result);
break;
case AML_EXT_INDEX_FIELD_OP: // IndexField
CONTEXT_ADVANCE_OPCODE (Context);
Status = ParseIndexField (Context, Result);
break;
case AML_EXT_MUTEX_OP: // Mutex
CONTEXT_ADVANCE_OPCODE (Context);
Status = ParseMutex (Context);
break;
default:
Status = EFI_DEVICE_ERROR;
break;
}
CONTEXT_DECREASE_NESTING (Context);
return Status;
}
/**
Translates one identifier to AML opcodes. Complements it with '_'
opcodes if identifier length is under 4.
@param[in] Name Pointer to the start of the identifier.
@param[in] NameEnd Pointer to the end of the identifier.
@param[out] OpcodeName Identifier translated to opcodes.
@retval EFI_SUCCESS Identifier was translated successfuly.
@retval EFI_INVALID_PARAMETER Identifier can't be translated to opcodes.
**/
EFI_STATUS
TranslateNameToOpcodes (
IN CONST CHAR8 *Name,
IN CONST CHAR8 *NameEnd,
OUT UINT32 *OpcodeName
)
{
UINT32 CurrentOpcode;
UINT8 NameLength;
UINT8 Index;
CurrentOpcode = 0;
NameLength = (UINT8) (NameEnd - Name);
*OpcodeName = 0;
if (NameLength > IDENT_LEN) {
return EFI_INVALID_PARAMETER;
}
for (Index = 0; Index < IDENT_LEN; ++Index) {
if (Index < NameLength) {
if ((Name[Index] >= 'a') && (Name[Index] <= 'z')) {
CurrentOpcode = AML_NAME_CHAR_A + (Name[Index] - 'a');
} else if ((Name[Index] >= 'A') && (Name[Index] <= 'Z')) {
CurrentOpcode = AML_NAME_CHAR_A + (Name[Index] - 'A');
} else if ((Name[Index] >= '0') && (Name[Index] <= '9')) {
// AML_EXT_REVISION_OP == AML_NAME_INTEGER_0
CurrentOpcode = AML_EXT_REVISION_OP + (Name[Index] - '0');
} else if (Name[Index] == '_') {
CurrentOpcode = AML_NAME_CHAR__;
} else if (Name[Index] == '\\') {
*OpcodeName = 0;
return EFI_INVALID_PARAMETER;
} else {
*OpcodeName = 0;
return EFI_INVALID_PARAMETER;
}
} else {
CurrentOpcode = AML_NAME_CHAR__;
}
*OpcodeName = *OpcodeName << OPCODE_LEN;
*OpcodeName |= CurrentOpcode;
}
return EFI_SUCCESS;
}
/**
Translates path (one or more identifiers) to AML opcodes.
@param[in, out] Context Structure containing the parser context.
@param[in] PathString Original path.
@retval EFI_SUCCESS Path was translated successfuly.
@retval EFI_INVALID_PARAMETER Path can't be translated to opcodes.
**/
EFI_STATUS
GetOpcodeArray (
IN OUT ACPI_PARSER_CONTEXT *Context,
IN CONST CHAR8 *PathString
)
{
EFI_STATUS Status;
UINT32 Index;
UINT32 PathLength;
CHAR8 *Walker;
CHAR8 *IdentifierStart;
CONST CHAR8 *PathStringEnd;
UINTN AsciiLength;
ASSERT (Context != NULL);
ASSERT (PathString != NULL);
if (PathString[0] == '\\') {
PathString += 1;
}
AsciiLength = AsciiStrLen (PathString);
if (AsciiLength == 0) {
return EFI_INVALID_PARAMETER;
}
PathLength = 0;
PathStringEnd = PathString + AsciiLength;
for (Index = 0; Index < AsciiLength; Index++) {
if (PathString[Index] == '.') {
PathLength += 1;
}
}
PathLength += 1;
Context->PathStart = (UINT32 *) AllocateZeroPool (sizeof (UINT32) * PathLength);
if (Context->PathStart == NULL) {
return EFI_OUT_OF_RESOURCES;
}
Context->CurrentIdentifier = Context->PathStart;
Walker = (CHAR8 *) PathString;
IdentifierStart = (CHAR8 *) PathString;
for (Index = 0; Index < PathLength; ++Index) {
while (*Walker != '.' && Walker < PathStringEnd) {
Walker++;
}
if (Walker - IdentifierStart < 1) {
return EFI_INVALID_PARAMETER;
}
Status = TranslateNameToOpcodes (
IdentifierStart,
Walker,
(UINT32 *) (Context->CurrentIdentifier + Index)
);
if (EFI_ERROR (Status)) {
return Status;
}
++Walker;
IdentifierStart = Walker;
}
Context->PathEnd = Context->CurrentIdentifier + PathLength;
return EFI_SUCCESS;
}
/**
Initializes ACPI Context parser variable which stores ACPI header.
@param[out] Context Address to a context structure, containing the parser context.
**/
VOID
InitContext (
OUT ACPI_PARSER_CONTEXT *Context
)
{
ASSERT (Context != NULL);
ZeroMem (Context, sizeof (*Context));
}
/**
Deinitialises ACPI Context parser variable which stores ACPI header.
@param[in,out] Context Address to a context structure, containing the parser context.
**/
VOID
ClearContext (
IN OUT ACPI_PARSER_CONTEXT *Context
)
{
if (Context->PathStart != NULL) {
FreePool (Context->PathStart);
Context->PathStart = NULL;
}
ZeroMem (Context, sizeof (*Context));
}
EFI_STATUS
AcpiFindEntryInMemory (
IN UINT8 *Table,
IN CONST CHAR8 *PathString,
IN UINT8 Entry,
OUT UINT32 *Offset,
IN UINT32 TableLength OPTIONAL
)
{
EFI_STATUS Status;
UINT8 *Result;
ACPI_PARSER_CONTEXT Context;
ASSERT (Table != NULL);
ASSERT (PathString != NULL);
ASSERT (Offset != NULL);
if (TableLength > 0) {
if (TableLength < sizeof (EFI_ACPI_COMMON_HEADER)) {
DEBUG ((DEBUG_VERBOSE, "OCA: Got bad table format which does not specify its length!\n"));
return EFI_LOAD_ERROR;
}
//
// We do not check length here, mainly because TableLength > 0 is for fuzzing.
//
} else {
TableLength = ((EFI_ACPI_COMMON_HEADER *) Table)->Length;
}
if (TableLength <= sizeof (EFI_ACPI_DESCRIPTION_HEADER)) {
DEBUG ((DEBUG_VERBOSE, "OCA: Bad or unsupported table header!\n"));
return EFI_DEVICE_ERROR;
}
InitContext (&Context);
Context.CurrentOpcode = Table;
Context.RequiredEntry = Entry;
Context.TableStart = Table;
Context.TableEnd = Table + TableLength;
Context.CurrentOpcode += sizeof (EFI_ACPI_DESCRIPTION_HEADER);
Status = GetOpcodeArray (
&Context,
PathString
);
if (EFI_ERROR (Status)) {
ClearContext (&Context);
return Status;
}
while (Context.CurrentOpcode < Context.TableEnd) {
Status = InternalAcpiParseTerm (&Context, &Result);
if (!EFI_ERROR (Status)) {
*Offset = (UINT32) (Result - Table);
ClearContext (&Context);
return EFI_SUCCESS;
}
if (Status != EFI_NOT_FOUND) {
ClearContext (&Context);
return Status;
}
}
ClearContext (&Context);
return EFI_NOT_FOUND;
}

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://gitlife.ru/oschina-mirror/zsl588-OpenCorePkg.git
git@gitlife.ru:oschina-mirror/zsl588-OpenCorePkg.git
oschina-mirror
zsl588-OpenCorePkg
zsl588-OpenCorePkg
0.7.7