--- Gnu-Mach/linux/dev/glue/kmem.c 2020/09/02 04:41:39 1.1 +++ Gnu-Mach/linux/dev/glue/kmem.c 2020/09/02 04:45:58 1.1.1.2 @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -40,14 +41,14 @@ #include -extern void *alloc_contig_mem (unsigned, unsigned, unsigned, vm_page_t *); -extern int printf (const char *, ...); +#include /* Amount of memory to reserve for Linux memory allocator. We reserve 64K chunks to stay within DMA limits. Increase MEM_CHUNKS if the kernel is running out of memory. */ #define MEM_CHUNK_SIZE (64 * 1024) -#define MEM_CHUNKS 7 +#define MEM_CHUNKS 32 +#define MEM_DMA_LIMIT (16 * 1024 * 1024) /* Mininum amount that linux_kmalloc will allocate. */ #define MIN_ALLOC 12 @@ -100,7 +101,7 @@ linux_kmem_init () { /* Allocate memory. */ pages_free[i].start = (unsigned long) alloc_contig_mem (MEM_CHUNK_SIZE, - 16 * 1024 * 1024, + MEM_DMA_LIMIT, 0xffff, &pages); assert (pages_free[i].start); @@ -109,7 +110,7 @@ linux_kmem_init () /* Sanity check: ensure pages are contiguous and within DMA limits. */ for (p = pages, j = 0; j < MEM_CHUNK_SIZE - PAGE_SIZE; j += PAGE_SIZE) { - assert (p->phys_addr < 16 * 1024 * 1024); + assert (p->phys_addr < MEM_DMA_LIMIT); assert (p->phys_addr + PAGE_SIZE == ((vm_page_t) p->pageq.next)->phys_addr); @@ -217,7 +218,7 @@ void * linux_kmalloc (unsigned int size, int priority) { int order, coalesced = 0; - unsigned flags; + unsigned long flags; struct pagehdr *ph; struct blkhdr *bh, *new_bh; @@ -309,7 +310,7 @@ again: void linux_kfree (void *p) { - unsigned flags; + unsigned long flags; struct blkhdr *bh; struct pagehdr *ph; @@ -384,7 +385,8 @@ unsigned long __get_free_pages (int priority, unsigned long order, int dma) { int i, pages_collected = 0; - unsigned flags, bits, off, j, len; + unsigned bits, off, j, len; + unsigned long flags; assert ((PAGE_SIZE << order) <= MEM_CHUNK_SIZE); @@ -443,7 +445,8 @@ void free_pages (unsigned long addr, unsigned long order) { int i; - unsigned flags, bits, len, j; + unsigned bits, len, j; + unsigned long flags; assert ((addr & PAGE_MASK) == 0); @@ -525,7 +528,7 @@ vmalloc_list_remove (struct vmalloc_stru p->next->prev = p->prev; p->prev->next = p->next; - kfree (p, sizeof (struct vmalloc_struct)); + kfree ((vm_offset_t) p, sizeof (struct vmalloc_struct)); } /* Allocate SIZE bytes of memory. The pages need not be contiguous. */ @@ -550,13 +553,19 @@ vfree (void *addr) struct vmalloc_struct *p; p = vmalloc_list_lookup ((vm_offset_t) addr); - if (p) + if (!p) panic ("vmalloc_list_lookup failure"); - kmem_free (kernel_map, addr, p->size); + kmem_free (kernel_map, (vm_offset_t) addr, p->size); vmalloc_list_remove (p); } +unsigned long +vmtophys (void *addr) +{ + return kvtophys((vm_offset_t) addr); +} + /* XXX: Quick hacking. */ /* Remap physical address into virtual address. */ void *