]>
Commit | Line | Data |
---|---|---|
ead42efc | 1 | /** @file\r |
2 | Header file for IDE Bus Driver, containing the helper functions'\r | |
630d580d | 3 | prototype.\r |
ead42efc | 4 | \r |
0a6f4824 | 5 | Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r |
c0a00b14 | 6 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
ead42efc | 7 | \r |
8 | @par Revision Reference:\r | |
9 | 2002-6: Add Atapi6 enhancement, support >120GB hard disk, including\r | |
10 | Add - IDEBlkIoReadBlocksExt() func definition\r | |
11 | Add - IDEBlkIoWriteBlocksExt() func definition\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
eeefcb9d | 15 | #ifndef _IDE_H_\r |
16 | #define _IDE_H_\r | |
ead42efc | 17 | \r |
18 | //\r | |
19 | // Helper functions Prototype\r | |
20 | //\r | |
21 | /**\r | |
cd57e888 | 22 | read a one-byte data from a IDE port.\r |
ead42efc | 23 | \r |
630d580d | 24 | @param PciIo The PCI IO protocol instance\r |
0a6f4824 | 25 | @param Port the IDE Port number\r |
ead42efc | 26 | \r |
630d580d | 27 | return the one-byte data read from IDE port\r |
ead42efc | 28 | **/\r |
29 | UINT8\r | |
30 | IDEReadPortB (\r | |
31 | IN EFI_PCI_IO_PROTOCOL *PciIo,\r | |
32 | IN UINT16 Port\r | |
ed66e1bc | 33 | );\r |
ead42efc | 34 | \r |
35 | /**\r | |
630d580d | 36 | Reads multiple words of data from the IDE data port.\r |
37 | Call the IO abstraction once to do the complete read,\r | |
cd57e888 | 38 | not one word at a time.\r |
ead42efc | 39 | \r |
630d580d | 40 | @param PciIo Pointer to the EFI_PCI_IO instance\r |
41 | @param Port IO port to read\r | |
42 | @param Count No. of UINT16's to read\r | |
43 | @param Buffer Pointer to the data buffer for read\r | |
ead42efc | 44 | \r |
45 | **/\r | |
46 | VOID\r | |
47 | IDEReadPortWMultiple (\r | |
48 | IN EFI_PCI_IO_PROTOCOL *PciIo,\r | |
49 | IN UINT16 Port,\r | |
50 | IN UINTN Count,\r | |
51 | OUT VOID *Buffer\r | |
ed66e1bc | 52 | );\r |
ead42efc | 53 | \r |
54 | /**\r | |
cd57e888 | 55 | write a 1-byte data to a specific IDE port.\r |
ead42efc | 56 | \r |
630d580d | 57 | @param PciIo PCI IO protocol instance\r |
58 | @param Port The IDE port to be writen\r | |
59 | @param Data The data to write to the port\r | |
ead42efc | 60 | **/\r |
61 | VOID\r | |
62 | IDEWritePortB (\r | |
63 | IN EFI_PCI_IO_PROTOCOL *PciIo,\r | |
64 | IN UINT16 Port,\r | |
65 | IN UINT8 Data\r | |
ed66e1bc | 66 | );\r |
ead42efc | 67 | \r |
68 | /**\r | |
cd57e888 | 69 | write a 1-word data to a specific IDE port.\r |
ead42efc | 70 | \r |
630d580d | 71 | @param PciIo PCI IO protocol instance\r |
72 | @param Port The IDE port to be writen\r | |
73 | @param Data The data to write to the port\r | |
ead42efc | 74 | **/\r |
75 | VOID\r | |
76 | IDEWritePortW (\r | |
77 | IN EFI_PCI_IO_PROTOCOL *PciIo,\r | |
78 | IN UINT16 Port,\r | |
79 | IN UINT16 Data\r | |
ed66e1bc | 80 | );\r |
ead42efc | 81 | \r |
82 | /**\r | |
630d580d | 83 | Write multiple words of data to the IDE data port.\r |
84 | Call the IO abstraction once to do the complete read,\r | |
cd57e888 | 85 | not one word at a time.\r |
ead42efc | 86 | \r |
630d580d | 87 | @param PciIo Pointer to the EFI_PCI_IO instance\r |
88 | @param Port IO port to read\r | |
89 | @param Count No. of UINT16's to read\r | |
90 | @param Buffer Pointer to the data buffer for read\r | |
ead42efc | 91 | \r |
92 | **/\r | |
93 | VOID\r | |
94 | IDEWritePortWMultiple (\r | |
95 | IN EFI_PCI_IO_PROTOCOL *PciIo,\r | |
96 | IN UINT16 Port,\r | |
97 | IN UINTN Count,\r | |
98 | IN VOID *Buffer\r | |
ed66e1bc | 99 | );\r |
ead42efc | 100 | \r |
101 | /**\r | |
630d580d | 102 | Get IDE IO port registers' base addresses by mode. In 'Compatibility' mode,\r |
103 | use fixed addresses. In Native-PCI mode, get base addresses from BARs in\r | |
104 | the PCI IDE controller's Configuration Space.\r | |
ead42efc | 105 | \r |
630d580d | 106 | The steps to get IDE IO port registers' base addresses for each channel\r |
107 | as follows:\r | |
ead42efc | 108 | \r |
630d580d | 109 | 1. Examine the Programming Interface byte of the Class Code fields in PCI IDE\r |
110 | controller's Configuration Space to determine the operating mode.\r | |
111 | \r | |
112 | 2. a) In 'Compatibility' mode, use fixed addresses shown in the Table 1 below.\r | |
113 | <pre>\r | |
114 | ___________________________________________\r | |
115 | | | Command Block | Control Block |\r | |
116 | | Channel | Registers | Registers |\r | |
117 | |___________|_______________|_______________|\r | |
118 | | Primary | 1F0h - 1F7h | 3F6h - 3F7h |\r | |
119 | |___________|_______________|_______________|\r | |
120 | | Secondary | 170h - 177h | 376h - 377h |\r | |
121 | |___________|_______________|_______________|\r | |
122 | \r | |
123 | Table 1. Compatibility resource mappings\r | |
124 | </pre>\r | |
125 | \r | |
126 | b) In Native-PCI mode, IDE registers are mapped into IO space using the BARs\r | |
127 | in IDE controller's PCI Configuration Space, shown in the Table 2 below.\r | |
128 | <pre>\r | |
129 | ___________________________________________________\r | |
130 | | | Command Block | Control Block |\r | |
131 | | Channel | Registers | Registers |\r | |
132 | |___________|___________________|___________________|\r | |
133 | | Primary | BAR at offset 0x10| BAR at offset 0x14|\r | |
134 | |___________|___________________|___________________|\r | |
135 | | Secondary | BAR at offset 0x18| BAR at offset 0x1C|\r | |
136 | |___________|___________________|___________________|\r | |
137 | \r | |
138 | Table 2. BARs for Register Mapping\r | |
139 | </pre>\r | |
140 | @note Refer to Intel ICH4 datasheet, Control Block Offset: 03F4h for\r | |
141 | primary, 0374h for secondary. So 2 bytes extra offset should be\r | |
142 | added to the base addresses read from BARs.\r | |
143 | \r | |
144 | For more details, please refer to PCI IDE Controller Specification and Intel\r | |
145 | ICH4 Datasheet.\r | |
146 | \r | |
147 | @param PciIo Pointer to the EFI_PCI_IO_PROTOCOL instance\r | |
148 | @param IdeRegsBaseAddr Pointer to IDE_REGISTERS_BASE_ADDR to\r | |
cd57e888 | 149 | receive IDE IO port registers' base addresses\r |
0a6f4824 | 150 | \r |
cd57e888 | 151 | @retval EFI_UNSUPPORTED return this value when the BARs is not IO type\r |
152 | @retval EFI_SUCCESS Get the Base address successfully\r | |
153 | @retval other read the pci configureation data error\r | |
ead42efc | 154 | \r |
155 | **/\r | |
156 | EFI_STATUS\r | |
157 | GetIdeRegistersBaseAddr (\r | |
158 | IN EFI_PCI_IO_PROTOCOL *PciIo,\r | |
159 | OUT IDE_REGISTERS_BASE_ADDR *IdeRegsBaseAddr\r | |
ed66e1bc | 160 | );\r |
ead42efc | 161 | \r |
162 | /**\r | |
630d580d | 163 | This function is used to requery IDE resources. The IDE controller will\r |
164 | probably switch between native and legacy modes during the EFI->CSM->OS\r | |
165 | transfer. We do this everytime before an BlkIo operation to ensure its\r | |
166 | succeess.\r | |
ead42efc | 167 | \r |
630d580d | 168 | @param IdeDev The BLK_IO private data which specifies the IDE device\r |
ead42efc | 169 | \r |
cd57e888 | 170 | @retval EFI_INVALID_PARAMETER return this value when the channel is invalid\r |
171 | @retval EFI_SUCCESS reassign the IDE IO resource successfully\r | |
172 | @retval other get the IDE current base address effor\r | |
173 | \r | |
ead42efc | 174 | **/\r |
175 | EFI_STATUS\r | |
176 | ReassignIdeResources (\r | |
177 | IN IDE_BLK_IO_DEV *IdeDev\r | |
ed66e1bc | 178 | );\r |
ead42efc | 179 | \r |
180 | /**\r | |
cd57e888 | 181 | Detect if there is disk attached to this port.\r |
ead42efc | 182 | \r |
630d580d | 183 | @param IdeDev The BLK_IO private data which specifies the IDE device.\r |
0a6f4824 | 184 | \r |
cd57e888 | 185 | @retval EFI_NOT_FOUND The device or channel is not found\r |
186 | @retval EFI_SUCCESS The device is found\r | |
ead42efc | 187 | \r |
188 | **/\r | |
189 | EFI_STATUS\r | |
190 | DiscoverIdeDevice (\r | |
191 | IN IDE_BLK_IO_DEV *IdeDev\r | |
ed66e1bc | 192 | );\r |
ead42efc | 193 | \r |
194 | /**\r | |
195 | This interface is used to initialize all state data related to the\r | |
196 | detection of one channel.\r | |
197 | \r | |
ead42efc | 198 | **/\r |
563c9c8a | 199 | VOID\r |
ead42efc | 200 | InitializeIDEChannelData (\r |
201 | VOID\r | |
ed66e1bc | 202 | );\r |
ead42efc | 203 | \r |
204 | /**\r | |
630d580d | 205 | This function is used to poll for the DRQ bit clear in the Status\r |
206 | Register. DRQ is cleared when the device is finished transferring data.\r | |
207 | So this function is called after data transfer is finished.\r | |
ead42efc | 208 | \r |
0a6f4824 | 209 | @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used\r |
630d580d | 210 | to record all the information of the IDE device.\r |
211 | @param TimeoutInMilliSeconds used to designate the timeout for the DRQ clear.\r | |
ead42efc | 212 | \r |
630d580d | 213 | @retval EFI_SUCCESS DRQ bit clear within the time out.\r |
ead42efc | 214 | \r |
630d580d | 215 | @retval EFI_TIMEOUT DRQ bit not clear within the time out.\r |
ead42efc | 216 | \r |
630d580d | 217 | @note\r |
218 | Read Status Register will clear interrupt status.\r | |
ead42efc | 219 | \r |
220 | **/\r | |
221 | EFI_STATUS\r | |
222 | DRQClear (\r | |
223 | IN IDE_BLK_IO_DEV *IdeDev,\r | |
224 | IN UINTN TimeoutInMilliSeconds\r | |
ed66e1bc | 225 | );\r |
ead42efc | 226 | \r |
227 | /**\r | |
630d580d | 228 | This function is used to poll for the DRQ bit clear in the Alternate\r |
229 | Status Register. DRQ is cleared when the device is finished\r | |
230 | transferring data. So this function is called after data transfer\r | |
231 | is finished.\r | |
ead42efc | 232 | \r |
0a6f4824 | 233 | @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used\r |
630d580d | 234 | to record all the information of the IDE device.\r |
ead42efc | 235 | \r |
630d580d | 236 | @param TimeoutInMilliSeconds used to designate the timeout for the DRQ clear.\r |
237 | \r | |
238 | @retval EFI_SUCCESS DRQ bit clear within the time out.\r | |
239 | \r | |
240 | @retval EFI_TIMEOUT DRQ bit not clear within the time out.\r | |
241 | @note\r | |
242 | Read Alternate Status Register will not clear interrupt status.\r | |
ead42efc | 243 | \r |
244 | **/\r | |
245 | EFI_STATUS\r | |
246 | DRQClear2 (\r | |
247 | IN IDE_BLK_IO_DEV *IdeDev,\r | |
248 | IN UINTN TimeoutInMilliSeconds\r | |
ed66e1bc | 249 | );\r |
ead42efc | 250 | \r |
251 | /**\r | |
630d580d | 252 | This function is used to poll for the DRQ bit set in the\r |
253 | Status Register.\r | |
254 | DRQ is set when the device is ready to transfer data. So this function\r | |
255 | is called after the command is sent to the device and before required\r | |
256 | data is transferred.\r | |
257 | \r | |
258 | @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure,used to\r | |
259 | record all the information of the IDE device.\r | |
260 | @param TimeoutInMilliSeconds used to designate the timeout for the DRQ ready.\r | |
ead42efc | 261 | \r |
630d580d | 262 | @retval EFI_SUCCESS DRQ bit set within the time out.\r |
263 | @retval EFI_TIMEOUT DRQ bit not set within the time out.\r | |
264 | @retval EFI_ABORTED DRQ bit not set caused by the command abort.\r | |
ead42efc | 265 | \r |
630d580d | 266 | @note Read Status Register will clear interrupt status.\r |
ead42efc | 267 | \r |
268 | **/\r | |
269 | EFI_STATUS\r | |
270 | DRQReady (\r | |
271 | IN IDE_BLK_IO_DEV *IdeDev,\r | |
272 | IN UINTN TimeoutInMilliSeconds\r | |
ed66e1bc | 273 | );\r |
ead42efc | 274 | \r |
275 | /**\r | |
630d580d | 276 | This function is used to poll for the DRQ bit set in the Alternate Status Register.\r |
0a6f4824 | 277 | DRQ is set when the device is ready to transfer data. So this function is called after\r |
630d580d | 278 | the command is sent to the device and before required data is transferred.\r |
ead42efc | 279 | \r |
0a6f4824 | 280 | @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used to\r |
630d580d | 281 | record all the information of the IDE device.\r |
ead42efc | 282 | \r |
630d580d | 283 | @param TimeoutInMilliSeconds used to designate the timeout for the DRQ ready.\r |
284 | \r | |
285 | @retval EFI_SUCCESS DRQ bit set within the time out.\r | |
286 | @retval EFI_TIMEOUT DRQ bit not set within the time out.\r | |
287 | @retval EFI_ABORTED DRQ bit not set caused by the command abort.\r | |
288 | @note Read Alternate Status Register will not clear interrupt status.\r | |
ead42efc | 289 | \r |
290 | **/\r | |
291 | EFI_STATUS\r | |
292 | DRQReady2 (\r | |
293 | IN IDE_BLK_IO_DEV *IdeDev,\r | |
294 | IN UINTN TimeoutInMilliSeconds\r | |
ed66e1bc | 295 | );\r |
ead42efc | 296 | \r |
297 | /**\r | |
630d580d | 298 | This function is used to poll for the BSY bit clear in the Status Register. BSY\r |
299 | is clear when the device is not busy. Every command must be sent after device is not busy.\r | |
ead42efc | 300 | \r |
0a6f4824 | 301 | @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used\r |
630d580d | 302 | to record all the information of the IDE device.\r |
303 | @param TimeoutInMilliSeconds used to designate the timeout for the DRQ ready.\r | |
ead42efc | 304 | \r |
630d580d | 305 | @retval EFI_SUCCESS BSY bit clear within the time out.\r |
306 | @retval EFI_TIMEOUT BSY bit not clear within the time out.\r | |
ead42efc | 307 | \r |
630d580d | 308 | @note Read Status Register will clear interrupt status.\r |
ead42efc | 309 | **/\r |
310 | EFI_STATUS\r | |
311 | WaitForBSYClear (\r | |
312 | IN IDE_BLK_IO_DEV *IdeDev,\r | |
313 | IN UINTN TimeoutInMilliSeconds\r | |
ed66e1bc | 314 | );\r |
ead42efc | 315 | \r |
316 | /**\r | |
0a6f4824 LG |
317 | This function is used to poll for the BSY bit clear in the Alternate Status Register.\r |
318 | BSY is clear when the device is not busy. Every command must be sent after device is\r | |
630d580d | 319 | not busy.\r |
ead42efc | 320 | \r |
0a6f4824 | 321 | @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used to record\r |
630d580d | 322 | all the information of the IDE device.\r |
cd57e888 | 323 | @param TimeoutInMilliSeconds used to designate the timeout for the DRQ ready.\r |
ead42efc | 324 | \r |
630d580d | 325 | @retval EFI_SUCCESS BSY bit clear within the time out.\r |
326 | @retval EFI_TIMEOUT BSY bit not clear within the time out.\r | |
327 | @note Read Alternate Status Register will not clear interrupt status.\r | |
ead42efc | 328 | \r |
329 | **/\r | |
330 | EFI_STATUS\r | |
331 | WaitForBSYClear2 (\r | |
332 | IN IDE_BLK_IO_DEV *IdeDev,\r | |
333 | IN UINTN TimeoutInMilliSeconds\r | |
ed66e1bc | 334 | );\r |
ead42efc | 335 | \r |
336 | /**\r | |
630d580d | 337 | This function is used to poll for the DRDY bit set in the Status Register. DRDY\r |
0a6f4824 | 338 | bit is set when the device is ready to accept command. Most ATA commands must be\r |
630d580d | 339 | sent after DRDY set except the ATAPI Packet Command.\r |
ead42efc | 340 | \r |
630d580d | 341 | @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used\r |
342 | to record all the information of the IDE device.\r | |
343 | @param DelayInMilliSeconds used to designate the timeout for the DRQ ready.\r | |
ead42efc | 344 | \r |
630d580d | 345 | @retval EFI_SUCCESS DRDY bit set within the time out.\r |
346 | @retval EFI_TIMEOUT DRDY bit not set within the time out.\r | |
ead42efc | 347 | \r |
630d580d | 348 | @note Read Status Register will clear interrupt status.\r |
ead42efc | 349 | **/\r |
350 | EFI_STATUS\r | |
351 | DRDYReady (\r | |
352 | IN IDE_BLK_IO_DEV *IdeDev,\r | |
353 | IN UINTN DelayInMilliSeconds\r | |
ed66e1bc | 354 | );\r |
ead42efc | 355 | \r |
356 | /**\r | |
0a6f4824 LG |
357 | This function is used to poll for the DRDY bit set in the Alternate Status Register.\r |
358 | DRDY bit is set when the device is ready to accept command. Most ATA commands must\r | |
630d580d | 359 | be sent after DRDY set except the ATAPI Packet Command.\r |
360 | \r | |
361 | @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used\r | |
362 | to record all the information of the IDE device.\r | |
363 | @param DelayInMilliSeconds used to designate the timeout for the DRQ ready.\r | |
ead42efc | 364 | \r |
630d580d | 365 | @retval EFI_SUCCESS DRDY bit set within the time out.\r |
366 | @retval EFI_TIMEOUT DRDY bit not set within the time out.\r | |
ead42efc | 367 | \r |
630d580d | 368 | @note Read Alternate Status Register will clear interrupt status.\r |
ead42efc | 369 | \r |
370 | **/\r | |
371 | EFI_STATUS\r | |
372 | DRDYReady2 (\r | |
373 | IN IDE_BLK_IO_DEV *IdeDev,\r | |
374 | IN UINTN DelayInMilliSeconds\r | |
ed66e1bc | 375 | );\r |
ead42efc | 376 | \r |
ead42efc | 377 | //\r |
378 | // ATA device functions' prototype\r | |
379 | //\r | |
380 | /**\r | |
630d580d | 381 | Sends out an ATA Identify Command to the specified device.\r |
382 | \r | |
383 | This function is called by DiscoverIdeDevice() during its device\r | |
384 | identification. It sends out the ATA Identify Command to the\r | |
385 | specified device. Only ATA device responses to this command. If\r | |
386 | the command succeeds, it returns the Identify data structure which\r | |
387 | contains information about the device. This function extracts the\r | |
388 | information it needs to fill the IDE_BLK_IO_DEV data structure,\r | |
389 | including device type, media block size, media capacity, and etc.\r | |
ead42efc | 390 | \r |
0a6f4824 | 391 | @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure,used to record\r |
630d580d | 392 | all the information of the IDE device.\r |
ead42efc | 393 | \r |
630d580d | 394 | @retval EFI_SUCCESS Identify ATA device successfully.\r |
395 | @retval EFI_DEVICE_ERROR ATA Identify Device Command failed or device is not ATA device.\r | |
396 | @note parameter IdeDev will be updated in this function.\r | |
ead42efc | 397 | \r |
398 | **/\r | |
399 | EFI_STATUS\r | |
400 | ATAIdentify (\r | |
401 | IN IDE_BLK_IO_DEV *IdeDev\r | |
ed66e1bc | 402 | );\r |
ead42efc | 403 | \r |
404 | /**\r | |
630d580d | 405 | This function is called by ATAIdentify() or ATAPIIdentify() to print device's module name.\r |
ead42efc | 406 | \r |
630d580d | 407 | @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used to record\r |
408 | all the information of the IDE device.\r | |
ead42efc | 409 | **/\r |
410 | VOID\r | |
411 | PrintAtaModuleName (\r | |
412 | IN IDE_BLK_IO_DEV *IdeDev\r | |
ed66e1bc | 413 | );\r |
ead42efc | 414 | /**\r |
630d580d | 415 | This function is used to send out ATA commands conforms to the PIO Data In Protocol.\r |
ead42efc | 416 | \r |
0a6f4824 | 417 | @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used to record\r |
630d580d | 418 | all the information of the IDE device.\r |
419 | @param Buffer buffer contained data transferred from device to host.\r | |
420 | @param ByteCount data size in byte unit of the buffer.\r | |
421 | @param AtaCommand value of the Command Register\r | |
422 | @param Head value of the Head/Device Register\r | |
423 | @param SectorCount value of the Sector Count Register\r | |
424 | @param SectorNumber value of the Sector Number Register\r | |
425 | @param CylinderLsb value of the low byte of the Cylinder Register\r | |
426 | @param CylinderMsb value of the high byte of the Cylinder Register\r | |
0a6f4824 | 427 | \r |
630d580d | 428 | @retval EFI_SUCCESS send out the ATA command and device send required data successfully.\r |
429 | @retval EFI_DEVICE_ERROR command sent failed.\r | |
ead42efc | 430 | \r |
431 | **/\r | |
432 | EFI_STATUS\r | |
433 | AtaPioDataIn (\r | |
434 | IN IDE_BLK_IO_DEV *IdeDev,\r | |
435 | IN VOID *Buffer,\r | |
436 | IN UINT32 ByteCount,\r | |
437 | IN UINT8 AtaCommand,\r | |
438 | IN UINT8 Head,\r | |
439 | IN UINT8 SectorCount,\r | |
440 | IN UINT8 SectorNumber,\r | |
441 | IN UINT8 CylinderLsb,\r | |
442 | IN UINT8 CylinderMsb\r | |
ed66e1bc | 443 | );\r |
ead42efc | 444 | \r |
445 | /**\r | |
630d580d | 446 | This function is used to send out ATA commands conforms to the\r |
447 | PIO Data Out Protocol.\r | |
ead42efc | 448 | \r |
630d580d | 449 | @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used\r |
450 | to record all the information of the IDE device.\r | |
451 | @param *Buffer buffer contained data transferred from host to device.\r | |
452 | @param ByteCount data size in byte unit of the buffer.\r | |
453 | @param AtaCommand value of the Command Register\r | |
454 | @param Head value of the Head/Device Register\r | |
455 | @param SectorCount value of the Sector Count Register\r | |
456 | @param SectorNumber value of the Sector Number Register\r | |
457 | @param CylinderLsb value of the low byte of the Cylinder Register\r | |
458 | @param CylinderMsb value of the high byte of the Cylinder Register\r | |
ead42efc | 459 | \r |
630d580d | 460 | @retval EFI_SUCCESS send out the ATA command and device received required\r |
461 | data successfully.\r | |
462 | @retval EFI_DEVICE_ERROR command sent failed.\r | |
ead42efc | 463 | \r |
464 | **/\r | |
465 | EFI_STATUS\r | |
466 | AtaPioDataOut (\r | |
467 | IN IDE_BLK_IO_DEV *IdeDev,\r | |
468 | IN VOID *Buffer,\r | |
469 | IN UINT32 ByteCount,\r | |
470 | IN UINT8 AtaCommand,\r | |
471 | IN UINT8 Head,\r | |
472 | IN UINT8 SectorCount,\r | |
473 | IN UINT8 SectorNumber,\r | |
474 | IN UINT8 CylinderLsb,\r | |
475 | IN UINT8 CylinderMsb\r | |
ed66e1bc | 476 | );\r |
ead42efc | 477 | \r |
478 | /**\r | |
630d580d | 479 | This function is used to analyze the Status Register and print out\r |
480 | some debug information and if there is ERR bit set in the Status\r | |
481 | Register, the Error Register's value is also be parsed and print out.\r | |
ead42efc | 482 | \r |
0a6f4824 | 483 | @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used to\r |
630d580d | 484 | record all the information of the IDE device.\r |
ead42efc | 485 | \r |
630d580d | 486 | @retval EFI_SUCCESS No err information in the Status Register.\r |
487 | @retval EFI_DEVICE_ERROR Any err information in the Status Register.\r | |
ead42efc | 488 | \r |
489 | **/\r | |
490 | EFI_STATUS\r | |
491 | CheckErrorStatus (\r | |
492 | IN IDE_BLK_IO_DEV *IdeDev\r | |
ed66e1bc | 493 | );\r |
ead42efc | 494 | \r |
495 | /**\r | |
630d580d | 496 | This function is used to implement the Soft Reset on the specified device. But,\r |
0a6f4824 | 497 | the ATA Soft Reset mechanism is so strong a reset method that it will force\r |
630d580d | 498 | resetting on both devices connected to the same cable.\r |
ead42efc | 499 | \r |
630d580d | 500 | It is called by IdeBlkIoReset(), a interface function of Block\r |
501 | I/O protocol.\r | |
ead42efc | 502 | \r |
630d580d | 503 | This function can also be used by the ATAPI device to perform reset when\r |
504 | ATAPI Reset command is failed.\r | |
ead42efc | 505 | \r |
630d580d | 506 | @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used to record\r |
507 | all the information of the IDE device.\r | |
508 | @retval EFI_SUCCESS Soft reset completes successfully.\r | |
509 | @retval EFI_DEVICE_ERROR Any step during the reset process is failed.\r | |
ead42efc | 510 | \r |
630d580d | 511 | @note The registers initial values after ATA soft reset are different\r |
512 | to the ATA device and ATAPI device.\r | |
ead42efc | 513 | **/\r |
514 | EFI_STATUS\r | |
515 | AtaSoftReset (\r | |
516 | IN IDE_BLK_IO_DEV *IdeDev\r | |
ed66e1bc | 517 | );\r |
ead42efc | 518 | \r |
519 | /**\r | |
630d580d | 520 | This function is the ATA implementation for ReadBlocks in the\r |
521 | Block I/O Protocol interface.\r | |
522 | \r | |
523 | @param IdeBlkIoDevice Indicates the calling context.\r | |
524 | @param MediaId The media id that the read request is for.\r | |
cd57e888 | 525 | @param Lba The starting logical block address to read from on the device.\r |
630d580d | 526 | @param BufferSize The size of the Buffer in bytes. This must be a multiple\r |
527 | of the intrinsic block size of the device.\r | |
ead42efc | 528 | \r |
630d580d | 529 | @param Buffer A pointer to the destination buffer for the data. The caller\r |
530 | is responsible for either having implicit or explicit ownership\r | |
531 | of the memory that data is read into.\r | |
ead42efc | 532 | \r |
630d580d | 533 | @retval EFI_SUCCESS Read Blocks successfully.\r |
534 | @retval EFI_DEVICE_ERROR Read Blocks failed.\r | |
535 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
536 | @retval EFI_MEDIA_CHANGE The MediaId is not for the current media.\r | |
537 | @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of the\r | |
538 | intrinsic block size of the device.\r | |
539 | @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,\r | |
540 | or the data buffer is not valid.\r | |
541 | \r | |
542 | @note If Read Block error because of device error, this function will call\r | |
543 | AtaSoftReset() function to reset device.\r | |
ead42efc | 544 | \r |
545 | **/\r | |
546 | EFI_STATUS\r | |
547 | AtaBlkIoReadBlocks (\r | |
548 | IN IDE_BLK_IO_DEV *IdeBlkIoDevice,\r | |
549 | IN UINT32 MediaId,\r | |
e72ca438 | 550 | IN EFI_LBA Lba,\r |
ead42efc | 551 | IN UINTN BufferSize,\r |
552 | OUT VOID *Buffer\r | |
ed66e1bc | 553 | );\r |
ead42efc | 554 | \r |
555 | /**\r | |
630d580d | 556 | This function is the ATA implementation for WriteBlocks in the\r |
557 | Block I/O Protocol interface.\r | |
558 | \r | |
559 | @param IdeBlkIoDevice Indicates the calling context.\r | |
560 | @param MediaId The media id that the write request is for.\r | |
cd57e888 | 561 | @param Lba The starting logical block address to write onto the device.\r |
630d580d | 562 | @param BufferSize The size of the Buffer in bytes. This must be a multiple\r |
563 | of the intrinsic block size of the device.\r | |
564 | @param Buffer A pointer to the source buffer for the data.The caller\r | |
0a6f4824 | 565 | is responsible for either having implicit or explicit\r |
630d580d | 566 | ownership of the memory that data is written from.\r |
ead42efc | 567 | \r |
630d580d | 568 | @retval EFI_SUCCESS Write Blocks successfully.\r |
569 | @retval EFI_DEVICE_ERROR Write Blocks failed.\r | |
570 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
571 | @retval EFI_MEDIA_CHANGE The MediaId is not for the current media.\r | |
ead42efc | 572 | \r |
630d580d | 573 | @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of the\r |
574 | intrinsic block size of the device.\r | |
575 | @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,\r | |
576 | or the data buffer is not valid.\r | |
ead42efc | 577 | \r |
630d580d | 578 | @note If Write Block error because of device error, this function will call\r |
579 | AtaSoftReset() function to reset device.\r | |
ead42efc | 580 | **/\r |
581 | EFI_STATUS\r | |
582 | AtaBlkIoWriteBlocks (\r | |
583 | IN IDE_BLK_IO_DEV *IdeBlkIoDevice,\r | |
584 | IN UINT32 MediaId,\r | |
e72ca438 | 585 | IN EFI_LBA Lba,\r |
ead42efc | 586 | IN UINTN BufferSize,\r |
587 | OUT VOID *Buffer\r | |
ed66e1bc | 588 | );\r |
ead42efc | 589 | \r |
ead42efc | 590 | /**\r |
630d580d | 591 | This function is called by DiscoverIdeDevice() during its device\r |
592 | identification.\r | |
593 | Its main purpose is to get enough information for the device media\r | |
594 | to fill in the Media data structure of the Block I/O Protocol interface.\r | |
595 | \r | |
596 | There are 5 steps to reach such objective:\r | |
0a6f4824 | 597 | 1. Sends out the ATAPI Identify Command to the specified device.\r |
630d580d | 598 | Only ATAPI device responses to this command. If the command succeeds,\r |
0a6f4824 LG |
599 | it returns the Identify data structure which filled with information\r |
600 | about the device. Since the ATAPI device contains removable media,\r | |
630d580d | 601 | the only meaningful information is the device module name.\r |
602 | 2. Sends out ATAPI Inquiry Packet Command to the specified device.\r | |
603 | This command will return inquiry data of the device, which contains\r | |
604 | the device type information.\r | |
605 | 3. Allocate sense data space for future use. We don't detect the media\r | |
0a6f4824 | 606 | presence here to improvement boot performance, especially when CD\r |
630d580d | 607 | media is present. The media detection will be performed just before\r |
608 | each BLK_IO read/write\r | |
0a6f4824 | 609 | \r |
630d580d | 610 | @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used\r |
611 | to record all the information of the IDE device.\r | |
ead42efc | 612 | \r |
630d580d | 613 | @retval EFI_SUCCESS Identify ATAPI device successfully.\r |
614 | @retval EFI_DEVICE_ERROR ATAPI Identify Device Command failed or device type\r | |
615 | is not supported by this IDE driver.\r | |
0a6f4824 | 616 | @retval EFI_OUT_OF_RESOURCES Allocate memory for sense data failed\r |
ead42efc | 617 | \r |
630d580d | 618 | @note Parameter "IdeDev" will be updated in this function.\r |
ead42efc | 619 | **/\r |
620 | EFI_STATUS\r | |
621 | ATAPIIdentify (\r | |
622 | IN IDE_BLK_IO_DEV *IdeDev\r | |
ed66e1bc | 623 | );\r |
ead42efc | 624 | \r |
625 | /**\r | |
630d580d | 626 | This function is used to implement the Soft Reset on the specified\r |
627 | ATAPI device. Different from the AtaSoftReset(), here reset is a ATA\r | |
628 | Soft Reset Command special for ATAPI device, and it only take effects\r | |
629 | on the specified ATAPI device, not on the whole IDE bus.\r | |
630 | Since the ATAPI soft reset is needed when device is in exceptional\r | |
631 | condition (such as BSY bit is always set ), I think the Soft Reset\r | |
632 | command should be sent without waiting for the BSY clear and DRDY\r | |
633 | set.\r | |
0a6f4824 | 634 | This function is called by IdeBlkIoReset(),\r |
630d580d | 635 | a interface function of Block I/O protocol.\r |
ead42efc | 636 | \r |
630d580d | 637 | @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used\r |
638 | to record all the information of the IDE device.\r | |
ead42efc | 639 | \r |
630d580d | 640 | @retval EFI_SUCCESS Soft reset completes successfully.\r |
641 | @retval EFI_DEVICE_ERROR Any step during the reset process is failed.\r | |
ead42efc | 642 | \r |
643 | **/\r | |
644 | EFI_STATUS\r | |
645 | AtapiSoftReset (\r | |
646 | IN IDE_BLK_IO_DEV *IdeDev\r | |
ed66e1bc | 647 | );\r |
ead42efc | 648 | \r |
649 | /**\r | |
630d580d | 650 | This function is the ATAPI implementation for ReadBlocks in the\r |
651 | Block I/O Protocol interface.\r | |
ead42efc | 652 | \r |
630d580d | 653 | @param IdeBlkIoDevice Indicates the calling context.\r |
654 | @param MediaId The media id that the read request is for.\r | |
cd57e888 | 655 | @param Lba The starting logical block address to read from on the device.\r |
630d580d | 656 | @param BufferSize The size of the Buffer in bytes. This must be a multiple\r |
657 | of the intrinsic block size of the device.\r | |
658 | @param Buffer A pointer to the destination buffer for the data. The caller\r | |
0a6f4824 | 659 | is responsible for either having implicit or explicit\r |
630d580d | 660 | ownership of the memory that data is read into.\r |
0a6f4824 | 661 | \r |
630d580d | 662 | @retval EFI_SUCCESS Read Blocks successfully.\r |
663 | @retval EFI_DEVICE_ERROR Read Blocks failed.\r | |
664 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
665 | @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.\r | |
666 | @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of the\r | |
667 | intrinsic block size of the device.\r | |
668 | @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,\r | |
669 | or the data buffer is not valid.\r | |
ead42efc | 670 | **/\r |
671 | EFI_STATUS\r | |
672 | AtapiBlkIoReadBlocks (\r | |
673 | IN IDE_BLK_IO_DEV *IdeBlkIoDevice,\r | |
674 | IN UINT32 MediaId,\r | |
e72ca438 | 675 | IN EFI_LBA Lba,\r |
ead42efc | 676 | IN UINTN BufferSize,\r |
677 | OUT VOID *Buffer\r | |
ed66e1bc | 678 | );\r |
ead42efc | 679 | \r |
680 | /**\r | |
630d580d | 681 | This function is the ATAPI implementation for WriteBlocks in the\r |
682 | Block I/O Protocol interface.\r | |
ead42efc | 683 | \r |
630d580d | 684 | @param IdeBlkIoDevice Indicates the calling context.\r |
685 | @param MediaId The media id that the write request is for.\r | |
cd57e888 | 686 | @param Lba The starting logical block address to write onto the device.\r |
630d580d | 687 | @param BufferSize The size of the Buffer in bytes. This must be a multiple\r |
688 | of the intrinsic block size of the device.\r | |
689 | @param Buffer A pointer to the source buffer for the data. The caller\r | |
690 | is responsible for either having implicit or explicit ownership\r | |
691 | of the memory that data is written from.\r | |
ead42efc | 692 | \r |
630d580d | 693 | @retval EFI_SUCCESS Write Blocks successfully.\r |
694 | @retval EFI_DEVICE_ERROR Write Blocks failed.\r | |
695 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
696 | @retval EFI_MEDIA_CHANGE The MediaId is not for the current media.\r | |
697 | @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of the\r | |
0a6f4824 LG |
698 | intrinsic block size of the device.\r |
699 | @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,\r | |
630d580d | 700 | or the data buffer is not valid.\r |
ead42efc | 701 | \r |
630d580d | 702 | @retval EFI_WRITE_PROTECTED The write protected is enabled or the media does not support write\r |
ead42efc | 703 | **/\r |
704 | EFI_STATUS\r | |
705 | AtapiBlkIoWriteBlocks (\r | |
706 | IN IDE_BLK_IO_DEV *IdeBlkIoDevice,\r | |
707 | IN UINT32 MediaId,\r | |
e72ca438 | 708 | IN EFI_LBA Lba,\r |
ead42efc | 709 | IN UINTN BufferSize,\r |
710 | OUT VOID *Buffer\r | |
ed66e1bc | 711 | );\r |
ead42efc | 712 | \r |
713 | /**\r | |
630d580d | 714 | Release resources of an IDE device before stopping it.\r |
ead42efc | 715 | \r |
630d580d | 716 | @param IdeBlkIoDevice Standard IDE device private data structure\r |
ead42efc | 717 | \r |
718 | **/\r | |
719 | VOID\r | |
720 | ReleaseIdeResources (\r | |
721 | IN IDE_BLK_IO_DEV *IdeBlkIoDevice\r | |
ed66e1bc | 722 | );\r |
ead42efc | 723 | \r |
724 | /**\r | |
630d580d | 725 | Set the calculated Best transfer mode to a detected device\r |
ead42efc | 726 | \r |
630d580d | 727 | @param IdeDev Standard IDE device private data structure\r |
728 | @param TransferMode The device transfer mode to be set\r | |
729 | @return Set transfer mode Command execute status.\r | |
ead42efc | 730 | **/\r |
731 | EFI_STATUS\r | |
732 | SetDeviceTransferMode (\r | |
733 | IN IDE_BLK_IO_DEV *IdeDev,\r | |
734 | IN ATA_TRANSFER_MODE *TransferMode\r | |
ed66e1bc | 735 | );\r |
ead42efc | 736 | /**\r |
cd57e888 | 737 | Send ATA command into device with NON_DATA protocol.\r |
ead42efc | 738 | \r |
630d580d | 739 | @param IdeDev Standard IDE device private data structure\r |
740 | @param AtaCommand The ATA command to be sent\r | |
741 | @param Device The value in Device register\r | |
742 | @param Feature The value in Feature register\r | |
743 | @param SectorCount The value in SectorCount register\r | |
744 | @param LbaLow The value in LBA_LOW register\r | |
745 | @param LbaMiddle The value in LBA_MIDDLE register\r | |
746 | @param LbaHigh The value in LBA_HIGH register\r | |
ead42efc | 747 | \r |
630d580d | 748 | @retval EFI_SUCCESS Reading succeed\r |
749 | @retval EFI_ABORTED Command failed\r | |
750 | @retval EFI_DEVICE_ERROR Device status error.\r | |
ead42efc | 751 | \r |
752 | **/\r | |
753 | EFI_STATUS\r | |
754 | AtaNonDataCommandIn (\r | |
755 | IN IDE_BLK_IO_DEV *IdeDev,\r | |
756 | IN UINT8 AtaCommand,\r | |
757 | IN UINT8 Device,\r | |
758 | IN UINT8 Feature,\r | |
759 | IN UINT8 SectorCount,\r | |
760 | IN UINT8 LbaLow,\r | |
761 | IN UINT8 LbaMiddle,\r | |
762 | IN UINT8 LbaHigh\r | |
ed66e1bc | 763 | );\r |
ead42efc | 764 | \r |
75eccf9d | 765 | /**\r |
766 | Enable Long Physical Sector Feature for ATA device.\r | |
767 | \r | |
768 | @param IdeDev The IDE device data\r | |
769 | \r | |
770 | @retval EFI_SUCCESS The ATA device supports Long Physical Sector feature\r | |
771 | and corresponding fields in BlockIo structure is updated.\r | |
772 | @retval EFI_UNSUPPORTED The device is not ATA device or Long Physical Sector\r | |
773 | feature is not supported.\r | |
774 | **/\r | |
775 | EFI_STATUS\r | |
776 | AtaEnableLongPhysicalSector (\r | |
777 | IN IDE_BLK_IO_DEV *IdeDev\r | |
778 | );\r | |
779 | \r | |
ead42efc | 780 | /**\r |
cd57e888 | 781 | Set drive parameters for devices not support PACKETS command.\r |
ead42efc | 782 | \r |
630d580d | 783 | @param IdeDev Standard IDE device private data structure\r |
784 | @param DriveParameters The device parameters to be set into the disk\r | |
785 | @return SetParameters Command execute status.\r | |
ead42efc | 786 | \r |
787 | **/\r | |
788 | EFI_STATUS\r | |
789 | SetDriveParameters (\r | |
790 | IN IDE_BLK_IO_DEV *IdeDev,\r | |
791 | IN ATA_DRIVE_PARMS *DriveParameters\r | |
ed66e1bc | 792 | );\r |
ead42efc | 793 | \r |
794 | /**\r | |
7dd94873 | 795 | Enable Interrupt on IDE controller.\r |
ead42efc | 796 | \r |
630d580d | 797 | @param IdeDev Standard IDE device private data structure\r |
ead42efc | 798 | \r |
630d580d | 799 | @retval EFI_SUCCESS Enable Interrupt successfully\r |
ead42efc | 800 | **/\r |
801 | EFI_STATUS\r | |
802 | EnableInterrupt (\r | |
803 | IN IDE_BLK_IO_DEV *IdeDev\r | |
ed66e1bc | 804 | );\r |
ead42efc | 805 | #endif\r |