hwregs.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827
  1. /*******************************************************************************
  2. *
  3. * Module Name: hwregs - Read/write access functions for the various ACPI
  4. * control and status registers.
  5. *
  6. ******************************************************************************/
  7. /*
  8. * Copyright (C) 2000 - 2017, Intel Corp.
  9. * All rights reserved.
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. * 1. Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions, and the following disclaimer,
  16. * without modification.
  17. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  18. * substantially similar to the "NO WARRANTY" disclaimer below
  19. * ("Disclaimer") and any redistribution must be conditioned upon
  20. * including a substantially similar Disclaimer requirement for further
  21. * binary redistribution.
  22. * 3. Neither the names of the above-listed copyright holders nor the names
  23. * of any contributors may be used to endorse or promote products derived
  24. * from this software without specific prior written permission.
  25. *
  26. * Alternatively, this software may be distributed under the terms of the
  27. * GNU General Public License ("GPL") version 2 as published by the Free
  28. * Software Foundation.
  29. *
  30. * NO WARRANTY
  31. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  32. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  33. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  34. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  35. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  36. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  37. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  38. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  40. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  41. * POSSIBILITY OF SUCH DAMAGES.
  42. */
  43. #include <acpi/acpi.h>
  44. #include "accommon.h"
  45. #include "acevents.h"
  46. #define _COMPONENT ACPI_HARDWARE
  47. ACPI_MODULE_NAME("hwregs")
  48. #if (!ACPI_REDUCED_HARDWARE)
  49. /* Local Prototypes */
  50. static u8
  51. acpi_hw_get_access_bit_width(u64 address,
  52. struct acpi_generic_address *reg,
  53. u8 max_bit_width);
  54. static acpi_status
  55. acpi_hw_read_multiple(u32 *value,
  56. struct acpi_generic_address *register_a,
  57. struct acpi_generic_address *register_b);
  58. static acpi_status
  59. acpi_hw_write_multiple(u32 value,
  60. struct acpi_generic_address *register_a,
  61. struct acpi_generic_address *register_b);
  62. #endif /* !ACPI_REDUCED_HARDWARE */
  63. /******************************************************************************
  64. *
  65. * FUNCTION: acpi_hw_get_access_bit_width
  66. *
  67. * PARAMETERS: address - GAS register address
  68. * reg - GAS register structure
  69. * max_bit_width - Max bit_width supported (32 or 64)
  70. *
  71. * RETURN: Status
  72. *
  73. * DESCRIPTION: Obtain optimal access bit width
  74. *
  75. ******************************************************************************/
  76. static u8
  77. acpi_hw_get_access_bit_width(u64 address,
  78. struct acpi_generic_address *reg, u8 max_bit_width)
  79. {
  80. u8 access_bit_width;
  81. /*
  82. * GAS format "register", used by FADT:
  83. * 1. Detected if bit_offset is 0 and bit_width is 8/16/32/64;
  84. * 2. access_size field is ignored and bit_width field is used for
  85. * determining the boundary of the IO accesses.
  86. * GAS format "region", used by APEI registers:
  87. * 1. Detected if bit_offset is not 0 or bit_width is not 8/16/32/64;
  88. * 2. access_size field is used for determining the boundary of the
  89. * IO accesses;
  90. * 3. bit_offset/bit_width fields are used to describe the "region".
  91. *
  92. * Note: This algorithm assumes that the "Address" fields should always
  93. * contain aligned values.
  94. */
  95. if (!reg->bit_offset && reg->bit_width &&
  96. ACPI_IS_POWER_OF_TWO(reg->bit_width) &&
  97. ACPI_IS_ALIGNED(reg->bit_width, 8)) {
  98. access_bit_width = reg->bit_width;
  99. } else if (reg->access_width) {
  100. access_bit_width = (1 << (reg->access_width + 2));
  101. } else {
  102. access_bit_width =
  103. ACPI_ROUND_UP_POWER_OF_TWO_8(reg->bit_offset +
  104. reg->bit_width);
  105. if (access_bit_width <= 8) {
  106. access_bit_width = 8;
  107. } else {
  108. while (!ACPI_IS_ALIGNED(address, access_bit_width >> 3)) {
  109. access_bit_width >>= 1;
  110. }
  111. }
  112. }
  113. /* Maximum IO port access bit width is 32 */
  114. if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
  115. max_bit_width = 32;
  116. }
  117. /*
  118. * Return access width according to the requested maximum access bit width,
  119. * as the caller should know the format of the register and may enforce
  120. * a 32-bit accesses.
  121. */
  122. if (access_bit_width < max_bit_width) {
  123. return (access_bit_width);
  124. }
  125. return (max_bit_width);
  126. }
  127. /******************************************************************************
  128. *
  129. * FUNCTION: acpi_hw_validate_register
  130. *
  131. * PARAMETERS: reg - GAS register structure
  132. * max_bit_width - Max bit_width supported (32 or 64)
  133. * address - Pointer to where the gas->address
  134. * is returned
  135. *
  136. * RETURN: Status
  137. *
  138. * DESCRIPTION: Validate the contents of a GAS register. Checks the GAS
  139. * pointer, Address, space_id, bit_width, and bit_offset.
  140. *
  141. ******************************************************************************/
  142. acpi_status
  143. acpi_hw_validate_register(struct acpi_generic_address *reg,
  144. u8 max_bit_width, u64 *address)
  145. {
  146. u8 bit_width;
  147. u8 access_width;
  148. /* Must have a valid pointer to a GAS structure */
  149. if (!reg) {
  150. return (AE_BAD_PARAMETER);
  151. }
  152. /*
  153. * Copy the target address. This handles possible alignment issues.
  154. * Address must not be null. A null address also indicates an optional
  155. * ACPI register that is not supported, so no error message.
  156. */
  157. ACPI_MOVE_64_TO_64(address, &reg->address);
  158. if (!(*address)) {
  159. return (AE_BAD_ADDRESS);
  160. }
  161. /* Validate the space_ID */
  162. if ((reg->space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY) &&
  163. (reg->space_id != ACPI_ADR_SPACE_SYSTEM_IO)) {
  164. ACPI_ERROR((AE_INFO,
  165. "Unsupported address space: 0x%X", reg->space_id));
  166. return (AE_SUPPORT);
  167. }
  168. /* Validate the access_width */
  169. if (reg->access_width > 4) {
  170. ACPI_ERROR((AE_INFO,
  171. "Unsupported register access width: 0x%X",
  172. reg->access_width));
  173. return (AE_SUPPORT);
  174. }
  175. /* Validate the bit_width, convert access_width into number of bits */
  176. access_width =
  177. acpi_hw_get_access_bit_width(*address, reg, max_bit_width);
  178. bit_width =
  179. ACPI_ROUND_UP(reg->bit_offset + reg->bit_width, access_width);
  180. if (max_bit_width < bit_width) {
  181. ACPI_WARNING((AE_INFO,
  182. "Requested bit width 0x%X is smaller than register bit width 0x%X",
  183. max_bit_width, bit_width));
  184. return (AE_SUPPORT);
  185. }
  186. return (AE_OK);
  187. }
  188. /******************************************************************************
  189. *
  190. * FUNCTION: acpi_hw_read
  191. *
  192. * PARAMETERS: value - Where the value is returned
  193. * reg - GAS register structure
  194. *
  195. * RETURN: Status
  196. *
  197. * DESCRIPTION: Read from either memory or IO space. This is a 32-bit max
  198. * version of acpi_read, used internally since the overhead of
  199. * 64-bit values is not needed.
  200. *
  201. * LIMITATIONS: <These limitations also apply to acpi_hw_write>
  202. * space_ID must be system_memory or system_IO.
  203. *
  204. ******************************************************************************/
  205. acpi_status acpi_hw_read(u32 *value, struct acpi_generic_address *reg)
  206. {
  207. u64 address;
  208. u8 access_width;
  209. u32 bit_width;
  210. u8 bit_offset;
  211. u64 value64;
  212. u32 value32;
  213. u8 index;
  214. acpi_status status;
  215. ACPI_FUNCTION_NAME(hw_read);
  216. /* Validate contents of the GAS register */
  217. status = acpi_hw_validate_register(reg, 32, &address);
  218. if (ACPI_FAILURE(status)) {
  219. return (status);
  220. }
  221. /*
  222. * Initialize entire 32-bit return value to zero, convert access_width
  223. * into number of bits based
  224. */
  225. *value = 0;
  226. access_width = acpi_hw_get_access_bit_width(address, reg, 32);
  227. bit_width = reg->bit_offset + reg->bit_width;
  228. bit_offset = reg->bit_offset;
  229. /*
  230. * Two address spaces supported: Memory or IO. PCI_Config is
  231. * not supported here because the GAS structure is insufficient
  232. */
  233. index = 0;
  234. while (bit_width) {
  235. if (bit_offset >= access_width) {
  236. value32 = 0;
  237. bit_offset -= access_width;
  238. } else {
  239. if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
  240. status =
  241. acpi_os_read_memory((acpi_physical_address)
  242. address +
  243. index *
  244. ACPI_DIV_8
  245. (access_width),
  246. &value64, access_width);
  247. value32 = (u32)value64;
  248. } else { /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
  249. status = acpi_hw_read_port((acpi_io_address)
  250. address +
  251. index *
  252. ACPI_DIV_8
  253. (access_width),
  254. &value32,
  255. access_width);
  256. }
  257. }
  258. /*
  259. * Use offset style bit writes because "Index * AccessWidth" is
  260. * ensured to be less than 32-bits by acpi_hw_validate_register().
  261. */
  262. ACPI_SET_BITS(value, index * access_width,
  263. ACPI_MASK_BITS_ABOVE_32(access_width), value32);
  264. bit_width -=
  265. bit_width > access_width ? access_width : bit_width;
  266. index++;
  267. }
  268. ACPI_DEBUG_PRINT((ACPI_DB_IO,
  269. "Read: %8.8X width %2d from %8.8X%8.8X (%s)\n",
  270. *value, access_width, ACPI_FORMAT_UINT64(address),
  271. acpi_ut_get_region_name(reg->space_id)));
  272. return (status);
  273. }
  274. /******************************************************************************
  275. *
  276. * FUNCTION: acpi_hw_write
  277. *
  278. * PARAMETERS: value - Value to be written
  279. * reg - GAS register structure
  280. *
  281. * RETURN: Status
  282. *
  283. * DESCRIPTION: Write to either memory or IO space. This is a 32-bit max
  284. * version of acpi_write, used internally since the overhead of
  285. * 64-bit values is not needed.
  286. *
  287. ******************************************************************************/
  288. acpi_status acpi_hw_write(u32 value, struct acpi_generic_address *reg)
  289. {
  290. u64 address;
  291. u8 access_width;
  292. u32 bit_width;
  293. u8 bit_offset;
  294. u64 value64;
  295. u32 value32;
  296. u8 index;
  297. acpi_status status;
  298. ACPI_FUNCTION_NAME(hw_write);
  299. /* Validate contents of the GAS register */
  300. status = acpi_hw_validate_register(reg, 32, &address);
  301. if (ACPI_FAILURE(status)) {
  302. return (status);
  303. }
  304. /* Convert access_width into number of bits based */
  305. access_width = acpi_hw_get_access_bit_width(address, reg, 32);
  306. bit_width = reg->bit_offset + reg->bit_width;
  307. bit_offset = reg->bit_offset;
  308. /*
  309. * Two address spaces supported: Memory or IO. PCI_Config is
  310. * not supported here because the GAS structure is insufficient
  311. */
  312. index = 0;
  313. while (bit_width) {
  314. /*
  315. * Use offset style bit reads because "Index * AccessWidth" is
  316. * ensured to be less than 32-bits by acpi_hw_validate_register().
  317. */
  318. value32 = ACPI_GET_BITS(&value, index * access_width,
  319. ACPI_MASK_BITS_ABOVE_32(access_width));
  320. if (bit_offset >= access_width) {
  321. bit_offset -= access_width;
  322. } else {
  323. if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
  324. value64 = (u64)value32;
  325. status =
  326. acpi_os_write_memory((acpi_physical_address)
  327. address +
  328. index *
  329. ACPI_DIV_8
  330. (access_width),
  331. value64, access_width);
  332. } else { /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
  333. status = acpi_hw_write_port((acpi_io_address)
  334. address +
  335. index *
  336. ACPI_DIV_8
  337. (access_width),
  338. value32,
  339. access_width);
  340. }
  341. }
  342. /*
  343. * Index * access_width is ensured to be less than 32-bits by
  344. * acpi_hw_validate_register().
  345. */
  346. bit_width -=
  347. bit_width > access_width ? access_width : bit_width;
  348. index++;
  349. }
  350. ACPI_DEBUG_PRINT((ACPI_DB_IO,
  351. "Wrote: %8.8X width %2d to %8.8X%8.8X (%s)\n",
  352. value, access_width, ACPI_FORMAT_UINT64(address),
  353. acpi_ut_get_region_name(reg->space_id)));
  354. return (status);
  355. }
  356. #if (!ACPI_REDUCED_HARDWARE)
  357. /*******************************************************************************
  358. *
  359. * FUNCTION: acpi_hw_clear_acpi_status
  360. *
  361. * PARAMETERS: None
  362. *
  363. * RETURN: Status
  364. *
  365. * DESCRIPTION: Clears all fixed and general purpose status bits
  366. *
  367. ******************************************************************************/
  368. acpi_status acpi_hw_clear_acpi_status(void)
  369. {
  370. acpi_status status;
  371. acpi_cpu_flags lock_flags = 0;
  372. ACPI_FUNCTION_TRACE(hw_clear_acpi_status);
  373. ACPI_DEBUG_PRINT((ACPI_DB_IO, "About to write %04X to %8.8X%8.8X\n",
  374. ACPI_BITMASK_ALL_FIXED_STATUS,
  375. ACPI_FORMAT_UINT64(acpi_gbl_xpm1a_status.address)));
  376. lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
  377. /* Clear the fixed events in PM1 A/B */
  378. status = acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS,
  379. ACPI_BITMASK_ALL_FIXED_STATUS);
  380. acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
  381. if (ACPI_FAILURE(status)) {
  382. goto exit;
  383. }
  384. /* Clear the GPE Bits in all GPE registers in all GPE blocks */
  385. status = acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block, NULL);
  386. exit:
  387. return_ACPI_STATUS(status);
  388. }
  389. /*******************************************************************************
  390. *
  391. * FUNCTION: acpi_hw_get_bit_register_info
  392. *
  393. * PARAMETERS: register_id - Index of ACPI Register to access
  394. *
  395. * RETURN: The bitmask to be used when accessing the register
  396. *
  397. * DESCRIPTION: Map register_id into a register bitmask.
  398. *
  399. ******************************************************************************/
  400. struct acpi_bit_register_info *acpi_hw_get_bit_register_info(u32 register_id)
  401. {
  402. ACPI_FUNCTION_ENTRY();
  403. if (register_id > ACPI_BITREG_MAX) {
  404. ACPI_ERROR((AE_INFO, "Invalid BitRegister ID: 0x%X",
  405. register_id));
  406. return (NULL);
  407. }
  408. return (&acpi_gbl_bit_register_info[register_id]);
  409. }
  410. /******************************************************************************
  411. *
  412. * FUNCTION: acpi_hw_write_pm1_control
  413. *
  414. * PARAMETERS: pm1a_control - Value to be written to PM1A control
  415. * pm1b_control - Value to be written to PM1B control
  416. *
  417. * RETURN: Status
  418. *
  419. * DESCRIPTION: Write the PM1 A/B control registers. These registers are
  420. * different than than the PM1 A/B status and enable registers
  421. * in that different values can be written to the A/B registers.
  422. * Most notably, the SLP_TYP bits can be different, as per the
  423. * values returned from the _Sx predefined methods.
  424. *
  425. ******************************************************************************/
  426. acpi_status acpi_hw_write_pm1_control(u32 pm1a_control, u32 pm1b_control)
  427. {
  428. acpi_status status;
  429. ACPI_FUNCTION_TRACE(hw_write_pm1_control);
  430. status =
  431. acpi_hw_write(pm1a_control, &acpi_gbl_FADT.xpm1a_control_block);
  432. if (ACPI_FAILURE(status)) {
  433. return_ACPI_STATUS(status);
  434. }
  435. if (acpi_gbl_FADT.xpm1b_control_block.address) {
  436. status =
  437. acpi_hw_write(pm1b_control,
  438. &acpi_gbl_FADT.xpm1b_control_block);
  439. }
  440. return_ACPI_STATUS(status);
  441. }
  442. /******************************************************************************
  443. *
  444. * FUNCTION: acpi_hw_register_read
  445. *
  446. * PARAMETERS: register_id - ACPI Register ID
  447. * return_value - Where the register value is returned
  448. *
  449. * RETURN: Status and the value read.
  450. *
  451. * DESCRIPTION: Read from the specified ACPI register
  452. *
  453. ******************************************************************************/
  454. acpi_status acpi_hw_register_read(u32 register_id, u32 *return_value)
  455. {
  456. u32 value = 0;
  457. acpi_status status;
  458. ACPI_FUNCTION_TRACE(hw_register_read);
  459. switch (register_id) {
  460. case ACPI_REGISTER_PM1_STATUS: /* PM1 A/B: 16-bit access each */
  461. status = acpi_hw_read_multiple(&value,
  462. &acpi_gbl_xpm1a_status,
  463. &acpi_gbl_xpm1b_status);
  464. break;
  465. case ACPI_REGISTER_PM1_ENABLE: /* PM1 A/B: 16-bit access each */
  466. status = acpi_hw_read_multiple(&value,
  467. &acpi_gbl_xpm1a_enable,
  468. &acpi_gbl_xpm1b_enable);
  469. break;
  470. case ACPI_REGISTER_PM1_CONTROL: /* PM1 A/B: 16-bit access each */
  471. status = acpi_hw_read_multiple(&value,
  472. &acpi_gbl_FADT.
  473. xpm1a_control_block,
  474. &acpi_gbl_FADT.
  475. xpm1b_control_block);
  476. /*
  477. * Zero the write-only bits. From the ACPI specification, "Hardware
  478. * Write-Only Bits": "Upon reads to registers with write-only bits,
  479. * software masks out all write-only bits."
  480. */
  481. value &= ~ACPI_PM1_CONTROL_WRITEONLY_BITS;
  482. break;
  483. case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
  484. status =
  485. acpi_hw_read(&value, &acpi_gbl_FADT.xpm2_control_block);
  486. break;
  487. case ACPI_REGISTER_PM_TIMER: /* 32-bit access */
  488. status = acpi_hw_read(&value, &acpi_gbl_FADT.xpm_timer_block);
  489. break;
  490. case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */
  491. status =
  492. acpi_hw_read_port(acpi_gbl_FADT.smi_command, &value, 8);
  493. break;
  494. default:
  495. ACPI_ERROR((AE_INFO, "Unknown Register ID: 0x%X", register_id));
  496. status = AE_BAD_PARAMETER;
  497. break;
  498. }
  499. if (ACPI_SUCCESS(status)) {
  500. *return_value = value;
  501. }
  502. return_ACPI_STATUS(status);
  503. }
  504. /******************************************************************************
  505. *
  506. * FUNCTION: acpi_hw_register_write
  507. *
  508. * PARAMETERS: register_id - ACPI Register ID
  509. * value - The value to write
  510. *
  511. * RETURN: Status
  512. *
  513. * DESCRIPTION: Write to the specified ACPI register
  514. *
  515. * NOTE: In accordance with the ACPI specification, this function automatically
  516. * preserves the value of the following bits, meaning that these bits cannot be
  517. * changed via this interface:
  518. *
  519. * PM1_CONTROL[0] = SCI_EN
  520. * PM1_CONTROL[9]
  521. * PM1_STATUS[11]
  522. *
  523. * ACPI References:
  524. * 1) Hardware Ignored Bits: When software writes to a register with ignored
  525. * bit fields, it preserves the ignored bit fields
  526. * 2) SCI_EN: OSPM always preserves this bit position
  527. *
  528. ******************************************************************************/
  529. acpi_status acpi_hw_register_write(u32 register_id, u32 value)
  530. {
  531. acpi_status status;
  532. u32 read_value;
  533. ACPI_FUNCTION_TRACE(hw_register_write);
  534. switch (register_id) {
  535. case ACPI_REGISTER_PM1_STATUS: /* PM1 A/B: 16-bit access each */
  536. /*
  537. * Handle the "ignored" bit in PM1 Status. According to the ACPI
  538. * specification, ignored bits are to be preserved when writing.
  539. * Normally, this would mean a read/modify/write sequence. However,
  540. * preserving a bit in the status register is different. Writing a
  541. * one clears the status, and writing a zero preserves the status.
  542. * Therefore, we must always write zero to the ignored bit.
  543. *
  544. * This behavior is clarified in the ACPI 4.0 specification.
  545. */
  546. value &= ~ACPI_PM1_STATUS_PRESERVED_BITS;
  547. status = acpi_hw_write_multiple(value,
  548. &acpi_gbl_xpm1a_status,
  549. &acpi_gbl_xpm1b_status);
  550. break;
  551. case ACPI_REGISTER_PM1_ENABLE: /* PM1 A/B: 16-bit access each */
  552. status = acpi_hw_write_multiple(value,
  553. &acpi_gbl_xpm1a_enable,
  554. &acpi_gbl_xpm1b_enable);
  555. break;
  556. case ACPI_REGISTER_PM1_CONTROL: /* PM1 A/B: 16-bit access each */
  557. /*
  558. * Perform a read first to preserve certain bits (per ACPI spec)
  559. * Note: This includes SCI_EN, we never want to change this bit
  560. */
  561. status = acpi_hw_read_multiple(&read_value,
  562. &acpi_gbl_FADT.
  563. xpm1a_control_block,
  564. &acpi_gbl_FADT.
  565. xpm1b_control_block);
  566. if (ACPI_FAILURE(status)) {
  567. goto exit;
  568. }
  569. /* Insert the bits to be preserved */
  570. ACPI_INSERT_BITS(value, ACPI_PM1_CONTROL_PRESERVED_BITS,
  571. read_value);
  572. /* Now we can write the data */
  573. status = acpi_hw_write_multiple(value,
  574. &acpi_gbl_FADT.
  575. xpm1a_control_block,
  576. &acpi_gbl_FADT.
  577. xpm1b_control_block);
  578. break;
  579. case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
  580. /*
  581. * For control registers, all reserved bits must be preserved,
  582. * as per the ACPI spec.
  583. */
  584. status =
  585. acpi_hw_read(&read_value,
  586. &acpi_gbl_FADT.xpm2_control_block);
  587. if (ACPI_FAILURE(status)) {
  588. goto exit;
  589. }
  590. /* Insert the bits to be preserved */
  591. ACPI_INSERT_BITS(value, ACPI_PM2_CONTROL_PRESERVED_BITS,
  592. read_value);
  593. status =
  594. acpi_hw_write(value, &acpi_gbl_FADT.xpm2_control_block);
  595. break;
  596. case ACPI_REGISTER_PM_TIMER: /* 32-bit access */
  597. status = acpi_hw_write(value, &acpi_gbl_FADT.xpm_timer_block);
  598. break;
  599. case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */
  600. /* SMI_CMD is currently always in IO space */
  601. status =
  602. acpi_hw_write_port(acpi_gbl_FADT.smi_command, value, 8);
  603. break;
  604. default:
  605. ACPI_ERROR((AE_INFO, "Unknown Register ID: 0x%X", register_id));
  606. status = AE_BAD_PARAMETER;
  607. break;
  608. }
  609. exit:
  610. return_ACPI_STATUS(status);
  611. }
  612. /******************************************************************************
  613. *
  614. * FUNCTION: acpi_hw_read_multiple
  615. *
  616. * PARAMETERS: value - Where the register value is returned
  617. * register_a - First ACPI register (required)
  618. * register_b - Second ACPI register (optional)
  619. *
  620. * RETURN: Status
  621. *
  622. * DESCRIPTION: Read from the specified two-part ACPI register (such as PM1 A/B)
  623. *
  624. ******************************************************************************/
  625. static acpi_status
  626. acpi_hw_read_multiple(u32 *value,
  627. struct acpi_generic_address *register_a,
  628. struct acpi_generic_address *register_b)
  629. {
  630. u32 value_a = 0;
  631. u32 value_b = 0;
  632. acpi_status status;
  633. /* The first register is always required */
  634. status = acpi_hw_read(&value_a, register_a);
  635. if (ACPI_FAILURE(status)) {
  636. return (status);
  637. }
  638. /* Second register is optional */
  639. if (register_b->address) {
  640. status = acpi_hw_read(&value_b, register_b);
  641. if (ACPI_FAILURE(status)) {
  642. return (status);
  643. }
  644. }
  645. /*
  646. * OR the two return values together. No shifting or masking is necessary,
  647. * because of how the PM1 registers are defined in the ACPI specification:
  648. *
  649. * "Although the bits can be split between the two register blocks (each
  650. * register block has a unique pointer within the FADT), the bit positions
  651. * are maintained. The register block with unimplemented bits (that is,
  652. * those implemented in the other register block) always returns zeros,
  653. * and writes have no side effects"
  654. */
  655. *value = (value_a | value_b);
  656. return (AE_OK);
  657. }
  658. /******************************************************************************
  659. *
  660. * FUNCTION: acpi_hw_write_multiple
  661. *
  662. * PARAMETERS: value - The value to write
  663. * register_a - First ACPI register (required)
  664. * register_b - Second ACPI register (optional)
  665. *
  666. * RETURN: Status
  667. *
  668. * DESCRIPTION: Write to the specified two-part ACPI register (such as PM1 A/B)
  669. *
  670. ******************************************************************************/
  671. static acpi_status
  672. acpi_hw_write_multiple(u32 value,
  673. struct acpi_generic_address *register_a,
  674. struct acpi_generic_address *register_b)
  675. {
  676. acpi_status status;
  677. /* The first register is always required */
  678. status = acpi_hw_write(value, register_a);
  679. if (ACPI_FAILURE(status)) {
  680. return (status);
  681. }
  682. /*
  683. * Second register is optional
  684. *
  685. * No bit shifting or clearing is necessary, because of how the PM1
  686. * registers are defined in the ACPI specification:
  687. *
  688. * "Although the bits can be split between the two register blocks (each
  689. * register block has a unique pointer within the FADT), the bit positions
  690. * are maintained. The register block with unimplemented bits (that is,
  691. * those implemented in the other register block) always returns zeros,
  692. * and writes have no side effects"
  693. */
  694. if (register_b->address) {
  695. status = acpi_hw_write(value, register_b);
  696. }
  697. return (status);
  698. }
  699. #endif /* !ACPI_REDUCED_HARDWARE */