Subversion Repositories Kolibri OS

Rev

Rev 1498 | 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
 
117
/*
2216 Serge 118
 * These interfaces are required in order to compile the ASL compiler and the
119
 * various ACPICA tools under Linux or other Unix-like system.
120
 *
121
 * Note: Use #define __APPLE__ for OS X generation.
1498 serge 122
 */
2216 Serge 123
#include "acpi.h"
124
#include "accommon.h"
125
#include "amlcode.h"
126
#include "acparser.h"
127
#include "acdebug.h"
1498 serge 128
 
129
#include 
130
#include 
131
#include 
132
#include 
133
#include 
134
#include 
135
#include 
2216 Serge 136
#include 
1498 serge 137
 
138
#define _COMPONENT          ACPI_OS_SERVICES
139
        ACPI_MODULE_NAME    ("osunixxf")
140
 
141
 
142
extern FILE                    *AcpiGbl_DebugFile;
143
FILE                           *AcpiGbl_OutputFile;
144
 
145
 
146
/* Upcalls to AcpiExec */
147
 
148
ACPI_PHYSICAL_ADDRESS
149
AeLocalGetRootPointer (
150
    void);
151
 
152
void
153
AeTableOverride (
154
    ACPI_TABLE_HEADER       *ExistingTable,
155
    ACPI_TABLE_HEADER       **NewTable);
156
 
157
typedef void* (*PTHREAD_CALLBACK) (void *);
158
 
2216 Serge 159
/* Apple-specific */
1498 serge 160
 
2216 Serge 161
#ifdef __APPLE__
162
#define sem_destroy         sem_close
163
#endif
164
 
165
 
1498 serge 166
/******************************************************************************
167
 *
168
 * FUNCTION:    AcpiOsInitialize, AcpiOsTerminate
169
 *
170
 * PARAMETERS:  None
171
 *
172
 * RETURN:      Status
173
 *
174
 * DESCRIPTION: Init and terminate.  Nothing to do.
175
 *
176
 *****************************************************************************/
177
 
178
ACPI_STATUS
179
AcpiOsInitialize (void)
180
{
181
 
182
    AcpiGbl_OutputFile = stdout;
183
    return (AE_OK);
184
}
185
 
186
 
187
ACPI_STATUS
188
AcpiOsTerminate (void)
189
{
190
 
191
    return (AE_OK);
192
}
193
 
194
 
195
/******************************************************************************
196
 *
197
 * FUNCTION:    AcpiOsGetRootPointer
198
 *
199
 * PARAMETERS:  None
200
 *
201
 * RETURN:      RSDP physical address
202
 *
2216 Serge 203
 * DESCRIPTION: Gets the ACPI root pointer (RSDP)
1498 serge 204
 *
205
 *****************************************************************************/
206
 
207
ACPI_PHYSICAL_ADDRESS
208
AcpiOsGetRootPointer (
209
    void)
210
{
211
 
212
    return (AeLocalGetRootPointer ());
213
}
214
 
215
 
216
/******************************************************************************
217
 *
218
 * FUNCTION:    AcpiOsPredefinedOverride
219
 *
220
 * PARAMETERS:  InitVal     - Initial value of the predefined object
221
 *              NewVal      - The new value for the object
222
 *
223
 * RETURN:      Status, pointer to value.  Null pointer returned if not
224
 *              overriding.
225
 *
226
 * DESCRIPTION: Allow the OS to override predefined names
227
 *
228
 *****************************************************************************/
229
 
230
ACPI_STATUS
231
AcpiOsPredefinedOverride (
232
    const ACPI_PREDEFINED_NAMES *InitVal,
233
    ACPI_STRING                 *NewVal)
234
{
235
 
236
    if (!InitVal || !NewVal)
237
    {
238
        return (AE_BAD_PARAMETER);
239
    }
240
 
241
    *NewVal = NULL;
242
    return (AE_OK);
243
}
244
 
245
 
