Uwe Hermann | b80dbf0 | 2007-04-22 19:08:13 +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 | * Copyright (C) 2003-2004 Linux Networx |
| 5 | * (Written by Eric Biederman <ebiederman@lnxi.com> for Linux Networx) |
| 6 | * Copyright (C) 2003 Ronald G. Minnich <rminnich@gmail.com> |
| 7 | * Copyright (C) 2004-2005 Li-Ta Lo <ollie@lanl.gov> |
| 8 | * Copyright (C) 2005 Tyan |
| 9 | * (Written by Yinghai Lu <yhlu@tyan.com> for Tyan) |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; version 2 of the License. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
Uwe Hermann | b80dbf0 | 2007-04-22 19:08:13 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 21 | #include <console/console.h> |
| 22 | #include <device/device.h> |
| 23 | #include <device/pci.h> |
Stefan Reinauer | de3206a | 2010-02-22 06:09:43 +0000 | [diff] [blame] | 24 | #include <reset.h> |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 25 | |
Kyösti Mälkki | a93c3fe | 2012-10-09 22:28:56 +0300 | [diff] [blame] | 26 | const char mainboard_name[] = CONFIG_MAINBOARD_VENDOR " " CONFIG_MAINBOARD_PART_NUMBER; |
| 27 | |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 28 | /** |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 29 | * Scan devices on static buses. |
Li-Ta Lo | fb4c50f | 2004-05-07 21:52:47 +0000 | [diff] [blame] | 30 | * |
Li-Ta Lo | 9f0d0f9 | 2004-05-10 16:05:16 +0000 | [diff] [blame] | 31 | * The enumeration of certain buses is purely static. The existence of |
| 32 | * devices on those buses can be completely determined at compile time |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 33 | * and is specified in the config file. Typical examples are the 'PNP' |
| 34 | * devices on a legacy ISA/LPC bus. There is no need of probing of any kind, |
| 35 | * the only thing we have to do is to walk through the bus and |
Li-Ta Lo | 0493069 | 2004-11-25 17:37:19 +0000 | [diff] [blame] | 36 | * enable or disable devices as indicated in the config file. |
Li-Ta Lo | fb4c50f | 2004-05-07 21:52:47 +0000 | [diff] [blame] | 37 | * |
Li-Ta Lo | 0493069 | 2004-11-25 17:37:19 +0000 | [diff] [blame] | 38 | * On the other hand, some devices are virtual and their existence is |
| 39 | * artificial. They can not be probed at run time. One example is the |
| 40 | * debug device. Those virtual devices have to be listed in the config |
| 41 | * file under some static bus in order to be enumerated at run time. |
Li-Ta Lo | fb4c50f | 2004-05-07 21:52:47 +0000 | [diff] [blame] | 42 | * |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 43 | * @param bus Pointer to the device to which the static buses are attached to. |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 44 | */ |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 45 | |
Elyes HAOUAS | 6e019d8 | 2018-05-02 21:34:56 +0200 | [diff] [blame] | 46 | void scan_static_bus(struct device *bus) |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 47 | { |
Elyes HAOUAS | 6e019d8 | 2018-05-02 21:34:56 +0200 | [diff] [blame] | 48 | struct device *child; |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 49 | struct bus *link; |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 50 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 51 | for (link = bus->link_list; link; link = link->next) { |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 52 | for (child = link->children; child; child = child->sibling) { |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 53 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 54 | if (child->chip_ops && child->chip_ops->enable_dev) |
Eric Biederman | 7003ba4 | 2004-10-16 06:20:29 +0000 | [diff] [blame] | 55 | child->chip_ops->enable_dev(child); |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 56 | |
| 57 | if (child->ops && child->ops->enable) |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 58 | child->ops->enable(child); |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 59 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 60 | printk(BIOS_DEBUG, "%s %s\n", dev_path(child), |
| 61 | child->enabled ? "enabled" : "disabled"); |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 62 | } |
| 63 | } |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 64 | } |
| 65 | |
Elyes HAOUAS | 6e019d8 | 2018-05-02 21:34:56 +0200 | [diff] [blame] | 66 | void scan_lpc_bus(struct device *bus) |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 67 | { |
| 68 | printk(BIOS_SPEW, "%s for %s\n", __func__, dev_path(bus)); |
| 69 | |
Kyösti Mälkki | 580e722 | 2015-03-19 21:04:23 +0200 | [diff] [blame] | 70 | scan_static_bus(bus); |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 71 | |
| 72 | printk(BIOS_SPEW, "%s for %s done\n", __func__, dev_path(bus)); |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 73 | } |
| 74 | |
Duncan Laurie | bae9f85 | 2018-05-07 14:18:13 -0700 | [diff] [blame] | 75 | void scan_usb_bus(struct device *bus) |
| 76 | { |
| 77 | struct bus *link; |
| 78 | |
| 79 | printk(BIOS_SPEW, "%s for %s\n", __func__, dev_path(bus)); |
| 80 | |
| 81 | scan_static_bus(bus); |
| 82 | |
| 83 | /* Scan bridges in case this device is a hub */ |
| 84 | for (link = bus->link_list; link; link = link->next) |
| 85 | scan_bridges(link); |
| 86 | |
| 87 | printk(BIOS_SPEW, "%s for %s done\n", __func__, dev_path(bus)); |
| 88 | } |
| 89 | |
Elyes HAOUAS | 6e019d8 | 2018-05-02 21:34:56 +0200 | [diff] [blame] | 90 | void scan_generic_bus(struct device *bus) |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 91 | { |
Elyes HAOUAS | 6e019d8 | 2018-05-02 21:34:56 +0200 | [diff] [blame] | 92 | struct device *child; |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 93 | struct bus *link; |
Furquan Shaikh | 4e08479 | 2017-02-13 13:22:19 -0800 | [diff] [blame] | 94 | static int bus_max = 0; |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 95 | |
| 96 | printk(BIOS_SPEW, "%s for %s\n", __func__, dev_path(bus)); |
| 97 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 98 | for (link = bus->link_list; link; link = link->next) { |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 99 | |
Furquan Shaikh | 4e08479 | 2017-02-13 13:22:19 -0800 | [diff] [blame] | 100 | link->secondary = ++bus_max; |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 101 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 102 | for (child = link->children; child; child = child->sibling) { |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 103 | |
| 104 | if (child->chip_ops && child->chip_ops->enable_dev) |
| 105 | child->chip_ops->enable_dev(child); |
| 106 | |
| 107 | if (child->ops && child->ops->enable) |
| 108 | child->ops->enable(child); |
| 109 | |
Furquan Shaikh | 4e08479 | 2017-02-13 13:22:19 -0800 | [diff] [blame] | 110 | printk(BIOS_DEBUG, "bus: %s[%d]->", dev_path(child->bus->dev), |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 111 | child->bus->link_num); |
| 112 | |
| 113 | printk(BIOS_DEBUG, "%s %s\n", dev_path(child), |
| 114 | child->enabled ? "enabled" : "disabled"); |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 115 | } |
| 116 | } |
Li-Ta Lo | fb4c50f | 2004-05-07 21:52:47 +0000 | [diff] [blame] | 117 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 118 | printk(BIOS_SPEW, "%s for %s done\n", __func__, dev_path(bus)); |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 119 | } |
| 120 | |
Elyes HAOUAS | 6e019d8 | 2018-05-02 21:34:56 +0200 | [diff] [blame] | 121 | void scan_smbus(struct device *bus) |
Furquan Shaikh | 4e08479 | 2017-02-13 13:22:19 -0800 | [diff] [blame] | 122 | { |
| 123 | scan_generic_bus(bus); |
| 124 | } |
| 125 | |
Li-Ta Lo | 9782f75 | 2004-05-05 21:15:42 +0000 | [diff] [blame] | 126 | /** |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 127 | * Scan root bus for generic systems. |
Li-Ta Lo | 9782f75 | 2004-05-05 21:15:42 +0000 | [diff] [blame] | 128 | * |
Li-Ta Lo | 0493069 | 2004-11-25 17:37:19 +0000 | [diff] [blame] | 129 | * This function is the default scan_bus() method of the root device. |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 130 | * |
| 131 | * @param root The root device structure. |
Li-Ta Lo | 9782f75 | 2004-05-05 21:15:42 +0000 | [diff] [blame] | 132 | */ |
Elyes HAOUAS | 6e019d8 | 2018-05-02 21:34:56 +0200 | [diff] [blame] | 133 | static void root_dev_scan_bus(struct device *bus) |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 134 | { |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 135 | struct bus *link; |
| 136 | |
| 137 | printk(BIOS_SPEW, "%s for %s\n", __func__, dev_path(bus)); |
| 138 | |
Kyösti Mälkki | 580e722 | 2015-03-19 21:04:23 +0200 | [diff] [blame] | 139 | scan_static_bus(bus); |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 140 | |
Kyösti Mälkki | 2d2367c | 2015-02-20 21:28:31 +0200 | [diff] [blame] | 141 | for (link = bus->link_list; link; link = link->next) |
| 142 | scan_bridges(link); |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 143 | |
| 144 | printk(BIOS_SPEW, "%s for %s done\n", __func__, dev_path(bus)); |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 145 | } |
| 146 | |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 147 | static void root_dev_reset(struct bus *bus) |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 148 | { |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 149 | printk(BIOS_INFO, "Resetting board...\n"); |
Nico Huber | 4f32b64 | 2018-10-05 23:40:21 +0200 | [diff] [blame] | 150 | board_reset(); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 151 | } |
| 152 | |
Duncan Laurie | d9af3ce | 2016-05-08 18:15:25 -0700 | [diff] [blame] | 153 | #if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES) |
Aaron Durbin | aa090cb | 2017-09-13 16:01:52 -0600 | [diff] [blame] | 154 | static const char *root_dev_acpi_name(const struct device *dev) |
Duncan Laurie | d9af3ce | 2016-05-08 18:15:25 -0700 | [diff] [blame] | 155 | { |
| 156 | return "\\_SB"; |
| 157 | } |
| 158 | #endif |
| 159 | |
Li-Ta Lo | 9782f75 | 2004-05-05 21:15:42 +0000 | [diff] [blame] | 160 | /** |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 161 | * Default device operation for root device. |
Li-Ta Lo | 9782f75 | 2004-05-05 21:15:42 +0000 | [diff] [blame] | 162 | * |
Li-Ta Lo | 0493069 | 2004-11-25 17:37:19 +0000 | [diff] [blame] | 163 | * This is the default device operation for root devices. These operations |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 164 | * should be fully usable as is. However the chip_operations::enable_dev() |
Li-Ta Lo | 0493069 | 2004-11-25 17:37:19 +0000 | [diff] [blame] | 165 | * of a motherboard can override this if you want non-default behavior. |
Li-Ta Lo | 9782f75 | 2004-05-05 21:15:42 +0000 | [diff] [blame] | 166 | */ |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 167 | struct device_operations default_dev_ops_root = { |
Kyösti Mälkki | 85756c1 | 2015-02-06 09:15:52 +0200 | [diff] [blame] | 168 | .read_resources = DEVICE_NOOP, |
| 169 | .set_resources = DEVICE_NOOP, |
| 170 | .enable_resources = DEVICE_NOOP, |
| 171 | .init = DEVICE_NOOP, |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 172 | .scan_bus = root_dev_scan_bus, |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 173 | .reset_bus = root_dev_reset, |
Duncan Laurie | d9af3ce | 2016-05-08 18:15:25 -0700 | [diff] [blame] | 174 | #if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES) |
| 175 | .acpi_name = root_dev_acpi_name, |
| 176 | #endif |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 177 | }; |