blob: 17df42dea9dc3266ad64b372304079737cbcbfa6 [file] [log] [blame]
Subrata Banik7609c652017-05-19 14:50:09 +05301/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2017 Intel Corporation.
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.
14 */
15
16#include <arch/io.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020017#include <device/pci_ops.h>
Subrata Banik7609c652017-05-19 14:50:09 +053018#include <delay.h>
19#include <device/device.h>
20#include <device/pci.h>
21#include <intelblocks/systemagent.h>
22#include <soc/iomap.h>
23#include <soc/pci_devs.h>
24#include <soc/systemagent.h>
25#include "systemagent_def.h"
26#include <timer.h>
27
28#if !ENV_RAMSTAGE
29void bootblock_systemagent_early_init(void)
30{
31 uint32_t reg;
32 uint8_t pciexbar_length;
33
34 /*
35 * The PCIEXBAR is assumed to live in the memory mapped IO space under
36 * 4GiB.
37 */
38 reg = 0;
39 pci_io_write_config32(SA_DEV_ROOT, PCIEXBAR + 4, reg);
40
41 /* Get PCI Express Region Length */
42 switch (CONFIG_SA_PCIEX_LENGTH) {
43 case 256 * MiB:
44 pciexbar_length = PCIEXBAR_LENGTH_256MB;
45 break;
46 case 128 * MiB:
47 pciexbar_length = PCIEXBAR_LENGTH_128MB;
48 break;
49 case 64 * MiB:
50 pciexbar_length = PCIEXBAR_LENGTH_64MB;
51 break;
52 default:
53 pciexbar_length = PCIEXBAR_LENGTH_256MB;
54 }
55 reg = CONFIG_MMCONF_BASE_ADDRESS | (pciexbar_length << 1)
56 | PCIEXBAR_PCIEXBAREN;
57 pci_io_write_config32(SA_DEV_ROOT, PCIEXBAR, reg);
58
59 /*
60 * TSEG defines the base of SMM range. BIOS determines the base
61 * of TSEG memory which must be at or below Graphics base of GTT
62 * Stolen memory, hence its better to clear TSEG register early
63 * to avoid power on default non-zero value (if any).
64 */
65 pci_write_config32(SA_DEV_ROOT, TSEG, 0);
66}
67#endif
68
69void sa_set_pci_bar(const struct sa_mmio_descriptor *fixed_set_resources,
70 size_t count)
71{
72 int i;
73
74 for (i = 0; i < count; i++) {
75 uintptr_t base;
76 unsigned int index;
77
78 index = fixed_set_resources[i].index;
79 /* Check if PCI BAR already enabled */
80 base = pci_read_config32(SA_DEV_ROOT, index);
81
82 /* If enabled don't program it. */
83 if (base & 0x1)
84 return;
85
86 base = fixed_set_resources[i].base;
87
88 pci_write_config32(SA_DEV_ROOT, index, base | 1);
89 }
90}
91
92/*
93 * There are special BARs that actually are programmed in the MCHBAR. These
94 * Intel special features, but they do consume resources that need to be
95 * accounted for.
96 */
97void sa_set_mch_bar(const struct sa_mmio_descriptor *fixed_set_resources,
98 size_t count)
99{
100 int i;
101
102 for (i = 0; i < count; i++) {
103 uintptr_t base;
104 unsigned int index;
105
106 base = fixed_set_resources[i].base;
107 index = fixed_set_resources[i].index;
108 write32((void *)(MCH_BASE_ADDRESS + index), base | 1);
109 }
110}
111
112void enable_pam_region(void)
113{
114 /* All read and writes in this region are serviced by DRAM */
115 pci_write_config8(SA_DEV_ROOT, PAM0, 0x30);
116 pci_write_config8(SA_DEV_ROOT, PAM1, 0x33);
117 pci_write_config8(SA_DEV_ROOT, PAM2, 0x33);
118 pci_write_config8(SA_DEV_ROOT, PAM3, 0x33);
119 pci_write_config8(SA_DEV_ROOT, PAM4, 0x33);
120 pci_write_config8(SA_DEV_ROOT, PAM5, 0x33);
121 pci_write_config8(SA_DEV_ROOT, PAM6, 0x33);
122}
123
124void enable_bios_reset_cpl(void)
125{
126 u8 bios_reset_cpl;
127
128 /*
129 * Set bits 0+1 of BIOS_RESET_CPL to indicate to the CPU
130 * that BIOS has initialized memory and power management
131 */
132 bios_reset_cpl = MCHBAR8(BIOS_RESET_CPL);
133 bios_reset_cpl |= 3;
134 MCHBAR8(BIOS_RESET_CPL) = bios_reset_cpl;
135}
Subrata Banikbd6ac222017-08-21 16:42:15 +0530136
Subrata Banik73f448f2017-08-29 18:51:14 +0530137uintptr_t sa_get_tolud_base(void)
Subrata Banikbd6ac222017-08-21 16:42:15 +0530138{
139 /* All regions concerned for have 1 MiB alignment. */
140 return ALIGN_DOWN(pci_read_config32(SA_DEV_ROOT, TOLUD), 1*MiB);
141}
142
143static uint16_t sa_get_ggc_reg(void)
144{
145 return pci_read_config16(SA_DEV_ROOT, GGC);
146}
147
Subrata Banik445368c2018-04-02 11:34:59 +0530148/*
149 * Internal Graphics Pre-allocated Memory - As per Intel FSP UPD Header
150 * definition, size of memory preallocatred for internal graphics can be
151 * configured based on below lists:
152 *
153 * 0x00:0MB, 0x01:32MB, 0x02:64MB, 0x03:96MB, 0x04:128MB, 0x05:160MB,
154 * 0xF0:4MB, 0xF1:8MB, 0xF2:12MB, 0xF3:16MB, 0xF4:20MB, 0xF5:24MB, 0xF6:28MB,
155 * 0xF7:32MB, 0xF8:36MB, 0xF9:40MB, 0xFA:44MB, 0xFB:48MB, 0xFC:52MB, 0xFD:56MB,
156 * 0xFE:60MB
157 *
158 * Today all existing SoCs(except Cannonlake) are supported under intel
159 * common code block design may not need to use any other values than 0x0-0x05
160 * for GFX DSM range. DSM memory ranges between 0xF0-0xF6 are majorly for
161 * early SoC samples and validation requirement. This code block to justify
162 * all differnet possible ranges that FSP may support for a platform.
163 */
Subrata Banikbd6ac222017-08-21 16:42:15 +0530164size_t sa_get_dsm_size(void)
165{
Subrata Banik445368c2018-04-02 11:34:59 +0530166 uint32_t prealloc_memory;
167 uint16_t ggc;
168
169 ggc = sa_get_ggc_reg();
170 prealloc_memory = (ggc & G_GMS_MASK) >> G_GMS_OFFSET;
171
172 if (prealloc_memory < 0xF0)
173 return prealloc_memory * 32*MiB;
174 else
175 return (prealloc_memory - 0xEF) * 4*MiB;
Subrata Banikbd6ac222017-08-21 16:42:15 +0530176}
177
Matt DeVilliercbe73ea2018-06-25 14:40:53 -0500178uintptr_t sa_get_gsm_base(void)
Subrata Banik73f448f2017-08-29 18:51:14 +0530179{
180 /* All regions concerned for have 1 MiB alignment. */
181 return ALIGN_DOWN(pci_read_config32(SA_DEV_ROOT, BGSM), 1*MiB);
182}
183
Subrata Banikbd6ac222017-08-21 16:42:15 +0530184size_t sa_get_gsm_size(void)
185{
186 uint8_t ggms;
187
188 ggms = (sa_get_ggc_reg() & G_GGMS_MASK) >> G_GGMS_OFFSET;
189
190 /*
191 * Size of GSM: 0x0: No Preallocated Memory 0x1: 2MB Memory
192 * 0x2: 4MB Memory 0x3: 8MB Memory
193 */
194 if (ggms)
195 return 1*MiB << ggms;
196 else
197 return 0;
198}
199
Subrata Banik73f448f2017-08-29 18:51:14 +0530200uintptr_t sa_get_tseg_base(void)
201{
202 /* All regions concerned for have 1 MiB alignment. */
203 return ALIGN_DOWN(pci_read_config32(SA_DEV_ROOT, TSEG), 1*MiB);
204}
205
206size_t sa_get_tseg_size(void)
207{
208 return sa_get_gsm_base() - sa_get_tseg_base();
209}
210
Subrata Banikbd6ac222017-08-21 16:42:15 +0530211/*
212 * Get DPR size in case CONFIG_SA_ENABLE_DPR is selected by SoC.
213 */
214size_t sa_get_dpr_size(void)
215{
216 uintptr_t dpr_reg;
217 size_t size = 0;
218 /*
219 * DMA Protected Range can be reserved below TSEG for PCODE patch
220 * or TXT/BootGuard related data. Rather than report a base address
221 * the DPR register reports the TOP of the region, which is the same
222 * as TSEG base. The region size is reported in MiB in bits 11:4.
223 */
224 dpr_reg = pci_read_config32(SA_DEV_ROOT, DPR);
225 if (dpr_reg & DPR_EPM)
226 size = (dpr_reg & DPR_SIZE_MASK) << 16;
227
228 return size;
229}