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> |
Nico Huber | 666c8f8 | 2020-07-14 12:22:16 +0200 | [diff] [blame] | 6 | #include <console/console.h> |
Arthur Heymans | 279c3e1 | 2020-12-02 13:28:53 +0100 | [diff] [blame] | 7 | #include <cpu/x86/smm.h> |
Patrick Rudolph | 69d5ef9 | 2018-11-11 12:43:48 +0100 | [diff] [blame] | 8 | #include "memory.h" |
Thomas Heijligen | 8d010db | 2019-01-10 19:45:47 +0100 | [diff] [blame] | 9 | #include "fw_cfg.h" |
Stefan Reinauer | 597ff87 | 2013-01-07 13:21:22 -0800 | [diff] [blame] | 10 | |
| 11 | #define CMOS_ADDR_PORT 0x70 |
| 12 | #define CMOS_DATA_PORT 0x71 |
Gerd Hoffmann | 9839a38 | 2013-06-17 12:26:17 +0200 | [diff] [blame] | 13 | |
Stefan Reinauer | 597ff87 | 2013-01-07 13:21:22 -0800 | [diff] [blame] | 14 | #define HIGH_RAM_ADDR 0x35 |
| 15 | #define LOW_RAM_ADDR 0x34 |
| 16 | |
Gerd Hoffmann | 9839a38 | 2013-06-17 12:26:17 +0200 | [diff] [blame] | 17 | #define HIGH_HIGHRAM_ADDR 0x5d |
| 18 | #define MID_HIGHRAM_ADDR 0x5c |
| 19 | #define LOW_HIGHRAM_ADDR 0x5b |
| 20 | |
Patrick Rudolph | 69d5ef9 | 2018-11-11 12:43:48 +0100 | [diff] [blame] | 21 | unsigned long qemu_get_high_memory_size(void) |
| 22 | { |
| 23 | unsigned long high; |
| 24 | outb(HIGH_HIGHRAM_ADDR, CMOS_ADDR_PORT); |
Elyes Haouas | 486240f | 2022-11-18 15:21:03 +0100 | [diff] [blame^] | 25 | high = ((unsigned long)inb(CMOS_DATA_PORT)) << 22; |
Patrick Rudolph | 69d5ef9 | 2018-11-11 12:43:48 +0100 | [diff] [blame] | 26 | outb(MID_HIGHRAM_ADDR, CMOS_ADDR_PORT); |
Elyes Haouas | 486240f | 2022-11-18 15:21:03 +0100 | [diff] [blame^] | 27 | high |= ((unsigned long)inb(CMOS_DATA_PORT)) << 14; |
Patrick Rudolph | 69d5ef9 | 2018-11-11 12:43:48 +0100 | [diff] [blame] | 28 | outb(LOW_HIGHRAM_ADDR, CMOS_ADDR_PORT); |
Elyes Haouas | 486240f | 2022-11-18 15:21:03 +0100 | [diff] [blame^] | 29 | high |= ((unsigned long)inb(CMOS_DATA_PORT)) << 6; |
Patrick Rudolph | 69d5ef9 | 2018-11-11 12:43:48 +0100 | [diff] [blame] | 30 | return high; |
| 31 | } |
| 32 | |
| 33 | unsigned long qemu_get_memory_size(void) |
Stefan Reinauer | 597ff87 | 2013-01-07 13:21:22 -0800 | [diff] [blame] | 34 | { |
| 35 | unsigned long tomk; |
Patrick Rudolph | 69d5ef9 | 2018-11-11 12:43:48 +0100 | [diff] [blame] | 36 | outb(HIGH_RAM_ADDR, CMOS_ADDR_PORT); |
Elyes Haouas | 486240f | 2022-11-18 15:21:03 +0100 | [diff] [blame^] | 37 | tomk = ((unsigned long)inb(CMOS_DATA_PORT)) << 14; |
Patrick Rudolph | 69d5ef9 | 2018-11-11 12:43:48 +0100 | [diff] [blame] | 38 | outb(LOW_RAM_ADDR, CMOS_ADDR_PORT); |
Elyes Haouas | 486240f | 2022-11-18 15:21:03 +0100 | [diff] [blame^] | 39 | tomk |= ((unsigned long)inb(CMOS_DATA_PORT)) << 6; |
Stefan Reinauer | 597ff87 | 2013-01-07 13:21:22 -0800 | [diff] [blame] | 40 | tomk += 16 * 1024; |
| 41 | return tomk; |
| 42 | } |
| 43 | |
Elyes Haouas | 799c321 | 2022-11-09 14:00:44 +0100 | [diff] [blame] | 44 | uintptr_t cbmem_top_chipset(void) |
Stefan Reinauer | 597ff87 | 2013-01-07 13:21:22 -0800 | [diff] [blame] | 45 | { |
Thomas Heijligen | 8d010db | 2019-01-10 19:45:47 +0100 | [diff] [blame] | 46 | uintptr_t top = 0; |
| 47 | |
| 48 | top = fw_cfg_tolud(); |
Nico Huber | 666c8f8 | 2020-07-14 12:22:16 +0200 | [diff] [blame] | 49 | if (!top) { |
| 50 | printk(BIOS_WARNING, "QEMU: Falling back to RAM info in CMOS\n"); |
Thomas Heijligen | 8d010db | 2019-01-10 19:45:47 +0100 | [diff] [blame] | 51 | top = (uintptr_t)qemu_get_memory_size() * 1024; |
Nico Huber | 666c8f8 | 2020-07-14 12:22:16 +0200 | [diff] [blame] | 52 | } |
Thomas Heijligen | 8d010db | 2019-01-10 19:45:47 +0100 | [diff] [blame] | 53 | |
Arthur Heymans | 279c3e1 | 2020-12-02 13:28:53 +0100 | [diff] [blame] | 54 | if (CONFIG(BOARD_EMULATION_QEMU_X86_Q35)) { |
| 55 | size_t smm_size; |
| 56 | smm_region(&top, &smm_size); |
| 57 | } |
| 58 | |
Elyes Haouas | 799c321 | 2022-11-09 14:00:44 +0100 | [diff] [blame] | 59 | return top; |
Stefan Reinauer | 597ff87 | 2013-01-07 13:21:22 -0800 | [diff] [blame] | 60 | } |
Kyösti Mälkki | f0a3d44 | 2019-08-18 08:02:23 +0300 | [diff] [blame] | 61 | |
| 62 | /* Nothing to do, MTRRs are no-op on QEMU. */ |
| 63 | void fill_postcar_frame(struct postcar_frame *pcf) |
| 64 | { |
| 65 | } |