blob: 68a7ae668f8644f9394b4b5b8f5ac909d2b1d91e [file] [log] [blame]
Angel Ponsc74dae92020-04-02 23:48:16 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Uwe Hermannb80dbf02007-04-22 19:08:13 +00003
Eric Biedermane9a271e32003-09-02 03:36:25 +00004#include <console/console.h>
5#include <device/device.h>
6#include <device/pci.h>
Stefan Reinauerde3206a2010-02-22 06:09:43 +00007#include <reset.h>
Eric Biedermane9a271e32003-09-02 03:36:25 +00008
Kyösti Mälkkia93c3fe2012-10-09 22:28:56 +03009const char mainboard_name[] = CONFIG_MAINBOARD_VENDOR " " CONFIG_MAINBOARD_PART_NUMBER;
10
Stefan Reinauer14e22772010-04-27 06:56:47 +000011/**
Nico Huberf7ed3d42019-03-14 15:50:06 +010012 * Enable devices on static buses.
Li-Ta Lofb4c50f2004-05-07 21:52:47 +000013 *
Li-Ta Lo9f0d0f92004-05-10 16:05:16 +000014 * The enumeration of certain buses is purely static. The existence of
15 * devices on those buses can be completely determined at compile time
Stefan Reinauer14e22772010-04-27 06:56:47 +000016 * and is specified in the config file. Typical examples are the 'PNP'
17 * devices on a legacy ISA/LPC bus. There is no need of probing of any kind,
18 * the only thing we have to do is to walk through the bus and
Li-Ta Lo04930692004-11-25 17:37:19 +000019 * enable or disable devices as indicated in the config file.
Li-Ta Lofb4c50f2004-05-07 21:52:47 +000020 *
Li-Ta Lo04930692004-11-25 17:37:19 +000021 * On the other hand, some devices are virtual and their existence is
22 * artificial. They can not be probed at run time. One example is the
23 * debug device. Those virtual devices have to be listed in the config
24 * file under some static bus in order to be enumerated at run time.
Li-Ta Lofb4c50f2004-05-07 21:52:47 +000025 *
Uwe Hermannc1ee4292010-10-17 19:01:48 +000026 * @param bus Pointer to the device to which the static buses are attached to.
Eric Biedermane9a271e32003-09-02 03:36:25 +000027 */
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020028
Nico Huberf7ed3d42019-03-14 15:50:06 +010029void enable_static_devices(struct device *bus)
Eric Biedermane9a271e32003-09-02 03:36:25 +000030{
Elyes HAOUAS6e019d82018-05-02 21:34:56 +020031 struct device *child;
Uwe Hermannd453dd02010-10-18 00:00:57 +000032 struct bus *link;
Li-Ta Loe5266692004-03-23 21:28:05 +000033
Uwe Hermannd453dd02010-10-18 00:00:57 +000034 for (link = bus->link_list; link; link = link->next) {
Uwe Hermannd453dd02010-10-18 00:00:57 +000035 for (child = link->children; child; child = child->sibling) {
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020036
Uwe Hermannd453dd02010-10-18 00:00:57 +000037 if (child->chip_ops && child->chip_ops->enable_dev)
Eric Biederman7003ba42004-10-16 06:20:29 +000038 child->chip_ops->enable_dev(child);
Uwe Hermannd453dd02010-10-18 00:00:57 +000039
40 if (child->ops && child->ops->enable)
Eric Biedermane9a271e32003-09-02 03:36:25 +000041 child->ops->enable(child);
Uwe Hermannd453dd02010-10-18 00:00:57 +000042
Uwe Hermannd453dd02010-10-18 00:00:57 +000043 printk(BIOS_DEBUG, "%s %s\n", dev_path(child),
44 child->enabled ? "enabled" : "disabled");
Eric Biedermane9a271e32003-09-02 03:36:25 +000045 }
46 }
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;
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020052 struct bus *link;
Furquan Shaikh4e084792017-02-13 13:22:19 -080053 static int bus_max = 0;
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020054
55 printk(BIOS_SPEW, "%s for %s\n", __func__, dev_path(bus));
56
Uwe Hermannd453dd02010-10-18 00:00:57 +000057 for (link = bus->link_list; link; link = link->next) {
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020058
Furquan Shaikh4e084792017-02-13 13:22:19 -080059 link->secondary = ++bus_max;
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020060
Uwe Hermannd453dd02010-10-18 00:00:57 +000061 for (child = link->children; child; child = child->sibling) {
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020062
63 if (child->chip_ops && child->chip_ops->enable_dev)
64 child->chip_ops->enable_dev(child);
65
66 if (child->ops && child->ops->enable)
67 child->ops->enable(child);
68
Furquan Shaikh4e084792017-02-13 13:22:19 -080069 printk(BIOS_DEBUG, "bus: %s[%d]->", dev_path(child->bus->dev),
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020070 child->bus->link_num);
71
72 printk(BIOS_DEBUG, "%s %s\n", dev_path(child),
73 child->enabled ? "enabled" : "disabled");
Eric Biedermane9a271e32003-09-02 03:36:25 +000074 }
75 }
Li-Ta Lofb4c50f2004-05-07 21:52:47 +000076
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000077 printk(BIOS_SPEW, "%s for %s done\n", __func__, dev_path(bus));
Eric Biedermane9a271e32003-09-02 03:36:25 +000078}
79
Elyes HAOUAS6e019d82018-05-02 21:34:56 +020080void scan_smbus(struct device *bus)
Furquan Shaikh4e084792017-02-13 13:22:19 -080081{
82 scan_generic_bus(bus);
83}
84
Nico Hubera89c82e2017-09-14 15:40:28 +020085/*
86 * Default scan_bus() implementation
Li-Ta Lo9782f752004-05-05 21:15:42 +000087 *
Nico Hubera89c82e2017-09-14 15:40:28 +020088 * This is the default implementation for buses that can't
89 * be probed at runtime. It simply walks through the topology
90 * given by the mainboard's `devicetree.cb`.
Uwe Hermannc1ee4292010-10-17 19:01:48 +000091 *
Nico Hubera89c82e2017-09-14 15:40:28 +020092 * First, all direct descendants of the given device are
93 * enabled. Then, downstream buses are scanned.
Li-Ta Lo9782f752004-05-05 21:15:42 +000094 */
Nico Hubera89c82e2017-09-14 15:40:28 +020095void scan_static_bus(struct device *bus)
Eric Biedermane9a271e32003-09-02 03:36:25 +000096{
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +020097 struct bus *link;
98
99 printk(BIOS_SPEW, "%s for %s\n", __func__, dev_path(bus));
100
Nico Huberf7ed3d42019-03-14 15:50:06 +0100101 enable_static_devices(bus);
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +0200102
Kyösti Mälkki2d2367c2015-02-20 21:28:31 +0200103 for (link = bus->link_list; link; link = link->next)
104 scan_bridges(link);
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +0200105
106 printk(BIOS_SPEW, "%s for %s done\n", __func__, dev_path(bus));
Eric Biederman03acab62004-10-14 21:25:53 +0000107}
108
Myles Watson7eac4452010-06-17 16:16:56 +0000109static void root_dev_reset(struct bus *bus)
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000110{
Uwe Hermannd453dd02010-10-18 00:00:57 +0000111 printk(BIOS_INFO, "Resetting board...\n");
Nico Huber4f32b642018-10-05 23:40:21 +0200112 board_reset();
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000113}
114
Julius Wernercd49cce2019-03-05 16:53:33 -0800115#if CONFIG(HAVE_ACPI_TABLES)
Aaron Durbinaa090cb2017-09-13 16:01:52 -0600116static const char *root_dev_acpi_name(const struct device *dev)
Duncan Lauried9af3ce2016-05-08 18:15:25 -0700117{
118 return "\\_SB";
119}
120#endif
121
Li-Ta Lo9782f752004-05-05 21:15:42 +0000122/**
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000123 * Default device operation for root device.
Li-Ta Lo9782f752004-05-05 21:15:42 +0000124 *
Li-Ta Lo04930692004-11-25 17:37:19 +0000125 * This is the default device operation for root devices. These operations
Uwe Hermannc1ee4292010-10-17 19:01:48 +0000126 * should be fully usable as is. However the chip_operations::enable_dev()
Li-Ta Lo04930692004-11-25 17:37:19 +0000127 * of a motherboard can override this if you want non-default behavior.
Li-Ta Lo9782f752004-05-05 21:15:42 +0000128 */
Eric Biedermane9a271e32003-09-02 03:36:25 +0000129struct device_operations default_dev_ops_root = {
Kyösti Mälkki85756c12015-02-06 09:15:52 +0200130 .read_resources = DEVICE_NOOP,
131 .set_resources = DEVICE_NOOP,
Nico Hubera89c82e2017-09-14 15:40:28 +0200132 .scan_bus = scan_static_bus,
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000133 .reset_bus = root_dev_reset,
Julius Wernercd49cce2019-03-05 16:53:33 -0800134#if CONFIG(HAVE_ACPI_TABLES)
Duncan Lauried9af3ce2016-05-08 18:15:25 -0700135 .acpi_name = root_dev_acpi_name,
136#endif
Eric Biedermane9a271e32003-09-02 03:36:25 +0000137};