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