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