From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by mx.groups.io with SMTP id smtpd.web09.2219.1576063567791004444 for ; Wed, 11 Dec 2019 03:26:08 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@akeo-ie.20150623.gappssmtp.com header.s=20150623 header.b=fHeSWffv; spf=none, err=permanent DNS error (domain: akeo.ie, ip: 209.85.221.66, mailfrom: pete@akeo.ie) Received: by mail-wr1-f66.google.com with SMTP id q6so2133632wro.9 for ; Wed, 11 Dec 2019 03:26:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=akeo-ie.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=x+yXos6xtvfQqTcrzNXTDrIbisCsCT92CsTa3kVM79k=; b=fHeSWffvTrATozPuA3LYKu97bjozwA9DdQbM79lrdt7YbwWmnVuItAvgvfOOAI8lhr mUtt9SKBM3SdttMJx2seqN5rdYkicfwDXdoZU01NMty8KqS/kbz3dYZzH370Ariyaee4 C+AJj4/ZB5BJ9PqAzJ/iENM9ttEf9b+DCTINK01YBy7z6vv4XZDqqrPFfODaQsJwfgg4 19/mJrqHdCbNOauFx3w9UJV2OnJV6jk8AL8dQrhXyO4Y/6aX+x6lf2rDBu8N06oEqm8v +BzMuswsx+6pLt/xh1fLcoeNIuazW+WbV0IPImUER8cXiktSM2R7hTwH1+Kg7xnrPjtx gAJg== 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:mime-version:content-transfer-encoding; bh=x+yXos6xtvfQqTcrzNXTDrIbisCsCT92CsTa3kVM79k=; b=kAOTAqj6F4NxGFBXXX9I0mDYikTdfqEM80WJCNp3NJkvc54RIl0i8NMaoUbCvlq01F vo+6uWpwArygw+02RMTkIhbl6eiAEeZmJTfCYrjMHXF7JGiF2M0IUBr2BhqSHzQf/4qx 5KHLnWsNLiklDDkpEShyi265QX7yopUCuUjC384ZTgxkzcFZ5v0dsu3dSJoA/R4ytbB2 K1GMMVHAZJBFkxTflYlLtqafAiRG1jRAtPVbJzSAMTqNgHOtjr37xC6jFsFYm5B5HG8o 5fHCXvCdXicLfaIz2atx244o48ArERuyhpuVpPCqXb58ZZ+VNpSrudNIxc8G5I1vi/3J 0AKg== X-Gm-Message-State: APjAAAUBtcVho0SSElAJtsR56kNLmGa1fg11Whi8hYaiVBmOuUZFMmRe 226T8YrbT96zFOXU+2SeeQmYKmCDjdORgA== X-Google-Smtp-Source: APXvYqzYVjtzvYcpjy2zW5QBrAdjIH8P+BFrUZ9KU2BKvepONDjZudjtMDqiYyZ/nyvQ3HB1IeCMtQ== X-Received: by 2002:adf:dd46:: with SMTP id u6mr3330343wrm.13.1576063566005; Wed, 11 Dec 2019 03:26:06 -0800 (PST) Return-Path: Received: from localhost.localdomain ([84.203.45.230]) by smtp.gmail.com with ESMTPSA id q8sm190460wmq.3.2019.12.11.03.26.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Dec 2019 03:26:05 -0800 (PST) From: "Pete Batard" To: devel@edk2.groups.io Cc: ard.biesheuvel@linaro.org, leif.lindholm@linaro.org, philmd@redhat.com, andrey.warkentin@gmail.com, samer.el-haj-mahmoud@arm.com Subject: [edk2-platforms][PATCH 1/5] Platform/RPi: Fix overlap of SoC registers and RAM Date: Wed, 11 Dec 2019 11:25:48 +0000 Message-Id: <20191211112552.15900-2-pete@akeo.ie> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20191211112552.15900-1-pete@akeo.ie> References: <20191211112552.15900-1-pete@akeo.ie> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Ard Biesheuvel Having RAM and SoC register regions overlap is problematic for MMIO, since, at the very least, we don't want these regions to be declared as cacheable. Signed-off-by: Pete Batard --- Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c | 36 +++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c b/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c index cc761bea1307..781cf78b83d3 100644 --- a/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c +++ b/Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c @@ -60,7 +60,7 @@ ArmPlatformGetVirtualMemoryMap ( { UINTN Index = 0; UINTN GpuIndex; - INT64 ExtendedMemorySize; + INT64 SystemMemorySize; ARM_MEMORY_REGION_DESCRIPTOR *VirtualMemoryTable; // Early output of the info we got from VideoCore can prove valuable. @@ -120,21 +120,21 @@ ArmPlatformGetVirtualMemoryMap ( VirtualMemoryInfo[Index].Type = RPI_MEM_RESERVED_REGION; VirtualMemoryInfo[Index++].Name = L"GPU Reserved"; - // Compute the amount of extended RAM available on this platform - ExtendedMemorySize = SIZE_256MB; - ExtendedMemorySize <<= (mBoardRevision >> 20) & 0x07; - ExtendedMemorySize -= SIZE_1GB; - if (ExtendedMemorySize > 0) { - VirtualMemoryTable[Index].PhysicalBase = FixedPcdGet64 (PcdExtendedMemoryBase); - VirtualMemoryTable[Index].VirtualBase = VirtualMemoryTable[Index].PhysicalBase; - VirtualMemoryTable[Index].Length = ExtendedMemorySize; - VirtualMemoryTable[Index].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK; - VirtualMemoryInfo[Index].Type = RPI_MEM_BASIC_REGION; - VirtualMemoryInfo[Index++].Name = L"Extended System RAM"; - } + // Compute the total RAM size available on this platform + SystemMemorySize = SIZE_256MB; + SystemMemorySize <<= (mBoardRevision >> 20) & 0x07; + + // + // Ensure that what we declare as System Memory doesn't overlap with the + // Bcm2836 SoC registers. This can be achieved through a MIN () with the + // base address since SystemMemoryBase is 0 (we assert if it isn't). + // + SystemMemorySize = MIN(SystemMemorySize, BCM2836_SOC_REGISTERS); // Extended SoC registers (PCIe, genet, ...) if (BCM2711_SOC_REGISTERS > 0) { + // Same overlap protection as above for the Bcm2711 SoC registers + SystemMemorySize = MIN(SystemMemorySize, BCM2711_SOC_REGISTERS); VirtualMemoryTable[Index].PhysicalBase = BCM2711_SOC_REGISTERS; VirtualMemoryTable[Index].VirtualBase = VirtualMemoryTable[Index].PhysicalBase; VirtualMemoryTable[Index].Length = BCM2711_SOC_REGISTER_LENGTH; @@ -155,6 +155,16 @@ ArmPlatformGetVirtualMemoryMap ( VirtualMemoryInfo[Index].Type = RPI_MEM_RESERVED_REGION; VirtualMemoryInfo[Index++].Name = L"SoC Reserved (283x)"; + // If we have RAM above the 1 GB mark, declare it + if (SystemMemorySize - SIZE_1GB > 0) { + VirtualMemoryTable[Index].PhysicalBase = FixedPcdGet64 (PcdExtendedMemoryBase); + VirtualMemoryTable[Index].VirtualBase = VirtualMemoryTable[Index].PhysicalBase; + VirtualMemoryTable[Index].Length = SystemMemorySize - SIZE_1GB; + VirtualMemoryTable[Index].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK; + VirtualMemoryInfo[Index].Type = RPI_MEM_BASIC_REGION; + VirtualMemoryInfo[Index++].Name = L"Extended System RAM"; + } + // End of Table VirtualMemoryTable[Index].PhysicalBase = 0; VirtualMemoryTable[Index].VirtualBase = 0; -- 2.21.0.windows.1