]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - sys/sun4v/include/pmap.h
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / sys / sun4v / include / pmap.h
1 /*-
2  * Copyright (c) 1991 Regents of the University of California.
3  * All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * the Systems Programming Group of the University of Utah Computer
7  * Science Department and William Jolitz of UUNET Technologies Inc.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 4. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  *      from: hp300: @(#)pmap.h 7.2 (Berkeley) 12/16/90
34  *      from: @(#)pmap.h        7.4 (Berkeley) 5/12/91
35  *      from: FreeBSD: src/sys/i386/include/pmap.h,v 1.70 2000/11/30
36  * $FreeBSD$
37  */
38
39 #ifndef _MACHINE_PMAP_H_
40 #define _MACHINE_PMAP_H_
41
42 #include <sys/types.h>
43 #include <sys/queue.h>
44 #include <sys/_lock.h>
45 #include <sys/_mutex.h>
46 #include <machine/hv_api.h>
47
48 #define TSB_INIT_SHIFT          3
49 #define PMAP_CONTEXT_MAX        8192
50 /* 
51  *  We don't want TSBs getting above 1MB - which is enough 
52  *  for a working set of 512MB - revisit in the future 
53  */
54 #define TSB_MAX_RESIZE          (20 - TSB_INIT_SHIFT - PAGE_SHIFT)
55
56 typedef struct pmap *pmap_t;
57 typedef uint32_t pmap_cpumask_t;
58
59 struct pv_entry;
60 struct tte_hash;
61
62 struct md_page {
63         int pv_list_count;
64         TAILQ_HEAD(, pv_entry) pv_list;
65 };
66
67
68 struct pmap {
69         uint64_t                pm_context;
70         uint64_t                pm_hashscratch;
71         uint64_t                pm_tsbscratch;
72         vm_paddr_t              pm_tsb_ra;
73
74         struct  mtx             pm_mtx;
75         struct tte_hash        *pm_hash;
76         TAILQ_HEAD(,pv_entry)   pm_pvlist;      /* list of mappings in pmap */
77         struct hv_tsb_info      pm_tsb;
78         pmap_cpumask_t          pm_active;      /* mask of cpus currently using pmap */
79         pmap_cpumask_t          pm_tlbactive;   /* mask of cpus that have used this pmap */
80         struct  pmap_statistics pm_stats;
81         uint32_t                pm_tsb_miss_count;
82         uint32_t                pm_tsb_cap_miss_count;
83         vm_paddr_t              pm_old_tsb_ra[TSB_MAX_RESIZE];
84 };
85
86 #define PMAP_LOCK(pmap)         mtx_lock(&(pmap)->pm_mtx)
87 #define PMAP_LOCK_ASSERT(pmap, type) \
88                                 mtx_assert(&(pmap)->pm_mtx, (type))
89 #define PMAP_LOCK_DESTROY(pmap) mtx_destroy(&(pmap)->pm_mtx)
90 #define PMAP_LOCK_INIT(pmap)    mtx_init(&(pmap)->pm_mtx, "pmap", \
91                                     NULL, MTX_DEF | MTX_DUPOK)
92 #define PMAP_LOCKED(pmap)       mtx_owned(&(pmap)->pm_mtx)
93 #define PMAP_MTX(pmap)          (&(pmap)->pm_mtx)
94 #define PMAP_TRYLOCK(pmap)      mtx_trylock(&(pmap)->pm_mtx)
95 #define PMAP_UNLOCK(pmap)       mtx_unlock(&(pmap)->pm_mtx)
96
97 /*
98  * For each vm_page_t, there is a list of all currently valid virtual
99  * mappings of that page.  An entry is a pv_entry_t, the list is pv_list.
100  */
101
102 typedef struct pv_entry {
103         pmap_t  pv_pmap;
104         vm_offset_t     pv_va;
105         TAILQ_ENTRY(pv_entry) pv_list;
106         TAILQ_ENTRY(pv_entry) pv_plist;
107 } *pv_entry_t;
108
109 #define pmap_page_get_memattr(m)        VM_MEMATTR_DEFAULT
110 #define pmap_page_is_mapped(m)  (!TAILQ_EMPTY(&(m)->md.pv_list))
111 #define pmap_page_set_memattr(m, ma)    (void)0
112
113 void    pmap_bootstrap(vm_offset_t ekva);
114 vm_paddr_t pmap_kextract(vm_offset_t va);
115
116 void    pmap_invalidate_page(pmap_t pmap, vm_offset_t va, int cleartsb);
117 void    pmap_invalidate_range(pmap_t pmap, vm_offset_t sva, vm_offset_t eva, int cleartsb);
118 void    pmap_invalidate_all(pmap_t pmap);
119 void    pmap_scrub_pages(vm_paddr_t pa, int64_t size);
120 void    pmap_free_contig_pages(void *ptr, int npages);
121 void    *pmap_alloc_zeroed_contig_pages(int npages, uint64_t alignment);
122
123 #define vtophys(va)     pmap_kextract((vm_offset_t)(va))
124
125 extern  struct pmap kernel_pmap_store;
126 #define kernel_pmap     (&kernel_pmap_store)
127 extern  vm_paddr_t phys_avail[];
128 extern  vm_offset_t virtual_avail;
129 extern  vm_offset_t virtual_end;
130 extern  vm_paddr_t msgbuf_phys;
131
132 #endif /* !_MACHINE_PMAP_H_ */