Various Doxygen comment fixes, typo fixes, etc.
[coreboot.git] / src / devices / root_device.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2003-2004 Linux Networx
5  * (Written by Eric Biederman <ebiederman@lnxi.com> for Linux Networx)
6  * Copyright (C) 2003 Ronald G. Minnich <rminnich@gmail.com>
7  * Copyright (C) 2004-2005 Li-Ta Lo <ollie@lanl.gov>
8  * Copyright (C) 2005 Tyan
9  * (Written by Yinghai Lu <yhlu@tyan.com> for Tyan)
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; version 2 of the License.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
23  */
24
25 #include <console/console.h>
26 #include <device/device.h>
27 #include <device/pci.h>
28 #include <reset.h>
29
30 /**
31  * Read the resources for the root device, that encompass the resources for
32  * the entire system.
33  *
34  * @param root Pointer to the device structure for the system root device.
35  */
36 static void root_dev_read_resources(device_t root)
37 {
38         printk(BIOS_ERR, "%s should never be called.\n", __func__);
39 }
40
41 /**
42  * Write the resources for every device.
43  *
44  * Write the resources for the root device, and every device under it which
45  * are all of the devices.
46  *
47  * @param root Pointer to the device structure for the system root device.
48  */
49 static void root_dev_set_resources(device_t root)
50 {
51         printk(BIOS_ERR, "%s should never be called.\n", __func__);
52 }
53
54 /**
55  * Scan devices on static buses.
56  *
57  * The enumeration of certain buses is purely static. The existence of
58  * devices on those buses can be completely determined at compile time
59  * and is specified in the config file. Typical examples are the 'PNP'
60  * devices on a legacy ISA/LPC bus. There is no need of probing of any kind,
61  * the only thing we have to do is to walk through the bus and
62  * enable or disable devices as indicated in the config file.
63  *
64  * On the other hand, some devices are virtual and their existence is
65  * artificial. They can not be probed at run time. One example is the
66  * debug device. Those virtual devices have to be listed in the config
67  * file under some static bus in order to be enumerated at run time.
68  *
69  * This function is the default scan_bus() method for the root device and
70  * LPC bridges.
71  *
72  * @param bus Pointer to the device to which the static buses are attached to.
73  * @param max Maximum bus number currently used before scanning.
74  * @return Largest bus number used.
75  */
76 static int smbus_max = 0;
77 unsigned int scan_static_bus(device_t bus, unsigned int max)
78 {
79         device_t child;
80         struct bus* link;
81
82         printk(BIOS_SPEW, "%s for %s\n", __func__, dev_path(bus));
83
84         for(link = bus->link_list; link; link = link->next) {
85                 /* for smbus bus enumerate */
86                 child = link->children;
87                 if(child && child->path.type == DEVICE_PATH_I2C) {
88                         link->secondary = ++smbus_max;
89                 }
90                 for(child =link->children; child; child = child->sibling) {
91                         if (child->chip_ops && child->chip_ops->enable_dev) {
92                                 child->chip_ops->enable_dev(child);
93                         }
94                         if (child->ops && child->ops->enable) {
95                                 child->ops->enable(child);
96                         }
97                         if (child->path.type == DEVICE_PATH_I2C) {
98                                 printk(BIOS_DEBUG, "smbus: %s[%d]->",
99                                         dev_path(child->bus->dev), child->bus->link_num );
100                         }
101                         printk(BIOS_DEBUG, "%s %s\n",
102                                 dev_path(child),
103                                 child->enabled?"enabled": "disabled");
104                 }
105         }
106         for(link = bus->link_list; link; link = link->next) {
107                 for(child = link->children; child; child = child->sibling) {
108                         if (!child->ops || !child->ops->scan_bus)
109                                 continue;
110                         printk(BIOS_SPEW, "%s scanning...\n", dev_path(child));
111                         max = scan_bus(child, max);
112                 }
113         }
114
115         printk(BIOS_SPEW, "%s for %s done\n", __func__, dev_path(bus));
116
117         return max;
118 }
119
120 static void root_dev_enable_resources(device_t dev)
121 {
122 }
123
124 /**
125  * Scan root bus for generic systems.
126  *
127  * This function is the default scan_bus() method of the root device.
128  *
129  * @param root The root device structure.
130  * @param max The current bus number scanned so far, usually 0x00.
131  * @return TODO.
132  */
133 static unsigned int root_dev_scan_bus(device_t root, unsigned int max)
134 {
135         return scan_static_bus(root, max);
136 }
137
138 static void root_dev_init(device_t root)
139 {
140 }
141
142 static void root_dev_reset(struct bus *bus)
143 {
144         printk(BIOS_INFO, "Reseting board...\n");
145         hard_reset();
146 }
147
148 /**
149  * Default device operation for root device.
150  *
151  * This is the default device operation for root devices. These operations
152  * should be fully usable as is. However the chip_operations::enable_dev()
153  * of a motherboard can override this if you want non-default behavior.
154  */
155 struct device_operations default_dev_ops_root = {
156         .read_resources   = root_dev_read_resources,
157         .set_resources    = root_dev_set_resources,
158         .enable_resources = root_dev_enable_resources,
159         .init             = root_dev_init,
160         .scan_bus         = root_dev_scan_bus,
161         .reset_bus        = root_dev_reset,
162 };