Kyösti Mälkki | 78c5d58 | 2015-01-09 23:48:47 +0200 | [diff] [blame^] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2010 Advanced Micro Devices, Inc. |
| 5 | * |
| 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. |
| 9 | * |
| 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. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <arch/io.h> |
| 22 | #include <arch/acpi.h> |
| 23 | #include <cbmem.h> |
| 24 | #include "SBPLATFORM.h" |
| 25 | |
| 26 | int acpi_get_sleep_type(void) |
| 27 | { |
| 28 | u16 tmp = inw(PM1_CNT_BLK_ADDRESS); |
| 29 | tmp = ((tmp & (7 << 10)) >> 10); |
| 30 | return (int)tmp; |
| 31 | } |
| 32 | |
| 33 | #ifndef __PRE_RAM__ |
| 34 | void backup_top_of_ram(uint64_t ramtop) |
| 35 | { |
| 36 | u32 dword = (u32) ramtop; |
| 37 | int nvram_pos = 0xf8, i; /* temp */ |
| 38 | for (i = 0; i<4; i++) { |
| 39 | outb(nvram_pos, BIOSRAM_INDEX); |
| 40 | outb((dword >>(8 * i)) & 0xff , BIOSRAM_DATA); |
| 41 | nvram_pos++; |
| 42 | } |
| 43 | } |
| 44 | #endif |
| 45 | |
| 46 | unsigned long get_top_of_ram(void) |
| 47 | { |
| 48 | u32 xdata = 0; |
| 49 | int xnvram_pos = 0xf8, xi; |
| 50 | if (acpi_get_sleep_type() != 3) |
| 51 | return 0; |
| 52 | for (xi = 0; xi<4; xi++) { |
| 53 | outb(xnvram_pos, BIOSRAM_INDEX); |
| 54 | xdata &= ~(0xff << (xi * 8)); |
| 55 | xdata |= inb(BIOSRAM_DATA) << (xi *8); |
| 56 | xnvram_pos++; |
| 57 | } |
| 58 | return (unsigned long) xdata; |
| 59 | } |