Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1 | /* |
Stefan Reinauer | 7e61e45 | 2008-01-18 10:35:56 +0000 | [diff] [blame] | 2 | * This file is part of the coreboot project. |
Uwe Hermann | b80dbf0 | 2007-04-22 19:08:13 +0000 | [diff] [blame] | 3 | * |
| 4 | * It was originally based on the Linux kernel (arch/i386/kernel/pci-pc.c). |
| 5 | * |
| 6 | * Modifications are: |
| 7 | * Copyright (C) 2003 Eric Biederman <ebiederm@xmission.com> |
| 8 | * Copyright (C) 2003-2004 Linux Networx |
| 9 | * (Written by Eric Biederman <ebiederman@lnxi.com> for Linux Networx) |
| 10 | * Copyright (C) 2003 Ronald G. Minnich <rminnich@gmail.com> |
| 11 | * Copyright (C) 2004-2005 Li-Ta Lo <ollie@lanl.gov> |
| 12 | * Copyright (C) 2005-2006 Tyan |
| 13 | * (Written by Yinghai Lu <yhlu@tyan.com> for Tyan) |
| 14 | * Copyright (C) 2005-2006 Stefan Reinauer <stepan@openbios.org> |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 15 | * Copyright (C) 2009 Myles Watson <mylesgw@gmail.com> |
Martin Roth | bb5953d | 2016-04-11 20:53:39 -0600 | [diff] [blame] | 16 | * Copyright (c) 1999--2000 Martin Mares <mj@suse.cz> |
| 17 | * |
| 18 | * This program is free software; you can redistribute it and/or modify |
| 19 | * it under the terms of the GNU General Public License as published by |
| 20 | * the Free Software Foundation; version 2 of the License. |
| 21 | * |
| 22 | * This program is distributed in the hope that it will be useful, |
| 23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 25 | * GNU General Public License for more details. |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 26 | */ |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 27 | |
| 28 | /* |
| 29 | * Lots of mods by Ron Minnich <rminnich@lanl.gov>, with |
| 30 | * the final architecture guidance from Tom Merritt <tjm@codegen.com>. |
| 31 | * |
Myles Watson | 032a965 | 2009-05-11 22:24:53 +0000 | [diff] [blame] | 32 | * In particular, we changed from the one-pass original version to |
| 33 | * Tom's recommended multiple-pass version. I wasn't sure about doing |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 34 | * it with multiple passes, until I actually started doing it and saw |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 35 | * the wisdom of Tom's recommendations... |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 36 | * |
| 37 | * Lots of cleanups by Eric Biederman to handle bridges, and to |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 38 | * handle resource allocation for non-PCI devices. |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 39 | */ |
| 40 | |
| 41 | #include <console/console.h> |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 42 | #include <device/device.h> |
Kyösti Mälkki | 318066f | 2014-02-12 14:18:50 +0200 | [diff] [blame] | 43 | #include <device/pci_def.h> |
Li-Ta Lo | 54f05f6 | 2004-05-14 17:20:29 +0000 | [diff] [blame] | 44 | #include <device/pci_ids.h> |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 45 | #include <stdlib.h> |
| 46 | #include <string.h> |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 47 | #include <smp/spinlock.h> |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 48 | #if CONFIG(ARCH_X86) |
Duncan Laurie | b4aaaa7 | 2012-01-17 09:03:11 -0800 | [diff] [blame] | 49 | #include <arch/ebda.h> |
| 50 | #endif |
Aaron Durbin | 0529429 | 2013-04-30 15:41:13 -0500 | [diff] [blame] | 51 | #include <timer.h> |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 52 | |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 53 | /** Pointer to the last device */ |
Myles Watson | 70679a0 | 2010-09-01 21:03:03 +0000 | [diff] [blame] | 54 | extern struct device *last_dev; |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 55 | /** Linked list of free resources */ |
| 56 | struct resource *free_resources = NULL; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 57 | |
Nico Huber | acd7d95 | 2012-07-25 10:33:05 +0200 | [diff] [blame] | 58 | /** |
| 59 | * Initialize all chips of statically known devices. |
| 60 | * |
| 61 | * Will be called before bus enumeration to initialize chips stated in the |
| 62 | * device tree. |
| 63 | */ |
| 64 | void dev_initialize_chips(void) |
| 65 | { |
Lubomir Rintel | 9ba8f7c | 2018-04-26 00:00:22 +0200 | [diff] [blame] | 66 | const struct device *dev; |
Nico Huber | acd7d95 | 2012-07-25 10:33:05 +0200 | [diff] [blame] | 67 | |
| 68 | for (dev = all_devices; dev; dev = dev->next) { |
| 69 | /* Initialize chip if we haven't yet. */ |
| 70 | if (dev->chip_ops && dev->chip_ops->init && |
| 71 | !dev->chip_ops->initialized) { |
Duncan Laurie | 8adf7a2 | 2013-06-10 10:34:20 -0700 | [diff] [blame] | 72 | post_log_path(dev); |
Nico Huber | acd7d95 | 2012-07-25 10:33:05 +0200 | [diff] [blame] | 73 | dev->chip_ops->init(dev->chip_info); |
| 74 | dev->chip_ops->initialized = 1; |
| 75 | } |
| 76 | } |
Duncan Laurie | 8adf7a2 | 2013-06-10 10:34:20 -0700 | [diff] [blame] | 77 | post_log_clear(); |
Nico Huber | acd7d95 | 2012-07-25 10:33:05 +0200 | [diff] [blame] | 78 | } |
| 79 | |
Marc Jones | 2a58ecd | 2013-10-29 17:32:00 -0600 | [diff] [blame] | 80 | /** |
| 81 | * Finalize all chips of statically known devices. |
| 82 | * |
| 83 | * This is the last call before calling the payload. This is a good place |
| 84 | * to lock registers or other final cleanup. |
| 85 | */ |
| 86 | void dev_finalize_chips(void) |
| 87 | { |
Lubomir Rintel | 9ba8f7c | 2018-04-26 00:00:22 +0200 | [diff] [blame] | 88 | const struct device *dev; |
Marc Jones | 2a58ecd | 2013-10-29 17:32:00 -0600 | [diff] [blame] | 89 | |
| 90 | for (dev = all_devices; dev; dev = dev->next) { |
| 91 | /* Initialize chip if we haven't yet. */ |
| 92 | if (dev->chip_ops && dev->chip_ops->final && |
| 93 | !dev->chip_ops->finalized) { |
| 94 | dev->chip_ops->final(dev->chip_info); |
| 95 | dev->chip_ops->finalized = 1; |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 100 | DECLARE_SPIN_LOCK(dev_lock) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 101 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 102 | #if CONFIG(GFXUMA) |
Kyösti Mälkki | cc55b9b | 2012-07-11 07:55:21 +0300 | [diff] [blame] | 103 | /* IGD UMA memory */ |
| 104 | uint64_t uma_memory_base = 0; |
| 105 | uint64_t uma_memory_size = 0; |
Kyösti Mälkki | b25374c | 2012-08-01 08:05:22 +0300 | [diff] [blame] | 106 | #endif |
Kyösti Mälkki | cc55b9b | 2012-07-11 07:55:21 +0300 | [diff] [blame] | 107 | |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 108 | /** |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 109 | * Allocate a new device structure. |
Myles Watson | 032a965 | 2009-05-11 22:24:53 +0000 | [diff] [blame] | 110 | * |
Martin Roth | 63373ed | 2013-07-08 16:24:19 -0600 | [diff] [blame] | 111 | * Allocate a new device structure and attach it to the device tree as a |
Li-Ta Lo | 9f0d0f9 | 2004-05-10 16:05:16 +0000 | [diff] [blame] | 112 | * child of the parent bus. |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 113 | * |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 114 | * @param parent Parent bus the newly created device should be attached to. |
| 115 | * @param path Path to the device to be created. |
| 116 | * @return Pointer to the newly created device structure. |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 117 | * |
| 118 | * @see device_path |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 119 | */ |
Elyes HAOUAS | d34a785 | 2018-09-17 10:44:14 +0200 | [diff] [blame] | 120 | static struct device *__alloc_dev(struct bus *parent, struct device_path *path) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 121 | { |
Elyes HAOUAS | e348066 | 2018-05-06 20:32:23 +0200 | [diff] [blame] | 122 | struct device *dev, *child; |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 123 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 124 | /* Find the last child of our parent. */ |
Elyes HAOUAS | a342f39 | 2018-10-17 10:56:26 +0200 | [diff] [blame] | 125 | for (child = parent->children; child && child->sibling; /* */) |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 126 | child = child->sibling; |
Li-Ta Lo | 3a81285 | 2004-12-03 22:39:34 +0000 | [diff] [blame] | 127 | |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 128 | dev = malloc(sizeof(*dev)); |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 129 | if (dev == 0) |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 130 | die("alloc_dev(): out of memory.\n"); |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 131 | |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 132 | memset(dev, 0, sizeof(*dev)); |
| 133 | memcpy(&dev->path, path, sizeof(*path)); |
| 134 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 135 | /* By default devices are enabled. */ |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 136 | dev->enabled = 1; |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 137 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 138 | /* Add the new device to the list of children of the bus. */ |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 139 | dev->bus = parent; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 140 | if (child) |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 141 | child->sibling = dev; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 142 | else |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 143 | parent->children = dev; |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 144 | |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 145 | /* Append a new device to the global device list. |
| 146 | * The list is used to find devices once everything is set up. |
| 147 | */ |
Myles Watson | 70679a0 | 2010-09-01 21:03:03 +0000 | [diff] [blame] | 148 | last_dev->next = dev; |
| 149 | last_dev = dev; |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 150 | |
Kyösti Mälkki | a5650a4 | 2012-07-07 17:15:51 +0300 | [diff] [blame] | 151 | return dev; |
| 152 | } |
| 153 | |
Elyes HAOUAS | d34a785 | 2018-09-17 10:44:14 +0200 | [diff] [blame] | 154 | struct device *alloc_dev(struct bus *parent, struct device_path *path) |
Kyösti Mälkki | a5650a4 | 2012-07-07 17:15:51 +0300 | [diff] [blame] | 155 | { |
Elyes HAOUAS | e348066 | 2018-05-06 20:32:23 +0200 | [diff] [blame] | 156 | struct device *dev; |
Kyösti Mälkki | a5650a4 | 2012-07-07 17:15:51 +0300 | [diff] [blame] | 157 | spin_lock(&dev_lock); |
| 158 | dev = __alloc_dev(parent, path); |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 159 | spin_unlock(&dev_lock); |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 160 | return dev; |
| 161 | } |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 162 | |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 163 | /** |
Kyösti Mälkki | a5650a4 | 2012-07-07 17:15:51 +0300 | [diff] [blame] | 164 | * See if a device structure already exists and if not allocate it. |
| 165 | * |
| 166 | * @param parent The bus to find the device on. |
| 167 | * @param path The relative path from the bus to the appropriate device. |
| 168 | * @return Pointer to a device structure for the device on bus at path. |
| 169 | */ |
Elyes HAOUAS | d34a785 | 2018-09-17 10:44:14 +0200 | [diff] [blame] | 170 | struct device *alloc_find_dev(struct bus *parent, struct device_path *path) |
Kyösti Mälkki | a5650a4 | 2012-07-07 17:15:51 +0300 | [diff] [blame] | 171 | { |
Elyes HAOUAS | e348066 | 2018-05-06 20:32:23 +0200 | [diff] [blame] | 172 | struct device *child; |
Kyösti Mälkki | a5650a4 | 2012-07-07 17:15:51 +0300 | [diff] [blame] | 173 | spin_lock(&dev_lock); |
| 174 | child = find_dev_path(parent, path); |
| 175 | if (!child) |
| 176 | child = __alloc_dev(parent, path); |
| 177 | spin_unlock(&dev_lock); |
| 178 | return child; |
| 179 | } |
| 180 | |
| 181 | /** |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 182 | * Round a number up to an alignment. |
| 183 | * |
| 184 | * @param val The starting value. |
Martin Roth | 32bc6b6 | 2015-01-04 16:54:35 -0700 | [diff] [blame] | 185 | * @param pow Alignment as a power of two. |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 186 | * @return Rounded up number. |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 187 | */ |
Eric Biederman | 448bd63 | 2004-10-14 22:52:15 +0000 | [diff] [blame] | 188 | static resource_t round(resource_t val, unsigned long pow) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 189 | { |
Eric Biederman | 448bd63 | 2004-10-14 22:52:15 +0000 | [diff] [blame] | 190 | resource_t mask; |
| 191 | mask = (1ULL << pow) - 1ULL; |
| 192 | val += mask; |
| 193 | val &= ~mask; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 194 | return val; |
| 195 | } |
| 196 | |
Elyes HAOUAS | b0b0c8c | 2018-07-08 12:33:47 +0200 | [diff] [blame] | 197 | static const char *resource2str(struct resource *res) |
Kyösti Mälkki | e6a9290f | 2015-03-23 19:37:38 +0200 | [diff] [blame] | 198 | { |
| 199 | if (res->flags & IORESOURCE_IO) |
| 200 | return "io"; |
| 201 | if (res->flags & IORESOURCE_PREFETCH) |
| 202 | return "prefmem"; |
| 203 | if (res->flags & IORESOURCE_MEM) |
| 204 | return "mem"; |
| 205 | return "undefined"; |
| 206 | } |
| 207 | |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 208 | /** |
| 209 | * Read the resources on all devices of a given bus. |
| 210 | * |
| 211 | * @param bus Bus to read the resources on. |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 212 | */ |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 213 | static void read_resources(struct bus *bus) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 214 | { |
| 215 | struct device *curdev; |
| 216 | |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 217 | printk(BIOS_SPEW, "%s %s bus %x link: %d\n", dev_path(bus->dev), |
| 218 | __func__, bus->secondary, bus->link_num); |
Eric Biederman | 448bd63 | 2004-10-14 22:52:15 +0000 | [diff] [blame] | 219 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 220 | /* Walk through all devices and find which resources they need. */ |
| 221 | for (curdev = bus->children; curdev; curdev = curdev->sibling) { |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 222 | struct bus *link; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 223 | |
| 224 | if (!curdev->enabled) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 225 | continue; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 226 | |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 227 | if (!curdev->ops || !curdev->ops->read_resources) { |
Martin Roth | 7bc74ab | 2015-11-18 20:23:02 -0700 | [diff] [blame] | 228 | if (curdev->path.type != DEVICE_PATH_APIC) |
| 229 | printk(BIOS_ERR, "%s missing read_resources\n", |
| 230 | dev_path(curdev)); |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 231 | continue; |
| 232 | } |
Duncan Laurie | 7ed3976 | 2013-07-09 10:46:52 -0700 | [diff] [blame] | 233 | post_log_path(curdev); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 234 | curdev->ops->read_resources(curdev); |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 235 | |
| 236 | /* Read in the resources behind the current device's links. */ |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 237 | for (link = curdev->link_list; link; link = link->next) |
| 238 | read_resources(link); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 239 | } |
Duncan Laurie | 7ed3976 | 2013-07-09 10:46:52 -0700 | [diff] [blame] | 240 | post_log_clear(); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 241 | printk(BIOS_SPEW, "%s read_resources bus %d link: %d done\n", |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 242 | dev_path(bus->dev), bus->secondary, bus->link_num); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 243 | } |
| 244 | |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 245 | struct pick_largest_state { |
| 246 | struct resource *last; |
Lubomir Rintel | 9ba8f7c | 2018-04-26 00:00:22 +0200 | [diff] [blame] | 247 | const struct device *result_dev; |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 248 | struct resource *result; |
| 249 | int seen_last; |
| 250 | }; |
| 251 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 252 | static void pick_largest_resource(void *gp, struct device *dev, |
| 253 | struct resource *resource) |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 254 | { |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 255 | struct pick_largest_state *state = gp; |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 256 | struct resource *last; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 257 | |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 258 | last = state->last; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 259 | |
| 260 | /* Be certain to pick the successor to last. */ |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 261 | if (resource == last) { |
| 262 | state->seen_last = 1; |
| 263 | return; |
| 264 | } |
Myles Watson | 032a965 | 2009-05-11 22:24:53 +0000 | [diff] [blame] | 265 | if (resource->flags & IORESOURCE_FIXED) |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 266 | return; /* Skip it. */ |
Myles Watson | 032a965 | 2009-05-11 22:24:53 +0000 | [diff] [blame] | 267 | if (last && ((last->align < resource->align) || |
| 268 | ((last->align == resource->align) && |
| 269 | (last->size < resource->size)) || |
| 270 | ((last->align == resource->align) && |
| 271 | (last->size == resource->size) && (!state->seen_last)))) { |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 272 | return; |
| 273 | } |
Myles Watson | 032a965 | 2009-05-11 22:24:53 +0000 | [diff] [blame] | 274 | if (!state->result || |
| 275 | (state->result->align < resource->align) || |
| 276 | ((state->result->align == resource->align) && |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 277 | (state->result->size < resource->size))) { |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 278 | state->result_dev = dev; |
| 279 | state->result = resource; |
Myles Watson | 032a965 | 2009-05-11 22:24:53 +0000 | [diff] [blame] | 280 | } |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 281 | } |
| 282 | |
Lubomir Rintel | 9ba8f7c | 2018-04-26 00:00:22 +0200 | [diff] [blame] | 283 | static const struct device *largest_resource(struct bus *bus, |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 284 | struct resource **result_res, |
| 285 | unsigned long type_mask, |
| 286 | unsigned long type) |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 287 | { |
| 288 | struct pick_largest_state state; |
| 289 | |
| 290 | state.last = *result_res; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 291 | state.result_dev = NULL; |
| 292 | state.result = NULL; |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 293 | state.seen_last = 0; |
| 294 | |
Myles Watson | 032a965 | 2009-05-11 22:24:53 +0000 | [diff] [blame] | 295 | search_bus_resources(bus, type_mask, type, pick_largest_resource, |
| 296 | &state); |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 297 | |
| 298 | *result_res = state.result; |
| 299 | return state.result_dev; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 300 | } |
| 301 | |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 302 | /** |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 303 | * This function is the guts of the resource allocator. |
Myles Watson | 032a965 | 2009-05-11 22:24:53 +0000 | [diff] [blame] | 304 | * |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 305 | * The problem. |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 306 | * - Allocate resource locations for every device. |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 307 | * - Don't overlap, and follow the rules of bridges. |
| 308 | * - Don't overlap with resources in fixed locations. |
| 309 | * - Be efficient so we don't have ugly strategies. |
| 310 | * |
| 311 | * The strategy. |
| 312 | * - Devices that have fixed addresses are the minority so don't |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 313 | * worry about them too much. Instead only use part of the address |
| 314 | * space for devices with programmable addresses. This easily handles |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 315 | * everything except bridges. |
| 316 | * |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 317 | * - PCI devices are required to have their sizes and their alignments |
| 318 | * equal. In this case an optimal solution to the packing problem |
| 319 | * exists. Allocate all devices from highest alignment to least |
| 320 | * alignment or vice versa. Use this. |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 321 | * |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 322 | * - So we can handle more than PCI run two allocation passes on bridges. The |
| 323 | * first to see how large the resources are behind the bridge, and what |
| 324 | * their alignment requirements are. The second to assign a safe address to |
| 325 | * the devices behind the bridge. This allows us to treat a bridge as just |
| 326 | * a device with a couple of resources, and not need to special case it in |
| 327 | * the allocator. Also this allows handling of other types of bridges. |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 328 | * |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 329 | * @param bus The bus we are traversing. |
| 330 | * @param bridge The bridge resource which must contain the bus' resources. |
| 331 | * @param type_mask This value gets ANDed with the resource type. |
| 332 | * @param type This value must match the result of the AND. |
| 333 | * @return TODO |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 334 | */ |
Myles Watson | 54913b9 | 2009-10-13 20:00:09 +0000 | [diff] [blame] | 335 | static void compute_resources(struct bus *bus, struct resource *bridge, |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 336 | unsigned long type_mask, unsigned long type) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 337 | { |
Lubomir Rintel | 9ba8f7c | 2018-04-26 00:00:22 +0200 | [diff] [blame] | 338 | const struct device *dev; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 339 | struct resource *resource; |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 340 | resource_t base; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 341 | base = round(bridge->base, bridge->align); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 342 | |
John Zhao | 2deb5fb | 2019-05-29 18:12:01 -0700 | [diff] [blame^] | 343 | if (!bus) |
| 344 | return; |
| 345 | |
Kyösti Mälkki | e6a9290f | 2015-03-23 19:37:38 +0200 | [diff] [blame] | 346 | printk(BIOS_SPEW, "%s %s: base: %llx size: %llx align: %d gran: %d" |
| 347 | " limit: %llx\n", dev_path(bus->dev), resource2str(bridge), |
| 348 | base, bridge->size, bridge->align, |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 349 | bridge->gran, bridge->limit); |
Ronald G. Minnich | 99dcf23 | 2003-09-30 02:16:47 +0000 | [diff] [blame] | 350 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 351 | /* For each child which is a bridge, compute the resource needs. */ |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 352 | for (dev = bus->children; dev; dev = dev->sibling) { |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 353 | struct resource *child_bridge; |
| 354 | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 355 | if (!dev->link_list) |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 356 | continue; |
| 357 | |
| 358 | /* Find the resources with matching type flags. */ |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 359 | for (child_bridge = dev->resource_list; child_bridge; |
| 360 | child_bridge = child_bridge->next) { |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 361 | struct bus* link; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 362 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 363 | if (!(child_bridge->flags & IORESOURCE_BRIDGE) |
| 364 | || (child_bridge->flags & type_mask) != type) |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 365 | continue; |
| 366 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 367 | /* |
| 368 | * Split prefetchable memory if combined. Many domains |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 369 | * use the same address space for prefetchable memory |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 370 | * and non-prefetchable memory. Bridges below them need |
| 371 | * it separated. Add the PREFETCH flag to the type_mask |
| 372 | * and type. |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 373 | */ |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 374 | link = dev->link_list; |
| 375 | while (link && link->link_num != |
| 376 | IOINDEX_LINK(child_bridge->index)) |
| 377 | link = link->next; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 378 | |
| 379 | if (link == NULL) { |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 380 | printk(BIOS_ERR, "link %ld not found on %s\n", |
| 381 | IOINDEX_LINK(child_bridge->index), |
| 382 | dev_path(dev)); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 383 | } |
| 384 | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 385 | compute_resources(link, child_bridge, |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 386 | type_mask | IORESOURCE_PREFETCH, |
| 387 | type | (child_bridge->flags & |
| 388 | IORESOURCE_PREFETCH)); |
| 389 | } |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 390 | } |
| 391 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 392 | /* Remember we haven't found anything yet. */ |
| 393 | resource = NULL; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 394 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 395 | /* |
| 396 | * Walk through all the resources on the current bus and compute the |
| 397 | * amount of address space taken by them. Take granularity and |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 398 | * alignment into account. |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 399 | */ |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 400 | while ((dev = largest_resource(bus, &resource, type_mask, type))) { |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 401 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 402 | /* Size 0 resources can be skipped. */ |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 403 | if (!resource->size) |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 404 | continue; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 405 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 406 | /* Propagate the resource alignment to the bridge resource. */ |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 407 | if (resource->align > bridge->align) |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 408 | bridge->align = resource->align; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 409 | |
| 410 | /* Propagate the resource limit to the bridge register. */ |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 411 | if (bridge->limit > resource->limit) |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 412 | bridge->limit = resource->limit; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 413 | |
| 414 | /* Warn if it looks like APICs aren't declared. */ |
| 415 | if ((resource->limit == 0xffffffff) && |
| 416 | (resource->flags & IORESOURCE_ASSIGNED)) { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 417 | printk(BIOS_ERR, |
| 418 | "Resource limit looks wrong! (no APIC?)\n"); |
Patrick Georgi | 5161509 | 2012-03-11 19:31:03 +0100 | [diff] [blame] | 419 | printk(BIOS_ERR, "%s %02lx limit %08llx\n", |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 420 | dev_path(dev), resource->index, resource->limit); |
Eric Biederman | dbec2d4 | 2004-10-21 10:44:08 +0000 | [diff] [blame] | 421 | } |
Stefan Reinauer | 51754a3 | 2008-08-01 12:28:38 +0000 | [diff] [blame] | 422 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 423 | if (resource->flags & IORESOURCE_IO) { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 424 | /* |
| 425 | * Don't allow potential aliases over the legacy PCI |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 426 | * expansion card addresses. The legacy PCI decodes |
| 427 | * only 10 bits, uses 0x100 - 0x3ff. Therefore, only |
| 428 | * 0x00 - 0xff can be used out of each 0x400 block of |
| 429 | * I/O space. |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 430 | */ |
Eric Biederman | bbb6d10 | 2003-08-04 19:54:48 +0000 | [diff] [blame] | 431 | if ((base & 0x300) != 0) { |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 432 | base = (base & ~0x3ff) + 0x400; |
| 433 | } |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 434 | /* |
| 435 | * Don't allow allocations in the VGA I/O range. |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 436 | * PCI has special cases for that. |
| 437 | */ |
| 438 | else if ((base >= 0x3b0) && (base <= 0x3df)) { |
| 439 | base = 0x3e0; |
| 440 | } |
| 441 | } |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 442 | /* Base must be aligned. */ |
| 443 | base = round(base, resource->align); |
| 444 | resource->base = base; |
| 445 | base += resource->size; |
Myles Watson | 032a965 | 2009-05-11 22:24:53 +0000 | [diff] [blame] | 446 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 447 | printk(BIOS_SPEW, "%s %02lx * [0x%llx - 0x%llx] %s\n", |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 448 | dev_path(dev), resource->index, resource->base, |
| 449 | resource->base + resource->size - 1, |
Kyösti Mälkki | e6a9290f | 2015-03-23 19:37:38 +0200 | [diff] [blame] | 450 | resource2str(resource)); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 451 | } |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 452 | |
| 453 | /* |
| 454 | * A PCI bridge resource does not need to be a power of two size, but |
| 455 | * it does have a minimum granularity. Round the size up to that |
| 456 | * minimum granularity so we know not to place something else at an |
Martin Roth | 63373ed | 2013-07-08 16:24:19 -0600 | [diff] [blame] | 457 | * address positively decoded by the bridge. |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 458 | */ |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 459 | bridge->size = round(base, bridge->gran) - |
| 460 | round(bridge->base, bridge->align); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 461 | |
Kyösti Mälkki | e6a9290f | 2015-03-23 19:37:38 +0200 | [diff] [blame] | 462 | printk(BIOS_SPEW, "%s %s: base: %llx size: %llx align: %d gran: %d" |
| 463 | " limit: %llx done\n", dev_path(bus->dev), |
| 464 | resource2str(bridge), |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 465 | base, bridge->size, bridge->align, bridge->gran, bridge->limit); |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | /** |
| 469 | * This function is the second part of the resource allocator. |
| 470 | * |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 471 | * See the compute_resources function for a more detailed explanation. |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 472 | * |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 473 | * This function assigns the resources a value. |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 474 | * |
| 475 | * @param bus The bus we are traversing. |
| 476 | * @param bridge The bridge resource which must contain the bus' resources. |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 477 | * @param type_mask This value gets ANDed with the resource type. |
| 478 | * @param type This value must match the result of the AND. |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 479 | * |
| 480 | * @see compute_resources |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 481 | */ |
Myles Watson | 54913b9 | 2009-10-13 20:00:09 +0000 | [diff] [blame] | 482 | static void allocate_resources(struct bus *bus, struct resource *bridge, |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 483 | unsigned long type_mask, unsigned long type) |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 484 | { |
Lubomir Rintel | 9ba8f7c | 2018-04-26 00:00:22 +0200 | [diff] [blame] | 485 | const struct device *dev; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 486 | struct resource *resource; |
| 487 | resource_t base; |
| 488 | base = bridge->base; |
| 489 | |
John Zhao | 2deb5fb | 2019-05-29 18:12:01 -0700 | [diff] [blame^] | 490 | if (!bus) |
| 491 | return; |
| 492 | |
Kyösti Mälkki | e6a9290f | 2015-03-23 19:37:38 +0200 | [diff] [blame] | 493 | printk(BIOS_SPEW, "%s %s: base:%llx size:%llx align:%d gran:%d " |
| 494 | "limit:%llx\n", dev_path(bus->dev), |
| 495 | resource2str(bridge), |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 496 | base, bridge->size, bridge->align, bridge->gran, bridge->limit); |
| 497 | |
| 498 | /* Remember we haven't found anything yet. */ |
| 499 | resource = NULL; |
| 500 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 501 | /* |
| 502 | * Walk through all the resources on the current bus and allocate them |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 503 | * address space. |
| 504 | */ |
| 505 | while ((dev = largest_resource(bus, &resource, type_mask, type))) { |
| 506 | |
| 507 | /* Propagate the bridge limit to the resource register. */ |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 508 | if (resource->limit > bridge->limit) |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 509 | resource->limit = bridge->limit; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 510 | |
| 511 | /* Size 0 resources can be skipped. */ |
| 512 | if (!resource->size) { |
| 513 | /* Set the base to limit so it doesn't confuse tolm. */ |
| 514 | resource->base = resource->limit; |
| 515 | resource->flags |= IORESOURCE_ASSIGNED; |
| 516 | continue; |
| 517 | } |
| 518 | |
| 519 | if (resource->flags & IORESOURCE_IO) { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 520 | /* |
| 521 | * Don't allow potential aliases over the legacy PCI |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 522 | * expansion card addresses. The legacy PCI decodes |
| 523 | * only 10 bits, uses 0x100 - 0x3ff. Therefore, only |
| 524 | * 0x00 - 0xff can be used out of each 0x400 block of |
| 525 | * I/O space. |
| 526 | */ |
| 527 | if ((base & 0x300) != 0) { |
| 528 | base = (base & ~0x3ff) + 0x400; |
| 529 | } |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 530 | /* |
| 531 | * Don't allow allocations in the VGA I/O range. |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 532 | * PCI has special cases for that. |
| 533 | */ |
| 534 | else if ((base >= 0x3b0) && (base <= 0x3df)) { |
| 535 | base = 0x3e0; |
| 536 | } |
| 537 | } |
| 538 | |
| 539 | if ((round(base, resource->align) + resource->size - 1) <= |
| 540 | resource->limit) { |
| 541 | /* Base must be aligned. */ |
| 542 | base = round(base, resource->align); |
| 543 | resource->base = base; |
Kyösti Mälkki | 134b616 | 2015-03-23 19:58:23 +0200 | [diff] [blame] | 544 | resource->limit = resource->base + resource->size - 1; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 545 | resource->flags |= IORESOURCE_ASSIGNED; |
| 546 | resource->flags &= ~IORESOURCE_STORED; |
| 547 | base += resource->size; |
| 548 | } else { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 549 | printk(BIOS_ERR, "!! Resource didn't fit !!\n"); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 550 | printk(BIOS_ERR, " aligned base %llx size %llx " |
| 551 | "limit %llx\n", round(base, resource->align), |
| 552 | resource->size, resource->limit); |
| 553 | printk(BIOS_ERR, " %llx needs to be <= %llx " |
| 554 | "(limit)\n", (round(base, resource->align) + |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 555 | resource->size) - 1, resource->limit); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 556 | printk(BIOS_ERR, " %s%s %02lx * [0x%llx - 0x%llx]" |
| 557 | " %s\n", (resource->flags & IORESOURCE_ASSIGNED) |
| 558 | ? "Assigned: " : "", dev_path(dev), |
| 559 | resource->index, resource->base, |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 560 | resource->base + resource->size - 1, |
Kyösti Mälkki | e6a9290f | 2015-03-23 19:37:38 +0200 | [diff] [blame] | 561 | resource2str(resource)); |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 562 | } |
| 563 | |
Kyösti Mälkki | e6a9290f | 2015-03-23 19:37:38 +0200 | [diff] [blame] | 564 | printk(BIOS_SPEW, "%s %02lx * [0x%llx - 0x%llx] %s\n", |
| 565 | dev_path(dev), resource->index, resource->base, |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 566 | resource->size ? resource->base + resource->size - 1 : |
Kyösti Mälkki | e6a9290f | 2015-03-23 19:37:38 +0200 | [diff] [blame] | 567 | resource->base, resource2str(resource)); |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 568 | } |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 569 | |
| 570 | /* |
| 571 | * A PCI bridge resource does not need to be a power of two size, but |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 572 | * it does have a minimum granularity. Round the size up to that |
| 573 | * minimum granularity so we know not to place something else at an |
| 574 | * address positively decoded by the bridge. |
| 575 | */ |
| 576 | |
| 577 | bridge->flags |= IORESOURCE_ASSIGNED; |
| 578 | |
Kyösti Mälkki | e6a9290f | 2015-03-23 19:37:38 +0200 | [diff] [blame] | 579 | printk(BIOS_SPEW, "%s %s: next_base: %llx size: %llx align: %d " |
| 580 | "gran: %d done\n", dev_path(bus->dev), |
| 581 | resource2str(bridge), base, bridge->size, bridge->align, |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 582 | bridge->gran); |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 583 | |
| 584 | /* For each child which is a bridge, allocate_resources. */ |
| 585 | for (dev = bus->children; dev; dev = dev->sibling) { |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 586 | struct resource *child_bridge; |
| 587 | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 588 | if (!dev->link_list) |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 589 | continue; |
| 590 | |
| 591 | /* Find the resources with matching type flags. */ |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 592 | for (child_bridge = dev->resource_list; child_bridge; |
| 593 | child_bridge = child_bridge->next) { |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 594 | struct bus* link; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 595 | |
| 596 | if (!(child_bridge->flags & IORESOURCE_BRIDGE) || |
| 597 | (child_bridge->flags & type_mask) != type) |
| 598 | continue; |
| 599 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 600 | /* |
| 601 | * Split prefetchable memory if combined. Many domains |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 602 | * use the same address space for prefetchable memory |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 603 | * and non-prefetchable memory. Bridges below them need |
| 604 | * it separated. Add the PREFETCH flag to the type_mask |
| 605 | * and type. |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 606 | */ |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 607 | link = dev->link_list; |
| 608 | while (link && link->link_num != |
| 609 | IOINDEX_LINK(child_bridge->index)) |
| 610 | link = link->next; |
| 611 | if (link == NULL) |
| 612 | printk(BIOS_ERR, "link %ld not found on %s\n", |
| 613 | IOINDEX_LINK(child_bridge->index), |
| 614 | dev_path(dev)); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 615 | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 616 | allocate_resources(link, child_bridge, |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 617 | type_mask | IORESOURCE_PREFETCH, |
| 618 | type | (child_bridge->flags & |
| 619 | IORESOURCE_PREFETCH)); |
| 620 | } |
| 621 | } |
| 622 | } |
| 623 | |
Kyösti Mälkki | fdc0a90 | 2015-03-26 20:04:38 +0200 | [diff] [blame] | 624 | static int resource_is(struct resource *res, u32 type) |
| 625 | { |
| 626 | return (res->flags & IORESOURCE_TYPE_MASK) == type; |
| 627 | } |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 628 | |
| 629 | struct constraints { |
Kyösti Mälkki | fcbebb6 | 2015-03-17 06:42:54 +0200 | [diff] [blame] | 630 | struct resource io, mem; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 631 | }; |
| 632 | |
Elyes HAOUAS | e348066 | 2018-05-06 20:32:23 +0200 | [diff] [blame] | 633 | static struct resource *resource_limit(struct constraints *limits, |
| 634 | struct resource *res) |
Kyösti Mälkki | fdc0a90 | 2015-03-26 20:04:38 +0200 | [diff] [blame] | 635 | { |
| 636 | struct resource *lim = NULL; |
| 637 | |
| 638 | /* MEM, or I/O - skip any others. */ |
| 639 | if (resource_is(res, IORESOURCE_MEM)) |
| 640 | lim = &limits->mem; |
| 641 | else if (resource_is(res, IORESOURCE_IO)) |
| 642 | lim = &limits->io; |
| 643 | |
| 644 | return lim; |
| 645 | } |
| 646 | |
Elyes HAOUAS | e348066 | 2018-05-06 20:32:23 +0200 | [diff] [blame] | 647 | static void constrain_resources(const struct device *dev, |
| 648 | struct constraints* limits) |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 649 | { |
Lubomir Rintel | 9ba8f7c | 2018-04-26 00:00:22 +0200 | [diff] [blame] | 650 | const struct device *child; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 651 | struct resource *res; |
| 652 | struct resource *lim; |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 653 | struct bus *link; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 654 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 655 | /* Constrain limits based on the fixed resources of this device. */ |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 656 | for (res = dev->resource_list; res; res = res->next) { |
Patrick Georgi | 18c585b | 2009-08-28 12:48:02 +0000 | [diff] [blame] | 657 | if (!(res->flags & IORESOURCE_FIXED)) |
| 658 | continue; |
Myles Watson | ce9d864 | 2009-08-19 19:12:39 +0000 | [diff] [blame] | 659 | if (!res->size) { |
| 660 | /* It makes no sense to have 0-sized, fixed resources.*/ |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 661 | printk(BIOS_ERR, "skipping %s@%lx fixed resource, " |
| 662 | "size=0!\n", dev_path(dev), res->index); |
Patrick Georgi | 6bd93f4 | 2009-08-19 17:29:41 +0000 | [diff] [blame] | 663 | continue; |
Myles Watson | ce9d864 | 2009-08-19 19:12:39 +0000 | [diff] [blame] | 664 | } |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 665 | |
Kyösti Mälkki | fdc0a90 | 2015-03-26 20:04:38 +0200 | [diff] [blame] | 666 | lim = resource_limit(limits, res); |
| 667 | if (!lim) |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 668 | continue; |
| 669 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 670 | /* |
| 671 | * Is it a fixed resource outside the current known region? |
| 672 | * If so, we don't have to consider it - it will be handled |
| 673 | * correctly and doesn't affect current region's limits. |
| 674 | */ |
| 675 | if (((res->base + res->size -1) < lim->base) |
| 676 | || (res->base > lim->limit)) |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 677 | continue; |
| 678 | |
Kyösti Mälkki | e6a9290f | 2015-03-23 19:37:38 +0200 | [diff] [blame] | 679 | printk(BIOS_SPEW, "%s: %s %02lx base %08llx limit %08llx %s (fixed)\n", |
| 680 | __func__, dev_path(dev), res->index, res->base, |
| 681 | res->base + res->size - 1, resource2str(res)); |
| 682 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 683 | /* |
| 684 | * Choose to be above or below fixed resources. This check is |
| 685 | * signed so that "negative" amounts of space are handled |
| 686 | * correctly. |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 687 | */ |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 688 | if ((signed long long)(lim->limit - (res->base + res->size -1)) |
| 689 | > (signed long long)(res->base - lim->base)) |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 690 | lim->base = res->base + res->size; |
| 691 | else |
| 692 | lim->limit = res->base -1; |
| 693 | } |
| 694 | |
| 695 | /* Descend into every enabled child and look for fixed resources. */ |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 696 | for (link = dev->link_list; link; link = link->next) { |
| 697 | for (child = link->children; child; child = child->sibling) { |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 698 | if (child->enabled) |
| 699 | constrain_resources(child, limits); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 700 | } |
| 701 | } |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 702 | } |
| 703 | |
Lubomir Rintel | 9ba8f7c | 2018-04-26 00:00:22 +0200 | [diff] [blame] | 704 | static void avoid_fixed_resources(const struct device *dev) |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 705 | { |
| 706 | struct constraints limits; |
| 707 | struct resource *res; |
Kyösti Mälkki | fdc0a90 | 2015-03-26 20:04:38 +0200 | [diff] [blame] | 708 | struct resource *lim; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 709 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 710 | printk(BIOS_SPEW, "%s: %s\n", __func__, dev_path(dev)); |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 711 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 712 | /* Initialize constraints to maximum size. */ |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 713 | limits.io.base = 0; |
| 714 | limits.io.limit = 0xffffffffffffffffULL; |
| 715 | limits.mem.base = 0; |
| 716 | limits.mem.limit = 0xffffffffffffffffULL; |
| 717 | |
| 718 | /* Constrain the limits to dev's initial resources. */ |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 719 | for (res = dev->resource_list; res; res = res->next) { |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 720 | if ((res->flags & IORESOURCE_FIXED)) |
| 721 | continue; |
Patrick Georgi | 5161509 | 2012-03-11 19:31:03 +0100 | [diff] [blame] | 722 | printk(BIOS_SPEW, "%s:@%s %02lx limit %08llx\n", __func__, |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 723 | dev_path(dev), res->index, res->limit); |
Kyösti Mälkki | fcbebb6 | 2015-03-17 06:42:54 +0200 | [diff] [blame] | 724 | |
Kyösti Mälkki | fdc0a90 | 2015-03-26 20:04:38 +0200 | [diff] [blame] | 725 | lim = resource_limit(&limits, res); |
| 726 | if (!lim) |
| 727 | continue; |
| 728 | |
| 729 | if (res->base > lim->base) |
| 730 | lim->base = res->base; |
Elyes HAOUAS | 1943f37 | 2018-05-04 16:30:39 +0200 | [diff] [blame] | 731 | if (res->limit < lim->limit) |
Kyösti Mälkki | fdc0a90 | 2015-03-26 20:04:38 +0200 | [diff] [blame] | 732 | lim->limit = res->limit; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | /* Look through the tree for fixed resources and update the limits. */ |
| 736 | constrain_resources(dev, &limits); |
| 737 | |
| 738 | /* Update dev's resources with new limits. */ |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 739 | for (res = dev->resource_list; res; res = res->next) { |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 740 | if ((res->flags & IORESOURCE_FIXED)) |
| 741 | continue; |
| 742 | |
Kyösti Mälkki | fdc0a90 | 2015-03-26 20:04:38 +0200 | [diff] [blame] | 743 | lim = resource_limit(&limits, res); |
| 744 | if (!lim) |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 745 | continue; |
| 746 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 747 | /* Is the resource outside the limits? */ |
| 748 | if (lim->base > res->base) |
| 749 | res->base = lim->base; |
| 750 | if (res->limit > lim->limit) |
| 751 | res->limit = lim->limit; |
Kyösti Mälkki | e6a9290f | 2015-03-23 19:37:38 +0200 | [diff] [blame] | 752 | |
Kyösti Mälkki | 634899c | 2015-03-23 14:22:22 +0200 | [diff] [blame] | 753 | /* MEM resources need to start at the highest address manageable. */ |
| 754 | if (res->flags & IORESOURCE_MEM) |
| 755 | res->base = resource_max(res); |
| 756 | |
Kyösti Mälkki | e6a9290f | 2015-03-23 19:37:38 +0200 | [diff] [blame] | 757 | printk(BIOS_SPEW, "%s:@%s %02lx base %08llx limit %08llx\n", |
| 758 | __func__, dev_path(dev), res->index, res->base, res->limit); |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 759 | } |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 760 | } |
arch import user (historical) | dc81118 | 2005-07-06 17:16:09 +0000 | [diff] [blame] | 761 | |
Elyes HAOUAS | e348066 | 2018-05-06 20:32:23 +0200 | [diff] [blame] | 762 | struct device *vga_pri = NULL; |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 763 | static void set_vga_bridge_bits(void) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 764 | { |
Uwe Hermann | 312673c | 2009-10-27 21:49:33 +0000 | [diff] [blame] | 765 | /* |
Martin Roth | 63373ed | 2013-07-08 16:24:19 -0600 | [diff] [blame] | 766 | * FIXME: Modify set_vga_bridge() so it is less PCI-centric! |
Uwe Hermann | 312673c | 2009-10-27 21:49:33 +0000 | [diff] [blame] | 767 | * This function knows too much about PCI stuff, it should be just |
| 768 | * an iterator/visitor. |
| 769 | */ |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 770 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 771 | /* FIXME: Handle the VGA palette snooping. */ |
Patrick Georgi | 557ecf2 | 2012-07-20 12:16:17 +0200 | [diff] [blame] | 772 | struct device *dev, *vga, *vga_onboard; |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 773 | struct bus *bus; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 774 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 775 | bus = 0; |
| 776 | vga = 0; |
Yinghai Lu | 1f1085b | 2005-01-17 21:37:12 +0000 | [diff] [blame] | 777 | vga_onboard = 0; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 778 | |
Patrick Georgi | 557ecf2 | 2012-07-20 12:16:17 +0200 | [diff] [blame] | 779 | dev = NULL; |
| 780 | while ((dev = dev_find_class(PCI_CLASS_DISPLAY_VGA << 8, dev))) { |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 781 | if (!dev->enabled) |
| 782 | continue; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 783 | |
Patrick Georgi | 557ecf2 | 2012-07-20 12:16:17 +0200 | [diff] [blame] | 784 | printk(BIOS_DEBUG, "found VGA at %s\n", dev_path(dev)); |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 785 | |
Patrick Georgi | 557ecf2 | 2012-07-20 12:16:17 +0200 | [diff] [blame] | 786 | if (dev->on_mainboard) { |
| 787 | vga_onboard = dev; |
Kostr | 1f0d379 | 2012-10-06 13:27:58 +0400 | [diff] [blame] | 788 | } else { |
Patrick Georgi | 557ecf2 | 2012-07-20 12:16:17 +0200 | [diff] [blame] | 789 | vga = dev; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 790 | } |
Myles Watson | 032a965 | 2009-05-11 22:24:53 +0000 | [diff] [blame] | 791 | |
Patrick Georgi | 557ecf2 | 2012-07-20 12:16:17 +0200 | [diff] [blame] | 792 | /* It isn't safe to enable all VGA cards. */ |
| 793 | dev->command &= ~(PCI_COMMAND_MEMORY | PCI_COMMAND_IO); |
Patrick Georgi | 594473d | 2012-07-25 08:55:53 +0200 | [diff] [blame] | 794 | } |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 795 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 796 | if (!vga) |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 797 | vga = vga_onboard; |
Patrick Georgi | 557ecf2 | 2012-07-20 12:16:17 +0200 | [diff] [blame] | 798 | |
Julius Werner | 5d1f9a0 | 2019-03-07 17:07:26 -0800 | [diff] [blame] | 799 | if (CONFIG(ONBOARD_VGA_IS_PRIMARY) && vga_onboard) |
Patrick Georgi | 557ecf2 | 2012-07-20 12:16:17 +0200 | [diff] [blame] | 800 | vga = vga_onboard; |
Myles Watson | 032a965 | 2009-05-11 22:24:53 +0000 | [diff] [blame] | 801 | |
Patrick Georgi | 5869fa2 | 2012-07-20 12:29:33 +0200 | [diff] [blame] | 802 | /* If we prefer plugin VGA over chipset VGA, the chipset might |
| 803 | want to know. */ |
Julius Werner | 5d1f9a0 | 2019-03-07 17:07:26 -0800 | [diff] [blame] | 804 | if (!CONFIG(ONBOARD_VGA_IS_PRIMARY) && (vga != vga_onboard) && |
Patrick Georgi | 5869fa2 | 2012-07-20 12:29:33 +0200 | [diff] [blame] | 805 | vga_onboard && vga_onboard->ops && vga_onboard->ops->disable) { |
| 806 | printk(BIOS_DEBUG, "Use plugin graphics over integrated.\n"); |
| 807 | vga_onboard->ops->disable(vga_onboard); |
| 808 | } |
| 809 | |
arch import user (historical) | dc81118 | 2005-07-06 17:16:09 +0000 | [diff] [blame] | 810 | if (vga) { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 811 | /* VGA is first add-on card or the only onboard VGA. */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 812 | printk(BIOS_DEBUG, "Setting up VGA for %s\n", dev_path(vga)); |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 813 | /* All legacy VGA cards have MEM & I/O space registers. */ |
Yinghai Lu | 1f1085b | 2005-01-17 21:37:12 +0000 | [diff] [blame] | 814 | vga->command |= (PCI_COMMAND_MEMORY | PCI_COMMAND_IO); |
| 815 | vga_pri = vga; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 816 | bus = vga->bus; |
| 817 | } |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 818 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 819 | /* Now walk up the bridges setting the VGA enable. */ |
| 820 | while (bus) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 821 | printk(BIOS_DEBUG, "Setting PCI_BRIDGE_CTL_VGA for bridge %s\n", |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 822 | dev_path(bus->dev)); |
Li-Ta Lo | db7f47c | 2004-01-08 21:15:49 +0000 | [diff] [blame] | 823 | bus->bridge_ctrl |= PCI_BRIDGE_CTL_VGA; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 824 | bus = (bus == bus->dev->bus) ? 0 : bus->dev->bus; |
Myles Watson | 032a965 | 2009-05-11 22:24:53 +0000 | [diff] [blame] | 825 | } |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 826 | } |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 827 | |
Li-Ta Lo | 0493069 | 2004-11-25 17:37:19 +0000 | [diff] [blame] | 828 | /** |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 829 | * Assign the computed resources to the devices on the bus. |
Li-Ta Lo | 0493069 | 2004-11-25 17:37:19 +0000 | [diff] [blame] | 830 | * |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 831 | * Use the device specific set_resources() method to store the computed |
Li-Ta Lo | 0493069 | 2004-11-25 17:37:19 +0000 | [diff] [blame] | 832 | * resources to hardware. For bridge devices, the set_resources() method |
| 833 | * has to recurse into every down stream buses. |
| 834 | * |
| 835 | * Mutual recursion: |
| 836 | * assign_resources() -> device_operation::set_resources() |
| 837 | * device_operation::set_resources() -> assign_resources() |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 838 | * |
| 839 | * @param bus Pointer to the structure for this bus. |
Li-Ta Lo | 0493069 | 2004-11-25 17:37:19 +0000 | [diff] [blame] | 840 | */ |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 841 | void assign_resources(struct bus *bus) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 842 | { |
| 843 | struct device *curdev; |
| 844 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 845 | printk(BIOS_SPEW, "%s assign_resources, bus %d link: %d\n", |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 846 | dev_path(bus->dev), bus->secondary, bus->link_num); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 847 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 848 | for (curdev = bus->children; curdev; curdev = curdev->sibling) { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 849 | if (!curdev->enabled || !curdev->resource_list) |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 850 | continue; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 851 | |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 852 | if (!curdev->ops || !curdev->ops->set_resources) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 853 | printk(BIOS_ERR, "%s missing set_resources\n", |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 854 | dev_path(curdev)); |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 855 | continue; |
| 856 | } |
Duncan Laurie | 8adf7a2 | 2013-06-10 10:34:20 -0700 | [diff] [blame] | 857 | post_log_path(curdev); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 858 | curdev->ops->set_resources(curdev); |
| 859 | } |
Duncan Laurie | 8adf7a2 | 2013-06-10 10:34:20 -0700 | [diff] [blame] | 860 | post_log_clear(); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 861 | printk(BIOS_SPEW, "%s assign_resources, bus %d link: %d\n", |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 862 | dev_path(bus->dev), bus->secondary, bus->link_num); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 863 | } |
| 864 | |
Li-Ta Lo | 5782d27 | 2004-04-26 17:51:20 +0000 | [diff] [blame] | 865 | /** |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 866 | * Enable the resources for devices on a link. |
Li-Ta Lo | 5782d27 | 2004-04-26 17:51:20 +0000 | [diff] [blame] | 867 | * |
| 868 | * Enable resources of the device by calling the device specific |
| 869 | * enable_resources() method. |
| 870 | * |
| 871 | * The parent's resources should be enabled first to avoid having enabling |
| 872 | * order problem. This is done by calling the parent's enable_resources() |
Martin Roth | 63373ed | 2013-07-08 16:24:19 -0600 | [diff] [blame] | 873 | * method before its children's enable_resources() methods. |
Li-Ta Lo | 9f0d0f9 | 2004-05-10 16:05:16 +0000 | [diff] [blame] | 874 | * |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 875 | * @param link The link whose devices' resources are to be enabled. |
Li-Ta Lo | 5782d27 | 2004-04-26 17:51:20 +0000 | [diff] [blame] | 876 | */ |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 877 | static void enable_resources(struct bus *link) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 878 | { |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 879 | struct device *dev; |
| 880 | struct bus *c_link; |
| 881 | |
| 882 | for (dev = link->children; dev; dev = dev->sibling) { |
Duncan Laurie | 8adf7a2 | 2013-06-10 10:34:20 -0700 | [diff] [blame] | 883 | if (dev->enabled && dev->ops && dev->ops->enable_resources) { |
| 884 | post_log_path(dev); |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 885 | dev->ops->enable_resources(dev); |
Duncan Laurie | 8adf7a2 | 2013-06-10 10:34:20 -0700 | [diff] [blame] | 886 | } |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 887 | } |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 888 | |
| 889 | for (dev = link->children; dev; dev = dev->sibling) { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 890 | for (c_link = dev->link_list; c_link; c_link = c_link->next) |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 891 | enable_resources(c_link); |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 892 | } |
Duncan Laurie | 8adf7a2 | 2013-06-10 10:34:20 -0700 | [diff] [blame] | 893 | post_log_clear(); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 894 | } |
| 895 | |
Myles Watson | 032a965 | 2009-05-11 22:24:53 +0000 | [diff] [blame] | 896 | /** |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 897 | * Reset all of the devices on a bus and clear the bus's reset_needed flag. |
| 898 | * |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 899 | * @param bus Pointer to the bus structure. |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 900 | * @return 1 if the bus was successfully reset, 0 otherwise. |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 901 | */ |
| 902 | int reset_bus(struct bus *bus) |
| 903 | { |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 904 | if (bus && bus->dev && bus->dev->ops && bus->dev->ops->reset_bus) { |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 905 | bus->dev->ops->reset_bus(bus); |
| 906 | bus->reset_needed = 0; |
| 907 | return 1; |
| 908 | } |
| 909 | return 0; |
| 910 | } |
| 911 | |
Myles Watson | 032a965 | 2009-05-11 22:24:53 +0000 | [diff] [blame] | 912 | /** |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 913 | * Scan for devices on a bus. |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 914 | * |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 915 | * If there are bridges on the bus, recursively scan the buses behind the |
| 916 | * bridges. If the setting up and tuning of the bus causes a reset to be |
| 917 | * required, reset the bus and scan it again. |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 918 | * |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 919 | * @param busdev Pointer to the bus device. |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 920 | */ |
Kyösti Mälkki | 580e722 | 2015-03-19 21:04:23 +0200 | [diff] [blame] | 921 | static void scan_bus(struct device *busdev) |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 922 | { |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 923 | int do_scan_bus; |
Paul Menzel | 662380f | 2015-10-20 10:21:08 +0200 | [diff] [blame] | 924 | struct stopwatch sw; |
| 925 | |
| 926 | stopwatch_init(&sw); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 927 | |
Kyösti Mälkki | 2d2367c | 2015-02-20 21:28:31 +0200 | [diff] [blame] | 928 | if (!busdev->enabled) |
Kyösti Mälkki | 580e722 | 2015-03-19 21:04:23 +0200 | [diff] [blame] | 929 | return; |
Kyösti Mälkki | 2d2367c | 2015-02-20 21:28:31 +0200 | [diff] [blame] | 930 | |
| 931 | printk(BIOS_SPEW, "%s scanning...\n", dev_path(busdev)); |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 932 | |
Duncan Laurie | 8adf7a2 | 2013-06-10 10:34:20 -0700 | [diff] [blame] | 933 | post_log_path(busdev); |
| 934 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 935 | do_scan_bus = 1; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 936 | while (do_scan_bus) { |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 937 | struct bus *link; |
Kyösti Mälkki | 580e722 | 2015-03-19 21:04:23 +0200 | [diff] [blame] | 938 | busdev->ops->scan_bus(busdev); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 939 | do_scan_bus = 0; |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 940 | for (link = busdev->link_list; link; link = link->next) { |
| 941 | if (link->reset_needed) { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 942 | if (reset_bus(link)) |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 943 | do_scan_bus = 1; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 944 | else |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 945 | busdev->bus->reset_needed = 1; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 946 | } |
| 947 | } |
| 948 | } |
Paul Menzel | 662380f | 2015-10-20 10:21:08 +0200 | [diff] [blame] | 949 | |
| 950 | printk(BIOS_DEBUG, "%s: scanning of bus %s took %ld usecs\n", |
| 951 | __func__, dev_path(busdev), stopwatch_duration_usecs(&sw)); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 952 | } |
| 953 | |
Kyösti Mälkki | 2d2367c | 2015-02-20 21:28:31 +0200 | [diff] [blame] | 954 | void scan_bridges(struct bus *bus) |
| 955 | { |
| 956 | struct device *child; |
Kyösti Mälkki | 2d2367c | 2015-02-20 21:28:31 +0200 | [diff] [blame] | 957 | |
| 958 | for (child = bus->children; child; child = child->sibling) { |
| 959 | if (!child->ops || !child->ops->scan_bus) |
| 960 | continue; |
Kyösti Mälkki | 580e722 | 2015-03-19 21:04:23 +0200 | [diff] [blame] | 961 | scan_bus(child); |
Kyösti Mälkki | 2d2367c | 2015-02-20 21:28:31 +0200 | [diff] [blame] | 962 | } |
Kyösti Mälkki | 2d2367c | 2015-02-20 21:28:31 +0200 | [diff] [blame] | 963 | } |
| 964 | |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 965 | /** |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 966 | * Determine the existence of devices and extend the device tree. |
Li-Ta Lo | 0493069 | 2004-11-25 17:37:19 +0000 | [diff] [blame] | 967 | * |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 968 | * Most of the devices in the system are listed in the mainboard devicetree.cb |
Li-Ta Lo | 0493069 | 2004-11-25 17:37:19 +0000 | [diff] [blame] | 969 | * file. The device structures for these devices are generated at compile |
| 970 | * time by the config tool and are organized into the device tree. This |
| 971 | * function determines if the devices created at compile time actually exist |
| 972 | * in the physical system. |
| 973 | * |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 974 | * For devices in the physical system but not listed in devicetree.cb, |
Li-Ta Lo | 0493069 | 2004-11-25 17:37:19 +0000 | [diff] [blame] | 975 | * the device structures have to be created at run time and attached to the |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 976 | * device tree. |
| 977 | * |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 978 | * This function starts from the root device 'dev_root', scans the buses in |
| 979 | * the system recursively, and modifies the device tree according to the |
| 980 | * result of the probe. |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 981 | * |
Li-Ta Lo | 5782d27 | 2004-04-26 17:51:20 +0000 | [diff] [blame] | 982 | * This function has no idea how to scan and probe buses and devices at all. |
| 983 | * It depends on the bus/device specific scan_bus() method to do it. The |
Li-Ta Lo | 0493069 | 2004-11-25 17:37:19 +0000 | [diff] [blame] | 984 | * scan_bus() method also has to create the device structure and attach |
Myles Watson | 032a965 | 2009-05-11 22:24:53 +0000 | [diff] [blame] | 985 | * it to the device tree. |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 986 | */ |
| 987 | void dev_enumerate(void) |
| 988 | { |
| 989 | struct device *root; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 990 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 991 | printk(BIOS_INFO, "Enumerating buses...\n"); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 992 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 993 | root = &dev_root; |
Myles Watson | cd5d756 | 2009-05-12 13:43:34 +0000 | [diff] [blame] | 994 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 995 | show_all_devs(BIOS_SPEW, "Before device enumeration."); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 996 | printk(BIOS_SPEW, "Compare with tree...\n"); |
Kyösti Mälkki | 3d3c8c3 | 2016-08-15 10:04:21 +0300 | [diff] [blame] | 997 | show_devs_tree(root, BIOS_SPEW, 0); |
Myles Watson | cd5d756 | 2009-05-12 13:43:34 +0000 | [diff] [blame] | 998 | |
Stefan Reinauer | a675d49 | 2012-08-07 14:50:47 -0700 | [diff] [blame] | 999 | if (root->chip_ops && root->chip_ops->enable_dev) |
| 1000 | root->chip_ops->enable_dev(root); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 1001 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 1002 | if (!root->ops || !root->ops->scan_bus) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1003 | printk(BIOS_ERR, "dev_root missing scan_bus operation"); |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 1004 | return; |
| 1005 | } |
Kyösti Mälkki | 580e722 | 2015-03-19 21:04:23 +0200 | [diff] [blame] | 1006 | scan_bus(root); |
Duncan Laurie | 8adf7a2 | 2013-06-10 10:34:20 -0700 | [diff] [blame] | 1007 | post_log_clear(); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1008 | printk(BIOS_INFO, "done\n"); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1009 | } |
| 1010 | |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 1011 | /** |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 1012 | * Configure devices on the devices tree. |
Myles Watson | 032a965 | 2009-05-11 22:24:53 +0000 | [diff] [blame] | 1013 | * |
Li-Ta Lo | 0493069 | 2004-11-25 17:37:19 +0000 | [diff] [blame] | 1014 | * Starting at the root of the device tree, travel it recursively in two |
| 1015 | * passes. In the first pass, we compute and allocate resources (ranges) |
Martin Roth | 63373ed | 2013-07-08 16:24:19 -0600 | [diff] [blame] | 1016 | * required by each device. In the second pass, the resources ranges are |
Li-Ta Lo | 0493069 | 2004-11-25 17:37:19 +0000 | [diff] [blame] | 1017 | * relocated to their final position and stored to the hardware. |
Li-Ta Lo | 5782d27 | 2004-04-26 17:51:20 +0000 | [diff] [blame] | 1018 | * |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 1019 | * I/O resources grow upward. MEM resources grow downward. |
Li-Ta Lo | 5782d27 | 2004-04-26 17:51:20 +0000 | [diff] [blame] | 1020 | * |
| 1021 | * Since the assignment is hierarchical we set the values into the dev_root |
Myles Watson | 032a965 | 2009-05-11 22:24:53 +0000 | [diff] [blame] | 1022 | * struct. |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1023 | */ |
| 1024 | void dev_configure(void) |
| 1025 | { |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 1026 | struct resource *res; |
Lubomir Rintel | 9ba8f7c | 2018-04-26 00:00:22 +0200 | [diff] [blame] | 1027 | const struct device *root; |
| 1028 | const struct device *child; |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 1029 | |
Marc Jones | 80bd74c | 2012-02-21 17:44:35 +0100 | [diff] [blame] | 1030 | set_vga_bridge_bits(); |
Marc Jones | 80bd74c | 2012-02-21 17:44:35 +0100 | [diff] [blame] | 1031 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1032 | printk(BIOS_INFO, "Allocating resources...\n"); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1033 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 1034 | root = &dev_root; |
Myles Watson | cd5d756 | 2009-05-12 13:43:34 +0000 | [diff] [blame] | 1035 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 1036 | /* |
| 1037 | * Each domain should create resources which contain the entire address |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 1038 | * space for IO, MEM, and PREFMEM resources in the domain. The |
| 1039 | * allocation of device resources will be done from this address space. |
| 1040 | */ |
Myles Watson | cd5d756 | 2009-05-12 13:43:34 +0000 | [diff] [blame] | 1041 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 1042 | /* Read the resources for the entire tree. */ |
Li-Ta Lo | 0493069 | 2004-11-25 17:37:19 +0000 | [diff] [blame] | 1043 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1044 | printk(BIOS_INFO, "Reading resources...\n"); |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 1045 | read_resources(root->link_list); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1046 | printk(BIOS_INFO, "Done reading resources.\n"); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1047 | |
Stefan Reinauer | 39e7229 | 2009-10-26 16:47:05 +0000 | [diff] [blame] | 1048 | print_resource_tree(root, BIOS_SPEW, "After reading."); |
Myles Watson | cd5d756 | 2009-05-12 13:43:34 +0000 | [diff] [blame] | 1049 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 1050 | /* Compute resources for all domains. */ |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 1051 | for (child = root->link_list->children; child; child = child->sibling) { |
Stefan Reinauer | 4aff445 | 2013-02-12 14:17:15 -0800 | [diff] [blame] | 1052 | if (!(child->path.type == DEVICE_PATH_DOMAIN)) |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 1053 | continue; |
Duncan Laurie | 7ed3976 | 2013-07-09 10:46:52 -0700 | [diff] [blame] | 1054 | post_log_path(child); |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 1055 | for (res = child->resource_list; res; res = res->next) { |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 1056 | if (res->flags & IORESOURCE_FIXED) |
| 1057 | continue; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 1058 | if (res->flags & IORESOURCE_MEM) { |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 1059 | compute_resources(child->link_list, |
Kyösti Mälkki | fdc0a90 | 2015-03-26 20:04:38 +0200 | [diff] [blame] | 1060 | res, IORESOURCE_TYPE_MASK, IORESOURCE_MEM); |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 1061 | continue; |
| 1062 | } |
| 1063 | if (res->flags & IORESOURCE_IO) { |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 1064 | compute_resources(child->link_list, |
Kyösti Mälkki | fdc0a90 | 2015-03-26 20:04:38 +0200 | [diff] [blame] | 1065 | res, IORESOURCE_TYPE_MASK, IORESOURCE_IO); |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 1066 | continue; |
| 1067 | } |
| 1068 | } |
| 1069 | } |
| 1070 | |
| 1071 | /* For all domains. */ |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 1072 | for (child = root->link_list->children; child; child=child->sibling) |
Stefan Reinauer | 4aff445 | 2013-02-12 14:17:15 -0800 | [diff] [blame] | 1073 | if (child->path.type == DEVICE_PATH_DOMAIN) |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 1074 | avoid_fixed_resources(child); |
| 1075 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 1076 | /* Store the computed resource allocations into device registers ... */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1077 | printk(BIOS_INFO, "Setting resources...\n"); |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 1078 | for (child = root->link_list->children; child; child = child->sibling) { |
Stefan Reinauer | 4aff445 | 2013-02-12 14:17:15 -0800 | [diff] [blame] | 1079 | if (!(child->path.type == DEVICE_PATH_DOMAIN)) |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 1080 | continue; |
Duncan Laurie | 7ed3976 | 2013-07-09 10:46:52 -0700 | [diff] [blame] | 1081 | post_log_path(child); |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 1082 | for (res = child->resource_list; res; res = res->next) { |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 1083 | if (res->flags & IORESOURCE_FIXED) |
| 1084 | continue; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 1085 | if (res->flags & IORESOURCE_MEM) { |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 1086 | allocate_resources(child->link_list, |
Kyösti Mälkki | fdc0a90 | 2015-03-26 20:04:38 +0200 | [diff] [blame] | 1087 | res, IORESOURCE_TYPE_MASK, IORESOURCE_MEM); |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 1088 | continue; |
| 1089 | } |
| 1090 | if (res->flags & IORESOURCE_IO) { |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 1091 | allocate_resources(child->link_list, |
Kyösti Mälkki | fdc0a90 | 2015-03-26 20:04:38 +0200 | [diff] [blame] | 1092 | res, IORESOURCE_TYPE_MASK, IORESOURCE_IO); |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 1093 | continue; |
| 1094 | } |
| 1095 | } |
| 1096 | } |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 1097 | assign_resources(root->link_list); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1098 | printk(BIOS_INFO, "Done setting resources.\n"); |
Stefan Reinauer | 39e7229 | 2009-10-26 16:47:05 +0000 | [diff] [blame] | 1099 | print_resource_tree(root, BIOS_SPEW, "After assigning values."); |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 1100 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1101 | printk(BIOS_INFO, "Done allocating resources.\n"); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1102 | } |
| 1103 | |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 1104 | /** |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 1105 | * Enable devices on the device tree. |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 1106 | * |
| 1107 | * Starting at the root, walk the tree and enable all devices/bridges by |
| 1108 | * calling the device's enable_resources() method. |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1109 | */ |
| 1110 | void dev_enable(void) |
| 1111 | { |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 1112 | struct bus *link; |
| 1113 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1114 | printk(BIOS_INFO, "Enabling resources...\n"); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1115 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 1116 | /* Now enable everything. */ |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 1117 | for (link = dev_root.link_list; link; link = link->next) |
| 1118 | enable_resources(link); |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 1119 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1120 | printk(BIOS_INFO, "done.\n"); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1121 | } |
| 1122 | |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 1123 | /** |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 1124 | * Initialize a specific device. |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 1125 | * |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 1126 | * The parent should be initialized first to avoid having an ordering problem. |
Martin Roth | 63373ed | 2013-07-08 16:24:19 -0600 | [diff] [blame] | 1127 | * This is done by calling the parent's init() method before its children's |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 1128 | * init() methods. |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 1129 | * |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 1130 | * @param dev The device to be initialized. |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 1131 | */ |
| 1132 | static void init_dev(struct device *dev) |
| 1133 | { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 1134 | if (!dev->enabled) |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 1135 | return; |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 1136 | |
| 1137 | if (!dev->initialized && dev->ops && dev->ops->init) { |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 1138 | #if CONFIG(HAVE_MONOTONIC_TIMER) |
Aaron Durbin | 46ba480 | 2014-09-23 16:34:40 -0500 | [diff] [blame] | 1139 | struct stopwatch sw; |
| 1140 | stopwatch_init(&sw); |
Aaron Durbin | 0529429 | 2013-04-30 15:41:13 -0500 | [diff] [blame] | 1141 | #endif |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 1142 | if (dev->path.type == DEVICE_PATH_I2C) { |
| 1143 | printk(BIOS_DEBUG, "smbus: %s[%d]->", |
| 1144 | dev_path(dev->bus->dev), dev->bus->link_num); |
| 1145 | } |
| 1146 | |
Paul Menzel | db23215 | 2015-06-07 20:28:17 +0200 | [diff] [blame] | 1147 | printk(BIOS_DEBUG, "%s init ...\n", dev_path(dev)); |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 1148 | dev->initialized = 1; |
| 1149 | dev->ops->init(dev); |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 1150 | #if CONFIG(HAVE_MONOTONIC_TIMER) |
Paul Menzel | db23215 | 2015-06-07 20:28:17 +0200 | [diff] [blame] | 1151 | printk(BIOS_DEBUG, "%s init finished in %ld usecs\n", dev_path(dev), |
Aaron Durbin | 46ba480 | 2014-09-23 16:34:40 -0500 | [diff] [blame] | 1152 | stopwatch_duration_usecs(&sw)); |
Aaron Durbin | 0529429 | 2013-04-30 15:41:13 -0500 | [diff] [blame] | 1153 | #endif |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 1154 | } |
| 1155 | } |
| 1156 | |
| 1157 | static void init_link(struct bus *link) |
| 1158 | { |
| 1159 | struct device *dev; |
| 1160 | struct bus *c_link; |
| 1161 | |
Duncan Laurie | 8adf7a2 | 2013-06-10 10:34:20 -0700 | [diff] [blame] | 1162 | for (dev = link->children; dev; dev = dev->sibling) { |
Duncan Laurie | cb73a84 | 2013-06-10 10:41:04 -0700 | [diff] [blame] | 1163 | post_code(POST_BS_DEV_INIT); |
Duncan Laurie | 8adf7a2 | 2013-06-10 10:34:20 -0700 | [diff] [blame] | 1164 | post_log_path(dev); |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 1165 | init_dev(dev); |
Duncan Laurie | 8adf7a2 | 2013-06-10 10:34:20 -0700 | [diff] [blame] | 1166 | } |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 1167 | |
| 1168 | for (dev = link->children; dev; dev = dev->sibling) { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 1169 | for (c_link = dev->link_list; c_link; c_link = c_link->next) |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 1170 | init_link(c_link); |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 1171 | } |
| 1172 | } |
| 1173 | |
| 1174 | /** |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 1175 | * Initialize all devices in the global device tree. |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 1176 | * |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 1177 | * Starting at the root device, call the device's init() method to do |
| 1178 | * device-specific setup, then call each child's init() method. |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1179 | */ |
| 1180 | void dev_initialize(void) |
| 1181 | { |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 1182 | struct bus *link; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1183 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1184 | printk(BIOS_INFO, "Initializing devices...\n"); |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 1185 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 1186 | #if CONFIG(ARCH_X86) |
Subrata Banik | c7590cd | 2017-09-04 18:44:38 +0530 | [diff] [blame] | 1187 | /* |
| 1188 | * Initialize EBDA area in ramstage if early |
| 1189 | * initialization is not done. |
| 1190 | */ |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 1191 | if (!CONFIG(EARLY_EBDA_INIT)) |
Subrata Banik | c7590cd | 2017-09-04 18:44:38 +0530 | [diff] [blame] | 1192 | /* Ensure EBDA is prepared before Option ROMs. */ |
| 1193 | setup_default_ebda(); |
Duncan Laurie | b4aaaa7 | 2012-01-17 09:03:11 -0800 | [diff] [blame] | 1194 | #endif |
| 1195 | |
Myles Watson | 1bd3fb7 | 2010-08-16 16:25:23 +0000 | [diff] [blame] | 1196 | /* First call the mainboard init. */ |
| 1197 | init_dev(&dev_root); |
| 1198 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 1199 | /* Now initialize everything. */ |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 1200 | for (link = dev_root.link_list; link; link = link->next) |
| 1201 | init_link(link); |
Duncan Laurie | 8adf7a2 | 2013-06-10 10:34:20 -0700 | [diff] [blame] | 1202 | post_log_clear(); |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 1203 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1204 | printk(BIOS_INFO, "Devices initialized\n"); |
Stefan Reinauer | 39e7229 | 2009-10-26 16:47:05 +0000 | [diff] [blame] | 1205 | show_all_devs(BIOS_SPEW, "After init."); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 1206 | } |
Marc Jones | 2a58ecd | 2013-10-29 17:32:00 -0600 | [diff] [blame] | 1207 | |
| 1208 | /** |
| 1209 | * Finalize a specific device. |
| 1210 | * |
| 1211 | * The parent should be finalized first to avoid having an ordering problem. |
| 1212 | * This is done by calling the parent's final() method before its childrens' |
| 1213 | * final() methods. |
| 1214 | * |
| 1215 | * @param dev The device to be initialized. |
| 1216 | */ |
| 1217 | static void final_dev(struct device *dev) |
| 1218 | { |
| 1219 | if (!dev->enabled) |
| 1220 | return; |
| 1221 | |
| 1222 | if (dev->ops && dev->ops->final) { |
| 1223 | printk(BIOS_DEBUG, "%s final\n", dev_path(dev)); |
| 1224 | dev->ops->final(dev); |
| 1225 | } |
| 1226 | } |
| 1227 | |
| 1228 | static void final_link(struct bus *link) |
| 1229 | { |
| 1230 | struct device *dev; |
| 1231 | struct bus *c_link; |
| 1232 | |
| 1233 | for (dev = link->children; dev; dev = dev->sibling) |
| 1234 | final_dev(dev); |
| 1235 | |
| 1236 | for (dev = link->children; dev; dev = dev->sibling) { |
| 1237 | for (c_link = dev->link_list; c_link; c_link = c_link->next) |
| 1238 | final_link(c_link); |
| 1239 | } |
| 1240 | } |
| 1241 | /** |
| 1242 | * Finalize all devices in the global device tree. |
| 1243 | * |
| 1244 | * Starting at the root device, call the device's final() method to do |
| 1245 | * device-specific cleanup, then call each child's final() method. |
| 1246 | */ |
| 1247 | void dev_finalize(void) |
| 1248 | { |
| 1249 | struct bus *link; |
| 1250 | |
| 1251 | printk(BIOS_INFO, "Finalize devices...\n"); |
| 1252 | |
| 1253 | /* First call the mainboard finalize. */ |
| 1254 | final_dev(&dev_root); |
| 1255 | |
| 1256 | /* Now finalize everything. */ |
| 1257 | for (link = dev_root.link_list; link; link = link->next) |
| 1258 | final_link(link); |
| 1259 | |
| 1260 | printk(BIOS_INFO, "Devices finalized\n"); |
| 1261 | } |