Subversion Repositories Kolibri OS

Rev

Rev 2216 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1498 serge 1
/******************************************************************************
2
 *
3
 * Module Name: osunixxf - UNIX OSL interfaces
4
 *
5
 *****************************************************************************/
6
 
7
/******************************************************************************
8
 *
9
 * 1. Copyright Notice
10
 *
2216 Serge 11
 * Some or all of this work - Copyright (c) 1999 - 2011, Intel Corp.
1498 serge 12
 * All rights reserved.
13
 *
14
 * 2. License
15
 *
16
 * 2.1. This is your license from Intel Corp. under its intellectual property
17
 * rights.  You may have additional license terms from the party that provided
18
 * you this software, covering your right to use that party's intellectual
19
 * property rights.
20
 *
21
 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22
 * copy of the source code appearing in this file ("Covered Code") an
23
 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24
 * base code distributed originally by Intel ("Original Intel Code") to copy,
25
 * make derivatives, distribute, use and display any portion of the Covered
26
 * Code in any form, with the right to sublicense such rights; and
27
 *
28
 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29
 * license (with the right to sublicense), under only those claims of Intel
30
 * patents that are infringed by the Original Intel Code, to make, use, sell,
31
 * offer to sell, and import the Covered Code and derivative works thereof
32
 * solely to the minimum extent necessary to exercise the above copyright
33
 * license, and in no event shall the patent license extend to any additions
34
 * to or modifications of the Original Intel Code.  No other license or right
35
 * is granted directly or by implication, estoppel or otherwise;
36
 *
37
 * The above copyright and patent license is granted only if the following
38
 * conditions are met:
39
 *
40
 * 3. Conditions
41
 *
42
 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43
 * Redistribution of source code of any substantial portion of the Covered
44
 * Code or modification with rights to further distribute source must include
45
 * the above Copyright Notice, the above License, this list of Conditions,
46
 * and the following Disclaimer and Export Compliance provision.  In addition,
47
 * Licensee must cause all Covered Code to which Licensee contributes to
48
 * contain a file documenting the changes Licensee made to create that Covered
49
 * Code and the date of any change.  Licensee must include in that file the
50
 * documentation of any changes made by any predecessor Licensee.  Licensee
51
 * must include a prominent statement that the modification is derived,
52
 * directly or indirectly, from Original Intel Code.
53
 *
54
 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55
 * Redistribution of source code of any substantial portion of the Covered
56
 * Code or modification without rights to further distribute source must
57
 * include the following Disclaimer and Export Compliance provision in the
58
 * documentation and/or other materials provided with distribution.  In
59
 * addition, Licensee may not authorize further sublicense of source of any
60
 * portion of the Covered Code, and must include terms to the effect that the
61
 * license from Licensee to its licensee is limited to the intellectual
62
 * property embodied in the software Licensee provides to its licensee, and
63
 * not to intellectual property embodied in modifications its licensee may
64
 * make.
65
 *
66
 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67
 * substantial portion of the Covered Code or modification must reproduce the
68
 * above Copyright Notice, and the following Disclaimer and Export Compliance
69
 * provision in the documentation and/or other materials provided with the
70
 * distribution.
71
 *
72
 * 3.4. Intel retains all right, title, and interest in and to the Original
73
 * Intel Code.
74
 *
75
 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76
 * Intel shall be used in advertising or otherwise to promote the sale, use or
77
 * other dealings in products derived from or relating to the Covered Code
78
 * without prior written authorization from Intel.
79
 *
80
 * 4. Disclaimer and Export Compliance
81
 *
82
 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83
 * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84
 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
85
 * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
86
 * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
87
 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88
 * PARTICULAR PURPOSE.
89
 *
90
 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91
 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92
 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93
 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94
 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95
 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
96
 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97
 * LIMITED REMEDY.
98
 *
99
 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100
 * software or system incorporating such software without first obtaining any
101
 * required license or other approval from the U. S. Department of Commerce or
102
 * any other agency or department of the United States Government.  In the
103
 * event Licensee exports any such software from the United States or
104
 * re-exports any such software from a foreign destination, Licensee shall
105
 * ensure that the distribution and export/re-export of the software is in
106
 * compliance with all laws, regulations, orders, or other restrictions of the
107
 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108
 * any of its subsidiaries will export/re-export any technical data, process,
109
 * software, or service, directly or indirectly, to any country for which the
110
 * United States government or any agency thereof requires an export license,
111
 * other governmental approval, or letter of assurance, without first obtaining
112
 * such license, approval or letter.
113
 *
114
 *****************************************************************************/
115
 
116
#include "acpi.h"
117
#include "accommon.h"
118
#include "amlcode.h"
119
#include "acparser.h"
120
#include "acdebug.h"
121
 
122
/*
123
 * These interfaces are required in order to compile the ASL compiler under
124
 * Linux or other Unix-like system.
125
 */
126
/*
127
#include 
128
#include 
129
#include 
130
#include 
131
#include 
132
#include 
133
#include 
134
*/
135
 
