You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

efi_snp_hii.c 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. /*
  2. * Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA.
  18. */
  19. FILE_LICENCE ( GPL2_OR_LATER );
  20. /**
  21. * @file
  22. *
  23. * EFI SNP HII protocol
  24. *
  25. * The HII protocols are some of the less-well designed parts of the
  26. * entire EFI specification. This is a significant accomplishment.
  27. *
  28. * The face-slappingly ludicrous query string syntax seems to be
  29. * motivated by the desire to allow a caller to query multiple drivers
  30. * simultaneously via the single-instance HII_CONFIG_ROUTING_PROTOCOL,
  31. * which is supposed to pass relevant subsets of the query string to
  32. * the relevant drivers.
  33. *
  34. * Nobody uses the HII_CONFIG_ROUTING_PROTOCOL. Not even the EFI
  35. * setup browser uses the HII_CONFIG_ROUTING_PROTOCOL. To the best of
  36. * my knowledge, there has only ever been one implementation of the
  37. * HII_CONFIG_ROUTING_PROTOCOL (as part of EDK2), and it just doesn't
  38. * work. It's so badly broken that I can't even figure out what the
  39. * code is _trying_ to do.
  40. *
  41. * Fundamentally, the problem seems to be that Javascript programmers
  42. * should not be allowed to design APIs for C code.
  43. */
  44. #include <string.h>
  45. #include <strings.h>
  46. #include <stdlib.h>
  47. #include <stdio.h>
  48. #include <wchar.h>
  49. #include <errno.h>
  50. #include <ipxe/settings.h>
  51. #include <ipxe/nvo.h>
  52. #include <ipxe/device.h>
  53. #include <ipxe/netdevice.h>
  54. #include <ipxe/version.h>
  55. #include <ipxe/efi/efi.h>
  56. #include <ipxe/efi/efi_hii.h>
  57. #include <ipxe/efi/efi_snp.h>
  58. #include <ipxe/efi/efi_strings.h>
  59. #include <config/general.h>
  60. /** EFI configuration access protocol GUID */
  61. static EFI_GUID efi_hii_config_access_protocol_guid
  62. = EFI_HII_CONFIG_ACCESS_PROTOCOL_GUID;
  63. /** EFI platform setup formset GUID */
  64. static EFI_GUID efi_hii_platform_setup_formset_guid
  65. = EFI_HII_PLATFORM_SETUP_FORMSET_GUID;
  66. /** EFI IBM UCM compliant formset GUID */
  67. static EFI_GUID efi_hii_ibm_ucm_compliant_formset_guid
  68. = EFI_HII_IBM_UCM_COMPLIANT_FORMSET_GUID;
  69. /** EFI HII database protocol */
  70. static EFI_HII_DATABASE_PROTOCOL *efihii;
  71. EFI_REQUIRE_PROTOCOL ( EFI_HII_DATABASE_PROTOCOL, &efihii );
  72. /**
  73. * Identify settings to be exposed via HII
  74. *
  75. * @v snpdev SNP device
  76. * @ret settings Settings, or NULL
  77. */
  78. static struct settings * efi_snp_hii_settings ( struct efi_snp_device *snpdev ){
  79. return find_child_settings ( netdev_settings ( snpdev->netdev ),
  80. NVO_SETTINGS_NAME );
  81. }
  82. /**
  83. * Check whether or not setting is applicable
  84. *
  85. * @v snpdev SNP device
  86. * @v setting Setting
  87. * @ret applies Setting applies
  88. */
  89. static int efi_snp_hii_setting_applies ( struct efi_snp_device *snpdev,
  90. struct setting *setting ) {
  91. return nvo_applies ( efi_snp_hii_settings ( snpdev ), setting );
  92. }
  93. /**
  94. * Generate a random GUID
  95. *
  96. * @v guid GUID to fill in
  97. */
  98. static void efi_snp_hii_random_guid ( EFI_GUID *guid ) {
  99. uint8_t *byte = ( ( uint8_t * ) guid );
  100. unsigned int i;
  101. for ( i = 0 ; i < sizeof ( *guid ) ; i++ )
  102. *(byte++) = random();
  103. }
  104. /**
  105. * Generate EFI SNP questions
  106. *
  107. * @v snpdev SNP device
  108. * @v ifr IFR builder
  109. * @v varstore_id Variable store identifier
  110. */
  111. static void efi_snp_hii_questions ( struct efi_snp_device *snpdev,
  112. struct efi_ifr_builder *ifr,
  113. unsigned int varstore_id ) {
  114. struct setting *setting;
  115. struct setting *previous = NULL;
  116. unsigned int name_id;
  117. unsigned int prompt_id;
  118. unsigned int help_id;
  119. unsigned int question_id;
  120. /* Add all applicable settings */
  121. for_each_table_entry ( setting, SETTINGS ) {
  122. if ( ! efi_snp_hii_setting_applies ( snpdev, setting ) )
  123. continue;
  124. if ( previous && ( setting_cmp ( setting, previous ) == 0 ) )
  125. continue;
  126. previous = setting;
  127. name_id = efi_ifr_string ( ifr, "%s", setting->name );
  128. prompt_id = efi_ifr_string ( ifr, "%s", setting->description );
  129. help_id = efi_ifr_string ( ifr, "http://ipxe.org/cfg/%s",
  130. setting->name );
  131. question_id = setting->tag;
  132. efi_ifr_string_op ( ifr, prompt_id, help_id,
  133. question_id, varstore_id, name_id,
  134. 0, 0x00, 0xff, 0 );
  135. }
  136. }
  137. /**
  138. * Build HII package list for SNP device
  139. *
  140. * @v snpdev SNP device
  141. * @ret package Package list, or NULL on error
  142. */
  143. static EFI_HII_PACKAGE_LIST_HEADER *
  144. efi_snp_hii_package_list ( struct efi_snp_device *snpdev ) {
  145. struct net_device *netdev = snpdev->netdev;
  146. struct device *dev = netdev->dev;
  147. struct efi_ifr_builder ifr;
  148. EFI_HII_PACKAGE_LIST_HEADER *package;
  149. const char *product_name;
  150. EFI_GUID package_guid;
  151. EFI_GUID formset_guid;
  152. EFI_GUID varstore_guid;
  153. unsigned int title_id;
  154. unsigned int varstore_id;
  155. /* Initialise IFR builder */
  156. efi_ifr_init ( &ifr );
  157. /* Determine product name */
  158. product_name = ( PRODUCT_NAME[0] ? PRODUCT_NAME : PRODUCT_SHORT_NAME );
  159. /* Generate GUIDs */
  160. efi_snp_hii_random_guid ( &package_guid );
  161. efi_snp_hii_random_guid ( &formset_guid );
  162. efi_snp_hii_random_guid ( &varstore_guid );
  163. /* Generate title string (used more than once) */
  164. title_id = efi_ifr_string ( &ifr, "%s (%s)", product_name,
  165. netdev_addr ( netdev ) );
  166. /* Generate opcodes */
  167. efi_ifr_form_set_op ( &ifr, &formset_guid, title_id,
  168. efi_ifr_string ( &ifr,
  169. "Configure " PRODUCT_SHORT_NAME),
  170. &efi_hii_platform_setup_formset_guid,
  171. &efi_hii_ibm_ucm_compliant_formset_guid, NULL );
  172. efi_ifr_guid_class_op ( &ifr, EFI_NETWORK_DEVICE_CLASS );
  173. efi_ifr_guid_subclass_op ( &ifr, 0x03 );
  174. varstore_id = efi_ifr_varstore_name_value_op ( &ifr, &varstore_guid );
  175. efi_ifr_form_op ( &ifr, title_id );
  176. efi_ifr_text_op ( &ifr,
  177. efi_ifr_string ( &ifr, "Name" ),
  178. efi_ifr_string ( &ifr, "Firmware product name" ),
  179. efi_ifr_string ( &ifr, "%s", product_name ) );
  180. efi_ifr_text_op ( &ifr,
  181. efi_ifr_string ( &ifr, "Version" ),
  182. efi_ifr_string ( &ifr, "Firmware version" ),
  183. efi_ifr_string ( &ifr, "%s", product_version ) );
  184. efi_ifr_text_op ( &ifr,
  185. efi_ifr_string ( &ifr, "Driver" ),
  186. efi_ifr_string ( &ifr, "Firmware driver" ),
  187. efi_ifr_string ( &ifr, "%s", dev->driver_name ) );
  188. efi_ifr_text_op ( &ifr,
  189. efi_ifr_string ( &ifr, "Device" ),
  190. efi_ifr_string ( &ifr, "Hardware device" ),
  191. efi_ifr_string ( &ifr, "%s", dev->name ) );
  192. efi_snp_hii_questions ( snpdev, &ifr, varstore_id );
  193. efi_ifr_end_op ( &ifr );
  194. efi_ifr_end_op ( &ifr );
  195. /* Build package */
  196. package = efi_ifr_package ( &ifr, &package_guid, "en-us",
  197. efi_ifr_string ( &ifr, "English" ) );
  198. if ( ! package ) {
  199. DBGC ( snpdev, "SNPDEV %p could not build IFR package\n",
  200. snpdev );
  201. efi_ifr_free ( &ifr );
  202. return NULL;
  203. }
  204. /* Free temporary storage */
  205. efi_ifr_free ( &ifr );
  206. return package;
  207. }
  208. /**
  209. * Append response to result string
  210. *
  211. * @v snpdev SNP device
  212. * @v key Key
  213. * @v value Value
  214. * @v results Result string
  215. * @ret rc Return status code
  216. *
  217. * The result string is allocated dynamically using
  218. * BootServices::AllocatePool(), and the caller is responsible for
  219. * eventually calling BootServices::FreePool().
  220. */
  221. static int efi_snp_hii_append ( struct efi_snp_device *snpdev __unused,
  222. const char *key, const char *value,
  223. wchar_t **results ) {
  224. EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
  225. size_t len;
  226. void *new;
  227. /* Allocate new string */
  228. len = ( ( *results ? ( wcslen ( *results ) + 1 /* "&" */ ) : 0 ) +
  229. strlen ( key ) + 1 /* "=" */ + strlen ( value ) + 1 /* NUL */ );
  230. bs->AllocatePool ( EfiBootServicesData, ( len * sizeof ( wchar_t ) ),
  231. &new );
  232. if ( ! new )
  233. return -ENOMEM;
  234. /* Populate string */
  235. efi_snprintf ( new, len, "%ls%s%s=%s", ( *results ? *results : L"" ),
  236. ( *results ? L"&" : L"" ), key, value );
  237. bs->FreePool ( *results );
  238. *results = new;
  239. return 0;
  240. }
  241. /**
  242. * Fetch HII setting
  243. *
  244. * @v snpdev SNP device
  245. * @v key Key
  246. * @v value Value
  247. * @v results Result string
  248. * @v have_setting Flag indicating detection of a setting
  249. * @ret rc Return status code
  250. */
  251. static int efi_snp_hii_fetch ( struct efi_snp_device *snpdev,
  252. const char *key, const char *value,
  253. wchar_t **results, int *have_setting ) {
  254. struct settings *settings = efi_snp_hii_settings ( snpdev );
  255. struct settings *origin;
  256. struct setting *setting;
  257. struct setting fetched;
  258. int len;
  259. char *buf;
  260. char *encoded;
  261. int i;
  262. int rc;
  263. /* Handle ConfigHdr components */
  264. if ( ( strcasecmp ( key, "GUID" ) == 0 ) ||
  265. ( strcasecmp ( key, "NAME" ) == 0 ) ||
  266. ( strcasecmp ( key, "PATH" ) == 0 ) ) {
  267. return efi_snp_hii_append ( snpdev, key, value, results );
  268. }
  269. if ( have_setting )
  270. *have_setting = 1;
  271. /* Do nothing more unless we have a settings block */
  272. if ( ! settings ) {
  273. rc = -ENOTSUP;
  274. goto err_no_settings;
  275. }
  276. /* Identify setting */
  277. setting = find_setting ( key );
  278. if ( ! setting ) {
  279. DBGC ( snpdev, "SNPDEV %p no such setting \"%s\"\n",
  280. snpdev, key );
  281. rc = -ENODEV;
  282. goto err_find_setting;
  283. }
  284. /* Encode value */
  285. if ( setting_exists ( settings, setting ) ) {
  286. /* Calculate formatted length */
  287. len = fetchf_setting ( settings, setting, &origin, &fetched,
  288. NULL, 0 );
  289. if ( len < 0 ) {
  290. rc = len;
  291. DBGC ( snpdev, "SNPDEV %p could not fetch %s: %s\n",
  292. snpdev, setting->name, strerror ( rc ) );
  293. goto err_fetchf_len;
  294. }
  295. /* Allocate buffer for formatted value and HII-encoded value */
  296. buf = zalloc ( len + 1 /* NUL */ + ( len * 4 ) + 1 /* NUL */ );
  297. if ( ! buf ) {
  298. rc = -ENOMEM;
  299. goto err_alloc;
  300. }
  301. encoded = ( buf + len + 1 /* NUL */ );
  302. /* Format value */
  303. fetchf_setting ( origin, &fetched, NULL, NULL, buf,
  304. ( len + 1 /* NUL */ ) );
  305. for ( i = 0 ; i < len ; i++ ) {
  306. sprintf ( ( encoded + ( 4 * i ) ), "%04x",
  307. *( ( uint8_t * ) buf + i ) );
  308. }
  309. } else {
  310. /* Non-existent or inapplicable setting */
  311. buf = NULL;
  312. encoded = "";
  313. }
  314. /* Append results */
  315. if ( ( rc = efi_snp_hii_append ( snpdev, key, encoded,
  316. results ) ) != 0 ) {
  317. goto err_append;
  318. }
  319. /* Success */
  320. rc = 0;
  321. err_append:
  322. free ( buf );
  323. err_alloc:
  324. err_fetchf_len:
  325. err_find_setting:
  326. err_no_settings:
  327. return rc;
  328. }
  329. /**
  330. * Fetch HII setting
  331. *
  332. * @v snpdev SNP device
  333. * @v key Key
  334. * @v value Value
  335. * @v results Result string (unused)
  336. * @v have_setting Flag indicating detection of a setting (unused)
  337. * @ret rc Return status code
  338. */
  339. static int efi_snp_hii_store ( struct efi_snp_device *snpdev,
  340. const char *key, const char *value,
  341. wchar_t **results __unused,
  342. int *have_setting __unused ) {
  343. struct settings *settings = efi_snp_hii_settings ( snpdev );
  344. struct setting *setting;
  345. char *buf;
  346. char tmp[5];
  347. char *endp;
  348. int len;
  349. int i;
  350. int rc;
  351. /* Handle ConfigHdr components */
  352. if ( ( strcasecmp ( key, "GUID" ) == 0 ) ||
  353. ( strcasecmp ( key, "NAME" ) == 0 ) ||
  354. ( strcasecmp ( key, "PATH" ) == 0 ) ) {
  355. /* Nothing to do */
  356. return 0;
  357. }
  358. /* Do nothing more unless we have a settings block */
  359. if ( ! settings ) {
  360. rc = -ENOTSUP;
  361. goto err_no_settings;
  362. }
  363. /* Identify setting */
  364. setting = find_setting ( key );
  365. if ( ! setting ) {
  366. DBGC ( snpdev, "SNPDEV %p no such setting \"%s\"\n",
  367. snpdev, key );
  368. rc = -ENODEV;
  369. goto err_find_setting;
  370. }
  371. /* Allocate buffer */
  372. len = ( strlen ( value ) / 4 );
  373. buf = zalloc ( len + 1 /* NUL */ );
  374. if ( ! buf ) {
  375. rc = -ENOMEM;
  376. goto err_alloc;
  377. }
  378. /* Decode value */
  379. tmp[4] = '\0';
  380. for ( i = 0 ; i < len ; i++ ) {
  381. memcpy ( tmp, ( value + ( i * 4 ) ), 4 );
  382. buf[i] = strtoul ( tmp, &endp, 16 );
  383. if ( endp != &tmp[4] ) {
  384. DBGC ( snpdev, "SNPDEV %p invalid character %s\n",
  385. snpdev, tmp );
  386. rc = -EINVAL;
  387. goto err_inval;
  388. }
  389. }
  390. /* Store value */
  391. if ( ( rc = storef_setting ( settings, setting, buf ) ) != 0 ) {
  392. DBGC ( snpdev, "SNPDEV %p could not store \"%s\" into %s: %s\n",
  393. snpdev, buf, setting->name, strerror ( rc ) );
  394. goto err_storef;
  395. }
  396. /* Success */
  397. rc = 0;
  398. err_storef:
  399. err_inval:
  400. free ( buf );
  401. err_alloc:
  402. err_find_setting:
  403. err_no_settings:
  404. return rc;
  405. }
  406. /**
  407. * Process portion of HII configuration string
  408. *
  409. * @v snpdev SNP device
  410. * @v string HII configuration string
  411. * @v progress Progress through HII configuration string
  412. * @v results Results string
  413. * @v have_setting Flag indicating detection of a setting (unused)
  414. * @v process Function used to process key=value pairs
  415. * @ret rc Return status code
  416. */
  417. static int efi_snp_hii_process ( struct efi_snp_device *snpdev,
  418. wchar_t *string, wchar_t **progress,
  419. wchar_t **results, int *have_setting,
  420. int ( * process ) ( struct efi_snp_device *,
  421. const char *key,
  422. const char *value,
  423. wchar_t **results,
  424. int *have_setting ) ) {
  425. wchar_t *wkey = string;
  426. wchar_t *wend = string;
  427. wchar_t *wvalue = NULL;
  428. size_t key_len;
  429. size_t value_len;
  430. void *temp;
  431. char *key;
  432. char *value;
  433. int rc;
  434. /* Locate key, value (if any), and end */
  435. while ( *wend ) {
  436. if ( *wend == L'&' )
  437. break;
  438. if ( *(wend++) == L'=' )
  439. wvalue = wend;
  440. }
  441. /* Allocate memory for key and value */
  442. key_len = ( ( wvalue ? ( wvalue - 1 ) : wend ) - wkey );
  443. value_len = ( wvalue ? ( wend - wvalue ) : 0 );
  444. temp = zalloc ( key_len + 1 /* NUL */ + value_len + 1 /* NUL */ );
  445. if ( ! temp )
  446. return -ENOMEM;
  447. key = temp;
  448. value = ( temp + key_len + 1 /* NUL */ );
  449. /* Copy key and value */
  450. while ( key_len-- )
  451. key[key_len] = wkey[key_len];
  452. while ( value_len-- )
  453. value[value_len] = wvalue[value_len];
  454. /* Process key and value */
  455. if ( ( rc = process ( snpdev, key, value, results,
  456. have_setting ) ) != 0 ) {
  457. goto err;
  458. }
  459. /* Update progress marker */
  460. *progress = wend;
  461. err:
  462. /* Free temporary storage */
  463. free ( temp );
  464. return rc;
  465. }
  466. /**
  467. * Fetch configuration
  468. *
  469. * @v hii HII configuration access protocol
  470. * @v request Configuration to fetch
  471. * @ret progress Progress made through configuration to fetch
  472. * @ret results Query results
  473. * @ret efirc EFI status code
  474. */
  475. static EFI_STATUS EFIAPI
  476. efi_snp_hii_extract_config ( const EFI_HII_CONFIG_ACCESS_PROTOCOL *hii,
  477. EFI_STRING request, EFI_STRING *progress,
  478. EFI_STRING *results ) {
  479. struct efi_snp_device *snpdev =
  480. container_of ( hii, struct efi_snp_device, hii );
  481. int have_setting = 0;
  482. wchar_t *pos;
  483. int rc;
  484. DBGC ( snpdev, "SNPDEV %p ExtractConfig request \"%ls\"\n",
  485. snpdev, request );
  486. /* Initialise results */
  487. *results = NULL;
  488. /* Process all request fragments */
  489. for ( pos = *progress = request ; *progress && **progress ;
  490. pos = *progress + 1 ) {
  491. if ( ( rc = efi_snp_hii_process ( snpdev, pos, progress,
  492. results, &have_setting,
  493. efi_snp_hii_fetch ) ) != 0 ) {
  494. return EFIRC ( rc );
  495. }
  496. }
  497. /* If we have no explicit request, return all settings */
  498. if ( ! have_setting ) {
  499. struct setting *setting;
  500. for_each_table_entry ( setting, SETTINGS ) {
  501. if ( ! efi_snp_hii_setting_applies ( snpdev, setting ) )
  502. continue;
  503. if ( ( rc = efi_snp_hii_fetch ( snpdev, setting->name,
  504. NULL, results,
  505. NULL ) ) != 0 ) {
  506. return EFIRC ( rc );
  507. }
  508. }
  509. }
  510. DBGC ( snpdev, "SNPDEV %p ExtractConfig results \"%ls\"\n",
  511. snpdev, *results );
  512. return 0;
  513. }
  514. /**
  515. * Store configuration
  516. *
  517. * @v hii HII configuration access protocol
  518. * @v config Configuration to store
  519. * @ret progress Progress made through configuration to store
  520. * @ret efirc EFI status code
  521. */
  522. static EFI_STATUS EFIAPI
  523. efi_snp_hii_route_config ( const EFI_HII_CONFIG_ACCESS_PROTOCOL *hii,
  524. EFI_STRING config, EFI_STRING *progress ) {
  525. struct efi_snp_device *snpdev =
  526. container_of ( hii, struct efi_snp_device, hii );
  527. wchar_t *pos;
  528. int rc;
  529. DBGC ( snpdev, "SNPDEV %p RouteConfig \"%ls\"\n", snpdev, config );
  530. /* Process all request fragments */
  531. for ( pos = *progress = config ; *progress && **progress ;
  532. pos = *progress + 1 ) {
  533. if ( ( rc = efi_snp_hii_process ( snpdev, pos, progress,
  534. NULL, NULL,
  535. efi_snp_hii_store ) ) != 0 ) {
  536. return EFIRC ( rc );
  537. }
  538. }
  539. return 0;
  540. }
  541. /**
  542. * Handle form actions
  543. *
  544. * @v hii HII configuration access protocol
  545. * @v action Form browser action
  546. * @v question_id Question ID
  547. * @v type Type of value
  548. * @v value Value
  549. * @ret action_request Action requested by driver
  550. * @ret efirc EFI status code
  551. */
  552. static EFI_STATUS EFIAPI
  553. efi_snp_hii_callback ( const EFI_HII_CONFIG_ACCESS_PROTOCOL *hii,
  554. EFI_BROWSER_ACTION action __unused,
  555. EFI_QUESTION_ID question_id __unused,
  556. UINT8 type __unused, EFI_IFR_TYPE_VALUE *value __unused,
  557. EFI_BROWSER_ACTION_REQUEST *action_request __unused ) {
  558. struct efi_snp_device *snpdev =
  559. container_of ( hii, struct efi_snp_device, hii );
  560. DBGC ( snpdev, "SNPDEV %p Callback\n", snpdev );
  561. return EFI_UNSUPPORTED;
  562. }
  563. /** HII configuration access protocol */
  564. static EFI_HII_CONFIG_ACCESS_PROTOCOL efi_snp_device_hii = {
  565. .ExtractConfig = efi_snp_hii_extract_config,
  566. .RouteConfig = efi_snp_hii_route_config,
  567. .Callback = efi_snp_hii_callback,
  568. };
  569. /**
  570. * Install HII protocol and packages for SNP device
  571. *
  572. * @v snpdev SNP device
  573. * @ret rc Return status code
  574. */
  575. int efi_snp_hii_install ( struct efi_snp_device *snpdev ) {
  576. EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
  577. int efirc;
  578. int rc;
  579. /* Initialise HII protocol */
  580. memcpy ( &snpdev->hii, &efi_snp_device_hii, sizeof ( snpdev->hii ) );
  581. /* Create HII package list */
  582. snpdev->package_list = efi_snp_hii_package_list ( snpdev );
  583. if ( ! snpdev->package_list ) {
  584. DBGC ( snpdev, "SNPDEV %p could not create HII package list\n",
  585. snpdev );
  586. rc = -ENOMEM;
  587. goto err_build_package_list;
  588. }
  589. /* Add HII packages */
  590. if ( ( efirc = efihii->NewPackageList ( efihii, snpdev->package_list,
  591. snpdev->handle,
  592. &snpdev->hii_handle ) ) != 0 ) {
  593. rc = -EEFI ( efirc );
  594. DBGC ( snpdev, "SNPDEV %p could not add HII packages: %s\n",
  595. snpdev, strerror ( rc ) );
  596. goto err_new_package_list;
  597. }
  598. /* Install HII protocol */
  599. if ( ( efirc = bs->InstallMultipleProtocolInterfaces (
  600. &snpdev->handle,
  601. &efi_hii_config_access_protocol_guid, &snpdev->hii,
  602. NULL ) ) != 0 ) {
  603. rc = -EEFI ( efirc );
  604. DBGC ( snpdev, "SNPDEV %p could not install HII protocol: %s\n",
  605. snpdev, strerror ( rc ) );
  606. goto err_install_protocol;
  607. }
  608. return 0;
  609. bs->UninstallMultipleProtocolInterfaces (
  610. snpdev->handle,
  611. &efi_hii_config_access_protocol_guid, &snpdev->hii,
  612. NULL );
  613. err_install_protocol:
  614. efihii->RemovePackageList ( efihii, snpdev->hii_handle );
  615. err_new_package_list:
  616. free ( snpdev->package_list );
  617. snpdev->package_list = NULL;
  618. err_build_package_list:
  619. return rc;
  620. }
  621. /**
  622. * Uninstall HII protocol and package for SNP device
  623. *
  624. * @v snpdev SNP device
  625. */
  626. void efi_snp_hii_uninstall ( struct efi_snp_device *snpdev ) {
  627. EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
  628. bs->UninstallMultipleProtocolInterfaces (
  629. snpdev->handle,
  630. &efi_hii_config_access_protocol_guid, &snpdev->hii,
  631. NULL );
  632. efihii->RemovePackageList ( efihii, snpdev->hii_handle );
  633. free ( snpdev->package_list );
  634. snpdev->package_list = NULL;
  635. }