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

fix errors

This commit is contained in:
ramenu 2024-03-31 16:13:17 -04:00
parent ab0e73b2b5
commit 43a3db6f1e
2 changed files with 159 additions and 160 deletions

View File

@ -63,42 +63,41 @@ proc service_proc stdcall, ioctl:dword
ret
endp
; todo complete
proc ns_management_supported stdcall
mov eax, [p_ident + id_controller.oacs]
test eax, OACS_NSMAN_SUPPORTED
ret
endp
proc memset stdcall, p_data:dword, val:byte, sz:dword
mov ah, byte [val]
xor ebx, ebx
mov bh, byte [val]
xor eax, eax
@@:
mov byte [p_data + ebx], ah
inc ebx
cmp ebx, dword [sz]
mov byte [p_data + eax], bh
inc eax
cmp eax, dword [sz]
jne @b
ret
endp
; Submit a Command in the Admin Submission Queue
proc submit_asq stdcall, p_sq:dword
mov eax, dword [p_sq]
mov ebx, dword [bar0]
add ebx, NVME_REG_ASQ
xor eax, eax
ret
endp
proc nvme_identify stdcall, nsid:dword, dptr:dword, cns:byte
sub esp, sizeof.sq_entry
stdcall memset, esp, 0, sizeof.cq_entry
sub esp, sizeof.SQ_ENTRY
stdcall memset, esp, 0, sizeof.SQ_ENTRY
mov eax, dword [nsid]
mov [esp + sq_entry.nsid], eax
mov [esp + SQ_ENTRY.nsid], eax
mov eax, dword [dptr]
mov [esp + sq_entry.dptr], eax
mov dword [esp + SQ_ENTRY.dptr], eax
; TODO: setting CID to 1 for now but later on keep a list of unique list of identifiers
mov dword [esp + sq_entry.cdw0], ADM_CMD_IDENTIFY or (1 shl 16)
mov dword [esp + SQ_ENTRY.cdw0], ADM_CMD_IDENTIFY or (1 shl 16)
mov ah, byte [cns]
mov byte [esp + sq_entry.cdw10], ah
add esp, sizeof.sq_entry
mov byte [esp + SQ_ENTRY.cdw10], ah
stdcall submit_asq, esp
add esp, sizeof.SQ_ENTRY
xor eax, eax
ret
endp
proc detect
@ -147,15 +146,16 @@ proc detect
invoke PciRead32, [pcidev_bus], [pcidev_devfn], PCI_header00.base_addr_0
mov [bar0], eax
invoke Kmalloc, sizeof.id_controller
invoke Kmalloc, sizeof.NVME_IDENT_CONTROLLER
test eax, eax
jz .alloc_id_controller_fail
DEBUGF DBG_INFO,"Successfully allocated %u bytes for 'id_controller'\n",sizeof.id_controller
jz .alloc_ident_controller_fail
DEBUGF DBG_INFO,"Successfully allocated %u bytes for 'NVME_IDENT_CONTROLLER'\n",sizeof.NVME_IDENT_CONTROLLER
mov [p_ident], eax
stdcall nvme_identify, 0, dword [p_ident], CNS_IDCS
mov ecx, dword [p_ident]
DEBUGF DBG_INFO,"Total NVMe SSD capacity: %ub\n",dword [ecx + id_controller.tnvmcap]
mov edx, dword [ecx + NVME_IDENT_CONTROLLER.tnvmcap]
DEBUGF DBG_INFO,"Total NVMe SSD capacity: %ub\n", edx
; return successfully
call nvme_cleanup
@ -165,8 +165,8 @@ proc detect
inc eax
ret
.alloc_id_controller_fail:
DEBUGF DBG_INFO,"ERROR: failed to allocate %u bytes for 'id_controller'\n", sizeof.id_controller
.alloc_ident_controller_fail:
DEBUGF DBG_INFO,"ERROR: failed to allocate %u bytes for 'NVME_IDENT_CONTROLLER'\n", sizeof.NVME_IDENT_CONTROLLER
pop eax
pop ebx
xor eax, eax

View File

@ -91,20 +91,20 @@ OACS_NSMAN_SUPPORTED = 1 shl 3
NSID_BROADCAST = 0xFFFFFFFF
; Submission Queue Entry (64 bytes)
struc sq_entry {
.cdw0 dd ?
.nsid dd ?
.cdw2 dd ?
.cdw3 dd ?
.mptr dq ?
.dptr dq ?
.cdw10 dd ?
.cdw11 dd ?
.cdw12 dd ?
.cdw13 dd ?
.cdw14 dd ?
.cdw15 dd ?
}
struct SQ_ENTRY
cdw0 rd 1
nsid rd 1
cdw2 rd 1
cdw3 rd 1
mptr rq 1
dptr rq 1
cdw10 rd 1
cdw11 rd 1
cdw12 rd 1
cdw13 rd 1
cdw14 rd 1
cdw15 rd 1
ends
struc nvme_dev {
.pci_bus dd ?
@ -114,133 +114,132 @@ struc nvme_dev {
.model db 40
}
struct id_controller
struct NVME_IDENT_CONTROLLER
pci_vid dw ?
pci_ssvid dw ?
serial db 20
model db 40
firm_rev dq ?
rab db ?
ieee db 3
cmic db ?
mdts db ?
ctrlid dw ?
ver db 3
rtd3r dd ?
rtd3e dd ?
ctrlatt dd ?
rrls dw ?
reserved db 9
ctrltyp db ?
fguid dq 2
crdt1 dw ?
ctdt2 dw ?
crdt3 dw ?
pci_vid rw 1
pci_ssvid rw 1
serial rb 20
model rb 40
firm_rev rq 1
rab rb 1
ieee rb 3
cmic rb 1
mdts rb 1
ctrlid rw 1
ver rb 3
rtd3r rd 1
rtd3e rd 1
ctrlatt rd 1
rrls rw 1
reserved rb 9
ctrltyp rb 1
fguid rq 2
crdt1 rw 1
ctdt2 rw 1
crdt3 rw 1
rb 106 ; reserved
rb 13 ; reserved (NVMMI)
nvmsr db ?
vmci db ?
mec db ?
oacs dw ?
acl db ?
aerl db ?
frmw db ?
lpa db ?
elpe db ?
npss db ?
avscc db ?
apsta db ?
wctemp dw ?
cctemp dw ?
mtfa dw ?
hmpre dd ?
hmmin dd ?
tnvmcap dq 2
unvmcap dq 2
rpmbs dd ?
edstt dw ?
dsto db ?
fwug db ?
kas dw ?
hctma dw ?
mntmt dw ?
mxtmt dw ?
sanicap dd ?
hmminds dd ?
hmmaxd dw ?
nsetidmax dw ?
endgidmax dw ?
anatt db ?
anacap db ?
anagrpmax dd ?
nanagrpid dd ?
pels dd ?
domid dw ?
nvmsr rb 1
vmci rb 1
mec rb 1
oacs rw 1
acl rb 1
aerl rb 1
frmw rb 1
lpa rb 1
elpe rb 1
npss rb 1
avscc rb 1
apsta rb 1
wctemp rw 1
cctemp rw 1
mtfa rw 1
hmpre rd 1
hmmin rd 1
tnvmcap rq 2
unvmcap rq 2
rpmbs rd 1
edstt rw 1
dsto rb 1
fwug rb 1
kas rw 1
hctma rw 1
mntmt rw 1
mxtmt rw 1
sanicap rd 1
hmminds rd 1
hmmaxd rw 1
nsetidmax rw 1
endgidmax rw 1
anatt rb 1
anacap rb 1
anagrpmax rd 1
nanagrpid rd 1
pels rd 1
domid rw 1
rb 10 ; reserved
megcap dq 2
megcap rq 2
rb 128 ; reserved
sqes db ?
cqes db ?
maxcmd dw ?
nn dd ?
oncs dw ?
fuses dw ?
fna db ?
vwc db ?
awun dw ?
awupf dw ?
icsvscc db ?
nwpc db ?
acwu dw ?
ocfs dw ?
sgls dd ?
mnan dd ?
maxdna dq 2
maxcna dd ?
sqes rb 1
cqes rb 1
maxcmd rw 1
nn rd 1
oncs rw 1
fuses rw 1
fna rb 1
vwc rb 1
awun rw 1
awupf rw 1
icsvscc rb 1
nwpc rb 1
acwu rw 1
ocfs rw 1
sgls rd 1
mnan rd 1
maxdna rq 2
maxcna rd 1
rb 204 ; reserved
subnqn db 256
subnqn rb 256
rb 768 ; reserved
ioccsz dd ?
iorcsz dd ?
icdoff dw ?
fcatt db ?
msdbd db ?
ofcs dw ?
ioccsz rd 1
iorcsz rd 1
icdoff rw 1
fcatt rb 1
msdbd rb 1
ofcs rw 1
rb 242 ; reserved
psd0 db 32
psd1 db 32
psd2 db 32
psd3 db 32
psd4 db 32
psd5 db 32
psd6 db 32
psd7 db 32
psd8 db 32
psd9 db 32
psd10 db 32
psd11 db 32
psd12 db 32
psd13 db 32
psd14 db 32
psd15 db 32
psd16 db 32
psd17 db 32
psd18 db 32
psd19 db 32
psd20 db 32
psd21 db 32
psd22 db 32
psd23 db 32
psd24 db 32
psd25 db 32
psd26 db 32
psd27 db 32
psd28 db 32
psd29 db 32
psd30 db 32
psd31 db 32
venspec db 1024
psd0 rb 32
psd1 rb 32
psd2 rb 32
psd3 rb 32
psd4 rb 32
psd5 rb 32
psd6 rb 32
psd7 rb 32
psd8 rb 32
psd9 rb 32
psd10 rb 32
psd11 rb 32
psd12 rb 32
psd13 rb 32
psd14 rb 32
psd15 rb 32
psd16 rb 32
psd17 rb 32
psd18 rb 32
psd19 rb 32
psd20 rb 32
psd21 rb 32
psd22 rb 32
psd23 rb 32
psd24 rb 32
psd25 rb 32
psd26 rb 32
psd27 rb 32
psd28 rb 32
psd29 rb 32
psd30 rb 32
psd31 rb 32
venspec rb 1024
ends