Move definitions of HIGH_MEMORY_SAVE
[coreboot.git] / src / cpu / amd / agesa / s3_resume.c
blob5f486f2fea754add35dccb9809873fc05813b125
1 /*
2 * This file is part of the coreboot project.
4 * Copyright (C) 2012 Advanced Micro Devices, Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include <arch/acpi.h>
17 #include <console/console.h>
18 #include <cpu/x86/msr.h>
19 #include <cpu/x86/mtrr.h>
20 #include <cpu/amd/car.h>
21 #include <cpu/amd/mtrr.h>
22 #include <cpu/x86/cache.h>
23 #include <cbmem.h>
24 #include <string.h>
25 #include <halt.h>
26 #include "s3_resume.h"
28 static void *backup_resume(void)
30 void *resume_backup_memory;
32 printk(BIOS_DEBUG, "Find resume memory location\n");
34 if (cbmem_recovery(1)) {
35 printk(BIOS_EMERG, "Unable to recover CBMEM\n");
36 halt();
39 resume_backup_memory = cbmem_find(CBMEM_ID_RESUME);
40 if (resume_backup_memory == NULL) {
41 printk(BIOS_EMERG, "No storage for low-memory backup\n");
42 halt();
45 return resume_backup_memory;
48 static void move_stack_high_mem(void)
50 void *high_stack = cbmem_find(CBMEM_ID_ROMSTAGE_RAM_STACK);
52 /* TODO: Make the switch with empty stack instead. */
53 memcpy(high_stack, (void *)BSP_STACK_BASE_ADDR, HIGH_ROMSTAGE_STACK_SIZE);
55 /* TODO: We only switch stack on BSP. */
56 #ifdef __x86_64__
57 __asm__
58 volatile ("add %0, %%rsp; add %0, %%rbp; invd"::"g"
59 (high_stack - BSP_STACK_BASE_ADDR)
60 :);
61 #else
62 __asm__
63 volatile ("add %0, %%esp; add %0, %%ebp; invd"::"g"
64 (high_stack - BSP_STACK_BASE_ADDR)
65 :);
66 #endif
69 static void set_resume_cache(void)
71 msr_t msr;
73 /* disable fixed mtrr for now, it will be enabled by mtrr restore */
74 msr = rdmsr(SYSCFG_MSR);
75 msr.lo &= ~(SYSCFG_MSR_MtrrFixDramEn | SYSCFG_MSR_MtrrFixDramModEn);
76 wrmsr(SYSCFG_MSR, msr);
78 /* Enable caching for 0 - coreboot ram using variable mtrr */
79 msr.lo = 0 | MTRR_TYPE_WRBACK;
80 msr.hi = 0;
81 wrmsr(MTRR_PHYS_BASE(0), msr);
82 msr.lo = ~(CONFIG_RAMTOP - 1) | MTRR_PHYS_MASK_VALID;
83 msr.hi = (1 << (CONFIG_CPU_ADDR_BITS - 32)) - 1;
84 wrmsr(MTRR_PHYS_MASK(0), msr);
86 /* Set the default memory type and disable fixed and enable variable MTRRs */
87 msr.hi = 0;
88 msr.lo = (1 << 11);
89 wrmsr(MTRR_DEF_TYPE_MSR, msr);
91 enable_cache();
94 void prepare_for_resume(void)
96 void *resume_backup_memory = backup_resume();
98 post_code(0x62);
99 printk(BIOS_DEBUG, "Move CAR stack.\n");
100 move_stack_high_mem();
102 post_code(0x63);
103 disable_cache_as_ram();
104 printk(BIOS_DEBUG, "CAR disabled.\n");
105 set_resume_cache();
108 * Copy the system memory that is in the ramstage area to the
109 * reserved area.
111 if (resume_backup_memory)
112 memcpy(resume_backup_memory, (void *)(CONFIG_RAMBASE), HIGH_MEMORY_SAVE);
114 printk(BIOS_DEBUG, "System memory saved. OK to load ramstage.\n");