VlanConfigDriver.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. /** @file
  2. The driver binding for VLAN configuration module.
  3. Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include "VlanConfigImpl.h"
  7. EFI_DRIVER_BINDING_PROTOCOL gVlanConfigDriverBinding = {
  8. VlanConfigDriverBindingSupported,
  9. VlanConfigDriverBindingStart,
  10. VlanConfigDriverBindingStop,
  11. 0xa,
  12. NULL,
  13. NULL
  14. };
  15. /**
  16. The entry point for IP4 config driver which install the driver
  17. binding and component name protocol on its image.
  18. @param[in] ImageHandle The image handle of the driver.
  19. @param[in] SystemTable The system table.
  20. @retval EFI_SUCCESS All the related protocols are installed on the driver.
  21. @retval Others Failed to install protocols.
  22. **/
  23. EFI_STATUS
  24. EFIAPI
  25. VlanConfigDriverEntryPoint (
  26. IN EFI_HANDLE ImageHandle,
  27. IN EFI_SYSTEM_TABLE *SystemTable
  28. )
  29. {
  30. return EfiLibInstallDriverBindingComponentName2 (
  31. ImageHandle,
  32. SystemTable,
  33. &gVlanConfigDriverBinding,
  34. ImageHandle,
  35. &gVlanConfigComponentName,
  36. &gVlanConfigComponentName2
  37. );
  38. }
  39. /**
  40. Test to see if this driver supports ControllerHandle.
  41. @param[in] This Protocol instance pointer.
  42. @param[in] ControllerHandle Handle of device to test
  43. @param[in] RemainingDevicePath Optional parameter use to pick a specific child
  44. device to start.
  45. @retval EFI_SUCCESS This driver supports this device
  46. @retval EFI_ALREADY_STARTED This driver is already running on this device
  47. @retval other This driver does not support this device
  48. **/
  49. EFI_STATUS
  50. EFIAPI
  51. VlanConfigDriverBindingSupported (
  52. IN EFI_DRIVER_BINDING_PROTOCOL *This,
  53. IN EFI_HANDLE ControllerHandle,
  54. IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
  55. )
  56. {
  57. EFI_STATUS Status;
  58. EFI_VLAN_CONFIG_PROTOCOL *VlanConfig;
  59. Status = gBS->OpenProtocol (
  60. ControllerHandle,
  61. &gEfiVlanConfigProtocolGuid,
  62. (VOID **)&VlanConfig,
  63. This->DriverBindingHandle,
  64. ControllerHandle,
  65. EFI_OPEN_PROTOCOL_BY_DRIVER
  66. );
  67. if (EFI_ERROR (Status)) {
  68. return Status;
  69. }
  70. //
  71. // Close the VlanConfig protocol opened for supported test
  72. //
  73. gBS->CloseProtocol (
  74. ControllerHandle,
  75. &gEfiVlanConfigProtocolGuid,
  76. This->DriverBindingHandle,
  77. ControllerHandle
  78. );
  79. return Status;
  80. }
  81. /**
  82. Start this driver on ControllerHandle.
  83. @param[in] This Protocol instance pointer.
  84. @param[in] ControllerHandle Handle of device to bind driver to
  85. @param[in] RemainingDevicePath Optional parameter use to pick a specific child
  86. device to start.
  87. @retval EFI_SUCCESS This driver is added to ControllerHandle
  88. @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
  89. @retval other This driver does not support this device
  90. **/
  91. EFI_STATUS
  92. EFIAPI
  93. VlanConfigDriverBindingStart (
  94. IN EFI_DRIVER_BINDING_PROTOCOL *This,
  95. IN EFI_HANDLE ControllerHandle,
  96. IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
  97. )
  98. {
  99. EFI_STATUS Status;
  100. EFI_VLAN_CONFIG_PROTOCOL *VlanConfig;
  101. EFI_DEVICE_PATH_PROTOCOL *DevicePath;
  102. VLAN_CONFIG_PRIVATE_DATA *PrivateData;
  103. //
  104. // Check for multiple start
  105. //
  106. Status = gBS->OpenProtocol (
  107. ControllerHandle,
  108. &gEfiCallerIdGuid,
  109. (VOID **)&PrivateData,
  110. This->DriverBindingHandle,
  111. ControllerHandle,
  112. EFI_OPEN_PROTOCOL_GET_PROTOCOL
  113. );
  114. if (!EFI_ERROR (Status)) {
  115. return EFI_ALREADY_STARTED;
  116. }
  117. //
  118. // Open VlanConfig protocol by driver
  119. //
  120. Status = gBS->OpenProtocol (
  121. ControllerHandle,
  122. &gEfiVlanConfigProtocolGuid,
  123. (VOID **)&VlanConfig,
  124. This->DriverBindingHandle,
  125. ControllerHandle,
  126. EFI_OPEN_PROTOCOL_BY_DRIVER
  127. );
  128. if (EFI_ERROR (Status)) {
  129. return Status;
  130. }
  131. //
  132. // Get parent device path
  133. //
  134. Status = gBS->OpenProtocol (
  135. ControllerHandle,
  136. &gEfiDevicePathProtocolGuid,
  137. (VOID **)&DevicePath,
  138. This->DriverBindingHandle,
  139. ControllerHandle,
  140. EFI_OPEN_PROTOCOL_GET_PROTOCOL
  141. );
  142. if (EFI_ERROR (Status)) {
  143. goto ErrorExit;
  144. }
  145. //
  146. // Create a private data for this network device
  147. //
  148. PrivateData = AllocateCopyPool (sizeof (VLAN_CONFIG_PRIVATE_DATA), &mVlanConfigPrivateDateTemplate);
  149. if (PrivateData == NULL) {
  150. Status = EFI_OUT_OF_RESOURCES;
  151. goto ErrorExit;
  152. }
  153. PrivateData->ImageHandle = This->DriverBindingHandle;
  154. PrivateData->ControllerHandle = ControllerHandle;
  155. PrivateData->VlanConfig = VlanConfig;
  156. PrivateData->ParentDevicePath = DevicePath;
  157. //
  158. // Install VLAN configuration form
  159. //
  160. Status = InstallVlanConfigForm (PrivateData);
  161. if (EFI_ERROR (Status)) {
  162. goto ErrorExit;
  163. }
  164. //
  165. // Install private GUID
  166. //
  167. Status = gBS->InstallMultipleProtocolInterfaces (
  168. &ControllerHandle,
  169. &gEfiCallerIdGuid,
  170. PrivateData,
  171. NULL
  172. );
  173. if (EFI_ERROR (Status)) {
  174. goto ErrorExit;
  175. }
  176. return Status;
  177. ErrorExit:
  178. gBS->CloseProtocol (
  179. ControllerHandle,
  180. &gEfiVlanConfigProtocolGuid,
  181. This->DriverBindingHandle,
  182. ControllerHandle
  183. );
  184. gBS->CloseProtocol (
  185. ControllerHandle,
  186. &gEfiDevicePathProtocolGuid,
  187. This->DriverBindingHandle,
  188. ControllerHandle
  189. );
  190. if (PrivateData != NULL) {
  191. UninstallVlanConfigForm (PrivateData);
  192. FreePool (PrivateData);
  193. }
  194. return Status;
  195. }
  196. /**
  197. Stop this driver on ControllerHandle.
  198. @param[in] This Protocol instance pointer.
  199. @param[in] ControllerHandle Handle of device to stop driver on
  200. @param[in] NumberOfChildren Number of Handles in ChildHandleBuffer. If number
  201. of children is zero stop the entire bus driver.
  202. @param[in] ChildHandleBuffer List of Child Handles to Stop.
  203. @retval EFI_SUCCESS This driver is removed ControllerHandle
  204. @retval other This driver was not removed from this device
  205. **/
  206. EFI_STATUS
  207. EFIAPI
  208. VlanConfigDriverBindingStop (
  209. IN EFI_DRIVER_BINDING_PROTOCOL *This,
  210. IN EFI_HANDLE ControllerHandle,
  211. IN UINTN NumberOfChildren,
  212. IN EFI_HANDLE *ChildHandleBuffer
  213. )
  214. {
  215. EFI_STATUS Status;
  216. VLAN_CONFIG_PRIVATE_DATA *PrivateData;
  217. //
  218. // Retrieve the PrivateData from ControllerHandle
  219. //
  220. Status = gBS->OpenProtocol (
  221. ControllerHandle,
  222. &gEfiCallerIdGuid,
  223. (VOID **)&PrivateData,
  224. This->DriverBindingHandle,
  225. ControllerHandle,
  226. EFI_OPEN_PROTOCOL_GET_PROTOCOL
  227. );
  228. if (EFI_ERROR (Status)) {
  229. return Status;
  230. }
  231. ASSERT (PrivateData->Signature == VLAN_CONFIG_PRIVATE_DATA_SIGNATURE);
  232. if (NumberOfChildren != 0) {
  233. if ((NumberOfChildren != 1) || (ChildHandleBuffer[0] != PrivateData->DriverHandle)) {
  234. return EFI_DEVICE_ERROR;
  235. }
  236. return UninstallVlanConfigForm (PrivateData);
  237. }
  238. //
  239. // Uninstall the private GUID
  240. //
  241. Status = gBS->UninstallMultipleProtocolInterfaces (
  242. ControllerHandle,
  243. &gEfiCallerIdGuid,
  244. PrivateData,
  245. NULL
  246. );
  247. if (EFI_ERROR (Status)) {
  248. return Status;
  249. }
  250. Status = gBS->CloseProtocol (
  251. ControllerHandle,
  252. &gEfiVlanConfigProtocolGuid,
  253. This->DriverBindingHandle,
  254. ControllerHandle
  255. );
  256. return Status;
  257. }