blob: d8edbd58bbe33488a48768ee89ec5a6714f1bc76 [file] [log] [blame]
Angel Ponsc74dae92020-04-02 23:48:16 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Uwe Hermannb80dbf02007-04-22 19:08:13 +00002
Eric Biedermane9a271e32003-09-02 03:36:25 +00003#include <console/console.h>
4#include <device/device.h>
5#include <device/pci.h>
Stefan Reinauerde3206a2010-02-22 06:09:43 +00006#include <reset.h>
Eric Biedermane9a271e32003-09-02 03:36:25 +00007
Duncan Laurie3e4a14e12020-10-18 15:04:41 -07008void enable_static_device(struct device *dev)
9{
10 if (dev->chip_ops && dev->chip_ops->enable_dev)
11 dev->chip_ops->enable_dev(dev);
12
13 if (dev->ops && dev->ops->enable)
14 dev->ops->enable(dev);
15
16 printk(BIOS_DEBUG, "%s %s\n", dev_path(dev),
17 dev->enabled ? "enabled" : "disabled");
18}
19
Stefan Reinauer14e22772010-04-27 06:56:47 +000020/**
Nico Huberf7ed3d42019-03-14 15:50:06 +010021 * Enable devices on static buses.
Li-Ta Lofb4c50f2004-05-07 21:52:47 +000022 *
Li-Ta Lo9f0d0f92004-05-10 16:05:16 +000023 * The enumeration of certain buses is purely static. The existence of
24 * devices on those buses can be completely determined at compile time
Stefan Reinauer14e22772010-04-27 06:56:47 +000025 * and is specified in the config file. Typical examples are the 'PNP'
26 * devices on a legacy ISA/LPC bus. There is no need of probing of any kind,
27 * the only thing we have to do is to walk through the bus and
Li-Ta Lo04930692004-11-25 17:37:19 +000028 * enable or disable devices as indicated in the config file.
Li-Ta Lofb4c50f2004-05-07 21:52:47 +000029 *
Li-Ta Lo04930692004-11-25 17:37:19 +000030 * On the other hand, some devices are virtual and their existence is
31 * artificial. They can not be probed at run time. One example is the
32 * debug device. Those virtual devices have to be listed in the config
33 * file under some static bus in order to be enumerated at run time.
Li-Ta Lofb4c50f2004-05-07 21:52:47 +000034 *
Uwe Hermannc1ee4292010-10-17 19:01:48 +000035 * @param bus Pointer to the device to which the static buses are attached to.
Eric Biedermane9a271e32003-09-02 03:36:25 +000036 */
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020037
Nico Huberf7ed3d42019-03-14 15:50:06 +010038void enable_static_devices(struct device *bus)
Eric Biedermane9a271e32003-09-02 03:36:25 +000039{
Elyes HAOUAS6e019d82018-05-02 21:34:56 +020040 struct device *child;
Uwe Hermannd453dd02010-10-18 00:00:57 +000041 struct bus *link;
Li-Ta Loe5266692004-03-23 21:28:05 +000042
Uwe Hermannd453dd02010-10-18 00:00:57 +000043 for (link = bus->link_list; link; link = link->next) {
Uwe Hermannd453dd02010-10-18 00:00:57 +000044 for (child = link->children; child; child = child->sibling) {
Duncan Laurie3e4a14e12020-10-18 15:04:41 -070045 enable_static_device(child);
Eric Biedermane9a271e32003-09-02 03:36:25 +000046 }
47 }
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020048}
49
Elyes HAOUAS6e019d82018-05-02 21:34:56 +020050void scan_generic_bus(struct device *bus)
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020051{
Elyes HAOUAS6e019d82018-05-02 21:34:56 +020052 struct device *child;
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020053 struct bus *link;
Furquan Shaikh4e084792017-02-13 13:22:19 -080054 static int bus_max = 0;
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020055
56 printk(BIOS_SPEW, "%s for %s\n", __func__, dev_path(bus));
57
Uwe Hermannd453dd02010-10-18 00:00:57 +000058 for (link = bus->link_list; link; link = link->next) {
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020059
Furquan Shaikh4e084792017-02-13 13:22:19 -080060 link->secondary = ++bus_max;
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020061
Uwe Hermannd453dd02010-10-18 00:00:57 +000062 for (child = link->children; child; child = child->sibling) {
Duncan Laurie3e4a14e12020-10-18 15:04:41 -070063 enable_static_device(child);
Furquan Shaikh4e084792017-02-13 13:22:19 -080064 printk(BIOS_DEBUG, "bus: %s[%d]->", dev_path(child->bus->dev),
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020065 child->bus->link_num);
Eric Biedermane9a271e32003-09-02 03:36:25 +000066 }
67 }
Li-Ta Lofb4c50f2004-05-07 21:52:47 +000068
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000069 printk(BIOS_SPEW, "%s for %s done\n", __func__, dev_path(bus));
Eric Biedermane9a271e32003-09-02 03:36:25 +000070}
71
Elyes HAOUAS6e019d82018-05-02 21:34:56 +020072void scan_smbus(struct device *bus)
Furquan Shaikh4e084792017-02-13 13:22:19 -080073{
74 scan_generic_bus(bus);
75}
76
Nico Hubera89c82e2017-09-14 15:40:28 +020077/*
78 * Default scan_bus() implementation
Li-Ta Lo9782f752004-05-05 21:15:42 +000079 *
Nico Hubera89c82e2017-09-14 15:40:28 +020080 * This is the default implementation for buses that can't
81 * be probed at runtime. It simply walks through the topology
82 * given by the mainboard's `devicetree.cb`.
Uwe Hermannc1ee4292010-10-17 19:01:48 +000083 *
Nico Hubera89c82e2017-09-14 15:40:28 +020084 * First, all direct descendants of the given device are
85 * enabled. Then, downstream buses are scanned.
Li-Ta Lo9782f752004-05-05 21:15:42 +000086 */
Nico Hubera89c82e2017-09-14 15:40:28 +020087void scan_static_bus(struct device *bus)
Eric Biedermane9a271e32003-09-02 03:36:25 +000088{
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020089 struct bus *link;
90
91 printk(BIOS_SPEW, "%s for %s\n", __func__, dev_path(bus));
92
Nico Huberf7ed3d42019-03-14 15:50:06 +010093 enable_static_devices(bus);
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020094
Kyösti Mälkki2d2367c2015-02-20 21:28:31 +020095 for (link = bus->link_list; link; link = link->next)
96 scan_bridges(link);
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020097
98 printk(BIOS_SPEW, "%s for %s done\n", __func__, dev_path(bus));
Eric Biederman03acab62004-10-14 21:25:53 +000099}
100
Myles Watson7eac4452010-06-17 16:16:56 +0000101static void root_dev_reset(struct bus *bus)
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000102{
Uwe Hermannd453dd02010-10-18 00:00:57 +0000103 printk(BIOS_INFO, "Resetting board...\n");
Nico Huber4f32b642018-10-05 23:40:21 +0200104 board_reset();
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000105}
106
Julius Wernercd49cce2019-03-05 16:53:33 -0800107#if CONFIG(HAVE_ACPI_TABLES)
Aaron Durbinaa090cb2017-09-13 16:01:52 -0600108static const char *root_dev_acpi_name(const struct device *dev)
Duncan Lauried9af3ce2016-05-08 18:15:25 -0700109{
110 return "\\_SB";
111}
112#endif
113
Li-Ta Lo9782f752004-05-05 21:15:42 +0000114/**
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000115 * Default device operation for root device.
Li-Ta Lo9782f752004-05-05 21:15:42 +0000116 *
Li-Ta Lo04930692004-11-25 17:37:19 +0000117 * This is the default device operation for root devices. These operations
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000118 * should be fully usable as is. However the chip_operations::enable_dev()
Li-Ta Lo04930692004-11-25 17:37:19 +0000119 * of a motherboard can override this if you want non-default behavior.
Li-Ta Lo9782f752004-05-05 21:15:42 +0000120 */
Eric Biedermane9a271e32003-09-02 03:36:25 +0000121struct device_operations default_dev_ops_root = {
Nico Huber2f8ba692020-04-05 14:05:24 +0200122 .read_resources = noop_read_resources,
123 .set_resources = noop_set_resources,
Nico Hubera89c82e2017-09-14 15:40:28 +0200124 .scan_bus = scan_static_bus,
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000125 .reset_bus = root_dev_reset,
Julius Wernercd49cce2019-03-05 16:53:33 -0800126#if CONFIG(HAVE_ACPI_TABLES)
Duncan Lauried9af3ce2016-05-08 18:15:25 -0700127 .acpi_name = root_dev_acpi_name,
128#endif
Eric Biedermane9a271e32003-09-02 03:36:25 +0000129};