acpigen.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Core ACPI (Advanced Configuration and Power Interface) support
  4. *
  5. * Copyright 2019 Google LLC
  6. *
  7. * Modified from coreboot file acpigen.h
  8. */
  9. #ifndef __ACPI_ACPIGEN_H
  10. #define __ACPI_ACPIGEN_H
  11. #include <acpi/acpi_table.h>
  12. #include <linux/types.h>
  13. struct acpi_cstate;
  14. struct acpi_ctx;
  15. struct acpi_gen_regaddr;
  16. struct acpi_gpio;
  17. /* Top 4 bits of the value used to indicate a three-byte length value */
  18. #define ACPI_PKG_LEN_3_BYTES 0x80
  19. #define ACPI_METHOD_NARGS_MASK 0x7
  20. #define ACPI_METHOD_SERIALIZED_MASK BIT(3)
  21. #define ACPI_END_TAG 0x79
  22. /* ACPI Op/Prefix codes */
  23. enum {
  24. ZERO_OP = 0x00,
  25. ONE_OP = 0x01,
  26. NAME_OP = 0x08,
  27. BYTE_PREFIX = 0x0a,
  28. WORD_PREFIX = 0x0b,
  29. DWORD_PREFIX = 0x0c,
  30. STRING_PREFIX = 0x0d,
  31. QWORD_PREFIX = 0x0e,
  32. SCOPE_OP = 0x10,
  33. BUFFER_OP = 0x11,
  34. PACKAGE_OP = 0x12,
  35. METHOD_OP = 0x14,
  36. SLEEP_OP = 0x22,
  37. DUAL_NAME_PREFIX = 0x2e,
  38. MULTI_NAME_PREFIX = 0x2f,
  39. DEBUG_OP = 0x31,
  40. EXT_OP_PREFIX = 0x5b,
  41. ROOT_PREFIX = 0x5c,
  42. LOCAL0_OP = 0x60,
  43. LOCAL1_OP = 0x61,
  44. LOCAL2_OP = 0x62,
  45. LOCAL3_OP = 0x63,
  46. LOCAL4_OP = 0x64,
  47. LOCAL5_OP = 0x65,
  48. LOCAL6_OP = 0x66,
  49. LOCAL7_OP = 0x67,
  50. ARG0_OP = 0x68,
  51. ARG1_OP = 0x69,
  52. ARG2_OP = 0x6a,
  53. ARG3_OP = 0x6b,
  54. ARG4_OP = 0x6c,
  55. ARG5_OP = 0x6d,
  56. ARG6_OP = 0x6e,
  57. STORE_OP = 0x70,
  58. AND_OP = 0x7b,
  59. OR_OP = 0x7d,
  60. NOT_OP = 0x80,
  61. DEVICE_OP = 0x82,
  62. PROCESSOR_OP = 0x83,
  63. POWER_RES_OP = 0x84,
  64. NOTIFY_OP = 0x86,
  65. LEQUAL_OP = 0x93,
  66. TO_BUFFER_OP = 0x96,
  67. TO_INTEGER_OP = 0x99,
  68. IF_OP = 0xa0,
  69. ELSE_OP = 0xa1,
  70. RETURN_OP = 0xa4,
  71. };
  72. /**
  73. * enum psd_coord - Coordination types for P-states
  74. *
  75. * The type of coordination that exists (hardware) or is required (software) as
  76. * a result of the underlying hardware dependency
  77. */
  78. enum psd_coord {
  79. SW_ALL = 0xfc,
  80. SW_ANY = 0xfd,
  81. HW_ALL = 0xfe
  82. };
  83. /**
  84. * enum csd_coord - Coordination types for C-states
  85. *
  86. * The type of coordination that exists (hardware) or is required (software) as
  87. * a result of the underlying hardware dependency
  88. */
  89. enum csd_coord {
  90. CSD_HW_ALL = 0xfe,
  91. };
  92. /**
  93. * struct acpi_cstate - Information about a C-State
  94. *
  95. * @ctype: C State type (1=C1, 2=C2, 3=C3)
  96. * @latency: Worst-case latency to enter and exit the C State (in uS)
  97. * @power: Average power consumption of the processor when in this C-State (mW)
  98. * @resource: Register to read to place the processor in this state
  99. */
  100. struct acpi_cstate {
  101. uint ctype;
  102. uint latency;
  103. uint power;
  104. struct acpi_gen_regaddr resource;
  105. };
  106. /**
  107. * struct acpi_tstate - Information about a Throttling Supported State
  108. *
  109. * See ACPI v6.3 section 8.4.5.2: _TSS (Throttling Supported States)
  110. *
  111. * @percent: Percent of the core CPU operating frequency that will be
  112. * available when this throttling state is invoked
  113. * @power: Throttling state’s maximum power dissipation (mw)
  114. * @latency: Worst-case latency (uS) that the CPU is unavailable during a
  115. * transition from any throttling state to this throttling state
  116. * @control: Value to be written to the Processor Control Register
  117. * (THROTTLE_CTRL) to initiate a transition to this throttling state
  118. * @status: Value in THROTTLE_STATUS when in this state
  119. */
  120. struct acpi_tstate {
  121. uint percent;
  122. uint power;
  123. uint latency;
  124. uint control;
  125. uint status;
  126. };
  127. /**
  128. * acpigen_get_current() - Get the current ACPI code output pointer
  129. *
  130. * @ctx: ACPI context pointer
  131. * @return output pointer
  132. */
  133. u8 *acpigen_get_current(struct acpi_ctx *ctx);
  134. /**
  135. * acpigen_emit_byte() - Emit a byte to the ACPI code
  136. *
  137. * @ctx: ACPI context pointer
  138. * @data: Value to output
  139. */
  140. void acpigen_emit_byte(struct acpi_ctx *ctx, uint data);
  141. /**
  142. * acpigen_emit_word() - Emit a 16-bit word to the ACPI code
  143. *
  144. * @ctx: ACPI context pointer
  145. * @data: Value to output
  146. */
  147. void acpigen_emit_word(struct acpi_ctx *ctx, uint data);
  148. /**
  149. * acpigen_emit_dword() - Emit a 32-bit 'double word' to the ACPI code
  150. *
  151. * @ctx: ACPI context pointer
  152. * @data: Value to output
  153. */
  154. void acpigen_emit_dword(struct acpi_ctx *ctx, uint data);
  155. /**
  156. * acpigen_emit_stream() - Emit a stream of bytes
  157. *
  158. * @ctx: ACPI context pointer
  159. * @data: Data to output
  160. * @size: Size of data in bytes
  161. */
  162. void acpigen_emit_stream(struct acpi_ctx *ctx, const char *data, int size);
  163. /**
  164. * acpigen_emit_string() - Emit a string
  165. *
  166. * Emit a string with a null terminator
  167. *
  168. * @ctx: ACPI context pointer
  169. * @str: String to output, or NULL for an empty string
  170. */
  171. void acpigen_emit_string(struct acpi_ctx *ctx, const char *str);
  172. /**
  173. * acpigen_write_len_f() - Write a 'forward' length placeholder
  174. *
  175. * This adds space for a length value in the ACPI stream and pushes the current
  176. * position (before the length) on the stack. After calling this you can write
  177. * some data and then call acpigen_pop_len() to update the length value.
  178. *
  179. * Usage:
  180. *
  181. * acpigen_write_len_f() ------\
  182. * acpigen_write...() |
  183. * acpigen_write...() |
  184. * acpigen_write_len_f() --\ |
  185. * acpigen_write...() | |
  186. * acpigen_write...() | |
  187. * acpigen_pop_len() ------/ |
  188. * acpigen_write...() |
  189. * acpigen_pop_len() ----------/
  190. *
  191. * See ACPI 6.3 section 20.2.4 Package Length Encoding
  192. *
  193. * This implementation always uses a 3-byte packet length for simplicity. It
  194. * could be adjusted to support other lengths.
  195. *
  196. * @ctx: ACPI context pointer
  197. */
  198. void acpigen_write_len_f(struct acpi_ctx *ctx);
  199. /**
  200. * acpigen_pop_len() - Update the previously stacked length placeholder
  201. *
  202. * Call this after the data for the block has been written. It updates the
  203. * top length value in the stack and pops it off.
  204. *
  205. * @ctx: ACPI context pointer
  206. */
  207. void acpigen_pop_len(struct acpi_ctx *ctx);
  208. /**
  209. * acpigen_write_package() - Start writing a package
  210. *
  211. * A package collects together a number of elements in the ACPI code. To write
  212. * a package use:
  213. *
  214. * acpigen_write_package(ctx, 3);
  215. * ...write things
  216. * acpigen_pop_len()
  217. *
  218. * If you don't know the number of elements in advance, acpigen_write_package()
  219. * returns a pointer to the value so you can update it later:
  220. *
  221. * char *num_elements = acpigen_write_package(ctx, 0);
  222. * ...write things
  223. * *num_elements += 1;
  224. * ...write things
  225. * *num_elements += 1;
  226. * acpigen_pop_len()
  227. *
  228. * @ctx: ACPI context pointer
  229. * @nr_el: Number of elements (0 if not known)
  230. * @returns pointer to the number of elements, which can be updated by the
  231. * caller if needed
  232. */
  233. char *acpigen_write_package(struct acpi_ctx *ctx, int nr_el);
  234. /**
  235. * acpigen_write_byte() - Write a byte
  236. *
  237. * @ctx: ACPI context pointer
  238. * @data: Value to write
  239. */
  240. void acpigen_write_byte(struct acpi_ctx *ctx, unsigned int data);
  241. /**
  242. * acpigen_write_word() - Write a word
  243. *
  244. * @ctx: ACPI context pointer
  245. * @data: Value to write
  246. */
  247. void acpigen_write_word(struct acpi_ctx *ctx, unsigned int data);
  248. /**
  249. * acpigen_write_dword() - Write a dword
  250. *
  251. * @ctx: ACPI context pointer
  252. * @data: Value to write
  253. */
  254. void acpigen_write_dword(struct acpi_ctx *ctx, unsigned int data);
  255. /**
  256. * acpigen_write_qword() - Write a qword
  257. *
  258. * @ctx: ACPI context pointer
  259. * @data: Value to write
  260. */
  261. void acpigen_write_qword(struct acpi_ctx *ctx, u64 data);
  262. /**
  263. * acpigen_write_zero() - Write zero
  264. *
  265. * @ctx: ACPI context pointer
  266. */
  267. void acpigen_write_zero(struct acpi_ctx *ctx);
  268. /**
  269. * acpigen_write_one() - Write one
  270. *
  271. * @ctx: ACPI context pointer
  272. */
  273. void acpigen_write_one(struct acpi_ctx *ctx);
  274. /**
  275. * acpigen_write_integer() - Write an integer
  276. *
  277. * This writes an operation (BYTE_OP, WORD_OP, DWORD_OP, QWORD_OP depending on
  278. * the integer size) and an integer value. Note that WORD means 16 bits in ACPI.
  279. *
  280. * @ctx: ACPI context pointer
  281. * @data: Integer to write
  282. */
  283. void acpigen_write_integer(struct acpi_ctx *ctx, u64 data);
  284. /**
  285. * acpigen_write_name_zero() - Write a named zero value
  286. *
  287. * @ctx: ACPI context pointer
  288. * @name: Name of the value
  289. */
  290. void acpigen_write_name_zero(struct acpi_ctx *ctx, const char *name);
  291. /**
  292. * acpigen_write_name_one() - Write a named one value
  293. *
  294. * @ctx: ACPI context pointer
  295. * @name: Name of the value
  296. */
  297. void acpigen_write_name_one(struct acpi_ctx *ctx, const char *name);
  298. /**
  299. * acpigen_write_name_byte() - Write a named byte value
  300. *
  301. * @ctx: ACPI context pointer
  302. * @name: Name of the value
  303. * @val: Value to write
  304. */
  305. void acpigen_write_name_byte(struct acpi_ctx *ctx, const char *name, uint val);
  306. /**
  307. * acpigen_write_name_word() - Write a named word value
  308. *
  309. * @ctx: ACPI context pointer
  310. * @name: Name of the value
  311. * @val: Value to write
  312. */
  313. void acpigen_write_name_word(struct acpi_ctx *ctx, const char *name, uint val);
  314. /**
  315. * acpigen_write_name_dword() - Write a named dword value
  316. *
  317. * @ctx: ACPI context pointer
  318. * @name: Name of the value
  319. * @val: Value to write
  320. */
  321. void acpigen_write_name_dword(struct acpi_ctx *ctx, const char *name, uint val);
  322. /**
  323. * acpigen_write_name_qword() - Write a named qword value
  324. *
  325. * @ctx: ACPI context pointer
  326. * @name: Name of the value
  327. * @val: Value to write
  328. */
  329. void acpigen_write_name_qword(struct acpi_ctx *ctx, const char *name, u64 val);
  330. /**
  331. * acpigen_write_name_integer() - Write a named integer value
  332. *
  333. * @ctx: ACPI context pointer
  334. * @name: Name of the value
  335. * @val: Value to write
  336. */
  337. void acpigen_write_name_integer(struct acpi_ctx *ctx, const char *name,
  338. u64 val);
  339. /**
  340. * acpigen_write_name_string() - Write a named string value
  341. *
  342. * @ctx: ACPI context pointer
  343. * @name: Name of the value
  344. * @string: String to write
  345. */
  346. void acpigen_write_name_string(struct acpi_ctx *ctx, const char *name,
  347. const char *string);
  348. /**
  349. * acpigen_write_string() - Write a string
  350. *
  351. * This writes a STRING_PREFIX followed by a null-terminated string
  352. *
  353. * @ctx: ACPI context pointer
  354. * @str: String to write
  355. */
  356. void acpigen_write_string(struct acpi_ctx *ctx, const char *str);
  357. /**
  358. * acpigen_emit_namestring() - Emit an ACPI name
  359. *
  360. * This writes out an ACPI name or path in the required special format. It does
  361. * not add the NAME_OP prefix.
  362. *
  363. * @ctx: ACPI context pointer
  364. * @namepath: Name / path to emit
  365. */
  366. void acpigen_emit_namestring(struct acpi_ctx *ctx, const char *namepath);
  367. /**
  368. * acpigen_write_name() - Write out an ACPI name
  369. *
  370. * This writes out an ACPI name or path in the required special format with a
  371. * NAME_OP prefix.
  372. *
  373. * @ctx: ACPI context pointer
  374. * @namepath: Name / path to emit
  375. */
  376. void acpigen_write_name(struct acpi_ctx *ctx, const char *namepath);
  377. /**
  378. * acpigen_write_scope() - Write a scope
  379. *
  380. * @ctx: ACPI context pointer
  381. * @scope: Scope to write (e.g. "\\_SB.ABCD")
  382. */
  383. void acpigen_write_scope(struct acpi_ctx *ctx, const char *scope);
  384. /**
  385. * acpigen_write_uuid() - Write a UUID
  386. *
  387. * This writes out a UUID in the format used by ACPI, with a BUFFER_OP prefix.
  388. *
  389. * @ctx: ACPI context pointer
  390. * @uuid: UUID to write in the form aabbccdd-eeff-gghh-iijj-kkllmmnnoopp
  391. * @return 0 if OK, -EINVAL if the format is incorrect
  392. */
  393. int acpigen_write_uuid(struct acpi_ctx *ctx, const char *uuid);
  394. /**
  395. * acpigen_emit_ext_op() - Emit an extended op with the EXT_OP_PREFIX prefix
  396. *
  397. * @ctx: ACPI context pointer
  398. * @op: Operation code (e.g. SLEEP_OP)
  399. */
  400. void acpigen_emit_ext_op(struct acpi_ctx *ctx, uint op);
  401. /**
  402. * acpigen_write_method() - Write a method header
  403. *
  404. * @ctx: ACPI context pointer
  405. * @name: Method name (4 characters)
  406. * @nargs: Number of method arguments (0 if none)
  407. */
  408. void acpigen_write_method(struct acpi_ctx *ctx, const char *name, int nargs);
  409. /**
  410. * acpigen_write_method_serialized() - Write a method header
  411. *
  412. * This sets the 'serialized' flag so that the method is thread-safe
  413. *
  414. * @ctx: ACPI context pointer
  415. * @name: Method name (4 characters)
  416. * @nargs: Number of method arguments (0 if none)
  417. */
  418. void acpigen_write_method_serialized(struct acpi_ctx *ctx, const char *name,
  419. int nargs);
  420. /**
  421. * acpigen_write_device() - Write an ACPI device
  422. *
  423. * @ctx: ACPI context pointer
  424. * @name: Device name to write
  425. */
  426. void acpigen_write_device(struct acpi_ctx *ctx, const char *name);
  427. /**
  428. * acpigen_write_sta() - Write a _STA method
  429. *
  430. * @ctx: ACPI context pointer
  431. * @status: Status value to return
  432. */
  433. void acpigen_write_sta(struct acpi_ctx *ctx, uint status);
  434. /**
  435. * acpigen_write_resourcetemplate_header() - Write a ResourceTemplate header
  436. *
  437. * @ctx: ACPI context pointer
  438. */
  439. void acpigen_write_resourcetemplate_header(struct acpi_ctx *ctx);
  440. /**
  441. * acpigen_write_resourcetemplate_footer() - Write a ResourceTemplate footer
  442. *
  443. * @ctx: ACPI context pointer
  444. */
  445. void acpigen_write_resourcetemplate_footer(struct acpi_ctx *ctx);
  446. /**
  447. * acpigen_write_register_resource() - Write a register resource
  448. *
  449. * This writes a header, the address information and a footer
  450. *
  451. * @ctx: ACPI context pointer
  452. * @addr: Address to write
  453. */
  454. void acpigen_write_register_resource(struct acpi_ctx *ctx,
  455. const struct acpi_gen_regaddr *addr);
  456. /**
  457. * acpigen_write_sleep() - Write a sleep operation
  458. *
  459. * @ctx: ACPI context pointer
  460. * @sleep_ms: Number of milliseconds to sleep for
  461. */
  462. void acpigen_write_sleep(struct acpi_ctx *ctx, u64 sleep_ms);
  463. /**
  464. * acpigen_write_store() - Write a store operation
  465. *
  466. * @ctx: ACPI context pointer
  467. */
  468. void acpigen_write_store(struct acpi_ctx *ctx);
  469. /**
  470. * acpigen_write_debug_string() - Write a debug string
  471. *
  472. * This writes a debug operation with an associated string
  473. *
  474. * @ctx: ACPI context pointer
  475. * @str: String to write
  476. */
  477. void acpigen_write_debug_string(struct acpi_ctx *ctx, const char *str);
  478. /**
  479. * acpigen_write_or() - Write a bitwise OR operation
  480. *
  481. * res = arg1 | arg2
  482. *
  483. * @ctx: ACPI context pointer
  484. * @arg1: ACPI opcode for operand 1 (e.g. LOCAL0_OP)
  485. * @arg2: ACPI opcode for operand 2 (e.g. LOCAL1_OP)
  486. * @res: ACPI opcode for result (e.g. LOCAL2_OP)
  487. */
  488. void acpigen_write_or(struct acpi_ctx *ctx, u8 arg1, u8 arg2, u8 res);
  489. /**
  490. * acpigen_write_and() - Write a bitwise AND operation
  491. *
  492. * res = arg1 & arg2
  493. *
  494. * @ctx: ACPI context pointer
  495. * @arg1: ACPI opcode for operand 1 (e.g. LOCAL0_OP)
  496. * @arg2: ACPI opcode for operand 2 (e.g. LOCAL1_OP)
  497. * @res: ACPI opcode for result (e.g. LOCAL2_OP)
  498. */
  499. void acpigen_write_and(struct acpi_ctx *ctx, u8 arg1, u8 arg2, u8 res);
  500. /**
  501. * acpigen_write_not() - Write a bitwise NOT operation
  502. *
  503. * res = ~arg1
  504. *
  505. * @ctx: ACPI context pointer
  506. * @arg: ACPI opcode for operand (e.g. LOCAL0_OP)
  507. * @res: ACPI opcode for result (e.g. LOCAL2_OP)
  508. */
  509. void acpigen_write_not(struct acpi_ctx *ctx, u8 arg, u8 res);
  510. /**
  511. * acpigen_write_power_res() - Write a power resource
  512. *
  513. * Name (_PRx, Package(One) { name })
  514. * ...
  515. * PowerResource (name, level, order)
  516. *
  517. * The caller should fill in the rest of the power resource and then call
  518. * acpigen_pop_len() to close it off
  519. *
  520. * @ctx: ACPI context pointer
  521. * @name: Name of power resource (e.g. "PRIC")
  522. * @level: Deepest sleep level that this resource must be kept on (0=S0, 3=S3)
  523. * @order: Order that this must be enabled/disabled (e.g. 0)
  524. * @dev_stats: List of states to define, e.g. {"_PR0", "_PR3"}
  525. * @dev_states_count: Number of dev states
  526. */
  527. void acpigen_write_power_res(struct acpi_ctx *ctx, const char *name, uint level,
  528. uint order, const char *const dev_states[],
  529. size_t dev_states_count);
  530. /**
  531. * acpigen_set_enable_tx_gpio() - Emit ACPI code to enable/disable a GPIO
  532. *
  533. * This emits code to either enable to disable a Tx GPIO. It takes account of
  534. * the GPIO polarity.
  535. *
  536. * The code needs access to the DW0 register for the pad being used. This is
  537. * provided by gpio->pin0_addr and ACPI methods must be defined for the board
  538. * which can read and write the pad's DW0 register given this address:
  539. * @dw0_read: takes a single argument, the DW0 address
  540. * returns the DW0 value
  541. * @dw0:write: takes two arguments, the DW0 address and the value to write
  542. * no return value
  543. *
  544. * Example code (-- means comment):
  545. *
  546. * -- Get Pad Configuration DW0 register value
  547. * Method (GPC0, 0x1, Serialized)
  548. * {
  549. * -- Arg0 - GPIO DW0 address
  550. * Store (Arg0, Local0)
  551. * OperationRegion (PDW0, SystemMemory, Local0, 4)
  552. * Field (PDW0, AnyAcc, NoLock, Preserve) {
  553. * TEMP, 32
  554. * }
  555. * Return (TEMP)
  556. * }
  557. *
  558. * -- Set Pad Configuration DW0 register value
  559. * Method (SPC0, 0x2, Serialized)
  560. * {
  561. * -- Arg0 - GPIO DW0 address
  562. * -- Arg1 - Value for DW0 register
  563. * Store (Arg0, Local0)
  564. * OperationRegion (PDW0, SystemMemory, Local0, 4)
  565. * Field (PDW0, AnyAcc, NoLock, Preserve) {
  566. * TEMP,32
  567. * }
  568. * Store (Arg1, TEMP)
  569. * }
  570. *
  571. *
  572. * @ctx: ACPI context pointer
  573. * @tx_state_val: Mask to use to toggle the TX state on the GPIO pin, e,g.
  574. * PAD_CFG0_TX_STATE
  575. * @dw0_read: Method name to use to read dw0, e.g. "\\_SB.GPC0"
  576. * @dw0_write: Method name to use to read dw0, e.g. "\\_SB.SPC0"
  577. * @gpio: GPIO to change
  578. * @enable: true to enable GPIO, false to disable
  579. * Returns 0 on success, -ve on error.
  580. */
  581. int acpigen_set_enable_tx_gpio(struct acpi_ctx *ctx, u32 tx_state_val,
  582. const char *dw0_read, const char *dw0_write,
  583. struct acpi_gpio *gpio, bool enable);
  584. /**
  585. * acpigen_write_prw() - Write a power resource for wake (_PRW)
  586. *
  587. * @ctx: ACPI context pointer
  588. * @wake: GPE that wakes up the device
  589. * @level: Deepest power system sleeping state that can be entered while still
  590. * providing wake functionality
  591. */
  592. void acpigen_write_prw(struct acpi_ctx *ctx, uint wake, uint level);
  593. /**
  594. * acpigen_write_if() - Write an If block
  595. *
  596. * This requires a call to acpigen_pop_len() to complete the block
  597. *
  598. * @ctx: ACPI context pointer
  599. */
  600. void acpigen_write_if(struct acpi_ctx *ctx);
  601. /**
  602. * acpigen_write_if_lequal_op_int() - Write comparison between op and integer
  603. *
  604. * Generates ACPI code for checking if operand1 and operand2 are equal
  605. *
  606. * If (Lequal (op, val))
  607. *
  608. * @ctx: ACPI context pointer
  609. * @op: Operand to check
  610. * @val: Value to check against
  611. */
  612. void acpigen_write_if_lequal_op_int(struct acpi_ctx *ctx, uint op, u64 val);
  613. /**
  614. * acpigen_write_else() - Write an Ef block
  615. *
  616. * This requires a call to acpigen_pop_len() to complete the block
  617. *
  618. * @ctx: ACPI context pointer
  619. */
  620. void acpigen_write_else(struct acpi_ctx *ctx);
  621. /**
  622. * acpigen_write_to_buffer() - Write a ToBuffer operation
  623. *
  624. * E.g.: to generate: ToBuffer (Arg0, Local0)
  625. * use acpigen_write_to_buffer(ctx, ARG0_OP, LOCAL0_OP)
  626. *
  627. * @ctx: ACPI context pointer
  628. * @src: Source argument
  629. * @dst: Destination argument
  630. */
  631. void acpigen_write_to_buffer(struct acpi_ctx *ctx, uint src, uint dst);
  632. /**
  633. * acpigen_write_to_integer() - Write a ToInteger operation
  634. *
  635. * E.g.: to generate: ToInteger (Arg0, Local0)
  636. * use acpigen_write_to_integer(ctx, ARG0_OP, LOCAL0_OP)
  637. *
  638. * @ctx: ACPI context pointer
  639. * @src: Source argument
  640. * @dst: Destination argument
  641. */
  642. void acpigen_write_to_integer(struct acpi_ctx *ctx, uint src, uint dst);
  643. /**
  644. * acpigen_write_return_byte_buffer() - Write a return of a byte buffer
  645. *
  646. * @ctx: ACPI context pointer
  647. * @arr: Array of bytes to return
  648. * @size: Number of bytes
  649. */
  650. void acpigen_write_return_byte_buffer(struct acpi_ctx *ctx, u8 *arr,
  651. size_t size);
  652. /**
  653. * acpigen_write_return_singleton_buffer() - Write a return of a 1-byte buffer
  654. *
  655. * @ctx: ACPI context pointer
  656. * @arg: Byte to return
  657. */
  658. void acpigen_write_return_singleton_buffer(struct acpi_ctx *ctx, uint arg);
  659. /**
  660. * acpigen_write_return_byte() - Write a return of a byte
  661. *
  662. * @ctx: ACPI context pointer
  663. * @arg: Byte to return
  664. */
  665. void acpigen_write_return_byte(struct acpi_ctx *ctx, uint arg);
  666. /**
  667. * acpigen_write_dsm_start() - Start a _DSM method
  668. *
  669. * Generate ACPI AML code to start the _DSM method.
  670. *
  671. * The functions need to be called in the correct sequence as below.
  672. *
  673. * Within the <generate-code-here> region, Local0 and Local1 must be are left
  674. * untouched, but Local2-Local7 can be used
  675. *
  676. * Arguments passed into _DSM method:
  677. * Arg0 = UUID
  678. * Arg1 = Revision
  679. * Arg2 = Function index
  680. * Arg3 = Function-specific arguments
  681. *
  682. * AML code generated looks like this:
  683. * Method (_DSM, 4, Serialized) { -- acpigen_write_dsm_start)
  684. * ToBuffer (Arg0, Local0)
  685. * If (LEqual (Local0, ToUUID(uuid))) { -- acpigen_write_dsm_uuid_start
  686. * ToInteger (Arg2, Local1)
  687. * If (LEqual (Local1, 0)) { -- acpigen_write_dsm_uuid_start_cond
  688. * <generate-code-here>
  689. * } -- acpigen_write_dsm_uuid_end_cond
  690. * ...
  691. * If (LEqual (Local1, n)) { -- acpigen_write_dsm_uuid_start_cond
  692. * <generate-code-here>
  693. * } -- acpigen_write_dsm_uuid_end_cond
  694. * Return (Buffer (One) { 0x0 })
  695. * } -- acpigen_write_dsm_uuid_end
  696. * ...
  697. * If (LEqual (Local0, ToUUID(uuidn))) {
  698. * ...
  699. * }
  700. * Return (Buffer (One) { 0x0 }) -- acpigen_write_dsm_end
  701. * }
  702. *
  703. * @ctx: ACPI context pointer
  704. */
  705. void acpigen_write_dsm_start(struct acpi_ctx *ctx);
  706. /**
  707. * acpigen_write_dsm_uuid_start() - Start a new UUID block
  708. *
  709. * This starts generation of code to handle a particular UUID:
  710. *
  711. * If (LEqual (Local0, ToUUID(uuid))) {
  712. * ToInteger (Arg2, Local1)
  713. *
  714. * @ctx: ACPI context pointer
  715. */
  716. int acpigen_write_dsm_uuid_start(struct acpi_ctx *ctx, const char *uuid);
  717. /**
  718. * acpigen_write_dsm_uuid_start_cond() - Start a new condition block
  719. *
  720. * This starts generation of condition-checking code to handle a particular
  721. * function:
  722. *
  723. * If (LEqual (Local1, i))
  724. *
  725. * @ctx: ACPI context pointer
  726. */
  727. void acpigen_write_dsm_uuid_start_cond(struct acpi_ctx *ctx, int seq);
  728. /**
  729. * acpigen_write_dsm_uuid_end_cond() - Start a new condition block
  730. *
  731. * This ends generation of condition-checking code to handle a particular
  732. * function:
  733. *
  734. * }
  735. *
  736. * @ctx: ACPI context pointer
  737. */
  738. void acpigen_write_dsm_uuid_end_cond(struct acpi_ctx *ctx);
  739. /**
  740. * acpigen_write_dsm_uuid_end() - End a UUID block
  741. *
  742. * This ends generation of code to handle a particular UUID:
  743. *
  744. * Return (Buffer (One) { 0x0 })
  745. *
  746. * @ctx: ACPI context pointer
  747. */
  748. void acpigen_write_dsm_uuid_end(struct acpi_ctx *ctx);
  749. /**
  750. * acpigen_write_dsm_end() - End a _DSM method
  751. *
  752. * This ends generates of the _DSM block:
  753. *
  754. * Return (Buffer (One) { 0x0 })
  755. *
  756. * @ctx: ACPI context pointer
  757. */
  758. void acpigen_write_dsm_end(struct acpi_ctx *ctx);
  759. /**
  760. * acpigen_write_processor() - Write a Processor package
  761. *
  762. * This emits a Processor package header with the required information. The
  763. * caller must complete the information and call acpigen_pop_len() at the end
  764. *
  765. * @ctx: ACPI context pointer
  766. * @cpuindex: CPU number
  767. * @pblock_addr: PBlk system IO address
  768. * @pblock_len: PBlk length
  769. */
  770. void acpigen_write_processor(struct acpi_ctx *ctx, uint cpuindex,
  771. u32 pblock_addr, uint pblock_len);
  772. /**
  773. * acpigen_write_processor_package() - Write a package containing the processors
  774. *
  775. * The package containins the name of each processor in the SoC
  776. *
  777. * @ctx: ACPI context pointer
  778. * @name: Package name (.e.g "PPKG")
  779. * @first_core: Number of the first core (e.g. 0)
  780. * @core_count: Number of cores (e.g. 4)
  781. */
  782. void acpigen_write_processor_package(struct acpi_ctx *ctx, const char *name,
  783. uint first_core, uint core_count);
  784. /**
  785. * acpigen_write_processor_cnot() - Write a processor notification method
  786. *
  787. * This writes a method that notifies all CPU cores
  788. *
  789. * @ctx: ACPI context pointer
  790. * @num_cores: Number of CPU cores
  791. */
  792. void acpigen_write_processor_cnot(struct acpi_ctx *ctx, const uint num_cores);
  793. /**
  794. * acpigen_write_ppc() - generates a function returning max P-states
  795. *
  796. * @ctx: ACPI context pointer
  797. * @num_pstates: Number of pstates to return
  798. */
  799. void acpigen_write_ppc(struct acpi_ctx *ctx, uint num_pstates);
  800. /**
  801. * acpigen_write_ppc() - generates a function returning PPCM
  802. *
  803. * This returns the maximum number of supported P-states, as saved in the
  804. * variable PPCM
  805. *
  806. * @ctx: ACPI context pointer
  807. */
  808. void acpigen_write_ppc_nvs(struct acpi_ctx *ctx);
  809. /**
  810. * acpigen_write_tpc() - Write a _TPC method that returns the TPC limit
  811. *
  812. * @ctx: ACPI context pointer
  813. * @gnvs_tpc_limit: Variable that holds the TPC limit
  814. */
  815. void acpigen_write_tpc(struct acpi_ctx *ctx, const char *gnvs_tpc_limit);
  816. /**
  817. * acpigen_write_pss_package() - Write a PSS package
  818. *
  819. * See ACPI v6.3 section 8.4.6: Processor Performance Control
  820. *
  821. * @ctx: ACPI context pointer
  822. * @corefreq: CPU core frequency in MHz
  823. * @translat: worst-case latency in uS that the CPU is unavailable during a
  824. * transition from any performance state to this performance state
  825. * @busmlat: worst-case latency in microseconds that Bus Masters are prevented
  826. * from accessing memory during a transition from any performance state to
  827. * this performance state
  828. * @control: Value to write to PERF_CTRL to move to this performance state
  829. * @status: Expected PERF_STATUS value when in this state
  830. */
  831. void acpigen_write_pss_package(struct acpi_ctx *ctx, uint corefreq, uint power,
  832. uint translat, uint busmlat, uint control,
  833. uint status);
  834. /**
  835. * acpigen_write_psd_package() - Write a PSD package
  836. *
  837. * Writes a P-State dependency package
  838. *
  839. * See ACPI v6.3 section 8.4.6.5: _PSD (P-State Dependency)
  840. *
  841. * @ctx: ACPI context pointer
  842. * @domain: Dependency domain number to which this P state entry belongs
  843. * @numprocs: Number of processors belonging to the domain for this logical
  844. * processor’s P-states
  845. * @coordtype: Coordination type
  846. */
  847. void acpigen_write_psd_package(struct acpi_ctx *ctx, uint domain, uint numprocs,
  848. enum psd_coord coordtype);
  849. /**
  850. * acpigen_write_cst_package() - Write a _CST package
  851. *
  852. * See ACPI v6.3 section 8.4.2.1: _CST (C States)
  853. *
  854. * @ctx: ACPI context pointer
  855. * @entry: Array of entries
  856. * @nentries; Number of entries
  857. */
  858. void acpigen_write_cst_package(struct acpi_ctx *ctx,
  859. const struct acpi_cstate *entry, int nentries);
  860. /**
  861. * acpigen_write_csd_package() - Write a _CSD Package
  862. *
  863. * See ACPI v6.3 section 8.4.2.2: _CSD (C-State Dependency)
  864. *
  865. * @ctx: ACPI context pointer
  866. * @domain: dependency domain number to which this C state entry belongs
  867. * @numprocs: number of processors belonging to the domain for the particular
  868. * C-state
  869. * @coordtype: Co-ordination type
  870. * @index: Index of the C-State entry in the _CST object for which the
  871. * dependency applies
  872. */
  873. void acpigen_write_csd_package(struct acpi_ctx *ctx, uint domain, uint numprocs,
  874. enum csd_coord coordtype, uint index);
  875. /**
  876. * acpigen_write_tss_package() - Write a _TSS package
  877. *
  878. * @ctx: ACPI context pointer
  879. * @entry: Entries to write
  880. * @nentries: Number of entries to write
  881. */
  882. void acpigen_write_tss_package(struct acpi_ctx *ctx,
  883. struct acpi_tstate *entry, int nentries);
  884. /**
  885. * acpigen_write_tsd_package() - Write a _TSD package
  886. *
  887. * See ACPI v6.3 section 8.4.5.4: _TSD (T-State Dependency)
  888. *
  889. * @ctx: ACPI context pointer
  890. * @domain: dependency domain number to which this T state entry belongs
  891. * @numprocs: Number of processors belonging to the domain for this logical
  892. * processor’s T-states
  893. * @coordtype: Coordination type
  894. */
  895. void acpigen_write_tsd_package(struct acpi_ctx *ctx, uint domain, uint numprocs,
  896. enum psd_coord coordtype);
  897. #endif