blob: 0164b19e99a810dc60dacf48fc586327fd715bbd [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;
Li-Ta Loe5266692004-03-23 21:28:05 +000041
Arthur Heymans7fcd4d52023-08-24 15:12:19 +020042 if (!bus->downstream)
Arthur Heymans80c79a52023-08-24 15:12:19 +020043 return;
44
Arthur Heymans7fcd4d52023-08-24 15:12:19 +020045 for (child = bus->downstream->children; child; child = child->sibling)
Arthur Heymans80c79a52023-08-24 15:12:19 +020046 enable_static_device(child);
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020047}
48
Elyes HAOUAS6e019d82018-05-02 21:34:56 +020049void scan_generic_bus(struct device *bus)
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020050{
Elyes HAOUAS6e019d82018-05-02 21:34:56 +020051 struct device *child;
Furquan Shaikh4e084792017-02-13 13:22:19 -080052 static int bus_max = 0;
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020053
54 printk(BIOS_SPEW, "%s for %s\n", __func__, dev_path(bus));
55
Arthur Heymans7fcd4d52023-08-24 15:12:19 +020056 if (bus->downstream) {
57 bus->downstream->secondary = ++bus_max;
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020058
Arthur Heymans7fcd4d52023-08-24 15:12:19 +020059 for (child = bus->downstream->children; child; child = child->sibling) {
Duncan Laurie3e4a14e12020-10-18 15:04:41 -070060 enable_static_device(child);
Arthur Heymans7fcd4d52023-08-24 15:12:19 +020061 printk(BIOS_DEBUG, "bus: %s->", dev_path(child->upstream->dev));
Eric Biedermane9a271e32003-09-02 03:36:25 +000062 }
63 }
Li-Ta Lofb4c50f2004-05-07 21:52:47 +000064
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000065 printk(BIOS_SPEW, "%s for %s done\n", __func__, dev_path(bus));
Eric Biedermane9a271e32003-09-02 03:36:25 +000066}
67
Elyes HAOUAS6e019d82018-05-02 21:34:56 +020068void scan_smbus(struct device *bus)
Furquan Shaikh4e084792017-02-13 13:22:19 -080069{
70 scan_generic_bus(bus);
71}
72
Nico Hubera89c82e2017-09-14 15:40:28 +020073/*
74 * Default scan_bus() implementation
Li-Ta Lo9782f752004-05-05 21:15:42 +000075 *
Nico Hubera89c82e2017-09-14 15:40:28 +020076 * This is the default implementation for buses that can't
77 * be probed at runtime. It simply walks through the topology
78 * given by the mainboard's `devicetree.cb`.
Uwe Hermannc1ee4292010-10-17 19:01:48 +000079 *
Nico Hubera89c82e2017-09-14 15:40:28 +020080 * First, all direct descendants of the given device are
81 * enabled. Then, downstream buses are scanned.
Li-Ta Lo9782f752004-05-05 21:15:42 +000082 */
Nico Hubera89c82e2017-09-14 15:40:28 +020083void scan_static_bus(struct device *bus)
Eric Biedermane9a271e32003-09-02 03:36:25 +000084{
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020085 printk(BIOS_SPEW, "%s for %s\n", __func__, dev_path(bus));
86
Nico Huberf7ed3d42019-03-14 15:50:06 +010087 enable_static_devices(bus);
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020088
Arthur Heymans7fcd4d52023-08-24 15:12:19 +020089 if (bus->downstream)
90 scan_bridges(bus->downstream);
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020091
92 printk(BIOS_SPEW, "%s for %s done\n", __func__, dev_path(bus));
Eric Biederman03acab62004-10-14 21:25:53 +000093}
94
Myles Watson7eac4452010-06-17 16:16:56 +000095static void root_dev_reset(struct bus *bus)
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000096{
Uwe Hermannd453dd02010-10-18 00:00:57 +000097 printk(BIOS_INFO, "Resetting board...\n");
Nico Huber4f32b642018-10-05 23:40:21 +020098 board_reset();
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000099}
100
Julius Wernercd49cce2019-03-05 16:53:33 -0800101#if CONFIG(HAVE_ACPI_TABLES)
Aaron Durbinaa090cb2017-09-13 16:01:52 -0600102static const char *root_dev_acpi_name(const struct device *dev)
Duncan Lauried9af3ce2016-05-08 18:15:25 -0700103{
104 return "\\_SB";
105}
106#endif
107
Li-Ta Lo9782f752004-05-05 21:15:42 +0000108/**
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000109 * Default device operation for root device.
Li-Ta Lo9782f752004-05-05 21:15:42 +0000110 *
Li-Ta Lo04930692004-11-25 17:37:19 +0000111 * This is the default device operation for root devices. These operations
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000112 * should be fully usable as is. However the chip_operations::enable_dev()
Li-Ta Lo04930692004-11-25 17:37:19 +0000113 * of a motherboard can override this if you want non-default behavior.
Li-Ta Lo9782f752004-05-05 21:15:42 +0000114 */
Eric Biedermane9a271e32003-09-02 03:36:25 +0000115struct device_operations default_dev_ops_root = {
Nico Huber2f8ba692020-04-05 14:05:24 +0200116 .read_resources = noop_read_resources,
117 .set_resources = noop_set_resources,
Nico Hubera89c82e2017-09-14 15:40:28 +0200118 .scan_bus = scan_static_bus,
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000119 .reset_bus = root_dev_reset,
Julius Wernercd49cce2019-03-05 16:53:33 -0800120#if CONFIG(HAVE_ACPI_TABLES)
Duncan Lauried9af3ce2016-05-08 18:15:25 -0700121 .acpi_name = root_dev_acpi_name,
122#endif
Eric Biedermane9a271e32003-09-02 03:36:25 +0000123};