Subversion Repositories Kolibri OS

Rev

Rev 9138 | Rev 9140 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 9138 Rev 9139
Line 24... Line 24...
24
AHCI_DEV_SATAPI = 4
24
AHCI_DEV_SATAPI = 4
Line 25... Line 25...
25
 
25
 
26
; ATA commands
26
; ATA commands
Line -... Line 27...
-
 
27
ATA_IDENTIFY    = 0xEC
-
 
28
 
-
 
29
; ATA constants
-
 
30
ATA_DEV_BUSY    = 0x80
27
ATA_IDENTIFY    = 0xEC
31
ATA_DEV_DRQ     = 0x08
28
 
32
 
Line 29... Line 33...
29
; ATAPI commands
33
; ATAPI commands
30
ATAPI_IDENTIFY  = 0xA1
34
ATAPI_IDENTIFY  = 0xA1
Line 43... Line 47...
43
 
47
 
44
bit_AHCI_HBA_PxCMD_ST    = 0
48
bit_AHCI_HBA_PxCMD_ST    = 0
45
bit_AHCI_HBA_PxCMD_FRE   = 4
49
bit_AHCI_HBA_PxCMD_FRE   = 4
46
bit_AHCI_HBA_PxCMD_FR    = 14
50
bit_AHCI_HBA_PxCMD_FR    = 14
-
 
51
bit_AHCI_HBA_PxCMD_CR    = 15
Line 47... Line 52...
47
bit_AHCI_HBA_PxCMD_CR    = 15
52
bit_AHCI_HBA_PxIS_TFES   = 30
48
 
53
 
49
AHCI_HBA_PxCMD_ST    = 1 shl 0
54
AHCI_HBA_PxCMD_ST    = 1 shl 0
50
AHCI_HBA_PxCMD_FRE   = 1 shl 4
55
AHCI_HBA_PxCMD_FRE   = 1 shl 4
Line 58... Line 63...
58
AHCI_HBA_PxSSTS_DET_PRESENT = 3
63
AHCI_HBA_PxSSTS_DET_PRESENT = 3
Line 59... Line 64...
59
 
64
 
60
AHCI_MAX_PORTS = 32        ;
65
AHCI_MAX_PORTS = 32        ;
Line -... Line 66...
-
 
66
;HBA_MEMORY_SIZE = 0x1100
-
 
67
 
61
;HBA_MEMORY_SIZE = 0x1100
68
AHCI_PORT_TIMEOUT = 1000000
62
 
69
 
63
; Frame Information Structure Types
70
; Frame Information Structure Types
64
FIS_TYPE_REG_H2D    = 0x27 ; Register FIS - host to device
71
FIS_TYPE_REG_H2D    = 0x27 ; Register FIS - host to device
65
FIS_TYPE_REG_D2H    = 0x34 ; Register FIS - device to host
72
FIS_TYPE_REG_D2H    = 0x34 ; Register FIS - device to host
Line 617... Line 624...
617
        jne     @f
624
        jne     @f
618
        mov     byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.command], ATAPI_IDENTIFY
625
        mov     byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.command], ATAPI_IDENTIFY
619
@@:
626
@@:
620
        mov     byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.device], 0
627
        mov     byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.device], 0
Line 621... Line 628...
621
 
628
 
-
 
629
        ; Wait on previous command to complete, before issuing new command.
622
        ; TODO Wait on previous command to complete. AHCIPortWait(bd->port_num, tS + 2);
630
        stdcall ahci_port_wait, edi, AHCI_PORT_TIMEOUT
623
        mov     ebx, 20 ;;;
631
        ; DEBUGF  1, "eax = %x\n", eax
Line 624... Line 632...
624
        call    delay_hs ;;;
632
        ; TODO check eax error value
625
 
633
 
Line 626... Line 634...
626
        mov     eax, [cmdslot]
634
        mov     eax, [cmdslot]
-
 
635
        bts     [edi + HBA_PORT.command_issue], eax ; Issue the command
627
        bts     [edi + HBA_PORT.command_issue], eax ; Issue the command
636
 
628
 
637
        ; Wait for command completion
Line 629... Line 638...
629
        ; TODO AHCIPortCmdWait(bd->port_num, cmd_slot);
638
        stdcall ahci_port_cmd_wait, edi, eax;, AHCI_PORT_CMD_TIMEOUT
Line 630... Line -...
630
        mov     ebx, 20 ;;;
-
 
631
        call    delay_hs ;;;
-
 
632
 
-
 
633
        ; DEBUGF  1, "sata_error register = 0x%x\n", [edi + HBA_PORT.sata_error]
-
 
634
 
-
 
635
;         mov     ecx, ecx
-
 
636
;         mov     esi, [buf_virt]
-
 
637
; .print_ident:
-
 
638
;         cmp     ecx, 512 - 1 ; why -1 ?
-
 
639
;         jae     .end_print_ident
-
 
640
 
-
 
641
;         mov     al, byte [esi + ecx]
-
 
642
;         mov     byte [modelstr], al
-
 
643
;         mov     byte [modelstr + 1], 0
-
 
644
;         DEBUGF  1, "(%s) ", modelstr
-
 
645
 
-
 
646
;         inc     ecx
-
 
647
;         jmp     .print_ident
-
 
648
; .end_print_ident:
639
        ; DEBUGF  1, " eax = %x\n", eax
649
        ; DEBUGF  1, "\n"
640
        ; TODO check eax error value
650
 
641
 
