coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
root_device.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <console/console.h>
4 #include <device/device.h>
5 #include <device/pci.h>
6 #include <reset.h>
7 
8 const char mainboard_name[] = CONFIG_MAINBOARD_VENDOR " " CONFIG_MAINBOARD_PART_NUMBER;
9 
10 void 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 
22 /**
23  * Enable devices on static buses.
24  *
25  * The enumeration of certain buses is purely static. The existence of
26  * devices on those buses can be completely determined at compile time
27  * 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
30  * enable or disable devices as indicated in the config file.
31  *
32  * 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.
36  *
37  * @param bus Pointer to the device to which the static buses are attached to.
38  */
39 
41 {
42  struct device *child;
43  struct bus *link;
44 
45  for (link = bus->link_list; link; link = link->next) {
46  for (child = link->children; child; child = child->sibling) {
47  enable_static_device(child);
48  }
49  }
50 }
51 
53 {
54  struct device *child;
55  struct bus *link;
56  static int bus_max = 0;
57 
58  printk(BIOS_SPEW, "%s for %s\n", __func__, dev_path(bus));
59 
60  for (link = bus->link_list; link; link = link->next) {
61 
62  link->secondary = ++bus_max;
63 
64  for (child = link->children; child; child = child->sibling) {
65  enable_static_device(child);
66  printk(BIOS_DEBUG, "bus: %s[%d]->", dev_path(child->bus->dev),
67  child->bus->link_num);
68  }
69  }
70 
71  printk(BIOS_SPEW, "%s for %s done\n", __func__, dev_path(bus));
72 }
73 
74 void scan_smbus(struct device *bus)
75 {
77 }
78 
79 /*
80  * Default scan_bus() implementation
81  *
82  * 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`.
85  *
86  * First, all direct descendants of the given device are
87  * enabled. Then, downstream buses are scanned.
88  */
89 void scan_static_bus(struct device *bus)
90 {
91  struct bus *link;
92 
93  printk(BIOS_SPEW, "%s for %s\n", __func__, dev_path(bus));
94 
96 
97  for (link = bus->link_list; link; link = link->next)
98  scan_bridges(link);
99 
100  printk(BIOS_SPEW, "%s for %s done\n", __func__, dev_path(bus));
101 }
102 
103 static void root_dev_reset(struct bus *bus)
104 {
105  printk(BIOS_INFO, "Resetting board...\n");
106  board_reset();
107 }
108 
109 #if CONFIG(HAVE_ACPI_TABLES)
110 static const char *root_dev_acpi_name(const struct device *dev)
111 {
112  return "\\_SB";
113 }
114 #endif
115 
116 /**
117  * Default device operation for root device.
118  *
119  * This is the default device operation for root devices. These operations
120  * should be fully usable as is. However the chip_operations::enable_dev()
121  * of a motherboard can override this if you want non-default behavior.
122  */
125  .set_resources = noop_set_resources,
126  .scan_bus = scan_static_bus,
127  .reset_bus = root_dev_reset,
128 #if CONFIG(HAVE_ACPI_TABLES)
129  .acpi_name = root_dev_acpi_name,
130 #endif
131 };
#define printk(level,...)
Definition: stdlib.h:16
void scan_bridges(struct bus *bus)
Definition: device.c:383
const char * dev_path(const struct device *dev)
Definition: device_util.c:149
static void noop_read_resources(struct device *dev)
Standard device operations function pointers shims.
Definition: device.h:73
static void noop_set_resources(struct device *dev)
Definition: device.h:74
__noreturn void board_reset(void)
Definition: reset.c:8
#define BIOS_INFO
BIOS_INFO - Expected events.
Definition: loglevel.h:113
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
#define BIOS_SPEW
BIOS_SPEW - Excessively verbose output.
Definition: loglevel.h:142
void scan_static_bus(struct device *bus)
Definition: root_device.c:89
static void root_dev_reset(struct bus *bus)
Definition: root_device.c:103
void scan_generic_bus(struct device *bus)
Definition: root_device.c:52
void scan_smbus(struct device *bus)
Definition: root_device.c:74
void enable_static_device(struct device *dev)
Definition: root_device.c:10
struct device_operations default_dev_ops_root
Default device operation for root device.
Definition: root_device.c:123
const char mainboard_name[]
Definition: root_device.c:8
void enable_static_devices(struct device *bus)
Enable devices on static buses.
Definition: root_device.c:40
Definition: device.h:76
DEVTREE_CONST struct bus * next
Definition: device.h:80
DEVTREE_CONST struct device * children
Definition: device.h:79
unsigned char link_num
Definition: device.h:83
DEVTREE_CONST struct device * dev
Definition: device.h:78
uint16_t secondary
Definition: device.h:84
void(* enable_dev)(struct device *dev)
Definition: device.h:24
void(* read_resources)(struct device *dev)
Definition: device.h:39
void(* enable)(struct device *dev)
Definition: device.h:45
Definition: device.h:107
struct chip_operations * chip_ops
Definition: device.h:144
DEVTREE_CONST struct device * sibling
Definition: device.h:111
struct device_operations * ops
Definition: device.h:143
DEVTREE_CONST struct bus * bus
Definition: device.h:108
unsigned int enabled
Definition: device.h:122