|
|
@@ -31,7 +31,7 @@
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
|
-extern char cano_putc(int);
|
|
|
+static int __init init_mapping_16m(void);
|
|
|
|
|
|
|
|
|
/* the most important work is: get total size of ram,
|
|
|
@@ -46,38 +46,40 @@ int arch_mm_init(void) {
|
|
|
|
|
|
__archptr_t addr;
|
|
|
|
|
|
+ init_mapping_16m();
|
|
|
|
|
|
/* put them there, after that, are the page structures. */
|
|
|
z = (struct zone *) &_end;
|
|
|
- p = (struct page *) ((struct zone *) &_end + 5);
|
|
|
+ p = (struct page *) ((struct zone *) &_end + 2);
|
|
|
|
|
|
|
|
|
- memset(z, 0, sizeof(struct zone) * 5);
|
|
|
+ memset(z, 0, sizeof(struct zone) * 2);
|
|
|
|
|
|
z[0].type = ZONETYPE_RAM;
|
|
|
-
|
|
|
-
|
|
|
- for (i = 1; i < 5; i++)
|
|
|
- z[i].type = ZONETYPE_OTHER;
|
|
|
+ z[1].type = ZONETYPE_OTHER;
|
|
|
|
|
|
|
|
|
for (e = E820_ADDR; e < E820_ADDR + 32; e++) {
|
|
|
+ long npages;
|
|
|
+
|
|
|
if (e->type > E820_TYPE_MAX || !e->type)
|
|
|
break;
|
|
|
+
|
|
|
+ e->type = e->type == E820_TYPE_RAM ? ZONETYPE_RAM : ZONETYPE_OTHER;
|
|
|
|
|
|
- addr = PAGE_ALIGN(e->addr);
|
|
|
+ addr = PAGE_ALIGN(HIGH_AND_LOW(e->addrh, e->addrl, 32));
|
|
|
|
|
|
|
|
|
if (z[e->type].start_addr > (void *) addr)
|
|
|
z[e->type].start_addr = (void *) addr;
|
|
|
|
|
|
|
|
|
- z[e->type].total_pages += PAGE_NR(e->len);
|
|
|
-
|
|
|
+ npages = PAGE_NR(HIGH_AND_LOW(e->lenh, e->lenl, 32));
|
|
|
+ z[e->type].total_pages += npages;
|
|
|
|
|
|
/* now initiallize page structures */
|
|
|
|
|
|
- for (i = 0; i < PAGE_NR(e->len); i++) {
|
|
|
+ for (i = 0; i < npages; i++) {
|
|
|
p->pnr = PAGE_NR(addr);
|
|
|
p->count = 0;
|
|
|
p->next = p + 1;
|
|
|
@@ -91,6 +93,82 @@ int arch_mm_init(void) {
|
|
|
|
|
|
|
|
|
|
|
|
+/* for a 4gb memory space, 12m used to create struct page */
|
|
|
+
|
|
|
+static int __init init_mapping_16m(void) {
|
|
|
+#if CONFIG_64BIT
|
|
|
+ /* already mapped to 1g */
|
|
|
+ return 0;
|
|
|
+#else
|
|
|
+
|
|
|
+ __archptr_t *lvl1 = (void *) 0,
|
|
|
+ *lvl2 = (void *) 4096;
|
|
|
+
|
|
|
+ __archptr_t addr = 7;
|
|
|
+ int i, j;
|
|
|
+
|
|
|
+ lvl1[0] = 4096 + 7;
|
|
|
+ lvl1[1] = 8192 + 7;
|
|
|
+ lvl1[2] = 4096 * 3 + 7;
|
|
|
+ lvl1[3] = 4096 * 4 + 7;
|
|
|
+
|
|
|
+ lvl1[0xc00] = 4096 + 7;
|
|
|
+ lvl1[0xc01] = 8192 + 7;
|
|
|
+ lvl1[0xc02] = 4096 * 3 + 7;
|
|
|
+ lvl1[0xc03] = 4096 * 4 + 7;
|
|
|
+
|
|
|
+
|
|
|
+ for (i = 0; i < 4; i++) {
|
|
|
+ lvl2 = (void *) (lvl1[i] & ~0xff);
|
|
|
+
|
|
|
+ for (j = 0; j < 1024; j++, addr += 4096)
|
|
|
+ lvl2[j] = addr;
|
|
|
+ }
|
|
|
+
|
|
|
+ invalidate();
|
|
|
+
|
|
|
+ return 0;
|
|
|
+#endif
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+/* pmap */
|
|
|
+#define START 0x3000
|
|
|
+
|
|
|
+/* stack - 8192 */
|
|
|
+#define END 0x8e000
|
|
|
+
|
|
|
+
|
|
|
+__archptr_t freeptr = START;
|
|
|
+
|
|
|
+
|
|
|
+void *early_kmalloc(int nbytes, int align) {
|
|
|
+ void *p;
|
|
|
+
|
|
|
+ freeptr = (freeptr + align - 1) & ~(align - 1);
|
|
|
+
|
|
|
+ if (freeptr + nbytes > END)
|
|
|
+ return NULL;
|
|
|
+
|
|
|
+ p = (void *) freeptr;
|
|
|
+ freeptr += nbytes;
|
|
|
+
|
|
|
+ return p;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+int early_free(void *p, int nbytes) {
|
|
|
+ if (p + nbytes != (void *) freeptr)
|
|
|
+ /* cannot free */
|
|
|
+ return 1;
|
|
|
+
|
|
|
+ freeptr -= nbytes;
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
arch_init(arch_mm_init);
|
|
|
|
|
|
|