Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 1 | /* |
| 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älkki | ef84401 | 2013-06-25 23:17:43 +0300 | [diff] [blame] | 22 | // Use simple device model for this file even in ramstage |
| 23 | #define __SIMPLE_DEVICE__ |
| 24 | |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 25 | #include <stdint.h> |
| 26 | #include <arch/io.h> |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 27 | #include <device/pci_def.h> |
| 28 | #include <console/console.h> |
Kyösti Mälkki | dcb688e | 2013-09-04 01:11:16 +0300 | [diff] [blame] | 29 | #include <cbmem.h> |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 30 | #include "gm45.h" |
| 31 | |
| 32 | /** Decodes used Graphics Mode Select (GMS) to kilobytes. */ |
| 33 | u32 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 Serbinenko | efd1c6b | 2014-08-16 10:57:15 +0200 | [diff] [blame^] | 46 | case 6: |
| 47 | return 48 << 10; |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 48 | 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. */ |
| 69 | u32 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älkki | dcb688e | 2013-09-04 01:11:16 +0300 | [diff] [blame] | 89 | unsigned long get_top_of_ram(void) |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 90 | { |
Kyösti Mälkki | 3f9a62e | 2013-06-20 20:25:21 +0300 | [diff] [blame] | 91 | const pci_devfn_t dev = PCI_DEV(0, 0, 0); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 92 | |
| 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 | } |