AtapiPassThru.h 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618
  1. /** @file
  2. Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
  3. SPDX-License-Identifier: BSD-2-Clause-Patent
  4. Module Name: AtapiPassThru.h
  5. **/
  6. #ifndef _APT_H
  7. #define _APT_H
  8. #include <Uefi.h>
  9. #include <Protocol/ScsiPassThru.h>
  10. #include <Protocol/ScsiPassThruExt.h>
  11. #include <Protocol/PciIo.h>
  12. #include <Protocol/DriverSupportedEfiVersion.h>
  13. #include <Library/DebugLib.h>
  14. #include <Library/UefiDriverEntryPoint.h>
  15. #include <Library/BaseLib.h>
  16. #include <Library/UefiLib.h>
  17. #include <Library/BaseMemoryLib.h>
  18. #include <Library/MemoryAllocationLib.h>
  19. #include <Library/UefiBootServicesTableLib.h>
  20. #include <Library/PcdLib.h>
  21. #include <Library/DevicePathLib.h>
  22. #include <IndustryStandard/Pci.h>
  23. #define MAX_TARGET_ID 4
  24. //
  25. // IDE Registers
  26. //
  27. typedef union {
  28. UINT16 Command; /* when write */
  29. UINT16 Status; /* when read */
  30. } IDE_CMD_OR_STATUS;
  31. typedef union {
  32. UINT16 Error; /* when read */
  33. UINT16 Feature; /* when write */
  34. } IDE_ERROR_OR_FEATURE;
  35. typedef union {
  36. UINT16 AltStatus; /* when read */
  37. UINT16 DeviceControl; /* when write */
  38. } IDE_AltStatus_OR_DeviceControl;
  39. typedef enum {
  40. IdePrimary = 0,
  41. IdeSecondary = 1,
  42. IdeMaxChannel = 2
  43. } EFI_IDE_CHANNEL;
  44. ///
  45. //
  46. // Bit definitions in Programming Interface byte of the Class Code field
  47. // in PCI IDE controller's Configuration Space
  48. //
  49. #define IDE_PRIMARY_OPERATING_MODE BIT0
  50. #define IDE_PRIMARY_PROGRAMMABLE_INDICATOR BIT1
  51. #define IDE_SECONDARY_OPERATING_MODE BIT2
  52. #define IDE_SECONDARY_PROGRAMMABLE_INDICATOR BIT3
  53. #define ATAPI_MAX_CHANNEL 2
  54. ///
  55. /// IDE registers set
  56. ///
  57. typedef struct {
  58. UINT16 Data;
  59. IDE_ERROR_OR_FEATURE Reg1;
  60. UINT16 SectorCount;
  61. UINT16 SectorNumber;
  62. UINT16 CylinderLsb;
  63. UINT16 CylinderMsb;
  64. UINT16 Head;
  65. IDE_CMD_OR_STATUS Reg;
  66. IDE_AltStatus_OR_DeviceControl Alt;
  67. UINT16 DriveAddress;
  68. } IDE_BASE_REGISTERS;
  69. #define ATAPI_SCSI_PASS_THRU_DEV_SIGNATURE SIGNATURE_32 ('a', 's', 'p', 't')
  70. typedef struct {
  71. UINTN Signature;
  72. EFI_HANDLE Handle;
  73. EFI_SCSI_PASS_THRU_PROTOCOL ScsiPassThru;
  74. EFI_EXT_SCSI_PASS_THRU_PROTOCOL ExtScsiPassThru;
  75. EFI_PCI_IO_PROTOCOL *PciIo;
  76. UINT64 OriginalPciAttributes;
  77. //
  78. // Local Data goes here
  79. //
  80. IDE_BASE_REGISTERS *IoPort;
  81. IDE_BASE_REGISTERS AtapiIoPortRegisters[2];
  82. UINT32 LatestTargetId;
  83. UINT64 LatestLun;
  84. } ATAPI_SCSI_PASS_THRU_DEV;
  85. //
  86. // IDE registers' base addresses
  87. //
  88. typedef struct {
  89. UINT16 CommandBlockBaseAddr;
  90. UINT16 ControlBlockBaseAddr;
  91. } IDE_REGISTERS_BASE_ADDR;
  92. #define ATAPI_SCSI_PASS_THRU_DEV_FROM_THIS(a) \
  93. CR (a, \
  94. ATAPI_SCSI_PASS_THRU_DEV, \
  95. ScsiPassThru, \
  96. ATAPI_SCSI_PASS_THRU_DEV_SIGNATURE \
  97. )
  98. #define ATAPI_EXT_SCSI_PASS_THRU_DEV_FROM_THIS(a) \
  99. CR (a, \
  100. ATAPI_SCSI_PASS_THRU_DEV, \
  101. ExtScsiPassThru, \
  102. ATAPI_SCSI_PASS_THRU_DEV_SIGNATURE \
  103. )
  104. //
  105. // Global Variables
  106. //
  107. extern EFI_DRIVER_BINDING_PROTOCOL gAtapiScsiPassThruDriverBinding;
  108. extern EFI_COMPONENT_NAME_PROTOCOL gAtapiScsiPassThruComponentName;
  109. extern EFI_COMPONENT_NAME2_PROTOCOL gAtapiScsiPassThruComponentName2;
  110. extern EFI_DRIVER_SUPPORTED_EFI_VERSION_PROTOCOL gAtapiScsiPassThruDriverSupportedEfiVersion;
  111. //
  112. // ATAPI Command op code
  113. //
  114. #define OP_INQUIRY 0x12
  115. #define OP_LOAD_UNLOAD_CD 0xa6
  116. #define OP_MECHANISM_STATUS 0xbd
  117. #define OP_MODE_SELECT_10 0x55
  118. #define OP_MODE_SENSE_10 0x5a
  119. #define OP_PAUSE_RESUME 0x4b
  120. #define OP_PLAY_AUDIO_10 0x45
  121. #define OP_PLAY_AUDIO_MSF 0x47
  122. #define OP_PLAY_CD 0xbc
  123. #define OP_PLAY_CD_MSF 0xb4
  124. #define OP_PREVENT_ALLOW_MEDIUM_REMOVAL 0x1e
  125. #define OP_READ_10 0x28
  126. #define OP_READ_12 0xa8
  127. #define OP_READ_CAPACITY 0x25
  128. #define OP_READ_CD 0xbe
  129. #define OP_READ_CD_MSF 0xb9
  130. #define OP_READ_HEADER 0x44
  131. #define OP_READ_SUB_CHANNEL 0x42
  132. #define OP_READ_TOC 0x43
  133. #define OP_REQUEST_SENSE 0x03
  134. #define OP_SCAN 0xba
  135. #define OP_SEEK_10 0x2b
  136. #define OP_SET_CD_SPEED 0xbb
  137. #define OP_STOPPLAY_SCAN 0x4e
  138. #define OP_START_STOP_UNIT 0x1b
  139. #define OP_TEST_UNIT_READY 0x00
  140. #define OP_FORMAT_UNIT 0x04
  141. #define OP_READ_FORMAT_CAPACITIES 0x23
  142. #define OP_VERIFY 0x2f
  143. #define OP_WRITE_10 0x2a
  144. #define OP_WRITE_12 0xaa
  145. #define OP_WRITE_AND_VERIFY 0x2e
  146. //
  147. // ATA Command
  148. //
  149. #define ATAPI_SOFT_RESET_CMD 0x08
  150. typedef enum {
  151. DataIn = 0,
  152. DataOut = 1,
  153. DataBi = 2,
  154. NoData = 3,
  155. End = 0xff
  156. } DATA_DIRECTION;
  157. typedef struct {
  158. UINT8 OpCode;
  159. DATA_DIRECTION Direction;
  160. } SCSI_COMMAND_SET;
  161. #define MAX_CHANNEL 2
  162. #define ValidCdbLength(Len) ((Len) == 6 || (Len) == 10 || (Len) == 12) ? 1 : 0
  163. //
  164. // IDE registers bit definitions
  165. //
  166. // ATA Err Reg bitmap
  167. //
  168. #define BBK_ERR BIT7 ///< Bad block detected
  169. #define UNC_ERR BIT6 ///< Uncorrectable Data
  170. #define MC_ERR BIT5 ///< Media Change
  171. #define IDNF_ERR BIT4 ///< ID Not Found
  172. #define MCR_ERR BIT3 ///< Media Change Requested
  173. #define ABRT_ERR BIT2 ///< Aborted Command
  174. #define TK0NF_ERR BIT1 ///< Track 0 Not Found
  175. #define AMNF_ERR BIT0 ///< Address Mark Not Found
  176. //
  177. // ATAPI Err Reg bitmap
  178. //
  179. #define SENSE_KEY_ERR (BIT7 | BIT6 | BIT5 | BIT4)
  180. #define EOM_ERR BIT1 ///< End of Media Detected
  181. #define ILI_ERR BIT0 ///< Illegal Length Indication
  182. //
  183. // Device/Head Reg
  184. //
  185. #define LBA_MODE BIT6
  186. #define DEV BIT4
  187. #define HS3 BIT3
  188. #define HS2 BIT2
  189. #define HS1 BIT1
  190. #define HS0 BIT0
  191. #define CHS_MODE (0)
  192. #define DRV0 (0)
  193. #define DRV1 (1)
  194. #define MST_DRV DRV0
  195. #define SLV_DRV DRV1
  196. //
  197. // Status Reg
  198. //
  199. #define BSY BIT7 ///< Controller Busy
  200. #define DRDY BIT6 ///< Drive Ready
  201. #define DWF BIT5 ///< Drive Write Fault
  202. #define DSC BIT4 ///< Disk Seek Complete
  203. #define DRQ BIT3 ///< Data Request
  204. #define CORR BIT2 ///< Corrected Data
  205. #define IDX BIT1 ///< Index
  206. #define ERR BIT0 ///< Error
  207. #define CHECK BIT0 ///< Check bit for ATAPI Status Reg
  208. //
  209. // Device Control Reg
  210. //
  211. #define SRST BIT2 ///< Software Reset
  212. #define IEN_L BIT1 ///< Interrupt Enable
  213. //
  214. // ATAPI Feature Register
  215. //
  216. #define OVERLAP BIT1
  217. #define DMA BIT0
  218. //
  219. // ATAPI Interrupt Reason Reson Reg (ATA Sector Count Register)
  220. //
  221. #define RELEASE BIT2
  222. #define IO BIT1
  223. #define CoD BIT0
  224. #define PACKET_CMD 0xA0
  225. #define DEFAULT_CMD (0xa0)
  226. //
  227. // default content of device control register, disable INT
  228. //
  229. #define DEFAULT_CTL (0x0a)
  230. #define MAX_ATAPI_BYTE_COUNT (0xfffe)
  231. //
  232. // function prototype
  233. //
  234. EFI_STATUS
  235. EFIAPI
  236. AtapiScsiPassThruDriverBindingSupported (
  237. IN EFI_DRIVER_BINDING_PROTOCOL *This,
  238. IN EFI_HANDLE Controller,
  239. IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
  240. );
  241. EFI_STATUS
  242. EFIAPI
  243. AtapiScsiPassThruDriverBindingStart (
  244. IN EFI_DRIVER_BINDING_PROTOCOL *This,
  245. IN EFI_HANDLE Controller,
  246. IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
  247. );
  248. EFI_STATUS
  249. EFIAPI
  250. AtapiScsiPassThruDriverBindingStop (
  251. IN EFI_DRIVER_BINDING_PROTOCOL *This,
  252. IN EFI_HANDLE Controller,
  253. IN UINTN NumberOfChildren,
  254. IN EFI_HANDLE *ChildHandleBuffer
  255. );
  256. //
  257. // EFI Component Name Functions
  258. //
  259. /**
  260. Retrieves a Unicode string that is the user readable name of the driver.
  261. This function retrieves the user readable name of a driver in the form of a
  262. Unicode string. If the driver specified by This has a user readable name in
  263. the language specified by Language, then a pointer to the driver name is
  264. returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
  265. by This does not support the language specified by Language,
  266. then EFI_UNSUPPORTED is returned.
  267. @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
  268. EFI_COMPONENT_NAME_PROTOCOL instance.
  269. @param Language[in] A pointer to a Null-terminated ASCII string
  270. array indicating the language. This is the
  271. language of the driver name that the caller is
  272. requesting, and it must match one of the
  273. languages specified in SupportedLanguages. The
  274. number of languages supported by a driver is up
  275. to the driver writer. Language is specified
  276. in RFC 4646 or ISO 639-2 language code format.
  277. @param DriverName[out] A pointer to the Unicode string to return.
  278. This Unicode string is the name of the
  279. driver specified by This in the language
  280. specified by Language.
  281. @retval EFI_SUCCESS The Unicode string for the Driver specified by
  282. This and the language specified by Language was
  283. returned in DriverName.
  284. @retval EFI_INVALID_PARAMETER Language is NULL.
  285. @retval EFI_INVALID_PARAMETER DriverName is NULL.
  286. @retval EFI_UNSUPPORTED The driver specified by This does not support
  287. the language specified by Language.
  288. **/
  289. EFI_STATUS
  290. EFIAPI
  291. AtapiScsiPassThruComponentNameGetDriverName (
  292. IN EFI_COMPONENT_NAME_PROTOCOL *This,
  293. IN CHAR8 *Language,
  294. OUT CHAR16 **DriverName
  295. );
  296. /**
  297. Retrieves a Unicode string that is the user readable name of the controller
  298. that is being managed by a driver.
  299. This function retrieves the user readable name of the controller specified by
  300. ControllerHandle and ChildHandle in the form of a Unicode string. If the
  301. driver specified by This has a user readable name in the language specified by
  302. Language, then a pointer to the controller name is returned in ControllerName,
  303. and EFI_SUCCESS is returned. If the driver specified by This is not currently
  304. managing the controller specified by ControllerHandle and ChildHandle,
  305. then EFI_UNSUPPORTED is returned. If the driver specified by This does not
  306. support the language specified by Language, then EFI_UNSUPPORTED is returned.
  307. @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
  308. EFI_COMPONENT_NAME_PROTOCOL instance.
  309. @param ControllerHandle[in] The handle of a controller that the driver
  310. specified by This is managing. This handle
  311. specifies the controller whose name is to be
  312. returned.
  313. @param ChildHandle[in] The handle of the child controller to retrieve
  314. the name of. This is an optional parameter that
  315. may be NULL. It will be NULL for device
  316. drivers. It will also be NULL for a bus drivers
  317. that wish to retrieve the name of the bus
  318. controller. It will not be NULL for a bus
  319. driver that wishes to retrieve the name of a
  320. child controller.
  321. @param Language[in] A pointer to a Null-terminated ASCII string
  322. array indicating the language. This is the
  323. language of the driver name that the caller is
  324. requesting, and it must match one of the
  325. languages specified in SupportedLanguages. The
  326. number of languages supported by a driver is up
  327. to the driver writer. Language is specified in
  328. RFC 4646 or ISO 639-2 language code format.
  329. @param ControllerName[out] A pointer to the Unicode string to return.
  330. This Unicode string is the name of the
  331. controller specified by ControllerHandle and
  332. ChildHandle in the language specified by
  333. Language from the point of view of the driver
  334. specified by This.
  335. @retval EFI_SUCCESS The Unicode string for the user readable name in
  336. the language specified by Language for the
  337. driver specified by This was returned in
  338. DriverName.
  339. @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
  340. @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
  341. EFI_HANDLE.
  342. @retval EFI_INVALID_PARAMETER Language is NULL.
  343. @retval EFI_INVALID_PARAMETER ControllerName is NULL.
  344. @retval EFI_UNSUPPORTED The driver specified by This is not currently
  345. managing the controller specified by
  346. ControllerHandle and ChildHandle.
  347. @retval EFI_UNSUPPORTED The driver specified by This does not support
  348. the language specified by Language.
  349. **/
  350. EFI_STATUS
  351. EFIAPI
  352. AtapiScsiPassThruComponentNameGetControllerName (
  353. IN EFI_COMPONENT_NAME_PROTOCOL *This,
  354. IN EFI_HANDLE ControllerHandle,
  355. IN EFI_HANDLE ChildHandle OPTIONAL,
  356. IN CHAR8 *Language,
  357. OUT CHAR16 **ControllerName
  358. );
  359. EFI_STATUS
  360. EFIAPI
  361. AtapiScsiPassThruDriverEntryPoint (
  362. IN EFI_HANDLE ImageHandle,
  363. IN EFI_SYSTEM_TABLE *SystemTable
  364. )
  365. /*++
  366. Routine Description:
  367. Entry point for EFI drivers.
  368. Arguments:
  369. ImageHandle - EFI_HANDLE
  370. SystemTable - EFI_SYSTEM_TABLE
  371. Returns:
  372. EFI_SUCCESS
  373. Others
  374. --*/
  375. ;
  376. EFI_STATUS
  377. RegisterAtapiScsiPassThru (
  378. IN EFI_DRIVER_BINDING_PROTOCOL *This,
  379. IN EFI_HANDLE Controller,
  380. IN EFI_PCI_IO_PROTOCOL *PciIo,
  381. IN UINT64 OriginalPciAttributes
  382. )
  383. /*++
  384. Routine Description:
  385. Attaches SCSI Pass Thru Protocol for specified IDE channel.
  386. Arguments:
  387. This - Protocol instance pointer.
  388. Controller - Parent device handle to the IDE channel.
  389. PciIo - PCI I/O protocol attached on the "Controller".
  390. Returns:
  391. Always return EFI_SUCCESS unless installing SCSI Pass Thru Protocol failed.
  392. --*/
  393. ;
  394. EFI_STATUS
  395. EFIAPI
  396. AtapiScsiPassThruFunction (
  397. IN EFI_SCSI_PASS_THRU_PROTOCOL *This,
  398. IN UINT32 Target,
  399. IN UINT64 Lun,
  400. IN OUT EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet,
  401. IN EFI_EVENT Event OPTIONAL
  402. )
  403. /*++
  404. Routine Description:
  405. Implements EFI_SCSI_PASS_THRU_PROTOCOL.PassThru() function.
  406. Arguments:
  407. This: The EFI_SCSI_PASS_THRU_PROTOCOL instance.
  408. Target: The Target ID of the ATAPI device to send the SCSI
  409. Request Packet. To ATAPI devices attached on an IDE
  410. Channel, Target ID 0 indicates Master device;Target
  411. ID 1 indicates Slave device.
  412. Lun: The LUN of the ATAPI device to send the SCSI Request
  413. Packet. To the ATAPI device, Lun is always 0.
  414. Packet: The SCSI Request Packet to send to the ATAPI device
  415. specified by Target and Lun.
  416. Event: If non-blocking I/O is not supported then Event is ignored,
  417. and blocking I/O is performed.
  418. If Event is NULL, then blocking I/O is performed.
  419. If Event is not NULL and non blocking I/O is supported,
  420. then non-blocking I/O is performed, and Event will be signaled
  421. when the SCSI Request Packet completes.
  422. Returns:
  423. EFI_STATUS
  424. --*/
  425. ;
  426. EFI_STATUS
  427. EFIAPI
  428. AtapiScsiPassThruGetNextDevice (
  429. IN EFI_SCSI_PASS_THRU_PROTOCOL *This,
  430. IN OUT UINT32 *Target,
  431. IN OUT UINT64 *Lun
  432. )
  433. /*++
  434. Routine Description:
  435. Used to retrieve the list of legal Target IDs for SCSI devices
  436. on a SCSI channel.
  437. Arguments:
  438. This - Protocol instance pointer.
  439. Target - On input, a pointer to the Target ID of a SCSI
  440. device present on the SCSI channel. On output,
  441. a pointer to the Target ID of the next SCSI device
  442. present on a SCSI channel. An input value of
  443. 0xFFFFFFFF retrieves the Target ID of the first
  444. SCSI device present on a SCSI channel.
  445. Lun - On input, a pointer to the LUN of a SCSI device
  446. present on the SCSI channel. On output, a pointer
  447. to the LUN of the next SCSI device present on
  448. a SCSI channel.
  449. Returns:
  450. EFI_SUCCESS - The Target ID and Lun of the next SCSI device
  451. on the SCSI channel was returned in Target and Lun.
  452. EFI_NOT_FOUND - There are no more SCSI devices on this SCSI channel.
  453. EFI_INVALID_PARAMETER - Target is not 0xFFFFFFFF,and Target and Lun were not
  454. returned on a previous call to GetNextDevice().
  455. --*/
  456. ;
  457. EFI_STATUS
  458. EFIAPI
  459. AtapiScsiPassThruBuildDevicePath (
  460. IN EFI_SCSI_PASS_THRU_PROTOCOL *This,
  461. IN UINT32 Target,
  462. IN UINT64 Lun,
  463. IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath
  464. )
  465. /*++
  466. Routine Description:
  467. Used to allocate and build a device path node for a SCSI device
  468. on a SCSI channel. Would not build device path for a SCSI Host Controller.
  469. Arguments:
  470. This - Protocol instance pointer.
  471. Target - The Target ID of the SCSI device for which
  472. a device path node is to be allocated and built.
  473. Lun - The LUN of the SCSI device for which a device
  474. path node is to be allocated and built.
  475. DevicePath - A pointer to a single device path node that
  476. describes the SCSI device specified by
  477. Target and Lun. This function is responsible
  478. for allocating the buffer DevicePath with the boot
  479. service AllocatePool(). It is the caller's
  480. responsibility to free DevicePath when the caller
  481. is finished with DevicePath.
  482. Returns:
  483. EFI_SUCCESS - The device path node that describes the SCSI device
  484. specified by Target and Lun was allocated and
  485. returned in DevicePath.
  486. EFI_NOT_FOUND - The SCSI devices specified by Target and Lun does
  487. not exist on the SCSI channel.
  488. EFI_INVALID_PARAMETER - DevicePath is NULL.
  489. EFI_OUT_OF_RESOURCES - There are not enough resources to allocate
  490. DevicePath.
  491. --*/
  492. ;
  493. EFI_STATUS
  494. EFIAPI
  495. AtapiScsiPassThruGetTargetLun (
  496. IN EFI_SCSI_PASS_THRU_PROTOCOL *This,
  497. IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
  498. OUT UINT32 *Target,
  499. OUT UINT64 *Lun
  500. )
  501. /*++
  502. Routine Description:
  503. Used to translate a device path node to a Target ID and LUN.
  504. Arguments:
  505. This - Protocol instance pointer.
  506. DevicePath - A pointer to the device path node that
  507. describes a SCSI device on the SCSI channel.
  508. Target - A pointer to the Target ID of a SCSI device
  509. on the SCSI channel.
  510. Lun - A pointer to the LUN of a SCSI device on
  511. the SCSI channel.
  512. Returns:
  513. EFI_SUCCESS - DevicePath was successfully translated to a
  514. Target ID and LUN, and they were returned
  515. in Target and Lun.
  516. EFI_INVALID_PARAMETER - DevicePath/Target/Lun is NULL.
  517. EFI_UNSUPPORTED - This driver does not support the device path
  518. node type in DevicePath.
  519. EFI_NOT_FOUND - A valid translation from DevicePath to a
  520. Target ID and LUN does not exist.
  521. --*/
  522. ;
  523. EFI_STATUS
  524. EFIAPI
  525. AtapiScsiPassThruResetChannel (
  526. IN EFI_SCSI_PASS_THRU_PROTOCOL *This
  527. )
  528. /*++
  529. Routine Description:
  530. Resets a SCSI channel.This operation resets all the
  531. SCSI devices connected to the SCSI channel.
  532. Arguments:
  533. This - Protocol instance pointer.
  534. Returns:
  535. EFI_SUCCESS - The SCSI channel was reset.
  536. EFI_UNSUPPORTED - The SCSI channel does not support
  537. a channel reset operation.
  538. EFI_DEVICE_ERROR - A device error occurred while
  539. attempting to reset the SCSI channel.
  540. EFI_TIMEOUT - A timeout occurred while attempting
  541. to reset the SCSI channel.
  542. --*/
  543. ;
  544. EFI_STATUS
  545. EFIAPI
  546. AtapiScsiPassThruResetTarget (
  547. IN EFI_SCSI_PASS_THRU_PROTOCOL *This,
  548. IN UINT32 Target,
  549. IN UINT64 Lun
  550. )
  551. /*++
  552. Routine Description:
  553. Resets a SCSI device that is connected to a SCSI channel.
  554. Arguments:
  555. This - Protocol instance pointer.
  556. Target - The Target ID of the SCSI device to reset.
  557. Lun - The LUN of the SCSI device to reset.
  558. Returns:
  559. EFI_SUCCESS - The SCSI device specified by Target and
  560. Lun was reset.
  561. EFI_UNSUPPORTED - The SCSI channel does not support a target
  562. reset operation.
  563. EFI_INVALID_PARAMETER - Target or Lun are invalid.
  564. EFI_DEVICE_ERROR - A device error occurred while attempting
  565. to reset the SCSI device specified by Target
  566. and Lun.
  567. EFI_TIMEOUT - A timeout occurred while attempting to reset
  568. the SCSI device specified by Target and Lun.
  569. --*/
  570. ;
  571. EFI_STATUS
  572. EFIAPI
  573. AtapiExtScsiPassThruFunction (
  574. IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
  575. IN UINT8 *Target,
  576. IN UINT64 Lun,
  577. IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet,
  578. IN EFI_EVENT Event OPTIONAL
  579. )
  580. /*++
  581. Routine Description:
  582. Implements EFI_EXT_SCSI_PASS_THRU_PROTOCOL.PassThru() function.
  583. Arguments:
  584. This: The EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
  585. Target: The Target ID of the ATAPI device to send the SCSI
  586. Request Packet. To ATAPI devices attached on an IDE
  587. Channel, Target ID 0 indicates Master device;Target
  588. ID 1 indicates Slave device.
  589. Lun: The LUN of the ATAPI device to send the SCSI Request
  590. Packet. To the ATAPI device, Lun is always 0.
  591. Packet: The SCSI Request Packet to send to the ATAPI device
  592. specified by Target and Lun.
  593. Event: If non-blocking I/O is not supported then Event is ignored,
  594. and blocking I/O is performed.
  595. If Event is NULL, then blocking I/O is performed.
  596. If Event is not NULL and non blocking I/O is supported,
  597. then non-blocking I/O is performed, and Event will be signaled
  598. when the SCSI Request Packet completes.
  599. Returns:
  600. EFI_STATUS
  601. --*/
  602. ;
  603. EFI_STATUS
  604. EFIAPI
  605. AtapiExtScsiPassThruGetNextTargetLun (
  606. IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
  607. IN OUT UINT8 **Target,
  608. IN OUT UINT64 *Lun
  609. )
  610. /*++
  611. Routine Description:
  612. Used to retrieve the list of legal Target IDs for SCSI devices
  613. on a SCSI channel.
  614. Arguments:
  615. This - Protocol instance pointer.
  616. Target - On input, a pointer to the Target ID of a SCSI
  617. device present on the SCSI channel. On output,
  618. a pointer to the Target ID of the next SCSI device
  619. present on a SCSI channel. An input value of
  620. 0xFFFFFFFF retrieves the Target ID of the first
  621. SCSI device present on a SCSI channel.
  622. Lun - On input, a pointer to the LUN of a SCSI device
  623. present on the SCSI channel. On output, a pointer
  624. to the LUN of the next SCSI device present on
  625. a SCSI channel.
  626. Returns:
  627. EFI_SUCCESS - The Target ID and Lun of the next SCSI device
  628. on the SCSI channel was returned in Target and Lun.
  629. EFI_NOT_FOUND - There are no more SCSI devices on this SCSI channel.
  630. EFI_INVALID_PARAMETER - Target is not 0xFFFFFFFF,and Target and Lun were not
  631. returned on a previous call to GetNextDevice().
  632. --*/
  633. ;
  634. EFI_STATUS
  635. EFIAPI
  636. AtapiExtScsiPassThruBuildDevicePath (
  637. IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
  638. IN UINT8 *Target,
  639. IN UINT64 Lun,
  640. IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath
  641. )
  642. /*++
  643. Routine Description:
  644. Used to allocate and build a device path node for a SCSI device
  645. on a SCSI channel. Would not build device path for a SCSI Host Controller.
  646. Arguments:
  647. This - Protocol instance pointer.
  648. Target - The Target ID of the SCSI device for which
  649. a device path node is to be allocated and built.
  650. Lun - The LUN of the SCSI device for which a device
  651. path node is to be allocated and built.
  652. DevicePath - A pointer to a single device path node that
  653. describes the SCSI device specified by
  654. Target and Lun. This function is responsible
  655. for allocating the buffer DevicePath with the boot
  656. service AllocatePool(). It is the caller's
  657. responsibility to free DevicePath when the caller
  658. is finished with DevicePath.
  659. Returns:
  660. EFI_SUCCESS - The device path node that describes the SCSI device
  661. specified by Target and Lun was allocated and
  662. returned in DevicePath.
  663. EFI_NOT_FOUND - The SCSI devices specified by Target and Lun does
  664. not exist on the SCSI channel.
  665. EFI_INVALID_PARAMETER - DevicePath is NULL.
  666. EFI_OUT_OF_RESOURCES - There are not enough resources to allocate
  667. DevicePath.
  668. --*/
  669. ;
  670. EFI_STATUS
  671. EFIAPI
  672. AtapiExtScsiPassThruGetTargetLun (
  673. IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
  674. IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
  675. OUT UINT8 **Target,
  676. OUT UINT64 *Lun
  677. )
  678. /*++
  679. Routine Description:
  680. Used to translate a device path node to a Target ID and LUN.
  681. Arguments:
  682. This - Protocol instance pointer.
  683. DevicePath - A pointer to the device path node that
  684. describes a SCSI device on the SCSI channel.
  685. Target - A pointer to the Target ID of a SCSI device
  686. on the SCSI channel.
  687. Lun - A pointer to the LUN of a SCSI device on
  688. the SCSI channel.
  689. Returns:
  690. EFI_SUCCESS - DevicePath was successfully translated to a
  691. Target ID and LUN, and they were returned
  692. in Target and Lun.
  693. EFI_INVALID_PARAMETER - DevicePath/Target/Lun is NULL.
  694. EFI_UNSUPPORTED - This driver does not support the device path
  695. node type in DevicePath.
  696. EFI_NOT_FOUND - A valid translation from DevicePath to a
  697. Target ID and LUN does not exist.
  698. --*/
  699. ;
  700. EFI_STATUS
  701. EFIAPI
  702. AtapiExtScsiPassThruResetChannel (
  703. IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This
  704. )
  705. /*++
  706. Routine Description:
  707. Resets a SCSI channel.This operation resets all the
  708. SCSI devices connected to the SCSI channel.
  709. Arguments:
  710. This - Protocol instance pointer.
  711. Returns:
  712. EFI_SUCCESS - The SCSI channel was reset.
  713. EFI_UNSUPPORTED - The SCSI channel does not support
  714. a channel reset operation.
  715. EFI_DEVICE_ERROR - A device error occurred while
  716. attempting to reset the SCSI channel.
  717. EFI_TIMEOUT - A timeout occurred while attempting
  718. to reset the SCSI channel.
  719. --*/
  720. ;
  721. EFI_STATUS
  722. EFIAPI
  723. AtapiExtScsiPassThruResetTarget (
  724. IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
  725. IN UINT8 *Target,
  726. IN UINT64 Lun
  727. )
  728. /*++
  729. Routine Description:
  730. Resets a SCSI device that is connected to a SCSI channel.
  731. Arguments:
  732. This - Protocol instance pointer.
  733. Target - The Target ID of the SCSI device to reset.
  734. Lun - The LUN of the SCSI device to reset.
  735. Returns:
  736. EFI_SUCCESS - The SCSI device specified by Target and
  737. Lun was reset.
  738. EFI_UNSUPPORTED - The SCSI channel does not support a target
  739. reset operation.
  740. EFI_INVALID_PARAMETER - Target or Lun are invalid.
  741. EFI_DEVICE_ERROR - A device error occurred while attempting
  742. to reset the SCSI device specified by Target
  743. and Lun.
  744. EFI_TIMEOUT - A timeout occurred while attempting to reset
  745. the SCSI device specified by Target and Lun.
  746. --*/
  747. ;
  748. EFI_STATUS
  749. EFIAPI
  750. AtapiExtScsiPassThruGetNextTarget (
  751. IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
  752. IN OUT UINT8 **Target
  753. )
  754. /*++
  755. Routine Description:
  756. Used to retrieve the list of legal Target IDs for SCSI devices
  757. on a SCSI channel.
  758. Arguments:
  759. This - Protocol instance pointer.
  760. Target - On input, a pointer to the Target ID of a SCSI
  761. device present on the SCSI channel. On output,
  762. a pointer to the Target ID of the next SCSI device
  763. present on a SCSI channel. An input value of
  764. 0xFFFFFFFF retrieves the Target ID of the first
  765. SCSI device present on a SCSI channel.
  766. Lun - On input, a pointer to the LUN of a SCSI device
  767. present on the SCSI channel. On output, a pointer
  768. to the LUN of the next SCSI device present on
  769. a SCSI channel.
  770. Returns:
  771. EFI_SUCCESS - The Target ID and Lun of the next SCSI device
  772. on the SCSI channel was returned in Target and Lun.
  773. EFI_NOT_FOUND - There are no more SCSI devices on this SCSI channel.
  774. EFI_INVALID_PARAMETER - Target is not 0xFFFFFFFF,and Target and Lun were not
  775. returned on a previous call to GetNextDevice().
  776. --*/
  777. ;
  778. EFI_STATUS
  779. CheckSCSIRequestPacket (
  780. EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet
  781. )
  782. /*++
  783. Routine Description:
  784. Checks the parameters in the SCSI Request Packet to make sure
  785. they are valid for a SCSI Pass Thru request.
  786. Arguments:
  787. Packet - The pointer of EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET
  788. Returns:
  789. EFI_STATUS
  790. --*/
  791. ;
  792. EFI_STATUS
  793. SubmitBlockingIoCommand (
  794. ATAPI_SCSI_PASS_THRU_DEV *AtapiScsiPrivate,
  795. UINT32 Target,
  796. EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet
  797. )
  798. /*++
  799. Routine Description:
  800. Performs blocking I/O request.
  801. Arguments:
  802. AtapiScsiPrivate: Private data structure for the specified channel.
  803. Target: The Target ID of the ATAPI device to send the SCSI
  804. Request Packet. To ATAPI devices attached on an IDE
  805. Channel, Target ID 0 indicates Master device;Target
  806. ID 1 indicates Slave device.
  807. Packet: The SCSI Request Packet to send to the ATAPI device
  808. specified by Target.
  809. Returns: EFI_STATUS
  810. --*/
  811. ;
  812. BOOLEAN
  813. IsCommandValid (
  814. EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet
  815. )
  816. /*++
  817. Routine Description:
  818. Checks the requested SCSI command:
  819. Is it supported by this driver?
  820. Is the Data transfer direction reasonable?
  821. Arguments:
  822. Packet - The pointer of EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET
  823. Returns:
  824. EFI_STATUS
  825. --*/
  826. ;
  827. EFI_STATUS
  828. CheckExtSCSIRequestPacket (
  829. EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet
  830. )
  831. /*++
  832. Routine Description:
  833. Checks the parameters in the SCSI Request Packet to make sure
  834. they are valid for a SCSI Pass Thru request.
  835. Arguments:
  836. Packet - The pointer of EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET
  837. Returns:
  838. EFI_STATUS
  839. --*/
  840. ;
  841. BOOLEAN
  842. IsExtCommandValid (
  843. EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet
  844. )
  845. /*++
  846. Routine Description:
  847. Checks the requested SCSI command:
  848. Is it supported by this driver?
  849. Is the Data transfer direction reasonable?
  850. Arguments:
  851. Packet - The pointer of EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET
  852. Returns:
  853. EFI_STATUS
  854. --*/
  855. ;
  856. EFI_STATUS
  857. SubmitExtBlockingIoCommand (
  858. ATAPI_SCSI_PASS_THRU_DEV *AtapiScsiPrivate,
  859. UINT8 Target,
  860. EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet
  861. )
  862. /*++
  863. Routine Description:
  864. Performs blocking I/O request.
  865. Arguments:
  866. AtapiScsiPrivate: Private data structure for the specified channel.
  867. Target: The Target ID of the ATAPI device to send the SCSI
  868. Request Packet. To ATAPI devices attached on an IDE
  869. Channel, Target ID 0 indicates Master device;Target
  870. ID 1 indicates Slave device.
  871. Packet: The SCSI Request Packet to send to the ATAPI device
  872. specified by Target.
  873. Returns: EFI_STATUS
  874. --*/
  875. ;
  876. EFI_STATUS
  877. RequestSenseCommand (
  878. ATAPI_SCSI_PASS_THRU_DEV *AtapiScsiPrivate,
  879. UINT32 Target,
  880. UINT64 Timeout,
  881. VOID *SenseData,
  882. UINT8 *SenseDataLength
  883. )
  884. /*++
  885. Routine Description:
  886. Submit request sense command
  887. Arguments:
  888. AtapiScsiPrivate - The pointer of ATAPI_SCSI_PASS_THRU_DEV
  889. Target - The target ID
  890. Timeout - The time to complete the command
  891. SenseData - The buffer to fill in sense data
  892. SenseDataLength - The length of buffer
  893. Returns:
  894. EFI_STATUS
  895. --*/
  896. ;
  897. EFI_STATUS
  898. AtapiPacketCommand (
  899. ATAPI_SCSI_PASS_THRU_DEV *AtapiScsiPrivate,
  900. UINT32 Target,
  901. UINT8 *PacketCommand,
  902. VOID *Buffer,
  903. UINT32 *ByteCount,
  904. DATA_DIRECTION Direction,
  905. UINT64 TimeOutInMicroSeconds
  906. )
  907. /*++
  908. Routine Description:
  909. Submits ATAPI command packet to the specified ATAPI device.
  910. Arguments:
  911. AtapiScsiPrivate: Private data structure for the specified channel.
  912. Target: The Target ID of the ATAPI device to send the SCSI
  913. Request Packet. To ATAPI devices attached on an IDE
  914. Channel, Target ID 0 indicates Master device;Target
  915. ID 1 indicates Slave device.
  916. PacketCommand: Points to the ATAPI command packet.
  917. Buffer: Points to the transferred data.
  918. ByteCount: When input,indicates the buffer size; when output,
  919. indicates the actually transferred data size.
  920. Direction: Indicates the data transfer direction.
  921. TimeoutInMicroSeconds:
  922. The timeout, in micro second units, to use for the
  923. execution of this ATAPI command.
  924. A TimeoutInMicroSeconds value of 0 means that
  925. this function will wait indefinitely for the ATAPI
  926. command to execute.
  927. If TimeoutInMicroSeconds is greater than zero, then
  928. this function will return EFI_TIMEOUT if the time
  929. required to execute the ATAPI command is greater
  930. than TimeoutInMicroSeconds.
  931. Returns:
  932. EFI_STATUS
  933. --*/
  934. ;
  935. UINT8
  936. ReadPortB (
  937. IN EFI_PCI_IO_PROTOCOL *PciIo,
  938. IN UINT16 Port
  939. )
  940. /*++
  941. Routine Description:
  942. Read one byte from a specified I/O port.
  943. Arguments:
  944. PciIo - The pointer of EFI_PCI_IO_PROTOCOL
  945. Port - IO port
  946. Returns:
  947. A byte read out
  948. --*/
  949. ;
  950. UINT16
  951. ReadPortW (
  952. IN EFI_PCI_IO_PROTOCOL *PciIo,
  953. IN UINT16 Port
  954. )
  955. /*++
  956. Routine Description:
  957. Read one word from a specified I/O port.
  958. Arguments:
  959. PciIo - The pointer of EFI_PCI_IO_PROTOCOL
  960. Port - IO port
  961. Returns:
  962. A word read out
  963. --*/
  964. ;
  965. VOID
  966. WritePortB (
  967. IN EFI_PCI_IO_PROTOCOL *PciIo,
  968. IN UINT16 Port,
  969. IN UINT8 Data
  970. )
  971. /*++
  972. Routine Description:
  973. Write one byte to a specified I/O port.
  974. Arguments:
  975. PciIo - The pointer of EFI_PCI_IO_PROTOCOL
  976. Port - IO port
  977. Data - The data to write
  978. Returns:
  979. NONE
  980. --*/
  981. ;
  982. VOID
  983. WritePortW (
  984. IN EFI_PCI_IO_PROTOCOL *PciIo,
  985. IN UINT16 Port,
  986. IN UINT16 Data
  987. )
  988. /*++
  989. Routine Description:
  990. Write one word to a specified I/O port.
  991. Arguments:
  992. PciIo - The pointer of EFI_PCI_IO_PROTOCOL
  993. Port - IO port
  994. Data - The data to write
  995. Returns:
  996. NONE
  997. --*/
  998. ;
  999. EFI_STATUS
  1000. StatusDRQClear (
  1001. ATAPI_SCSI_PASS_THRU_DEV *AtapiScsiPrivate,
  1002. UINT64 TimeOutInMicroSeconds
  1003. )
  1004. /*++
  1005. Routine Description:
  1006. Check whether DRQ is clear in the Status Register. (BSY must also be cleared)
  1007. If TimeoutInMicroSeconds is zero, this routine should wait infinitely for
  1008. DRQ clear. Otherwise, it will return EFI_TIMEOUT when specified time is
  1009. elapsed.
  1010. Arguments:
  1011. AtapiScsiPrivate - The pointer of ATAPI_SCSI_PASS_THRU_DEV
  1012. TimeoutInMicroSeconds - The time to wait for
  1013. Returns:
  1014. EFI_STATUS
  1015. --*/
  1016. ;
  1017. EFI_STATUS
  1018. AltStatusDRQClear (
  1019. ATAPI_SCSI_PASS_THRU_DEV *AtapiScsiPrivate,
  1020. UINT64 TimeOutInMicroSeconds
  1021. )
  1022. /*++
  1023. Routine Description:
  1024. Check whether DRQ is clear in the Alternate Status Register.
  1025. (BSY must also be cleared).If TimeoutInMicroSeconds is zero, this routine should
  1026. wait infinitely for DRQ clear. Otherwise, it will return EFI_TIMEOUT when specified time is
  1027. elapsed.
  1028. Arguments:
  1029. AtapiScsiPrivate - The pointer of ATAPI_SCSI_PASS_THRU_DEV
  1030. TimeoutInMicroSeconds - The time to wait for
  1031. Returns:
  1032. EFI_STATUS
  1033. --*/
  1034. ;
  1035. EFI_STATUS
  1036. StatusDRQReady (
  1037. ATAPI_SCSI_PASS_THRU_DEV *AtapiScsiPrivate,
  1038. UINT64 TimeOutInMicroSeconds
  1039. )
  1040. /*++
  1041. Routine Description:
  1042. Check whether DRQ is ready in the Status Register. (BSY must also be cleared)
  1043. If TimeoutInMicroSeconds is zero, this routine should wait infinitely for
  1044. DRQ ready. Otherwise, it will return EFI_TIMEOUT when specified time is
  1045. elapsed.
  1046. Arguments:
  1047. AtapiScsiPrivate - The pointer of ATAPI_SCSI_PASS_THRU_DEV
  1048. TimeoutInMicroSeconds - The time to wait for
  1049. Returns:
  1050. EFI_STATUS
  1051. --*/
  1052. ;
  1053. EFI_STATUS
  1054. AltStatusDRQReady (
  1055. ATAPI_SCSI_PASS_THRU_DEV *AtapiScsiPrivate,
  1056. UINT64 TimeOutInMicroSeconds
  1057. )
  1058. /*++
  1059. Routine Description:
  1060. Check whether DRQ is ready in the Alternate Status Register.
  1061. (BSY must also be cleared)
  1062. If TimeoutInMicroSeconds is zero, this routine should wait infinitely for
  1063. DRQ ready. Otherwise, it will return EFI_TIMEOUT when specified time is
  1064. elapsed.
  1065. Arguments:
  1066. AtapiScsiPrivate - The pointer of ATAPI_SCSI_PASS_THRU_DEV
  1067. TimeoutInMicroSeconds - The time to wait for
  1068. Returns:
  1069. EFI_STATUS
  1070. --*/
  1071. ;
  1072. EFI_STATUS
  1073. StatusWaitForBSYClear (
  1074. ATAPI_SCSI_PASS_THRU_DEV *AtapiScsiPrivate,
  1075. UINT64 TimeoutInMicroSeconds
  1076. )
  1077. /*++
  1078. Routine Description:
  1079. Check whether BSY is clear in the Status Register.
  1080. If TimeoutInMicroSeconds is zero, this routine should wait infinitely for
  1081. BSY clear. Otherwise, it will return EFI_TIMEOUT when specified time is
  1082. elapsed.
  1083. Arguments:
  1084. AtapiScsiPrivate - The pointer of ATAPI_SCSI_PASS_THRU_DEV
  1085. TimeoutInMicroSeconds - The time to wait for
  1086. Returns:
  1087. EFI_STATUS
  1088. --*/
  1089. ;
  1090. EFI_STATUS
  1091. AltStatusWaitForBSYClear (
  1092. ATAPI_SCSI_PASS_THRU_DEV *AtapiScsiPrivate,
  1093. UINT64 TimeoutInMicroSeconds
  1094. )
  1095. /*++
  1096. Routine Description:
  1097. Check whether BSY is clear in the Alternate Status Register.
  1098. If TimeoutInMicroSeconds is zero, this routine should wait infinitely for
  1099. BSY clear. Otherwise, it will return EFI_TIMEOUT when specified time is
  1100. elapsed.
  1101. Arguments:
  1102. AtapiScsiPrivate - The pointer of ATAPI_SCSI_PASS_THRU_DEV
  1103. TimeoutInMicroSeconds - The time to wait for
  1104. Returns:
  1105. EFI_STATUS
  1106. --*/
  1107. ;
  1108. EFI_STATUS
  1109. StatusDRDYReady (
  1110. ATAPI_SCSI_PASS_THRU_DEV *AtapiScsiPrivate,
  1111. UINT64 TimeoutInMicroSeconds
  1112. )
  1113. /*++
  1114. Routine Description:
  1115. Check whether DRDY is ready in the Status Register.
  1116. (BSY must also be cleared)
  1117. If TimeoutInMicroSeconds is zero, this routine should wait infinitely for
  1118. DRDY ready. Otherwise, it will return EFI_TIMEOUT when specified time is
  1119. elapsed.
  1120. Arguments:
  1121. AtapiScsiPrivate - The pointer of ATAPI_SCSI_PASS_THRU_DEV
  1122. TimeoutInMicroSeconds - The time to wait for
  1123. Returns:
  1124. EFI_STATUS
  1125. --*/
  1126. ;
  1127. EFI_STATUS
  1128. AltStatusDRDYReady (
  1129. ATAPI_SCSI_PASS_THRU_DEV *AtapiScsiPrivate,
  1130. UINT64 TimeoutInMicroSeconds
  1131. )
  1132. /*++
  1133. Routine Description:
  1134. Check whether DRDY is ready in the Alternate Status Register.
  1135. (BSY must also be cleared)
  1136. If TimeoutInMicroSeconds is zero, this routine should wait infinitely for
  1137. DRDY ready. Otherwise, it will return EFI_TIMEOUT when specified time is
  1138. elapsed.
  1139. Arguments:
  1140. AtapiScsiPrivate - The pointer of ATAPI_SCSI_PASS_THRU_DEV
  1141. TimeoutInMicroSeconds - The time to wait for
  1142. Returns:
  1143. EFI_STATUS
  1144. --*/
  1145. ;
  1146. EFI_STATUS
  1147. AtapiPassThruPioReadWriteData (
  1148. ATAPI_SCSI_PASS_THRU_DEV *AtapiScsiPrivate,
  1149. UINT16 *Buffer,
  1150. UINT32 *ByteCount,
  1151. DATA_DIRECTION Direction,
  1152. UINT64 TimeOutInMicroSeconds
  1153. )
  1154. /*++
  1155. Routine Description:
  1156. Performs data transfer between ATAPI device and host after the
  1157. ATAPI command packet is sent.
  1158. Arguments:
  1159. AtapiScsiPrivate: Private data structure for the specified channel.
  1160. Buffer: Points to the transferred data.
  1161. ByteCount: When input,indicates the buffer size; when output,
  1162. indicates the actually transferred data size.
  1163. Direction: Indicates the data transfer direction.
  1164. TimeoutInMicroSeconds:
  1165. The timeout, in micro second units, to use for the
  1166. execution of this ATAPI command.
  1167. A TimeoutInMicroSeconds value of 0 means that
  1168. this function will wait indefinitely for the ATAPI
  1169. command to execute.
  1170. If TimeoutInMicroSeconds is greater than zero, then
  1171. this function will return EFI_TIMEOUT if the time
  1172. required to execute the ATAPI command is greater
  1173. than TimeoutInMicroSeconds.
  1174. Returns:
  1175. EFI_STATUS
  1176. --*/
  1177. ;
  1178. EFI_STATUS
  1179. AtapiPassThruCheckErrorStatus (
  1180. ATAPI_SCSI_PASS_THRU_DEV *AtapiScsiPrivate
  1181. )
  1182. /*++
  1183. Routine Description:
  1184. Check Error Register for Error Information.
  1185. Arguments:
  1186. AtapiScsiPrivate - The pointer of ATAPI_SCSI_PASS_THRU_DEV
  1187. Returns:
  1188. EFI_STATUS
  1189. --*/
  1190. ;
  1191. EFI_STATUS
  1192. GetIdeRegistersBaseAddr (
  1193. IN EFI_PCI_IO_PROTOCOL *PciIo,
  1194. OUT IDE_REGISTERS_BASE_ADDR *IdeRegsBaseAddr
  1195. )
  1196. /*++
  1197. Routine Description:
  1198. Get IDE IO port registers' base addresses by mode. In 'Compatibility' mode,
  1199. use fixed addresses. In Native-PCI mode, get base addresses from BARs in
  1200. the PCI IDE controller's Configuration Space.
  1201. Arguments:
  1202. PciIo - Pointer to the EFI_PCI_IO_PROTOCOL instance
  1203. IdeRegsBaseAddr - Pointer to IDE_REGISTERS_BASE_ADDR to
  1204. receive IDE IO port registers' base addresses
  1205. Returns:
  1206. EFI_STATUS
  1207. --*/
  1208. ;
  1209. VOID
  1210. InitAtapiIoPortRegisters (
  1211. IN ATAPI_SCSI_PASS_THRU_DEV *AtapiScsiPrivate,
  1212. IN IDE_REGISTERS_BASE_ADDR *IdeRegsBaseAddr
  1213. )
  1214. /*++
  1215. Routine Description:
  1216. Initialize each Channel's Base Address of CommandBlock and ControlBlock.
  1217. Arguments:
  1218. AtapiScsiPrivate - The pointer of ATAPI_SCSI_PASS_THRU_DEV
  1219. IdeRegsBaseAddr - The pointer of IDE_REGISTERS_BASE_ADDR
  1220. Returns:
  1221. None
  1222. --*/
  1223. ;
  1224. /**
  1225. Installs Scsi Pass Thru and/or Ext Scsi Pass Thru
  1226. protocols based on feature flags.
  1227. @param Controller The controller handle to
  1228. install these protocols on.
  1229. @param AtapiScsiPrivate A pointer to the protocol private
  1230. data structure.
  1231. @retval EFI_SUCCESS The installation succeeds.
  1232. @retval other The installation fails.
  1233. **/
  1234. EFI_STATUS
  1235. InstallScsiPassThruProtocols (
  1236. IN EFI_HANDLE *ControllerHandle,
  1237. IN ATAPI_SCSI_PASS_THRU_DEV *AtapiScsiPrivate
  1238. );
  1239. #endif