Angel Pons | 585495e | 2020-04-03 01:21:38 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Stefan Reinauer | 597ff87 | 2013-01-07 13:21:22 -0800 | [diff] [blame] | 2 | |
| 3 | #include <cbmem.h> |
Patrick Rudolph | 69d5ef9 | 2018-11-11 12:43:48 +0100 | [diff] [blame] | 4 | #include <arch/io.h> |
Kyösti Mälkki | f0a3d44 | 2019-08-18 08:02:23 +0300 | [diff] [blame] | 5 | #include <arch/romstage.h> |
Patrick Rudolph | 69d5ef9 | 2018-11-11 12:43:48 +0100 | [diff] [blame] | 6 | #include "memory.h" |
Thomas Heijligen | 8d010db | 2019-01-10 19:45:47 +0100 | [diff] [blame] | 7 | #include "fw_cfg.h" |
Stefan Reinauer | 597ff87 | 2013-01-07 13:21:22 -0800 | [diff] [blame] | 8 | |
| 9 | #define CMOS_ADDR_PORT 0x70 |
| 10 | #define CMOS_DATA_PORT 0x71 |
Gerd Hoffmann | 9839a38 | 2013-06-17 12:26:17 +0200 | [diff] [blame] | 11 | |
Stefan Reinauer | 597ff87 | 2013-01-07 13:21:22 -0800 | [diff] [blame] | 12 | #define HIGH_RAM_ADDR 0x35 |
| 13 | #define LOW_RAM_ADDR 0x34 |
| 14 | |
Gerd Hoffmann | 9839a38 | 2013-06-17 12:26:17 +0200 | [diff] [blame] | 15 | #define HIGH_HIGHRAM_ADDR 0x5d |
| 16 | #define MID_HIGHRAM_ADDR 0x5c |
| 17 | #define LOW_HIGHRAM_ADDR 0x5b |
| 18 | |
Patrick Rudolph | 69d5ef9 | 2018-11-11 12:43:48 +0100 | [diff] [blame] | 19 | unsigned long qemu_get_high_memory_size(void) |
| 20 | { |
| 21 | unsigned long high; |
| 22 | outb(HIGH_HIGHRAM_ADDR, CMOS_ADDR_PORT); |
| 23 | high = ((unsigned long) inb(CMOS_DATA_PORT)) << 22; |
| 24 | outb(MID_HIGHRAM_ADDR, CMOS_ADDR_PORT); |
| 25 | high |= ((unsigned long) inb(CMOS_DATA_PORT)) << 14; |
| 26 | outb(LOW_HIGHRAM_ADDR, CMOS_ADDR_PORT); |
| 27 | high |= ((unsigned long) inb(CMOS_DATA_PORT)) << 6; |
| 28 | return high; |
| 29 | } |
| 30 | |
| 31 | unsigned long qemu_get_memory_size(void) |
Stefan Reinauer | 597ff87 | 2013-01-07 13:21:22 -0800 | [diff] [blame] | 32 | { |
| 33 | unsigned long tomk; |
Patrick Rudolph | 69d5ef9 | 2018-11-11 12:43:48 +0100 | [diff] [blame] | 34 | outb(HIGH_RAM_ADDR, CMOS_ADDR_PORT); |
Stefan Reinauer | 597ff87 | 2013-01-07 13:21:22 -0800 | [diff] [blame] | 35 | tomk = ((unsigned long) inb(CMOS_DATA_PORT)) << 14; |
Patrick Rudolph | 69d5ef9 | 2018-11-11 12:43:48 +0100 | [diff] [blame] | 36 | outb(LOW_RAM_ADDR, CMOS_ADDR_PORT); |
Stefan Reinauer | 597ff87 | 2013-01-07 13:21:22 -0800 | [diff] [blame] | 37 | tomk |= ((unsigned long) inb(CMOS_DATA_PORT)) << 6; |
| 38 | tomk += 16 * 1024; |
| 39 | return tomk; |
| 40 | } |
| 41 | |
Arthur Heymans | 340e4b8 | 2019-10-23 17:25:58 +0200 | [diff] [blame] | 42 | void *cbmem_top_chipset(void) |
Stefan Reinauer | 597ff87 | 2013-01-07 13:21:22 -0800 | [diff] [blame] | 43 | { |
Thomas Heijligen | 8d010db | 2019-01-10 19:45:47 +0100 | [diff] [blame] | 44 | uintptr_t top = 0; |
| 45 | |
| 46 | top = fw_cfg_tolud(); |
| 47 | if (!top) |
| 48 | top = (uintptr_t)qemu_get_memory_size() * 1024; |
| 49 | |
| 50 | return (void *)top; |
Stefan Reinauer | 597ff87 | 2013-01-07 13:21:22 -0800 | [diff] [blame] | 51 | } |
Kyösti Mälkki | f0a3d44 | 2019-08-18 08:02:23 +0300 | [diff] [blame] | 52 | |
| 53 | /* Nothing to do, MTRRs are no-op on QEMU. */ |
| 54 | void fill_postcar_frame(struct postcar_frame *pcf) |
| 55 | { |
| 56 | } |