246
/******************************************************************************
247
 *
248
 * FUNCTION:    AcpiOsTableOverride
249
 *
2216 Serge 250
 * PARAMETERS:  ExistingTable       - Header of current table (probably
251
 *                                    firmware)
1498 serge 252
 *              NewTable        - Where an entire new table is returned.
253
 *
254
 * RETURN:      Status, pointer to new table.  Null pointer returned if no
255
 *              table is available to override
256
 *
257
 * DESCRIPTION: Return a different version of a table if one is available
258
 *
259
 *****************************************************************************/
260
 
261
ACPI_STATUS
262
AcpiOsTableOverride (
263
    ACPI_TABLE_HEADER       *ExistingTable,
264
    ACPI_TABLE_HEADER       **NewTable)
265
{
266
 
267
    if (!ExistingTable || !NewTable)
268
    {
269
        return (AE_BAD_PARAMETER);
270
    }
271
 
272
    *NewTable = NULL;
273
 
274
#ifdef ACPI_EXEC_APP
275
 
276
    AeTableOverride (ExistingTable, NewTable);
277
    return (AE_OK);
278
#else
279
 
280
    return (AE_NO_ACPI_TABLES);
281
#endif
282
}
283
 
284
 
285
/******************************************************************************
286
 *
287
 * FUNCTION:    AcpiOsRedirectOutput
288
 *
289
 * PARAMETERS:  Destination         - An open file handle/pointer
290
 *
291
 * RETURN:      None
292
 *
293
 * DESCRIPTION: Causes redirect of AcpiOsPrintf and AcpiOsVprintf
294
 *
295
 *****************************************************************************/
296
 
297
void
298
AcpiOsRedirectOutput (
299
    void                    *Destination)
300
{
301
 
302
    AcpiGbl_OutputFile = Destination;
303
}
304
 
305
 
306
/******************************************************************************
307
 *
308
 * FUNCTION:    AcpiOsPrintf
309
 *
2216 Serge 310
 * PARAMETERS:  fmt, ...            - Standard printf format
1498 serge 311
 *
312
 * RETURN:      None
313
 *
314
 * DESCRIPTION: Formatted output
315
 *
316
 *****************************************************************************/
317
 
318
void ACPI_INTERNAL_VAR_XFACE
319
AcpiOsPrintf (
320
    const char              *Fmt,
321
    ...)
322
{
323
    va_list                 Args;
324
 
325
 
326
    va_start (Args, Fmt);
327
    AcpiOsVprintf (Fmt, Args);
328
    va_end (Args);
329
}
330
 
331
 
332
/******************************************************************************
333
 *
334
 * FUNCTION:    AcpiOsVprintf
335
 *
2216 Serge 336
 * PARAMETERS:  fmt                 - Standard printf format
337
 *              args                - Argument list
1498 serge 338
 *
339
 * RETURN:      None
340
 *
341
 * DESCRIPTION: Formatted output with argument list pointer
342
 *
343
 *****************************************************************************/
344
 
345
void
346
AcpiOsVprintf (
347
    const char              *Fmt,
348
    va_list                 Args)
349
{
350
    INT32                   Count = 0;
351
    UINT8                   Flags;
352
 
353
 
354
    Flags = AcpiGbl_DbOutputFlags;
355
    if (Flags & ACPI_DB_REDIRECTABLE_OUTPUT)
356
    {
357
        /* Output is directable to either a file (if open) or the console */
358
 
359
        if (AcpiGbl_DebugFile)
360
        {
361
            /* Output file is open, send the output there */
362
 
363
            Count = vfprintf (AcpiGbl_DebugFile, Fmt, Args);
364
        }
365
        else
366
        {
367
            /* No redirection, send output to console (once only!) */
368
 
369
            Flags |= ACPI_DB_CONSOLE_OUTPUT;
370
        }
371
    }
372
 
373
    if (Flags & ACPI_DB_CONSOLE_OUTPUT)
374
    {
375
        Count = vfprintf (AcpiGbl_OutputFile, Fmt, Args);
376
    }
377
}
378
 
