[release] Update version to 0.9.5+ post release
[gpxe.git] / src / core / device.c
blob84915c2daf153f136d86d2d45c09bbf5a57e4ad8
1 /*
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 #include <string.h>
20 #include <gpxe/list.h>
21 #include <gpxe/tables.h>
22 #include <gpxe/device.h>
23 #include <gpxe/init.h>
25 /**
26 * @file
28 * Device model
32 static struct root_device root_devices[0]
33 __table_start ( struct root_device, root_devices );
34 static struct root_device root_devices_end[0]
35 __table_end ( struct root_device, root_devices );
37 /** Registered root devices */
38 static LIST_HEAD ( devices );
40 /**
41 * Probe a root device
43 * @v rootdev Root device
44 * @ret rc Return status code
46 static int rootdev_probe ( struct root_device *rootdev ) {
47 int rc;
49 DBG ( "Adding %s root bus\n", rootdev->dev.name );
50 if ( ( rc = rootdev->driver->probe ( rootdev ) ) != 0 ) {
51 DBG ( "Failed to add %s root bus: %s\n",
52 rootdev->dev.name, strerror ( rc ) );
53 return rc;
56 return 0;
59 /**
60 * Remove a root device
62 * @v rootdev Root device
64 static void rootdev_remove ( struct root_device *rootdev ) {
65 rootdev->driver->remove ( rootdev );
66 DBG ( "Removed %s root bus\n", rootdev->dev.name );
69 /**
70 * Probe all devices
72 * This initiates probing for all devices in the system. After this
73 * call, the device hierarchy will be populated, and all hardware
74 * should be ready to use.
76 static void probe_devices ( void ) {
77 struct root_device *rootdev;
78 int rc;
80 for ( rootdev = root_devices; rootdev < root_devices_end; rootdev++ ) {
81 list_add ( &rootdev->dev.siblings, &devices );
82 INIT_LIST_HEAD ( &rootdev->dev.children );
83 if ( ( rc = rootdev_probe ( rootdev ) ) != 0 )
84 list_del ( &rootdev->dev.siblings );
88 /**
89 * Remove all devices
92 static void remove_devices ( int flags ) {
93 struct root_device *rootdev;
94 struct root_device *tmp;
96 if ( flags & SHUTDOWN_KEEP_DEVICES ) {
97 DBG ( "Refusing to remove devices on shutdown\n" );
98 return;
101 list_for_each_entry_safe ( rootdev, tmp, &devices, dev.siblings ) {
102 rootdev_remove ( rootdev );
103 list_del ( &rootdev->dev.siblings );
107 struct startup_fn startup_devices __startup_fn ( STARTUP_NORMAL ) = {
108 .startup = probe_devices,
109 .shutdown = remove_devices,