Subversion Repositories Kolibri OS

Rev

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

Rev 9271 Rev 9272
Line 163... Line 163...
163
    ctba_arr      rd 32 ; ctba_arr[0] = clb[0].ctba, ... and so on.
163
    ctba_arr      rd 32 ; ctba_arr[0] = clb[0].ctba, ... and so on.
164
    port          dd ? ; address of correspoding HBA_PORT structure
164
    port          dd ? ; address of correspoding HBA_PORT structure
165
    portno        dd ? ; port index, 0..31
165
    portno        dd ? ; port index, 0..31
166
    drive_type    db ? ; drive type
166
    drive_type    db ? ; drive type
167
    sector_count  dq ? ; number of sectors
167
    sector_count  dq ? ; number of sectors
-
 
168
    ctr_ptr       dd ? ; pointer to controller to which port belongs
168
ends
169
ends
Line 169... Line 170...
169
 
170
 
170
; Register FIS – Host to Device
171
; Register FIS – Host to Device
171
struct FIS_REG_H2D
172
struct FIS_REG_H2D
Line 556... Line 557...
556
 
557
 
557
        mov     ecx, ebx
558
        mov     ecx, ebx
558
        imul    ecx, sizeof.PORT_DATA
559
        imul    ecx, sizeof.PORT_DATA
559
        add     ecx, AHCI_CTR.port_data_arr
560
        add     ecx, AHCI_CTR.port_data_arr
-
 
561
        add     ecx, [ctr_ptr]
-
 
562
        mov     eax, [ctr_ptr]
560
        add     ecx, [ctr_ptr]
563
        mov     [ecx + PORT_DATA.ctr_ptr], eax ; to which controller the port belongs
Line 561... Line 564...
561
        stdcall ahci_port_rebase, edi, ebx, ecx
564
        stdcall ahci_port_rebase, edi, ebx, ecx
Line 562... Line 565...
562
 
565
 
Line 660... Line 663...
660
        endl
663
        endl
Line 661... Line 664...
661
 
664
 
Line 662... Line 665...
662
        pushad
665
        pushad
663
        
-
 
664
        mov     esi, [pdata] ; esi - address of PORT_DATA struct of port
-
 
665
        mov     edi, [esi + PORT_DATA.port] ; edi - address of HBA_PORT struct of port
-
 
666
 
666
        
Line 667... Line 667...
667
        mov     eax, edi
667
        mov     esi, [pdata] ; esi - address of PORT_DATA struct of port
668
        call    ahci_find_cmdslot
668
        stdcall ahci_find_cmdslot, esi
Line 669... Line 669...
669
 
669
 
Line 722... Line 722...
722
        jne     @f
722
        jne     @f
723
        mov     byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.command], ATAPI_IDENTIFY
723
        mov     byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.command], ATAPI_IDENTIFY
724
@@:
724
@@:
725
        mov     byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.device], 0
725
        mov     byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.device], 0
Line -... Line 726...
-
 
726
 
-
 
727
        mov     edi, [esi + PORT_DATA.port] ; edi - address of HBA_PORT struct of port
726
 
728
 
727
        ; Wait on previous command to complete, before issuing new command.
729
        ; Wait on previous command to complete, before issuing new command.
728
        stdcall ahci_port_wait, edi, AHCI_PORT_TIMEOUT
730
        stdcall ahci_port_wait, edi, AHCI_PORT_TIMEOUT
729
        ; DEBUGF  1, "eax = %x\n", eax
731
        ; DEBUGF  1, "eax = %x\n", eax
Line 806... Line 808...
806
        pushad
808
        pushad
Line 807... Line 809...
807
 
809
 
Line 808... Line 810...
808
        DEBUGF  AHCI_DBGLVL, "    ahci_rw_sectors: buffer = 0x%x, startsector = 0x%x:%x, numsectors = %u, is_write = %u\n", [vbuf], [startsector], [startsector + 4], [numsectors], [is_write]:1
810
        DEBUGF  AHCI_DBGLVL, "    ahci_rw_sectors: buffer = 0x%x, startsector = 0x%x:%x, numsectors = %u, is_write = %u\n", [vbuf], [startsector], [startsector + 4], [numsectors], [is_write]:1
