2 * memory.c: PROM library functions for acquiring/using memory descriptors
3 * given to us from the ARCS firmware.
5 * Copyright (C) 1996 by David S. Miller
6 * Copyright (C) 1999, 2000, 2001 by Ralf Baechle
7 * Copyright (C) 1999, 2000 by Silicon Graphics, Inc.
9 * PROM library functions for acquiring/using memory descriptors given to us
10 * from the ARCS firmware. This is only used when CONFIG_ARC_MEMORY is set
11 * because on some machines like SGI IP27 the ARC memory configuration data
12 * completly bogus and alternate easier to use mechanisms are available.
14 #include <linux/init.h>
15 #include <linux/kernel.h>
16 #include <linux/types.h>
17 #include <linux/sched.h>
19 #include <linux/bootmem.h>
20 #include <linux/swap.h>
22 #include <asm/sgialib.h>
24 #include <asm/pgtable.h>
25 #include <asm/bootinfo.h>
30 * For ARC firmware memory functions the unit of meassuring memory is always
33 #define ARC_PAGE_SHIFT 12
35 struct linux_mdesc
* __init
ArcGetMemoryDescriptor(struct linux_mdesc
*Current
)
37 return (struct linux_mdesc
*) ARC_CALL1(get_mdesc
, Current
);
40 #ifdef DEBUG /* convenient for debugging */
41 static char *arcs_mtypes
[8] = {
47 "Standalone Program Pages",
48 "ARCS Temp Storage Area",
49 "ARCS Permanent Storage Area"
52 static char *arc_mtypes
[8] = {
54 "SystemParameterBlock",
62 #define mtypes(a) (prom_flags & PROM_FLAG_ARCS) ? arcs_mtypes[a.arcs] \
66 static inline int memtype_classify_arcs (union linux_memtypes type
)
73 return BOOT_MEM_ROM_DATA
;
79 return BOOT_MEM_RESERVED
;
83 while(1); /* Nuke warning. */
86 static inline int memtype_classify_arc (union linux_memtypes type
)
93 return BOOT_MEM_ROM_DATA
;
99 return BOOT_MEM_RESERVED
;
103 while(1); /* Nuke warning. */
106 static int __init
prom_memtype_classify (union linux_memtypes type
)
108 if (prom_flags
& PROM_FLAG_ARCS
) /* SGI is ``different'' ... */
109 return memtype_classify_arcs(type
);
111 return memtype_classify_arc(type
);
114 void __init
prom_meminit(void)
116 struct linux_mdesc
*p
;
121 prom_printf("ARCS MEMORY DESCRIPTOR dump:\n");
122 p
= ArcGetMemoryDescriptor(PROM_NULL_MDESC
);
124 prom_printf("[%d,%p]: base<%08lx> pages<%08lx> type<%s>\n",
125 i
, p
, p
->base
, p
->pages
, mtypes(p
->type
));
126 p
= ArcGetMemoryDescriptor(p
);
132 while ((p
= ArcGetMemoryDescriptor(p
))) {
133 unsigned long base
, size
;
136 base
= p
->base
<< ARC_PAGE_SHIFT
;
137 size
= p
->pages
<< ARC_PAGE_SHIFT
;
138 type
= prom_memtype_classify(p
->type
);
140 add_memory_region(base
, size
, type
);
144 unsigned long __init
prom_free_prom_memory(void)
146 unsigned long freed
= 0;
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 while (addr
< boot_mem_map
.map
[i
].addr
159 + boot_mem_map
.map
[i
].size
) {
160 ClearPageReserved(virt_to_page(__va(addr
)));
161 set_page_count(virt_to_page(__va(addr
)), 1);
162 free_page((unsigned long)__va(addr
));
167 printk(KERN_INFO
"Freeing prom memory: %ldkb freed\n", freed
>> 10);