void *mapiodev __P((void *, int)); void unmapiodev __P((void *, int)); vm_offset_t mapiospace __P((caddr_t, int)); void unmapiospace __P((vm_offset_t)); int badpaddr __P((caddr_t, int));    void cpu_fork(struct proc *p1, struct proc *p2, void *stack, size_t stacksize) { struct switchframe *p2sf; int cpu; struct ksigframe { void (*func)(struct proc *); void *proc; } *ksfp; extern struct pcb *curpcb; extern void proc_trampoline __P((void)); extern void save_u_area __P((struct proc *, vm_offset_t));  cpu = cpu_number();  savectx(curpcb);   bcopy((void *)&p1->p_addr->u_pcb, (void *)&p2->p_addr->u_pcb, sizeof(struct pcb)); p2->p_addr->u_pcb.kernel_state.pcb_ipl = 0;  p2->p_md.md_tf = USER_REGS(p2);   save_u_area(p2, (vm_offset_t)p2->p_addr); #ifdef notneeded pmap_activate(p2); #endif    p2sf = (struct switchframe *)((char *)p2->p_addr + USPACE - 8) - 1;  p2sf->sf_pc = (u_int)proc_do_uret; p2sf->sf_proc = p2; p2->p_addr->u_pcb.kernel_state.pcb_sp = (u_int)p2sf;   if (stack != NULL) USER_REGS(p2)->r[31] = (u_int)stack + stacksize;  ksfp = (struct ksigframe *)p2->p_addr->u_pcb.kernel_state.pcb_sp - 1;  ksfp->func = child_return; ksfp->proc = p2;    p2->p_addr->u_pcb.kernel_state.pcb_sp = (u_int)ksfp; p2->p_addr->u_pcb.kernel_state.pcb_pc = (u_int)proc_trampoline; }  void cpu_set_kpc(struct proc *p, void (*func)(void *), void *arg) {   struct ksigframe { void (*func)(void *); void *arg; } *ksfp;  ksfp = (struct ksigframe *)p->p_addr->u_pcb.kernel_state.pcb_sp;  ksfp->func = func; ksfp->arg = arg; }   void cpu_exit(struct proc *p) { (void) splimp();  uvmexp.swtch++; switch_exit(p);  }  int cpu_coredump(struct proc *p, struct vnode *vp, struct ucred *cred, struct core *corep) { return (vn_rdwr(UIO_WRITE, vp, (caddr_t) p->p_addr, ctob(UPAGES), (off_t)0, UIO_SYSSPACE, IO_NODELOCKED|IO_UNIT, cred, NULL, p)); }    void cpu_swapin(struct proc *p) { extern void save_u_area __P((struct proc *, vm_offset_t));  save_u_area(p, (vm_offset_t)p->p_addr); }  extern vm_map_t phys_map;   void vmapbuf(bp, len) struct buf *bp; vm_size_t len; { register caddr_t addr; register vm_offset_t kva, off; vm_offset_t pa; struct pmap *pmap;  #ifdef DIAGNOSTIC if ((bp->b_flags & B_PHYS) == 0) panic("vmapbuf"); #endif  addr = (caddr_t)trunc_page((vaddr_t)(bp->b_saveaddr = bp->b_data)); off = (vm_offset_t)bp->b_saveaddr & PGOFSET; len = round_page(off + len); pmap = vm_map_pmap(&bp->b_proc->p_vmspace->vm_map);    kva = uvm_km_valloc_wait(phys_map, len);    cmmu_flush_tlb(1, kva, len);  bp->b_data = (caddr_t)(kva + off); while (len > 0) { if (pmap_extract(pmap, (vm_offset_t)addr, &pa) == FALSE) panic("vmapbuf: null page frame"); pmap_enter(vm_map_pmap(phys_map), kva, pa, VM_PROT_READ|VM_PROT_WRITE, PMAP_WIRED); addr += PAGE_SIZE; kva += PAGE_SIZE; len -= PAGE_SIZE; } }   void vunmapbuf(bp, len) struct buf *bp; vm_size_t len; { register vm_offset_t addr, off;  #ifdef DIAGNOSTIC if ((bp->b_flags & B_PHYS) == 0) panic("vunmapbuf"); #endif  addr = trunc_page((vaddr_t)bp->b_data); off = (vm_offset_t)bp->b_data & PGOFSET; len = round_page(off + len); uvm_km_free_wakeup(phys_map, addr, len); bp->b_data = bp->b_saveaddr; bp->b_saveaddr = 0; }    vm_offset_t iomap_mapin(vm_offset_t pa, vm_size_t len, boolean_t canwait) { vm_offset_t	iova, tva, off, ppa; int 		s, error;  if (len == 0) return NULL;  ppa = pa; off = (u_long)ppa & PGOFSET;  len = round_page(off + len);  s = splhigh(); error = extent_alloc(iomap_extent, len, PAGE_SIZE, 0, EX_NOBOUNDARY, canwait ? EX_WAITSPACE : EX_NOWAIT, &iova); splx(s);  if (error != 0) return NULL;  cmmu_flush_tlb(1, iova, len);  ppa = trunc_page(ppa);  #ifndef NEW_MAPPING tva = iova; #else tva = ppa; #endif  while (len>0) { pmap_enter(vm_map_pmap(iomap_map), tva, ppa, VM_PROT_WRITE|VM_PROT_READ|(CACHE_INH << 16), PMAP_WIRED); len -= PAGE_SIZE; tva += PAGE_SIZE; ppa += PAGE_SIZE; } #ifndef NEW_MAPPING return (iova + off); #else return (pa + off); #endif  }   void iomap_mapout(vm_offset_t kva, vm_size_t len) { vm_offset_t 	off; int 		s, error;  off = kva & PGOFSET; kva = trunc_page(kva); len = round_page(off + len);  pmap_remove(vm_map_pmap(iomap_map), kva, kva + len);  s = splhigh(); error = extent_free(iomap_extent, kva, len, EX_NOWAIT); splx(s);  if (error != 0) printf("iomap_mapout: extent_free failed\n"); }   void *
mapiodev(pa, size)	void *pa;	int size;{	vm_offset_t ppa;	ppa = (vm_offset_t)pa;	return ((void *)iomap_mapin(ppa, size, 0));}