blob: 45905447654e97780f52ce3c36c8643262392499 [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>
29#include "gm45.h"
30
31/** Decodes used Graphics Mode Select (GMS) to kilobytes. */
32u32 decode_igd_memory_size(const u32 gms)
33{
34 switch (gms) {
35 case 1:
36 return 1 << 10;
37 case 2:
38 return 4 << 10; /* guessed */
39 case 3:
40 return 8 << 10; /* guessed */
41 case 4:
42 return 16 << 10;
43 case 5:
44 return 32 << 10;
45 case 7:
46 return 64 << 10;
47 case 8:
48 return 128 << 10;
49 case 9:
50 return 256 << 10;
51 case 10:
52 return 96 << 10;
53 case 11:
54 return 160 << 10;
55 case 12:
56 return 224 << 10;
57 case 13:
58 return 352 << 10;
59 default:
60 die("Bad Graphics Mode Select (GMS) setting.\n");
61 return 0;
62 }
63}
64
65/** Decodes used Graphics Stolen Memory (GSM) to kilobytes. */
66u32 decode_igd_gtt_size(const u32 gsm)
67{
68 switch (gsm) {
69 case 0:
70 return 0 << 10;
71 case 1:
72 return 1 << 10;
73 case 3:
74 case 9:
75 return 2 << 10;
76 case 10:
77 return 3 << 10;
78 case 11:
79 return 4 << 10;
80 default:
81 die("Bad Graphics Stolen Memory (GSM) setting.\n");
82 return 0;
83 }
84}
85
86u32 get_top_of_ram(void)
87{
88 const device_t dev = PCI_DEV(0, 0, 0);
89
90 u32 tor;
91
92 /* Top of Lower Usable DRAM */
93 tor = (pci_read_config16(dev, D0F0_TOLUD) & 0xfff0) << 16;
94
95 /* Graphics memory comes next */
96 const u32 ggc = pci_read_config16(dev, D0F0_GGC);
97 if (!(ggc & 2)) {
98 /* Graphics memory */
99 tor -= decode_igd_memory_size((ggc >> 4) & 0xf) << 10;
100 /* GTT Graphics Stolen Memory Size (GGMS) */
101 tor -= decode_igd_gtt_size((ggc >> 8) & 0xf) << 10;
102 }
103 return tor;
104}