blob: dd39cb284bcb3f44c13a5fa8f524d0eaa129aaff [file] [log] [blame]
Marshall Dawsoneb724872019-07-16 15:46:35 -06001/* SPDX-License-Identifier: GPL-2.0-only */
2
3#include <acpi/acpigen.h>
Felix Held95f1bb82021-05-07 18:46:36 +02004#include <amdblocks/alib.h>
Arthur Heymansce179722023-06-07 15:27:18 +02005#include <amdblocks/data_fabric.h>
Felix Held604ffa62021-02-12 00:43:20 +01006#include <amdblocks/ioapic.h>
Felix Held43662b52023-07-18 20:36:34 +02007#include <amdblocks/root_complex.h>
Felix Heldf9608cd2020-12-03 16:57:02 +01008#include <arch/ioapic.h>
Marshall Dawsoneb724872019-07-16 15:46:35 -06009#include <device/device.h>
10#include <device/pci.h>
Marshall Dawsoneb724872019-07-16 15:46:35 -060011#include <stdint.h>
Marshall Dawson39c64b02020-09-04 12:07:27 -060012#include <soc/iomap.h>
Chris Wang4735b1c2020-07-13 23:29:29 +080013#include "chip.h"
Marshall Dawsoneb724872019-07-16 15:46:35 -060014
Felix Heldef511572021-05-07 19:02:45 +020015#define DPTC_TOTAL_UPDATE_PARAMS 4
16
Chris Wang4735b1c2020-07-13 23:29:29 +080017struct dptc_input {
18 uint16_t size;
Felix Heldf0610172021-05-07 19:21:08 +020019 struct alib_dptc_param params[DPTC_TOTAL_UPDATE_PARAMS];
Chris Wang4735b1c2020-07-13 23:29:29 +080020} __packed;
21
Kevin Chiucdd9f5c2020-09-18 17:30:30 +080022#define DPTC_INPUTS(_thermctllmit, _sustained, _fast, _slow) \
Felix Held3acafa22021-05-07 19:17:51 +020023 { \
24 .size = sizeof(struct dptc_input), \
25 .params = { \
26 { \
27 .id = ALIB_DPTC_THERMAL_CONTROL_LIMIT_ID, \
28 .value = _thermctllmit, \
Chris Wang4735b1c2020-07-13 23:29:29 +080029 }, \
Felix Held3acafa22021-05-07 19:17:51 +020030 { \
31 .id = ALIB_DPTC_SUSTAINED_POWER_LIMIT_ID, \
32 .value = _sustained, \
33 }, \
34 { \
35 .id = ALIB_DPTC_FAST_PPT_LIMIT_ID, \
36 .value = _fast, \
37 }, \
38 { \
39 .id = ALIB_DPTC_SLOW_PPT_LIMIT_ID, \
40 .value = _slow, \
41 }, \
42 }, \
43 }
Marshall Dawsoneb724872019-07-16 15:46:35 -060044
Chris Wang4735b1c2020-07-13 23:29:29 +080045static void acipgen_dptci(void)
46{
Felix Held507fc032020-12-05 01:55:27 +010047 const struct soc_amd_picasso_config *config = config_of_soc();
Chris Wang4735b1c2020-07-13 23:29:29 +080048
Tim Van Patten54ce4aa2022-09-13 14:37:32 -060049 /* Normal mode DPTC values. */
Zheng Bao795d73c2020-10-27 15:36:55 +080050 struct dptc_input default_input = DPTC_INPUTS(config->thermctl_limit_degreeC,
51 config->sustained_power_limit_mW,
52 config->fast_ppt_limit_mW,
53 config->slow_ppt_limit_mW);
Tim Van Patten92443582022-08-23 16:06:33 -060054 acpigen_write_alib_dptc_default((uint8_t *)&default_input, sizeof(default_input));
55
56 /* Tablet Mode */
Chris Wang4735b1c2020-07-13 23:29:29 +080057 struct dptc_input tablet_mode_input = DPTC_INPUTS(
Zheng Bao795d73c2020-10-27 15:36:55 +080058 config->thermctl_limit_tablet_mode_degreeC,
59 config->sustained_power_limit_tablet_mode_mW,
60 config->fast_ppt_limit_tablet_mode_mW,
61 config->slow_ppt_limit_tablet_mode_mW);
Tim Van Patten92443582022-08-23 16:06:33 -060062 acpigen_write_alib_dptc_tablet((uint8_t *)&tablet_mode_input,
63 sizeof(tablet_mode_input));
Chris Wang4735b1c2020-07-13 23:29:29 +080064}
65
Marshall Dawsoneb724872019-07-16 15:46:35 -060066static void root_complex_fill_ssdt(const struct device *device)
67{
Tim Van Patten54ce4aa2022-09-13 14:37:32 -060068 if (CONFIG(SOC_AMD_COMMON_BLOCK_ACPI_DPTC))
69 acipgen_dptci();
Marshall Dawsoneb724872019-07-16 15:46:35 -060070}
71
Felix Heldff092d42021-02-17 00:04:59 +010072static const char *gnb_acpi_name(const struct device *dev)
73{
74 return "GNB";
75}
76
Arthur Heymans826955d2022-09-20 17:26:30 +020077struct device_operations picasso_root_complex_operations = {
Felix Held30f36c32024-01-30 15:15:31 +010078 /* The root complex has no PCI BARs implemented, so there's no need to call
79 pci_dev_read_resources for it */
80 .read_resources = noop_read_resources,
Felix Held9541d172021-01-05 00:56:10 +010081 .set_resources = noop_set_resources,
Marshall Dawsoneb724872019-07-16 15:46:35 -060082 .enable_resources = pci_dev_enable_resources,
Felix Heldff092d42021-02-17 00:04:59 +010083 .acpi_name = gnb_acpi_name,
Marshall Dawsoneb724872019-07-16 15:46:35 -060084 .acpi_fill_ssdt = root_complex_fill_ssdt,
85};
Felix Held43662b52023-07-18 20:36:34 +020086
87uint32_t get_iohc_misc_smn_base(struct device *domain)
88{
Felix Held69ffebf2023-07-24 21:31:44 +020089 return SMN_IOHC_MISC_BASE_13B1;
Felix Held43662b52023-07-18 20:36:34 +020090}
91
92static const struct non_pci_mmio_reg non_pci_mmio[] = {
93 { 0x2e0, 0xfffffff00000ull, 1 * MiB, NON_PCI_RES_IDX_AUTO },
94 { 0x2e8, 0xfffffff00000ull, 1 * MiB, NON_PCI_RES_IDX_AUTO },
95 /* The hardware has a 256 byte alignment requirement for the IOAPIC MMIO base, but we
96 tell the FSP to configure a 4k-aligned base address and this is reported as 4 KiB
97 resource. */
98 { 0x2f0, 0xffffffffff00ull, 4 * KiB, IOMMU_IOAPIC_IDX },
99 { 0x2f8, 0xfffffff00000ull, 1 * MiB, NON_PCI_RES_IDX_AUTO },
100 { 0x300, 0xfffffff00000ull, 1 * MiB, NON_PCI_RES_IDX_AUTO },
101 { 0x308, 0xfffffffff000ull, 4 * KiB, NON_PCI_RES_IDX_AUTO },
102 { 0x318, 0xfffffff80000ull, 512 * KiB, NON_PCI_RES_IDX_AUTO },
103};
104
105const struct non_pci_mmio_reg *get_iohc_non_pci_mmio_regs(size_t *count)
106{
107 *count = ARRAY_SIZE(non_pci_mmio);
108 return non_pci_mmio;
109}
Felix Heldb0ab5452023-08-11 22:24:00 +0200110
111signed int get_iohc_fabric_id(struct device *domain)
112{
113 switch (domain->path.domain.domain) {
114 case 0:
115 return IOMS0_FABRIC_ID;
116 default:
117 return -1;
118 }
119}