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>
18 * List of supported C-states in this processor.
28 static const acpi_cstate_t cstate_map
[NUM_C_STATES
] = {
33 .resource
= MWAIT_RES(0, 0),
39 .resource
= MWAIT_RES(1, 0),
45 .resource
= MWAIT_RES(2, 0),
51 .resource
= MWAIT_RES(3, 0),
55 /* Max states supported */
56 static int cstate_set_all
[] = {
63 static int cstate_set_c1_c6
[] = {
68 const acpi_cstate_t
*soc_get_cstate_map(size_t *entries
)
70 static acpi_cstate_t map
[ARRAY_SIZE(cstate_set_all
)];
74 const config_t
*config
= config_of_soc();
76 const enum acpi_cstate_mode states
= config
->cstate_states
;
80 *entries
= ARRAY_SIZE(cstate_set_c1_c6
);
81 cstate_set
= cstate_set_c1_c6
;
85 *entries
= ARRAY_SIZE(cstate_set_all
);
86 cstate_set
= cstate_set_all
;
90 for (i
= 0; i
< *entries
; i
++) {
91 map
[i
] = cstate_map
[cstate_set
[i
]];
97 void iio_domain_set_acpi_name(struct device
*dev
, const char *prefix
)
99 const union xeon_domain_path dn
= {
100 .domain_path
= dev_get_domain_id(dev
)
103 assert(dn
.socket
< CONFIG_MAX_SOCKET
);
104 assert(dn
.stack
< 16);
105 assert(prefix
!= NULL
&& strlen(prefix
) == 2);
107 if (dn
.socket
>= CONFIG_MAX_SOCKET
|| dn
.stack
>= 16 ||
108 !prefix
|| strlen(prefix
) != 2)
111 char *name
= xmalloc(ACPI_NAME_BUFFER_SIZE
);
112 snprintf(name
, ACPI_NAME_BUFFER_SIZE
, "%s%1X%1X", prefix
, dn
.socket
, dn
.stack
);
116 const char *soc_acpi_name(const struct device
*dev
)
118 if (dev
->path
.type
== DEVICE_PATH_DOMAIN
)
121 /* FIXME: Add SoC specific device names here */
126 void acpigen_write_OSC_pci_domain_fixed_caps(const struct device
*domain
,
127 const uint32_t granted_pcie_features
,
128 const bool is_cxl_domain
,
129 const uint32_t granted_cxl_features
)
131 acpigen_write_method("_OSC", 4);
133 acpigen_write_return_namestr("\\_SB.POSC");
134 acpigen_emit_byte(ARG0_OP
);
135 acpigen_emit_byte(ARG1_OP
);
136 acpigen_emit_byte(ARG2_OP
);
137 acpigen_emit_byte(ARG3_OP
);
138 acpigen_write_integer(granted_pcie_features
);
139 acpigen_write_integer(is_cxl_domain
);
140 acpigen_write_integer(granted_cxl_features
);
145 static bool read_physical_slot_number(const struct device
*dev
, uint8_t *psn
)
150 const size_t pos
= pci_find_capability(dev
, PCI_CAP_ID_PCIE
);
154 u32 sltcap
= pci_read_config32(dev
, pos
+ PCI_EXP_SLTCAP
);
155 *psn
= ((sltcap
>> 19) & 0x1FF);
159 static void acpigen_write_pci_root_port_devices(const struct device
*rp
)
162 bool have_psn
= read_physical_slot_number(rp
, &psn
);
164 struct device
*dev
= NULL
;
165 while ((dev
= dev_bus_each_child(rp
->downstream
, dev
))) {
168 const char *name
= acpi_device_name(dev
);
171 acpigen_write_device(name
);
172 acpigen_write_ADR_pci_device(dev
);
174 acpigen_write_name_integer("_SUN", psn
);
179 void acpigen_write_pci_root_port(const struct device
*rp
)
181 const char *acpi_scope
= acpi_device_scope(rp
);
184 acpigen_write_scope(acpi_scope
);
186 const char *acpi_name
= acpi_device_name(rp
);
189 acpigen_write_device(acpi_name
);
190 acpigen_write_ADR_pci_device(rp
);
191 acpigen_write_pci_root_port_devices(rp
);