blob: 79eb19992d058b53c04404c259485974c2144c1d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
// SPDX-License-Identifier: GPL-2.0+
/*
* Onboard memory detection for Snapdragon boards
*
* (C) Copyright 2018 Ramon Fried <ramon.fried@gmail.com>
*
*/
#include <common.h>
#include <dm.h>
#include <smem.h>
#include <fdt_support.h>
#include <asm/arch/dram.h>
#define SMEM_USABLE_RAM_PARTITION_TABLE 402
#define RAM_PART_NAME_LENGTH 16
#define RAM_NUM_PART_ENTRIES 32
#define CATEGORY_SDRAM 0x0E
#define TYPE_SYSMEM 0x01
struct smem_ram_ptable_hdr {
u32 magic[2];
u32 version;
u32 reserved;
u32 len;
} __attribute__ ((__packed__));
struct smem_ram_ptn {
char name[RAM_PART_NAME_LENGTH];
u64 start;
u64 size;
u32 attr;
u32 category;
u32 domain;
u32 type;
u32 num_partitions;
u32 reserved[3];
} __attribute__ ((__packed__));
struct smem_ram_ptable {
struct smem_ram_ptable_hdr hdr;
u32 reserved; /* Added for 8 bytes alignment of header */
struct smem_ram_ptn parts[RAM_NUM_PART_ENTRIES];
} __attribute__ ((__packed__));
#ifndef MEMORY_BANKS_MAX
#define MEMORY_BANKS_MAX 4
#endif
int msm_fixup_memory(void *blob)
{
u64 bank_start[MEMORY_BANKS_MAX];
u64 bank_size[MEMORY_BANKS_MAX];
size_t size;
int i;
int count = 0;
struct udevice *smem;
int ret;
struct smem_ram_ptable *ram_ptable;
struct smem_ram_ptn *p;
ret = uclass_get_device_by_name(UCLASS_SMEM, "smem", &smem);
if (ret < 0) {
printf("Failed to find SMEM node. Check device tree\n");
return 0;
}
ram_ptable = smem_get(smem, -1, SMEM_USABLE_RAM_PARTITION_TABLE, &size);
if (!ram_ptable) {
printf("Failed to find SMEM partition.\n");
return -ENODEV;
}
/* Check validy of RAM */
for (i = 0; i < RAM_NUM_PART_ENTRIES; i++) {
p = &ram_ptable->parts[i];
if (p->category == CATEGORY_SDRAM && p->type == TYPE_SYSMEM) {
bank_start[count] = p->start;
bank_size[count] = p->size;
debug("Detected memory bank %u: start: 0x%llx size: 0x%llx\n",
count, p->start, p->size);
count++;
}
}
if (!count) {
printf("Failed to detect any memory bank\n");
return -ENODEV;
}
ret = fdt_fixup_memory_banks(blob, bank_start, bank_size, count);
if (ret)
return ret;
return 0;
}
|