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