136
#define _COMPONENT          ACPI_OS_SERVICES
137
ACPI_MODULE_NAME            ("oskolibri")
138
 
139
 
140
extern void                    *AcpiGbl_DebugFile;
141
void                           *AcpiGbl_OutputFile;
142
 
143
static UINT32 sACPIRoot = 0;
144
 
145
 
146
void
147
AeTableOverride (
148
    ACPI_TABLE_HEADER       *ExistingTable,
149
    ACPI_TABLE_HEADER       **NewTable);
150
 
151
typedef void* (*PTHREAD_CALLBACK) (void *);
152
 
153
 
154
/******************************************************************************
155
 *
156
 * FUNCTION:    AcpiOsInitialize, AcpiOsTerminate
157
 *
158
 * PARAMETERS:  None
159
 *
160
 * RETURN:      Status
161
 *
162
 * DESCRIPTION: Init and terminate.  Nothing to do.
163
 *
164
 *****************************************************************************/
165
 
166
ACPI_STATUS
167
AcpiOsInitialize (void)
168
{
169
    if(!dbg_open("/rd/1/drivers/acpi.log"))
170
    {
171
        dbgprintf("Can't open /rd/1/drivers/acpi.log\nExit\n");
172
        return AE_ERROR;
173
    }
174
 
175
    return (AE_OK);
176
}
177
 
178
 
179
ACPI_STATUS
180
AcpiOsTerminate (void)
181
{
182
 
183
    return (AE_OK);
184
}
185
 
186
 
187
/******************************************************************************
188
 *
189
 * FUNCTION:    AcpiOsGetRootPointer
190
 *
191
 * PARAMETERS:  None
192
 *
193
 * RETURN:      RSDP physical address
194
 *
195
 * DESCRIPTION: Gets the root pointer (RSDP)
196
 *
197
 *****************************************************************************/
198
 
199
ACPI_PHYSICAL_ADDRESS
200
AcpiOsGetRootPointer (
201
    void)
202
{
203
    ACPI_SIZE address;
204
    ACPI_STATUS status;
205
    if (sACPIRoot == 0) {
206
        status = AcpiFindRootPointer(&address);
207
        if (status == AE_OK)
208
            sACPIRoot = address;
209
    }
210
    dbgprintf("AcpiOsGetRootPointer returning %p\n", (void *)sACPIRoot);
211
    return sACPIRoot;
212
}
213
 
214
 
215
/******************************************************************************
216
 *
217
 * FUNCTION:    AcpiOsPredefinedOverride
218
 *
2216 Serge 219
 * PARAMETERS:  InitVal             - Initial value of the predefined object
220
 *              NewVal              - The new value for the object
1498 serge 221
 *
2216 Serge 222
 * RETURN:      Status, pointer to value. Null pointer returned if not
1498 serge 223
 *              overriding.
224
 *
225
 * DESCRIPTION: Allow the OS to override predefined names
226
 *
227
 *****************************************************************************/
228
 
229
ACPI_STATUS
230
AcpiOsPredefinedOverride (
231
    const ACPI_PREDEFINED_NAMES *InitVal,
232
    ACPI_STRING                 *NewVal)
233
{
234
 
235
    if (!InitVal || !NewVal)
236
    {
237
        return (AE_BAD_PARAMETER);
238
    }
239
 
240
    *NewVal = NULL;
241
    return (AE_OK);
242
}
243
 
244
 
245
/******************************************************************************
246
 *
247
 * FUNCTION:    AcpiOsTableOverride
248
 *
2216 Serge 249
 * PARAMETERS:  ExistingTable       - Header of current table (probably
250
 *                                    firmware)
251
 *              NewTable            - Where an entire new table is returned.
1498 serge 252
 *
2216 Serge 253
 * RETURN:      Status, pointer to new table. Null pointer returned if no
1498 serge 254
 *              table is available to override
255
 *
256
 * DESCRIPTION: Return a different version of a table if one is available
257
 *
258
 *****************************************************************************/
259
 
260
ACPI_STATUS
261
AcpiOsTableOverride (
262
    ACPI_TABLE_HEADER       *ExistingTable,
263
    ACPI_TABLE_HEADER       **NewTable)
264
{
265
 
266
    if (!ExistingTable || !NewTable)
267
    {
268
        return (AE_BAD_PARAMETER);
269
    }
270
 
271
    *NewTable = NULL;
272
 
273
#ifdef ACPI_EXEC_APP
274
 
275
    AeTableOverride (ExistingTable, NewTable);
276
    return (AE_OK);
277
#else
278
 
279
    return (AE_NO_ACPI_TABLES);
280
#endif
281
}
282
 
283
 
284
/******************************************************************************
285
 *
286
 * FUNCTION:    AcpiOsRedirectOutput
287
 *
288
 * PARAMETERS:  Destination         - An open file handle/pointer
289
 *
290
 * RETURN:      None
291
 *
292
 * DESCRIPTION: Causes redirect of AcpiOsPrintf and AcpiOsVprintf
293
 *
294
 *****************************************************************************/
295
 
296
void
297
AcpiOsRedirectOutput (
298
    void                    *Destination)
