Angel Pons | 4b42983 | 2020-04-02 23:48:50 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Keith Hui | d0301c1 | 2017-09-02 18:13:11 -0400 | [diff] [blame] | 2 | |
Kyösti Mälkki | a963acd | 2019-08-16 20:34:25 +0300 | [diff] [blame] | 3 | #include <arch/romstage.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 4 | #include <device/pci_ops.h> |
Keith Hui | d0301c1 | 2017-09-02 18:13:11 -0400 | [diff] [blame] | 5 | #include <cbmem.h> |
| 6 | #include <commonlib/helpers.h> |
Kyösti Mälkki | 54d6a28 | 2018-05-25 06:03:14 +0300 | [diff] [blame] | 7 | #include <cpu/x86/mtrr.h> |
| 8 | #include <program_loading.h> |
Keith Hui | d0301c1 | 2017-09-02 18:13:11 -0400 | [diff] [blame] | 9 | #include "i440bx.h" |
| 10 | |
Arthur Heymans | 340e4b8 | 2019-10-23 17:25:58 +0200 | [diff] [blame] | 11 | void *cbmem_top_chipset(void) |
Keith Hui | d0301c1 | 2017-09-02 18:13:11 -0400 | [diff] [blame] | 12 | { |
| 13 | /* Base of TSEG is top of usable DRAM */ |
| 14 | /* |
| 15 | * SMRAM - System Management RAM Control Register |
| 16 | * 0x72 |
| 17 | * [7:4] Not relevant to this function. |
| 18 | * [3:3] Global SMRAM Enable (G_SMRAME) |
| 19 | * [2:0] Hardwired to 010. |
| 20 | * |
| 21 | * ESMRAMC - Extended System Management RAM Control |
| 22 | * 0x73 |
| 23 | * [7:7] H_SMRAM_EN |
| 24 | * 1 = When G_SMRAME=1, High SMRAM space is enabled at |
| 25 | * 0x100A0000-0x100FFFFF and forwarded to DRAM address |
| 26 | * 0x000A0000-0x000FFFFF. |
| 27 | * 0 = When G_SMRAME=1, Compatible SMRAM space is enabled at |
| 28 | * 0x000A0000-0x000BFFFF. |
| 29 | * [6:3] Not relevant to this function. |
| 30 | * [2:1] TSEG Size (T_SZ) |
| 31 | * Selects the size of the TSEG memory block, if enabled. |
| 32 | * 00 = 128KiB |
| 33 | * 01 = 256KiB |
| 34 | * 10 = 512KiB |
| 35 | * 11 = 1MiB |
| 36 | * [0:0] TSEG_EN |
| 37 | * When SMRAM[G_SMRAME] and this bit are 1, TSEG is enabled to |
| 38 | * appear between DRAM address (TOM-<TSEG Size>) to TOM. |
| 39 | * |
| 40 | * Source: 440BX datasheet, pages 3-28 thru 3-29. |
| 41 | */ |
| 42 | unsigned long tom = pci_read_config8(NB, DRB7) * 8 * MiB; |
| 43 | |
| 44 | int gsmrame = pci_read_config8(NB, SMRAM) & 0x8; |
| 45 | /* T_SZ and TSEG_EN */ |
| 46 | int tseg = pci_read_config8(NB, ESMRAMC) & 0x7; |
| 47 | if ((tseg & 0x1) && gsmrame) { |
| 48 | int tseg_size = 128 * KiB * (1 << (tseg >> 1)); |
| 49 | tom -= tseg_size; |
| 50 | } |
| 51 | return (void *)tom; |
| 52 | } |
Kyösti Mälkki | 54d6a28 | 2018-05-25 06:03:14 +0300 | [diff] [blame] | 53 | |
Kyösti Mälkki | 5bc641a | 2019-08-09 09:37:49 +0300 | [diff] [blame] | 54 | void fill_postcar_frame(struct postcar_frame *pcf) |
Kyösti Mälkki | 54d6a28 | 2018-05-25 06:03:14 +0300 | [diff] [blame] | 55 | { |
Kyösti Mälkki | 54d6a28 | 2018-05-25 06:03:14 +0300 | [diff] [blame] | 56 | uintptr_t top_of_ram; |
| 57 | |
Kyösti Mälkki | 54d6a28 | 2018-05-25 06:03:14 +0300 | [diff] [blame] | 58 | /* Cache CBMEM region as WB. */ |
| 59 | top_of_ram = (uintptr_t)cbmem_top(); |
Kyösti Mälkki | 5bc641a | 2019-08-09 09:37:49 +0300 | [diff] [blame] | 60 | postcar_frame_add_mtrr(pcf, top_of_ram - 8*MiB, 8*MiB, |
Kyösti Mälkki | 54d6a28 | 2018-05-25 06:03:14 +0300 | [diff] [blame] | 61 | MTRR_TYPE_WRBACK); |
| 62 | |
Kyösti Mälkki | 54d6a28 | 2018-05-25 06:03:14 +0300 | [diff] [blame] | 63 | } |