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

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