651
        ; DEBUGF  1, "after identification: signature = 0x%x\n", [edi + HBA_PORT.signature]
642
        ; DEBUGF  1, "sata_error register = 0x%x\n", [edi + HBA_PORT.sata_error]
652
 
643
 
Line 700... Line 691...
700
        bt      [eax + HBA_PORT.command], bit_AHCI_HBA_PxCMD_CR
691
        bt      [eax + HBA_PORT.command], bit_AHCI_HBA_PxCMD_CR
701
        jc      .wait_fr_cr
692
        jc      .wait_fr_cr
Line 702... Line 693...
702
 
693
 
Line 703... Line 694...
703
        ret
694
        ret
704
 
695
 
705
; The commands may not take effect until the command
696
; waits until the port is no longer busy before issuing a new command
706
; register is read again by software, because reasons.
697
; in: [port] - address of HBA_PORT structure
-
 
698
; [timeout] - timeout (in iterations)
707
; in: eax - address of HBA_PORT structure
699
; out: eax = 0 if success, 1 if timeout expired
-
 
700
proc ahci_port_wait stdcall, port: dword, timeout: dword
-
 
701
        push    ebx ecx
-
 
702
        mov     ebx, [port]
-
 
703
        xor     ecx, ecx
-
 
704
.wait:
708
; out: eax - command register value
705
        cmp     ecx, [timeout]
-
 
706
        jae     .wait_end
-
 
707
        mov     eax, [ebx + HBA_PORT.task_file_data]
-
 
708
        and     eax, ATA_DEV_BUSY or ATA_DEV_DRQ
-
 
709
        test    eax, eax
-
 
710
        jz      .wait_end
-
 
711
        inc     ecx
-
 
712
        jmp     .wait
-
 
713
.wait_end:
-
 
714
        xor     eax, eax
-
 
715
        DEBUGF  1, "port wait counter = %u\n", ecx
-
 
716
        cmp     ecx, [timeout] ; if they equal it means port is hung
709
ahci_flush_cmd:
717
        setz    al
-
 
718
        pop     ecx ebx
Line 710... Line -...
710
        mov     eax, [eax + HBA_PORT.command]
-
 
711
        ret
-
 
712
 
-
 
713
; Send command to port
-
 
714
; in: eax - address of HBA_PORT structure
-
 
715
;     ebx - index of command slot
-
 
716
ahci_send_cmd:
-
 
717
        push    ecx
-
 
718
        mov     [eax + HBA_PORT.interrupt_status], 0xFFFFFFFF
-
 
719
        
-
 
Line -... Line 719...
-
 
719
        ret
-
 
720
endp
-
 
721
 
-
 
722
 
-
 
723
; Wait for command completion
-
 
724
; in: [port] - address of HBA_PORT structure
-
 
725
;     [cmdslot] - number of command slot
-
 
726
; out: eax = 0 if success, 1 if error
-
 
727
proc ahci_port_cmd_wait stdcall, port: dword, cmdslot: dword ;, timeout: dword
-
 
728
        push    ebx ecx edx
-
 
729
        mov     ebx, [port]
-
 
730
        mov     edx, [cmdslot]
720
        mov     cl, bl
731
        xor     eax, eax
-
 
732
        xor     ecx, ecx
-
 
733
.wait:
721
        mov     [eax + HBA_PORT.command_issue], 1
734
        bt      [ebx + HBA_PORT.command_issue], edx
-
 
735
        jnc     .wait_end
-
 
736
        bt      [ebx + HBA_PORT.interrupt_status], bit_AHCI_HBA_PxIS_TFES ; check for Task File Error
-
 
737
        jc      .error
-
 
738
        inc     ecx
-
 
739
        jmp     .wait
-
 
740
.wait_end:
-
 
741
        DEBUGF  1, "port cmd wait counter = %u\n", ecx
-
 
742
        bt      [ebx + HBA_PORT.interrupt_status], bit_AHCI_HBA_PxIS_TFES ; check for Task File Error
-
 
743
        jc      .error
-
 
744
        jmp     .ret
722
        shl     [eax + HBA_PORT.command_issue], cl
745
.error:
-
 
746
        mov     eax, 1
-
 
747
.ret:
-
 
748
        pop     edx ecx ebx
-
 
749
        ret
-
 
750
endp
-
 
751
 
-
 
752
; ; The commands may not take effect until the command
-
 
753
; ; register is read again by software, because reasons.
-
 
754
; ; in: eax - address of HBA_PORT structure
-
 
755
; ; out: eax - command register value
-
 
756
; ahci_flush_cmd:
-
 
757
;         mov     eax, [eax + HBA_PORT.command]
-
 
758
;         ret
-
 
759
 
-
 
760
; ; Send command to port
-
 
761
; ; in: eax - address of HBA_PORT structure
-
 
762
; ;     ebx - index of command slot
-
 
763
; ahci_send_cmd:
-
 
764
;         push    ecx
-
 
765
;         mov     [eax + HBA_PORT.interrupt_status], 0xFFFFFFFF
-
 
766
        
-
 
767
;         mov     cl, bl
-
 
768
;         mov     [eax + HBA_PORT.command_issue], 1
-
 
769
;         shl     [eax + HBA_PORT.command_issue], cl
Line 723... Line 770...
723
 
770
 
724
        call    ahci_flush_cmd
771
;         call    ahci_flush_cmd
725
        pop     ecx
772
;         pop     ecx
726
        ret
773
;         ret