2
0
mirror of https://git.missingno.dev/kolibrios-nvme-driver/ synced 2025-01-03 11:25:55 +01:00

chore: fix some bugs

This commit is contained in:
ramenu 2024-04-27 20:11:57 -04:00
parent 41f9a71103
commit 481fd087bd

View File

@ -36,9 +36,14 @@ proc START c, reason:dword
.entry: .entry:
DEBUGF DBG_INFO, "Detecting NVMe hardware...\n" DEBUGF DBG_INFO, "Detecting NVMe hardware...\n"
call detect_nvme call detect_nvme
test eax, eax
jz .err
mov eax, dword [p_nvme_devices] mov eax, dword [p_nvme_devices]
test eax, eax test eax, eax
jz .err ; no NVMe device found? jz .err
stdcall device_is_compat, dword [eax + pcidev.bus], dword [eax + pcidev.devfn]
test eax, eax
jz .err
mov eax, dword [eax] mov eax, dword [eax]
stdcall nvme_init, dword [eax + pcidev.bus], dword [eax + pcidev.devfn] stdcall nvme_init, dword [eax + pcidev.bus], dword [eax + pcidev.devfn]
@ -49,6 +54,7 @@ proc START c, reason:dword
ret ret
.err: .err:
DEBUGF DBG_INFO, "(NVMe): driver failed to initialize"
call nvme_cleanup call nvme_cleanup
xor eax, eax xor eax, eax
ret ret
@ -76,14 +82,14 @@ endp
proc memset stdcall, p_data:dword, val:byte, sz:dword proc memset stdcall, p_data:dword, val:byte, sz:dword
mov bh, byte [val] mov edx, [sz]
mov bh, [val]
xor ecx, ecx xor ecx, ecx
@@: @@:
mov byte [p_data + ecx], bh mov byte [p_data + ecx], bh
inc ecx inc ecx
cmp ecx, dword [sz] cmp ecx, edx
jne @b jne @b
xor eax, eax
ret ret
endp endp
@ -131,46 +137,46 @@ proc detect_nvme
mov eax, dword [eax + PCIDEV.fd] mov eax, dword [eax + PCIDEV.fd]
cmp eax, edx cmp eax, edx
jne .check_dev jne .check_dev
ret jmp .exit_success
.found_dev: .found_dev:
PDEBUGF DBG_INFO, "PCI(%u.%u.%u): Detected NVMe device...\n", [eax + PCIDEV.bus], byte [eax + PCIDEV.devfn] push edx eax
push eax PDEBUGF DBG_INFO, "PCI(%u.%u.%u): Detected NVMe device...\n", byte [eax + PCIDEV.bus], [eax + PCIDEV.devfn]
mov eax, dword [pcidevs_len] cmp dword [pcidevs_len], TOTAL_PCIDEVS
cmp eax, MAX_NVM_PCIDEVS
jne @f jne @f
pop eax pop eax edx
ret jmp .exit_success
@@: @@:
inc dword [pcidevs_len]
mov ebx, dword [p_nvme_devices] mov ebx, dword [p_nvme_devices]
test ebx, ebx test ebx, ebx
jnz @f jnz @f
invoke KernelAlloc, MAX_NVM_PCIDEVS_BYTES invoke KernelAlloc, TOTAL_PCIDEVS_MALLOC_SZ
test eax, eax test eax, eax
jz .err jz .err_no_mem
mov dword [ebx], eax mov dword [p_nvme_devices], eax
@@: @@:
mov ebx, dword [p_nvme_devices]
mov ecx, dword [pcidevs_len] mov ecx, dword [pcidevs_len]
inc ecx dec ecx
mov dword [pcidevs_len], ecx
invoke KernelAlloc, sizeof.pcidev
test eax, eax
jz .err
mov dword [p_nvme_devices + ecx * 4], eax
mov ebx, eax
pop eax pop eax
mov ecx, dword [eax + PCIDEV.bus] movzx edx, byte [eax + PCIDEV.bus]
mov dword [ebx + pcidev.bus], ecx mov byte [ebx + ecx * sizeof.pcidev + pcidev.bus], dl
mov ecx, dword [eax + PCIDEV.devfn] movzx edx, byte [eax + PCIDEV.devfn]
mov dword [ebx + pcidev.devfn], ecx mov byte [ebx + ecx * sizeof.pcidev + pcidev.devfn], dl
jmp .check_dev pop edx
jmp .next_dev
.err: .err_no_mem:
pop eax pop eax edx
PDEBUGF DBG_INFO, "PCI(%u.%u.%u): error initializing NVMe driver, unable to allocate memory\n", [eax + PCIDEV.bus], byte [eax + PCIDEV.devfn] xor eax, eax
ret
.exit_success:
xor eax, eax
inc eax
ret ret
endp endp
@ -186,9 +192,12 @@ proc device_is_compat, bus:dword, devfn:dword
test eax, eax test eax, eax
jz .exit_fail jz .exit_fail
mov [p_mmap], eax mov [p_mmap], eax
xor eax, eax
inc eax
ret
.exit_fail: .exit_fail:
PDEBUGF DBG_INFO, "PCI(%u.%u.%u): incompatible NVMe device\n", [bus], byte [devfn] PDEBUGF DBG_INFO, "PCI(%u.%u.%u): incompatible NVMe device\n", byte [bus], byte [devfn]
xor eax, eax xor eax, eax
ret ret
@ -201,10 +210,10 @@ proc nvme_init, bus:dword, devfn:dword
jz .exit_fail jz .exit_fail
mov eax, dword [p_mmap] mov eax, dword [p_mmap]
mov ebx, dword [eax + NVME_REG_MAP.CAP] mov ebx, dword [eax + NVME_REG_MAP.CAP]
PDEBUGF DBG_INFO, "PCI(%u.%u.%u): NVMe maximum queue entries supported: %u\n", [bus], byte [devfn], bx PDEBUGF DBG_INFO, "PCI(%u.%u.%u): NVMe maximum queue entries supported: %u\n", byte [bus], byte [devfn], bx
test ebx, CAP_CQR test ebx, CAP_CQR
jz .cqr_not_req jz .cqr_not_req
PDEBUGF DBG_INFO, "PCI(%u.%u.%u): NVMe contiguous queues required\n", [bus], byte [devfn] PDEBUGF DBG_INFO, "PCI(%u.%u.%u): NVMe contiguous queues required\n", byte [bus], byte [devfn]
.cqr_not_req: .cqr_not_req:
mov ebx, dword [eax + NVME_REG_MAP.CAP + 4] mov ebx, dword [eax + NVME_REG_MAP.CAP + 4]
@ -217,8 +226,8 @@ proc nvme_init, bus:dword, devfn:dword
and ecx, CAP_MPSMAX and ecx, CAP_MPSMAX
shr ebx, 16 shr ebx, 16
shr ecx, 16 shr ecx, 16
PDEBUGF DBG_INFO, "PCI(%u.%u.%u): NVMe memory page size minimum: %u\n", [bus], byte [devfn], ebx PDEBUGF DBG_INFO, "PCI(%u.%u.%u): NVMe memory page size minimum: %u\n", byte [bus], byte [devfn], ebx
PDEBUGF DBG_INFO, "PCI(%u.%u.%u): NVMe memory page size maximum: %u\n", [bus], byte [devfn], ecx PDEBUGF DBG_INFO, "PCI(%u.%u.%u): NVMe memory page size maximum: %u\n", byte [bus], byte [devfn], ecx
mov ebx, dword [eax + NVME_REG_MAP.CC] mov ebx, dword [eax + NVME_REG_MAP.CC]
mov ecx, ebx mov ecx, ebx
@ -228,8 +237,8 @@ proc nvme_init, bus:dword, devfn:dword
shl ecx, 16 shl ecx, 16
; TODO: Change entry sizes to their appropriate values ; TODO: Change entry sizes to their appropriate values
PDEBUGF DBG_INFO, "PCI(%u.%u.%u): NVMe I/O submission queue entry size: %u\n", [bus], byte [devfn], ebx PDEBUGF DBG_INFO, "PCI(%u.%u.%u): NVMe I/O submission queue entry size: %u\n", byte [bus], byte [devfn], ebx
PDEBUGF DBG_INFO, "PCI(%u.%u.%u): NVMe I/O completion queue entry size: %u\n", [bus], byte [devfn], ecx PDEBUGF DBG_INFO, "PCI(%u.%u.%u): NVMe I/O completion queue entry size: %u\n", byte [bus], byte [devfn], ecx
end if end if
xor eax, eax xor eax, eax
@ -237,7 +246,7 @@ proc nvme_init, bus:dword, devfn:dword
ret ret
.exit_fail: .exit_fail:
PDEBUGF DBG_INFO, "PCI(%u.%u.%u): failed to initialize NVMe controller\n", [bus], byte [devfn] PDEBUGF DBG_INFO, "PCI(%u.%u.%u): failed to initialize NVMe controller\n", byte [bus], byte [devfn]
xor eax, eax xor eax, eax
ret ret
@ -246,23 +255,8 @@ endp
proc nvme_cleanup proc nvme_cleanup
DEBUGF DBG_INFO, "(NVMe): Cleaning up...\n" DEBUGF DBG_INFO, "(NVMe): Cleaning up...\n"
xor ecx, ecx invoke KernelFree, [p_nvme_devices]
mov eax, dword [p_nvme_devices] invoke KernelFree, [p_ident]
test eax, eax
jz .last
@@:
mov ebx, dword [eax + ecx * 4]
invoke KernelFree, ebx
inc ecx
cmp ecx, dword [pcidevs_len]
jl @b
mov eax, dword [p_ident]
test eax, eax
jz .last
invoke KernelFree, eax
.last:
ret ret
endp endp