From 39dcfd2edc3b139e914370cd15fea37a91bff7de Mon Sep 17 00:00:00 2001 From: Abdur-Rahman Mansoor Date: Tue, 23 Jul 2024 14:10:42 -0400 Subject: [PATCH] perf: remove some unneeded code bloat --- drivers/nvme/nvme.asm | 67 +++++++++++++++++-------------------------- drivers/nvme/nvme.inc | 3 +- 2 files changed, 27 insertions(+), 43 deletions(-) diff --git a/drivers/nvme/nvme.asm b/drivers/nvme/nvme.asm index 6f3d8e9..f8208cd 100644 --- a/drivers/nvme/nvme.asm +++ b/drivers/nvme/nvme.asm @@ -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 diff --git a/drivers/nvme/nvme.inc b/drivers/nvme/nvme.inc index 87e38ab..2c8d4d8 100644 --- a/drivers/nvme/nvme.inc +++ b/drivers/nvme/nvme.inc @@ -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