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/pgtable.h>
26 #include <asm/bootinfo.h>
30 #define MAX_PROM_MEM 5
31 static phys_addr_t prom_mem_base
[MAX_PROM_MEM
] __initdata
;
32 static phys_addr_t prom_mem_size
[MAX_PROM_MEM
] __initdata
;
33 static unsigned int nr_prom_mem __initdata
;
36 * For ARC firmware memory functions the unit of meassuring memory is always
39 #define ARC_PAGE_SHIFT 12
41 struct linux_mdesc
* __init
ArcGetMemoryDescriptor(struct linux_mdesc
*Current
)
43 return (struct linux_mdesc
*) ARC_CALL1(get_mdesc
, Current
);
46 #ifdef DEBUG /* convenient for debugging */
47 static char *arcs_mtypes
[8] = {
53 "Standalone Program Pages",
54 "ARCS Temp Storage Area",
55 "ARCS Permanent Storage Area"
58 static char *arc_mtypes
[8] = {
60 "SystemParameterBlock",
68 #define mtypes(a) (prom_flags & PROM_FLAG_ARCS) ? arcs_mtypes[a.arcs] \
72 static inline int memtype_classify_arcs(union linux_memtypes type
)
79 return BOOT_MEM_ROM_DATA
;
85 return BOOT_MEM_RESERVED
;
89 while(1); /* Nuke warning. */
92 static inline int memtype_classify_arc(union linux_memtypes type
)
99 return BOOT_MEM_ROM_DATA
;
105 return BOOT_MEM_RESERVED
;
109 while(1); /* Nuke warning. */
112 static int __init
prom_memtype_classify(union linux_memtypes type
)
114 if (prom_flags
& PROM_FLAG_ARCS
) /* SGI is ``different'' ... */
115 return memtype_classify_arcs(type
);
117 return memtype_classify_arc(type
);
120 void __weak __init
prom_meminit(void)
122 struct linux_mdesc
*p
;
127 printk("ARCS MEMORY DESCRIPTOR dump:\n");
128 p
= ArcGetMemoryDescriptor(PROM_NULL_MDESC
);
130 printk("[%d,%p]: base<%08lx> pages<%08lx> type<%s>\n",
131 i
, p
, p
->base
, p
->pages
, mtypes(p
->type
));
132 p
= ArcGetMemoryDescriptor(p
);
139 while ((p
= ArcGetMemoryDescriptor(p
))) {
140 unsigned long base
, size
;
143 base
= p
->base
<< ARC_PAGE_SHIFT
;
144 size
= p
->pages
<< ARC_PAGE_SHIFT
;
145 type
= prom_memtype_classify(p
->type
);
147 add_memory_region(base
, size
, type
);
149 if (type
== BOOT_MEM_ROM_DATA
) {
150 if (nr_prom_mem
>= 5) {
151 pr_err("Too many ROM DATA regions");
154 prom_mem_base
[nr_prom_mem
] = base
;
155 prom_mem_size
[nr_prom_mem
] = size
;
161 void __weak __init
prom_cleanup(void)
165 void __weak __init
prom_free_prom_memory(void)
169 if (prom_flags
& PROM_FLAG_DONT_FREE_TEMP
)
172 for (i
= 0; i
< nr_prom_mem
; i
++) {
173 free_init_pages("prom memory",
174 prom_mem_base
[i
], prom_mem_base
[i
] + prom_mem_size
[i
]);
177 * at this point it isn't safe to call PROM functions
178 * give platforms a way to do PROM cleanups