| 1 |
|
| 2 |
|
| 3 |
#include <amdblocks/pci_clk_req.h> |
| 4 |
#include <console/console.h> |
| 5 |
#include <device/device.h> |
| 6 |
#include <device/pci.h> |
| 7 |
#include <device/pci_ids.h> |
| 8 |
#include <soc/platform_descriptors.h> |
| 9 |
|
| 10 |
|
| 11 |
void pcie_gpp_dxio_update_clk_req_config(enum gpp_clk_req *gpp_clk_config, |
| 12 |
size_t gpp_clk_config_num) |
| 13 |
{ |
| 14 |
const fsp_dxio_descriptor *dxio_descs = NULL; |
| 15 |
const fsp_ddi_descriptor *ddi_descs = NULL; |
| 16 |
size_t dxio_num = 0; |
| 17 |
size_t ddi_num = 0; |
| 18 |
|
| 19 |
mainboard_get_dxio_ddi_descriptors(&dxio_descs, &dxio_num, &ddi_descs, &ddi_num); |
| 20 |
if (dxio_descs == NULL) { |
| 21 |
printk(BIOS_WARNING, |
| 22 |
"No DXIO descriptors found, GPP clk req may not reflect enabled devices\n"); |
| 23 |
return; |
| 24 |
} |
| 25 |
|
| 26 |
for (int i = 0; i < dxio_num; i++) { |
| 27 |
const fsp_dxio_descriptor *dxio_desc = &dxio_descs[i]; |
| 28 |
|
| 29 |
|
| 30 |
if (dxio_desc->engine_type != PCIE_ENGINE |
| 31 |
&& dxio_desc->engine_type != UNUSED_ENGINE) |
| 32 |
continue; |
| 33 |
enum cpm_clk_req dxio_clk_req = dxio_desc->clk_req; |
| 34 |
|
| 35 |
|
| 36 |
if (dxio_clk_req == CLK_DISABLE) |
| 37 |
continue; |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
if (dxio_clk_req == (CLK_ENABLE & 0xF)) { |
| 47 |
printk(BIOS_WARNING, |
| 48 |
"CLK_ENABLE is an invalid clk_req value for PCIe device %d.%d, DXIO descriptor %d\n", |
| 49 |
dxio_desc->device_number, dxio_desc->function_number, i); |
| 50 |
continue; |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
int gpp_req_index = dxio_clk_req - CLK_REQ0; |
| 55 |
|
| 56 |
if (gpp_req_index < 0 || gpp_req_index >= gpp_clk_config_num) { |
| 57 |
printk(BIOS_ERR, |
| 58 |
"Failed to convert DXIO clk req value %d to GPP clk req index for PCIe device %d.%d, DXIO descriptor %d, clk req settings may be incorrect\n", |
| 59 |
dxio_clk_req, dxio_desc->device_number, |
| 60 |
dxio_desc->function_number, i); |
| 61 |
continue; |
| 62 |
} |
| 63 |
|
| 64 |
const struct device *pci_device = pcidev_path_on_root( |
| 65 |
PCI_DEVFN(dxio_desc->device_number, dxio_desc->function_number)); |
| 66 |
if (pci_device == NULL) { |
| 67 |
gpp_clk_config[gpp_req_index] = GPP_CLK_OFF; |
| 68 |
printk(BIOS_WARNING, |
| 69 |
"Cannot find PCIe device %d.%d, disabling GPP clk req %d, DXIO descriptor %d\n", |
| 70 |
dxio_desc->device_number, dxio_desc->function_number, i, |
| 71 |
gpp_req_index); |
| 72 |
continue; |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
u32 id = pci_read_config32(pci_device, PCI_VENDOR_ID); |
| 80 |
bool enabled = pci_device->enabled && (id != 0xffffffff) && (id != 0x00000000) |
| 81 |
&& (id != 0x0000ffff) && (id != 0xffff0000); |
| 82 |
|
| 83 |
|
| 84 |
if (!enabled && gpp_clk_config[gpp_req_index] != GPP_CLK_OFF) { |
| 85 |
gpp_clk_config[gpp_req_index] = GPP_CLK_OFF; |
| 86 |
printk(BIOS_INFO, |
| 87 |
"PCIe device %d.%d disabled, disabling GPP clk req %d, DXIO descriptor %d\n", |
| 88 |
dxio_desc->device_number, dxio_desc->function_number, |
| 89 |
gpp_req_index, i); |
| 90 |
} else if (enabled && gpp_clk_config[gpp_req_index] == GPP_CLK_OFF) { |
| 91 |
printk(BIOS_INFO, |
| 92 |
"PCIe device %d.%d enabled, GPP clk req is off, DXIO descriptor %d\n", |
| 93 |
dxio_desc->device_number, dxio_desc->function_number, i); |
| 94 |
} |
| 95 |
} |
| 96 |
} |