2
0
mirror of https://git.missingno.dev/kolibrios-nvme-driver/ synced 2025-02-01 18:10:29 +01:00

perf: remove some unneeded code bloat

This commit is contained in:
Abdur-Rahman Mansoor 2024-07-23 14:10:42 -04:00
parent 1b88a4ff17
commit 39dcfd2edc
2 changed files with 27 additions and 43 deletions

View File

@ -565,48 +565,48 @@ endp
proc alloc_dptr stdcall, ns:dword, prps_ptr:dword, numsectors:dword, prp_list_ptr:dword, buf:dword
push esi edi
push ebx esi edi
mov esi, [ns]
; the pointer to our PRP list (virtual), needed so
; that the caller can free the PRP list afterwards
mov edi, [prp_list_ptr]
mov dword [edi], 0
mov edi, [prps_ptr]
mov dword [edi], 0 ; PRP1 default value
mov dword [edi + 4], 0 ; PRP2 default value
mov eax, [buf]
invoke GetPhysAddr
mov dword [edi], eax
mov edx, [numsectors]
mov cl, byte [esi + NSINFO.lbads]
mov ebx, PAGE_SIZE
shr ebx, cl
mov eax, edx
mov [numsectors], 0
cmp eax, dword [esi + NSINFO.pg_sectors]
cmp eax, ebx
jbe @f
sub eax, dword [esi + NSINFO.pg_sectors]
mov [numsectors], eax
sub eax, ebx
@@:
mov esi, [ns]
mov eax, dword [esi + NSINFO.pg_sectors]
mov edx, [numsectors]
; is the buffer offset portion equal to 0?
mov ecx, [buf]
and ecx, PAGE_SIZE - 1
mov eax, [buf]
mov ecx, eax
and eax, PAGE_SIZE - 1
jnz @f
; is the number of sectors less than or equal to one memory page?
cmp edx, eax
cmp edx, ebx
jbe .success
shl eax, 1 ; it is page aligned, so set eax to 2 memory pages
@@:
; is the number of sectors greater than one or two memory pages?
cmp edx, eax
cmp edx, ebx
ja .build_prp_list
; set PRP2
mov eax, dword [buf]
mov eax, ecx
and eax, not (PAGE_SIZE - 1)
add eax, PAGE_SIZE
invoke GetPhysAddr
@ -614,40 +614,29 @@ proc alloc_dptr stdcall, ns:dword, prps_ptr:dword, numsectors:dword, prp_list_pt
jmp .success
.build_prp_list:
DEBUGF DBG_INFO, "Allocating PRP list\n"
; allocate PRP list for PRP2
xchg ecx, ebx
and ebx, not (PAGE_SIZE - 1)
add ebx, PAGE_SIZE
mov eax, [numsectors]
mov ecx, dword [esi + NSINFO.pg_sectors]
mov ecx, ebx
xor edx, edx
div ecx
;test edx, edx
;jz @f
;inc eax
;test eax, eax
;jz @f
;dec eax
@@:
mov edx, [buf]
and edx, not (PAGE_SIZE - 1)
add edx, PAGE_SIZE
stdcall build_prp_list, eax, edx, [prp_list_ptr]
stdcall build_prp_list, eax, ebx, [prp_list_ptr]
test eax, eax
jz .err
mov dword [edi + 4], eax
jmp .success
.err:
xor eax, eax
pop edi esi
ret
.success:
xor eax, eax
inc eax
pop edi esi
pop edi esi ebx
ret
.err:
xor eax, eax
pop edi esi ebx
ret
endp
nvme_read:
@ -1120,10 +1109,6 @@ proc nvme_init stdcall, pci:dword
jne .exit_fail
mov dword [ebx + NSINFO.lbads], eax
mov eax, PAGE_SIZE
mov cl, dl
shr eax, cl
mov dword [ebx + NSINFO.pg_sectors], eax
invoke KernelFree, edi
if 0
invoke KernelAlloc, 0x6000

View File

@ -311,10 +311,9 @@ ends
struct NSINFO
capacity dq ?
size dq ?
lbads dd ?
nsid dd ?
pg_sectors dd ? ; how many sectors equal 1 page?
pci dd ?
lbads db ?
features db ?
ends