dswload.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. /******************************************************************************
  2. *
  3. * Module Name: dswload - Dispatcher first pass namespace load callbacks
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2015, Intel Corp.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #include "acpi.h"
  43. #include "accommon.h"
  44. #include "acparser.h"
  45. #include "amlcode.h"
  46. #include "acdispat.h"
  47. #include "acinterp.h"
  48. #include "acnamesp.h"
  49. #ifdef ACPI_ASL_COMPILER
  50. #include "acdisasm.h"
  51. #endif
  52. #define _COMPONENT ACPI_DISPATCHER
  53. ACPI_MODULE_NAME ("dswload")
  54. /*******************************************************************************
  55. *
  56. * FUNCTION: AcpiDsInitCallbacks
  57. *
  58. * PARAMETERS: WalkState - Current state of the parse tree walk
  59. * PassNumber - 1, 2, or 3
  60. *
  61. * RETURN: Status
  62. *
  63. * DESCRIPTION: Init walk state callbacks
  64. *
  65. ******************************************************************************/
  66. ACPI_STATUS
  67. AcpiDsInitCallbacks (
  68. ACPI_WALK_STATE *WalkState,
  69. UINT32 PassNumber)
  70. {
  71. switch (PassNumber)
  72. {
  73. case 0:
  74. /* Parse only - caller will setup callbacks */
  75. WalkState->ParseFlags = ACPI_PARSE_LOAD_PASS1 |
  76. ACPI_PARSE_DELETE_TREE |
  77. ACPI_PARSE_DISASSEMBLE;
  78. WalkState->DescendingCallback = NULL;
  79. WalkState->AscendingCallback = NULL;
  80. break;
  81. case 1:
  82. /* Load pass 1 */
  83. WalkState->ParseFlags = ACPI_PARSE_LOAD_PASS1 |
  84. ACPI_PARSE_DELETE_TREE;
  85. WalkState->DescendingCallback = AcpiDsLoad1BeginOp;
  86. WalkState->AscendingCallback = AcpiDsLoad1EndOp;
  87. break;
  88. case 2:
  89. /* Load pass 2 */
  90. WalkState->ParseFlags = ACPI_PARSE_LOAD_PASS1 |
  91. ACPI_PARSE_DELETE_TREE;
  92. WalkState->DescendingCallback = AcpiDsLoad2BeginOp;
  93. WalkState->AscendingCallback = AcpiDsLoad2EndOp;
  94. break;
  95. case 3:
  96. /* Execution pass */
  97. #ifndef ACPI_NO_METHOD_EXECUTION
  98. WalkState->ParseFlags |= ACPI_PARSE_EXECUTE |
  99. ACPI_PARSE_DELETE_TREE;
  100. WalkState->DescendingCallback = AcpiDsExecBeginOp;
  101. WalkState->AscendingCallback = AcpiDsExecEndOp;
  102. #endif
  103. break;
  104. default:
  105. return (AE_BAD_PARAMETER);
  106. }
  107. return (AE_OK);
  108. }
  109. /*******************************************************************************
  110. *
  111. * FUNCTION: AcpiDsLoad1BeginOp
  112. *
  113. * PARAMETERS: WalkState - Current state of the parse tree walk
  114. * OutOp - Where to return op if a new one is created
  115. *
  116. * RETURN: Status
  117. *
  118. * DESCRIPTION: Descending callback used during the loading of ACPI tables.
  119. *
  120. ******************************************************************************/
  121. ACPI_STATUS
  122. AcpiDsLoad1BeginOp (
  123. ACPI_WALK_STATE *WalkState,
  124. ACPI_PARSE_OBJECT **OutOp)
  125. {
  126. ACPI_PARSE_OBJECT *Op;
  127. ACPI_NAMESPACE_NODE *Node;
  128. ACPI_STATUS Status;
  129. ACPI_OBJECT_TYPE ObjectType;
  130. char *Path;
  131. UINT32 Flags;
  132. ACPI_FUNCTION_TRACE (DsLoad1BeginOp);
  133. Op = WalkState->Op;
  134. ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
  135. /* We are only interested in opcodes that have an associated name */
  136. if (Op)
  137. {
  138. if (!(WalkState->OpInfo->Flags & AML_NAMED))
  139. {
  140. *OutOp = Op;
  141. return_ACPI_STATUS (AE_OK);
  142. }
  143. /* Check if this object has already been installed in the namespace */
  144. if (Op->Common.Node)
  145. {
  146. *OutOp = Op;
  147. return_ACPI_STATUS (AE_OK);
  148. }
  149. }
  150. Path = AcpiPsGetNextNamestring (&WalkState->ParserState);
  151. /* Map the raw opcode into an internal object type */
  152. ObjectType = WalkState->OpInfo->ObjectType;
  153. ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
  154. "State=%p Op=%p [%s]\n", WalkState, Op,
  155. AcpiUtGetTypeName (ObjectType)));
  156. switch (WalkState->Opcode)
  157. {
  158. case AML_SCOPE_OP:
  159. /*
  160. * The target name of the Scope() operator must exist at this point so
  161. * that we can actually open the scope to enter new names underneath it.
  162. * Allow search-to-root for single namesegs.
  163. */
  164. Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
  165. ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT, WalkState, &(Node));
  166. #ifdef ACPI_ASL_COMPILER
  167. if (Status == AE_NOT_FOUND)
  168. {
  169. /*
  170. * Table disassembly:
  171. * Target of Scope() not found. Generate an External for it, and
  172. * insert the name into the namespace.
  173. */
  174. AcpiDmAddOpToExternalList (Op, Path, ACPI_TYPE_DEVICE, 0, 0);
  175. Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
  176. ACPI_IMODE_LOAD_PASS1, ACPI_NS_SEARCH_PARENT,
  177. WalkState, &Node);
  178. }
  179. #endif
  180. if (ACPI_FAILURE (Status))
  181. {
  182. ACPI_ERROR_NAMESPACE (Path, Status);
  183. return_ACPI_STATUS (Status);
  184. }
  185. /*
  186. * Check to make sure that the target is
  187. * one of the opcodes that actually opens a scope
  188. */
  189. switch (Node->Type)
  190. {
  191. case ACPI_TYPE_ANY:
  192. case ACPI_TYPE_LOCAL_SCOPE: /* Scope */
  193. case ACPI_TYPE_DEVICE:
  194. case ACPI_TYPE_POWER:
  195. case ACPI_TYPE_PROCESSOR:
  196. case ACPI_TYPE_THERMAL:
  197. /* These are acceptable types */
  198. break;
  199. case ACPI_TYPE_INTEGER:
  200. case ACPI_TYPE_STRING:
  201. case ACPI_TYPE_BUFFER:
  202. /*
  203. * These types we will allow, but we will change the type.
  204. * This enables some existing code of the form:
  205. *
  206. * Name (DEB, 0)
  207. * Scope (DEB) { ... }
  208. *
  209. * Note: silently change the type here. On the second pass,
  210. * we will report a warning
  211. */
  212. ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
  213. "Type override - [%4.4s] had invalid type (%s) "
  214. "for Scope operator, changed to type ANY\n",
  215. AcpiUtGetNodeName (Node), AcpiUtGetTypeName (Node->Type)));
  216. Node->Type = ACPI_TYPE_ANY;
  217. WalkState->ScopeInfo->Common.Value = ACPI_TYPE_ANY;
  218. break;
  219. case ACPI_TYPE_METHOD:
  220. /*
  221. * Allow scope change to root during execution of module-level
  222. * code. Root is typed METHOD during this time.
  223. */
  224. if ((Node == AcpiGbl_RootNode) &&
  225. (WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL))
  226. {
  227. break;
  228. }
  229. /*lint -fallthrough */
  230. default:
  231. /* All other types are an error */
  232. ACPI_ERROR ((AE_INFO,
  233. "Invalid type (%s) for target of "
  234. "Scope operator [%4.4s] (Cannot override)",
  235. AcpiUtGetTypeName (Node->Type), AcpiUtGetNodeName (Node)));
  236. return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
  237. }
  238. break;
  239. default:
  240. /*
  241. * For all other named opcodes, we will enter the name into
  242. * the namespace.
  243. *
  244. * Setup the search flags.
  245. * Since we are entering a name into the namespace, we do not want to
  246. * enable the search-to-root upsearch.
  247. *
  248. * There are only two conditions where it is acceptable that the name
  249. * already exists:
  250. * 1) the Scope() operator can reopen a scoping object that was
  251. * previously defined (Scope, Method, Device, etc.)
  252. * 2) Whenever we are parsing a deferred opcode (OpRegion, Buffer,
  253. * BufferField, or Package), the name of the object is already
  254. * in the namespace.
  255. */
  256. if (WalkState->DeferredNode)
  257. {
  258. /* This name is already in the namespace, get the node */
  259. Node = WalkState->DeferredNode;
  260. Status = AE_OK;
  261. break;
  262. }
  263. /*
  264. * If we are executing a method, do not create any namespace objects
  265. * during the load phase, only during execution.
  266. */
  267. if (WalkState->MethodNode)
  268. {
  269. Node = NULL;
  270. Status = AE_OK;
  271. break;
  272. }
  273. Flags = ACPI_NS_NO_UPSEARCH;
  274. if ((WalkState->Opcode != AML_SCOPE_OP) &&
  275. (!(WalkState->ParseFlags & ACPI_PARSE_DEFERRED_OP)))
  276. {
  277. if (WalkState->NamespaceOverride)
  278. {
  279. Flags |= ACPI_NS_OVERRIDE_IF_FOUND;
  280. ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[%s] Override allowed\n",
  281. AcpiUtGetTypeName (ObjectType)));
  282. }
  283. else
  284. {
  285. Flags |= ACPI_NS_ERROR_IF_FOUND;
  286. ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[%s] Cannot already exist\n",
  287. AcpiUtGetTypeName (ObjectType)));
  288. }
  289. }
  290. else
  291. {
  292. ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
  293. "[%s] Both Find or Create allowed\n",
  294. AcpiUtGetTypeName (ObjectType)));
  295. }
  296. /*
  297. * Enter the named type into the internal namespace. We enter the name
  298. * as we go downward in the parse tree. Any necessary subobjects that
  299. * involve arguments to the opcode must be created as we go back up the
  300. * parse tree later.
  301. */
  302. Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
  303. ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &Node);
  304. if (ACPI_FAILURE (Status))
  305. {
  306. if (Status == AE_ALREADY_EXISTS)
  307. {
  308. /* The name already exists in this scope */
  309. if (Node->Flags & ANOBJ_IS_EXTERNAL)
  310. {
  311. /*
  312. * Allow one create on an object or segment that was
  313. * previously declared External
  314. */
  315. Node->Flags &= ~ANOBJ_IS_EXTERNAL;
  316. Node->Type = (UINT8) ObjectType;
  317. /* Just retyped a node, probably will need to open a scope */
  318. if (AcpiNsOpensScope (ObjectType))
  319. {
  320. Status = AcpiDsScopeStackPush (
  321. Node, ObjectType, WalkState);
  322. if (ACPI_FAILURE (Status))
  323. {
  324. return_ACPI_STATUS (Status);
  325. }
  326. }
  327. Status = AE_OK;
  328. }
  329. }
  330. if (ACPI_FAILURE (Status))
  331. {
  332. ACPI_ERROR_NAMESPACE (Path, Status);
  333. return_ACPI_STATUS (Status);
  334. }
  335. }
  336. break;
  337. }
  338. /* Common exit */
  339. if (!Op)
  340. {
  341. /* Create a new op */
  342. Op = AcpiPsAllocOp (WalkState->Opcode, WalkState->Aml);
  343. if (!Op)
  344. {
  345. return_ACPI_STATUS (AE_NO_MEMORY);
  346. }
  347. }
  348. /* Initialize the op */
  349. #if (defined (ACPI_NO_METHOD_EXECUTION) || defined (ACPI_CONSTANT_EVAL_ONLY))
  350. Op->Named.Path = ACPI_CAST_PTR (UINT8, Path);
  351. #endif
  352. if (Node)
  353. {
  354. /*
  355. * Put the Node in the "op" object that the parser uses, so we
  356. * can get it again quickly when this scope is closed
  357. */
  358. Op->Common.Node = Node;
  359. Op->Named.Name = Node->Name.Integer;
  360. }
  361. AcpiPsAppendArg (AcpiPsGetParentScope (&WalkState->ParserState), Op);
  362. *OutOp = Op;
  363. return_ACPI_STATUS (Status);
  364. }
  365. /*******************************************************************************
  366. *
  367. * FUNCTION: AcpiDsLoad1EndOp
  368. *
  369. * PARAMETERS: WalkState - Current state of the parse tree walk
  370. *
  371. * RETURN: Status
  372. *
  373. * DESCRIPTION: Ascending callback used during the loading of the namespace,
  374. * both control methods and everything else.
  375. *
  376. ******************************************************************************/
  377. ACPI_STATUS
  378. AcpiDsLoad1EndOp (
  379. ACPI_WALK_STATE *WalkState)
  380. {
  381. ACPI_PARSE_OBJECT *Op;
  382. ACPI_OBJECT_TYPE ObjectType;
  383. ACPI_STATUS Status = AE_OK;
  384. ACPI_FUNCTION_TRACE (DsLoad1EndOp);
  385. Op = WalkState->Op;
  386. ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p State=%p\n", Op, WalkState));
  387. /* We are only interested in opcodes that have an associated name */
  388. if (!(WalkState->OpInfo->Flags & (AML_NAMED | AML_FIELD)))
  389. {
  390. return_ACPI_STATUS (AE_OK);
  391. }
  392. /* Get the object type to determine if we should pop the scope */
  393. ObjectType = WalkState->OpInfo->ObjectType;
  394. #ifndef ACPI_NO_METHOD_EXECUTION
  395. if (WalkState->OpInfo->Flags & AML_FIELD)
  396. {
  397. /*
  398. * If we are executing a method, do not create any namespace objects
  399. * during the load phase, only during execution.
  400. */
  401. if (!WalkState->MethodNode)
  402. {
  403. if (WalkState->Opcode == AML_FIELD_OP ||
  404. WalkState->Opcode == AML_BANK_FIELD_OP ||
  405. WalkState->Opcode == AML_INDEX_FIELD_OP)
  406. {
  407. Status = AcpiDsInitFieldObjects (Op, WalkState);
  408. }
  409. }
  410. return_ACPI_STATUS (Status);
  411. }
  412. /*
  413. * If we are executing a method, do not create any namespace objects
  414. * during the load phase, only during execution.
  415. */
  416. if (!WalkState->MethodNode)
  417. {
  418. if (Op->Common.AmlOpcode == AML_REGION_OP)
  419. {
  420. Status = AcpiExCreateRegion (Op->Named.Data, Op->Named.Length,
  421. (ACPI_ADR_SPACE_TYPE)
  422. ((Op->Common.Value.Arg)->Common.Value.Integer),
  423. WalkState);
  424. if (ACPI_FAILURE (Status))
  425. {
  426. return_ACPI_STATUS (Status);
  427. }
  428. }
  429. else if (Op->Common.AmlOpcode == AML_DATA_REGION_OP)
  430. {
  431. Status = AcpiExCreateRegion (Op->Named.Data, Op->Named.Length,
  432. ACPI_ADR_SPACE_DATA_TABLE, WalkState);
  433. if (ACPI_FAILURE (Status))
  434. {
  435. return_ACPI_STATUS (Status);
  436. }
  437. }
  438. }
  439. #endif
  440. if (Op->Common.AmlOpcode == AML_NAME_OP)
  441. {
  442. /* For Name opcode, get the object type from the argument */
  443. if (Op->Common.Value.Arg)
  444. {
  445. ObjectType = (AcpiPsGetOpcodeInfo (
  446. (Op->Common.Value.Arg)->Common.AmlOpcode))->ObjectType;
  447. /* Set node type if we have a namespace node */
  448. if (Op->Common.Node)
  449. {
  450. Op->Common.Node->Type = (UINT8) ObjectType;
  451. }
  452. }
  453. }
  454. /*
  455. * If we are executing a method, do not create any namespace objects
  456. * during the load phase, only during execution.
  457. */
  458. if (!WalkState->MethodNode)
  459. {
  460. if (Op->Common.AmlOpcode == AML_METHOD_OP)
  461. {
  462. /*
  463. * MethodOp PkgLength NameString MethodFlags TermList
  464. *
  465. * Note: We must create the method node/object pair as soon as we
  466. * see the method declaration. This allows later pass1 parsing
  467. * of invocations of the method (need to know the number of
  468. * arguments.)
  469. */
  470. ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
  471. "LOADING-Method: State=%p Op=%p NamedObj=%p\n",
  472. WalkState, Op, Op->Named.Node));
  473. if (!AcpiNsGetAttachedObject (Op->Named.Node))
  474. {
  475. WalkState->Operands[0] = ACPI_CAST_PTR (void, Op->Named.Node);
  476. WalkState->NumOperands = 1;
  477. Status = AcpiDsCreateOperands (
  478. WalkState, Op->Common.Value.Arg);
  479. if (ACPI_SUCCESS (Status))
  480. {
  481. Status = AcpiExCreateMethod (Op->Named.Data,
  482. Op->Named.Length, WalkState);
  483. }
  484. WalkState->Operands[0] = NULL;
  485. WalkState->NumOperands = 0;
  486. if (ACPI_FAILURE (Status))
  487. {
  488. return_ACPI_STATUS (Status);
  489. }
  490. }
  491. }
  492. }
  493. /* Pop the scope stack (only if loading a table) */
  494. if (!WalkState->MethodNode &&
  495. AcpiNsOpensScope (ObjectType))
  496. {
  497. ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "(%s): Popping scope for Op %p\n",
  498. AcpiUtGetTypeName (ObjectType), Op));
  499. Status = AcpiDsScopeStackPop (WalkState);
  500. }
  501. return_ACPI_STATUS (Status);
  502. }