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. |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 15 | */ |
| 16 | |
Kyösti Mälkki | ef84401 | 2013-06-25 23:17:43 +0300 | [diff] [blame] | 17 | // Use simple device model for this file even in ramstage |
| 18 | #define __SIMPLE_DEVICE__ |
| 19 | |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 20 | #include <stdint.h> |
| 21 | #include <arch/io.h> |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 22 | #include <device/pci_def.h> |
| 23 | #include <console/console.h> |
Kyösti Mälkki | a4ffe9d | 2016-06-27 13:24:11 +0300 | [diff] [blame] | 24 | #include <cpu/intel/romstage.h> |
Kyösti Mälkki | dcb688e | 2013-09-04 01:11:16 +0300 | [diff] [blame] | 25 | #include <cbmem.h> |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 26 | #include "gm45.h" |
| 27 | |
Arthur Heymans | eeaf9e4 | 2016-11-12 20:13:07 +0100 | [diff] [blame] | 28 | /* |
| 29 | * Decodes used Graphics Mode Select (GMS) to kilobytes. |
| 30 | * The options for 1M, 4M, 8M and 16M preallocated igd memory are |
| 31 | * undocumented but are verified to work. |
| 32 | */ |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 33 | u32 decode_igd_memory_size(const u32 gms) |
| 34 | { |
Arthur Heymans | eeaf9e4 | 2016-11-12 20:13:07 +0100 | [diff] [blame] | 35 | static const u16 ggc2uma[] = { 0, 1, 4, 8, 16, 32, 48, 64, 128, 256, |
| 36 | 96, 160, 224, 352 }; |
| 37 | |
| 38 | if (gms > ARRAY_SIZE(ggc2uma)) |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 39 | die("Bad Graphics Mode Select (GMS) setting.\n"); |
Arthur Heymans | eeaf9e4 | 2016-11-12 20:13:07 +0100 | [diff] [blame] | 40 | |
| 41 | return ggc2uma[gms] << 10; |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | /** Decodes used Graphics Stolen Memory (GSM) to kilobytes. */ |
| 45 | u32 decode_igd_gtt_size(const u32 gsm) |
| 46 | { |
| 47 | switch (gsm) { |
| 48 | case 0: |
| 49 | return 0 << 10; |
| 50 | case 1: |
| 51 | return 1 << 10; |
| 52 | case 3: |
| 53 | case 9: |
| 54 | return 2 << 10; |
| 55 | case 10: |
| 56 | return 3 << 10; |
| 57 | case 11: |
| 58 | return 4 << 10; |
| 59 | default: |
| 60 | die("Bad Graphics Stolen Memory (GSM) setting.\n"); |
| 61 | return 0; |
| 62 | } |
| 63 | } |
| 64 | |
Kyösti Mälkki | f1e3c76 | 2014-12-22 12:28:07 +0200 | [diff] [blame] | 65 | static uintptr_t smm_region_start(void) |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 66 | { |
Kyösti Mälkki | 3f9a62e | 2013-06-20 20:25:21 +0300 | [diff] [blame] | 67 | const pci_devfn_t dev = PCI_DEV(0, 0, 0); |
Patrick Georgi | 2efc880 | 2012-11-06 11:03:53 +0100 | [diff] [blame] | 68 | |
| 69 | u32 tor; |
| 70 | |
| 71 | /* Top of Lower Usable DRAM */ |
| 72 | tor = (pci_read_config16(dev, D0F0_TOLUD) & 0xfff0) << 16; |
| 73 | |
| 74 | /* Graphics memory comes next */ |
| 75 | const u32 ggc = pci_read_config16(dev, D0F0_GGC); |
| 76 | if (!(ggc & 2)) { |
| 77 | /* Graphics memory */ |
| 78 | tor -= decode_igd_memory_size((ggc >> 4) & 0xf) << 10; |
| 79 | /* GTT Graphics Stolen Memory Size (GGMS) */ |
| 80 | tor -= decode_igd_gtt_size((ggc >> 8) & 0xf) << 10; |
| 81 | } |
| 82 | return tor; |
| 83 | } |
Kyösti Mälkki | f1e3c76 | 2014-12-22 12:28:07 +0200 | [diff] [blame] | 84 | |
| 85 | void *cbmem_top(void) |
| 86 | { |
| 87 | return (void *) smm_region_start(); |
| 88 | } |
Kyösti Mälkki | a4ffe9d | 2016-06-27 13:24:11 +0300 | [diff] [blame] | 89 | |
| 90 | void *setup_stack_and_mtrrs(void) |
| 91 | { |
| 92 | return (void*)CONFIG_RAMTOP; |
| 93 | } |