blob: 2a5d7e57528b3fdd06898144f0201080f9a53439 [file] [log] [blame]
Damien Zammit43a1f782015-08-19 15:16:59 +10001/*
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 Zammit5680faf2016-01-22 22:12:30 +110020#include <cbmem.h>
Damien Zammit43a1f782015-08-19 15:16:59 +100021#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älkkia4ffe9d2016-06-27 13:24:11 +030026#include <cpu/intel/romstage.h>
Damien Zammit43a1f782015-08-19 15:16:59 +100027#include <northbridge/intel/x4x/x4x.h>
28
29/** Decodes used Graphics Mode Select (GMS) to kilobytes. */
30u32 decode_igd_memory_size(const u32 gms)
31{
Arthur Heymans27f94ee2016-06-18 21:08:58 +020032 static const u16 ggc2uma[] = { 0, 1, 4, 8, 16,
Damien Zammit43a1f782015-08-19 15:16:59 +100033 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. */
42u32 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
52u8 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 Zammit5680faf2016-01-22 22:12:30 +110091
Kyösti Mälkki811932a2016-07-22 22:53:19 +030092/* 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 Zammit5680faf2016-01-22 22:12:30 +110096void *cbmem_top(void)
97{
Kyösti Mälkki811932a2016-07-22 22:53:19 +030098 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 Zammit5680faf2016-01-22 22:12:30 +1100101}
Kyösti Mälkkia4ffe9d2016-06-27 13:24:11 +0300102
103void *setup_stack_and_mtrrs(void)
104{
105 return (void*)CONFIG_RAMTOP;
106}