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

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