1 /*
2  * fixmap.h: compile-time virtual memory allocation
3  *
4  * This file is subject to the terms and conditions of the GNU General Public
5  * License.  See the file "COPYING" in the main directory of this archive
6  * for more details.
7  *
8  * Copyright (C) 1998 Ingo Molnar
9  * Modifications for Xen are copyright (c) 2002-2004, K A Fraser
10  */
11 
12 #ifndef _ASM_FIXMAP_H
13 #define _ASM_FIXMAP_H
14 
15 #include <asm/page.h>
16 
17 #define FIXADDR_TOP (VMAP_VIRT_END - PAGE_SIZE)
18 #define FIXADDR_X_TOP (XEN_VIRT_END - PAGE_SIZE)
19 
20 #ifndef __ASSEMBLY__
21 
22 #include <xen/acpi.h>
23 #include <xen/pfn.h>
24 #include <xen/kexec.h>
25 #include <asm/apicdef.h>
26 #include <asm/msi.h>
27 #include <acpi/apei.h>
28 
29 /*
30  * Here we define all the compile-time 'special' virtual
31  * addresses. The point is to have a constant address at
32  * compile time, but to set the physical address only
33  * in the boot process. We allocate these special addresses
34  * from the end of virtual memory backwards.
35  */
36 enum fixed_addresses {
37     /* Index 0 is reserved since fix_to_virt(0) == FIXADDR_TOP. */
38     FIX_RESERVED,
39     /*
40      * Indexes using the page tables set up before entering __start_xen()
41      * must be among the first (L1_PAGETABLE_ENTRIES - 1) entries.
42      * These are generally those needed by the various console drivers.
43      */
44     FIX_COM_BEGIN,
45     FIX_COM_END,
46     FIX_EHCI_DBGP,
47 #ifdef CONFIG_XEN_GUEST
48     FIX_PV_CONSOLE,
49     FIX_XEN_SHARED_INFO,
50 #endif /* CONFIG_XEN_GUEST */
51     /* Everything else should go further down. */
52     FIX_APIC_BASE,
53     FIX_IO_APIC_BASE_0,
54     FIX_IO_APIC_BASE_END = FIX_IO_APIC_BASE_0 + MAX_IO_APICS-1,
55     FIX_ACPI_BEGIN,
56     FIX_ACPI_END = FIX_ACPI_BEGIN + NUM_FIXMAP_ACPI_PAGES - 1,
57     FIX_HPET_BASE,
58     FIX_TBOOT_SHARED_BASE,
59     FIX_MSIX_IO_RESERV_BASE,
60     FIX_MSIX_IO_RESERV_END = FIX_MSIX_IO_RESERV_BASE + FIX_MSIX_MAX_PAGES -1,
61     FIX_TBOOT_MAP_ADDRESS,
62     FIX_APEI_RANGE_BASE,
63     FIX_APEI_RANGE_END = FIX_APEI_RANGE_BASE + FIX_APEI_RANGE_MAX -1,
64     FIX_EFI_MPF,
65     __end_of_fixed_addresses
66 };
67 
68 #define FIXADDR_SIZE  (__end_of_fixed_addresses << PAGE_SHIFT)
69 #define FIXADDR_START (FIXADDR_TOP - FIXADDR_SIZE)
70 
71 extern void __set_fixmap(
72     enum fixed_addresses idx, unsigned long mfn, unsigned long flags);
73 
74 #define set_fixmap(idx, phys) \
75     __set_fixmap(idx, (phys)>>PAGE_SHIFT, PAGE_HYPERVISOR)
76 
77 #define set_fixmap_nocache(idx, phys) \
78     __set_fixmap(idx, (phys)>>PAGE_SHIFT, PAGE_HYPERVISOR_UCMINUS)
79 
80 #define clear_fixmap(idx) __set_fixmap(idx, 0, 0)
81 
82 #define __fix_to_virt(x) (FIXADDR_TOP - ((x) << PAGE_SHIFT))
83 #define __virt_to_fix(x) ((FIXADDR_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT)
84 
85 #define fix_to_virt(x)   ((void *)__fix_to_virt(x))
86 
virt_to_fix(const unsigned long vaddr)87 static inline unsigned long virt_to_fix(const unsigned long vaddr)
88 {
89     BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START);
90     return __virt_to_fix(vaddr);
91 }
92 
93 enum fixed_addresses_x {
94     /* Index 0 is reserved since fix_x_to_virt(0) == FIXADDR_X_TOP. */
95     FIX_X_RESERVED,
96 #ifdef CONFIG_HYPERV_GUEST
97     FIX_X_HYPERV_HCALL,
98 #endif
99     __end_of_fixed_addresses_x
100 };
101 
102 #define FIXADDR_X_SIZE  (__end_of_fixed_addresses_x << PAGE_SHIFT)
103 #define FIXADDR_X_START (FIXADDR_X_TOP - FIXADDR_X_SIZE)
104 
105 extern void __set_fixmap_x(
106     enum fixed_addresses_x idx, unsigned long mfn, unsigned long flags);
107 
108 #define set_fixmap_x(idx, phys) \
109     __set_fixmap_x(idx, (phys)>>PAGE_SHIFT, PAGE_HYPERVISOR_RX | MAP_SMALL_PAGES)
110 
111 #define clear_fixmap_x(idx) __set_fixmap_x(idx, 0, 0)
112 
113 #define __fix_x_to_virt(x) (FIXADDR_X_TOP - ((x) << PAGE_SHIFT))
114 #define fix_x_to_virt(x)   ((void *)__fix_x_to_virt(x))
115 
116 #endif /* __ASSEMBLY__ */
117 
118 #endif
119