Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

efi_driver.c 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * Copyright (C) 2011 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 <stddef.h>
  20. #include <stdio.h>
  21. #include <ipxe/efi/efi.h>
  22. #include <ipxe/efi/Protocol/DriverBinding.h>
  23. #include <ipxe/efi/Protocol/ComponentName2.h>
  24. #include <ipxe/efi/efi_strings.h>
  25. #include <ipxe/efi/efi_driver.h>
  26. #include <config/general.h>
  27. /** @file
  28. *
  29. * EFI driver interface
  30. *
  31. */
  32. /** EFI driver binding protocol GUID */
  33. static EFI_GUID efi_driver_binding_protocol_guid
  34. = EFI_DRIVER_BINDING_PROTOCOL_GUID;
  35. /** EFI component name protocol GUID */
  36. static EFI_GUID efi_component_name2_protocol_guid
  37. = EFI_COMPONENT_NAME2_PROTOCOL_GUID;
  38. /**
  39. * Find end of device path
  40. *
  41. * @v path Path to device
  42. * @ret path_end End of device path
  43. */
  44. EFI_DEVICE_PATH_PROTOCOL * efi_devpath_end ( EFI_DEVICE_PATH_PROTOCOL *path ) {
  45. while ( path->Type != END_DEVICE_PATH_TYPE ) {
  46. path = ( ( ( void * ) path ) +
  47. /* There's this amazing new-fangled thing known as
  48. * a UINT16, but who wants to use one of those? */
  49. ( ( path->Length[1] << 8 ) | path->Length[0] ) );
  50. }
  51. return path;
  52. }
  53. /**
  54. * Look up driver name
  55. *
  56. * @v wtf Component name protocol
  57. * @v language Language to use
  58. * @v driver_name Driver name to fill in
  59. * @ret efirc EFI status code
  60. */
  61. static EFI_STATUS EFIAPI
  62. efi_driver_get_driver_name ( EFI_COMPONENT_NAME2_PROTOCOL *wtf,
  63. CHAR8 *language __unused, CHAR16 **driver_name ) {
  64. struct efi_driver *efidrv =
  65. container_of ( wtf, struct efi_driver, wtf );
  66. *driver_name = efidrv->wname;
  67. return 0;
  68. }
  69. /**
  70. * Look up controller name
  71. *
  72. * @v wtf Component name protocol
  73. * @v device Device
  74. * @v child Child device, or NULL
  75. * @v language Language to use
  76. * @v driver_name Device name to fill in
  77. * @ret efirc EFI status code
  78. */
  79. static EFI_STATUS EFIAPI
  80. efi_driver_get_controller_name ( EFI_COMPONENT_NAME2_PROTOCOL *wtf __unused,
  81. EFI_HANDLE device __unused,
  82. EFI_HANDLE child __unused,
  83. CHAR8 *language __unused,
  84. CHAR16 **controller_name __unused ) {
  85. /* Just let EFI use the default Device Path Name */
  86. return EFI_UNSUPPORTED;
  87. }
  88. /**
  89. * Install EFI driver
  90. *
  91. * @v efidrv EFI driver
  92. * @ret efirc EFI status code
  93. */
  94. EFI_STATUS efi_driver_install ( struct efi_driver *efidrv ) {
  95. EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
  96. EFI_DRIVER_BINDING_PROTOCOL *driver = &efidrv->driver;
  97. EFI_COMPONENT_NAME2_PROTOCOL *wtf = &efidrv->wtf;
  98. EFI_STATUS efirc;
  99. /* Configure driver binding protocol */
  100. driver->ImageHandle = efi_image_handle;
  101. /* Configure component name protocol */
  102. wtf->GetDriverName = efi_driver_get_driver_name;
  103. wtf->GetControllerName = efi_driver_get_controller_name;
  104. wtf->SupportedLanguages = "en";
  105. /* Fill in driver name */
  106. efi_snprintf ( efidrv->wname,
  107. ( sizeof ( efidrv->wname ) /
  108. sizeof ( efidrv->wname[0] ) ),
  109. PRODUCT_SHORT_NAME " - %s", efidrv->name );
  110. /* Install driver */
  111. if ( ( efirc = bs->InstallMultipleProtocolInterfaces (
  112. &driver->DriverBindingHandle,
  113. &efi_driver_binding_protocol_guid, driver,
  114. &efi_component_name2_protocol_guid, wtf,
  115. NULL ) ) != 0 ) {
  116. DBGC ( efidrv, "EFIDRV %s could not install protocol: %s\n",
  117. efidrv->name, efi_strerror ( efirc ) );
  118. return efirc;
  119. }
  120. DBGC ( efidrv, "EFIDRV %s installed\n", efidrv->name );
  121. return 0;
  122. }