efi_variable.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (c) 2020, Heinrich Schuchardt <xypron.glpk@gmx.de>
  4. */
  5. #ifndef _EFI_VARIABLE_H
  6. #define _EFI_VARIABLE_H
  7. #include <linux/bitops.h>
  8. #define EFI_VARIABLE_READ_ONLY BIT(31)
  9. /**
  10. * efi_get_variable() - retrieve value of a UEFI variable
  11. *
  12. * @variable_name: name of the variable
  13. * @vendor: vendor GUID
  14. * @attributes: attributes of the variable
  15. * @data_size: size of the buffer to which the variable value is copied
  16. * @data: buffer to which the variable value is copied
  17. * @timep: authentication time (seconds since start of epoch)
  18. * Return: status code
  19. */
  20. efi_status_t efi_get_variable_int(u16 *variable_name, const efi_guid_t *vendor,
  21. u32 *attributes, efi_uintn_t *data_size,
  22. void *data, u64 *timep);
  23. /**
  24. * efi_set_variable() - set value of a UEFI variable
  25. *
  26. * @variable_name: name of the variable
  27. * @vendor: vendor GUID
  28. * @attributes: attributes of the variable
  29. * @data_size: size of the buffer with the variable value
  30. * @data: buffer with the variable value
  31. * @ro_check: check the read only read only bit in attributes
  32. * Return: status code
  33. */
  34. efi_status_t efi_set_variable_int(u16 *variable_name, const efi_guid_t *vendor,
  35. u32 attributes, efi_uintn_t data_size,
  36. const void *data, bool ro_check);
  37. /**
  38. * efi_get_next_variable_name_int() - enumerate the current variable names
  39. *
  40. * @variable_name_size: size of variable_name buffer in byte
  41. * @variable_name: name of uefi variable's name in u16
  42. * @vendor: vendor's guid
  43. *
  44. * See the Unified Extensible Firmware Interface (UEFI) specification for
  45. * details.
  46. *
  47. * Return: status code
  48. */
  49. efi_status_t efi_get_next_variable_name_int(efi_uintn_t *variable_name_size,
  50. u16 *variable_name,
  51. efi_guid_t *vendor);
  52. /**
  53. * efi_query_variable_info_int() - get information about EFI variables
  54. *
  55. * This function implements the QueryVariableInfo() runtime service.
  56. *
  57. * See the Unified Extensible Firmware Interface (UEFI) specification for
  58. * details.
  59. *
  60. * @attributes: bitmask to select variables to be
  61. * queried
  62. * @maximum_variable_storage_size: maximum size of storage area for the
  63. * selected variable types
  64. * @remaining_variable_storage_size: remaining size of storage are for the
  65. * selected variable types
  66. * @maximum_variable_size: maximum size of a variable of the
  67. * selected type
  68. * Returns: status code
  69. */
  70. efi_status_t efi_query_variable_info_int(u32 attributes,
  71. u64 *maximum_variable_storage_size,
  72. u64 *remaining_variable_storage_size,
  73. u64 *maximum_variable_size);
  74. #define EFI_VAR_FILE_NAME "ubootefi.var"
  75. #define EFI_VAR_BUF_SIZE 0x4000
  76. #define EFI_VAR_FILE_MAGIC 0x0161566966456255 /* UbEfiVa, version 1 */
  77. /**
  78. * struct efi_var_entry - UEFI variable file entry
  79. *
  80. * @length: length of enty, multiple of 8
  81. * @attr: variable attributes
  82. * @time: authentication time (seconds since start of epoch)
  83. * @guid: vendor GUID
  84. * @name: UTF16 variable name
  85. */
  86. struct efi_var_entry {
  87. u32 length;
  88. u32 attr;
  89. u64 time;
  90. efi_guid_t guid;
  91. u16 name[];
  92. };
  93. /**
  94. * struct efi_var_file - file for storing UEFI variables
  95. *
  96. * @reserved: unused, may be overwritten by memory probing
  97. * @magic: identifies file format
  98. * @length: length including header
  99. * @crc32: CRC32 without header
  100. * @var: variables
  101. */
  102. struct efi_var_file {
  103. u64 reserved;
  104. u64 magic;
  105. u32 length;
  106. u32 crc32;
  107. struct efi_var_entry var[];
  108. };
  109. /**
  110. * efi_var_to_file() - save non-volatile variables as file
  111. *
  112. * File ubootefi.var is created on the EFI system partion.
  113. *
  114. * Return: status code
  115. */
  116. efi_status_t efi_var_to_file(void);
  117. /**
  118. * efi_var_from_file() - read variables from file
  119. *
  120. * File ubootefi.var is read from the EFI system partitions and the variables
  121. * stored in the file are created.
  122. *
  123. * In case the file does not exist yet or a variable cannot be set EFI_SUCCESS
  124. * is returned.
  125. *
  126. * Return: status code
  127. */
  128. efi_status_t efi_var_from_file(void);
  129. /**
  130. * efi_var_mem_init() - set-up variable list
  131. *
  132. * Return: status code
  133. */
  134. efi_status_t efi_var_mem_init(void);
  135. /**
  136. * efi_var_mem_find() - find a variable in the list
  137. *
  138. * @guid: GUID of the variable
  139. * @name: name of the variable
  140. * @next: on exit pointer to the next variable after the found one
  141. * Return: found variable
  142. */
  143. struct efi_var_entry *efi_var_mem_find(const efi_guid_t *guid, const u16 *name,
  144. struct efi_var_entry **next);
  145. /**
  146. * efi_var_mem_del() - delete a variable from the list of variables
  147. *
  148. * @var: variable to delete
  149. */
  150. void efi_var_mem_del(struct efi_var_entry *var);
  151. /**
  152. * efi_var_mem_ins() - append a variable to the list of variables
  153. *
  154. * The variable is appended without checking if a variable of the same name
  155. * already exists. The two data buffers are concatenated.
  156. *
  157. * @variable_name: variable name
  158. * @vendor: GUID
  159. * @attributes: variable attributes
  160. * @size1: size of the first data buffer
  161. * @data1: first data buffer
  162. * @size2: size of the second data field
  163. * @data2: second data buffer
  164. * @time: time of authentication (as seconds since start of epoch)
  165. * Result: status code
  166. */
  167. efi_status_t efi_var_mem_ins(u16 *variable_name,
  168. const efi_guid_t *vendor, u32 attributes,
  169. const efi_uintn_t size1, const void *data1,
  170. const efi_uintn_t size2, const void *data2,
  171. const u64 time);
  172. /**
  173. * efi_var_mem_free() - determine free memory for variables
  174. *
  175. * Return: maximum data size plus variable name size
  176. */
  177. u64 efi_var_mem_free(void);
  178. #endif