mirror of
https://git.missingno.dev/kolibrios-nvme-driver/
synced 2026-03-09 12:53:24 +00:00
feat: implement determine_active_nsids
This commit is contained in:
@@ -165,6 +165,72 @@ proc create_namespace stdcall, pci:dword, cid:word
|
||||
|
||||
endp
|
||||
|
||||
; See page 248 of the NVMe 1.4 specification for reference
|
||||
proc determine_active_nsids stdcall, pci:dword
|
||||
|
||||
push esi edi ebx
|
||||
xor esi, esi
|
||||
xor edi, edi
|
||||
invoke KernelAlloc, 0x1000
|
||||
test eax, eax
|
||||
jz .fail
|
||||
mov esi, eax
|
||||
invoke GetPhysAddr
|
||||
stdcall nvme_identify, [pci], 0, eax, CNS_IDCS
|
||||
mov eax, dword [esi + IDENTC.nn]
|
||||
test eax, eax
|
||||
jz .fail
|
||||
invoke KernelAlloc, 0x1000
|
||||
test eax, eax
|
||||
jz .fail
|
||||
mov edi, eax
|
||||
invoke GetPhysAddr
|
||||
mov ebx, eax
|
||||
xor ecx, ecx
|
||||
|
||||
.loop:
|
||||
cmp ecx, dword [esi + IDENTC.nn]
|
||||
jg .success
|
||||
stdcall nvme_identify, [pci], ecx, ebx, CNS_IDNS
|
||||
push ecx
|
||||
xor ecx, ecx
|
||||
|
||||
.inner_loop:
|
||||
mov eax, dword [edi + ecx * 4]
|
||||
test eax, eax
|
||||
jnz .is_active_nsid
|
||||
inc ecx
|
||||
cmp ecx, 0x1000 / 4
|
||||
jne .inner_loop
|
||||
pop ecx
|
||||
inc ecx
|
||||
jmp .loop
|
||||
|
||||
.is_active_nsid:
|
||||
pop ecx ; pop active NSID value into ecx
|
||||
mov eax, [pci]
|
||||
mov eax, dword [eax + pcidev.nsids]
|
||||
mov dword [eax + ecx * 4], ecx
|
||||
inc ecx
|
||||
jmp .loop
|
||||
|
||||
.fail:
|
||||
invoke KernelFree, esi ; assumes KernelFree can check if its nullptr (hopefully)
|
||||
invoke KernelFree, edi
|
||||
pop ebx edi esi
|
||||
xor eax, eax
|
||||
ret
|
||||
|
||||
.success:
|
||||
invoke KernelFree, esi
|
||||
invoke KernelFree, edi
|
||||
pop ebx edi esi
|
||||
xor eax, eax
|
||||
inc eax
|
||||
ret
|
||||
|
||||
endp
|
||||
|
||||
; See page 101 of the NVMe 1.4 specification for reference
|
||||
proc create_io_completion_queue stdcall, pci:dword, prp1:dword, qid:dword, ien:byte
|
||||
|
||||
|
||||
Reference in New Issue
Block a user