299
{
300
 
301
    AcpiGbl_OutputFile = Destination;
302
}
303
 
304
 
305
/******************************************************************************
306
 *
307
 * FUNCTION:    AcpiOsPrintf
308
 *
2216 Serge 309
 * PARAMETERS:  fmt, ...            - Standard printf format
1498 serge 310
 *
311
 * RETURN:      None
312
 *
313
 * DESCRIPTION: Formatted output
314
 *
315
 *****************************************************************************/
316
 
317
void ACPI_INTERNAL_VAR_XFACE
318
AcpiOsPrintf (
319
    const char              *Fmt,
320
    ...)
321
{
322
    va_list                 Args;
323
 
324
 
325
    va_start (Args, Fmt);
326
    AcpiOsVprintf (Fmt, Args);
327
    va_end (Args);
328
}
329
 
330
 
331
/******************************************************************************
332
 *
333
 * FUNCTION:    AcpiOsVprintf
334
 *
2216 Serge 335
 * PARAMETERS:  fmt                 - Standard printf format
336
 *              args                - Argument list
1498 serge 337
 *
338
 * RETURN:      None
339
 *
340
 * DESCRIPTION: Formatted output with argument list pointer
341
 *
342
 *****************************************************************************/
343
 
344
void
345
AcpiOsVprintf (
346
    const char              *Fmt,
347
    va_list                 Args)
348
{
349
//    INT32                   Count = 0;
350
//    UINT8                   Flags;
351
 
352
//   static char outputBuffer[1024];
353
//   vsnprintf(outputBuffer, 1024, Fmt, Args);
354
}
355
 
356
 
357
 
358
/******************************************************************************
359
 *
360
 * FUNCTION:    AcpiOsMapMemory
361
 *
2216 Serge 362
 * PARAMETERS:  where               - Physical address of memory to be mapped
363
 *              length              - How much memory to map
1498 serge 364
 *
2216 Serge 365
 * RETURN:      Pointer to mapped memory. Null on error.
1498 serge 366
 *
367
 * DESCRIPTION: Map physical memory into caller's address space
368
 *
369
 *****************************************************************************/
370
 
371
void *
372
AcpiOsMapMemory (
373
    ACPI_PHYSICAL_ADDRESS   where,
374
    ACPI_SIZE               length)
375
{
376
 
377
 
2216 Serge 378
    void* retval=NULL;
1498 serge 379
 
2216 Serge 380
    if( (UINT64)where+length <= 0x100000000ULL)
381
        retval = (void*)MapIoMem(where, 4096+(UINT32)length, 0x07);
1498 serge 382
 
2216 Serge 383
//    dbgprintf("%s %x-> %x %x\n",__FUNCTION__,
384
//              where, retval, length);
385
 
1498 serge 386
    return retval;
387
}
388
 
389
 
390
/******************************************************************************
391
 *
392
 * FUNCTION:    AcpiOsUnmapMemory
393
 *
2216 Serge 394
 * PARAMETERS:  where               - Logical address of memory to be unmapped
395
 *              length              - How much memory to unmap
1498 serge 396
 *
397
 * RETURN:      None.
398
 *
2216 Serge 399
 * DESCRIPTION: Delete a previously created mapping. Where and Length must
1498 serge 400
 *              correspond to a previous mapping exactly.
401
 *
402
 *****************************************************************************/
403
 
404
void
405
AcpiOsUnmapMemory (
406
    void                    *where,
407
    ACPI_SIZE               length)
408
{
2216 Serge 409
    FreeKernelSpace( 0xFFFFF000 & (UINT32)where);
1498 serge 410
    return;
411
}
412
 
413
 
414
/******************************************************************************
415
 *
416
 * FUNCTION:    AcpiOsAllocate
417
 *
2216 Serge 418
 * PARAMETERS:  Size                - Amount to allocate, in bytes
1498 serge 419
 *
2216 Serge 420
 * RETURN:      Pointer to the new allocation. Null on error.
1498 serge 421
 *
2216 Serge 422
 * DESCRIPTION: Allocate memory. Algorithm is dependent on the OS.
1498 serge 423
 *
424
 *****************************************************************************/
425
 
426
void *
427
AcpiOsAllocate (
428
    ACPI_SIZE               size)
429
{
430
    void                    *Mem;
431
 
432
 
433
    Mem = (void *) malloc ((size_t) size);
434
    return (Mem);
435
}
436
 
437
 
438
/******************************************************************************
439
 *
440
 * FUNCTION:    AcpiOsFree
441
 *
2216 Serge 442
 * PARAMETERS:  mem                 - Pointer to previously allocated memory
1498 serge 443
 *
444
 * RETURN:      None.
445
 *
446
 * DESCRIPTION: Free memory allocated via AcpiOsAllocate
447
 *
448
 *****************************************************************************/
449
 
450
void
451
AcpiOsFree (
452
    void                    *mem)
453
{
454
 
455
    free (mem);
456
}
457
 
458
 
