DriverConfiguration.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. /**@file
  2. Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
  3. SPDX-License-Identifier: BSD-2-Clause-Patent
  4. Module Name:
  5. DriverConfiguration.c
  6. Abstract:
  7. **/
  8. #include "EmuBlockIo.h"
  9. //
  10. // EFI Driver Configuration Functions
  11. //
  12. EFI_STATUS
  13. EFIAPI
  14. EmuBlockIoDriverConfigurationSetOptions (
  15. IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
  16. IN EFI_HANDLE ControllerHandle,
  17. IN EFI_HANDLE ChildHandle OPTIONAL,
  18. IN CHAR8 *Language,
  19. OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED *ActionRequired
  20. );
  21. EFI_STATUS
  22. EFIAPI
  23. EmuBlockIoDriverConfigurationOptionsValid (
  24. IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
  25. IN EFI_HANDLE ControllerHandle,
  26. IN EFI_HANDLE ChildHandle OPTIONAL
  27. );
  28. EFI_STATUS
  29. EFIAPI
  30. EmuBlockIoDriverConfigurationForceDefaults (
  31. IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
  32. IN EFI_HANDLE ControllerHandle,
  33. IN EFI_HANDLE ChildHandle OPTIONAL,
  34. IN UINT32 DefaultType,
  35. OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED *ActionRequired
  36. );
  37. //
  38. // EFI Driver Configuration Protocol
  39. //
  40. EFI_DRIVER_CONFIGURATION_PROTOCOL gEmuBlockIoDriverConfiguration = {
  41. EmuBlockIoDriverConfigurationSetOptions,
  42. EmuBlockIoDriverConfigurationOptionsValid,
  43. EmuBlockIoDriverConfigurationForceDefaults,
  44. "eng"
  45. };
  46. /*++
  47. Routine Description:
  48. Allows the user to set controller specific options for a controller that a
  49. driver is currently managing.
  50. Arguments:
  51. This - A pointer to the EFI_DRIVER_CONFIGURATION_ PROTOCOL instance.
  52. ControllerHandle - The handle of the controller to set options on.
  53. ChildHandle - The handle of the child controller to set options on. This
  54. is an optional parameter that may be NULL. It will be NULL
  55. for device drivers, and for a bus drivers that wish to set
  56. options for the bus controller. It will not be NULL for a
  57. bus driver that wishes to set options for one of its child
  58. controllers.
  59. Language - A pointer to a three character ISO 639-2 language identifier.
  60. This is the language of the user interface that should be
  61. presented to the user, and it must match one of the languages
  62. specified in SupportedLanguages. The number of languages
  63. supported by a driver is up to the driver writer.
  64. ActionRequired - A pointer to the action that the calling agent is required
  65. to perform when this function returns. See "Related
  66. Definitions" for a list of the actions that the calling
  67. agent is required to perform prior to accessing
  68. ControllerHandle again.
  69. Returns:
  70. EFI_SUCCESS - The driver specified by This successfully set the
  71. configuration options for the controller specified
  72. by ControllerHandle..
  73. EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
  74. EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.
  75. EFI_INVALID_PARAMETER - ActionRequired is NULL.
  76. EFI_UNSUPPORTED - The driver specified by This does not support setting
  77. configuration options for the controller specified by
  78. ControllerHandle and ChildHandle.
  79. EFI_UNSUPPORTED - The driver specified by This does not support the
  80. language specified by Language.
  81. EFI_DEVICE_ERROR - A device error occurred while attempt to set the
  82. configuration options for the controller specified
  83. by ControllerHandle and ChildHandle.
  84. EFI_OUT_RESOURCES - There are not enough resources available to set the
  85. configuration options for the controller specified
  86. by ControllerHandle and ChildHandle.
  87. --*/
  88. EFI_STATUS
  89. EFIAPI
  90. EmuBlockIoDriverConfigurationSetOptions (
  91. IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
  92. IN EFI_HANDLE ControllerHandle,
  93. IN EFI_HANDLE ChildHandle OPTIONAL,
  94. IN CHAR8 *Language,
  95. OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED *ActionRequired
  96. )
  97. {
  98. EFI_STATUS Status;
  99. EFI_BLOCK_IO_PROTOCOL *BlockIo;
  100. CHAR8 *SupportedLanguage;
  101. SupportedLanguage = This->SupportedLanguages;
  102. Status = EFI_UNSUPPORTED;
  103. while (*SupportedLanguage != 0) {
  104. if (AsciiStrnCmp (Language, SupportedLanguage, 3) == 0) {
  105. Status = EFI_SUCCESS;
  106. }
  107. SupportedLanguage += 3;
  108. }
  109. if (EFI_ERROR (Status)) {
  110. return Status;
  111. }
  112. if ((ActionRequired == NULL) || (ControllerHandle == NULL)) {
  113. return EFI_INVALID_PARAMETER;
  114. }
  115. if (ChildHandle != NULL) {
  116. return EFI_UNSUPPORTED;
  117. }
  118. //
  119. // Validate controller handle
  120. //
  121. Status = gBS->OpenProtocol (
  122. ControllerHandle,
  123. &gEmuIoThunkProtocolGuid,
  124. (VOID **)&BlockIo,
  125. gEmuBlockIoDriverBinding.DriverBindingHandle,
  126. ControllerHandle,
  127. EFI_OPEN_PROTOCOL_BY_DRIVER
  128. );
  129. if (!EFI_ERROR (Status)) {
  130. gBS->CloseProtocol (
  131. ControllerHandle,
  132. &gEmuIoThunkProtocolGuid,
  133. gEmuBlockIoDriverBinding.DriverBindingHandle,
  134. ControllerHandle
  135. );
  136. return EFI_UNSUPPORTED;
  137. }
  138. if (Status == EFI_UNSUPPORTED) {
  139. return Status;
  140. } else if (Status != EFI_ALREADY_STARTED) {
  141. return EFI_INVALID_PARAMETER;
  142. }
  143. *ActionRequired = EfiDriverConfigurationActionNone;
  144. return EFI_SUCCESS;
  145. }
  146. /*++
  147. Routine Description:
  148. Tests to see if a controller's current configuration options are valid.
  149. Arguments:
  150. This - A pointer to the EFI_DRIVER_CONFIGURATION_PROTOCOL instance.
  151. ControllerHandle - The handle of the controller to test if it's current
  152. configuration options are valid.
  153. ChildHandle - The handle of the child controller to test if it's current
  154. configuration options are valid. This is an optional
  155. parameter that may be NULL. It will be NULL for device
  156. drivers. It will also be NULL for a bus drivers that wish
  157. to test the configuration options for the bus controller.
  158. It will not be NULL for a bus driver that wishes to test
  159. configuration options for one of its child controllers.
  160. Returns:
  161. EFI_SUCCESS - The controller specified by ControllerHandle and
  162. ChildHandle that is being managed by the driver
  163. specified by This has a valid set of configuration
  164. options.
  165. EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
  166. EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.
  167. EFI_UNSUPPORTED - The driver specified by This is not currently
  168. managing the controller specified by ControllerHandle
  169. and ChildHandle.
  170. EFI_DEVICE_ERROR - The controller specified by ControllerHandle and
  171. ChildHandle that is being managed by the driver
  172. specified by This has an invalid set of configuration
  173. options.
  174. --*/
  175. EFI_STATUS
  176. EFIAPI
  177. EmuBlockIoDriverConfigurationOptionsValid (
  178. IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
  179. IN EFI_HANDLE ControllerHandle,
  180. IN EFI_HANDLE ChildHandle OPTIONAL
  181. )
  182. {
  183. EFI_STATUS Status;
  184. EFI_BLOCK_IO_PROTOCOL *BlockIo;
  185. if (ChildHandle != NULL) {
  186. return EFI_UNSUPPORTED;
  187. }
  188. if (ControllerHandle == NULL) {
  189. return EFI_INVALID_PARAMETER;
  190. }
  191. //
  192. // Validate controller handle
  193. //
  194. Status = gBS->OpenProtocol (
  195. ControllerHandle,
  196. &gEmuIoThunkProtocolGuid,
  197. (VOID **)&BlockIo,
  198. gEmuBlockIoDriverBinding.DriverBindingHandle,
  199. ControllerHandle,
  200. EFI_OPEN_PROTOCOL_BY_DRIVER
  201. );
  202. if (!EFI_ERROR (Status)) {
  203. gBS->CloseProtocol (
  204. ControllerHandle,
  205. &gEmuIoThunkProtocolGuid,
  206. gEmuBlockIoDriverBinding.DriverBindingHandle,
  207. ControllerHandle
  208. );
  209. return EFI_UNSUPPORTED;
  210. }
  211. if (Status == EFI_UNSUPPORTED) {
  212. return Status;
  213. } else if (Status != EFI_ALREADY_STARTED) {
  214. return EFI_INVALID_PARAMETER;
  215. }
  216. return EFI_SUCCESS;
  217. }
  218. /*++
  219. Routine Description:
  220. Forces a driver to set the default configuration options for a controller.
  221. Arguments:
  222. This - A pointer to the EFI_DRIVER_CONFIGURATION_ PROTOCOL instance.
  223. ControllerHandle - The handle of the controller to force default configuration options on.
  224. ChildHandle - The handle of the child controller to force default configuration options on This is an optional parameter that may be NULL. It will be NULL for device drivers. It will also be NULL for a bus drivers that wish to force default configuration options for the bus controller. It will not be NULL for a bus driver that wishes to force default configuration options for one of its child controllers.
  225. DefaultType - The type of default configuration options to force on the controller specified by ControllerHandle and ChildHandle. See Table 9-1 for legal values. A DefaultType of 0x00000000 must be supported by this protocol.
  226. ActionRequired - A pointer to the action that the calling agent is required to perform when this function returns. See "Related Definitions" in Section 9.1for a list of the actions that the calling agent is required to perform prior to accessing ControllerHandle again.
  227. Returns:
  228. EFI_SUCCESS - The driver specified by This successfully forced the default configuration options on the controller specified by ControllerHandle and ChildHandle.
  229. EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
  230. EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.
  231. EFI_INVALID_PARAMETER - ActionRequired is NULL.
  232. EFI_UNSUPPORTED - The driver specified by This does not support forcing the default configuration options on the controller specified by ControllerHandle and ChildHandle.
  233. EFI_UNSUPPORTED - The driver specified by This does not support the configuration type specified by DefaultType.
  234. EFI_DEVICE_ERROR - A device error occurred while attempt to force the default configuration options on the controller specified by ControllerHandle and ChildHandle.
  235. EFI_OUT_RESOURCES - There are not enough resources available to force the default configuration options on the controller specified by ControllerHandle and ChildHandle.
  236. --*/
  237. EFI_STATUS
  238. EFIAPI
  239. EmuBlockIoDriverConfigurationForceDefaults (
  240. IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
  241. IN EFI_HANDLE ControllerHandle,
  242. IN EFI_HANDLE ChildHandle OPTIONAL,
  243. IN UINT32 DefaultType,
  244. OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED *ActionRequired
  245. )
  246. {
  247. EFI_STATUS Status;
  248. EFI_BLOCK_IO_PROTOCOL *BlockIo;
  249. if (ChildHandle != NULL) {
  250. return EFI_UNSUPPORTED;
  251. }
  252. if ((ActionRequired == NULL) || (ControllerHandle == NULL)) {
  253. return EFI_INVALID_PARAMETER;
  254. }
  255. //
  256. // Validate controller handle
  257. //
  258. Status = gBS->OpenProtocol (
  259. ControllerHandle,
  260. &gEmuIoThunkProtocolGuid,
  261. (VOID **)&BlockIo,
  262. gEmuBlockIoDriverBinding.DriverBindingHandle,
  263. ControllerHandle,
  264. EFI_OPEN_PROTOCOL_BY_DRIVER
  265. );
  266. if (!EFI_ERROR (Status)) {
  267. gBS->CloseProtocol (
  268. ControllerHandle,
  269. &gEmuIoThunkProtocolGuid,
  270. gEmuBlockIoDriverBinding.DriverBindingHandle,
  271. ControllerHandle
  272. );
  273. return EFI_UNSUPPORTED;
  274. }
  275. if (Status == EFI_UNSUPPORTED) {
  276. return Status;
  277. } else if (Status != EFI_ALREADY_STARTED) {
  278. return EFI_INVALID_PARAMETER;
  279. }
  280. *ActionRequired = EfiDriverConfigurationActionNone;
  281. return EFI_SUCCESS;
  282. }