mirror of
https://git.missingno.dev/kolibrios-nvme-driver/
synced 2024-12-22 13:58:47 +01:00
add num
field to each detected NVMe device
This commit is contained in:
parent
f612befee6
commit
43f29c791a
@ -465,6 +465,7 @@ proc detect_nvme
|
||||
mov byte [ebx + pcidev.bus], dl
|
||||
movzx edx, byte [eax + PCIDEV.devfn]
|
||||
mov byte [ebx + pcidev.devfn], dl
|
||||
mov dword [ebx + pcidev.num], ecx
|
||||
|
||||
pop edx
|
||||
jmp .next_dev
|
||||
@ -516,7 +517,7 @@ proc device_is_compat stdcall, pci:dword
|
||||
invoke MapIoMem, edx, ecx, PG_SW+PG_NOCACHE
|
||||
mov dword [esi + pcidev.io_addr], eax
|
||||
mov eax, dword [eax + NVME_MMIO.VS]
|
||||
DEBUGF DBG_INFO, "(NVMe) Controller version: 0x%x\n", eax
|
||||
DEBUGF DBG_INFO, "nvme%u: Controller version: 0x%x\n", [esi + pcidev.num], eax
|
||||
mov dword [esi + pcidev.version], eax
|
||||
pop ecx edx esi
|
||||
xor eax, eax
|
||||
@ -556,7 +557,7 @@ proc nvme_init stdcall, pci:dword
|
||||
jz .exit_fail
|
||||
|
||||
; Reset controller before we configure it
|
||||
stdcall nvme_controller_reset, edi
|
||||
stdcall nvme_controller_reset, esi
|
||||
if __DEBUG__
|
||||
stdcall nvme_wait, edi
|
||||
end if
|
||||
@ -629,14 +630,14 @@ proc nvme_init stdcall, pci:dword
|
||||
|
||||
; Attach interrupt handler
|
||||
movzx eax, byte [esi + pcidev.iline]
|
||||
DEBUGF DBG_INFO, "(NVMe) Attaching interrupt handler to IRQ %u\n", eax
|
||||
DEBUGF DBG_INFO, "nvme%u: Attaching interrupt handler to IRQ %u\n", [esi + pcidev.num], eax
|
||||
invoke AttachIntHandler, eax, irq_handler, 0
|
||||
test eax, eax
|
||||
jz .exit_fail
|
||||
DEBUGF DBG_INFO, "(NVMe) Successfully attached interrupt handler\n"
|
||||
DEBUGF DBG_INFO, "nvme%u: Successfully attached interrupt handler\n", [esi + pcidev.num]
|
||||
|
||||
; Restart the controller
|
||||
stdcall nvme_controller_start, edi
|
||||
stdcall nvme_controller_start, esi
|
||||
;mov dword [edi + NVME_MMIO.INTMC], 0xffffffff ; re-enable interrupts
|
||||
|
||||
invoke KernelAlloc, 0x1000
|
||||
@ -649,15 +650,15 @@ proc nvme_init stdcall, pci:dword
|
||||
mov edi, ebx
|
||||
mov eax, dword [edi + IDENTC.nn]
|
||||
mov dword [esi + pcidev.nn], eax
|
||||
DEBUGF DBG_INFO, "(NVMe) Namespace Count: %u\n", eax
|
||||
DEBUGF DBG_INFO, "nvme%u: Namespace Count: %u\n", [esi + pcidev.num], eax
|
||||
lea ebx, byte [edi + IDENTC.sn]
|
||||
lea eax, byte [esi + pcidev.serial]
|
||||
stdcall memcpy, eax, ebx, 20
|
||||
DEBUGF DBG_INFO, "(NVMe) Serial Number: %s\n", eax
|
||||
DEBUGF DBG_INFO, "nvme%u: Serial Number: %s\n", [esi + pcidev.num], eax
|
||||
add ebx, 20
|
||||
lea eax, byte [esi + pcidev.model]
|
||||
stdcall memcpy, eax, ebx, 40
|
||||
DEBUGF DBG_INFO, "(NVMe) Model: %s\n", eax
|
||||
DEBUGF DBG_INFO, "nvme%u: Model: %s\n", [esi + pcidev.num], eax
|
||||
mov edx, dword [esi + pcidev.version]
|
||||
|
||||
cmp edx, VS140
|
||||
@ -666,7 +667,7 @@ proc nvme_init stdcall, pci:dword
|
||||
mov al, byte [edi + IDENTC.cntrltype]
|
||||
cmp al, CNTRLTYPE_IO_CONTROLLER
|
||||
jne .exit_fail
|
||||
DEBUGF DBG_INFO, "(NVMe) I/O controller detected...\n"
|
||||
DEBUGF DBG_INFO, "nvme%u: I/O controller detected...\n", [esi + pcidev.num]
|
||||
|
||||
@@:
|
||||
mov al, byte [edi + IDENTC.sqes]
|
||||
@ -685,7 +686,10 @@ proc nvme_init stdcall, pci:dword
|
||||
mov esi, dword [esi + pcidev.queue_entries]
|
||||
mov esi, dword [esi + NVM_QUEUE_ENTRY.cq_ptr]
|
||||
mov eax, dword [esi + sizeof.CQ_ENTRY + CQ_ENTRY.cdw0]
|
||||
DEBUGF DBG_INFO, "(NVMe) Set Features CDW0: 0x%x\n", eax
|
||||
if __DEBUG__
|
||||
mov esi, [pci]
|
||||
DEBUGF DBG_INFO, "nvme%u: Set Features CDW0: 0x%x\n", [esi + pcidev.num], eax
|
||||
end if
|
||||
test ax, ax ; Number of I/O Submission Queues allocated
|
||||
jz .exit_fail
|
||||
shl eax, 16
|
||||
@ -716,7 +720,7 @@ proc nvme_init stdcall, pci:dword
|
||||
jz .exit_fail ; No active NSIDS
|
||||
mov esi, [pci]
|
||||
mov dword [esi + pcidev.nsid], eax
|
||||
DEBUGF DBG_INFO, "(NVMe) Found active NSID: %u\n", eax
|
||||
DEBUGF DBG_INFO, "nvme%u: Found active NSID: %u\n", [esi + pcidev.num], eax
|
||||
else
|
||||
mov esi, [pci]
|
||||
xor eax, eax
|
||||
@ -730,24 +734,27 @@ proc nvme_init stdcall, pci:dword
|
||||
invoke GetPhysAddr
|
||||
stdcall nvme_identify, [pci], [esi + pcidev.nsid], eax, CNS_IDNS
|
||||
mov al, byte [edi + IDENTN.nsfeat]
|
||||
DEBUGF DBG_INFO, "(nvme%un%u): Namespace Features: 0x%x\n", 0, [esi + pcidev.nsid], al
|
||||
DEBUGF DBG_INFO, "(nvme%un%u): Namespace Size: %u + %u logical blocks\n", 0, [esi + pcidev.nsid], [edi + IDENTN.nsze], [edi + IDENTN.nsze + 4]
|
||||
DEBUGF DBG_INFO, "(nvme%un%u): Namespace Capacity: %u + %u logical blocks\n", 0, [esi + pcidev.nsid], [edi + IDENTN.ncap], [edi + IDENTN.ncap + 4]
|
||||
DEBUGF DBG_INFO, "nvme%un%u: Namespace Features: 0x%x\n", [esi + pcidev.num], [esi + pcidev.nsid], al
|
||||
DEBUGF DBG_INFO, "nvme%un%u: Namespace Size: %u + %u logical blocks\n", [esi + pcidev.num], [esi + pcidev.nsid], [edi + IDENTN.nsze], [edi + IDENTN.nsze + 4]
|
||||
DEBUGF DBG_INFO, "nvme%un%u: Namespace Capacity: %u + %u logical blocks\n", [esi + pcidev.num], [esi + pcidev.nsid], [edi + IDENTN.ncap], [edi + IDENTN.ncap + 4]
|
||||
mov eax, dword [edi + IDENTN.lbaf0]
|
||||
shr eax, 16 ; Get LBADS
|
||||
and eax, 0xff
|
||||
stdcall pow2, eax
|
||||
DEBUGF DBG_INFO, "(nvme%un%u): Namespace LBA Data Size: %u\n", 0, [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
|
||||
|
||||
DEBUGF DBG_INFO, "(NVMe) Successfully initialized driver!\n"
|
||||
DEBUGF DBG_INFO, "nvme%u: Successfully initialized driver\n", [esi + pcidev.num]
|
||||
xor eax, eax
|
||||
inc eax
|
||||
pop edi esi ebx
|
||||
ret
|
||||
|
||||
.exit_fail:
|
||||
DEBUGF DBG_INFO, "(NVMe) failed to initialize controller\n"
|
||||
if __DEBUG__
|
||||
mov esi, [pci]
|
||||
DEBUGF DBG_INFO, "nvme%u: failed to initialize controller\n", [esi + pcidev.num]
|
||||
end if
|
||||
xor eax, eax
|
||||
pop edi esi ebx
|
||||
ret
|
||||
@ -767,36 +774,38 @@ proc get_new_cid stdcall, pci:dword, y:dword
|
||||
|
||||
endp
|
||||
|
||||
proc nvme_controller_reset stdcall, mmio:dword
|
||||
proc nvme_controller_reset stdcall, pci:dword
|
||||
|
||||
DEBUGF DBG_INFO, "(NVMe) Resetting Controller...\n"
|
||||
push edi
|
||||
mov edi, dword [mmio]
|
||||
push esi edi
|
||||
mov esi, [pci]
|
||||
DEBUGF DBG_INFO, "nvme%u: Resetting Controller...\n", [esi + pcidev.num]
|
||||
mov edi, dword [esi + pcidev.io_addr]
|
||||
and dword [edi + NVME_MMIO.CC], 0xfffffffe ; CC.EN = 0
|
||||
|
||||
; Wait for controller to be brought to idle state, CSTS.RDY should be cleared to 0 when this happens
|
||||
.wait:
|
||||
test dword [edi + NVME_MMIO.CSTS], CSTS_RDY
|
||||
jnz .wait
|
||||
DEBUGF DBG_INFO, "(NVMe) Successfully reset controller...\n"
|
||||
pop edi
|
||||
DEBUGF DBG_INFO, "nvme%u: Successfully reset controller...\n", [esi + pcidev.num]
|
||||
pop edi esi
|
||||
ret
|
||||
|
||||
endp
|
||||
|
||||
proc nvme_controller_start stdcall, mmio:dword
|
||||
proc nvme_controller_start stdcall, pci:dword
|
||||
|
||||
DEBUGF DBG_INFO, "(NVMe) Starting Controller...\n"
|
||||
push edi
|
||||
mov edi, dword [mmio]
|
||||
push esi edi
|
||||
mov esi, [pci]
|
||||
DEBUGF DBG_INFO, "nvme%u: Starting Controller...\n", [esi + pcidev.num]
|
||||
mov edi, dword [esi + pcidev.io_addr]
|
||||
or dword [edi + NVME_MMIO.CC], 1 ; CC.EN = 1
|
||||
|
||||
; Wait for controller to be brought into active state, CSTS.RDY should be set to 1 when this happens
|
||||
.wait:
|
||||
test dword [edi + NVME_MMIO.CSTS], CSTS_RDY
|
||||
jz .wait
|
||||
DEBUGF DBG_INFO, "(NVMe) Successfully started controller...\n"
|
||||
pop edi
|
||||
DEBUGF DBG_INFO, "nvme%u: Successfully started controller...\n", [esi + pcidev.num]
|
||||
pop edi esi
|
||||
ret
|
||||
|
||||
endp
|
||||
@ -1009,7 +1018,6 @@ proc irq_handler
|
||||
; a fatal error or if a completion is not received for a deletion
|
||||
; of a submission or completion queue (section 10.1 - page 400 of NVMe 1.4 spec)
|
||||
;mov esi, dword [p_nvme_devices]
|
||||
;mov esi, dword [esi + pcidev.io_addr]
|
||||
;stdcall nvme_controller_reset, esi
|
||||
;stdcall nvme_controller_start, esi
|
||||
;jmp .end
|
||||
|
@ -308,6 +308,7 @@ struct pcidev
|
||||
devfn db ?
|
||||
ipin db ?
|
||||
iline db ?
|
||||
num dd ?
|
||||
io_addr dd ?
|
||||
queue_entries dd ?
|
||||
version dd ?
|
||||
|
Loading…
Reference in New Issue
Block a user