Kyösti Mälkki | cb08e16 | 2013-10-15 17:19:41 +0300 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2007-2009 coresystems GmbH |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Kyösti Mälkki | cb08e16 | 2013-10-15 17:19:41 +0300 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | // Use simple device model for this file even in ramstage |
| 17 | #define __SIMPLE_DEVICE__ |
| 18 | |
| 19 | #include <arch/io.h> |
| 20 | #include <cbmem.h> |
| 21 | #include "i945.h" |
Arthur Heymans | 874a8f9 | 2016-05-19 16:06:09 +0200 | [diff] [blame] | 22 | #include <console/console.h> |
Kyösti Mälkki | a4ffe9d | 2016-06-27 13:24:11 +0300 | [diff] [blame^] | 23 | #include <cpu/intel/romstage.h> |
Kyösti Mälkki | cb08e16 | 2013-10-15 17:19:41 +0300 | [diff] [blame] | 24 | |
Kyösti Mälkki | f1e3c76 | 2014-12-22 12:28:07 +0200 | [diff] [blame] | 25 | static uintptr_t smm_region_start(void) |
Kyösti Mälkki | cb08e16 | 2013-10-15 17:19:41 +0300 | [diff] [blame] | 26 | { |
Kyösti Mälkki | f1e3c76 | 2014-12-22 12:28:07 +0200 | [diff] [blame] | 27 | uintptr_t tom; |
Kyösti Mälkki | cb08e16 | 2013-10-15 17:19:41 +0300 | [diff] [blame] | 28 | |
Kyösti Mälkki | 3c3e34d | 2014-05-31 11:32:54 +0300 | [diff] [blame] | 29 | if (pci_read_config8(PCI_DEV(0, 0x0, 0), DEVEN) & (DEVEN_D2F0 | DEVEN_D2F1)) { |
Kyösti Mälkki | cb08e16 | 2013-10-15 17:19:41 +0300 | [diff] [blame] | 30 | /* IGD enabled, get top of Memory from BSM register */ |
Paul Menzel | 355ce38 | 2014-05-30 13:58:59 +0200 | [diff] [blame] | 31 | tom = pci_read_config32(PCI_DEV(0,2,0), BSM); |
Kyösti Mälkki | cb08e16 | 2013-10-15 17:19:41 +0300 | [diff] [blame] | 32 | } else { |
| 33 | tom = (pci_read_config8(PCI_DEV(0,0,0), TOLUD) & 0xf7) << 24; |
| 34 | } |
| 35 | |
| 36 | /* if TSEG enabled subtract size */ |
Kyösti Mälkki | fd2501b | 2014-05-31 16:36:29 +0300 | [diff] [blame] | 37 | switch(pci_read_config8(PCI_DEV(0, 0, 0), ESMRAM) & 0x07) { |
Kyösti Mälkki | cb08e16 | 2013-10-15 17:19:41 +0300 | [diff] [blame] | 38 | case 0x01: |
| 39 | /* 1MB TSEG */ |
Kyösti Mälkki | fd2501b | 2014-05-31 16:36:29 +0300 | [diff] [blame] | 40 | tom -= 0x100000; |
Kyösti Mälkki | cb08e16 | 2013-10-15 17:19:41 +0300 | [diff] [blame] | 41 | break; |
| 42 | case 0x03: |
| 43 | /* 2MB TSEG */ |
Kyösti Mälkki | fd2501b | 2014-05-31 16:36:29 +0300 | [diff] [blame] | 44 | tom -= 0x200000; |
Kyösti Mälkki | cb08e16 | 2013-10-15 17:19:41 +0300 | [diff] [blame] | 45 | break; |
| 46 | case 0x05: |
| 47 | /* 8MB TSEG */ |
Kyösti Mälkki | fd2501b | 2014-05-31 16:36:29 +0300 | [diff] [blame] | 48 | tom -= 0x800000; |
Kyösti Mälkki | cb08e16 | 2013-10-15 17:19:41 +0300 | [diff] [blame] | 49 | break; |
| 50 | default: |
| 51 | /* TSEG either disabled or invalid */ |
| 52 | break; |
| 53 | } |
Kyösti Mälkki | f1e3c76 | 2014-12-22 12:28:07 +0200 | [diff] [blame] | 54 | return tom; |
| 55 | } |
| 56 | |
| 57 | void *cbmem_top(void) |
| 58 | { |
| 59 | return (void *) smm_region_start(); |
Kyösti Mälkki | cb08e16 | 2013-10-15 17:19:41 +0300 | [diff] [blame] | 60 | } |
Arthur Heymans | 874a8f9 | 2016-05-19 16:06:09 +0200 | [diff] [blame] | 61 | |
| 62 | /** Decodes used Graphics Mode Select (GMS) to kilobytes. */ |
| 63 | u32 decode_igd_memory_size(const u32 gms) |
| 64 | { |
| 65 | static const u16 ggc2uma[] = { 0, 1, 4, 8, 16, 32, |
| 66 | 48, 64 }; |
| 67 | |
| 68 | if (gms > ARRAY_SIZE(ggc2uma)) |
| 69 | die("Bad Graphics Mode Select (GMS) setting.\n"); |
| 70 | |
| 71 | return ggc2uma[gms] << 10; |
| 72 | } |
Kyösti Mälkki | a4ffe9d | 2016-06-27 13:24:11 +0300 | [diff] [blame^] | 73 | |
| 74 | void *setup_stack_and_mtrrs(void) |
| 75 | { |
| 76 | return (void*)CONFIG_RAMTOP; |
| 77 | } |