Bin Meng | 08e484c | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014, Bin Meng <bmeng.cn@gmail.com> |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Bin Meng | e0ff4b2 | 2016-02-01 01:40:54 -0800 | [diff] [blame] | 8 | #include <dm.h> |
Bin Meng | 4f6c577 | 2016-02-01 01:40:55 -0800 | [diff] [blame] | 9 | #include <dm/device-internal.h> |
Bin Meng | e0ff4b2 | 2016-02-01 01:40:54 -0800 | [diff] [blame] | 10 | #include <pci.h> |
Bin Meng | 08e484c | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 11 | #include <asm/io.h> |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 12 | #include <asm/irq.h> |
Bin Meng | 08e484c | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 13 | #include <asm/post.h> |
Bin Meng | 1530536 | 2015-04-24 18:10:06 +0800 | [diff] [blame] | 14 | #include <asm/arch/device.h> |
Bin Meng | 51c3b1e | 2015-05-25 22:35:04 +0800 | [diff] [blame] | 15 | #include <asm/arch/tnc.h> |
Simon Glass | b93abfc | 2015-01-27 22:13:36 -0700 | [diff] [blame] | 16 | #include <asm/fsp/fsp_support.h> |
Bin Meng | 08e484c | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 17 | #include <asm/processor.h> |
| 18 | |
Bin Meng | f041c56 | 2016-02-01 01:40:53 -0800 | [diff] [blame] | 19 | static int __maybe_unused disable_igd(void) |
Bin Meng | 2f0999e | 2015-10-01 00:36:04 -0700 | [diff] [blame] | 20 | { |
Bin Meng | e0ff4b2 | 2016-02-01 01:40:54 -0800 | [diff] [blame] | 21 | struct udevice *igd, *sdvo; |
| 22 | int ret; |
| 23 | |
| 24 | ret = dm_pci_bus_find_bdf(TNC_IGD, &igd); |
| 25 | if (ret) |
| 26 | return ret; |
| 27 | if (!igd) |
| 28 | return 0; |
| 29 | |
| 30 | ret = dm_pci_bus_find_bdf(TNC_SDVO, &sdvo); |
| 31 | if (ret) |
| 32 | return ret; |
| 33 | if (!sdvo) |
| 34 | return 0; |
| 35 | |
Bin Meng | 239a40a | 2015-10-22 19:13:32 -0700 | [diff] [blame] | 36 | /* |
| 37 | * According to Atom E6xx datasheet, setting VGA Disable (bit17) |
| 38 | * of Graphics Controller register (offset 0x50) prevents IGD |
| 39 | * (D2:F0) from reporting itself as a VGA display controller |
| 40 | * class in the PCI configuration space, and should also prevent |
| 41 | * it from responding to VGA legacy memory range and I/O addresses. |
| 42 | * |
| 43 | * However test result shows that with just VGA Disable bit set and |
| 44 | * a PCIe graphics card connected to one of the PCIe controllers on |
| 45 | * the E6xx, accessing the VGA legacy space still causes system hang. |
| 46 | * After a number of attempts, it turns out besides VGA Disable bit, |
| 47 | * the SDVO (D3:F0) device should be disabled to make it work. |
| 48 | * |
| 49 | * To simplify, use the Function Disable register (offset 0xc4) |
| 50 | * to disable both IGD (D2:F0) and SDVO (D3:F0) devices. Now these |
| 51 | * two devices will be completely disabled (invisible in the PCI |
| 52 | * configuration space) unless a system reset is performed. |
| 53 | */ |
Bin Meng | e0ff4b2 | 2016-02-01 01:40:54 -0800 | [diff] [blame] | 54 | dm_pci_write_config32(igd, IGD_FD, FUNC_DISABLE); |
| 55 | dm_pci_write_config32(sdvo, IGD_FD, FUNC_DISABLE); |
Bin Meng | f041c56 | 2016-02-01 01:40:53 -0800 | [diff] [blame] | 56 | |
Bin Meng | 4f6c577 | 2016-02-01 01:40:55 -0800 | [diff] [blame] | 57 | /* |
| 58 | * After setting the function disable bit, IGD and SDVO devices will |
| 59 | * disappear in the PCI configuration space. This however creates an |
| 60 | * inconsistent state from a driver model PCI controller point of view, |
| 61 | * as these two PCI devices are still attached to its parent's child |
| 62 | * device list as maintained by the driver model. Some driver model PCI |
| 63 | * APIs like dm_pci_find_class(), are referring to the list to speed up |
| 64 | * the finding process instead of re-enumerating the whole PCI bus, so |
| 65 | * it gets the stale cached data which is wrong. |
| 66 | * |
| 67 | * Note x86 PCI enueration normally happens twice, in pre-relocation |
| 68 | * phase and post-relocation. One option might be to call disable_igd() |
| 69 | * in one of the pre-relocation initialization hooks so that it gets |
| 70 | * disabled in the first round, and when it comes to the second round |
| 71 | * driver model PCI will construct a correct list. Unfortunately this |
| 72 | * does not work as Intel FSP is used on this platform to perform low |
| 73 | * level initialization, and fsp_init_phase_pci() is called only once |
| 74 | * in the post-relocation phase. If we disable IGD and SDVO devices, |
| 75 | * fsp_init_phase_pci() simply hangs and never returns. |
| 76 | * |
| 77 | * So the only option we have is to manually remove these two devices. |
| 78 | */ |
Stefan Roese | 80b5bc9 | 2017-03-20 12:51:48 +0100 | [diff] [blame] | 79 | ret = device_remove(igd, DM_REMOVE_NORMAL); |
Bin Meng | 4f6c577 | 2016-02-01 01:40:55 -0800 | [diff] [blame] | 80 | if (ret) |
| 81 | return ret; |
| 82 | ret = device_unbind(igd); |
| 83 | if (ret) |
| 84 | return ret; |
Stefan Roese | 80b5bc9 | 2017-03-20 12:51:48 +0100 | [diff] [blame] | 85 | ret = device_remove(sdvo, DM_REMOVE_NORMAL); |
Bin Meng | 4f6c577 | 2016-02-01 01:40:55 -0800 | [diff] [blame] | 86 | if (ret) |
| 87 | return ret; |
| 88 | ret = device_unbind(sdvo); |
| 89 | if (ret) |
| 90 | return ret; |
| 91 | |
Bin Meng | f041c56 | 2016-02-01 01:40:53 -0800 | [diff] [blame] | 92 | return 0; |
Bin Meng | 2f0999e | 2015-10-01 00:36:04 -0700 | [diff] [blame] | 93 | } |
| 94 | |
Bin Meng | 08e484c | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 95 | int arch_cpu_init(void) |
| 96 | { |
| 97 | post_code(POST_CPU_INIT); |
Bin Meng | 08e484c | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 98 | |
Masahiro Yamada | 1710321 | 2016-09-06 22:17:36 +0900 | [diff] [blame] | 99 | return x86_cpu_init_f(); |
Bin Meng | 08e484c | 2014-12-17 15:50:36 +0800 | [diff] [blame] | 100 | } |
Bin Meng | 1530536 | 2015-04-24 18:10:06 +0800 | [diff] [blame] | 101 | |
Bin Meng | 2f0999e | 2015-10-01 00:36:04 -0700 | [diff] [blame] | 102 | int arch_early_init_r(void) |
| 103 | { |
Bin Meng | f041c56 | 2016-02-01 01:40:53 -0800 | [diff] [blame] | 104 | int ret = 0; |
| 105 | |
Bin Meng | 2f0999e | 2015-10-01 00:36:04 -0700 | [diff] [blame] | 106 | #ifdef CONFIG_DISABLE_IGD |
Bin Meng | f041c56 | 2016-02-01 01:40:53 -0800 | [diff] [blame] | 107 | ret = disable_igd(); |
Bin Meng | 2f0999e | 2015-10-01 00:36:04 -0700 | [diff] [blame] | 108 | #endif |
| 109 | |
Bin Meng | f041c56 | 2016-02-01 01:40:53 -0800 | [diff] [blame] | 110 | return ret; |
Bin Meng | 2f0999e | 2015-10-01 00:36:04 -0700 | [diff] [blame] | 111 | } |