1 // SPDX-License-Identifier: GPL-2.0
3 * memory.c: PROM library functions for acquiring/using memory descriptors
4 * given to us from the ARCS firmware.
6 * Copyright (C) 1996 by David S. Miller
7 * Copyright (C) 1999, 2000, 2001 by Ralf Baechle
8 * Copyright (C) 1999, 2000 by Silicon Graphics, Inc.
10 * PROM library functions for acquiring/using memory descriptors given to us
11 * from the ARCS firmware. This is only used when CONFIG_ARC_MEMORY is set
12 * because on some machines like SGI IP27 the ARC memory configuration data
13 * completely bogus and alternate easier to use mechanisms are available.
15 #include <linux/init.h>
16 #include <linux/kernel.h>
17 #include <linux/types.h>
18 #include <linux/sched.h>
20 #include <linux/memblock.h>
21 #include <linux/swap.h>
23 #include <asm/sgialib.h>
25 #include <asm/bootinfo.h>
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;
35 * For ARC firmware memory functions the unit of meassuring memory is always
38 #define ARC_PAGE_SHIFT 12
40 struct linux_mdesc * __init ArcGetMemoryDescriptor(struct linux_mdesc *Current)
42 return (struct linux_mdesc *) ARC_CALL1(get_mdesc, Current);
45 #ifdef DEBUG /* convenient for debugging */
46 static char *arcs_mtypes[8] = {
52 "Standalone Program Pages",
53 "ARCS Temp Storage Area",
54 "ARCS Permanent Storage Area"
57 static char *arc_mtypes[8] = {
59 "SystemParameterBlock",
67 #define mtypes(a) (prom_flags & PROM_FLAG_ARCS) ? arcs_mtypes[a.arcs] \
72 mem_free, mem_prom_used, mem_reserved
75 static inline int memtype_classify_arcs(union linux_memtypes type)
92 while(1); /* Nuke warning. */
95 static inline int memtype_classify_arc(union linux_memtypes type)
102 return mem_prom_used;
112 while(1); /* Nuke warning. */
115 static int __init prom_memtype_classify(union linux_memtypes type)
117 if (prom_flags & PROM_FLAG_ARCS) /* SGI is ``different'' ... */
118 return memtype_classify_arcs(type);
120 return memtype_classify_arc(type);
123 void __weak __init prom_meminit(void)
125 struct linux_mdesc *p;
130 printk("ARCS MEMORY DESCRIPTOR dump:\n");
131 p = ArcGetMemoryDescriptor(PROM_NULL_MDESC);
133 printk("[%d,%p]: base<%08lx> pages<%08lx> type<%s>\n",
134 i, p, p->base, p->pages, mtypes(p->type));
135 p = ArcGetMemoryDescriptor(p);
142 while ((p = ArcGetMemoryDescriptor(p))) {
143 unsigned long base, size;
146 base = p->base << ARC_PAGE_SHIFT;
147 size = p->pages << ARC_PAGE_SHIFT;
148 type = prom_memtype_classify(p->type);
150 /* ignore mirrored RAM on IP28/IP30 */
151 if (base < PHYS_OFFSET)
154 memblock_add(base, size);
156 if (type == mem_reserved)
157 memblock_reserve(base, size);
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");
165 prom_mem_base[nr_prom_mem] = base;
166 prom_mem_size[nr_prom_mem] = size;
172 void __weak __init prom_cleanup(void)
176 void __weak __init prom_free_prom_memory(void)
180 if (prom_flags & PROM_FLAG_DONT_FREE_TEMP)
183 for (i = 0; i < nr_prom_mem; i++) {
184 free_init_pages("prom memory",
185 prom_mem_base[i], prom_mem_base[i] + prom_mem_size[i]);
188 * at this point it isn't safe to call PROM functions
189 * give platforms a way to do PROM cleanups