xref: /titanic_41/usr/src/uts/intel/io/acpica/acpica.c (revision 5bbb4db2c3f208d12bf0fd11769728f9e5ba66a2)
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 	/* do after AcpiEnableSubsystem() so GPEs are initialized */
412 	acpica_ec_init();	/* initialize EC if present */
413 
414 	if (ACPI_FAILURE(status = AcpiInitializeObjects(0)))
415 		goto error;
416 
417 	acpica_init_state = ACPICA_INITIALIZED;
418 
419 	/*
420 	 * If we are running on the Xen hypervisor as dom0 we need to
421 	 * find the ioapics so we can prevent ACPI from trying to
422 	 * access them.
423 	 */
424 	if (get_hwenv() == HW_XEN_PV && is_controldom())
425 		acpica_find_ioapics();
426 	acpica_init_kstats();
427 error:
428 	if (acpica_init_state != ACPICA_INITIALIZED) {
429 		cmn_err(CE_NOTE, "!failed to initialize ACPI services");
430 	}
431 
432 	/*
433 	 * Set acpi-status to 13 if acpica has been initialized successfully.
434 	 * This indicates that acpica is up and running.  This variable name
435 	 * and value were chosen in order to remain compatible with acpi_intp.
436 	 */
437 	e_ddi_prop_update_int(DDI_DEV_T_NONE, ddi_root_node(), "acpi-status",
438 	    (ACPI_SUCCESS(status)) ? (ACPI_BOOT_INIT | ACPI_BOOT_ENABLE |
439 	    ACPI_BOOT_BOOTCONF) : 0);
440 
441 	/* Mark acpica subsystem as fully initialized. */
442 	if (ACPI_SUCCESS(status) &&
443 	    acpi_init_level == ACPI_FULL_INITIALIZATION) {
444 		acpica_set_core_feature(ACPI_FEATURE_FULL_INIT);
445 	}
446 
447 	mutex_exit(&acpica_module_lock);
448 	return (status);
449 }
450 
451 /*
452  * SCI handling
453  */
454 
455 ACPI_STATUS
456 acpica_get_sci(int *sci_irq, iflag_t *sci_flags)
457 {
458 	ACPI_SUBTABLE_HEADER		*ap;
459 	ACPI_TABLE_MADT			*mat;
460 	ACPI_MADT_INTERRUPT_OVERRIDE	*mio;
461 	ACPI_TABLE_FADT			*fadt;
462 	int			madt_seen, madt_size;
463 
464 
465 	/*
466 	 * Make sure user options are processed,
467 	 * then return error if ACPI CA has been
468 	 * disabled or system is not running in ACPI
469 	 * and won't need/understand SCI
470 	 */
471 	acpica_process_user_options();
472 	if ((!acpica_enable) || (acpi_init_level & ACPI_NO_ACPI_ENABLE))
473 		return (AE_ERROR);
474 
475 	/*
476 	 * according to Intel ACPI developers, SCI
477 	 * conforms to PCI bus conventions; level/low
478 	 * unless otherwise directed by overrides.
479 	 */
480 	sci_flags->intr_el = INTR_EL_LEVEL;
481 	sci_flags->intr_po = INTR_PO_ACTIVE_LOW;
482 	sci_flags->bustype = BUS_PCI;	/*  we *do* conform to PCI */
483 
484 	/* get the SCI from the FADT */
485 	if (AcpiGetTable(ACPI_SIG_FADT, 1, (ACPI_TABLE_HEADER **)&fadt) !=
486 	    AE_OK)
487 		return (AE_ERROR);
488 
489 	*sci_irq = fadt->SciInterrupt;
490 
491 	/* search for ISOs that modify it */
492 	/* if we don't find a MADT, that's OK; no ISOs then */
493 	if (AcpiGetTable(ACPI_SIG_MADT, 1, (ACPI_TABLE_HEADER **) &mat) !=
494 	    AE_OK)
495 		return (AE_OK);
496 
497 	ap = (ACPI_SUBTABLE_HEADER *) (mat + 1);
498 	madt_size = mat->Header.Length;
499 	madt_seen = sizeof (*mat);
500 
501 	while (madt_seen < madt_size) {
502 		switch (ap->Type) {
503 		case ACPI_MADT_TYPE_INTERRUPT_OVERRIDE:
504 			mio = (ACPI_MADT_INTERRUPT_OVERRIDE *) ap;
505 			if (mio->SourceIrq == *sci_irq) {
506 				*sci_irq = mio->GlobalIrq;
507 				sci_flags->intr_el = (mio->IntiFlags &
508 				    ACPI_MADT_TRIGGER_MASK) >> 2;
509 				sci_flags->intr_po = mio->IntiFlags &
510 				    ACPI_MADT_POLARITY_MASK;
511 			}
512 			break;
513 		}
514 
515 		/* advance to next entry */
516 		madt_seen += ap->Length;
517 		ap = (ACPI_SUBTABLE_HEADER *)(((char *)ap) + ap->Length);
518 	}
519 
520 	/*
521 	 * One more check; if ISO said "conform", revert to default
522 	 */
523 	if (sci_flags->intr_el == INTR_EL_CONFORM)
524 		sci_flags->intr_el = INTR_EL_LEVEL;
525 	if (sci_flags->intr_po == INTR_PO_CONFORM)
526 		sci_flags->intr_po = INTR_PO_ACTIVE_LOW;
527 
528 	return (AE_OK);
529 }
530 
531 /*
532  * Sets ACPI wake state for device referenced by dip.
533  * If level is S0 (0), disables wake event; otherwise,
534  * enables wake event which will wake system from level.
535  */
536 static int
537 acpica_ddi_setwake(dev_info_t *dip, int level)
538 {
539 	ACPI_STATUS	status;
540 	ACPI_HANDLE	devobj, gpeobj;
541 	ACPI_OBJECT	*prw, *gpe;
542 	ACPI_BUFFER	prw_buf;
543 	int		gpebit, pwr_res_count, prw_level, rv;
544 
545 	/*
546 	 * initialize these early so we can use a common
547 	 * exit point below
548 	 */
549 	prw_buf.Pointer = NULL;
550 	prw_buf.Length = ACPI_ALLOCATE_BUFFER;
551 	rv = 0;
552 
553 	/*
554 	 * Attempt to get a handle to a corresponding ACPI object.
555 	 * If no object is found, return quietly, since not all
556 	 * devices have corresponding ACPI objects.
557 	 */
558 	status = acpica_get_handle(dip, &devobj);
559 	if (ACPI_FAILURE(status)) {
560 		char pathbuf[MAXPATHLEN];
561 		ddi_pathname(dip, pathbuf);
562 #ifdef DEBUG
563 		cmn_err(CE_NOTE, "!acpica_ddi_setwake: could not get"
564 		    " handle for %s, %s:%d", pathbuf, ddi_driver_name(dip),
565 		    ddi_get_instance(dip));
566 #endif
567 		goto done;
568 	}
569 
570 	/*
571 	 * Attempt to evaluate _PRW object.
572 	 * If no valid object is found, return quietly, since not all
573 	 * devices have _PRW objects.
574 	 */
575 	status = AcpiEvaluateObject(devobj, "_PRW", NULL, &prw_buf);
576 	prw = prw_buf.Pointer;
577 	if (ACPI_FAILURE(status) || prw_buf.Length == 0 || prw == NULL ||
578 	    prw->Type != ACPI_TYPE_PACKAGE || prw->Package.Count < 2 ||
579 	    prw->Package.Elements[1].Type != ACPI_TYPE_INTEGER) {
580 		cmn_err(CE_NOTE, "acpica_ddi_setwake: could not "
581 		    " evaluate _PRW");
582 		goto done;
583 	}
584 
585 	/* fetch the lowest wake level from the _PRW */
586 	prw_level = prw->Package.Elements[1].Integer.Value;
587 
588 	/*
589 	 * process the GPE description
590 	 */
591 	switch (prw->Package.Elements[0].Type) {
592 	case ACPI_TYPE_INTEGER:
593 		gpeobj = NULL;
594 		gpebit = prw->Package.Elements[0].Integer.Value;
595 		break;
596 	case ACPI_TYPE_PACKAGE:
597 		gpe = &prw->Package.Elements[0];
598 		if (gpe->Package.Count != 2 ||
599 		    gpe->Package.Elements[1].Type != ACPI_TYPE_INTEGER)
600 			goto done;
601 		gpeobj = gpe->Package.Elements[0].Reference.Handle;
602 		gpebit = gpe->Package.Elements[1].Integer.Value;
603 		if (gpeobj == NULL)
604 			goto done;
605 	default:
606 		goto done;
607 	}
608 
609 	rv = -1;
610 	if (level == 0) {
611 		if (ACPI_FAILURE(AcpiDisableGpe(gpeobj, gpebit, ACPI_NOT_ISR)))
612 			goto done;
613 	} else if (prw_level <= level) {
614 		if (ACPI_SUCCESS(
615 		    AcpiSetGpeType(gpeobj, gpebit, ACPI_GPE_TYPE_WAKE)))
616 			if (ACPI_FAILURE(
617 			    AcpiEnableGpe(gpeobj, gpebit, ACPI_NOT_ISR)))
618 				goto done;
619 	}
620 	rv = 0;
621 done:
622 	if (prw_buf.Pointer != NULL)
623 		AcpiOsFree(prw_buf.Pointer);
624 	return (rv);
625 }
626 
627 /*
628  * kstat access to a limited set of ACPI propertis
629  */
630 static void
631 acpica_init_kstats()
632 {
633 	ACPI_HANDLE	s3handle;
634 	ACPI_STATUS	status;
635 	ACPI_TABLE_FADT	*fadt;
636 	kstat_named_t *knp;
637 
638 	/*
639 	 * Create a small set of named kstats; just return in the rare
640 	 * case of a failure, * in which case, the kstats won't be present.
641 	 */
642 	if ((acpica_ksp = kstat_create("acpi", 0, "acpi", "misc",
643 	    KSTAT_TYPE_NAMED, 2, 0)) == NULL)
644 		return;
645 
646 	/*
647 	 * initialize kstat 'S3' to reflect the presence of \_S3 in
648 	 * the ACPI namespace (1 = present, 0 = not present)
649 	 */
650 	knp = acpica_ksp->ks_data;
651 	knp->value.l = (AcpiGetHandle(NULL, "\\_S3", &s3handle) == AE_OK);
652 	kstat_named_init(knp, "S3", KSTAT_DATA_LONG);
653 	knp++;		/* advance to next named kstat */
654 
655 	/*
656 	 * initialize kstat 'preferred_pm_profile' to the value
657 	 * contained in the (always present) FADT
658 	 */
659 	status = AcpiGetTable(ACPI_SIG_FADT, 1, (ACPI_TABLE_HEADER **)&fadt);
660 	knp->value.l = (status == AE_OK) ? fadt->PreferredProfile : -1;
661 	kstat_named_init(knp, "preferred_pm_profile", KSTAT_DATA_LONG);
662 
663 	/*
664 	 * install the named kstats
665 	 */
666 	kstat_install(acpica_ksp);
667 }
668 
669 /*
670  * Attempt to save the current ACPI settings (_CRS) for the device
671  * which corresponds to the supplied devinfo node.  The settings are
672  * saved as a property on the dip.  If no ACPI object is found to be
673  * associated with the devinfo node, no action is taken and no error
674  * is reported.
675  */
676 void
677 acpica_ddi_save_resources(dev_info_t *dip)
678 {
679 	ACPI_HANDLE	devobj;
680 	ACPI_BUFFER	resbuf;
681 	int		ret;
682 
683 	resbuf.Length = ACPI_ALLOCATE_BUFFER;
684 	if (ACPI_FAILURE(acpica_get_handle(dip, &devobj)) ||
685 	    ACPI_FAILURE(AcpiGetCurrentResources(devobj, &resbuf)))
686 		return;
687 
688 	ret = ddi_prop_create(DDI_DEV_T_NONE, dip, DDI_PROP_CANSLEEP,
689 	    "acpi-crs", resbuf.Pointer, resbuf.Length);
690 
691 	ASSERT(ret == DDI_PROP_SUCCESS);
692 
693 	AcpiOsFree(resbuf.Pointer);
694 }
695 
696 /*
697  * If the supplied devinfo node has an ACPI settings property attached,
698  * restore them to the associated ACPI device using _SRS.  The property
699  * is deleted from the devinfo node afterward.
700  */
701 void
702 acpica_ddi_restore_resources(dev_info_t *dip)
703 {
704 	ACPI_HANDLE	devobj;
705 	ACPI_BUFFER	resbuf;
706 	uchar_t		*propdata;
707 	uint_t		proplen;
708 
709 	if (ACPI_FAILURE(acpica_get_handle(dip, &devobj)))
710 		return;
711 
712 	if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
713 	    "acpi-crs", &propdata, &proplen) != DDI_PROP_SUCCESS)
714 		return;
715 
716 	resbuf.Pointer = propdata;
717 	resbuf.Length = proplen;
718 	(void) AcpiSetCurrentResources(devobj, &resbuf);
719 	ddi_prop_free(propdata);
720 	(void) ddi_prop_remove(DDI_DEV_T_NONE, dip, "acpi-crs");
721 }
722 
723 void
724 acpi_reset_system(void)
725 {
726 	ACPI_STATUS status;
727 	int ten;
728 
729 	status = AcpiReset();
730 	if (status == AE_OK) {
731 		/*
732 		 * Wait up to 500 milliseconds for AcpiReset() to make its
733 		 * way.
734 		 */
735 		ten = 50000;
736 		while (ten-- > 0)
737 			tenmicrosec();
738 	}
739 }
740