459
/******************************************************************************
460
 *
461
 * FUNCTION:    AcpiOsCreateSemaphore
462
 *
463
 * PARAMETERS:  InitialUnits        - Units to be assigned to the new semaphore
464
 *              OutHandle           - Where a handle will be returned
465
 *
466
 * RETURN:      Status
467
 *
468
 * DESCRIPTION: Create an OS semaphore
469
 *
470
 *****************************************************************************/
471
 
472
ACPI_STATUS
473
AcpiOsCreateSemaphore (
474
    UINT32              MaxUnits,
475
    UINT32              InitialUnits,
476
    ACPI_HANDLE         *OutHandle)
477
{
478
 
479
 
480
 
481
    if (!OutHandle)
482
    {
483
        return (AE_BAD_PARAMETER);
484
    }
485
 
486
    *OutHandle = (ACPI_HANDLE) 1;
487
 
488
    return (AE_OK);
489
}
490
 
491
 
492
/******************************************************************************
493
 *
494
 * FUNCTION:    AcpiOsDeleteSemaphore
495
 *
496
 * PARAMETERS:  Handle              - Handle returned by AcpiOsCreateSemaphore
497
 *
498
 * RETURN:      Status
499
 *
500
 * DESCRIPTION: Delete an OS semaphore
501
 *
502
 *****************************************************************************/
503
 
504
ACPI_STATUS
505
AcpiOsDeleteSemaphore (
506
    ACPI_HANDLE         Handle)
507
{
508
 
509
    if (!Handle)
510
    {
511
        return (AE_BAD_PARAMETER);
512
    }
513
 
514
    return (AE_OK);
515
}
516
 
517
 
518
/******************************************************************************
519
 *
520
 * FUNCTION:    AcpiOsWaitSemaphore
521
 *
522
 * PARAMETERS:  Handle              - Handle returned by AcpiOsCreateSemaphore
523
 *              Units               - How many units to wait for
524
 *              Timeout             - How long to wait
525
 *
526
 * RETURN:      Status
527
 *
528
 * DESCRIPTION: Wait for units
529
 *
530
 *****************************************************************************/
531
 
532
ACPI_STATUS
533
AcpiOsWaitSemaphore (
534
    ACPI_HANDLE         Handle,
535
    UINT32              Units,
536
    UINT16              Timeout)
537
{
538
    ACPI_STATUS         Status = AE_OK;
539
 
540
#if 0
541
    if (!Sem)
542
    {
543
        return (AE_BAD_PARAMETER);
544
    }
545
 
546
    switch (Timeout)
547
    {
548
    /*
549
     * No Wait:
550
     * --------
551
     * A zero timeout value indicates that we shouldn't wait - just
552
     * acquire the semaphore if available otherwise return AE_TIME
553
     * (a.k.a. 'would block').
554
     */
555
    case 0:
556
 
557
        if (sem_trywait(Sem) == -1)
558
        {
559
            Status = (AE_TIME);
560
        }
561
        break;
562
 
563
    /* Wait Indefinitely */
564
 
565
    case ACPI_WAIT_FOREVER:
566
 
567
        if (sem_wait (Sem))
568
        {
569
            Status = (AE_TIME);
570
        }
571
        break;
572
 
573
    /* Wait with Timeout */
574
 
575
    default:
576
 
577
        T.tv_sec = Timeout / 1000;
578
        T.tv_nsec = (Timeout - (T.tv_sec * 1000)) * 1000000;
579
 
580
#ifdef ACPI_USE_ALTERNATE_TIMEOUT
581
        /*
582
         * Alternate timeout mechanism for environments where
583
         * sem_timedwait is not available or does not work properly.
584
         */
585
        while (Timeout)
586
        {
587
            if (sem_trywait (Sem) == 0)
588
            {
589
                /* Got the semaphore */
590
                return (AE_OK);
591
            }
592
            usleep (1000);  /* one millisecond */
593
            Timeout--;
594
        }
595
        Status = (AE_TIME);
596
#else
597
 
598
        if (sem_timedwait (Sem, &T))
599
        {
600
            Status = (AE_TIME);
601
        }
602
#endif
603
 
604
        break;
605
    }
606
#endif
607
 
608
    return (Status);
609
}
610
 
611
 
612
/******************************************************************************
613
 *
614
 * FUNCTION:    AcpiOsSignalSemaphore
615
 *
616
 * PARAMETERS:  Handle              - Handle returned by AcpiOsCreateSemaphore
617
 *              Units               - Number of units to send
618
 *
619
 * RETURN:      Status
620
 *
621
 * DESCRIPTION: Send units
622
 *
623
 *****************************************************************************/
624
 
625
ACPI_STATUS
626
AcpiOsSignalSemaphore (
627
    ACPI_HANDLE         Handle,
628
    UINT32              Units)
629
{
630
 
631
    return (AE_OK);
632
}
633
 
634
 
635
/******************************************************************************
636
 *
637
 * FUNCTION:    Spinlock interfaces
638
 *
639
 * DESCRIPTION: Map these interfaces to semaphore interfaces
640
 *
641
 *****************************************************************************/
642
 
