1 /* $NetBSD: OsdSchedule.c,v 1.11 2009/08/18 16:41:02 jmcneill Exp $ */
4 * Copyright 2001 Wasabi Systems, Inc.
7 * Written by Jason R. Thorpe for Wasabi Systems, Inc.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed for the NetBSD Project by
20 * Wasabi Systems, Inc.
21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 * or promote products derived from this software without specific prior
25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
41 * 6.3: Scheduling services
44 #include <sys/cdefs.h>
45 __KERNEL_RCSID(0, "$NetBSD: OsdSchedule.c,v 1.11 2009/08/18 16:41:02 jmcneill Exp $");
47 #include <sys/param.h>
48 #include <sys/malloc.h>
50 #include <sys/systm.h>
51 #include <sys/kernel.h>
52 #include <sys/condvar.h>
53 #include <sys/mutex.h>
55 #include <dev/acpi/acpica.h>
57 #include <dev/acpi/acpi_osd.h>
59 #include <dev/sysmon/sysmon_taskq.h>
61 extern int acpi_suspended
;
63 #define _COMPONENT ACPI_OS_SERVICES
64 ACPI_MODULE_NAME("SCHEDULE")
66 static kcondvar_t acpi_osd_sleep_cv
;
67 static kmutex_t acpi_osd_sleep_mtx
;
70 * acpi_osd_sched_init:
72 * Initialize the APCICA Osd scheduler. Called from AcpiOsInitialize().
75 acpi_osd_sched_init(void)
77 sysmon_task_queue_init();
78 mutex_init(&acpi_osd_sleep_mtx
, MUTEX_DEFAULT
, IPL_NONE
);
79 cv_init(&acpi_osd_sleep_cv
, "acpislp");
85 * Obtain the ID of the currently executing thread.
88 AcpiOsGetThreadId(void)
90 return (ACPI_THREAD_ID
)curlwp
;
94 * AcpiOsQueueForExecution:
96 * Schedule a procedure for deferred execution.
99 AcpiOsExecute(ACPI_EXECUTE_TYPE Type
, ACPI_OSD_EXEC_CALLBACK Function
,
105 case OSL_GPE_HANDLER
:
108 case OSL_GLOBAL_LOCK_HANDLER
:
109 case OSL_EC_POLL_HANDLER
:
110 case OSL_EC_BURST_HANDLER
:
113 case OSL_NOTIFY_HANDLER
:
116 case OSL_DEBUGGER_THREAD
:
120 return AE_BAD_PARAMETER
;
123 switch (sysmon_task_queue_sched(pri
, Function
, Context
)) {
131 return AE_BAD_PARAMETER
;
138 * Suspend the running task (coarse granularity).
141 AcpiOsSleep(ACPI_INTEGER Milliseconds
)
143 if (cold
|| doing_shutdown
|| acpi_suspended
)
144 DELAY(Milliseconds
* 1000);
146 mutex_enter(&acpi_osd_sleep_mtx
);
147 cv_timedwait_sig(&acpi_osd_sleep_cv
, &acpi_osd_sleep_mtx
,
148 MAX(mstohz(Milliseconds
), 1));
149 mutex_exit(&acpi_osd_sleep_mtx
);
156 * Suspend the running task (fine granularity).
159 AcpiOsStall(UINT32 Microseconds
)
162 * sleep(9) isn't safe because AcpiOsStall may be called
163 * with interrupt-disabled. (eg. by AcpiEnterSleepState)
164 * we should watch out for long stall requests.
167 if (Microseconds
> 1000)
168 ACPI_DEBUG_PRINT((ACPI_DB_INFO
, "long stall: %uus\n",
178 * Get the current system time in 100 nanosecond units
186 /* XXX During early boot there is no (decent) timer available yet. */
188 panic("acpi: timer op not yet supported during boot");
191 t
= (UINT64
)10 * tv
.tv_usec
;
192 t
+= (UINT64
)10000000 * tv
.tv_sec
;