Angel Pons | c74dae9 | 2020-04-02 23:48:16 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 2 | |
| 3 | /* |
Martin Roth | 99f83bb | 2019-09-15 20:57:18 -0700 | [diff] [blame] | 4 | * Originally based on the Linux kernel (arch/i386/kernel/pci-pc.c). |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <console/console.h> |
Eric Biederman | 5899fd8 | 2003-04-24 06:25:08 +0000 | [diff] [blame] | 8 | #include <device/device.h> |
Kyösti Mälkki | 318066f | 2014-02-12 14:18:50 +0200 | [diff] [blame] | 9 | #include <device/pci_def.h> |
Li-Ta Lo | 54f05f6 | 2004-05-14 17:20:29 +0000 | [diff] [blame] | 10 | #include <device/pci_ids.h> |
Kyösti Mälkki | ce39ba9 | 2020-01-04 16:15:50 +0200 | [diff] [blame] | 11 | #include <post.h> |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 12 | #include <stdlib.h> |
| 13 | #include <string.h> |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 14 | #include <smp/spinlock.h> |
Kyösti Mälkki | 7336f97 | 2020-06-08 06:05:03 +0300 | [diff] [blame] | 15 | #if ENV_X86 |
Duncan Laurie | b4aaaa7 | 2012-01-17 09:03:11 -0800 | [diff] [blame] | 16 | #include <arch/ebda.h> |
| 17 | #endif |
Aaron Durbin | 0529429 | 2013-04-30 15:41:13 -0500 | [diff] [blame] | 18 | #include <timer.h> |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 19 | |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 20 | /** Pointer to the last device */ |
Myles Watson | 70679a0 | 2010-09-01 21:03:03 +0000 | [diff] [blame] | 21 | extern struct device *last_dev; |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 22 | /** Linked list of free resources */ |
| 23 | struct resource *free_resources = NULL; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 24 | |
Nico Huber | acd7d95 | 2012-07-25 10:33:05 +0200 | [diff] [blame] | 25 | /** |
| 26 | * Initialize all chips of statically known devices. |
| 27 | * |
| 28 | * Will be called before bus enumeration to initialize chips stated in the |
| 29 | * device tree. |
| 30 | */ |
| 31 | void dev_initialize_chips(void) |
| 32 | { |
Lubomir Rintel | 9ba8f7c | 2018-04-26 00:00:22 +0200 | [diff] [blame] | 33 | const struct device *dev; |
Nico Huber | acd7d95 | 2012-07-25 10:33:05 +0200 | [diff] [blame] | 34 | |
| 35 | for (dev = all_devices; dev; dev = dev->next) { |
| 36 | /* Initialize chip if we haven't yet. */ |
| 37 | if (dev->chip_ops && dev->chip_ops->init && |
| 38 | !dev->chip_ops->initialized) { |
Duncan Laurie | 8adf7a2 | 2013-06-10 10:34:20 -0700 | [diff] [blame] | 39 | post_log_path(dev); |
Nico Huber | acd7d95 | 2012-07-25 10:33:05 +0200 | [diff] [blame] | 40 | dev->chip_ops->init(dev->chip_info); |
| 41 | dev->chip_ops->initialized = 1; |
| 42 | } |
| 43 | } |
Duncan Laurie | 8adf7a2 | 2013-06-10 10:34:20 -0700 | [diff] [blame] | 44 | post_log_clear(); |
Nico Huber | acd7d95 | 2012-07-25 10:33:05 +0200 | [diff] [blame] | 45 | } |
| 46 | |
Marc Jones | 2a58ecd | 2013-10-29 17:32:00 -0600 | [diff] [blame] | 47 | /** |
| 48 | * Finalize all chips of statically known devices. |
| 49 | * |
| 50 | * This is the last call before calling the payload. This is a good place |
| 51 | * to lock registers or other final cleanup. |
| 52 | */ |
| 53 | void dev_finalize_chips(void) |
| 54 | { |
Lubomir Rintel | 9ba8f7c | 2018-04-26 00:00:22 +0200 | [diff] [blame] | 55 | const struct device *dev; |
Marc Jones | 2a58ecd | 2013-10-29 17:32:00 -0600 | [diff] [blame] | 56 | |
| 57 | for (dev = all_devices; dev; dev = dev->next) { |
| 58 | /* Initialize chip if we haven't yet. */ |
| 59 | if (dev->chip_ops && dev->chip_ops->final && |
| 60 | !dev->chip_ops->finalized) { |
| 61 | dev->chip_ops->final(dev->chip_info); |
| 62 | dev->chip_ops->finalized = 1; |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 67 | DECLARE_SPIN_LOCK(dev_lock) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 68 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 69 | #if CONFIG(GFXUMA) |
Kyösti Mälkki | cc55b9b | 2012-07-11 07:55:21 +0300 | [diff] [blame] | 70 | /* IGD UMA memory */ |
| 71 | uint64_t uma_memory_base = 0; |
| 72 | uint64_t uma_memory_size = 0; |
Kyösti Mälkki | b25374c | 2012-08-01 08:05:22 +0300 | [diff] [blame] | 73 | #endif |
Kyösti Mälkki | cc55b9b | 2012-07-11 07:55:21 +0300 | [diff] [blame] | 74 | |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 75 | /** |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 76 | * Allocate a new device structure. |
Myles Watson | 032a965 | 2009-05-11 22:24:53 +0000 | [diff] [blame] | 77 | * |
Martin Roth | 63373ed | 2013-07-08 16:24:19 -0600 | [diff] [blame] | 78 | * 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] | 79 | * child of the parent bus. |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 80 | * |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 81 | * @param parent Parent bus the newly created device should be attached to. |
| 82 | * @param path Path to the device to be created. |
| 83 | * @return Pointer to the newly created device structure. |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 84 | * |
| 85 | * @see device_path |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 86 | */ |
Elyes HAOUAS | d34a785 | 2018-09-17 10:44:14 +0200 | [diff] [blame] | 87 | static struct device *__alloc_dev(struct bus *parent, struct device_path *path) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 88 | { |
Elyes HAOUAS | e348066 | 2018-05-06 20:32:23 +0200 | [diff] [blame] | 89 | struct device *dev, *child; |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 90 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 91 | /* Find the last child of our parent. */ |
Elyes HAOUAS | a342f39 | 2018-10-17 10:56:26 +0200 | [diff] [blame] | 92 | for (child = parent->children; child && child->sibling; /* */) |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 93 | child = child->sibling; |
Li-Ta Lo | 3a81285 | 2004-12-03 22:39:34 +0000 | [diff] [blame] | 94 | |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 95 | dev = malloc(sizeof(*dev)); |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 96 | if (dev == 0) |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 97 | die("alloc_dev(): out of memory.\n"); |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 98 | |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 99 | memset(dev, 0, sizeof(*dev)); |
| 100 | memcpy(&dev->path, path, sizeof(*path)); |
| 101 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 102 | /* By default devices are enabled. */ |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 103 | dev->enabled = 1; |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 104 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 105 | /* Add the new device to the list of children of the bus. */ |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 106 | dev->bus = parent; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 107 | if (child) |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 108 | child->sibling = dev; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 109 | else |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 110 | parent->children = dev; |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 111 | |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 112 | /* Append a new device to the global device list. |
| 113 | * The list is used to find devices once everything is set up. |
| 114 | */ |
Myles Watson | 70679a0 | 2010-09-01 21:03:03 +0000 | [diff] [blame] | 115 | last_dev->next = dev; |
| 116 | last_dev = dev; |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 117 | |
Kyösti Mälkki | a5650a4 | 2012-07-07 17:15:51 +0300 | [diff] [blame] | 118 | return dev; |
| 119 | } |
| 120 | |
Elyes HAOUAS | d34a785 | 2018-09-17 10:44:14 +0200 | [diff] [blame] | 121 | 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] | 122 | { |
Elyes HAOUAS | e348066 | 2018-05-06 20:32:23 +0200 | [diff] [blame] | 123 | struct device *dev; |
Kyösti Mälkki | a5650a4 | 2012-07-07 17:15:51 +0300 | [diff] [blame] | 124 | spin_lock(&dev_lock); |
| 125 | dev = __alloc_dev(parent, path); |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 126 | spin_unlock(&dev_lock); |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 127 | return dev; |
| 128 | } |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 129 | |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 130 | /** |
Kyösti Mälkki | a5650a4 | 2012-07-07 17:15:51 +0300 | [diff] [blame] | 131 | * See if a device structure already exists and if not allocate it. |
| 132 | * |
| 133 | * @param parent The bus to find the device on. |
| 134 | * @param path The relative path from the bus to the appropriate device. |
| 135 | * @return Pointer to a device structure for the device on bus at path. |
| 136 | */ |
Elyes HAOUAS | d34a785 | 2018-09-17 10:44:14 +0200 | [diff] [blame] | 137 | 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] | 138 | { |
Elyes HAOUAS | e348066 | 2018-05-06 20:32:23 +0200 | [diff] [blame] | 139 | struct device *child; |
Kyösti Mälkki | a5650a4 | 2012-07-07 17:15:51 +0300 | [diff] [blame] | 140 | spin_lock(&dev_lock); |
| 141 | child = find_dev_path(parent, path); |
| 142 | if (!child) |
| 143 | child = __alloc_dev(parent, path); |
| 144 | spin_unlock(&dev_lock); |
| 145 | return child; |
| 146 | } |
| 147 | |
| 148 | /** |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 149 | * Read the resources on all devices of a given bus. |
| 150 | * |
| 151 | * @param bus Bus to read the resources on. |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 152 | */ |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 153 | static void read_resources(struct bus *bus) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 154 | { |
| 155 | struct device *curdev; |
| 156 | |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 157 | printk(BIOS_SPEW, "%s %s bus %x link: %d\n", dev_path(bus->dev), |
| 158 | __func__, bus->secondary, bus->link_num); |
Eric Biederman | 448bd63 | 2004-10-14 22:52:15 +0000 | [diff] [blame] | 159 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 160 | /* Walk through all devices and find which resources they need. */ |
| 161 | for (curdev = bus->children; curdev; curdev = curdev->sibling) { |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 162 | struct bus *link; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 163 | |
| 164 | if (!curdev->enabled) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 165 | continue; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 166 | |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 167 | if (!curdev->ops || !curdev->ops->read_resources) { |
Martin Roth | 7bc74ab | 2015-11-18 20:23:02 -0700 | [diff] [blame] | 168 | if (curdev->path.type != DEVICE_PATH_APIC) |
Frans Hendriks | a9caa50 | 2021-02-01 11:44:37 +0100 | [diff] [blame] | 169 | printk(BIOS_ERR, "%s missing %s\n", |
| 170 | dev_path(curdev), __func__); |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 171 | continue; |
| 172 | } |
Duncan Laurie | 7ed3976 | 2013-07-09 10:46:52 -0700 | [diff] [blame] | 173 | post_log_path(curdev); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 174 | curdev->ops->read_resources(curdev); |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 175 | |
| 176 | /* Read in the resources behind the current device's links. */ |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 177 | for (link = curdev->link_list; link; link = link->next) |
| 178 | read_resources(link); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 179 | } |
Duncan Laurie | 7ed3976 | 2013-07-09 10:46:52 -0700 | [diff] [blame] | 180 | post_log_clear(); |
Frans Hendriks | a9caa50 | 2021-02-01 11:44:37 +0100 | [diff] [blame] | 181 | printk(BIOS_SPEW, "%s %s bus %d link: %d done\n", |
| 182 | dev_path(bus->dev), __func__, bus->secondary, bus->link_num); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 183 | } |
| 184 | |
Elyes HAOUAS | e348066 | 2018-05-06 20:32:23 +0200 | [diff] [blame] | 185 | struct device *vga_pri = NULL; |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 186 | static void set_vga_bridge_bits(void) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 187 | { |
Uwe Hermann | 312673c | 2009-10-27 21:49:33 +0000 | [diff] [blame] | 188 | /* |
Martin Roth | 63373ed | 2013-07-08 16:24:19 -0600 | [diff] [blame] | 189 | * FIXME: Modify set_vga_bridge() so it is less PCI-centric! |
Uwe Hermann | 312673c | 2009-10-27 21:49:33 +0000 | [diff] [blame] | 190 | * This function knows too much about PCI stuff, it should be just |
| 191 | * an iterator/visitor. |
| 192 | */ |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 193 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 194 | /* FIXME: Handle the VGA palette snooping. */ |
Patrick Georgi | 557ecf2 | 2012-07-20 12:16:17 +0200 | [diff] [blame] | 195 | struct device *dev, *vga, *vga_onboard; |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 196 | struct bus *bus; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 197 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 198 | bus = 0; |
| 199 | vga = 0; |
Yinghai Lu | 1f1085b | 2005-01-17 21:37:12 +0000 | [diff] [blame] | 200 | vga_onboard = 0; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 201 | |
Patrick Georgi | 557ecf2 | 2012-07-20 12:16:17 +0200 | [diff] [blame] | 202 | dev = NULL; |
| 203 | while ((dev = dev_find_class(PCI_CLASS_DISPLAY_VGA << 8, dev))) { |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 204 | if (!dev->enabled) |
| 205 | continue; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 206 | |
Patrick Georgi | 557ecf2 | 2012-07-20 12:16:17 +0200 | [diff] [blame] | 207 | printk(BIOS_DEBUG, "found VGA at %s\n", dev_path(dev)); |
Nico Huber | 061b905 | 2019-09-21 15:58:23 +0200 | [diff] [blame] | 208 | if (dev->bus->no_vga16) { |
| 209 | printk(BIOS_WARNING, |
| 210 | "A bridge on the path doesn't support 16-bit VGA decoding!"); |
| 211 | } |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 212 | |
Frans Hendriks | a9caa50 | 2021-02-01 11:44:37 +0100 | [diff] [blame] | 213 | if (dev->on_mainboard) |
Patrick Georgi | 557ecf2 | 2012-07-20 12:16:17 +0200 | [diff] [blame] | 214 | vga_onboard = dev; |
Frans Hendriks | a9caa50 | 2021-02-01 11:44:37 +0100 | [diff] [blame] | 215 | else |
Patrick Georgi | 557ecf2 | 2012-07-20 12:16:17 +0200 | [diff] [blame] | 216 | vga = dev; |
Myles Watson | 032a965 | 2009-05-11 22:24:53 +0000 | [diff] [blame] | 217 | |
Patrick Georgi | 557ecf2 | 2012-07-20 12:16:17 +0200 | [diff] [blame] | 218 | /* It isn't safe to enable all VGA cards. */ |
| 219 | dev->command &= ~(PCI_COMMAND_MEMORY | PCI_COMMAND_IO); |
Patrick Georgi | 594473d | 2012-07-25 08:55:53 +0200 | [diff] [blame] | 220 | } |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 221 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 222 | if (!vga) |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 223 | vga = vga_onboard; |
Patrick Georgi | 557ecf2 | 2012-07-20 12:16:17 +0200 | [diff] [blame] | 224 | |
Julius Werner | 5d1f9a0 | 2019-03-07 17:07:26 -0800 | [diff] [blame] | 225 | if (CONFIG(ONBOARD_VGA_IS_PRIMARY) && vga_onboard) |
Patrick Georgi | 557ecf2 | 2012-07-20 12:16:17 +0200 | [diff] [blame] | 226 | vga = vga_onboard; |
Myles Watson | 032a965 | 2009-05-11 22:24:53 +0000 | [diff] [blame] | 227 | |
Patrick Georgi | 5869fa2 | 2012-07-20 12:29:33 +0200 | [diff] [blame] | 228 | /* If we prefer plugin VGA over chipset VGA, the chipset might |
| 229 | want to know. */ |
Julius Werner | 5d1f9a0 | 2019-03-07 17:07:26 -0800 | [diff] [blame] | 230 | if (!CONFIG(ONBOARD_VGA_IS_PRIMARY) && (vga != vga_onboard) && |
Patrick Georgi | 5869fa2 | 2012-07-20 12:29:33 +0200 | [diff] [blame] | 231 | vga_onboard && vga_onboard->ops && vga_onboard->ops->disable) { |
| 232 | printk(BIOS_DEBUG, "Use plugin graphics over integrated.\n"); |
| 233 | vga_onboard->ops->disable(vga_onboard); |
| 234 | } |
| 235 | |
arch import user (historical) | dc81118 | 2005-07-06 17:16:09 +0000 | [diff] [blame] | 236 | if (vga) { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 237 | /* VGA is first add-on card or the only onboard VGA. */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 238 | printk(BIOS_DEBUG, "Setting up VGA for %s\n", dev_path(vga)); |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 239 | /* All legacy VGA cards have MEM & I/O space registers. */ |
Yinghai Lu | 1f1085b | 2005-01-17 21:37:12 +0000 | [diff] [blame] | 240 | vga->command |= (PCI_COMMAND_MEMORY | PCI_COMMAND_IO); |
| 241 | vga_pri = vga; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 242 | bus = vga->bus; |
| 243 | } |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 244 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 245 | /* Now walk up the bridges setting the VGA enable. */ |
| 246 | while (bus) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 247 | printk(BIOS_DEBUG, "Setting PCI_BRIDGE_CTL_VGA for bridge %s\n", |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 248 | dev_path(bus->dev)); |
Nico Huber | 061b905 | 2019-09-21 15:58:23 +0200 | [diff] [blame] | 249 | bus->bridge_ctrl |= PCI_BRIDGE_CTL_VGA | PCI_BRIDGE_CTL_VGA16; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 250 | bus = (bus == bus->dev->bus) ? 0 : bus->dev->bus; |
Myles Watson | 032a965 | 2009-05-11 22:24:53 +0000 | [diff] [blame] | 251 | } |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 252 | } |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 253 | |
Li-Ta Lo | 0493069 | 2004-11-25 17:37:19 +0000 | [diff] [blame] | 254 | /** |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 255 | * Assign the computed resources to the devices on the bus. |
Li-Ta Lo | 0493069 | 2004-11-25 17:37:19 +0000 | [diff] [blame] | 256 | * |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 257 | * Use the device specific set_resources() method to store the computed |
Li-Ta Lo | 0493069 | 2004-11-25 17:37:19 +0000 | [diff] [blame] | 258 | * resources to hardware. For bridge devices, the set_resources() method |
| 259 | * has to recurse into every down stream buses. |
| 260 | * |
| 261 | * Mutual recursion: |
| 262 | * assign_resources() -> device_operation::set_resources() |
| 263 | * device_operation::set_resources() -> assign_resources() |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 264 | * |
| 265 | * @param bus Pointer to the structure for this bus. |
Li-Ta Lo | 0493069 | 2004-11-25 17:37:19 +0000 | [diff] [blame] | 266 | */ |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 267 | void assign_resources(struct bus *bus) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 268 | { |
| 269 | struct device *curdev; |
| 270 | |
Frans Hendriks | a9caa50 | 2021-02-01 11:44:37 +0100 | [diff] [blame] | 271 | printk(BIOS_SPEW, "%s %s, bus %d link: %d\n", |
| 272 | dev_path(bus->dev), __func__, bus->secondary, bus->link_num); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 273 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 274 | for (curdev = bus->children; curdev; curdev = curdev->sibling) { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 275 | if (!curdev->enabled || !curdev->resource_list) |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 276 | continue; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 277 | |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 278 | if (!curdev->ops || !curdev->ops->set_resources) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 279 | printk(BIOS_ERR, "%s missing set_resources\n", |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 280 | dev_path(curdev)); |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 281 | continue; |
| 282 | } |
Duncan Laurie | 8adf7a2 | 2013-06-10 10:34:20 -0700 | [diff] [blame] | 283 | post_log_path(curdev); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 284 | curdev->ops->set_resources(curdev); |
| 285 | } |
Duncan Laurie | 8adf7a2 | 2013-06-10 10:34:20 -0700 | [diff] [blame] | 286 | post_log_clear(); |
Frans Hendriks | 739c080 | 2021-02-01 11:52:51 +0100 | [diff] [blame^] | 287 | printk(BIOS_SPEW, "%s %s, bus %d link: %d done\n", |
Frans Hendriks | a9caa50 | 2021-02-01 11:44:37 +0100 | [diff] [blame] | 288 | dev_path(bus->dev), __func__, bus->secondary, bus->link_num); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 289 | } |
| 290 | |
Li-Ta Lo | 5782d27 | 2004-04-26 17:51:20 +0000 | [diff] [blame] | 291 | /** |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 292 | * Enable the resources for devices on a link. |
Li-Ta Lo | 5782d27 | 2004-04-26 17:51:20 +0000 | [diff] [blame] | 293 | * |
| 294 | * Enable resources of the device by calling the device specific |
| 295 | * enable_resources() method. |
| 296 | * |
| 297 | * The parent's resources should be enabled first to avoid having enabling |
| 298 | * order problem. This is done by calling the parent's enable_resources() |
Martin Roth | 63373ed | 2013-07-08 16:24:19 -0600 | [diff] [blame] | 299 | * method before its children's enable_resources() methods. |
Li-Ta Lo | 9f0d0f9 | 2004-05-10 16:05:16 +0000 | [diff] [blame] | 300 | * |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 301 | * @param link The link whose devices' resources are to be enabled. |
Li-Ta Lo | 5782d27 | 2004-04-26 17:51:20 +0000 | [diff] [blame] | 302 | */ |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 303 | static void enable_resources(struct bus *link) |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 304 | { |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 305 | struct device *dev; |
| 306 | struct bus *c_link; |
| 307 | |
| 308 | for (dev = link->children; dev; dev = dev->sibling) { |
Duncan Laurie | 8adf7a2 | 2013-06-10 10:34:20 -0700 | [diff] [blame] | 309 | if (dev->enabled && dev->ops && dev->ops->enable_resources) { |
| 310 | post_log_path(dev); |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 311 | dev->ops->enable_resources(dev); |
Duncan Laurie | 8adf7a2 | 2013-06-10 10:34:20 -0700 | [diff] [blame] | 312 | } |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 313 | } |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 314 | |
| 315 | for (dev = link->children; dev; dev = dev->sibling) { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 316 | 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] | 317 | enable_resources(c_link); |
Eric Biederman | 83b991a | 2003-10-11 06:20:25 +0000 | [diff] [blame] | 318 | } |
Duncan Laurie | 8adf7a2 | 2013-06-10 10:34:20 -0700 | [diff] [blame] | 319 | post_log_clear(); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 320 | } |
| 321 | |
Myles Watson | 032a965 | 2009-05-11 22:24:53 +0000 | [diff] [blame] | 322 | /** |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 323 | * Reset all of the devices on a bus and clear the bus's reset_needed flag. |
| 324 | * |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 325 | * @param bus Pointer to the bus structure. |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 326 | * @return 1 if the bus was successfully reset, 0 otherwise. |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 327 | */ |
| 328 | int reset_bus(struct bus *bus) |
| 329 | { |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 330 | if (bus && bus->dev && bus->dev->ops && bus->dev->ops->reset_bus) { |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 331 | bus->dev->ops->reset_bus(bus); |
| 332 | bus->reset_needed = 0; |
| 333 | return 1; |
| 334 | } |
| 335 | return 0; |
| 336 | } |
| 337 | |
Myles Watson | 032a965 | 2009-05-11 22:24:53 +0000 | [diff] [blame] | 338 | /** |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 339 | * Scan for devices on a bus. |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 340 | * |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 341 | * If there are bridges on the bus, recursively scan the buses behind the |
| 342 | * bridges. If the setting up and tuning of the bus causes a reset to be |
| 343 | * required, reset the bus and scan it again. |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 344 | * |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 345 | * @param busdev Pointer to the bus device. |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 346 | */ |
Kyösti Mälkki | 580e722 | 2015-03-19 21:04:23 +0200 | [diff] [blame] | 347 | static void scan_bus(struct device *busdev) |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 348 | { |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 349 | int do_scan_bus; |
Paul Menzel | 662380f | 2015-10-20 10:21:08 +0200 | [diff] [blame] | 350 | struct stopwatch sw; |
Kyösti Mälkki | e3d9d67 | 2019-12-01 12:27:44 +0200 | [diff] [blame] | 351 | long scan_time; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 352 | |
Kyösti Mälkki | 2d2367c | 2015-02-20 21:28:31 +0200 | [diff] [blame] | 353 | if (!busdev->enabled) |
Kyösti Mälkki | 580e722 | 2015-03-19 21:04:23 +0200 | [diff] [blame] | 354 | return; |
Kyösti Mälkki | 2d2367c | 2015-02-20 21:28:31 +0200 | [diff] [blame] | 355 | |
Kyösti Mälkki | e3d9d67 | 2019-12-01 12:27:44 +0200 | [diff] [blame] | 356 | printk(BIOS_DEBUG, "%s scanning...\n", dev_path(busdev)); |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 357 | |
Duncan Laurie | 8adf7a2 | 2013-06-10 10:34:20 -0700 | [diff] [blame] | 358 | post_log_path(busdev); |
| 359 | |
Kyösti Mälkki | e3d9d67 | 2019-12-01 12:27:44 +0200 | [diff] [blame] | 360 | stopwatch_init(&sw); |
| 361 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 362 | do_scan_bus = 1; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 363 | while (do_scan_bus) { |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 364 | struct bus *link; |
Kyösti Mälkki | 580e722 | 2015-03-19 21:04:23 +0200 | [diff] [blame] | 365 | busdev->ops->scan_bus(busdev); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 366 | do_scan_bus = 0; |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 367 | for (link = busdev->link_list; link; link = link->next) { |
| 368 | if (link->reset_needed) { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 369 | if (reset_bus(link)) |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 370 | do_scan_bus = 1; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 371 | else |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 372 | busdev->bus->reset_needed = 1; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 373 | } |
| 374 | } |
| 375 | } |
Paul Menzel | 662380f | 2015-10-20 10:21:08 +0200 | [diff] [blame] | 376 | |
Kyösti Mälkki | e3d9d67 | 2019-12-01 12:27:44 +0200 | [diff] [blame] | 377 | scan_time = stopwatch_duration_msecs(&sw); |
| 378 | printk(BIOS_DEBUG, "%s: bus %s finished in %ld msecs\n", __func__, |
| 379 | dev_path(busdev), scan_time); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 380 | } |
| 381 | |
Kyösti Mälkki | 2d2367c | 2015-02-20 21:28:31 +0200 | [diff] [blame] | 382 | void scan_bridges(struct bus *bus) |
| 383 | { |
| 384 | struct device *child; |
Kyösti Mälkki | 2d2367c | 2015-02-20 21:28:31 +0200 | [diff] [blame] | 385 | |
| 386 | for (child = bus->children; child; child = child->sibling) { |
| 387 | if (!child->ops || !child->ops->scan_bus) |
| 388 | continue; |
Kyösti Mälkki | 580e722 | 2015-03-19 21:04:23 +0200 | [diff] [blame] | 389 | scan_bus(child); |
Kyösti Mälkki | 2d2367c | 2015-02-20 21:28:31 +0200 | [diff] [blame] | 390 | } |
Kyösti Mälkki | 2d2367c | 2015-02-20 21:28:31 +0200 | [diff] [blame] | 391 | } |
| 392 | |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 393 | /** |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 394 | * Determine the existence of devices and extend the device tree. |
Li-Ta Lo | 0493069 | 2004-11-25 17:37:19 +0000 | [diff] [blame] | 395 | * |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 396 | * 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] | 397 | * file. The device structures for these devices are generated at compile |
| 398 | * time by the config tool and are organized into the device tree. This |
| 399 | * function determines if the devices created at compile time actually exist |
| 400 | * in the physical system. |
| 401 | * |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 402 | * 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] | 403 | * 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] | 404 | * device tree. |
| 405 | * |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 406 | * This function starts from the root device 'dev_root', scans the buses in |
| 407 | * the system recursively, and modifies the device tree according to the |
| 408 | * result of the probe. |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 409 | * |
Li-Ta Lo | 5782d27 | 2004-04-26 17:51:20 +0000 | [diff] [blame] | 410 | * This function has no idea how to scan and probe buses and devices at all. |
| 411 | * 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] | 412 | * scan_bus() method also has to create the device structure and attach |
Myles Watson | 032a965 | 2009-05-11 22:24:53 +0000 | [diff] [blame] | 413 | * it to the device tree. |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 414 | */ |
| 415 | void dev_enumerate(void) |
| 416 | { |
| 417 | struct device *root; |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 418 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 419 | printk(BIOS_INFO, "Enumerating buses...\n"); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 420 | |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 421 | root = &dev_root; |
Myles Watson | cd5d756 | 2009-05-12 13:43:34 +0000 | [diff] [blame] | 422 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 423 | show_all_devs(BIOS_SPEW, "Before device enumeration."); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 424 | printk(BIOS_SPEW, "Compare with tree...\n"); |
Kyösti Mälkki | 3d3c8c3 | 2016-08-15 10:04:21 +0300 | [diff] [blame] | 425 | show_devs_tree(root, BIOS_SPEW, 0); |
Myles Watson | cd5d756 | 2009-05-12 13:43:34 +0000 | [diff] [blame] | 426 | |
Stefan Reinauer | a675d49 | 2012-08-07 14:50:47 -0700 | [diff] [blame] | 427 | if (root->chip_ops && root->chip_ops->enable_dev) |
| 428 | root->chip_ops->enable_dev(root); |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 429 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 430 | if (!root->ops || !root->ops->scan_bus) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 431 | printk(BIOS_ERR, "dev_root missing scan_bus operation"); |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 432 | return; |
| 433 | } |
Kyösti Mälkki | 580e722 | 2015-03-19 21:04:23 +0200 | [diff] [blame] | 434 | scan_bus(root); |
Duncan Laurie | 8adf7a2 | 2013-06-10 10:34:20 -0700 | [diff] [blame] | 435 | post_log_clear(); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 436 | printk(BIOS_INFO, "done\n"); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 437 | } |
| 438 | |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 439 | /** |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 440 | * Configure devices on the devices tree. |
Myles Watson | 032a965 | 2009-05-11 22:24:53 +0000 | [diff] [blame] | 441 | * |
Li-Ta Lo | 0493069 | 2004-11-25 17:37:19 +0000 | [diff] [blame] | 442 | * Starting at the root of the device tree, travel it recursively in two |
| 443 | * passes. In the first pass, we compute and allocate resources (ranges) |
Martin Roth | 63373ed | 2013-07-08 16:24:19 -0600 | [diff] [blame] | 444 | * 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] | 445 | * relocated to their final position and stored to the hardware. |
Li-Ta Lo | 5782d27 | 2004-04-26 17:51:20 +0000 | [diff] [blame] | 446 | * |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 447 | * I/O resources grow upward. MEM resources grow downward. |
Li-Ta Lo | 5782d27 | 2004-04-26 17:51:20 +0000 | [diff] [blame] | 448 | * |
| 449 | * 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] | 450 | * struct. |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 451 | */ |
| 452 | void dev_configure(void) |
| 453 | { |
Lubomir Rintel | 9ba8f7c | 2018-04-26 00:00:22 +0200 | [diff] [blame] | 454 | const struct device *root; |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 455 | |
Marc Jones | 80bd74c | 2012-02-21 17:44:35 +0100 | [diff] [blame] | 456 | set_vga_bridge_bits(); |
Marc Jones | 80bd74c | 2012-02-21 17:44:35 +0100 | [diff] [blame] | 457 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 458 | printk(BIOS_INFO, "Allocating resources...\n"); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 459 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 460 | root = &dev_root; |
Myles Watson | cd5d756 | 2009-05-12 13:43:34 +0000 | [diff] [blame] | 461 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 462 | /* |
| 463 | * Each domain should create resources which contain the entire address |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 464 | * space for IO, MEM, and PREFMEM resources in the domain. The |
| 465 | * allocation of device resources will be done from this address space. |
| 466 | */ |
Myles Watson | cd5d756 | 2009-05-12 13:43:34 +0000 | [diff] [blame] | 467 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 468 | /* Read the resources for the entire tree. */ |
Li-Ta Lo | 0493069 | 2004-11-25 17:37:19 +0000 | [diff] [blame] | 469 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 470 | printk(BIOS_INFO, "Reading resources...\n"); |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 471 | read_resources(root->link_list); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 472 | printk(BIOS_INFO, "Done reading resources.\n"); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 473 | |
Stefan Reinauer | 39e7229 | 2009-10-26 16:47:05 +0000 | [diff] [blame] | 474 | print_resource_tree(root, BIOS_SPEW, "After reading."); |
Myles Watson | cd5d756 | 2009-05-12 13:43:34 +0000 | [diff] [blame] | 475 | |
Furquan Shaikh | 6939574 | 2020-05-15 15:43:15 -0700 | [diff] [blame] | 476 | allocate_resources(root); |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 477 | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 478 | assign_resources(root->link_list); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 479 | printk(BIOS_INFO, "Done setting resources.\n"); |
Stefan Reinauer | 39e7229 | 2009-10-26 16:47:05 +0000 | [diff] [blame] | 480 | print_resource_tree(root, BIOS_SPEW, "After assigning values."); |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 481 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 482 | printk(BIOS_INFO, "Done allocating resources.\n"); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 483 | } |
| 484 | |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 485 | /** |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 486 | * Enable devices on the device tree. |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 487 | * |
| 488 | * Starting at the root, walk the tree and enable all devices/bridges by |
| 489 | * calling the device's enable_resources() method. |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 490 | */ |
| 491 | void dev_enable(void) |
| 492 | { |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 493 | struct bus *link; |
| 494 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 495 | printk(BIOS_INFO, "Enabling resources...\n"); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 496 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 497 | /* Now enable everything. */ |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 498 | for (link = dev_root.link_list; link; link = link->next) |
| 499 | enable_resources(link); |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 500 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 501 | printk(BIOS_INFO, "done.\n"); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 502 | } |
| 503 | |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 504 | /** |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 505 | * Initialize a specific device. |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 506 | * |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 507 | * The parent should be initialized first to avoid having an ordering problem. |
Martin Roth | 63373ed | 2013-07-08 16:24:19 -0600 | [diff] [blame] | 508 | * 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] | 509 | * init() methods. |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 510 | * |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 511 | * @param dev The device to be initialized. |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 512 | */ |
| 513 | static void init_dev(struct device *dev) |
| 514 | { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 515 | if (!dev->enabled) |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 516 | return; |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 517 | |
| 518 | if (!dev->initialized && dev->ops && dev->ops->init) { |
Aaron Durbin | 46ba480 | 2014-09-23 16:34:40 -0500 | [diff] [blame] | 519 | struct stopwatch sw; |
Kyösti Mälkki | e3d9d67 | 2019-12-01 12:27:44 +0200 | [diff] [blame] | 520 | long init_time; |
| 521 | |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 522 | if (dev->path.type == DEVICE_PATH_I2C) { |
| 523 | printk(BIOS_DEBUG, "smbus: %s[%d]->", |
| 524 | dev_path(dev->bus->dev), dev->bus->link_num); |
| 525 | } |
| 526 | |
Kyösti Mälkki | e3d9d67 | 2019-12-01 12:27:44 +0200 | [diff] [blame] | 527 | printk(BIOS_DEBUG, "%s init\n", dev_path(dev)); |
| 528 | |
| 529 | stopwatch_init(&sw); |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 530 | dev->initialized = 1; |
| 531 | dev->ops->init(dev); |
Kyösti Mälkki | e3d9d67 | 2019-12-01 12:27:44 +0200 | [diff] [blame] | 532 | |
| 533 | init_time = stopwatch_duration_msecs(&sw); |
| 534 | printk(BIOS_DEBUG, "%s init finished in %ld msecs\n", dev_path(dev), |
| 535 | init_time); |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 536 | } |
| 537 | } |
| 538 | |
| 539 | static void init_link(struct bus *link) |
| 540 | { |
| 541 | struct device *dev; |
| 542 | struct bus *c_link; |
| 543 | |
Duncan Laurie | 8adf7a2 | 2013-06-10 10:34:20 -0700 | [diff] [blame] | 544 | for (dev = link->children; dev; dev = dev->sibling) { |
Duncan Laurie | cb73a84 | 2013-06-10 10:41:04 -0700 | [diff] [blame] | 545 | post_code(POST_BS_DEV_INIT); |
Duncan Laurie | 8adf7a2 | 2013-06-10 10:34:20 -0700 | [diff] [blame] | 546 | post_log_path(dev); |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 547 | init_dev(dev); |
Duncan Laurie | 8adf7a2 | 2013-06-10 10:34:20 -0700 | [diff] [blame] | 548 | } |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 549 | |
| 550 | for (dev = link->children; dev; dev = dev->sibling) { |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 551 | 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] | 552 | init_link(c_link); |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 553 | } |
| 554 | } |
| 555 | |
| 556 | /** |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 557 | * Initialize all devices in the global device tree. |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 558 | * |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 559 | * Starting at the root device, call the device's init() method to do |
| 560 | * device-specific setup, then call each child's init() method. |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 561 | */ |
| 562 | void dev_initialize(void) |
| 563 | { |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 564 | struct bus *link; |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 565 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 566 | printk(BIOS_INFO, "Initializing devices...\n"); |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 567 | |
Kyösti Mälkki | 7336f97 | 2020-06-08 06:05:03 +0300 | [diff] [blame] | 568 | #if ENV_X86 |
Arthur Heymans | 8b7cd43 | 2019-10-26 20:31:41 +0200 | [diff] [blame] | 569 | /* Ensure EBDA is prepared before Option ROMs. */ |
| 570 | setup_default_ebda(); |
Duncan Laurie | b4aaaa7 | 2012-01-17 09:03:11 -0800 | [diff] [blame] | 571 | #endif |
| 572 | |
Myles Watson | 1bd3fb7 | 2010-08-16 16:25:23 +0000 | [diff] [blame] | 573 | /* First call the mainboard init. */ |
| 574 | init_dev(&dev_root); |
| 575 | |
Uwe Hermann | e487047 | 2010-11-04 23:23:47 +0000 | [diff] [blame] | 576 | /* Now initialize everything. */ |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 577 | for (link = dev_root.link_list; link; link = link->next) |
| 578 | init_link(link); |
Duncan Laurie | 8adf7a2 | 2013-06-10 10:34:20 -0700 | [diff] [blame] | 579 | post_log_clear(); |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 580 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 581 | printk(BIOS_INFO, "Devices initialized\n"); |
Stefan Reinauer | 39e7229 | 2009-10-26 16:47:05 +0000 | [diff] [blame] | 582 | show_all_devs(BIOS_SPEW, "After init."); |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 583 | } |
Marc Jones | 2a58ecd | 2013-10-29 17:32:00 -0600 | [diff] [blame] | 584 | |
| 585 | /** |
| 586 | * Finalize a specific device. |
| 587 | * |
| 588 | * The parent should be finalized first to avoid having an ordering problem. |
| 589 | * This is done by calling the parent's final() method before its childrens' |
| 590 | * final() methods. |
| 591 | * |
| 592 | * @param dev The device to be initialized. |
| 593 | */ |
| 594 | static void final_dev(struct device *dev) |
| 595 | { |
| 596 | if (!dev->enabled) |
| 597 | return; |
| 598 | |
| 599 | if (dev->ops && dev->ops->final) { |
| 600 | printk(BIOS_DEBUG, "%s final\n", dev_path(dev)); |
| 601 | dev->ops->final(dev); |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | static void final_link(struct bus *link) |
| 606 | { |
| 607 | struct device *dev; |
| 608 | struct bus *c_link; |
| 609 | |
| 610 | for (dev = link->children; dev; dev = dev->sibling) |
| 611 | final_dev(dev); |
| 612 | |
| 613 | for (dev = link->children; dev; dev = dev->sibling) { |
| 614 | for (c_link = dev->link_list; c_link; c_link = c_link->next) |
| 615 | final_link(c_link); |
| 616 | } |
| 617 | } |
| 618 | /** |
| 619 | * Finalize all devices in the global device tree. |
| 620 | * |
| 621 | * Starting at the root device, call the device's final() method to do |
| 622 | * device-specific cleanup, then call each child's final() method. |
| 623 | */ |
| 624 | void dev_finalize(void) |
| 625 | { |
| 626 | struct bus *link; |
| 627 | |
| 628 | printk(BIOS_INFO, "Finalize devices...\n"); |
| 629 | |
| 630 | /* First call the mainboard finalize. */ |
| 631 | final_dev(&dev_root); |
| 632 | |
| 633 | /* Now finalize everything. */ |
| 634 | for (link = dev_root.link_list; link; link = link->next) |
| 635 | final_link(link); |
| 636 | |
| 637 | printk(BIOS_INFO, "Devices finalized\n"); |
| 638 | } |