blob: 084679ff4af892371c34b100eff4ca3078839050 [file] [log] [blame]
Keith Huid0301c12017-09-02 18:13:11 -04001/*
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älkki6e2d0c12019-06-28 10:08:51 +030018#include <arch/cpu.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020019#include <device/pci_ops.h>
Keith Huid0301c12017-09-02 18:13:11 -040020#include <cbmem.h>
Kyösti Mälkki54d6a282018-05-25 06:03:14 +030021#include <console/console.h>
Keith Huid0301c12017-09-02 18:13:11 -040022#include <commonlib/helpers.h>
Kyösti Mälkki54d6a282018-05-25 06:03:14 +030023#include <cpu/intel/romstage.h>
24#include <cpu/x86/mtrr.h>
25#include <program_loading.h>
Keith Huid0301c12017-09-02 18:13:11 -040026#include "i440bx.h"
27
28void *cbmem_top(void)
29{
30 /* Base of TSEG is top of usable DRAM */
31 /*
32 * SMRAM - System Management RAM Control Register
33 * 0x72
34 * [7:4] Not relevant to this function.
35 * [3:3] Global SMRAM Enable (G_SMRAME)
36 * [2:0] Hardwired to 010.
37 *
38 * ESMRAMC - Extended System Management RAM Control
39 * 0x73
40 * [7:7] H_SMRAM_EN
41 * 1 = When G_SMRAME=1, High SMRAM space is enabled at
42 * 0x100A0000-0x100FFFFF and forwarded to DRAM address
43 * 0x000A0000-0x000FFFFF.
44 * 0 = When G_SMRAME=1, Compatible SMRAM space is enabled at
45 * 0x000A0000-0x000BFFFF.
46 * [6:3] Not relevant to this function.
47 * [2:1] TSEG Size (T_SZ)
48 * Selects the size of the TSEG memory block, if enabled.
49 * 00 = 128KiB
50 * 01 = 256KiB
51 * 10 = 512KiB
52 * 11 = 1MiB
53 * [0:0] TSEG_EN
54 * When SMRAM[G_SMRAME] and this bit are 1, TSEG is enabled to
55 * appear between DRAM address (TOM-<TSEG Size>) to TOM.
56 *
57 * Source: 440BX datasheet, pages 3-28 thru 3-29.
58 */
59 unsigned long tom = pci_read_config8(NB, DRB7) * 8 * MiB;
60
61 int gsmrame = pci_read_config8(NB, SMRAM) & 0x8;
62 /* T_SZ and TSEG_EN */
63 int tseg = pci_read_config8(NB, ESMRAMC) & 0x7;
64 if ((tseg & 0x1) && gsmrame) {
65 int tseg_size = 128 * KiB * (1 << (tseg >> 1));
66 tom -= tseg_size;
67 }
68 return (void *)tom;
69}
Kyösti Mälkki54d6a282018-05-25 06:03:14 +030070
Kyösti Mälkki5bc641a2019-08-09 09:37:49 +030071void fill_postcar_frame(struct postcar_frame *pcf)
Kyösti Mälkki54d6a282018-05-25 06:03:14 +030072{
Kyösti Mälkki54d6a282018-05-25 06:03:14 +030073 uintptr_t top_of_ram;
74
Kyösti Mälkki54d6a282018-05-25 06:03:14 +030075
76 /* Cache the ROM as WP just below 4GiB. */
Kyösti Mälkki5bc641a2019-08-09 09:37:49 +030077 postcar_frame_add_romcache(pcf, MTRR_TYPE_WRPROT);
Kyösti Mälkki54d6a282018-05-25 06:03:14 +030078
79 /* Cache RAM as WB from 0 -> CACHE_TMP_RAMTOP. */
Kyösti Mälkki5bc641a2019-08-09 09:37:49 +030080 postcar_frame_add_mtrr(pcf, 0, CACHE_TMP_RAMTOP, MTRR_TYPE_WRBACK);
Kyösti Mälkki54d6a282018-05-25 06:03:14 +030081
82 /* Cache CBMEM region as WB. */
83 top_of_ram = (uintptr_t)cbmem_top();
Kyösti Mälkki5bc641a2019-08-09 09:37:49 +030084 postcar_frame_add_mtrr(pcf, top_of_ram - 8*MiB, 8*MiB,
Kyösti Mälkki54d6a282018-05-25 06:03:14 +030085 MTRR_TYPE_WRBACK);
86
Kyösti Mälkki54d6a282018-05-25 06:03:14 +030087}