| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
#include <platform_def.h> |
| 9 |
|
| 10 |
#include <common/debug.h> |
| 11 |
#include <lib/mmio.h> |
| 12 |
|
| 13 |
#include <ddr_info.h> |
| 14 |
|
| 15 |
#define DRAM_CH0_MMAP_LOW_REG(iface, cs, base) \ |
| 16 |
(base + DRAM_CH0_MMAP_LOW_OFFSET + (iface) * 0x10000 + (cs) * 0x8) |
| 17 |
#define DRAM_CH0_MMAP_HIGH_REG(iface, cs, base) \ |
| 18 |
(DRAM_CH0_MMAP_LOW_REG(iface, cs, base) + 4) |
| 19 |
#define DRAM_CS_VALID_ENABLED_MASK 0x1 |
| 20 |
#define DRAM_AREA_LENGTH_OFFS 16 |
| 21 |
#define DRAM_AREA_LENGTH_MASK (0x1f << DRAM_AREA_LENGTH_OFFS) |
| 22 |
#define DRAM_START_ADDRESS_L_OFFS 23 |
| 23 |
#define DRAM_START_ADDRESS_L_MASK \ |
| 24 |
(0x1ff << DRAM_START_ADDRESS_L_OFFS) |
| 25 |
#define DRAM_START_ADDR_HTOL_OFFS 32 |
| 26 |
|
| 27 |
#define DRAM_MAX_CS_NUM 2 |
| 28 |
|
| 29 |
#define DRAM_CS_ENABLED(iface, cs, base) \ |
| 30 |
(mmio_read_32(DRAM_CH0_MMAP_LOW_REG(iface, cs, base)) & \ |
| 31 |
DRAM_CS_VALID_ENABLED_MASK) |
| 32 |
#define GET_DRAM_REGION_SIZE_CODE(iface, cs, base) \ |
| 33 |
(mmio_read_32(DRAM_CH0_MMAP_LOW_REG(iface, cs, base)) & \ |
| 34 |
DRAM_AREA_LENGTH_MASK) >> DRAM_AREA_LENGTH_OFFS |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
#define DRAM_REGION_SIZE_EVEN(C) (((C) >= 7) && ((C) <= 26)) |
| 72 |
#define GET_DRAM_REGION_SIZE_EVEN(C) ((uint64_t)1 << ((C) + 16)) |
| 73 |
#define DRAM_REGION_SIZE_ODD(C) ((C) <= 4) |
| 74 |
#define GET_DRAM_REGION_SIZE_ODD(C) ((uint64_t)0x18000000 << (C)) |
| 75 |
|
| 76 |
|
| 77 |
uint64_t mvebu_get_dram_size(uint64_t ap_base_addr) |
| 78 |
{ |
| 79 |
uint64_t mem_size = 0; |
| 80 |
uint8_t region_code; |
| 81 |
uint8_t cs, iface; |
| 82 |
|
| 83 |
for (iface = 0; iface < DRAM_MAX_IFACE; iface++) { |
| 84 |
for (cs = 0; cs < DRAM_MAX_CS_NUM; cs++) { |
| 85 |
|
| 86 |
|
| 87 |
if (!DRAM_CS_ENABLED(iface, cs, ap_base_addr)) |
| 88 |
break; |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
region_code = |
| 94 |
GET_DRAM_REGION_SIZE_CODE(iface, cs, |
| 95 |
ap_base_addr); |
| 96 |
|
| 97 |
if (DRAM_REGION_SIZE_EVEN(region_code)) { |
| 98 |
mem_size += |
| 99 |
GET_DRAM_REGION_SIZE_EVEN(region_code); |
| 100 |
} else if (DRAM_REGION_SIZE_ODD(region_code)) { |
| 101 |
mem_size += |
| 102 |
GET_DRAM_REGION_SIZE_ODD(region_code); |
| 103 |
} else { |
| 104 |
WARN("%s: Invalid mem region (0x%x) CS#%d\n", |
| 105 |
__func__, region_code, cs); |
| 106 |
return 0; |
| 107 |
} |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
return mem_size; |
| 112 |
} |