25 #include <linux/export.h>
27 #include <linux/sched.h>
36 #include <asm/processor.h>
37 #include <asm/bootparam.h>
38 #include <asm/pgtable.h>
39 #include <asm/pgalloc.h>
40 #include <asm/swiotlb.h>
41 #include <asm/fixmap.h>
43 #include <asm/setup.h>
47 #include "../realmode/rm/wakeup.h"
54 #define AP_WAIT_TIMEOUT 1
57 #define pr_fmt(fmt) "tboot: " fmt
72 pr_warning(
"non-0 tboot_addr but it is not of type E820_RESERVED\n");
78 pr_warning(
"non-0 tboot_addr but pv_ops is enabled\n");
84 tboot = (
struct tboot *)fix_to_virt(FIX_TBOOT_BASE);
85 if (
memcmp(&tboot_uuid, &tboot->uuid,
sizeof(tboot->uuid))) {
91 if (tboot->version < 5) {
92 pr_warning(
"tboot version is invalid: %u\n", tboot->version);
97 pr_info(
"found shared page at phys addr 0x%llx:\n",
99 pr_debug(
"version: %d\n", tboot->version);
100 pr_debug(
"log_addr: 0x%08x\n", tboot->log_addr);
101 pr_debug(
"shutdown_entry: 0x%x\n", tboot->shutdown_entry);
102 pr_debug(
"tboot_base: 0x%08x\n", tboot->tboot_base);
103 pr_debug(
"tboot_size: 0x%x\n", tboot->tboot_size);
106 static pgd_t *tboot_pg_dir;
117 static inline void switch_to_tboot_pt(
void)
122 static int map_tboot_page(
unsigned long vaddr,
unsigned long pfn,
137 pte = pte_alloc_map(&tboot_mm,
NULL, pmd, vaddr);
145 static int map_tboot_pages(
unsigned long vaddr,
unsigned long start_pfn,
153 for (; nr > 0; nr--, vaddr +=
PAGE_SIZE, start_pfn++) {
161 static void tboot_create_trampoline(
void)
163 u32 map_base, map_size;
166 map_base =
PFN_DOWN(tboot->tboot_base);
167 map_size =
PFN_UP(tboot->tboot_size);
168 if (map_tboot_pages(map_base <<
PAGE_SHIFT, map_base, map_size))
169 panic(
"tboot: Error mapping tboot pages (mfns) @ 0x%x, 0x%x\n",
173 #ifdef CONFIG_ACPI_SLEEP
177 struct tboot_mac_region *mr;
180 if (tboot->num_mac_regions >= MAX_TB_MAC_REGIONS)
181 panic(
"tboot: Too many MAC regions\n");
184 mr = &tboot->mac_regions[tboot->num_mac_regions++];
190 static int tboot_setup_sleep(
void)
194 tboot->num_mac_regions = 0;
196 for (i = 0; i <
e820.nr_map; i++) {
201 add_mac_region(
e820.map[i].addr,
e820.map[i].size);
204 tboot->acpi_sinfo.kernel_s3_resume_vector =
212 static int tboot_setup_sleep(
void)
238 if (tboot_setup_sleep())
241 tboot->shutdown_type = shutdown_type;
243 switch_to_tboot_pt();
255 #define TB_COPY_GAS(tbg, g) \
256 tbg.space_id = g.space_id; \
257 tbg.bit_width = g.bit_width; \
258 tbg.bit_offset = g.bit_offset; \
259 tbg.access_width = g.access_width; \
260 tbg.address = g.address;
272 tboot->acpi_sinfo.wakeup_vector = fadt->
facs +
287 tboot_copy_fadt(&acpi_gbl_FADT);
288 tboot->acpi_sinfo.pm1a_cnt_val = pm1a_control;
289 tboot->acpi_sinfo.pm1b_cnt_val = pm1b_control;
291 tboot->acpi_sinfo.vector_width = 32;
294 acpi_shutdown_map[sleep_state] == -1) {
295 pr_warning(
"unsupported sleep state 0x%x\n", sleep_state);
305 static int tboot_wait_for_aps(
int num_aps)
323 unsigned long action,
void *hcpu)
329 if (tboot_wait_for_aps(
atomic_read(&ap_wfs_count)))
338 .notifier_call = tboot_cpu_callback,
341 static __init int tboot_late_init(
void)
346 tboot_create_trampoline();
361 #define TXT_PUB_CONFIG_REGS_BASE 0xfed30000
362 #define TXT_PRIV_CONFIG_REGS_BASE 0xfed20000
365 #define NR_TXT_CONFIG_PAGES ((TXT_PUB_CONFIG_REGS_BASE - \
366 TXT_PRIV_CONFIG_REGS_BASE) >> PAGE_SHIFT)
369 #define TXTCR_HEAP_BASE 0x0300
370 #define TXTCR_HEAP_SIZE 0x0308
398 void *heap_base, *heap_ptr, *
config;
423 heap_ptr = heap_base + *(
u64 *)heap_base;
425 heap_ptr += *(
u64 *)heap_ptr;
427 heap_ptr += *(
u64 *)heap_ptr;
429 heap_ptr +=
sizeof(
u64);
446 pr_warning(
"Forcing Intel-IOMMU to enabled\n");
449 #ifdef CONFIG_SWIOTLB