=================================================================== RCS file: /cvs/prex-old/sys/mem/page.c,v retrieving revision 1.1.1.1.2.1 retrieving revision 1.2 diff -u -r1.1.1.1.2.1 -r1.2 --- prex-old/sys/mem/page.c 2008/08/13 17:12:32 1.1.1.1.2.1 +++ prex-old/sys/mem/page.c 2008/07/20 23:24:21 1.2 @@ -65,11 +65,12 @@ /* * page_alloc - allocate continuous pages of the specified size. + * @size: number of bytes to allocate * - * This routine returns the physical address of a new free page - * block, or returns NULL on failure. The requested size is - * automatically round up to the page boundary. The allocated - * memory is _not_ filled with 0. + * This routine returns the physical address of a new free page block, + * or returns NULL on failure. The requested size is automatically + * round up to the page boundary. + * The allocated memory is _not_ filled with 0. */ void * page_alloc(size_t size) @@ -89,7 +90,7 @@ blk = blk->next; if (blk == &page_head) { sched_unlock(); - DPRINTF(("page_alloc: out of memory\n")); + printk("page_alloc: out of memory\n"); return NULL; /* Not found. */ } } while (blk->size < size); @@ -104,7 +105,7 @@ blk->prev->next = blk->next; blk->next->prev = blk->prev; } else { - tmp = (struct page_block *)((char *)blk + size); + tmp = (struct page_block *)((u_long)blk + size); tmp->size = blk->size - size; tmp->prev = blk->prev; tmp->next = blk->next; @@ -113,15 +114,15 @@ } used_bytes += size; sched_unlock(); + return virt_to_phys(blk); } /* * Free page block. * - * This allocator does not maintain the size of allocated page - * block. The caller must provide the size information of the - * block. + * This allocator does not maintain the size of allocated page block. + * The caller must provide the size information of the block. */ void page_free(void *addr, size_t size) @@ -134,7 +135,7 @@ sched_lock(); size = (size_t)PAGE_ALIGN(size); - blk = (struct page_block *)phys_to_virt(addr); + blk = phys_to_virt(addr); /* * Find the target position in list. @@ -143,12 +144,11 @@ if (prev->next == &page_head) break; } - #ifdef DEBUG if (prev != &page_head) - ASSERT((char *)prev + prev->size <= (char *)blk); + ASSERT((u_long)prev + prev->size <= (u_long)blk); if (prev->next != &page_head) - ASSERT((char *)blk + size <= (char *)prev->next); + ASSERT((u_long)blk + size <= (u_long)prev->next); #endif /* DEBUG */ /* @@ -165,13 +165,13 @@ * is made on block. */ if (blk->next != &page_head && - ((char *)blk + blk->size) == (char *)blk->next) { + ((u_long)blk + blk->size) == (u_long)blk->next) { blk->size += blk->next->size; blk->next = blk->next->next; blk->next->prev = blk; } if (blk->prev != &page_head && - (char *)blk->prev + blk->prev->size == (char *)blk) { + (u_long)blk->prev + blk->prev->size == (u_long)blk) { blk->prev->size += blk->size; blk->prev->next = blk->next; blk->next->prev = blk->prev; @@ -188,15 +188,15 @@ page_reserve(void *addr, size_t size) { struct page_block *blk, *tmp; - char *end; + u_long end; if (size == 0) return 0; addr = phys_to_virt(addr); - end = (char *)PAGE_ALIGN((char *)addr + size); + end = PAGE_ALIGN((u_long)addr + size); addr = (void *)PAGE_TRUNC(addr); - size = (size_t)(end - (char *)addr); + size = (size_t)(end - (u_long)addr); /* * Find the block which includes specified block. @@ -204,13 +204,17 @@ blk = page_head.next; for (;;) { if (blk == &page_head) - panic("failed to reserve pages"); - if ((char *)blk <= (char *)addr - && end <= (char *)blk + blk->size) +#if 0 + panic("page_reserve"); +#endif + printk("page_reserve: warning, blk == &page_head\n"); break; + if ((u_long)blk <= (u_long)addr + && end <= (u_long)blk + blk->size) + break; blk = blk->next; } - if ((char *)blk == (char *)addr && blk->size == size) { + if ((u_long)blk == (u_long)addr && blk->size == size) { /* * Unlink the block from free list. */ @@ -220,9 +224,9 @@ /* * Split this block. */ - if ((char *)blk + blk->size != end) { + if ((u_long)blk + blk->size != end) { tmp = (struct page_block *)end; - tmp->size = (size_t)((char *)blk + blk->size - end); + tmp->size = (size_t)((u_long)blk + blk->size - end); tmp->next = blk->next; tmp->prev = blk; @@ -230,11 +234,11 @@ blk->next->prev = tmp; blk->next = tmp; } - if ((char *)blk == (char *)addr) { + if ((u_long)blk == (u_long)addr) { blk->prev->next = blk->next; blk->next->prev = blk->prev; } else - blk->size = (size_t)((char *)addr - (char *)blk); + blk->size = (size_t)((u_long)addr - (u_long)blk); } used_bytes += size; return 0; @@ -248,6 +252,56 @@ *free = total_bytes - used_bytes; } +#if defined(DEBUG) && defined(CONFIG_KDUMP) +void +page_dump(void) +{ + struct page_block *blk; + void *addr; + struct mem_map *mem; + struct module *img; + int i; + + printk("Page dump:\n"); + printk(" free pages:\n"); + printk(" start end size\n"); + printk(" -------- -------- --------\n"); + + blk = page_head.next; + do { + addr = virt_to_phys(blk); + printk(" %08x - %08x %8x\n", addr, (u_long)addr + blk->size, + blk->size); + blk = blk->next; + } while (blk != &page_head); + printk(" used=%dK free=%dK total=%dK\n\n", + used_bytes / 1024, (total_bytes - used_bytes) / 1024, + total_bytes / 1024); + + img = (struct module *)&boot_info->kernel; + printk(" kernel: %08x - %08x (%dK)\n", + img->phys, img->phys + img->size, img->size / 1024); + + img = (struct module *)&boot_info->driver; + printk(" driver: %08x - %08x (%dK)\n", + img->phys, img->phys + img->size, img->size / 1024); + + for (i = 0; i < NRESMEM; i++) { + mem = &boot_info->reserved[i]; + if (mem->size != 0) { + printk(" reserved: %08x - %08x (%dK)\n", + mem->start, mem->start + mem->size, + mem->size / 1024); + } + } +#ifdef CONFIG_RAMDISK + mem = (struct mem_map *)&boot_info->ram_disk; + printk(" RAM disk: %08x - %08x (%dK)\n", + mem->start, mem->start + mem->size, mem->size / 1024); +#endif +} +#endif + /* * Initialize page allocator. * page_init() must be called prior to other memory manager's @@ -260,8 +314,8 @@ struct mem_map *mem; int i; - DPRINTF(("Memory: base=%x size=%dK\n", boot_info->main_mem.start, - boot_info->main_mem.size / 1024)); + printk("Memory: base=%x size=%dK\n", boot_info->main_mem.start, + boot_info->main_mem.size / 1024); /* * First, create one block containing all memory pages.