IdeController.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. /** @file
  2. Header file for IDE controller driver.
  3. Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #ifndef _IDE_CONTROLLER_H_
  7. #define _IDE_CONTROLLER_H_
  8. #include <Uefi.h>
  9. #include <Protocol/ComponentName.h>
  10. #include <Protocol/DriverBinding.h>
  11. #include <Protocol/PciIo.h>
  12. #include <Protocol/IdeControllerInit.h>
  13. #include <Library/UefiDriverEntryPoint.h>
  14. #include <Library/DebugLib.h>
  15. #include <Library/UefiLib.h>
  16. #include <Library/BaseLib.h>
  17. #include <Library/BaseMemoryLib.h>
  18. #include <Library/MemoryAllocationLib.h>
  19. #include <Library/UefiBootServicesTableLib.h>
  20. #include <IndustryStandard/Pci.h>
  21. //
  22. // Global Variables definitions
  23. //
  24. extern EFI_DRIVER_BINDING_PROTOCOL gIdeControllerDriverBinding;
  25. extern EFI_COMPONENT_NAME_PROTOCOL gIdeControllerComponentName;
  26. extern EFI_COMPONENT_NAME2_PROTOCOL gIdeControllerComponentName2;
  27. ///
  28. /// Supports 2 channel max
  29. ///
  30. #define ICH_IDE_MAX_CHANNEL 0x02
  31. ///
  32. /// Supports 2 devices max
  33. ///
  34. #define ICH_IDE_MAX_DEVICES 0x02
  35. #define ICH_IDE_ENUMER_ALL FALSE
  36. //
  37. // Driver binding functions declaration
  38. //
  39. /**
  40. Register Driver Binding protocol for this driver.
  41. @param This A pointer points to the Binding Protocol instance
  42. @param Controller The handle of controller to be tested.
  43. @param RemainingDevicePath A pointer to the device path. Ignored by device
  44. driver but used by bus driver
  45. @retval EFI_SUCCESS Driver loaded.
  46. @retval !EFI_SUCCESS Driver not loaded.
  47. **/
  48. EFI_STATUS
  49. EFIAPI
  50. IdeControllerSupported (
  51. IN EFI_DRIVER_BINDING_PROTOCOL *This,
  52. IN EFI_HANDLE Controller,
  53. IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
  54. )
  55. ;
  56. /**
  57. This routine is called right after the .Supported() called and return
  58. EFI_SUCCESS. Notes: The supported protocols are checked but the Protocols
  59. are closed.
  60. @param This A pointer points to the Binding Protocol instance
  61. @param Controller The handle of controller to be tested. Parameter
  62. passed by the caller
  63. @param RemainingDevicePath A pointer to the device path. Should be ignored by
  64. device driver
  65. @return EFI_STATUS Status of InstallMultipleProtocolInterfaces()
  66. **/
  67. EFI_STATUS
  68. EFIAPI
  69. IdeControllerStart (
  70. IN EFI_DRIVER_BINDING_PROTOCOL *This,
  71. IN EFI_HANDLE Controller,
  72. IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
  73. )
  74. ;
  75. /**
  76. Stop this driver on Controller Handle.
  77. @param This Protocol instance pointer.
  78. @param Controller Handle of device to stop driver on
  79. @param NumberOfChildren Not used
  80. @param ChildHandleBuffer Not used
  81. @retval EFI_SUCCESS This driver is removed DeviceHandle
  82. @retval !EFI_SUCCESS This driver was not removed from this device
  83. **/
  84. EFI_STATUS
  85. EFIAPI
  86. IdeControllerStop (
  87. IN EFI_DRIVER_BINDING_PROTOCOL *This,
  88. IN EFI_HANDLE Controller,
  89. IN UINTN NumberOfChildren,
  90. IN EFI_HANDLE *ChildHandleBuffer
  91. )
  92. ;
  93. //
  94. // IDE controller init functions declaration
  95. //
  96. /**
  97. Returns the information about the specified IDE channel.
  98. This function can be used to obtain information about a particular IDE channel.
  99. The driver entity uses this information during the enumeration process.
  100. If Enabled is set to FALSE, the driver entity will not scan the channel. Note
  101. that it will not prevent an operating system driver from scanning the channel.
  102. For most of today's controllers, MaxDevices will either be 1 or 2. For SATA
  103. controllers, this value will always be 1. SATA configurations can contain SATA
  104. port multipliers. SATA port multipliers behave like SATA bridges and can support
  105. up to 16 devices on the other side. If a SATA port out of the IDE controller
  106. is connected to a port multiplier, MaxDevices will be set to the number of SATA
  107. devices that the port multiplier supports. Because today's port multipliers
  108. support up to fifteen SATA devices, this number can be as large as fifteen. The IDE
  109. bus driver is required to scan for the presence of port multipliers behind an SATA
  110. controller and enumerate up to MaxDevices number of devices behind the port
  111. multiplier.
  112. In this context, the devices behind a port multiplier constitute a channel.
  113. @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
  114. @param[in] Channel Zero-based channel number.
  115. @param[out] Enabled TRUE if this channel is enabled. Disabled channels
  116. are not scanned to see if any devices are present.
  117. @param[out] MaxDevices The maximum number of IDE devices that the bus driver
  118. can expect on this channel. For the ATA/ATAPI
  119. specification, version 6, this number will either be
  120. one or two. For Serial ATA (SATA) configurations with a
  121. port multiplier, this number can be as large as fifteen.
  122. @retval EFI_SUCCESS Information was returned without any errors.
  123. @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
  124. **/
  125. EFI_STATUS
  126. EFIAPI
  127. IdeInitGetChannelInfo (
  128. IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,
  129. IN UINT8 Channel,
  130. OUT BOOLEAN *Enabled,
  131. OUT UINT8 *MaxDevices
  132. )
  133. ;
  134. /**
  135. The notifications from the driver entity that it is about to enter a certain
  136. phase of the IDE channel enumeration process.
  137. This function can be used to notify the IDE controller driver to perform
  138. specific actions, including any chipset-specific initialization, so that the
  139. chipset is ready to enter the next phase. Seven notification points are defined
  140. at this time.
  141. More synchronization points may be added as required in the future.
  142. @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
  143. @param[in] Phase The phase during enumeration.
  144. @param[in] Channel Zero-based channel number.
  145. @retval EFI_SUCCESS The notification was accepted without any errors.
  146. @retval EFI_UNSUPPORTED Phase is not supported.
  147. @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
  148. @retval EFI_NOT_READY This phase cannot be entered at this time; for
  149. example, an attempt was made to enter a Phase
  150. without having entered one or more previous
  151. Phase.
  152. **/
  153. EFI_STATUS
  154. EFIAPI
  155. IdeInitNotifyPhase (
  156. IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,
  157. IN EFI_IDE_CONTROLLER_ENUM_PHASE Phase,
  158. IN UINT8 Channel
  159. )
  160. ;
  161. /**
  162. Submits the device information to the IDE controller driver.
  163. This function is used by the driver entity to pass detailed information about
  164. a particular device to the IDE controller driver. The driver entity obtains
  165. this information by issuing an ATA or ATAPI IDENTIFY_DEVICE command. IdentifyData
  166. is the pointer to the response data buffer. The IdentifyData buffer is owned
  167. by the driver entity, and the IDE controller driver must make a local copy
  168. of the entire buffer or parts of the buffer as needed. The original IdentifyData
  169. buffer pointer may not be valid when
  170. - EFI_IDE_CONTROLLER_INIT_PROTOCOL.CalculateMode() or
  171. - EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode() is called at a later point.
  172. The IDE controller driver may consult various fields of EFI_IDENTIFY_DATA to
  173. compute the optimum mode for the device. These fields are not limited to the
  174. timing information. For example, an implementation of the IDE controller driver
  175. may examine the vendor and type/mode field to match known bad drives.
  176. The driver entity may submit drive information in any order, as long as it
  177. submits information for all the devices belonging to the enumeration group
  178. before EFI_IDE_CONTROLLER_INIT_PROTOCOL.CalculateMode() is called for any device
  179. in that enumeration group. If a device is absent, EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData()
  180. should be called with IdentifyData set to NULL. The IDE controller driver may
  181. not have any other mechanism to know whether a device is present or not. Therefore,
  182. setting IdentifyData to NULL does not constitute an error condition.
  183. EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData() can be called only once for a
  184. given (Channel, Device) pair.
  185. @param[in] This A pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
  186. @param[in] Channel Zero-based channel number.
  187. @param[in] Device Zero-based device number on the Channel.
  188. @param[in] IdentifyData The device's response to the ATA IDENTIFY_DEVICE command.
  189. @retval EFI_SUCCESS The information was accepted without any errors.
  190. @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
  191. @retval EFI_INVALID_PARAMETER Device is invalid.
  192. **/
  193. EFI_STATUS
  194. EFIAPI
  195. IdeInitSubmitData (
  196. IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,
  197. IN UINT8 Channel,
  198. IN UINT8 Device,
  199. IN EFI_IDENTIFY_DATA *IdentifyData
  200. )
  201. ;
  202. /**
  203. Disqualifies specific modes for an IDE device.
  204. This function allows the driver entity or other drivers (such as platform
  205. drivers) to reject certain timing modes and request the IDE controller driver
  206. to recalculate modes. This function allows the driver entity and the IDE
  207. controller driver to negotiate the timings on a per-device basis. This function
  208. is useful in the case of drives that lie about their capabilities. An example
  209. is when the IDE device fails to accept the timing modes that are calculated
  210. by the IDE controller driver based on the response to the Identify Drive command.
  211. If the driver entity does not want to limit the ATA timing modes and leave that
  212. decision to the IDE controller driver, it can either not call this function for
  213. the given device or call this function and set the Valid flag to FALSE for all
  214. modes that are listed in EFI_ATA_COLLECTIVE_MODE.
  215. The driver entity may disqualify modes for a device in any order and any number
  216. of times.
  217. This function can be called multiple times to invalidate multiple modes of the
  218. same type (e.g., Programmed Input/Output [PIO] modes 3 and 4). See the ATA/ATAPI
  219. specification for more information on PIO modes.
  220. For Serial ATA (SATA) controllers, this member function can be used to disqualify
  221. a higher transfer rate mode on a given channel. For example, a platform driver
  222. may inform the IDE controller driver to not use second-generation (Gen2) speeds
  223. for a certain SATA drive.
  224. @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
  225. @param[in] Channel The zero-based channel number.
  226. @param[in] Device The zero-based device number on the Channel.
  227. @param[in] BadModes The modes that the device does not support and that
  228. should be disqualified.
  229. @retval EFI_SUCCESS The modes were accepted without any errors.
  230. @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
  231. @retval EFI_INVALID_PARAMETER Device is invalid.
  232. @retval EFI_INVALID_PARAMETER IdentifyData is NULL.
  233. **/
  234. EFI_STATUS
  235. EFIAPI
  236. IdeInitDisqualifyMode (
  237. IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,
  238. IN UINT8 Channel,
  239. IN UINT8 Device,
  240. IN EFI_ATA_COLLECTIVE_MODE *BadModes
  241. )
  242. ;
  243. /**
  244. Returns the information about the optimum modes for the specified IDE device.
  245. This function is used by the driver entity to obtain the optimum ATA modes for
  246. a specific device. The IDE controller driver takes into account the following
  247. while calculating the mode:
  248. - The IdentifyData inputs to EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData()
  249. - The BadModes inputs to EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode()
  250. The driver entity is required to call EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData()
  251. for all the devices that belong to an enumeration group before calling
  252. EFI_IDE_CONTROLLER_INIT_PROTOCOL.CalculateMode() for any device in the same group.
  253. The IDE controller driver will use controller- and possibly platform-specific
  254. algorithms to arrive at SupportedModes. The IDE controller may base its
  255. decision on user preferences and other considerations as well. This function
  256. may be called multiple times because the driver entity may renegotiate the mode
  257. with the IDE controller driver using EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode().
  258. The driver entity may collect timing information for various devices in any
  259. order. The driver entity is responsible for making sure that all the dependencies
  260. are satisfied. For example, the SupportedModes information for device A that
  261. was previously returned may become stale after a call to
  262. EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyMode() for device B.
  263. The buffer SupportedModes is allocated by the callee because the caller does
  264. not necessarily know the size of the buffer. The type EFI_ATA_COLLECTIVE_MODE
  265. is defined in a way that allows for future extensibility and can be of variable
  266. length. This memory pool should be deallocated by the caller when it is no
  267. longer necessary.
  268. The IDE controller driver for a Serial ATA (SATA) controller can use this
  269. member function to force a lower speed (first-generation [Gen1] speeds on a
  270. second-generation [Gen2]-capable hardware). The IDE controller driver can
  271. also allow the driver entity to stay with the speed that has been negotiated
  272. by the physical layer.
  273. @param[in] This The pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
  274. @param[in] Channel A zero-based channel number.
  275. @param[in] Device A zero-based device number on the Channel.
  276. @param[out] SupportedModes The optimum modes for the device.
  277. @retval EFI_SUCCESS SupportedModes was returned.
  278. @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
  279. @retval EFI_INVALID_PARAMETER Device is invalid.
  280. @retval EFI_INVALID_PARAMETER SupportedModes is NULL.
  281. @retval EFI_NOT_READY Modes cannot be calculated due to a lack of
  282. data. This error may happen if
  283. EFI_IDE_CONTROLLER_INIT_PROTOCOL.SubmitData()
  284. and EFI_IDE_CONTROLLER_INIT_PROTOCOL.DisqualifyData()
  285. were not called for at least one drive in the
  286. same enumeration group.
  287. **/
  288. EFI_STATUS
  289. EFIAPI
  290. IdeInitCalculateMode (
  291. IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,
  292. IN UINT8 Channel,
  293. IN UINT8 Device,
  294. OUT EFI_ATA_COLLECTIVE_MODE **SupportedModes
  295. )
  296. ;
  297. /**
  298. Commands the IDE controller driver to program the IDE controller hardware
  299. so that the specified device can operate at the specified mode.
  300. This function is used by the driver entity to instruct the IDE controller
  301. driver to program the IDE controller hardware to the specified modes. This
  302. function can be called only once for a particular device. For a Serial ATA
  303. (SATA) Advanced Host Controller Interface (AHCI) controller, no controller-
  304. specific programming may be required.
  305. @param[in] This Pointer to the EFI_IDE_CONTROLLER_INIT_PROTOCOL instance.
  306. @param[in] Channel Zero-based channel number.
  307. @param[in] Device Zero-based device number on the Channel.
  308. @param[in] Modes The modes to set.
  309. @retval EFI_SUCCESS The command was accepted without any errors.
  310. @retval EFI_INVALID_PARAMETER Channel is invalid (Channel >= ChannelCount).
  311. @retval EFI_INVALID_PARAMETER Device is invalid.
  312. @retval EFI_NOT_READY Modes cannot be set at this time due to lack of data.
  313. @retval EFI_DEVICE_ERROR Modes cannot be set due to hardware failure.
  314. The driver entity should not use this device.
  315. **/
  316. EFI_STATUS
  317. EFIAPI
  318. IdeInitSetTiming (
  319. IN EFI_IDE_CONTROLLER_INIT_PROTOCOL *This,
  320. IN UINT8 Channel,
  321. IN UINT8 Device,
  322. IN EFI_ATA_COLLECTIVE_MODE *Modes
  323. )
  324. ;
  325. //
  326. // Forward reference declaration
  327. //
  328. /**
  329. Retrieves a Unicode string that is the user readable name of the EFI Driver.
  330. @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
  331. @param Language A pointer to a three character ISO 639-2 language identifier.
  332. This is the language of the driver name that that the caller
  333. is requesting, and it must match one of the languages specified
  334. in SupportedLanguages. The number of languages supported by a
  335. driver is up to the driver writer.
  336. @param DriverName A pointer to the Unicode string to return. This Unicode string
  337. is the name of the driver specified by This in the language
  338. specified by Language.
  339. @retval EFI_SUCCESS The Unicode string for the Driver specified by This
  340. and the language specified by Language was returned
  341. in DriverName.
  342. @retval EFI_INVALID_PARAMETER Language is NULL.
  343. @retval EFI_INVALID_PARAMETER DriverName is NULL.
  344. @retval EFI_UNSUPPORTED The driver specified by This does not support the
  345. language specified by Language.
  346. **/
  347. EFI_STATUS
  348. EFIAPI
  349. IdeControllerComponentNameGetDriverName (
  350. IN EFI_COMPONENT_NAME_PROTOCOL *This,
  351. IN CHAR8 *Language,
  352. OUT CHAR16 **DriverName
  353. )
  354. ;
  355. /**
  356. Retrieves a Unicode string that is the user readable name of the controller
  357. that is being managed by an EFI Driver.
  358. @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
  359. @param ControllerHandle The handle of a controller that the driver specified by
  360. This is managing. This handle specifies the controller
  361. whose name is to be returned.
  362. @param OPTIONAL ChildHandle The handle of the child controller to retrieve the name
  363. of. This is an optional parameter that may be NULL. It
  364. will be NULL for device drivers. It will also be NULL
  365. for a bus drivers that wish to retrieve the name of the
  366. bus controller. It will not be NULL for a bus driver
  367. that wishes to retrieve the name of a child controller.
  368. @param Language A pointer to a three character ISO 639-2 language
  369. identifier. This is the language of the controller name
  370. that that the caller is requesting, and it must match one
  371. of the languages specified in SupportedLanguages. The
  372. number of languages supported by a driver is up to the
  373. driver writer.
  374. @param ControllerName A pointer to the Unicode string to return. This Unicode
  375. string is the name of the controller specified by
  376. ControllerHandle and ChildHandle in the language
  377. specified by Language from the point of view of the
  378. driver specified by This.
  379. @retval EFI_SUCCESS The Unicode string for the user readable name in the
  380. language specified by Language for the driver
  381. specified by This was returned in DriverName.
  382. @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
  383. @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
  384. EFI_HANDLE.
  385. @retval EFI_INVALID_PARAMETER Language is NULL.
  386. @retval EFI_INVALID_PARAMETER ControllerName is NULL.
  387. @retval EFI_UNSUPPORTED The driver specified by This is not currently
  388. managing the controller specified by
  389. ControllerHandle and ChildHandle.
  390. @retval EFI_UNSUPPORTED The driver specified by This does not support the
  391. language specified by Language.
  392. **/
  393. EFI_STATUS
  394. EFIAPI
  395. IdeControllerComponentNameGetControllerName (
  396. IN EFI_COMPONENT_NAME_PROTOCOL *This,
  397. IN EFI_HANDLE ControllerHandle,
  398. IN EFI_HANDLE ChildHandle OPTIONAL,
  399. IN CHAR8 *Language,
  400. OUT CHAR16 **ControllerName
  401. )
  402. ;
  403. #endif