379
 
380
/******************************************************************************
381
 *
382
 * FUNCTION:    AcpiOsGetLine
383
 *
2216 Serge 384
 * PARAMETERS:  Buffer              - Where to return the command line
385
 *              BufferLength        - Maximum length of Buffer
386
 *              BytesRead           - Where the actual byte count is returned
1498 serge 387
 *
2216 Serge 388
 * RETURN:      Status and actual bytes read
1498 serge 389
 *
390
 * DESCRIPTION: Formatted input with argument list pointer
391
 *
392
 *****************************************************************************/
393
 
2216 Serge 394
ACPI_STATUS
1498 serge 395
AcpiOsGetLine (
2216 Serge 396
    char                    *Buffer,
397
    UINT32                  BufferLength,
398
    UINT32                  *BytesRead)
1498 serge 399
{
400
    UINT8                   Temp;
401
    UINT32                  i;
402
 
403
 
404
    for (i = 0; ; i++)
405
    {
2216 Serge 406
        if (i >= BufferLength)
407
        {
408
            return (AE_BUFFER_OVERFLOW);
409
        }
410
 
1498 serge 411
        scanf ("%1c", &Temp);
412
        if (!Temp || Temp == '\n')
413
        {
414
            break;
415
        }
416
 
417
        Buffer [i] = Temp;
418
    }
419
 
420
    /* Null terminate the buffer */
421
 
422
    Buffer [i] = 0;
423
 
424
    /* Return the number of bytes in the string */
425
 
2216 Serge 426
    if (BytesRead)
427
    {
428
        *BytesRead = i;
429
    }
430
    return (AE_OK);
1498 serge 431
}
432
 
2216 Serge 433
 
1498 serge 434
/******************************************************************************
435
 *
436
 * FUNCTION:    AcpiOsMapMemory
437
 *
2216 Serge 438
 * PARAMETERS:  where               - Physical address of memory to be mapped
439
 *              length              - How much memory to map
1498 serge 440
 *
441
 * RETURN:      Pointer to mapped memory.  Null on error.
442
 *
443
 * DESCRIPTION: Map physical memory into caller's address space
444
 *
445
 *****************************************************************************/
446
 
447
void *
448
AcpiOsMapMemory (
449
    ACPI_PHYSICAL_ADDRESS   where,
450
    ACPI_SIZE               length)
451
{
452
 
453
    return (ACPI_TO_POINTER ((ACPI_SIZE) where));
454
}
455
 
456
 
457
/******************************************************************************
458
 *
459
 * FUNCTION:    AcpiOsUnmapMemory
460
 *
2216 Serge 461
 * PARAMETERS:  where               - Logical address of memory to be unmapped
462
 *              length              - How much memory to unmap
1498 serge 463
 *
464
 * RETURN:      None.
465
 *
466
 * DESCRIPTION: Delete a previously created mapping.  Where and Length must
467
 *              correspond to a previous mapping exactly.
468
 *
469
 *****************************************************************************/
470
 
471
void
472
AcpiOsUnmapMemory (
473
    void                    *where,
474
    ACPI_SIZE               length)
475
{
476
 
477
    return;
478
}
479
 
480
 
481
/******************************************************************************
482
 *
483
 * FUNCTION:    AcpiOsAllocate
484
 *
2216 Serge 485
 * PARAMETERS:  Size                - Amount to allocate, in bytes
1498 serge 486
 *
487
 * RETURN:      Pointer to the new allocation.  Null on error.
488
 *
489
 * DESCRIPTION: Allocate memory.  Algorithm is dependent on the OS.
490
 *
491
 *****************************************************************************/
492
 
493
void *
494
AcpiOsAllocate (
495
    ACPI_SIZE               size)
