Subversion Repositories Kolibri OS

Rev

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

Rev 9143 Rev 9145
Line 720... Line 720...
720
        mov     esi, [buf_virt]
720
        mov     esi, [buf_virt]
721
        mov     eax, [esi + 200]
721
        mov     eax, [esi + 200]
722
        mov     edx, [esi + 200 + 4]
722
        mov     edx, [esi + 200 + 4]
723
        DEBUGF 1, "lba48 mode sector count = 0x%x:%x\n", edx, eax
723
        DEBUGF 1, "lba48 mode sector count = 0x%x:%x\n", edx, eax
Line -... Line 724...
-
 
724
 
-
 
725
        mov     ebx, [pdata]
-
 
726
        mov     dword [ebx + PORT_DATA.sector_count], eax
-
 
727
        mov     dword [ebx + PORT_DATA.sector_count + 4], edx
724
 
728
 
725
        shrd    eax, edx, 11 ; i.e *512 / 1024 / 1024, 512 - sector size
729
        shrd    eax, edx, 11 ; i.e *512 / 1024 / 1024, 512 - sector size
726
        DEBUGF  1, "disk capacity = %u MiB ", eax
730
        DEBUGF  1, "disk capacity = %u MiB ", eax
727
        shrd    eax, edx, 10 ; / 1024
731
        shrd    eax, edx, 10 ; / 1024
728
        DEBUGF  1, "= %u GiB\n", eax
732
        DEBUGF  1, "= %u GiB\n", eax
Line 744... Line 748...
744
        pop     edx ecx
748
        pop     edx ecx
745
        xor     eax, eax
749
        xor     eax, eax
746
        ret
750
        ret
747
endp
751
endp
Line 748... Line -...
748
 
-
 
749
;------------------------TEST-------------------------------
-
 
750
 
-
 
751
proc ahci_read_first_sector stdcall pdata: dword
-
 
752
        locals
-
 
753
            cmdslot dd ?
-
 
754
            cmdheader dd ?
-
 
755
            cmdtable  dd ?
-
 
756
            buf_phys  dd ?
-
 
757
            buf_virt  dd ?
-
 
758
            ;numsectors dd ?
-
 
759
        endl
-
 
760
 
-
 
761
        pushad
-
 
762
        mov     ecx, ahci_mutex
-
 
763
        call    mutex_lock
-
 
764
 
-
 
765
        mov     esi, [pdata] ; esi - address of PORT_DATA struct of port
-
 
766
        mov     edi, [esi + PORT_DATA.port] ; edi - address of HBA_PORT struct of port
-
 
767
        mov     eax, edi
-
 
768
        call    ahci_find_cmdslot
-
 
769
        cmp     eax, -1
-
 
770
        jne      .cmdslot_found
-
 
771
 
-
 
772
        DEBUGF  1, "No free cmdslot on port %u\n", [esi + PORT_DATA.portno]
-
 
773
        jmp     .ret
-
 
774
 
-
 
775
.cmdslot_found:
-
 
776
        mov     [cmdslot], eax
-
 
777
        DEBUGF  1, "Found free cmdslot %u on port %u\n", [cmdslot], [esi + PORT_DATA.portno]
-
 
778
 
-
 
779
        shl     eax, BSF sizeof.HBA_CMD_HDR
-
 
780
        add     eax, [esi + PORT_DATA.clb]
-
 
781
        mov     [cmdheader], eax ; address of virtual mapping of command header
-
 
782
        mov     eax, [cmdslot]
-
 
783
        mov     eax, [esi + eax*4 + PORT_DATA.ctba_arr]
-
 
784
        mov     [cmdtable], eax ; address of virtual mapping of command table of command header
-
 
785
 
-
 
786
        mov     eax, [cmdheader]
-
 
787
        and     [eax + HBA_CMD_HDR.flags1], not 0x1F ; zero out lower 5 bits, they will be used for cfl
-
 
788
        or      [eax + HBA_CMD_HDR.flags1], (sizeof.FIS_REG_H2D / 4) ; set command fis length in dwords
-
 
789
        movzx   bx, [eax + HBA_CMD_HDR.flags1]
-
 
790
        btr     bx, 6 ; flag W = 0
-
 
791
        mov     [eax + HBA_CMD_HDR.flags1], bl
-
 
792
        movzx   bx, [eax + HBA_CMD_HDR.flags2]
-
 
793
        btr     bx, 2 ; flag C = 0
-
 
794
        mov     [eax + HBA_CMD_HDR.flags2], bl
-
 
795
 
-
 
796
        mov     [eax + HBA_CMD_HDR.prdtl], 1
