Keith Hui | d0301c1 | 2017-09-02 18:13:11 -0400 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2017 Keith Hui <buurin@gmail.com> |
| 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. |
| 14 | */ |
| 15 | |
| 16 | #define __SIMPLE_DEVICE__ |
| 17 | |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 18 | #include <device/pci_ops.h> |
Keith Hui | d0301c1 | 2017-09-02 18:13:11 -0400 | [diff] [blame] | 19 | #include <cbmem.h> |
Kyösti Mälkki | 54d6a28 | 2018-05-25 06:03:14 +0300 | [diff] [blame] | 20 | #include <console/console.h> |
Keith Hui | d0301c1 | 2017-09-02 18:13:11 -0400 | [diff] [blame] | 21 | #include <commonlib/helpers.h> |
Kyösti Mälkki | 54d6a28 | 2018-05-25 06:03:14 +0300 | [diff] [blame] | 22 | #include <cpu/intel/romstage.h> |
| 23 | #include <cpu/x86/mtrr.h> |
| 24 | #include <program_loading.h> |
Keith Hui | d0301c1 | 2017-09-02 18:13:11 -0400 | [diff] [blame] | 25 | #include "i440bx.h" |
| 26 | |
| 27 | void *cbmem_top(void) |
| 28 | { |
| 29 | /* Base of TSEG is top of usable DRAM */ |
| 30 | /* |
| 31 | * SMRAM - System Management RAM Control Register |
| 32 | * 0x72 |
| 33 | * [7:4] Not relevant to this function. |
| 34 | * [3:3] Global SMRAM Enable (G_SMRAME) |
| 35 | * [2:0] Hardwired to 010. |
| 36 | * |
| 37 | * ESMRAMC - Extended System Management RAM Control |
| 38 | * 0x73 |
| 39 | * [7:7] H_SMRAM_EN |
| 40 | * 1 = When G_SMRAME=1, High SMRAM space is enabled at |
| 41 | * 0x100A0000-0x100FFFFF and forwarded to DRAM address |
| 42 | * 0x000A0000-0x000FFFFF. |
| 43 | * 0 = When G_SMRAME=1, Compatible SMRAM space is enabled at |
| 44 | * 0x000A0000-0x000BFFFF. |
| 45 | * [6:3] Not relevant to this function. |
| 46 | * [2:1] TSEG Size (T_SZ) |
| 47 | * Selects the size of the TSEG memory block, if enabled. |
| 48 | * 00 = 128KiB |
| 49 | * 01 = 256KiB |
| 50 | * 10 = 512KiB |
| 51 | * 11 = 1MiB |
| 52 | * [0:0] TSEG_EN |
| 53 | * When SMRAM[G_SMRAME] and this bit are 1, TSEG is enabled to |
| 54 | * appear between DRAM address (TOM-<TSEG Size>) to TOM. |
| 55 | * |
| 56 | * Source: 440BX datasheet, pages 3-28 thru 3-29. |
| 57 | */ |
| 58 | unsigned long tom = pci_read_config8(NB, DRB7) * 8 * MiB; |
| 59 | |
| 60 | int gsmrame = pci_read_config8(NB, SMRAM) & 0x8; |
| 61 | /* T_SZ and TSEG_EN */ |
| 62 | int tseg = pci_read_config8(NB, ESMRAMC) & 0x7; |
| 63 | if ((tseg & 0x1) && gsmrame) { |
| 64 | int tseg_size = 128 * KiB * (1 << (tseg >> 1)); |
| 65 | tom -= tseg_size; |
| 66 | } |
| 67 | return (void *)tom; |
| 68 | } |
Kyösti Mälkki | 54d6a28 | 2018-05-25 06:03:14 +0300 | [diff] [blame] | 69 | |
| 70 | #define ROMSTAGE_RAM_STACK_SIZE 0x5000 |
| 71 | |
Kyösti Mälkki | aea8eec | 2018-06-04 08:49:17 +0300 | [diff] [blame] | 72 | /* platform_enter_postcar() determines the stack to use after |
| 73 | * cache-as-ram is torn down as well as the MTRR settings to use, |
| 74 | * and continues execution in postcar stage. */ |
| 75 | void platform_enter_postcar(void) |
Kyösti Mälkki | 54d6a28 | 2018-05-25 06:03:14 +0300 | [diff] [blame] | 76 | { |
| 77 | struct postcar_frame pcf; |
| 78 | uintptr_t top_of_ram; |
| 79 | |
| 80 | if (postcar_frame_init(&pcf, ROMSTAGE_RAM_STACK_SIZE)) |
| 81 | die("Unable to initialize postcar frame.\n"); |
| 82 | |
| 83 | /* Cache the ROM as WP just below 4GiB. */ |
Nico Huber | 4c7eee2 | 2019-02-10 19:35:41 +0100 | [diff] [blame] | 84 | postcar_frame_add_romcache(&pcf, MTRR_TYPE_WRPROT); |
Kyösti Mälkki | 54d6a28 | 2018-05-25 06:03:14 +0300 | [diff] [blame] | 85 | |
| 86 | /* Cache RAM as WB from 0 -> CACHE_TMP_RAMTOP. */ |
| 87 | postcar_frame_add_mtrr(&pcf, 0, CACHE_TMP_RAMTOP, MTRR_TYPE_WRBACK); |
| 88 | |
| 89 | /* Cache CBMEM region as WB. */ |
| 90 | top_of_ram = (uintptr_t)cbmem_top(); |
| 91 | postcar_frame_add_mtrr(&pcf, top_of_ram - 8*MiB, 8*MiB, |
| 92 | MTRR_TYPE_WRBACK); |
| 93 | |
Kyösti Mälkki | aea8eec | 2018-06-04 08:49:17 +0300 | [diff] [blame] | 94 | run_postcar_phase(&pcf); |
Kyösti Mälkki | 54d6a28 | 2018-05-25 06:03:14 +0300 | [diff] [blame] | 95 | } |