496
{
497
    void                    *Mem;
498
 
499
 
500
    Mem = (void *) malloc ((size_t) size);
501
    return (Mem);
502
}
503
 
504
 
505
/******************************************************************************
506
 *
507
 * FUNCTION:    AcpiOsFree
508
 *
2216 Serge 509
 * PARAMETERS:  mem                 - Pointer to previously allocated memory
1498 serge 510
 *
511
 * RETURN:      None.
512
 *
513
 * DESCRIPTION: Free memory allocated via AcpiOsAllocate
514
 *
515
 *****************************************************************************/
516
 
517
void
518
AcpiOsFree (
519
    void                    *mem)
520
{
521
 
522
    free (mem);
523
}
524
 
525
 
526
/******************************************************************************
527
 *
528
 * FUNCTION:    AcpiOsCreateSemaphore
529
 *
530
 * PARAMETERS:  InitialUnits        - Units to be assigned to the new semaphore
531
 *              OutHandle           - Where a handle will be returned
532
 *
533
 * RETURN:      Status
534
 *
535
 * DESCRIPTION: Create an OS semaphore
536
 *
537
 *****************************************************************************/
538
 
539
ACPI_STATUS
540
AcpiOsCreateSemaphore (
541
    UINT32              MaxUnits,
542
    UINT32              InitialUnits,
543
    ACPI_HANDLE         *OutHandle)
544
{
545
    sem_t               *Sem;
546
 
547
 
548
    if (!OutHandle)
549
    {
550
        return (AE_BAD_PARAMETER);
551
    }
552
 
553
    Sem = AcpiOsAllocate (sizeof (sem_t));
554
    if (!Sem)
555
    {
556
        return (AE_NO_MEMORY);
557
    }
558
 
559
    if (sem_init (Sem, 0, InitialUnits) == -1)
560
    {
561
        AcpiOsFree (Sem);
562
        return (AE_BAD_PARAMETER);
563
    }
564
 
565
    *OutHandle = (ACPI_HANDLE) Sem;
566
    return (AE_OK);
567
}
568
 
569
 
570
/******************************************************************************
571
 *
572
 * FUNCTION:    AcpiOsDeleteSemaphore
573
 *
574
 * PARAMETERS:  Handle              - Handle returned by AcpiOsCreateSemaphore
575
 *
576
 * RETURN:      Status
577
 *
578
 * DESCRIPTION: Delete an OS semaphore
579
 *
580
 *****************************************************************************/
581
 
582
ACPI_STATUS
583
AcpiOsDeleteSemaphore (
584
    ACPI_HANDLE         Handle)
585
{
586
    sem_t               *Sem = (sem_t *) Handle;
587
 
588
 
589
    if (!Sem)
590
    {
591
        return (AE_BAD_PARAMETER);
592
    }
593
 
594
    if (sem_destroy (Sem) == -1)
595
    {
596
        return (AE_BAD_PARAMETER);
597
    }
598
 
599
    return (AE_OK);
600
}
601
 
602
 
603
/******************************************************************************
604
 *
605
 * FUNCTION:    AcpiOsWaitSemaphore
606
 *
607
 * PARAMETERS:  Handle              - Handle returned by AcpiOsCreateSemaphore
608
 *              Units               - How many units to wait for
609
 *              Timeout             - How long to wait
610
 *
611
 * RETURN:      Status
612
 *
613
 * DESCRIPTION: Wait for units
614
 *
615
 *****************************************************************************/
616
 
617
ACPI_STATUS
618
AcpiOsWaitSemaphore (
619
    ACPI_HANDLE         Handle,
620
    UINT32              Units,
621
    UINT16              Timeout)
