Debian Codegraph @

src/vendorcode/amd/opensil/genoa_poc/mpio/chip.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <device/device.h>
4 #include <device/pci_def.h>
5 #include <Mpio/Common/MpioStructs.h>
6 #include <Mpio/MpioClass-api.h>
7 #include <NBIO/NbioClass-api.h>
8 #include <RcMgr/DfX/RcManager4-api.h>
9 #include <vendorcode/amd/opensil/opensil.h>
10 #include <xSIM-api.h>
11
12 #include "chip.h"
13
14 static void mpio_params_config(void)
15 {
16 MPIOCLASS_INPUT_BLK *mpio_data = SilFindStructure(SilId_MpioClass, 0);
17 mpio_data->CfgDxioClockGating = 1;
18 mpio_data->PcieDxioTimingControlEnable = 0;
19 mpio_data->PCIELinkReceiverDetectionPolling = 0;
20 mpio_data->PCIELinkResetToTrainingTime = 0;
21 mpio_data->PCIELinkL0Polling = 0;
22 mpio_data->PCIeExactMatchEnable = 0;
23 mpio_data->DxioPhyValid = 1;
24 mpio_data->DxioPhyProgramming = 1;
25 mpio_data->CfgSkipPspMessage = 1;
26 mpio_data->DxioSaveRestoreModes = 0xff;
27 mpio_data->AmdAllowCompliance = 0;
28 mpio_data->AmdAllowCompliance = 0xff;
29 mpio_data->SrisEnableMode = 0xff;
30 mpio_data->SrisSkipInterval = 0;
31 mpio_data->SrisSkpIntervalSel = 1;
32 mpio_data->SrisCfgType = 0;
33 mpio_data->SrisAutoDetectMode = 0xff;
34 mpio_data->SrisAutodetectFactor = 0;
35 mpio_data->SrisLowerSkpOsGenSup = 0;
36 mpio_data->SrisLowerSkpOsRcvSup = 0;
37 mpio_data->AmdCxlOnAllPorts = 1;
38 mpio_data->CxlCorrectableErrorLogging = 1;
39 mpio_data->CxlUnCorrectableErrorLogging = 1;
40 // This is also available in Nbio. How to handle duplicate entries?
41 mpio_data->CfgAEREnable = 1;
42 mpio_data->CfgMcCapEnable = 0;
43 mpio_data->CfgRcvErrEnable = 0;
44 mpio_data->EarlyBmcLinkTraining = 1;
45 mpio_data->SurpriseDownFeature = 1;
46 mpio_data->LcMultAutoSpdChgOnLastRateEnable = 0;
47 mpio_data->AmdRxMarginEnabled = 1;
48 mpio_data->CfgPcieCVTestWA = 1;
49 mpio_data->CfgPcieAriSupport = 1;
50 mpio_data->CfgNbioCTOtoSC = 0;
51 mpio_data->CfgNbioCTOIgnoreError = 1;
52 mpio_data->CfgNbioSsid = 0;
53 mpio_data->CfgIommuSsid = 0;
54 mpio_data->CfgPspccpSsid = 0;
55 mpio_data->CfgNtbccpSsid = 0;
56 mpio_data->CfgNbifF0Ssid = 0;
57 mpio_data->CfgNtbSsid = 0;
58 mpio_data->AmdPcieSubsystemDeviceID = 0x1453;
59 mpio_data->AmdPcieSubsystemVendorID = 0x1022;
60 mpio_data->GppAtomicOps = 1;
61 mpio_data->GfxAtomicOps = 1;
62 mpio_data->AmdNbioReportEdbErrors = 0;
63 mpio_data->OpnSpare = 0;
64 mpio_data->AmdPreSilCtrl0 = 0;
65 mpio_data->MPIOAncDataSupport = 1;
66 mpio_data->AfterResetDelay = 0;
67 mpio_data->CfgEarlyLink = 0;
68 mpio_data->AmdCfgExposeUnusedPciePorts = 1; // Show all ports
69 mpio_data->CfgForcePcieGenSpeed = 0;
70 mpio_data->CfgSataPhyTuning = 0;
71 mpio_data->PcieLinkComplianceModeAllPorts = 0;
72 mpio_data->AmdMCTPEnable = 0;
73 mpio_data->SbrBrokenLaneAvoidanceSup = 1;
74 mpio_data->AutoFullMarginSup = 1;
75 // A getter and setter, both are needed for this PCD.
76 mpio_data->AmdPciePresetMask8GtAllPort = 0xffffffff;
77 // A getter and setter, both are needed for this PCD.
78 mpio_data->AmdPciePresetMask16GtAllPort = 0xffffffff;
79 // A getter and setter, both are needed for this PCD.
80 mpio_data->AmdPciePresetMask32GtAllPort = 0xffffffff;
81 mpio_data->PcieLinkAspmAllPort = 0xff;
82
83 mpio_data->SyncHeaderByPass = 1;
84 mpio_data->CxlTempGen5AdvertAltPtcl = 0;
85
86 /* TODO handle this differently on multisocket */
87 mpio_data->PcieTopologyData.PlatformData[0].Flags = DESCRIPTOR_TERMINATE_LIST;
88 mpio_data->PcieTopologyData.PlatformData[0].PciePortList = mpio_data->PcieTopologyData.PortList;
89 }
90
91 static void nbio_params_config(void)
92 {
93 NBIOCLASS_DATA_BLOCK *nbio_data = SilFindStructure(SilId_NbioClass, 0);
94 NBIOCLASS_INPUT_BLK *input = &nbio_data->NbioInputBlk;
95 input->CfgHdAudioEnable = false;
96 input->EsmEnableAllRootPorts = false;
97 input->EsmTargetSpeed = 16;
98 input->CfgRxMarginPersistenceMode = 1;
99 input->CfgDxioFrequencyVetting = false;
100 input->CfgSkipPspMessage = 1;
101 input->CfgEarlyTrainTwoPcieLinks = false;
102 input->EarlyBmcLinkTraining = true;
103 input->EdpcEnable = 0;
104 input->PcieAerReportMechanism = 2;
105 input->SevSnpSupport = false;
106 }
107
108 static void setup_bmc_lanes(uint8_t lane, uint8_t socket)
109 {
110 DFX_RCMGR_INPUT_BLK *rc_mgr_input_block = SilFindStructure(SilId_RcManager, 0);
111 rc_mgr_input_block->BmcSocket = socket;
112 rc_mgr_input_block->EarlyBmcLinkLaneNum = lane;
113
114 NBIOCLASS_DATA_BLOCK *nbio_data = SilFindStructure(SilId_NbioClass, 0);
115 NBIOCLASS_INPUT_BLK *nbio_input = &nbio_data->NbioInputBlk;
116 nbio_input->EarlyBmcLinkSocket = socket;
117 nbio_input->EarlyBmcLinkLaneNum = lane;
118 nbio_input->EarlyBmcLinkDie = 0;
119
120 MPIOCLASS_INPUT_BLK *mpio_data = SilFindStructure(SilId_MpioClass, 0);
121 mpio_data->EarlyBmcLinkSocket = socket;
122 mpio_data->EarlyBmcLinkLaneNum = lane;
123 mpio_data->EarlyBmcLinkDie = 0;
124 }
125
126 void opensil_mpio_per_device_config(struct device *dev)
127 {
128 /* Cache *mpio_data from SilFindStructure */
129 static MPIOCLASS_INPUT_BLK *mpio_data = NULL;
130 if (mpio_data == NULL) {
131 mpio_data = SilFindStructure(SilId_MpioClass, 0);
132 }
133
134 static uint32_t slot_num;
135 const uint32_t domain = dev_get_domain_id(dev);
136 const uint32_t devfn = dev->path.pci.devfn;
137 const struct drivers_amd_opensil_mpio_config *const config = dev->chip_info;
138 printk(BIOS_DEBUG, "Setting MPIO port for domain 0x%x, PCI %d:%d\n",
139 domain, PCI_SLOT(devfn), PCI_FUNC(devfn));
140
141 if (config->type == IFTYPE_UNUSED) {
142 if (is_dev_enabled(dev)) {
143 printk(BIOS_WARNING, "Unused MPIO chip, disabling PCI device.\n");
144 dev->enabled = false;
145 } else {
146 printk(BIOS_DEBUG, "Unused MPIO chip, skipping.\n");
147 }
148 return;
149 }
150
151 if (config->bmc) {
152 setup_bmc_lanes(config->start_lane, 0); // TODO support multiple sockets
153 return;
154 }
155
156 static int mpio_port = 0;
157 MPIO_PORT_DESCRIPTOR port = { .Flags = DESCRIPTOR_TERMINATE_LIST };
158 if (config->type == IFTYPE_PCIE) {
159 const MPIO_ENGINE_DATA engine_data =
160 MPIO_ENGINE_DATA_INITIALIZER(MpioPcieEngine,
161 config->start_lane, config->end_lane,
162 config->hotplug == HotplugDisabled ? 0 : 1,
163 config->gpio_group);
164 port.EngineData = engine_data;
165 const MPIO_PORT_DATA port_data =
166 MPIO_PORT_DATA_INITIALIZER_PCIE(is_dev_enabled(dev) ?
167 MpioPortEnabled : MpioPortDisabled,
168 PCI_SLOT(devfn),
169 PCI_FUNC(devfn),
170 config->hotplug,
171 config->speed,
172 0, // No backup PCIe speed
173 config->aspm,
174 config->aspm_l1_1,
175 config->aspm_l1_2,
176 config->clock_pm);
177 port.Port = port_data;
178 } else if (config->type == IFTYPE_SATA) {
179 const MPIO_ENGINE_DATA engine_data =
180 MPIO_ENGINE_DATA_INITIALIZER(MpioSATAEngine,
181 config->start_lane, config->end_lane,
182 0, // meaningless field
183 config->gpio_group);
184 port.EngineData = engine_data;
185 const MPIO_PORT_DATA port_data = { .PortPresent = 1 };
186 port.Port = port_data;
187
188 }
189 port.Port.AlwaysExpose = 1;
190 port.Port.SlotNum = ++slot_num;
191 mpio_data->PcieTopologyData.PortList[mpio_port] = port;
192 /* Update TERMINATE list */
193 if (mpio_port > 0)
194 mpio_data->PcieTopologyData.PortList[mpio_port - 1].Flags = 0;
195 mpio_port++;
196 }
197
198 void opensil_mpio_global_config(void)
199 {
200 mpio_params_config();
201 nbio_params_config();
202 }