IsaBusDxe.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. /** @file
  2. This file consumes the ISA Host Controller protocol produced by the ISA Host
  3. Controller and installs the ISA Host Controller Service Binding protocol
  4. on the ISA Host Controller's handle.
  5. Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
  6. SPDX-License-Identifier: BSD-2-Clause-Patent
  7. **/
  8. #include "IsaBusDxe.h"
  9. #include "ComponentName.h"
  10. /**
  11. Tests to see if this driver supports a given controller. If a child device is provided,
  12. it further tests to see if this driver supports creating a handle for the specified child device.
  13. @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
  14. @param[in] ControllerHandle The handle of the controller to test. This handle
  15. must support a protocol interface that supplies
  16. an I/O abstraction to the driver.
  17. @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
  18. parameter is ignored by device drivers, and is optional for bus
  19. drivers. For bus drivers, if this parameter is not NULL, then
  20. the bus driver must determine if the bus controller specified
  21. by ControllerHandle and the child controller specified
  22. by RemainingDevicePath are both supported by this
  23. bus driver.
  24. @retval EFI_SUCCESS The device specified by ControllerHandle and
  25. RemainingDevicePath is supported by the driver specified by This.
  26. @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
  27. RemainingDevicePath is already being managed by the driver
  28. specified by This.
  29. @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
  30. RemainingDevicePath is already being managed by a different
  31. driver or an application that requires exclusive access.
  32. Currently not implemented.
  33. @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
  34. RemainingDevicePath is not supported by the driver specified by This.
  35. **/
  36. EFI_STATUS
  37. EFIAPI
  38. IsaBusDriverBindingSupported (
  39. IN EFI_DRIVER_BINDING_PROTOCOL *This,
  40. IN EFI_HANDLE Controller,
  41. IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
  42. )
  43. {
  44. EFI_STATUS Status;
  45. VOID *Instance;
  46. Status = gBS->OpenProtocol (
  47. Controller,
  48. &gEfiIsaHcProtocolGuid,
  49. &Instance,
  50. This->DriverBindingHandle,
  51. Controller,
  52. EFI_OPEN_PROTOCOL_BY_DRIVER
  53. );
  54. if (!EFI_ERROR (Status)) {
  55. gBS->CloseProtocol (
  56. Controller,
  57. &gEfiIsaHcProtocolGuid,
  58. This->DriverBindingHandle,
  59. Controller
  60. );
  61. }
  62. if (EFI_ERROR (Status)) {
  63. return Status;
  64. }
  65. Status = gBS->OpenProtocol (
  66. Controller,
  67. &gEfiDevicePathProtocolGuid,
  68. &Instance,
  69. This->DriverBindingHandle,
  70. Controller,
  71. EFI_OPEN_PROTOCOL_BY_DRIVER
  72. );
  73. if (!EFI_ERROR (Status)) {
  74. gBS->CloseProtocol (
  75. Controller,
  76. &gEfiDevicePathProtocolGuid,
  77. This->DriverBindingHandle,
  78. Controller
  79. );
  80. }
  81. return Status;
  82. }
  83. ISA_BUS_CHILD_PRIVATE_DATA mIsaBusChildPrivateTemplate = {
  84. ISA_BUS_CHILD_PRIVATE_DATA_SIGNATURE,
  85. FALSE
  86. };
  87. /**
  88. Creates a child handle and installs a protocol.
  89. The CreateChild() function installs a protocol on ChildHandle.
  90. If ChildHandle is a pointer to NULL, then a new handle is created and returned in ChildHandle.
  91. If ChildHandle is not a pointer to NULL, then the protocol installs on the existing ChildHandle.
  92. @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
  93. @param ChildHandle Pointer to the handle of the child to create. If it is NULL,
  94. then a new handle is created. If it is a pointer to an existing UEFI handle,
  95. then the protocol is added to the existing UEFI handle.
  96. @retval EFI_SUCCES The protocol was added to ChildHandle.
  97. @retval EFI_INVALID_PARAMETER ChildHandle is NULL.
  98. @retval EFI_OUT_OF_RESOURCES There are not enough resources available to create
  99. the child
  100. @retval other The child handle was not created
  101. **/
  102. EFI_STATUS
  103. EFIAPI
  104. IsaBusCreateChild (
  105. IN EFI_SERVICE_BINDING_PROTOCOL *This,
  106. IN OUT EFI_HANDLE *ChildHandle
  107. )
  108. {
  109. EFI_STATUS Status;
  110. ISA_BUS_PRIVATE_DATA *Private;
  111. EFI_ISA_HC_PROTOCOL *IsaHc;
  112. ISA_BUS_CHILD_PRIVATE_DATA *Child;
  113. Private = ISA_BUS_PRIVATE_DATA_FROM_THIS (This);
  114. Child = AllocateCopyPool (sizeof (mIsaBusChildPrivateTemplate), &mIsaBusChildPrivateTemplate);
  115. if (Child == NULL) {
  116. return EFI_OUT_OF_RESOURCES;
  117. }
  118. Status = gBS->InstallMultipleProtocolInterfaces (
  119. ChildHandle,
  120. &gEfiIsaHcProtocolGuid, Private->IsaHc,
  121. &gEfiCallerIdGuid, Child,
  122. NULL
  123. );
  124. if (EFI_ERROR (Status)) {
  125. FreePool (Child);
  126. return Status;
  127. }
  128. return gBS->OpenProtocol (
  129. Private->IsaHcHandle,
  130. &gEfiIsaHcProtocolGuid,
  131. (VOID **) &IsaHc,
  132. gIsaBusDriverBinding.DriverBindingHandle,
  133. *ChildHandle,
  134. EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
  135. );
  136. }
  137. /**
  138. Destroys a child handle with a protocol installed on it.
  139. The DestroyChild() function does the opposite of CreateChild(). It removes a protocol
  140. that was installed by CreateChild() from ChildHandle. If the removed protocol is the
  141. last protocol on ChildHandle, then ChildHandle is destroyed.
  142. @param This Pointer to the EFI_SERVICE_BINDING_PROTOCOL instance.
  143. @param ChildHandle Handle of the child to destroy
  144. @retval EFI_SUCCES The protocol was removed from ChildHandle.
  145. @retval EFI_UNSUPPORTED ChildHandle does not support the protocol that is being removed.
  146. @retval EFI_INVALID_PARAMETER Child handle is NULL.
  147. @retval EFI_ACCESS_DENIED The protocol could not be removed from the ChildHandle
  148. because its services are being used.
  149. @retval other The child handle was not destroyed
  150. **/
  151. EFI_STATUS
  152. EFIAPI
  153. IsaBusDestroyChild (
  154. IN EFI_SERVICE_BINDING_PROTOCOL *This,
  155. IN EFI_HANDLE ChildHandle
  156. )
  157. {
  158. EFI_STATUS Status;
  159. ISA_BUS_PRIVATE_DATA *Private;
  160. EFI_ISA_HC_PROTOCOL *IsaHc;
  161. ISA_BUS_CHILD_PRIVATE_DATA *Child;
  162. Private = ISA_BUS_PRIVATE_DATA_FROM_THIS (This);
  163. Status = gBS->OpenProtocol (
  164. ChildHandle,
  165. &gEfiCallerIdGuid,
  166. (VOID **) &Child,
  167. gIsaBusDriverBinding.DriverBindingHandle,
  168. ChildHandle,
  169. EFI_OPEN_PROTOCOL_GET_PROTOCOL
  170. );
  171. if (EFI_ERROR (Status)) {
  172. return Status;
  173. }
  174. ASSERT (Child->Signature == ISA_BUS_CHILD_PRIVATE_DATA_SIGNATURE);
  175. if (Child->InDestroying) {
  176. return EFI_SUCCESS;
  177. }
  178. Child->InDestroying = TRUE;
  179. Status = gBS->CloseProtocol (
  180. Private->IsaHcHandle,
  181. &gEfiIsaHcProtocolGuid,
  182. gIsaBusDriverBinding.DriverBindingHandle,
  183. ChildHandle
  184. );
  185. ASSERT_EFI_ERROR (Status);
  186. if (!EFI_ERROR (Status)) {
  187. Status = gBS->UninstallMultipleProtocolInterfaces (
  188. ChildHandle,
  189. &gEfiIsaHcProtocolGuid, Private->IsaHc,
  190. &gEfiCallerIdGuid, Child,
  191. NULL
  192. );
  193. if (EFI_ERROR (Status)) {
  194. gBS->OpenProtocol (
  195. Private->IsaHcHandle,
  196. &gEfiIsaHcProtocolGuid,
  197. (VOID **) &IsaHc,
  198. gIsaBusDriverBinding.DriverBindingHandle,
  199. ChildHandle,
  200. EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
  201. );
  202. }
  203. }
  204. if (EFI_ERROR (Status)) {
  205. Child->InDestroying = FALSE;
  206. } else {
  207. FreePool (Child);
  208. }
  209. return Status;
  210. }
  211. ISA_BUS_PRIVATE_DATA mIsaBusPrivateTemplate = {
  212. ISA_BUS_PRIVATE_DATA_SIGNATURE,
  213. {
  214. IsaBusCreateChild,
  215. IsaBusDestroyChild
  216. }
  217. };
  218. /**
  219. Starts a device controller or a bus controller.
  220. @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
  221. @param[in] ControllerHandle The handle of the controller to start. This handle
  222. must support a protocol interface that supplies
  223. an I/O abstraction to the driver.
  224. @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
  225. parameter is ignored by device drivers, and is optional for bus
  226. drivers. For a bus driver, if this parameter is NULL, then handles
  227. for all the children of Controller are created by this driver.
  228. If this parameter is not NULL and the first Device Path Node is
  229. not the End of Device Path Node, then only the handle for the
  230. child device specified by the first Device Path Node of
  231. RemainingDevicePath is created by this driver.
  232. If the first Device Path Node of RemainingDevicePath is
  233. the End of Device Path Node, no child handle is created by this
  234. driver.
  235. @retval EFI_SUCCESS The device was started.
  236. @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
  237. @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
  238. @retval Others The driver failded to start the device.
  239. **/
  240. EFI_STATUS
  241. EFIAPI
  242. IsaBusDriverBindingStart (
  243. IN EFI_DRIVER_BINDING_PROTOCOL *This,
  244. IN EFI_HANDLE Controller,
  245. IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
  246. )
  247. {
  248. EFI_STATUS Status;
  249. EFI_DEVICE_PATH_PROTOCOL *DevicePath;
  250. ISA_BUS_PRIVATE_DATA *Private;
  251. Status = gBS->OpenProtocol (
  252. Controller,
  253. &gEfiIsaHcProtocolGuid,
  254. (VOID **) &mIsaBusPrivateTemplate.IsaHc,
  255. This->DriverBindingHandle,
  256. Controller,
  257. EFI_OPEN_PROTOCOL_BY_DRIVER
  258. );
  259. if (EFI_ERROR (Status)) {
  260. return Status;
  261. }
  262. Status = gBS->OpenProtocol (
  263. Controller,
  264. &gEfiDevicePathProtocolGuid,
  265. (VOID **) &DevicePath,
  266. This->DriverBindingHandle,
  267. Controller,
  268. EFI_OPEN_PROTOCOL_BY_DRIVER
  269. );
  270. if (EFI_ERROR (Status)) {
  271. gBS->CloseProtocol (
  272. Controller,
  273. &gEfiIsaHcProtocolGuid,
  274. This->DriverBindingHandle,
  275. Controller
  276. );
  277. return Status;
  278. }
  279. Private = AllocateCopyPool (sizeof (mIsaBusPrivateTemplate), &mIsaBusPrivateTemplate);
  280. ASSERT (Private != NULL);
  281. Private->IsaHcHandle = Controller;
  282. Status = gBS->InstallMultipleProtocolInterfaces (
  283. &Controller,
  284. &gEfiIsaHcServiceBindingProtocolGuid, &Private->ServiceBinding,
  285. NULL
  286. );
  287. ASSERT_EFI_ERROR (Status);
  288. return Status;
  289. }
  290. /**
  291. Stops a device controller or a bus controller.
  292. @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
  293. @param[in] ControllerHandle A handle to the device being stopped. The handle must
  294. support a bus specific I/O protocol for the driver
  295. to use to stop the device.
  296. @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
  297. @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
  298. if NumberOfChildren is 0.
  299. @retval EFI_SUCCESS The device was stopped.
  300. @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
  301. **/
  302. EFI_STATUS
  303. EFIAPI
  304. IsaBusDriverBindingStop (
  305. IN EFI_DRIVER_BINDING_PROTOCOL *This,
  306. IN EFI_HANDLE Controller,
  307. IN UINTN NumberOfChildren,
  308. IN EFI_HANDLE *ChildHandleBuffer
  309. )
  310. {
  311. EFI_STATUS Status;
  312. EFI_SERVICE_BINDING_PROTOCOL *ServiceBinding;
  313. ISA_BUS_PRIVATE_DATA *Private;
  314. UINTN Index;
  315. BOOLEAN AllChildrenStopped;
  316. Status = gBS->OpenProtocol (
  317. Controller,
  318. &gEfiIsaHcServiceBindingProtocolGuid,
  319. (VOID **) &ServiceBinding,
  320. This->DriverBindingHandle,
  321. Controller,
  322. EFI_OPEN_PROTOCOL_GET_PROTOCOL
  323. );
  324. if (EFI_ERROR (Status)) {
  325. return Status;
  326. }
  327. Private = ISA_BUS_PRIVATE_DATA_FROM_THIS (ServiceBinding);
  328. if (NumberOfChildren == 0) {
  329. Status = gBS->UninstallMultipleProtocolInterfaces (
  330. Controller,
  331. &gEfiIsaHcServiceBindingProtocolGuid, &Private->ServiceBinding,
  332. NULL
  333. );
  334. if (!EFI_ERROR (Status)) {
  335. gBS->CloseProtocol (
  336. Controller,
  337. &gEfiDevicePathProtocolGuid,
  338. This->DriverBindingHandle,
  339. Controller
  340. );
  341. gBS->CloseProtocol (
  342. Controller,
  343. &gEfiIsaHcProtocolGuid,
  344. This->DriverBindingHandle,
  345. Controller
  346. );
  347. FreePool (Private);
  348. }
  349. return Status;
  350. }
  351. AllChildrenStopped = TRUE;
  352. for (Index = 0; Index < NumberOfChildren; Index++) {
  353. Status = ServiceBinding->DestroyChild (ServiceBinding, ChildHandleBuffer[Index]);
  354. if (EFI_ERROR (Status)) {
  355. AllChildrenStopped = FALSE;
  356. }
  357. }
  358. return AllChildrenStopped ? EFI_SUCCESS : EFI_DEVICE_ERROR;
  359. }
  360. //
  361. // ISA Bus Driver Binding Protocol Instance
  362. //
  363. EFI_DRIVER_BINDING_PROTOCOL gIsaBusDriverBinding = {
  364. IsaBusDriverBindingSupported,
  365. IsaBusDriverBindingStart,
  366. IsaBusDriverBindingStop,
  367. 0x10,
  368. NULL,
  369. NULL
  370. };
  371. /**
  372. Entry point of the IsaBusDxe driver.
  373. @param[in] ImageHandle The firmware allocated handle for the EFI image.
  374. @param[in] SystemTable A pointer to the EFI System Table.
  375. @retval EFI_SUCCESS The entry point is executed successfully.
  376. @retval other Some error occurs when executing this entry point.
  377. **/
  378. EFI_STATUS
  379. EFIAPI
  380. InitializeIsaBus (
  381. IN EFI_HANDLE ImageHandle,
  382. IN EFI_SYSTEM_TABLE *SystemTable
  383. )
  384. {
  385. EFI_STATUS Status;
  386. Status = EfiLibInstallDriverBindingComponentName2 (
  387. ImageHandle,
  388. SystemTable,
  389. &gIsaBusDriverBinding,
  390. ImageHandle,
  391. &gIsaBusComponentName,
  392. &gIsaBusComponentName2
  393. );
  394. ASSERT_EFI_ERROR (Status);
  395. return Status;
  396. }