#include <linux/cc_platform.h>
 #include <linux/pgtable.h>
 
+#include <asm/asm.h>
 #include <asm/processor.h>
 #include <asm/proto.h>
 #include <asm/smp.h>
        [GDT_ENTRY_KERNEL_DS]           = GDT_ENTRY_INIT(DESC_DATA64, 0, 0xfffff),
 };
 
-/*
- * Address needs to be set at runtime because it references the startup_gdt
- * while the kernel still uses a direct mapping.
- */
-static struct desc_ptr startup_gdt_descr __initdata = {
-       .size = sizeof(startup_gdt)-1,
-       .address = 0,
-};
-
 static void __head *fixup_pointer(void *ptr, unsigned long physaddr)
 {
        return ptr - (void *)_text + (void *)physaddr;
  */
 static gate_desc bringup_idt_table[NUM_EXCEPTION_VECTORS] __page_aligned_data;
 
-static struct desc_ptr bringup_idt_descr = {
-       .size           = (NUM_EXCEPTION_VECTORS * sizeof(gate_desc)) - 1,
-       .address        = 0, /* Set at runtime */
-};
-
-static void set_bringup_idt_handler(gate_desc *idt, int n, void *handler)
+/* This may run while still in the direct mapping */
+static void __head startup_64_load_idt(void *vc_handler)
 {
-#ifdef CONFIG_AMD_MEM_ENCRYPT
+       struct desc_ptr desc = {
+               .address = (unsigned long)&RIP_REL_REF(bringup_idt_table),
+               .size    = sizeof(bringup_idt_table) - 1,
+       };
        struct idt_data data;
-       gate_desc desc;
-
-       init_idt_data(&data, n, handler);
-       idt_init_desc(&desc, &data);
-       native_write_idt_entry(idt, n, &desc);
-#endif
-}
+       gate_desc idt_desc;
 
-/* This runs while still in the direct mapping */
-static void __head startup_64_load_idt(unsigned long physbase)
-{
-       struct desc_ptr *desc = fixup_pointer(&bringup_idt_descr, physbase);
-       gate_desc *idt = fixup_pointer(bringup_idt_table, physbase);
-
-
-       if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT)) {
-               void *handler;
-
-               /* VMM Communication Exception */
-               handler = fixup_pointer(vc_no_ghcb, physbase);
-               set_bringup_idt_handler(idt, X86_TRAP_VC, handler);
+       /* @vc_handler is set only for a VMM Communication Exception */
+       if (vc_handler) {
+               init_idt_data(&data, X86_TRAP_VC, vc_handler);
+               idt_init_desc(&idt_desc, &data);
+               native_write_idt_entry((gate_desc *)desc.address, X86_TRAP_VC, &idt_desc);
        }
 
-       desc->address = (unsigned long)idt;
-       native_load_idt(desc);
+       native_load_idt(&desc);
 }
 
 /* This is used when running on kernel addresses */
 void early_setup_idt(void)
 {
-       /* VMM Communication Exception */
+       void *handler = NULL;
+
        if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT)) {
                setup_ghcb();
-               set_bringup_idt_handler(bringup_idt_table, X86_TRAP_VC, vc_boot_ghcb);
+               handler = vc_boot_ghcb;
        }
 
-       bringup_idt_descr.address = (unsigned long)bringup_idt_table;
-       native_load_idt(&bringup_idt_descr);
+       startup_64_load_idt(handler);
 }
 
 /*
  * Setup boot CPU state needed before kernel switches to virtual addresses.
  */
-void __head startup_64_setup_env(unsigned long physbase)
+void __head startup_64_setup_gdt_idt(void)
 {
+       void *handler = NULL;
+
+       struct desc_ptr startup_gdt_descr = {
+               .address = (unsigned long)&RIP_REL_REF(startup_gdt),
+               .size    = sizeof(startup_gdt) - 1,
+       };
+
        /* Load GDT */
-       startup_gdt_descr.address = (unsigned long)fixup_pointer(startup_gdt, physbase);
        native_load_gdt(&startup_gdt_descr);
 
        /* New GDT is live - reload data segment registers */
                     "movl %%eax, %%ss\n"
                     "movl %%eax, %%es\n" : : "a"(__KERNEL_DS) : "memory");
 
-       startup_64_load_idt(physbase);
+       if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT))
+               handler = &RIP_REL_REF(vc_no_ghcb);
+
+       startup_64_load_idt(handler);
 }