643
ACPI_STATUS
644
AcpiOsCreateLock (
645
    ACPI_SPINLOCK           *OutHandle)
646
{
647
    if (!OutHandle)
648
    {
649
        return (AE_BAD_PARAMETER);
650
    }
651
 
9492 turbocat 652
    *OutHandle = (ACPI_HANDLE)malloc(sizeof(UINT32));
1498 serge 653
 
654
	if (*OutHandle == NULL)
655
		return AE_NO_MEMORY;
656
 
657
    *((UINT32*)(*OutHandle)) = 0;
658
	return AE_OK;
659
 
660
}
661
 
662
 
663
void
664
AcpiOsDeleteLock (
665
    ACPI_SPINLOCK           Handle)
666
{
667
    free (Handle);
668
}
669
 
670
 
671
ACPI_CPU_FLAGS
672
AcpiOsAcquireLock (
673
    ACPI_HANDLE             Handle)
674
{
675
    AcpiOsWaitSemaphore (Handle, 1, 0xFFFF);
676
    return (0);
677
}
678
 
679
 
680
void
681
AcpiOsReleaseLock (
682
    ACPI_SPINLOCK           Handle,
683
    ACPI_CPU_FLAGS          Flags)
684
{
685
    AcpiOsSignalSemaphore (Handle, 1);
686
}
687
 
688
 
689
/******************************************************************************
690
 *
691
 * FUNCTION:    AcpiOsInstallInterruptHandler
692
 *
693
 * PARAMETERS:  InterruptNumber     Level handler should respond to.
694
 *              Isr                 Address of the ACPI interrupt handler
695
 *              ExceptPtr           Where status is returned
696
 *
697
 * RETURN:      Handle to the newly installed handler.
698
 *
699
 * DESCRIPTION: Install an interrupt handler.  Used to install the ACPI
700
 *              OS-independent handler.
701
 *
702
 *****************************************************************************/
703
 
704
UINT32
705
AcpiOsInstallInterruptHandler (
706
    UINT32                  InterruptNumber,
707
    ACPI_OSD_HANDLER        ServiceRoutine,
708
    void                    *Context)
709
{
2187 Serge 710
    dbgprintf("%s irq %d\n", InterruptNumber );
1498 serge 711
    return (AE_OK);
712
}
713
 
714
 
715
/******************************************************************************
716
 *
717
 * FUNCTION:    AcpiOsRemoveInterruptHandler
718
 *
719
 * PARAMETERS:  Handle              Returned when handler was installed
720
 *
721
 * RETURN:      Status
722
 *
723
 * DESCRIPTION: Uninstalls an interrupt handler.
724
 *
725
 *****************************************************************************/
726
 
727
ACPI_STATUS
728
AcpiOsRemoveInterruptHandler (
729
    UINT32                  InterruptNumber,
730
    ACPI_OSD_HANDLER        ServiceRoutine)
731
{
732
 
733
    return (AE_OK);
734
}
735
 
736
 
737
/******************************************************************************
738
 *
739
 * FUNCTION:    AcpiOsExecute
740
 *
741
 * PARAMETERS:  Type            - Type of execution
742
 *              Function        - Address of the function to execute
743
 *              Context         - Passed as a parameter to the function
744
 *
745
 * RETURN:      Status.
746
 *
747
 * DESCRIPTION: Execute a new thread
748
 *
749
 *****************************************************************************/
750
 
751
ACPI_STATUS
752
AcpiOsExecute (
753
    ACPI_EXECUTE_TYPE       Type,
754
    ACPI_OSD_EXEC_CALLBACK  Function,
755
    void                    *Context)
756
{
757
//    pthread_t               thread;
758
//    int                     ret;
759
 
760
 
761
//    ret = pthread_create (&thread, NULL, (PTHREAD_CALLBACK) Function, Context);
762
//    if (ret)
763
//    {
764
//        AcpiOsPrintf("Create thread failed");
765
//    }
766
    return (0);
767
}
768
 
769
 
770
/******************************************************************************
771
 *
772
 * FUNCTION:    AcpiOsStall
773
 *
2216 Serge 774
 * PARAMETERS:  microseconds        - Time to sleep
1498 serge 775
 *
776
 * RETURN:      Blocks until sleep is completed.
777
 *
778
 * DESCRIPTION: Sleep at microsecond granularity
779
 *
780
 *****************************************************************************/
781
 
782
void
783
AcpiOsStall (
784
    UINT32                  microseconds)
785
{
786
 
787
    if (microseconds)
788
    {
789
        usleep (microseconds);
790
    }
791
}
792
 
793
 
794
/******************************************************************************
795
 *
796
 * FUNCTION:    AcpiOsSleep
797
 *
2216 Serge 798
 * PARAMETERS:  milliseconds        - Time to sleep
1498 serge 799
 *
800
 * RETURN:      Blocks until sleep is completed.
801
 *
802
 * DESCRIPTION: Sleep at millisecond granularity
803
 *
804
 *****************************************************************************/
805
 
806
void
807
AcpiOsSleep (
808
    UINT64                  milliseconds)
