From 7393da0eb5183033e9cdaed66a90a32a8513267e Mon Sep 17 00:00:00 2001 From: Abdur-Rahman Mansoor Date: Mon, 3 Jun 2024 12:02:36 -0400 Subject: [PATCH] wip: submit command support --- drivers/nvme/nvme.asm | 63 ++++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 25 deletions(-) diff --git a/drivers/nvme/nvme.asm b/drivers/nvme/nvme.asm index 79dd0c3..f253cb2 100644 --- a/drivers/nvme/nvme.asm +++ b/drivers/nvme/nvme.asm @@ -101,8 +101,8 @@ proc memset stdcall, p_data:dword, val:byte, sz:dword endp -; Submit a Command in the Admin Submission Queue -proc submit_asq stdcall, sq_ptr:dword +; Submit a Administrator Command in the Submission Queue +proc submit_admin_cmd stdcall, sq_ptr:dword, slot:dword mov esi, [sq_ptr] xor eax, eax @@ -110,24 +110,25 @@ proc submit_asq stdcall, sq_ptr:dword endp -proc nvme_identify stdcall, nsid:dword, dptr:dword, cid:word, cns:byte - - sub esp, sizeof.SQ_ENTRY - stdcall memset, esp, 0, sizeof.SQ_ENTRY +proc nvme_identify stdcall, pci:dword, slot:dword, nsid:dword, dptr:dword, cid:word, cns:byte + push esi + mov esi, [pci] + mov esi, [esi + pcidev.sq_ptr] + mov eax, [slot] + imul eax, sizeof.SQ_ENTRY + add esi, eax mov eax, [nsid] - mov dword [esp + SQ_ENTRY.nsid], eax + mov dword [esi + SQ_ENTRY.nsid], eax mov eax, [dptr] - mov dword [esp + SQ_ENTRY.dptr], eax + mov dword [esi + SQ_ENTRY.dptr], eax movzx eax, [cid] - or dword [esp + SQ_ENTRY.cdw0], ADM_CMD_IDENTIFY - or dword [esp + SQ_ENTRY.cdw0], eax + or dword [esi + SQ_ENTRY.cdw0], ADM_CMD_IDENTIFY + or dword [esi + SQ_ENTRY.cdw0], eax mov al, [cns] - mov byte [esp + SQ_ENTRY.cdw10], al - stdcall submit_asq, esp - - add esp, sizeof.SQ_ENTRY - xor eax, eax + mov byte [esi + SQ_ENTRY.cdw10], al + stdcall sqytdbl_write, [pci], 0, 0 + pop esi ret endp @@ -202,10 +203,8 @@ proc device_is_compat stdcall, pci:dword test eax, eax jz .failure mov byte [esi + pcidev.ipin], al - DEBUGF DBG_INFO, "(NVMe) pcidev.ipin = %u\n", al invoke PciRead8, dword [esi + pcidev.bus], dword [esi + pcidev.devfn], PCI_header00.interrupt_line mov byte [esi + pcidev.iline], al - DEBUGF DBG_INFO, "(NVMe) pcidev.iline = %u\n", al invoke PciRead32, dword [esi + pcidev.bus], dword [esi + pcidev.devfn], PCI_header00.base_addr_0 and eax, 0xfffffff0 test eax, eax @@ -345,8 +344,8 @@ proc nvme_init stdcall, pci:dword invoke AllocPage test eax, eax jz .exit_fail - ; nsid:dword, dptr:dword, cid:word, cns:byte - stdcall nvme_identify, 0, eax, 0, CNS_IDCS + ; pci:dword, nsid:dword, dptr:dword, cid:word, cns:byte + stdcall nvme_identify, [pci], 0, eax, 0, CNS_IDCS xor eax, eax inc eax @@ -427,15 +426,26 @@ proc cqyhdbl_write stdcall, mmio:dword, dstrd:byte, y:byte endp ; Writes to submission queue 'y' tail doorbell -proc sqytdbl_write stdcall, mmio:dword, dstrd:byte, y:byte +proc sqytdbl_write stdcall, pci:dword, y:byte, offset:dword + + push ebx esi edi + mov esi, [pci] + mov edi, [esi + pcidev.sq_ptr] + add edi, [offset] + mov esi, [esi + pcidev.mmio_ptr] ; 1000h + (2y * (4 << CAP.DSTRD)) - xor ecx, ecx - shl ecx, [y] + mov ecx, dword [esi + pcidev.dstrd] mov eax, 4 - shl eax, [dstrd] - imul eax, ecx - add eax, 0x1000 + shl eax, cl + mov cl, [y] + xor ebx, ebx + shl ebx, cl + imul ebx, eax + add ebx, 0x1000 + + mov dword [esi + ebx], edi ; Write to register + pop edi esi ebx ret endp @@ -460,6 +470,9 @@ proc pow2 stdcall, x:byte endp proc irq_handler + + DEBUGF DBG_INFO, "HI, I GOT CALLED!\n" + endp proc nvme_cleanup