From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: None (no SPF record) identity=mailfrom; client-ip=2a00:1450:4864:20::142; helo=mail-lf1-x142.google.com; envelope-from=mw@semihalf.com; receiver=edk2-devel@lists.01.org Received: from mail-lf1-x142.google.com (mail-lf1-x142.google.com [IPv6:2a00:1450:4864:20::142]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 2FFFB211B5A34 for ; Mon, 28 Jan 2019 01:45:40 -0800 (PST) Received: by mail-lf1-x142.google.com with SMTP id a8so11330875lfk.5 for ; Mon, 28 Jan 2019 01:45:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=yVlPhJUkPzZ/YGx0a1tNUzZo+GKVoo5TL9WUBz9bCLY=; b=kLu8/lVsbN22yZta72rRVr3NjIJcDbQelWD0xB3AH4g6oADIdg7EfZTuovhXZi1fP8 182+jtm/j4W1lP6nsQj8DLOyWH9/qGf7YWjCnQC6y4XNge6WtIapI5MwHFdko6XCBaFa ScsVqS4EjwIuaxYxRhpV0zP1ydVYWMjikObqiGmO8N2K5AhyXR6XhTEEVJALcUKTiZyz XwvWU2z2lgPc+alpKPJV6UzMNdMkktvEA1wvCQEaE3MZLQcVmjbUcG75q46p8LxPRAtp DAiE1XjXkA7uozkRxu7Di8LpKVP9gGm4ZTcJWbTqnaA5GTprpf8a7hYQFCG0rx9Bzu8D sOSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=yVlPhJUkPzZ/YGx0a1tNUzZo+GKVoo5TL9WUBz9bCLY=; b=LMWzzqIqEveT9+NMdDl1CIDB1xuBvFkO6dKbA1O40+xfX5TVJxjp+mCRFcpXZh8wP/ 8cJdxQi2a8C7WOTsphTNHmczzgWqq8qrCjYq1M3sAFert4BcickEgTYX5AvDQ2dsMree OZdVWa9fJUf1pcllV8d0Sr8iQ9fHnWzXOCENIXwWb2zn235Yket8Y+acxKDnG7TaNulL dzb7KbU/GlnmhB/xr0vaAMmFc5Yo8GrNQujKEFiwcMEGSylA+bJ1ySDF9g0G/CJSB63t SmIX5/I7hdlbNmEJzIGw7vkjjnWWaCWavG5g+EqRkVbZ7i9itVHE1mkiON/n2jFdwWlF vSiw== X-Gm-Message-State: AJcUukdwYDYdkrmMNi15I6szmKRFTe4Ay0IXRMXWRSSx8egRY4VLGAsN xm57/23mPBvbBZmnp31ofUEAHo7HaxA= X-Google-Smtp-Source: ALg8bN7cmyCktlBBW6fWXl2wmEjDnejxYoz/xq0L+gsmsIPFFtQxSVzf43bzHhDqjBRaLCzVSsIcNQ== X-Received: by 2002:a19:8c1b:: with SMTP id o27mr15372336lfd.90.1548668737986; Mon, 28 Jan 2019 01:45:37 -0800 (PST) Received: from gilgamesh.semihalf.com (31-172-191-173.noc.fibertech.net.pl. [31.172.191.173]) by smtp.gmail.com with ESMTPSA id 10sm2895213ljr.4.2019.01.28.01.45.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 28 Jan 2019 01:45:37 -0800 (PST) From: Marcin Wojtas To: edk2-devel@lists.01.org Cc: leif.lindholm@linaro.org, ard.biesheuvel@linaro.org, nadavh@marvell.com, mw@semihalf.com, jsd@semihalf.com, jaz@semihalf.com, kostap@marvell.com Date: Mon, 28 Jan 2019 10:45:11 +0100 Message-Id: <1548668715-15042-2-git-send-email-mw@semihalf.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1548668715-15042-1-git-send-email-mw@semihalf.com> References: <1548668715-15042-1-git-send-email-mw@semihalf.com> Subject: [platforms: PATCH v3 1/5] Marvell/Armada7k8k: Refactor reserving memory regions X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Jan 2019 09:45:40 -0000 X-List-Received-Date: Mon, 28 Jan 2019 09:45:40 -0000 X-List-Received-Date: Mon, 28 Jan 2019 09:45:40 -0000 X-List-Received-Date: Mon, 28 Jan 2019 09:45:40 -0000 X-List-Received-Date: Mon, 28 Jan 2019 09:45:40 -0000 X-List-Received-Date: Mon, 28 Jan 2019 09:45:40 -0000 X-List-Received-Date: Mon, 28 Jan 2019 09:45:40 -0000 X-List-Received-Date: Mon, 28 Jan 2019 09:45:40 -0000 X-List-Received-Date: Mon, 28 Jan 2019 09:45:40 -0000 X-List-Received-Date: Mon, 28 Jan 2019 09:45:40 -0000 X-List-Received-Date: Mon, 28 Jan 2019 09:45:40 -0000 X-List-Received-Date: Mon, 28 Jan 2019 09:45:40 -0000 X-List-Received-Date: Mon, 28 Jan 2019 09:45:40 -0000 X-List-Received-Date: Mon, 28 Jan 2019 09:45:40 -0000 X-List-Received-Date: Mon, 28 Jan 2019 09:45:40 -0000 X-List-Received-Date: Mon, 28 Jan 2019 09:45:40 -0000 X-List-Received-Date: Mon, 28 Jan 2019 09:45:40 -0000 X-List-Received-Date: Mon, 28 Jan 2019 09:45:40 -0000 X-List-Received-Date: Mon, 28 Jan 2019 09:45:40 -0000 X-List-Received-Date: Mon, 28 Jan 2019 09:45:40 -0000 X-List-Received-Date: Mon, 28 Jan 2019 09:45:40 -0000 X-List-Received-Date: Mon, 28 Jan 2019 09:45:40 -0000 X-List-Received-Date: Mon, 28 Jan 2019 09:45:40 -0000 X-List-Received-Date: Mon, 28 Jan 2019 09:45:40 -0000 Extract reserving memory region in the Hob list into a separate routine. It is a preparation for adding multiple of such regions in a following patch. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Marcin Wojtas --- Silicon/Marvell/Armada7k8k/Library/Armada7k8kMemoryInitPeiLib/Armada7k8kMemoryInitPeiLib.c | 95 +++++++++++++------- 1 file changed, 61 insertions(+), 34 deletions(-) diff --git a/Silicon/Marvell/Armada7k8k/Library/Armada7k8kMemoryInitPeiLib/Armada7k8kMemoryInitPeiLib.c b/Silicon/Marvell/Armada7k8k/Library/Armada7k8kMemoryInitPeiLib/Armada7k8kMemoryInitPeiLib.c index 53119f4..3e7902f 100644 --- a/Silicon/Marvell/Armada7k8k/Library/Armada7k8kMemoryInitPeiLib/Armada7k8kMemoryInitPeiLib.c +++ b/Silicon/Marvell/Armada7k8k/Library/Armada7k8kMemoryInitPeiLib/Armada7k8kMemoryInitPeiLib.c @@ -49,40 +49,31 @@ InitMmu ( Routine Description: - + Remove the reserved region from a System Memory Hob that covers it. Arguments: FileHandle - Handle of the file being invoked. PeiServices - Describes the list of possible PEI Services. -Returns: - - Status - EFI_SUCCESS if the boot mode could be set - --*/ -EFI_STATUS -EFIAPI -MemoryPeim ( - IN EFI_PHYSICAL_ADDRESS UefiMemoryBase, - IN UINT64 UefiMemorySize +STATIC +VOID +ReserveMemoryRegion ( + IN EFI_PHYSICAL_ADDRESS ReservedRegionBase, + IN UINT32 ReservedRegionSize ) { - ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable; EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttributes; - UINT64 ResourceLength; - EFI_PEI_HOB_POINTERS NextHob; - EFI_PHYSICAL_ADDRESS SecureTop; + EFI_PHYSICAL_ADDRESS ReservedRegionTop; EFI_PHYSICAL_ADDRESS ResourceTop; + EFI_PEI_HOB_POINTERS NextHob; + UINT64 ResourceLength; - // Get Virtual Memory Map from the Platform Library - ArmPlatformGetVirtualMemoryMap (&MemoryTable); - - SecureTop = (EFI_PHYSICAL_ADDRESS)FixedPcdGet64 (PcdSecureRegionBase) + - FixedPcdGet32 (PcdSecureRegionSize); + ReservedRegionTop = ReservedRegionBase + ReservedRegionSize; // - // Search for System Memory Hob that covers the secure firmware, + // Search for System Memory Hob that covers the reserved region, // and punch a hole in it // for (NextHob.Raw = GetHobList (); @@ -91,31 +82,32 @@ MemoryPeim ( NextHob.Raw)) { if ((NextHob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) && - (FixedPcdGet64 (PcdSecureRegionBase) >= NextHob.ResourceDescriptor->PhysicalStart) && - (SecureTop <= NextHob.ResourceDescriptor->PhysicalStart + + (ReservedRegionBase >= NextHob.ResourceDescriptor->PhysicalStart) && + (ReservedRegionTop <= NextHob.ResourceDescriptor->PhysicalStart + NextHob.ResourceDescriptor->ResourceLength)) { ResourceAttributes = NextHob.ResourceDescriptor->ResourceAttribute; ResourceLength = NextHob.ResourceDescriptor->ResourceLength; ResourceTop = NextHob.ResourceDescriptor->PhysicalStart + ResourceLength; - if (FixedPcdGet64 (PcdSecureRegionBase) == NextHob.ResourceDescriptor->PhysicalStart) { + if (ReservedRegionBase == NextHob.ResourceDescriptor->PhysicalStart) { // // This region starts right at the start of the reserved region, so we // can simply move its start pointer and reduce its length by the same // value // - NextHob.ResourceDescriptor->PhysicalStart += FixedPcdGet32 (PcdSecureRegionSize); - NextHob.ResourceDescriptor->ResourceLength -= FixedPcdGet32 (PcdSecureRegionSize); + NextHob.ResourceDescriptor->PhysicalStart += ReservedRegionSize; + NextHob.ResourceDescriptor->ResourceLength -= ReservedRegionSize; } else if ((NextHob.ResourceDescriptor->PhysicalStart + - NextHob.ResourceDescriptor->ResourceLength) == SecureTop) { + NextHob.ResourceDescriptor->ResourceLength) == + ReservedRegionTop) { // // This region ends right at the end of the reserved region, so we // can simply reduce its length by the size of the region. // - NextHob.ResourceDescriptor->ResourceLength -= FixedPcdGet32 (PcdSecureRegionSize); + NextHob.ResourceDescriptor->ResourceLength -= ReservedRegionSize; } else { // @@ -123,28 +115,63 @@ MemoryPeim ( // each one touching the reserved region at either end, but not covering // it. // - NextHob.ResourceDescriptor->ResourceLength = FixedPcdGet64 (PcdSecureRegionBase) - - NextHob.ResourceDescriptor->PhysicalStart; + NextHob.ResourceDescriptor->ResourceLength = + ReservedRegionBase - NextHob.ResourceDescriptor->PhysicalStart; // Create the System Memory HOB for the remaining region (top of the FD) BuildResourceDescriptorHob (EFI_RESOURCE_SYSTEM_MEMORY, ResourceAttributes, - SecureTop, - ResourceTop - SecureTop); + ReservedRegionTop, + ResourceTop - ReservedRegionTop); } // - // Reserve the memory space occupied by the secure firmware + // Reserve the memory space. // BuildResourceDescriptorHob (EFI_RESOURCE_MEMORY_RESERVED, 0, - FixedPcdGet64 (PcdSecureRegionBase), - FixedPcdGet32 (PcdSecureRegionSize)); + ReservedRegionBase, + ReservedRegionSize); break; } NextHob.Raw = GET_NEXT_HOB (NextHob); } +} + +/*++ + +Routine Description: + + + +Arguments: + + FileHandle - Handle of the file being invoked. + PeiServices - Describes the list of possible PEI Services. + +Returns: + + Status - EFI_SUCCESS if the boot mode could be set + +--*/ +EFI_STATUS +EFIAPI +MemoryPeim ( + IN EFI_PHYSICAL_ADDRESS UefiMemoryBase, + IN UINT64 UefiMemorySize + ) +{ + ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable; + + // Get Virtual Memory Map from the Platform Library + ArmPlatformGetVirtualMemoryMap (&MemoryTable); + + // Reserve memory region for secure firmware + ReserveMemoryRegion ( + (EFI_PHYSICAL_ADDRESS)FixedPcdGet64 (PcdSecureRegionBase), + FixedPcdGet32 (PcdSecureRegionSize) + ); // Build Memory Allocation Hob InitMmu (MemoryTable); -- 2.7.4