Adding debian version 3.70~pre8+dfsg-1.
[syslinux-debian/hramrach.git] / gpxe / src / core / device.c
blobb1b148e853746765e17d0d906902a6a2e6c35666
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>
24 /**
25 * @file
27 * Device model
31 static struct root_device root_devices[0]
32 __table_start ( struct root_device, root_devices );
33 static struct root_device root_devices_end[0]
34 __table_end ( struct root_device, root_devices );
36 /** Registered root devices */
37 static LIST_HEAD ( devices );
39 /**
40 * Probe a root device
42 * @v rootdev Root device
43 * @ret rc Return status code
45 static int rootdev_probe ( struct root_device *rootdev ) {
46 int rc;
48 DBG ( "Adding %s root bus\n", rootdev->dev.name );
49 if ( ( rc = rootdev->driver->probe ( rootdev ) ) != 0 ) {
50 DBG ( "Failed to add %s root bus: %s\n",
51 rootdev->dev.name, strerror ( rc ) );
52 return rc;
55 return 0;
58 /**
59 * Remove a root device
61 * @v rootdev Root device
63 static void rootdev_remove ( struct root_device *rootdev ) {
64 rootdev->driver->remove ( rootdev );
65 DBG ( "Removed %s root bus\n", rootdev->dev.name );
68 /**
69 * Probe all devices
71 * @ret rc Return status code
73 * This initiates probing for all devices in the system. After this
74 * call, the device hierarchy will be populated, and all hardware
75 * should be ready to use.
77 int probe_devices ( void ) {
78 struct root_device *rootdev;
79 int rc;
81 for ( rootdev = root_devices; rootdev < root_devices_end; rootdev++ ) {
82 list_add ( &rootdev->dev.siblings, &devices );
83 INIT_LIST_HEAD ( &rootdev->dev.children );
84 if ( ( rc = rootdev_probe ( rootdev ) ) != 0 )
85 list_del ( &rootdev->dev.siblings );
87 return 0;
90 /**
91 * Remove all devices
94 void remove_devices ( void ) {
95 struct root_device *rootdev;
96 struct root_device *tmp;
98 list_for_each_entry_safe ( rootdev, tmp, &devices, dev.siblings ) {
99 rootdev_remove ( rootdev );
100 list_del ( &rootdev->dev.siblings );