809
 
-
 
810
        mov     esi, [pdata] ; esi - address of PORT_DATA struct of port
-
 
811
        mov     edi, [esi + PORT_DATA.port] ; edi - address of HBA_PORT struct of port
811
 
812
        mov     eax, edi
812
        mov     esi, [pdata] ; esi - address of PORT_DATA struct of port
813
        call    ahci_find_cmdslot
813
        stdcall ahci_find_cmdslot, esi
Line 814... Line 814...
814
        cmp     eax, -1
814
        cmp     eax, -1
815
        jne     .cmdslot_found
815
        jne     .cmdslot_found
Line 996... Line 996...
996
        mov     ebx, [numsectors]
996
        mov     ebx, [numsectors]
997
        mov     byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.countl], bl
997
        mov     byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.countl], bl
998
        shr     ebx, 8
998
        shr     ebx, 8
999
        mov     byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.counth], bl
999
        mov     byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.counth], bl
Line -... Line 1000...
-
 
1000
 
-
 
1001
        mov     edi, [esi + PORT_DATA.port] ; edi - address of HBA_PORT struct of port
1000
 
1002
 
1001
        ; Wait on previous command to complete, before issuing new command.
1003
        ; Wait on previous command to complete, before issuing new command.
Line 1002... Line 1004...
1002
        stdcall ahci_port_wait, edi, AHCI_PORT_TIMEOUT
1004
        stdcall ahci_port_wait, edi, AHCI_PORT_TIMEOUT
1003
 
1005
 
Line 1048... Line 1050...
1048
                numsectors dd ?
1050
                numsectors dd ?
1049
        endl
1051
        endl
Line 1050... Line 1052...
1050
 
1052
 
Line -... Line 1053...
-
 
1053
        pushad
1051
        pushad
1054
 
-
 
1055
        mov     ecx, [pdata]
1052
 
1056
        mov     ecx, [ecx + PORT_DATA.ctr_ptr]
Line 1053... Line 1057...
1053
        mov     ecx, ctr1_data.mutex  ; why ctr1 ? TODO: make for corresponding controller
1057
        mov     ecx, [ecx + AHCI_CTR.mutex]
1054
        call    mutex_lock
1058
        call    mutex_lock
1055
 
1059
 
Line 1086... Line 1090...
1086
        adc     dword [startsector + 4], 0
1090
        adc     dword [startsector + 4], 0
Line 1087... Line 1091...
1087
 
1091
 
1088
        jmp     .read_loop
1092
        jmp     .read_loop
Line -... Line 1093...
-
 
1093
.read_loop_end:
1089
.read_loop_end:
1094
 
-
 
1095
        mov     ecx, [pdata]
1090
 
1096
        mov     ecx, [ecx + PORT_DATA.ctr_ptr]
Line 1091... Line 1097...
1091
        mov     ecx, ctr1_data.mutex  ; why ctr1 ? TODO: make for corresponding controller
1097
        mov     ecx, [ecx + AHCI_CTR.mutex]
1092
        call    mutex_unlock
1098
        call    mutex_unlock
1093
 
1099
 
Line 1103... Line 1109...
1103
                numsectors dd ?
1109
                numsectors dd ?
1104
        endl
1110
        endl
Line 1105... Line 1111...
1105
 
1111
 
Line -... Line 1112...
-
 
1112
        pushad
1106
        pushad
1113
 
-
 
1114
        mov     ecx, [pdata]
1107
 
1115
        mov     ecx, [ecx + PORT_DATA.ctr_ptr]
Line 1108... Line 1116...
1108
        mov     ecx, ctr1_data.mutex  ; why ctr1 ? TODO: make for corresponding controller
1116
        mov     ecx, [ecx + AHCI_CTR.mutex]
1109
        call    mutex_lock
1117
        call    mutex_lock
1110
 
1118
 
Line 1132... Line 1140...
1132
        adc     dword [startsector + 4], 0
1140
        adc     dword [startsector + 4], 0
Line 1133... Line 1141...
1133
 
1141
 
1134
        jmp     .write_loop
1142
        jmp     .write_loop
