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 
19 #ifndef __ASSEMBLY__
20 
21 #include <xen/acpi.h>
22 #include <xen/pfn.h>
23 #include <xen/kexec.h>
24 #include <xen/iommu.h>
25 #include <asm/apicdef.h>
26 #include <asm/amd-iommu.h>
27 #include <asm/msi.h>
28 #include <acpi/apei.h>
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_XEN_GUEST
49     FIX_PV_CONSOLE,
50     FIX_XEN_SHARED_INFO,
51 #endif /* CONFIG_XEN_GUEST */
52     /* Everything else should go further down. */
53     FIX_APIC_BASE,
54     FIX_IO_APIC_BASE_0,
55     FIX_IO_APIC_BASE_END = FIX_IO_APIC_BASE_0 + MAX_IO_APICS-1,
56     FIX_ACPI_BEGIN,
57     FIX_ACPI_END = FIX_ACPI_BEGIN + NUM_FIXMAP_ACPI_PAGES - 1,
58     FIX_HPET_BASE,
59     FIX_TBOOT_SHARED_BASE,
60     FIX_MSIX_IO_RESERV_BASE,
61     FIX_MSIX_IO_RESERV_END = FIX_MSIX_IO_RESERV_BASE + FIX_MSIX_MAX_PAGES -1,
62     FIX_TBOOT_MAP_ADDRESS,
63     FIX_APEI_RANGE_BASE,
64     FIX_APEI_RANGE_END = FIX_APEI_RANGE_BASE + FIX_APEI_RANGE_MAX -1,
65     FIX_EFI_MPF,
66     __end_of_fixed_addresses
67 };
68 
69 #define FIXADDR_SIZE  (__end_of_fixed_addresses << PAGE_SHIFT)
70 #define FIXADDR_START (FIXADDR_TOP - FIXADDR_SIZE)
71 
72 extern void __set_fixmap(
73     enum fixed_addresses idx, unsigned long mfn, unsigned long flags);
74 
75 #define set_fixmap(idx, phys) \
76     __set_fixmap(idx, (phys)>>PAGE_SHIFT, PAGE_HYPERVISOR)
77 
78 #define set_fixmap_nocache(idx, phys) \
79     __set_fixmap(idx, (phys)>>PAGE_SHIFT, PAGE_HYPERVISOR_UCMINUS)
80 
81 #define clear_fixmap(idx) __set_fixmap(idx, 0, 0)
82 
83 #define __fix_to_virt(x) (FIXADDR_TOP - ((x) << PAGE_SHIFT))
84 #define __virt_to_fix(x) ((FIXADDR_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT)
85 
86 #define fix_to_virt(x)   ((void *)__fix_to_virt(x))
87 
virt_to_fix(const unsigned long vaddr)88 static inline unsigned long virt_to_fix(const unsigned long vaddr)
89 {
90     BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START);
91     return __virt_to_fix(vaddr);
92 }
93 
94 #endif /* __ASSEMBLY__ */
95 
96 #endif
97