kolibri-ahci:

- added ahci_read_first_sector and it works
- temporariry removed ahci_read
- small changes

git-svn-id: svn://kolibrios.org@9141 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Rustem Gimadutdinov (rgimad) 2021-08-19 10:10:28 +00:00
parent 8dfac86e67
commit 6a6dcc90ae

View File

@ -322,7 +322,7 @@ ahci_callbacks:
dd 0 ; no close function dd 0 ; no close function
dd 0 ; no closemedia function dd 0 ; no closemedia function
dd ahci_querymedia dd ahci_querymedia
dd ahci_read dd 0;ahci_read
dd 0;ahci_write dd 0;ahci_write
dd 0 ; no flush function dd 0 ; no flush function
dd 0 ; use default cache size dd 0 ; use default cache size
@ -564,6 +564,8 @@ ahci_init:
cmp [ecx + PORT_DATA.drive_type], AHCI_DEV_SATA cmp [ecx + PORT_DATA.drive_type], AHCI_DEV_SATA
jne .after_add_disk ; skip adding disk code jne .after_add_disk ; skip adding disk code
; register disk in system: ; register disk in system:
stdcall ahci_read_first_sector, ecx
push ecx edx push ecx edx
mov eax, [hd_counter] mov eax, [hd_counter]
xor edx, edx xor edx, edx
@ -588,6 +590,7 @@ ahci_init:
test eax, eax test eax, eax
jz .disk_add_fail jz .disk_add_fail
stdcall disk_media_changed, eax, 1 ; system will scan for partitions on disk stdcall disk_media_changed, eax, 1 ; system will scan for partitions on disk
jmp .after_add_disk jmp .after_add_disk
.disk_add_fail: .disk_add_fail:
@ -738,45 +741,22 @@ proc ahci_querymedia stdcall, pdata, mediainfo
ret ret
endp endp
; Read sectors ;------------------------TEST-------------------------------
; return value: 0 = success, otherwise = error
proc ahci_read stdcall pdata: dword, buffer: dword, startsector: qword, numsectors_ptr:dword proc ahci_read_first_sector stdcall pdata: dword
locals locals
cmdslot dd ? cmdslot dd ?
cmdheader dd ? cmdheader dd ?
cmdtable dd ? cmdtable dd ?
numsectors dd ? buf_phys dd ?
buffer_pos dd ? buf_virt dd ?
buffer_length dd ? ;numsectors dd ?
endl endl
pushad pushad
mov ecx, ahci_mutex mov ecx, ahci_mutex
call mutex_lock call mutex_lock
; xor ecx, ecx
; mov esi, [buffer]
; .print_data:
; cmp ecx, 512
; jae .end_print_data
; mov al, byte [esi + ecx]
; mov byte [tmpstr], al
; mov byte [tmpstr + 1], 0
; DEBUGF 1, "0x%x(%s) ", al:1, tmpstr
; inc ecx
; jmp .print_data
; .end_print_data:
; DEBUGF 1, "\n"
mov eax, [numsectors_ptr]
mov eax, [eax]
mov [numsectors], eax
DEBUGF 1, " ahci_read: buffer = 0x%x, startsector = 0x%x:%x, numsectors = %u\n", [buffer], [startsector], [startsector + 4], eax
mov esi, [pdata] ; esi - address of PORT_DATA struct of port mov esi, [pdata] ; esi - address of PORT_DATA struct of port
mov edi, [esi + PORT_DATA.port] ; edi - address of HBA_PORT struct of port mov edi, [esi + PORT_DATA.port] ; edi - address of HBA_PORT struct of port
mov eax, edi mov eax, edi
@ -789,7 +769,7 @@ proc ahci_read stdcall pdata: dword, buffer: dword, startsector: qword, numsecto
.cmdslot_found: .cmdslot_found:
mov [cmdslot], eax mov [cmdslot], eax
; DEBUGF 1, "Found free cmdslot %u on port %u\n", [cmdslot], [esi + PORT_DATA.portno] DEBUGF 1, "Found free cmdslot %u on port %u\n", [cmdslot], [esi + PORT_DATA.portno]
shl eax, BSF sizeof.HBA_CMD_HDR shl eax, BSF sizeof.HBA_CMD_HDR
add eax, [esi + PORT_DATA.clb] add eax, [esi + PORT_DATA.clb]
@ -808,73 +788,26 @@ proc ahci_read stdcall pdata: dword, buffer: dword, startsector: qword, numsecto
btr bx, 2 ; flag C = 0 btr bx, 2 ; flag C = 0
mov [eax + HBA_CMD_HDR.flags2], bl mov [eax + HBA_CMD_HDR.flags2], bl
mov ebx, [numsectors] mov [eax + HBA_CMD_HDR.prdtl], 1
shl ebx, 9 ; *= 512
mov [buffer_length], ebx
dec ebx
shr ebx, 12 ; /= 4096
inc ebx
mov [eax + HBA_CMD_HDR.prdtl], bx
;DEBUGF 1, " prdtl = %u\n", [eax + HBA_CMD_HDR.prdtl]:2
; zero out the command table with its prdt entries ; zero out the command table
dec ebx stdcall _memset, [cmdtable], 0, sizeof.HBA_CMD_TBL
shl ebx, BSF sizeof.HBA_PRDT_ENTRY
add ebx, sizeof.HBA_CMD_TBL
stdcall _memset, [cmdtable], 0, ebx
DEBUGF 1, " prdtl = %u\n", [eax + HBA_CMD_HDR.prdtl]:2 DEBUGF 1, " prdtl = %u\n", [eax + HBA_CMD_HDR.prdtl]:2
;jmp .ret
xor ecx, ecx call alloc_page
movzx edx, [eax + HBA_CMD_HDR.prdtl] mov [buf_phys], eax
dec edx
mov eax, [buffer]
mov [buffer_pos], eax
.prdt_fill: stdcall map_io_mem, eax, 4096, PG_NOCACHE + PG_SWR ; map to virt memory so we can work with it
cmp ecx, edx mov [buf_virt], eax
jae .prdt_fill_end
mov ebx, [buffer_pos]
and ebx, 0xFFF
call get_pg_addr ; eax = phys addr
add eax, ebx
DEBUGF 1, " PHYS = 0x%x\n", eax
mov ebx, ecx
shl ebx, BSF sizeof.HBA_PRDT_ENTRY
add ebx, [cmdtable]
add ebx, HBA_CMD_TBL.prdt_entry ; now ebx - address of ecx'th prdt_entry
mov [ebx + HBA_PRDT_ENTRY.dba], eax mov eax, [cmdtable]
mov [ebx + HBA_PRDT_ENTRY.dbau], 0 mov ebx, [buf_phys]
and [ebx + HBA_PRDT_ENTRY.flags], not 0x3FFFFF ; zero out lower 22 bits, they used for byte count DEBUGF 1, "DBA = 0x%x\n", ebx
or [ebx + HBA_PRDT_ENTRY.flags], 4096 - 1 ; reason why -1 see in spec on this field mov [eax + HBA_CMD_TBL.prdt_entry + HBA_PRDT_ENTRY.dba], ebx
; or [eax + HBA_CMD_TBL.prdt_entry + HBA_PRDT_ENTRY.flags], 1 shl 31 ; enable interrupt on completion mov [eax + HBA_CMD_TBL.prdt_entry + HBA_PRDT_ENTRY.dbau], 0
and [eax + HBA_CMD_TBL.prdt_entry + HBA_PRDT_ENTRY.flags], not 0x3FFFFF ; zero out lower 22 bits, they used for byte count
add [buffer_pos], 4096 or [eax + HBA_CMD_TBL.prdt_entry + HBA_PRDT_ENTRY.flags], 512 - 1 ; reason why -1 see in spec on this field
sub [buffer_length], 4096
inc ecx
jmp .prdt_fill
.prdt_fill_end:
mov ebx, [buffer_pos]
and ebx, 0xFFF
call get_pg_addr ; eax = phys addr
add eax, ebx
DEBUGF 1, " PHYS. = 0x%x\n", eax
mov ebx, ecx
shl ebx, BSF sizeof.HBA_PRDT_ENTRY
add ebx, [cmdtable]
add ebx, HBA_CMD_TBL.prdt_entry ; now ebx - address of ecx'th prdt_entry
mov [ebx + HBA_PRDT_ENTRY.dba], eax
mov [ebx + HBA_PRDT_ENTRY.dbau], 0
and [ebx + HBA_PRDT_ENTRY.flags], not 0x3FFFFF ; zero out lower 22 bits, they used for byte count
mov eax, [buffer_length]
dec eax
DEBUGF 1, " DBC = %u\n", eax
or [ebx + HBA_PRDT_ENTRY.flags], eax ; reason why -1 see in spec on this field
; or [eax + HBA_CMD_TBL.prdt_entry + HBA_PRDT_ENTRY.flags], 1 shl 31 ; enable interrupt on completion ; or [eax + HBA_CMD_TBL.prdt_entry + HBA_PRDT_ENTRY.flags], 1 shl 31 ; enable interrupt on completion
mov eax, [cmdtable] mov eax, [cmdtable]
@ -885,24 +818,21 @@ proc ahci_read stdcall pdata: dword, buffer: dword, startsector: qword, numsecto
mov byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.command], ATA_CMD_READ_DMA_EX mov byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.command], ATA_CMD_READ_DMA_EX
mov ebx, dword [startsector] mov ebx, 0 ; start sector is 0
mov byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.lba0], bl mov byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.lba0], bl
shr ebx, 8
mov byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.lba1], bl mov byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.lba1], bl
shr ebx, 8
mov byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.lba2], bl mov byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.lba2], bl
mov byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.device], 1 shl 6 ; LBA mode mov byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.device], 1 shl 6 ; LBA mode
shr ebx, 8
mov byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.lba3], bl mov byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.lba3], bl
mov ebx, dword [startsector + 4]
mov byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.lba4], bl mov byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.lba4], bl
shr ebx, 8
mov byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.lba5], bl mov byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.lba5], bl
mov ebx, [numsectors] ; num sectors to read = 1
mov byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.countl], bl mov byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.countl], 1
shr ebx, 8 mov byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.counth], 0
mov byte [eax + HBA_CMD_TBL.cfis + FIS_REG_H2D.counth], bl
;mov eax, [cmdheader]
;DEBUGF 1, "PRDBC = %u\n", [eax + HBA_CMD_HDR.prdbc]
; Wait on previous command to complete, before issuing new command. ; Wait on previous command to complete, before issuing new command.
stdcall ahci_port_wait, edi, AHCI_PORT_TIMEOUT stdcall ahci_port_wait, edi, AHCI_PORT_TIMEOUT
@ -910,6 +840,8 @@ proc ahci_read stdcall pdata: dword, buffer: dword, startsector: qword, numsecto
mov eax, [cmdslot] mov eax, [cmdslot]
bts [edi + HBA_PORT.command_issue], eax ; Issue the command bts [edi + HBA_PORT.command_issue], eax ; Issue the command
; mov ebx, 20
; call delay_hs
; Wait for command completion ; Wait for command completion
stdcall ahci_port_cmd_wait, edi, eax;, AHCI_PORT_CMD_TIMEOUT stdcall ahci_port_cmd_wait, edi, eax;, AHCI_PORT_CMD_TIMEOUT
@ -917,16 +849,19 @@ proc ahci_read stdcall pdata: dword, buffer: dword, startsector: qword, numsecto
DEBUGF 1, "reading completed\n" DEBUGF 1, "reading completed\n"
;mov eax, [cmdheader]
;DEBUGF 1, "PRDBC = %u\n", [eax + HBA_CMD_HDR.prdbc]
xor ecx, ecx xor ecx, ecx
mov esi, [buffer] mov esi, [buf_virt]
.print_data: .print_data:
cmp ecx, 512 cmp ecx, 512
jae .end_print_data jae .end_print_data
mov al, byte [esi + ecx] mov al, byte [esi + ecx]
mov byte [tmpstr], al mov byte [tmpstr2], al
mov byte [tmpstr + 1], 0 mov byte [tmpstr2 + 1], 0
DEBUGF 1, "0x%x(%s) ", al:1, tmpstr DEBUGF 1, "0x%x(%s) ", al:2, tmpstr2
inc ecx inc ecx
jmp .print_data jmp .print_data
@ -941,7 +876,8 @@ proc ahci_read stdcall pdata: dword, buffer: dword, startsector: qword, numsecto
xor eax, eax xor eax, eax
ret ret
endp endp
tmpstr rb 16 tmpstr2 rb 16
;----------------------------------------------------------
; Start command engine ; Start command engine
; in: eax - address of HBA_PORT structure ; in: eax - address of HBA_PORT structure