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. |
Stefan Reinauer | 597ff87 | 2013-01-07 13:21:22 -0800 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <cbmem.h> |
| 17 | |
| 18 | #define CMOS_ADDR_PORT 0x70 |
| 19 | #define CMOS_DATA_PORT 0x71 |
Gerd Hoffmann | 9839a38 | 2013-06-17 12:26:17 +0200 | [diff] [blame] | 20 | |
Stefan Reinauer | 597ff87 | 2013-01-07 13:21:22 -0800 | [diff] [blame] | 21 | #define HIGH_RAM_ADDR 0x35 |
| 22 | #define LOW_RAM_ADDR 0x34 |
| 23 | |
Gerd Hoffmann | 9839a38 | 2013-06-17 12:26:17 +0200 | [diff] [blame] | 24 | #define HIGH_HIGHRAM_ADDR 0x5d |
| 25 | #define MID_HIGHRAM_ADDR 0x5c |
| 26 | #define LOW_HIGHRAM_ADDR 0x5b |
| 27 | |
Stefan Reinauer | 597ff87 | 2013-01-07 13:21:22 -0800 | [diff] [blame] | 28 | static unsigned long qemu_get_memory_size(void) |
| 29 | { |
| 30 | unsigned long tomk; |
| 31 | outb (HIGH_RAM_ADDR, CMOS_ADDR_PORT); |
| 32 | tomk = ((unsigned long) inb(CMOS_DATA_PORT)) << 14; |
| 33 | outb (LOW_RAM_ADDR, CMOS_ADDR_PORT); |
| 34 | tomk |= ((unsigned long) inb(CMOS_DATA_PORT)) << 6; |
| 35 | tomk += 16 * 1024; |
| 36 | return tomk; |
| 37 | } |
| 38 | |
Kyösti Mälkki | f1e3c76 | 2014-12-22 12:28:07 +0200 | [diff] [blame] | 39 | void *cbmem_top(void) |
Stefan Reinauer | 597ff87 | 2013-01-07 13:21:22 -0800 | [diff] [blame] | 40 | { |
Kyösti Mälkki | f1e3c76 | 2014-12-22 12:28:07 +0200 | [diff] [blame] | 41 | return (void *) (qemu_get_memory_size() * 1024); |
Stefan Reinauer | 597ff87 | 2013-01-07 13:21:22 -0800 | [diff] [blame] | 42 | } |