183d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+ 2b2e02d28SBin Meng /* 3b2e02d28SBin Meng * Copyright (C) 2014, Bin Meng <bmeng.cn@gmail.com> 4b2e02d28SBin Meng */ 5b2e02d28SBin Meng 6b2e02d28SBin Meng #include <common.h> 72b94d9fcSBin Meng #include <dm.h> 866484f0fSBin Meng #include <dm/device-internal.h> 92b94d9fcSBin Meng #include <pci.h> 10b2e02d28SBin Meng #include <asm/io.h> 119c7dea60SBin Meng #include <asm/irq.h> 12b2e02d28SBin Meng #include <asm/post.h> 13afbf1404SBin Meng #include <asm/arch/device.h> 149c7dea60SBin Meng #include <asm/arch/tnc.h> 151021af4dSSimon Glass #include <asm/fsp/fsp_support.h> 16b2e02d28SBin Meng #include <asm/processor.h> 17b2e02d28SBin Meng 189e36c53dSBin Meng static int __maybe_unused disable_igd(void) 191f124ebaSBin Meng { 202b94d9fcSBin Meng struct udevice *igd, *sdvo; 212b94d9fcSBin Meng int ret; 222b94d9fcSBin Meng 232b94d9fcSBin Meng ret = dm_pci_bus_find_bdf(TNC_IGD, &igd); 242b94d9fcSBin Meng if (ret) 252b94d9fcSBin Meng return ret; 262b94d9fcSBin Meng if (!igd) 272b94d9fcSBin Meng return 0; 282b94d9fcSBin Meng 292b94d9fcSBin Meng ret = dm_pci_bus_find_bdf(TNC_SDVO, &sdvo); 302b94d9fcSBin Meng if (ret) 312b94d9fcSBin Meng return ret; 322b94d9fcSBin Meng if (!sdvo) 332b94d9fcSBin Meng return 0; 342b94d9fcSBin Meng 35e5ffa4bbSBin Meng /* 36e5ffa4bbSBin Meng * According to Atom E6xx datasheet, setting VGA Disable (bit17) 37e5ffa4bbSBin Meng * of Graphics Controller register (offset 0x50) prevents IGD 38e5ffa4bbSBin Meng * (D2:F0) from reporting itself as a VGA display controller 39e5ffa4bbSBin Meng * class in the PCI configuration space, and should also prevent 40e5ffa4bbSBin Meng * it from responding to VGA legacy memory range and I/O addresses. 41e5ffa4bbSBin Meng * 42e5ffa4bbSBin Meng * However test result shows that with just VGA Disable bit set and 43e5ffa4bbSBin Meng * a PCIe graphics card connected to one of the PCIe controllers on 44e5ffa4bbSBin Meng * the E6xx, accessing the VGA legacy space still causes system hang. 45e5ffa4bbSBin Meng * After a number of attempts, it turns out besides VGA Disable bit, 46e5ffa4bbSBin Meng * the SDVO (D3:F0) device should be disabled to make it work. 47e5ffa4bbSBin Meng * 48e5ffa4bbSBin Meng * To simplify, use the Function Disable register (offset 0xc4) 49e5ffa4bbSBin Meng * to disable both IGD (D2:F0) and SDVO (D3:F0) devices. Now these 50e5ffa4bbSBin Meng * two devices will be completely disabled (invisible in the PCI 51e5ffa4bbSBin Meng * configuration space) unless a system reset is performed. 52e5ffa4bbSBin Meng */ 532b94d9fcSBin Meng dm_pci_write_config32(igd, IGD_FD, FUNC_DISABLE); 542b94d9fcSBin Meng dm_pci_write_config32(sdvo, IGD_FD, FUNC_DISABLE); 559e36c53dSBin Meng 5666484f0fSBin Meng /* 5766484f0fSBin Meng * After setting the function disable bit, IGD and SDVO devices will 5866484f0fSBin Meng * disappear in the PCI configuration space. This however creates an 5966484f0fSBin Meng * inconsistent state from a driver model PCI controller point of view, 6066484f0fSBin Meng * as these two PCI devices are still attached to its parent's child 6166484f0fSBin Meng * device list as maintained by the driver model. Some driver model PCI 6266484f0fSBin Meng * APIs like dm_pci_find_class(), are referring to the list to speed up 6366484f0fSBin Meng * the finding process instead of re-enumerating the whole PCI bus, so 6466484f0fSBin Meng * it gets the stale cached data which is wrong. 6566484f0fSBin Meng * 6666484f0fSBin Meng * Note x86 PCI enueration normally happens twice, in pre-relocation 6766484f0fSBin Meng * phase and post-relocation. One option might be to call disable_igd() 6866484f0fSBin Meng * in one of the pre-relocation initialization hooks so that it gets 6966484f0fSBin Meng * disabled in the first round, and when it comes to the second round 7066484f0fSBin Meng * driver model PCI will construct a correct list. Unfortunately this 7166484f0fSBin Meng * does not work as Intel FSP is used on this platform to perform low 7266484f0fSBin Meng * level initialization, and fsp_init_phase_pci() is called only once 7366484f0fSBin Meng * in the post-relocation phase. If we disable IGD and SDVO devices, 7466484f0fSBin Meng * fsp_init_phase_pci() simply hangs and never returns. 7566484f0fSBin Meng * 7666484f0fSBin Meng * So the only option we have is to manually remove these two devices. 7766484f0fSBin Meng */ 78706865afSStefan Roese ret = device_remove(igd, DM_REMOVE_NORMAL); 7966484f0fSBin Meng if (ret) 8066484f0fSBin Meng return ret; 8166484f0fSBin Meng ret = device_unbind(igd); 8266484f0fSBin Meng if (ret) 8366484f0fSBin Meng return ret; 84706865afSStefan Roese ret = device_remove(sdvo, DM_REMOVE_NORMAL); 8566484f0fSBin Meng if (ret) 8666484f0fSBin Meng return ret; 8766484f0fSBin Meng ret = device_unbind(sdvo); 8866484f0fSBin Meng if (ret) 8966484f0fSBin Meng return ret; 9066484f0fSBin Meng 919e36c53dSBin Meng return 0; 921f124ebaSBin Meng } 931f124ebaSBin Meng 94b2e02d28SBin Meng int arch_cpu_init(void) 95b2e02d28SBin Meng { 96b2e02d28SBin Meng post_code(POST_CPU_INIT); 97b2e02d28SBin Meng 980a8547a2SMasahiro Yamada return x86_cpu_init_f(); 99b2e02d28SBin Meng } 100afbf1404SBin Meng 101*bc728b1bSBin Meng static void tnc_irq_init(void) 102*bc728b1bSBin Meng { 103*bc728b1bSBin Meng struct tnc_rcba *rcba; 104*bc728b1bSBin Meng u32 base; 105*bc728b1bSBin Meng 106*bc728b1bSBin Meng pci_read_config32(TNC_LPC, LPC_RCBA, &base); 107*bc728b1bSBin Meng base &= ~MEM_BAR_EN; 108*bc728b1bSBin Meng rcba = (struct tnc_rcba *)base; 109*bc728b1bSBin Meng 110*bc728b1bSBin Meng /* Make sure all internal PCI devices are using INTA */ 111*bc728b1bSBin Meng writel(INTA, &rcba->d02ip); 112*bc728b1bSBin Meng writel(INTA, &rcba->d03ip); 113*bc728b1bSBin Meng writel(INTA, &rcba->d27ip); 114*bc728b1bSBin Meng writel(INTA, &rcba->d31ip); 115*bc728b1bSBin Meng writel(INTA, &rcba->d23ip); 116*bc728b1bSBin Meng writel(INTA, &rcba->d24ip); 117*bc728b1bSBin Meng writel(INTA, &rcba->d25ip); 118*bc728b1bSBin Meng writel(INTA, &rcba->d26ip); 119*bc728b1bSBin Meng 120*bc728b1bSBin Meng /* 121*bc728b1bSBin Meng * Route TunnelCreek PCI device interrupt pin to PIRQ 122*bc728b1bSBin Meng * 123*bc728b1bSBin Meng * Since PCIe downstream ports received INTx are routed to PIRQ 124*bc728b1bSBin Meng * A/B/C/D directly and not configurable, we have to route PCIe 125*bc728b1bSBin Meng * root ports' INTx to PIRQ A/B/C/D as well. For other devices 126*bc728b1bSBin Meng * on TunneCreek, route them to PIRQ E/F/G/H. 127*bc728b1bSBin Meng */ 128*bc728b1bSBin Meng writew(PIRQE, &rcba->d02ir); 129*bc728b1bSBin Meng writew(PIRQF, &rcba->d03ir); 130*bc728b1bSBin Meng writew(PIRQG, &rcba->d27ir); 131*bc728b1bSBin Meng writew(PIRQH, &rcba->d31ir); 132*bc728b1bSBin Meng writew(PIRQA, &rcba->d23ir); 133*bc728b1bSBin Meng writew(PIRQB, &rcba->d24ir); 134*bc728b1bSBin Meng writew(PIRQC, &rcba->d25ir); 135*bc728b1bSBin Meng writew(PIRQD, &rcba->d26ir); 136*bc728b1bSBin Meng } 137*bc728b1bSBin Meng 1381f124ebaSBin Meng int arch_early_init_r(void) 1391f124ebaSBin Meng { 1409e36c53dSBin Meng int ret = 0; 1419e36c53dSBin Meng 1421f124ebaSBin Meng #ifdef CONFIG_DISABLE_IGD 1439e36c53dSBin Meng ret = disable_igd(); 1441f124ebaSBin Meng #endif 1451f124ebaSBin Meng 146*bc728b1bSBin Meng tnc_irq_init(); 147*bc728b1bSBin Meng 1489e36c53dSBin Meng return ret; 1491f124ebaSBin Meng } 150