mirror of
https://git.missingno.dev/kolibrios-nvme-driver/
synced 2024-11-13 03:37:28 +01:00
refactor some stuff
This commit is contained in:
parent
4e9a9cc8c2
commit
cc3e3f6ec4
1
.gitignore
vendored
1
.gitignore
vendored
@ -31,3 +31,4 @@
|
|||||||
/drivers/*.inc
|
/drivers/*.inc
|
||||||
/drivers/*.asm
|
/drivers/*.asm
|
||||||
/drivers/**/*.sys
|
/drivers/**/*.sys
|
||||||
|
/nvme.c
|
||||||
|
@ -555,11 +555,11 @@ proc nvme_init stdcall, pci:dword
|
|||||||
stdcall memset, dword [esi + pcidev.cq_ptr], 0, sizeof.CQ_ENTRY * NVM_ACQS
|
stdcall memset, dword [esi + pcidev.cq_ptr], 0, sizeof.CQ_ENTRY * NVM_ACQS
|
||||||
|
|
||||||
; Allocate list of queues
|
; Allocate list of queues
|
||||||
invoke KernelAlloc, sizeof.NVM_QUEUE * NVM_ASQS
|
invoke KernelAlloc, sizeof.NVM_QUEUE_ENTRY * NVM_ASQS
|
||||||
test eax, eax
|
test eax, eax
|
||||||
jz .exit_fail
|
jz .exit_fail
|
||||||
mov dword [esi + pcidev.queue_ptr], eax
|
mov dword [esi + pcidev.queue_entries], eax
|
||||||
stdcall memset, eax, 0, sizeof.NVM_QUEUE * NVM_ASQS
|
stdcall memset, eax, 0, sizeof.NVM_QUEUE_ENTRY * NVM_ASQS
|
||||||
|
|
||||||
; we want to disable all interrupts for now, since the controller randomly
|
; we want to disable all interrupts for now, since the controller randomly
|
||||||
; generates interrupts while starting up
|
; generates interrupts while starting up
|
||||||
@ -598,6 +598,40 @@ proc nvme_init stdcall, pci:dword
|
|||||||
|
|
||||||
endp
|
endp
|
||||||
|
|
||||||
|
proc get_avl_cmd stdcall, pci:dword, y:dword
|
||||||
|
|
||||||
|
push esi ebx
|
||||||
|
mov esi, [pci]
|
||||||
|
mov ecx, [y]
|
||||||
|
mov eax, dword [esi + ecx * pcidev.queue_entries + NVM_QUEUE_ENTRY.cid_slots]
|
||||||
|
xor edx, edx
|
||||||
|
cmp eax, 0xffffffff
|
||||||
|
jne @f
|
||||||
|
mov eax, dword [esi + ecx * pcidev.queue_entries + NVM_QUEUE_ENTRY.cid_slots + 4]
|
||||||
|
add edx, 4
|
||||||
|
cmp eax, 0xffffffff
|
||||||
|
jne @f
|
||||||
|
pop esi
|
||||||
|
mov eax, -1
|
||||||
|
ret
|
||||||
|
|
||||||
|
@@:
|
||||||
|
mov ebx, eax
|
||||||
|
|
||||||
|
; Equivalant to (~(-X) & ~(X)), retrieves first free bit
|
||||||
|
not eax
|
||||||
|
mov ecx, eax
|
||||||
|
neg ecx
|
||||||
|
and eax, ecx
|
||||||
|
or ebx, eax
|
||||||
|
|
||||||
|
mov ecx, [y]
|
||||||
|
mov dword [esi + ecx * pcidev.queue_entries + NVM_QUEUE_ENTRY.cid_slots + edx], ebx
|
||||||
|
pop ebx esi
|
||||||
|
ret
|
||||||
|
|
||||||
|
endp
|
||||||
|
|
||||||
proc nvme_controller_reset stdcall, mmio:dword
|
proc nvme_controller_reset stdcall, mmio:dword
|
||||||
|
|
||||||
DEBUGF DBG_INFO, "(NVMe) Resetting Controller...\n"
|
DEBUGF DBG_INFO, "(NVMe) Resetting Controller...\n"
|
||||||
@ -642,7 +676,7 @@ proc nvme_wait stdcall, mmio:dword
|
|||||||
mov esi, dword [esi + NVME_MMIO.CAP]
|
mov esi, dword [esi + NVME_MMIO.CAP]
|
||||||
and esi, CAP_TO
|
and esi, CAP_TO
|
||||||
shr esi, 24
|
shr esi, 24
|
||||||
imul esi, 100 ; TODO: bad time delay, set to appropriate value later
|
imul esi, 150 ; TODO: bad time delay, set to appropriate value later
|
||||||
invoke Sleep
|
invoke Sleep
|
||||||
pop esi
|
pop esi
|
||||||
ret
|
ret
|
||||||
@ -675,7 +709,7 @@ proc sqytdbl_write stdcall, pci:dword, y:byte, sqt:word
|
|||||||
endp
|
endp
|
||||||
|
|
||||||
; Writes to completion queue 'y' head doorbell
|
; Writes to completion queue 'y' head doorbell
|
||||||
proc cqyhdbl_write stdcall, pci:dword, y:byte
|
proc cqyhdbl_write stdcall, pci:dword, y:byte, cqh:word
|
||||||
|
|
||||||
push esi edi
|
push esi edi
|
||||||
mov esi, [pci]
|
mov esi, [pci]
|
||||||
@ -684,25 +718,18 @@ proc cqyhdbl_write stdcall, pci:dword, y:byte
|
|||||||
movzx eax, [y]
|
movzx eax, [y]
|
||||||
shl al, 1
|
shl al, 1
|
||||||
inc al
|
inc al
|
||||||
mov dx, 4
|
mov edx, 4
|
||||||
mov cl, byte [esi + pcidev.dstrd]
|
mov cl, byte [esi + pcidev.dstrd]
|
||||||
shl dx, cl
|
shl dx, cl
|
||||||
imul dx, ax
|
imul dx, ax
|
||||||
add dx, 0x1000
|
add dx, 0x1000
|
||||||
|
|
||||||
movzx ecx, [y]
|
movzx ecx, [y]
|
||||||
mov edi, dword [esi + pcidev.queue_ptr]
|
mov edi, dword [esi + pcidev.queue_entries]
|
||||||
mov ax, word [edi + ecx * sizeof.NVM_QUEUE + NVM_QUEUE.head] ; get head for completion queue Y
|
|
||||||
cmp ax, NVM_ACQS
|
|
||||||
jl @f
|
|
||||||
xor ax, ax
|
|
||||||
|
|
||||||
@@:
|
|
||||||
inc ax
|
|
||||||
mov esi, dword [esi + pcidev.io_addr]
|
mov esi, dword [esi + pcidev.io_addr]
|
||||||
|
mov ax, [cqh]
|
||||||
DEBUGF DBG_INFO, "(NVMe) Writing to completion queue doorbell register 0x%x: %u\n", dx, ax
|
DEBUGF DBG_INFO, "(NVMe) Writing to completion queue doorbell register 0x%x: %u\n", dx, ax
|
||||||
mov word [esi + edx], ax ; Write to CQyHDBL
|
mov word [esi + edx], ax ; Write to CQyHDBL
|
||||||
mov word [edi + ecx * sizeof.NVM_QUEUE + NVM_QUEUE.head], ax
|
mov word [edi + ecx * sizeof.NVM_QUEUE_ENTRY + NVM_QUEUE_ENTRY.head], ax
|
||||||
pop edi esi
|
pop edi esi
|
||||||
ret
|
ret
|
||||||
|
|
||||||
@ -712,8 +739,8 @@ proc write_admin_cmd stdcall, pci:dword
|
|||||||
|
|
||||||
push esi
|
push esi
|
||||||
mov esi, [pci]
|
mov esi, [pci]
|
||||||
mov esi, dword [esi + pcidev.queue_ptr]
|
mov esi, dword [esi + pcidev.queue_entries]
|
||||||
mov ax, word [esi + NVM_QUEUE.tail]
|
mov ax, word [esi + NVM_QUEUE_ENTRY.tail]
|
||||||
cmp ax, NVM_ASQS
|
cmp ax, NVM_ASQS
|
||||||
jl @f
|
jl @f
|
||||||
xor ax, ax
|
xor ax, ax
|
||||||
@ -723,7 +750,7 @@ proc write_admin_cmd stdcall, pci:dword
|
|||||||
mov esi, dword [esi + pcidev.io_addr]
|
mov esi, dword [esi + pcidev.io_addr]
|
||||||
inc ax
|
inc ax
|
||||||
mov word [esi + 0x1000], ax
|
mov word [esi + 0x1000], ax
|
||||||
mov word [esi + NVM_QUEUE.tail], ax
|
mov word [esi + NVM_QUEUE_ENTRY.tail], ax
|
||||||
pop esi
|
pop esi
|
||||||
ret
|
ret
|
||||||
|
|
||||||
@ -773,7 +800,7 @@ proc irq_handler
|
|||||||
|
|
||||||
@@:
|
@@:
|
||||||
mov dword [esi + NVME_MMIO.INTMC], 0x1
|
mov dword [esi + NVME_MMIO.INTMC], 0x1
|
||||||
stdcall cqyhdbl_write, [p_nvme_devices], 0
|
stdcall cqyhdbl_write, [p_nvme_devices], 0x0, 0x1
|
||||||
|
|
||||||
.exit:
|
.exit:
|
||||||
; Interrupt handled by driver, return 1
|
; Interrupt handled by driver, return 1
|
||||||
|
@ -16,6 +16,7 @@ VS121 = 0x00010201 ; (v1.2.1)
|
|||||||
VS130 = 0x00010300 ; (v1.3.0)
|
VS130 = 0x00010300 ; (v1.3.0)
|
||||||
VS140 = 0x00010400 ; (v1.4.0)
|
VS140 = 0x00010400 ; (v1.4.0)
|
||||||
|
|
||||||
|
NVM_CMDS = 64 ; Number of Commands
|
||||||
NVM_MPS = 0 ; Memory Page Size (2 ^ (12 + MPS))
|
NVM_MPS = 0 ; Memory Page Size (2 ^ (12 + MPS))
|
||||||
NVM_ASQS = 2 ; Admin Submission Queue Size
|
NVM_ASQS = 2 ; Admin Submission Queue Size
|
||||||
NVM_ACQS = NVM_ASQS ; Admin Completion Queue Size
|
NVM_ACQS = NVM_ASQS ; Admin Completion Queue Size
|
||||||
@ -301,7 +302,7 @@ struct pcidev
|
|||||||
io_addr dd ?
|
io_addr dd ?
|
||||||
sq_ptr dd ?
|
sq_ptr dd ?
|
||||||
cq_ptr dd ?
|
cq_ptr dd ?
|
||||||
queue_ptr dd ?
|
queue_entries dd ?
|
||||||
pc db ?
|
pc db ?
|
||||||
dstrd db ?
|
dstrd db ?
|
||||||
rb 2 ; align
|
rb 2 ; align
|
||||||
@ -309,9 +310,16 @@ ends
|
|||||||
TOTAL_PCIDEVS = 4
|
TOTAL_PCIDEVS = 4
|
||||||
TOTAL_PCIDEVS_MALLOC_SZ = TOTAL_PCIDEVS * sizeof.pcidev
|
TOTAL_PCIDEVS_MALLOC_SZ = TOTAL_PCIDEVS * sizeof.pcidev
|
||||||
|
|
||||||
struct NVM_QUEUE
|
struct DPTR
|
||||||
|
prp1 dd ?
|
||||||
|
prp2 dd ?
|
||||||
|
ends
|
||||||
|
|
||||||
|
struct NVM_QUEUE_ENTRY
|
||||||
tail dw ?
|
tail dw ?
|
||||||
head dw ?
|
head dw ?
|
||||||
|
dptr dd ?
|
||||||
|
;cid_slots dq ?
|
||||||
ends
|
ends
|
||||||
|
|
||||||
; Identify Controller Data Structure
|
; Identify Controller Data Structure
|
||||||
|
Loading…
Reference in New Issue
Block a user