Deleted Added
full compact
acpi_battery.c (143771) acpi_battery.c (148352)
1/*-
1/*-
2 * Copyright (c) 2005 Nate Lawson
2 * Copyright (c) 2000 Mitsuru IWASAKI <iwasaki@jp.freebsd.org>
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 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
3 * Copyright (c) 2000 Mitsuru IWASAKI <iwasaki@jp.freebsd.org>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.

--- 10 unchanged lines hidden (view full) ---

21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/dev/acpica/acpi_battery.c 143771 2005-03-17 22:42:49Z njl $");
29__FBSDID("$FreeBSD: head/sys/dev/acpica/acpi_battery.c 148352 2005-07-23 19:36:00Z njl $");
29
30#include "opt_acpi.h"
31#include <sys/param.h>
32#include <sys/kernel.h>
33#include <sys/malloc.h>
34#include <sys/bus.h>
35#include <sys/ioccom.h>
36#include <sys/sysctl.h>
37
38#include "acpi.h"
39#include <dev/acpica/acpivar.h>
40#include <dev/acpica/acpiio.h>
41
30
31#include "opt_acpi.h"
32#include <sys/param.h>
33#include <sys/kernel.h>
34#include <sys/malloc.h>
35#include <sys/bus.h>
36#include <sys/ioccom.h>
37#include <sys/sysctl.h>
38
39#include "acpi.h"
40#include <dev/acpica/acpivar.h>
41#include <dev/acpica/acpiio.h>
42
42MALLOC_DEFINE(M_ACPIBATT, "acpibatt", "ACPI generic battery data");
43/* Default seconds before re-sampling the battery state. */
44#define ACPI_BATTERY_INFO_EXPIRE 5
43
45
44struct acpi_batteries {
45 TAILQ_ENTRY(acpi_batteries) link;
46 struct acpi_battdesc battdesc;
47};
46static int acpi_batteries_initted;
47static int acpi_battery_info_expire = ACPI_BATTERY_INFO_EXPIRE;
48static struct acpi_battinfo acpi_battery_battinfo;
49static struct sysctl_ctx_list acpi_battery_sysctl_ctx;
50static struct sysctl_oid *acpi_battery_sysctl_tree;
48
51
49static TAILQ_HEAD(,acpi_batteries) acpi_batteries;
50static int acpi_batteries_initted;
51static int acpi_batteries_units;
52static int acpi_battery_info_expire = 5;
53static struct acpi_battinfo acpi_battery_battinfo;
54ACPI_SERIAL_DECL(battery, "ACPI generic battery");
55
52ACPI_SERIAL_DECL(battery, "ACPI generic battery");
53
54static void acpi_reset_battinfo(struct acpi_battinfo *info);
55static int acpi_battery_ioctl(u_long cmd, caddr_t addr, void *arg);
56static int acpi_battery_sysctl(SYSCTL_HANDLER_ARGS);
57static int acpi_battery_units_sysctl(SYSCTL_HANDLER_ARGS);
58static int acpi_battery_init(void);
59
56int
60int
57acpi_battery_get_info_expire(void)
61acpi_battery_register(device_t dev)
58{
62{
59 return (acpi_battery_info_expire);
63 int error;
64
65 error = 0;
66 ACPI_SERIAL_BEGIN(battery);
67 if (!acpi_batteries_initted)
68 error = acpi_battery_init();
69 ACPI_SERIAL_END(battery);
70 return (error);
60}
61
62int
71}
72
73int
74acpi_battery_remove(device_t dev)
75{
76
77 return (0);
78}
79
80int
63acpi_battery_get_units(void)
64{
81acpi_battery_get_units(void)
82{
65 return (acpi_batteries_units);
83 devclass_t batt_dc;
84
85 batt_dc = devclass_find("battery");
86 if (batt_dc == NULL)
87 return (0);
88 return (devclass_get_count(batt_dc));
66}
67
68int
89}
90
91int
69acpi_battery_get_battdesc(int unit, struct acpi_battdesc *battdesc)
92acpi_battery_get_info_expire(void)
70{
93{
71 struct acpi_batteries *bp;
72 int error, i;
73
94
74 error = ENXIO;
75 ACPI_SERIAL_BEGIN(battery);
76 if (unit < 0 || unit >= acpi_batteries_units)
77 goto out;
95 return (acpi_battery_info_expire);
96}
78
97
79 i = 0;
80 TAILQ_FOREACH(bp, &acpi_batteries, link) {
81 if (unit == i) {
82 battdesc->type = bp->battdesc.type;
83 battdesc->phys_unit = bp->battdesc.phys_unit;
84 error = 0;
85 break;
86 }
87 i++;
88 }
98/* Check _BST results for validity. */
99int
100acpi_battery_bst_valid(struct acpi_bst *bst)
101{
102 if (bst->state >= ACPI_BATT_STAT_MAX || bst->cap == 0xffffffff ||
103 bst->volt == 0xffffffff)
104 return (FALSE);
105 else
106 return (TRUE);
107}
89
108
90out:
91 ACPI_SERIAL_END(battery);
92 return (error);
109/* Check _BIF results for validity. */
110int
111acpi_battery_bif_valid(struct acpi_bif *bif)
112{
113 if (bif->lfcap == 0)
114 return (FALSE);
115 else
116 return (TRUE);
93}
94
117}
118
119/* Get info about one or all batteries. */
95int
120int
96acpi_battery_get_battinfo(int unit, struct acpi_battinfo *battinfo)
121acpi_battery_get_battinfo(device_t dev, struct acpi_battinfo *battinfo)
97{
122{
98 struct acpi_battdesc battdesc;
99 int error;
123 int batt_stat, devcount, dev_idx, error, i;
124 int total_cap, total_min, valid_rate, valid_units;
125 devclass_t batt_dc;
126 device_t batt_dev;
127 struct acpi_bst *bst;
128 struct acpi_bif *bif;
129 struct acpi_battinfo *bi;
100
130
101 error = 0;
102 if (unit == -1) {
103 error = acpi_cmbat_get_battinfo(-1, battinfo);
104 goto out;
105 } else {
106 error = acpi_battery_get_battdesc(unit, &battdesc);
107 if (error != 0)
108 goto out;
131 /*
132 * Get the battery devclass and number of devices. If there are none
133 * or error, return immediately.
134 */
135 batt_dc = devclass_find("battery");
136 if (batt_dc == NULL)
137 return (ENXIO);
138 devcount = devclass_get_count(batt_dc);
139 if (devcount == 0)
140 return (ENXIO);
109
141
110 switch (battdesc.type) {
111 case ACPI_BATT_TYPE_CMBAT:
112 error = acpi_cmbat_get_battinfo(battdesc.phys_unit, battinfo);
113 break;
114 default:
115 error = ENXIO;
116 break;
142 /*
143 * Allocate storage for all _BST data, their derived battinfo data,
144 * and the current battery's _BIF data.
145 */
146 bst = malloc(devcount * sizeof(*bst), M_TEMP, M_WAITOK);
147 bi = malloc(devcount * sizeof(*bi), M_TEMP, M_WAITOK);
148 bif = malloc(sizeof(*bif), M_TEMP, M_WAITOK);
149
150 /*
151 * Pass 1: for each battery that is present and valid, get its status,
152 * calculate percent capacity remaining, and sum all the current
153 * discharge rates.
154 */
155 dev_idx = -1;
156 batt_stat = valid_rate = valid_units = 0;
157 for (i = 0; i < devcount; i++) {
158 /* Find the device. If it disappeared, the user can try again. */
159 batt_dev = devclass_get_device(batt_dc, i);
160 if (batt_dev == NULL) {
161 error = ENOMEM;
162 goto out;
117 }
163 }
164
165 /* Default info for every battery is "not present". */
166 acpi_reset_battinfo(&bi[i]);
167
168 /* If examining a specific battery and this is it, record its index. */
169 if (dev != NULL && dev == batt_dev)
170 dev_idx = i;
171
172 /* Be sure we can get various info from the battery. */
173 if (!acpi_BatteryIsPresent(batt_dev) ||
174 ACPI_BATT_GET_STATUS(batt_dev, &bst[i]) != 0 ||
175 ACPI_BATT_GET_INFO(batt_dev, bif) != 0)
176 continue;
177
178 /* If a battery is not installed, we sometimes get strange values. */
179 if (!acpi_battery_bst_valid(&bst[i]) ||
180 !acpi_battery_bif_valid(bif))
181 continue;
182
183 /* Record state and calculate percent capacity remaining. */
184 valid_units++;
185 batt_stat |= bst[i].state;
186 bi[i].state = bst[i].state;
187 bi[i].cap = 100 * bst[i].cap / bif->lfcap;
188
189 /*
190 * Some laptops report the "design-capacity" instead of the
191 * "real-capacity" when the battery is fully charged. That breaks
192 * the above arithmetic as it needs to be 100% maximum.
193 */
194 if (bi[i].cap > 100)
195 bi[i].cap = 100;
196
197 /*
198 * On systems with more than one battery, they may get used
199 * sequentially, thus bst.rate may only signify the one currently
200 * in use. For the remaining batteries, bst.rate will be zero,
201 * which makes it impossible to calculate the total remaining time.
202 * Therefore, we sum the bst.rate for batteries in the discharging
203 * state and use the sum to calculate the total remaining time.
204 */
205 if (bst[i].rate > 0 && (bst[i].state & ACPI_BATT_STAT_DISCHARG))
206 valid_rate += bst[i].rate;
118 }
119
207 }
208
209 /* If the caller asked for a device but we didn't find it, error. */
210 if (dev != NULL && dev_idx < 0) {
211 error = ENXIO;
212 goto out;
213 }
214
215 /* Pass 2: calculate capacity and remaining time for all batteries. */
216 total_cap = total_min = 0;
217 for (i = 0; i < devcount; i++) {
218 /*
219 * If any batteries are discharging, use the sum of the bst.rate
220 * values. Otherwise, we are on AC power, and there is infinite
221 * time remaining for this battery until we go offline.
222 */
223 if (valid_rate > 0)
224 bi[i].min = 60 * bst[i].cap / valid_rate;
225 else
226 bi[i].min = 0;
227 total_min += bi[i].min;
228 total_cap += bi[i].cap;
229 }
230
231 /*
232 * Return total battery percent and time remaining. If there are
233 * no valid batteries, report values as unknown.
234 */
235 if (valid_units > 0) {
236 if (dev == NULL) {
237 battinfo->cap = total_cap / valid_units;
238 battinfo->min = total_min;
239 battinfo->state = batt_stat;
240 battinfo->rate = valid_rate;
241 } else {
242 battinfo->cap = bi[dev_idx].cap;
243 battinfo->min = bi[dev_idx].min;
244 battinfo->state = bi[dev_idx].state;
245 battinfo->rate = bst[dev_idx].rate;
246 }
247 } else
248 acpi_reset_battinfo(battinfo);
249
250 error = 0;
251
120out:
252out:
253 if (bi)
254 free(bi, M_TEMP);
255 if (bif)
256 free(bif, M_TEMP);
257 if (bst)
258 free(bst, M_TEMP);
121 return (error);
122}
123
259 return (error);
260}
261
262static void
263acpi_reset_battinfo(struct acpi_battinfo *info)
264{
265 info->cap = -1;
266 info->min = -1;
267 info->state = ACPI_BATT_STAT_NOT_PRESENT;
268 info->rate = -1;
269}
270
124static int
125acpi_battery_ioctl(u_long cmd, caddr_t addr, void *arg)
126{
127 union acpi_battery_ioctl_arg *ioctl_arg;
128 int error, unit;
271static int
272acpi_battery_ioctl(u_long cmd, caddr_t addr, void *arg)
273{
274 union acpi_battery_ioctl_arg *ioctl_arg;
275 int error, unit;
276 device_t dev;
129
277
278 error = ENXIO;
130 ioctl_arg = (union acpi_battery_ioctl_arg *)addr;
279 ioctl_arg = (union acpi_battery_ioctl_arg *)addr;
131 error = 0;
280 unit = ioctl_arg->unit;
281 if (unit != ACPI_BATTERY_ALL_UNITS)
282 dev = devclass_get_device(devclass_find("battery"), unit);
283 else
284 dev = NULL;
132
133 /*
134 * No security check required: information retrieval only. If
135 * new functions are added here, a check might be required.
136 */
137 switch (cmd) {
138 case ACPIIO_BATT_GET_UNITS:
139 *(int *)addr = acpi_battery_get_units();
140 break;
285
286 /*
287 * No security check required: information retrieval only. If
288 * new functions are added here, a check might be required.
289 */
290 switch (cmd) {
291 case ACPIIO_BATT_GET_UNITS:
292 *(int *)addr = acpi_battery_get_units();
293 break;
141 case ACPIIO_BATT_GET_BATTDESC:
142 unit = ioctl_arg->unit;
143 error = acpi_battery_get_battdesc(unit, &ioctl_arg->battdesc);
144 break;
145 case ACPIIO_BATT_GET_BATTINFO:
294 case ACPIIO_BATT_GET_BATTINFO:
146 unit = ioctl_arg->unit;
147 error = acpi_battery_get_battinfo(unit, &ioctl_arg->battinfo);
295 if (dev != NULL || unit == ACPI_BATTERY_ALL_UNITS)
296 error = acpi_battery_get_battinfo(dev, &ioctl_arg->battinfo);
148 break;
297 break;
298 case ACPIIO_BATT_GET_BIF:
299 if (dev != NULL)
300 error = ACPI_BATT_GET_INFO(dev, &ioctl_arg->bif);
301 break;
302 case ACPIIO_BATT_GET_BST:
303 if (dev != NULL)
304 error = ACPI_BATT_GET_STATUS(dev, &ioctl_arg->bst);
305 break;
149 default:
150 error = EINVAL;
306 default:
307 error = EINVAL;
151 break;
152 }
153
154 return (error);
155}
156
157static int
158acpi_battery_sysctl(SYSCTL_HANDLER_ARGS)
159{
160 int val, error;
161
308 }
309
310 return (error);
311}
312
313static int
314acpi_battery_sysctl(SYSCTL_HANDLER_ARGS)
315{
316 int val, error;
317
162 acpi_battery_get_battinfo(-1, &acpi_battery_battinfo);
318 acpi_battery_get_battinfo(NULL, &acpi_battery_battinfo);
163 val = *(u_int *)oidp->oid_arg1;
164 error = sysctl_handle_int(oidp, &val, 0, req);
165 return (error);
166}
167
168static int
319 val = *(u_int *)oidp->oid_arg1;
320 error = sysctl_handle_int(oidp, &val, 0, req);
321 return (error);
322}
323
324static int
325acpi_battery_units_sysctl(SYSCTL_HANDLER_ARGS)
326{
327 int count, error;
328
329 count = acpi_battery_get_units();
330 error = sysctl_handle_int(oidp, &count, 0, req);
331 return (error);
332}
333
334static int
169acpi_battery_init(void)
170{
171 struct acpi_softc *sc;
172 device_t dev;
173 int error;
174
175 ACPI_SERIAL_ASSERT(battery);
176
177 error = ENXIO;
178 dev = devclass_get_device(devclass_find("acpi"), 0);
179 if (dev == NULL)
180 goto out;
181 sc = device_get_softc(dev);
182
335acpi_battery_init(void)
336{
337 struct acpi_softc *sc;
338 device_t dev;
339 int error;
340
341 ACPI_SERIAL_ASSERT(battery);
342
343 error = ENXIO;
344 dev = devclass_get_device(devclass_find("acpi"), 0);
345 if (dev == NULL)
346 goto out;
347 sc = device_get_softc(dev);
348
183 TAILQ_INIT(&acpi_batteries);
184
185 /* XXX We should back out registered ioctls on error. */
186 error = acpi_register_ioctl(ACPIIO_BATT_GET_UNITS, acpi_battery_ioctl,
187 NULL);
188 if (error != 0)
189 goto out;
349 error = acpi_register_ioctl(ACPIIO_BATT_GET_UNITS, acpi_battery_ioctl,
350 NULL);
351 if (error != 0)
352 goto out;
190 error = acpi_register_ioctl(ACPIIO_BATT_GET_BATTDESC, acpi_battery_ioctl,
353 error = acpi_register_ioctl(ACPIIO_BATT_GET_BATTINFO, acpi_battery_ioctl,
191 NULL);
192 if (error != 0)
193 goto out;
354 NULL);
355 if (error != 0)
356 goto out;
194 error = acpi_register_ioctl(ACPIIO_BATT_GET_BATTINFO, acpi_battery_ioctl,
195 NULL);
357 error = acpi_register_ioctl(ACPIIO_BATT_GET_BIF, acpi_battery_ioctl, NULL);
196 if (error != 0)
197 goto out;
358 if (error != 0)
359 goto out;
360 error = acpi_register_ioctl(ACPIIO_BATT_GET_BST, acpi_battery_ioctl, NULL);
361 if (error != 0)
362 goto out;
198
363
199 sysctl_ctx_init(&sc->acpi_battery_sysctl_ctx);
200 sc->acpi_battery_sysctl_tree = SYSCTL_ADD_NODE(&sc->acpi_battery_sysctl_ctx,
364 sysctl_ctx_init(&acpi_battery_sysctl_ctx);
365 acpi_battery_sysctl_tree = SYSCTL_ADD_NODE(&acpi_battery_sysctl_ctx,
201 SYSCTL_CHILDREN(sc->acpi_sysctl_tree), OID_AUTO, "battery", CTLFLAG_RD,
202 0, "");
366 SYSCTL_CHILDREN(sc->acpi_sysctl_tree), OID_AUTO, "battery", CTLFLAG_RD,
367 0, "");
203 SYSCTL_ADD_PROC(&sc->acpi_battery_sysctl_ctx,
204 SYSCTL_CHILDREN(sc->acpi_battery_sysctl_tree),
368 SYSCTL_ADD_PROC(&acpi_battery_sysctl_ctx,
369 SYSCTL_CHILDREN(acpi_battery_sysctl_tree),
205 OID_AUTO, "life", CTLTYPE_INT | CTLFLAG_RD,
206 &acpi_battery_battinfo.cap, 0, acpi_battery_sysctl, "I", "");
370 OID_AUTO, "life", CTLTYPE_INT | CTLFLAG_RD,
371 &acpi_battery_battinfo.cap, 0, acpi_battery_sysctl, "I", "");
207 SYSCTL_ADD_PROC(&sc->acpi_battery_sysctl_ctx,
208 SYSCTL_CHILDREN(sc->acpi_battery_sysctl_tree),
372 SYSCTL_ADD_PROC(&acpi_battery_sysctl_ctx,
373 SYSCTL_CHILDREN(acpi_battery_sysctl_tree),
209 OID_AUTO, "time", CTLTYPE_INT | CTLFLAG_RD,
210 &acpi_battery_battinfo.min, 0, acpi_battery_sysctl, "I", "");
374 OID_AUTO, "time", CTLTYPE_INT | CTLFLAG_RD,
375 &acpi_battery_battinfo.min, 0, acpi_battery_sysctl, "I", "");
211 SYSCTL_ADD_PROC(&sc->acpi_battery_sysctl_ctx,
212 SYSCTL_CHILDREN(sc->acpi_battery_sysctl_tree),
376 SYSCTL_ADD_PROC(&acpi_battery_sysctl_ctx,
377 SYSCTL_CHILDREN(acpi_battery_sysctl_tree),
213 OID_AUTO, "state", CTLTYPE_INT | CTLFLAG_RD,
214 &acpi_battery_battinfo.state, 0, acpi_battery_sysctl, "I", "");
378 OID_AUTO, "state", CTLTYPE_INT | CTLFLAG_RD,
379 &acpi_battery_battinfo.state, 0, acpi_battery_sysctl, "I", "");
215 SYSCTL_ADD_INT(&sc->acpi_battery_sysctl_ctx,
216 SYSCTL_CHILDREN(sc->acpi_battery_sysctl_tree),
217 OID_AUTO, "units", CTLFLAG_RD, &acpi_batteries_units, 0, "");
218 SYSCTL_ADD_INT(&sc->acpi_battery_sysctl_ctx,
219 SYSCTL_CHILDREN(sc->acpi_battery_sysctl_tree),
380 SYSCTL_ADD_PROC(&acpi_battery_sysctl_ctx,
381 SYSCTL_CHILDREN(acpi_battery_sysctl_tree),
382 OID_AUTO, "units", CTLTYPE_INT | CTLFLAG_RD,
383 NULL, 0, acpi_battery_units_sysctl, "I", "");
384 SYSCTL_ADD_INT(&acpi_battery_sysctl_ctx,
385 SYSCTL_CHILDREN(acpi_battery_sysctl_tree),
220 OID_AUTO, "info_expire", CTLFLAG_RD | CTLFLAG_RW,
221 &acpi_battery_info_expire, 0, "");
222
223 acpi_batteries_initted = TRUE;
224
225out:
386 OID_AUTO, "info_expire", CTLFLAG_RD | CTLFLAG_RW,
387 &acpi_battery_info_expire, 0, "");
388
389 acpi_batteries_initted = TRUE;
390
391out:
226 return (error);
227}
228
229int
230acpi_battery_register(int type, int phys_unit)
231{
232 struct acpi_batteries *bp;
233 int error;
234
235 error = 0;
236 bp = malloc(sizeof(*bp), M_ACPIBATT, M_NOWAIT);
237 if (bp == NULL)
238 return (ENOMEM);
239
240 ACPI_SERIAL_BEGIN(battery);
241 if (!acpi_batteries_initted && (error = acpi_battery_init()) != 0) {
242 printf("acpi_battery_register failed for unit %d\n", phys_unit);
243 goto out;
392 if (error != 0) {
393 acpi_deregister_ioctl(ACPIIO_BATT_GET_UNITS, acpi_battery_ioctl);
394 acpi_deregister_ioctl(ACPIIO_BATT_GET_BATTINFO, acpi_battery_ioctl);
395 acpi_deregister_ioctl(ACPIIO_BATT_GET_BIF, acpi_battery_ioctl);
396 acpi_deregister_ioctl(ACPIIO_BATT_GET_BST, acpi_battery_ioctl);
244 }
397 }
245 bp->battdesc.type = type;
246 bp->battdesc.phys_unit = phys_unit;
247 TAILQ_INSERT_TAIL(&acpi_batteries, bp, link);
248 acpi_batteries_units++;
249
250out:
251 ACPI_SERIAL_END(battery);
252 if (error)
253 free(bp, M_ACPIBATT);
254 return (error);
255}
398 return (error);
399}
256
257int
258acpi_battery_remove(int type, int phys_unit)
259{
260 struct acpi_batteries *bp, *tmp;
261 int ret;
262
263 ret = ENOENT;
264 ACPI_SERIAL_BEGIN(battery);
265 TAILQ_FOREACH_SAFE(bp, &acpi_batteries, link, tmp) {
266 if (bp->battdesc.type == type && bp->battdesc.phys_unit == phys_unit) {
267 TAILQ_REMOVE(&acpi_batteries, bp, link);
268 acpi_batteries_units--;
269 ret = 0;
270 break;
271 }
272 }
273 ACPI_SERIAL_END(battery);
274 if (ret == 0)
275 free(bp, M_ACPIBATT);
276 return (ret);
277}