efi_variable_tee.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * EFI variable service via OP-TEE
  4. *
  5. * Copyright (C) 2019 Linaro Ltd. <sughosh.ganu@linaro.org>
  6. * Copyright (C) 2019 Linaro Ltd. <ilias.apalodimas@linaro.org>
  7. */
  8. #include <common.h>
  9. #include <efi.h>
  10. #include <efi_api.h>
  11. #include <efi_loader.h>
  12. #include <efi_variable.h>
  13. #include <tee.h>
  14. #include <malloc.h>
  15. #include <mm_communication.h>
  16. static efi_uintn_t max_buffer_size; /* comm + var + func + data */
  17. static efi_uintn_t max_payload_size; /* func + data */
  18. struct mm_connection {
  19. struct udevice *tee;
  20. u32 session;
  21. };
  22. /**
  23. * get_connection() - Retrieve OP-TEE session for a specific UUID.
  24. *
  25. * @conn: session buffer to fill
  26. * Return: status code
  27. */
  28. static int get_connection(struct mm_connection *conn)
  29. {
  30. static const struct tee_optee_ta_uuid uuid = PTA_STMM_UUID;
  31. struct udevice *tee = NULL;
  32. struct tee_open_session_arg arg;
  33. int rc;
  34. tee = tee_find_device(tee, NULL, NULL, NULL);
  35. if (!tee)
  36. return -ENODEV;
  37. memset(&arg, 0, sizeof(arg));
  38. tee_optee_ta_uuid_to_octets(arg.uuid, &uuid);
  39. rc = tee_open_session(tee, &arg, 0, NULL);
  40. if (!rc) {
  41. conn->tee = tee;
  42. conn->session = arg.session;
  43. }
  44. return rc;
  45. }
  46. /**
  47. * optee_mm_communicate() - Pass a buffer to StandaloneMM running in OP-TEE
  48. *
  49. * @comm_buf: locally allocted communcation buffer
  50. * @dsize: buffer size
  51. * Return: status code
  52. */
  53. static efi_status_t optee_mm_communicate(void *comm_buf, ulong dsize)
  54. {
  55. ulong buf_size;
  56. efi_status_t ret;
  57. struct efi_mm_communicate_header *mm_hdr;
  58. struct mm_connection conn = { NULL, 0 };
  59. struct tee_invoke_arg arg;
  60. struct tee_param param[2];
  61. struct tee_shm *shm = NULL;
  62. int rc;
  63. if (!comm_buf)
  64. return EFI_INVALID_PARAMETER;
  65. mm_hdr = (struct efi_mm_communicate_header *)comm_buf;
  66. buf_size = mm_hdr->message_len + sizeof(efi_guid_t) + sizeof(size_t);
  67. if (dsize != buf_size)
  68. return EFI_INVALID_PARAMETER;
  69. rc = get_connection(&conn);
  70. if (rc) {
  71. log_err("Unable to open OP-TEE session (err=%d)\n", rc);
  72. return EFI_UNSUPPORTED;
  73. }
  74. if (tee_shm_register(conn.tee, comm_buf, buf_size, 0, &shm)) {
  75. log_err("Unable to register shared memory\n");
  76. return EFI_UNSUPPORTED;
  77. }
  78. memset(&arg, 0, sizeof(arg));
  79. arg.func = PTA_STMM_CMDID_COMMUNICATE;
  80. arg.session = conn.session;
  81. memset(param, 0, sizeof(param));
  82. param[0].attr = TEE_PARAM_ATTR_TYPE_MEMREF_INOUT;
  83. param[0].u.memref.size = buf_size;
  84. param[0].u.memref.shm = shm;
  85. param[1].attr = TEE_PARAM_ATTR_TYPE_VALUE_OUTPUT;
  86. rc = tee_invoke_func(conn.tee, &arg, 2, param);
  87. if (rc)
  88. return EFI_INVALID_PARAMETER;
  89. tee_shm_free(shm);
  90. tee_close_session(conn.tee, conn.session);
  91. switch (param[1].u.value.a) {
  92. case ARM_SVC_SPM_RET_SUCCESS:
  93. ret = EFI_SUCCESS;
  94. break;
  95. case ARM_SVC_SPM_RET_INVALID_PARAMS:
  96. ret = EFI_INVALID_PARAMETER;
  97. break;
  98. case ARM_SVC_SPM_RET_DENIED:
  99. ret = EFI_ACCESS_DENIED;
  100. break;
  101. case ARM_SVC_SPM_RET_NO_MEMORY:
  102. ret = EFI_OUT_OF_RESOURCES;
  103. break;
  104. default:
  105. ret = EFI_ACCESS_DENIED;
  106. }
  107. return ret;
  108. }
  109. /**
  110. * mm_communicate() - Adjust the cmonnucation buffer to StandAlonneMM and send
  111. * it to OP-TEE
  112. *
  113. * @comm_buf: locally allocted communcation buffer
  114. * @dsize: buffer size
  115. * Return: status code
  116. */
  117. static efi_status_t mm_communicate(u8 *comm_buf, efi_uintn_t dsize)
  118. {
  119. efi_status_t ret;
  120. struct efi_mm_communicate_header *mm_hdr;
  121. struct smm_variable_communicate_header *var_hdr;
  122. dsize += MM_COMMUNICATE_HEADER_SIZE + MM_VARIABLE_COMMUNICATE_SIZE;
  123. mm_hdr = (struct efi_mm_communicate_header *)comm_buf;
  124. var_hdr = (struct smm_variable_communicate_header *)mm_hdr->data;
  125. ret = optee_mm_communicate(comm_buf, dsize);
  126. if (ret != EFI_SUCCESS) {
  127. log_err("%s failed!\n", __func__);
  128. return ret;
  129. }
  130. return var_hdr->ret_status;
  131. }
  132. /**
  133. * setup_mm_hdr() - Allocate a buffer for StandAloneMM and initialize the
  134. * header data.
  135. *
  136. * @dptr: pointer address of the corresponding StandAloneMM
  137. * function
  138. * @payload_size: buffer size
  139. * @func: standAloneMM function number
  140. * @ret: EFI return code
  141. * Return: buffer or NULL
  142. */
  143. static u8 *setup_mm_hdr(void **dptr, efi_uintn_t payload_size,
  144. efi_uintn_t func, efi_status_t *ret)
  145. {
  146. const efi_guid_t mm_var_guid = EFI_MM_VARIABLE_GUID;
  147. struct efi_mm_communicate_header *mm_hdr;
  148. struct smm_variable_communicate_header *var_hdr;
  149. u8 *comm_buf;
  150. /* In the init function we initialize max_buffer_size with
  151. * get_max_payload(). So skip the test if max_buffer_size is initialized
  152. * StandAloneMM will perform similar checks and drop the buffer if it's
  153. * too long
  154. */
  155. if (max_buffer_size && max_buffer_size <
  156. (MM_COMMUNICATE_HEADER_SIZE +
  157. MM_VARIABLE_COMMUNICATE_SIZE +
  158. payload_size)) {
  159. *ret = EFI_INVALID_PARAMETER;
  160. return NULL;
  161. }
  162. comm_buf = calloc(1, MM_COMMUNICATE_HEADER_SIZE +
  163. MM_VARIABLE_COMMUNICATE_SIZE +
  164. payload_size);
  165. if (!comm_buf) {
  166. *ret = EFI_OUT_OF_RESOURCES;
  167. return NULL;
  168. }
  169. mm_hdr = (struct efi_mm_communicate_header *)comm_buf;
  170. guidcpy(&mm_hdr->header_guid, &mm_var_guid);
  171. mm_hdr->message_len = MM_VARIABLE_COMMUNICATE_SIZE + payload_size;
  172. var_hdr = (struct smm_variable_communicate_header *)mm_hdr->data;
  173. var_hdr->function = func;
  174. if (dptr)
  175. *dptr = var_hdr->data;
  176. *ret = EFI_SUCCESS;
  177. return comm_buf;
  178. }
  179. /**
  180. * get_max_payload() - Get variable payload size from StandAloneMM.
  181. *
  182. * @size: size of the variable in storage
  183. * Return: status code
  184. */
  185. efi_status_t EFIAPI get_max_payload(efi_uintn_t *size)
  186. {
  187. struct smm_variable_payload_size *var_payload = NULL;
  188. efi_uintn_t payload_size;
  189. u8 *comm_buf = NULL;
  190. efi_status_t ret;
  191. if (!size) {
  192. ret = EFI_INVALID_PARAMETER;
  193. goto out;
  194. }
  195. payload_size = sizeof(*var_payload);
  196. comm_buf = setup_mm_hdr((void **)&var_payload, payload_size,
  197. SMM_VARIABLE_FUNCTION_GET_PAYLOAD_SIZE, &ret);
  198. if (!comm_buf)
  199. goto out;
  200. ret = mm_communicate(comm_buf, payload_size);
  201. if (ret != EFI_SUCCESS)
  202. goto out;
  203. *size = var_payload->size;
  204. out:
  205. free(comm_buf);
  206. return ret;
  207. }
  208. /*
  209. * StMM can store internal attributes and properties for variables, i.e enabling
  210. * R/O variables
  211. */
  212. static efi_status_t set_property_int(u16 *variable_name, efi_uintn_t name_size,
  213. const efi_guid_t *vendor,
  214. struct var_check_property *var_property)
  215. {
  216. struct smm_variable_var_check_property *smm_property;
  217. efi_uintn_t payload_size;
  218. u8 *comm_buf = NULL;
  219. efi_status_t ret;
  220. payload_size = sizeof(*smm_property) + name_size;
  221. if (payload_size > max_payload_size) {
  222. ret = EFI_INVALID_PARAMETER;
  223. goto out;
  224. }
  225. comm_buf = setup_mm_hdr((void **)&smm_property, payload_size,
  226. SMM_VARIABLE_FUNCTION_VAR_CHECK_VARIABLE_PROPERTY_SET,
  227. &ret);
  228. if (!comm_buf)
  229. goto out;
  230. guidcpy(&smm_property->guid, vendor);
  231. smm_property->name_size = name_size;
  232. memcpy(&smm_property->property, var_property,
  233. sizeof(smm_property->property));
  234. memcpy(smm_property->name, variable_name, name_size);
  235. ret = mm_communicate(comm_buf, payload_size);
  236. out:
  237. free(comm_buf);
  238. return ret;
  239. }
  240. static efi_status_t get_property_int(u16 *variable_name, efi_uintn_t name_size,
  241. const efi_guid_t *vendor,
  242. struct var_check_property *var_property)
  243. {
  244. struct smm_variable_var_check_property *smm_property;
  245. efi_uintn_t payload_size;
  246. u8 *comm_buf = NULL;
  247. efi_status_t ret;
  248. memset(var_property, 0, sizeof(*var_property));
  249. payload_size = sizeof(*smm_property) + name_size;
  250. if (payload_size > max_payload_size) {
  251. ret = EFI_INVALID_PARAMETER;
  252. goto out;
  253. }
  254. comm_buf = setup_mm_hdr((void **)&smm_property, payload_size,
  255. SMM_VARIABLE_FUNCTION_VAR_CHECK_VARIABLE_PROPERTY_GET,
  256. &ret);
  257. if (!comm_buf)
  258. goto out;
  259. guidcpy(&smm_property->guid, vendor);
  260. smm_property->name_size = name_size;
  261. memcpy(smm_property->name, variable_name, name_size);
  262. ret = mm_communicate(comm_buf, payload_size);
  263. /*
  264. * Currently only R/O property is supported in StMM.
  265. * Variables that are not set to R/O will not set the property in StMM
  266. * and the call will return EFI_NOT_FOUND. We are setting the
  267. * properties to 0x0 so checking against that is enough for the
  268. * EFI_NOT_FOUND case.
  269. */
  270. if (ret == EFI_NOT_FOUND)
  271. ret = EFI_SUCCESS;
  272. if (ret != EFI_SUCCESS)
  273. goto out;
  274. memcpy(var_property, &smm_property->property, sizeof(*var_property));
  275. out:
  276. free(comm_buf);
  277. return ret;
  278. }
  279. efi_status_t efi_get_variable_int(u16 *variable_name, const efi_guid_t *vendor,
  280. u32 *attributes, efi_uintn_t *data_size,
  281. void *data, u64 *timep)
  282. {
  283. struct var_check_property var_property;
  284. struct smm_variable_access *var_acc;
  285. efi_uintn_t payload_size;
  286. efi_uintn_t name_size;
  287. efi_uintn_t tmp_dsize;
  288. u8 *comm_buf = NULL;
  289. efi_status_t ret;
  290. if (!variable_name || !vendor || !data_size) {
  291. ret = EFI_INVALID_PARAMETER;
  292. goto out;
  293. }
  294. /* Check payload size */
  295. name_size = u16_strsize(variable_name);
  296. if (name_size > max_payload_size - MM_VARIABLE_ACCESS_HEADER_SIZE) {
  297. ret = EFI_INVALID_PARAMETER;
  298. goto out;
  299. }
  300. /* Trim output buffer size */
  301. tmp_dsize = *data_size;
  302. if (name_size + tmp_dsize >
  303. max_payload_size - MM_VARIABLE_ACCESS_HEADER_SIZE) {
  304. tmp_dsize = max_payload_size -
  305. MM_VARIABLE_ACCESS_HEADER_SIZE -
  306. name_size;
  307. }
  308. /* Get communication buffer and initialize header */
  309. payload_size = MM_VARIABLE_ACCESS_HEADER_SIZE + name_size + tmp_dsize;
  310. comm_buf = setup_mm_hdr((void **)&var_acc, payload_size,
  311. SMM_VARIABLE_FUNCTION_GET_VARIABLE, &ret);
  312. if (!comm_buf)
  313. goto out;
  314. /* Fill in contents */
  315. guidcpy(&var_acc->guid, vendor);
  316. var_acc->data_size = tmp_dsize;
  317. var_acc->name_size = name_size;
  318. var_acc->attr = attributes ? *attributes : 0;
  319. memcpy(var_acc->name, variable_name, name_size);
  320. /* Communicate */
  321. ret = mm_communicate(comm_buf, payload_size);
  322. if (ret == EFI_SUCCESS || ret == EFI_BUFFER_TOO_SMALL) {
  323. /* Update with reported data size for trimmed case */
  324. *data_size = var_acc->data_size;
  325. }
  326. if (ret != EFI_SUCCESS)
  327. goto out;
  328. ret = get_property_int(variable_name, name_size, vendor, &var_property);
  329. if (ret != EFI_SUCCESS)
  330. goto out;
  331. if (attributes) {
  332. *attributes = var_acc->attr;
  333. if (var_property.property & VAR_CHECK_VARIABLE_PROPERTY_READ_ONLY)
  334. *attributes |= EFI_VARIABLE_READ_ONLY;
  335. }
  336. if (data)
  337. memcpy(data, (u8 *)var_acc->name + var_acc->name_size,
  338. var_acc->data_size);
  339. else
  340. ret = EFI_INVALID_PARAMETER;
  341. out:
  342. free(comm_buf);
  343. return ret;
  344. }
  345. efi_status_t efi_get_next_variable_name_int(efi_uintn_t *variable_name_size,
  346. u16 *variable_name,
  347. efi_guid_t *guid)
  348. {
  349. struct smm_variable_getnext *var_getnext;
  350. efi_uintn_t payload_size;
  351. efi_uintn_t out_name_size;
  352. efi_uintn_t in_name_size;
  353. efi_uintn_t tmp_dsize;
  354. u8 *comm_buf = NULL;
  355. efi_status_t ret;
  356. if (!variable_name_size || !variable_name || !guid) {
  357. ret = EFI_INVALID_PARAMETER;
  358. goto out;
  359. }
  360. out_name_size = *variable_name_size;
  361. in_name_size = u16_strsize(variable_name);
  362. if (out_name_size < in_name_size) {
  363. ret = EFI_INVALID_PARAMETER;
  364. goto out;
  365. }
  366. if (in_name_size > max_payload_size - MM_VARIABLE_GET_NEXT_HEADER_SIZE) {
  367. ret = EFI_INVALID_PARAMETER;
  368. goto out;
  369. }
  370. /* Trim output buffer size */
  371. tmp_dsize = *variable_name_size;
  372. if (in_name_size + tmp_dsize >
  373. max_payload_size - MM_VARIABLE_GET_NEXT_HEADER_SIZE) {
  374. tmp_dsize = max_payload_size -
  375. MM_VARIABLE_GET_NEXT_HEADER_SIZE -
  376. in_name_size;
  377. }
  378. payload_size = MM_VARIABLE_GET_NEXT_HEADER_SIZE + out_name_size;
  379. comm_buf = setup_mm_hdr((void **)&var_getnext, payload_size,
  380. SMM_VARIABLE_FUNCTION_GET_NEXT_VARIABLE_NAME,
  381. &ret);
  382. if (!comm_buf)
  383. goto out;
  384. /* Fill in contents */
  385. guidcpy(&var_getnext->guid, guid);
  386. var_getnext->name_size = out_name_size;
  387. memcpy(var_getnext->name, variable_name, in_name_size);
  388. memset((u8 *)var_getnext->name + in_name_size, 0x0,
  389. out_name_size - in_name_size);
  390. /* Communicate */
  391. ret = mm_communicate(comm_buf, payload_size);
  392. if (ret == EFI_SUCCESS || ret == EFI_BUFFER_TOO_SMALL) {
  393. /* Update with reported data size for trimmed case */
  394. *variable_name_size = var_getnext->name_size;
  395. }
  396. if (ret != EFI_SUCCESS)
  397. goto out;
  398. guidcpy(guid, &var_getnext->guid);
  399. memcpy(variable_name, (u8 *)var_getnext->name,
  400. var_getnext->name_size);
  401. out:
  402. free(comm_buf);
  403. return ret;
  404. }
  405. efi_status_t efi_set_variable_int(u16 *variable_name, const efi_guid_t *vendor,
  406. u32 attributes, efi_uintn_t data_size,
  407. const void *data, bool ro_check)
  408. {
  409. efi_status_t ret, alt_ret = EFI_SUCCESS;
  410. struct var_check_property var_property;
  411. struct smm_variable_access *var_acc;
  412. efi_uintn_t payload_size;
  413. efi_uintn_t name_size;
  414. u8 *comm_buf = NULL;
  415. bool ro;
  416. if (!variable_name || variable_name[0] == 0 || !vendor) {
  417. ret = EFI_INVALID_PARAMETER;
  418. goto out;
  419. }
  420. if (data_size > 0 && !data) {
  421. ret = EFI_INVALID_PARAMETER;
  422. goto out;
  423. }
  424. /* Check payload size */
  425. name_size = u16_strsize(variable_name);
  426. payload_size = MM_VARIABLE_ACCESS_HEADER_SIZE + name_size + data_size;
  427. if (payload_size > max_payload_size) {
  428. ret = EFI_INVALID_PARAMETER;
  429. goto out;
  430. }
  431. /*
  432. * Allocate the buffer early, before switching to RW (if needed)
  433. * so we won't need to account for any failures in reading/setting
  434. * the properties, if the allocation fails
  435. */
  436. comm_buf = setup_mm_hdr((void **)&var_acc, payload_size,
  437. SMM_VARIABLE_FUNCTION_SET_VARIABLE, &ret);
  438. if (!comm_buf)
  439. goto out;
  440. ro = !!(attributes & EFI_VARIABLE_READ_ONLY);
  441. attributes &= EFI_VARIABLE_MASK;
  442. /*
  443. * The API has the ability to override RO flags. If no RO check was
  444. * requested switch the variable to RW for the duration of this call
  445. */
  446. ret = get_property_int(variable_name, name_size, vendor,
  447. &var_property);
  448. if (ret != EFI_SUCCESS)
  449. goto out;
  450. if (var_property.property & VAR_CHECK_VARIABLE_PROPERTY_READ_ONLY) {
  451. /* Bypass r/o check */
  452. if (!ro_check) {
  453. var_property.property &= ~VAR_CHECK_VARIABLE_PROPERTY_READ_ONLY;
  454. ret = set_property_int(variable_name, name_size, vendor, &var_property);
  455. if (ret != EFI_SUCCESS)
  456. goto out;
  457. } else {
  458. ret = EFI_WRITE_PROTECTED;
  459. goto out;
  460. }
  461. }
  462. /* Fill in contents */
  463. guidcpy(&var_acc->guid, vendor);
  464. var_acc->data_size = data_size;
  465. var_acc->name_size = name_size;
  466. var_acc->attr = attributes;
  467. memcpy(var_acc->name, variable_name, name_size);
  468. memcpy((u8 *)var_acc->name + name_size, data, data_size);
  469. /* Communicate */
  470. ret = mm_communicate(comm_buf, payload_size);
  471. if (ret != EFI_SUCCESS)
  472. alt_ret = ret;
  473. if (ro && !(var_property.property & VAR_CHECK_VARIABLE_PROPERTY_READ_ONLY)) {
  474. var_property.revision = VAR_CHECK_VARIABLE_PROPERTY_REVISION;
  475. var_property.property |= VAR_CHECK_VARIABLE_PROPERTY_READ_ONLY;
  476. var_property.attributes = attributes;
  477. var_property.minsize = 1;
  478. var_property.maxsize = var_acc->data_size;
  479. ret = set_property_int(variable_name, name_size, vendor, &var_property);
  480. }
  481. if (alt_ret != EFI_SUCCESS)
  482. goto out;
  483. if (!u16_strcmp(variable_name, L"PK"))
  484. alt_ret = efi_init_secure_state();
  485. out:
  486. free(comm_buf);
  487. return alt_ret == EFI_SUCCESS ? ret : alt_ret;
  488. }
  489. efi_status_t efi_query_variable_info_int(u32 attributes,
  490. u64 *max_variable_storage_size,
  491. u64 *remain_variable_storage_size,
  492. u64 *max_variable_size)
  493. {
  494. struct smm_variable_query_info *mm_query_info;
  495. efi_uintn_t payload_size;
  496. efi_status_t ret;
  497. u8 *comm_buf;
  498. payload_size = sizeof(*mm_query_info);
  499. comm_buf = setup_mm_hdr((void **)&mm_query_info, payload_size,
  500. SMM_VARIABLE_FUNCTION_QUERY_VARIABLE_INFO,
  501. &ret);
  502. if (!comm_buf)
  503. goto out;
  504. mm_query_info->attr = attributes;
  505. ret = mm_communicate(comm_buf, payload_size);
  506. if (ret != EFI_SUCCESS)
  507. goto out;
  508. *max_variable_storage_size = mm_query_info->max_variable_storage;
  509. *remain_variable_storage_size =
  510. mm_query_info->remaining_variable_storage;
  511. *max_variable_size = mm_query_info->max_variable_size;
  512. out:
  513. free(comm_buf);
  514. return ret;
  515. }
  516. /**
  517. * efi_get_variable_runtime() - runtime implementation of GetVariable()
  518. *
  519. * @variable_name: name of the variable
  520. * @guid: vendor GUID
  521. * @attributes: attributes of the variable
  522. * @data_size: size of the buffer to which the variable value is copied
  523. * @data: buffer to which the variable value is copied
  524. * Return: status code
  525. */
  526. static efi_status_t __efi_runtime EFIAPI
  527. efi_get_variable_runtime(u16 *variable_name, const efi_guid_t *guid,
  528. u32 *attributes, efi_uintn_t *data_size, void *data)
  529. {
  530. return EFI_UNSUPPORTED;
  531. }
  532. /**
  533. * efi_get_next_variable_name_runtime() - runtime implementation of
  534. * GetNextVariable()
  535. *
  536. * @variable_name_size: size of variable_name buffer in byte
  537. * @variable_name: name of uefi variable's name in u16
  538. * @guid: vendor's guid
  539. * Return: status code
  540. */
  541. static efi_status_t __efi_runtime EFIAPI
  542. efi_get_next_variable_name_runtime(efi_uintn_t *variable_name_size,
  543. u16 *variable_name, efi_guid_t *guid)
  544. {
  545. return EFI_UNSUPPORTED;
  546. }
  547. /**
  548. * efi_query_variable_info() - get information about EFI variables
  549. *
  550. * This function implements the QueryVariableInfo() runtime service.
  551. *
  552. * See the Unified Extensible Firmware Interface (UEFI) specification for
  553. * details.
  554. *
  555. * @attributes: bitmask to select variables to be
  556. * queried
  557. * @maximum_variable_storage_size: maximum size of storage area for the
  558. * selected variable types
  559. * @remaining_variable_storage_size: remaining size of storage are for the
  560. * selected variable types
  561. * @maximum_variable_size: maximum size of a variable of the
  562. * selected type
  563. * Return: status code
  564. */
  565. efi_status_t EFIAPI __efi_runtime
  566. efi_query_variable_info_runtime(u32 attributes, u64 *max_variable_storage_size,
  567. u64 *remain_variable_storage_size,
  568. u64 *max_variable_size)
  569. {
  570. return EFI_UNSUPPORTED;
  571. }
  572. /**
  573. * efi_set_variable_runtime() - runtime implementation of SetVariable()
  574. *
  575. * @variable_name: name of the variable
  576. * @guid: vendor GUID
  577. * @attributes: attributes of the variable
  578. * @data_size: size of the buffer with the variable value
  579. * @data: buffer with the variable value
  580. * Return: status code
  581. */
  582. static efi_status_t __efi_runtime EFIAPI
  583. efi_set_variable_runtime(u16 *variable_name, const efi_guid_t *guid,
  584. u32 attributes, efi_uintn_t data_size,
  585. const void *data)
  586. {
  587. return EFI_UNSUPPORTED;
  588. }
  589. /**
  590. * efi_variables_boot_exit_notify() - notify ExitBootServices() is called
  591. */
  592. void efi_variables_boot_exit_notify(void)
  593. {
  594. u8 *comm_buf;
  595. efi_status_t ret;
  596. comm_buf = setup_mm_hdr(NULL, 0,
  597. SMM_VARIABLE_FUNCTION_EXIT_BOOT_SERVICE, &ret);
  598. if (comm_buf)
  599. ret = mm_communicate(comm_buf, 0);
  600. else
  601. ret = EFI_NOT_FOUND;
  602. if (ret != EFI_SUCCESS)
  603. log_err("Unable to notify StMM for ExitBootServices\n");
  604. free(comm_buf);
  605. /* Update runtime service table */
  606. efi_runtime_services.query_variable_info =
  607. efi_query_variable_info_runtime;
  608. efi_runtime_services.get_variable = efi_get_variable_runtime;
  609. efi_runtime_services.get_next_variable_name =
  610. efi_get_next_variable_name_runtime;
  611. efi_runtime_services.set_variable = efi_set_variable_runtime;
  612. efi_update_table_header_crc32(&efi_runtime_services.hdr);
  613. }
  614. /**
  615. * efi_init_variables() - initialize variable services
  616. *
  617. * Return: status code
  618. */
  619. efi_status_t efi_init_variables(void)
  620. {
  621. efi_status_t ret;
  622. ret = get_max_payload(&max_payload_size);
  623. if (ret != EFI_SUCCESS)
  624. return ret;
  625. max_buffer_size = MM_COMMUNICATE_HEADER_SIZE +
  626. MM_VARIABLE_COMMUNICATE_SIZE +
  627. max_payload_size;
  628. ret = efi_init_secure_state();
  629. if (ret != EFI_SUCCESS)
  630. return ret;
  631. return EFI_SUCCESS;
  632. }