-
 
797
        
-
 
798
        ; zero out the command table
-
 
799
        stdcall _memset, [cmdtable], 0, sizeof.HBA_CMD_TBL
-
 
800
        
-
 
801
        DEBUGF  1, "  prdtl = %u\n", [eax + HBA_CMD_HDR.prdtl]:2
-
 
802
 
-
 
803
        call    alloc_page
-
 
804
        mov     [buf_phys], eax
-
 
805
 
-
 
806
        stdcall map_io_mem, eax, 4096, PG_NOCACHE + PG_SWR  ; map to virt memory so we can work with it
-
 
807
        mov     [buf_virt], eax
-
 
808
 
-
 
809
        mov     eax, [cmdtable]
-
 
810
        mov     ebx, [buf_phys]
-
 
811
        DEBUGF  1, "DBA = 0x%x\n", ebx
-
 
812
        mov     [eax + HBA_CMD_TBL.prdt_entry + HBA_PRDT_ENTRY.dba], ebx
-
 
813
        mov     [eax + HBA_CMD_TBL.prdt_entry + HBA_PRDT_ENTRY.dbau], 0
-
 
814
        and     [eax + HBA_CMD_TBL.prdt_entry + HBA_PRDT_ENTRY.flags], not 0x3FFFFF ; zero out lower 22 bits, they used for byte count
-
 
815
        or      [eax + HBA_CMD_TBL.prdt_entry + HBA_PRDT_ENTRY.flags], 512 - 1 ; reason why -1 see in spec on this field
-
 
816
        ; or      [eax + HBA_CMD_TBL.prdt_entry + HBA_PRDT_ENTRY.flags], 1 shl 31 ; enable interrupt on completion
-
 
817
 
-
 
818
        mov     eax, [cmdtable]
-
 
819
        mov     byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.fis_type], FIS_TYPE_REG_H2D
-
 
820
        movzx   ebx, byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.flags]
-
 
821
        bts     ebx, bit_AHCI_H2D_FLAG_CMD ; Set Command bit in H2D FIS.
-
 
822
        mov     byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.flags], bl
-
 
823
 
-
 
824
        mov     byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.command], ATA_CMD_READ_DMA_EX
-
 
825
 
-
 
826
        mov     ebx, 0 ; start sector is 0
-
 
827
        mov     byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.lba0], bl
-
 
828
        mov     byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.lba1], bl
-
 
829
        mov     byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.lba2], bl
-
 
830
        mov     byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.device], 1 shl 6 ; LBA mode
-
 
831
        mov     byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.lba3], bl
-
 
832
        mov     byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.lba4], bl
-
 
833
        mov     byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.lba5], bl
-
 
834
 
-
 
835
        ; num sectors to read  = 1
-
 
836
        mov     byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.countl], 1
-
 
837
        mov     byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.counth], 0
-
 
838
 
-
 
839
        ;mov     eax, [cmdheader]
-
 
840
        ;DEBUGF  1, "PRDBC = %u\n", [eax + HBA_CMD_HDR.prdbc]
-
 
841
 
-
 
842
        ; Wait on previous command to complete, before issuing new command.
-
 
843
        stdcall ahci_port_wait, edi, AHCI_PORT_TIMEOUT
-
 
844
 
-
 
845
        mov     eax, [cmdslot]
-
 
846
        bts     [edi + HBA_PORT.command_issue], eax ; Issue the command
-
 
847
 
-
 
848
        ; mov     ebx, 20
-
 
849
        ; call    delay_hs
-
 
850
        ; Wait for command completion
-
 
851
        stdcall ahci_port_cmd_wait, edi, eax;, AHCI_PORT_CMD_TIMEOUT
-
 
852
 
-
 
853
        DEBUGF  1, "sata_error register = 0x%x\n", [edi + HBA_PORT.sata_error]
-
 
854
 
-
 
855
        DEBUGF  1, "reading completed\n"
-
 
856
 
-
 
857
        ;mov     eax, [cmdheader]
-
 
858
        ;DEBUGF  1, "PRDBC = %u\n", [eax + HBA_CMD_HDR.prdbc]
-
 
859
 
-
 
860
        xor     ecx, ecx
-
 
861
        mov     esi, [buf_virt]
-
 
862
.print_data:
-
 
863
        cmp     ecx, 512
-
 
864
        jae     .end_print_data
-
 
865
 
-
 
866
        mov     al, byte [esi + ecx]
-
 
867
        mov     byte [tmpstr2], al
-
 
868
        mov     byte [tmpstr2 + 1], 0
-
 
