The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/powerpc/powerpc/vm_machdep.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 1982, 1986 The Regents of the University of California.
    3  * Copyright (c) 1989, 1990 William Jolitz
    4  * Copyright (c) 1994 John Dyson
    5  * All rights reserved.
    6  *
    7  * This code is derived from software contributed to Berkeley by
    8  * the Systems Programming Group of the University of Utah Computer
    9  * Science Department, and William Jolitz.
   10  *
   11  * Redistribution and use in source and binary forms, with or without
   12  * modification, are permitted provided that the following conditions
   13  * are met:
   14  * 1. Redistributions of source code must retain the above copyright
   15  *    notice, this list of conditions and the following disclaimer.
   16  * 2. Redistributions in binary form must reproduce the above copyright
   17  *    notice, this list of conditions and the following disclaimer in the
   18  *    documentation and/or other materials provided with the distribution.
   19  * 3. All advertising materials mentioning features or use of this software
   20  *    must display the following acknowledgement:
   21  *      This product includes software developed by the University of
   22  *      California, Berkeley and its contributors.
   23  * 4. Neither the name of the University nor the names of its contributors
   24  *    may be used to endorse or promote products derived from this software
   25  *    without specific prior written permission.
   26  *
   27  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   28  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   29  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   30  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   31  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   32  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   33  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   34  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   35  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   36  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   37  * SUCH DAMAGE.
   38  *
   39  *      from: @(#)vm_machdep.c  7.3 (Berkeley) 5/13/91
   40  *      Utah $Hdr: vm_machdep.c 1.16.1.1 89/06/23$
   41  * $FreeBSD: releng/5.0/sys/powerpc/powerpc/vm_machdep.c 107719 2002-12-10 02:33:45Z julian $
   42  */
   43 /*
   44  * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
   45  * All rights reserved.
   46  *
   47  * Author: Chris G. Demetriou
   48  * 
   49  * Permission to use, copy, modify and distribute this software and
   50  * its documentation is hereby granted, provided that both the copyright
   51  * notice and this permission notice appear in all copies of the
   52  * software, derivative works or modified versions, and any portions
   53  * thereof, and that both notices appear in supporting documentation.
   54  * 
   55  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 
   56  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 
   57  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
   58  * 
   59  * Carnegie Mellon requests users of this software to return to
   60  *
   61  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
   62  *  School of Computer Science
   63  *  Carnegie Mellon University
   64  *  Pittsburgh PA 15213-3890
   65  *
   66  * any improvements or extensions that they make and grant Carnegie the
   67  * rights to redistribute these changes.
   68  */
   69 
   70 #include <sys/param.h>
   71 #include <sys/systm.h>
   72 #include <sys/proc.h>
   73 #include <sys/malloc.h>
   74 #include <sys/bio.h>
   75 #include <sys/buf.h>
   76 #include <sys/ktr.h>
   77 #include <sys/lock.h>
   78 #include <sys/mutex.h>
   79 #include <sys/vnode.h>
   80 #include <sys/vmmeter.h>
   81 #include <sys/kernel.h>
   82 #include <sys/sysctl.h>
   83 #include <sys/unistd.h>
   84 
   85 #include <machine/clock.h>
   86 #include <machine/cpu.h>
   87 #include <machine/fpu.h>
   88 #include <machine/frame.h>
   89 #include <machine/md_var.h>
   90 
   91 #include <dev/ofw/openfirm.h>
   92 
   93 #include <vm/vm.h>
   94 #include <vm/vm_param.h>
   95 #include <vm/vm_kern.h>
   96 #include <vm/vm_page.h>
   97 #include <vm/vm_map.h>
   98 #include <vm/vm_extern.h>
   99 
  100 #include <sys/user.h>
  101 
  102 /*
  103  * quick version of vm_fault
  104  */
  105 int
  106 vm_fault_quick(v, prot)
  107         caddr_t v;
  108         int prot;
  109 {
  110         int r;
  111         if (prot & VM_PROT_WRITE)
  112                 r = subyte(v, fubyte(v));
  113         else
  114                 r = fubyte(v);
  115         return(r);
  116 }
  117 
  118 /*
  119  * Finish a fork operation, with process p2 nearly set up.
  120  * Copy and update the pcb, set up the stack so that the child
  121  * ready to run and return to user mode.
  122  */
  123 void
  124 cpu_fork(struct thread *td1, struct proc *p2, struct thread *td2, int flags)
  125 {
  126         struct  proc *p1;
  127         struct  trapframe *tf;
  128         struct  callframe *cf;
  129         struct  pcb *pcb;
  130 
  131         KASSERT(td1 == curthread || td1 == &thread0,
  132             ("cpu_fork: p1 not curproc and not proc0"));
  133         CTR3(KTR_PROC, "cpu_fork: called td1=%08x p2=%08x flags=%x", (u_int)td1, (u_int)p2, flags);
  134 
  135         if ((flags & RFPROC) == 0)
  136                 return;
  137 
  138         p1 = td1->td_proc;
  139 
  140         pcb = (struct pcb *)((td2->td_kstack + KSTACK_PAGES * PAGE_SIZE -
  141             sizeof(struct pcb)) & ~0x2fU);
  142         td2->td_pcb = pcb;
  143 
  144         /* Copy the pcb */
  145         bcopy(td1->td_pcb, pcb, sizeof(struct pcb));
  146 
  147         /*
  148          * Create a fresh stack for the new process.
  149          * Copy the trap frame for the return to user mode as if from a
  150          * syscall.  This copies most of the user mode register values.
  151          */
  152         tf = (struct trapframe *)pcb - 1;
  153         bcopy(td1->td_frame, tf, sizeof(*tf));
  154 
  155         /* Set up trap frame. */
  156         tf->fixreg[FIRSTARG] = 0;
  157         tf->fixreg[FIRSTARG + 1] = 0;
  158         tf->cr &= ~0x10000000;
  159 
  160         td2->td_frame = tf;
  161 
  162         cf = (struct callframe *)tf - 1;
  163         cf->cf_func = (register_t)fork_return;
  164         cf->cf_arg0 = (register_t)td2;
  165         cf->cf_arg1 = (register_t)tf;
  166 
  167         pcb->pcb_sp = (register_t)cf;
  168         pcb->pcb_lr = (register_t)fork_trampoline;
  169         pcb->pcb_usr = kernel_pmap->pm_sr[USER_SR];
  170 
  171         /*
  172          * Now cpu_switch() can schedule the new process.
  173          */
  174 }
  175 
  176 /*
  177  * Intercept the return address from a freshly forked process that has NOT
  178  * been scheduled yet.
  179  *
  180  * This is needed to make kernel threads stay in kernel mode.
  181  */
  182 void
  183 cpu_set_fork_handler(td, func, arg)
  184         struct thread *td;
  185         void (*func)(void *);
  186         void *arg;
  187 {
  188         struct  callframe *cf;
  189 
  190         CTR3(KTR_PROC, "cpu_set_fork_handler: called with td=%08x func=%08x arg=%08x",
  191             (u_int)td, (u_int)func, (u_int)arg);
  192 
  193         cf = (struct callframe *)td->td_pcb->pcb_sp;
  194 
  195         cf->cf_func = (register_t)func;
  196         cf->cf_arg0 = (register_t)arg;
  197 }
  198 
  199 /*
  200  * cpu_exit is called as the last action during exit.
  201  * We release the address space of the process, block interrupts,
  202  * and call switch_exit.  switch_exit switches to proc0's PCB and stack,
  203  * then jumps into the middle of cpu_switch, as if it were switching
  204  * from proc0.
  205  */
  206 void
  207 cpu_exit(td)
  208         register struct thread *td;
  209 {
  210 }
  211 
  212 void
  213 cpu_sched_exit(td)
  214         register struct thread *td;
  215 {
  216 }
  217 
  218 void
  219 cpu_wait(td)
  220         struct proc *td;
  221 {
  222 }
  223 
  224 /* Temporary helper */
  225 void
  226 cpu_throw(void)
  227 {
  228 
  229         cpu_switch();
  230         panic("cpu_throw() didn't");
  231 }
  232 
  233 /*
  234  * Map an IO request into kernel virtual address space.
  235  *
  236  * All requests are (re)mapped into kernel VA space.
  237  * Notice that we use b_bufsize for the size of the buffer
  238  * to be mapped.  b_bcount might be modified by the driver.
  239  */
  240 void
  241 vmapbuf(struct buf *bp)
  242 {
  243         caddr_t addr, kva;
  244         vm_offset_t pa;
  245         int pidx;
  246         struct vm_page *m;
  247         pmap_t pmap;
  248 
  249         GIANT_REQUIRED;
  250 
  251         if ((bp->b_flags & B_PHYS) == 0)
  252                 panic("vmapbuf");
  253 
  254         pmap = &curproc->p_vmspace->vm_pmap;
  255         for (addr = (caddr_t)trunc_page(bp->b_data), pidx = 0;
  256             addr < bp->b_data + bp->b_bufsize;
  257             addr += PAGE_SIZE, pidx++) {
  258                 /*
  259                  * Do the vm_fault if needed; do the copy-on-write thing
  260                  * when reading stuff off device into memory.
  261                  */
  262                 vm_fault_quick((addr >= bp->b_data) ? addr : bp->b_data,
  263                         (bp->b_iocmd == BIO_READ)?(VM_PROT_READ|VM_PROT_WRITE):VM_PROT_READ);
  264                 pa = trunc_page(pmap_extract(pmap, (vm_offset_t) addr));
  265                 if (pa == 0)
  266                         panic("vmapbuf: page not present");
  267                 m = PHYS_TO_VM_PAGE(pa);
  268                 vm_page_hold(m);
  269                 bp->b_pages[pidx] = m;
  270         }
  271         if (pidx > btoc(MAXPHYS))
  272                 panic("vmapbuf: mapped more than MAXPHYS");
  273         pmap_qenter((vm_offset_t)bp->b_saveaddr, bp->b_pages, pidx);
  274 
  275         kva = bp->b_saveaddr;
  276         bp->b_npages = pidx;
  277         bp->b_saveaddr = bp->b_data;
  278         bp->b_data = kva + (((vm_offset_t) bp->b_data) & PAGE_MASK);
  279 }
  280 
  281 /*
  282  * Free the io map PTEs associated with this IO operation.
  283  * We also invalidate the TLB entries and restore the original b_addr.
  284  */
  285 void
  286 vunmapbuf(struct buf *bp)
  287 {
  288         int pidx;
  289         int npages;
  290 
  291         GIANT_REQUIRED;
  292 
  293         if ((bp->b_flags & B_PHYS) == 0)
  294                 panic("vunmapbuf");
  295 
  296         npages = bp->b_npages;
  297         pmap_qremove(trunc_page((vm_offset_t)bp->b_data),
  298             npages);
  299         for (pidx = 0; pidx < npages; pidx++)
  300                 vm_page_unhold(bp->b_pages[pidx]);
  301 
  302         bp->b_data = bp->b_saveaddr;
  303 }
  304 
  305 /*
  306  * Reset back to firmware.
  307  */
  308 void
  309 cpu_reset()
  310 {
  311         OF_exit();
  312 }
  313 
  314 /*
  315  * Software interrupt handler for queued VM system processing.
  316  */   
  317 void  
  318 swi_vm(void *dummy) 
  319 {     
  320 #if 0 /* XXX: Don't have busdma stuff yet */
  321         if (busdma_swi_pending != 0)
  322                 busdma_swi();
  323 #endif
  324 }
  325 
  326 /*
  327  * Tell whether this address is in some physical memory region.
  328  * Currently used by the kernel coredump code in order to avoid
  329  * dumping the ``ISA memory hole'' which could cause indefinite hangs,
  330  * or other unpredictable behaviour.
  331  */
  332 
  333 
  334 int
  335 is_physical_memory(addr)
  336         vm_offset_t addr;
  337 {
  338         /*
  339          * stuff other tests for known memory-mapped devices (PCI?)
  340          * here
  341          */
  342 
  343         return 1;
  344 }
  345 
  346 /*
  347  * KSE functions
  348  */
  349 void
  350 cpu_thread_exit(struct thread *td)     
  351 {
  352 
  353         return;
  354 }
  355 
  356 void
  357 cpu_thread_clean(struct thread *td)     
  358 {
  359 }
  360 
  361 void
  362 cpu_thread_setup(struct thread *td)
  363 {
  364 
  365         return;
  366 }
  367 
  368 void
  369 cpu_set_upcall(struct thread *td, void *pcb)
  370 {
  371 
  372         return;
  373 }
  374 
  375 void
  376 cpu_set_upcall_kse(struct thread *td, struct kse *ke)
  377 {
  378 
  379         return;
  380 }

Cache object: ba8c5c1b905c0e9edaf2048b7b9cb6eb


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.