]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/acpica/lib-acpi/src/osl-basic.cc
update
[l4.git] / l4 / pkg / acpica / lib-acpi / src / osl-basic.cc
1 #include <l4/sys/compiler.h>
2
3 __BEGIN_DECLS
4 #include "acpi.h"
5 #include "acpiosxf.h"
6 #include "actypes.h"
7 __END_DECLS
8
9 #include <stdlib.h>
10 #include <stdint.h>
11 #include <stdio.h>
12 #include <sys/time.h>
13
14 #include <l4/util/util.h>
15 #if defined(ARCH_amd64) || defined(ARCH_x86)
16 #include <l4/util/port_io.h>
17 #endif
18
19 #include <l4/re/env>
20 #include <l4/re/rm>
21
22 #include <l4/re/util/cap_alloc>
23
24 #define DEBUG_OSL_PORT_IO 0
25
26
27 ACPI_STATUS
28 AcpiOsInitialize (void)
29 {
30   return AE_OK;
31 }
32
33 ACPI_STATUS
34 AcpiOsTerminate (void)
35 {
36   return AE_OK;
37 }
38
39 void *
40 AcpiOsAllocate (ACPI_SIZE size)
41 {
42   return malloc(size);
43 }
44
45 void
46 AcpiOsFree (void * memory)
47 {
48   free(memory);
49   return;
50 }
51
52 void
53 AcpiOsSleep (ACPI_INTEGER milliseconds)
54 {
55   l4_sleep(milliseconds);
56 }
57
58 void
59 AcpiOsStall (uint32_t microseconds)
60 {
61   l4_usleep(microseconds);
62 }
63
64
65 /******************************************************************************
66  *
67  * FUNCTION:    AcpiOsPredefinedOverride
68  *
69  * PARAMETERS:  InitVal     - Initial value of the predefined object
70  *              NewVal      - The new value for the object
71  *
72  * RETURN:      Status, pointer to value.  Null pointer returned if not
73  *              overriding.
74  *
75  * DESCRIPTION: Allow the OS to override predefined names
76  *
77  *****************************************************************************/
78
79 ACPI_STATUS
80 AcpiOsPredefinedOverride (
81     const ACPI_PREDEFINED_NAMES *InitVal,
82     ACPI_STRING                 *NewVal)
83 {
84
85     if (!InitVal || !NewVal)
86     {
87         return (AE_BAD_PARAMETER);
88     }
89
90     *NewVal = NULL;
91     return (AE_OK);
92 }
93
94
95 /******************************************************************************
96  *
97  * FUNCTION:    AcpiOsTableOverride
98  *
99  * PARAMETERS:  ExistingTable   - Header of current table (probably firmware)
100  *              NewTable        - Where an entire new table is returned.
101  *
102  * RETURN:      Status, pointer to new table.  Null pointer returned if no
103  *              table is available to override
104  *
105  * DESCRIPTION: Return a different version of a table if one is available
106  *
107  *****************************************************************************/
108
109 ACPI_STATUS
110 AcpiOsTableOverride (
111     ACPI_TABLE_HEADER       *ExistingTable,
112     ACPI_TABLE_HEADER       **NewTable)
113 {
114
115     if (!ExistingTable || !NewTable)
116     {
117         return (AE_BAD_PARAMETER);
118     }
119
120     *NewTable = NULL;
121
122 #ifdef ACPI_EXEC_APP
123
124     /* This code exercises the table override mechanism in the core */
125
126     if (ACPI_COMPARE_NAME (ExistingTable->Signature, ACPI_SIG_DSDT))
127     {
128         /* override DSDT with itself */
129
130         *NewTable = AcpiGbl_DbTablePtr;
131     }
132     return (AE_OK);
133 #else
134     return AE_NO_ACPI_TABLES;
135 #endif
136 }
137
138 /*
139  * ACPI Table interfaces
140  */
141 ACPI_PHYSICAL_ADDRESS
142 AcpiOsGetRootPointer (void)
143 {
144   ACPI_SIZE table_address = 0;
145   printf("Find root Pointer\n");
146   AcpiFindRootPointer(&table_address);
147   printf("Find root Pointer: %lx\n", (unsigned long)table_address);
148   return (ACPI_PHYSICAL_ADDRESS)table_address;
149 }
150
151 /******************************************************************************
152  *
153  * FUNCTION:    AcpiOsSignal
154  *
155  * PARAMETERS:  Function            ACPI CA signal function code
156  *              Info                Pointer to function-dependent structure
157  *
158  * RETURN:      Status
159  *
160  * DESCRIPTION: Miscellaneous functions
161  *
162  *****************************************************************************/
163
164 ACPI_STATUS
165 AcpiOsSignal (
166     UINT32                  Function,
167     void                    *Info)
168 {
169
170     switch (Function)
171     {
172     case ACPI_SIGNAL_FATAL:
173         break;
174
175     case ACPI_SIGNAL_BREAKPOINT:
176
177         if (Info)
178         {
179             AcpiOsPrintf ("AcpiOsBreakpoint: %s ****\n", Info);
180         }
181         else
182         {
183             AcpiOsPrintf ("At AcpiOsBreakpoint ****\n");
184         }
185
186         break;
187     }
188
189
190     return (AE_OK);
191 }
192
193 /******************************************************************************
194  *
195  * FUNCTION:    AcpiOsGetTimer
196  *
197  * PARAMETERS:  None
198  *
199  * RETURN:      Current time in 100 nanosecond units
200  *
201  * DESCRIPTION: Get the current system time
202  *
203  *****************************************************************************/
204
205 UINT64
206 AcpiOsGetTimer (void)
207 {
208     struct timeval  time;
209
210     gettimeofday(&time, NULL);
211
212     /* Seconds * 10^7 = 100ns(10^-7), Microseconds(10^-6) * 10^1 = 100ns */
213
214     return (((UINT64) time.tv_sec * 10000000) + ((UINT64) time.tv_usec * 10));
215 }
216
217
218 // from: acpica/source/os_specific/service_layers/osunixxf.c
219 /******************************************************************************
220  *
221  * FUNCTION:    AcpiOsReadMemory
222  *
223  * PARAMETERS:  Address             - Physical Memory Address to read
224  *              Value               - Where value is placed
225  *              Width               - Number of bits (8,16,32, or 64)
226  *
227  * RETURN:      Value read from physical memory address. Always returned
228  *              as a 64-bit integer, regardless of the read width.
229  *
230  * DESCRIPTION: Read data from a physical memory address
231  *
232  *****************************************************************************/
233
234 ACPI_STATUS
235 AcpiOsReadMemory (
236     ACPI_PHYSICAL_ADDRESS   Address,
237     UINT64                  *Value,
238     UINT32                  Width)
239 {
240
241     printf("%s:%d:%s(%lx, %p, %u): UNINPLEMENTED\n",
242            __FILE__, __LINE__, __func__, (unsigned long)Address, Value, Width);
243     switch (Width)
244     {
245     case 8:
246     case 16:
247     case 32:
248     case 64:
249         *Value = 0;
250         break;
251
252     default:
253         return (AE_BAD_PARAMETER);
254     }
255     return (AE_OK);
256 }
257
258
259 /******************************************************************************
260  *
261  * FUNCTION:    AcpiOsWriteMemory
262  *
263  * PARAMETERS:  Address             - Physical Memory Address to write
264  *              Value               - Value to write
265  *              Width               - Number of bits (8,16,32, or 64)
266  *
267  * RETURN:      None
268  *
269  * DESCRIPTION: Write data to a physical memory address
270  *
271  *****************************************************************************/
272
273 ACPI_STATUS
274 AcpiOsWriteMemory (
275     ACPI_PHYSICAL_ADDRESS   Address,
276     UINT64                  Value,
277     UINT32                  Width)
278 {
279   printf("%s:%d:%s(%lx, %llu, %u): UNINPLEMENTED\n",
280          __FILE__, __LINE__, __func__, (unsigned long)Address, Value, Width);
281     return (AE_OK);
282 }
283
284
285 /******************************************************************************
286  *
287  * FUNCTION:    AcpiOsPhysicalTableOverride
288  *
289  * PARAMETERS:  ExistingTable       - Header of current table (probably firmware)
290  *              NewAddress          - Where new table address is returned
291  *                                    (Physical address)
292  *              NewTableLength      - Where new table length is returned
293  *
294  * RETURN:      Status, address/length of new table. Null pointer returned
295  *              if no table is available to override.
296  *
297  * DESCRIPTION: Returns AE_SUPPORT, function not used in user space.
298  *
299  *****************************************************************************/
300
301 ACPI_STATUS
302 AcpiOsPhysicalTableOverride (
303     ACPI_TABLE_HEADER       *ExistingTable,
304     ACPI_PHYSICAL_ADDRESS   *NewAddress,
305     UINT32                  *NewTableLength)
306 {
307   (void)ExistingTable;
308   (void)NewTableLength;
309   *NewAddress = 0;
310   return (AE_SUPPORT);
311 }
312
313 /******************************************************************************
314  *
315  * FUNCTION:    AcpiOsWaitEventsComplete
316  *
317  * PARAMETERS:  None
318  *
319  * RETURN:      None
320  *
321  * DESCRIPTION: Wait for all asynchronous events to complete. This
322  *              implementation does nothing.
323  *
324  *****************************************************************************/
325
326 void
327 AcpiOsWaitEventsComplete (
328     void)
329 {
330     return;
331 }