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/bootmem.h>
21 #include <linux/swap.h>
23 #include <asm/sgialib.h>
25 #include <asm/pgtable.h>
26 #include <asm/bootinfo.h>
31 * For ARC firmware memory functions the unit of meassuring memory is always
34 #define ARC_PAGE_SHIFT 12
36 struct linux_mdesc
* __init
ArcGetMemoryDescriptor(struct linux_mdesc
*Current
)
38 return (struct linux_mdesc
*) ARC_CALL1(get_mdesc
, Current
);
41 #ifdef DEBUG /* convenient for debugging */
42 static char *arcs_mtypes
[8] = {
48 "Standalone Program Pages",
49 "ARCS Temp Storage Area",
50 "ARCS Permanent Storage Area"
53 static char *arc_mtypes
[8] = {
55 "SystemParameterBlock",
63 #define mtypes(a) (prom_flags & PROM_FLAG_ARCS) ? arcs_mtypes[a.arcs] \
67 static inline int memtype_classify_arcs(union linux_memtypes type
)
74 return BOOT_MEM_ROM_DATA
;
80 return BOOT_MEM_RESERVED
;
84 while(1); /* Nuke warning. */
87 static inline int memtype_classify_arc(union linux_memtypes type
)
94 return BOOT_MEM_ROM_DATA
;
100 return BOOT_MEM_RESERVED
;
104 while(1); /* Nuke warning. */
107 static int __init
prom_memtype_classify(union linux_memtypes type
)
109 if (prom_flags
& PROM_FLAG_ARCS
) /* SGI is ``different'' ... */
110 return memtype_classify_arcs(type
);
112 return memtype_classify_arc(type
);
115 void __init
prom_meminit(void)
117 struct linux_mdesc
*p
;
122 printk("ARCS MEMORY DESCRIPTOR dump:\n");
123 p
= ArcGetMemoryDescriptor(PROM_NULL_MDESC
);
125 printk("[%d,%p]: base<%08lx> pages<%08lx> type<%s>\n",
126 i
, p
, p
->base
, p
->pages
, mtypes(p
->type
));
127 p
= ArcGetMemoryDescriptor(p
);
133 while ((p
= ArcGetMemoryDescriptor(p
))) {
134 unsigned long base
, size
;
137 base
= p
->base
<< ARC_PAGE_SHIFT
;
138 size
= p
->pages
<< ARC_PAGE_SHIFT
;
139 type
= prom_memtype_classify(p
->type
);
141 add_memory_region(base
, size
, type
);
145 void __init
prom_free_prom_memory(void)
150 if (prom_flags
& PROM_FLAG_DONT_FREE_TEMP
)
153 for (i
= 0; i
< boot_mem_map
.nr_map
; i
++) {
154 if (boot_mem_map
.map
[i
].type
!= BOOT_MEM_ROM_DATA
)
157 addr
= boot_mem_map
.map
[i
].addr
;
158 free_init_pages("prom memory",
159 addr
, addr
+ boot_mem_map
.map
[i
].size
);