622
{
623
    ACPI_STATUS         Status = AE_OK;
624
    sem_t               *Sem = (sem_t *) Handle;
625
    struct timespec     T;
626
 
627
 
628
    if (!Sem)
629
    {
630
        return (AE_BAD_PARAMETER);
631
    }
632
 
633
    switch (Timeout)
634
    {
635
    /*
636
     * No Wait:
637
     * --------
638
     * A zero timeout value indicates that we shouldn't wait - just
639
     * acquire the semaphore if available otherwise return AE_TIME
640
     * (a.k.a. 'would block').
641
     */
642
    case 0:
643
 
644
        if (sem_trywait(Sem) == -1)
645
        {
646
            Status = (AE_TIME);
647
        }
648
        break;
649
 
650
    /* Wait Indefinitely */
651
 
652
    case ACPI_WAIT_FOREVER:
653
 
654
        if (sem_wait (Sem))
655
        {
656
            Status = (AE_TIME);
657
        }
658
        break;
659
 
660
    /* Wait with Timeout */
661
 
662
    default:
663
 
664
        T.tv_sec = Timeout / 1000;
665
        T.tv_nsec = (Timeout - (T.tv_sec * 1000)) * 1000000;
666
 
667
#ifdef ACPI_USE_ALTERNATE_TIMEOUT
668
        /*
669
         * Alternate timeout mechanism for environments where
670
         * sem_timedwait is not available or does not work properly.
671
         */
672
        while (Timeout)
673
        {
674
            if (sem_trywait (Sem) == 0)
675
            {
676
                /* Got the semaphore */
677
                return (AE_OK);
678
            }
679
            usleep (1000);  /* one millisecond */
680
            Timeout--;
681
        }
682
        Status = (AE_TIME);
683
#else
684
 
685
        if (sem_timedwait (Sem, &T))
686
        {
687
            Status = (AE_TIME);
688
        }
689
#endif
690
 
691
        break;
692
    }
693
 
694
    return (Status);
695
}
696
 
697
 
698
/******************************************************************************
699
 *
700
 * FUNCTION:    AcpiOsSignalSemaphore
701
 *
702
 * PARAMETERS:  Handle              - Handle returned by AcpiOsCreateSemaphore
703
 *              Units               - Number of units to send
704
 *
705
 * RETURN:      Status
706
 *
707
 * DESCRIPTION: Send units
708
 *
709
 *****************************************************************************/
710
 
711
ACPI_STATUS
712
AcpiOsSignalSemaphore (
713
    ACPI_HANDLE         Handle,
714
    UINT32              Units)
715
{
716
    sem_t               *Sem = (sem_t *)Handle;
717
 
718
 
719
    if (!Sem)
720
    {
721
        return (AE_BAD_PARAMETER);
722
    }
723
 
724
    if (sem_post (Sem) == -1)
725
    {
726
        return (AE_LIMIT);
727
    }
728
 
729
    return (AE_OK);
730
}
731
 
732
 
733
/******************************************************************************
734
 *
735
 * FUNCTION:    Spinlock interfaces
736
 *
737
 * DESCRIPTION: Map these interfaces to semaphore interfaces
738
 *
739
 *****************************************************************************/
740
 
741
ACPI_STATUS
742
AcpiOsCreateLock (
743
    ACPI_SPINLOCK           *OutHandle)
744
{
745
 
746
    return (AcpiOsCreateSemaphore (1, 1, OutHandle));
747
}
748
 
749
 
750
void
751
AcpiOsDeleteLock (
752
    ACPI_SPINLOCK           Handle)
753
{
754
    AcpiOsDeleteSemaphore (Handle);
755
}
756
 
757
 
758
ACPI_CPU_FLAGS
759
AcpiOsAcquireLock (
760
    ACPI_HANDLE             Handle)
761
{
762
    AcpiOsWaitSemaphore (Handle, 1, 0xFFFF);
763
    return (0);
764
}
765
 
766
 
767
void
768
AcpiOsReleaseLock (
769
    ACPI_SPINLOCK           Handle,
770
    ACPI_CPU_FLAGS          Flags)
771
{
772
    AcpiOsSignalSemaphore (Handle, 1);
773
}
774
 
775
 
