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> |
Patrick Rudolph | 69d5ef9 | 2018-11-11 12:43:48 +0100 | [diff] [blame] | 17 | #include <arch/io.h> |
Kyösti Mälkki | f0a3d44 | 2019-08-18 08:02:23 +0300 | [diff] [blame^] | 18 | #include <arch/romstage.h> |
Patrick Rudolph | 69d5ef9 | 2018-11-11 12:43:48 +0100 | [diff] [blame] | 19 | #include "memory.h" |
Thomas Heijligen | 8d010db | 2019-01-10 19:45:47 +0100 | [diff] [blame] | 20 | #include "fw_cfg.h" |
Stefan Reinauer | 597ff87 | 2013-01-07 13:21:22 -0800 | [diff] [blame] | 21 | |
| 22 | #define CMOS_ADDR_PORT 0x70 |
| 23 | #define CMOS_DATA_PORT 0x71 |
Gerd Hoffmann | 9839a38 | 2013-06-17 12:26:17 +0200 | [diff] [blame] | 24 | |
Stefan Reinauer | 597ff87 | 2013-01-07 13:21:22 -0800 | [diff] [blame] | 25 | #define HIGH_RAM_ADDR 0x35 |
| 26 | #define LOW_RAM_ADDR 0x34 |
| 27 | |
Gerd Hoffmann | 9839a38 | 2013-06-17 12:26:17 +0200 | [diff] [blame] | 28 | #define HIGH_HIGHRAM_ADDR 0x5d |
| 29 | #define MID_HIGHRAM_ADDR 0x5c |
| 30 | #define LOW_HIGHRAM_ADDR 0x5b |
| 31 | |
Patrick Rudolph | 69d5ef9 | 2018-11-11 12:43:48 +0100 | [diff] [blame] | 32 | unsigned long qemu_get_high_memory_size(void) |
| 33 | { |
| 34 | unsigned long high; |
| 35 | outb(HIGH_HIGHRAM_ADDR, CMOS_ADDR_PORT); |
| 36 | high = ((unsigned long) inb(CMOS_DATA_PORT)) << 22; |
| 37 | outb(MID_HIGHRAM_ADDR, CMOS_ADDR_PORT); |
| 38 | high |= ((unsigned long) inb(CMOS_DATA_PORT)) << 14; |
| 39 | outb(LOW_HIGHRAM_ADDR, CMOS_ADDR_PORT); |
| 40 | high |= ((unsigned long) inb(CMOS_DATA_PORT)) << 6; |
| 41 | return high; |
| 42 | } |
| 43 | |
| 44 | unsigned long qemu_get_memory_size(void) |
Stefan Reinauer | 597ff87 | 2013-01-07 13:21:22 -0800 | [diff] [blame] | 45 | { |
| 46 | unsigned long tomk; |
Patrick Rudolph | 69d5ef9 | 2018-11-11 12:43:48 +0100 | [diff] [blame] | 47 | outb(HIGH_RAM_ADDR, CMOS_ADDR_PORT); |
Stefan Reinauer | 597ff87 | 2013-01-07 13:21:22 -0800 | [diff] [blame] | 48 | tomk = ((unsigned long) inb(CMOS_DATA_PORT)) << 14; |
Patrick Rudolph | 69d5ef9 | 2018-11-11 12:43:48 +0100 | [diff] [blame] | 49 | outb(LOW_RAM_ADDR, CMOS_ADDR_PORT); |
Stefan Reinauer | 597ff87 | 2013-01-07 13:21:22 -0800 | [diff] [blame] | 50 | tomk |= ((unsigned long) inb(CMOS_DATA_PORT)) << 6; |
| 51 | tomk += 16 * 1024; |
| 52 | return tomk; |
| 53 | } |
| 54 | |
Kyösti Mälkki | f1e3c76 | 2014-12-22 12:28:07 +0200 | [diff] [blame] | 55 | void *cbmem_top(void) |
Stefan Reinauer | 597ff87 | 2013-01-07 13:21:22 -0800 | [diff] [blame] | 56 | { |
Thomas Heijligen | 8d010db | 2019-01-10 19:45:47 +0100 | [diff] [blame] | 57 | uintptr_t top = 0; |
| 58 | |
| 59 | top = fw_cfg_tolud(); |
| 60 | if (!top) |
| 61 | top = (uintptr_t)qemu_get_memory_size() * 1024; |
| 62 | |
| 63 | return (void *)top; |
Stefan Reinauer | 597ff87 | 2013-01-07 13:21:22 -0800 | [diff] [blame] | 64 | } |
Kyösti Mälkki | f0a3d44 | 2019-08-18 08:02:23 +0300 | [diff] [blame^] | 65 | |
| 66 | /* Nothing to do, MTRRs are no-op on QEMU. */ |
| 67 | void fill_postcar_frame(struct postcar_frame *pcf) |
| 68 | { |
| 69 | } |