coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
acpi.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <acpi/acpi.h>
4 #include <acpi/acpi_gnvs.h>
5 #include <acpi/acpigen.h>
6 #include <arch/smp/mpspec.h>
7 #include <console/console.h>
8 #include <device/mmio.h>
9 #include <device/pci_ops.h>
10 #include <intelblocks/cpulib.h>
11 #include <intelblocks/pmclib.h>
12 #include <intelblocks/acpi.h>
13 #include <intelblocks/p2sb.h>
14 #include <soc/cpu.h>
15 #include <soc/iomap.h>
16 #include <soc/nvs.h>
17 #include <soc/pci_devs.h>
18 #include <soc/pm.h>
19 #include <soc/systemagent.h>
20 
21 #include "chip.h"
22 
23 /*
24  * List of supported C-states in this processor.
25  */
26 enum {
27  C_STATE_C0, /* 0 */
28  C_STATE_C1, /* 1 */
29  C_STATE_C1E, /* 2 */
36  C_STATE_C8, /* 9 */
37  C_STATE_C9, /* 10 */
38  C_STATE_C10, /* 11 */
40 };
41 
43  [C_STATE_C0] = {},
44  [C_STATE_C1] = {
45  .latency = 0,
46  .power = C1_POWER,
47  .resource = MWAIT_RES(0, 0),
48  },
49  [C_STATE_C1E] = {
50  .latency = 0,
51  .power = C1_POWER,
52  .resource = MWAIT_RES(0, 1),
53  },
55  .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
56  .power = C6_POWER,
57  .resource = MWAIT_RES(2, 0),
58  },
60  .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
61  .power = C6_POWER,
62  .resource = MWAIT_RES(2, 1),
63  },
65  .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
66  .power = C7_POWER,
67  .resource = MWAIT_RES(3, 0),
68  },
70  .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
71  .power = C7_POWER,
72  .resource = MWAIT_RES(3, 1),
73  },
75  .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
76  .power = C7_POWER,
77  .resource = MWAIT_RES(3, 2),
78  },
80  .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
81  .power = C7_POWER,
82  .resource = MWAIT_RES(3, 3),
83  },
84  [C_STATE_C8] = {
85  .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
86  .power = C8_POWER,
87  .resource = MWAIT_RES(4, 0),
88  },
89  [C_STATE_C9] = {
90  .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
91  .power = C9_POWER,
92  .resource = MWAIT_RES(5, 0),
93  },
94  [C_STATE_C10] = {
95  .latency = C_STATE_LATENCY_FROM_LAT_REG(0),
96  .power = C10_POWER,
97  .resource = MWAIT_RES(6, 0),
98  },
99 };
100 
101 static int cstate_set_non_s0ix[] = {
102  C_STATE_C1E,
105 };
106 
107 static int cstate_set_s0ix[] = {
108  C_STATE_C1E,
111 };
112 
113 const acpi_cstate_t *soc_get_cstate_map(size_t *entries)
114 {
117  int *set;
118  int i;
119 
121 
122  int is_s0ix_enable = config->s0ix_enable;
123 
124  if (is_s0ix_enable) {
125  *entries = ARRAY_SIZE(cstate_set_s0ix);
126  set = cstate_set_s0ix;
127  } else {
128  *entries = ARRAY_SIZE(cstate_set_non_s0ix);
129  set = cstate_set_non_s0ix;
130  }
131 
132  for (i = 0; i < *entries; i++) {
133  map[i] = cstate_map[set[i]];
134  map[i].ctype = i + 1;
135  }
136  return map;
137 }
138 
139 void soc_power_states_generation(int core_id, int cores_per_package)
140 {
142 
143  /* Generate P-state tables */
144  if (config->eist_enable)
145  generate_p_state_entries(core_id, cores_per_package);
146 }
147 
149 {
151  const struct soc_intel_cannonlake_config *config;
152  config = config_of_soc();
153 
154  fadt->pm_tmr_blk = pmbase + PM1_TMR;
155  fadt->pm_tmr_len = 4;
157  fadt->x_pm_tmr_blk.bit_width = fadt->pm_tmr_len * 8;
158  fadt->x_pm_tmr_blk.bit_offset = 0;
160  fadt->x_pm_tmr_blk.addrl = pmbase + PM1_TMR;
161  fadt->x_pm_tmr_blk.addrh = 0x0;
162 
163  if (config->s0ix_enable)
165 }
167 {
168  return read32p(soc_read_pmc_base() + IRQ_REG);
169 }
170 
172 {
173  const struct soc_intel_cannonlake_config *config;
174  config = config_of_soc();
175 
176  /* Enable DPTF based on mainboard configuration */
177  gnvs->dpte = config->dptf_enable;
178 
179  /* Set USB2/USB3 wake enable bitmaps. */
180  gnvs->u2we = config->usb2_wake_enable_bitmap;
181  gnvs->u3we = config->usb3_wake_enable_bitmap;
182 
183  /* Fill in Above 4GB MMIO resource */
185 }
186 
188 {
189  return MP_IRQ_POLARITY_HIGH;
190 }
191 
192 static unsigned long soc_fill_dmar(unsigned long current)
193 {
194  struct device *const igfx_dev = pcidev_path_on_root(SA_DEVFN_IGD);
195  uint64_t gfxvtbar = MCHBAR64(GFXVTBAR) & VTBAR_MASK;
196  bool gfxvten = MCHBAR32(GFXVTBAR) & VTBAR_ENABLED;
197  const bool emit_igd = igfx_dev && igfx_dev->enabled && gfxvtbar && gfxvten;
198  if (emit_igd) {
199  unsigned long tmp = current;
200 
201  current += acpi_create_dmar_drhd(current, 0, 0, gfxvtbar);
202  current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
203 
204  acpi_dmar_drhd_fixup(tmp, current);
205  }
206 
207  struct device *const ipu_dev = pcidev_path_on_root(SA_DEVFN_IPU);
208  uint64_t ipuvtbar = MCHBAR64(IPUVTBAR) & VTBAR_MASK;
209  bool ipuvten = MCHBAR32(IPUVTBAR) & VTBAR_ENABLED;
210 
211  if (ipu_dev && ipu_dev->enabled && ipuvtbar && ipuvten) {
212  unsigned long tmp = current;
213 
214  current += acpi_create_dmar_drhd(current, 0, 0, ipuvtbar);
215  current += acpi_create_dmar_ds_pci(current, 0, 5, 0);
216 
217  acpi_dmar_drhd_fixup(tmp, current);
218  }
219 
220  uint64_t vtvc0bar = MCHBAR64(VTVC0BAR) & VTBAR_MASK;
221  bool vtvc0en = MCHBAR32(VTVC0BAR) & VTBAR_ENABLED;
222 
223  if (vtvc0bar && vtvc0en) {
224  const unsigned long tmp = current;
225 
226  current += acpi_create_dmar_drhd(current,
227  DRHD_INCLUDE_PCI_ALL, 0, vtvc0bar);
228  current += acpi_create_dmar_ds_ioapic(current,
231  current += acpi_create_dmar_ds_msi_hpet(current,
234 
235  acpi_dmar_drhd_fixup(tmp, current);
236  }
237 
238  /* Add RMRR entry after all DRHD entries */
239  if (emit_igd) {
240  const unsigned long tmp = current;
241 
242  current += acpi_create_dmar_rmrr(current, 0,
244  current += acpi_create_dmar_ds_pci(current, 0, 2, 0);
245  acpi_dmar_rmrr_fixup(tmp, current);
246  }
247 
248  return current;
249 }
250 
251 unsigned long sa_write_acpi_tables(const struct device *dev, unsigned long current,
252  struct acpi_rsdp *rsdp)
253 {
254  acpi_dmar_t *const dmar = (acpi_dmar_t *)current;
255 
256  /* Create DMAR table only if we have VT-d capability
257  * and FSP does not override its feature.
258  */
259  if ((pci_read_config32(dev, CAPID0_A) & VTD_DISABLE) ||
261  return current;
262 
263  printk(BIOS_DEBUG, "ACPI: * DMAR\n");
265 
266  current += dmar->header.length;
267  current = acpi_align_current(current);
268  acpi_add_table(rsdp, dmar);
269 
270  return current;
271 }
unsigned long acpi_create_dmar_ds_ioapic(unsigned long current, u8 enumeration_id, u8 bus, u8 dev, u8 fn)
Definition: acpi.c:775
unsigned long acpi_create_dmar_rmrr(unsigned long current, u16 segment, u64 bar, u64 limit)
Definition: acpi.c:652
__weak void soc_fill_fadt(acpi_fadt_t *fadt)
Definition: acpi.c:1483
void acpi_dmar_drhd_fixup(unsigned long base, unsigned long current)
Definition: acpi.c:719
void acpi_add_table(acpi_rsdp_t *rsdp, void *table)
Add an ACPI table to the RSDT (and XSDT) structure, recalculate length and checksum.
Definition: acpi.c:49
unsigned long acpi_create_dmar_ds_msi_hpet(unsigned long current, u8 enumeration_id, u8 bus, u8 dev, u8 fn)
Definition: acpi.c:782
unsigned long acpi_create_dmar_ds_pci(unsigned long current, u8 bus, u8 dev, u8 fn)
Definition: acpi.c:768
void acpi_create_dmar(acpi_dmar_t *dmar, enum dmar_flags flags, unsigned long(*acpi_fill_dmar)(unsigned long))
Definition: acpi.c:607
void acpi_dmar_rmrr_fixup(unsigned long base, unsigned long current)
Definition: acpi.c:725
unsigned long acpi_create_dmar_drhd(unsigned long current, u8 flags, u16 segment, u64 bar)
Definition: acpi.c:638
#define PM1_TMR
Definition: pm.h:31
#define VTBAR_ENABLED
Definition: systemagent.h:38
#define V_P2SB_CFG_IBDF_BUS
Definition: systemagent.h:51
#define V_P2SB_CFG_IBDF_FUNC
Definition: systemagent.h:53
#define V_P2SB_CFG_HBDF_FUNC
Definition: systemagent.h:56
#define VTBAR_MASK
Definition: systemagent.h:39
#define IPUVTBAR
Definition: systemagent.h:33
#define V_P2SB_CFG_IBDF_DEV
Definition: systemagent.h:52
#define V_P2SB_CFG_HBDF_DEV
Definition: systemagent.h:55
#define V_P2SB_CFG_HBDF_BUS
Definition: systemagent.h:54
#define ARRAY_SIZE(a)
Definition: helpers.h:12
#define MAX(a, b)
Definition: helpers.h:40
#define MCHBAR32(x)
Definition: systemagent.h:23
void sa_fill_gnvs(struct global_nvs *gnvs)
Definition: systemagent.c:140
#define MCHBAR64(x)
Definition: systemagent.h:24
uintptr_t sa_get_tolud_base(void)
uintptr_t sa_get_gsm_base(void)
#define printk(level,...)
Definition: stdlib.h:16
#define MWAIT_RES(state, sub_state)
Definition: acpi.c:17
#define C_STATE_LATENCY_FROM_LAT_REG(reg)
Definition: haswell.h:119
DEVTREE_CONST struct device * pcidev_path_on_root(pci_devfn_t devfn)
Definition: device_const.c:255
#define CAPID0_A
Definition: host_bridge.h:65
#define VTD_DISABLE
Definition: host_bridge.h:67
#define VTVC0BAR
Definition: mchbar.h:20
#define GFXVTBAR
Definition: mchbar.h:18
static uintptr_t acpi_align_current(uintptr_t current)
Definition: acpi.h:1435
@ DRHD_INCLUDE_PCI_ALL
Definition: acpi.h:515
@ DMAR_INTR_REMAP
Definition: acpi.h:523
#define ACPI_ACCESS_SIZE_DWORD_ACCESS
Definition: acpi.h:129
#define ACPI_FADT_LOW_PWR_IDLE_S0
Definition: acpi.h:814
#define ACPI_ADDRESS_SPACE_IO
Definition: acpi.h:105
#define config_of_soc()
Definition: device.h:394
static __always_inline uint32_t read32p(const uintptr_t addr)
Definition: mmio.h:220
static __always_inline u32 pci_read_config32(const struct device *dev, u16 reg)
Definition: pci_ops.h:58
#define ACPI_BASE_ADDRESS
Definition: iomap.h:99
#define IRQ_REG
Definition: pmc.h:142
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
enum board_config config
Definition: memory.c:448
#define MP_IRQ_POLARITY_HIGH
Definition: mpspec.h:124
struct global_nvs * gnvs
const acpi_cstate_t * soc_get_cstate_map(size_t *entries)
Definition: acpi.c:113
@ C_STATE_C0
Definition: acpi.c:27
@ C_STATE_C7S_LONG_LAT
Definition: acpi.c:35
@ C_STATE_C1E
Definition: acpi.c:29
@ C_STATE_C7S_SHORT_LAT
Definition: acpi.c:34
@ C_STATE_C7_LONG_LAT
Definition: acpi.c:33
@ C_STATE_C6_LONG_LAT
Definition: acpi.c:31
@ C_STATE_C9
Definition: acpi.c:37
@ C_STATE_C10
Definition: acpi.c:38
@ C_STATE_C7_SHORT_LAT
Definition: acpi.c:32
@ C_STATE_C1
Definition: acpi.c:28
@ C_STATE_C8
Definition: acpi.c:36
@ NUM_C_STATES
Definition: acpi.c:39
@ C_STATE_C6_SHORT_LAT
Definition: acpi.c:30
unsigned long sa_write_acpi_tables(const struct device *dev, unsigned long current, struct acpi_rsdp *rsdp)
Definition: acpi.c:245
int soc_madt_sci_irq_polarity(int sci)
Definition: acpi.c:282
void soc_power_states_generation(int core_id, int cores_per_package)
Definition: acpi.c:139
void soc_fill_gnvs(struct global_nvs *gnvs)
Definition: acpi.c:267
uint32_t soc_read_sci_irq_select(void)
Definition: acpi.c:167
#define C7_POWER
Definition: cpu.h:17
#define C1_POWER
Definition: cpu.h:15
#define C6_POWER
Definition: cpu.h:16
#define C9_POWER
Definition: cpu.h:19
#define C10_POWER
Definition: cpu.h:20
#define C8_POWER
Definition: cpu.h:18
#define SA_DEVFN_IPU
Definition: pci_devs.h:40
#define SA_DEVFN_IGD
Definition: pci_devs.h:32
uintptr_t soc_read_pmc_base(void)
Definition: pmutil.c:147
static unsigned long soc_fill_dmar(unsigned long current)
Definition: acpi.c:192
static int cstate_set_non_s0ix[]
Definition: acpi.c:101
static int cstate_set_s0ix[]
Definition: acpi.c:107
static const acpi_cstate_t cstate_map[NUM_C_STATES]
Definition: acpi.c:42
void generate_p_state_entries(int core, int cores_per_package)
Definition: acpi.c:259
static u16 pmbase
Definition: smi.c:27
unsigned short uint16_t
Definition: stdint.h:11
unsigned int uint32_t
Definition: stdint.h:14
unsigned long long uint64_t
Definition: stdint.h:17
u8 ctype
Definition: acpi.h:984
u16 latency
Definition: acpi.h:985
acpi_header_t header
Definition: acpi.h:580
u32 pm_tmr_blk
Definition: acpi.h:724
u8 pm_tmr_len
Definition: acpi.h:730
u32 flags
Definition: acpi.h:746
acpi_addr_t x_pm_tmr_blk
Definition: acpi.h:760
u8 bit_offset
Definition: acpi.h:98
u8 bit_width
Definition: acpi.h:97
u8 access_size
Definition: acpi.h:99
Definition: acpi.h:82
Definition: device.h:107
unsigned int enabled
Definition: device.h:122
Definition: nvs.h:14
u16 u2we
Definition: nvs.h:24
u16 u3we
Definition: nvs.h:25
uint8_t dpte
Definition: nvs.h:20