xref: /titanic_51/usr/src/uts/intel/io/acpica/acpica.c (revision af4c679f647cf088543c762e33d41a3ac52cfa14)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 /*
26  * Copyright (c) 2009, Intel Corporation.
27  * All rights reserved.
28  */
29 /*
30  * Solaris x86 ACPI CA services
31  */
32 
33 #include <sys/file.h>
34 #include <sys/errno.h>
35 #include <sys/conf.h>
36 #include <sys/modctl.h>
37 #include <sys/open.h>
38 #include <sys/stat.h>
39 #include <sys/ddi.h>
40 #include <sys/sunddi.h>
41 #include <sys/esunddi.h>
42 #include <sys/kstat.h>
43 #include <sys/x86_archext.h>
44 
45 #include <sys/acpi/acpi.h>
46 #include <sys/acpica.h>
47 #include <sys/archsystm.h>
48 
49 /*
50  *
51  */
52 static	struct modlmisc modlmisc = {
53 	&mod_miscops,
54 	"ACPI interpreter",
55 };
56 
57 static	struct modlinkage modlinkage = {
58 	MODREV_1,		/* MODREV_1 manual */
59 	(void *)&modlmisc,	/* module linkage */
60 	NULL,			/* list terminator */
61 };
62 
63 /*
64  * Local prototypes
65  */
66 
67 static void	acpica_init_kstats(void);
68 
69 /*
70  * Local data
71  */
72 
73 static kmutex_t	acpica_module_lock;
74 static kstat_t	*acpica_ksp;
75 
76 /*
77  * State of acpica subsystem
78  * After successful initialization, will be ACPICA_INITIALIZED
79  */
80 int acpica_init_state = ACPICA_NOT_INITIALIZED;
81 
82 /*
83  * Following are set by acpica_process_user_options()
84  *
85  * acpica_enable = FALSE prevents initialization of ACPI CA
86  * completely
87  *
88  * acpi_init_level determines level of ACPI CA functionality
89  * enabled in acpica_init()
90  */
91 int	acpica_enable;
92 UINT32	acpi_init_level;
93 
94 /*
95  * Non-zero enables lax behavior with respect to some
96  * common ACPI BIOS issues; see ACPI CA documentation
97  * Setting this to zero causes ACPI CA to enforce strict
98  * compliance with ACPI specification
99  */
100 int acpica_enable_interpreter_slack = 1;
101 
102 /*
103  * For non-DEBUG builds, set the ACPI CA debug level to 0
104  * to quiet chatty BIOS output into /var/adm/messages
105  * Field-patchable for diagnostic use.
106  */
107 #ifdef  DEBUG
108 int acpica_muzzle_debug_output = 0;
109 #else
110 int acpica_muzzle_debug_output = 1;
111 #endif
112 
113 /*
114  * ACPI DDI hooks
115  */
116 static int acpica_ddi_setwake(dev_info_t *dip, int level);
117 
118 int
119 _init(void)
120 {
121 	int error = EBUSY;
122 	int	status;
123 	extern int (*acpi_fp_setwake)();
124 
125 	mutex_init(&acpica_module_lock, NULL, MUTEX_DRIVER, NULL);
126 
127 	if ((error = mod_install(&modlinkage)) != 0) {
128 		mutex_destroy(&acpica_module_lock);
129 		goto load_error;
130 	}
131 
132 	AcpiGbl_EnableInterpreterSlack = (acpica_enable_interpreter_slack != 0);
133 
134 	/* global ACPI CA initialization */
135 	if (ACPI_FAILURE(status = AcpiInitializeSubsystem()))
136 		cmn_err(CE_WARN, "!AcpiInitializeSubsystem failed: %d", status);
137 
138 	/* initialize table manager */
139 	if (ACPI_FAILURE(status = AcpiInitializeTables(NULL, 0, 0)))
140 		cmn_err(CE_WARN, "!AcpiInitializeTables failed: %d", status);
141 
142 	acpi_fp_setwake = acpica_ddi_setwake;
143 
144 load_error:
145 	return (error);
146 }
147 
148 int
149 _info(struct modinfo *modinfop)
150 {
151 	return (mod_info(&modlinkage, modinfop));
152 }
153 
154 int
155 _fini(void)
156 {
157 	/*
158 	 * acpica module is never unloaded at run-time; there's always
159 	 * a PSM depending on it, at the very least
160 	 */
161 	return (EBUSY);
162 }
163 
164 /*
165  * Install acpica-provided address-space handlers
166  */
167 static int
168 acpica_install_handlers()
169 {
170 	ACPI_STATUS	rv = AE_OK;
171 
172 	/*
173 	 * Install ACPI CA default handlers
174 	 */
175 	if (AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT,
176 	    ACPI_ADR_SPACE_SYSTEM_MEMORY,
177 	    ACPI_DEFAULT_HANDLER, NULL, NULL) != AE_OK) {
178 		cmn_err(CE_WARN, "!acpica: no default handler for"
179 		    " system memory");
180 		rv = AE_ERROR;
181 	}
182 
183 	if (AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT,
184 	    ACPI_ADR_SPACE_SYSTEM_IO,
185 	    ACPI_DEFAULT_HANDLER, NULL, NULL) != AE_OK) {
186 		cmn_err(CE_WARN, "!acpica: no default handler for"
187 		    " system I/O");
188 		rv = AE_ERROR;
189 	}
190 
191 	if (AcpiInstallAddressSpaceHandler(ACPI_ROOT_OBJECT,
192 	    ACPI_ADR_SPACE_PCI_CONFIG,
193 	    ACPI_DEFAULT_HANDLER, NULL, NULL) != AE_OK) {
194 		cmn_err(CE_WARN, "!acpica: no default handler for"
195 		    " PCI Config");
196 		rv = AE_ERROR;
197 	}
198 
199 
200 	return (rv);
201 }
202 
203 /*
204  * Find the BIOS date, and return TRUE if supplied
205  * date is same or later than the BIOS date, or FALSE
206  * if the BIOS date can't be fetched for any reason
207  */
208 static int
209 acpica_check_bios_date(int yy, int mm, int dd)
210 {
211 
212 	char *datep;
213 	int bios_year, bios_month, bios_day;
214 
215 	/* If firmware has no bios, skip the check */
216 	if (ddi_prop_exists(DDI_DEV_T_ANY, ddi_root_node(), DDI_PROP_DONTPASS,
217 	    "bios-free"))
218 		return (TRUE);
219 
220 	/*
221 	 * PC BIOSes contain a string in the form of
222 	 * "mm/dd/yy" at absolute address 0xffff5,
223 	 * where mm, dd and yy are all ASCII digits.
224 	 * We map the string, pluck out the values,
225 	 * and accept all BIOSes from 1 Jan 1999 on
226 	 * as valid.
227 	 */
228 
229 	if ((datep = (char *)AcpiOsMapMemory(0xffff5, 8)) == NULL)
230 		return (FALSE);
231 
232 	/* year */
233 	bios_year = ((int)(*(datep + 6) - '0') * 10) + (*(datep + 7) - '0');
234 	/* month */
235 	bios_month = ((int)(*datep - '0') * 10) + (*(datep + 1) - '0');
236 	/* day */
237 	bios_day = ((int)(*(datep + 3) - '0') * 10) + (*(datep + 4) - '0');
238 
239 	AcpiOsUnmapMemory((void *) datep, 8);
240 
241 	if (bios_year < 0 || bios_year > 99 || bios_month < 0 ||
242 	    bios_month > 99 || bios_day < 0 || bios_day > 99) {
243 		/* non-digit chars in BIOS date */
244 		return (FALSE);
245 	}
246 
247 	/*
248 	 * Adjust for 2-digit year; note to grand-children:
249 	 * need a new scheme before 2080 rolls around
250 	 */
251 	bios_year += (bios_year >= 80 && bios_year <= 99) ?
252 	    1900 : 2000;
253 
254 	if (bios_year < yy)
255 		return (FALSE);
256 	else if (bios_year > yy)
257 		return (TRUE);
258 
259 	if (bios_month < mm)
260 		return (FALSE);
261 	else if (bios_month > mm)
262 		return (TRUE);
263 
264 	if (bios_day < dd)
265 		return (FALSE);
266 
267 	return (TRUE);
268 }
269 
270 /*
271  * Check for Metropolis systems with BIOSes older than 10/12/04
272  * return TRUE if BIOS requires legacy mode, FALSE otherwise
273  */
274 static int
275 acpica_metro_old_bios()
276 {
277 	ACPI_TABLE_HEADER *fadt;
278 
279 	/* get the FADT */
280 	if (AcpiGetTable(ACPI_SIG_FADT, 1, (ACPI_TABLE_HEADER **)&fadt) !=
281 	    AE_OK)
282 		return (FALSE);
283 
284 	/* compare OEM Table ID to "SUNmetro" - no match, return false */
285 	if (strncmp("SUNmetro", fadt->OemTableId, 8))
286 		return (FALSE);
287 
288 	/* On a Metro - return FALSE if later than 10/12/04 */
289 	return (!acpica_check_bios_date(2004, 10, 12));
290 }
291 
292 
293 /*
294  * Process acpi-user-options property  if present
295  */
296 static void
297 acpica_process_user_options()
298 {
299 	static int processed = 0;
300 	int acpi_user_options;
301 	char *acpi_prop;
302 
303 	/*
304 	 * return if acpi-user-options has already been processed
305 	 */
306 	if (processed)
307 		return;
308 	else
309 		processed = 1;
310 
311 	/* converts acpi-user-options from type string to int, if any */
312 	if (ddi_prop_lookup_string(DDI_DEV_T_ANY, ddi_root_node(),
313 	    DDI_PROP_DONTPASS, "acpi-user-options", &acpi_prop) ==
314 	    DDI_PROP_SUCCESS) {
315 		long data;
316 		int ret;
317 		ret = ddi_strtol(acpi_prop, NULL, 0, &data);
318 		if (ret == 0) {
319 			e_ddi_prop_remove(DDI_DEV_T_NONE, ddi_root_node(),
320 			    "acpi-user-options");
321 			e_ddi_prop_update_int(DDI_DEV_T_NONE, ddi_root_node(),
322 			    "acpi-user-options", data);
323 		}
324 		ddi_prop_free(acpi_prop);
325 	}
326 
327 	/*
328 	 * fetch the optional options property
329 	 */
330 	acpi_user_options = ddi_prop_get_int(DDI_DEV_T_ANY, ddi_root_node(),
331 	    DDI_PROP_DONTPASS, "acpi-user-options", 0);
332 
333 	/*
334 	 * Note that 'off' has precedence over 'on'
335 	 * Also note - all cases of ACPI_OUSER_MASK
336 	 * provided here, no default: case is present
337 	 */
338 	switch (acpi_user_options & ACPI_OUSER_MASK) {
339 	case ACPI_OUSER_DFLT:
340 		acpica_enable = acpica_check_bios_date(1999, 1, 1);
341 		break;
342 	case ACPI_OUSER_ON:
343 		acpica_enable = TRUE;
344 		break;
345 	case ACPI_OUSER_OFF:
346 	case ACPI_OUSER_OFF | ACPI_OUSER_ON:
347 		acpica_enable = FALSE;
348 		break;
349 	}
350 
351 	acpi_init_level = ACPI_FULL_INITIALIZATION;
352 
353 	/*
354 	 * special test here; may be generalized in the
355 	 * future - test for a machines that are known to
356 	 * work only in legacy mode, and set OUSER_LEGACY if
357 	 * we're on one
358 	 */
359 	if (acpica_metro_old_bios())
360 		acpi_user_options |= ACPI_OUSER_LEGACY;
361 
362 	/*
363 	 * If legacy mode is specified, set initialization
364 	 * options to avoid entering ACPI mode and hooking SCI
365 	 * - basically try to act like legacy acpi_intp
366 	 */
367 	if ((acpi_user_options & ACPI_OUSER_LEGACY) != 0)
368 		acpi_init_level |= (ACPI_NO_ACPI_ENABLE | ACPI_NO_HANDLER_INIT);
369 
370 	/*
371 	 * modify default ACPI CA debug output level for non-DEBUG builds
372 	 * (to avoid BIOS debug chatter in /var/adm/messages)
373 	 */
374 	if (acpica_muzzle_debug_output)
375 		AcpiDbgLevel = 0;
376 }
377 
378 /*
379  * Initialize the CA subsystem if it hasn't been done already
380  */
381 int
382 acpica_init()
383 {
384 	extern void acpica_find_ioapics(void);
385 	ACPI_STATUS status;
386 
387 	/*
388 	 * Make sure user options are processed,
389 	 * then fail to initialize if ACPI CA has been
390 	 * disabled
391 	 */
392 	acpica_process_user_options();
393 	if (!acpica_enable)
394 		return (AE_ERROR);
395 
396 	mutex_enter(&acpica_module_lock);
397 	if (acpica_init_state == ACPICA_INITIALIZED) {
398 		mutex_exit(&acpica_module_lock);
399 		return (AE_OK);
400 	}
401 
402 	if (ACPI_FAILURE(status = AcpiLoadTables()))
403 		goto error;
404 
405 	if (ACPI_FAILURE(status = acpica_install_handlers()))
406 		goto error;
407 
408 	if (ACPI_FAILURE(status = AcpiEnableSubsystem(acpi_init_level)))
409 		goto error;
410 
411 	scan_d2a_map();
412 
413 	/* do after AcpiEnableSubsystem() so GPEs are initialized */
414 	acpica_ec_init();	/* initialize EC if present */
415 
416 	if (ACPI_FAILURE(status = AcpiInitializeObjects(0)))
417 		goto error;
418 
419 	acpica_init_state = ACPICA_INITIALIZED;
420 
421 	/*
422 	 * If we are running on the Xen hypervisor as dom0 we need to
423 	 * find the ioapics so we can prevent ACPI from trying to
424 	 * access them.
425 	 */
426 	if (get_hwenv() == HW_XEN_PV && is_controldom())
427 		acpica_find_ioapics();
428 	acpica_init_kstats();
429 error:
430 	if (acpica_init_state != ACPICA_INITIALIZED) {
431 		cmn_err(CE_NOTE, "!failed to initialize ACPI services");
432 	}
433 
434 	/*
435 	 * Set acpi-status to 13 if acpica has been initialized successfully.
436 	 * This indicates that acpica is up and running.  This variable name
437 	 * and value were chosen in order to remain compatible with acpi_intp.
438 	 */
439 	e_ddi_prop_update_int(DDI_DEV_T_NONE, ddi_root_node(), "acpi-status",
440 	    (ACPI_SUCCESS(status)) ? (ACPI_BOOT_INIT | ACPI_BOOT_ENABLE |
441 	    ACPI_BOOT_BOOTCONF) : 0);
442 
443 	/* Mark acpica subsystem as fully initialized. */
444 	if (ACPI_SUCCESS(status) &&
445 	    acpi_init_level == ACPI_FULL_INITIALIZATION) {
446 		acpica_set_core_feature(ACPI_FEATURE_FULL_INIT);
447 	}
448 
449 	mutex_exit(&acpica_module_lock);
450 	return (status);
451 }
452 
453 /*
454  * SCI handling
455  */
456 
457 ACPI_STATUS
458 acpica_get_sci(int *sci_irq, iflag_t *sci_flags)
459 {
460 	ACPI_SUBTABLE_HEADER		*ap;
461 	ACPI_TABLE_MADT			*mat;
462 	ACPI_MADT_INTERRUPT_OVERRIDE	*mio;
463 	ACPI_TABLE_FADT			*fadt;
464 	int			madt_seen, madt_size;
465 
466 
467 	/*
468 	 * Make sure user options are processed,
469 	 * then return error if ACPI CA has been
470 	 * disabled or system is not running in ACPI
471 	 * and won't need/understand SCI
472 	 */
473 	acpica_process_user_options();
474 	if ((!acpica_enable) || (acpi_init_level & ACPI_NO_ACPI_ENABLE))
475 		return (AE_ERROR);
476 
477 	/*
478 	 * according to Intel ACPI developers, SCI
479 	 * conforms to PCI bus conventions; level/low
480 	 * unless otherwise directed by overrides.
481 	 */
482 	sci_flags->intr_el = INTR_EL_LEVEL;
483 	sci_flags->intr_po = INTR_PO_ACTIVE_LOW;
484 	sci_flags->bustype = BUS_PCI;	/*  we *do* conform to PCI */
485 
486 	/* get the SCI from the FADT */
487 	if (AcpiGetTable(ACPI_SIG_FADT, 1, (ACPI_TABLE_HEADER **)&fadt) !=
488 	    AE_OK)
489 		return (AE_ERROR);
490 
491 	*sci_irq = fadt->SciInterrupt;
492 
493 	/* search for ISOs that modify it */
494 	/* if we don't find a MADT, that's OK; no ISOs then */
495 	if (AcpiGetTable(ACPI_SIG_MADT, 1, (ACPI_TABLE_HEADER **) &mat) !=
496 	    AE_OK)
497 		return (AE_OK);
498 
499 	ap = (ACPI_SUBTABLE_HEADER *) (mat + 1);
500 	madt_size = mat->Header.Length;
501 	madt_seen = sizeof (*mat);
502 
503 	while (madt_seen < madt_size) {
504 		switch (ap->Type) {
505 		case ACPI_MADT_TYPE_INTERRUPT_OVERRIDE:
506 			mio = (ACPI_MADT_INTERRUPT_OVERRIDE *) ap;
507 			if (mio->SourceIrq == *sci_irq) {
508 				*sci_irq = mio->GlobalIrq;
509 				sci_flags->intr_el = (mio->IntiFlags &
510 				    ACPI_MADT_TRIGGER_MASK) >> 2;
511 				sci_flags->intr_po = mio->IntiFlags &
512 				    ACPI_MADT_POLARITY_MASK;
513 			}
514 			break;
515 		}
516 
517 		/* advance to next entry */
518 		madt_seen += ap->Length;
519 		ap = (ACPI_SUBTABLE_HEADER *)(((char *)ap) + ap->Length);
520 	}
521 
522 	/*
523 	 * One more check; if ISO said "conform", revert to default
524 	 */
525 	if (sci_flags->intr_el == INTR_EL_CONFORM)
526 		sci_flags->intr_el = INTR_EL_LEVEL;
527 	if (sci_flags->intr_po == INTR_PO_CONFORM)
528 		sci_flags->intr_po = INTR_PO_ACTIVE_LOW;
529 
530 	return (AE_OK);
531 }
532 
533 /*
534  * Sets ACPI wake state for device referenced by dip.
535  * If level is S0 (0), disables wake event; otherwise,
536  * enables wake event which will wake system from level.
537  */
538 static int
539 acpica_ddi_setwake(dev_info_t *dip, int level)
540 {
541 	ACPI_STATUS	status;
542 	ACPI_HANDLE	devobj, gpeobj;
543 	ACPI_OBJECT	*prw, *gpe;
544 	ACPI_BUFFER	prw_buf;
545 	int		gpebit, pwr_res_count, prw_level, rv;
546 
547 	/*
548 	 * initialize these early so we can use a common
549 	 * exit point below
550 	 */
551 	prw_buf.Pointer = NULL;
552 	prw_buf.Length = ACPI_ALLOCATE_BUFFER;
553 	rv = 0;
554 
555 	/*
556 	 * Attempt to get a handle to a corresponding ACPI object.
557 	 * If no object is found, return quietly, since not all
558 	 * devices have corresponding ACPI objects.
559 	 */
560 	status = acpica_get_handle(dip, &devobj);
561 	if (ACPI_FAILURE(status)) {
562 		char pathbuf[MAXPATHLEN];
563 		ddi_pathname(dip, pathbuf);
564 #ifdef DEBUG
565 		cmn_err(CE_NOTE, "!acpica_ddi_setwake: could not get"
566 		    " handle for %s, %s:%d", pathbuf, ddi_driver_name(dip),
567 		    ddi_get_instance(dip));
568 #endif
569 		goto done;
570 	}
571 
572 	/*
573 	 * Attempt to evaluate _PRW object.
574 	 * If no valid object is found, return quietly, since not all
575 	 * devices have _PRW objects.
576 	 */
577 	status = AcpiEvaluateObject(devobj, "_PRW", NULL, &prw_buf);
578 	prw = prw_buf.Pointer;
579 	if (ACPI_FAILURE(status) || prw_buf.Length == 0 || prw == NULL ||
580 	    prw->Type != ACPI_TYPE_PACKAGE || prw->Package.Count < 2 ||
581 	    prw->Package.Elements[1].Type != ACPI_TYPE_INTEGER) {
582 		cmn_err(CE_NOTE, "acpica_ddi_setwake: could not "
583 		    " evaluate _PRW");
584 		goto done;
585 	}
586 
587 	/* fetch the lowest wake level from the _PRW */
588 	prw_level = prw->Package.Elements[1].Integer.Value;
589 
590 	/*
591 	 * process the GPE description
592 	 */
593 	switch (prw->Package.Elements[0].Type) {
594 	case ACPI_TYPE_INTEGER:
595 		gpeobj = NULL;
596 		gpebit = prw->Package.Elements[0].Integer.Value;
597 		break;
598 	case ACPI_TYPE_PACKAGE:
599 		gpe = &prw->Package.Elements[0];
600 		if (gpe->Package.Count != 2 ||
601 		    gpe->Package.Elements[1].Type != ACPI_TYPE_INTEGER)
602 			goto done;
603 		gpeobj = gpe->Package.Elements[0].Reference.Handle;
604 		gpebit = gpe->Package.Elements[1].Integer.Value;
605 		if (gpeobj == NULL)
606 			goto done;
607 	default:
608 		goto done;
609 	}
610 
611 	rv = -1;
612 	if (level == 0) {
613 		if (ACPI_FAILURE(AcpiDisableGpe(gpeobj, gpebit, ACPI_NOT_ISR)))
614 			goto done;
615 	} else if (prw_level <= level) {
616 		if (ACPI_SUCCESS(
617 		    AcpiSetGpeType(gpeobj, gpebit, ACPI_GPE_TYPE_WAKE)))
618 			if (ACPI_FAILURE(
619 			    AcpiEnableGpe(gpeobj, gpebit, ACPI_NOT_ISR)))
620 				goto done;
621 	}
622 	rv = 0;
623 done:
624 	if (prw_buf.Pointer != NULL)
625 		AcpiOsFree(prw_buf.Pointer);
626 	return (rv);
627 }
628 
629 /*
630  * kstat access to a limited set of ACPI propertis
631  */
632 static void
633 acpica_init_kstats()
634 {
635 	ACPI_HANDLE	s3handle;
636 	ACPI_STATUS	status;
637 	ACPI_TABLE_FADT	*fadt;
638 	kstat_named_t *knp;
639 
640 	/*
641 	 * Create a small set of named kstats; just return in the rare
642 	 * case of a failure, * in which case, the kstats won't be present.
643 	 */
644 	if ((acpica_ksp = kstat_create("acpi", 0, "acpi", "misc",
645 	    KSTAT_TYPE_NAMED, 2, 0)) == NULL)
646 		return;
647 
648 	/*
649 	 * initialize kstat 'S3' to reflect the presence of \_S3 in
650 	 * the ACPI namespace (1 = present, 0 = not present)
651 	 */
652 	knp = acpica_ksp->ks_data;
653 	knp->value.l = (AcpiGetHandle(NULL, "\\_S3", &s3handle) == AE_OK);
654 	kstat_named_init(knp, "S3", KSTAT_DATA_LONG);
655 	knp++;		/* advance to next named kstat */
656 
657 	/*
658 	 * initialize kstat 'preferred_pm_profile' to the value
659 	 * contained in the (always present) FADT
660 	 */
661 	status = AcpiGetTable(ACPI_SIG_FADT, 1, (ACPI_TABLE_HEADER **)&fadt);
662 	knp->value.l = (status == AE_OK) ? fadt->PreferredProfile : -1;
663 	kstat_named_init(knp, "preferred_pm_profile", KSTAT_DATA_LONG);
664 
665 	/*
666 	 * install the named kstats
667 	 */
668 	kstat_install(acpica_ksp);
669 }
670 
671 /*
672  * Attempt to save the current ACPI settings (_CRS) for the device
673  * which corresponds to the supplied devinfo node.  The settings are
674  * saved as a property on the dip.  If no ACPI object is found to be
675  * associated with the devinfo node, no action is taken and no error
676  * is reported.
677  */
678 void
679 acpica_ddi_save_resources(dev_info_t *dip)
680 {
681 	ACPI_HANDLE	devobj;
682 	ACPI_BUFFER	resbuf;
683 	int		ret;
684 
685 	resbuf.Length = ACPI_ALLOCATE_BUFFER;
686 	if (ACPI_FAILURE(acpica_get_handle(dip, &devobj)) ||
687 	    ACPI_FAILURE(AcpiGetCurrentResources(devobj, &resbuf)))
688 		return;
689 
690 	ret = ddi_prop_create(DDI_DEV_T_NONE, dip, DDI_PROP_CANSLEEP,
691 	    "acpi-crs", resbuf.Pointer, resbuf.Length);
692 
693 	ASSERT(ret == DDI_PROP_SUCCESS);
694 
695 	AcpiOsFree(resbuf.Pointer);
696 }
697 
698 /*
699  * If the supplied devinfo node has an ACPI settings property attached,
700  * restore them to the associated ACPI device using _SRS.  The property
701  * is deleted from the devinfo node afterward.
702  */
703 void
704 acpica_ddi_restore_resources(dev_info_t *dip)
705 {
706 	ACPI_HANDLE	devobj;
707 	ACPI_BUFFER	resbuf;
708 	uchar_t		*propdata;
709 	uint_t		proplen;
710 
711 	if (ACPI_FAILURE(acpica_get_handle(dip, &devobj)))
712 		return;
713 
714 	if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
715 	    "acpi-crs", &propdata, &proplen) != DDI_PROP_SUCCESS)
716 		return;
717 
718 	resbuf.Pointer = propdata;
719 	resbuf.Length = proplen;
720 	(void) AcpiSetCurrentResources(devobj, &resbuf);
721 	ddi_prop_free(propdata);
722 	(void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "acpi-crs");
723 }
724 
725 void
726 acpi_reset_system(void)
727 {
728 	ACPI_STATUS status;
729 	int ten;
730 
731 	status = AcpiReset();
732 	if (status == AE_OK) {
733 		/*
734 		 * Wait up to 500 milliseconds for AcpiReset() to make its
735 		 * way.
736 		 */
737 		ten = 50000;
738 		while (ten-- > 0)
739 			tenmicrosec();
740 	}
741 }
742