809
{
810
    delay(milliseconds / 8);
811
}
812
 
813
/******************************************************************************
814
 *
815
 * FUNCTION:    AcpiOsGetTimer
816
 *
817
 * PARAMETERS:  None
818
 *
819
 * RETURN:      Current time in 100 nanosecond units
820
 *
821
 * DESCRIPTION: Get the current system time
822
 *
823
 *****************************************************************************/
824
 
825
UINT64
826
AcpiOsGetTimer (void)
827
{
828
//    struct timeval          time;
829
 
830
 
831
//    gettimeofday (&time, NULL);
832
 
833
    /* Seconds * 10^7 = 100ns(10^-7), Microseconds(10^-6) * 10^1 = 100ns */
834
 
835
//    return (((UINT64) time.tv_sec * 10000000) + ((UINT64) time.tv_usec * 10));
836
 
837
    return 0;
838
}
839
 
840
 
841
/******************************************************************************
842
 *
843
 * FUNCTION:    AcpiOsReadPciConfiguration
844
 *
2216 Serge 845
 * PARAMETERS:  PciId               - Seg/Bus/Dev
846
 *              Register            - Device Register
847
 *              Value               - Buffer where value is placed
848
 *              Width               - Number of bits
1498 serge 849
 *
850
 * RETURN:      Status
851
 *
852
 * DESCRIPTION: Read data from PCI configuration space
853
 *
854
 *****************************************************************************/
855
 
856
ACPI_STATUS
857
AcpiOsReadPciConfiguration (
858
    ACPI_PCI_ID             *PciId,
859
    UINT32                  Register,
2216 Serge 860
    UINT64                  *Value,
1498 serge 861
    UINT32                  Width)
862
{
863
    UINT32 devfn = ((PciId->Device & 0x1f)<<3)|(PciId->Function & 0x07);
864
 
865
    switch (Width)
866
    {
867
        case 8:
868
            *(UINT8 *)Value = PciRead8(PciId->Bus,devfn,Register);
869
			break;
870
		case 16:
871
            *(UINT16 *)Value = PciRead16(PciId->Bus,devfn,Register);
872
			break;
873
		case 32:
874
            *(UINT32 *)Value = PciRead32(PciId->Bus,devfn,Register);
875
			break;
876
		default:
877
            dbgprintf("AcpiOsReadPciConfiguration unhandled value width: %u\n",
878
                Width);
879
			return AE_ERROR;
880
	}
881
 
882
    return (AE_OK);
883
}
884
 
885
 
886
/******************************************************************************
887
 *
888
 * FUNCTION:    AcpiOsWritePciConfiguration
889
 *
2216 Serge 890
 * PARAMETERS:  PciId               - Seg/Bus/Dev
891
 *              Register            - Device Register
892
 *              Value               - Value to be written
893
 *              Width               - Number of bits
1498 serge 894
 *
895
 * RETURN:      Status.
896
 *
897
 * DESCRIPTION: Write data to PCI configuration space
898
 *
899
 *****************************************************************************/
900
 
901
ACPI_STATUS
902
AcpiOsWritePciConfiguration (
903
    ACPI_PCI_ID             *PciId,
904
    UINT32                  Register,
905
    UINT64                  Value,
906
    UINT32                  Width)
907
{
908
    UINT32 devfn = ((PciId->Device & 0x1f)<<3)|(PciId->Function & 0x07);
909
 
910
    switch (Width)
911
    {
912
        case 8:
913
            PciWrite8(PciId->Bus,devfn,Register,Value);
914
			break;
915
		case 16:
916
            PciWrite16(PciId->Bus,devfn,Register,Value);
917
			break;
918
		case 32:
919
            PciWrite32(PciId->Bus,devfn,Register,Value);
920
			break;
921
		default:
922
            dbgprintf("AcpiOsReadPciConfiguration unhandled value width: %u\n",
923
                Width);
924
			return AE_ERROR;
925
	}
926
 
927
    return (AE_OK);
928
}
929
 
930
/* TEMPORARY STUB FUNCTION */
931
void
932
AcpiOsDerivePciId(
933
    ACPI_HANDLE             Device,
934
    ACPI_HANDLE             Region,
935
    ACPI_PCI_ID             **PciId)
936
{
937
 
938
}
939
 
940
 
941
/******************************************************************************
942
 *
943
 * FUNCTION:    AcpiOsReadPort
944
 *
2216 Serge 945
 * PARAMETERS:  Address             - Address of I/O port/register to read
946
 *              Value               - Where value is placed
947
 *              Width               - Number of bits
1498 serge 948
 *
949
 * RETURN:      Value read from port
950
 *
951
 * DESCRIPTION: Read data from an I/O port or register
952
 *
953
 *****************************************************************************/
954
 
955
ACPI_STATUS
956
AcpiOsReadPort (
957
    ACPI_IO_ADDRESS         Address,
958
    UINT32                  *Value,
959
    UINT32                  Width)
