Stefan Reinauer | 597ff87 | 2013-01-07 13:21:22 -0800 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2004 Stefan Reinauer <stefan.reinauer@coreboot.org> |
| 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 |
Paul Menzel | a46a712 | 2013-02-23 18:37:27 +0100 | [diff] [blame^] | 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Stefan Reinauer | 597ff87 | 2013-01-07 13:21:22 -0800 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #include <cbmem.h> |
| 21 | |
| 22 | #define CMOS_ADDR_PORT 0x70 |
| 23 | #define CMOS_DATA_PORT 0x71 |
| 24 | #define HIGH_RAM_ADDR 0x35 |
| 25 | #define LOW_RAM_ADDR 0x34 |
| 26 | |
| 27 | static unsigned long qemu_get_memory_size(void) |
| 28 | { |
| 29 | unsigned long tomk; |
| 30 | outb (HIGH_RAM_ADDR, CMOS_ADDR_PORT); |
| 31 | tomk = ((unsigned long) inb(CMOS_DATA_PORT)) << 14; |
| 32 | outb (LOW_RAM_ADDR, CMOS_ADDR_PORT); |
| 33 | tomk |= ((unsigned long) inb(CMOS_DATA_PORT)) << 6; |
| 34 | tomk += 16 * 1024; |
| 35 | return tomk; |
| 36 | } |
| 37 | |
| 38 | unsigned long get_top_of_ram(void); |
| 39 | unsigned long get_top_of_ram(void) |
| 40 | { |
| 41 | return qemu_get_memory_size() * 1024; |
| 42 | } |
| 43 | |
| 44 | struct cbmem_entry *get_cbmem_toc(void) |
| 45 | { |
| 46 | return (struct cbmem_entry *)(get_top_of_ram() - HIGH_MEMORY_SIZE); |
| 47 | } |