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

remap entire MMIO

This commit is contained in:
Abdur-Rahman Mansoor 2024-05-29 19:29:01 -04:00
parent 97d9fc0c76
commit f5534dbdcf

View File

@ -196,12 +196,14 @@ endp
proc device_is_compat stdcall, pci:dword proc device_is_compat stdcall, pci:dword
push esi push esi edx ecx
mov esi, [pci] mov esi, [pci]
invoke PciRead32, dword [esi + pcidev.bus], dword [esi + pcidev.devfn], PCI_header00.base_addr_0 invoke PciRead32, dword [esi + pcidev.bus], dword [esi + pcidev.devfn], PCI_header00.base_addr_0
and eax, 0xfffffff0 and eax, 0xfffffff0
test eax, eax test eax, eax
jz .failure jz .failure
mov edx, eax
push edx
invoke MapIoMem, eax, sizeof.NVME_MMIO, PG_SW+PG_NOCACHE invoke MapIoMem, eax, sizeof.NVME_MMIO, PG_SW+PG_NOCACHE
test eax, eax test eax, eax
@ -214,21 +216,32 @@ proc device_is_compat stdcall, pci:dword
; Stride is (2 ^ (2 + DSTRD)) bytes ; Stride is (2 ^ (2 + DSTRD)) bytes
add eax, 2 add eax, 2
stdcall pow2, eax stdcall pow2, eax
mov ecx, eax
mov dword [esi + pcidev.dstrd], eax mov dword [esi + pcidev.dstrd], eax
; TODO: Remap I/O with new size ; 1003h + ((2y + 1) * (4 << CAP.DSTRD))
mov eax, 4
shl ax, cl
mov ecx, NVM_ASQS
shl ecx, 1
inc ecx
imul ecx, eax
add ecx, 0x1003
mov esi, dword [esi + pcidev.mmio_ptr] ;invoke FreePage, dword [esi + pcidev.mmio_ptr]
mov eax, dword [esi + NVME_MMIO.VS] pop edx
invoke MapIoMem, edx, ecx, PG_SW+PG_NOCACHE
mov dword [esi + pcidev.mmio_ptr], eax
mov eax, dword [eax + NVME_MMIO.VS]
DEBUGF DBG_INFO, "(NVMe) Controller version: 0x%x\n", eax DEBUGF DBG_INFO, "(NVMe) Controller version: 0x%x\n", eax
pop esi pop ecx edx esi
xor eax, eax xor eax, eax
inc eax inc eax
ret ret
.failure: .failure:
PDEBUGF DBG_INFO, "PCI(%u.%u.%u): something went wrong checking NVMe device compatibility\n", byte [esi + pcidev.bus], byte [esi + pcidev.devfn] PDEBUGF DBG_INFO, "PCI(%u.%u.%u): something went wrong checking NVMe device compatibility\n", byte [esi + pcidev.bus], byte [esi + pcidev.devfn]
pop esi pop ecx edx esi
xor eax, eax xor eax, eax
ret ret
@ -384,18 +397,19 @@ proc cq0thbl_write stdcall, dstrd:dword
endp endp
; Calculates 2^x ; Calculates 2^x
proc pow2 stdcall, x:dword proc pow2 stdcall, x:byte
push ecx push ecx
mov ecx, [x] mov cl, [x]
xor eax, eax xor eax, eax
inc eax inc eax
test ecx, ecx test cl, cl
jnz @f jnz @f
pop ecx
ret ret
@@: @@:
shl eax, ecx shl eax, cl
pop ecx pop ecx
ret ret