960
{
961
 
962
    switch (Width)
963
    {
964
    case 8:
965
        *Value = in8(Address);
966
        break;
967
 
968
    case 16:
969
        *Value = in16(Address);
970
        break;
971
 
972
    case 32:
973
        *Value = in32(Address);
974
        break;
975
 
976
    default:
977
        return (AE_BAD_PARAMETER);
978
    }
979
 
2216 Serge 980
//    dbgprintf("%s %x, %x\n",__FUNCTION__, Address, *Value);
2187 Serge 981
 
1498 serge 982
    return (AE_OK);
983
}
984
 
985
 
986
/******************************************************************************
987
 *
988
 * FUNCTION:    AcpiOsWritePort
989
 *
2216 Serge 990
 * PARAMETERS:  Address             - Address of I/O port/register to write
991
 *              Value               - Value to write
992
 *              Width               - Number of bits
1498 serge 993
 *
994
 * RETURN:      None
995
 *
996
 * DESCRIPTION: Write data to an I/O port or register
997
 *
998
 *****************************************************************************/
999
 
1000
ACPI_STATUS
1001
AcpiOsWritePort (
1002
    ACPI_IO_ADDRESS         Address,
1003
    UINT32                  Value,
1004
    UINT32                  Width)
1005
{
1006
 
1007
	switch (Width) {
1008
		case 8:
1009
            out8(Address, Value);
1010
			break;
1011
 
1012
		case 16:
1013
            out16(Address,Value);
1014
			break;
1015
 
1016
		case 32:
1017
            out32(Address,Value);
1018
			break;
1019
 
1020
		default:
1021
			return (AE_ERROR);
1022
	}
1023
 
2216 Serge 1024
//    dbgprintf("%s %x, %x\n",__FUNCTION__, Address, Value);
2187 Serge 1025
 
1498 serge 1026
	return (AE_OK);
1027
};
1028
 
1029
/******************************************************************************
1030
 *
1031
 * FUNCTION:    AcpiOsReadMemory
1032
 *
2216 Serge 1033
 * PARAMETERS:  Address             - Physical Memory Address to read
1034
 *              Value               - Where value is placed
1035
 *              Width               - Number of bits
1498 serge 1036
 *
1037
 * RETURN:      Value read from physical memory address
1038
 *
1039
 * DESCRIPTION: Read data from a physical memory address
1040
 *
1041
 *****************************************************************************/
1042
 
1043
ACPI_STATUS
1044
AcpiOsReadMemory (
1045
    ACPI_PHYSICAL_ADDRESS   Address,
1046
    UINT32                  *Value,
1047
    UINT32                  Width)
1048
{
2187 Serge 1049
    void        *memptr;
1050
    ACPI_STATUS  status = AE_ERROR;
1498 serge 1051
 
2216 Serge 1052
//    dbgprintf("%s %x\n",__FUNCTION__, Address);
1498 serge 1053
 
2216 Serge 1054
    if( (UINT64)Address+Width > 0x100000000ULL)
1055
        return (AE_BAD_PARAMETER);
1056
 
2187 Serge 1057
    if( Address >= 0x400000)
1058
    {
1059
        memptr = AcpiOsMapMemory(Address, Width);
1060
 
1061
        if(memptr)
1062
        {
1063
            status = AE_OK;
1064
 
1065
            switch (Width)
1066
            {
1067
                case 8:
1068
                    *Value = *(UINT8*)Address;
1069
                    break;
1070
 
1071
                case 16:
1072
                    *Value = *(UINT16*)Address;
1073
                    break;
1074
 
1075
                case 32:
1076
                    *Value = *(UINT32*)Address;
1077
                    break;
1078
 
1079
                default:
1080
                    status = (AE_BAD_PARAMETER);
1081
            }
1082
            FreeKernelSpace(memptr);
1083
        }
1084
        return status;
1085
    }
1498 serge 1086
	else
1087
		Address+= 0x80000000;
1088
 
1089
    switch (Width)
1090
    {
2187 Serge 1091
        case 8:
1092
            *Value = *(UINT8*)Address;
1093
            break;
1498 serge 1094
 
2187 Serge 1095
        case 16:
1096
            *Value = *(UINT16*)Address;
1097
            break;
1098
 
1099
        case 32:
1100
            *Value = *(UINT32*)Address;
1101
            break;
1102
 
1103
        default:
1104
            return (AE_BAD_PARAMETER);
1498 serge 1105
    }
1106
    return (AE_OK);
1107
}
1108
 
1109
 
1110
/******************************************************************************
1111
 *
1112
 * FUNCTION:    AcpiOsWriteMemory
1113
 *
2216 Serge 1114
 * PARAMETERS:  Address             - Physical Memory Address to write
1115
 *              Value               - Value to write
1116
 *              Width               - Number of bits
1498 serge 1117
 *
1118
 * RETURN:      None
1119
 *
1120
 * DESCRIPTION: Write data to a physical memory address
1121
 *
1122
 *****************************************************************************/
1123
 
1124
ACPI_STATUS
1125
AcpiOsWriteMemory (
1126
    ACPI_PHYSICAL_ADDRESS   Address,
1127
    UINT32                  Value,
1128
    UINT32                  Width)
