2 * Copyright (C) 2006 Michael Brown <mbrown@fensystems.co.uk>.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 FILE_LICENCE ( GPL2_OR_LATER
);
22 #include <gpxe/list.h>
23 #include <gpxe/tables.h>
24 #include <gpxe/device.h>
25 #include <gpxe/init.h>
34 /** Registered root devices */
35 static LIST_HEAD ( devices
);
40 * @v rootdev Root device
41 * @ret rc Return status code
43 static int rootdev_probe ( struct root_device
*rootdev
) {
46 DBG ( "Adding %s root bus\n", rootdev
->dev
.name
);
47 if ( ( rc
= rootdev
->driver
->probe ( rootdev
) ) != 0 ) {
48 DBG ( "Failed to add %s root bus: %s\n",
49 rootdev
->dev
.name
, strerror ( rc
) );
57 * Remove a root device
59 * @v rootdev Root device
61 static void rootdev_remove ( struct root_device
*rootdev
) {
62 rootdev
->driver
->remove ( rootdev
);
63 DBG ( "Removed %s root bus\n", rootdev
->dev
.name
);
69 * This initiates probing for all devices in the system. After this
70 * call, the device hierarchy will be populated, and all hardware
71 * should be ready to use.
73 static void probe_devices ( void ) {
74 struct root_device
*rootdev
;
77 for_each_table_entry ( rootdev
, ROOT_DEVICES
) {
78 list_add ( &rootdev
->dev
.siblings
, &devices
);
79 INIT_LIST_HEAD ( &rootdev
->dev
.children
);
80 if ( ( rc
= rootdev_probe ( rootdev
) ) != 0 )
81 list_del ( &rootdev
->dev
.siblings
);
89 static void remove_devices ( int flags
) {
90 struct root_device
*rootdev
;
91 struct root_device
*tmp
;
93 if ( flags
& SHUTDOWN_KEEP_DEVICES
) {
94 DBG ( "Refusing to remove devices on shutdown\n" );
98 list_for_each_entry_safe ( rootdev
, tmp
, &devices
, dev
.siblings
) {
99 rootdev_remove ( rootdev
);
100 list_del ( &rootdev
->dev
.siblings
);
104 struct startup_fn startup_devices
__startup_fn ( STARTUP_NORMAL
) = {
105 .startup
= probe_devices
,
106 .shutdown
= remove_devices
,