Home | History | Annotate | Line # | Download | only in include
xenpmap.h revision 1.3
      1  1.3  cl /*	$NetBSD: xenpmap.h,v 1.3 2004/04/26 22:05:05 cl Exp $	*/
      2  1.1  cl 
      3  1.1  cl /*
      4  1.1  cl  *
      5  1.1  cl  * Copyright (c) 2004 Christian Limpach.
      6  1.1  cl  * All rights reserved.
      7  1.1  cl  *
      8  1.1  cl  * Redistribution and use in source and binary forms, with or without
      9  1.1  cl  * modification, are permitted provided that the following conditions
     10  1.1  cl  * are met:
     11  1.1  cl  * 1. Redistributions of source code must retain the above copyright
     12  1.1  cl  *    notice, this list of conditions and the following disclaimer.
     13  1.1  cl  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.1  cl  *    notice, this list of conditions and the following disclaimer in the
     15  1.1  cl  *    documentation and/or other materials provided with the distribution.
     16  1.1  cl  * 3. All advertising materials mentioning features or use of this software
     17  1.1  cl  *    must display the following acknowledgement:
     18  1.1  cl  *      This product includes software developed by Christian Limpach.
     19  1.1  cl  * 4. The name of the author may not be used to endorse or promote products
     20  1.1  cl  *    derived from this software without specific prior written permission.
     21  1.1  cl  *
     22  1.1  cl  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  1.1  cl  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  1.1  cl  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  1.1  cl  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  1.1  cl  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  1.1  cl  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  1.1  cl  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  1.1  cl  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  1.1  cl  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  1.1  cl  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  1.1  cl  */
     33  1.1  cl 
     34  1.1  cl 
     35  1.1  cl #ifndef _XEN_XENPMAP_H_
     36  1.1  cl #define _XEN_XENPMAP_H_
     37  1.1  cl 
     38  1.1  cl void xpq_queue_invlpg(vaddr_t);
     39  1.1  cl void xpq_queue_pde_update(pd_entry_t *, pd_entry_t);
     40  1.1  cl void xpq_queue_pte_update(pt_entry_t *, pt_entry_t);
     41  1.3  cl void xpq_queue_unchecked_pte_update(pt_entry_t *, pt_entry_t);
     42  1.1  cl void xpq_queue_pt_switch(paddr_t);
     43  1.1  cl void xpq_flush_queue(void);
     44  1.1  cl void xpq_queue_set_ldt(vaddr_t, uint32_t);
     45  1.1  cl void xpq_queue_tlb_flush(void);
     46  1.1  cl void xpq_queue_pin_table(paddr_t, int);
     47  1.1  cl void xpq_queue_unpin_table(paddr_t);
     48  1.1  cl 
     49  1.1  cl extern paddr_t *xpmap_phys_to_machine_mapping;
     50  1.1  cl 
     51  1.1  cl #define	XPQ_PIN_L1_TABLE 1
     52  1.1  cl #define	XPQ_PIN_L2_TABLE 2
     53  1.1  cl 
     54  1.1  cl #ifndef XEN
     55  1.1  cl #define	PDE_GET(_pdp)						\
     56  1.1  cl 	*(_pdp)
     57  1.1  cl #define PDE_SET(_pdp,_npde)					\
     58  1.1  cl 	*(_pdp) = (_npde)
     59  1.1  cl #define PDE_CLEAR(_pdp)						\
     60  1.1  cl 	*(_pdp) = 0
     61  1.1  cl #define PTE_SET(_ptp,_npte)					\
     62  1.1  cl 	*(_ptp) = (_npte)
     63  1.1  cl #define PTE_CLEAR(_ptp)						\
     64  1.1  cl 	*(_ptp) = 0
     65  1.1  cl #define PTE_ATOMIC_SET(_ptp,_npte,_opte)			\
     66  1.1  cl 	(_opte) = x86_atomic_testset_ul((_ptp), (_npte))
     67  1.1  cl #define PTE_ATOMIC_CLEAR(_ptp,_opte)				\
     68  1.1  cl 	(_opte) = x86_atomic_testset_ul((_ptp), 0)
     69  1.1  cl #define PDE_CLEARBITS(_pdp,_bits)				\
     70  1.1  cl 	*(_pdp) &= ~(_bits)
     71  1.1  cl #define PTE_ATOMIC_CLEARBITS(_ptp,_bits)			\
     72  1.1  cl 	x86_atomic_clearbits_l((_ptp), (_bits))
     73  1.1  cl #define PTE_SETBITS(_ptp,_bits)					\
     74  1.1  cl 	*(_ptp) |= (_bits)
     75  1.1  cl #define PTE_ATOMIC_SETBITS(_ptp,_bits)				\
     76  1.1  cl 	x86_atomic_setbits_l((_ptp), (_bits))
     77  1.1  cl #else
     78  1.1  cl paddr_t *xpmap_phys_to_machine_mapping;
     79  1.1  cl 
     80  1.1  cl #define	PDE_GET(_pdp)						\
     81  1.1  cl 	(pmap_valid_entry(*(_pdp)) ? xpmap_mtop(*(_pdp)) : *(_pdp))
     82  1.1  cl #define PDE_SET(_pdp,_npde) do {				\
     83  1.1  cl 	xpq_queue_pde_update((_pdp), xpmap_ptom((_npde)));	\
     84  1.1  cl 	xpq_flush_queue();					\
     85  1.1  cl } while (/*CONSTCOND*/0)
     86  1.1  cl #define PDE_CLEAR(_pdp) do {					\
     87  1.1  cl 	xpq_queue_pde_update((_pdp), 0);			\
     88  1.1  cl 	xpq_flush_queue();					\
     89  1.1  cl } while (/*CONSTCOND*/0)
     90  1.1  cl #define	PTE_GET(_ptp)						\
     91  1.1  cl 	(pmap_valid_entry(*(_ptp)) ? xpmap_mtop(*(_ptp)) : *(_ptp))
     92  1.3  cl #define	PTE_GET_MA(_ptp)					\
     93  1.3  cl 	*(_ptp)
     94  1.1  cl #define PTE_SET(_ptp,_npte) do {				\
     95  1.1  cl 	xpq_queue_pte_update((_ptp), xpmap_ptom((_npte)));	\
     96  1.1  cl 	xpq_flush_queue();					\
     97  1.1  cl } while (/*CONSTCOND*/0)
     98  1.1  cl #define PTE_SET_MA(_ptp,_npte) do {				\
     99  1.1  cl 	xpq_queue_pte_update((_ptp), (_npte));			\
    100  1.1  cl 	xpq_flush_queue();					\
    101  1.1  cl } while (/*CONSTCOND*/0)
    102  1.3  cl #define PTE_SET_MA_UNCHECKED(_ptp,_npte) do {			\
    103  1.3  cl 	xpq_queue_unchecked_pte_update((_ptp), (_npte));	\
    104  1.3  cl 	xpq_flush_queue();					\
    105  1.3  cl } while (/*CONSTCOND*/0)
    106  1.1  cl #define PTE_CLEAR(_ptp) do {					\
    107  1.1  cl 	xpq_queue_pte_update((_ptp), 0);			\
    108  1.1  cl 	xpq_flush_queue();					\
    109  1.1  cl } while (/*CONSTCOND*/0)
    110  1.1  cl #define PTE_ATOMIC_SET(_ptp,_npte,_opte) do {			\
    111  1.1  cl 	(_opte) = PTE_GET(_ptp);				\
    112  1.1  cl 	xpq_queue_pte_update((_ptp), xpmap_ptom((_npte)));	\
    113  1.1  cl 	xpq_flush_queue();					\
    114  1.1  cl } while (/*CONSTCOND*/0)
    115  1.1  cl #define PTE_ATOMIC_SET_MA(_ptp,_npte,_opte) do {		\
    116  1.3  cl 	(_opte) = *(_ptp);					\
    117  1.1  cl 	xpq_queue_pte_update((_ptp), (_npte));			\
    118  1.1  cl 	xpq_flush_queue();					\
    119  1.1  cl } while (/*CONSTCOND*/0)
    120  1.1  cl #define PTE_ATOMIC_CLEAR(_ptp,_opte) do {			\
    121  1.1  cl 	(_opte) = PTE_GET(_ptp);				\
    122  1.1  cl 	xpq_queue_pte_update((_ptp), 0);			\
    123  1.1  cl 	xpq_flush_queue();					\
    124  1.1  cl } while (/*CONSTCOND*/0)
    125  1.3  cl #define PTE_ATOMIC_CLEAR_MA(_ptp,_opte) do {			\
    126  1.3  cl 	(_opte) = *(_ptp);					\
    127  1.3  cl 	xpq_queue_pte_update((_ptp), 0);			\
    128  1.3  cl 	xpq_flush_queue();					\
    129  1.3  cl } while (/*CONSTCOND*/0)
    130  1.1  cl #define PDE_CLEARBITS(_pdp,_bits) do {				\
    131  1.1  cl 	xpq_queue_pte_update((_pdp), *(_pdp) & ~((_bits) & ~PG_FRAME));	\
    132  1.1  cl 	xpq_flush_queue();					\
    133  1.1  cl } while (/*CONSTCOND*/0)
    134  1.1  cl #define PTE_CLEARBITS(_ptp,_bits) do {				\
    135  1.1  cl 	xpq_queue_pte_update((_ptp), *(_ptp) & ~((_bits) & ~PG_FRAME));	\
    136  1.1  cl 	xpq_flush_queue();					\
    137  1.1  cl } while (/*CONSTCOND*/0)
    138  1.1  cl #define PDE_ATOMIC_CLEARBITS(_pdp,_bits) do {			\
    139  1.1  cl 	xpq_queue_pde_update((_pdp), *(_pdp) & ~((_bits) & ~PG_FRAME));	\
    140  1.1  cl 	xpq_flush_queue();					\
    141  1.1  cl } while (/*CONSTCOND*/0)
    142  1.1  cl #define PTE_ATOMIC_CLEARBITS(_ptp,_bits) do {			\
    143  1.1  cl 	xpq_queue_pte_update((_ptp), *(_ptp) & ~((_bits) & ~PG_FRAME));	\
    144  1.1  cl 	xpq_flush_queue();					\
    145  1.1  cl } while (/*CONSTCOND*/0)
    146  1.1  cl #define PTE_SETBITS(_ptp,_bits) do {				\
    147  1.1  cl 	xpq_queue_pte_update((_ptp), *(_ptp) | ((_bits) & ~PG_FRAME));	\
    148  1.2  cl 	xpq_flush_queue();					\
    149  1.1  cl } while (/*CONSTCOND*/0)
    150  1.1  cl #define PDE_ATOMIC_SETBITS(_pdp,_bits) do {			\
    151  1.1  cl 	xpq_queue_pde_update((_pdp), *(_pdp) | ((_bits) & ~PG_FRAME));	\
    152  1.1  cl 	xpq_flush_queue();					\
    153  1.1  cl } while (/*CONSTCOND*/0)
    154  1.1  cl #define PTE_ATOMIC_SETBITS(_ptp,_bits) do {			\
    155  1.1  cl 	xpq_queue_pde_update((_ptp), *(_ptp) | ((_bits) & ~PG_FRAME));	\
    156  1.1  cl 	xpq_flush_queue();					\
    157  1.1  cl } while (/*CONSTCOND*/0)
    158  1.1  cl #define PDE_COPY(_dpdp,_spdp) do {				\
    159  1.1  cl 	xpq_queue_pde_update((_dpdp), *(_spdp));		\
    160  1.1  cl 	xpq_flush_queue();					\
    161  1.1  cl } while (/*CONSTCOND*/0)
    162  1.1  cl #define	PTE_UPDATES_FLUSH() do {				\
    163  1.1  cl 	xpq_flush_queue();					\
    164  1.1  cl } while (/*CONSTCOND*/0)
    165  1.1  cl 
    166  1.1  cl #endif
    167  1.1  cl 
    168  1.1  cl static __inline paddr_t
    169  1.1  cl xpmap_mtop(paddr_t mpa)
    170  1.1  cl {
    171  1.3  cl 	return ((machine_to_phys_mapping[mpa >> PAGE_SHIFT] << PAGE_SHIFT) +
    172  1.3  cl 	    (KERNTEXTOFF - KERNBASE_LOCORE)) | (mpa & ~PG_FRAME);
    173  1.1  cl }
    174  1.1  cl 
    175  1.1  cl static __inline paddr_t
    176  1.1  cl xpmap_ptom(paddr_t ppa)
    177  1.1  cl {
    178  1.3  cl 	return (xpmap_phys_to_machine_mapping[(ppa -
    179  1.3  cl 	    (KERNTEXTOFF - KERNBASE_LOCORE)) >> PAGE_SHIFT] << PAGE_SHIFT)
    180  1.3  cl 		| (ppa & ~PG_FRAME);
    181  1.3  cl }
    182  1.3  cl 
    183  1.3  cl static __inline paddr_t
    184  1.3  cl xpmap_ptom_masked(paddr_t ppa)
    185  1.3  cl {
    186  1.3  cl 	return (xpmap_phys_to_machine_mapping[(ppa -
    187  1.3  cl 	    (KERNTEXTOFF - KERNBASE_LOCORE)) >> PAGE_SHIFT] << PAGE_SHIFT);
    188  1.1  cl }
    189  1.1  cl 
    190  1.1  cl #endif /* _XEN_XENPMAP_H_ */
    191