--- Gnu-Mach/i386/i386at/model_dep.c 2020/09/02 04:44:34 1.1.1.3 +++ Gnu-Mach/i386/i386at/model_dep.c 2020/09/02 04:46:51 1.1.1.4 @@ -32,23 +32,47 @@ * Basic initialization for I386 - ISA bus machines. */ -#include -#include +#include + +#include #include #include #include #include +#include -#include "vm_param.h" -#include +#include #include #include +#include +#include +#include #include +#include #include +#include +#include +#include +#include #include +#include +#include #include -#include "proc_reg.h" +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef MACH_XEN +#include +#include +#include +#include +#endif /* MACH_XEN */ /* Location of the kernel's symbol table. Both of these are 0 if none is available. */ @@ -64,11 +88,21 @@ static vm_offset_t kern_sym_start, kern_ vm_offset_t phys_first_addr = 0; vm_offset_t phys_last_addr; -/* Virtual address of physical memory, for the kvtophys/phystokv macros. */ -vm_offset_t phys_mem_va; - /* A copy of the multiboot info structure passed by the boot loader. */ +#ifdef MACH_XEN +struct start_info boot_info; +#ifdef MACH_PSEUDO_PHYS +unsigned long *mfn_list; +#if VM_MIN_KERNEL_ADDRESS != LINEAR_MIN_KERNEL_ADDRESS +unsigned long *pfn_list = (void*) PFN_LIST; +#endif +#endif /* MACH_PSEUDO_PHYS */ +#if VM_MIN_KERNEL_ADDRESS != LINEAR_MIN_KERNEL_ADDRESS +unsigned long la_shift = VM_MIN_KERNEL_ADDRESS; +#endif +#else /* MACH_XEN */ struct multiboot_info boot_info; +#endif /* MACH_XEN */ /* Command line supplied to kernel. */ char *kernel_cmdline = ""; @@ -77,31 +111,21 @@ char *kernel_cmdline = ""; it gets bumped up through physical memory that exists and is not occupied by boot gunk. It is not necessarily page-aligned. */ -static vm_offset_t avail_next = 0x1000; /* XX end of BIOS data area */ +static vm_offset_t avail_next +#ifndef MACH_HYP + = 0x1000 /* XX end of BIOS data area */ +#endif /* MACH_HYP */ + ; /* Possibly overestimated amount of available memory still remaining to be handed to the VM system. */ static vm_size_t avail_remaining; -/* Configuration parameter: - if zero, only use physical memory in the low 16MB of addresses. - Only SCSI still has DMA problems. */ -#ifdef LINUX_DEV -#define use_all_mem 1 -#else -#include "nscsi.h" -#if NSCSI > 0 -#define use_all_mem 0 -#else -#define use_all_mem 1 -#endif -#endif - extern char version[]; extern void setup_main(); -void halt_all_cpu (boolean_t reboot) __attribute__ ((noreturn)); +void halt_all_cpus (boolean_t reboot) __attribute__ ((noreturn)); void halt_cpu (void) __attribute__ ((noreturn)); void inittodr(); /* forward */ @@ -115,10 +139,12 @@ vm_offset_t int_stack_top, int_stack_hig extern void linux_init(void); #endif +boolean_t init_alloc_aligned(vm_size_t size, vm_offset_t *addrp); + /* * Find devices. The system is alive. */ -void machine_init() +void machine_init(void) { /* * Initialize the console. @@ -130,6 +156,9 @@ void machine_init() */ init_fpu(); +#ifdef MACH_HYP + hyp_init(); +#else /* MACH_HYP */ #ifdef LINUX_DEV /* * Initialize Linux drivers. @@ -141,16 +170,19 @@ void machine_init() * Find the devices */ probeio(); +#endif /* MACH_HYP */ /* * Get the time */ inittodr(); +#ifndef MACH_HYP /* * Tell the BIOS not to clear and test memory. */ *(unsigned short *)phystokv(0x472) = 0x1234; +#endif /* MACH_HYP */ /* * Unmap page 0 to trap NULL references. @@ -161,8 +193,17 @@ void machine_init() /* Conserve power on processor CPU. */ void machine_idle (int cpu) { +#ifdef MACH_HYP + hyp_idle(); +#else /* MACH_HYP */ assert (cpu == cpu_number ()); asm volatile ("hlt" : : : "memory"); +#endif /* MACH_HYP */ +} + +void machine_relax () +{ + asm volatile ("rep; nop" : : : "memory"); } /* @@ -170,8 +211,13 @@ void machine_idle (int cpu) */ void halt_cpu(void) { +#ifdef MACH_HYP + hyp_halt(); +#else /* MACH_HYP */ asm volatile("cli"); - while(1); + while (TRUE) + machine_idle (cpu_number ()); +#endif /* MACH_HYP */ } /* @@ -181,15 +227,21 @@ void halt_all_cpus(reboot) boolean_t reboot; { if (reboot) { +#ifdef MACH_HYP + hyp_reboot(); +#endif /* MACH_HYP */ kdreboot(); } else { rebootflag = 1; +#ifdef MACH_HYP + hyp_halt(); +#endif /* MACH_HYP */ printf("In tight loop: hit ctl-alt-del to reboot\n"); (void) spl0(); } - for (;;) - continue; + while (TRUE) + machine_idle (cpu_number ()); } void exit(int rc) @@ -197,7 +249,7 @@ void exit(int rc) halt_all_cpus(0); } -void db_reset_cpu() +void db_reset_cpu(void) { halt_all_cpus(1); } @@ -207,48 +259,149 @@ void db_reset_cpu() * Compute physical memory size and other parameters. */ void -mem_size_init() +mem_size_init(void) { + vm_offset_t max_phys_size; + /* Physical memory on all PCs starts at physical address 0. XX make it a constant. */ phys_first_addr = 0; - phys_last_addr = 0x100000 + (boot_info.mem_upper * 0x400); - avail_remaining - = phys_last_addr - (0x100000 - (boot_info.mem_lower * 0x400) - - 0x1000); +#ifdef MACH_HYP + if (boot_info.nr_pages >= 0x100000) { + printf("Truncating memory size to 4GiB\n"); + phys_last_addr = 0xffffffffU; + } else + phys_last_addr = boot_info.nr_pages * 0x1000; +#else /* MACH_HYP */ + vm_size_t phys_last_kb; + + if (boot_info.flags & MULTIBOOT_MEM_MAP) { + struct multiboot_mmap *map, *map_end; + + map = (void*) phystokv(boot_info.mmap_addr); + map_end = (void*) map + boot_info.mmap_count; + + while (map + 1 <= map_end) { + if (map->Type == MB_ARD_MEMORY) { + unsigned long long start = map->BaseAddr, end = map->BaseAddr + map->Length;; + + if (start >= 0x100000000ULL) { + printf("Ignoring %luMiB RAM region above 4GiB\n", (unsigned long) (map->Length >> 20)); + } else { + if (end >= 0x100000000ULL) { + printf("Truncating memory region to 4GiB\n"); + end = 0x0ffffffffU; + } + if (end > phys_last_addr) + phys_last_addr = end; - printf("AT386 boot: physical memory from 0x%x to 0x%x\n", + printf("AT386 boot: physical memory map from 0x%lx to 0x%lx\n", + (unsigned long) start, + (unsigned long) end); + } + } + map = (void*) map + map->size + sizeof(map->size); + } + } else { + phys_last_kb = 0x400 + boot_info.mem_upper; + /* Avoid 4GiB overflow. */ + if (phys_last_kb < 0x400 || phys_last_kb >= 0x400000) { + printf("Truncating memory size to 4GiB\n"); + phys_last_addr = 0xffffffffU; + } else + phys_last_addr = phys_last_kb * 0x400; + } +#endif /* MACH_HYP */ + + printf("AT386 boot: physical memory from 0x%lx to 0x%lx\n", phys_first_addr, phys_last_addr); - if ((!use_all_mem) && phys_last_addr > 16 * 1024*1024) { - printf("** Limiting useable memory to 16 Meg to avoid DMA problems.\n"); - /* This is actually enforced below, in init_alloc_aligned. */ + /* Reserve room for virtual mappings. + * Yes, this loses memory. Blame i386. */ + max_phys_size = VM_MAX_KERNEL_ADDRESS - VM_MIN_KERNEL_ADDRESS - VM_KERNEL_MAP_SIZE; + if (phys_last_addr - phys_first_addr > max_phys_size) { + phys_last_addr = phys_first_addr + max_phys_size; + printf("Truncating memory to %luMiB\n", (phys_last_addr - phys_first_addr) / (1024 * 1024)); + /* TODO Xen: be nice, free lost memory */ } phys_first_addr = round_page(phys_first_addr); phys_last_addr = trunc_page(phys_last_addr); + +#ifdef MACH_HYP + /* Memory is just contiguous */ + avail_remaining = phys_last_addr; +#else /* MACH_HYP */ + avail_remaining + = phys_last_addr - (0x100000 - (boot_info.mem_lower * 0x400) + - 0x1000); +#endif /* MACH_HYP */ } /* * Basic PC VM initialization. * Turns on paging and changes the kernel segments to use high linear addresses. */ -i386at_init() +void +i386at_init(void) { /* XXX move to intel/pmap.h */ extern pt_entry_t *kernel_page_dir; + int nb_direct, i; + vm_offset_t addr, delta; /* * Initialize the PIC prior to any possible call to an spl. */ +#ifndef MACH_HYP picinit(); +#else /* MACH_HYP */ + hyp_intrinit(); +#endif /* MACH_HYP */ /* * Find memory size parameters. */ mem_size_init(); +#ifdef MACH_XEN + kernel_cmdline = (char*) boot_info.cmd_line; +#else /* MACH_XEN */ + /* Copy content pointed by boot_info before losing access to it when it + * is too far in physical memory. */ + if (boot_info.flags & MULTIBOOT_CMDLINE) { + int len = strlen ((char*)phystokv(boot_info.cmdline)) + 1; + assert(init_alloc_aligned(round_page(len), &addr)); + kernel_cmdline = (char*) phystokv(addr); + memcpy(kernel_cmdline, (char*)phystokv(boot_info.cmdline), len); + boot_info.cmdline = addr; + } + + if (boot_info.flags & MULTIBOOT_MODS) { + struct multiboot_module *m; + int i; + + assert(init_alloc_aligned(round_page(boot_info.mods_count * sizeof(*m)), &addr)); + m = (void*) phystokv(addr); + memcpy(m, (void*) phystokv(boot_info.mods_addr), boot_info.mods_count * sizeof(*m)); + boot_info.mods_addr = addr; + + for (i = 0; i < boot_info.mods_count; i++) { + vm_size_t size = m[i].mod_end - m[i].mod_start; + assert(init_alloc_aligned(round_page(size), &addr)); + memcpy((void*) phystokv(addr), (void*) phystokv(m[i].mod_start), size); + m[i].mod_start = addr; + m[i].mod_end = addr + size; + + size = strlen((char*) phystokv(m[i].string)) + 1; + assert(init_alloc_aligned(round_page(size), &addr)); + memcpy((void*) phystokv(addr), (void*) phystokv(m[i].string), size); + m[i].string = addr; + } + } +#endif /* MACH_XEN */ + /* * Initialize kernel physical map, mapping the * region from loadpt to avail_start. @@ -258,44 +411,113 @@ i386at_init() pmap_bootstrap(); /* - * Turn paging on. * We'll have to temporarily install a direct mapping * between physical memory and low linear memory, * until we start using our new kernel segment descriptors. - * One page table (4MB) should do the trick. - * Also, set the WP bit so that on 486 or better processors - * page-level write protection works in kernel mode. */ - kernel_page_dir[lin2pdenum(0)] = +#if INIT_VM_MIN_KERNEL_ADDRESS != LINEAR_MIN_KERNEL_ADDRESS + delta = INIT_VM_MIN_KERNEL_ADDRESS - LINEAR_MIN_KERNEL_ADDRESS; + if ((vm_offset_t)(-delta) < delta) + delta = (vm_offset_t)(-delta); + nb_direct = delta >> PDESHIFT; + for (i = 0; i < nb_direct; i++) + kernel_page_dir[lin2pdenum(INIT_VM_MIN_KERNEL_ADDRESS) + i] = + kernel_page_dir[lin2pdenum(LINEAR_MIN_KERNEL_ADDRESS) + i]; +#endif + /* We need BIOS memory mapped at 0xc0000 & co for Linux drivers */ +#ifdef LINUX_DEV +#if VM_MIN_KERNEL_ADDRESS != 0 + kernel_page_dir[lin2pdenum(LINEAR_MIN_KERNEL_ADDRESS - VM_MIN_KERNEL_ADDRESS)] = kernel_page_dir[lin2pdenum(LINEAR_MIN_KERNEL_ADDRESS)]; - set_cr3((unsigned)kernel_page_dir); +#endif +#endif + +#ifdef MACH_PV_PAGETABLES + for (i = 0; i < PDPNUM; i++) + pmap_set_page_readonly_init((void*) kernel_page_dir + i * INTEL_PGBYTES); +#if PAE + pmap_set_page_readonly_init(kernel_pmap->pdpbase); +#endif /* PAE */ +#endif /* MACH_PV_PAGETABLES */ +#if PAE + set_cr3((unsigned)_kvtophys(kernel_pmap->pdpbase)); +#ifndef MACH_HYP + if (!CPU_HAS_FEATURE(CPU_FEATURE_PAE)) + panic("CPU doesn't have support for PAE."); + set_cr4(get_cr4() | CR4_PAE); +#endif /* MACH_HYP */ +#else + set_cr3((unsigned)_kvtophys(kernel_page_dir)); +#endif /* PAE */ +#ifndef MACH_HYP + /* Turn paging on. + * Also set the WP bit so that on 486 or better processors + * page-level write protection works in kernel mode. + */ set_cr0(get_cr0() | CR0_PG | CR0_WP); + set_cr0(get_cr0() & ~(CR0_CD | CR0_NW)); + if (CPU_HAS_FEATURE(CPU_FEATURE_PGE)) + set_cr4(get_cr4() | CR4_PGE); +#endif /* MACH_HYP */ flush_instr_queue(); +#ifdef MACH_PV_PAGETABLES + pmap_clear_bootstrap_pagetable((void *)boot_info.pt_base); +#endif /* MACH_PV_PAGETABLES */ + + /* Interrupt stacks are allocated in physical memory, + while kernel stacks are allocated in kernel virtual memory, + so phys_last_addr serves as a convenient dividing point. */ + int_stack_high = phystokv(phys_last_addr); /* * Initialize and activate the real i386 protected-mode structures. */ gdt_init(); idt_init(); +#ifndef MACH_HYP int_init(); +#endif /* MACH_HYP */ ldt_init(); ktss_init(); +#if INIT_VM_MIN_KERNEL_ADDRESS != LINEAR_MIN_KERNEL_ADDRESS /* Get rid of the temporary direct mapping and flush it out of the TLB. */ - kernel_page_dir[lin2pdenum(0)] = 0; - set_cr3((unsigned)kernel_page_dir); - + for (i = 0 ; i < nb_direct; i++) { +#ifdef MACH_XEN +#ifdef MACH_PSEUDO_PHYS + if (!hyp_mmu_update_pte(kv_to_ma(&kernel_page_dir[lin2pdenum(VM_MIN_KERNEL_ADDRESS) + i]), 0)) +#else /* MACH_PSEUDO_PHYS */ + if (hyp_do_update_va_mapping(VM_MIN_KERNEL_ADDRESS + i * INTEL_PGBYTES, 0, UVMF_INVLPG | UVMF_ALL)) +#endif /* MACH_PSEUDO_PHYS */ + printf("couldn't unmap frame %d\n", i); +#else /* MACH_XEN */ + kernel_page_dir[lin2pdenum(INIT_VM_MIN_KERNEL_ADDRESS) + i] = 0; +#endif /* MACH_XEN */ + } +#endif + /* Keep BIOS memory mapped */ +#ifdef LINUX_DEV +#if VM_MIN_KERNEL_ADDRESS != 0 + kernel_page_dir[lin2pdenum(LINEAR_MIN_KERNEL_ADDRESS - VM_MIN_KERNEL_ADDRESS)] = + kernel_page_dir[lin2pdenum(LINEAR_MIN_KERNEL_ADDRESS)]; +#endif +#endif + /* Not used after boot, better give it back. */ +#ifdef MACH_XEN + hyp_free_page(0, (void*) VM_MIN_KERNEL_ADDRESS); +#endif /* MACH_XEN */ + + flush_tlb(); + +#ifdef MACH_XEN + hyp_p2m_init(); +#endif /* MACH_XEN */ /* XXX We'll just use the initialization stack we're already running on as the interrupt stack for now. Later this will have to change, because the init stack will get freed after bootup. */ asm("movl %%esp,%0" : "=m" (int_stack_top)); - - /* Interrupt stacks are allocated in physical memory, - while kernel stacks are allocated in kernel virtual memory, - so phys_last_addr serves as a convenient dividing point. */ - int_stack_high = phys_last_addr; } /* @@ -305,20 +527,23 @@ i386at_init() void c_boot_entry(vm_offset_t bi) { /* Stash the boot_image_info pointer. */ - boot_info = *(struct multiboot_info*)phystokv(bi); - - /* XXX we currently assume phys_mem_va is always 0 here - - if it isn't, we must tweak the pointers in the boot_info. */ + boot_info = *(typeof(boot_info)*)phystokv(bi); + int cpu_type; /* Before we do _anything_ else, print the hello message. If there are no initialized console devices yet, it will be stored and printed at the first opportunity. */ - printf(version); + printf("%s", version); printf("\n"); - /* Find the kernel command line, if there is one. */ - if (boot_info.flags & MULTIBOOT_CMDLINE) - kernel_cmdline = (char*)phystokv(boot_info.cmdline); +#ifdef MACH_XEN + printf("Running on %s.\n", boot_info.magic); + if (boot_info.flags & SIF_PRIVILEGED) + panic("Mach can't run as dom0."); +#ifdef MACH_PSEUDO_PHYS + mfn_list = (void*)boot_info.mfn_list; +#endif +#else /* MACH_XEN */ #if MACH_KDB /* @@ -336,11 +561,14 @@ void c_boot_entry(vm_offset_t bi) strtab_size = (vm_offset_t)phystokv(boot_info.syms.a.strsize); kern_sym_end = kern_sym_start + 4 + symtab_size + strtab_size; - printf("kernel symbol table at %08x-%08x (%d,%d)\n", + printf("kernel symbol table at %08lx-%08lx (%d,%d)\n", kern_sym_start, kern_sym_end, symtab_size, strtab_size); } #endif /* MACH_KDB */ +#endif /* MACH_XEN */ + + cpu_type = discover_x86_cpu_type (); /* * Do basic VM initialization @@ -355,28 +583,17 @@ void c_boot_entry(vm_offset_t bi) { aout_db_sym_init(kern_sym_start, kern_sym_end, "mach", 0); } - - /* - * Cause a breakpoint trap to the debugger before proceeding - * any further if the proper option flag was specified - * on the kernel's command line. - * XXX check for surrounding spaces. - */ - if (strstr(kernel_cmdline, "-d ")) { - cninit(); /* need console for debugger */ - Debugger(); - } #endif /* MACH_KDB */ machine_slot[0].is_cpu = TRUE; machine_slot[0].running = TRUE; machine_slot[0].cpu_subtype = CPU_SUBTYPE_AT386; -#if 0 - switch (discover_x86_cpu_type ()) + switch (cpu_type) { - case 3: default: + printf("warning: unknown cpu type %d, assuming i386\n", cpu_type); + case 3: machine_slot[0].cpu_type = CPU_TYPE_I386; break; case 4: @@ -386,13 +603,10 @@ void c_boot_entry(vm_offset_t bi) machine_slot[0].cpu_type = CPU_TYPE_PENTIUM; break; case 6: + case 15: machine_slot[0].cpu_type = CPU_TYPE_PENTIUMPRO; break; } -#else - machine_slot[0].cpu_type = CPU_TYPE_I386; -#endif - /* * Start the system. @@ -405,6 +619,7 @@ void c_boot_entry(vm_offset_t bi) #include #include +int timemmap(dev,off,prot) vm_prot_t prot; { @@ -419,20 +634,21 @@ timemmap(dev,off,prot) return (i386_btop(pmap_extract(pmap_kernel(), (vm_offset_t) mtime))); } -startrtclock() +void +startrtclock(void) { clkstart(); } void -inittodr() +inittodr(void) { time_value_t new_time; new_time.seconds = 0; new_time.microseconds = 0; - (void) readtodc(&new_time.seconds); + (void) readtodc((u_int *)&new_time.seconds); { spl_t s = splhigh(); @@ -442,21 +658,27 @@ inittodr() } void -resettodr() +resettodr(void) { writetodc(); } -unsigned int pmap_free_pages() +unsigned int pmap_free_pages(void) { return atop(avail_remaining); } /* Always returns page-aligned regions. */ -static boolean_t +boolean_t init_alloc_aligned(vm_size_t size, vm_offset_t *addrp) { vm_offset_t addr; + +#ifdef MACH_HYP + /* There is none */ + if (!avail_next) + avail_next = _kvtophys(boot_info.pt_base) + (boot_info.nr_pt_frames + 3) * 0x1000; +#else /* MACH_HYP */ extern char start[], end[]; int i; static int wrapped = 0; @@ -475,12 +697,15 @@ init_alloc_aligned(vm_size_t size, vm_of : 0; retry: +#endif /* MACH_HYP */ /* Page-align the start address. */ avail_next = round_page(avail_next); +#ifndef MACH_HYP /* Start with memory above 16MB, reserving the low memory for later. */ - if (use_all_mem && !wrapped && phys_last_addr > 16 * 1024*1024) + /* Don't care on Xen */ + if (!wrapped && phys_last_addr > 16 * 1024*1024) { if (avail_next < 16 * 1024*1024) avail_next = 16 * 1024*1024; @@ -495,9 +720,15 @@ init_alloc_aligned(vm_size_t size, vm_of wrapped = 1; } } +#endif /* MACH_HYP */ /* Check if we have reached the end of memory. */ - if (avail_next == (wrapped ? 16 * 1024*1024 : phys_last_addr)) + if (avail_next == + ( +#ifndef MACH_HYP + wrapped ? 16 * 1024*1024 : +#endif /* MACH_HYP */ + phys_last_addr)) return FALSE; /* Tentatively assign the current location to the caller. */ @@ -507,22 +738,67 @@ init_alloc_aligned(vm_size_t size, vm_of and see where that puts us. */ avail_next += size; +#ifndef MACH_HYP /* Skip past the I/O and ROM area. */ - if ((avail_next > (boot_info.mem_lower * 0x400)) && (addr < 0x100000)) + if (boot_info.flags & MULTIBOOT_MEM_MAP) + { + struct multiboot_mmap *map, *map_end, *current = NULL, *next = NULL; + unsigned long long minimum_next = ~0ULL; + + map = (void*) phystokv(boot_info.mmap_addr); + map_end = (void*) map + boot_info.mmap_count; + + /* Find both our current map, and the next one */ + while (map + 1 <= map_end) + { + if (map->Type == MB_ARD_MEMORY) + { + unsigned long long start = map->BaseAddr; + unsigned long long end = start + map->Length;; + + if (start <= addr && avail_next <= end) + { + /* Ok, fits in the current map */ + current = map; + break; + } + else if (avail_next <= start && start < minimum_next) + { + /* This map is not far from avail_next */ + next = map; + minimum_next = start; + } + } + map = (void*) map + map->size + sizeof(map->size); + } + + if (!current) { + /* Area does not fit in the current map, switch to next + * map if any */ + if (!next || next->BaseAddr >= phys_last_addr) + { + /* No further reachable map, we have reached + * the end of memory, but possibly wrap around + * 16MiB. */ + avail_next = phys_last_addr; + goto retry; + } + + /* Start from next map */ + avail_next = next->BaseAddr; + goto retry; + } + } + else if ((avail_next > (boot_info.mem_lower * 0x400)) && (addr < 0x100000)) { avail_next = 0x100000; goto retry; } - /* If we're only supposed to use the low 16 megs, enforce that. */ - if ((!use_all_mem) && (addr >= 16 * 1024*1024)) { - return FALSE; - } - /* Skip our own kernel code, data, and bss. */ - if ((avail_next > (vm_offset_t)start) && (addr < (vm_offset_t)end)) + if ((phystokv(avail_next) > (vm_offset_t)start) && (phystokv(addr) < (vm_offset_t)end)) { - avail_next = (vm_offset_t)end; + avail_next = _kvtophys(end); goto retry; } @@ -537,9 +813,9 @@ init_alloc_aligned(vm_size_t size, vm_of avail_next = mods_end_pa; goto retry; } - if ((avail_next > kern_sym_start) && (addr < kern_sym_end)) + if ((phystokv(avail_next) > kern_sym_start) && (phystokv(addr) < kern_sym_end)) { - avail_next = kern_sym_end; + avail_next = _kvtophys(kern_sym_end); goto retry; } if (boot_info.flags & MULTIBOOT_MODS) @@ -557,6 +833,7 @@ init_alloc_aligned(vm_size_t size, vm_of /* XXX string */ } } +#endif /* MACH_HYP */ avail_remaining -= size; @@ -574,7 +851,7 @@ boolean_t pmap_next_page(addrp) the standard memory allocation mechanism during system initialization. */ vm_offset_t -pmap_grab_page() +pmap_grab_page(void) { vm_offset_t addr; if (!pmap_next_page(&addr)) @@ -586,111 +863,11 @@ boolean_t pmap_valid_page(x) vm_offset_t x; { /* XXX is this OK? What does it matter for? */ - return (((phys_first_addr <= x) && (x < phys_last_addr)) && - !(((boot_info.mem_lower * 1024) <= x) && (x < 1024*1024))); -} - -#ifndef NBBY -#define NBBY 8 -#endif -#ifndef NBPW -#define NBPW (NBBY * sizeof(int)) -#endif -#define DMA_MAX (16*1024*1024) - -/* - * Allocate contiguous pages below 16 MB - * starting at specified boundary for DMA. - */ -vm_offset_t -alloc_dma_mem(size, align) - vm_size_t size; - vm_offset_t align; -{ - int *bits, i, j, k, n; - int npages, count, bit, mask; - int first_page, last_page; - vm_offset_t addr; - vm_page_t p, prevp; - - npages = round_page(size) / PAGE_SIZE; - mask = align ? (align - 1) / PAGE_SIZE : 0; - - /* - * Allocate bit array. - */ - n = ((DMA_MAX / PAGE_SIZE) + NBPW - 1) / NBPW; - i = n * NBPW; - bits = (unsigned *)kalloc(i); - if (bits == 0) { - printf("alloc_dma_mem: unable alloc bit array\n"); - return (0); - } - bzero((char *)bits, i); - - /* - * Walk the page free list and set a bit for - * every usable page in bit array. - */ - simple_lock(&vm_page_queue_free_lock); - for (p = vm_page_queue_free; p; p = (vm_page_t)p->pageq.next) { - if (p->phys_addr < DMA_MAX) { - i = p->phys_addr / PAGE_SIZE; - bits[i / NBPW] |= 1 << (i % NBPW); - } - } - - /* - * Search for contiguous pages by scanning bit array. - */ - for (i = 0, first_page = -1; i < n; i++) { - for (bit = 1, j = 0; j < NBPW; j++, bit <<= 1) { - if (bits[i] & bit) { - if (first_page < 0) { - k = i * NBPW + j; - if (!mask - || (((k & mask) + npages) - <= mask + 1)) { - first_page = k; - if (npages == 1) - goto found; - count = 1; - } - } else if (++count == npages) - goto found; - } else - first_page = -1; - } - } - addr = 0; - goto out; - - found: - /* - * Remove pages from the free list. - */ - addr = first_page * PAGE_SIZE; - last_page = first_page + npages; - vm_page_free_count -= npages; - p = vm_page_queue_free; - prevp = 0; - while (1) { - i = p->phys_addr / PAGE_SIZE; - if (i >= first_page && i < last_page) { - if (prevp) - prevp->pageq.next = p->pageq.next; - else - vm_page_queue_free = (vm_page_t)p->pageq.next; - p->free = FALSE; - if (--npages == 0) - break; - } else - prevp = p; - p = (vm_page_t)p->pageq.next; - } - - out: - simple_unlock(&vm_page_queue_free_lock); - kfree((vm_offset_t)bits, n * NBPW); - return (addr); + return (((phys_first_addr <= x) && (x < phys_last_addr)) +#ifndef MACH_HYP + && !( + ((boot_info.mem_lower * 1024) <= x) && + (x < 1024*1024)) +#endif /* MACH_HYP */ + ); }