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