~ubuntu-branches/ubuntu/raring/virtualbox-ose/raring

« back to all changes in this revision

Viewing changes to src/VBox/Devices/EFI/Firmware2/VBoxPkg/VBoxIdeBusDxe/Ide.h

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2011-01-30 23:27:25 UTC
  • mfrom: (0.3.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20110130232725-2ouajjd2ggdet0zd
Tags: 4.0.2-dfsg-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Add Apport hook.
    - debian/virtualbox-ose.files/source_virtualbox-ose.py
    - debian/virtualbox-ose.install
  - Drop *-source packages.
* Drop ubuntu-01-fix-build-gcc45.patch, fixed upstream.
* Drop ubuntu-02-as-needed.patch, added to the Debian package.

Show diffs side-by-side

added added

removed removed

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