1/*- 2 * Copyright (c) 2000 Michael Smith 3 * Copyright (c) 2000 BSDi 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 10 unchanged lines hidden (view full) --- 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * |
27 * $FreeBSD: head/sys/dev/acpica/Osd/OsdSchedule.c 71875 2001-01-31 09:34:54Z msmith $ |
28 */ 29 30/* 31 * 6.3 : Scheduling services 32 */ 33 34#include "acpi.h" 35 36#include <sys/kernel.h> 37#include <sys/malloc.h> 38#include <sys/taskqueue.h> 39#include <machine/clock.h> 40 |
41#define _COMPONENT OS_DEPENDENT 42MODULE_NAME("SCHEDULE") 43 |
44/* 45 * This is a little complicated due to the fact that we need to build and then 46 * free a 'struct task' for each task we enqueue. 47 * 48 * We use the default taskqueue_swi queue, since it really doesn't matter what 49 * else we're queued along with. 50 */ 51 --- 7 unchanged lines hidden (view full) --- 59 void *at_context; 60}; 61 62ACPI_STATUS 63AcpiOsQueueForExecution(UINT32 Priority, OSD_EXECUTION_CALLBACK Function, void *Context) 64{ 65 struct acpi_task *at; 66 |
67 FUNCTION_TRACE(__FUNCTION__); 68 |
69 if (Function == NULL) |
70 return_ACPI_STATUS(AE_BAD_PARAMETER); |
71 72 at = malloc(sizeof(*at), M_ACPITASK, M_NOWAIT); /* Interrupt Context */ 73 if (at == NULL) |
74 return_ACPI_STATUS(AE_NO_MEMORY); |
75 bzero(at, sizeof(*at)); 76 77 at->at_function = Function; 78 at->at_context = Context; 79 at->at_task.ta_func = AcpiOsExecuteQueue; 80 at->at_task.ta_context = at; 81 switch (Priority) { 82 case OSD_PRIORITY_GPE: --- 5 unchanged lines hidden (view full) --- 88 case OSD_PRIORITY_MED: 89 at->at_task.ta_priority = 2; 90 break; 91 case OSD_PRIORITY_LO: 92 at->at_task.ta_priority = 1; 93 break; 94 default: 95 free(at, M_ACPITASK); |
96 return_ACPI_STATUS(AE_BAD_PARAMETER); |
97 } 98 99 taskqueue_enqueue(taskqueue_swi, (struct task *)at); |
100 return_ACPI_STATUS(AE_OK); |
101} 102 103static void 104AcpiOsExecuteQueue(void *arg, int pending) 105{ 106 struct acpi_task *at = (struct acpi_task *)arg; 107 OSD_EXECUTION_CALLBACK Function; 108 void *Context; 109 |
110 FUNCTION_TRACE(__FUNCTION__); 111 |
112 Function = (OSD_EXECUTION_CALLBACK)at->at_function; 113 Context = at->at_context; 114 115 free(at, M_ACPITASK); 116 117 Function(Context); |
118 return_VOID; |
119} 120 121/* 122 * We don't have any sleep granularity better than hz, so 123 * make do with that. 124 */ 125void 126AcpiOsSleep (UINT32 Seconds, UINT32 Milliseconds) 127{ 128 int timo; 129 |
130 FUNCTION_TRACE(__FUNCTION__); 131 |
132 timo = (Seconds * hz) + Milliseconds / (1000 * hz); 133 if (timo == 0) 134 timo = 1; 135 tsleep(NULL, 0, "acpislp", timo); |
136 return_VOID; |
137} 138 139void 140AcpiOsSleepUsec (UINT32 Microseconds) 141{ |
142 FUNCTION_TRACE(__FUNCTION__); 143 |
144 if (Microseconds > 1000) { /* long enough to be worth the overhead of sleeping */ 145 AcpiOsSleep(0, Microseconds / 1000); 146 } else { 147 DELAY(Microseconds); 148 } |
149 return_VOID; |
150} |