Home | History | Annotate | Download | only in Armada70x0Lib
      1 /*******************************************************************************
      2 Copyright (C) 2016 Marvell International Ltd.
      3 
      4 Marvell BSD License Option
      5 
      6 If you received this File from Marvell, you may opt to use, redistribute and/or
      7 modify this File under the following licensing terms.
      8 Redistribution and use in source and binary forms, with or without modification,
      9 are permitted provided that the following conditions are met:
     10 
     11 * Redistributions of source code must retain the above copyright notice,
     12  this list of conditions and the following disclaimer.
     13 
     14 * Redistributions in binary form must reproduce the above copyright
     15  notice, this list of conditions and the following disclaimer in the
     16  documentation and/or other materials provided with the distribution.
     17 
     18 * Neither the name of Marvell nor the names of its contributors may be
     19  used to endorse or promote products derived from this software without
     20  specific prior written permission.
     21 
     22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
     23 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     24 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     25 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
     26 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     27 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     28 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
     29 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     31 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32 
     33 *******************************************************************************/
     34 
     35 #include <Base.h>
     36 #include <Library/ArmPlatformLib.h>
     37 #include <Library/DebugLib.h>
     38 #include <Library/MemoryAllocationLib.h>
     39 
     40 // The total number of descriptors, including the final "end-of-table" descriptor.
     41 #define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 16
     42 
     43 // DDR attributes
     44 #define DDR_ATTRIBUTES_CACHED           ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_BACK
     45 #define DDR_ATTRIBUTES_UNCACHED         ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED
     46 
     47 /**
     48   Return the Virtual Memory Map of your platform
     49 
     50   This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU on your platform.
     51 
     52   @param[out]   VirtualMemoryMap    Array of ARM_MEMORY_REGION_DESCRIPTOR describing a Physical-to-
     53                                     Virtual Memory mapping. This array must be ended by a zero-filled
     54                                     entry
     55 
     56 **/
     57 VOID
     58 ArmPlatformGetVirtualMemoryMap (
     59   IN ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap
     60   )
     61 {
     62   ARM_MEMORY_REGION_DESCRIPTOR  *VirtualMemoryTable;
     63   UINTN                         Index = 0;
     64 
     65   ASSERT (VirtualMemoryMap != NULL);
     66 
     67   VirtualMemoryTable = (ARM_MEMORY_REGION_DESCRIPTOR*)AllocatePages(EFI_SIZE_TO_PAGES (sizeof(ARM_MEMORY_REGION_DESCRIPTOR) * MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS));
     68   if (VirtualMemoryTable == NULL) {
     69       return;
     70   }
     71 
     72   // DDR
     73   VirtualMemoryTable[Index].PhysicalBase    = PcdGet64 (PcdSystemMemoryBase);
     74   VirtualMemoryTable[Index].VirtualBase     = PcdGet64 (PcdSystemMemoryBase);
     75   VirtualMemoryTable[Index].Length          = PcdGet64 (PcdSystemMemorySize);
     76   VirtualMemoryTable[Index].Attributes      = DDR_ATTRIBUTES_CACHED;
     77 
     78   // Configuration space 0xF000_0000 - 0xFFFF_FFFF
     79   VirtualMemoryTable[++Index].PhysicalBase  = 0xF0000000;
     80   VirtualMemoryTable[Index].VirtualBase     = 0xF0000000;
     81   VirtualMemoryTable[Index].Length          = 0x10000000;
     82   VirtualMemoryTable[Index].Attributes      = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
     83 
     84   // End of Table
     85   VirtualMemoryTable[++Index].PhysicalBase  = 0;
     86   VirtualMemoryTable[Index].VirtualBase     = 0;
     87   VirtualMemoryTable[Index].Length          = 0;
     88   VirtualMemoryTable[Index].Attributes      = 0;
     89 
     90   ASSERT((Index + 1) <= MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS);
     91 
     92   *VirtualMemoryMap = VirtualMemoryTable;
     93 }
     94