2000-10-28 06:56:15 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2000 Michael Smith
|
|
|
|
* Copyright (c) 2000 BSDi
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 6.3 : Scheduling services
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "acpi.h"
|
|
|
|
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/malloc.h>
|
2001-05-30 05:34:10 +00:00
|
|
|
#include <sys/proc.h>
|
2000-10-28 06:56:15 +00:00
|
|
|
#include <sys/taskqueue.h>
|
|
|
|
#include <machine/clock.h>
|
|
|
|
|
2001-05-29 20:13:42 +00:00
|
|
|
#define _COMPONENT ACPI_OS_SERVICES
|
2001-01-31 09:34:54 +00:00
|
|
|
MODULE_NAME("SCHEDULE")
|
|
|
|
|
2000-10-28 06:56:15 +00:00
|
|
|
/*
|
|
|
|
* This is a little complicated due to the fact that we need to build and then
|
|
|
|
* free a 'struct task' for each task we enqueue.
|
|
|
|
*
|
|
|
|
* We use the default taskqueue_swi queue, since it really doesn't matter what
|
|
|
|
* else we're queued along with.
|
|
|
|
*/
|
|
|
|
|
|
|
|
MALLOC_DEFINE(M_ACPITASK, "acpitask", "ACPI deferred task");
|
|
|
|
|
|
|
|
static void AcpiOsExecuteQueue(void *arg, int pending);
|
|
|
|
|
|
|
|
struct acpi_task {
|
|
|
|
struct task at_task;
|
|
|
|
OSD_EXECUTION_CALLBACK at_function;
|
|
|
|
void *at_context;
|
|
|
|
};
|
|
|
|
|
|
|
|
ACPI_STATUS
|
|
|
|
AcpiOsQueueForExecution(UINT32 Priority, OSD_EXECUTION_CALLBACK Function, void *Context)
|
|
|
|
{
|
|
|
|
struct acpi_task *at;
|
2001-10-25 19:56:02 +00:00
|
|
|
int pri;
|
2000-10-28 06:56:15 +00:00
|
|
|
|
2001-05-29 20:13:42 +00:00
|
|
|
FUNCTION_TRACE(__func__);
|
2001-01-31 09:34:54 +00:00
|
|
|
|
2000-10-28 06:56:15 +00:00
|
|
|
if (Function == NULL)
|
2001-01-31 09:34:54 +00:00
|
|
|
return_ACPI_STATUS(AE_BAD_PARAMETER);
|
2000-10-28 06:56:15 +00:00
|
|
|
|
2001-01-23 09:43:23 +00:00
|
|
|
at = malloc(sizeof(*at), M_ACPITASK, M_NOWAIT); /* Interrupt Context */
|
|
|
|
if (at == NULL)
|
2001-01-31 09:34:54 +00:00
|
|
|
return_ACPI_STATUS(AE_NO_MEMORY);
|
2000-10-28 06:56:15 +00:00
|
|
|
bzero(at, sizeof(*at));
|
|
|
|
|
|
|
|
at->at_function = Function;
|
|
|
|
at->at_context = Context;
|
|
|
|
switch (Priority) {
|
2000-12-20 19:15:38 +00:00
|
|
|
case OSD_PRIORITY_GPE:
|
2001-10-25 19:56:02 +00:00
|
|
|
pri = 4;
|
2000-12-20 19:15:38 +00:00
|
|
|
break;
|
2000-10-28 06:56:15 +00:00
|
|
|
case OSD_PRIORITY_HIGH:
|
2001-10-25 19:56:02 +00:00
|
|
|
pri = 3;
|
2000-10-28 06:56:15 +00:00
|
|
|
break;
|
|
|
|
case OSD_PRIORITY_MED:
|
2001-10-25 19:56:02 +00:00
|
|
|
pri = 2;
|
2000-10-28 06:56:15 +00:00
|
|
|
break;
|
|
|
|
case OSD_PRIORITY_LO:
|
2001-10-25 19:56:02 +00:00
|
|
|
pri = 1;
|
2000-10-28 06:56:15 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
free(at, M_ACPITASK);
|
2001-01-31 09:34:54 +00:00
|
|
|
return_ACPI_STATUS(AE_BAD_PARAMETER);
|
2000-10-28 06:56:15 +00:00
|
|
|
}
|
2001-10-25 19:56:02 +00:00
|
|
|
TASK_INIT(&at->at_task, pri, AcpiOsExecuteQueue, at);
|
2000-10-28 06:56:15 +00:00
|
|
|
|
|
|
|
taskqueue_enqueue(taskqueue_swi, (struct task *)at);
|
2001-01-31 09:34:54 +00:00
|
|
|
return_ACPI_STATUS(AE_OK);
|
2000-10-28 06:56:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
AcpiOsExecuteQueue(void *arg, int pending)
|
|
|
|
{
|
|
|
|
struct acpi_task *at = (struct acpi_task *)arg;
|
|
|
|
OSD_EXECUTION_CALLBACK Function;
|
|
|
|
void *Context;
|
|
|
|
|
2001-05-29 20:13:42 +00:00
|
|
|
FUNCTION_TRACE(__func__);
|
2001-01-31 09:34:54 +00:00
|
|
|
|
2000-10-28 06:56:15 +00:00
|
|
|
Function = (OSD_EXECUTION_CALLBACK)at->at_function;
|
|
|
|
Context = at->at_context;
|
|
|
|
|
|
|
|
free(at, M_ACPITASK);
|
|
|
|
|
|
|
|
Function(Context);
|
2001-01-31 09:34:54 +00:00
|
|
|
return_VOID;
|
2000-10-28 06:56:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We don't have any sleep granularity better than hz, so
|
|
|
|
* make do with that.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
AcpiOsSleep (UINT32 Seconds, UINT32 Milliseconds)
|
|
|
|
{
|
|
|
|
int timo;
|
2001-05-29 20:13:42 +00:00
|
|
|
static int dummy;
|
2000-10-28 06:56:15 +00:00
|
|
|
|
2001-05-29 20:13:42 +00:00
|
|
|
FUNCTION_TRACE(__func__);
|
2001-01-31 09:34:54 +00:00
|
|
|
|
2001-05-29 20:13:42 +00:00
|
|
|
timo = (Seconds * hz) + Milliseconds * hz / 1000;
|
2000-10-28 06:56:15 +00:00
|
|
|
if (timo == 0)
|
|
|
|
timo = 1;
|
2001-05-29 20:13:42 +00:00
|
|
|
tsleep(&dummy, 0, "acpislp", timo);
|
2001-01-31 09:34:54 +00:00
|
|
|
return_VOID;
|
2000-10-28 06:56:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-07-21 04:10:01 +00:00
|
|
|
AcpiOsStall (UINT32 Microseconds)
|
2000-10-28 06:56:15 +00:00
|
|
|
{
|
2001-05-29 20:13:42 +00:00
|
|
|
FUNCTION_TRACE(__func__);
|
2001-01-31 09:34:54 +00:00
|
|
|
|
2001-09-08 17:03:26 +00:00
|
|
|
DELAY(Microseconds);
|
2001-01-31 09:34:54 +00:00
|
|
|
return_VOID;
|
2000-10-28 06:56:15 +00:00
|
|
|
}
|
2001-05-29 20:13:42 +00:00
|
|
|
|
|
|
|
UINT32
|
|
|
|
AcpiOsGetThreadId (void)
|
|
|
|
{
|
|
|
|
/* XXX do not add FUNCTION_TRACE here, results in recursive call */
|
|
|
|
|
|
|
|
KASSERT(curproc != NULL, (__func__ ": curproc is NULL!"));
|
|
|
|
return(curproc->p_pid + 1); /* can't return 0 */
|
|
|
|
}
|