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:
parent
1c69e25c2b
commit
0b16efacd3
@ -165,73 +165,81 @@ 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
|
||||
proc is_active_namespace stdcall, pci:dword, nsid:dword
|
||||
|
||||
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
|
||||
|
||||
.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
|
||||
jne @b
|
||||
|
||||
.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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user