1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 #include <acpi/acpigen.h>
4 #include <acpi/acpigen_pci.h>
6 #include <device/pci_ops.h>
7 #include <intelblocks/acpi.h>
8 #include <soc/chip_common.h>
9 #include <soc/pci_devs.h>
11 #include <southbridge/intel/common/acpi_pirq_gen.h>
20 * List of supported C-states in this processor.
30 static const acpi_cstate_t cstate_map
[NUM_C_STATES
] = {
35 .resource
= MWAIT_RES(0, 0),
41 .resource
= MWAIT_RES(1, 0),
47 .resource
= MWAIT_RES(2, 0),
53 .resource
= MWAIT_RES(3, 0),
57 /* Max states supported */
58 static int cstate_set_all
[] = {
65 static int cstate_set_c1_c6
[] = {
70 const acpi_cstate_t
*soc_get_cstate_map(size_t *entries
)
72 static acpi_cstate_t map
[ARRAY_SIZE(cstate_set_all
)];
76 const config_t
*config
= config_of_soc();
78 const enum acpi_cstate_mode states
= config
->cstate_states
;
82 *entries
= ARRAY_SIZE(cstate_set_c1_c6
);
83 cstate_set
= cstate_set_c1_c6
;
87 *entries
= ARRAY_SIZE(cstate_set_all
);
88 cstate_set
= cstate_set_all
;
92 for (i
= 0; i
< *entries
; i
++) {
93 map
[i
] = cstate_map
[cstate_set
[i
]];
99 void iio_domain_set_acpi_name(struct device
*dev
, const char *prefix
)
101 const union xeon_domain_path dn
= {
102 .domain_path
= dev_get_domain_id(dev
)
105 assert(dn
.socket
< 8);
106 assert(dn
.stack
< 32);
107 assert(prefix
!= NULL
&& strlen(prefix
) == 2);
109 if (dn
.socket
>= 8 || dn
.stack
>= 32 ||
110 !prefix
|| strlen(prefix
) != 2)
113 char *name
= xmalloc(ACPI_NAME_BUFFER_SIZE
);
114 snprintf(name
, ACPI_NAME_BUFFER_SIZE
, "%s%02X", prefix
, ((dn
.socket
<< 5) + dn
.stack
));
118 const char *soc_acpi_name(const struct device
*dev
)
120 if (dev
->path
.type
== DEVICE_PATH_DOMAIN
)
123 /* FIXME: Add SoC specific device names here */
128 void acpigen_write_OSC_pci_domain_fixed_caps(const struct device
*domain
,
129 const uint32_t granted_pcie_features
,
130 const bool is_cxl_domain
,
131 const uint32_t granted_cxl_features
)
133 acpigen_write_method("_OSC", 4);
135 acpigen_write_return_namestr("\\_SB.POSC");
136 acpigen_emit_byte(ARG0_OP
);
137 acpigen_emit_byte(ARG1_OP
);
138 acpigen_emit_byte(ARG2_OP
);
139 acpigen_emit_byte(ARG3_OP
);
140 acpigen_write_integer(granted_pcie_features
);
141 acpigen_write_integer(is_cxl_domain
);
142 acpigen_write_integer(granted_cxl_features
);
147 static bool read_physical_slot_number(const struct device
*dev
, uint8_t *psn
)
152 const size_t pos
= pci_find_capability(dev
, PCI_CAP_ID_PCIE
);
156 u32 sltcap
= pci_read_config32(dev
, pos
+ PCI_EXP_SLTCAP
);
157 *psn
= ((sltcap
>> 19) & 0x1FF);
161 static void acpigen_write_pci_root_port_devices(const struct device
*rp
)
164 bool have_psn
= read_physical_slot_number(rp
, &psn
);
166 struct device
*dev
= NULL
;
167 while ((dev
= dev_bus_each_child(rp
->downstream
, dev
))) {
170 const char *name
= acpi_device_name(dev
);
173 acpigen_write_device(name
);
174 acpigen_write_ADR_pci_device(dev
);
176 acpigen_write_name_integer("_SUN", psn
);
181 void acpigen_write_pci_root_port(const struct device
*rp
)
183 const char *acpi_scope
= acpi_device_scope(rp
);
186 acpigen_write_scope(acpi_scope
);
188 const char *acpi_name
= acpi_device_name(rp
);
191 acpigen_write_device(acpi_name
);
192 acpigen_write_ADR_pci_device(rp
);
193 acpigen_write_pci_root_port_devices(rp
);
199 void acpigen_write_PRT_pre_routed(const struct device
*br
)
202 uint32_t routed_dev_bitmap
= 0;
205 if (!is_pci_bridge(br
))
208 const char *acpi_scope
= acpi_device_path(br
);
212 acpigen_write_scope(acpi_scope
);
213 acpigen_write_name("_PRT");
214 entry_count
= acpigen_write_package(0);
216 struct device
*dev
= NULL
;
217 while ((dev
= dev_bus_each_child(br
->downstream
, dev
))) {
220 dev_num
= PCI_SLOT(dev
->path
.pci
.devfn
);
221 if (routed_dev_bitmap
& (1 << dev_num
))
224 uint8_t int_line
= pci_read_config8(dev
, PCI_INTERRUPT_LINE
);
225 uint8_t int_pin
= pci_read_config8(dev
, PCI_INTERRUPT_PIN
);
226 if ((int_pin
> PCI_INT_MAX
) || (int_pin
< PCI_INT_A
))
229 acpigen_write_PRT_GSI_entry(dev_num
, int_pin
- PCI_INT_A
, int_line
);
232 routed_dev_bitmap
|= (1 << dev_num
);