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

more fixes

This commit is contained in:
Abdur-Rahman Mansoor 2024-06-27 17:10:25 -04:00
parent 34ff6d786e
commit 1f4b25a309

View File

@ -445,26 +445,26 @@ proc get_log_page stdcall, pci:dword, dptr:dword, lid:byte
endp endp
; See page 269-271 of the NVMe 1.4 specification for reference ; See page 269-271 of the NVMe 1.4 specification for reference
proc nvme_write stdcall, pci:dword, qid:word, slba:qword, nlb:dword, dsm:byte proc nvme_write stdcall, pci:dword, qid:word, dptr:dword, slba:qword, nlb:word
; TODO: Use IDENTC.NOIOB to construct read/write commands that don't ; TODO: Use IDENTC.NOIOB to construct read/write commands that don't
; cross the I/O boundary to achieve optimal performance ; cross the I/O boundary to achieve optimal performance
; Also add DPTR/MPTR ; Also add DPTR/MPTR
sub esp, sizeof.SQ_ENTRY sub esp, sizeof.SQ_ENTRY
stdcall memset, esp, 0 sizeof.SQ_ENTRY stdcall memset, esp, 0, sizeof.SQ_ENTRY
stdcall set_cdw0, [pci], [qid], NVM_CMD_WRITE movzx ecx, [qid]
stdcall set_cdw0, [pci], ecx, NVM_CMD_WRITE
mov dword [esp + SQ_ENTRY.cdw0], eax ; CDW0 mov dword [esp + SQ_ENTRY.cdw0], eax ; CDW0
mov eax, [dptr]
; Starting LBA (SLBA) mov dword [esp + SQ_ENTRY.dptr], eax
mov eax, dword [slba] mov eax, dword [slba]
mov dword [esp + SQ_ENTRY.cdw10], eax mov dword [esp + SQ_ENTRY.cdw10], eax
mov eax, dword [slba + 4] mov eax, dword [slba + 4]
mov dword [esp + SQ_ENTRY.cdw11], eax mov dword [esp + SQ_ENTRY.cdw11], eax
mov ax, [nlb] movzx eax, [nlb]
mov word [esp + SQ_ENTRY.cdw12], ax mov word [esp + SQ_ENTRY.cdw12], ax
mov al, [dsm] movzx ecx, [qid]
mov byte [esp + SQ_ENTRY.cdw13], al stdcall sqytdbl_write, [pci], ecx, esp
stdcall sqytdbl_write, [pci], [qid], esp
add esp, sizeof.SQ_ENTRY add esp, sizeof.SQ_ENTRY
ret ret
@ -819,6 +819,8 @@ proc nvme_init stdcall, pci:dword
DEBUGF DBG_INFO, "nvme%un%u: Namespace LBA Data Size: %u\n", [esi + pcidev.num], [esi + pcidev.nsid], eax DEBUGF DBG_INFO, "nvme%un%u: Namespace LBA Data Size: %u\n", [esi + pcidev.num], [esi + pcidev.nsid], eax
invoke KernelFree, edi invoke KernelFree, edi
mov eax, test_string
stdcall nvme_write, [pci], 1, eax, 0, 1
DEBUGF DBG_INFO, "nvme%u: Successfully initialized driver\n", [esi + pcidev.num] DEBUGF DBG_INFO, "nvme%u: Successfully initialized driver\n", [esi + pcidev.num]
xor eax, eax xor eax, eax
inc eax inc eax
@ -948,7 +950,9 @@ proc sqytdbl_write stdcall, pci:dword, y:word, cmd:dword
mov edi, [pci] mov edi, [pci]
mov esi, dword [edi + pcidev.io_addr] mov esi, dword [edi + pcidev.io_addr]
mov edi, dword [edi + pcidev.queue_entries] mov edi, dword [edi + pcidev.queue_entries]
movzx eax, word [edi + NVM_QUEUE_ENTRY.tail] movzx ecx, [y]
imul ecx, sizeof.NVM_QUEUE_ENTRY
movzx eax, word [edi + ecx + NVM_QUEUE_ENTRY.tail]
cmp ax, NVM_ASQS cmp ax, NVM_ASQS
jl @f jl @f
xor ax, ax xor ax, ax
@ -956,19 +960,19 @@ proc sqytdbl_write stdcall, pci:dword, y:word, cmd:dword
@@: @@:
mov esi, [pci] mov esi, [pci]
inc ax inc ax
; 1000h + ((2y + 1) * (4 << CAP.DSTRD)) ; 1000h + (2y * (4 << CAP.DSTRD))
movzx ebx, [y] movzx ebx, [y]
shl bl, 1 shl ebx, 1
mov edx, 4 mov edx, 4
mov cl, byte [esi + pcidev.dstrd] mov cl, byte [esi + pcidev.dstrd]
shl dx, cl shl edx, cl
imul dx, bx imul edx, ebx
add dx, 0x1000 add edx, 0x1000
;DEBUGF DBG_INFO, "(NVMe) Writing to submission queue doorbell register 0x%x: %u\n", dx, ax
mov esi, dword [esi + pcidev.io_addr] mov esi, dword [esi + pcidev.io_addr]
mov word [esi + edx], ax mov word [esi + edx], ax
movzx ecx, [y] movzx ecx, [y]
mov word [edi + NVM_QUEUE_ENTRY.tail], ax imul ecx, sizeof.NVM_QUEUE_ENTRY
mov word [edi + ecx + NVM_QUEUE_ENTRY.tail], ax
dec ax dec ax
stdcall nvme_cmd_wait, [pci], ecx, eax stdcall nvme_cmd_wait, [pci], ecx, eax
pop edi esi ebx pop edi esi ebx
@ -1109,7 +1113,7 @@ proc irq_handler
pop ecx pop ecx
inc ecx inc ecx
cmp ecx, LAST_QUEUE_ID cmp ecx, LAST_QUEUE_ID
jne @b jng @b
; Interrupt handled by driver, return 1 ; Interrupt handled by driver, return 1
mov dword [edi + NVME_MMIO.INTMC], 0x3 mov dword [edi + NVME_MMIO.INTMC], 0x3
@ -1163,6 +1167,7 @@ align 4
dd 0 ; use default cache size dd 0 ; use default cache size
.end: .end:
if __DEBUG__ if __DEBUG__
test_string db "NVMe driver successfully wrote to disk! :D",0
include_debug_strings include_debug_strings
end if end if