mirror of
https://git.missingno.dev/kolibrios-nvme-driver/
synced 2024-12-23 06:18:47 +01:00
fix more stuff
This commit is contained in:
parent
7181653389
commit
becabd38b5
@ -75,6 +75,7 @@ proc START c, reason:dword
|
|||||||
stdcall add_nvme_disk, [p_nvme_devices]
|
stdcall add_nvme_disk, [p_nvme_devices]
|
||||||
test eax, eax
|
test eax, eax
|
||||||
jz .err
|
jz .err
|
||||||
|
|
||||||
invoke RegService, my_service, service_proc
|
invoke RegService, my_service, service_proc
|
||||||
ret
|
ret
|
||||||
|
|
||||||
@ -119,6 +120,7 @@ proc add_nvme_disk stdcall, pci:dword
|
|||||||
add esp, 20
|
add esp, 20
|
||||||
test eax, eax
|
test eax, eax
|
||||||
jz @f
|
jz @f
|
||||||
|
invoke DiskMediaChanged, eax, 1
|
||||||
DEBUGF DBG_INFO, "nvme%u: Successfully registered disk\n", [esi + pcidev.num]
|
DEBUGF DBG_INFO, "nvme%u: Successfully registered disk\n", [esi + pcidev.num]
|
||||||
xor eax, eax
|
xor eax, eax
|
||||||
inc eax
|
inc eax
|
||||||
@ -454,27 +456,20 @@ endp
|
|||||||
|
|
||||||
proc free_prp_list stdcall, prp_list_ptr:dword, nprps:dword
|
proc free_prp_list stdcall, prp_list_ptr:dword, nprps:dword
|
||||||
|
|
||||||
push edi
|
push edi esi ebx
|
||||||
mov edi, [prp_list_ptr]
|
mov esi, [prp_list_ptr]
|
||||||
mov ecx, [nprps]
|
invoke KernelAlloc, PAGE_SIZE
|
||||||
cmp ecx, PAGE_SIZE / 8 - 1
|
test eax, eax
|
||||||
jbe @f
|
jz .exit
|
||||||
mov eax, dword [edi + PAGE_SIZE - 8]
|
mov edi, eax
|
||||||
sub ecx, PAGE_SIZE / 8 - 1
|
invoke MapPage, edi, esi, PG_SW+PG_NOCACHE
|
||||||
stdcall free_prp_list, eax, ecx, TRUE
|
mov ebx, dword [edi + PAGE_SIZE / 8]
|
||||||
|
invoke FreePage, esi
|
||||||
@@:
|
sub [nprps], PAGE_SIZE / 8
|
||||||
cmp [recursive], 0
|
|
||||||
jz @f
|
|
||||||
invoke FreePage, edi
|
|
||||||
jmp .exit
|
|
||||||
|
|
||||||
@@:
|
|
||||||
invoke KernelFree, edi
|
|
||||||
|
|
||||||
.exit:
|
.exit:
|
||||||
xor eax, eax
|
xor eax, eax
|
||||||
pop edi
|
pop ebx esi edi
|
||||||
ret
|
ret
|
||||||
|
|
||||||
endp
|
endp
|
||||||
@ -546,6 +541,7 @@ proc build_prp_list stdcall, nprps:dword
|
|||||||
.loop:
|
.loop:
|
||||||
mov dword [edi + ecx * 4], esi
|
mov dword [edi + ecx * 4], esi
|
||||||
mov dword [edi + ecx * 4 + 4], 0
|
mov dword [edi + ecx * 4 + 4], 0
|
||||||
|
DEBUGF DBG_INFO, "PRP: %x\n", esi
|
||||||
add esi, PAGE_SIZE
|
add esi, PAGE_SIZE
|
||||||
inc ecx
|
inc ecx
|
||||||
cmp ecx, ebx
|
cmp ecx, ebx
|
||||||
@ -583,7 +579,7 @@ proc build_prp_list stdcall, nprps:dword
|
|||||||
|
|
||||||
endp
|
endp
|
||||||
|
|
||||||
proc alloc_dptr stdcall, ns:dword, prps_ptr:dword, numsectors:dword
|
proc alloc_dptr stdcall, ns:dword, prps_ptr:dword, numsectors:dword, nprps_ptr:dword
|
||||||
|
|
||||||
push esi edi
|
push esi edi
|
||||||
mov edi, [prps_ptr]
|
mov edi, [prps_ptr]
|
||||||
@ -605,7 +601,7 @@ proc alloc_dptr stdcall, ns:dword, prps_ptr:dword, numsectors:dword
|
|||||||
; is the number of sectors greater than to two memory pages?
|
; is the number of sectors greater than to two memory pages?
|
||||||
shl eax, 1
|
shl eax, 1
|
||||||
cmp edx, eax
|
cmp edx, eax
|
||||||
jae @f
|
jae .build_prp_list
|
||||||
|
|
||||||
; allocate a single PRP entry for PRP2
|
; allocate a single PRP entry for PRP2
|
||||||
invoke AllocPage
|
invoke AllocPage
|
||||||
@ -614,22 +610,28 @@ proc alloc_dptr stdcall, ns:dword, prps_ptr:dword, numsectors:dword
|
|||||||
mov dword [edi + 4], eax
|
mov dword [edi + 4], eax
|
||||||
jmp .success
|
jmp .success
|
||||||
|
|
||||||
@@:
|
.build_prp_list:
|
||||||
|
DEBUGF DBG_INFO, "Allocating PRP list\n"
|
||||||
; allocate PRP list for PRP2
|
; allocate PRP list for PRP2
|
||||||
shr eax, 1
|
mov eax, [numsectors]
|
||||||
mov ecx, [numsectors]
|
mov ecx, dword [esi + NSINFO.pg_sectors]
|
||||||
xchg eax, ecx
|
|
||||||
xor edx, edx
|
xor edx, edx
|
||||||
div ecx
|
div ecx
|
||||||
|
test edx, edx
|
||||||
|
jz @f
|
||||||
|
inc eax
|
||||||
|
|
||||||
|
@@:
|
||||||
|
mov esi, [nprps_ptr]
|
||||||
|
dec eax
|
||||||
|
mov dword [esi], eax
|
||||||
stdcall build_prp_list, eax
|
stdcall build_prp_list, eax
|
||||||
test eax, eax
|
test eax, eax
|
||||||
jz .free_prp_list
|
jz .err
|
||||||
|
DEBUGF DBG_INFO, "Successfully allocated PRP list at: %x\n", eax
|
||||||
mov dword [edi + 4], eax
|
mov dword [edi + 4], eax
|
||||||
jmp .success
|
jmp .success
|
||||||
|
|
||||||
.free_prp_list:
|
|
||||||
stdcall free_prp_list, edi, eax, FALSE
|
|
||||||
|
|
||||||
.err:
|
.err:
|
||||||
mov eax, dword [edi]
|
mov eax, dword [edi]
|
||||||
test eax, eax
|
test eax, eax
|
||||||
@ -759,23 +761,27 @@ nvme_write:
|
|||||||
proc nvme_readwrite stdcall, ns:dword, buf:dword, start_sector:qword, numsectors_ptr:dword
|
proc nvme_readwrite stdcall, ns:dword, buf:dword, start_sector:qword, numsectors_ptr:dword
|
||||||
|
|
||||||
push ebx esi edi
|
push ebx esi edi
|
||||||
sub esp, 16
|
sub esp, 20
|
||||||
mov ebx, esp
|
mov ebx, esp
|
||||||
mov eax, [numsectors_ptr]
|
mov eax, [numsectors_ptr]
|
||||||
mov eax, dword [eax]
|
mov eax, dword [eax]
|
||||||
|
DEBUGF DBG_INFO, "buf: %x, start_sector: %x%x\n, numsectors: %u", [buf], [start_sector + 4], [start_sector], eax
|
||||||
mov dword [ebx + 8], edx ; command type (read or write)
|
mov dword [ebx + 8], edx ; command type (read or write)
|
||||||
mov dword [ebx + 12], eax ; save original numsectors value
|
mov dword [ebx + 12], eax ; save original numsectors value
|
||||||
|
mov dword [ebx + 16], 0 ; nPRPs for PRP list
|
||||||
mov esi, [ns]
|
mov esi, [ns]
|
||||||
mov edi, [buf]
|
mov edi, [buf]
|
||||||
|
|
||||||
mov edx, [numsectors_ptr]
|
mov edx, [numsectors_ptr]
|
||||||
mov edx, [edx]
|
mov edx, [edx]
|
||||||
|
mov ecx, ebx
|
||||||
|
add ecx, 16
|
||||||
; Note that [esp] will contain the value of PRP1 and [esp + 4] will
|
; Note that [esp] will contain the value of PRP1 and [esp + 4] will
|
||||||
; contain the value of PRP2 (after this call, if it completes successfully)
|
; contain the value of PRP2 (after this call, if it completes successfully)
|
||||||
stdcall alloc_dptr, esi, ebx, edx
|
stdcall alloc_dptr, esi, ebx, edx, ecx
|
||||||
test eax, eax
|
test eax, eax
|
||||||
jz .dptr_fail
|
jz .dptr_fail
|
||||||
DEBUGF DBG_INFO, "PRP1: %x, PRP2: %x\n", [ebx], [ebx + 4]
|
DEBUGF DBG_INFO, "PRP1: %x, PRP2: %x, nPRPs for PRP list: %u\n", [ebx], [ebx + 4], [ebx + 16]
|
||||||
stdcall nvme_io_rw, [esi + NSINFO.pci], \
|
stdcall nvme_io_rw, [esi + NSINFO.pci], \
|
||||||
1, \
|
1, \
|
||||||
[esi + NSINFO.nsid], \
|
[esi + NSINFO.nsid], \
|
||||||
@ -819,14 +825,8 @@ proc nvme_readwrite stdcall, ns:dword, buf:dword, start_sector:qword, numsectors
|
|||||||
jmp .end
|
jmp .end
|
||||||
|
|
||||||
.is_prp_list:
|
.is_prp_list:
|
||||||
; TODO: Fix this
|
stdcall write_prp_list_buf, dword [ebx + 4], [buf], [ebx + 16]
|
||||||
mov eax, ebx
|
;stdcall free_prp_list, dword [ebx + 4], ebx
|
||||||
xor edx, edx
|
|
||||||
mov ecx, dword [esi + NSINFO.lbads]
|
|
||||||
div ecx
|
|
||||||
mov ebx, eax
|
|
||||||
stdcall write_prp_list_buf, dword [ebx + 4], [buf], ebx
|
|
||||||
stdcall free_prp_list, dword [ebx + 4], ebx, FALSE
|
|
||||||
jmp .end
|
jmp .end
|
||||||
|
|
||||||
.dptr_fail:
|
.dptr_fail:
|
||||||
@ -834,7 +834,7 @@ proc nvme_readwrite stdcall, ns:dword, buf:dword, start_sector:qword, numsectors
|
|||||||
mov dword [ebx], 0
|
mov dword [ebx], 0
|
||||||
|
|
||||||
.end:
|
.end:
|
||||||
add esp, 16
|
add esp, 20
|
||||||
pop edi esi ebx
|
pop edi esi ebx
|
||||||
ret
|
ret
|
||||||
|
|
||||||
@ -1225,6 +1225,7 @@ proc nvme_init stdcall, pci:dword
|
|||||||
div ecx
|
div ecx
|
||||||
mov dword [ebx + NSINFO.pg_sectors], eax
|
mov dword [ebx + NSINFO.pg_sectors], eax
|
||||||
invoke KernelFree, edi
|
invoke KernelFree, edi
|
||||||
|
if 0
|
||||||
invoke KernelAlloc, 0x1000
|
invoke KernelAlloc, 0x1000
|
||||||
test eax, eax
|
test eax, eax
|
||||||
jz .exit_fail
|
jz .exit_fail
|
||||||
@ -1233,11 +1234,12 @@ proc nvme_init stdcall, pci:dword
|
|||||||
test eax, eax
|
test eax, eax
|
||||||
jz .exit_fail
|
jz .exit_fail
|
||||||
mov edx, NVM_CMD_READ
|
mov edx, NVM_CMD_READ
|
||||||
mov dword [eax], 0x9
|
mov dword [eax], 0x11
|
||||||
stdcall nvme_readwrite, [esi + pcidev.nsinfo], edi, 0, 0, eax
|
stdcall nvme_readwrite, [esi + pcidev.nsinfo], edi, 0, 0, eax
|
||||||
test eax, eax
|
test eax, eax
|
||||||
jz .exit_fail
|
jz .exit_fail
|
||||||
DEBUGF DBG_INFO, "%s\n", edi
|
DEBUGF DBG_INFO, "%s\n", edi
|
||||||
|
end if
|
||||||
DEBUGF DBG_INFO, "nvme%u: Successfully initialized driver\n", [esi + pcidev.num]
|
DEBUGF DBG_INFO, "nvme%u: Successfully initialized driver\n", [esi + pcidev.num]
|
||||||
xor eax, eax
|
xor eax, eax
|
||||||
inc eax
|
inc eax
|
||||||
@ -1583,7 +1585,7 @@ align 4
|
|||||||
dd 0 ; no close function
|
dd 0 ; no close function
|
||||||
dd 0 ; no closemedia function
|
dd 0 ; no closemedia function
|
||||||
dd nvme_query_media
|
dd nvme_query_media
|
||||||
dd 0 ; no read function (for now)
|
dd nvme_read
|
||||||
dd 0 ; no write function (for now)
|
dd 0 ; no write function (for now)
|
||||||
dd 0 ; no flush function
|
dd 0 ; no flush function
|
||||||
dd 0 ; use default cache size
|
dd 0 ; use default cache size
|
||||||
|
Loading…
Reference in New Issue
Block a user