hwregs.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  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 - 2016, 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(struct acpi_generic_address *reg,
  52. u8 max_bit_width);
  53. static acpi_status
  54. acpi_hw_read_multiple(u32 *value,
  55. struct acpi_generic_address *register_a,
  56. struct acpi_generic_address *register_b);
  57. static acpi_status
  58. acpi_hw_write_multiple(u32 value,
  59. struct acpi_generic_address *register_a,
  60. struct acpi_generic_address *register_b);
  61. #endif /* !ACPI_REDUCED_HARDWARE */
  62. /******************************************************************************
  63. *
  64. * FUNCTION: acpi_hw_get_access_bit_width
  65. *
  66. * PARAMETERS: reg - GAS register structure
  67. * max_bit_width - Max bit_width supported (32 or 64)
  68. *
  69. * RETURN: Status
  70. *
  71. * DESCRIPTION: Obtain optimal access bit width
  72. *
  73. ******************************************************************************/
  74. static u8
  75. acpi_hw_get_access_bit_width(struct acpi_generic_address *reg, u8 max_bit_width)
  76. {
  77. if (!reg->access_width) {
  78. if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
  79. max_bit_width = 32;
  80. }
  81. /*
  82. * Detect old register descriptors where only the bit_width field
  83. * makes senses.
  84. */
  85. if (reg->bit_width < max_bit_width &&
  86. !reg->bit_offset && reg->bit_width &&
  87. ACPI_IS_POWER_OF_TWO(reg->bit_width) &&
  88. ACPI_IS_ALIGNED(reg->bit_width, 8)) {
  89. return (reg->bit_width);
  90. }
  91. return (max_bit_width);
  92. } else {
  93. return (1 << (reg->access_width + 2));
  94. }
  95. }
  96. /******************************************************************************
  97. *
  98. * FUNCTION: acpi_hw_validate_register
  99. *
  100. * PARAMETERS: reg - GAS register structure
  101. * max_bit_width - Max bit_width supported (32 or 64)
  102. * address - Pointer to where the gas->address
  103. * is returned
  104. *
  105. * RETURN: Status
  106. *
  107. * DESCRIPTION: Validate the contents of a GAS register. Checks the GAS
  108. * pointer, Address, space_id, bit_width, and bit_offset.
  109. *
  110. ******************************************************************************/
  111. acpi_status
  112. acpi_hw_validate_register(struct acpi_generic_address *reg,
  113. u8 max_bit_width, u64 *address)
  114. {
  115. u8 bit_width;
  116. u8 access_width;
  117. /* Must have a valid pointer to a GAS structure */
  118. if (!reg) {
  119. return (AE_BAD_PARAMETER);
  120. }
  121. /*
  122. * Copy the target address. This handles possible alignment issues.
  123. * Address must not be null. A null address also indicates an optional
  124. * ACPI register that is not supported, so no error message.
  125. */
  126. ACPI_MOVE_64_TO_64(address, &reg->address);
  127. if (!(*address)) {
  128. return (AE_BAD_ADDRESS);
  129. }
  130. /* Validate the space_ID */
  131. if ((reg->space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY) &&
  132. (reg->space_id != ACPI_ADR_SPACE_SYSTEM_IO)) {
  133. ACPI_ERROR((AE_INFO,
  134. "Unsupported address space: 0x%X", reg->space_id));
  135. return (AE_SUPPORT);
  136. }
  137. /* Validate the access_width */
  138. if (reg->access_width > 4) {
  139. ACPI_ERROR((AE_INFO,
  140. "Unsupported register access width: 0x%X",
  141. reg->access_width));
  142. return (AE_SUPPORT);
  143. }
  144. /* Validate the bit_width, convert access_width into number of bits */
  145. access_width = acpi_hw_get_access_bit_width(reg, max_bit_width);
  146. bit_width =
  147. ACPI_ROUND_UP(reg->bit_offset + reg->bit_width, access_width);
  148. if (max_bit_width < bit_width) {
  149. ACPI_WARNING((AE_INFO,
  150. "Requested bit width 0x%X is smaller than register bit width 0x%X",
  151. max_bit_width, bit_width));
  152. return (AE_SUPPORT);
  153. }
  154. return (AE_OK);
  155. }
  156. /******************************************************************************
  157. *
  158. * FUNCTION: acpi_hw_read
  159. *
  160. * PARAMETERS: value - Where the value is returned
  161. * reg - GAS register structure
  162. *
  163. * RETURN: Status
  164. *
  165. * DESCRIPTION: Read from either memory or IO space. This is a 32-bit max
  166. * version of acpi_read, used internally since the overhead of
  167. * 64-bit values is not needed.
  168. *
  169. * LIMITATIONS: <These limitations also apply to acpi_hw_write>
  170. * space_ID must be system_memory or system_IO.
  171. *
  172. ******************************************************************************/
  173. acpi_status acpi_hw_read(u32 *value, struct acpi_generic_address *reg)
  174. {
  175. u64 address;
  176. u8 access_width;
  177. u32 bit_width;
  178. u8 bit_offset;
  179. u64 value64;
  180. u32 value32;
  181. u8 index;
  182. acpi_status status;
  183. ACPI_FUNCTION_NAME(hw_read);
  184. /* Validate contents of the GAS register */
  185. status = acpi_hw_validate_register(reg, 32, &address);
  186. if (ACPI_FAILURE(status)) {
  187. return (status);
  188. }
  189. /*
  190. * Initialize entire 32-bit return value to zero, convert access_width
  191. * into number of bits based
  192. */
  193. *value = 0;
  194. access_width = acpi_hw_get_access_bit_width(reg, 32);
  195. bit_width = reg->bit_offset + reg->bit_width;
  196. bit_offset = reg->bit_offset;
  197. /*
  198. * Two address spaces supported: Memory or IO. PCI_Config is
  199. * not supported here because the GAS structure is insufficient
  200. */
  201. index = 0;
  202. while (bit_width) {
  203. if (bit_offset >= access_width) {
  204. value32 = 0;
  205. bit_offset -= access_width;
  206. } else {
  207. if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
  208. status =
  209. acpi_os_read_memory((acpi_physical_address)
  210. address +
  211. index *
  212. ACPI_DIV_8
  213. (access_width),
  214. &value64, access_width);
  215. value32 = (u32)value64;
  216. } else { /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
  217. status = acpi_hw_read_port((acpi_io_address)
  218. address +
  219. index *
  220. ACPI_DIV_8
  221. (access_width),
  222. &value32,
  223. access_width);
  224. }
  225. /*
  226. * Use offset style bit masks because:
  227. * bit_offset < access_width/bit_width < access_width, and
  228. * access_width is ensured to be less than 32-bits by
  229. * acpi_hw_validate_register().
  230. */
  231. if (bit_offset) {
  232. value32 &= ACPI_MASK_BITS_BELOW(bit_offset);
  233. bit_offset = 0;
  234. }
  235. if (bit_width < access_width) {
  236. value32 &= ACPI_MASK_BITS_ABOVE(bit_width);
  237. }
  238. }
  239. /*
  240. * Use offset style bit writes because "Index * AccessWidth" is
  241. * ensured to be less than 32-bits by acpi_hw_validate_register().
  242. */
  243. ACPI_SET_BITS(value, index * access_width,
  244. ACPI_MASK_BITS_ABOVE_32(access_width), value32);
  245. bit_width -=
  246. bit_width > access_width ? access_width : bit_width;
  247. index++;
  248. }
  249. ACPI_DEBUG_PRINT((ACPI_DB_IO,
  250. "Read: %8.8X width %2d from %8.8X%8.8X (%s)\n",
  251. *value, access_width, ACPI_FORMAT_UINT64(address),
  252. acpi_ut_get_region_name(reg->space_id)));
  253. return (status);
  254. }
  255. /******************************************************************************
  256. *
  257. * FUNCTION: acpi_hw_write
  258. *
  259. * PARAMETERS: value - Value to be written
  260. * reg - GAS register structure
  261. *
  262. * RETURN: Status
  263. *
  264. * DESCRIPTION: Write to either memory or IO space. This is a 32-bit max
  265. * version of acpi_write, used internally since the overhead of
  266. * 64-bit values is not needed.
  267. *
  268. ******************************************************************************/
  269. acpi_status acpi_hw_write(u32 value, struct acpi_generic_address *reg)
  270. {
  271. u64 address;
  272. acpi_status status;
  273. ACPI_FUNCTION_NAME(hw_write);
  274. /* Validate contents of the GAS register */
  275. status = acpi_hw_validate_register(reg, 32, &address);
  276. if (ACPI_FAILURE(status)) {
  277. return (status);
  278. }
  279. /*
  280. * Two address spaces supported: Memory or IO. PCI_Config is
  281. * not supported here because the GAS structure is insufficient
  282. */
  283. if (reg->space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
  284. status = acpi_os_write_memory((acpi_physical_address)
  285. address, (u64)value,
  286. reg->bit_width);
  287. } else { /* ACPI_ADR_SPACE_SYSTEM_IO, validated earlier */
  288. status = acpi_hw_write_port((acpi_io_address)
  289. address, value, reg->bit_width);
  290. }
  291. ACPI_DEBUG_PRINT((ACPI_DB_IO,
  292. "Wrote: %8.8X width %2d to %8.8X%8.8X (%s)\n",
  293. value, reg->bit_width, ACPI_FORMAT_UINT64(address),
  294. acpi_ut_get_region_name(reg->space_id)));
  295. return (status);
  296. }
  297. #if (!ACPI_REDUCED_HARDWARE)
  298. /*******************************************************************************
  299. *
  300. * FUNCTION: acpi_hw_clear_acpi_status
  301. *
  302. * PARAMETERS: None
  303. *
  304. * RETURN: Status
  305. *
  306. * DESCRIPTION: Clears all fixed and general purpose status bits
  307. *
  308. ******************************************************************************/
  309. acpi_status acpi_hw_clear_acpi_status(void)
  310. {
  311. acpi_status status;
  312. acpi_cpu_flags lock_flags = 0;
  313. ACPI_FUNCTION_TRACE(hw_clear_acpi_status);
  314. ACPI_DEBUG_PRINT((ACPI_DB_IO, "About to write %04X to %8.8X%8.8X\n",
  315. ACPI_BITMASK_ALL_FIXED_STATUS,
  316. ACPI_FORMAT_UINT64(acpi_gbl_xpm1a_status.address)));
  317. lock_flags = acpi_os_acquire_lock(acpi_gbl_hardware_lock);
  318. /* Clear the fixed events in PM1 A/B */
  319. status = acpi_hw_register_write(ACPI_REGISTER_PM1_STATUS,
  320. ACPI_BITMASK_ALL_FIXED_STATUS);
  321. acpi_os_release_lock(acpi_gbl_hardware_lock, lock_flags);
  322. if (ACPI_FAILURE(status)) {
  323. goto exit;
  324. }
  325. /* Clear the GPE Bits in all GPE registers in all GPE blocks */
  326. status = acpi_ev_walk_gpe_list(acpi_hw_clear_gpe_block, NULL);
  327. exit:
  328. return_ACPI_STATUS(status);
  329. }
  330. /*******************************************************************************
  331. *
  332. * FUNCTION: acpi_hw_get_bit_register_info
  333. *
  334. * PARAMETERS: register_id - Index of ACPI Register to access
  335. *
  336. * RETURN: The bitmask to be used when accessing the register
  337. *
  338. * DESCRIPTION: Map register_id into a register bitmask.
  339. *
  340. ******************************************************************************/
  341. struct acpi_bit_register_info *acpi_hw_get_bit_register_info(u32 register_id)
  342. {
  343. ACPI_FUNCTION_ENTRY();
  344. if (register_id > ACPI_BITREG_MAX) {
  345. ACPI_ERROR((AE_INFO, "Invalid BitRegister ID: 0x%X",
  346. register_id));
  347. return (NULL);
  348. }
  349. return (&acpi_gbl_bit_register_info[register_id]);
  350. }
  351. /******************************************************************************
  352. *
  353. * FUNCTION: acpi_hw_write_pm1_control
  354. *
  355. * PARAMETERS: pm1a_control - Value to be written to PM1A control
  356. * pm1b_control - Value to be written to PM1B control
  357. *
  358. * RETURN: Status
  359. *
  360. * DESCRIPTION: Write the PM1 A/B control registers. These registers are
  361. * different than than the PM1 A/B status and enable registers
  362. * in that different values can be written to the A/B registers.
  363. * Most notably, the SLP_TYP bits can be different, as per the
  364. * values returned from the _Sx predefined methods.
  365. *
  366. ******************************************************************************/
  367. acpi_status acpi_hw_write_pm1_control(u32 pm1a_control, u32 pm1b_control)
  368. {
  369. acpi_status status;
  370. ACPI_FUNCTION_TRACE(hw_write_pm1_control);
  371. status =
  372. acpi_hw_write(pm1a_control, &acpi_gbl_FADT.xpm1a_control_block);
  373. if (ACPI_FAILURE(status)) {
  374. return_ACPI_STATUS(status);
  375. }
  376. if (acpi_gbl_FADT.xpm1b_control_block.address) {
  377. status =
  378. acpi_hw_write(pm1b_control,
  379. &acpi_gbl_FADT.xpm1b_control_block);
  380. }
  381. return_ACPI_STATUS(status);
  382. }
  383. /******************************************************************************
  384. *
  385. * FUNCTION: acpi_hw_register_read
  386. *
  387. * PARAMETERS: register_id - ACPI Register ID
  388. * return_value - Where the register value is returned
  389. *
  390. * RETURN: Status and the value read.
  391. *
  392. * DESCRIPTION: Read from the specified ACPI register
  393. *
  394. ******************************************************************************/
  395. acpi_status acpi_hw_register_read(u32 register_id, u32 *return_value)
  396. {
  397. u32 value = 0;
  398. acpi_status status;
  399. ACPI_FUNCTION_TRACE(hw_register_read);
  400. switch (register_id) {
  401. case ACPI_REGISTER_PM1_STATUS: /* PM1 A/B: 16-bit access each */
  402. status = acpi_hw_read_multiple(&value,
  403. &acpi_gbl_xpm1a_status,
  404. &acpi_gbl_xpm1b_status);
  405. break;
  406. case ACPI_REGISTER_PM1_ENABLE: /* PM1 A/B: 16-bit access each */
  407. status = acpi_hw_read_multiple(&value,
  408. &acpi_gbl_xpm1a_enable,
  409. &acpi_gbl_xpm1b_enable);
  410. break;
  411. case ACPI_REGISTER_PM1_CONTROL: /* PM1 A/B: 16-bit access each */
  412. status = acpi_hw_read_multiple(&value,
  413. &acpi_gbl_FADT.
  414. xpm1a_control_block,
  415. &acpi_gbl_FADT.
  416. xpm1b_control_block);
  417. /*
  418. * Zero the write-only bits. From the ACPI specification, "Hardware
  419. * Write-Only Bits": "Upon reads to registers with write-only bits,
  420. * software masks out all write-only bits."
  421. */
  422. value &= ~ACPI_PM1_CONTROL_WRITEONLY_BITS;
  423. break;
  424. case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
  425. status =
  426. acpi_hw_read(&value, &acpi_gbl_FADT.xpm2_control_block);
  427. break;
  428. case ACPI_REGISTER_PM_TIMER: /* 32-bit access */
  429. status = acpi_hw_read(&value, &acpi_gbl_FADT.xpm_timer_block);
  430. break;
  431. case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */
  432. status =
  433. acpi_hw_read_port(acpi_gbl_FADT.smi_command, &value, 8);
  434. break;
  435. default:
  436. ACPI_ERROR((AE_INFO, "Unknown Register ID: 0x%X", register_id));
  437. status = AE_BAD_PARAMETER;
  438. break;
  439. }
  440. if (ACPI_SUCCESS(status)) {
  441. *return_value = value;
  442. }
  443. return_ACPI_STATUS(status);
  444. }
  445. /******************************************************************************
  446. *
  447. * FUNCTION: acpi_hw_register_write
  448. *
  449. * PARAMETERS: register_id - ACPI Register ID
  450. * value - The value to write
  451. *
  452. * RETURN: Status
  453. *
  454. * DESCRIPTION: Write to the specified ACPI register
  455. *
  456. * NOTE: In accordance with the ACPI specification, this function automatically
  457. * preserves the value of the following bits, meaning that these bits cannot be
  458. * changed via this interface:
  459. *
  460. * PM1_CONTROL[0] = SCI_EN
  461. * PM1_CONTROL[9]
  462. * PM1_STATUS[11]
  463. *
  464. * ACPI References:
  465. * 1) Hardware Ignored Bits: When software writes to a register with ignored
  466. * bit fields, it preserves the ignored bit fields
  467. * 2) SCI_EN: OSPM always preserves this bit position
  468. *
  469. ******************************************************************************/
  470. acpi_status acpi_hw_register_write(u32 register_id, u32 value)
  471. {
  472. acpi_status status;
  473. u32 read_value;
  474. ACPI_FUNCTION_TRACE(hw_register_write);
  475. switch (register_id) {
  476. case ACPI_REGISTER_PM1_STATUS: /* PM1 A/B: 16-bit access each */
  477. /*
  478. * Handle the "ignored" bit in PM1 Status. According to the ACPI
  479. * specification, ignored bits are to be preserved when writing.
  480. * Normally, this would mean a read/modify/write sequence. However,
  481. * preserving a bit in the status register is different. Writing a
  482. * one clears the status, and writing a zero preserves the status.
  483. * Therefore, we must always write zero to the ignored bit.
  484. *
  485. * This behavior is clarified in the ACPI 4.0 specification.
  486. */
  487. value &= ~ACPI_PM1_STATUS_PRESERVED_BITS;
  488. status = acpi_hw_write_multiple(value,
  489. &acpi_gbl_xpm1a_status,
  490. &acpi_gbl_xpm1b_status);
  491. break;
  492. case ACPI_REGISTER_PM1_ENABLE: /* PM1 A/B: 16-bit access each */
  493. status = acpi_hw_write_multiple(value,
  494. &acpi_gbl_xpm1a_enable,
  495. &acpi_gbl_xpm1b_enable);
  496. break;
  497. case ACPI_REGISTER_PM1_CONTROL: /* PM1 A/B: 16-bit access each */
  498. /*
  499. * Perform a read first to preserve certain bits (per ACPI spec)
  500. * Note: This includes SCI_EN, we never want to change this bit
  501. */
  502. status = acpi_hw_read_multiple(&read_value,
  503. &acpi_gbl_FADT.
  504. xpm1a_control_block,
  505. &acpi_gbl_FADT.
  506. xpm1b_control_block);
  507. if (ACPI_FAILURE(status)) {
  508. goto exit;
  509. }
  510. /* Insert the bits to be preserved */
  511. ACPI_INSERT_BITS(value, ACPI_PM1_CONTROL_PRESERVED_BITS,
  512. read_value);
  513. /* Now we can write the data */
  514. status = acpi_hw_write_multiple(value,
  515. &acpi_gbl_FADT.
  516. xpm1a_control_block,
  517. &acpi_gbl_FADT.
  518. xpm1b_control_block);
  519. break;
  520. case ACPI_REGISTER_PM2_CONTROL: /* 8-bit access */
  521. /*
  522. * For control registers, all reserved bits must be preserved,
  523. * as per the ACPI spec.
  524. */
  525. status =
  526. acpi_hw_read(&read_value,
  527. &acpi_gbl_FADT.xpm2_control_block);
  528. if (ACPI_FAILURE(status)) {
  529. goto exit;
  530. }
  531. /* Insert the bits to be preserved */
  532. ACPI_INSERT_BITS(value, ACPI_PM2_CONTROL_PRESERVED_BITS,
  533. read_value);
  534. status =
  535. acpi_hw_write(value, &acpi_gbl_FADT.xpm2_control_block);
  536. break;
  537. case ACPI_REGISTER_PM_TIMER: /* 32-bit access */
  538. status = acpi_hw_write(value, &acpi_gbl_FADT.xpm_timer_block);
  539. break;
  540. case ACPI_REGISTER_SMI_COMMAND_BLOCK: /* 8-bit access */
  541. /* SMI_CMD is currently always in IO space */
  542. status =
  543. acpi_hw_write_port(acpi_gbl_FADT.smi_command, value, 8);
  544. break;
  545. default:
  546. ACPI_ERROR((AE_INFO, "Unknown Register ID: 0x%X", register_id));
  547. status = AE_BAD_PARAMETER;
  548. break;
  549. }
  550. exit:
  551. return_ACPI_STATUS(status);
  552. }
  553. /******************************************************************************
  554. *
  555. * FUNCTION: acpi_hw_read_multiple
  556. *
  557. * PARAMETERS: value - Where the register value is returned
  558. * register_a - First ACPI register (required)
  559. * register_b - Second ACPI register (optional)
  560. *
  561. * RETURN: Status
  562. *
  563. * DESCRIPTION: Read from the specified two-part ACPI register (such as PM1 A/B)
  564. *
  565. ******************************************************************************/
  566. static acpi_status
  567. acpi_hw_read_multiple(u32 *value,
  568. struct acpi_generic_address *register_a,
  569. struct acpi_generic_address *register_b)
  570. {
  571. u32 value_a = 0;
  572. u32 value_b = 0;
  573. acpi_status status;
  574. /* The first register is always required */
  575. status = acpi_hw_read(&value_a, register_a);
  576. if (ACPI_FAILURE(status)) {
  577. return (status);
  578. }
  579. /* Second register is optional */
  580. if (register_b->address) {
  581. status = acpi_hw_read(&value_b, register_b);
  582. if (ACPI_FAILURE(status)) {
  583. return (status);
  584. }
  585. }
  586. /*
  587. * OR the two return values together. No shifting or masking is necessary,
  588. * because of how the PM1 registers are defined in the ACPI specification:
  589. *
  590. * "Although the bits can be split between the two register blocks (each
  591. * register block has a unique pointer within the FADT), the bit positions
  592. * are maintained. The register block with unimplemented bits (that is,
  593. * those implemented in the other register block) always returns zeros,
  594. * and writes have no side effects"
  595. */
  596. *value = (value_a | value_b);
  597. return (AE_OK);
  598. }
  599. /******************************************************************************
  600. *
  601. * FUNCTION: acpi_hw_write_multiple
  602. *
  603. * PARAMETERS: value - The value to write
  604. * register_a - First ACPI register (required)
  605. * register_b - Second ACPI register (optional)
  606. *
  607. * RETURN: Status
  608. *
  609. * DESCRIPTION: Write to the specified two-part ACPI register (such as PM1 A/B)
  610. *
  611. ******************************************************************************/
  612. static acpi_status
  613. acpi_hw_write_multiple(u32 value,
  614. struct acpi_generic_address *register_a,
  615. struct acpi_generic_address *register_b)
  616. {
  617. acpi_status status;
  618. /* The first register is always required */
  619. status = acpi_hw_write(value, register_a);
  620. if (ACPI_FAILURE(status)) {
  621. return (status);
  622. }
  623. /*
  624. * Second register is optional
  625. *
  626. * No bit shifting or clearing is necessary, because of how the PM1
  627. * registers are defined in the ACPI specification:
  628. *
  629. * "Although the bits can be split between the two register blocks (each
  630. * register block has a unique pointer within the FADT), the bit positions
  631. * are maintained. The register block with unimplemented bits (that is,
  632. * those implemented in the other register block) always returns zeros,
  633. * and writes have no side effects"
  634. */
  635. if (register_b->address) {
  636. status = acpi_hw_write(value, register_b);
  637. }
  638. return (status);
  639. }
  640. #endif /* !ACPI_REDUCED_HARDWARE */