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_init.c 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Copyright (C) 2008 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., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. FILE_LICENCE ( GPL2_OR_LATER );
  19. #include <string.h>
  20. #include <gpxe/efi/efi.h>
  21. #include <gpxe/uuid.h>
  22. /** Image handle passed to entry point */
  23. EFI_HANDLE efi_image_handle;
  24. /** System table passed to entry point */
  25. EFI_SYSTEM_TABLE *efi_systab;
  26. /**
  27. * Look up EFI configuration table
  28. *
  29. * @v guid Configuration table GUID
  30. * @ret table Configuration table, or NULL
  31. */
  32. static void * efi_find_table ( EFI_GUID *guid ) {
  33. unsigned int i;
  34. for ( i = 0 ; i < efi_systab->NumberOfTableEntries ; i++ ) {
  35. if ( memcmp ( &efi_systab->ConfigurationTable[i].VendorGuid,
  36. guid, sizeof ( *guid ) ) == 0 )
  37. return efi_systab->ConfigurationTable[i].VendorTable;
  38. }
  39. return NULL;
  40. }
  41. /**
  42. * Initialise EFI environment
  43. *
  44. * @v image_handle Image handle
  45. * @v systab System table
  46. * @ret efirc EFI return status code
  47. */
  48. EFI_STATUS efi_init ( EFI_HANDLE image_handle,
  49. EFI_SYSTEM_TABLE *systab ) {
  50. EFI_BOOT_SERVICES *bs;
  51. struct efi_protocol *prot;
  52. struct efi_config_table *tab;
  53. EFI_STATUS efirc;
  54. /* Store image handle and system table pointer for future use */
  55. efi_image_handle = image_handle;
  56. efi_systab = systab;
  57. /* Sanity checks */
  58. if ( ! systab )
  59. return EFI_NOT_AVAILABLE_YET;
  60. if ( ! systab->ConOut )
  61. return EFI_NOT_AVAILABLE_YET;
  62. if ( ! systab->BootServices ) {
  63. DBGC ( systab, "EFI provided no BootServices entry point\n" );
  64. return EFI_NOT_AVAILABLE_YET;
  65. }
  66. if ( ! systab->RuntimeServices ) {
  67. DBGC ( systab, "EFI provided no RuntimeServices entry "
  68. "point\n" );
  69. return EFI_NOT_AVAILABLE_YET;
  70. }
  71. DBGC ( systab, "EFI handle %p systab %p\n", image_handle, systab );
  72. /* Look up used protocols */
  73. bs = systab->BootServices;
  74. for_each_table_entry ( prot, EFI_PROTOCOLS ) {
  75. if ( ( efirc = bs->LocateProtocol ( &prot->u.guid, NULL,
  76. prot->protocol ) ) == 0 ) {
  77. DBGC ( systab, "EFI protocol %s is at %p\n",
  78. uuid_ntoa ( &prot->u.uuid ), *(prot->protocol));
  79. } else {
  80. DBGC ( systab, "EFI does not provide protocol %s\n",
  81. uuid_ntoa ( &prot->u.uuid ) );
  82. /* All protocols are required */
  83. return efirc;
  84. }
  85. }
  86. /* Look up used configuration tables */
  87. for_each_table_entry ( tab, EFI_CONFIG_TABLES ) {
  88. if ( ( *(tab->table) = efi_find_table ( &tab->u.guid ) ) ) {
  89. DBGC ( systab, "EFI configuration table %s is at %p\n",
  90. uuid_ntoa ( &tab->u.uuid ), *(tab->table) );
  91. } else {
  92. DBGC ( systab, "EFI does not provide configuration "
  93. "table %s\n", uuid_ntoa ( &tab->u.uuid ) );
  94. if ( tab->required )
  95. return EFI_NOT_AVAILABLE_YET;
  96. }
  97. }
  98. return 0;
  99. }