Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014 Google, Inc |
| 4 | * Written by Simon Glass <sjg@chromium.org> |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
Patrick Delaunay | 8131335 | 2021-04-27 11:02:19 +0200 | [diff] [blame] | 7 | #define LOG_CATEGORY UCLASS_PCI |
| 8 | |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 9 | #include <common.h> |
| 10 | #include <dm.h> |
| 11 | #include <errno.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 12 | #include <init.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 13 | #include <log.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 14 | #include <malloc.h> |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 15 | #include <pci.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 16 | #include <asm/global_data.h> |
Simon Glass | c5f053b | 2015-11-29 13:18:03 -0700 | [diff] [blame] | 17 | #include <asm/io.h> |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 18 | #include <dm/device-internal.h> |
Simon Glass | 89d8323 | 2017-05-18 20:09:51 -0600 | [diff] [blame] | 19 | #include <dm/lists.h> |
Simon Glass | be70610 | 2020-12-16 21:20:18 -0700 | [diff] [blame] | 20 | #include <dm/uclass-internal.h> |
Bin Meng | c0820a4 | 2015-08-20 06:40:23 -0700 | [diff] [blame] | 21 | #if defined(CONFIG_X86) && defined(CONFIG_HAVE_FSP) |
Simon Glass | ef8a2dd | 2019-08-24 14:19:05 -0600 | [diff] [blame] | 22 | #include <asm/fsp/fsp_support.h> |
Bin Meng | c0820a4 | 2015-08-20 06:40:23 -0700 | [diff] [blame] | 23 | #endif |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 24 | #include <linux/delay.h> |
Simon Glass | 37a3f94b | 2015-11-29 13:17:49 -0700 | [diff] [blame] | 25 | #include "pci_internal.h" |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 26 | |
| 27 | DECLARE_GLOBAL_DATA_PTR; |
| 28 | |
Simon Glass | 2e4e443 | 2016-01-18 20:19:14 -0700 | [diff] [blame] | 29 | int pci_get_bus(int busnum, struct udevice **busp) |
Simon Glass | 7d07e59 | 2015-08-31 18:55:35 -0600 | [diff] [blame] | 30 | { |
| 31 | int ret; |
| 32 | |
| 33 | ret = uclass_get_device_by_seq(UCLASS_PCI, busnum, busp); |
| 34 | |
| 35 | /* Since buses may not be numbered yet try a little harder with bus 0 */ |
| 36 | if (ret == -ENODEV) { |
Simon Glass | c7298e7 | 2016-02-11 13:23:26 -0700 | [diff] [blame] | 37 | ret = uclass_first_device_err(UCLASS_PCI, busp); |
Simon Glass | 7d07e59 | 2015-08-31 18:55:35 -0600 | [diff] [blame] | 38 | if (ret) |
| 39 | return ret; |
Simon Glass | 7d07e59 | 2015-08-31 18:55:35 -0600 | [diff] [blame] | 40 | ret = uclass_get_device_by_seq(UCLASS_PCI, busnum, busp); |
| 41 | } |
| 42 | |
| 43 | return ret; |
| 44 | } |
| 45 | |
Simon Glass | 6256d67 | 2015-11-19 20:27:00 -0700 | [diff] [blame] | 46 | struct udevice *pci_get_controller(struct udevice *dev) |
| 47 | { |
| 48 | while (device_is_on_pci_bus(dev)) |
| 49 | dev = dev->parent; |
| 50 | |
| 51 | return dev; |
| 52 | } |
| 53 | |
Simon Glass | c92aac1 | 2020-01-27 08:49:38 -0700 | [diff] [blame] | 54 | pci_dev_t dm_pci_get_bdf(const struct udevice *dev) |
Simon Glass | c9118d4 | 2015-07-06 16:47:46 -0600 | [diff] [blame] | 55 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 56 | struct pci_child_plat *pplat = dev_get_parent_plat(dev); |
Simon Glass | c9118d4 | 2015-07-06 16:47:46 -0600 | [diff] [blame] | 57 | struct udevice *bus = dev->parent; |
| 58 | |
Simon Glass | 1c6449c | 2019-12-29 21:19:14 -0700 | [diff] [blame] | 59 | /* |
| 60 | * This error indicates that @dev is a device on an unprobed PCI bus. |
| 61 | * The bus likely has bus=seq == -1, so the PCI_ADD_BUS() macro below |
| 62 | * will produce a bad BDF> |
| 63 | * |
| 64 | * A common cause of this problem is that this function is called in the |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 65 | * of_to_plat() method of @dev. Accessing the PCI bus in that |
Simon Glass | 1c6449c | 2019-12-29 21:19:14 -0700 | [diff] [blame] | 66 | * method is not allowed, since it has not yet been probed. To fix this, |
| 67 | * move that access to the probe() method of @dev instead. |
| 68 | */ |
| 69 | if (!device_active(bus)) |
| 70 | log_err("PCI: Device '%s' on unprobed bus '%s'\n", dev->name, |
| 71 | bus->name); |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 72 | return PCI_ADD_BUS(dev_seq(bus), pplat->devfn); |
Simon Glass | c9118d4 | 2015-07-06 16:47:46 -0600 | [diff] [blame] | 73 | } |
| 74 | |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 75 | /** |
| 76 | * pci_get_bus_max() - returns the bus number of the last active bus |
| 77 | * |
| 78 | * @return last bus number, or -1 if no active buses |
| 79 | */ |
| 80 | static int pci_get_bus_max(void) |
| 81 | { |
| 82 | struct udevice *bus; |
| 83 | struct uclass *uc; |
| 84 | int ret = -1; |
| 85 | |
| 86 | ret = uclass_get(UCLASS_PCI, &uc); |
| 87 | uclass_foreach_dev(bus, uc) { |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 88 | if (dev_seq(bus) > ret) |
| 89 | ret = dev_seq(bus); |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | debug("%s: ret=%d\n", __func__, ret); |
| 93 | |
| 94 | return ret; |
| 95 | } |
| 96 | |
| 97 | int pci_last_busno(void) |
| 98 | { |
Bin Meng | 5bc3f8a | 2015-10-01 00:36:01 -0700 | [diff] [blame] | 99 | return pci_get_bus_max(); |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | int pci_get_ff(enum pci_size_t size) |
| 103 | { |
| 104 | switch (size) { |
| 105 | case PCI_SIZE_8: |
| 106 | return 0xff; |
| 107 | case PCI_SIZE_16: |
| 108 | return 0xffff; |
| 109 | default: |
| 110 | return 0xffffffff; |
| 111 | } |
| 112 | } |
| 113 | |
Marek Vasut | b453579 | 2018-10-10 21:27:06 +0200 | [diff] [blame] | 114 | static void pci_dev_find_ofnode(struct udevice *bus, phys_addr_t bdf, |
| 115 | ofnode *rnode) |
| 116 | { |
| 117 | struct fdt_pci_addr addr; |
| 118 | ofnode node; |
| 119 | int ret; |
| 120 | |
| 121 | dev_for_each_subnode(node, bus) { |
| 122 | ret = ofnode_read_pci_addr(node, FDT_PCI_SPACE_CONFIG, "reg", |
| 123 | &addr); |
| 124 | if (ret) |
| 125 | continue; |
| 126 | |
| 127 | if (PCI_MASK_BUS(addr.phys_hi) != PCI_MASK_BUS(bdf)) |
| 128 | continue; |
| 129 | |
| 130 | *rnode = node; |
| 131 | break; |
| 132 | } |
| 133 | }; |
| 134 | |
Simon Glass | 2a311e8 | 2020-01-27 08:49:37 -0700 | [diff] [blame] | 135 | int pci_bus_find_devfn(const struct udevice *bus, pci_dev_t find_devfn, |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 136 | struct udevice **devp) |
| 137 | { |
| 138 | struct udevice *dev; |
| 139 | |
| 140 | for (device_find_first_child(bus, &dev); |
| 141 | dev; |
| 142 | device_find_next_child(&dev)) { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 143 | struct pci_child_plat *pplat; |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 144 | |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 145 | pplat = dev_get_parent_plat(dev); |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 146 | if (pplat && pplat->devfn == find_devfn) { |
| 147 | *devp = dev; |
| 148 | return 0; |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | return -ENODEV; |
| 153 | } |
| 154 | |
Simon Glass | 84283d5 | 2015-11-29 13:17:48 -0700 | [diff] [blame] | 155 | int dm_pci_bus_find_bdf(pci_dev_t bdf, struct udevice **devp) |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 156 | { |
| 157 | struct udevice *bus; |
| 158 | int ret; |
| 159 | |
Simon Glass | 7d07e59 | 2015-08-31 18:55:35 -0600 | [diff] [blame] | 160 | ret = pci_get_bus(PCI_BUS(bdf), &bus); |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 161 | if (ret) |
| 162 | return ret; |
| 163 | return pci_bus_find_devfn(bus, PCI_MASK_BUS(bdf), devp); |
| 164 | } |
| 165 | |
| 166 | static int pci_device_matches_ids(struct udevice *dev, |
| 167 | struct pci_device_id *ids) |
| 168 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 169 | struct pci_child_plat *pplat; |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 170 | int i; |
| 171 | |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 172 | pplat = dev_get_parent_plat(dev); |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 173 | if (!pplat) |
| 174 | return -EINVAL; |
| 175 | for (i = 0; ids[i].vendor != 0; i++) { |
| 176 | if (pplat->vendor == ids[i].vendor && |
| 177 | pplat->device == ids[i].device) |
| 178 | return i; |
| 179 | } |
| 180 | |
| 181 | return -EINVAL; |
| 182 | } |
| 183 | |
| 184 | int pci_bus_find_devices(struct udevice *bus, struct pci_device_id *ids, |
| 185 | int *indexp, struct udevice **devp) |
| 186 | { |
| 187 | struct udevice *dev; |
| 188 | |
| 189 | /* Scan all devices on this bus */ |
| 190 | for (device_find_first_child(bus, &dev); |
| 191 | dev; |
| 192 | device_find_next_child(&dev)) { |
| 193 | if (pci_device_matches_ids(dev, ids) >= 0) { |
| 194 | if ((*indexp)-- <= 0) { |
| 195 | *devp = dev; |
| 196 | return 0; |
| 197 | } |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | return -ENODEV; |
| 202 | } |
| 203 | |
| 204 | int pci_find_device_id(struct pci_device_id *ids, int index, |
| 205 | struct udevice **devp) |
| 206 | { |
| 207 | struct udevice *bus; |
| 208 | |
| 209 | /* Scan all known buses */ |
| 210 | for (uclass_first_device(UCLASS_PCI, &bus); |
| 211 | bus; |
| 212 | uclass_next_device(&bus)) { |
| 213 | if (!pci_bus_find_devices(bus, ids, &index, devp)) |
| 214 | return 0; |
| 215 | } |
| 216 | *devp = NULL; |
| 217 | |
| 218 | return -ENODEV; |
| 219 | } |
| 220 | |
Simon Glass | 70e0c58 | 2015-11-29 13:17:50 -0700 | [diff] [blame] | 221 | static int dm_pci_bus_find_device(struct udevice *bus, unsigned int vendor, |
| 222 | unsigned int device, int *indexp, |
| 223 | struct udevice **devp) |
| 224 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 225 | struct pci_child_plat *pplat; |
Simon Glass | 70e0c58 | 2015-11-29 13:17:50 -0700 | [diff] [blame] | 226 | struct udevice *dev; |
| 227 | |
| 228 | for (device_find_first_child(bus, &dev); |
| 229 | dev; |
| 230 | device_find_next_child(&dev)) { |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 231 | pplat = dev_get_parent_plat(dev); |
Simon Glass | 70e0c58 | 2015-11-29 13:17:50 -0700 | [diff] [blame] | 232 | if (pplat->vendor == vendor && pplat->device == device) { |
| 233 | if (!(*indexp)--) { |
| 234 | *devp = dev; |
| 235 | return 0; |
| 236 | } |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | return -ENODEV; |
| 241 | } |
| 242 | |
| 243 | int dm_pci_find_device(unsigned int vendor, unsigned int device, int index, |
| 244 | struct udevice **devp) |
| 245 | { |
| 246 | struct udevice *bus; |
| 247 | |
| 248 | /* Scan all known buses */ |
| 249 | for (uclass_first_device(UCLASS_PCI, &bus); |
| 250 | bus; |
| 251 | uclass_next_device(&bus)) { |
| 252 | if (!dm_pci_bus_find_device(bus, vendor, device, &index, devp)) |
| 253 | return device_probe(*devp); |
| 254 | } |
| 255 | *devp = NULL; |
| 256 | |
| 257 | return -ENODEV; |
| 258 | } |
| 259 | |
Simon Glass | b639d51 | 2015-11-29 13:17:52 -0700 | [diff] [blame] | 260 | int dm_pci_find_class(uint find_class, int index, struct udevice **devp) |
| 261 | { |
| 262 | struct udevice *dev; |
| 263 | |
| 264 | /* Scan all known buses */ |
| 265 | for (pci_find_first_device(&dev); |
| 266 | dev; |
| 267 | pci_find_next_device(&dev)) { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 268 | struct pci_child_plat *pplat = dev_get_parent_plat(dev); |
Simon Glass | b639d51 | 2015-11-29 13:17:52 -0700 | [diff] [blame] | 269 | |
| 270 | if (pplat->class == find_class && !index--) { |
| 271 | *devp = dev; |
| 272 | return device_probe(*devp); |
| 273 | } |
| 274 | } |
| 275 | *devp = NULL; |
| 276 | |
| 277 | return -ENODEV; |
| 278 | } |
| 279 | |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 280 | int pci_bus_write_config(struct udevice *bus, pci_dev_t bdf, int offset, |
| 281 | unsigned long value, enum pci_size_t size) |
| 282 | { |
| 283 | struct dm_pci_ops *ops; |
| 284 | |
| 285 | ops = pci_get_ops(bus); |
| 286 | if (!ops->write_config) |
| 287 | return -ENOSYS; |
| 288 | return ops->write_config(bus, bdf, offset, value, size); |
| 289 | } |
| 290 | |
Simon Glass | 9cec2df | 2016-03-06 19:27:52 -0700 | [diff] [blame] | 291 | int pci_bus_clrset_config32(struct udevice *bus, pci_dev_t bdf, int offset, |
| 292 | u32 clr, u32 set) |
| 293 | { |
| 294 | ulong val; |
| 295 | int ret; |
| 296 | |
| 297 | ret = pci_bus_read_config(bus, bdf, offset, &val, PCI_SIZE_32); |
| 298 | if (ret) |
| 299 | return ret; |
| 300 | val &= ~clr; |
| 301 | val |= set; |
| 302 | |
| 303 | return pci_bus_write_config(bus, bdf, offset, val, PCI_SIZE_32); |
| 304 | } |
| 305 | |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 306 | int pci_write_config(pci_dev_t bdf, int offset, unsigned long value, |
| 307 | enum pci_size_t size) |
| 308 | { |
| 309 | struct udevice *bus; |
| 310 | int ret; |
| 311 | |
Simon Glass | 7d07e59 | 2015-08-31 18:55:35 -0600 | [diff] [blame] | 312 | ret = pci_get_bus(PCI_BUS(bdf), &bus); |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 313 | if (ret) |
| 314 | return ret; |
| 315 | |
Bin Meng | 0a72152 | 2015-07-19 00:20:04 +0800 | [diff] [blame] | 316 | return pci_bus_write_config(bus, bdf, offset, value, size); |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 317 | } |
| 318 | |
Simon Glass | 94ef242 | 2015-08-10 07:05:03 -0600 | [diff] [blame] | 319 | int dm_pci_write_config(struct udevice *dev, int offset, unsigned long value, |
| 320 | enum pci_size_t size) |
| 321 | { |
| 322 | struct udevice *bus; |
| 323 | |
Bin Meng | 05bedb1 | 2015-09-11 03:24:34 -0700 | [diff] [blame] | 324 | for (bus = dev; device_is_on_pci_bus(bus);) |
Simon Glass | 94ef242 | 2015-08-10 07:05:03 -0600 | [diff] [blame] | 325 | bus = bus->parent; |
Simon Glass | eaa1489 | 2015-11-29 13:17:47 -0700 | [diff] [blame] | 326 | return pci_bus_write_config(bus, dm_pci_get_bdf(dev), offset, value, |
| 327 | size); |
Simon Glass | 94ef242 | 2015-08-10 07:05:03 -0600 | [diff] [blame] | 328 | } |
| 329 | |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 330 | int pci_write_config32(pci_dev_t bdf, int offset, u32 value) |
| 331 | { |
| 332 | return pci_write_config(bdf, offset, value, PCI_SIZE_32); |
| 333 | } |
| 334 | |
| 335 | int pci_write_config16(pci_dev_t bdf, int offset, u16 value) |
| 336 | { |
| 337 | return pci_write_config(bdf, offset, value, PCI_SIZE_16); |
| 338 | } |
| 339 | |
| 340 | int pci_write_config8(pci_dev_t bdf, int offset, u8 value) |
| 341 | { |
| 342 | return pci_write_config(bdf, offset, value, PCI_SIZE_8); |
| 343 | } |
| 344 | |
Simon Glass | 94ef242 | 2015-08-10 07:05:03 -0600 | [diff] [blame] | 345 | int dm_pci_write_config8(struct udevice *dev, int offset, u8 value) |
| 346 | { |
| 347 | return dm_pci_write_config(dev, offset, value, PCI_SIZE_8); |
| 348 | } |
| 349 | |
| 350 | int dm_pci_write_config16(struct udevice *dev, int offset, u16 value) |
| 351 | { |
| 352 | return dm_pci_write_config(dev, offset, value, PCI_SIZE_16); |
| 353 | } |
| 354 | |
| 355 | int dm_pci_write_config32(struct udevice *dev, int offset, u32 value) |
| 356 | { |
| 357 | return dm_pci_write_config(dev, offset, value, PCI_SIZE_32); |
| 358 | } |
| 359 | |
Simon Glass | c92aac1 | 2020-01-27 08:49:38 -0700 | [diff] [blame] | 360 | int pci_bus_read_config(const struct udevice *bus, pci_dev_t bdf, int offset, |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 361 | unsigned long *valuep, enum pci_size_t size) |
| 362 | { |
| 363 | struct dm_pci_ops *ops; |
| 364 | |
| 365 | ops = pci_get_ops(bus); |
| 366 | if (!ops->read_config) |
| 367 | return -ENOSYS; |
| 368 | return ops->read_config(bus, bdf, offset, valuep, size); |
| 369 | } |
| 370 | |
| 371 | int pci_read_config(pci_dev_t bdf, int offset, unsigned long *valuep, |
| 372 | enum pci_size_t size) |
| 373 | { |
| 374 | struct udevice *bus; |
| 375 | int ret; |
| 376 | |
Simon Glass | 7d07e59 | 2015-08-31 18:55:35 -0600 | [diff] [blame] | 377 | ret = pci_get_bus(PCI_BUS(bdf), &bus); |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 378 | if (ret) |
| 379 | return ret; |
| 380 | |
Bin Meng | 0a72152 | 2015-07-19 00:20:04 +0800 | [diff] [blame] | 381 | return pci_bus_read_config(bus, bdf, offset, valuep, size); |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 382 | } |
| 383 | |
Simon Glass | c92aac1 | 2020-01-27 08:49:38 -0700 | [diff] [blame] | 384 | int dm_pci_read_config(const struct udevice *dev, int offset, |
| 385 | unsigned long *valuep, enum pci_size_t size) |
Simon Glass | 94ef242 | 2015-08-10 07:05:03 -0600 | [diff] [blame] | 386 | { |
Simon Glass | c92aac1 | 2020-01-27 08:49:38 -0700 | [diff] [blame] | 387 | const struct udevice *bus; |
Simon Glass | 94ef242 | 2015-08-10 07:05:03 -0600 | [diff] [blame] | 388 | |
Bin Meng | 05bedb1 | 2015-09-11 03:24:34 -0700 | [diff] [blame] | 389 | for (bus = dev; device_is_on_pci_bus(bus);) |
Simon Glass | 94ef242 | 2015-08-10 07:05:03 -0600 | [diff] [blame] | 390 | bus = bus->parent; |
Simon Glass | eaa1489 | 2015-11-29 13:17:47 -0700 | [diff] [blame] | 391 | return pci_bus_read_config(bus, dm_pci_get_bdf(dev), offset, valuep, |
Simon Glass | 94ef242 | 2015-08-10 07:05:03 -0600 | [diff] [blame] | 392 | size); |
| 393 | } |
| 394 | |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 395 | int pci_read_config32(pci_dev_t bdf, int offset, u32 *valuep) |
| 396 | { |
| 397 | unsigned long value; |
| 398 | int ret; |
| 399 | |
| 400 | ret = pci_read_config(bdf, offset, &value, PCI_SIZE_32); |
| 401 | if (ret) |
| 402 | return ret; |
| 403 | *valuep = value; |
| 404 | |
| 405 | return 0; |
| 406 | } |
| 407 | |
| 408 | int pci_read_config16(pci_dev_t bdf, int offset, u16 *valuep) |
| 409 | { |
| 410 | unsigned long value; |
| 411 | int ret; |
| 412 | |
| 413 | ret = pci_read_config(bdf, offset, &value, PCI_SIZE_16); |
| 414 | if (ret) |
| 415 | return ret; |
| 416 | *valuep = value; |
| 417 | |
| 418 | return 0; |
| 419 | } |
| 420 | |
| 421 | int pci_read_config8(pci_dev_t bdf, int offset, u8 *valuep) |
| 422 | { |
| 423 | unsigned long value; |
| 424 | int ret; |
| 425 | |
| 426 | ret = pci_read_config(bdf, offset, &value, PCI_SIZE_8); |
| 427 | if (ret) |
| 428 | return ret; |
| 429 | *valuep = value; |
| 430 | |
| 431 | return 0; |
| 432 | } |
| 433 | |
Simon Glass | c92aac1 | 2020-01-27 08:49:38 -0700 | [diff] [blame] | 434 | int dm_pci_read_config8(const struct udevice *dev, int offset, u8 *valuep) |
Simon Glass | 94ef242 | 2015-08-10 07:05:03 -0600 | [diff] [blame] | 435 | { |
| 436 | unsigned long value; |
| 437 | int ret; |
| 438 | |
| 439 | ret = dm_pci_read_config(dev, offset, &value, PCI_SIZE_8); |
| 440 | if (ret) |
| 441 | return ret; |
| 442 | *valuep = value; |
| 443 | |
| 444 | return 0; |
| 445 | } |
| 446 | |
Simon Glass | c92aac1 | 2020-01-27 08:49:38 -0700 | [diff] [blame] | 447 | int dm_pci_read_config16(const struct udevice *dev, int offset, u16 *valuep) |
Simon Glass | 94ef242 | 2015-08-10 07:05:03 -0600 | [diff] [blame] | 448 | { |
| 449 | unsigned long value; |
| 450 | int ret; |
| 451 | |
| 452 | ret = dm_pci_read_config(dev, offset, &value, PCI_SIZE_16); |
| 453 | if (ret) |
| 454 | return ret; |
| 455 | *valuep = value; |
| 456 | |
| 457 | return 0; |
| 458 | } |
| 459 | |
Simon Glass | c92aac1 | 2020-01-27 08:49:38 -0700 | [diff] [blame] | 460 | int dm_pci_read_config32(const struct udevice *dev, int offset, u32 *valuep) |
Simon Glass | 94ef242 | 2015-08-10 07:05:03 -0600 | [diff] [blame] | 461 | { |
| 462 | unsigned long value; |
| 463 | int ret; |
| 464 | |
| 465 | ret = dm_pci_read_config(dev, offset, &value, PCI_SIZE_32); |
| 466 | if (ret) |
| 467 | return ret; |
| 468 | *valuep = value; |
| 469 | |
| 470 | return 0; |
| 471 | } |
| 472 | |
Simon Glass | 9cec2df | 2016-03-06 19:27:52 -0700 | [diff] [blame] | 473 | int dm_pci_clrset_config8(struct udevice *dev, int offset, u32 clr, u32 set) |
| 474 | { |
| 475 | u8 val; |
| 476 | int ret; |
| 477 | |
| 478 | ret = dm_pci_read_config8(dev, offset, &val); |
| 479 | if (ret) |
| 480 | return ret; |
| 481 | val &= ~clr; |
| 482 | val |= set; |
| 483 | |
| 484 | return dm_pci_write_config8(dev, offset, val); |
| 485 | } |
| 486 | |
| 487 | int dm_pci_clrset_config16(struct udevice *dev, int offset, u32 clr, u32 set) |
| 488 | { |
| 489 | u16 val; |
| 490 | int ret; |
| 491 | |
| 492 | ret = dm_pci_read_config16(dev, offset, &val); |
| 493 | if (ret) |
| 494 | return ret; |
| 495 | val &= ~clr; |
| 496 | val |= set; |
| 497 | |
| 498 | return dm_pci_write_config16(dev, offset, val); |
| 499 | } |
| 500 | |
| 501 | int dm_pci_clrset_config32(struct udevice *dev, int offset, u32 clr, u32 set) |
| 502 | { |
| 503 | u32 val; |
| 504 | int ret; |
| 505 | |
| 506 | ret = dm_pci_read_config32(dev, offset, &val); |
| 507 | if (ret) |
| 508 | return ret; |
| 509 | val &= ~clr; |
| 510 | val |= set; |
| 511 | |
| 512 | return dm_pci_write_config32(dev, offset, val); |
| 513 | } |
| 514 | |
Bin Meng | a070578 | 2015-10-01 00:36:02 -0700 | [diff] [blame] | 515 | static void set_vga_bridge_bits(struct udevice *dev) |
| 516 | { |
| 517 | struct udevice *parent = dev->parent; |
| 518 | u16 bc; |
| 519 | |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 520 | while (dev_seq(parent) != 0) { |
Bin Meng | a070578 | 2015-10-01 00:36:02 -0700 | [diff] [blame] | 521 | dm_pci_read_config16(parent, PCI_BRIDGE_CONTROL, &bc); |
| 522 | bc |= PCI_BRIDGE_CTL_VGA; |
| 523 | dm_pci_write_config16(parent, PCI_BRIDGE_CONTROL, bc); |
| 524 | parent = parent->parent; |
| 525 | } |
| 526 | } |
| 527 | |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 528 | int pci_auto_config_devices(struct udevice *bus) |
| 529 | { |
Simon Glass | 9558862 | 2020-12-22 19:30:28 -0700 | [diff] [blame] | 530 | struct pci_controller *hose = dev_get_uclass_priv(bus); |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 531 | struct pci_child_plat *pplat; |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 532 | unsigned int sub_bus; |
| 533 | struct udevice *dev; |
| 534 | int ret; |
| 535 | |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 536 | sub_bus = dev_seq(bus); |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 537 | debug("%s: start\n", __func__); |
| 538 | pciauto_config_init(hose); |
| 539 | for (ret = device_find_first_child(bus, &dev); |
| 540 | !ret && dev; |
| 541 | ret = device_find_next_child(&dev)) { |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 542 | unsigned int max_bus; |
Simon Glass | b072d52 | 2015-09-08 17:52:47 -0600 | [diff] [blame] | 543 | int ret; |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 544 | |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 545 | debug("%s: device %s\n", __func__, dev->name); |
Simon Glass | f1d50f7 | 2020-12-19 10:40:13 -0700 | [diff] [blame] | 546 | if (dev_has_ofnode(dev) && |
Suneel Garapati | f8c8628 | 2020-05-04 21:25:25 -0700 | [diff] [blame] | 547 | dev_read_bool(dev, "pci,no-autoconfig")) |
Simon Glass | f3005fb | 2020-04-08 16:57:26 -0600 | [diff] [blame] | 548 | continue; |
Simon Glass | 37a3f94b | 2015-11-29 13:17:49 -0700 | [diff] [blame] | 549 | ret = dm_pciauto_config_device(dev); |
Simon Glass | b072d52 | 2015-09-08 17:52:47 -0600 | [diff] [blame] | 550 | if (ret < 0) |
Simon Glass | be70610 | 2020-12-16 21:20:18 -0700 | [diff] [blame] | 551 | return log_msg_ret("auto", ret); |
Simon Glass | b072d52 | 2015-09-08 17:52:47 -0600 | [diff] [blame] | 552 | max_bus = ret; |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 553 | sub_bus = max(sub_bus, max_bus); |
Bin Meng | a070578 | 2015-10-01 00:36:02 -0700 | [diff] [blame] | 554 | |
Masami Hiramatsu | 7ccdc67 | 2021-06-04 18:43:34 +0900 | [diff] [blame] | 555 | if (dev_get_parent(dev) == bus) |
| 556 | continue; |
| 557 | |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 558 | pplat = dev_get_parent_plat(dev); |
Bin Meng | a070578 | 2015-10-01 00:36:02 -0700 | [diff] [blame] | 559 | if (pplat->class == (PCI_CLASS_DISPLAY_VGA << 8)) |
| 560 | set_vga_bridge_bits(dev); |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 561 | } |
| 562 | debug("%s: done\n", __func__); |
| 563 | |
Simon Glass | be70610 | 2020-12-16 21:20:18 -0700 | [diff] [blame] | 564 | return log_msg_ret("sub", sub_bus); |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 565 | } |
| 566 | |
Tuomas Tynkkynen | 8cce4cf | 2017-09-19 23:18:03 +0300 | [diff] [blame] | 567 | int pci_generic_mmap_write_config( |
Simon Glass | 2a311e8 | 2020-01-27 08:49:37 -0700 | [diff] [blame] | 568 | const struct udevice *bus, |
| 569 | int (*addr_f)(const struct udevice *bus, pci_dev_t bdf, uint offset, |
| 570 | void **addrp), |
Tuomas Tynkkynen | 8cce4cf | 2017-09-19 23:18:03 +0300 | [diff] [blame] | 571 | pci_dev_t bdf, |
| 572 | uint offset, |
| 573 | ulong value, |
| 574 | enum pci_size_t size) |
| 575 | { |
| 576 | void *address; |
| 577 | |
| 578 | if (addr_f(bus, bdf, offset, &address) < 0) |
| 579 | return 0; |
| 580 | |
| 581 | switch (size) { |
| 582 | case PCI_SIZE_8: |
| 583 | writeb(value, address); |
| 584 | return 0; |
| 585 | case PCI_SIZE_16: |
| 586 | writew(value, address); |
| 587 | return 0; |
| 588 | case PCI_SIZE_32: |
| 589 | writel(value, address); |
| 590 | return 0; |
| 591 | default: |
| 592 | return -EINVAL; |
| 593 | } |
| 594 | } |
| 595 | |
| 596 | int pci_generic_mmap_read_config( |
Simon Glass | 2a311e8 | 2020-01-27 08:49:37 -0700 | [diff] [blame] | 597 | const struct udevice *bus, |
| 598 | int (*addr_f)(const struct udevice *bus, pci_dev_t bdf, uint offset, |
| 599 | void **addrp), |
Tuomas Tynkkynen | 8cce4cf | 2017-09-19 23:18:03 +0300 | [diff] [blame] | 600 | pci_dev_t bdf, |
| 601 | uint offset, |
| 602 | ulong *valuep, |
| 603 | enum pci_size_t size) |
| 604 | { |
| 605 | void *address; |
| 606 | |
| 607 | if (addr_f(bus, bdf, offset, &address) < 0) { |
| 608 | *valuep = pci_get_ff(size); |
| 609 | return 0; |
| 610 | } |
| 611 | |
| 612 | switch (size) { |
| 613 | case PCI_SIZE_8: |
| 614 | *valuep = readb(address); |
| 615 | return 0; |
| 616 | case PCI_SIZE_16: |
| 617 | *valuep = readw(address); |
| 618 | return 0; |
| 619 | case PCI_SIZE_32: |
| 620 | *valuep = readl(address); |
| 621 | return 0; |
| 622 | default: |
| 623 | return -EINVAL; |
| 624 | } |
| 625 | } |
| 626 | |
Simon Glass | 37a3f94b | 2015-11-29 13:17:49 -0700 | [diff] [blame] | 627 | int dm_pci_hose_probe_bus(struct udevice *bus) |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 628 | { |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 629 | int sub_bus; |
| 630 | int ret; |
Suneel Garapati | 1b9c44e | 2019-10-19 15:52:32 -0700 | [diff] [blame] | 631 | int ea_pos; |
| 632 | u8 reg; |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 633 | |
| 634 | debug("%s\n", __func__); |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 635 | |
Suneel Garapati | 1b9c44e | 2019-10-19 15:52:32 -0700 | [diff] [blame] | 636 | ea_pos = dm_pci_find_capability(bus, PCI_CAP_ID_EA); |
| 637 | if (ea_pos) { |
| 638 | dm_pci_read_config8(bus, ea_pos + sizeof(u32) + sizeof(u8), |
| 639 | ®); |
| 640 | sub_bus = reg; |
| 641 | } else { |
| 642 | sub_bus = pci_get_bus_max() + 1; |
| 643 | } |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 644 | debug("%s: bus = %d/%s\n", __func__, sub_bus, bus->name); |
Simon Glass | 37a3f94b | 2015-11-29 13:17:49 -0700 | [diff] [blame] | 645 | dm_pciauto_prescan_setup_bridge(bus, sub_bus); |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 646 | |
| 647 | ret = device_probe(bus); |
| 648 | if (ret) { |
Simon Glass | 3b02d84 | 2015-09-08 17:52:48 -0600 | [diff] [blame] | 649 | debug("%s: Cannot probe bus %s: %d\n", __func__, bus->name, |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 650 | ret); |
Simon Glass | be70610 | 2020-12-16 21:20:18 -0700 | [diff] [blame] | 651 | return log_msg_ret("probe", ret); |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 652 | } |
Suneel Garapati | 1b9c44e | 2019-10-19 15:52:32 -0700 | [diff] [blame] | 653 | |
Masami Hiramatsu | ff02245 | 2021-04-16 14:53:46 -0700 | [diff] [blame] | 654 | if (!ea_pos) |
| 655 | sub_bus = pci_get_bus_max(); |
| 656 | |
Simon Glass | 37a3f94b | 2015-11-29 13:17:49 -0700 | [diff] [blame] | 657 | dm_pciauto_postscan_setup_bridge(bus, sub_bus); |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 658 | |
| 659 | return sub_bus; |
| 660 | } |
| 661 | |
Simon Glass | 318d71c | 2015-07-06 16:47:44 -0600 | [diff] [blame] | 662 | /** |
| 663 | * pci_match_one_device - Tell if a PCI device structure has a matching |
| 664 | * PCI device id structure |
| 665 | * @id: single PCI device id structure to match |
Hou Zhiqiang | d19d061 | 2017-03-22 16:07:24 +0800 | [diff] [blame] | 666 | * @find: the PCI device id structure to match against |
Simon Glass | 318d71c | 2015-07-06 16:47:44 -0600 | [diff] [blame] | 667 | * |
Hou Zhiqiang | d19d061 | 2017-03-22 16:07:24 +0800 | [diff] [blame] | 668 | * Returns true if the finding pci_device_id structure matched or false if |
| 669 | * there is no match. |
Simon Glass | 318d71c | 2015-07-06 16:47:44 -0600 | [diff] [blame] | 670 | */ |
| 671 | static bool pci_match_one_id(const struct pci_device_id *id, |
| 672 | const struct pci_device_id *find) |
| 673 | { |
| 674 | if ((id->vendor == PCI_ANY_ID || id->vendor == find->vendor) && |
| 675 | (id->device == PCI_ANY_ID || id->device == find->device) && |
| 676 | (id->subvendor == PCI_ANY_ID || id->subvendor == find->subvendor) && |
| 677 | (id->subdevice == PCI_ANY_ID || id->subdevice == find->subdevice) && |
| 678 | !((id->class ^ find->class) & id->class_mask)) |
| 679 | return true; |
| 680 | |
| 681 | return false; |
| 682 | } |
| 683 | |
| 684 | /** |
| 685 | * pci_find_and_bind_driver() - Find and bind the right PCI driver |
| 686 | * |
| 687 | * This only looks at certain fields in the descriptor. |
Simon Glass | c45abf1 | 2015-09-08 17:52:49 -0600 | [diff] [blame] | 688 | * |
| 689 | * @parent: Parent bus |
| 690 | * @find_id: Specification of the driver to find |
| 691 | * @bdf: Bus/device/function addreess - see PCI_BDF() |
| 692 | * @devp: Returns a pointer to the device created |
| 693 | * @return 0 if OK, -EPERM if the device is not needed before relocation and |
| 694 | * therefore was not created, other -ve value on error |
Simon Glass | 318d71c | 2015-07-06 16:47:44 -0600 | [diff] [blame] | 695 | */ |
| 696 | static int pci_find_and_bind_driver(struct udevice *parent, |
Simon Glass | c45abf1 | 2015-09-08 17:52:49 -0600 | [diff] [blame] | 697 | struct pci_device_id *find_id, |
| 698 | pci_dev_t bdf, struct udevice **devp) |
Simon Glass | 318d71c | 2015-07-06 16:47:44 -0600 | [diff] [blame] | 699 | { |
| 700 | struct pci_driver_entry *start, *entry; |
Marek Vasut | b453579 | 2018-10-10 21:27:06 +0200 | [diff] [blame] | 701 | ofnode node = ofnode_null(); |
Simon Glass | 318d71c | 2015-07-06 16:47:44 -0600 | [diff] [blame] | 702 | const char *drv; |
| 703 | int n_ents; |
| 704 | int ret; |
| 705 | char name[30], *str; |
Bin Meng | 984c0dc | 2015-08-20 06:40:17 -0700 | [diff] [blame] | 706 | bool bridge; |
Simon Glass | 318d71c | 2015-07-06 16:47:44 -0600 | [diff] [blame] | 707 | |
| 708 | *devp = NULL; |
| 709 | |
| 710 | debug("%s: Searching for driver: vendor=%x, device=%x\n", __func__, |
| 711 | find_id->vendor, find_id->device); |
Marek Vasut | b453579 | 2018-10-10 21:27:06 +0200 | [diff] [blame] | 712 | |
| 713 | /* Determine optional OF node */ |
Suneel Garapati | cb7093d | 2019-10-19 16:02:48 -0700 | [diff] [blame] | 714 | if (ofnode_valid(dev_ofnode(parent))) |
| 715 | pci_dev_find_ofnode(parent, bdf, &node); |
Marek Vasut | b453579 | 2018-10-10 21:27:06 +0200 | [diff] [blame] | 716 | |
Michael Walle | 2e21f37 | 2019-12-01 17:45:18 +0100 | [diff] [blame] | 717 | if (ofnode_valid(node) && !ofnode_is_available(node)) { |
| 718 | debug("%s: Ignoring disabled device\n", __func__); |
Simon Glass | be70610 | 2020-12-16 21:20:18 -0700 | [diff] [blame] | 719 | return log_msg_ret("dis", -EPERM); |
Michael Walle | 2e21f37 | 2019-12-01 17:45:18 +0100 | [diff] [blame] | 720 | } |
| 721 | |
Simon Glass | 318d71c | 2015-07-06 16:47:44 -0600 | [diff] [blame] | 722 | start = ll_entry_start(struct pci_driver_entry, pci_driver_entry); |
| 723 | n_ents = ll_entry_count(struct pci_driver_entry, pci_driver_entry); |
| 724 | for (entry = start; entry != start + n_ents; entry++) { |
| 725 | const struct pci_device_id *id; |
| 726 | struct udevice *dev; |
| 727 | const struct driver *drv; |
| 728 | |
| 729 | for (id = entry->match; |
| 730 | id->vendor || id->subvendor || id->class_mask; |
| 731 | id++) { |
| 732 | if (!pci_match_one_id(id, find_id)) |
| 733 | continue; |
| 734 | |
| 735 | drv = entry->driver; |
Bin Meng | 984c0dc | 2015-08-20 06:40:17 -0700 | [diff] [blame] | 736 | |
| 737 | /* |
| 738 | * In the pre-relocation phase, we only bind devices |
| 739 | * whose driver has the DM_FLAG_PRE_RELOC set, to save |
| 740 | * precious memory space as on some platforms as that |
| 741 | * space is pretty limited (ie: using Cache As RAM). |
| 742 | */ |
| 743 | if (!(gd->flags & GD_FLG_RELOC) && |
| 744 | !(drv->flags & DM_FLAG_PRE_RELOC)) |
Simon Glass | be70610 | 2020-12-16 21:20:18 -0700 | [diff] [blame] | 745 | return log_msg_ret("pre", -EPERM); |
Bin Meng | 984c0dc | 2015-08-20 06:40:17 -0700 | [diff] [blame] | 746 | |
Simon Glass | 318d71c | 2015-07-06 16:47:44 -0600 | [diff] [blame] | 747 | /* |
| 748 | * We could pass the descriptor to the driver as |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 749 | * plat (instead of NULL) and allow its bind() |
Simon Glass | 318d71c | 2015-07-06 16:47:44 -0600 | [diff] [blame] | 750 | * method to return -ENOENT if it doesn't support this |
| 751 | * device. That way we could continue the search to |
| 752 | * find another driver. For now this doesn't seem |
| 753 | * necesssary, so just bind the first match. |
| 754 | */ |
Simon Glass | 884870f | 2020-11-28 17:50:01 -0700 | [diff] [blame] | 755 | ret = device_bind(parent, drv, drv->name, NULL, node, |
| 756 | &dev); |
Simon Glass | 318d71c | 2015-07-06 16:47:44 -0600 | [diff] [blame] | 757 | if (ret) |
| 758 | goto error; |
| 759 | debug("%s: Match found: %s\n", __func__, drv->name); |
Bin Meng | a8d2780 | 2018-08-03 01:14:44 -0700 | [diff] [blame] | 760 | dev->driver_data = id->driver_data; |
Simon Glass | 318d71c | 2015-07-06 16:47:44 -0600 | [diff] [blame] | 761 | *devp = dev; |
| 762 | return 0; |
| 763 | } |
| 764 | } |
| 765 | |
Bin Meng | 984c0dc | 2015-08-20 06:40:17 -0700 | [diff] [blame] | 766 | bridge = (find_id->class >> 8) == PCI_CLASS_BRIDGE_PCI; |
| 767 | /* |
| 768 | * In the pre-relocation phase, we only bind bridge devices to save |
| 769 | * precious memory space as on some platforms as that space is pretty |
| 770 | * limited (ie: using Cache As RAM). |
| 771 | */ |
| 772 | if (!(gd->flags & GD_FLG_RELOC) && !bridge) |
Simon Glass | be70610 | 2020-12-16 21:20:18 -0700 | [diff] [blame] | 773 | return log_msg_ret("notbr", -EPERM); |
Bin Meng | 984c0dc | 2015-08-20 06:40:17 -0700 | [diff] [blame] | 774 | |
Simon Glass | 318d71c | 2015-07-06 16:47:44 -0600 | [diff] [blame] | 775 | /* Bind a generic driver so that the device can be used */ |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 776 | sprintf(name, "pci_%x:%x.%x", dev_seq(parent), PCI_DEV(bdf), |
Bin Meng | 0a72152 | 2015-07-19 00:20:04 +0800 | [diff] [blame] | 777 | PCI_FUNC(bdf)); |
Simon Glass | 318d71c | 2015-07-06 16:47:44 -0600 | [diff] [blame] | 778 | str = strdup(name); |
| 779 | if (!str) |
| 780 | return -ENOMEM; |
Bin Meng | 984c0dc | 2015-08-20 06:40:17 -0700 | [diff] [blame] | 781 | drv = bridge ? "pci_bridge_drv" : "pci_generic_drv"; |
| 782 | |
Marek Vasut | b453579 | 2018-10-10 21:27:06 +0200 | [diff] [blame] | 783 | ret = device_bind_driver_to_node(parent, drv, str, node, devp); |
Simon Glass | 318d71c | 2015-07-06 16:47:44 -0600 | [diff] [blame] | 784 | if (ret) { |
Simon Glass | 3b02d84 | 2015-09-08 17:52:48 -0600 | [diff] [blame] | 785 | debug("%s: Failed to bind generic driver: %d\n", __func__, ret); |
xypron.glpk@gmx.de | a89009c | 2017-05-08 20:40:16 +0200 | [diff] [blame] | 786 | free(str); |
Simon Glass | 318d71c | 2015-07-06 16:47:44 -0600 | [diff] [blame] | 787 | return ret; |
| 788 | } |
| 789 | debug("%s: No match found: bound generic driver instead\n", __func__); |
| 790 | |
| 791 | return 0; |
| 792 | |
| 793 | error: |
| 794 | debug("%s: No match found: error %d\n", __func__, ret); |
| 795 | return ret; |
| 796 | } |
| 797 | |
Tim Harvey | 4c57bf7 | 2021-04-16 14:53:47 -0700 | [diff] [blame] | 798 | __weak extern void board_pci_fixup_dev(struct udevice *bus, struct udevice *dev) |
| 799 | { |
| 800 | } |
| 801 | |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 802 | int pci_bind_bus_devices(struct udevice *bus) |
| 803 | { |
| 804 | ulong vendor, device; |
| 805 | ulong header_type; |
Bin Meng | 0a72152 | 2015-07-19 00:20:04 +0800 | [diff] [blame] | 806 | pci_dev_t bdf, end; |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 807 | bool found_multi; |
Suneel Garapati | a99a5eb | 2019-10-23 18:40:36 -0700 | [diff] [blame] | 808 | int ari_off; |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 809 | int ret; |
| 810 | |
| 811 | found_multi = false; |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 812 | end = PCI_BDF(dev_seq(bus), PCI_MAX_PCI_DEVICES - 1, |
Bin Meng | 0a72152 | 2015-07-19 00:20:04 +0800 | [diff] [blame] | 813 | PCI_MAX_PCI_FUNCTIONS - 1); |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 814 | for (bdf = PCI_BDF(dev_seq(bus), 0, 0); bdf <= end; |
Bin Meng | 0a72152 | 2015-07-19 00:20:04 +0800 | [diff] [blame] | 815 | bdf += PCI_BDF(0, 0, 1)) { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 816 | struct pci_child_plat *pplat; |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 817 | struct udevice *dev; |
| 818 | ulong class; |
| 819 | |
Bin Meng | 20bdc1e | 2018-08-03 01:14:37 -0700 | [diff] [blame] | 820 | if (!PCI_FUNC(bdf)) |
| 821 | found_multi = false; |
Bin Meng | 0a72152 | 2015-07-19 00:20:04 +0800 | [diff] [blame] | 822 | if (PCI_FUNC(bdf) && !found_multi) |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 823 | continue; |
Hou Zhiqiang | fb862b05 | 2018-10-08 16:35:47 +0800 | [diff] [blame] | 824 | |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 825 | /* Check only the first access, we don't expect problems */ |
Hou Zhiqiang | fb862b05 | 2018-10-08 16:35:47 +0800 | [diff] [blame] | 826 | ret = pci_bus_read_config(bus, bdf, PCI_VENDOR_ID, &vendor, |
| 827 | PCI_SIZE_16); |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 828 | if (ret) |
| 829 | goto error; |
Hou Zhiqiang | fb862b05 | 2018-10-08 16:35:47 +0800 | [diff] [blame] | 830 | |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 831 | if (vendor == 0xffff || vendor == 0x0000) |
| 832 | continue; |
| 833 | |
Hou Zhiqiang | fb862b05 | 2018-10-08 16:35:47 +0800 | [diff] [blame] | 834 | pci_bus_read_config(bus, bdf, PCI_HEADER_TYPE, |
| 835 | &header_type, PCI_SIZE_8); |
| 836 | |
Bin Meng | 0a72152 | 2015-07-19 00:20:04 +0800 | [diff] [blame] | 837 | if (!PCI_FUNC(bdf)) |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 838 | found_multi = header_type & 0x80; |
| 839 | |
Simon Glass | 25916d6 | 2019-09-25 08:56:12 -0600 | [diff] [blame] | 840 | debug("%s: bus %d/%s: found device %x, function %d", __func__, |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 841 | dev_seq(bus), bus->name, PCI_DEV(bdf), PCI_FUNC(bdf)); |
Bin Meng | 0a72152 | 2015-07-19 00:20:04 +0800 | [diff] [blame] | 842 | pci_bus_read_config(bus, bdf, PCI_DEVICE_ID, &device, |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 843 | PCI_SIZE_16); |
Bin Meng | 0a72152 | 2015-07-19 00:20:04 +0800 | [diff] [blame] | 844 | pci_bus_read_config(bus, bdf, PCI_CLASS_REVISION, &class, |
Simon Glass | 318d71c | 2015-07-06 16:47:44 -0600 | [diff] [blame] | 845 | PCI_SIZE_32); |
| 846 | class >>= 8; |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 847 | |
| 848 | /* Find this device in the device tree */ |
Bin Meng | 0a72152 | 2015-07-19 00:20:04 +0800 | [diff] [blame] | 849 | ret = pci_bus_find_devfn(bus, PCI_MASK_BUS(bdf), &dev); |
Simon Glass | 25916d6 | 2019-09-25 08:56:12 -0600 | [diff] [blame] | 850 | debug(": find ret=%d\n", ret); |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 851 | |
Simon Glass | 413ebdb | 2015-11-29 13:18:09 -0700 | [diff] [blame] | 852 | /* If nothing in the device tree, bind a device */ |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 853 | if (ret == -ENODEV) { |
Simon Glass | 318d71c | 2015-07-06 16:47:44 -0600 | [diff] [blame] | 854 | struct pci_device_id find_id; |
| 855 | ulong val; |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 856 | |
Simon Glass | 318d71c | 2015-07-06 16:47:44 -0600 | [diff] [blame] | 857 | memset(&find_id, '\0', sizeof(find_id)); |
| 858 | find_id.vendor = vendor; |
| 859 | find_id.device = device; |
| 860 | find_id.class = class; |
| 861 | if ((header_type & 0x7f) == PCI_HEADER_TYPE_NORMAL) { |
Bin Meng | 0a72152 | 2015-07-19 00:20:04 +0800 | [diff] [blame] | 862 | pci_bus_read_config(bus, bdf, |
Simon Glass | 318d71c | 2015-07-06 16:47:44 -0600 | [diff] [blame] | 863 | PCI_SUBSYSTEM_VENDOR_ID, |
| 864 | &val, PCI_SIZE_32); |
| 865 | find_id.subvendor = val & 0xffff; |
| 866 | find_id.subdevice = val >> 16; |
| 867 | } |
Bin Meng | 0a72152 | 2015-07-19 00:20:04 +0800 | [diff] [blame] | 868 | ret = pci_find_and_bind_driver(bus, &find_id, bdf, |
Simon Glass | 318d71c | 2015-07-06 16:47:44 -0600 | [diff] [blame] | 869 | &dev); |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 870 | } |
Simon Glass | c45abf1 | 2015-09-08 17:52:49 -0600 | [diff] [blame] | 871 | if (ret == -EPERM) |
| 872 | continue; |
| 873 | else if (ret) |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 874 | return ret; |
| 875 | |
| 876 | /* Update the platform data */ |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 877 | pplat = dev_get_parent_plat(dev); |
Simon Glass | c45abf1 | 2015-09-08 17:52:49 -0600 | [diff] [blame] | 878 | pplat->devfn = PCI_MASK_BUS(bdf); |
| 879 | pplat->vendor = vendor; |
| 880 | pplat->device = device; |
| 881 | pplat->class = class; |
Suneel Garapati | a99a5eb | 2019-10-23 18:40:36 -0700 | [diff] [blame] | 882 | |
| 883 | if (IS_ENABLED(CONFIG_PCI_ARID)) { |
| 884 | ari_off = dm_pci_find_ext_capability(dev, |
| 885 | PCI_EXT_CAP_ID_ARI); |
| 886 | if (ari_off) { |
| 887 | u16 ari_cap; |
| 888 | |
| 889 | /* |
| 890 | * Read Next Function number in ARI Cap |
| 891 | * Register |
| 892 | */ |
| 893 | dm_pci_read_config16(dev, ari_off + 4, |
| 894 | &ari_cap); |
| 895 | /* |
| 896 | * Update next scan on this function number, |
| 897 | * subtract 1 in BDF to satisfy loop increment. |
| 898 | */ |
| 899 | if (ari_cap & 0xff00) { |
| 900 | bdf = PCI_BDF(PCI_BUS(bdf), |
| 901 | PCI_DEV(ari_cap), |
| 902 | PCI_FUNC(ari_cap)); |
| 903 | bdf = bdf - 0x100; |
| 904 | } |
| 905 | } |
| 906 | } |
Tim Harvey | 4c57bf7 | 2021-04-16 14:53:47 -0700 | [diff] [blame] | 907 | |
| 908 | board_pci_fixup_dev(bus, dev); |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 909 | } |
| 910 | |
| 911 | return 0; |
| 912 | error: |
| 913 | printf("Cannot read bus configuration: %d\n", ret); |
| 914 | |
| 915 | return ret; |
| 916 | } |
| 917 | |
Christian Gmeiner | 5f4e094 | 2018-06-10 06:25:05 -0700 | [diff] [blame] | 918 | static void decode_regions(struct pci_controller *hose, ofnode parent_node, |
| 919 | ofnode node) |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 920 | { |
| 921 | int pci_addr_cells, addr_cells, size_cells; |
| 922 | int cells_per_record; |
Stefan Roese | bbc8846 | 2020-08-12 11:55:46 +0200 | [diff] [blame] | 923 | struct bd_info *bd; |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 924 | const u32 *prop; |
Stefan Roese | 950864f | 2020-07-23 16:34:10 +0200 | [diff] [blame] | 925 | int max_regions; |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 926 | int len; |
| 927 | int i; |
| 928 | |
Masahiro Yamada | 9cf85cb | 2017-06-22 16:54:05 +0900 | [diff] [blame] | 929 | prop = ofnode_get_property(node, "ranges", &len); |
Christian Gmeiner | 5f4e094 | 2018-06-10 06:25:05 -0700 | [diff] [blame] | 930 | if (!prop) { |
| 931 | debug("%s: Cannot decode regions\n", __func__); |
| 932 | return; |
| 933 | } |
| 934 | |
Simon Glass | 4191dc1 | 2017-06-12 06:21:31 -0600 | [diff] [blame] | 935 | pci_addr_cells = ofnode_read_simple_addr_cells(node); |
| 936 | addr_cells = ofnode_read_simple_addr_cells(parent_node); |
| 937 | size_cells = ofnode_read_simple_size_cells(node); |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 938 | |
| 939 | /* PCI addresses are always 3-cells */ |
| 940 | len /= sizeof(u32); |
| 941 | cells_per_record = pci_addr_cells + addr_cells + size_cells; |
| 942 | hose->region_count = 0; |
| 943 | debug("%s: len=%d, cells_per_record=%d\n", __func__, len, |
| 944 | cells_per_record); |
Stefan Roese | 950864f | 2020-07-23 16:34:10 +0200 | [diff] [blame] | 945 | |
| 946 | /* Dynamically allocate the regions array */ |
| 947 | max_regions = len / cells_per_record + CONFIG_NR_DRAM_BANKS; |
| 948 | hose->regions = (struct pci_region *) |
| 949 | calloc(1, max_regions * sizeof(struct pci_region)); |
| 950 | |
| 951 | for (i = 0; i < max_regions; i++, len -= cells_per_record) { |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 952 | u64 pci_addr, addr, size; |
| 953 | int space_code; |
| 954 | u32 flags; |
| 955 | int type; |
Simon Glass | 7efc9ba | 2015-11-19 20:26:58 -0700 | [diff] [blame] | 956 | int pos; |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 957 | |
| 958 | if (len < cells_per_record) |
| 959 | break; |
| 960 | flags = fdt32_to_cpu(prop[0]); |
| 961 | space_code = (flags >> 24) & 3; |
| 962 | pci_addr = fdtdec_get_number(prop + 1, 2); |
| 963 | prop += pci_addr_cells; |
| 964 | addr = fdtdec_get_number(prop, addr_cells); |
| 965 | prop += addr_cells; |
| 966 | size = fdtdec_get_number(prop, size_cells); |
| 967 | prop += size_cells; |
Masahiro Yamada | c7570a3 | 2018-08-06 20:47:40 +0900 | [diff] [blame] | 968 | debug("%s: region %d, pci_addr=%llx, addr=%llx, size=%llx, space_code=%d\n", |
| 969 | __func__, hose->region_count, pci_addr, addr, size, space_code); |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 970 | if (space_code & 2) { |
| 971 | type = flags & (1U << 30) ? PCI_REGION_PREFETCH : |
| 972 | PCI_REGION_MEM; |
| 973 | } else if (space_code & 1) { |
| 974 | type = PCI_REGION_IO; |
| 975 | } else { |
| 976 | continue; |
| 977 | } |
Tuomas Tynkkynen | c307e17 | 2018-05-14 18:47:50 +0300 | [diff] [blame] | 978 | |
| 979 | if (!IS_ENABLED(CONFIG_SYS_PCI_64BIT) && |
| 980 | type == PCI_REGION_MEM && upper_32_bits(pci_addr)) { |
| 981 | debug(" - beyond the 32-bit boundary, ignoring\n"); |
| 982 | continue; |
| 983 | } |
| 984 | |
Simon Glass | 7efc9ba | 2015-11-19 20:26:58 -0700 | [diff] [blame] | 985 | pos = -1; |
Suneel Garapati | 3ac3aec | 2019-10-19 17:10:20 -0700 | [diff] [blame] | 986 | if (!IS_ENABLED(CONFIG_PCI_REGION_MULTI_ENTRY)) { |
| 987 | for (i = 0; i < hose->region_count; i++) { |
| 988 | if (hose->regions[i].flags == type) |
| 989 | pos = i; |
| 990 | } |
Simon Glass | 7efc9ba | 2015-11-19 20:26:58 -0700 | [diff] [blame] | 991 | } |
Suneel Garapati | 3ac3aec | 2019-10-19 17:10:20 -0700 | [diff] [blame] | 992 | |
Simon Glass | 7efc9ba | 2015-11-19 20:26:58 -0700 | [diff] [blame] | 993 | if (pos == -1) |
| 994 | pos = hose->region_count++; |
| 995 | debug(" - type=%d, pos=%d\n", type, pos); |
| 996 | pci_set_region(hose->regions + pos, pci_addr, addr, size, type); |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 997 | } |
| 998 | |
| 999 | /* Add a region for our local memory */ |
Stefan Roese | bbc8846 | 2020-08-12 11:55:46 +0200 | [diff] [blame] | 1000 | bd = gd->bd; |
Bin Meng | ae0bdde | 2018-03-27 00:46:05 -0700 | [diff] [blame] | 1001 | if (!bd) |
Christian Gmeiner | 5f4e094 | 2018-06-10 06:25:05 -0700 | [diff] [blame] | 1002 | return; |
Bin Meng | ae0bdde | 2018-03-27 00:46:05 -0700 | [diff] [blame] | 1003 | |
Bernhard Messerklinger | 9c5df38 | 2018-02-15 08:59:53 +0100 | [diff] [blame] | 1004 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) { |
| 1005 | if (bd->bi_dram[i].size) { |
| 1006 | pci_set_region(hose->regions + hose->region_count++, |
| 1007 | bd->bi_dram[i].start, |
| 1008 | bd->bi_dram[i].start, |
| 1009 | bd->bi_dram[i].size, |
| 1010 | PCI_REGION_MEM | PCI_REGION_SYS_MEMORY); |
| 1011 | } |
| 1012 | } |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 1013 | |
Christian Gmeiner | 5f4e094 | 2018-06-10 06:25:05 -0700 | [diff] [blame] | 1014 | return; |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 1015 | } |
| 1016 | |
| 1017 | static int pci_uclass_pre_probe(struct udevice *bus) |
| 1018 | { |
| 1019 | struct pci_controller *hose; |
Simon Glass | be70610 | 2020-12-16 21:20:18 -0700 | [diff] [blame] | 1020 | struct uclass *uc; |
| 1021 | int ret; |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 1022 | |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 1023 | debug("%s, bus=%d/%s, parent=%s\n", __func__, dev_seq(bus), bus->name, |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 1024 | bus->parent->name); |
Simon Glass | 9558862 | 2020-12-22 19:30:28 -0700 | [diff] [blame] | 1025 | hose = dev_get_uclass_priv(bus); |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 1026 | |
Simon Glass | be70610 | 2020-12-16 21:20:18 -0700 | [diff] [blame] | 1027 | /* |
| 1028 | * Set the sequence number, if device_bind() doesn't. We want control |
| 1029 | * of this so that numbers are allocated as devices are probed. That |
| 1030 | * ensures that sub-bus numbered is correct (sub-buses must get numbers |
| 1031 | * higher than their parents) |
| 1032 | */ |
| 1033 | if (dev_seq(bus) == -1) { |
| 1034 | ret = uclass_get(UCLASS_PCI, &uc); |
| 1035 | if (ret) |
| 1036 | return ret; |
Simon Glass | 5e34992 | 2020-12-19 10:40:09 -0700 | [diff] [blame] | 1037 | bus->seq_ = uclass_find_next_free_seq(uc); |
Simon Glass | be70610 | 2020-12-16 21:20:18 -0700 | [diff] [blame] | 1038 | } |
| 1039 | |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 1040 | /* For bridges, use the top-level PCI controller */ |
Paul Burton | e3b106d | 2016-09-08 07:47:32 +0100 | [diff] [blame] | 1041 | if (!device_is_on_pci_bus(bus)) { |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 1042 | hose->ctlr = bus; |
Christian Gmeiner | 5f4e094 | 2018-06-10 06:25:05 -0700 | [diff] [blame] | 1043 | decode_regions(hose, dev_ofnode(bus->parent), dev_ofnode(bus)); |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 1044 | } else { |
| 1045 | struct pci_controller *parent_hose; |
| 1046 | |
| 1047 | parent_hose = dev_get_uclass_priv(bus->parent); |
| 1048 | hose->ctlr = parent_hose->bus; |
| 1049 | } |
Simon Glass | be70610 | 2020-12-16 21:20:18 -0700 | [diff] [blame] | 1050 | |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 1051 | hose->bus = bus; |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 1052 | hose->first_busno = dev_seq(bus); |
| 1053 | hose->last_busno = dev_seq(bus); |
Simon Glass | f1d50f7 | 2020-12-19 10:40:13 -0700 | [diff] [blame] | 1054 | if (dev_has_ofnode(bus)) { |
Suneel Garapati | f8c8628 | 2020-05-04 21:25:25 -0700 | [diff] [blame] | 1055 | hose->skip_auto_config_until_reloc = |
| 1056 | dev_read_bool(bus, |
| 1057 | "u-boot,skip-auto-config-until-reloc"); |
| 1058 | } |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 1059 | |
| 1060 | return 0; |
| 1061 | } |
| 1062 | |
| 1063 | static int pci_uclass_post_probe(struct udevice *bus) |
| 1064 | { |
Simon Glass | 68e35a7 | 2019-12-06 21:41:37 -0700 | [diff] [blame] | 1065 | struct pci_controller *hose = dev_get_uclass_priv(bus); |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 1066 | int ret; |
| 1067 | |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 1068 | debug("%s: probing bus %d\n", __func__, dev_seq(bus)); |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 1069 | ret = pci_bind_bus_devices(bus); |
| 1070 | if (ret) |
Simon Glass | be70610 | 2020-12-16 21:20:18 -0700 | [diff] [blame] | 1071 | return log_msg_ret("bind", ret); |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 1072 | |
Simon Glass | bd165e7 | 2020-04-26 09:12:56 -0600 | [diff] [blame] | 1073 | if (CONFIG_IS_ENABLED(PCI_PNP) && ll_boot_init() && |
Simon Glass | 68e35a7 | 2019-12-06 21:41:37 -0700 | [diff] [blame] | 1074 | (!hose->skip_auto_config_until_reloc || |
| 1075 | (gd->flags & GD_FLG_RELOC))) { |
| 1076 | ret = pci_auto_config_devices(bus); |
| 1077 | if (ret < 0) |
Simon Glass | be70610 | 2020-12-16 21:20:18 -0700 | [diff] [blame] | 1078 | return log_msg_ret("cfg", ret); |
Simon Glass | 68e35a7 | 2019-12-06 21:41:37 -0700 | [diff] [blame] | 1079 | } |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 1080 | |
Bin Meng | c0820a4 | 2015-08-20 06:40:23 -0700 | [diff] [blame] | 1081 | #if defined(CONFIG_X86) && defined(CONFIG_HAVE_FSP) |
| 1082 | /* |
| 1083 | * Per Intel FSP specification, we should call FSP notify API to |
| 1084 | * inform FSP that PCI enumeration has been done so that FSP will |
| 1085 | * do any necessary initialization as required by the chipset's |
| 1086 | * BIOS Writer's Guide (BWG). |
| 1087 | * |
| 1088 | * Unfortunately we have to put this call here as with driver model, |
| 1089 | * the enumeration is all done on a lazy basis as needed, so until |
| 1090 | * something is touched on PCI it won't happen. |
| 1091 | * |
| 1092 | * Note we only call this 1) after U-Boot is relocated, and 2) |
| 1093 | * root bus has finished probing. |
| 1094 | */ |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 1095 | if ((gd->flags & GD_FLG_RELOC) && dev_seq(bus) == 0 && ll_boot_init()) { |
Bin Meng | c0820a4 | 2015-08-20 06:40:23 -0700 | [diff] [blame] | 1096 | ret = fsp_init_phase_pci(); |
Simon Glass | b072d52 | 2015-09-08 17:52:47 -0600 | [diff] [blame] | 1097 | if (ret) |
Simon Glass | be70610 | 2020-12-16 21:20:18 -0700 | [diff] [blame] | 1098 | return log_msg_ret("fsp", ret); |
Simon Glass | b072d52 | 2015-09-08 17:52:47 -0600 | [diff] [blame] | 1099 | } |
Bin Meng | c0820a4 | 2015-08-20 06:40:23 -0700 | [diff] [blame] | 1100 | #endif |
| 1101 | |
Simon Glass | b072d52 | 2015-09-08 17:52:47 -0600 | [diff] [blame] | 1102 | return 0; |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 1103 | } |
| 1104 | |
| 1105 | static int pci_uclass_child_post_bind(struct udevice *dev) |
| 1106 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 1107 | struct pci_child_plat *pplat; |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 1108 | |
Simon Glass | f1d50f7 | 2020-12-19 10:40:13 -0700 | [diff] [blame] | 1109 | if (!dev_has_ofnode(dev)) |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 1110 | return 0; |
| 1111 | |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 1112 | pplat = dev_get_parent_plat(dev); |
Bin Meng | 00d808e | 2018-08-03 01:14:36 -0700 | [diff] [blame] | 1113 | |
| 1114 | /* Extract vendor id and device id if available */ |
| 1115 | ofnode_read_pci_vendev(dev_ofnode(dev), &pplat->vendor, &pplat->device); |
| 1116 | |
| 1117 | /* Extract the devfn from fdt_pci_addr */ |
Stefan Roese | a74eb55 | 2019-01-25 11:52:42 +0100 | [diff] [blame] | 1118 | pplat->devfn = pci_get_devfn(dev); |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 1119 | |
| 1120 | return 0; |
| 1121 | } |
| 1122 | |
Simon Glass | 2a311e8 | 2020-01-27 08:49:37 -0700 | [diff] [blame] | 1123 | static int pci_bridge_read_config(const struct udevice *bus, pci_dev_t bdf, |
Bin Meng | 0a72152 | 2015-07-19 00:20:04 +0800 | [diff] [blame] | 1124 | uint offset, ulong *valuep, |
| 1125 | enum pci_size_t size) |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 1126 | { |
Simon Glass | 9558862 | 2020-12-22 19:30:28 -0700 | [diff] [blame] | 1127 | struct pci_controller *hose = dev_get_uclass_priv(bus); |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 1128 | |
| 1129 | return pci_bus_read_config(hose->ctlr, bdf, offset, valuep, size); |
| 1130 | } |
| 1131 | |
Bin Meng | 0a72152 | 2015-07-19 00:20:04 +0800 | [diff] [blame] | 1132 | static int pci_bridge_write_config(struct udevice *bus, pci_dev_t bdf, |
| 1133 | uint offset, ulong value, |
| 1134 | enum pci_size_t size) |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 1135 | { |
Simon Glass | 9558862 | 2020-12-22 19:30:28 -0700 | [diff] [blame] | 1136 | struct pci_controller *hose = dev_get_uclass_priv(bus); |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 1137 | |
| 1138 | return pci_bus_write_config(hose->ctlr, bdf, offset, value, size); |
| 1139 | } |
| 1140 | |
Simon Glass | 04c8b6a | 2015-08-10 07:05:04 -0600 | [diff] [blame] | 1141 | static int skip_to_next_device(struct udevice *bus, struct udevice **devp) |
| 1142 | { |
| 1143 | struct udevice *dev; |
| 1144 | int ret = 0; |
| 1145 | |
| 1146 | /* |
| 1147 | * Scan through all the PCI controllers. On x86 there will only be one |
| 1148 | * but that is not necessarily true on other hardware. |
| 1149 | */ |
| 1150 | do { |
| 1151 | device_find_first_child(bus, &dev); |
| 1152 | if (dev) { |
| 1153 | *devp = dev; |
| 1154 | return 0; |
| 1155 | } |
| 1156 | ret = uclass_next_device(&bus); |
| 1157 | if (ret) |
| 1158 | return ret; |
| 1159 | } while (bus); |
| 1160 | |
| 1161 | return 0; |
| 1162 | } |
| 1163 | |
| 1164 | int pci_find_next_device(struct udevice **devp) |
| 1165 | { |
| 1166 | struct udevice *child = *devp; |
| 1167 | struct udevice *bus = child->parent; |
| 1168 | int ret; |
| 1169 | |
| 1170 | /* First try all the siblings */ |
| 1171 | *devp = NULL; |
| 1172 | while (child) { |
| 1173 | device_find_next_child(&child); |
| 1174 | if (child) { |
| 1175 | *devp = child; |
| 1176 | return 0; |
| 1177 | } |
| 1178 | } |
| 1179 | |
| 1180 | /* We ran out of siblings. Try the next bus */ |
| 1181 | ret = uclass_next_device(&bus); |
| 1182 | if (ret) |
| 1183 | return ret; |
| 1184 | |
| 1185 | return bus ? skip_to_next_device(bus, devp) : 0; |
| 1186 | } |
| 1187 | |
| 1188 | int pci_find_first_device(struct udevice **devp) |
| 1189 | { |
| 1190 | struct udevice *bus; |
| 1191 | int ret; |
| 1192 | |
| 1193 | *devp = NULL; |
| 1194 | ret = uclass_first_device(UCLASS_PCI, &bus); |
| 1195 | if (ret) |
| 1196 | return ret; |
| 1197 | |
| 1198 | return skip_to_next_device(bus, devp); |
| 1199 | } |
| 1200 | |
Simon Glass | 27a733f | 2015-11-19 20:26:59 -0700 | [diff] [blame] | 1201 | ulong pci_conv_32_to_size(ulong value, uint offset, enum pci_size_t size) |
| 1202 | { |
| 1203 | switch (size) { |
| 1204 | case PCI_SIZE_8: |
| 1205 | return (value >> ((offset & 3) * 8)) & 0xff; |
| 1206 | case PCI_SIZE_16: |
| 1207 | return (value >> ((offset & 2) * 8)) & 0xffff; |
| 1208 | default: |
| 1209 | return value; |
| 1210 | } |
| 1211 | } |
| 1212 | |
| 1213 | ulong pci_conv_size_to_32(ulong old, ulong value, uint offset, |
| 1214 | enum pci_size_t size) |
| 1215 | { |
| 1216 | uint off_mask; |
| 1217 | uint val_mask, shift; |
| 1218 | ulong ldata, mask; |
| 1219 | |
| 1220 | switch (size) { |
| 1221 | case PCI_SIZE_8: |
| 1222 | off_mask = 3; |
| 1223 | val_mask = 0xff; |
| 1224 | break; |
| 1225 | case PCI_SIZE_16: |
| 1226 | off_mask = 2; |
| 1227 | val_mask = 0xffff; |
| 1228 | break; |
| 1229 | default: |
| 1230 | return value; |
| 1231 | } |
| 1232 | shift = (offset & off_mask) * 8; |
| 1233 | ldata = (value & val_mask) << shift; |
| 1234 | mask = val_mask << shift; |
| 1235 | value = (old & ~mask) | ldata; |
| 1236 | |
| 1237 | return value; |
| 1238 | } |
| 1239 | |
Rayagonda Kokatanur | cdc7ed3 | 2020-05-12 13:29:49 +0530 | [diff] [blame] | 1240 | int pci_get_dma_regions(struct udevice *dev, struct pci_region *memp, int index) |
| 1241 | { |
| 1242 | int pci_addr_cells, addr_cells, size_cells; |
| 1243 | int cells_per_record; |
| 1244 | const u32 *prop; |
| 1245 | int len; |
| 1246 | int i = 0; |
| 1247 | |
| 1248 | prop = ofnode_get_property(dev_ofnode(dev), "dma-ranges", &len); |
| 1249 | if (!prop) { |
| 1250 | log_err("PCI: Device '%s': Cannot decode dma-ranges\n", |
| 1251 | dev->name); |
| 1252 | return -EINVAL; |
| 1253 | } |
| 1254 | |
| 1255 | pci_addr_cells = ofnode_read_simple_addr_cells(dev_ofnode(dev)); |
| 1256 | addr_cells = ofnode_read_simple_addr_cells(dev_ofnode(dev->parent)); |
| 1257 | size_cells = ofnode_read_simple_size_cells(dev_ofnode(dev)); |
| 1258 | |
| 1259 | /* PCI addresses are always 3-cells */ |
| 1260 | len /= sizeof(u32); |
| 1261 | cells_per_record = pci_addr_cells + addr_cells + size_cells; |
| 1262 | debug("%s: len=%d, cells_per_record=%d\n", __func__, len, |
| 1263 | cells_per_record); |
| 1264 | |
| 1265 | while (len) { |
| 1266 | memp->bus_start = fdtdec_get_number(prop + 1, 2); |
| 1267 | prop += pci_addr_cells; |
| 1268 | memp->phys_start = fdtdec_get_number(prop, addr_cells); |
| 1269 | prop += addr_cells; |
| 1270 | memp->size = fdtdec_get_number(prop, size_cells); |
| 1271 | prop += size_cells; |
| 1272 | |
| 1273 | if (i == index) |
| 1274 | return 0; |
| 1275 | i++; |
| 1276 | len -= cells_per_record; |
| 1277 | } |
| 1278 | |
| 1279 | return -EINVAL; |
| 1280 | } |
| 1281 | |
Simon Glass | dcdc012 | 2015-11-19 20:27:01 -0700 | [diff] [blame] | 1282 | int pci_get_regions(struct udevice *dev, struct pci_region **iop, |
| 1283 | struct pci_region **memp, struct pci_region **prefp) |
| 1284 | { |
| 1285 | struct udevice *bus = pci_get_controller(dev); |
| 1286 | struct pci_controller *hose = dev_get_uclass_priv(bus); |
| 1287 | int i; |
| 1288 | |
| 1289 | *iop = NULL; |
| 1290 | *memp = NULL; |
| 1291 | *prefp = NULL; |
| 1292 | for (i = 0; i < hose->region_count; i++) { |
| 1293 | switch (hose->regions[i].flags) { |
| 1294 | case PCI_REGION_IO: |
| 1295 | if (!*iop || (*iop)->size < hose->regions[i].size) |
| 1296 | *iop = hose->regions + i; |
| 1297 | break; |
| 1298 | case PCI_REGION_MEM: |
| 1299 | if (!*memp || (*memp)->size < hose->regions[i].size) |
| 1300 | *memp = hose->regions + i; |
| 1301 | break; |
| 1302 | case (PCI_REGION_MEM | PCI_REGION_PREFETCH): |
| 1303 | if (!*prefp || (*prefp)->size < hose->regions[i].size) |
| 1304 | *prefp = hose->regions + i; |
| 1305 | break; |
| 1306 | } |
| 1307 | } |
| 1308 | |
| 1309 | return (*iop != NULL) + (*memp != NULL) + (*prefp != NULL); |
| 1310 | } |
| 1311 | |
Simon Glass | c92aac1 | 2020-01-27 08:49:38 -0700 | [diff] [blame] | 1312 | u32 dm_pci_read_bar32(const struct udevice *dev, int barnum) |
Simon Glass | 3452cb1 | 2015-11-29 13:17:53 -0700 | [diff] [blame] | 1313 | { |
| 1314 | u32 addr; |
| 1315 | int bar; |
| 1316 | |
| 1317 | bar = PCI_BASE_ADDRESS_0 + barnum * 4; |
| 1318 | dm_pci_read_config32(dev, bar, &addr); |
Simon Glass | 71fafd1 | 2020-04-09 10:27:36 -0600 | [diff] [blame] | 1319 | |
| 1320 | /* |
| 1321 | * If we get an invalid address, return this so that comparisons with |
| 1322 | * FDT_ADDR_T_NONE work correctly |
| 1323 | */ |
| 1324 | if (addr == 0xffffffff) |
| 1325 | return addr; |
| 1326 | else if (addr & PCI_BASE_ADDRESS_SPACE_IO) |
Simon Glass | 3452cb1 | 2015-11-29 13:17:53 -0700 | [diff] [blame] | 1327 | return addr & PCI_BASE_ADDRESS_IO_MASK; |
| 1328 | else |
| 1329 | return addr & PCI_BASE_ADDRESS_MEM_MASK; |
| 1330 | } |
| 1331 | |
Simon Glass | e2b6b56 | 2016-01-18 20:19:15 -0700 | [diff] [blame] | 1332 | void dm_pci_write_bar32(struct udevice *dev, int barnum, u32 addr) |
| 1333 | { |
| 1334 | int bar; |
| 1335 | |
| 1336 | bar = PCI_BASE_ADDRESS_0 + barnum * 4; |
| 1337 | dm_pci_write_config32(dev, bar, addr); |
| 1338 | } |
| 1339 | |
Simon Glass | c5f053b | 2015-11-29 13:18:03 -0700 | [diff] [blame] | 1340 | static int _dm_pci_bus_to_phys(struct udevice *ctlr, |
| 1341 | pci_addr_t bus_addr, unsigned long flags, |
| 1342 | unsigned long skip_mask, phys_addr_t *pa) |
| 1343 | { |
| 1344 | struct pci_controller *hose = dev_get_uclass_priv(ctlr); |
| 1345 | struct pci_region *res; |
| 1346 | int i; |
| 1347 | |
Christian Gmeiner | 7241f80 | 2018-06-10 06:25:06 -0700 | [diff] [blame] | 1348 | if (hose->region_count == 0) { |
| 1349 | *pa = bus_addr; |
| 1350 | return 0; |
| 1351 | } |
| 1352 | |
Simon Glass | c5f053b | 2015-11-29 13:18:03 -0700 | [diff] [blame] | 1353 | for (i = 0; i < hose->region_count; i++) { |
| 1354 | res = &hose->regions[i]; |
| 1355 | |
| 1356 | if (((res->flags ^ flags) & PCI_REGION_TYPE) != 0) |
| 1357 | continue; |
| 1358 | |
| 1359 | if (res->flags & skip_mask) |
| 1360 | continue; |
| 1361 | |
| 1362 | if (bus_addr >= res->bus_start && |
| 1363 | (bus_addr - res->bus_start) < res->size) { |
| 1364 | *pa = (bus_addr - res->bus_start + res->phys_start); |
| 1365 | return 0; |
| 1366 | } |
| 1367 | } |
| 1368 | |
| 1369 | return 1; |
| 1370 | } |
| 1371 | |
| 1372 | phys_addr_t dm_pci_bus_to_phys(struct udevice *dev, pci_addr_t bus_addr, |
| 1373 | unsigned long flags) |
| 1374 | { |
| 1375 | phys_addr_t phys_addr = 0; |
| 1376 | struct udevice *ctlr; |
| 1377 | int ret; |
| 1378 | |
| 1379 | /* The root controller has the region information */ |
| 1380 | ctlr = pci_get_controller(dev); |
| 1381 | |
| 1382 | /* |
| 1383 | * if PCI_REGION_MEM is set we do a two pass search with preference |
| 1384 | * on matches that don't have PCI_REGION_SYS_MEMORY set |
| 1385 | */ |
| 1386 | if ((flags & PCI_REGION_TYPE) == PCI_REGION_MEM) { |
| 1387 | ret = _dm_pci_bus_to_phys(ctlr, bus_addr, |
| 1388 | flags, PCI_REGION_SYS_MEMORY, |
| 1389 | &phys_addr); |
| 1390 | if (!ret) |
| 1391 | return phys_addr; |
| 1392 | } |
| 1393 | |
| 1394 | ret = _dm_pci_bus_to_phys(ctlr, bus_addr, flags, 0, &phys_addr); |
| 1395 | |
| 1396 | if (ret) |
| 1397 | puts("pci_hose_bus_to_phys: invalid physical address\n"); |
| 1398 | |
| 1399 | return phys_addr; |
| 1400 | } |
| 1401 | |
| 1402 | int _dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t phys_addr, |
| 1403 | unsigned long flags, unsigned long skip_mask, |
| 1404 | pci_addr_t *ba) |
| 1405 | { |
| 1406 | struct pci_region *res; |
| 1407 | struct udevice *ctlr; |
| 1408 | pci_addr_t bus_addr; |
| 1409 | int i; |
| 1410 | struct pci_controller *hose; |
| 1411 | |
| 1412 | /* The root controller has the region information */ |
| 1413 | ctlr = pci_get_controller(dev); |
| 1414 | hose = dev_get_uclass_priv(ctlr); |
| 1415 | |
Christian Gmeiner | 7241f80 | 2018-06-10 06:25:06 -0700 | [diff] [blame] | 1416 | if (hose->region_count == 0) { |
| 1417 | *ba = phys_addr; |
| 1418 | return 0; |
| 1419 | } |
| 1420 | |
Simon Glass | c5f053b | 2015-11-29 13:18:03 -0700 | [diff] [blame] | 1421 | for (i = 0; i < hose->region_count; i++) { |
| 1422 | res = &hose->regions[i]; |
| 1423 | |
| 1424 | if (((res->flags ^ flags) & PCI_REGION_TYPE) != 0) |
| 1425 | continue; |
| 1426 | |
| 1427 | if (res->flags & skip_mask) |
| 1428 | continue; |
| 1429 | |
| 1430 | bus_addr = phys_addr - res->phys_start + res->bus_start; |
| 1431 | |
| 1432 | if (bus_addr >= res->bus_start && |
| 1433 | (bus_addr - res->bus_start) < res->size) { |
| 1434 | *ba = bus_addr; |
| 1435 | return 0; |
| 1436 | } |
| 1437 | } |
| 1438 | |
| 1439 | return 1; |
| 1440 | } |
| 1441 | |
| 1442 | pci_addr_t dm_pci_phys_to_bus(struct udevice *dev, phys_addr_t phys_addr, |
| 1443 | unsigned long flags) |
| 1444 | { |
| 1445 | pci_addr_t bus_addr = 0; |
| 1446 | int ret; |
| 1447 | |
| 1448 | /* |
| 1449 | * if PCI_REGION_MEM is set we do a two pass search with preference |
| 1450 | * on matches that don't have PCI_REGION_SYS_MEMORY set |
| 1451 | */ |
| 1452 | if ((flags & PCI_REGION_TYPE) == PCI_REGION_MEM) { |
| 1453 | ret = _dm_pci_phys_to_bus(dev, phys_addr, flags, |
| 1454 | PCI_REGION_SYS_MEMORY, &bus_addr); |
| 1455 | if (!ret) |
| 1456 | return bus_addr; |
| 1457 | } |
| 1458 | |
| 1459 | ret = _dm_pci_phys_to_bus(dev, phys_addr, flags, 0, &bus_addr); |
| 1460 | |
| 1461 | if (ret) |
| 1462 | puts("pci_hose_phys_to_bus: invalid physical address\n"); |
| 1463 | |
| 1464 | return bus_addr; |
| 1465 | } |
| 1466 | |
Suneel Garapati | 5858ba8 | 2019-10-19 16:34:16 -0700 | [diff] [blame] | 1467 | static phys_addr_t dm_pci_map_ea_virt(struct udevice *dev, int ea_off, |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 1468 | struct pci_child_plat *pdata) |
Suneel Garapati | 5858ba8 | 2019-10-19 16:34:16 -0700 | [diff] [blame] | 1469 | { |
| 1470 | phys_addr_t addr = 0; |
| 1471 | |
| 1472 | /* |
| 1473 | * In the case of a Virtual Function device using BAR |
| 1474 | * base and size, add offset for VFn BAR(1, 2, 3...n) |
| 1475 | */ |
| 1476 | if (pdata->is_virtfn) { |
| 1477 | size_t sz; |
| 1478 | u32 ea_entry; |
| 1479 | |
| 1480 | /* MaxOffset, 1st DW */ |
| 1481 | dm_pci_read_config32(dev, ea_off + 8, &ea_entry); |
| 1482 | sz = ea_entry & PCI_EA_FIELD_MASK; |
| 1483 | /* Fill up lower 2 bits */ |
| 1484 | sz |= (~PCI_EA_FIELD_MASK); |
| 1485 | |
| 1486 | if (ea_entry & PCI_EA_IS_64) { |
| 1487 | /* MaxOffset 2nd DW */ |
| 1488 | dm_pci_read_config32(dev, ea_off + 16, &ea_entry); |
| 1489 | sz |= ((u64)ea_entry) << 32; |
| 1490 | } |
| 1491 | |
| 1492 | addr = (pdata->virtid - 1) * (sz + 1); |
| 1493 | } |
| 1494 | |
| 1495 | return addr; |
| 1496 | } |
| 1497 | |
Alex Marginean | 1c934a6 | 2019-06-07 11:24:23 +0300 | [diff] [blame] | 1498 | static void *dm_pci_map_ea_bar(struct udevice *dev, int bar, int flags, |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 1499 | int ea_off, struct pci_child_plat *pdata) |
Alex Marginean | 1c934a6 | 2019-06-07 11:24:23 +0300 | [diff] [blame] | 1500 | { |
| 1501 | int ea_cnt, i, entry_size; |
| 1502 | int bar_id = (bar - PCI_BASE_ADDRESS_0) >> 2; |
| 1503 | u32 ea_entry; |
| 1504 | phys_addr_t addr; |
| 1505 | |
Suneel Garapati | 5858ba8 | 2019-10-19 16:34:16 -0700 | [diff] [blame] | 1506 | if (IS_ENABLED(CONFIG_PCI_SRIOV)) { |
| 1507 | /* |
| 1508 | * In the case of a Virtual Function device, device is |
| 1509 | * Physical function, so pdata will point to required VF |
| 1510 | * specific data. |
| 1511 | */ |
| 1512 | if (pdata->is_virtfn) |
| 1513 | bar_id += PCI_EA_BEI_VF_BAR0; |
| 1514 | } |
| 1515 | |
Alex Marginean | 1c934a6 | 2019-06-07 11:24:23 +0300 | [diff] [blame] | 1516 | /* EA capability structure header */ |
| 1517 | dm_pci_read_config32(dev, ea_off, &ea_entry); |
| 1518 | ea_cnt = (ea_entry >> 16) & PCI_EA_NUM_ENT_MASK; |
| 1519 | ea_off += PCI_EA_FIRST_ENT; |
| 1520 | |
| 1521 | for (i = 0; i < ea_cnt; i++, ea_off += entry_size) { |
| 1522 | /* Entry header */ |
| 1523 | dm_pci_read_config32(dev, ea_off, &ea_entry); |
| 1524 | entry_size = ((ea_entry & PCI_EA_ES) + 1) << 2; |
| 1525 | |
| 1526 | if (((ea_entry & PCI_EA_BEI) >> 4) != bar_id) |
| 1527 | continue; |
| 1528 | |
| 1529 | /* Base address, 1st DW */ |
| 1530 | dm_pci_read_config32(dev, ea_off + 4, &ea_entry); |
| 1531 | addr = ea_entry & PCI_EA_FIELD_MASK; |
| 1532 | if (ea_entry & PCI_EA_IS_64) { |
| 1533 | /* Base address, 2nd DW, skip over 4B MaxOffset */ |
| 1534 | dm_pci_read_config32(dev, ea_off + 12, &ea_entry); |
| 1535 | addr |= ((u64)ea_entry) << 32; |
| 1536 | } |
| 1537 | |
Suneel Garapati | 5858ba8 | 2019-10-19 16:34:16 -0700 | [diff] [blame] | 1538 | if (IS_ENABLED(CONFIG_PCI_SRIOV)) |
| 1539 | addr += dm_pci_map_ea_virt(dev, ea_off, pdata); |
| 1540 | |
Alex Marginean | 1c934a6 | 2019-06-07 11:24:23 +0300 | [diff] [blame] | 1541 | /* size ignored for now */ |
Suneel Garapati | 47f1962 | 2019-10-19 16:44:35 -0700 | [diff] [blame] | 1542 | return map_physmem(addr, 0, flags); |
Alex Marginean | 1c934a6 | 2019-06-07 11:24:23 +0300 | [diff] [blame] | 1543 | } |
| 1544 | |
| 1545 | return 0; |
| 1546 | } |
| 1547 | |
Simon Glass | c5f053b | 2015-11-29 13:18:03 -0700 | [diff] [blame] | 1548 | void *dm_pci_map_bar(struct udevice *dev, int bar, int flags) |
| 1549 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 1550 | struct pci_child_plat *pdata = dev_get_parent_plat(dev); |
Suneel Garapati | 5858ba8 | 2019-10-19 16:34:16 -0700 | [diff] [blame] | 1551 | struct udevice *udev = dev; |
Simon Glass | c5f053b | 2015-11-29 13:18:03 -0700 | [diff] [blame] | 1552 | pci_addr_t pci_bus_addr; |
| 1553 | u32 bar_response; |
Alex Marginean | 1c934a6 | 2019-06-07 11:24:23 +0300 | [diff] [blame] | 1554 | int ea_off; |
| 1555 | |
Suneel Garapati | 5858ba8 | 2019-10-19 16:34:16 -0700 | [diff] [blame] | 1556 | if (IS_ENABLED(CONFIG_PCI_SRIOV)) { |
| 1557 | /* |
| 1558 | * In case of Virtual Function devices, use PF udevice |
| 1559 | * as EA capability is defined in Physical Function |
| 1560 | */ |
| 1561 | if (pdata->is_virtfn) |
| 1562 | udev = pdata->pfdev; |
| 1563 | } |
| 1564 | |
Alex Marginean | 1c934a6 | 2019-06-07 11:24:23 +0300 | [diff] [blame] | 1565 | /* |
| 1566 | * if the function supports Enhanced Allocation use that instead of |
| 1567 | * BARs |
Suneel Garapati | 5858ba8 | 2019-10-19 16:34:16 -0700 | [diff] [blame] | 1568 | * Incase of virtual functions, pdata will help read VF BEI |
| 1569 | * and EA entry size. |
Alex Marginean | 1c934a6 | 2019-06-07 11:24:23 +0300 | [diff] [blame] | 1570 | */ |
Suneel Garapati | 5858ba8 | 2019-10-19 16:34:16 -0700 | [diff] [blame] | 1571 | ea_off = dm_pci_find_capability(udev, PCI_CAP_ID_EA); |
Alex Marginean | 1c934a6 | 2019-06-07 11:24:23 +0300 | [diff] [blame] | 1572 | if (ea_off) |
Suneel Garapati | 5858ba8 | 2019-10-19 16:34:16 -0700 | [diff] [blame] | 1573 | return dm_pci_map_ea_bar(udev, bar, flags, ea_off, pdata); |
Simon Glass | c5f053b | 2015-11-29 13:18:03 -0700 | [diff] [blame] | 1574 | |
| 1575 | /* read BAR address */ |
Suneel Garapati | 5858ba8 | 2019-10-19 16:34:16 -0700 | [diff] [blame] | 1576 | dm_pci_read_config32(udev, bar, &bar_response); |
Simon Glass | c5f053b | 2015-11-29 13:18:03 -0700 | [diff] [blame] | 1577 | pci_bus_addr = (pci_addr_t)(bar_response & ~0xf); |
| 1578 | |
| 1579 | /* |
| 1580 | * Pass "0" as the length argument to pci_bus_to_virt. The arg |
Suneel Garapati | 47f1962 | 2019-10-19 16:44:35 -0700 | [diff] [blame] | 1581 | * isn't actually used on any platform because U-Boot assumes a static |
Simon Glass | c5f053b | 2015-11-29 13:18:03 -0700 | [diff] [blame] | 1582 | * linear mapping. In the future, this could read the BAR size |
| 1583 | * and pass that as the size if needed. |
| 1584 | */ |
Suneel Garapati | 5858ba8 | 2019-10-19 16:34:16 -0700 | [diff] [blame] | 1585 | return dm_pci_bus_to_virt(udev, pci_bus_addr, flags, 0, MAP_NOCACHE); |
Simon Glass | c5f053b | 2015-11-29 13:18:03 -0700 | [diff] [blame] | 1586 | } |
| 1587 | |
Bin Meng | 631f348 | 2018-10-15 02:21:21 -0700 | [diff] [blame] | 1588 | static int _dm_pci_find_next_capability(struct udevice *dev, u8 pos, int cap) |
Bin Meng | a7366f0 | 2018-08-03 01:14:52 -0700 | [diff] [blame] | 1589 | { |
Bin Meng | a7366f0 | 2018-08-03 01:14:52 -0700 | [diff] [blame] | 1590 | int ttl = PCI_FIND_CAP_TTL; |
| 1591 | u8 id; |
| 1592 | u16 ent; |
Bin Meng | a7366f0 | 2018-08-03 01:14:52 -0700 | [diff] [blame] | 1593 | |
| 1594 | dm_pci_read_config8(dev, pos, &pos); |
Bin Meng | 631f348 | 2018-10-15 02:21:21 -0700 | [diff] [blame] | 1595 | |
Bin Meng | a7366f0 | 2018-08-03 01:14:52 -0700 | [diff] [blame] | 1596 | while (ttl--) { |
| 1597 | if (pos < PCI_STD_HEADER_SIZEOF) |
| 1598 | break; |
| 1599 | pos &= ~3; |
| 1600 | dm_pci_read_config16(dev, pos, &ent); |
| 1601 | |
| 1602 | id = ent & 0xff; |
| 1603 | if (id == 0xff) |
| 1604 | break; |
| 1605 | if (id == cap) |
| 1606 | return pos; |
| 1607 | pos = (ent >> 8); |
| 1608 | } |
| 1609 | |
| 1610 | return 0; |
| 1611 | } |
| 1612 | |
Bin Meng | 631f348 | 2018-10-15 02:21:21 -0700 | [diff] [blame] | 1613 | int dm_pci_find_next_capability(struct udevice *dev, u8 start, int cap) |
| 1614 | { |
| 1615 | return _dm_pci_find_next_capability(dev, start + PCI_CAP_LIST_NEXT, |
| 1616 | cap); |
| 1617 | } |
| 1618 | |
| 1619 | int dm_pci_find_capability(struct udevice *dev, int cap) |
| 1620 | { |
| 1621 | u16 status; |
| 1622 | u8 header_type; |
| 1623 | u8 pos; |
| 1624 | |
| 1625 | dm_pci_read_config16(dev, PCI_STATUS, &status); |
| 1626 | if (!(status & PCI_STATUS_CAP_LIST)) |
| 1627 | return 0; |
| 1628 | |
| 1629 | dm_pci_read_config8(dev, PCI_HEADER_TYPE, &header_type); |
| 1630 | if ((header_type & 0x7f) == PCI_HEADER_TYPE_CARDBUS) |
| 1631 | pos = PCI_CB_CAPABILITY_LIST; |
| 1632 | else |
| 1633 | pos = PCI_CAPABILITY_LIST; |
| 1634 | |
| 1635 | return _dm_pci_find_next_capability(dev, pos, cap); |
| 1636 | } |
| 1637 | |
| 1638 | int dm_pci_find_next_ext_capability(struct udevice *dev, int start, int cap) |
Bin Meng | a7366f0 | 2018-08-03 01:14:52 -0700 | [diff] [blame] | 1639 | { |
| 1640 | u32 header; |
| 1641 | int ttl; |
| 1642 | int pos = PCI_CFG_SPACE_SIZE; |
| 1643 | |
| 1644 | /* minimum 8 bytes per capability */ |
| 1645 | ttl = (PCI_CFG_SPACE_EXP_SIZE - PCI_CFG_SPACE_SIZE) / 8; |
| 1646 | |
Bin Meng | 631f348 | 2018-10-15 02:21:21 -0700 | [diff] [blame] | 1647 | if (start) |
| 1648 | pos = start; |
| 1649 | |
Bin Meng | a7366f0 | 2018-08-03 01:14:52 -0700 | [diff] [blame] | 1650 | dm_pci_read_config32(dev, pos, &header); |
| 1651 | /* |
| 1652 | * If we have no capabilities, this is indicated by cap ID, |
| 1653 | * cap version and next pointer all being 0. |
| 1654 | */ |
| 1655 | if (header == 0) |
| 1656 | return 0; |
| 1657 | |
| 1658 | while (ttl--) { |
| 1659 | if (PCI_EXT_CAP_ID(header) == cap) |
| 1660 | return pos; |
| 1661 | |
| 1662 | pos = PCI_EXT_CAP_NEXT(header); |
| 1663 | if (pos < PCI_CFG_SPACE_SIZE) |
| 1664 | break; |
| 1665 | |
| 1666 | dm_pci_read_config32(dev, pos, &header); |
| 1667 | } |
| 1668 | |
| 1669 | return 0; |
| 1670 | } |
| 1671 | |
Bin Meng | 631f348 | 2018-10-15 02:21:21 -0700 | [diff] [blame] | 1672 | int dm_pci_find_ext_capability(struct udevice *dev, int cap) |
| 1673 | { |
| 1674 | return dm_pci_find_next_ext_capability(dev, 0, cap); |
| 1675 | } |
| 1676 | |
Alex Marginean | 09467d3 | 2019-06-07 11:24:25 +0300 | [diff] [blame] | 1677 | int dm_pci_flr(struct udevice *dev) |
| 1678 | { |
| 1679 | int pcie_off; |
| 1680 | u32 cap; |
| 1681 | |
| 1682 | /* look for PCI Express Capability */ |
| 1683 | pcie_off = dm_pci_find_capability(dev, PCI_CAP_ID_EXP); |
| 1684 | if (!pcie_off) |
| 1685 | return -ENOENT; |
| 1686 | |
| 1687 | /* check FLR capability */ |
| 1688 | dm_pci_read_config32(dev, pcie_off + PCI_EXP_DEVCAP, &cap); |
| 1689 | if (!(cap & PCI_EXP_DEVCAP_FLR)) |
| 1690 | return -ENOENT; |
| 1691 | |
| 1692 | dm_pci_clrset_config16(dev, pcie_off + PCI_EXP_DEVCTL, 0, |
| 1693 | PCI_EXP_DEVCTL_BCR_FLR); |
| 1694 | |
| 1695 | /* wait 100ms, per PCI spec */ |
| 1696 | mdelay(100); |
| 1697 | |
| 1698 | return 0; |
| 1699 | } |
| 1700 | |
Suneel Garapati | 13822f7 | 2019-10-19 16:07:20 -0700 | [diff] [blame] | 1701 | #if defined(CONFIG_PCI_SRIOV) |
| 1702 | int pci_sriov_init(struct udevice *pdev, int vf_en) |
| 1703 | { |
| 1704 | u16 vendor, device; |
| 1705 | struct udevice *bus; |
| 1706 | struct udevice *dev; |
| 1707 | pci_dev_t bdf; |
| 1708 | u16 ctrl; |
| 1709 | u16 num_vfs; |
| 1710 | u16 total_vf; |
| 1711 | u16 vf_offset; |
| 1712 | u16 vf_stride; |
| 1713 | int vf, ret; |
| 1714 | int pos; |
| 1715 | |
| 1716 | pos = dm_pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV); |
| 1717 | if (!pos) { |
| 1718 | debug("Error: SRIOV capability not found\n"); |
| 1719 | return -ENOENT; |
| 1720 | } |
| 1721 | |
| 1722 | dm_pci_read_config16(pdev, pos + PCI_SRIOV_CTRL, &ctrl); |
| 1723 | |
| 1724 | dm_pci_read_config16(pdev, pos + PCI_SRIOV_TOTAL_VF, &total_vf); |
| 1725 | if (vf_en > total_vf) |
| 1726 | vf_en = total_vf; |
| 1727 | dm_pci_write_config16(pdev, pos + PCI_SRIOV_NUM_VF, vf_en); |
| 1728 | |
| 1729 | ctrl |= PCI_SRIOV_CTRL_VFE | PCI_SRIOV_CTRL_MSE; |
| 1730 | dm_pci_write_config16(pdev, pos + PCI_SRIOV_CTRL, ctrl); |
| 1731 | |
| 1732 | dm_pci_read_config16(pdev, pos + PCI_SRIOV_NUM_VF, &num_vfs); |
| 1733 | if (num_vfs > vf_en) |
| 1734 | num_vfs = vf_en; |
| 1735 | |
| 1736 | dm_pci_read_config16(pdev, pos + PCI_SRIOV_VF_OFFSET, &vf_offset); |
| 1737 | dm_pci_read_config16(pdev, pos + PCI_SRIOV_VF_STRIDE, &vf_stride); |
| 1738 | |
| 1739 | dm_pci_read_config16(pdev, PCI_VENDOR_ID, &vendor); |
| 1740 | dm_pci_read_config16(pdev, pos + PCI_SRIOV_VF_DID, &device); |
| 1741 | |
| 1742 | bdf = dm_pci_get_bdf(pdev); |
| 1743 | |
| 1744 | pci_get_bus(PCI_BUS(bdf), &bus); |
| 1745 | |
| 1746 | if (!bus) |
| 1747 | return -ENODEV; |
| 1748 | |
| 1749 | bdf += PCI_BDF(0, 0, vf_offset); |
| 1750 | |
| 1751 | for (vf = 0; vf < num_vfs; vf++) { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 1752 | struct pci_child_plat *pplat; |
Suneel Garapati | 13822f7 | 2019-10-19 16:07:20 -0700 | [diff] [blame] | 1753 | ulong class; |
| 1754 | |
| 1755 | pci_bus_read_config(bus, bdf, PCI_CLASS_DEVICE, |
| 1756 | &class, PCI_SIZE_16); |
| 1757 | |
| 1758 | debug("%s: bus %d/%s: found VF %x:%x\n", __func__, |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 1759 | dev_seq(bus), bus->name, PCI_DEV(bdf), PCI_FUNC(bdf)); |
Suneel Garapati | 13822f7 | 2019-10-19 16:07:20 -0700 | [diff] [blame] | 1760 | |
| 1761 | /* Find this device in the device tree */ |
| 1762 | ret = pci_bus_find_devfn(bus, PCI_MASK_BUS(bdf), &dev); |
| 1763 | |
| 1764 | if (ret == -ENODEV) { |
| 1765 | struct pci_device_id find_id; |
| 1766 | |
| 1767 | memset(&find_id, '\0', sizeof(find_id)); |
| 1768 | find_id.vendor = vendor; |
| 1769 | find_id.device = device; |
| 1770 | find_id.class = class; |
| 1771 | |
| 1772 | ret = pci_find_and_bind_driver(bus, &find_id, |
| 1773 | bdf, &dev); |
| 1774 | |
| 1775 | if (ret) |
| 1776 | return ret; |
| 1777 | } |
| 1778 | |
| 1779 | /* Update the platform data */ |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 1780 | pplat = dev_get_parent_plat(dev); |
Suneel Garapati | 13822f7 | 2019-10-19 16:07:20 -0700 | [diff] [blame] | 1781 | pplat->devfn = PCI_MASK_BUS(bdf); |
| 1782 | pplat->vendor = vendor; |
| 1783 | pplat->device = device; |
| 1784 | pplat->class = class; |
| 1785 | pplat->is_virtfn = true; |
| 1786 | pplat->pfdev = pdev; |
| 1787 | pplat->virtid = vf * vf_stride + vf_offset; |
| 1788 | |
| 1789 | debug("%s: bus %d/%s: found VF %x:%x %x:%x class %lx id %x\n", |
Simon Glass | 75e534b | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 1790 | __func__, dev_seq(dev), dev->name, PCI_DEV(bdf), |
Suneel Garapati | 13822f7 | 2019-10-19 16:07:20 -0700 | [diff] [blame] | 1791 | PCI_FUNC(bdf), vendor, device, class, pplat->virtid); |
| 1792 | bdf += PCI_BDF(0, 0, vf_stride); |
| 1793 | } |
| 1794 | |
| 1795 | return 0; |
| 1796 | } |
| 1797 | |
| 1798 | int pci_sriov_get_totalvfs(struct udevice *pdev) |
| 1799 | { |
| 1800 | u16 total_vf; |
| 1801 | int pos; |
| 1802 | |
| 1803 | pos = dm_pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_SRIOV); |
| 1804 | if (!pos) { |
| 1805 | debug("Error: SRIOV capability not found\n"); |
| 1806 | return -ENOENT; |
| 1807 | } |
| 1808 | |
| 1809 | dm_pci_read_config16(pdev, pos + PCI_SRIOV_TOTAL_VF, &total_vf); |
| 1810 | |
| 1811 | return total_vf; |
| 1812 | } |
| 1813 | #endif /* SRIOV */ |
| 1814 | |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 1815 | UCLASS_DRIVER(pci) = { |
| 1816 | .id = UCLASS_PCI, |
| 1817 | .name = "pci", |
Simon Glass | be70610 | 2020-12-16 21:20:18 -0700 | [diff] [blame] | 1818 | .flags = DM_UC_FLAG_SEQ_ALIAS | DM_UC_FLAG_NO_AUTO_SEQ, |
Simon Glass | 1823034 | 2016-07-05 17:10:10 -0600 | [diff] [blame] | 1819 | .post_bind = dm_scan_fdt_dev, |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 1820 | .pre_probe = pci_uclass_pre_probe, |
| 1821 | .post_probe = pci_uclass_post_probe, |
| 1822 | .child_post_bind = pci_uclass_child_post_bind, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 1823 | .per_device_auto = sizeof(struct pci_controller), |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 1824 | .per_child_plat_auto = sizeof(struct pci_child_plat), |
Simon Glass | b94dc89 | 2015-03-05 12:25:25 -0700 | [diff] [blame] | 1825 | }; |
| 1826 | |
| 1827 | static const struct dm_pci_ops pci_bridge_ops = { |
| 1828 | .read_config = pci_bridge_read_config, |
| 1829 | .write_config = pci_bridge_write_config, |
| 1830 | }; |
| 1831 | |
| 1832 | static const struct udevice_id pci_bridge_ids[] = { |
| 1833 | { .compatible = "pci-bridge" }, |
| 1834 | { } |
| 1835 | }; |
| 1836 | |
| 1837 | U_BOOT_DRIVER(pci_bridge_drv) = { |
| 1838 | .name = "pci_bridge_drv", |
| 1839 | .id = UCLASS_PCI, |
| 1840 | .of_match = pci_bridge_ids, |
| 1841 | .ops = &pci_bridge_ops, |
| 1842 | }; |
| 1843 | |
| 1844 | UCLASS_DRIVER(pci_generic) = { |
| 1845 | .id = UCLASS_PCI_GENERIC, |
| 1846 | .name = "pci_generic", |
| 1847 | }; |
| 1848 | |
| 1849 | static const struct udevice_id pci_generic_ids[] = { |
| 1850 | { .compatible = "pci-generic" }, |
| 1851 | { } |
| 1852 | }; |
| 1853 | |
| 1854 | U_BOOT_DRIVER(pci_generic_drv) = { |
| 1855 | .name = "pci_generic_drv", |
| 1856 | .id = UCLASS_PCI_GENERIC, |
| 1857 | .of_match = pci_generic_ids, |
| 1858 | }; |
Stephen Warren | 04eb269 | 2016-01-26 11:10:11 -0700 | [diff] [blame] | 1859 | |
Ovidiu Panait | e353edb | 2020-11-28 10:43:12 +0200 | [diff] [blame] | 1860 | int pci_init(void) |
Stephen Warren | 04eb269 | 2016-01-26 11:10:11 -0700 | [diff] [blame] | 1861 | { |
| 1862 | struct udevice *bus; |
| 1863 | |
| 1864 | /* |
| 1865 | * Enumerate all known controller devices. Enumeration has the side- |
| 1866 | * effect of probing them, so PCIe devices will be enumerated too. |
| 1867 | */ |
Marek BehĂșn | 5df208d | 2019-05-21 12:04:31 +0200 | [diff] [blame] | 1868 | for (uclass_first_device_check(UCLASS_PCI, &bus); |
Stephen Warren | 04eb269 | 2016-01-26 11:10:11 -0700 | [diff] [blame] | 1869 | bus; |
Marek BehĂșn | 5df208d | 2019-05-21 12:04:31 +0200 | [diff] [blame] | 1870 | uclass_next_device_check(&bus)) { |
Stephen Warren | 04eb269 | 2016-01-26 11:10:11 -0700 | [diff] [blame] | 1871 | ; |
| 1872 | } |
Ovidiu Panait | e353edb | 2020-11-28 10:43:12 +0200 | [diff] [blame] | 1873 | |
| 1874 | return 0; |
Stephen Warren | 04eb269 | 2016-01-26 11:10:11 -0700 | [diff] [blame] | 1875 | } |