869
        DEBUGF  1, "0x%x(%s) ", al:2, tmpstr2
-
 
870
 
-
 
871
        inc     ecx
-
 
872
        jmp     .print_data
-
 
873
.end_print_data:
-
 
874
        DEBUGF  1, "\n"
-
 
875
 
-
 
876
.ret:
-
 
877
        mov     ecx, ahci_mutex
-
 
878
        call    mutex_unlock
-
 
879
 
-
 
880
        popad
-
 
881
        xor     eax, eax
-
 
882
        ret
-
 
883
endp
-
 
884
tmpstr2    rb 16
-
 
885
;----------------------------------------------------------
-
 
886
 
-
 
887
 
752
 
888
; Read sectors
753
; Read sectors
889
; return value: 0 = success, otherwise = error
754
; return value: 0 = success, otherwise = error
890
proc ahci_read stdcall pdata: dword, buffer: dword, startsector: qword, numsectors_ptr:dword
755
proc ahci_read stdcall pdata: dword, buffer: dword, startsector: qword, numsectors_ptr:dword
891
        locals
756
        locals
Line 983... Line 848...
983
        cmp     ecx, edx
848
        cmp     ecx, edx
984
        jae     .prdt_fill_end
849
        jae     .prdt_fill_end
Line 985... Line 850...
985
 
850
 
986
        mov     ebx, [buffer_pos]
851
        mov     ebx, [buffer_pos]
-
 
852
        and     ebx, 0xFFF
987
        and     ebx, 0xFFF
853
        mov     eax, [buffer_pos]
988
        call    get_pg_addr ; eax = phys addr 
854
        call    get_pg_addr ; eax = phys addr 
989
        add     eax, ebx
855
        add     eax, ebx
990
        DEBUGF  1, "  PHYS = 0x%x\n", eax
856
        DEBUGF  1, "  PHYS = 0x%x\n", eax
991
        mov     ebx, ecx
857
        mov     ebx, ecx
Line 1005... Line 871...
1005
        jmp     .prdt_fill
871
        jmp     .prdt_fill
1006
.prdt_fill_end:
872
.prdt_fill_end:
Line 1007... Line 873...
1007
 
873
 
1008
        mov     ebx, [buffer_pos]
874
        mov     ebx, [buffer_pos]
-
 
875
        and     ebx, 0xFFF
1009
        and     ebx, 0xFFF
876
        mov     eax, [buffer_pos]
1010
        call    get_pg_addr ; eax = phys addr 
877
        call    get_pg_addr ; eax = phys addr 
1011
        add     eax, ebx
878
        add     eax, ebx
1012
        DEBUGF  1, "  PHYS. = 0x%x\n", eax
879
        DEBUGF  1, "  PHYS. = 0x%x\n", eax
1013
        DEBUGF  1, "  ecx = 0x%x\n", ecx
880
        DEBUGF  1, "  ecx = 0x%x\n", ecx
Line 1062... Line 929...
1062
 
929
 
Line 1063... Line 930...
1063
        DEBUGF  1, "sata_error register = 0x%x\n", [edi + HBA_PORT.sata_error]
930
        DEBUGF  1, "sata_error register = 0x%x\n", [edi + HBA_PORT.sata_error]
Line 1064... Line 931...
1064
 
931
 
1065
        DEBUGF  1, "reading completed\n"
932
        DEBUGF  1, "reading completed\n"
1066
 
933
 
1067
        xor     ecx, ecx
934
;         xor     ecx, ecx
1068
        mov     esi, [buffer]
935
;         mov     esi, [buffer]
1069
.print_data:
-
 
1070
        cmp     ecx, 512
-
 
1071
        jae     .end_print_data
-
 
1072
 
-
 
1073
        mov     al, byte [esi + ecx]
-
 
Line -... Line 936...
-
 
936
; .print_data:
-
 
937
;         cmp     ecx, 512
-
 
938
;         jae     .end_print_data
-
 
939
 
-
 
940
;         mov     al, byte [esi + ecx]
1074
        mov     byte [tmpstr], al
941
;         mov     byte [tmpstr], al
1075
        mov     byte [tmpstr + 1], 0
942
;         mov     byte [tmpstr + 1], 0
1076
        DEBUGF  1, "0x%x(%s) ", al:2, tmpstr
943
;         DEBUGF  1, "0x%x(%s) ", al:2, tmpstr
1077
 
944
 
Line 1078... Line 945...
1078
        inc     ecx
945
;         inc     ecx
1079
        jmp     .print_data
946
;         jmp     .print_data
1080
.end_print_data:
947
; .end_print_data: