Print this page
PANKOVs restructure
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/i86pc/io/tzmon/tzmon.c
+++ new/usr/src/uts/i86pc/io/tzmon/tzmon.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 /*
23 23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 27 /*
28 28 * Solaris x86 ACPI ThermalZone Monitor
29 29 */
30 30
↓ open down ↓ |
30 lines elided |
↑ open up ↑ |
31 31
32 32 #include <sys/errno.h>
33 33 #include <sys/conf.h>
34 34 #include <sys/modctl.h>
35 35 #include <sys/open.h>
36 36 #include <sys/stat.h>
37 37 #include <sys/ddi.h>
38 38 #include <sys/sunddi.h>
39 39 #include <sys/ksynch.h>
40 40 #include <sys/uadmin.h>
41 -#include <sys/acpi/acpi.h>
41 +#include <acpica/include/acpi.h>
42 42 #include <sys/acpica.h>
43 43 #include <sys/sdt.h>
44 44
45 45 #include "tzmon.h"
46 46
47 47
48 48 #define TZMON_ENUM_TRIP_POINTS 1
49 49 #define TZMON_ENUM_DEV_LISTS 2
50 50 #define TZMON_ENUM_ALL (TZMON_ENUM_TRIP_POINTS | TZMON_ENUM_DEV_LISTS)
51 51
52 52 /*
53 53 * TZ_TASKQ_NAME_LEN is precisely the length of the string "AcpiThermalMonitor"
54 54 * plus a two-digit instance number plus a NULL. If the taskq name is changed
55 55 * (particularly if it is lengthened), then this value needs to change.
56 56 */
57 57 #define TZ_TASKQ_NAME_LEN 21
58 58
59 59 /*
60 60 * Kelvin to Celsius conversion
61 61 * The formula for converting degrees Kelvin to degrees Celsius is
62 62 * C = K - 273.15 (we round to 273.2). The unit for thermal zone
63 63 * temperatures is tenths of a degree Kelvin. Use tenth of a degree
64 64 * to convert, then make a whole number out of it.
65 65 */
66 66 #define K_TO_C(temp) (((temp) - 2732) / 10)
67 67
68 68
69 69 /* cb_ops or dev_ops forward declarations */
70 70 static int tzmon_getinfo(dev_info_t *dip, ddi_info_cmd_t infocmd,
71 71 void *arg, void **result);
72 72 static int tzmon_attach(dev_info_t *dip, ddi_attach_cmd_t cmd);
73 73 static int tzmon_detach(dev_info_t *dip, ddi_detach_cmd_t cmd);
74 74
75 75 /* other forward declarations */
76 76 static void tzmon_notify_zone(ACPI_HANDLE obj, UINT32 val, void *ctx);
77 77 static void tzmon_eval_int(ACPI_HANDLE obj, char *method, int *rv);
78 78 static thermal_zone_t *tzmon_alloc_zone();
79 79 static void tzmon_free_zone_list();
80 80 static void tzmon_discard_buffers(thermal_zone_t *tzp);
81 81 static void tzmon_enumerate_zone(ACPI_HANDLE obj, thermal_zone_t *tzp,
82 82 int enum_flag);
83 83 static ACPI_STATUS tzmon_zone_callback(ACPI_HANDLE obj, UINT32 nest,
84 84 void *ctx, void **rv);
85 85 static void tzmon_find_zones(void);
86 86 static void tzmon_monitor(void *ctx);
87 87 static void tzmon_set_power_device(ACPI_HANDLE dev, int on_off, char *tz_name);
88 88 static void tzmon_set_power(ACPI_BUFFER devlist, int on_off, char *tz_name);
89 89 static void tzmon_eval_zone(thermal_zone_t *tzp);
90 90 static void tzmon_do_shutdown(void);
91 91
92 92 extern void halt(char *);
93 93
94 94 static struct cb_ops tzmon_cb_ops = {
95 95 nodev, /* no open routine */
96 96 nodev, /* no close routine */
97 97 nodev, /* not a block driver */
98 98 nodev, /* no print routine */
99 99 nodev, /* no dump routine */
100 100 nodev, /* no read routine */
101 101 nodev, /* no write routine */
102 102 nodev, /* no ioctl routine */
103 103 nodev, /* no devmap routine */
104 104 nodev, /* no mmap routine */
105 105 nodev, /* no segmap routine */
106 106 nochpoll, /* no chpoll routine */
107 107 ddi_prop_op,
108 108 0, /* not a STREAMS driver */
109 109 D_NEW | D_MP, /* safe for multi-thread/multi-processor */
110 110 };
111 111
112 112 static struct dev_ops tzmon_ops = {
113 113 DEVO_REV, /* devo_rev */
114 114 0, /* devo_refcnt */
115 115 tzmon_getinfo, /* devo_getinfo */
116 116 nulldev, /* devo_identify */
117 117 nulldev, /* devo_probe */
118 118 tzmon_attach, /* devo_attach */
119 119 tzmon_detach, /* devo_detach */
120 120 nodev, /* devo_reset */
121 121 &tzmon_cb_ops, /* devo_cb_ops */
122 122 (struct bus_ops *)0, /* devo_bus_ops */
123 123 NULL, /* devo_power */
124 124 ddi_quiesce_not_needed, /* devo_quiesce */
125 125 };
126 126
127 127 extern struct mod_ops mod_driverops;
128 128
129 129 static struct modldrv modldrv = {
130 130 &mod_driverops,
131 131 "ACPI Thermal Zone Monitor",
132 132 &tzmon_ops,
133 133 };
134 134
135 135 static struct modlinkage modlinkage = {
136 136 MODREV_1, /* MODREV_1 indicated by manual */
137 137 (void *)&modldrv,
138 138 NULL, /* termination of list of linkage structures */
139 139 };
140 140
141 141 /* globals for this module */
142 142 static dev_info_t *tzmon_dip;
143 143 static thermal_zone_t *zone_list;
144 144 static int zone_count;
145 145 static kmutex_t zone_list_lock;
146 146 static kcondvar_t zone_list_condvar;
147 147
148 148
149 149 /*
150 150 * _init, _info, and _fini support loading and unloading the driver.
151 151 */
152 152 int
153 153 _init(void)
154 154 {
155 155 return (mod_install(&modlinkage));
156 156 }
157 157
158 158
159 159 int
160 160 _info(struct modinfo *modinfop)
161 161 {
162 162 return (mod_info(&modlinkage, modinfop));
163 163 }
164 164
165 165
166 166 int
167 167 _fini(void)
168 168 {
169 169 return (mod_remove(&modlinkage));
170 170 }
171 171
172 172
173 173 static int
174 174 tzmon_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
175 175 {
176 176 if (cmd != DDI_ATTACH)
177 177 return (DDI_FAILURE);
178 178
179 179 if (tzmon_dip != NULL)
180 180 return (DDI_FAILURE);
181 181
182 182 /*
183 183 * Check to see if ACPI CA services are available
184 184 */
185 185 if (AcpiSubsystemStatus() != AE_OK)
186 186 return (DDI_FAILURE);
187 187
188 188 mutex_init(&zone_list_lock, NULL, MUTEX_DRIVER, NULL);
189 189 cv_init(&zone_list_condvar, NULL, CV_DRIVER, NULL);
190 190
191 191 tzmon_find_zones();
192 192 mutex_enter(&zone_list_lock);
193 193 if (zone_count < 1) {
194 194 mutex_exit(&zone_list_lock);
195 195 mutex_destroy(&zone_list_lock);
196 196 cv_destroy(&zone_list_condvar);
197 197 return (DDI_FAILURE);
198 198 }
199 199 mutex_exit(&zone_list_lock);
200 200
201 201 if (ddi_create_minor_node(dip, ddi_get_name(dip), S_IFCHR, 0,
202 202 DDI_PSEUDO, 0) == DDI_FAILURE) {
203 203 tzmon_free_zone_list();
204 204 mutex_destroy(&zone_list_lock);
205 205 cv_destroy(&zone_list_condvar);
206 206 return (DDI_FAILURE);
207 207 }
208 208
209 209 tzmon_dip = dip;
210 210
211 211 ddi_report_dev(dip);
212 212
213 213 return (DDI_SUCCESS);
214 214 }
215 215
216 216
217 217 /*ARGSUSED*/
218 218 static int
219 219 tzmon_getinfo(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result)
220 220 {
221 221 int error;
222 222
223 223 switch (infocmd) {
224 224 case DDI_INFO_DEVT2DEVINFO:
225 225 *result = tzmon_dip;
226 226 if (tzmon_dip == NULL)
227 227 error = DDI_FAILURE;
228 228 else
229 229 error = DDI_SUCCESS;
230 230 break;
231 231 case DDI_INFO_DEVT2INSTANCE:
232 232 *result = 0;
233 233 error = DDI_SUCCESS;
234 234 break;
235 235 default:
236 236 *result = NULL;
237 237 error = DDI_FAILURE;
238 238 }
239 239
240 240 return (error);
241 241 }
242 242
243 243
244 244 static int
245 245 tzmon_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
246 246 {
247 247 thermal_zone_t *tzp = zone_list;
248 248
249 249 if (cmd != DDI_DETACH)
250 250 return (DDI_FAILURE);
251 251
252 252 /* free allocated thermal zone name(s) */
253 253 while (tzp != NULL) {
254 254 AcpiOsFree(tzp->zone_name);
255 255 tzp = tzp->next;
256 256 }
257 257
258 258 /* discard zone list assets */
259 259 tzmon_free_zone_list();
260 260
261 261 ddi_remove_minor_node(dip, NULL);
262 262 tzmon_dip = NULL;
263 263
264 264 mutex_destroy(&zone_list_lock);
265 265 cv_destroy(&zone_list_condvar);
266 266
267 267 return (DDI_SUCCESS);
268 268 }
269 269
270 270
271 271 /*
272 272 * tzmon_notify_zone
273 273 * Thermal zone notification handler.
274 274 */
275 275 static void
276 276 tzmon_notify_zone(ACPI_HANDLE obj, UINT32 val, void *ctx)
277 277 {
278 278 thermal_zone_t *tzp = (thermal_zone_t *)ctx;
279 279
280 280 switch (val) {
281 281 case 0x80: /* Thermal Zone status changed */
282 282 tzmon_eval_zone(tzp);
283 283 break;
284 284 case 0x81: /* Thermal Zone trip points changed */
285 285 tzmon_enumerate_zone(obj, tzp, TZMON_ENUM_TRIP_POINTS);
286 286 break;
287 287 case 0x82: /* Device Lists changed */
288 288 tzmon_enumerate_zone(obj, tzp, TZMON_ENUM_DEV_LISTS);
289 289 break;
290 290 case 0x83: /* Thermal Relationship Table changed */
291 291 /* not handling _TRT objects, so not handling this event */
292 292 DTRACE_PROBE1(trt__change, char *, (char *)tzp->zone_name);
293 293 break;
294 294 default:
295 295 break;
296 296 }
297 297 }
298 298
299 299
300 300 /*
301 301 * tzmon_eval_int
302 302 * Evaluate the object/method as an integer.
303 303 */
304 304 static void
305 305 tzmon_eval_int(ACPI_HANDLE obj, char *method, int *rv)
306 306 {
307 307
308 308 if (acpica_eval_int(obj, method, rv) != AE_OK)
309 309 *rv = -1;
310 310 }
311 311
312 312
313 313 /*
314 314 * tzmon_alloc_zone
315 315 * Allocate memory for the zone structure and initialize it lock mutex.
316 316 */
317 317 static thermal_zone_t *
318 318 tzmon_alloc_zone()
319 319 {
320 320 thermal_zone_t *tzp;
321 321
322 322 tzp = kmem_zalloc(sizeof (thermal_zone_t), KM_SLEEP);
323 323 mutex_init(&tzp->lock, NULL, MUTEX_DRIVER, NULL);
324 324
325 325 return (tzp);
326 326 }
327 327
328 328
329 329 /*
330 330 * tzmon_free_zone_list
331 331 * Free the zone list, either because attach failed or detach initiated.
332 332 */
333 333 static void
334 334 tzmon_free_zone_list()
335 335 {
336 336 thermal_zone_t *tzp = zone_list;
337 337
338 338 while (tzp != NULL) {
339 339 thermal_zone_t *next;
340 340
341 341 mutex_enter(&tzp->lock);
342 342
343 343 /*
344 344 * Remove the notify handler for the zone. Not much to
345 345 * do if this fails (since we are on our way out), so
346 346 * just ignore failure.
347 347 */
348 348 (void) AcpiRemoveNotifyHandler(tzp->obj, ACPI_DEVICE_NOTIFY,
349 349 tzmon_notify_zone);
350 350
351 351 /* Shut down monitor thread, if running */
352 352 if (tzp->taskq != NULL) {
353 353 tzp->polling_period = 0;
354 354 cv_broadcast(&zone_list_condvar);
355 355
356 356 /* Drop mutex to allow the thread to run */
357 357 mutex_exit(&tzp->lock);
358 358 ddi_taskq_destroy(tzp->taskq);
359 359 mutex_enter(&tzp->lock);
360 360 }
361 361
362 362 tzmon_discard_buffers(tzp);
363 363 mutex_exit(&tzp->lock);
364 364 mutex_destroy(&tzp->lock);
365 365
366 366 next = tzp->next;
367 367 kmem_free(tzp, sizeof (thermal_zone_t));
368 368 tzp = next;
369 369 }
370 370 }
371 371
372 372
373 373 static void
374 374 tzmon_discard_buffers(thermal_zone_t *tzp)
375 375 {
376 376 int level;
377 377
378 378 for (level = 0; level < TZ_NUM_LEVELS; level++) {
379 379 if (tzp->al[level].Pointer != NULL)
380 380 AcpiOsFree(tzp->al[level].Pointer);
381 381 }
382 382
383 383 if (tzp->psl.Pointer != NULL)
384 384 AcpiOsFree(tzp->psl.Pointer);
385 385 }
386 386
387 387
388 388 /*
389 389 * tzmon_enumerate_zone
390 390 * Enumerates the contents of a thermal zone and updates passed-in
391 391 * thermal_zone or creates a new one if tzp is NULL. Newly-created
392 392 * zones are linked into the global zone_list.
393 393 */
394 394 static void
395 395 tzmon_enumerate_zone(ACPI_HANDLE obj, thermal_zone_t *tzp, int enum_flag)
396 396 {
397 397 ACPI_STATUS status;
398 398 ACPI_BUFFER zone_name;
399 399 int level;
400 400 int instance;
401 401 char abuf[5];
402 402
403 403 /*
404 404 * Newly-created zones and existing zones both require
405 405 * some individual attention.
406 406 */
407 407 if (tzp == NULL) {
408 408 /* New zone required */
409 409 tzp = tzmon_alloc_zone();
410 410 mutex_enter(&zone_list_lock);
411 411 tzp->next = zone_list;
412 412 zone_list = tzp;
413 413
414 414 /*
415 415 * It is exceedingly unlikely that instance will exceed 99.
416 416 * However, if it does, this will cause problems when
417 417 * creating the taskq for this thermal zone.
418 418 */
419 419 instance = zone_count;
420 420 zone_count++;
421 421 mutex_exit(&zone_list_lock);
422 422 mutex_enter(&tzp->lock);
423 423 tzp->obj = obj;
424 424
425 425 /*
426 426 * Set to a low level. Will get set to the actual
427 427 * current power level when the thread monitor polls
428 428 * the current temperature.
429 429 */
430 430 tzp->current_level = 0;
431 431
432 432 /* Get the zone name in case we need to display it later */
433 433 zone_name.Length = ACPI_ALLOCATE_BUFFER;
434 434 zone_name.Pointer = NULL;
435 435
436 436 status = AcpiGetName(obj, ACPI_FULL_PATHNAME, &zone_name);
437 437 ASSERT(status == AE_OK);
438 438
439 439 tzp->zone_name = zone_name.Pointer;
440 440
441 441 status = AcpiInstallNotifyHandler(obj, ACPI_DEVICE_NOTIFY,
442 442 tzmon_notify_zone, (void *)tzp);
443 443 ASSERT(status == AE_OK);
444 444 } else {
445 445 /* Existing zone - toss out allocated items */
446 446 mutex_enter(&tzp->lock);
447 447 ASSERT(tzp->obj == obj);
448 448
449 449 if (enum_flag & TZMON_ENUM_DEV_LISTS)
450 450 tzmon_discard_buffers(tzp);
451 451 }
452 452
453 453 if (enum_flag & TZMON_ENUM_TRIP_POINTS) {
454 454 for (level = 0; level < TZ_NUM_LEVELS; level++) {
455 455 (void) snprintf(abuf, 5, "_AC%d", level);
456 456 tzmon_eval_int(obj, abuf, &tzp->ac[level]);
457 457
458 458 }
459 459
460 460 tzmon_eval_int(obj, "_CRT", &tzp->crt);
461 461 tzmon_eval_int(obj, "_HOT", &tzp->hot);
462 462 tzmon_eval_int(obj, "_PSV", &tzp->psv);
463 463 }
464 464
465 465 if (enum_flag & TZMON_ENUM_DEV_LISTS) {
466 466 for (level = 0; level < TZ_NUM_LEVELS; level++) {
467 467 if (tzp->ac[level] == -1) {
468 468 tzp->al[level].Length = 0;
469 469 tzp->al[level].Pointer = NULL;
470 470 } else {
471 471 (void) snprintf(abuf, 5, "_AL%d", level);
472 472 tzp->al[level].Length = ACPI_ALLOCATE_BUFFER;
473 473 tzp->al[level].Pointer = NULL;
474 474 if (AcpiEvaluateObjectTyped(obj, abuf, NULL,
475 475 &tzp->al[level], ACPI_TYPE_PACKAGE) !=
476 476 AE_OK) {
477 477 DTRACE_PROBE2(alx__missing, int, level,
478 478 char *, (char *)tzp->zone_name);
479 479
480 480 tzp->al[level].Length = 0;
481 481 tzp->al[level].Pointer = NULL;
482 482 }
483 483 }
484 484 }
485 485
486 486 tzp->psl.Length = ACPI_ALLOCATE_BUFFER;
487 487 tzp->psl.Pointer = NULL;
488 488 (void) AcpiEvaluateObjectTyped(obj, "_PSL", NULL, &tzp->psl,
489 489 ACPI_TYPE_PACKAGE);
490 490 }
491 491
492 492 tzmon_eval_int(obj, "_TC1", &tzp->tc1);
493 493 tzmon_eval_int(obj, "_TC2", &tzp->tc2);
494 494 tzmon_eval_int(obj, "_TSP", &tzp->tsp);
495 495 tzmon_eval_int(obj, "_TZP", &tzp->tzp);
496 496
497 497 if (tzp->tzp == 0) {
498 498 tzp->polling_period = 0;
499 499 } else {
500 500 if (tzp->tzp < 0)
501 501 tzp->polling_period = TZ_DEFAULT_PERIOD;
502 502 else
503 503 tzp->polling_period = tzp->tzp/10;
504 504
505 505 /* start monitor thread if needed */
506 506 if (tzp->taskq == NULL) {
507 507 char taskq_name[TZ_TASKQ_NAME_LEN];
508 508
509 509 (void) snprintf(taskq_name, TZ_TASKQ_NAME_LEN,
510 510 "AcpiThermalMonitor%02d", instance);
511 511 tzp->taskq = ddi_taskq_create(tzmon_dip,
512 512 taskq_name, 1, TASKQ_DEFAULTPRI, 0);
513 513 if (tzp->taskq == NULL) {
514 514 tzp->polling_period = 0;
515 515 cmn_err(CE_WARN, "tzmon: could not create "
516 516 "monitor thread for thermal zone %s - "
517 517 "monitor by notify only",
518 518 (char *)tzp->zone_name);
519 519 } else {
520 520 (void) ddi_taskq_dispatch(tzp->taskq,
521 521 tzmon_monitor, tzp, DDI_SLEEP);
522 522 }
523 523 }
524 524 }
525 525
526 526 mutex_exit(&tzp->lock);
527 527 }
528 528
529 529
530 530 /*
531 531 * tzmon_zone_callback
532 532 * Enumerate the thermal zone if it has a _TMP (current thermal zone
533 533 * operating temperature) method.
534 534 */
535 535 /*ARGSUSED*/
536 536 static ACPI_STATUS
537 537 tzmon_zone_callback(ACPI_HANDLE obj, UINT32 nest, void *ctx, void **rv)
538 538 {
539 539 ACPI_HANDLE tmpobj;
540 540
541 541 /*
542 542 * We get both ThermalZone() and Scope(\_TZ) objects here;
543 543 * look for _TMP (without which a zone is invalid) to pick
544 544 * between them (and ignore invalid zones)
545 545 */
546 546 if (AcpiGetHandle(obj, "_TMP", &tmpobj) == AE_OK) {
547 547 tzmon_enumerate_zone(obj, NULL, TZMON_ENUM_ALL);
548 548 }
549 549
550 550 return (AE_OK);
551 551 }
552 552
553 553
554 554 /*
555 555 * tzmon_find_zones
556 556 * Find all of the thermal zones by calling a ACPICA function that
557 557 * walks the ACPI namespace and invokes a callback for each thermal
558 558 * object found.
559 559 */
560 560 static void
561 561 tzmon_find_zones()
562 562 {
563 563 ACPI_STATUS status;
564 564 int retval;
565 565
566 566 status = AcpiWalkNamespace(ACPI_TYPE_THERMAL, ACPI_ROOT_OBJECT,
567 567 8, tzmon_zone_callback, NULL, NULL, (void **)&retval);
568 568
569 569 ASSERT(status == AE_OK);
570 570 }
571 571
572 572
573 573 /*
574 574 * tzmon_monitor
575 575 * Run as a separate thread, this wakes according to polling period and
576 576 * checks particular objects in the thermal zone. One instance per
577 577 * thermal zone.
578 578 */
579 579 static void
580 580 tzmon_monitor(void *ctx)
581 581 {
582 582 thermal_zone_t *tzp = (thermal_zone_t *)ctx;
583 583 clock_t ticks;
584 584
585 585 do {
586 586 /* Check out the zone */
587 587 tzmon_eval_zone(tzp);
588 588
589 589 /* Go back to sleep */
590 590 mutex_enter(&tzp->lock);
591 591 ticks = drv_usectohz(tzp->polling_period * 1000000);
592 592 if (ticks > 0)
593 593 (void) cv_reltimedwait(&zone_list_condvar,
594 594 &tzp->lock, ticks, TR_CLOCK_TICK);
595 595 mutex_exit(&tzp->lock);
596 596 } while (ticks > 0);
597 597 }
598 598
599 599
600 600 /*
601 601 * tzmon_set_power_device
602 602 */
603 603 static void
604 604 tzmon_set_power_device(ACPI_HANDLE dev, int on_off, char *tz_name)
605 605 {
606 606 ACPI_BUFFER rb;
607 607 ACPI_OBJECT *pr0;
608 608 ACPI_STATUS status;
609 609 int i;
610 610
611 611 rb.Length = ACPI_ALLOCATE_BUFFER;
612 612 rb.Pointer = NULL;
613 613 status = AcpiEvaluateObjectTyped(dev, "_PR0", NULL, &rb,
614 614 ACPI_TYPE_PACKAGE);
615 615 if (status != AE_OK) {
616 616 DTRACE_PROBE2(alx__error, int, 2, char *, tz_name);
617 617 return;
618 618 }
619 619
620 620 pr0 = ((ACPI_OBJECT *)rb.Pointer);
621 621 for (i = 0; i < pr0->Package.Count; i++) {
622 622 status = AcpiEvaluateObject(
623 623 pr0->Package.Elements[i].Reference.Handle,
624 624 on_off ? "_ON" : "_OFF", NULL, NULL);
625 625 if (status != AE_OK) {
626 626 DTRACE_PROBE2(alx__error, int, 4, char *, tz_name);
627 627 }
628 628 }
629 629
630 630 AcpiOsFree(rb.Pointer);
631 631 }
632 632
633 633
634 634 /*
635 635 * tzmon_set_power
636 636 * Turn on or turn off all devices in the supplied list.
637 637 */
638 638 static void
639 639 tzmon_set_power(ACPI_BUFFER devlist, int on_off, char *tz_name)
640 640 {
641 641 ACPI_OBJECT *devs;
642 642 int i;
643 643
644 644 devs = ((ACPI_OBJECT *)devlist.Pointer);
645 645 if (devs->Type != ACPI_TYPE_PACKAGE) {
646 646 DTRACE_PROBE2(alx__error, int, 1, char *, tz_name);
647 647 return;
648 648 }
649 649
650 650 for (i = 0; i < devs->Package.Count; i++)
651 651 tzmon_set_power_device(
652 652 devs->Package.Elements[i].Reference.Handle, on_off,
653 653 tz_name);
654 654 }
655 655
656 656
657 657 /*
658 658 * tzmon_eval_zone
659 659 * Evaluate the current conditions within the thermal zone.
660 660 */
661 661 static void
662 662 tzmon_eval_zone(thermal_zone_t *tzp)
663 663 {
664 664 int tmp, new_level, level;
665 665
666 666 mutex_enter(&tzp->lock);
667 667
668 668 /* get the current temperature from ACPI */
669 669 tzmon_eval_int(tzp->obj, "_TMP", &tmp);
670 670 DTRACE_PROBE4(tz__temp, int, tmp, int, tzp->crt, int, tzp->hot,
671 671 char *, (char *)tzp->zone_name);
672 672
673 673 /* _HOT handling */
674 674 if (tzp->hot > 0 && tmp >= tzp->hot) {
675 675 cmn_err(CE_WARN,
676 676 "tzmon: Thermal zone (%s) is too hot (%d C); "
677 677 "initiating shutdown\n",
678 678 (char *)tzp->zone_name, K_TO_C(tmp));
679 679
680 680 tzmon_do_shutdown();
681 681 }
682 682
683 683 /* _CRT handling */
684 684 if (tzp->crt > 0 && tmp >= tzp->crt) {
685 685 cmn_err(CE_WARN,
686 686 "tzmon: Thermal zone (%s) is critically hot (%d C); "
687 687 "initiating rapid shutdown\n",
688 688 (char *)tzp->zone_name, K_TO_C(tmp));
689 689
690 690 /* shut down (fairly) immediately */
691 691 mdboot(A_REBOOT, AD_HALT, NULL, B_FALSE);
692 692 }
693 693
694 694 /*
695 695 * use the temperature to determine whether the thermal zone
696 696 * is at a new active cooling threshold level
697 697 */
698 698 for (level = 0, new_level = -1; level < TZ_NUM_LEVELS; level++) {
699 699 if (tzp->ac[level] >= 0 && (tmp >= tzp->ac[level])) {
700 700 new_level = level;
701 701 break;
702 702 }
703 703 }
704 704
705 705 /*
706 706 * if the active cooling threshold has changed, turn off the
707 707 * devices associated with the old one and turn on the new one
708 708 */
709 709 if (tzp->current_level != new_level) {
710 710 if ((tzp->current_level >= 0) &&
711 711 (tzp->al[tzp->current_level].Length != 0))
712 712 tzmon_set_power(tzp->al[tzp->current_level], 0,
713 713 (char *)tzp->zone_name);
714 714
715 715 if ((new_level >= 0) &&
716 716 (tzp->al[new_level].Length != 0))
717 717 tzmon_set_power(tzp->al[new_level], 1,
718 718 (char *)tzp->zone_name);
719 719
720 720 tzp->current_level = new_level;
721 721 }
722 722
723 723 mutex_exit(&tzp->lock);
724 724 }
725 725
726 726
727 727 /*
728 728 * tzmon_do_shutdown
729 729 * Initiates shutdown by sending a SIGPWR signal to init.
730 730 */
731 731 static void
732 732 tzmon_do_shutdown(void)
733 733 {
734 734 proc_t *initpp;
735 735
736 736 mutex_enter(&pidlock);
737 737 initpp = prfind(P_INITPID);
738 738 mutex_exit(&pidlock);
739 739
740 740 /* if we can't find init, just halt */
741 741 if (initpp == NULL) {
742 742 mdboot(A_REBOOT, AD_HALT, NULL, B_FALSE);
743 743 }
744 744
745 745 /* graceful shutdown with inittab and all getting involved */
746 746 psignal(initpp, SIGPWR);
747 747 }
↓ open down ↓ |
696 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX