blob: a3ae8c38bf23ea5c013e5e50cbf79f524b3f857e [file] [log] [blame]
Angel Pons0612b272020-04-05 15:46:56 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Subrata Banik01ae11b2017-03-04 23:32:41 +05302
3#ifndef SOC_INTEL_COMMON_BLOCK_SA_H
4#define SOC_INTEL_COMMON_BLOCK_SA_H
5
Subrata Banik7609c652017-05-19 14:50:09 +05306#include <device/device.h>
7#include <soc/iomap.h>
Subrata Banikb6df6b02020-01-03 15:29:02 +05308#include <soc/nvs.h>
Subrata Banik7609c652017-05-19 14:50:09 +05309#include <stddef.h>
10
Subrata Banik01ae11b2017-03-04 23:32:41 +053011/* Device 0:0.0 PCI configuration space */
Subrata Banik7609c652017-05-19 14:50:09 +053012#define MCHBAR 0x48
Subrata Banike9fd5622024-02-08 01:01:14 +053013#define GGC 0x50 /* GMCH Graphics Control Register */
14#define G_GMS_OFFSET 0x8
15#define G_GMS_MASK 0xff00
16#define G_GGMS_OFFSET 0x6
17#define G_GGMS_MASK 0xc0
18#define DPR 0x5C /* DMA Protected Range Register */
19#define PCIEXBAR 0x60
20#define TOUUD 0xa8 /* Top of Upper Usable DRAM */
21#define BDSM 0xb0 /* Base Data Stolen Memory */
22#define BGSM 0xb4 /* Base GTT Stolen Memory */
23#define TSEG 0xb8 /* TSEG base */
24#define TOLUD 0xbc /* Top of Low Used Memory */
Subrata Banik01ae11b2017-03-04 23:32:41 +053025
Eran Mitrani400c3002022-05-25 16:29:19 -070026/* PCIEXBAR register fields */
27#define PCIEXBAR_LENGTH_4096MB 6
28#define PCIEXBAR_LENGTH_2048MB 5
29#define PCIEXBAR_LENGTH_1024MB 4
30#define PCIEXBAR_LENGTH_512MB 3
31#define PCIEXBAR_LENGTH_64MB 2
32#define PCIEXBAR_LENGTH_128MB 1
33#define PCIEXBAR_LENGTH_256MB 0
34#define PCIEXBAR_PCIEXBAREN (1 << 0)
35
Subrata Banik7609c652017-05-19 14:50:09 +053036/* MCHBAR */
Patrick Rudolph4d4953b2021-01-04 09:04:22 +010037#define MCHBAR8(x) (*(volatile u8 *)(uintptr_t)(MCH_BASE_ADDRESS + x))
38#define MCHBAR16(x) (*(volatile u16 *)(uintptr_t)(MCH_BASE_ADDRESS + x))
39#define MCHBAR32(x) (*(volatile u32 *)(uintptr_t)(MCH_BASE_ADDRESS + x))
40#define MCHBAR64(x) (*(volatile u64 *)(uintptr_t)(MCH_BASE_ADDRESS + x))
Subrata Banik01ae11b2017-03-04 23:32:41 +053041
Tim Wawrzynczak5b90c0f2021-03-22 10:34:46 -060042/* REGBAR */
43#define REGBAR_OFFSET(pid, x) (REG_BASE_ADDRESS + ((pid) << 16) + (x))
44#define REGBAR8(pid, x) (*(volatile u8 *)(uintptr_t)REGBAR_OFFSET(pid, x))
45#define REGBAR16(pid, x) (*(volatile u16 *)(uintptr_t)REGBAR_OFFSET(pid, x))
46#define REGBAR32(pid, x) (*(volatile u32 *)(uintptr_t)REGBAR_OFFSET(pid, x))
47#define REGBAR64(pid, x) (*(volatile u64 *)(uintptr_t)REGBAR_OFFSET(pid, x))
48
Subrata Banik7609c652017-05-19 14:50:09 +053049/* Perform System Agent Initialization during Bootblock phase */
Subrata Banik01ae11b2017-03-04 23:32:41 +053050void bootblock_systemagent_early_init(void);
51
Subrata Banik7609c652017-05-19 14:50:09 +053052/*
53 * Fixed MMIO range
54 * INDEX = Either PCI configuration space registers or MMIO offsets
55 * mapped from REG.
Subrata Banikf8d9a132020-01-21 14:28:26 +053056 * BASE = 64 bit Address.
Subrata Banik41aab352020-04-13 12:23:07 +053057 * SIZE = 64 bit base length
Subrata Banik7609c652017-05-19 14:50:09 +053058 * DESCRIPTION = Name of the register/offset.
59 */
60struct sa_mmio_descriptor {
61 unsigned int index;
Subrata Banikf8d9a132020-01-21 14:28:26 +053062 uint64_t base;
Subrata Banik41aab352020-04-13 12:23:07 +053063 uint64_t size;
Subrata Banik7609c652017-05-19 14:50:09 +053064 const char *description;
65};
66
Jonathan Neuschäfer5268b762018-02-12 12:24:25 +010067/* API to set Fixed MMIO address into PCI configuration space */
Subrata Banik7609c652017-05-19 14:50:09 +053068void sa_set_pci_bar(const struct sa_mmio_descriptor *fixed_set_resources,
69 size_t count);
Jonathan Neuschäfer5268b762018-02-12 12:24:25 +010070/* API to set Fixed MMIO address into MCH base address */
Subrata Banik7609c652017-05-19 14:50:09 +053071void sa_set_mch_bar(const struct sa_mmio_descriptor *fixed_set_resources,
72 size_t count);
73/*
74 * API to program fixed mmio resource range based on SoC input
75 * struct sa_mmio_descriptor
76 */
77void sa_add_fixed_mmio_resources(struct device *dev, int *resource_cnt,
78 const struct sa_mmio_descriptor *sa_fixed_resources, size_t count);
79/*
80 * API to set BIOS Reset CPL through MCHBAR
81 * SoC to provide BIOS_RESET_CPL register offset through soc/systemagent.h
82 */
83void enable_bios_reset_cpl(void);
Jonathan Neuschäfer5268b762018-02-12 12:24:25 +010084/* API to enable PAM registers */
Subrata Banik7609c652017-05-19 14:50:09 +053085void enable_pam_region(void);
86/* API to enable Power Aware Interrupt Routing through MCHBAR */
87void enable_power_aware_intr(void);
Subrata Banikbd6ac222017-08-21 16:42:15 +053088/* API to get TOLUD base address */
Subrata Banik73f448f2017-08-29 18:51:14 +053089uintptr_t sa_get_tolud_base(void);
Matt DeVilliercbe73ea2018-06-25 14:40:53 -050090/* API to get GSM base address */
91uintptr_t sa_get_gsm_base(void);
Subrata Banik73f448f2017-08-29 18:51:14 +053092/* API to get TSEG base address */
93uintptr_t sa_get_tseg_base(void);
94/* API to get TSEG size */
95size_t sa_get_tseg_size(void);
Tim Wawrzynczakd87af792021-08-24 09:20:14 -060096/* API to lock PAM registers */
97void sa_lock_pam(void);
Subrata Banik8b532042024-02-08 00:14:26 +053098/* API to get MMIO config size */
99uint64_t sa_get_mmcfg_size(void);
100/* API to get DSM size */
101uint64_t sa_get_dsm_size(void);
102/* API to get GSM size */
103uint64_t sa_get_gsm_size(void);
104/* API to get DPR size */
105uint64_t sa_get_dpr_size(void);
Tim Wawrzynczakd87af792021-08-24 09:20:14 -0600106
Subrata Banik7609c652017-05-19 14:50:09 +0530107/*
108 * SoC overrides
109 *
110 * All new SoC must implement below functionality for ramstage.
111 */
112
113/* Perform System Agent Initialization during Ramstage phase */
114void soc_systemagent_init(struct device *dev);
115/*
116 * SoC call to provide all known fixed memory ranges for Device 0:0.0.
117 * SoC function should provide fixed resource ranges in form of
118 * struct sa_mmio_descriptor along with resource count.
119 */
120void soc_add_fixed_mmio_resources(struct device *dev, int *resource_cnt);
121
Eran Mitrani400c3002022-05-25 16:29:19 -0700122/*
123 * SoC call to provide all known configurable memory ranges for Device 0:0.0.
124 * SoC function should provide configurable resource ranges in form of
125 * struct sa_mmio_descriptor along with resource count.
126 */
127void soc_add_configurable_mmio_resources(struct device *dev, int *resource_cnt);
128
Pratik Prajapati82cdfa72017-08-28 14:48:55 -0700129/* SoC specific APIs to get UNCORE PRMRR base and mask values
130 * returns 0, if able to get base and mask values; otherwise returns -1 */
131int soc_get_uncore_prmmr_base_and_mask(uint64_t *base, uint64_t *mask);
Patrick Rudolphbf72dcb2020-05-12 16:04:47 +0200132
133/* Returns the maximum supported capacity of a channel as encoded by DDRSZ in MiB */
134uint32_t soc_systemagent_max_chan_capacity_mib(u8 capid0_a_ddrsz);
135
Arthur Heymans08769c62022-05-09 14:33:15 +0200136/* To be called in the acpi_fill_ssdt op of the domain */
137void ssdt_set_above_4g_pci(const struct device *dev);
138
Subrata Banik01ae11b2017-03-04 23:32:41 +0530139#endif /* SOC_INTEL_COMMON_BLOCK_SA_H */