1129
{
1130
 
2187 Serge 1131
    void        *memptr;
1132
    ACPI_STATUS  status = AE_ERROR;
1498 serge 1133
 
2216 Serge 1134
//    dbgprintf("%s %x, %x\n",__FUNCTION__, Address, Value);
2187 Serge 1135
 
2216 Serge 1136
    if( (UINT64)Address+Width > 0x100000000ULL)
1137
        return (AE_BAD_PARAMETER);
1138
 
2187 Serge 1139
    if( Address >= 0x400000)
1140
    {
1141
        memptr = AcpiOsMapMemory(Address, Width);
1142
 
1143
        if(memptr)
1144
        {
1145
            status = AE_OK;
1146
 
1147
            switch (Width)
1148
            {
1149
                case 8:
1150
                    *(UINT8*)Address = (UINT8)Value;
1151
                    break;
1152
 
1153
                case 16:
1154
                    *(UINT16*)Address = (UINT16)Value;
1155
                    break;
1156
 
1157
                case 32:
1158
                    *(UINT32*)Address = Value;
1159
                    break;
1160
 
1161
                default:
1162
                    status = (AE_BAD_PARAMETER);
1163
            }
1164
            FreeKernelSpace(memptr);
1165
        }
1166
        return status;
1167
    }
1498 serge 1168
	else
1169
		Address+= 0x80000000;
1170
 
1171
    switch (Width)
1172
    {
1173
    case 8:
2187 Serge 1174
        *(UINT8*)Address = (UINT8)Value;
1175
        break;
1176
 
1498 serge 1177
    case 16:
2187 Serge 1178
        *(UINT16*)Address = (UINT16)Value;
1179
        break;
1180
 
1498 serge 1181
    case 32:
1182
        *(UINT32*)Address = Value;
1183
        break;
1184
 
1185
    default:
1186
        return (AE_BAD_PARAMETER);
1187
    }
1188
 
1189
    return (AE_OK);
1190
 
1191
}
1192
 
1193
 
1194
/******************************************************************************
1195
 *
1196
 * FUNCTION:    AcpiOsReadable
1197
 *
1198
 * PARAMETERS:  Pointer             - Area to be verified
1199
 *              Length              - Size of area
1200
 *
1201
 * RETURN:      TRUE if readable for entire length
1202
 *
1203
 * DESCRIPTION: Verify that a pointer is valid for reading
1204
 *
1205
 *****************************************************************************/
1206
 
1207
BOOLEAN
1208
AcpiOsReadable (
1209
    void                    *Pointer,
1210
    ACPI_SIZE               Length)
1211
{
1212
 
1213
    return (TRUE);
1214
}
1215
 
1216
 
1217
/******************************************************************************
1218
 *
1219
 * FUNCTION:    AcpiOsWritable
1220
 *
1221
 * PARAMETERS:  Pointer             - Area to be verified
1222
 *              Length              - Size of area
1223
 *
1224
 * RETURN:      TRUE if writable for entire length
1225
 *
1226
 * DESCRIPTION: Verify that a pointer is valid for writing
1227
 *
1228
 *****************************************************************************/
1229
 
1230
BOOLEAN
1231
AcpiOsWritable (
1232
    void                    *Pointer,
1233
    ACPI_SIZE               Length)
1234
{
1235
 
1236
    return (TRUE);
1237
}
1238
 
1239
 
1240
/******************************************************************************
1241
 *
1242
 * FUNCTION:    AcpiOsGetThreadId
1243
 *
1244
 * PARAMETERS:  None
1245
 *
1246
 * RETURN:      Id of the running thread
1247
 *
1248
 * DESCRIPTION: Get the Id of the current (running) thread
1249
 *
1250
 * NOTE:        The environment header should contain this line:
1251
 *                  #define ACPI_THREAD_ID pthread_t
1252
 *
1253
 *****************************************************************************/
1254
 
1255
ACPI_THREAD_ID
1256
AcpiOsGetThreadId (void)
1257
{
1258
 
1259
    return ( 1 );
1260
}
1261
 
1262
 
1263
/******************************************************************************
1264
 *
1265
 * FUNCTION:    AcpiOsSignal
1266
 *
2216 Serge 1267
 * PARAMETERS:  Function            - ACPI CA signal function code
1268
 *              Info                - Pointer to function-dependent structure
1498 serge 1269
 *
1270
 * RETURN:      Status
1271
 *
1272
 * DESCRIPTION: Miscellaneous functions. Example implementation only.
1273
 *
1274
 *****************************************************************************/
1275
 
1276
ACPI_STATUS
1277
AcpiOsSignal (
1278
    UINT32                  Function,
1279
    void                    *Info)
1280
{
1281
 
1282
    switch (Function)
1283
    {
1284
    case ACPI_SIGNAL_FATAL:
1285
        break;
1286
 
1287
    case ACPI_SIGNAL_BREAKPOINT:
1288
        break;
1289
 
1290
    default:
1291
        break;
1292
    }
1293
 
1294
    return (AE_OK);
1295
}
1296