Home | History | Annotate | Line # | Download | only in include
xenpmap.h revision 1.2
      1  1.2  cl /*	$NetBSD: xenpmap.h,v 1.2 2004/04/24 19:43:53 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.1  cl void xpq_queue_pt_switch(paddr_t);
     42  1.1  cl void xpq_flush_queue(void);
     43  1.1  cl void xpq_queue_set_ldt(vaddr_t, uint32_t);
     44  1.1  cl void xpq_queue_tlb_flush(void);
     45  1.1  cl void xpq_queue_pin_table(paddr_t, int);
     46  1.1  cl void xpq_queue_unpin_table(paddr_t);
     47  1.1  cl 
     48  1.1  cl extern paddr_t *xpmap_phys_to_machine_mapping;
     49  1.1  cl 
     50  1.1  cl #define	XPQ_PIN_L1_TABLE 1
     51  1.1  cl #define	XPQ_PIN_L2_TABLE 2
     52  1.1  cl 
     53  1.1  cl #ifndef XEN
     54  1.1  cl #define	PDE_GET(_pdp)						\
     55  1.1  cl 	*(_pdp)
     56  1.1  cl #define PDE_SET(_pdp,_npde)					\
     57  1.1  cl 	*(_pdp) = (_npde)
     58  1.1  cl #define PDE_CLEAR(_pdp)						\
     59  1.1  cl 	*(_pdp) = 0
     60  1.1  cl #define PTE_SET(_ptp,_npte)					\
     61  1.1  cl 	*(_ptp) = (_npte)
     62  1.1  cl #define PTE_CLEAR(_ptp)						\
     63  1.1  cl 	*(_ptp) = 0
     64  1.1  cl #define PTE_ATOMIC_SET(_ptp,_npte,_opte)			\
     65  1.1  cl 	(_opte) = x86_atomic_testset_ul((_ptp), (_npte))
     66  1.1  cl #define PTE_ATOMIC_CLEAR(_ptp,_opte)				\
     67  1.1  cl 	(_opte) = x86_atomic_testset_ul((_ptp), 0)
     68  1.1  cl #define PDE_CLEARBITS(_pdp,_bits)				\
     69  1.1  cl 	*(_pdp) &= ~(_bits)
     70  1.1  cl #define PTE_ATOMIC_CLEARBITS(_ptp,_bits)			\
     71  1.1  cl 	x86_atomic_clearbits_l((_ptp), (_bits))
     72  1.1  cl #define PTE_SETBITS(_ptp,_bits)					\
     73  1.1  cl 	*(_ptp) |= (_bits)
     74  1.1  cl #define PTE_ATOMIC_SETBITS(_ptp,_bits)				\
     75  1.1  cl 	x86_atomic_setbits_l((_ptp), (_bits))
     76  1.1  cl #else
     77  1.1  cl paddr_t *xpmap_phys_to_machine_mapping;
     78  1.1  cl 
     79  1.1  cl #define	PDE_GET(_pdp)						\
     80  1.1  cl 	(pmap_valid_entry(*(_pdp)) ? xpmap_mtop(*(_pdp)) : *(_pdp))
     81  1.1  cl #define PDE_SET(_pdp,_npde) do {				\
     82  1.1  cl 	xpq_queue_pde_update((_pdp), xpmap_ptom((_npde)));	\
     83  1.1  cl 	xpq_flush_queue();					\
     84  1.1  cl } while (/*CONSTCOND*/0)
     85  1.1  cl #define PDE_CLEAR(_pdp) do {					\
     86  1.1  cl 	xpq_queue_pde_update((_pdp), 0);			\
     87  1.1  cl 	xpq_flush_queue();					\
     88  1.1  cl } while (/*CONSTCOND*/0)
     89  1.1  cl #define	PTE_GET(_ptp)						\
     90  1.1  cl 	(pmap_valid_entry(*(_ptp)) ? xpmap_mtop(*(_ptp)) : *(_ptp))
     91  1.1  cl #define PTE_SET(_ptp,_npte) do {				\
     92  1.1  cl 	xpq_queue_pte_update((_ptp), xpmap_ptom((_npte)));	\
     93  1.1  cl 	xpq_flush_queue();					\
     94  1.1  cl } while (/*CONSTCOND*/0)
     95  1.1  cl #define PTE_SET_MA(_ptp,_npte) do {				\
     96  1.1  cl 	xpq_queue_pte_update((_ptp), (_npte));			\
     97  1.1  cl 	xpq_flush_queue();					\
     98  1.1  cl } while (/*CONSTCOND*/0)
     99  1.1  cl #define PTE_CLEAR(_ptp) do {					\
    100  1.1  cl 	xpq_queue_pte_update((_ptp), 0);			\
    101  1.1  cl 	xpq_flush_queue();					\
    102  1.1  cl } while (/*CONSTCOND*/0)
    103  1.1  cl #define PTE_ATOMIC_SET(_ptp,_npte,_opte) do {			\
    104  1.1  cl 	(_opte) = PTE_GET(_ptp);				\
    105  1.1  cl 	xpq_queue_pte_update((_ptp), xpmap_ptom((_npte)));	\
    106  1.1  cl 	xpq_flush_queue();					\
    107  1.1  cl } while (/*CONSTCOND*/0)
    108  1.1  cl #define PTE_ATOMIC_SET_MA(_ptp,_npte,_opte) do {		\
    109  1.1  cl 	(_opte) = PTE_GET(_ptp);				\
    110  1.1  cl 	xpq_queue_pte_update((_ptp), (_npte));			\
    111  1.1  cl 	xpq_flush_queue();					\
    112  1.1  cl } while (/*CONSTCOND*/0)
    113  1.1  cl #define PTE_ATOMIC_CLEAR(_ptp,_opte) do {			\
    114  1.1  cl 	(_opte) = PTE_GET(_ptp);				\
    115  1.1  cl 	xpq_queue_pte_update((_ptp), 0);			\
    116  1.1  cl 	xpq_flush_queue();					\
    117  1.1  cl } while (/*CONSTCOND*/0)
    118  1.1  cl #define PDE_CLEARBITS(_pdp,_bits) do {				\
    119  1.1  cl 	xpq_queue_pte_update((_pdp), *(_pdp) & ~((_bits) & ~PG_FRAME));	\
    120  1.1  cl 	xpq_flush_queue();					\
    121  1.1  cl } while (/*CONSTCOND*/0)
    122  1.1  cl #define PTE_CLEARBITS(_ptp,_bits) do {				\
    123  1.1  cl 	xpq_queue_pte_update((_ptp), *(_ptp) & ~((_bits) & ~PG_FRAME));	\
    124  1.1  cl 	xpq_flush_queue();					\
    125  1.1  cl } while (/*CONSTCOND*/0)
    126  1.1  cl #define PDE_ATOMIC_CLEARBITS(_pdp,_bits) do {			\
    127  1.1  cl 	xpq_queue_pde_update((_pdp), *(_pdp) & ~((_bits) & ~PG_FRAME));	\
    128  1.1  cl 	xpq_flush_queue();					\
    129  1.1  cl } while (/*CONSTCOND*/0)
    130  1.1  cl #define PTE_ATOMIC_CLEARBITS(_ptp,_bits) do {			\
    131  1.1  cl 	xpq_queue_pte_update((_ptp), *(_ptp) & ~((_bits) & ~PG_FRAME));	\
    132  1.1  cl 	xpq_flush_queue();					\
    133  1.1  cl } while (/*CONSTCOND*/0)
    134  1.1  cl #define PTE_SETBITS(_ptp,_bits) do {				\
    135  1.1  cl 	xpq_queue_pte_update((_ptp), *(_ptp) | ((_bits) & ~PG_FRAME));	\
    136  1.2  cl 	xpq_flush_queue();					\
    137  1.1  cl } while (/*CONSTCOND*/0)
    138  1.1  cl #define PDE_ATOMIC_SETBITS(_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_SETBITS(_ptp,_bits) do {			\
    143  1.1  cl 	xpq_queue_pde_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 PDE_COPY(_dpdp,_spdp) do {				\
    147  1.1  cl 	xpq_queue_pde_update((_dpdp), *(_spdp));		\
    148  1.1  cl 	xpq_flush_queue();					\
    149  1.1  cl } while (/*CONSTCOND*/0)
    150  1.1  cl #define	PTE_UPDATES_FLUSH() do {				\
    151  1.1  cl 	xpq_flush_queue();					\
    152  1.1  cl } while (/*CONSTCOND*/0)
    153  1.1  cl 
    154  1.1  cl #endif
    155  1.1  cl 
    156  1.1  cl static __inline paddr_t
    157  1.1  cl xpmap_mtop(paddr_t mpa)
    158  1.1  cl {
    159  1.1  cl 	return (machine_to_phys_mapping[mpa >> PAGE_SHIFT] << PAGE_SHIFT) |
    160  1.1  cl 		(mpa & ~PG_FRAME);
    161  1.1  cl }
    162  1.1  cl 
    163  1.1  cl static __inline paddr_t
    164  1.1  cl xpmap_ptom(paddr_t ppa)
    165  1.1  cl {
    166  1.1  cl 	return (xpmap_phys_to_machine_mapping[ppa >> PAGE_SHIFT] << PAGE_SHIFT) |
    167  1.1  cl 		(ppa & ~PG_FRAME);
    168  1.1  cl }
    169  1.1  cl 
    170  1.1  cl #endif /* _XEN_XENPMAP_H_ */
    171