2
0
mirror of https://git.missingno.dev/kolibrios-nvme-driver/ synced 2025-01-03 19:35:56 +01:00

separate determine_active_nsids and is_active_namespace

This commit is contained in:
Abdur-Rahman Mansoor 2024-06-22 15:18:43 -04:00
parent 1c69e25c2b
commit 0b16efacd3

View File

@ -165,76 +165,84 @@ 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
proc is_active_namespace stdcall, pci:dword, nsid:dword
push esi edi ebx
xor esi, esi
xor edi, edi
push esi edi
invoke KernelAlloc, 0x1000
test eax, eax
jz .fail
jnz @f
pop edi esi
ret
@@:
mov esi, eax
invoke GetPhysAddr
stdcall nvme_identify, [pci], 0, eax, CNS_IDCS
mov eax, dword [esi + IDENTC.nn]
mov edx, [pci]
mov dword [edx + pcidev.nn], eax
test eax, eax
jz .fail
invoke KernelAlloc, 0x1000
test eax, eax
jz .fail
mov edi, eax
invoke GetPhysAddr
mov ebx, eax
stdcall nvme_identify, [pci], [nsid], eax, CNS_IDNS
xor ecx, ecx
.loop:
cmp ecx, dword [esi + IDENTC.nn]
jg .success
stdcall nvme_identify, [pci], ecx, ebx, CNS_IDNS ; identify N'th namespace
push ecx
xor ecx, ecx
; We want to check if entire struct is zeroed out, if so, it is not an active NSID,
; otherwise it is
.inner_loop:
mov eax, dword [edi + ecx * 4]
@@:
mov eax, dword [esi + ecx * 4]
test eax, eax
jnz .is_active_nsid
inc ecx
cmp ecx, 0x1000 / 4
jne .inner_loop
pop ecx
inc ecx
jmp .loop
jne @b
.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
.not_active_nsid:
invoke KernelFree, esi
pop edi esi
xor eax, eax
ret
.success:
.is_active_nsid:
invoke KernelFree, esi
invoke KernelFree, edi
pop ebx edi esi
pop edi esi
xor eax, eax
inc eax
ret
endp
; See page 248 of the NVMe 1.4 specification for reference
proc determine_active_nsids stdcall, pci:dword
push esi edi
invoke KernelAlloc, 0x1000
test eax, eax
jnz @f
pop edi esi
ret
@@:
mov esi, eax
invoke GetPhysAddr
stdcall nvme_identify, [pci], 0, eax, CNS_IDCS
mov edi, [pci]
mov eax, dword [esi + IDENTC.nn]
mov dword [edi + pcidev.nn], eax
mov edi, [edi + pcidev.nsids]
xor ecx, ecx
.loop:
cmp ecx, dword [esi + IDENTC.nn]
je .ret
stdcall is_active_namespace, [pci], ecx
test eax, eax
jz .not_active_namespace
mov dword [edi + ecx * 4], ecx
.not_active_namespace:
inc ecx
jmp .loop
.ret:
invoke KernelFree, esi
pop edi esi
xor eax, 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