2 * memory.c: memory initialisation code.
4 * Copyright (C) 1998 Harald Koerfgen, Frieder Streffer and Paul M. Antoine
8 #include <asm/addrspace.h>
9 #include <linux/init.h>
10 #include <linux/config.h>
11 #include <linux/string.h>
16 unsigned char bitmap
[0];
19 extern int (*rex_getbitmap
)(memmap
*);
24 extern int (*prom_printf
)(char *, ...);
27 extern unsigned long mips_memory_upper
;
29 volatile unsigned long mem_err
= 0; /* So we know an error occured */
32 * Probe memory in 4MB chunks, waiting for an error to tell us we've fallen
33 * off the end of real memory. Only suitable for the 2100/3100's (PMAX).
36 #define CHUNK_SIZE 0x400000
38 __initfunc(unsigned long pmax_get_memory_size(void))
40 volatile unsigned char *memory_page
, dummy
;
41 char old_handler
[0x80];
42 extern char genexcept_early
;
44 /* Install exception handler */
45 memcpy(&old_handler
, (void *)(KSEG0
+ 0x80), 0x80);
46 memcpy((void *)(KSEG0
+ 0x80), &genexcept_early
, 0x80);
48 /* read unmapped and uncached (KSEG1)
49 * DECstations have at least 4MB RAM
50 * Assume less than 480MB of RAM, as this is max for 5000/2xx
51 * FIXME this should be replaced by the first free page!
53 for (memory_page
= (unsigned char *) KSEG1
+ CHUNK_SIZE
;
54 (mem_err
== 0) && (memory_page
< ((unsigned char *) KSEG1
+0x1E000000));
55 memory_page
+= CHUNK_SIZE
) {
58 memcpy((void *)(KSEG0
+ 0x80), &old_handler
, 0x80);
59 return (unsigned long)memory_page
- KSEG1
- CHUNK_SIZE
;
63 * Use the REX prom calls to get hold of the memory bitmap, and thence
64 * determine memory size.
66 __initfunc(unsigned long rex_get_memory_size(void))
69 unsigned long mem_size
= 0;
73 bm
= (memmap
*) 0x80028000;
75 bitmap_size
= rex_getbitmap(bm
);
77 for (i
= 0; i
< bitmap_size
; i
++) {
78 /* FIXME: very simplistically only add full sets of pages */
79 if (bm
->bitmap
[i
] == 0xff)
80 mem_size
+= (8 * bm
->pagesize
);
85 __initfunc(void prom_meminit(unsigned int magic
))
87 if (magic
!= REX_PROM_MAGIC
)
88 mips_memory_upper
= KSEG0
+ pmax_get_memory_size();
90 mips_memory_upper
= KSEG0
+ rex_get_memory_size();
93 prom_printf("mips_memory_upper: 0x%08x\n", mips_memory_upper
);
97 /* Called from mem_init() to fixup the mem_map page settings. */
98 __initfunc(void prom_fixup_mem_map(unsigned long start
, unsigned long end
))
102 void prom_free_prom_memory (void)