776
/******************************************************************************
777
 *
778
 * FUNCTION:    AcpiOsInstallInterruptHandler
779
 *
2216 Serge 780
 * PARAMETERS:  InterruptNumber     - Level handler should respond to.
781
 *              Isr                 - Address of the ACPI interrupt handler
782
 *              ExceptPtr           - Where status is returned
1498 serge 783
 *
784
 * RETURN:      Handle to the newly installed handler.
785
 *
786
 * DESCRIPTION: Install an interrupt handler.  Used to install the ACPI
787
 *              OS-independent handler.
788
 *
789
 *****************************************************************************/
790
 
791
UINT32
792
AcpiOsInstallInterruptHandler (
793
    UINT32                  InterruptNumber,
794
    ACPI_OSD_HANDLER        ServiceRoutine,
795
    void                    *Context)
796
{
797
 
798
    return (AE_OK);
799
}
800
 
801
 
802
/******************************************************************************
803
 *
804
 * FUNCTION:    AcpiOsRemoveInterruptHandler
805
 *
2216 Serge 806
 * PARAMETERS:  Handle              - Returned when handler was installed
1498 serge 807
 *
808
 * RETURN:      Status
809
 *
810
 * DESCRIPTION: Uninstalls an interrupt handler.
811
 *
812
 *****************************************************************************/
813
 
814
ACPI_STATUS
815
AcpiOsRemoveInterruptHandler (
816
    UINT32                  InterruptNumber,
817
    ACPI_OSD_HANDLER        ServiceRoutine)
818
{
819
 
820
    return (AE_OK);
821
}
822
 
823
 
824
/******************************************************************************
825
 *
826
 * FUNCTION:    AcpiOsStall
827
 *
2216 Serge 828
 * PARAMETERS:  microseconds        - Time to sleep
1498 serge 829
 *
830
 * RETURN:      Blocks until sleep is completed.
831
 *
832
 * DESCRIPTION: Sleep at microsecond granularity
833
 *
834
 *****************************************************************************/
835
 
836
void
837
AcpiOsStall (
838
    UINT32                  microseconds)
839
{
840
 
841
    if (microseconds)
842
    {
843
        usleep (microseconds);
844
    }
845
}
846
 
847
 
848
/******************************************************************************
849
 *
850
 * FUNCTION:    AcpiOsSleep
851
 *
2216 Serge 852
 * PARAMETERS:  milliseconds        - Time to sleep
1498 serge 853
 *
854
 * RETURN:      Blocks until sleep is completed.
855
 *
856
 * DESCRIPTION: Sleep at millisecond granularity
857
 *
858
 *****************************************************************************/
859
 
860
void
861
AcpiOsSleep (
862
    UINT64                  milliseconds)
863
{
864
 
865
    sleep (milliseconds / 1000);    /* Sleep for whole seconds */
866
 
867
    /*
868
     * Arg to usleep() must be less than 1,000,000 (1 second)
869
     */
870
    usleep ((milliseconds % 1000) * 1000);      /* Sleep for remaining usecs */
871
}
872
 
2216 Serge 873
 
1498 serge 874
/******************************************************************************
875
 *
876
 * FUNCTION:    AcpiOsGetTimer
877
 *
878
 * PARAMETERS:  None
879
 *
880
 * RETURN:      Current time in 100 nanosecond units
881
 *
882
 * DESCRIPTION: Get the current system time
883
 *
884
 *****************************************************************************/
885
 
886
UINT64
2216 Serge 887
AcpiOsGetTimer (
888
    void)
1498 serge 889
{
890
    struct timeval          time;
891
 
892
 
893
    gettimeofday (&time, NULL);
894
 
895
    /* Seconds * 10^7 = 100ns(10^-7), Microseconds(10^-6) * 10^1 = 100ns */
896
 
897
    return (((UINT64) time.tv_sec * 10000000) + ((UINT64) time.tv_usec * 10));
898
}
899
 
900
 
