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.

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