Home | History | Annotate | Line # | Download | only in include
xenpmap.h revision 1.13
      1  1.13   perry /*	$NetBSD: xenpmap.h,v 1.13 2006/02/16 20:17:15 perry 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.4  bouyer #define	INVALID_P2M_ENTRY	(~0UL)
     39   1.4  bouyer 
     40   1.8  bouyer void xpq_queue_machphys_update(paddr_t, paddr_t);
     41   1.1      cl void xpq_queue_invlpg(vaddr_t);
     42   1.1      cl void xpq_queue_pde_update(pd_entry_t *, pd_entry_t);
     43   1.1      cl void xpq_queue_pte_update(pt_entry_t *, pt_entry_t);
     44   1.3      cl void xpq_queue_unchecked_pte_update(pt_entry_t *, pt_entry_t);
     45   1.1      cl void xpq_queue_pt_switch(paddr_t);
     46   1.1      cl void xpq_flush_queue(void);
     47   1.1      cl void xpq_queue_set_ldt(vaddr_t, uint32_t);
     48   1.1      cl void xpq_queue_tlb_flush(void);
     49   1.1      cl void xpq_queue_pin_table(paddr_t, int);
     50   1.1      cl void xpq_queue_unpin_table(paddr_t);
     51   1.5    yamt int  xpq_update_foreign(pt_entry_t *, pt_entry_t, int);
     52   1.1      cl 
     53   1.1      cl extern paddr_t *xpmap_phys_to_machine_mapping;
     54   1.1      cl 
     55   1.1      cl #define	XPQ_PIN_L1_TABLE 1
     56   1.1      cl #define	XPQ_PIN_L2_TABLE 2
     57   1.1      cl 
     58   1.1      cl #ifndef XEN
     59   1.1      cl #define	PDE_GET(_pdp)						\
     60   1.1      cl 	*(_pdp)
     61   1.4  bouyer #define PDE_SET(_pdp,_mapdp,_npde)				\
     62   1.4  bouyer 	*(_mapdp) = (_npde)
     63   1.4  bouyer #define PDE_CLEAR(_pdp,_mapdp)					\
     64   1.4  bouyer 	*(_mapdp) = 0
     65   1.4  bouyer #define PTE_SET(_ptp,_maptp,_npte)				\
     66   1.4  bouyer 	*(_maptp) = (_npte)
     67   1.4  bouyer #define PTE_CLEAR(_ptp,_maptp)					\
     68   1.4  bouyer 	*(_maptp) = 0
     69   1.4  bouyer #define PTE_ATOMIC_SET(_ptp,_maptp,_npte,_opte)			\
     70   1.4  bouyer 	(_opte) = x86_atomic_testset_ul((_maptp), (_npte))
     71   1.4  bouyer #define PTE_ATOMIC_CLEAR(_ptp,_maptp,_opte)			\
     72   1.4  bouyer 	(_opte) = x86_atomic_testset_ul((_maptp), 0)
     73   1.4  bouyer #define PDE_CLEARBITS(_pdp,_mapdp,_bits)			\
     74   1.4  bouyer 	*(_mapdp) &= ~(_bits)
     75   1.4  bouyer #define PTE_ATOMIC_CLEARBITS(_ptp,_maptp,_bits)			\
     76   1.4  bouyer 	x86_atomic_clearbits_l((_maptp), (_bits))
     77   1.4  bouyer #define PTE_SETBITS(_ptp,_maptp,_bits)				\
     78   1.4  bouyer 	*(_maptp) |= (_bits)
     79   1.4  bouyer #define PTE_ATOMIC_SETBITS(_ptp,_maptp,_bits)			\
     80   1.4  bouyer 	x86_atomic_setbits_l((_maptp), (_bits))
     81   1.1      cl #else
     82   1.1      cl paddr_t *xpmap_phys_to_machine_mapping;
     83   1.1      cl 
     84   1.1      cl #define	PDE_GET(_pdp)						\
     85   1.1      cl 	(pmap_valid_entry(*(_pdp)) ? xpmap_mtop(*(_pdp)) : *(_pdp))
     86   1.4  bouyer #define PDE_SET(_pdp,_mapdp,_npde) do {				\
     87   1.7    yamt 	int _s = splvm();					\
     88   1.4  bouyer 	xpq_queue_pde_update((_mapdp), xpmap_ptom((_npde)));	\
     89   1.1      cl 	xpq_flush_queue();					\
     90   1.7    yamt 	splx(_s);						\
     91   1.1      cl } while (/*CONSTCOND*/0)
     92   1.4  bouyer #define PDE_CLEAR(_pdp,_mapdp) do {				\
     93   1.7    yamt 	int _s = splvm();					\
     94   1.4  bouyer 	xpq_queue_pde_update((_mapdp), 0);			\
     95   1.1      cl 	xpq_flush_queue();					\
     96   1.7    yamt 	splx(_s);						\
     97   1.1      cl } while (/*CONSTCOND*/0)
     98   1.1      cl #define	PTE_GET(_ptp)						\
     99   1.1      cl 	(pmap_valid_entry(*(_ptp)) ? xpmap_mtop(*(_ptp)) : *(_ptp))
    100   1.3      cl #define	PTE_GET_MA(_ptp)					\
    101   1.3      cl 	*(_ptp)
    102   1.4  bouyer #define PTE_SET(_ptp,_maptp,_npte) do {				\
    103   1.7    yamt 	int _s = splvm();					\
    104   1.4  bouyer 	xpq_queue_pte_update((_maptp), xpmap_ptom((_npte)));	\
    105   1.1      cl 	xpq_flush_queue();					\
    106   1.7    yamt 	splx(_s);						\
    107   1.1      cl } while (/*CONSTCOND*/0)
    108   1.4  bouyer #define PTE_SET_MA(_ptp,_maptp,_npte) do {			\
    109   1.7    yamt 	int _s = splvm();					\
    110   1.4  bouyer 	xpq_queue_pte_update((_maptp), (_npte));		\
    111   1.1      cl 	xpq_flush_queue();					\
    112   1.7    yamt 	splx(_s);						\
    113   1.1      cl } while (/*CONSTCOND*/0)
    114   1.4  bouyer #define PTE_SET_MA_UNCHECKED(_ptp,_maptp,_npte) do {		\
    115   1.7    yamt 	_s = splvm();						\
    116   1.4  bouyer 	xpq_queue_unchecked_pte_update((_maptp), (_npte));	\
    117   1.3      cl 	xpq_flush_queue();					\
    118   1.7    yamt 	splx(_s);						\
    119   1.3      cl } while (/*CONSTCOND*/0)
    120   1.4  bouyer #define PTE_CLEAR(_ptp,_maptp) do {				\
    121   1.7    yamt 	int _s = splvm();					\
    122   1.4  bouyer 	xpq_queue_pte_update((_maptp), 0);			\
    123   1.1      cl 	xpq_flush_queue();					\
    124   1.7    yamt 	splx(_s);						\
    125   1.1      cl } while (/*CONSTCOND*/0)
    126   1.4  bouyer #define PTE_ATOMIC_SET(_ptp,_maptp,_npte,_opte) do {		\
    127   1.7    yamt 	int _s;							\
    128   1.1      cl 	(_opte) = PTE_GET(_ptp);				\
    129   1.7    yamt 	_s = splvm();						\
    130   1.4  bouyer 	xpq_queue_pte_update((_maptp), xpmap_ptom((_npte)));	\
    131   1.1      cl 	xpq_flush_queue();					\
    132   1.7    yamt 	splx(_s);						\
    133   1.1      cl } while (/*CONSTCOND*/0)
    134   1.4  bouyer #define PTE_ATOMIC_SET_MA(_ptp,_maptp,_npte,_opte) do {		\
    135   1.7    yamt 	int _s;							\
    136   1.3      cl 	(_opte) = *(_ptp);					\
    137   1.7    yamt 	_s = splvm();						\
    138   1.4  bouyer 	xpq_queue_pte_update((_maptp), (_npte));		\
    139   1.1      cl 	xpq_flush_queue();					\
    140   1.7    yamt 	splx(_s);						\
    141   1.1      cl } while (/*CONSTCOND*/0)
    142   1.4  bouyer #define PTE_ATOMIC_CLEAR(_ptp,_maptp,_opte) do {		\
    143   1.7    yamt 	int _s;							\
    144   1.1      cl 	(_opte) = PTE_GET(_ptp);				\
    145   1.7    yamt 	_s = splvm();						\
    146   1.4  bouyer 	xpq_queue_pte_update((_maptp), 0);			\
    147   1.1      cl 	xpq_flush_queue();					\
    148   1.7    yamt 	splx(_s);						\
    149   1.1      cl } while (/*CONSTCOND*/0)
    150   1.4  bouyer #define PTE_ATOMIC_CLEAR_MA(_ptp,_maptp,_opte) do {		\
    151   1.7    yamt 	int _s;							\
    152   1.3      cl 	(_opte) = *(_ptp);					\
    153   1.7    yamt 	_s = splvm();						\
    154   1.4  bouyer 	xpq_queue_pte_update((_maptp), 0);			\
    155   1.3      cl 	xpq_flush_queue();					\
    156   1.7    yamt 	splx(_s);						\
    157   1.3      cl } while (/*CONSTCOND*/0)
    158   1.4  bouyer #define PDE_CLEARBITS(_pdp,_mapdp,_bits) do {			\
    159   1.7    yamt 	int _s = splvm();					\
    160   1.4  bouyer 	xpq_queue_pte_update((_mapdp), *(_pdp) & ~((_bits) & ~PG_FRAME)); \
    161   1.1      cl 	xpq_flush_queue();					\
    162   1.7    yamt 	splx(_s);						\
    163   1.1      cl } while (/*CONSTCOND*/0)
    164   1.4  bouyer #define PTE_CLEARBITS(_ptp,_maptp,_bits) do {			\
    165   1.7    yamt 	int _s = splvm();					\
    166   1.4  bouyer 	xpq_queue_pte_update((_maptp), *(_ptp) & ~((_bits) & ~PG_FRAME)); \
    167   1.1      cl 	xpq_flush_queue();					\
    168   1.7    yamt 	splx(_s);						\
    169   1.1      cl } while (/*CONSTCOND*/0)
    170   1.4  bouyer #define PDE_ATOMIC_CLEARBITS(_pdp,_mapdp,_bits) do {		\
    171   1.7    yamt 	int _s = splvm();					\
    172   1.4  bouyer 	xpq_queue_pde_update((_mapdp), *(_pdp) & ~((_bits) & ~PG_FRAME)); \
    173   1.1      cl 	xpq_flush_queue();					\
    174   1.7    yamt 	splx(_s);						\
    175   1.1      cl } while (/*CONSTCOND*/0)
    176   1.4  bouyer #define PTE_ATOMIC_CLEARBITS(_ptp,_maptp,_bits) do {		\
    177   1.7    yamt 	int _s = splvm();					\
    178   1.4  bouyer 	xpq_queue_pte_update((_maptp), *(_ptp) & ~((_bits) & ~PG_FRAME)); \
    179   1.1      cl 	xpq_flush_queue();					\
    180   1.7    yamt 	splx(_s);						\
    181   1.1      cl } while (/*CONSTCOND*/0)
    182   1.4  bouyer #define PTE_SETBITS(_ptp,_maptp,_bits) do {			\
    183   1.7    yamt 	int _s = splvm();					\
    184   1.4  bouyer 	xpq_queue_pte_update((_maptp), *(_ptp) | ((_bits) & ~PG_FRAME)); \
    185   1.2      cl 	xpq_flush_queue();					\
    186   1.7    yamt 	splx(_s);						\
    187   1.1      cl } while (/*CONSTCOND*/0)
    188   1.4  bouyer #define PDE_ATOMIC_SETBITS(_pdp,_mapdp,_bits) do {		\
    189   1.7    yamt 	int _s = splvm();					\
    190   1.4  bouyer 	xpq_queue_pde_update((_mapdp), *(_pdp) | ((_bits) & ~PG_FRAME)); \
    191   1.1      cl 	xpq_flush_queue();					\
    192   1.7    yamt 	splx(_s);						\
    193   1.1      cl } while (/*CONSTCOND*/0)
    194   1.4  bouyer #define PTE_ATOMIC_SETBITS(_ptp,_maptp,_bits) do {		\
    195   1.7    yamt 	int _s = splvm();					\
    196   1.4  bouyer 	xpq_queue_pte_update((_maptp), *(_ptp) | ((_bits) & ~PG_FRAME)); \
    197   1.1      cl 	xpq_flush_queue();					\
    198   1.7    yamt 	splx(_s);						\
    199   1.1      cl } while (/*CONSTCOND*/0)
    200   1.4  bouyer #define PDE_COPY(_dpdp,_madpdp,_spdp) do {			\
    201   1.7    yamt 	int _s = splvm();					\
    202   1.4  bouyer 	xpq_queue_pde_update((_madpdp), *(_spdp));		\
    203   1.1      cl 	xpq_flush_queue();					\
    204   1.7    yamt 	splx(_s);						\
    205   1.1      cl } while (/*CONSTCOND*/0)
    206   1.1      cl #define	PTE_UPDATES_FLUSH() do {				\
    207   1.7    yamt 	int _s = splvm();					\
    208   1.1      cl 	xpq_flush_queue();					\
    209   1.7    yamt 	splx(_s);						\
    210   1.1      cl } while (/*CONSTCOND*/0)
    211   1.1      cl 
    212   1.1      cl #endif
    213   1.1      cl 
    214  1.12  bouyer /*
    215  1.12  bouyer  * On Xen-2, the start of the day virual memory starts at KERNTEXTOFF
    216  1.12  bouyer  * (0xc0100000). On Xen-3 for domain0 it starts at KERNBASE (0xc0000000).
    217  1.12  bouyer  * So the offset between physical and virtual address is different on
    218  1.12  bouyer  * Xen-2 and Xen-3 for domain0.
    219  1.12  bouyer  */
    220  1.12  bouyer #if defined(XEN3) && defined(DOM0OPS)
    221  1.12  bouyer #define XPMAP_OFFSET	0
    222  1.12  bouyer #else
    223   1.9    yamt #define	XPMAP_OFFSET	(KERNTEXTOFF - KERNBASE)
    224  1.12  bouyer #endif
    225  1.12  bouyer 
    226  1.13   perry static __inline paddr_t
    227   1.1      cl xpmap_mtop(paddr_t mpa)
    228   1.1      cl {
    229   1.3      cl 	return ((machine_to_phys_mapping[mpa >> PAGE_SHIFT] << PAGE_SHIFT) +
    230   1.4  bouyer 	    XPMAP_OFFSET) | (mpa & ~PG_FRAME);
    231   1.1      cl }
    232   1.1      cl 
    233  1.13   perry static __inline paddr_t
    234   1.1      cl xpmap_ptom(paddr_t ppa)
    235   1.1      cl {
    236   1.3      cl 	return (xpmap_phys_to_machine_mapping[(ppa -
    237   1.4  bouyer 	    XPMAP_OFFSET) >> PAGE_SHIFT] << PAGE_SHIFT)
    238   1.3      cl 		| (ppa & ~PG_FRAME);
    239   1.3      cl }
    240   1.3      cl 
    241  1.13   perry static __inline paddr_t
    242   1.3      cl xpmap_ptom_masked(paddr_t ppa)
    243   1.3      cl {
    244   1.3      cl 	return (xpmap_phys_to_machine_mapping[(ppa -
    245   1.4  bouyer 	    XPMAP_OFFSET) >> PAGE_SHIFT] << PAGE_SHIFT);
    246   1.1      cl }
    247   1.1      cl 
    248   1.1      cl #endif /* _XEN_XENPMAP_H_ */
    249