blob: 92f1a7f7e39c8bfbe4162221f47a9fb582b2805f [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
28/** Decodes used Graphics Mode Select (GMS) to kilobytes. */
29u32 decode_igd_memory_size(const u32 gms)
30{
31 switch (gms) {
32 case 1:
33 return 1 << 10;
34 case 2:
35 return 4 << 10; /* guessed */
36 case 3:
37 return 8 << 10; /* guessed */
38 case 4:
39 return 16 << 10;
40 case 5:
41 return 32 << 10;
Vladimir Serbinenkoefd1c6b2014-08-16 10:57:15 +020042 case 6:
43 return 48 << 10;
Patrick Georgi2efc8802012-11-06 11:03:53 +010044 case 7:
45 return 64 << 10;
46 case 8:
47 return 128 << 10;
48 case 9:
49 return 256 << 10;
50 case 10:
51 return 96 << 10;
52 case 11:
53 return 160 << 10;
54 case 12:
55 return 224 << 10;
56 case 13:
57 return 352 << 10;
58 default:
59 die("Bad Graphics Mode Select (GMS) setting.\n");
60 return 0;
61 }
62}
63
64/** Decodes used Graphics Stolen Memory (GSM) to kilobytes. */
65u32 decode_igd_gtt_size(const u32 gsm)
66{
67 switch (gsm) {
68 case 0:
69 return 0 << 10;
70 case 1:
71 return 1 << 10;
72 case 3:
73 case 9:
74 return 2 << 10;
75 case 10:
76 return 3 << 10;
77 case 11:
78 return 4 << 10;
79 default:
80 die("Bad Graphics Stolen Memory (GSM) setting.\n");
81 return 0;
82 }
83}
84
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020085static uintptr_t smm_region_start(void)
Patrick Georgi2efc8802012-11-06 11:03:53 +010086{
Kyösti Mälkki3f9a62e2013-06-20 20:25:21 +030087 const pci_devfn_t dev = PCI_DEV(0, 0, 0);
Patrick Georgi2efc8802012-11-06 11:03:53 +010088
89 u32 tor;
90
91 /* Top of Lower Usable DRAM */
92 tor = (pci_read_config16(dev, D0F0_TOLUD) & 0xfff0) << 16;
93
94 /* Graphics memory comes next */
95 const u32 ggc = pci_read_config16(dev, D0F0_GGC);
96 if (!(ggc & 2)) {
97 /* Graphics memory */
98 tor -= decode_igd_memory_size((ggc >> 4) & 0xf) << 10;
99 /* GTT Graphics Stolen Memory Size (GGMS) */
100 tor -= decode_igd_gtt_size((ggc >> 8) & 0xf) << 10;
101 }
102 return tor;
103}
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +0200104
105void *cbmem_top(void)
106{
107 return (void *) smm_region_start();
108}
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +0300109
110void *setup_stack_and_mtrrs(void)
111{
112 return (void*)CONFIG_RAMTOP;
113}