901
/******************************************************************************
902
 *
903
 * FUNCTION:    AcpiOsReadPciConfiguration
904
 *
2216 Serge 905
 * PARAMETERS:  PciId               - Seg/Bus/Dev
906
 *              Register            - Device Register
907
 *              Value               - Buffer where value is placed
908
 *              Width               - Number of bits
1498 serge 909
 *
910
 * RETURN:      Status
911
 *
912
 * DESCRIPTION: Read data from PCI configuration space
913
 *
914
 *****************************************************************************/
915
 
916
ACPI_STATUS
917
AcpiOsReadPciConfiguration (
918
    ACPI_PCI_ID             *PciId,
919
    UINT32                  Register,
2216 Serge 920
    UINT64                  *Value,
1498 serge 921
    UINT32                  Width)
922
{
923
 
924
    return (AE_OK);
925
}
926
 
927
 
928
/******************************************************************************
929
 *
930
 * FUNCTION:    AcpiOsWritePciConfiguration
931
 *
2216 Serge 932
 * PARAMETERS:  PciId               - Seg/Bus/Dev
933
 *              Register            - Device Register
934
 *              Value               - Value to be written
935
 *              Width               - Number of bits
1498 serge 936
 *
937
 * RETURN:      Status.
938
 *
939
 * DESCRIPTION: Write data to PCI configuration space
940
 *
941
 *****************************************************************************/
942
 
943
ACPI_STATUS
944
AcpiOsWritePciConfiguration (
945
    ACPI_PCI_ID             *PciId,
946
    UINT32                  Register,
947
    UINT64                  Value,
948
    UINT32                  Width)
949
{
950
 
951
    return (AE_OK);
952
}
953
 
954
 
955
/******************************************************************************
956
 *
957
 * FUNCTION:    AcpiOsReadPort
958
 *
2216 Serge 959
 * PARAMETERS:  Address             - Address of I/O port/register to read
960
 *              Value               - Where value is placed
961
 *              Width               - Number of bits
1498 serge 962
 *
963
 * RETURN:      Value read from port
964
 *
965
 * DESCRIPTION: Read data from an I/O port or register
966
 *
967
 *****************************************************************************/
968
 
969
ACPI_STATUS
970
AcpiOsReadPort (
971
    ACPI_IO_ADDRESS         Address,
972
    UINT32                  *Value,
973
    UINT32                  Width)
974
{
975
 
976
    switch (Width)
977
    {
978
    case 8:
979
        *Value = 0xFF;
980
        break;
981
 
982
    case 16:
983
        *Value = 0xFFFF;
984
        break;
985
 
986
    case 32:
987
        *Value = 0xFFFFFFFF;
988
        break;
989
 
990
    default:
991
        return (AE_BAD_PARAMETER);
992
    }
993
 
994
    return (AE_OK);
995
}
996
 
997
 
998
/******************************************************************************
999
 *
1000
 * FUNCTION:    AcpiOsWritePort
1001
 *
2216 Serge 1002
 * PARAMETERS:  Address             - Address of I/O port/register to write
1003
 *              Value               - Value to write
1004
 *              Width               - Number of bits
1498 serge 1005
 *
1006
 * RETURN:      None
1007
 *
1008
 * DESCRIPTION: Write data to an I/O port or register
1009
 *
1010
 *****************************************************************************/
1011
 
1012
ACPI_STATUS
1013
AcpiOsWritePort (
1014
    ACPI_IO_ADDRESS         Address,
1015
    UINT32                  Value,
1016
    UINT32                  Width)
1017
{
1018
 
1019
    return (AE_OK);
1020
}
1021
 
1022
 
1023
/******************************************************************************
1024
 *
1025
 * FUNCTION:    AcpiOsReadMemory
1026
 *
2216 Serge 1027
 * PARAMETERS:  Address             - Physical Memory Address to read
1028
 *              Value               - Where value is placed
1029
 *              Width               - Number of bits
1498 serge 1030
 *
1031
 * RETURN:      Value read from physical memory address
1032
 *
1033
 * DESCRIPTION: Read data from a physical memory address
1034
 *
1035
 *****************************************************************************/
