blob: a0290207489235ab801901c4444c995cee12a26c [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.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
19 * MA 02110-1301 USA
20 */
21
Kyösti Mälkkief844012013-06-25 23:17:43 +030022// Use simple device model for this file even in ramstage
23#define __SIMPLE_DEVICE__
24
Patrick Georgi2efc8802012-11-06 11:03:53 +010025#include <stdint.h>
26#include <arch/io.h>
Patrick Georgi2efc8802012-11-06 11:03:53 +010027#include <device/pci_def.h>
28#include <console/console.h>
Kyösti Mälkkidcb688e2013-09-04 01:11:16 +030029#include <cbmem.h>
Patrick Georgi2efc8802012-11-06 11:03:53 +010030#include "gm45.h"
31
32/** Decodes used Graphics Mode Select (GMS) to kilobytes. */
33u32 decode_igd_memory_size(const u32 gms)
34{
35 switch (gms) {
36 case 1:
37 return 1 << 10;
38 case 2:
39 return 4 << 10; /* guessed */
40 case 3:
41 return 8 << 10; /* guessed */
42 case 4:
43 return 16 << 10;
44 case 5:
45 return 32 << 10;
46 case 7:
47 return 64 << 10;
48 case 8:
49 return 128 << 10;
50 case 9:
51 return 256 << 10;
52 case 10:
53 return 96 << 10;
54 case 11:
55 return 160 << 10;
56 case 12:
57 return 224 << 10;
58 case 13:
59 return 352 << 10;
60 default:
61 die("Bad Graphics Mode Select (GMS) setting.\n");
62 return 0;
63 }
64}
65
66/** Decodes used Graphics Stolen Memory (GSM) to kilobytes. */
67u32 decode_igd_gtt_size(const u32 gsm)
68{
69 switch (gsm) {
70 case 0:
71 return 0 << 10;
72 case 1:
73 return 1 << 10;
74 case 3:
75 case 9:
76 return 2 << 10;
77 case 10:
78 return 3 << 10;
79 case 11:
80 return 4 << 10;
81 default:
82 die("Bad Graphics Stolen Memory (GSM) setting.\n");
83 return 0;
84 }
85}
86
Kyösti Mälkkidcb688e2013-09-04 01:11:16 +030087unsigned long get_top_of_ram(void)
Patrick Georgi2efc8802012-11-06 11:03:53 +010088{
Kyösti Mälkki3f9a62e2013-06-20 20:25:21 +030089 const pci_devfn_t dev = PCI_DEV(0, 0, 0);
Patrick Georgi2efc8802012-11-06 11:03:53 +010090
91 u32 tor;
92
93 /* Top of Lower Usable DRAM */
94 tor = (pci_read_config16(dev, D0F0_TOLUD) & 0xfff0) << 16;
95
96 /* Graphics memory comes next */
97 const u32 ggc = pci_read_config16(dev, D0F0_GGC);
98 if (!(ggc & 2)) {
99 /* Graphics memory */
100 tor -= decode_igd_memory_size((ggc >> 4) & 0xf) << 10;
101 /* GTT Graphics Stolen Memory Size (GGMS) */
102 tor -= decode_igd_gtt_size((ggc >> 8) & 0xf) << 10;
103 }
104 return tor;
105}