2 * This file is part of the coreboot project.
4 * Copyright (C) 2010 Advanced Micro Devices, Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #include <console/console.h>
21 #include <device/device.h>
22 #include <device/pci.h>
23 #include <device/pci_ids.h>
24 #include <device/pci_ops.h>
29 /*------------------------------------------------
31 ------------------------------------------------*/
32 PCIE_CFG AtiPcieCfg = {
33 PCIE_ENABLE_STATIC_DEV_REMAP, /* Config */
34 0, /* ResetReleaseDelay */
39 0, /* PortDetect, filled by GppSbInit */
52 static void ValidatePortEn(device_t nb_dev);
54 static void ValidatePortEn(device_t nb_dev)
58 /*****************************************************************
59 * Compliant with CIM_33's PCIEPowerOffGppPorts
60 * Power off unused GPP lines
61 *****************************************************************/
62 static void PciePowerOffGppPorts(device_t nb_dev, device_t dev, u32 port)
66 struct southbridge_amd_sr5650_config *cfg =
67 (struct southbridge_amd_sr5650_config *)nb_dev->chip_info;
68 u16 state = cfg->port_enable;
70 if (!(AtiPcieCfg.Config & PCIE_DISABLE_HIDE_UNUSED_PORTS))
71 state &= AtiPcieCfg.PortDetect;
73 state &= (1 << 4) + (1 << 5) + (1 << 6) + (1 << 7);
74 state_save = state << 17;
75 state &= !(AtiPcieCfg.PortHp);
76 reg = nbmisc_read_index(nb_dev, 0x0c);
78 nbmisc_write_index(nb_dev, 0x0c, reg);
80 reg = nbmisc_read_index(nb_dev, 0x08);
82 nbmisc_write_index(nb_dev, 0x08, reg);
84 if ((AtiPcieCfg.Config & PCIE_OFF_UNUSED_GPP_LANES)
86 Config & (PCIE_DISABLE_HIDE_UNUSED_PORTS +
87 PCIE_GFX_COMPLIANCE))) {
89 /* step 3 Power Down Control for Southbridge */
90 reg = nbpcie_p_read_index(dev, 0xa2);
92 switch ((reg >> 4) & 0x7) { /* get bit 4-6, LC_LINK_WIDTH_RD */
94 nbpcie_ind_write_index(nb_dev, 0x65, 0x0e0e);
97 nbpcie_ind_write_index(nb_dev, 0x65, 0x0c0c);
104 /**********************************************************************
105 **********************************************************************/
106 static void switching_gpp1_configurations(device_t nb_dev, device_t sb_dev)
109 struct southbridge_amd_sr5650_config *cfg =
110 (struct southbridge_amd_sr5650_config *)nb_dev->chip_info;
112 /* 4.3.3.1.1.1.step1. Asserts PCIE-GPP1 global reset */
113 reg = nbmisc_read_index(nb_dev, 0x8);
115 nbmisc_write_index(nb_dev, 0x8, reg);
117 /* 4.3.3.1.1.1.step2. De-asserts STRAP_BIF_all_valid for PCIE-GPP1 core */
118 reg = nbmisc_read_index(nb_dev, 0x26);
120 nbmisc_write_index(nb_dev, 0x26, reg);
122 /* 4.3.3.1.1.1.step3. Programs PCIE-GPP1 to be desired port configuration 8:8 or 16:0. */
123 reg = nbmisc_read_index(nb_dev, 0x8);
124 reg &= ~(1 << 8); /* clean */
125 reg |= cfg->gpp1_configuration << 8;
126 nbmisc_write_index(nb_dev, 0x8, reg);
128 /* 4.3.3.1.1.1.step4. Wait for 2ms */
131 /* 4.3.3.1.1.1.step5. Asserts STRAP_BIF_all_valid for PCIE-GPP1 core */
132 reg = nbmisc_read_index(nb_dev, 0x26);
134 nbmisc_write_index(nb_dev, 0x26, reg);
136 /* 4.3.3.1.1.1.step6. De-asserts PCIE-GPP1 global reset */
137 reg = nbmisc_read_index(nb_dev, 0x8);
139 nbmisc_write_index(nb_dev, 0x8, reg);
141 /* Follow the procedure for PCIE-GPP1 common initialization and
142 * link training sequence. */
145 /**********************************************************************
146 **********************************************************************/
147 static void switching_gpp2_configurations(device_t nb_dev, device_t sb_dev)
150 struct southbridge_amd_sr5650_config *cfg =
151 (struct southbridge_amd_sr5650_config *)nb_dev->chip_info;
153 /* 4.3.3.1.1.2.step1. Asserts PCIE-GPP2 global reset */
154 reg = nbmisc_read_index(nb_dev, 0x8);
156 nbmisc_write_index(nb_dev, 0x8, reg);
158 /* 4.3.3.1.1.2.step2. De-asserts STRAP_BIF_all_valid for PCIE-GPP2 core */
159 reg = nbmisc_read_index(nb_dev, 0x26);
161 nbmisc_write_index(nb_dev, 0x26, reg);
163 /* 4.3.3.1.1.2.step3. Programs PCIE-GPP2 to be desired port configuration 8:8 or 16:0. */
164 reg = nbmisc_read_index(nb_dev, 0x8);
165 reg &= ~(1 << 9); /* clean */
166 reg |= (cfg->gpp2_configuration & 1) << 9;
167 nbmisc_write_index(nb_dev, 0x8, reg);
169 /* 4.3.3.1.1.2.step4. Wait for 2ms */
172 /* 4.3.3.1.1.2.step5. Asserts STRAP_BIF_all_valid for PCIE-GPP2 core */
173 reg = nbmisc_read_index(nb_dev, 0x26);
175 nbmisc_write_index(nb_dev, 0x26, reg);
177 /* 4.3.3.1.1.2.step6. De-asserts PCIE-GPP2 global reset */
178 reg = nbmisc_read_index(nb_dev, 0x8);
180 nbmisc_write_index(nb_dev, 0x8, reg);
182 /* Follow the procedure for PCIE-GPP2 common initialization and
183 * link training sequence. */
185 static void switching_gpp3a_configurations(device_t nb_dev, device_t sb_dev)
188 struct southbridge_amd_sr5650_config *cfg =
189 (struct southbridge_amd_sr5650_config *)nb_dev->chip_info;
191 /* 4.3.3.2.3.2.step1. Asserts PCIE-GPP3a global reset. */
192 reg = nbmisc_read_index(nb_dev, 0x8);
194 nbmisc_write_index(nb_dev, 0x8, reg);
195 /* 4.3.3.2.3.2.step2. De-asserts STRAP_BIF_all_valid for PCIE-GPP3a core */
196 reg = nbmisc_read_index(nb_dev, 0x26);
198 nbmisc_write_index(nb_dev, 0x26, reg);
199 /* 4.3.3.2.3.2.step3. Programs the desired PCIE-GPP3a configuration. */
200 reg = nbmisc_read_index(nb_dev, 0x67);
201 reg &= ~0x1F; /* clean */
202 reg |= cfg->gpp3a_configuration;
203 nbmisc_write_index(nb_dev, 0x67, reg);
204 /* 4.3.3.2.3.2.step4. Programs PCIE-GPP3a Line Director. */
205 reg = nbmisc_read_index(nb_dev, 0x26);
206 reg &= 0xF0000000; /* TODO:Lane reversed. */
207 switch (cfg->gpp3a_configuration) {
208 case 0xB: /* 1:1:1:1:1:1 */
211 case 0x1: /* 4:2:0:0:0:0 */
214 case 0x2: /* 4:1:1:0:0:0 */
217 case 0xC: /* 2:2:2:0:0:0 */
220 case 0xA: /* 2:2:1:1:0:0 */
223 case 0x4: /* 2:1:1:1:1:0 */
226 default: /* shouldn't be here. */
227 printk(BIOS_DEBUG, "Warning:gpp3a_configuration is not correct. Check you devicetree.cb\n");
230 nbmisc_write_index(nb_dev, 0x26, reg);
231 /* 4.3.3.2.3.2.step5. De-asserts STRAP_BIF_all_valid for PCIE-GPP3a core */
232 reg = nbmisc_read_index(nb_dev, 0x26);
234 nbmisc_write_index(nb_dev, 0x26, reg);
235 /* 4.3.3.2.3.2.step6. De-asserts PCIE-GPP3a global reset. */
236 reg = nbmisc_read_index(nb_dev, 0x8);
238 nbmisc_write_index(nb_dev, 0x8, reg);
241 /*****************************************************************
242 * The sr5650 uses NBCONFIG:0x1c (BAR3) to map the PCIE Extended Configuration
243 * Space to a 256MB range within the first 4GB of addressable memory.
244 *****************************************************************/
245 void enable_pcie_bar3(device_t nb_dev)
247 printk(BIOS_DEBUG, "enable_pcie_bar3()\n");
248 set_nbcfg_enable_bits(nb_dev, 0x7C, 1 << 30, 1 << 30); /* Enables writes to the BAR3 register. */
249 set_nbcfg_enable_bits(nb_dev, 0x84, 7 << 16, 0 << 16);
251 pci_write_config32(nb_dev, 0x1C, EXT_CONF_BASE_ADDRESS); /* PCIEMiscInit */
252 pci_write_config32(nb_dev, 0x20, 0x00000000);
253 set_htiu_enable_bits(nb_dev, 0x32, 1 << 28, 1 << 28); /* PCIEMiscInit */
254 ProgK8TempMmioBase(1, EXT_CONF_BASE_ADDRESS, TEMP_MMIO_BASE_ADDRESS);
257 /*****************************************************************
258 * We should disable bar3 when we want to exit sr5650_enable, because bar3 will be
259 * remapped in set_resource later.
260 *****************************************************************/
261 void disable_pcie_bar3(device_t nb_dev)
263 printk(BIOS_DEBUG, "disable_pcie_bar3()\n");
264 pci_write_config32(nb_dev, 0x1C, 0); /* clear BAR3 address */
265 set_nbcfg_enable_bits(nb_dev, 0x7C, 1 << 30, 0 << 30); /* Disable writes to the BAR3. */
266 ProgK8TempMmioBase(0, EXT_CONF_BASE_ADDRESS, TEMP_MMIO_BASE_ADDRESS);
271 void init_gen2(device_t nb_dev, device_t dev, u8 port)
274 /* for A11 (0x89 == 0) */
284 /* todo: check for rev > a11
316 set_pcie_enable_bits(dev, 0xA4, 0x1, 0x1);
317 pci_ext_write_config32(nb_dev, dev, 0x88, 0xF0, 1<<2); /* LINK_CRTL2*/
318 set_nbmisc_enable_bits(nb_dev, reg, val, val);
322 /* Alternative to default CPL buffer count */
323 const u8 pGpp420000[] = {0x38, 0x1C};
324 const u8 pGpp411000[] = {0x38, 0x0E, 0x0E};
325 const u8 pGpp222000[] = {0x1C, 0x1C, 0x1C};
326 const u8 pGpp221100[] = {0x1C, 0x1C, 0x0E, 0x0E};
327 const u8 pGpp211110[] = {0x1C, 0x0E, 0x0E, 0x0E, 0, 0x0E, 0x0E};
328 const u8 pGpp111111[] = {0x0E, 0x0E, 0x0E, 0x0E, 0, 0x0E, 0x0E};
331 * Enabling Dynamic Slave CPL Buffer Allocation Feature for PCIE-GPP3a Ports
332 * PcieLibCplBufferAllocation
334 static void gpp3a_cpl_buf_alloc(device_t nb_dev, device_t dev)
339 struct southbridge_amd_sr5650_config *cfg =
340 (struct southbridge_amd_sr5650_config *)nb_dev->chip_info;
342 dev_index = dev->path.pci.devfn >> 3;
343 if (dev_index < 4 || dev_index > 0xa) {
347 switch (cfg->gpp3a_configuration) {
348 case 0x1: /* 4:2:0:0:0:0 */
349 slave_cpl = (u8 *)&pGpp420000;
351 case 0x2: /* 4:1:1:0:0:0 */
352 slave_cpl = (u8 *)&pGpp411000;
354 case 0xC: /* 2:2:2:0:0:0 */
355 slave_cpl = (u8 *)&pGpp222000;
357 case 0xA: /* 2:2:1:1:0:0 */
358 slave_cpl = (u8 *)&pGpp221100;
360 case 0x4: /* 2:1:1:1:1:0 */
361 slave_cpl = (u8 *)&pGpp211110;
363 case 0xB: /* 1:1:1:1:1:1 */
364 slave_cpl = (u8 *)&pGpp111111;
366 default: /* shouldn't be here. */
367 printk(BIOS_DEBUG, "buggy gpp3a_configuration\n");
371 value = slave_cpl[dev_index - 4];
373 set_pcie_enable_bits(dev, 0x10, 0x3f << 8, value << 8);
374 set_pcie_enable_bits(dev, 0x20, 1 << 11, 1 << 11);
379 * Enabling Dynamic Slave CPL Buffer Allocation Feature for PCIE-GPP1/PCIE-GPP2 Ports
380 * PcieLibCplBufferAllocation
382 static void gpp12_cpl_buf_alloc(device_t nb_dev, device_t dev)
388 dev_index = dev->path.pci.devfn >> 3;
389 struct southbridge_amd_sr5650_config *cfg =
390 (struct southbridge_amd_sr5650_config *)nb_dev->chip_info;
393 gpp_cfg = cfg->gpp1_configuration;
394 } else if (dev_index > 0xa) {
395 gpp_cfg = cfg->gpp2_configuration;
401 /* Configuration 16:0, leave the default value */
402 } else if (gpp_cfg == 1) {
403 /* Configuration 8:8 */
405 set_pcie_enable_bits(dev, 0x10, 0x3f << 8, value << 8);
406 set_pcie_enable_bits(dev, 0x20, 1 << 11, 1 << 11);
408 printk(BIOS_DEBUG, "buggy gpp configuration\n");
412 #if 0 /* BTS report error without this function. But some board
413 * fail to boot. Leave it here for future debug. */
416 * Enable LCLK clock gating
418 static void EnableLclkGating(device_t dev)
424 device_t nb_dev = dev_find_slot(0, 0);
425 device_t clk_f1= dev_find_slot(0, 1);
427 port = dev->path.pci.devfn >> 3;
429 //PCIE_CORE_INDEX_GPP1
436 //PCIE_CORE_INDEX_GPP2
443 //PCIE_CORE_INDEX_GPP3a
451 //PCIE_CORE_INDEX_GPP3b;
457 //PCIE_CORE_INDEX_SB;
465 /* enable access func1 */
466 set_nbcfg_enable_bits(nb_dev, 0x4C, 1 << 0, 1 << 0);
467 set_nbcfg_enable_bits(clk_f1, reg, mask, value);
471 /*****************************************
472 * Compliant with CIM_33's PCIEGPPInit
478 * p2p bridge number, 4-10
479 *****************************************/
480 void sr5650_gpp_sb_init(device_t nb_dev, device_t dev, u32 port)
483 struct southbridge_amd_sr5650_config *cfg =
484 (struct southbridge_amd_sr5650_config *)nb_dev->chip_info;
486 printk(BIOS_DEBUG, "gpp_sb_init nb_dev=0x%p, dev=0x%p, port=0x%x\n", nb_dev, dev, port);
490 gpp_sb_sel = PCIE_CORE_INDEX_GPP1;
495 gpp_sb_sel = PCIE_CORE_INDEX_GPP3a;
498 gpp_sb_sel = PCIE_CORE_INDEX_SB;
502 gpp_sb_sel = PCIE_CORE_INDEX_GPP2;
505 gpp_sb_sel = PCIE_CORE_INDEX_GPP3b;
509 /* Init common Core registers */
510 set_pcie_enable_bits(dev, 0xB1, 1 << 28 | 1 << 23 | 1 << 20 | 1 << 19,
511 1 << 28 | 1 << 23 | 1 << 20 | 1 << 19);
512 if (gpp_sb_sel == PCIE_CORE_INDEX_GPP3a) {
513 set_pcie_enable_bits(dev, 0xB1, 1 << 22, 1 << 22);
514 /* 4.3.3.2.3 Step 10: Dynamic Slave CPL Buffer Allocation */
515 gpp3a_cpl_buf_alloc(nb_dev, dev);
517 if (gpp_sb_sel == PCIE_CORE_INDEX_GPP1 || gpp_sb_sel == PCIE_CORE_INDEX_GPP2) {
518 gpp12_cpl_buf_alloc(nb_dev, dev);
520 set_pcie_enable_bits(dev, 0xA1, (1 << 26) | (1 << 24) | (1 << 11), 1 << 11);
521 set_pcie_enable_bits(dev, 0xA0, 0x0000FFF0, 0x6830);
522 // PCIE should not ignore malformed packet error or ATS request
523 set_pcie_enable_bits(dev, 0x70, 1 << 12, 0);
524 //Step 14.1: Advertising Hot Plug Capabilities
525 set_pcie_enable_bits(dev, 0x10, 1 << 4, 1 << 4); //Enable power fault
527 set_pcie_enable_bits(nb_dev, 0xC1 | gpp_sb_sel, 1 << 0, 1 << 0);
530 /* 4.4.2.step13.1. Sets RCB completion timeout to be 200ms */
531 pci_ext_write_config32(nb_dev, dev, 0x80, 0xF << 0, 0x6 << 0);
532 /* 4.4.2.step13.2. RCB completion timeout on link down to shorten enumeration time. */
533 set_pcie_enable_bits(dev, 0x70, 1 << 19, 1 << 19);
534 /* 4.4.2.step13.3. Enable slave ordering rules */
535 set_pcie_enable_bits(nb_dev, 0x20 | gpp_sb_sel, 1 << 8, 0 << 8);
536 /* 4.4.2.step13.4. Sets DMA payload size to 64 bytes. */
537 set_pcie_enable_bits(nb_dev, 0x10 | gpp_sb_sel, 7 << 10, 4 << 10);
538 /* 4.4.2.step13.5. Set REGS_DLP_IGNORE_IN_L1_EN to ignore DLLPs
539 during L1 so that Tx Clk can be turned off. */
540 set_pcie_enable_bits(nb_dev, 0x02 | gpp_sb_sel, 1 << 0 | 1 << 8, 1 << 0 | 1 << 8); // add bit 8 from CIMx
541 /* 4.4.2.step13.6. Set REGS_LC_ALLOW_TX_L1_CONTROL to allow TX to
542 prevent LC from going to L1 when there are outstanding completions.*/
543 set_pcie_enable_bits(dev, 0x02, 1 << 15, 1 << 15);
544 /* 4.4.2.step13.7. Set REGS_LC_DONT_GO_TO_L0S_IF_L1_ARMED to prevent
545 lc to go to from L0 to Rcv_L0s if L1 is armed. */
546 set_pcie_enable_bits(dev, 0xA1, 1 << 11, 1 << 11);
547 /* 4.4.2.step13.8. CMGOOD_OVERRIDE for all five PCIe cores. */
548 set_nbmisc_enable_bits(nb_dev, 0x22, 1 << 27, 1 << 27);
549 /* 4.4.2.step13.9. Prevents Electrical Idle from causing a
550 transition from Rcv_L0 to Rcv_L0s. */
551 set_pcie_enable_bits(dev, 0xB1, 1 << 20, 1 << 20);
552 /* 4.4.2.step13.10. Prevents the LTSSM from going to Rcv_L0s if
553 it has already acknowledged a request to go
554 to L1 but it has not transitioned there yet. */
555 /* seems the same as step13.7 */
556 set_pcie_enable_bits(dev, 0xA1, 1 << 11, 1 << 11);
557 /* 4.4.2.step13.11. Transmits FTS before Recovery. */
558 set_pcie_enable_bits(dev, 0xA3, 1 << 9, 1 << 9);
559 /* 4.4.2.step13.12. Sets TX arbitration algorithm to round robin
560 for PCIE-GPP1, PCIE-GPP2, PCIE-GPP3a and PCIE-GPP3b cores only. */
561 //if (gpp_sb_sel != PCIE_CORE_INDEX_SB) /* RPR NOT set SB_CORE, BTS set SB_CORE, we comply with BTS */
562 set_pcie_enable_bits(nb_dev, 0x1C | gpp_sb_sel, 0x7FF, 0x109);
563 /* 4.4.2.step13.13. Sets number of TX Clocks to drain TX Pipe to 0x3.*/
564 set_pcie_enable_bits(dev, 0xA0, 0xF << 4, 0x3 << 4);
565 /* 4.4.2.step13.14. Lets PI use Electrical Idle from PHY when
566 turning off PLL in L1 at Gen 2 speed instead of Inferred Electrical
568 NOTE: LC still uses Inferred Electrical Idle. */
569 set_pcie_enable_bits(nb_dev, 0x40 | gpp_sb_sel, 3 << 14, 2 << 14);
570 /* 4.4.2.step13.15. Turn on rx_fronten_en for all active lanes upon
571 exit from Electrical Idle, rather than being tied to PLL_PDNB. */
572 set_pcie_enable_bits(nb_dev, 0xC2 | gpp_sb_sel, 1 << 25, 1 << 25);
574 /* 4.4.2.step13.16. Advertises TX L0s and L1 exit latency.
575 TX L0s exit latency to be 100b: 512ns to less than 1us;
576 L1 exit latency to be 011b: 4us to less than 8us.
577 For Hot-Plug Slots: Advertise TX L0s and L1 exit latency.
578 TX L0s exit latency to be 110b: 2us to 4us.
579 L1 exit latency to be 111b: more than 64us.*/
580 //set_pcie_enable_bits(dev, 0xC1, 0xF << 0, 0xC << 0); /* 0xF for htplg. */
581 set_pcie_enable_bits(dev, 0xC1, 0xF << 0, 0xF << 0); /* 0xF for htplg. */
582 /* 4.4.2.step13.17. Always ACK an ASPM L1 entry DLLP to
583 workaround credit control issue on PM_NAK
584 message of SB700 and SB800. */
585 /* 4.4.4.step13.18. To allow advertising Gen 2 capabilities to Southbridge. */
587 set_pcie_enable_bits(dev, 0xA0, 1 << 23, 1 << 23);
588 set_pcie_enable_bits(nb_dev, 0xC1 | gpp_sb_sel, 1 << 1, 1 << 1);
590 /* 4.4.2.step13.19. CMOS Option (Gen 2 AUTO-Part 1 - Enabled by Default) */
591 /* 4.4.2.step13.20. CMOS Option (RC Advertised Gen 2-Part1 - Disabled by Default)*/
592 set_nbcfg_enable_bits(dev, 0x88, 0xF << 0, 0x2 << 0);
593 /* Disables GEN2 capability of the device.
594 * RPR typo- it says enable but the bit setting says disable.
595 * Disable it here and we enable it later. */
596 set_pcie_enable_bits(dev, 0xA4, 1 << 0, 1 << 0);
597 /* 4.4.2.step13.21. */
598 /* 4.4.2.step13.22 */
599 /* Enable native PME. */
600 set_pcie_enable_bits(dev, 0x10, 1 << 3, 1 < 3);
601 /* This bit when set indicates that the PCIe Link associated with this port
602 is connected to a slot. */
603 pci_ext_write_config32(nb_dev, dev, 0x5a, 1 << 8, 1 << 8);
604 /* This bit when set indicates that this slot is capable of supporting
605 Hot-Plug operations. */
606 set_nbcfg_enable_bits(dev, 0x6C, 1 << 6, 1 << 6);
607 /* Enables flushing of TLPs when Data Link is down. */
608 set_pcie_enable_bits(dev, 0x20, 1 << 19, 0 << 19);
610 /* 4.4.2.step14. Server Class Hot Plug Feature */
611 /* 4.4.2 step14.1: Advertising Hot Plug Capabilities */
612 /* 4.4.2.step14.2: Firmware Upload */
613 /* 4.4.2.Step14.3: SBIOS Acknowledgment to Firmware of Successful Firmware Upload */
618 /* CIMx LPC Deadlock workaround - Enable Memory Write Map*/
619 if (gpp_sb_sel == PCIE_CORE_INDEX_SB) {
620 set_pcie_enable_bits(nb_dev, 0x10 | gpp_sb_sel, 1 << 9, 1 << 9);
621 set_htiu_enable_bits(nb_dev, 0x06, 1 << 26, 1 << 26);
624 /* This CPL setup requires more than this one register and should be done in gpp_core.
625 * The additional setup is for the different revisions. */
627 /* CIMx CommonPortInit settings that are not set above. */
628 pci_ext_write_config32(nb_dev, dev, 0x88, 0xF0, 1 << 0); /* LINK_CRTL2 */
631 set_pcie_enable_bits(dev, 0xA0, 0, 1 << 23);
633 /* set automatic Gen2 support, needs mainboard config option as Gen2 can cause issues on some platforms. */
634 init_gen2(nb_dev, dev, port);
635 set_pcie_enable_bits(dev, 0xA4, 1 << 29, 1 << 29);
636 set_pcie_enable_bits(dev, 0xC0, 1 << 15, 0);
637 set_pcie_enable_bits(dev, 0xA2, 1 << 13, 0);
639 /* Hotplug Support - bit5 + bit6 capable and surprise */
640 pci_ext_write_config32(nb_dev, dev, 0x6c, 0x60, 0x60);
642 /* Set interrupt pin info 0x3d */
643 pci_ext_write_config32(nb_dev, dev, 0x3c, 1 << 8, 1 << 8);
645 /* 5.12.9.3 Hotplug step 1 - NB_PCIE_ROOT_CTRL - enable pm irq
646 The RPR is wrong - this is not a PCIEND_P register */
647 pci_ext_write_config32(nb_dev, dev, 0x74, 1 << 3, 1 << 3);
649 /* 5.12.9.3 step 2 - PCIEP_PORT_CNTL - enable hotplug messages */
651 set_pcie_enable_bits(dev, 0x10, 1 << 2, 1 << 2);
653 /* Not sure about this PME setup */
655 set_pcie_enable_bits(dev, 0x10, 1 << 3, 1 << 3); /* Not set in CIMx */
658 pci_ext_write_config32(nb_dev, dev, 0x54, 1 << 8, 1 << 8); /* Not in CIMx */
660 /* 4.4.3 Training for GPP devices */
674 /* 4.4.2.step13.5. Blocks DMA traffic during C3 state */
675 set_pcie_enable_bits(dev, 0x10, 1 << 0, 0 << 0);
676 /* Enabels TLP flushing */
677 set_pcie_enable_bits(dev, 0x20, 1 << 19, 0 << 19);
679 /* check port enable */
680 if (cfg->port_enable & (1 << port)) {
681 PcieReleasePortTraining(nb_dev, dev, port);
682 if (!(AtiPcieCfg.Config & PCIE_GPP_COMPLIANCE)) {
683 u8 res = PcieTrainPort(nb_dev, dev, port);
684 printk(BIOS_DEBUG, "PcieTrainPort port=0x%x result=%d\n", port, res);
686 AtiPcieCfg.PortDetect |= 1 << port;
697 /* Re-enable RC ordering logic after training (from CIMx)*/
698 set_pcie_enable_bits(nb_dev, 0x20 | gpp_sb_sel, 1 << 9, 0);
700 /* Advertising Hot Plug Capabilities */
701 pci_ext_write_config32(nb_dev, dev, 0x6c, 0x04001B, 0x00001B);
703 /* PCIE Late Init (CIMx late init - Maybe move somewhere else? Later in the coreboot PCI device enum?) */
704 /* Set Slot Number */
705 pci_ext_write_config32(nb_dev, dev, 0x6c, 0x1FFF << 19, port << 19);
707 /* Set Slot present 0x5A*/
708 pci_ext_write_config32(nb_dev, dev, 0x58, 1 << 24, 1 << 24);
710 //PCIE-GPP1 TXCLK Clock Gating In L1 Late Core sttting - Maybe move somewhere else? */
711 set_pcie_enable_bits(nb_dev, 0x11 | gpp_sb_sel, 0xF << 0, 0x0C << 0);
712 /* Enable powering down PLLs in L1 or L23 Ready states.
713 * Turns off PHY`s RX FRONTEND during L1 when PLL power down is enabled */
714 set_pcie_enable_bits(nb_dev, 0x40 | gpp_sb_sel, 0x1219, 0x1009);
715 /* 4.4..7.1 TXCLK Gating in L1, Enables powering down TXCLK clock pads on the receive side. */
716 set_pcie_enable_bits(nb_dev, 0x40 | gpp_sb_sel, 1 << 6, 1 << 6);
718 /* Step 21: Register Locking PCIE Misc. Late Core sttting - Must move somewhere do PciInitLate FIXME */
719 /* Lock HWInit Register */
720 //set_pcie_enable_bits(nb_dev, 0x10 | gpp_sb_sel, 1 << 0, 1 << 0);
722 /* Step 27: LCLK Gating */
723 //EnableLclkGating(dev);
725 /* Set Common Clock */
726 /* If dev present, set PcieCapPtr+0x10, BIT6);
728 * retrain link, set dev, 0x68 bit 5;
729 * wait dev 0x6B bit3 clear
733 PciePowerOffGppPorts(nb_dev, dev, port); /* , This should be run for all ports that are not hotplug and don't detect devices */
737 /*****************************************
738 * Compliant with CIM_33's PCIEConfigureGPPCore
739 *****************************************/
740 void config_gpp_core(device_t nb_dev, device_t sb_dev)
743 struct southbridge_amd_sr5650_config *cfg =
744 (struct southbridge_amd_sr5650_config *)nb_dev->chip_info;
746 reg = nbmisc_read_index(nb_dev, 0x20);
747 if (AtiPcieCfg.Config & PCIE_ENABLE_STATIC_DEV_REMAP)
748 reg &= 0xfffffffd; /* set bit1 = 0 */
750 reg |= 0x2; /* set bit1 = 1 */
751 nbmisc_write_index(nb_dev, 0x20, reg);
753 /* Must perform PCIE-GPP1, GPP2, GPP3a global reset anyway */
754 reg = nbmisc_read_index(nb_dev, 0x8);
755 reg |= (1 << 31) | (1 << 15) | (1 << 13); //asserts
756 nbmisc_write_index(nb_dev, 0x8, reg);
757 reg &= ~((1 << 31) | (1 << 15) | (1 << 13)); //De-aserts
758 nbmisc_write_index(nb_dev, 0x8, reg);
760 reg = nbmisc_read_index(nb_dev, 0x67); /* get STRAP_BIF_LINK_CONFIG at bit 0-4 */
761 if (cfg->gpp3a_configuration != (reg & 0x1F))
762 switching_gpp3a_configurations(nb_dev, sb_dev);
763 reg = nbmisc_read_index(nb_dev, 0x8); /* get MULTIPORT_CONFIG_GPP1 MULTIPORT_CONFIG_CONFIG_GPP2 at bit 8,9 */
764 if ((cfg->gpp1_configuration << 8) != (reg & (1 << 8)))
765 switching_gpp1_configurations(nb_dev, sb_dev);
766 if ((cfg->gpp2_configuration << 9) != (reg & (1 << 9)))
767 switching_gpp2_configurations(nb_dev, sb_dev);
768 ValidatePortEn(nb_dev);
771 /*****************************************
772 * Compliant with CIM_33's PCIEMiscClkProg
773 *****************************************/
774 void pcie_config_misc_clk(device_t nb_dev)
777 //struct bus pbus; /* fake bus for dev0 fun1 */
779 reg = pci_read_config32(nb_dev, 0x4c);
781 pci_write_config32(nb_dev, 0x4c, reg);
783 #if 0 /* TODO: Check the mics clock later. */
784 if (AtiPcieCfg.Config & PCIE_GFX_CLK_GATING) {
785 /* TXCLK Clock Gating */
786 set_nbmisc_enable_bits(nb_dev, 0x07, 3 << 0, 3 << 0);
787 set_nbmisc_enable_bits(nb_dev, 0x07, 1 << 22, 1 << 22);
788 set_pcie_enable_bits(nb_dev, 0x11 | PCIE_CORE_INDEX_GFX, (3 << 6) | (~0xf), 3 << 6);
790 /* LCLK Clock Gating */
791 reg = pci_cf8_conf1.read32(&pbus, 0, 1, 0x94);
793 pci_cf8_conf1.write32(&pbus, 0, 1, 0x94, reg);
796 if (AtiPcieCfg.Config & PCIE_GPP_CLK_GATING) {
797 /* TXCLK Clock Gating */
798 set_nbmisc_enable_bits(nb_dev, 0x07, 3 << 4, 3 << 4);
799 set_nbmisc_enable_bits(nb_dev, 0x07, 1 << 22, 1 << 22);
800 set_pcie_enable_bits(nb_dev, 0x11 | PCIE_CORE_INDEX_SB, (3 << 6) | (~0xf), 3 << 6);
802 /* LCLK Clock Gating */
803 reg = pci_cf8_conf1.read32(&pbus, 0, 1, 0x94);
805 pci_cf8_conf1.write32(&pbus, 0, 1, 0x94, reg);
809 reg = pci_read_config32(nb_dev, 0x4c);
811 pci_write_config32(nb_dev, 0x4c, reg);