exconfig.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. /******************************************************************************
  2. *
  3. * Module Name: exconfig - Namespace reconfiguration (Load/Unload opcodes)
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2019, 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 "acinterp.h"
  45. #include "acnamesp.h"
  46. #include "actables.h"
  47. #include "acdispat.h"
  48. #include "acevents.h"
  49. #include "amlcode.h"
  50. #define _COMPONENT ACPI_EXECUTER
  51. ACPI_MODULE_NAME ("exconfig")
  52. /* Local prototypes */
  53. static ACPI_STATUS
  54. AcpiExAddTable (
  55. UINT32 TableIndex,
  56. ACPI_OPERAND_OBJECT **DdbHandle);
  57. static ACPI_STATUS
  58. AcpiExRegionRead (
  59. ACPI_OPERAND_OBJECT *ObjDesc,
  60. UINT32 Length,
  61. UINT8 *Buffer);
  62. /*******************************************************************************
  63. *
  64. * FUNCTION: AcpiExAddTable
  65. *
  66. * PARAMETERS: Table - Pointer to raw table
  67. * ParentNode - Where to load the table (scope)
  68. * DdbHandle - Where to return the table handle.
  69. *
  70. * RETURN: Status
  71. *
  72. * DESCRIPTION: Common function to Install and Load an ACPI table with a
  73. * returned table handle.
  74. *
  75. ******************************************************************************/
  76. static ACPI_STATUS
  77. AcpiExAddTable (
  78. UINT32 TableIndex,
  79. ACPI_OPERAND_OBJECT **DdbHandle)
  80. {
  81. ACPI_OPERAND_OBJECT *ObjDesc;
  82. ACPI_FUNCTION_TRACE (ExAddTable);
  83. /* Create an object to be the table handle */
  84. ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE);
  85. if (!ObjDesc)
  86. {
  87. return_ACPI_STATUS (AE_NO_MEMORY);
  88. }
  89. /* Init the table handle */
  90. ObjDesc->Common.Flags |= AOPOBJ_DATA_VALID;
  91. ObjDesc->Reference.Class = ACPI_REFCLASS_TABLE;
  92. ObjDesc->Reference.Value = TableIndex;
  93. *DdbHandle = ObjDesc;
  94. return_ACPI_STATUS (AE_OK);
  95. }
  96. /*******************************************************************************
  97. *
  98. * FUNCTION: AcpiExLoadTableOp
  99. *
  100. * PARAMETERS: WalkState - Current state with operands
  101. * ReturnDesc - Where to store the return object
  102. *
  103. * RETURN: Status
  104. *
  105. * DESCRIPTION: Load an ACPI table from the RSDT/XSDT
  106. *
  107. ******************************************************************************/
  108. ACPI_STATUS
  109. AcpiExLoadTableOp (
  110. ACPI_WALK_STATE *WalkState,
  111. ACPI_OPERAND_OBJECT **ReturnDesc)
  112. {
  113. ACPI_STATUS Status;
  114. ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
  115. ACPI_NAMESPACE_NODE *ParentNode;
  116. ACPI_NAMESPACE_NODE *StartNode;
  117. ACPI_NAMESPACE_NODE *ParameterNode = NULL;
  118. ACPI_OPERAND_OBJECT *DdbHandle;
  119. UINT32 TableIndex;
  120. ACPI_FUNCTION_TRACE (ExLoadTableOp);
  121. /* Find the ACPI table in the RSDT/XSDT */
  122. AcpiExExitInterpreter ();
  123. Status = AcpiTbFindTable (
  124. Operand[0]->String.Pointer,
  125. Operand[1]->String.Pointer,
  126. Operand[2]->String.Pointer, &TableIndex);
  127. AcpiExEnterInterpreter ();
  128. if (ACPI_FAILURE (Status))
  129. {
  130. if (Status != AE_NOT_FOUND)
  131. {
  132. return_ACPI_STATUS (Status);
  133. }
  134. /* Table not found, return an Integer=0 and AE_OK */
  135. DdbHandle = AcpiUtCreateIntegerObject ((UINT64) 0);
  136. if (!DdbHandle)
  137. {
  138. return_ACPI_STATUS (AE_NO_MEMORY);
  139. }
  140. *ReturnDesc = DdbHandle;
  141. return_ACPI_STATUS (AE_OK);
  142. }
  143. /* Default nodes */
  144. StartNode = WalkState->ScopeInfo->Scope.Node;
  145. ParentNode = AcpiGbl_RootNode;
  146. /* RootPath (optional parameter) */
  147. if (Operand[3]->String.Length > 0)
  148. {
  149. /*
  150. * Find the node referenced by the RootPathString. This is the
  151. * location within the namespace where the table will be loaded.
  152. */
  153. Status = AcpiNsGetNodeUnlocked (StartNode,
  154. Operand[3]->String.Pointer, ACPI_NS_SEARCH_PARENT,
  155. &ParentNode);
  156. if (ACPI_FAILURE (Status))
  157. {
  158. return_ACPI_STATUS (Status);
  159. }
  160. }
  161. /* ParameterPath (optional parameter) */
  162. if (Operand[4]->String.Length > 0)
  163. {
  164. if ((Operand[4]->String.Pointer[0] != AML_ROOT_PREFIX) &&
  165. (Operand[4]->String.Pointer[0] != AML_PARENT_PREFIX))
  166. {
  167. /*
  168. * Path is not absolute, so it will be relative to the node
  169. * referenced by the RootPathString (or the NS root if omitted)
  170. */
  171. StartNode = ParentNode;
  172. }
  173. /* Find the node referenced by the ParameterPathString */
  174. Status = AcpiNsGetNodeUnlocked (StartNode,
  175. Operand[4]->String.Pointer, ACPI_NS_SEARCH_PARENT,
  176. &ParameterNode);
  177. if (ACPI_FAILURE (Status))
  178. {
  179. return_ACPI_STATUS (Status);
  180. }
  181. }
  182. /* Load the table into the namespace */
  183. ACPI_INFO (("Dynamic OEM Table Load:"));
  184. AcpiExExitInterpreter ();
  185. Status = AcpiTbLoadTable (TableIndex, ParentNode);
  186. AcpiExEnterInterpreter ();
  187. if (ACPI_FAILURE (Status))
  188. {
  189. return_ACPI_STATUS (Status);
  190. }
  191. Status = AcpiExAddTable (TableIndex, &DdbHandle);
  192. if (ACPI_FAILURE (Status))
  193. {
  194. return_ACPI_STATUS (Status);
  195. }
  196. /* Complete the initialization/resolution of package objects */
  197. Status = AcpiNsWalkNamespace (ACPI_TYPE_PACKAGE, ACPI_ROOT_OBJECT,
  198. ACPI_UINT32_MAX, 0, AcpiNsInitOnePackage, NULL, NULL, NULL);
  199. /* Parameter Data (optional) */
  200. if (ParameterNode)
  201. {
  202. /* Store the parameter data into the optional parameter object */
  203. Status = AcpiExStore (Operand[5],
  204. ACPI_CAST_PTR (ACPI_OPERAND_OBJECT, ParameterNode), WalkState);
  205. if (ACPI_FAILURE (Status))
  206. {
  207. (void) AcpiExUnloadTable (DdbHandle);
  208. AcpiUtRemoveReference (DdbHandle);
  209. return_ACPI_STATUS (Status);
  210. }
  211. }
  212. *ReturnDesc = DdbHandle;
  213. return_ACPI_STATUS (Status);
  214. }
  215. /*******************************************************************************
  216. *
  217. * FUNCTION: AcpiExRegionRead
  218. *
  219. * PARAMETERS: ObjDesc - Region descriptor
  220. * Length - Number of bytes to read
  221. * Buffer - Pointer to where to put the data
  222. *
  223. * RETURN: Status
  224. *
  225. * DESCRIPTION: Read data from an operation region. The read starts from the
  226. * beginning of the region.
  227. *
  228. ******************************************************************************/
  229. static ACPI_STATUS
  230. AcpiExRegionRead (
  231. ACPI_OPERAND_OBJECT *ObjDesc,
  232. UINT32 Length,
  233. UINT8 *Buffer)
  234. {
  235. ACPI_STATUS Status;
  236. UINT64 Value;
  237. UINT32 RegionOffset = 0;
  238. UINT32 i;
  239. /* Bytewise reads */
  240. for (i = 0; i < Length; i++)
  241. {
  242. Status = AcpiEvAddressSpaceDispatch (ObjDesc, NULL, ACPI_READ,
  243. RegionOffset, 8, &Value);
  244. if (ACPI_FAILURE (Status))
  245. {
  246. return (Status);
  247. }
  248. *Buffer = (UINT8) Value;
  249. Buffer++;
  250. RegionOffset++;
  251. }
  252. return (AE_OK);
  253. }
  254. /*******************************************************************************
  255. *
  256. * FUNCTION: AcpiExLoadOp
  257. *
  258. * PARAMETERS: ObjDesc - Region or Buffer/Field where the table will be
  259. * obtained
  260. * Target - Where a handle to the table will be stored
  261. * WalkState - Current state
  262. *
  263. * RETURN: Status
  264. *
  265. * DESCRIPTION: Load an ACPI table from a field or operation region
  266. *
  267. * NOTE: Region Fields (Field, BankField, IndexFields) are resolved to buffer
  268. * objects before this code is reached.
  269. *
  270. * If source is an operation region, it must refer to SystemMemory, as
  271. * per the ACPI specification.
  272. *
  273. ******************************************************************************/
  274. ACPI_STATUS
  275. AcpiExLoadOp (
  276. ACPI_OPERAND_OBJECT *ObjDesc,
  277. ACPI_OPERAND_OBJECT *Target,
  278. ACPI_WALK_STATE *WalkState)
  279. {
  280. ACPI_OPERAND_OBJECT *DdbHandle;
  281. ACPI_TABLE_HEADER *TableHeader;
  282. ACPI_TABLE_HEADER *Table;
  283. UINT32 TableIndex;
  284. ACPI_STATUS Status;
  285. UINT32 Length;
  286. ACPI_FUNCTION_TRACE (ExLoadOp);
  287. /* Source Object can be either an OpRegion or a Buffer/Field */
  288. switch (ObjDesc->Common.Type)
  289. {
  290. case ACPI_TYPE_REGION:
  291. ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
  292. "Load table from Region %p\n", ObjDesc));
  293. /* Region must be SystemMemory (from ACPI spec) */
  294. if (ObjDesc->Region.SpaceId != ACPI_ADR_SPACE_SYSTEM_MEMORY)
  295. {
  296. return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
  297. }
  298. /*
  299. * If the Region Address and Length have not been previously
  300. * evaluated, evaluate them now and save the results.
  301. */
  302. if (!(ObjDesc->Common.Flags & AOPOBJ_DATA_VALID))
  303. {
  304. Status = AcpiDsGetRegionArguments (ObjDesc);
  305. if (ACPI_FAILURE (Status))
  306. {
  307. return_ACPI_STATUS (Status);
  308. }
  309. }
  310. /* Get the table header first so we can get the table length */
  311. TableHeader = ACPI_ALLOCATE (sizeof (ACPI_TABLE_HEADER));
  312. if (!TableHeader)
  313. {
  314. return_ACPI_STATUS (AE_NO_MEMORY);
  315. }
  316. Status = AcpiExRegionRead (ObjDesc, sizeof (ACPI_TABLE_HEADER),
  317. ACPI_CAST_PTR (UINT8, TableHeader));
  318. Length = TableHeader->Length;
  319. ACPI_FREE (TableHeader);
  320. if (ACPI_FAILURE (Status))
  321. {
  322. return_ACPI_STATUS (Status);
  323. }
  324. /* Must have at least an ACPI table header */
  325. if (Length < sizeof (ACPI_TABLE_HEADER))
  326. {
  327. return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
  328. }
  329. /*
  330. * The original implementation simply mapped the table, with no copy.
  331. * However, the memory region is not guaranteed to remain stable and
  332. * we must copy the table to a local buffer. For example, the memory
  333. * region is corrupted after suspend on some machines. Dynamically
  334. * loaded tables are usually small, so this overhead is minimal.
  335. *
  336. * The latest implementation (5/2009) does not use a mapping at all.
  337. * We use the low-level operation region interface to read the table
  338. * instead of the obvious optimization of using a direct mapping.
  339. * This maintains a consistent use of operation regions across the
  340. * entire subsystem. This is important if additional processing must
  341. * be performed in the (possibly user-installed) operation region
  342. * handler. For example, AcpiExec and ASLTS depend on this.
  343. */
  344. /* Allocate a buffer for the table */
  345. Table = ACPI_ALLOCATE (Length);
  346. if (!Table)
  347. {
  348. return_ACPI_STATUS (AE_NO_MEMORY);
  349. }
  350. /* Read the entire table */
  351. Status = AcpiExRegionRead (ObjDesc, Length,
  352. ACPI_CAST_PTR (UINT8, Table));
  353. if (ACPI_FAILURE (Status))
  354. {
  355. ACPI_FREE (Table);
  356. return_ACPI_STATUS (Status);
  357. }
  358. break;
  359. case ACPI_TYPE_BUFFER: /* Buffer or resolved RegionField */
  360. ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
  361. "Load table from Buffer or Field %p\n", ObjDesc));
  362. /* Must have at least an ACPI table header */
  363. if (ObjDesc->Buffer.Length < sizeof (ACPI_TABLE_HEADER))
  364. {
  365. return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
  366. }
  367. /* Get the actual table length from the table header */
  368. TableHeader = ACPI_CAST_PTR (
  369. ACPI_TABLE_HEADER, ObjDesc->Buffer.Pointer);
  370. Length = TableHeader->Length;
  371. /* Table cannot extend beyond the buffer */
  372. if (Length > ObjDesc->Buffer.Length)
  373. {
  374. return_ACPI_STATUS (AE_AML_BUFFER_LIMIT);
  375. }
  376. if (Length < sizeof (ACPI_TABLE_HEADER))
  377. {
  378. return_ACPI_STATUS (AE_INVALID_TABLE_LENGTH);
  379. }
  380. /*
  381. * Copy the table from the buffer because the buffer could be
  382. * modified or even deleted in the future
  383. */
  384. Table = ACPI_ALLOCATE (Length);
  385. if (!Table)
  386. {
  387. return_ACPI_STATUS (AE_NO_MEMORY);
  388. }
  389. memcpy (Table, TableHeader, Length);
  390. break;
  391. default:
  392. return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
  393. }
  394. /* Install the new table into the local data structures */
  395. ACPI_INFO (("Dynamic OEM Table Load:"));
  396. AcpiExExitInterpreter ();
  397. Status = AcpiTbInstallAndLoadTable (ACPI_PTR_TO_PHYSADDR (Table),
  398. ACPI_TABLE_ORIGIN_INTERNAL_VIRTUAL, TRUE, &TableIndex);
  399. AcpiExEnterInterpreter ();
  400. if (ACPI_FAILURE (Status))
  401. {
  402. /* Delete allocated table buffer */
  403. ACPI_FREE (Table);
  404. return_ACPI_STATUS (Status);
  405. }
  406. /*
  407. * Add the table to the namespace.
  408. *
  409. * Note: Load the table objects relative to the root of the namespace.
  410. * This appears to go against the ACPI specification, but we do it for
  411. * compatibility with other ACPI implementations.
  412. */
  413. Status = AcpiExAddTable (TableIndex, &DdbHandle);
  414. if (ACPI_FAILURE (Status))
  415. {
  416. /* On error, TablePtr was deallocated above */
  417. return_ACPI_STATUS (Status);
  418. }
  419. /* Complete the initialization/resolution of package objects */
  420. Status = AcpiNsWalkNamespace (ACPI_TYPE_PACKAGE, ACPI_ROOT_OBJECT,
  421. ACPI_UINT32_MAX, 0, AcpiNsInitOnePackage, NULL, NULL, NULL);
  422. /* Store the DdbHandle into the Target operand */
  423. Status = AcpiExStore (DdbHandle, Target, WalkState);
  424. if (ACPI_FAILURE (Status))
  425. {
  426. (void) AcpiExUnloadTable (DdbHandle);
  427. /* TablePtr was deallocated above */
  428. AcpiUtRemoveReference (DdbHandle);
  429. return_ACPI_STATUS (Status);
  430. }
  431. /* Remove the reference by added by AcpiExStore above */
  432. AcpiUtRemoveReference (DdbHandle);
  433. return_ACPI_STATUS (Status);
  434. }
  435. /*******************************************************************************
  436. *
  437. * FUNCTION: AcpiExUnloadTable
  438. *
  439. * PARAMETERS: DdbHandle - Handle to a previously loaded table
  440. *
  441. * RETURN: Status
  442. *
  443. * DESCRIPTION: Unload an ACPI table
  444. *
  445. ******************************************************************************/
  446. ACPI_STATUS
  447. AcpiExUnloadTable (
  448. ACPI_OPERAND_OBJECT *DdbHandle)
  449. {
  450. ACPI_STATUS Status = AE_OK;
  451. ACPI_OPERAND_OBJECT *TableDesc = DdbHandle;
  452. UINT32 TableIndex;
  453. ACPI_FUNCTION_TRACE (ExUnloadTable);
  454. /*
  455. * Temporarily emit a warning so that the ASL for the machine can be
  456. * hopefully obtained. This is to say that the Unload() operator is
  457. * extremely rare if not completely unused.
  458. */
  459. ACPI_WARNING ((AE_INFO,
  460. "Received request to unload an ACPI table"));
  461. /*
  462. * May 2018: Unload is no longer supported for the following reasons:
  463. * 1) A correct implementation on some hosts may not be possible.
  464. * 2) Other ACPI implementations do not correctly/fully support it.
  465. * 3) It requires host device driver support which does not exist.
  466. * (To properly support namespace unload out from underneath.)
  467. * 4) This AML operator has never been seen in the field.
  468. */
  469. ACPI_EXCEPTION ((AE_INFO, AE_NOT_IMPLEMENTED,
  470. "AML Unload operator is not supported"));
  471. /*
  472. * Validate the handle
  473. * Although the handle is partially validated in AcpiExReconfiguration()
  474. * when it calls AcpiExResolveOperands(), the handle is more completely
  475. * validated here.
  476. *
  477. * Handle must be a valid operand object of type reference. Also, the
  478. * DdbHandle must still be marked valid (table has not been previously
  479. * unloaded)
  480. */
  481. if ((!DdbHandle) ||
  482. (ACPI_GET_DESCRIPTOR_TYPE (DdbHandle) != ACPI_DESC_TYPE_OPERAND) ||
  483. (DdbHandle->Common.Type != ACPI_TYPE_LOCAL_REFERENCE) ||
  484. (!(DdbHandle->Common.Flags & AOPOBJ_DATA_VALID)))
  485. {
  486. return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
  487. }
  488. /* Get the table index from the DdbHandle */
  489. TableIndex = TableDesc->Reference.Value;
  490. /*
  491. * Release the interpreter lock so that the table lock won't have
  492. * strict order requirement against it.
  493. */
  494. AcpiExExitInterpreter ();
  495. Status = AcpiTbUnloadTable (TableIndex);
  496. AcpiExEnterInterpreter ();
  497. /*
  498. * Invalidate the handle. We do this because the handle may be stored
  499. * in a named object and may not be actually deleted until much later.
  500. */
  501. if (ACPI_SUCCESS (Status))
  502. {
  503. DdbHandle->Common.Flags &= ~AOPOBJ_DATA_VALID;
  504. }
  505. return_ACPI_STATUS (Status);
  506. }