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/sparc64/sparc64/tsb.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) 1997 Berkeley Software Design, Inc. All rights reserved.
    3  *
    4  * Redistribution and use in source and binary forms, with or without
    5  * modification, are permitted provided that the following conditions
    6  * are met:
    7  * 1. Redistributions of source code must retain the above copyright
    8  *    notice, this list of conditions and the following disclaimer.
    9  * 2. Redistributions in binary form must reproduce the above copyright
   10  *    notice, this list of conditions and the following disclaimer in the
   11  *    documentation and/or other materials provided with the distribution.
   12  * 3. Berkeley Software Design Inc's name may not be used to endorse or
   13  *    promote products derived from this software without specific prior
   14  *    written permission.
   15  *
   16  * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``AS IS'' AND
   17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   19  * ARE DISCLAIMED.  IN NO EVENT SHALL BERKELEY SOFTWARE DESIGN INC BE LIABLE
   20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   26  * SUCH DAMAGE.
   27  *
   28  *      from BSDI: pmap.c,v 1.28.2.15 2000/04/27 03:10:31 cp Exp
   29  * $FreeBSD: releng/5.2/sys/sparc64/sparc64/tsb.c 119291 2003-08-22 07:39:05Z imp $
   30  */
   31 
   32 #include "opt_ddb.h"
   33 #include "opt_pmap.h"
   34 
   35 #include <sys/param.h>
   36 #include <sys/queue.h>
   37 #include <sys/ktr.h>
   38 #include <sys/linker_set.h>
   39 #include <sys/lock.h>
   40 #include <sys/mutex.h>
   41 #include <sys/proc.h>
   42 #include <sys/smp.h>
   43 #include <sys/sysctl.h>
   44 #include <sys/systm.h>
   45 
   46 #include <vm/vm.h> 
   47 #include <vm/vm_param.h>
   48 #include <vm/vm_kern.h>
   49 #include <vm/vm_page.h>
   50 #include <vm/vm_map.h>
   51 #include <vm/vm_object.h>
   52 #include <vm/vm_extern.h>
   53 #include <vm/vm_pageout.h>
   54 #include <vm/vm_pager.h>
   55 
   56 #include <machine/cpufunc.h>
   57 #include <machine/frame.h>
   58 #include <machine/trap.h>
   59 #include <machine/pmap.h>
   60 #include <machine/smp.h>
   61 #include <machine/tlb.h>
   62 #include <machine/tsb.h>
   63 #include <machine/tte.h>
   64 
   65 CTASSERT((1 << TTE_SHIFT) == sizeof(struct tte));
   66 CTASSERT(TSB_BUCKET_MASK < (1 << 12));
   67 
   68 PMAP_STATS_VAR(tsb_nrepl);
   69 PMAP_STATS_VAR(tsb_nlookup_k);
   70 PMAP_STATS_VAR(tsb_nlookup_u);
   71 PMAP_STATS_VAR(tsb_nenter_k);
   72 PMAP_STATS_VAR(tsb_nenter_k_oc);
   73 PMAP_STATS_VAR(tsb_nenter_u);
   74 PMAP_STATS_VAR(tsb_nenter_u_oc);
   75 PMAP_STATS_VAR(tsb_nforeach);
   76 
   77 struct tte *tsb_kernel;
   78 vm_size_t tsb_kernel_mask;
   79 vm_size_t tsb_kernel_size;
   80 vm_paddr_t tsb_kernel_phys;
   81 
   82 struct tte *
   83 tsb_tte_lookup(pmap_t pm, vm_offset_t va)
   84 {
   85         struct tte *bucket;
   86         struct tte *tp;
   87         u_long sz;
   88         u_int i;
   89 
   90         if (pm == kernel_pmap) {
   91                 PMAP_STATS_INC(tsb_nlookup_k);
   92                 tp = tsb_kvtotte(va);
   93                 if (tte_match(tp, va))
   94                         return (tp);
   95         } else {
   96                 PMAP_STATS_INC(tsb_nlookup_u);
   97                 for (sz = TS_MIN; sz <= TS_MAX; sz++) {
   98                         bucket = tsb_vtobucket(pm, sz, va);
   99                         for (i = 0; i < TSB_BUCKET_SIZE; i++) {
  100                                 tp = &bucket[i];
  101                                 if (tte_match(tp, va))
  102                                         return (tp);
  103                         }
  104                 }
  105         }
  106         return (NULL);
  107 }
  108 
  109 struct tte *
  110 tsb_tte_enter(pmap_t pm, vm_page_t m, vm_offset_t va, u_long sz, u_long data)
  111 {
  112         struct tte *bucket;
  113         struct tte *rtp;
  114         struct tte *tp;
  115         vm_offset_t ova;
  116         int b0;
  117         int i;
  118 
  119         if (m->pc != DCACHE_COLOR(va)) {
  120                 CTR6(KTR_CT2,
  121         "tsb_tte_enter: off colour va=%#lx pa=%#lx o=%p oc=%#lx ot=%d pi=%#lx",
  122                     va, VM_PAGE_TO_PHYS(m), m->object,
  123                     m->object ? m->object->pg_color : -1,
  124                     m->object ? m->object->type : -1,
  125                     m->pindex);
  126                 if (pm == kernel_pmap)
  127                         PMAP_STATS_INC(tsb_nenter_k_oc);
  128                 else
  129                         PMAP_STATS_INC(tsb_nenter_u_oc);
  130         }
  131 
  132         if (pm == kernel_pmap) {
  133                 PMAP_STATS_INC(tsb_nenter_k);
  134                 tp = tsb_kvtotte(va);
  135                 KASSERT((tp->tte_data & TD_V) == 0,
  136                     ("tsb_tte_enter: replacing valid kernel mapping"));
  137                 goto enter;
  138         }
  139         PMAP_STATS_INC(tsb_nenter_u);
  140 
  141         bucket = tsb_vtobucket(pm, sz, va);
  142 
  143         tp = NULL;
  144         rtp = NULL;
  145         b0 = rd(tick) & (TSB_BUCKET_SIZE - 1);
  146         i = b0;
  147         do {
  148                 if ((bucket[i].tte_data & TD_V) == 0) {
  149                         tp = &bucket[i];
  150                         break;
  151                 }
  152                 if (tp == NULL) {
  153                         if ((bucket[i].tte_data & TD_REF) == 0)
  154                                 tp = &bucket[i];
  155                         else if (rtp == NULL)
  156                                 rtp = &bucket[i];
  157                 }
  158         } while ((i = (i + 1) & (TSB_BUCKET_SIZE - 1)) != b0);
  159 
  160         if (tp == NULL)
  161                 tp = rtp;
  162         if ((tp->tte_data & TD_V) != 0) {
  163                 PMAP_STATS_INC(tsb_nrepl);
  164                 ova = TTE_GET_VA(tp);
  165                 vm_page_lock_queues();
  166                 pmap_remove_tte(pm, NULL, tp, ova);
  167                 vm_page_unlock_queues();
  168                 tlb_page_demap(pm, ova);
  169         }
  170 
  171 enter:
  172         if ((m->flags & PG_FICTITIOUS) == 0) {
  173                 data |= TD_CP;
  174                 if ((m->flags & PG_UNMANAGED) == 0) {
  175                         pm->pm_stats.resident_count++;
  176                         data |= TD_PV;
  177                 }
  178                 vm_page_lock_queues();
  179                 if (pmap_cache_enter(m, va) != 0)
  180                         data |= TD_CV;
  181                 TAILQ_INSERT_TAIL(&m->md.tte_list, tp, tte_link);
  182                 vm_page_unlock_queues();
  183         } else
  184                 data |= TD_FAKE | TD_E;
  185 
  186         tp->tte_vpn = TV_VPN(va, sz);
  187         tp->tte_data = data;
  188 
  189         return (tp);
  190 }
  191 
  192 /*
  193  * Traverse the tsb of a pmap, calling the callback function for any tte entry
  194  * that has a virtual address between start and end. If this function returns 0,
  195  * tsb_foreach() terminates.
  196  * This is used by pmap_remove() and pmap_protect() in the case that the number
  197  * of pages in the range given to them reaches the dimensions of the tsb size as
  198  * an optimization.
  199  */
  200 void
  201 tsb_foreach(pmap_t pm1, pmap_t pm2, vm_offset_t start, vm_offset_t end,
  202     tsb_callback_t *callback)
  203 {
  204         vm_offset_t va;
  205         struct tte *tp;
  206         int i;
  207 
  208         PMAP_STATS_INC(tsb_nforeach);
  209         for (i = 0; i < TSB_SIZE; i++) {
  210                 tp = &pm1->pm_tsb[i];
  211                 if ((tp->tte_data & TD_V) != 0) {
  212                         va = TTE_GET_VA(tp);
  213                         if (va >= start && va < end) {
  214                                 if (!callback(pm1, pm2, tp, va))
  215                                         break;
  216                         }
  217                 }
  218         }
  219 }

Cache object: e444e01aa81eeec6af75d056a4b5d6ac


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