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