root / prex-0.9.0 / bsp / drv / dev / base / init.c @ 03e9c04a
History | View | Annotate | Download (3.47 KB)
1 | 03e9c04a | Brad Neuman | /*-
|
---|---|---|---|
2 | * Copyright (c) 2005-2009, Kohsuke Ohtani
|
||
3 | * All rights reserved.
|
||
4 | *
|
||
5 | * Redistribution and use in source and binary forms, with or without
|
||
6 | * modification, are permitted provided that the following conditions
|
||
7 | * are met:
|
||
8 | * 1. Redistributions of source code must retain the above copyright
|
||
9 | * notice, this list of conditions and the following disclaimer.
|
||
10 | * 2. Redistributions in binary form must reproduce the above copyright
|
||
11 | * notice, this list of conditions and the following disclaimer in the
|
||
12 | * documentation and/or other materials provided with the distribution.
|
||
13 | * 3. Neither the name of the author nor the names of any co-contributors
|
||
14 | * may be used to endorse or promote products derived from this software
|
||
15 | * without specific prior written permission.
|
||
16 | *
|
||
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||
18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||
19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||
20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||
21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||
22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||
23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||
24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||
25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||
26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||
27 | * SUCH DAMAGE.
|
||
28 | */
|
||
29 | |||
30 | /*
|
||
31 | * init.c - driver initialization routine
|
||
32 | */
|
||
33 | |||
34 | #include <driver.h> |
||
35 | #include <cons.h> |
||
36 | #include <dki.h> |
||
37 | #include <kd.h> |
||
38 | #include <conf/drvtab.h> |
||
39 | |||
40 | #ifdef DEBUG
|
||
41 | #define DPRINTF(a) printf a
|
||
42 | #else
|
||
43 | #define DPRINTF(a)
|
||
44 | #endif
|
||
45 | |||
46 | #define NDRIVERS (int)(sizeof(driver_table) / sizeof(driver_table[0])) |
||
47 | |||
48 | |||
49 | /*
|
||
50 | * Call xxx_probe routine for all drivers.
|
||
51 | */
|
||
52 | void
|
||
53 | driver_probe(void)
|
||
54 | { |
||
55 | struct driver *dp;
|
||
56 | int i;
|
||
57 | |||
58 | DPRINTF(("Probing devices...\n"));
|
||
59 | |||
60 | for (i = 0; i < NDRIVERS; i++) { |
||
61 | dp = driver_table[i]; |
||
62 | ASSERT(dp != NULL);
|
||
63 | |||
64 | if (dp->probe != NULL) { |
||
65 | if (dp->probe(dp) == 0) |
||
66 | dp->flags |= DS_ALIVE; |
||
67 | } else {
|
||
68 | /*
|
||
69 | * No probe method. Mark it alive.
|
||
70 | */
|
||
71 | dp->flags |= DS_ALIVE; |
||
72 | } |
||
73 | } |
||
74 | } |
||
75 | |||
76 | /*
|
||
77 | * Call xxx_init routine for all living drivers.
|
||
78 | */
|
||
79 | void
|
||
80 | driver_init(void)
|
||
81 | { |
||
82 | struct driver *dp;
|
||
83 | int i;
|
||
84 | |||
85 | for (i = 0; i < NDRIVERS; i++) { |
||
86 | dp = driver_table[i]; |
||
87 | |||
88 | /* All drivers must have init method */
|
||
89 | ASSERT(dp->init != NULL);
|
||
90 | |||
91 | if (dp->flags & DS_ALIVE) {
|
||
92 | DPRINTF(("Initializing %s\n", dp->name));
|
||
93 | if (dp->init(dp) == 0) |
||
94 | dp->flags |= DS_ACTIVE; |
||
95 | } |
||
96 | } |
||
97 | } |
||
98 | |||
99 | /*
|
||
100 | * Call xxx_unload routine for all active drivers.
|
||
101 | */
|
||
102 | void
|
||
103 | driver_shutdown(void)
|
||
104 | { |
||
105 | struct driver *dp;
|
||
106 | int i;
|
||
107 | |||
108 | DPRINTF(("Shutting down...\n"));
|
||
109 | for (i = NDRIVERS - 1; i >= 0; i--) { |
||
110 | dp = driver_table[i]; |
||
111 | if (dp == NULL) |
||
112 | break;
|
||
113 | /*
|
||
114 | * Process only active drivers.
|
||
115 | */
|
||
116 | if (dp->flags & DS_ACTIVE) {
|
||
117 | DPRINTF(("Unloading %s\n", dp->name));
|
||
118 | if (dp->unload != NULL) |
||
119 | dp->unload(dp); |
||
120 | } |
||
121 | } |
||
122 | } |
||
123 | |||
124 | #if defined(DEBUG) && defined(CONFIG_KD)
|
||
125 | void
|
||
126 | driver_dump(void)
|
||
127 | { |
||
128 | struct driver *dp;
|
||
129 | int i = 0; |
||
130 | |||
131 | printf("Driver table:\n");
|
||
132 | printf(" probe init unload devops flags name\n");
|
||
133 | printf(" -------- -------- -------- -------- -------- -----------\n");
|
||
134 | |||
135 | for (i = 0; i < NDRIVERS; i++) { |
||
136 | dp = driver_table[i]; |
||
137 | printf(" %08lx %08lx %08lx %08lx %08lx %s\n",
|
||
138 | (long)dp->probe, (long)dp->init, (long)dp->unload, |
||
139 | (long)dp->devops,(long) dp->flags, dp->name); |
||
140 | } |
||
141 | } |
||
142 | #endif |