blob: c8c15d3a76281737be81c30d0bb93546170a82d7 [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;
Vladimir Serbinenkoefd1c6b2014-08-16 10:57:15 +020046 case 6:
47 return 48 << 10;
Patrick Georgi2efc8802012-11-06 11:03:53 +010048 case 7:
49 return 64 << 10;
50 case 8:
51 return 128 << 10;
52 case 9:
53 return 256 << 10;
54 case 10:
55 return 96 << 10;
56 case 11:
57 return 160 << 10;
58 case 12:
59 return 224 << 10;
60 case 13:
61 return 352 << 10;
62 default:
63 die("Bad Graphics Mode Select (GMS) setting.\n");
64 return 0;
65 }
66}
67
68/** Decodes used Graphics Stolen Memory (GSM) to kilobytes. */
69u32 decode_igd_gtt_size(const u32 gsm)
70{
71 switch (gsm) {
72 case 0:
73 return 0 << 10;
74 case 1:
75 return 1 << 10;
76 case 3:
77 case 9:
78 return 2 << 10;
79 case 10:
80 return 3 << 10;
81 case 11:
82 return 4 << 10;
83 default:
84 die("Bad Graphics Stolen Memory (GSM) setting.\n");
85 return 0;
86 }
87}
88
Kyösti Mälkkidcb688e2013-09-04 01:11:16 +030089unsigned long get_top_of_ram(void)
Patrick Georgi2efc8802012-11-06 11:03:53 +010090{
Kyösti Mälkki3f9a62e2013-06-20 20:25:21 +030091 const pci_devfn_t dev = PCI_DEV(0, 0, 0);
Patrick Georgi2efc8802012-11-06 11:03:53 +010092
93 u32 tor;
94
95 /* Top of Lower Usable DRAM */
96 tor = (pci_read_config16(dev, D0F0_TOLUD) & 0xfff0) << 16;
97
98 /* Graphics memory comes next */
99 const u32 ggc = pci_read_config16(dev, D0F0_GGC);
100 if (!(ggc & 2)) {
101 /* Graphics memory */
102 tor -= decode_igd_memory_size((ggc >> 4) & 0xf) << 10;
103 /* GTT Graphics Stolen Memory Size (GGMS) */
104 tor -= decode_igd_gtt_size((ggc >> 8) & 0xf) << 10;
105 }
106 return tor;
107}