• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <acpi/acpigen.h>
4 #include <amdblocks/alib.h>
5 #include <amdblocks/data_fabric.h>
6 #include <amdblocks/ioapic.h>
7 #include <amdblocks/root_complex.h>
8 #include <arch/ioapic.h>
9 #include <device/device.h>
10 #include <device/pci.h>
11 #include <stdint.h>
12 #include <soc/iomap.h>
13 #include "chip.h"
14 
15 #define DPTC_TOTAL_UPDATE_PARAMS	4
16 
17 struct dptc_input {
18 	uint16_t size;
19 	struct alib_dptc_param params[DPTC_TOTAL_UPDATE_PARAMS];
20 } __packed;
21 
22 #define DPTC_INPUTS(_thermctllmit, _sustained, _fast, _slow)			\
23 	{									\
24 		.size = sizeof(struct dptc_input),				\
25 		.params = {							\
26 			{							\
27 				.id = ALIB_DPTC_THERMAL_CONTROL_LIMIT_ID,	\
28 				.value = _thermctllmit,				\
29 			},							\
30 			{							\
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 	}
44 
acipgen_dptci(void)45 static void acipgen_dptci(void)
46 {
47 	const struct soc_amd_picasso_config *config = config_of_soc();
48 
49 	/* Normal mode DPTC values. */
50 	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);
54 	acpigen_write_alib_dptc_default((uint8_t *)&default_input, sizeof(default_input));
55 
56 	/* Tablet Mode */
57 	struct dptc_input tablet_mode_input = DPTC_INPUTS(
58 					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);
62 	acpigen_write_alib_dptc_tablet((uint8_t *)&tablet_mode_input,
63 		sizeof(tablet_mode_input));
64 }
65 
root_complex_fill_ssdt(const struct device * device)66 static void root_complex_fill_ssdt(const struct device *device)
67 {
68 	if (CONFIG(SOC_AMD_COMMON_BLOCK_ACPI_DPTC))
69 		acipgen_dptci();
70 }
71 
gnb_acpi_name(const struct device * dev)72 static const char *gnb_acpi_name(const struct device *dev)
73 {
74 	return "GNB";
75 }
76 
77 struct device_operations picasso_root_complex_operations = {
78 	/* 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,
81 	.set_resources		= noop_set_resources,
82 	.enable_resources	= pci_dev_enable_resources,
83 	.acpi_name		= gnb_acpi_name,
84 	.acpi_fill_ssdt		= root_complex_fill_ssdt,
85 };
86 
get_iohc_misc_smn_base(struct device * domain)87 uint32_t get_iohc_misc_smn_base(struct device *domain)
88 {
89 	return SMN_IOHC_MISC_BASE_13B1;
90 }
91 
92 static 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 
get_iohc_non_pci_mmio_regs(size_t * count)105 const 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 }
110 
get_iohc_fabric_id(struct device * domain)111 signed 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 }
120