Print this page
7127 remove -Wno-missing-braces from Makefile.uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/avs/ns/nsctl/nsc_power.c
+++ new/usr/src/uts/common/avs/ns/nsctl/nsc_power.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 26 #include <sys/types.h>
27 27 #include <sys/ksynch.h>
28 28 #include <sys/kmem.h>
29 29 #include <sys/file.h>
30 30 #include <sys/errno.h>
31 31 #include <sys/open.h>
32 32 #include <sys/cred.h>
33 33 #include <sys/conf.h>
34 34 #include <sys/uio.h>
35 35 #include <sys/cmn_err.h>
36 36
37 37 #define __NSC_GEN__
38 38 #include "nsc_dev.h"
39 39 #include "nsc_ioctl.h"
40 40 #include "nsc_power.h"
41 41 #include "../nsctl.h"
42 42
43 43 extern nsc_mem_t *_nsc_local_mem;
44 44 static int null_power(void);
45 45
46 46
47 47 typedef struct _nsc_power_s {
48 48 struct _nsc_power_s *next; /* chain */
↓ open down ↓ |
48 lines elided |
↑ open up ↑ |
49 49 char *name; /* module name */
50 50 void (*pw_power_lost)(int); /* callback power lost(rideout) */
51 51 void (*pw_power_ok)(void); /* callback power ok */
52 52 void (*pw_power_down)(void);
53 53 /* callback power down (shutdown imminent) */
54 54 } _nsc_power_t;
55 55
56 56 #define _P(x) (((long)(&((_nsc_power_t *)0)->x))/sizeof (long))
57 57
58 58 static nsc_def_t _nsc_power_def[] = {
59 - "Power_Lost", (uintptr_t)null_power, _P(pw_power_lost),
60 - "Power_OK", (uintptr_t)null_power, _P(pw_power_ok),
61 - "Power_Down", (uintptr_t)null_power, _P(pw_power_down),
62 - 0, 0, 0,
59 + { "Power_Lost", (uintptr_t)null_power, _P(pw_power_lost) },
60 + { "Power_OK", (uintptr_t)null_power, _P(pw_power_ok) },
61 + { "Power_Down", (uintptr_t)null_power, _P(pw_power_down) },
62 + { NULL, (uintptr_t)NULL, 0}
63 63 };
64 64
65 65 static _nsc_power_t *_power_clients;
66 66 static kmutex_t _power_mutex;
67 67
68 68
69 69 static int null_power(void)
70 70 /*
71 71 * init null_power - dummy power routine for clients that choose not
72 72 * to implement all the power hooks.
73 73 *
74 74 */
75 75 {
76 76 return (0);
77 77 }
78 78
79 79 /*
80 80 * int
81 81 * _nsc_power
82 82 * Call registered clients of the generic power ioctls.
83 83 *
84 84 * Calling/Exit State:
85 85 * Calls all the registered clients with a message describing the
86 86 * current state of the power for the system.
87 87 */
88 88 int
89 89 _nsc_power(blind_t argp, int *rvp)
90 90 {
91 91 nsc_power_ctl_t opc;
92 92 _nsc_power_t *pp;
93 93
94 94 *rvp = 0;
95 95 if (copyin((void *) argp, &opc, sizeof (nsc_power_ctl_t)))
96 96 return (EFAULT);
97 97 mutex_enter(&_power_mutex);
98 98
99 99 pp = _power_clients;
100 100 while (pp) {
101 101 switch ((nsc_power_ops_t)opc.msg) {
102 102
103 103 case Power_OK:
104 104 (*pp->pw_power_ok)();
105 105 break;
106 106
107 107 case Power_Down:
108 108 (*pp->pw_power_down)();
109 109 break;
110 110
111 111 case Power_Lost:
112 112 (*pp->pw_power_lost)(opc.arg1);
113 113 break;
114 114
115 115 default:
116 116 mutex_exit(&_power_mutex);
117 117 return (EINVAL);
118 118 }
119 119
120 120 pp = pp->next;
121 121 }
122 122 mutex_exit(&_power_mutex);
123 123 return (0);
124 124 }
125 125
126 126 /*
127 127 * int
128 128 * _nsc_init_power (void)
129 129 * Initialise power ioctl subsystem.
130 130 *
131 131 * Calling/Exit State:
132 132 * Called at driver initialisation time to allocate necessary
133 133 * data structures.
134 134 */
135 135 int
136 136 _nsc_init_power(void)
137 137 {
138 138 mutex_init(&_power_mutex, NULL, MUTEX_DRIVER, NULL);
139 139 return (0);
140 140 }
141 141
142 142 /*
143 143 * int
144 144 * _nsc_deinit_power (void)
145 145 * Initialise power ioctl subsystem.
146 146 *
147 147 * Calling/Exit State:
148 148 * Called at driver initialisation time to allocate necessary
149 149 * data structures.
150 150 */
151 151 int
152 152 _nsc_deinit_power(void)
153 153 {
154 154 _nsc_power_t *pp, *npp;
155 155
156 156 mutex_enter(&_power_mutex);
157 157 pp = _power_clients;
158 158 while (pp) {
159 159 npp = pp->next;
160 160 nsc_kmem_free(pp, sizeof (_nsc_power_t));
161 161 pp = npp;
162 162 }
163 163 _power_clients = NULL;
164 164 mutex_exit(&_power_mutex);
165 165 mutex_destroy(&_power_mutex);
166 166 return (0);
167 167 }
168 168
169 169 /*
170 170 * blind_t
171 171 * nsc_register_power (char *name, nsc_def_t *def)
172 172 * Register an power ioctl client.
173 173 *
174 174 * Calling/Exit State:
175 175 * Returns a token for use in future calls to nsc_unregister_power.
176 176 * If a client with the same name is already registered then NULL
177 177 * is return to indicate failure.
178 178 * If registration fails NULL is returned.
179 179 *
180 180 * Description:
181 181 * Registers an power ioctl client for notifications during subsequent
182 182 * ioctl from UPS/PCU management.
183 183 */
184 184 blind_t
185 185 nsc_register_power(char *name, nsc_def_t *def)
186 186 {
187 187 _nsc_power_t *entry, *pp;
188 188
189 189
190 190 entry = nsc_kmem_alloc(sizeof (_nsc_power_t), 0, _nsc_local_mem);
191 191
192 192 if (entry == NULL)
193 193 return (NULL);
194 194 nsc_decode_param(def, _nsc_power_def, (long *)entry);
195 195
196 196 mutex_enter(&_power_mutex);
197 197
198 198 for (pp = _power_clients; pp; pp = pp->next) {
199 199 if (strcmp(pp->name, name) == 0) {
200 200 mutex_exit(&_power_mutex);
201 201 nsc_kmem_free(entry, sizeof (_nsc_power_t));
202 202 return (NULL);
203 203 }
204 204 }
205 205 entry->name = name;
206 206
207 207 entry->next = _power_clients;
208 208 _power_clients = entry;
209 209 mutex_exit(&_power_mutex);
210 210 return ((blind_t)entry);
211 211 }
212 212
213 213 /*
214 214 * int
215 215 * nsc_unregister_power (blind_t powerp)
216 216 * Un-register a power ioctl client.
217 217 *
218 218 * Calling/Exit State:
219 219 * Returns 0 on success, otherwise returns an error code.
220 220 *
221 221 * Description:
222 222 * The specified power ioctl client is un-registered if possible.
223 223 * Zero is returned on success otherwise an error code.
224 224 */
225 225 int
226 226 nsc_unregister_power(blind_t powerp)
227 227 {
228 228 _nsc_power_t **xpp, *entry;
229 229
230 230 entry = (_nsc_power_t *)powerp;
231 231 if (entry == NULL)
232 232 return (EINVAL);
233 233
234 234 mutex_enter(&_power_mutex);
235 235
236 236 for (xpp = &_power_clients; *xpp; xpp = &(*xpp)->next)
237 237 if (*xpp == entry)
238 238 break;
239 239
240 240 if (*xpp == NULL) {
241 241 mutex_exit(&_power_mutex);
242 242 return (EALREADY);
243 243 }
244 244 *xpp = entry->next;
245 245 mutex_exit(&_power_mutex);
246 246 nsc_kmem_free(entry, sizeof (_nsc_power_t));
247 247
248 248 return (0);
249 249 }
↓ open down ↓ |
177 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX