Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2012 secunet Security Networks AG |
| 5 | * Copyright (C) 2015 Damien Zammit <damien@zamaudio.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License as |
| 9 | * published by the Free Software Foundation; version 2 of |
| 10 | * the License. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | */ |
| 17 | |
| 18 | #define __SIMPLE_DEVICE__ |
| 19 | |
Damien Zammit | 5680faf | 2016-01-22 22:12:30 +1100 | [diff] [blame] | 20 | #include <cbmem.h> |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 21 | #include <commonlib/helpers.h> |
| 22 | #include <stdint.h> |
| 23 | #include <arch/io.h> |
| 24 | #include <device/pci_def.h> |
| 25 | #include <console/console.h> |
Kyösti Mälkki | a4ffe9d | 2016-06-27 13:24:11 +0300 | [diff] [blame] | 26 | #include <cpu/intel/romstage.h> |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 27 | #include <northbridge/intel/x4x/x4x.h> |
| 28 | |
| 29 | /** Decodes used Graphics Mode Select (GMS) to kilobytes. */ |
| 30 | u32 decode_igd_memory_size(const u32 gms) |
| 31 | { |
Arthur Heymans | 27f94ee | 2016-06-18 21:08:58 +0200 | [diff] [blame] | 32 | static const u16 ggc2uma[] = { 0, 1, 4, 8, 16, |
Damien Zammit | 43a1f78 | 2015-08-19 15:16:59 +1000 | [diff] [blame] | 33 | 32, 48, 64, 128, 256, 96, 160, 224, 352 }; |
| 34 | |
| 35 | if (gms > ARRAY_SIZE(ggc2uma)) |
| 36 | die("Bad Graphics Mode Select (GMS) setting.\n"); |
| 37 | |
| 38 | return ggc2uma[gms] << 10; |
| 39 | } |
| 40 | |
| 41 | /** Decodes used GTT Graphics Memory Size (GGMS) to kilobytes. */ |
| 42 | u32 decode_igd_gtt_size(const u32 gsm) |
| 43 | { |
| 44 | static const u8 ggc2gtt[] = { 0, 1, 0, 2, 0, 0, 0, 0, 0, 2, 3, 4}; |
| 45 | |
| 46 | if (gsm > ARRAY_SIZE(ggc2gtt)) |
| 47 | die("Bad GTT Graphics Memory Size (GGMS) setting.\n"); |
| 48 | |
| 49 | return ggc2gtt[gsm] << 10; |
| 50 | } |
| 51 | |
| 52 | u8 decode_pciebar(u32 *const base, u32 *const len) |
| 53 | { |
| 54 | *base = 0; |
| 55 | *len = 0; |
| 56 | const pci_devfn_t dev = PCI_DEV(0,0,0); |
| 57 | u32 pciexbar = 0; |
| 58 | u32 pciexbar_reg; |
| 59 | u32 reg32; |
| 60 | int max_buses; |
| 61 | const struct { |
| 62 | u16 num_buses; |
| 63 | u32 addr_mask; |
| 64 | } busmask[] = { |
| 65 | {256, 0xf0000000}, |
| 66 | {128, 0xf8000000}, |
| 67 | {64, 0xfc000000}, |
| 68 | {0, 0}, |
| 69 | }; |
| 70 | |
| 71 | pciexbar_reg = pci_read_config32(dev, D0F0_PCIEXBAR_LO); |
| 72 | |
| 73 | if (!(pciexbar_reg & 1)) { |
| 74 | printk(BIOS_WARNING, "WARNING: MMCONF not set\n"); |
| 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | reg32 = (pciexbar_reg >> 1) & 3; |
| 79 | pciexbar = pciexbar_reg & busmask[reg32].addr_mask; |
| 80 | max_buses = busmask[reg32].num_buses; |
| 81 | |
| 82 | if (!pciexbar) { |
| 83 | printk(BIOS_WARNING, "WARNING: pciexbar invalid\n"); |
| 84 | return 0; |
| 85 | } |
| 86 | |
| 87 | *base = pciexbar; |
| 88 | *len = max_buses << 20; |
| 89 | return 1; |
| 90 | } |
Damien Zammit | 5680faf | 2016-01-22 22:12:30 +1100 | [diff] [blame] | 91 | |
Kyösti Mälkki | 811932a | 2016-07-22 22:53:19 +0300 | [diff] [blame^] | 92 | /* Depending of UMA and TSEG configuration, TSEG might start at any |
| 93 | * 1 MiB aligment. As this may cause very greedy MTRR setup, push |
| 94 | * CBMEM top downwards to 4 MiB boundary. |
| 95 | */ |
Damien Zammit | 5680faf | 2016-01-22 22:12:30 +1100 | [diff] [blame] | 96 | void *cbmem_top(void) |
| 97 | { |
Kyösti Mälkki | 811932a | 2016-07-22 22:53:19 +0300 | [diff] [blame^] | 98 | uintptr_t top_of_ram = pci_read_config32(PCI_DEV(0,0,0), D0F0_TSEG); |
| 99 | top_of_ram = ALIGN_DOWN(top_of_ram, 4*MiB); |
| 100 | return (void *) top_of_ram; |
Damien Zammit | 5680faf | 2016-01-22 22:12:30 +1100 | [diff] [blame] | 101 | } |
Kyösti Mälkki | a4ffe9d | 2016-06-27 13:24:11 +0300 | [diff] [blame] | 102 | |
| 103 | void *setup_stack_and_mtrrs(void) |
| 104 | { |
| 105 | return (void*)CONFIG_RAMTOP; |
| 106 | } |