2
0
mirror of https://git.missingno.dev/kolibrios-nvme-driver/ synced 2024-11-09 18:10:33 +01:00

fix: allocate queues next to eachother

This commit is contained in:
Abdur-Rahman Mansoor 2024-08-05 16:17:54 -04:00
parent 8557d0a450
commit 3dbcfa5bad

View File

@ -730,14 +730,26 @@ proc nvme_init stdcall, pci:dword
xor ebx, ebx
.init_queues:
invoke KernelAlloc, PAGE_SIZE * 2
invoke AllocPages, 2
test eax, eax
jz .exit_fail
or eax, PG_SW+PG_NOCACHE
mov esi, eax
invoke KernelAlloc, 0x2000
test eax, eax
jz .exit_fail
mov dword [edi + ebx + NVM_QUEUE_ENTRY.sq_ptr], eax
add eax, PAGE_SIZE
mov dword [edi + ebx + NVM_QUEUE_ENTRY.cq_ptr], eax
sub eax, PAGE_SIZE
stdcall memsetdz, eax, PAGE_SIZE * 2 / 4
push ebx
mov ebx, eax
mov eax, esi
mov ecx, 2
invoke CommitPages
pop ebx
mov eax, dword [edi + ebx + NVM_QUEUE_ENTRY.cq_ptr]
mov edx, eax
add eax, 0x1000
mov dword [edi + ebx + NVM_QUEUE_ENTRY.sq_ptr], eax
stdcall memsetdz, edx, 0x2000 / 4
; Initialize command entries
invoke KernelAlloc, sizeof.NVMQCMD * CQ_ENTRIES
@ -749,10 +761,9 @@ proc nvme_init stdcall, pci:dword
xor ebx, ebx
.init_cmd_entries:
; BUG: Won't pop ecx if allocation fails
invoke KernelAlloc, sizeof.MUTEX
test eax, eax
jz .exit_fail
jz .exit_fail_cleanup
mov dword [esi + NVMQCMD.mutex_ptr], eax
mov dword [esi + NVMQCMD.cid], ebx
mov ecx, eax
@ -959,6 +970,9 @@ proc nvme_init stdcall, pci:dword
pop edi esi ebx
ret
.exit_fail_cleanup:
pop eax
.exit_fail:
mov esi, [pci]
DEBUGF DBG_INFO, "nvme%u: Failed to initialize controller\n", [esi + pcidev.num]