Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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