Change #define bit(a) 1 << (a)
[mirror_edk2.git] / EdkModulePkg / Bus / Pci / AtapiPassThru / Dxe / AtapiPassThru.h
1 /** @file
2 Copyright (c) 2006, Intel Corporation
3 All rights reserved. This program and the accompanying materials
4 are licensed and made available under the terms and conditions of the BSD License
5 which accompanies this distribution. The full text of the license may be found at
6 http://opensource.org/licenses/bsd-license.php
7
8 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
9 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
10
11 Module Name: AtapiPassThru.h
12
13 **/
14
15 #ifndef _APT_H
16 #define _APT_H
17
18
19 #include <IndustryStandard/pci22.h>
20
21 ///
22 /// bit definition
23 ///
24 #define bit(a) (1 << (a))
25
26 #define MAX_TARGET_ID 4
27
28 //
29 // IDE Registers
30 //
31 typedef union {
32 UINT16 Command; /* when write */
33 UINT16 Status; /* when read */
34 } IDE_CMD_OR_STATUS;
35
36 typedef union {
37 UINT16 Error; /* when read */
38 UINT16 Feature; /* when write */
39 } IDE_ERROR_OR_FEATURE;
40
41 typedef union {
42 UINT16 AltStatus; /* when read */
43 UINT16 DeviceControl; /* when write */
44 } IDE_AltStatus_OR_DeviceControl;
45
46 ///
47 /// IDE registers set
48 ///
49 typedef struct {
50 UINT16 Data;
51 IDE_ERROR_OR_FEATURE Reg1;
52 UINT16 SectorCount;
53 UINT16 SectorNumber;
54 UINT16 CylinderLsb;
55 UINT16 CylinderMsb;
56 UINT16 Head;
57 IDE_CMD_OR_STATUS Reg;
58
59 IDE_AltStatus_OR_DeviceControl Alt;
60 UINT16 DriveAddress;
61
62 UINT16 MasterSlave;
63 } IDE_BASE_REGISTERS;
64
65 #define ATAPI_SCSI_PASS_THRU_DEV_SIGNATURE EFI_SIGNATURE_32 ('a', 's', 'p', 't')
66
67 typedef struct {
68 UINTN Signature;
69
70 EFI_HANDLE Handle;
71 EFI_SCSI_PASS_THRU_PROTOCOL ScsiPassThru;
72 EFI_SCSI_PASS_THRU_MODE ScsiPassThruMode;
73 EFI_PCI_IO_PROTOCOL *PciIo;
74
75 //
76 // Local Data goes here
77 //
78 IDE_BASE_REGISTERS *IoPort;
79
80 CHAR16 ControllerName[100];
81 CHAR16 ChannelName[100];
82
83 UINT32 LatestTargetId;
84 UINT64 LatestLun;
85
86 } ATAPI_SCSI_PASS_THRU_DEV;
87
88 #define ATAPI_SCSI_PASS_THRU_DEV_FROM_THIS(a) \
89 CR (a, \
90 ATAPI_SCSI_PASS_THRU_DEV, \
91 ScsiPassThru, \
92 ATAPI_SCSI_PASS_THRU_DEV_SIGNATURE \
93 )
94
95 //
96 // Global Variables
97 //
98 extern EFI_DRIVER_BINDING_PROTOCOL gAtapiScsiPassThruDriverBinding;
99 extern EFI_COMPONENT_NAME_PROTOCOL gAtapiScsiPassThruComponentName;
100
101 //
102 // ATAPI Command op code
103 //
104 #define OP_INQUIRY 0x12
105 #define OP_LOAD_UNLOAD_CD 0xa6
106 #define OP_MECHANISM_STATUS 0xbd
107 #define OP_MODE_SELECT_10 0x55
108 #define OP_MODE_SENSE_10 0x5a
109 #define OP_PAUSE_RESUME 0x4b
110 #define OP_PLAY_AUDIO_10 0x45
111 #define OP_PLAY_AUDIO_MSF 0x47
112 #define OP_PLAY_CD 0xbc
113 #define OP_PLAY_CD_MSF 0xb4
114 #define OP_PREVENT_ALLOW_MEDIUM_REMOVAL 0x1e
115 #define OP_READ_10 0x28
116 #define OP_READ_12 0xa8
117 #define OP_READ_CAPACITY 0x25
118 #define OP_READ_CD 0xbe
119 #define OP_READ_CD_MSF 0xb9
120 #define OP_READ_HEADER 0x44
121 #define OP_READ_SUB_CHANNEL 0x42
122 #define OP_READ_TOC 0x43
123 #define OP_REQUEST_SENSE 0x03
124 #define OP_SCAN 0xba
125 #define OP_SEEK_10 0x2b
126 #define OP_SET_CD_SPEED 0xbb
127 #define OP_STOPPLAY_SCAN 0x4e
128 #define OP_START_STOP_UNIT 0x1b
129 #define OP_TEST_UNIT_READY 0x00
130
131 #define OP_FORMAT_UNIT 0x04
132 #define OP_READ_FORMAT_CAPACITIES 0x23
133 #define OP_VERIFY 0x2f
134 #define OP_WRITE_10 0x2a
135 #define OP_WRITE_12 0xaa
136 #define OP_WRITE_AND_VERIFY 0x2e
137
138 //
139 // ATA Command
140 //
141 #define ATAPI_SOFT_RESET_CMD 0x08
142
143 typedef enum {
144 DataIn = 0,
145 DataOut = 1,
146 NoData = 2,
147 End = 0xff
148 } DATA_DIRECTION;
149
150 typedef struct {
151 UINT8 OpCode;
152 DATA_DIRECTION Direction;
153 } SCSI_COMMAND_SET;
154
155 #define MAX_CHANNEL 2
156
157 #define ValidCdbLength(Len) ((Len) == 6 || (Len) == 10 || (Len) == 12) ? 1 : 0
158
159 //
160 // IDE registers bit definitions
161 //
162 // ATA Err Reg bitmap
163 //
164 #define BBK_ERR bit (7) ///< Bad block detected
165 #define UNC_ERR bit (6) ///< Uncorrectable Data
166 #define MC_ERR bit (5) ///< Media Change
167 #define IDNF_ERR bit (4) ///< ID Not Found
168 #define MCR_ERR bit (3) ///< Media Change Requested
169 #define ABRT_ERR bit (2) ///< Aborted Command
170 #define TK0NF_ERR bit (1) ///< Track 0 Not Found
171 #define AMNF_ERR bit (0) ///< Address Mark Not Found
172
173 //
174 // ATAPI Err Reg bitmap
175 //
176 #define SENSE_KEY_ERR (bit (7) | bit (6) | bit (5) | bit (4))
177 #define EOM_ERR bit (1) ///< End of Media Detected
178 #define ILI_ERR bit (0) ///< Illegal Length Indication
179
180 //
181 // Device/Head Reg
182 //
183 #define LBA_MODE bit (6)
184 #define DEV bit (4)
185 #define HS3 bit (3)
186 #define HS2 bit (2)
187 #define HS1 bit (1)
188 #define HS0 bit (0)
189 #define CHS_MODE (0)
190 #define DRV0 (0)
191 #define DRV1 (1)
192 #define MST_DRV DRV0
193 #define SLV_DRV DRV1
194
195 //
196 // Status Reg
197 //
198 #define BSY bit (7) ///< Controller Busy
199 #define DRDY bit (6) ///< Drive Ready
200 #define DWF bit (5) ///< Drive Write Fault
201 #define DSC bit (4) ///< Disk Seek Complete
202 #define DRQ bit (3) ///< Data Request
203 #define CORR bit (2) ///< Corrected Data
204 #define IDX bit (1) ///< Index
205 #define ERR bit (0) ///< Error
206 #define CHECK bit (0) ///< Check bit for ATAPI Status Reg
207
208 //
209 // Device Control Reg
210 //
211 #define SRST bit (2) ///< Software Reset
212 #define IEN_L bit (1) ///< Interrupt Enable
213
214 //
215 // ATAPI Feature Register
216 //
217 #define OVERLAP bit (1)
218 #define DMA bit (0)
219
220 //
221 // ATAPI Interrupt Reason Reson Reg (ATA Sector Count Register)
222 //
223 #define RELEASE bit (2)
224 #define IO bit (1)
225 #define CoD bit (0)
226
227 #define PACKET_CMD 0xA0
228
229 #define DEFAULT_CMD (0xa0)
230 //
231 // default content of device control register, disable INT
232 //
233 #define DEFAULT_CTL (0x0a)
234 #define MAX_ATAPI_BYTE_COUNT (0xfffe)
235
236 //
237 // function prototype
238 //
239 /**
240 AtapiScsiPassThruDriverEntryPoint
241
242 @param ImageHandle
243 @param SystemTable
244
245 @todo Add function description
246 @todo ImageHandle - add argument description
247 @todo SystemTable - add argument description
248 @todo add return values
249 --*/
250 EFI_STATUS
251 EFIAPI
252 AtapiScsiPassThruDriverEntryPoint (
253 IN EFI_HANDLE ImageHandle,
254 IN EFI_SYSTEM_TABLE *SystemTable
255 )
256 ;
257
258 /**
259 RegisterAtapiScsiPassThru
260
261 @param This
262 @param Controller
263 @param PciIo
264
265 @todo Add function description
266 @todo This add argument description
267 @todo Controller add argument description
268 @todo PciIo add argument description
269 @todo add return values
270 **/
271 EFI_STATUS
272 RegisterAtapiScsiPassThru (
273 IN EFI_DRIVER_BINDING_PROTOCOL *This,
274 IN EFI_HANDLE Controller,
275 IN EFI_PCI_IO_PROTOCOL *PciIo
276 )
277 ;
278
279 /**
280 AtapiScsiPassThruFunction
281
282 @param This
283 @param Target
284 @param Lun
285 @param Packet
286 @param Event
287
288 @todo Add function description
289 @todo This - add argument description
290 @todo Target - add argument description
291 @todo Lun - add argument description
292 @todo Packet - add argument description
293 @todo Event - add argument description
294 @todo add return values
295 **/
296 EFI_STATUS
297 EFIAPI
298 AtapiScsiPassThruFunction (
299 IN EFI_SCSI_PASS_THRU_PROTOCOL *This,
300 IN UINT32 Target,
301 IN UINT64 Lun,
302 IN OUT EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet,
303 IN EFI_EVENT Event OPTIONAL
304 )
305 ;
306
307 /**
308 AtapiScsiPassThruGetNextDevice
309
310 TODO: Add function description
311
312 @param This TODO: add argument description
313 @param Target TODO: add argument description
314 @param Lun TODO: add argument description
315
316 TODO: add return values
317
318 **/
319 EFI_STATUS
320 EFIAPI
321 AtapiScsiPassThruGetNextDevice (
322 IN EFI_SCSI_PASS_THRU_PROTOCOL *This,
323 IN OUT UINT32 *Target,
324 IN OUT UINT64 *Lun
325 )
326 ;
327
328 /**
329 AtapiScsiPassThruBuildDevicePath
330
331 TODO: Add function description
332
333 @param This TODO: add argument description
334 @param Target TODO: add argument description
335 @param Lun TODO: add argument description
336 @param DevicePath TODO: add argument description
337
338 TODO: add return values
339
340 **/
341 EFI_STATUS
342 EFIAPI
343 AtapiScsiPassThruBuildDevicePath (
344 IN EFI_SCSI_PASS_THRU_PROTOCOL *This,
345 IN UINT32 Target,
346 IN UINT64 Lun,
347 IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath
348 )
349 ;
350
351 /**
352 AtapiScsiPassThruGetTargetLun
353
354 TODO: Add function description
355
356 @param This TODO: add argument description
357 @param DevicePath TODO: add argument description
358 @param Target TODO: add argument description
359 @param Lun TODO: add argument description
360
361 TODO: add return values
362
363 **/
364 EFI_STATUS
365 EFIAPI
366 AtapiScsiPassThruGetTargetLun (
367 IN EFI_SCSI_PASS_THRU_PROTOCOL *This,
368 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
369 OUT UINT32 *Target,
370 OUT UINT64 *Lun
371 )
372 ;
373
374 /**
375 AtapiScsiPassThruResetChannel
376
377 TODO: Add function description
378
379 @param This TODO: add argument description
380
381 TODO: add return values
382
383 **/
384 EFI_STATUS
385 EFIAPI
386 AtapiScsiPassThruResetChannel (
387 IN EFI_SCSI_PASS_THRU_PROTOCOL *This
388 )
389 ;
390
391 /**
392 AtapiScsiPassThruResetTarget
393
394 TODO: Add function description
395
396 @param This TODO: add argument description
397 @param Target TODO: add argument description
398 @param Lun TODO: add argument description
399
400 TODO: add return values
401
402 **/
403 EFI_STATUS
404 EFIAPI
405 AtapiScsiPassThruResetTarget (
406 IN EFI_SCSI_PASS_THRU_PROTOCOL *This,
407 IN UINT32 Target,
408 IN UINT64 Lun
409 )
410 ;
411
412 /**
413 CheckSCSIRequestPacket
414
415 TODO: Add function description
416
417 @param Packet TODO: add argument description
418
419 TODO: add return values
420
421 **/
422 EFI_STATUS
423 CheckSCSIRequestPacket (
424 EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet
425 )
426 ;
427
428 /**
429 SubmitBlockingIoCommand
430
431 TODO: Add function description
432
433 @param AtapiScsiPrivate TODO: add argument description
434 @param Target TODO: add argument description
435 @param Packet TODO: add argument description
436
437 TODO: add return values
438
439 **/
440 EFI_STATUS
441 SubmitBlockingIoCommand (
442 ATAPI_SCSI_PASS_THRU_DEV *AtapiScsiPrivate,
443 UINT32 Target,
444 EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet
445 )
446 ;
447
448 /**
449 IsCommandValid
450
451 TODO: Add function description
452
453 @param Packet - TODO: add argument description
454
455 @return TODO: add return values
456
457 --*/
458 BOOLEAN
459 IsCommandValid (
460 EFI_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet
461 )
462 ;
463
464 /**
465 RequestSenseCommand
466
467 TODO: Add function description
468
469 @param AtapiScsiPrivate TODO: add argument description
470 @param Target TODO: add argument description
471 @param Timeout TODO: add argument description
472 @param SenseData TODO: add argument description
473 @param SenseDataLength TODO: add argument description
474
475 TODO: add return values
476
477 **/
478 EFI_STATUS
479 RequestSenseCommand (
480 ATAPI_SCSI_PASS_THRU_DEV *AtapiScsiPrivate,
481 UINT32 Target,
482 UINT64 Timeout,
483 VOID *SenseData,
484 UINT8 *SenseDataLength
485 )
486 ;
487
488 /**
489 AtapiPacketCommand
490
491 TODO: Add function description
492
493 @param AtapiScsiPrivate TODO: add argument description
494 @param Target TODO: add argument description
495 @param PacketCommand TODO: add argument description
496 @param Buffer TODO: add argument description
497 @param ByteCount TODO: add argument description
498 @param Direction TODO: add argument description
499 @param TimeOutInMicroSeconds TODO: add argument description
500
501 TODO: add return values
502
503 **/
504 EFI_STATUS
505 AtapiPacketCommand (
506 ATAPI_SCSI_PASS_THRU_DEV *AtapiScsiPrivate,
507 UINT32 Target,
508 UINT8 *PacketCommand,
509 VOID *Buffer,
510 UINT32 *ByteCount,
511 DATA_DIRECTION Direction,
512 UINT64 TimeOutInMicroSeconds
513 )
514 ;
515
516
517 /**
518 ReadPortB
519
520 TODO: Add function description
521
522 @param PciIo TODO: add argument description
523 @param Port TODO: add argument description
524
525 TODO: add return values
526
527 **/
528 UINT8
529 ReadPortB (
530 IN EFI_PCI_IO_PROTOCOL *PciIo,
531 IN UINT16 Port
532 )
533 ;
534
535
536 /**
537 ReadPortW
538
539 TODO: Add function description
540
541 @param PciIo TODO: add argument description
542 @param Port TODO: add argument description
543
544 TODO: add return values
545
546 **/
547 UINT16
548 ReadPortW (
549 IN EFI_PCI_IO_PROTOCOL *PciIo,
550 IN UINT16 Port
551 )
552 ;
553
554
555 /**
556 WritePortB
557
558 TODO: Add function description
559
560 @param PciIo TODO: add argument description
561 @param Port TODO: add argument description
562 @param Data TODO: add argument description
563
564 TODO: add return values
565
566 **/
567 VOID
568 WritePortB (
569 IN EFI_PCI_IO_PROTOCOL *PciIo,
570 IN UINT16 Port,
571 IN UINT8 Data
572 )
573 ;
574
575
576 /**
577 WritePortW
578
579 TODO: Add function description
580
581 @param PciIo TODO: add argument description
582 @param Port TODO: add argument description
583 @param Data TODO: add argument description
584
585 TODO: add return values
586
587 **/
588 VOID
589 WritePortW (
590 IN EFI_PCI_IO_PROTOCOL *PciIo,
591 IN UINT16 Port,
592 IN UINT16 Data
593 )
594 ;
595
596 /**
597 StatusDRQClear
598
599 TODO: Add function description
600
601 @param AtapiScsiPrivate TODO: add argument description
602 @param TimeOutInMicroSeconds TODO: add argument description
603
604 TODO: add return values
605
606 **/
607 EFI_STATUS
608 StatusDRQClear (
609 ATAPI_SCSI_PASS_THRU_DEV *AtapiScsiPrivate,
610 UINT64 TimeOutInMicroSeconds
611 )
612 ;
613
614 /**
615 AltStatusDRQClear
616
617 TODO: Add function description
618
619 @param AtapiScsiPrivate TODO: add argument description
620 @param TimeOutInMicroSeconds TODO: add argument description
621
622 TODO: add return values
623
624 **/
625 EFI_STATUS
626 AltStatusDRQClear (
627 ATAPI_SCSI_PASS_THRU_DEV *AtapiScsiPrivate,
628 UINT64 TimeOutInMicroSeconds
629 )
630 ;
631
632 /**
633 StatusDRQReady
634
635 TODO: Add function description
636
637 @param AtapiScsiPrivate TODO: add argument description
638 @param TimeOutInMicroSeconds TODO: add argument description
639
640 TODO: add return values
641
642 **/
643 EFI_STATUS
644 StatusDRQReady (
645 ATAPI_SCSI_PASS_THRU_DEV *AtapiScsiPrivate,
646 UINT64 TimeOutInMicroSeconds
647 )
648 ;
649
650 /**
651 AltStatusDRQReady
652
653 TODO: Add function description
654
655 @param AtapiScsiPrivate TODO: add argument description
656 @param TimeOutInMicroSeconds TODO: add argument description
657
658 TODO: add return values
659
660 **/
661 EFI_STATUS
662 AltStatusDRQReady (
663 ATAPI_SCSI_PASS_THRU_DEV *AtapiScsiPrivate,
664 UINT64 TimeOutInMicroSeconds
665 )
666 ;
667
668 /**
669 TODO: Add function description
670
671 @param AtapiScsiPrivate TODO: add argument description
672 @param TimeoutInMicroSeconds TODO: add argument description
673
674 TODO: add return values
675
676 **/
677 EFI_STATUS
678 StatusWaitForBSYClear (
679 ATAPI_SCSI_PASS_THRU_DEV *AtapiScsiPrivate,
680 UINT64 TimeoutInMicroSeconds
681 )
682 ;
683
684 /**
685 TODO: Add function description
686
687 @param AtapiScsiPrivate TODO: add argument description
688 @param TimeoutInMicroSeconds TODO: add argument description
689
690 TODO: add return values
691
692 **/
693 EFI_STATUS
694 AltStatusWaitForBSYClear (
695 ATAPI_SCSI_PASS_THRU_DEV *AtapiScsiPrivate,
696 UINT64 TimeoutInMicroSeconds
697 )
698 ;
699
700 /**
701 TODO: Add function description
702
703 @param AtapiScsiPrivate TODO: add argument description
704 @param TimeoutInMicroSeconds TODO: add argument description
705
706 TODO: add return values
707
708 **/
709 EFI_STATUS
710 StatusDRDYReady (
711 ATAPI_SCSI_PASS_THRU_DEV *AtapiScsiPrivate,
712 UINT64 TimeoutInMicroSeconds
713 )
714 ;
715
716 /**
717 TODO: Add function description
718
719 @param AtapiScsiPrivate TODO: add argument description
720 @param TimeoutInMicroSeconds TODO: add argument description
721
722 TODO: add return values
723
724 **/
725 EFI_STATUS
726 AltStatusDRDYReady (
727 ATAPI_SCSI_PASS_THRU_DEV *AtapiScsiPrivate,
728 UINT64 TimeoutInMicroSeconds
729 )
730 ;
731
732 /**
733 TODO: Add function description
734
735 @param AtapiScsiPrivate TODO: add argument description
736 @param Buffer TODO: add argument description
737 @param ByteCount TODO: add argument description
738 @param Direction TODO: add argument description
739 @param TimeOutInMicroSeconds TODO: add argument description
740
741 TODO: add return values
742
743 **/
744 EFI_STATUS
745 AtapiPassThruPioReadWriteData (
746 ATAPI_SCSI_PASS_THRU_DEV *AtapiScsiPrivate,
747 UINT16 *Buffer,
748 UINT32 *ByteCount,
749 DATA_DIRECTION Direction,
750 UINT64 TimeOutInMicroSeconds
751 )
752 ;
753
754 /**
755 TODO: Add function description
756
757 @param AtapiScsiPrivate TODO: add argument description
758
759 TODO: add return values
760
761 **/
762 EFI_STATUS
763 AtapiPassThruCheckErrorStatus (
764 ATAPI_SCSI_PASS_THRU_DEV *AtapiScsiPrivate
765 )
766 ;
767 #endif