1b2e02d28SBin Meng /* 2b2e02d28SBin Meng * Copyright (C) 2014, Bin Meng <bmeng.cn@gmail.com> 3b2e02d28SBin Meng * 4b2e02d28SBin Meng * SPDX-License-Identifier: GPL-2.0+ 5b2e02d28SBin Meng */ 6b2e02d28SBin Meng 7b2e02d28SBin Meng #include <common.h> 82b94d9fcSBin Meng #include <dm.h> 966484f0fSBin Meng #include <dm/device-internal.h> 102b94d9fcSBin Meng #include <pci.h> 11b2e02d28SBin Meng #include <asm/io.h> 129c7dea60SBin Meng #include <asm/irq.h> 13b2e02d28SBin Meng #include <asm/post.h> 14afbf1404SBin Meng #include <asm/arch/device.h> 159c7dea60SBin Meng #include <asm/arch/tnc.h> 161021af4dSSimon Glass #include <asm/fsp/fsp_support.h> 17b2e02d28SBin Meng #include <asm/processor.h> 18b2e02d28SBin Meng 199e36c53dSBin Meng static int __maybe_unused disable_igd(void) 201f124ebaSBin Meng { 212b94d9fcSBin Meng struct udevice *igd, *sdvo; 222b94d9fcSBin Meng int ret; 232b94d9fcSBin Meng 242b94d9fcSBin Meng ret = dm_pci_bus_find_bdf(TNC_IGD, &igd); 252b94d9fcSBin Meng if (ret) 262b94d9fcSBin Meng return ret; 272b94d9fcSBin Meng if (!igd) 282b94d9fcSBin Meng return 0; 292b94d9fcSBin Meng 302b94d9fcSBin Meng ret = dm_pci_bus_find_bdf(TNC_SDVO, &sdvo); 312b94d9fcSBin Meng if (ret) 322b94d9fcSBin Meng return ret; 332b94d9fcSBin Meng if (!sdvo) 342b94d9fcSBin Meng return 0; 352b94d9fcSBin Meng 36e5ffa4bbSBin Meng /* 37e5ffa4bbSBin Meng * According to Atom E6xx datasheet, setting VGA Disable (bit17) 38e5ffa4bbSBin Meng * of Graphics Controller register (offset 0x50) prevents IGD 39e5ffa4bbSBin Meng * (D2:F0) from reporting itself as a VGA display controller 40e5ffa4bbSBin Meng * class in the PCI configuration space, and should also prevent 41e5ffa4bbSBin Meng * it from responding to VGA legacy memory range and I/O addresses. 42e5ffa4bbSBin Meng * 43e5ffa4bbSBin Meng * However test result shows that with just VGA Disable bit set and 44e5ffa4bbSBin Meng * a PCIe graphics card connected to one of the PCIe controllers on 45e5ffa4bbSBin Meng * the E6xx, accessing the VGA legacy space still causes system hang. 46e5ffa4bbSBin Meng * After a number of attempts, it turns out besides VGA Disable bit, 47e5ffa4bbSBin Meng * the SDVO (D3:F0) device should be disabled to make it work. 48e5ffa4bbSBin Meng * 49e5ffa4bbSBin Meng * To simplify, use the Function Disable register (offset 0xc4) 50e5ffa4bbSBin Meng * to disable both IGD (D2:F0) and SDVO (D3:F0) devices. Now these 51e5ffa4bbSBin Meng * two devices will be completely disabled (invisible in the PCI 52e5ffa4bbSBin Meng * configuration space) unless a system reset is performed. 53e5ffa4bbSBin Meng */ 542b94d9fcSBin Meng dm_pci_write_config32(igd, IGD_FD, FUNC_DISABLE); 552b94d9fcSBin Meng dm_pci_write_config32(sdvo, IGD_FD, FUNC_DISABLE); 569e36c53dSBin Meng 5766484f0fSBin Meng /* 5866484f0fSBin Meng * After setting the function disable bit, IGD and SDVO devices will 5966484f0fSBin Meng * disappear in the PCI configuration space. This however creates an 6066484f0fSBin Meng * inconsistent state from a driver model PCI controller point of view, 6166484f0fSBin Meng * as these two PCI devices are still attached to its parent's child 6266484f0fSBin Meng * device list as maintained by the driver model. Some driver model PCI 6366484f0fSBin Meng * APIs like dm_pci_find_class(), are referring to the list to speed up 6466484f0fSBin Meng * the finding process instead of re-enumerating the whole PCI bus, so 6566484f0fSBin Meng * it gets the stale cached data which is wrong. 6666484f0fSBin Meng * 6766484f0fSBin Meng * Note x86 PCI enueration normally happens twice, in pre-relocation 6866484f0fSBin Meng * phase and post-relocation. One option might be to call disable_igd() 6966484f0fSBin Meng * in one of the pre-relocation initialization hooks so that it gets 7066484f0fSBin Meng * disabled in the first round, and when it comes to the second round 7166484f0fSBin Meng * driver model PCI will construct a correct list. Unfortunately this 7266484f0fSBin Meng * does not work as Intel FSP is used on this platform to perform low 7366484f0fSBin Meng * level initialization, and fsp_init_phase_pci() is called only once 7466484f0fSBin Meng * in the post-relocation phase. If we disable IGD and SDVO devices, 7566484f0fSBin Meng * fsp_init_phase_pci() simply hangs and never returns. 7666484f0fSBin Meng * 7766484f0fSBin Meng * So the only option we have is to manually remove these two devices. 7866484f0fSBin Meng */ 79*706865afSStefan Roese ret = device_remove(igd, DM_REMOVE_NORMAL); 8066484f0fSBin Meng if (ret) 8166484f0fSBin Meng return ret; 8266484f0fSBin Meng ret = device_unbind(igd); 8366484f0fSBin Meng if (ret) 8466484f0fSBin Meng return ret; 85*706865afSStefan Roese ret = device_remove(sdvo, DM_REMOVE_NORMAL); 8666484f0fSBin Meng if (ret) 8766484f0fSBin Meng return ret; 8866484f0fSBin Meng ret = device_unbind(sdvo); 8966484f0fSBin Meng if (ret) 9066484f0fSBin Meng return ret; 9166484f0fSBin Meng 929e36c53dSBin Meng return 0; 931f124ebaSBin Meng } 941f124ebaSBin Meng 95b2e02d28SBin Meng int arch_cpu_init(void) 96b2e02d28SBin Meng { 97b2e02d28SBin Meng post_code(POST_CPU_INIT); 98b2e02d28SBin Meng 990a8547a2SMasahiro Yamada return x86_cpu_init_f(); 100b2e02d28SBin Meng } 101afbf1404SBin Meng 1021f124ebaSBin Meng int arch_early_init_r(void) 1031f124ebaSBin Meng { 1049e36c53dSBin Meng int ret = 0; 1059e36c53dSBin Meng 1061f124ebaSBin Meng #ifdef CONFIG_DISABLE_IGD 1079e36c53dSBin Meng ret = disable_igd(); 1081f124ebaSBin Meng #endif 1091f124ebaSBin Meng 1109e36c53dSBin Meng return ret; 1111f124ebaSBin Meng } 112