Line -... Line 1143...
-
 
1143
.write_loop_end:
1135
.write_loop_end:
1144
 
-
 
1145
        mov     ecx, [pdata]
1136
 
1146
        mov     ecx, [ecx + PORT_DATA.ctr_ptr]
Line 1137... Line 1147...
1137
        mov     ecx, ctr1_data.mutex  ; why ctr1 ? TODO: make for corresponding controller
1147
        mov     ecx, [ecx + AHCI_CTR.mutex]
1138
        call    mutex_unlock
1148
        call    mutex_unlock
1139
 
1149
 
Line 1249... Line 1259...
1249
 
1259
 
1250
; ---------------------------------------------------------------------------
1260
; ---------------------------------------------------------------------------
1251
; in: port - address of HBA_PORT structure
1261
; in: port - address of HBA_PORT structure
1252
;     portno - port index (0..31)
1262
;     portno - port index (0..31)
-
 
1263
;     pdata - address of PORT_DATA structure
-
 
1264
; out:
1253
;     pdata - address of PORT_DATA structure
1265
;     rebases port and fills pdata with mappings
1254
proc ahci_port_rebase stdcall, port: dword, portno: dword, pdata: dword
1266
proc ahci_port_rebase stdcall, port: dword, portno: dword, pdata: dword
1255
        locals
1267
        locals
1256
            phys_page1  dd ?
1268
            phys_page1  dd ?
1257
            virt_page1  dd ?
1269
            virt_page1  dd ?
Line 1358... Line 1370...
1358
        ret    
1370
        ret    
1359
endp
1371
endp
Line 1360... Line 1372...
1360
 
1372
 
1361
; ----------------------------------------------------------- ; TODO check
1373
; ----------------------------------------------------------- ; TODO check
1362
; Find a free command list slot
1374
; Find a free command list slot
1363
; in: eax - address of HBA_PORT structure
1375
; in: pdata - address of HBA_PORT structure
1364
; out: eax - if not found -1, else slot index
1376
; out: eax - if not found -1, else slot index
1365
ahci_find_cmdslot:
1377
proc ahci_find_cmdslot stdcall, pdata: dword
-
 
1378
        push    ebx ecx edx esi
-
 
1379
        mov     esi, [pdata]
-
 
1380
        mov     eax, [esi + PORT_DATA.port]
1366
        push    ebx ecx edx esi
1381
 
1367
        ; If not set in SACT and CI, the slot is free
1382
        ; If not set in SACT and CI, the slot is free
1368
        mov     ebx, [eax + HBA_PORT.sata_active]
1383
        mov     ebx, [eax + HBA_PORT.sata_active]
Line 1369... Line 1384...
1369
        or      ebx, [eax + HBA_PORT.command_issue] ; ebx = slots
1384
        or      ebx, [eax + HBA_PORT.command_issue] ; ebx = slots
-
 
1385
 
1370
 
1386
        mov     esi, [esi + PORT_DATA.ctr_ptr]
1371
        mov     esi, [ctr1_data.abar] ; why ctr1 ? TODO: make for corresponding controller
1387
        mov     esi, [esi + AHCI_CTR.abar]
1372
        mov     edx, [esi + HBA_MEM.cap]
1388
        mov     edx, [esi + HBA_MEM.cap]
1373
        shr     edx, 8
1389
        shr     edx, 8
1374
        and     edx, 0xf
1390
        and     edx, 0xf
Line 1393... Line 1409...
1393
        DEBUGF  1, "Cannot find free command list entry\n"
1409
        DEBUGF  1, "Cannot find free command list entry\n"
1394
        mov     eax, -1
1410
        mov     eax, -1
1395
.ret:
1411
.ret:
1396
        pop     esi edx ecx ebx
1412
        pop     esi edx ecx ebx
1397
        ret
1413
        ret
-
 
1414
endp
Line 1398... Line 1415...
1398
 
1415
 
1399
 
1416
 
1400
proc _memset stdcall, dest:dword, val:byte, cnt:dword ; doesnt clobber any registers
1417
proc _memset stdcall, dest:dword, val:byte, cnt:dword ; doesnt clobber any registers