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