2
0
mirror of https://git.missingno.dev/kolibrios-nvme-driver/ synced 2024-12-22 22:08:47 +01:00

fix fatal bugs in write_admin_cmd and dont handle IRQs if they dont belong to the NVMe device

This commit is contained in:
Abdur-Rahman Mansoor 2024-06-20 15:55:32 -04:00
parent b0f9e47c9b
commit 2f07187623
2 changed files with 22 additions and 8 deletions

View File

@ -730,21 +730,19 @@ proc write_admin_cmd stdcall, pci:dword, cmd:dword
lea edi, [edi + ecx]
stdcall memcpy, edi, esi, sizeof.SQ_ENTRY
mov esi, dword [edi + pcidev.sq_ptr]
mov esi, dword [esi + pcidev.queue_entries]
mov edi, esi
mov ax, word [esi + NVM_QUEUE_ENTRY.tail]
mov edi, [pci]
mov esi, dword [edi + pcidev.io_addr]
mov edi, dword [edi + pcidev.queue_entries]
mov ax, word [edi + NVM_QUEUE_ENTRY.tail]
cmp ax, NVM_ASQS
jl @f
xor ax, ax
@@:
mov esi, [pci]
mov esi, dword [esi + pcidev.io_addr]
inc ax
DEBUGF DBG_INFO, "(NVMe) Writing to Admin Submission Queue: %u\n", ax
mov word [esi + 0x1000], ax
mov word [edi + NVM_QUEUE_ENTRY.tail], ax
mov word [esi + 0x1000], ax
pop edi esi
ret
@ -789,11 +787,21 @@ proc irq_handler
push esi edi
mov esi, dword [p_nvme_devices]
; check if the NVMe device generated an interrupt
invoke PciRead16, dword [esi + pcidev.bus], dword [esi + pcidev.devfn], PCI_header00.status
test al, 1000b ; check interrupt status
jz .not_our_irq
mov edi, esi
mov edi, dword [edi + pcidev.io_addr]
mov dword [edi + NVME_MMIO.INTMS], 0x1
mov esi, dword [esi + pcidev.queue_entries]
movzx ecx, word [esi + NVM_QUEUE_ENTRY.head]
mov dx, word [esi + NVM_QUEUE_ENTRY.tail]
DEBUGF DBG_INFO, "IRQ (head): 0x%x, (tail): 0x%x\n", cx, dx
cmp cx, dx
je .end
mov edx, ecx
imul edx, sizeof.CQ_ENTRY
mov esi, dword [p_nvme_devices]
@ -831,6 +839,12 @@ proc irq_handler
pop edi esi
ret
.not_our_irq:
; Interrupt not handled by driver, return 0
xor eax, eax
pop edi esi
ret
endp
proc nvme_cleanup

View File

@ -18,7 +18,7 @@ VS140 = 0x00010400 ; (v1.4.0)
NVM_CMDS = 64 ; Number of Commands
NVM_MPS = 0 ; Memory Page Size (2 ^ (12 + MPS))
NVM_ASQS = 4 ; Admin Submission Queue Size
NVM_ASQS = 8 ; Admin Submission Queue Size
NVM_ACQS = NVM_ASQS ; Admin Completion Queue Size
ADMIN_QUEUE = 0 ; Admin Queue ID