|
@@ -0,0 +1,97 @@
|
|
1
|
+/*
|
|
2
|
+ * Copyright (C) 2006 Michael Brown <mbrown@fensystems.co.uk>.
|
|
3
|
+ *
|
|
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.
|
|
8
|
+ *
|
|
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.
|
|
13
|
+ *
|
|
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.
|
|
17
|
+ */
|
|
18
|
+
|
|
19
|
+#include <gpxe/list.h>
|
|
20
|
+#include <gpxe/tables.h>
|
|
21
|
+#include <gpxe/device.h>
|
|
22
|
+
|
|
23
|
+/**
|
|
24
|
+ * @file
|
|
25
|
+ *
|
|
26
|
+ * Device model
|
|
27
|
+ *
|
|
28
|
+ */
|
|
29
|
+
|
|
30
|
+static struct root_device root_devices[0] __table_start ( root_devices );
|
|
31
|
+static struct root_device root_devices_end[0] __table_end ( root_devices );
|
|
32
|
+
|
|
33
|
+/** Registered root devices */
|
|
34
|
+static LIST_HEAD ( devices );
|
|
35
|
+
|
|
36
|
+/**
|
|
37
|
+ * Register a root device
|
|
38
|
+ *
|
|
39
|
+ * @v rootdev Root device
|
|
40
|
+ * @ret rc Return status code
|
|
41
|
+ *
|
|
42
|
+ * Calls the root device driver's probe() method, and adds it to the
|
|
43
|
+ * list of registered root devices if successful.
|
|
44
|
+ */
|
|
45
|
+static int register_rootdev ( struct root_device *rootdev ) {
|
|
46
|
+ int rc;
|
|
47
|
+
|
|
48
|
+ DBG ( "Registering %s root bus\n", rootdev->name );
|
|
49
|
+
|
|
50
|
+ if ( ( rc = rootdev->driver->probe ( rootdev ) ) != 0 )
|
|
51
|
+ return rc;
|
|
52
|
+
|
|
53
|
+ list_add ( &rootdev->dev.siblings, &devices );
|
|
54
|
+ return 0;
|
|
55
|
+}
|
|
56
|
+
|
|
57
|
+/**
|
|
58
|
+ * Unregister a root device
|
|
59
|
+ *
|
|
60
|
+ * @v rootdev Root device
|
|
61
|
+ */
|
|
62
|
+static void unregister_rootdev ( struct root_device *rootdev ) {
|
|
63
|
+ rootdev->driver->remove ( rootdev );
|
|
64
|
+ list_del ( &rootdev->dev.siblings );
|
|
65
|
+ DBG ( "Unregistered %s root bus\n", rootdev->name );
|
|
66
|
+}
|
|
67
|
+
|
|
68
|
+/**
|
|
69
|
+ * Probe all devices
|
|
70
|
+ *
|
|
71
|
+ * @ret rc Return status code
|
|
72
|
+ *
|
|
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.
|
|
76
|
+ */
|
|
77
|
+int probe_devices ( void ) {
|
|
78
|
+ struct root_device *rootdev;
|
|
79
|
+
|
|
80
|
+ for ( rootdev = root_devices; rootdev < root_devices_end; rootdev++ ) {
|
|
81
|
+ register_rootdev ( rootdev );
|
|
82
|
+ }
|
|
83
|
+ return 0;
|
|
84
|
+}
|
|
85
|
+
|
|
86
|
+/**
|
|
87
|
+ * Remove all devices
|
|
88
|
+ *
|
|
89
|
+ */
|
|
90
|
+void remove_devices ( void ) {
|
|
91
|
+ struct root_device *rootdev;
|
|
92
|
+ struct root_device *tmp;
|
|
93
|
+
|
|
94
|
+ list_for_each_entry_safe ( rootdev, tmp, &devices, dev.siblings ) {
|
|
95
|
+ unregister_rootdev ( rootdev );
|
|
96
|
+ }
|
|
97
|
+}
|