blob: c22b491c66f816ece71b99aa0da48a7e69d5ceed [file] [log] [blame]
Patrick Georgi2efc8802012-11-06 11:03:53 +01001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2012 secunet Security Networks AG
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; version 2 of
9 * the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Patrick Georgi2efc8802012-11-06 11:03:53 +010015 */
16
Kyösti Mälkkief844012013-06-25 23:17:43 +030017// Use simple device model for this file even in ramstage
18#define __SIMPLE_DEVICE__
19
Patrick Georgi2efc8802012-11-06 11:03:53 +010020#include <stdint.h>
21#include <arch/io.h>
Patrick Georgi2efc8802012-11-06 11:03:53 +010022#include <device/pci_def.h>
23#include <console/console.h>
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030024#include <cpu/intel/romstage.h>
Kyösti Mälkkidcb688e2013-09-04 01:11:16 +030025#include <cbmem.h>
Patrick Georgi2efc8802012-11-06 11:03:53 +010026#include "gm45.h"
27
Arthur Heymanseeaf9e42016-11-12 20:13:07 +010028/*
29 * Decodes used Graphics Mode Select (GMS) to kilobytes.
30 * The options for 1M, 4M, 8M and 16M preallocated igd memory are
31 * undocumented but are verified to work.
32 */
Patrick Georgi2efc8802012-11-06 11:03:53 +010033u32 decode_igd_memory_size(const u32 gms)
34{
Arthur Heymanseeaf9e42016-11-12 20:13:07 +010035 static const u16 ggc2uma[] = { 0, 1, 4, 8, 16, 32, 48, 64, 128, 256,
36 96, 160, 224, 352 };
37
38 if (gms > ARRAY_SIZE(ggc2uma))
Patrick Georgi2efc8802012-11-06 11:03:53 +010039 die("Bad Graphics Mode Select (GMS) setting.\n");
Arthur Heymanseeaf9e42016-11-12 20:13:07 +010040
41 return ggc2uma[gms] << 10;
Patrick Georgi2efc8802012-11-06 11:03:53 +010042}
43
44/** Decodes used Graphics Stolen Memory (GSM) to kilobytes. */
45u32 decode_igd_gtt_size(const u32 gsm)
46{
47 switch (gsm) {
48 case 0:
49 return 0 << 10;
50 case 1:
51 return 1 << 10;
52 case 3:
53 case 9:
54 return 2 << 10;
55 case 10:
56 return 3 << 10;
57 case 11:
58 return 4 << 10;
59 default:
60 die("Bad Graphics Stolen Memory (GSM) setting.\n");
61 return 0;
62 }
63}
64
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020065static uintptr_t smm_region_start(void)
Patrick Georgi2efc8802012-11-06 11:03:53 +010066{
Kyösti Mälkki3f9a62e2013-06-20 20:25:21 +030067 const pci_devfn_t dev = PCI_DEV(0, 0, 0);
Patrick Georgi2efc8802012-11-06 11:03:53 +010068
69 u32 tor;
70
71 /* Top of Lower Usable DRAM */
72 tor = (pci_read_config16(dev, D0F0_TOLUD) & 0xfff0) << 16;
73
74 /* Graphics memory comes next */
75 const u32 ggc = pci_read_config16(dev, D0F0_GGC);
76 if (!(ggc & 2)) {
77 /* Graphics memory */
78 tor -= decode_igd_memory_size((ggc >> 4) & 0xf) << 10;
79 /* GTT Graphics Stolen Memory Size (GGMS) */
80 tor -= decode_igd_gtt_size((ggc >> 8) & 0xf) << 10;
81 }
82 return tor;
83}
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020084
Kyösti Mälkki811932a2016-07-22 22:53:19 +030085/* Depending of UMA and TSEG configuration, TSEG might start at any
86 * 1 MiB aligment. As this may cause very greedy MTRR setup, push
87 * CBMEM top downwards to 4 MiB boundary.
88 */
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020089void *cbmem_top(void)
90{
Kyösti Mälkki811932a2016-07-22 22:53:19 +030091 uintptr_t top_of_ram = ALIGN_DOWN(smm_region_start(), 4*MiB);
92 return (void *) top_of_ram;
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020093}
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +030094
95void *setup_stack_and_mtrrs(void)
96{
97 return (void*)CONFIG_RAMTOP;
98}