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/ofw_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) 1996 Wolfgang Solfrank.
    3  * Copyright (C) 1996 TooLs GmbH.
    4  * All rights reserved.
    5  *
    6  * Redistribution and use in source and binary forms, with or without
    7  * modification, are permitted provided that the following conditions
    8  * are met:
    9  * 1. Redistributions of source code must retain the above copyright
   10  *    notice, this list of conditions and the following disclaimer.
   11  * 2. Redistributions in binary form must reproduce the above copyright
   12  *    notice, this list of conditions and the following disclaimer in the
   13  *    documentation and/or other materials provided with the distribution.
   14  * 3. All advertising materials mentioning features or use of this software
   15  *    must display the following acknowledgement:
   16  *      This product includes software developed by TooLs GmbH.
   17  * 4. The name of TooLs GmbH may not be used to endorse or promote products
   18  *    derived from this software without specific prior written permission.
   19  *
   20  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
   21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   23  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
   25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
   26  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
   27  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
   28  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
   29  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   30  *
   31  * $NetBSD: ofw_machdep.c,v 1.5 2000/05/23 13:25:43 tsubai Exp $
   32  */
   33 
   34 #include <sys/cdefs.h>
   35 __FBSDID("$FreeBSD: releng/5.1/sys/powerpc/powerpc/ofw_machdep.c 113038 2003-04-03 21:36:33Z obrien $");
   36 
   37 #include <sys/param.h>
   38 #include <sys/bus.h>
   39 #include <sys/systm.h>
   40 #include <sys/conf.h>
   41 #include <sys/disk.h>
   42 #include <sys/disklabel.h>
   43 #include <sys/fcntl.h>
   44 #include <sys/malloc.h>
   45 #include <sys/stat.h>
   46 
   47 #include <net/ethernet.h>
   48 
   49 #include <dev/ofw/openfirm.h>
   50 
   51 #include <vm/vm.h>
   52 #include <vm/vm_param.h>
   53 #include <vm/vm_page.h>
   54 
   55 #include <machine/powerpc.h>
   56 #include <machine/ofw_machdep.h>
   57 #include <powerpc/ofw/ofw_pci.h>
   58 
   59 #define OFMEM_REGIONS   32
   60 static struct mem_region OFmem[OFMEM_REGIONS + 1], OFavail[OFMEM_REGIONS + 3];
   61 
   62 extern long     ofmsr;
   63 extern struct   pmap ofw_pmap;
   64 extern int      pmap_bootstrapped;
   65 static int      (*ofwcall)(void *);
   66 
   67 /*
   68  * This is called during powerpc_init, before the system is really initialized.
   69  * It shall provide the total and the available regions of RAM.
   70  * Both lists must have a zero-size entry as terminator.
   71  * The available regions need not take the kernel into account, but needs
   72  * to provide space for two additional entry beyond the terminating one.
   73  */
   74 void
   75 mem_regions(struct mem_region **memp, int *memsz,
   76                 struct mem_region **availp, int *availsz)
   77 {
   78         int phandle;
   79         int asz, msz; 
   80         
   81         /*
   82          * Get memory.
   83          */
   84         if ((phandle = OF_finddevice("/memory")) == -1
   85             || (msz = OF_getprop(phandle, "reg",
   86                           OFmem, sizeof OFmem[0] * OFMEM_REGIONS))
   87                <= 0
   88             || (asz = OF_getprop(phandle, "available",
   89                           OFavail, sizeof OFavail[0] * OFMEM_REGIONS))
   90                <= 0)
   91                 panic("no memory?");
   92         *memp = OFmem;
   93         *memsz = msz / sizeof(struct mem_region);
   94         *availp = OFavail;
   95         *availsz = asz / sizeof(struct mem_region);
   96 }
   97 
   98 void
   99 set_openfirm_callback(int (*openfirm)(void *))
  100 {
  101 
  102         ofwcall = openfirm;
  103 }
  104 
  105 int
  106 openfirmware(void *args)
  107 {
  108         long    oldmsr;
  109         int     result;
  110         u_int   srsave[16];
  111         u_int   i;
  112 
  113         __asm __volatile(       "\t"
  114                 "sync\n\t"
  115                 "mfmsr  %0\n\t"
  116                 "mtmsr  %1\n\t"
  117                 "isync\n"
  118                 : "=r" (oldmsr)
  119                 : "r" (ofmsr)
  120         );
  121 
  122         if (pmap_bootstrapped) {
  123                 /*
  124                  * Swap the kernel's address space with OpenFirmware's
  125                  */
  126                 for (i = 0; i < 16; i++) {
  127                         srsave[i] = mfsrin(i << ADDR_SR_SHFT);
  128                         mtsrin(i << ADDR_SR_SHFT, ofw_pmap.pm_sr[i]);
  129                 }
  130 
  131                 /*
  132                  * Clear battable[] translations
  133                  */
  134                 __asm __volatile("mtdbatu 2, %0\n"
  135                                  "mtdbatu 3, %0" : : "r" (0));
  136                 isync();
  137         }
  138         
  139         result = ofwcall(args);
  140 
  141         if (pmap_bootstrapped) {
  142                 /*
  143                  * Restore the kernel's addr space. The isync() doesn;t
  144                  * work outside the loop unless mtsrin() is open-coded
  145                  * in an asm statement :(
  146                  */
  147                 for (i = 0; i < 16; i++) {
  148                         mtsrin(i << ADDR_SR_SHFT, srsave[i]);
  149                         isync();
  150                 }
  151         }
  152 
  153         __asm(  "\t"
  154                 "mtmsr  %0\n\t"
  155                 "isync\n"
  156                 : : "r" (oldmsr)
  157         );
  158 
  159         return (result);
  160 }
  161 
  162 void
  163 ppc_exit()
  164 {
  165 
  166         OF_exit();
  167 }
  168 
  169 void
  170 ppc_boot(str)
  171         char *str;
  172 {
  173 
  174         OF_boot(str);
  175 }
  176 
  177 void
  178 OF_getetheraddr(device_t dev, u_char *addr)
  179 {
  180         phandle_t       node;
  181 
  182         node = ofw_pci_find_node(dev);
  183         OF_getprop(node, "local-mac-address", addr, ETHER_ADDR_LEN);
  184 }

Cache object: 22e5c8f073a6d30f281591eaf1062f39


[ 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.