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/compat/darwin/darwin_commpage.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 /*      $NetBSD: darwin_commpage.c,v 1.15 2008/04/28 20:23:41 martin Exp $ */
    2 
    3 /*-
    4  * Copyright (c) 2004 The NetBSD Foundation, Inc.
    5  * All rights reserved.
    6  *
    7  * This code is derived from software contributed to The NetBSD Foundation
    8  * by Emmanuel Dreyfus.
    9  *
   10  * Redistribution and use in source and binary forms, with or without
   11  * modification, are permitted provided that the following conditions
   12  * are met:
   13  * 1. Redistributions of source code must retain the above copyright
   14  *    notice, this list of conditions and the following disclaimer.
   15  * 2. Redistributions in binary form must reproduce the above copyright
   16  *    notice, this list of conditions and the following disclaimer in the
   17  *    documentation and/or other materials provided with the distribution.
   18  *
   19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
   20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
   23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   29  * POSSIBILITY OF SUCH DAMAGE.
   30  */
   31 
   32 #include <sys/cdefs.h>
   33 __KERNEL_RCSID(0, "$NetBSD: darwin_commpage.c,v 1.15 2008/04/28 20:23:41 martin Exp $");
   34 
   35 #include <sys/param.h>
   36 #include <sys/kernel.h>
   37 #include <sys/sysctl.h>
   38 #include <sys/lwp.h>
   39 #include <sys/proc.h>
   40 
   41 #include <compat/sys/signal.h>
   42 #include <compat/sys/signalvar.h>
   43 
   44 #include <sys/cpu.h>
   45 #include <machine/darwin_machdep.h>
   46 
   47 #include <uvm/uvm_extern.h>
   48 #include <uvm/uvm_map.h>
   49 #include <uvm/uvm.h>
   50 
   51 #include <compat/darwin/darwin_commpage.h>
   52 
   53 /* XXX: this does not belong here! */
   54 #ifdef __powerpc__
   55 #include "opt_altivec.h"
   56 #endif
   57 
   58 #ifdef DEBUG_DARWIN
   59 #define DPRINTF(a) uprintf a
   60 #else
   61 #define DPRINTF(a) 
   62 #endif
   63 
   64 static struct uvm_object *darwin_commpage_uao = NULL;
   65 
   66 static void darwin_commpage_init(struct darwin_commpage *);
   67 
   68 int
   69 darwin_commpage_map(struct proc *p)
   70 {
   71         int error;
   72         vaddr_t kvaddr;
   73         vaddr_t pvaddr;
   74         size_t memsize;
   75 
   76         /*
   77          * XXX This crashes. For now we map only one page,
   78          * to avoid the crash, but this ought to be fixed
   79          */
   80         memsize = round_page(sizeof(struct darwin_commpage));
   81 
   82         if (darwin_commpage_uao == NULL) {
   83                 darwin_commpage_uao = uao_create(memsize, 0);
   84                 kvaddr = vm_map_min(kernel_map);
   85 
   86                 error = uvm_map(kernel_map, &kvaddr, memsize,
   87                     darwin_commpage_uao, 0, PAGE_SIZE,
   88                     UVM_MAPFLAG(UVM_PROT_RW, UVM_PROT_RW,
   89                     UVM_INH_SHARE, UVM_ADV_RANDOM, 0));
   90                 if (error != 0) {
   91                         DPRINTF(("kernel uvm_map darwin_compage failed "
   92                             "(error %d)\n", error));
   93                         uao_detach(darwin_commpage_uao);
   94                         darwin_commpage_uao = NULL;
   95                         return -1;
   96                 }
   97 
   98                 error = uvm_map_pageable(kernel_map, kvaddr,
   99                     kvaddr + memsize, FALSE, 0);
  100                 if (error != 0) {
  101                         DPRINTF(("kernel uvm_map_pageable darwin_compage "
  102                             "failed (error %d)\n", error));
  103                         uao_detach(darwin_commpage_uao);
  104                         darwin_commpage_uao = NULL;
  105                         return -1;
  106                 }
  107 
  108                 darwin_commpage_init((struct darwin_commpage *)kvaddr);
  109         }
  110 
  111         uao_reference(darwin_commpage_uao);
  112         pvaddr = DARWIN_COMMPAGE_BASE;
  113 
  114         if ((error = uvm_map(&p->p_vmspace->vm_map, &pvaddr,
  115             memsize, darwin_commpage_uao, 0, 0,
  116             UVM_MAPFLAG(UVM_PROT_RX, UVM_PROT_RX,
  117             UVM_INH_SHARE, UVM_ADV_NORMAL, UVM_FLAG_FIXED))) != 0) {
  118                 DPRINTF(("user uvm_map darwin_commpage failed at "
  119                     "0x%08lx/memsize (error %d)\n", (long)pvaddr, error));
  120                 return -1;
  121         }
  122 
  123         DPRINTF(("mapped darwin_commpage at 0x%08lx\n", (long)pvaddr));
  124 
  125         return 0;
  126 }
  127 
  128 #define DCP_MEMCPY(x) {                                                 \
  129         size_t len;                                                     \
  130                                                                         \
  131         len = (size_t)darwin_commpage_##x##_size;                       \
  132                                                                         \
  133         if (len > sizeof(dcp->dcp_##x)) {                               \
  134                 printf("darwin_commpage: %s too big (%zu/%zu)\n", #x,   \
  135                         len, sizeof(dcp->dcp_##x));                     \
  136         } else {                                                        \
  137                 memcpy(dcp->dcp_##x, (void *)darwin_commpage_##x, len); \
  138         }                                                               \
  139 }
  140 
  141 void
  142 darwin_commpage_init(struct darwin_commpage *dcp)
  143 {
  144         /*
  145          * XXX Only one page is mapped yet (see higher in the file)
  146          */
  147         (void)memset(dcp, 0, sizeof(*dcp));
  148 
  149         dcp->dcp_version = DARWIN_COMMPAGE_VERSION;
  150         dcp->dcp_ncpu = ncpu;
  151         dcp->dcp_cap |= (ncpu << DARWIN_CAP_NCPUSHIFT);
  152 
  153 #ifdef DARWIN_CAP_UP
  154         if (ncpu == 1)
  155                 dcp->dcp_cap |= DARWIN_CAP_UP;
  156 #endif
  157 
  158         /* XXX: This needs to be processor specific */
  159 #ifdef ALTIVEC
  160         dcp->dcp_vector = 1;
  161         dcp->dcp_cap |= DARWIN_CAP_ALTIVEC;
  162 #endif
  163 
  164 #if defined(_LP64) && defined(DARWIN_CAP_64BIT)
  165         dcp->dcp_64bit = 1;
  166         dcp->dcp_cap |= DARWIN_CAP_64BIT;
  167 #endif
  168 
  169 #ifndef CACHELINESIZE
  170 #define CACHELINESIZE 32        /* for i386... */
  171 #endif
  172         dcp->dcp_cachelinelen = CACHELINESIZE;
  173 #if (CACHELINESIZE == 32)
  174         dcp->dcp_cap |= DARWIN_CAP_CACHE32;
  175 #elif (CACHELINESIZE == 64)
  176         dcp->dcp_cap |= DARWIN_CAP_CACHE64;
  177 #elif (CACHELINESIZE == 128)
  178         dcp->dcp_cap |= DARWIN_CAP_CACHE128;
  179 #endif
  180 
  181         dcp->dcp_2pow52 = 4503599627370496ULL;  /* 2^52 */
  182         dcp->dcp_10pow6 = 1000000ULL;           /* 10^6 */
  183 
  184         /*
  185          * On Darwin, these are maintained up to date by the kernel
  186          */
  187         dcp->dcp_timebase = 0; /* XXX */
  188         dcp->dcp_timestamp = 0; /* XXX */
  189         dcp->dcp_secpertick = hz; /* XXX Not sure */
  190 
  191         DCP_MEMCPY(mach_absolute_time);
  192         DCP_MEMCPY(spinlock_try);
  193         DCP_MEMCPY(spinlock_lock);
  194         DCP_MEMCPY(spinlock_unlock);
  195         DCP_MEMCPY(pthread_getspecific);
  196         DCP_MEMCPY(gettimeofday);
  197         DCP_MEMCPY(sys_dcache_flush);
  198         DCP_MEMCPY(sys_icache_invalidate);
  199         DCP_MEMCPY(pthread_self);
  200         DCP_MEMCPY(spinlock_relinquish);
  201         DCP_MEMCPY(bzero);
  202         DCP_MEMCPY(bcopy);
  203         DCP_MEMCPY(memcpy);
  204         DCP_MEMCPY(bigcopy);
  205 }

Cache object: e64a2858629016c92473627e32766f93


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