Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 2 | /* |
Simon Glass | 0ba553a | 2015-11-29 13:17:46 -0700 | [diff] [blame] | 3 | * PCI autoconfiguration library (legacy version, do not change) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 4 | * |
| 5 | * Author: Matt Porter <mporter@mvista.com> |
| 6 | * |
| 7 | * Copyright 2000 MontaVista Software Inc. |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
Simon Glass | 1c1695b | 2015-01-14 21:37:04 -0700 | [diff] [blame] | 11 | #include <errno.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 12 | #include <log.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 13 | #include <pci.h> |
| 14 | |
Simon Glass | 0ba553a | 2015-11-29 13:17:46 -0700 | [diff] [blame] | 15 | /* |
| 16 | * Do not change this file. Instead, convert your board to use CONFIG_DM_PCI |
| 17 | * and change pci_auto.c. |
| 18 | */ |
| 19 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 20 | /* the user can define CONFIG_SYS_PCI_CACHE_LINE_SIZE to avoid problems */ |
| 21 | #ifndef CONFIG_SYS_PCI_CACHE_LINE_SIZE |
| 22 | #define CONFIG_SYS_PCI_CACHE_LINE_SIZE 8 |
Gary Jennejohn | 9a1263f | 2007-08-31 15:21:46 +0200 | [diff] [blame] | 23 | #endif |
| 24 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 25 | /* |
| 26 | * |
| 27 | */ |
| 28 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 29 | void pciauto_setup_device(struct pci_controller *hose, |
| 30 | pci_dev_t dev, int bars_num, |
| 31 | struct pci_region *mem, |
Kumar Gala | e5ce420 | 2006-01-11 13:24:15 -0600 | [diff] [blame] | 32 | struct pci_region *prefetch, |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 33 | struct pci_region *io) |
| 34 | { |
Kumar Gala | 1873d5c | 2012-09-19 04:47:36 +0000 | [diff] [blame] | 35 | u32 bar_response; |
Kumar Gala | ad714f5 | 2008-10-21 08:36:08 -0500 | [diff] [blame] | 36 | pci_size_t bar_size; |
Andrew Sharp | f4f2482 | 2012-08-01 12:27:16 +0000 | [diff] [blame] | 37 | u16 cmdstat = 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 38 | int bar, bar_nr = 0; |
Bin Meng | 51e98ca | 2015-07-08 13:06:40 +0800 | [diff] [blame] | 39 | u8 header_type; |
| 40 | int rom_addr; |
Andrew Sharp | 61d47ca | 2012-08-29 14:16:32 +0000 | [diff] [blame] | 41 | pci_addr_t bar_value; |
| 42 | struct pci_region *bar_res; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 43 | int found_mem64 = 0; |
Bin Meng | 9dd7c00 | 2015-10-01 00:35:59 -0700 | [diff] [blame] | 44 | u16 class; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 45 | |
Andrew Sharp | f4f2482 | 2012-08-01 12:27:16 +0000 | [diff] [blame] | 46 | pci_hose_read_config_word(hose, dev, PCI_COMMAND, &cmdstat); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 47 | cmdstat = (cmdstat & ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY)) | PCI_COMMAND_MASTER; |
| 48 | |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame] | 49 | for (bar = PCI_BASE_ADDRESS_0; |
| 50 | bar < PCI_BASE_ADDRESS_0 + (bars_num * 4); bar += 4) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 51 | /* Tickle the BAR and get the response */ |
| 52 | pci_hose_write_config_dword(hose, dev, bar, 0xffffffff); |
| 53 | pci_hose_read_config_dword(hose, dev, bar, &bar_response); |
| 54 | |
| 55 | /* If BAR is not implemented go to the next BAR */ |
| 56 | if (!bar_response) |
| 57 | continue; |
| 58 | |
| 59 | found_mem64 = 0; |
| 60 | |
| 61 | /* Check the BAR type and set our address mask */ |
wdenk | 56ed43e | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 62 | if (bar_response & PCI_BASE_ADDRESS_SPACE) { |
Jin Zhengxiong-R64188 | f4ff3e8 | 2006-06-27 18:12:02 +0800 | [diff] [blame] | 63 | bar_size = ((~(bar_response & PCI_BASE_ADDRESS_IO_MASK)) |
| 64 | & 0xffff) + 1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 65 | bar_res = io; |
| 66 | |
Simon Glass | 927c104 | 2015-07-31 09:31:33 -0600 | [diff] [blame] | 67 | debug("PCI Autoconfig: BAR %d, I/O, size=0x%llx, ", |
| 68 | bar_nr, (unsigned long long)bar_size); |
wdenk | 56ed43e | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 69 | } else { |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame] | 70 | if ((bar_response & PCI_BASE_ADDRESS_MEM_TYPE_MASK) == |
Kumar Gala | ad714f5 | 2008-10-21 08:36:08 -0500 | [diff] [blame] | 71 | PCI_BASE_ADDRESS_MEM_TYPE_64) { |
| 72 | u32 bar_response_upper; |
| 73 | u64 bar64; |
Andrew Sharp | 61d47ca | 2012-08-29 14:16:32 +0000 | [diff] [blame] | 74 | |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame] | 75 | pci_hose_write_config_dword(hose, dev, bar + 4, |
| 76 | 0xffffffff); |
| 77 | pci_hose_read_config_dword(hose, dev, bar + 4, |
| 78 | &bar_response_upper); |
Kumar Gala | ad714f5 | 2008-10-21 08:36:08 -0500 | [diff] [blame] | 79 | |
| 80 | bar64 = ((u64)bar_response_upper << 32) | bar_response; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 81 | |
Kumar Gala | ad714f5 | 2008-10-21 08:36:08 -0500 | [diff] [blame] | 82 | bar_size = ~(bar64 & PCI_BASE_ADDRESS_MEM_MASK) + 1; |
| 83 | found_mem64 = 1; |
| 84 | } else { |
| 85 | bar_size = (u32)(~(bar_response & PCI_BASE_ADDRESS_MEM_MASK) + 1); |
| 86 | } |
Kumar Gala | e5ce420 | 2006-01-11 13:24:15 -0600 | [diff] [blame] | 87 | if (prefetch && (bar_response & PCI_BASE_ADDRESS_MEM_PREFETCH)) |
| 88 | bar_res = prefetch; |
| 89 | else |
| 90 | bar_res = mem; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 91 | |
Simon Glass | a292d2a | 2015-07-27 15:47:18 -0600 | [diff] [blame] | 92 | debug("PCI Autoconfig: BAR %d, %s, size=0x%llx, ", |
| 93 | bar_nr, bar_res == prefetch ? "Prf" : "Mem", |
| 94 | (unsigned long long)bar_size); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 95 | } |
| 96 | |
Tuomas Tynkkynen | f20b718 | 2018-05-14 19:38:13 +0300 | [diff] [blame] | 97 | if (pciauto_region_allocate(bar_res, bar_size, |
| 98 | &bar_value, found_mem64) == 0) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 99 | /* Write it out and update our limit */ |
Kumar Gala | ad714f5 | 2008-10-21 08:36:08 -0500 | [diff] [blame] | 100 | pci_hose_write_config_dword(hose, dev, bar, (u32)bar_value); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 101 | |
wdenk | 56ed43e | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 102 | if (found_mem64) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 103 | bar += 4; |
Kumar Gala | ad714f5 | 2008-10-21 08:36:08 -0500 | [diff] [blame] | 104 | #ifdef CONFIG_SYS_PCI_64BIT |
| 105 | pci_hose_write_config_dword(hose, dev, bar, (u32)(bar_value>>32)); |
| 106 | #else |
| 107 | /* |
| 108 | * If we are a 64-bit decoder then increment to the |
| 109 | * upper 32 bits of the bar and force it to locate |
| 110 | * in the lower 4GB of memory. |
| 111 | */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 112 | pci_hose_write_config_dword(hose, dev, bar, 0x00000000); |
Kumar Gala | ad714f5 | 2008-10-21 08:36:08 -0500 | [diff] [blame] | 113 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 114 | } |
| 115 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 116 | } |
Andrew Sharp | 61d47ca | 2012-08-29 14:16:32 +0000 | [diff] [blame] | 117 | cmdstat |= (bar_response & PCI_BASE_ADDRESS_SPACE) ? |
| 118 | PCI_COMMAND_IO : PCI_COMMAND_MEMORY; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 119 | |
Simon Glass | 927c104 | 2015-07-31 09:31:33 -0600 | [diff] [blame] | 120 | debug("\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 121 | |
| 122 | bar_nr++; |
| 123 | } |
| 124 | |
Bin Meng | 51e98ca | 2015-07-08 13:06:40 +0800 | [diff] [blame] | 125 | /* Configure the expansion ROM address */ |
| 126 | pci_hose_read_config_byte(hose, dev, PCI_HEADER_TYPE, &header_type); |
Bin Meng | e8bd746 | 2015-10-07 02:13:18 -0700 | [diff] [blame] | 127 | header_type &= 0x7f; |
Bin Meng | 51e98ca | 2015-07-08 13:06:40 +0800 | [diff] [blame] | 128 | if (header_type != PCI_HEADER_TYPE_CARDBUS) { |
| 129 | rom_addr = (header_type == PCI_HEADER_TYPE_NORMAL) ? |
| 130 | PCI_ROM_ADDRESS : PCI_ROM_ADDRESS1; |
| 131 | pci_hose_write_config_dword(hose, dev, rom_addr, 0xfffffffe); |
| 132 | pci_hose_read_config_dword(hose, dev, rom_addr, &bar_response); |
| 133 | if (bar_response) { |
| 134 | bar_size = -(bar_response & ~1); |
Simon Glass | 927c104 | 2015-07-31 09:31:33 -0600 | [diff] [blame] | 135 | debug("PCI Autoconfig: ROM, size=%#x, ", |
| 136 | (unsigned int)bar_size); |
Bin Meng | 51e98ca | 2015-07-08 13:06:40 +0800 | [diff] [blame] | 137 | if (pciauto_region_allocate(mem, bar_size, |
Tuomas Tynkkynen | f20b718 | 2018-05-14 19:38:13 +0300 | [diff] [blame] | 138 | &bar_value, false) == 0) { |
Bin Meng | 51e98ca | 2015-07-08 13:06:40 +0800 | [diff] [blame] | 139 | pci_hose_write_config_dword(hose, dev, rom_addr, |
| 140 | bar_value); |
| 141 | } |
| 142 | cmdstat |= PCI_COMMAND_MEMORY; |
Simon Glass | 927c104 | 2015-07-31 09:31:33 -0600 | [diff] [blame] | 143 | debug("\n"); |
Bin Meng | 51e98ca | 2015-07-08 13:06:40 +0800 | [diff] [blame] | 144 | } |
| 145 | } |
| 146 | |
Bin Meng | 9dd7c00 | 2015-10-01 00:35:59 -0700 | [diff] [blame] | 147 | /* PCI_COMMAND_IO must be set for VGA device */ |
| 148 | pci_hose_read_config_word(hose, dev, PCI_CLASS_DEVICE, &class); |
| 149 | if (class == PCI_CLASS_DISPLAY_VGA) |
| 150 | cmdstat |= PCI_COMMAND_IO; |
| 151 | |
Andrew Sharp | f4f2482 | 2012-08-01 12:27:16 +0000 | [diff] [blame] | 152 | pci_hose_write_config_word(hose, dev, PCI_COMMAND, cmdstat); |
Gary Jennejohn | 9a1263f | 2007-08-31 15:21:46 +0200 | [diff] [blame] | 153 | pci_hose_write_config_byte(hose, dev, PCI_CACHE_LINE_SIZE, |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 154 | CONFIG_SYS_PCI_CACHE_LINE_SIZE); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 155 | pci_hose_write_config_byte(hose, dev, PCI_LATENCY_TIMER, 0x80); |
| 156 | } |
| 157 | |
Ed Swarthout | a523296 | 2007-07-11 14:51:48 -0500 | [diff] [blame] | 158 | void pciauto_prescan_setup_bridge(struct pci_controller *hose, |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 159 | pci_dev_t dev, int sub_bus) |
| 160 | { |
Bin Meng | 3916409 | 2015-07-19 00:20:06 +0800 | [diff] [blame] | 161 | struct pci_region *pci_mem; |
| 162 | struct pci_region *pci_prefetch; |
| 163 | struct pci_region *pci_io; |
David Feng | 3be54fd | 2015-02-02 16:53:13 +0800 | [diff] [blame] | 164 | u16 cmdstat, prefechable_64; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 165 | |
Bin Meng | 3916409 | 2015-07-19 00:20:06 +0800 | [diff] [blame] | 166 | pci_mem = hose->pci_mem; |
| 167 | pci_prefetch = hose->pci_prefetch; |
| 168 | pci_io = hose->pci_io; |
Bin Meng | 3916409 | 2015-07-19 00:20:06 +0800 | [diff] [blame] | 169 | |
Andrew Sharp | f4f2482 | 2012-08-01 12:27:16 +0000 | [diff] [blame] | 170 | pci_hose_read_config_word(hose, dev, PCI_COMMAND, &cmdstat); |
David Feng | 3be54fd | 2015-02-02 16:53:13 +0800 | [diff] [blame] | 171 | pci_hose_read_config_word(hose, dev, PCI_PREF_MEMORY_BASE, |
| 172 | &prefechable_64); |
| 173 | prefechable_64 &= PCI_PREF_RANGE_TYPE_MASK; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 174 | |
| 175 | /* Configure bus number registers */ |
Ed Swarthout | 4aeb55a | 2007-07-11 14:52:08 -0500 | [diff] [blame] | 176 | pci_hose_write_config_byte(hose, dev, PCI_PRIMARY_BUS, |
| 177 | PCI_BUS(dev) - hose->first_busno); |
| 178 | pci_hose_write_config_byte(hose, dev, PCI_SECONDARY_BUS, |
| 179 | sub_bus - hose->first_busno); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 180 | pci_hose_write_config_byte(hose, dev, PCI_SUBORDINATE_BUS, 0xff); |
| 181 | |
wdenk | 56ed43e | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 182 | if (pci_mem) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 183 | /* Round memory allocator to 1MB boundary */ |
| 184 | pciauto_region_align(pci_mem, 0x100000); |
| 185 | |
| 186 | /* Set up memory and I/O filter limits, assume 32-bit I/O space */ |
| 187 | pci_hose_write_config_word(hose, dev, PCI_MEMORY_BASE, |
| 188 | (pci_mem->bus_lower & 0xfff00000) >> 16); |
| 189 | |
| 190 | cmdstat |= PCI_COMMAND_MEMORY; |
| 191 | } |
| 192 | |
Kumar Gala | e5ce420 | 2006-01-11 13:24:15 -0600 | [diff] [blame] | 193 | if (pci_prefetch) { |
| 194 | /* Round memory allocator to 1MB boundary */ |
| 195 | pciauto_region_align(pci_prefetch, 0x100000); |
| 196 | |
| 197 | /* Set up memory and I/O filter limits, assume 32-bit I/O space */ |
| 198 | pci_hose_write_config_word(hose, dev, PCI_PREF_MEMORY_BASE, |
| 199 | (pci_prefetch->bus_lower & 0xfff00000) >> 16); |
David Feng | 3be54fd | 2015-02-02 16:53:13 +0800 | [diff] [blame] | 200 | if (prefechable_64 == PCI_PREF_RANGE_TYPE_64) |
| 201 | #ifdef CONFIG_SYS_PCI_64BIT |
| 202 | pci_hose_write_config_dword(hose, dev, |
| 203 | PCI_PREF_BASE_UPPER32, |
| 204 | pci_prefetch->bus_lower >> 32); |
| 205 | #else |
| 206 | pci_hose_write_config_dword(hose, dev, |
| 207 | PCI_PREF_BASE_UPPER32, |
| 208 | 0x0); |
| 209 | #endif |
Kumar Gala | e5ce420 | 2006-01-11 13:24:15 -0600 | [diff] [blame] | 210 | |
| 211 | cmdstat |= PCI_COMMAND_MEMORY; |
| 212 | } else { |
| 213 | /* We don't support prefetchable memory for now, so disable */ |
| 214 | pci_hose_write_config_word(hose, dev, PCI_PREF_MEMORY_BASE, 0x1000); |
Matthew McClintock | 2f43f33 | 2006-06-28 10:44:23 -0500 | [diff] [blame] | 215 | pci_hose_write_config_word(hose, dev, PCI_PREF_MEMORY_LIMIT, 0x0); |
David Feng | 3be54fd | 2015-02-02 16:53:13 +0800 | [diff] [blame] | 216 | if (prefechable_64 == PCI_PREF_RANGE_TYPE_64) { |
| 217 | pci_hose_write_config_word(hose, dev, PCI_PREF_BASE_UPPER32, 0x0); |
| 218 | pci_hose_write_config_word(hose, dev, PCI_PREF_LIMIT_UPPER32, 0x0); |
| 219 | } |
Kumar Gala | e5ce420 | 2006-01-11 13:24:15 -0600 | [diff] [blame] | 220 | } |
| 221 | |
wdenk | 56ed43e | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 222 | if (pci_io) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 223 | /* Round I/O allocator to 4KB boundary */ |
| 224 | pciauto_region_align(pci_io, 0x1000); |
| 225 | |
| 226 | pci_hose_write_config_byte(hose, dev, PCI_IO_BASE, |
| 227 | (pci_io->bus_lower & 0x0000f000) >> 8); |
| 228 | pci_hose_write_config_word(hose, dev, PCI_IO_BASE_UPPER16, |
| 229 | (pci_io->bus_lower & 0xffff0000) >> 16); |
| 230 | |
| 231 | cmdstat |= PCI_COMMAND_IO; |
| 232 | } |
| 233 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 234 | /* Enable memory and I/O accesses, enable bus master */ |
Andrew Sharp | f4f2482 | 2012-08-01 12:27:16 +0000 | [diff] [blame] | 235 | pci_hose_write_config_word(hose, dev, PCI_COMMAND, |
| 236 | cmdstat | PCI_COMMAND_MASTER); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 237 | } |
| 238 | |
Ed Swarthout | a523296 | 2007-07-11 14:51:48 -0500 | [diff] [blame] | 239 | void pciauto_postscan_setup_bridge(struct pci_controller *hose, |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 240 | pci_dev_t dev, int sub_bus) |
| 241 | { |
Bin Meng | 3916409 | 2015-07-19 00:20:06 +0800 | [diff] [blame] | 242 | struct pci_region *pci_mem; |
| 243 | struct pci_region *pci_prefetch; |
| 244 | struct pci_region *pci_io; |
| 245 | |
Bin Meng | 3916409 | 2015-07-19 00:20:06 +0800 | [diff] [blame] | 246 | pci_mem = hose->pci_mem; |
| 247 | pci_prefetch = hose->pci_prefetch; |
| 248 | pci_io = hose->pci_io; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 249 | |
| 250 | /* Configure bus number registers */ |
Ed Swarthout | 4aeb55a | 2007-07-11 14:52:08 -0500 | [diff] [blame] | 251 | pci_hose_write_config_byte(hose, dev, PCI_SUBORDINATE_BUS, |
| 252 | sub_bus - hose->first_busno); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 253 | |
wdenk | 56ed43e | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 254 | if (pci_mem) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 255 | /* Round memory allocator to 1MB boundary */ |
| 256 | pciauto_region_align(pci_mem, 0x100000); |
| 257 | |
| 258 | pci_hose_write_config_word(hose, dev, PCI_MEMORY_LIMIT, |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame] | 259 | (pci_mem->bus_lower - 1) >> 16); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 260 | } |
| 261 | |
Kumar Gala | e5ce420 | 2006-01-11 13:24:15 -0600 | [diff] [blame] | 262 | if (pci_prefetch) { |
David Feng | 3be54fd | 2015-02-02 16:53:13 +0800 | [diff] [blame] | 263 | u16 prefechable_64; |
| 264 | |
| 265 | pci_hose_read_config_word(hose, dev, |
| 266 | PCI_PREF_MEMORY_LIMIT, |
| 267 | &prefechable_64); |
| 268 | prefechable_64 &= PCI_PREF_RANGE_TYPE_MASK; |
| 269 | |
Kumar Gala | e5ce420 | 2006-01-11 13:24:15 -0600 | [diff] [blame] | 270 | /* Round memory allocator to 1MB boundary */ |
| 271 | pciauto_region_align(pci_prefetch, 0x100000); |
| 272 | |
| 273 | pci_hose_write_config_word(hose, dev, PCI_PREF_MEMORY_LIMIT, |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame] | 274 | (pci_prefetch->bus_lower - 1) >> 16); |
David Feng | 3be54fd | 2015-02-02 16:53:13 +0800 | [diff] [blame] | 275 | if (prefechable_64 == PCI_PREF_RANGE_TYPE_64) |
| 276 | #ifdef CONFIG_SYS_PCI_64BIT |
| 277 | pci_hose_write_config_dword(hose, dev, |
| 278 | PCI_PREF_LIMIT_UPPER32, |
| 279 | (pci_prefetch->bus_lower - 1) >> 32); |
| 280 | #else |
| 281 | pci_hose_write_config_dword(hose, dev, |
| 282 | PCI_PREF_LIMIT_UPPER32, |
| 283 | 0x0); |
| 284 | #endif |
Kumar Gala | e5ce420 | 2006-01-11 13:24:15 -0600 | [diff] [blame] | 285 | } |
| 286 | |
wdenk | 56ed43e | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 287 | if (pci_io) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 288 | /* Round I/O allocator to 4KB boundary */ |
| 289 | pciauto_region_align(pci_io, 0x1000); |
| 290 | |
| 291 | pci_hose_write_config_byte(hose, dev, PCI_IO_LIMIT, |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame] | 292 | ((pci_io->bus_lower - 1) & 0x0000f000) >> 8); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 293 | pci_hose_write_config_word(hose, dev, PCI_IO_LIMIT_UPPER16, |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame] | 294 | ((pci_io->bus_lower - 1) & 0xffff0000) >> 16); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 295 | } |
| 296 | } |
| 297 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 298 | |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame] | 299 | /* |
| 300 | * HJF: Changed this to return int. I think this is required |
wdenk | 452cfd6 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 301 | * to get the correct result when scanning bridges |
| 302 | */ |
| 303 | int pciauto_config_device(struct pci_controller *hose, pci_dev_t dev) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 304 | { |
Bin Meng | 3916409 | 2015-07-19 00:20:06 +0800 | [diff] [blame] | 305 | struct pci_region *pci_mem; |
| 306 | struct pci_region *pci_prefetch; |
| 307 | struct pci_region *pci_io; |
wdenk | 452cfd6 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 308 | unsigned int sub_bus = PCI_BUS(dev); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 309 | unsigned short class; |
wdenk | 2cefd15 | 2004-02-08 22:55:38 +0000 | [diff] [blame] | 310 | int n; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 311 | |
Bin Meng | 3916409 | 2015-07-19 00:20:06 +0800 | [diff] [blame] | 312 | pci_mem = hose->pci_mem; |
| 313 | pci_prefetch = hose->pci_prefetch; |
| 314 | pci_io = hose->pci_io; |
Bin Meng | 3916409 | 2015-07-19 00:20:06 +0800 | [diff] [blame] | 315 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 316 | pci_hose_read_config_word(hose, dev, PCI_CLASS_DEVICE, &class); |
| 317 | |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame] | 318 | switch (class) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 319 | case PCI_CLASS_BRIDGE_PCI: |
Simon Glass | 927c104 | 2015-07-31 09:31:33 -0600 | [diff] [blame] | 320 | debug("PCI Autoconfig: Found P2P bridge, device %d\n", |
| 321 | PCI_DEV(dev)); |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 322 | |
Bin Meng | 3916409 | 2015-07-19 00:20:06 +0800 | [diff] [blame] | 323 | pciauto_setup_device(hose, dev, 2, pci_mem, |
| 324 | pci_prefetch, pci_io); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 325 | |
wdenk | 56ed43e | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 326 | /* Passing in current_busno allows for sibling P2P bridges */ |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 327 | hose->current_busno++; |
wdenk | 2cefd15 | 2004-02-08 22:55:38 +0000 | [diff] [blame] | 328 | pciauto_prescan_setup_bridge(hose, dev, hose->current_busno); |
wdenk | 6cfa84e | 2004-02-10 00:03:41 +0000 | [diff] [blame] | 329 | /* |
wdenk | 56ed43e | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 330 | * need to figure out if this is a subordinate bridge on the bus |
wdenk | 2cefd15 | 2004-02-08 22:55:38 +0000 | [diff] [blame] | 331 | * to be able to properly set the pri/sec/sub bridge registers. |
| 332 | */ |
| 333 | n = pci_hose_scan_bus(hose, hose->current_busno); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 334 | |
wdenk | 56ed43e | 2004-02-22 23:46:08 +0000 | [diff] [blame] | 335 | /* figure out the deepest we've gone for this leg */ |
Masahiro Yamada | db20464 | 2014-11-07 03:03:31 +0900 | [diff] [blame] | 336 | sub_bus = max((unsigned int)n, sub_bus); |
wdenk | b666c8f | 2003-03-06 00:58:30 +0000 | [diff] [blame] | 337 | pciauto_postscan_setup_bridge(hose, dev, sub_bus); |
wdenk | 2cefd15 | 2004-02-08 22:55:38 +0000 | [diff] [blame] | 338 | |
wdenk | b666c8f | 2003-03-06 00:58:30 +0000 | [diff] [blame] | 339 | sub_bus = hose->current_busno; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 340 | break; |
| 341 | |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 342 | case PCI_CLASS_BRIDGE_CARDBUS: |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame] | 343 | /* |
| 344 | * just do a minimal setup of the bridge, |
| 345 | * let the OS take care of the rest |
| 346 | */ |
Bin Meng | 3916409 | 2015-07-19 00:20:06 +0800 | [diff] [blame] | 347 | pciauto_setup_device(hose, dev, 0, pci_mem, |
| 348 | pci_prefetch, pci_io); |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 349 | |
Simon Glass | 927c104 | 2015-07-31 09:31:33 -0600 | [diff] [blame] | 350 | debug("PCI Autoconfig: Found P2CardBus bridge, device %d\n", |
| 351 | PCI_DEV(dev)); |
wdenk | 1fe2c70 | 2003-03-06 21:55:29 +0000 | [diff] [blame] | 352 | |
| 353 | hose->current_busno++; |
| 354 | break; |
| 355 | |
TsiChung Liew | 521f97b | 2008-03-30 01:19:06 -0500 | [diff] [blame] | 356 | #if defined(CONFIG_PCIAUTO_SKIP_HOST_BRIDGE) |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 357 | case PCI_CLASS_BRIDGE_OTHER: |
Simon Glass | 927c104 | 2015-07-31 09:31:33 -0600 | [diff] [blame] | 358 | debug("PCI Autoconfig: Skipping bridge device %d\n", |
| 359 | PCI_DEV(dev)); |
wdenk | 5d84173 | 2003-08-17 18:55:18 +0000 | [diff] [blame] | 360 | break; |
| 361 | #endif |
Mario Six | a83f549 | 2019-01-21 09:17:38 +0100 | [diff] [blame] | 362 | #if defined(CONFIG_ARCH_MPC834X) && !defined(CONFIG_TARGET_VME8349) && \ |
| 363 | !defined(CONFIG_TARGET_CADDY2) |
Rafal Jaworowski | 384da5e | 2005-10-17 02:39:53 +0200 | [diff] [blame] | 364 | case PCI_CLASS_BRIDGE_OTHER: |
| 365 | /* |
| 366 | * The host/PCI bridge 1 seems broken in 8349 - it presents |
| 367 | * itself as 'PCI_CLASS_BRIDGE_OTHER' and appears as an _agent_ |
| 368 | * device claiming resources io/mem/irq.. we only allow for |
| 369 | * the PIMMR window to be allocated (BAR0 - 1MB size) |
| 370 | */ |
Simon Glass | 927c104 | 2015-07-31 09:31:33 -0600 | [diff] [blame] | 371 | debug("PCI Autoconfig: Broken bridge found, only minimal config\n"); |
Andrew Sharp | 6870513 | 2012-08-29 14:16:29 +0000 | [diff] [blame] | 372 | pciauto_setup_device(hose, dev, 0, hose->pci_mem, |
| 373 | hose->pci_prefetch, hose->pci_io); |
Rafal Jaworowski | 384da5e | 2005-10-17 02:39:53 +0200 | [diff] [blame] | 374 | break; |
| 375 | #endif |
Andrew Sharp | 61d47ca | 2012-08-29 14:16:32 +0000 | [diff] [blame] | 376 | |
| 377 | case PCI_CLASS_PROCESSOR_POWERPC: /* an agent or end-point */ |
Simon Glass | 927c104 | 2015-07-31 09:31:33 -0600 | [diff] [blame] | 378 | debug("PCI AutoConfig: Found PowerPC device\n"); |
Andrew Sharp | 61d47ca | 2012-08-29 14:16:32 +0000 | [diff] [blame] | 379 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 380 | default: |
Bin Meng | 3916409 | 2015-07-19 00:20:06 +0800 | [diff] [blame] | 381 | pciauto_setup_device(hose, dev, 6, pci_mem, |
| 382 | pci_prefetch, pci_io); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 383 | break; |
| 384 | } |
wdenk | 452cfd6 | 2002-11-19 11:04:11 +0000 | [diff] [blame] | 385 | |
| 386 | return sub_bus; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 387 | } |