From d172666be29dc597e616ca1891a54872e0da395a Mon Sep 17 00:00:00 2001 From: Abdur-Rahman Mansoor Date: Sat, 25 May 2024 20:37:42 -0400 Subject: [PATCH] wip: setup controller configuration --- drivers/nvme/nvme.asm | 30 ++++++++++++++++++++++++------ drivers/nvme/nvme.inc | 2 ++ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/drivers/nvme/nvme.asm b/drivers/nvme/nvme.asm index b507664..6e85d29 100644 --- a/drivers/nvme/nvme.asm +++ b/drivers/nvme/nvme.asm @@ -231,6 +231,10 @@ proc nvme_init stdcall, pci:dword DEBUGF DBG_INFO, "(NVMe) CAP (0-31): 0x%x\n", ebx mov ebx, dword [eax + NVME_MMIO.CAP + 4] DEBUGF DBG_INFO, "(NVMe) CAP (32-63): 0x%x\n", ebx + mov ebx, dword [eax + NVME_MMIO.CC] + DEBUGF DBG_INFO, "(NVMe) CC: 0x%x\n", ebx + mov ebx, dword [eax + NVME_MMIO.CSTS] + DEBUGF DBG_INFO, "(NVMe) CSTS: 0x%x\n", ebx end if mov ebx, dword [eax + NVME_MMIO.CAP] @@ -244,8 +248,25 @@ proc nvme_init stdcall, pci:dword test ebx, CAP_CSS_NVM_CMDSET jz .exit_fail - ; Reset controller + ; Reset controller before we configure it stdcall nvme_controller_reset, [pci] + mov eax, [pci] + mov eax, [eax + pcidev.mmio_ptr] + mov ebx, dword [eax + NVME_MMIO.CC] + and ebx, CAP_MPSMAX + shr ebx, 20 + cmp ebx, NVM_MPS + jl .exit_fail + + ; Configure IOSQES, IOCQES, MPS, CSS + mov ebx, dword [eax + NVME_MMIO.CC] + or ebx, (4 shl 16) or (6 shl 20) + and ebx, not (CC_MPS or CC_CSS) + mov dword [eax + NVME_MMIO.CC], ebx + + ; Configure Admin Queue Attributes + + ; Configure Admin Submission/Completion Queue Base Address xor eax, eax inc eax @@ -266,15 +287,12 @@ proc nvme_controller_reset stdcall, pci:dword push ebx mov ebx, dword [pci] mov ebx, dword [ebx + pcidev.mmio_ptr] - mov eax, dword [ebx + NVME_MMIO.CC] - and eax, 0xfffffffe ; CC.EN = 0 - mov dword [ebx + NVME_MMIO.CC], eax + and dword [ebx + NVME_MMIO.CC], 0xfffffffe stdcall nvme_wait, [pci] ; Wait for controller to be brought to idle state, CSTS.RDY should be cleared to 0 when this happens .wait: - mov eax, dword [ebx + NVME_MMIO.CSTS] - test eax, CSTS_RDY + test dword [ebx + NVME_MMIO.CSTS], CSTS_RDY jnz .wait DEBUGF DBG_INFO, "(NVMe) Successfully reset controller...\n" pop ebx diff --git a/drivers/nvme/nvme.inc b/drivers/nvme/nvme.inc index 152cdc3..3863bf1 100644 --- a/drivers/nvme/nvme.inc +++ b/drivers/nvme/nvme.inc @@ -11,6 +11,8 @@ ; Supported NVMe Controller Version NVM_SUPPORTED_CONTROLLER_VERSION = 0x00010400 ; (v1.4) +NVM_MPS = 0 + ; Opcodes for NVM commands NVM_CMD_FLUSH = 0x00 NVM_CMD_WRITE = 0x01