1036
 
1037
ACPI_STATUS
1038
AcpiOsReadMemory (
1039
    ACPI_PHYSICAL_ADDRESS   Address,
1040
    UINT32                  *Value,
1041
    UINT32                  Width)
1042
{
1043
 
1044
    switch (Width)
1045
    {
1046
    case 8:
1047
    case 16:
1048
    case 32:
1049
        *Value = 0;
1050
        break;
1051
 
1052
    default:
1053
        return (AE_BAD_PARAMETER);
1054
    }
1055
    return (AE_OK);
1056
}
1057
 
1058
 
1059
/******************************************************************************
1060
 *
1061
 * FUNCTION:    AcpiOsWriteMemory
1062
 *
2216 Serge 1063
 * PARAMETERS:  Address             - Physical Memory Address to write
1064
 *              Value               - Value to write
1065
 *              Width               - Number of bits
1498 serge 1066
 *
1067
 * RETURN:      None
1068
 *
1069
 * DESCRIPTION: Write data to a physical memory address
1070
 *
1071
 *****************************************************************************/
1072
 
1073
ACPI_STATUS
1074
AcpiOsWriteMemory (
1075
    ACPI_PHYSICAL_ADDRESS   Address,
1076
    UINT32                  Value,
1077
    UINT32                  Width)
1078
{
1079
 
1080
    return (AE_OK);
1081
}
1082
 
1083
 
1084
/******************************************************************************
1085
 *
1086
 * FUNCTION:    AcpiOsReadable
1087
 *
1088
 * PARAMETERS:  Pointer             - Area to be verified
1089
 *              Length              - Size of area
1090
 *
1091
 * RETURN:      TRUE if readable for entire length
1092
 *
1093
 * DESCRIPTION: Verify that a pointer is valid for reading
1094
 *
1095
 *****************************************************************************/
1096
 
1097
BOOLEAN
1098
AcpiOsReadable (
1099
    void                    *Pointer,
1100
    ACPI_SIZE               Length)
1101
{
1102
 
1103
    return (TRUE);
1104
}
1105
 
1106
 
1107
/******************************************************************************
1108
 *
1109
 * FUNCTION:    AcpiOsWritable
1110
 *
1111
 * PARAMETERS:  Pointer             - Area to be verified
1112
 *              Length              - Size of area
1113
 *
1114
 * RETURN:      TRUE if writable for entire length
1115
 *
1116
 * DESCRIPTION: Verify that a pointer is valid for writing
1117
 *
1118
 *****************************************************************************/
1119
 
1120
BOOLEAN
1121
AcpiOsWritable (
1122
    void                    *Pointer,
1123
    ACPI_SIZE               Length)
1124
{
1125
 
1126
    return (TRUE);
1127
}
1128
 
1129
 
1130
/******************************************************************************
1131
 *
1132
 * FUNCTION:    AcpiOsSignal
1133
 *
2216 Serge 1134
 * PARAMETERS:  Function            - ACPI CA signal function code
1135
 *              Info                - Pointer to function-dependent structure
1498 serge 1136
 *
1137
 * RETURN:      Status
1138
 *
1139
 * DESCRIPTION: Miscellaneous functions. Example implementation only.
1140
 *
1141
 *****************************************************************************/
1142
 
1143
ACPI_STATUS
1144
AcpiOsSignal (
1145
    UINT32                  Function,
1146
    void                    *Info)
1147
{
1148
 
1149
    switch (Function)
1150
    {
1151
    case ACPI_SIGNAL_FATAL:
1152
        break;
1153
 
1154
    case ACPI_SIGNAL_BREAKPOINT:
1155
        break;
1156
 
1157
    default:
1158
        break;
1159
    }
1160
 
1161
    return (AE_OK);
1162
}
1163