1
2
3
4
5
6
7#include <linux/init.h>
8#include <linux/kernel.h>
9#include <linux/mm.h>
10#include <linux/bootmem.h>
11#include <linux/types.h>
12
13#include <asm/addrspace.h>
14#include <asm/bootinfo.h>
15#include <asm/dec/machtype.h>
16#include <asm/dec/prom.h>
17#include <asm/page.h>
18#include <asm/sections.h>
19
20
21volatile unsigned long mem_err = 0;
22
23
24
25
26
27
28#define CHUNK_SIZE 0x400000
29
30static inline void pmax_setup_memory_region(void)
31{
32 volatile unsigned char *memory_page, dummy;
33 char old_handler[0x80];
34 extern char genexcept_early;
35
36
37 memcpy(&old_handler, (void *)(CKSEG0 + 0x80), 0x80);
38 memcpy((void *)(CKSEG0 + 0x80), &genexcept_early, 0x80);
39
40
41
42
43
44
45 for (memory_page = (unsigned char *)CKSEG1 + CHUNK_SIZE;
46 mem_err == 0 && memory_page < (unsigned char *)CKSEG1 + 0x1e00000;
47 memory_page += CHUNK_SIZE) {
48 dummy = *memory_page;
49 }
50 memcpy((void *)(CKSEG0 + 0x80), &old_handler, 0x80);
51
52 add_memory_region(0, (unsigned long)memory_page - CKSEG1 - CHUNK_SIZE,
53 BOOT_MEM_RAM);
54}
55
56
57
58
59
60static inline void rex_setup_memory_region(void)
61{
62 int i, bitmap_size;
63 unsigned long mem_start = 0, mem_size = 0;
64 memmap *bm;
65
66
67 bm = (memmap *)CKSEG0ADDR(0x28000);
68
69 bitmap_size = rex_getbitmap(bm);
70
71 for (i = 0; i < bitmap_size; i++) {
72
73 if (bm->bitmap[i] == 0xff)
74 mem_size += (8 * bm->pagesize);
75 else if (!mem_size)
76 mem_start += (8 * bm->pagesize);
77 else {
78 add_memory_region(mem_start, mem_size, BOOT_MEM_RAM);
79 mem_start += mem_size + (8 * bm->pagesize);
80 mem_size = 0;
81 }
82 }
83 if (mem_size)
84 add_memory_region(mem_start, mem_size, BOOT_MEM_RAM);
85}
86
87void __init prom_meminit(u32 magic)
88{
89 if (!prom_is_rex(magic))
90 pmax_setup_memory_region();
91 else
92 rex_setup_memory_region();
93}
94
95void __init prom_free_prom_memory(void)
96{
97 unsigned long end;
98
99
100
101
102
103
104#if defined(CONFIG_DECLANCE) || defined(CONFIG_DECLANCE_MODULE)
105
106
107
108
109
110
111 if (IOASIC)
112 end = __pa(&_text) - 0x00020000;
113 else
114#endif
115 end = __pa(&_text);
116
117 free_init_pages("unused PROM memory", PAGE_SIZE, end);
118}
119