blob: 1f51786153c8afa52110816ff4ba10ca4f2cd058 [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
Kyösti Mälkkia93c3fe2012-10-09 22:28:56 +03008const char mainboard_name[] = CONFIG_MAINBOARD_VENDOR " " CONFIG_MAINBOARD_PART_NUMBER;
9
Duncan Laurie3e4a14e12020-10-18 15:04:41 -070010void 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 Reinauer14e22772010-04-27 06:56:47 +000022/**
Nico Huberf7ed3d42019-03-14 15:50:06 +010023 * Enable devices on static buses.
Li-Ta Lofb4c50f2004-05-07 21:52:47 +000024 *
Li-Ta Lo9f0d0f92004-05-10 16:05:16 +000025 * The enumeration of certain buses is purely static. The existence of
26 * devices on those buses can be completely determined at compile time
Stefan Reinauer14e22772010-04-27 06:56:47 +000027 * 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 Lo04930692004-11-25 17:37:19 +000030 * enable or disable devices as indicated in the config file.
Li-Ta Lofb4c50f2004-05-07 21:52:47 +000031 *
Li-Ta Lo04930692004-11-25 17:37:19 +000032 * 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 Lofb4c50f2004-05-07 21:52:47 +000036 *
Uwe Hermannc1ee4292010-10-17 19:01:48 +000037 * @param bus Pointer to the device to which the static buses are attached to.
Eric Biedermane9a271e32003-09-02 03:36:25 +000038 */
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020039
Nico Huberf7ed3d42019-03-14 15:50:06 +010040void enable_static_devices(struct device *bus)
Eric Biedermane9a271e32003-09-02 03:36:25 +000041{
Elyes HAOUAS6e019d82018-05-02 21:34:56 +020042 struct device *child;
Uwe Hermannd453dd02010-10-18 00:00:57 +000043 struct bus *link;
Li-Ta Loe5266692004-03-23 21:28:05 +000044
Uwe Hermannd453dd02010-10-18 00:00:57 +000045 for (link = bus->link_list; link; link = link->next) {
Uwe Hermannd453dd02010-10-18 00:00:57 +000046 for (child = link->children; child; child = child->sibling) {
Duncan Laurie3e4a14e12020-10-18 15:04:41 -070047 enable_static_device(child);
Eric Biedermane9a271e32003-09-02 03:36:25 +000048 }
49 }
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020050}
51
Elyes HAOUAS6e019d82018-05-02 21:34:56 +020052void scan_generic_bus(struct device *bus)
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020053{
Elyes HAOUAS6e019d82018-05-02 21:34:56 +020054 struct device *child;
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020055 struct bus *link;
Furquan Shaikh4e084792017-02-13 13:22:19 -080056 static int bus_max = 0;
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020057
58 printk(BIOS_SPEW, "%s for %s\n", __func__, dev_path(bus));
59
Uwe Hermannd453dd02010-10-18 00:00:57 +000060 for (link = bus->link_list; link; link = link->next) {
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020061
Furquan Shaikh4e084792017-02-13 13:22:19 -080062 link->secondary = ++bus_max;
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020063
Uwe Hermannd453dd02010-10-18 00:00:57 +000064 for (child = link->children; child; child = child->sibling) {
Duncan Laurie3e4a14e12020-10-18 15:04:41 -070065 enable_static_device(child);
Furquan Shaikh4e084792017-02-13 13:22:19 -080066 printk(BIOS_DEBUG, "bus: %s[%d]->", dev_path(child->bus->dev),
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020067 child->bus->link_num);
Eric Biedermane9a271e32003-09-02 03:36:25 +000068 }
69 }
Li-Ta Lofb4c50f2004-05-07 21:52:47 +000070
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000071 printk(BIOS_SPEW, "%s for %s done\n", __func__, dev_path(bus));
Eric Biedermane9a271e32003-09-02 03:36:25 +000072}
73
Elyes HAOUAS6e019d82018-05-02 21:34:56 +020074void scan_smbus(struct device *bus)
Furquan Shaikh4e084792017-02-13 13:22:19 -080075{
76 scan_generic_bus(bus);
77}
78
Nico Hubera89c82e2017-09-14 15:40:28 +020079/*
80 * Default scan_bus() implementation
Li-Ta Lo9782f752004-05-05 21:15:42 +000081 *
Nico Hubera89c82e2017-09-14 15:40:28 +020082 * 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 Hermannc1ee4292010-10-17 19:01:48 +000085 *
Nico Hubera89c82e2017-09-14 15:40:28 +020086 * First, all direct descendants of the given device are
87 * enabled. Then, downstream buses are scanned.
Li-Ta Lo9782f752004-05-05 21:15:42 +000088 */
Nico Hubera89c82e2017-09-14 15:40:28 +020089void scan_static_bus(struct device *bus)
Eric Biedermane9a271e32003-09-02 03:36:25 +000090{
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020091 struct bus *link;
92
93 printk(BIOS_SPEW, "%s for %s\n", __func__, dev_path(bus));
94
Nico Huberf7ed3d42019-03-14 15:50:06 +010095 enable_static_devices(bus);
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020096
Kyösti Mälkki2d2367c2015-02-20 21:28:31 +020097 for (link = bus->link_list; link; link = link->next)
98 scan_bridges(link);
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020099
100 printk(BIOS_SPEW, "%s for %s done\n", __func__, dev_path(bus));
Eric Biederman03acab62004-10-14 21:25:53 +0000101}
102
Myles Watson7eac4452010-06-17 16:16:56 +0000103static void root_dev_reset(struct bus *bus)
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000104{
Uwe Hermannd453dd02010-10-18 00:00:57 +0000105 printk(BIOS_INFO, "Resetting board...\n");
Nico Huber4f32b642018-10-05 23:40:21 +0200106 board_reset();
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000107}
108
Julius Wernercd49cce2019-03-05 16:53:33 -0800109#if CONFIG(HAVE_ACPI_TABLES)
Aaron Durbinaa090cb2017-09-13 16:01:52 -0600110static const char *root_dev_acpi_name(const struct device *dev)
Duncan Lauried9af3ce2016-05-08 18:15:25 -0700111{
112 return "\\_SB";
113}
114#endif
115
Li-Ta Lo9782f752004-05-05 21:15:42 +0000116/**
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000117 * Default device operation for root device.
Li-Ta Lo9782f752004-05-05 21:15:42 +0000118 *
Li-Ta Lo04930692004-11-25 17:37:19 +0000119 * This is the default device operation for root devices. These operations
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000120 * should be fully usable as is. However the chip_operations::enable_dev()
Li-Ta Lo04930692004-11-25 17:37:19 +0000121 * of a motherboard can override this if you want non-default behavior.
Li-Ta Lo9782f752004-05-05 21:15:42 +0000122 */
Eric Biedermane9a271e32003-09-02 03:36:25 +0000123struct device_operations default_dev_ops_root = {
Nico Huber2f8ba692020-04-05 14:05:24 +0200124 .read_resources = noop_read_resources,
125 .set_resources = noop_set_resources,
Nico Hubera89c82e2017-09-14 15:40:28 +0200126 .scan_bus = scan_static_bus,
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000127 .reset_bus = root_dev_reset,
Julius Wernercd49cce2019-03-05 16:53:33 -0800128#if CONFIG(HAVE_ACPI_TABLES)
Duncan Lauried9af3ce2016-05-08 18:15:25 -0700129 .acpi_name = root_dev_acpi_name,
130#endif
Eric Biedermane9a271e32003-09-02 03:36:25 +0000131};