Arthur Heymans | 279c3e1 | 2020-12-02 13:28:53 +0100 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #define __SIMPLE_DEVICE__ |
| 4 | |
| 5 | #include <console/console.h> |
| 6 | #include <cpu/x86/smm.h> |
| 7 | #include <device/pci_ops.h> |
| 8 | #include <mainboard/emulation/qemu-i440fx/memory.h> |
| 9 | #include <mainboard/emulation/qemu-i440fx/fw_cfg.h> |
| 10 | |
| 11 | #define EXT_TSEG_MBYTES 0x50 |
| 12 | |
| 13 | #define SMRAMC 0x9d |
| 14 | #define G_SMRAME (1 << 3) |
| 15 | #define D_LCK (1 << 4) |
| 16 | #define D_CLS (1 << 5) |
| 17 | #define D_OPEN (1 << 6) |
| 18 | #define ESMRAMC 0x9e |
| 19 | #define T_EN (1 << 0) |
| 20 | #define TSEG_SZ_MASK (3 << 1) |
| 21 | #define H_SMRAME (1 << 7) |
| 22 | |
| 23 | void smm_region(uintptr_t *start, size_t *size) |
| 24 | { |
| 25 | uint8_t esmramc = pci_read_config8(PCI_DEV(0, 0, 0), ESMRAMC); |
| 26 | |
| 27 | switch ((esmramc & TSEG_SZ_MASK) >> 1) { |
| 28 | case 0: |
| 29 | *size = 1 * MiB; |
| 30 | break; |
| 31 | case 1: |
| 32 | *size = 2 * MiB; |
| 33 | break; |
| 34 | case 2: |
| 35 | *size = 8 * MiB; |
| 36 | break; |
| 37 | default: |
| 38 | *size = pci_read_config16(PCI_DEV(0, 0, 0), EXT_TSEG_MBYTES) * MiB; |
| 39 | } |
| 40 | |
| 41 | *start = qemu_get_memory_size() * KiB - *size; |
| 42 | printk(BIOS_SPEW, "SMM_BASE: 0x%08lx, SMM_SIZE: %zu MiB\n", *start, *size / MiB); |
| 43 | } |