1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <console/console.h>
4 #include <device/device.h>
5 #include <device/pci.h>
8 void enable_static_device(struct device
*dev
)
10 if (dev
->chip_ops
&& dev
->chip_ops
->enable_dev
)
11 dev
->chip_ops
->enable_dev(dev
);
13 if (dev
->ops
&& dev
->ops
->enable
)
14 dev
->ops
->enable(dev
);
16 printk(BIOS_DEBUG
, "%s %s\n", dev_path(dev
),
17 dev
->enabled
? "enabled" : "disabled");
21 * Enable devices on static buses.
23 * The enumeration of certain buses is purely static. The existence of
24 * devices on those buses can be completely determined at compile time
25 * 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
28 * enable or disable devices as indicated in the config file.
30 * 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.
35 * @param bus Pointer to the device to which the static buses are attached to.
38 void enable_static_devices(struct device
*bus
)
43 for (link
= bus
->link_list
; link
; link
= link
->next
) {
44 for (child
= link
->children
; child
; child
= child
->sibling
) {
45 enable_static_device(child
);
50 void scan_generic_bus(struct device
*bus
)
54 static int bus_max
= 0;
56 printk(BIOS_SPEW
, "%s for %s\n", __func__
, dev_path(bus
));
58 for (link
= bus
->link_list
; link
; link
= link
->next
) {
60 link
->secondary
= ++bus_max
;
62 for (child
= link
->children
; child
; child
= child
->sibling
) {
63 enable_static_device(child
);
64 printk(BIOS_DEBUG
, "bus: %s[%d]->", dev_path(child
->bus
->dev
),
65 child
->bus
->link_num
);
69 printk(BIOS_SPEW
, "%s for %s done\n", __func__
, dev_path(bus
));
72 void scan_smbus(struct device
*bus
)
74 scan_generic_bus(bus
);
78 * Default scan_bus() implementation
80 * 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`.
84 * First, all direct descendants of the given device are
85 * enabled. Then, downstream buses are scanned.
87 void scan_static_bus(struct device
*bus
)
91 printk(BIOS_SPEW
, "%s for %s\n", __func__
, dev_path(bus
));
93 enable_static_devices(bus
);
95 for (link
= bus
->link_list
; link
; link
= link
->next
)
98 printk(BIOS_SPEW
, "%s for %s done\n", __func__
, dev_path(bus
));
101 static void root_dev_reset(struct bus
*bus
)
103 printk(BIOS_INFO
, "Resetting board...\n");
107 #if CONFIG(HAVE_ACPI_TABLES)
108 static const char *root_dev_acpi_name(const struct device
*dev
)
115 * Default device operation for root device.
117 * This is the default device operation for root devices. These operations
118 * should be fully usable as is. However the chip_operations::enable_dev()
119 * of a motherboard can override this if you want non-default behavior.
121 struct device_operations default_dev_ops_root
= {
122 .read_resources
= noop_read_resources
,
123 .set_resources
= noop_set_resources
,
124 .scan_bus
= scan_static_bus
,
125 .reset_bus
= root_dev_reset
,
126 #if CONFIG(HAVE_ACPI_TABLES)
127 .acpi_name
= root_dev_acpi_name
,