forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/arch/mips/fw/arc/memory.c
....@@ -17,15 +17,19 @@
1717 #include <linux/types.h>
1818 #include <linux/sched.h>
1919 #include <linux/mm.h>
20
-#include <linux/bootmem.h>
20
+#include <linux/memblock.h>
2121 #include <linux/swap.h>
2222
2323 #include <asm/sgialib.h>
2424 #include <asm/page.h>
25
-#include <asm/pgtable.h>
2625 #include <asm/bootinfo.h>
2726
2827 #undef DEBUG
28
+
29
+#define MAX_PROM_MEM 5
30
+static phys_addr_t prom_mem_base[MAX_PROM_MEM] __initdata;
31
+static phys_addr_t prom_mem_size[MAX_PROM_MEM] __initdata;
32
+static unsigned int nr_prom_mem __initdata;
2933
3034 /*
3135 * For ARC firmware memory functions the unit of meassuring memory is always
....@@ -64,20 +68,24 @@
6468 : arc_mtypes[a.arc]
6569 #endif
6670
71
+enum {
72
+ mem_free, mem_prom_used, mem_reserved
73
+};
74
+
6775 static inline int memtype_classify_arcs(union linux_memtypes type)
6876 {
6977 switch (type.arcs) {
7078 case arcs_fcontig:
7179 case arcs_free:
72
- return BOOT_MEM_RAM;
80
+ return mem_free;
7381 case arcs_atmp:
74
- return BOOT_MEM_ROM_DATA;
82
+ return mem_prom_used;
7583 case arcs_eblock:
7684 case arcs_rvpage:
7785 case arcs_bmem:
7886 case arcs_prog:
7987 case arcs_aperm:
80
- return BOOT_MEM_RESERVED;
88
+ return mem_reserved;
8189 default:
8290 BUG();
8391 }
....@@ -89,15 +97,15 @@
8997 switch (type.arc) {
9098 case arc_free:
9199 case arc_fcontig:
92
- return BOOT_MEM_RAM;
100
+ return mem_free;
93101 case arc_atmp:
94
- return BOOT_MEM_ROM_DATA;
102
+ return mem_prom_used;
95103 case arc_eblock:
96104 case arc_rvpage:
97105 case arc_bmem:
98106 case arc_prog:
99107 case arc_aperm:
100
- return BOOT_MEM_RESERVED;
108
+ return mem_reserved;
101109 default:
102110 BUG();
103111 }
....@@ -112,7 +120,7 @@
112120 return memtype_classify_arc(type);
113121 }
114122
115
-void __init prom_meminit(void)
123
+void __weak __init prom_meminit(void)
116124 {
117125 struct linux_mdesc *p;
118126
....@@ -129,6 +137,7 @@
129137 }
130138 #endif
131139
140
+ nr_prom_mem = 0;
132141 p = PROM_NULL_MDESC;
133142 while ((p = ArcGetMemoryDescriptor(p))) {
134143 unsigned long base, size;
....@@ -138,24 +147,46 @@
138147 size = p->pages << ARC_PAGE_SHIFT;
139148 type = prom_memtype_classify(p->type);
140149
141
- add_memory_region(base, size, type);
150
+ /* ignore mirrored RAM on IP28/IP30 */
151
+ if (base < PHYS_OFFSET)
152
+ continue;
153
+
154
+ memblock_add(base, size);
155
+
156
+ if (type == mem_reserved)
157
+ memblock_reserve(base, size);
158
+
159
+ if (type == mem_prom_used) {
160
+ memblock_reserve(base, size);
161
+ if (nr_prom_mem >= 5) {
162
+ pr_err("Too many ROM DATA regions");
163
+ continue;
164
+ }
165
+ prom_mem_base[nr_prom_mem] = base;
166
+ prom_mem_size[nr_prom_mem] = size;
167
+ nr_prom_mem++;
168
+ }
142169 }
143170 }
144171
145
-void __init prom_free_prom_memory(void)
172
+void __weak __init prom_cleanup(void)
146173 {
147
- unsigned long addr;
174
+}
175
+
176
+void __weak __init prom_free_prom_memory(void)
177
+{
148178 int i;
149179
150180 if (prom_flags & PROM_FLAG_DONT_FREE_TEMP)
151181 return;
152182
153
- for (i = 0; i < boot_mem_map.nr_map; i++) {
154
- if (boot_mem_map.map[i].type != BOOT_MEM_ROM_DATA)
155
- continue;
156
-
157
- addr = boot_mem_map.map[i].addr;
183
+ for (i = 0; i < nr_prom_mem; i++) {
158184 free_init_pages("prom memory",
159
- addr, addr + boot_mem_map.map[i].size);
185
+ prom_mem_base[i], prom_mem_base[i] + prom_mem_size[i]);
160186 }
187
+ /*
188
+ * at this point it isn't safe to call PROM functions
189
+ * give platforms a way to do PROM cleanups
190
+ */
191
+ prom_cleanup();
161192 }