xref: /openbmc/u-boot/arch/x86/cpu/queensbay/tnc.c (revision 66484f0fc01ab3c65007c869f563adc04aa5c175)
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>
9*66484f0fSBin 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 
57*66484f0fSBin Meng 	/*
58*66484f0fSBin Meng 	 * After setting the function disable bit, IGD and SDVO devices will
59*66484f0fSBin Meng 	 * disappear in the PCI configuration space. This however creates an
60*66484f0fSBin Meng 	 * inconsistent state from a driver model PCI controller point of view,
61*66484f0fSBin Meng 	 * as these two PCI devices are still attached to its parent's child
62*66484f0fSBin Meng 	 * device list as maintained by the driver model. Some driver model PCI
63*66484f0fSBin Meng 	 * APIs like dm_pci_find_class(), are referring to the list to speed up
64*66484f0fSBin Meng 	 * the finding process instead of re-enumerating the whole PCI bus, so
65*66484f0fSBin Meng 	 * it gets the stale cached data which is wrong.
66*66484f0fSBin Meng 	 *
67*66484f0fSBin Meng 	 * Note x86 PCI enueration normally happens twice, in pre-relocation
68*66484f0fSBin Meng 	 * phase and post-relocation. One option might be to call disable_igd()
69*66484f0fSBin Meng 	 * in one of the pre-relocation initialization hooks so that it gets
70*66484f0fSBin Meng 	 * disabled in the first round, and when it comes to the second round
71*66484f0fSBin Meng 	 * driver model PCI will construct a correct list. Unfortunately this
72*66484f0fSBin Meng 	 * does not work as Intel FSP is used on this platform to perform low
73*66484f0fSBin Meng 	 * level initialization, and fsp_init_phase_pci() is called only once
74*66484f0fSBin Meng 	 * in the post-relocation phase. If we disable IGD and SDVO devices,
75*66484f0fSBin Meng 	 * fsp_init_phase_pci() simply hangs and never returns.
76*66484f0fSBin Meng 	 *
77*66484f0fSBin Meng 	 * So the only option we have is to manually remove these two devices.
78*66484f0fSBin Meng 	 */
79*66484f0fSBin Meng 	ret = device_remove(igd);
80*66484f0fSBin Meng 	if (ret)
81*66484f0fSBin Meng 		return ret;
82*66484f0fSBin Meng 	ret = device_unbind(igd);
83*66484f0fSBin Meng 	if (ret)
84*66484f0fSBin Meng 		return ret;
85*66484f0fSBin Meng 	ret = device_remove(sdvo);
86*66484f0fSBin Meng 	if (ret)
87*66484f0fSBin Meng 		return ret;
88*66484f0fSBin Meng 	ret = device_unbind(sdvo);
89*66484f0fSBin Meng 	if (ret)
90*66484f0fSBin Meng 		return ret;
91*66484f0fSBin Meng 
929e36c53dSBin Meng 	return 0;
931f124ebaSBin Meng }
941f124ebaSBin Meng 
95b2e02d28SBin Meng int arch_cpu_init(void)
96b2e02d28SBin Meng {
97adfe3b24SBin Meng 	int ret;
98adfe3b24SBin Meng 
99b2e02d28SBin Meng 	post_code(POST_CPU_INIT);
100b2e02d28SBin Meng 
101adfe3b24SBin Meng 	ret = x86_cpu_init_f();
102adfe3b24SBin Meng 	if (ret)
103adfe3b24SBin Meng 		return ret;
104adfe3b24SBin Meng 
105adfe3b24SBin Meng 	return 0;
106b2e02d28SBin Meng }
107afbf1404SBin Meng 
1081f124ebaSBin Meng int arch_early_init_r(void)
1091f124ebaSBin Meng {
1109e36c53dSBin Meng 	int ret = 0;
1119e36c53dSBin Meng 
1121f124ebaSBin Meng #ifdef CONFIG_DISABLE_IGD
1139e36c53dSBin Meng 	ret = disable_igd();
1141f124ebaSBin Meng #endif
1151f124ebaSBin Meng 
1169e36c53dSBin Meng 	return ret;
1171f124ebaSBin Meng }
118