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 <xen/page-size.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 <asm/apicdef.h>
25 #include <asm/msi.h>
26 #include <acpi/apei.h>
27 
28 #define MAX_XHCI_PAGES 256
29 
30 /*
31  * Here we define all the compile-time 'special' virtual
32  * addresses. The point is to have a constant address at
33  * compile time, but to set the physical address only
34  * in the boot process. We allocate these special addresses
35  * from the end of virtual memory backwards.
36  */
37 enum fixed_addresses {
38     /* Index 0 is reserved since fix_to_virt(0) == FIXADDR_TOP. */
39     FIX_RESERVED,
40     /*
41      * Indexes using the page tables set up before entering __start_xen()
42      * must be among the first (L1_PAGETABLE_ENTRIES - 1) entries.
43      * These are generally those needed by the various console drivers.
44      */
45     FIX_COM_BEGIN,
46     FIX_COM_END,
47     FIX_EHCI_DBGP,
48 #ifdef CONFIG_XHCI
49     FIX_XHCI_BEGIN,
50     FIX_XHCI_END = FIX_XHCI_BEGIN + MAX_XHCI_PAGES - 1,
51 #endif
52 #ifdef CONFIG_XEN_GUEST
53     FIX_PV_CONSOLE,
54     FIX_XEN_SHARED_INFO,
55 #endif /* CONFIG_XEN_GUEST */
56     /* Everything else should go further down. */
57     FIX_APIC_BASE,
58     FIX_IO_APIC_BASE_0,
59     FIX_IO_APIC_BASE_END = FIX_IO_APIC_BASE_0 + MAX_IO_APICS-1,
60     FIX_ACPI_BEGIN,
61     FIX_ACPI_END = FIX_ACPI_BEGIN + NUM_FIXMAP_ACPI_PAGES - 1,
62     FIX_HPET_BASE,
63     FIX_TBOOT_SHARED_BASE,
64     FIX_MSIX_IO_RESERV_BASE,
65     FIX_MSIX_IO_RESERV_END = FIX_MSIX_IO_RESERV_BASE + FIX_MSIX_MAX_PAGES -1,
66     FIX_TBOOT_MAP_ADDRESS,
67     FIX_APEI_RANGE_BASE,
68     FIX_APEI_RANGE_END = FIX_APEI_RANGE_BASE + FIX_APEI_RANGE_MAX -1,
69     FIX_EFI_MPF,
70     __end_of_fixed_addresses
71 };
72 
73 #define FIXADDR_SIZE  (__end_of_fixed_addresses << PAGE_SHIFT)
74 #define FIXADDR_START (FIXADDR_TOP - FIXADDR_SIZE)
75 
76 extern void __set_fixmap(
77     enum fixed_addresses idx, unsigned long mfn, unsigned long flags);
78 
79 #define set_fixmap(idx, phys) \
80     __set_fixmap(idx, (phys)>>PAGE_SHIFT, PAGE_HYPERVISOR)
81 
82 #define set_fixmap_nocache(idx, phys) \
83     __set_fixmap(idx, (phys)>>PAGE_SHIFT, PAGE_HYPERVISOR_UCMINUS)
84 
85 #define clear_fixmap(idx) __set_fixmap(idx, 0, 0)
86 
87 #define __fix_to_virt(x) gcc11_wrap(FIXADDR_TOP - ((x) << PAGE_SHIFT))
88 #define __virt_to_fix(x) ((FIXADDR_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT)
89 
90 #define fix_to_virt(x)   ((void *)__fix_to_virt(x))
91 
virt_to_fix(const unsigned long vaddr)92 static inline unsigned long virt_to_fix(const unsigned long vaddr)
93 {
94     BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START);
95     return __virt_to_fix(vaddr);
96 }
97 
98 enum fixed_addresses_x {
99     /* Index 0 is reserved since fix_x_to_virt(0) == FIXADDR_X_TOP. */
100     FIX_X_RESERVED,
101 #ifdef CONFIG_HYPERV_GUEST
102     FIX_X_HYPERV_HCALL,
103 #endif
104     __end_of_fixed_addresses_x
105 };
106 
107 #define FIXADDR_X_SIZE  (__end_of_fixed_addresses_x << PAGE_SHIFT)
108 #define FIXADDR_X_START (FIXADDR_X_TOP - FIXADDR_X_SIZE)
109 
110 extern void __set_fixmap_x(
111     enum fixed_addresses_x idx, unsigned long mfn, unsigned long flags);
112 
113 #define set_fixmap_x(idx, phys) \
114     __set_fixmap_x(idx, (phys)>>PAGE_SHIFT, PAGE_HYPERVISOR_RX | MAP_SMALL_PAGES)
115 
116 #define clear_fixmap_x(idx) __set_fixmap_x(idx, 0, 0)
117 
118 #define __fix_x_to_virt(x) (FIXADDR_X_TOP - ((x) << PAGE_SHIFT))
119 #define fix_x_to_virt(x)   ((void *)__fix_x_to_virt(x))
120 
121 #endif /* __ASSEMBLY__ */
122 
123 #endif
124