Angel Pons | c74dae9 | 2020-04-02 23:48:16 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Uwe Hermann | b80dbf0 | 2007-04-22 19:08:13 +0000 | [diff] [blame] | 2 | |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 3 | #include <console/console.h> |
| 4 | #include <device/device.h> |
| 5 | #include <device/pci.h> |
Stefan Reinauer | de3206a | 2010-02-22 06:09:43 +0000 | [diff] [blame] | 6 | #include <reset.h> |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 7 | |
Kyösti Mälkki | a93c3fe | 2012-10-09 22:28:56 +0300 | [diff] [blame] | 8 | const char mainboard_name[] = CONFIG_MAINBOARD_VENDOR " " CONFIG_MAINBOARD_PART_NUMBER; |
| 9 | |
Duncan Laurie | 3e4a14e1 | 2020-10-18 15:04:41 -0700 | [diff] [blame] | 10 | void enable_static_device(struct device *dev) |
| 11 | { |
| 12 | if (dev->chip_ops && dev->chip_ops->enable_dev) |
| 13 | dev->chip_ops->enable_dev(dev); |
| 14 | |
| 15 | if (dev->ops && dev->ops->enable) |
| 16 | dev->ops->enable(dev); |
| 17 | |
| 18 | printk(BIOS_DEBUG, "%s %s\n", dev_path(dev), |
| 19 | dev->enabled ? "enabled" : "disabled"); |
| 20 | } |
| 21 | |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 22 | /** |
Nico Huber | f7ed3d4 | 2019-03-14 15:50:06 +0100 | [diff] [blame] | 23 | * Enable devices on static buses. |
Li-Ta Lo | fb4c50f | 2004-05-07 21:52:47 +0000 | [diff] [blame] | 24 | * |
Li-Ta Lo | 9f0d0f9 | 2004-05-10 16:05:16 +0000 | [diff] [blame] | 25 | * The enumeration of certain buses is purely static. The existence of |
| 26 | * devices on those buses can be completely determined at compile time |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 27 | * and is specified in the config file. Typical examples are the 'PNP' |
| 28 | * devices on a legacy ISA/LPC bus. There is no need of probing of any kind, |
| 29 | * 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] | 30 | * enable or disable devices as indicated in the config file. |
Li-Ta Lo | fb4c50f | 2004-05-07 21:52:47 +0000 | [diff] [blame] | 31 | * |
Li-Ta Lo | 0493069 | 2004-11-25 17:37:19 +0000 | [diff] [blame] | 32 | * On the other hand, some devices are virtual and their existence is |
| 33 | * artificial. They can not be probed at run time. One example is the |
| 34 | * debug device. Those virtual devices have to be listed in the config |
| 35 | * 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] | 36 | * |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 37 | * @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] | 38 | */ |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 39 | |
Nico Huber | f7ed3d4 | 2019-03-14 15:50:06 +0100 | [diff] [blame] | 40 | void enable_static_devices(struct device *bus) |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 41 | { |
Elyes HAOUAS | 6e019d8 | 2018-05-02 21:34:56 +0200 | [diff] [blame] | 42 | struct device *child; |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 43 | struct bus *link; |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 44 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 45 | for (link = bus->link_list; link; link = link->next) { |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 46 | for (child = link->children; child; child = child->sibling) { |
Duncan Laurie | 3e4a14e1 | 2020-10-18 15:04:41 -0700 | [diff] [blame] | 47 | enable_static_device(child); |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 48 | } |
| 49 | } |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 50 | } |
| 51 | |
Elyes HAOUAS | 6e019d8 | 2018-05-02 21:34:56 +0200 | [diff] [blame] | 52 | void scan_generic_bus(struct device *bus) |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 53 | { |
Elyes HAOUAS | 6e019d8 | 2018-05-02 21:34:56 +0200 | [diff] [blame] | 54 | struct device *child; |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 55 | struct bus *link; |
Furquan Shaikh | 4e08479 | 2017-02-13 13:22:19 -0800 | [diff] [blame] | 56 | static int bus_max = 0; |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 57 | |
| 58 | printk(BIOS_SPEW, "%s for %s\n", __func__, dev_path(bus)); |
| 59 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 60 | for (link = bus->link_list; link; link = link->next) { |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 61 | |
Furquan Shaikh | 4e08479 | 2017-02-13 13:22:19 -0800 | [diff] [blame] | 62 | link->secondary = ++bus_max; |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 63 | |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 64 | for (child = link->children; child; child = child->sibling) { |
Duncan Laurie | 3e4a14e1 | 2020-10-18 15:04:41 -0700 | [diff] [blame] | 65 | enable_static_device(child); |
Furquan Shaikh | 4e08479 | 2017-02-13 13:22:19 -0800 | [diff] [blame] | 66 | 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] | 67 | child->bus->link_num); |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 68 | } |
| 69 | } |
Li-Ta Lo | fb4c50f | 2004-05-07 21:52:47 +0000 | [diff] [blame] | 70 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 71 | printk(BIOS_SPEW, "%s for %s done\n", __func__, dev_path(bus)); |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 72 | } |
| 73 | |
Elyes HAOUAS | 6e019d8 | 2018-05-02 21:34:56 +0200 | [diff] [blame] | 74 | void scan_smbus(struct device *bus) |
Furquan Shaikh | 4e08479 | 2017-02-13 13:22:19 -0800 | [diff] [blame] | 75 | { |
| 76 | scan_generic_bus(bus); |
| 77 | } |
| 78 | |
Nico Huber | a89c82e | 2017-09-14 15:40:28 +0200 | [diff] [blame] | 79 | /* |
| 80 | * Default scan_bus() implementation |
Li-Ta Lo | 9782f75 | 2004-05-05 21:15:42 +0000 | [diff] [blame] | 81 | * |
Nico Huber | a89c82e | 2017-09-14 15:40:28 +0200 | [diff] [blame] | 82 | * This is the default implementation for buses that can't |
| 83 | * be probed at runtime. It simply walks through the topology |
| 84 | * given by the mainboard's `devicetree.cb`. |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 85 | * |
Nico Huber | a89c82e | 2017-09-14 15:40:28 +0200 | [diff] [blame] | 86 | * First, all direct descendants of the given device are |
| 87 | * enabled. Then, downstream buses are scanned. |
Li-Ta Lo | 9782f75 | 2004-05-05 21:15:42 +0000 | [diff] [blame] | 88 | */ |
Nico Huber | a89c82e | 2017-09-14 15:40:28 +0200 | [diff] [blame] | 89 | void scan_static_bus(struct device *bus) |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 90 | { |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 91 | struct bus *link; |
| 92 | |
| 93 | printk(BIOS_SPEW, "%s for %s\n", __func__, dev_path(bus)); |
| 94 | |
Nico Huber | f7ed3d4 | 2019-03-14 15:50:06 +0100 | [diff] [blame] | 95 | enable_static_devices(bus); |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 96 | |
Kyösti Mälkki | 2d2367c | 2015-02-20 21:28:31 +0200 | [diff] [blame] | 97 | for (link = bus->link_list; link; link = link->next) |
| 98 | scan_bridges(link); |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 99 | |
| 100 | printk(BIOS_SPEW, "%s for %s done\n", __func__, dev_path(bus)); |
Eric Biederman | 03acab6 | 2004-10-14 21:25:53 +0000 | [diff] [blame] | 101 | } |
| 102 | |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 103 | static void root_dev_reset(struct bus *bus) |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 104 | { |
Uwe Hermann | d453dd0 | 2010-10-18 00:00:57 +0000 | [diff] [blame] | 105 | printk(BIOS_INFO, "Resetting board...\n"); |
Nico Huber | 4f32b64 | 2018-10-05 23:40:21 +0200 | [diff] [blame] | 106 | board_reset(); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 107 | } |
| 108 | |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 109 | #if CONFIG(HAVE_ACPI_TABLES) |
Aaron Durbin | aa090cb | 2017-09-13 16:01:52 -0600 | [diff] [blame] | 110 | static const char *root_dev_acpi_name(const struct device *dev) |
Duncan Laurie | d9af3ce | 2016-05-08 18:15:25 -0700 | [diff] [blame] | 111 | { |
| 112 | return "\\_SB"; |
| 113 | } |
| 114 | #endif |
| 115 | |
Li-Ta Lo | 9782f75 | 2004-05-05 21:15:42 +0000 | [diff] [blame] | 116 | /** |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 117 | * Default device operation for root device. |
Li-Ta Lo | 9782f75 | 2004-05-05 21:15:42 +0000 | [diff] [blame] | 118 | * |
Li-Ta Lo | 0493069 | 2004-11-25 17:37:19 +0000 | [diff] [blame] | 119 | * This is the default device operation for root devices. These operations |
Uwe Hermann | c1ee429 | 2010-10-17 19:01:48 +0000 | [diff] [blame] | 120 | * 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] | 121 | * 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] | 122 | */ |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 123 | struct device_operations default_dev_ops_root = { |
Nico Huber | 2f8ba69 | 2020-04-05 14:05:24 +0200 | [diff] [blame] | 124 | .read_resources = noop_read_resources, |
| 125 | .set_resources = noop_set_resources, |
Nico Huber | a89c82e | 2017-09-14 15:40:28 +0200 | [diff] [blame] | 126 | .scan_bus = scan_static_bus, |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 127 | .reset_bus = root_dev_reset, |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 128 | #if CONFIG(HAVE_ACPI_TABLES) |
Duncan Laurie | d9af3ce | 2016-05-08 18:15:25 -0700 | [diff] [blame] | 129 | .acpi_name = root_dev_acpi_name, |
| 130 | #endif |
Eric Biederman | e9a271e3 | 2003-09-02 03:36:25 +0000 | [diff] [blame] | 131 | }; |