Subversion Repositories Kolibri OS

Rev

Rev 1498 | 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
 *
11
 * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
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
 *
219
 * PARAMETERS:  InitVal     - Initial value of the predefined object
220
 *              NewVal      - The new value for the object
221
 *
222
 * RETURN:      Status, pointer to value.  Null pointer returned if not
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
 *
249
 * PARAMETERS:  ExistingTable   - Header of current table (probably firmware)
250
 *              NewTable        - Where an entire new table is returned.
251
 *
252
 * RETURN:      Status, pointer to new table.  Null pointer returned if no
253
 *              table is available to override
254
 *
255
 * DESCRIPTION: Return a different version of a table if one is available
256
 *
257
 *****************************************************************************/
258
 
259
ACPI_STATUS
260
AcpiOsTableOverride (
261
    ACPI_TABLE_HEADER       *ExistingTable,
262
    ACPI_TABLE_HEADER       **NewTable)
263
{
264
 
265
    if (!ExistingTable || !NewTable)
266
    {
267
        return (AE_BAD_PARAMETER);
268
    }
269
 
270
    *NewTable = NULL;
271
 
272
#ifdef ACPI_EXEC_APP
273
 
274
    AeTableOverride (ExistingTable, NewTable);
275
    return (AE_OK);
276
#else
277
 
278
    return (AE_NO_ACPI_TABLES);
279
#endif
280
}
281
 
282
 
283
/******************************************************************************
284
 *
285
 * FUNCTION:    AcpiOsRedirectOutput
286
 *
287
 * PARAMETERS:  Destination         - An open file handle/pointer
288
 *
289
 * RETURN:      None
290
 *
291
 * DESCRIPTION: Causes redirect of AcpiOsPrintf and AcpiOsVprintf
292
 *
293
 *****************************************************************************/
294
 
295
void
296
AcpiOsRedirectOutput (
297
    void                    *Destination)
298
{
299
 
300
    AcpiGbl_OutputFile = Destination;
301
}
302
 
303
 
304
/******************************************************************************
305
 *
306
 * FUNCTION:    AcpiOsPrintf
307
 *
308
 * PARAMETERS:  fmt, ...            Standard printf format
309
 *
310
 * RETURN:      None
311
 *
312
 * DESCRIPTION: Formatted output
313
 *
314
 *****************************************************************************/
315
 
316
void ACPI_INTERNAL_VAR_XFACE
317
AcpiOsPrintf (
318
    const char              *Fmt,
319
    ...)
320
{
321
    va_list                 Args;
322
 
323
 
324
    va_start (Args, Fmt);
325
    AcpiOsVprintf (Fmt, Args);
326
    va_end (Args);
327
}
328
 
329
 
330
/******************************************************************************
331
 *
332
 * FUNCTION:    AcpiOsVprintf
333
 *
334
 * PARAMETERS:  fmt                 Standard printf format
335
 *              args                Argument list
336
 *
337
 * RETURN:      None
338
 *
339
 * DESCRIPTION: Formatted output with argument list pointer
340
 *
341
 *****************************************************************************/
342
 
343
void
344
AcpiOsVprintf (
345
    const char              *Fmt,
346
    va_list                 Args)
347
{
348
//    INT32                   Count = 0;
349
//    UINT8                   Flags;
350
 
351
//   static char outputBuffer[1024];
352
//   vsnprintf(outputBuffer, 1024, Fmt, Args);
353
}
354
 
355
 
356
 
357
/******************************************************************************
358
 *
359
 * FUNCTION:    AcpiOsMapMemory
360
 *
361
 * PARAMETERS:  where               Physical address of memory to be mapped
362
 *              length              How much memory to map
363
 *
364
 * RETURN:      Pointer to mapped memory.  Null on error.
365
 *
366
 * DESCRIPTION: Map physical memory into caller's address space
367
 *
368
 *****************************************************************************/
369
 
370
void *
371
AcpiOsMapMemory (
372
    ACPI_PHYSICAL_ADDRESS   where,
373
    ACPI_SIZE               length)
374
{
375
 
376
 
377
    void* retval;
378
 
379
    retval = (void*)MapIoMem((UINT32)where, (UINT32)length, 0x03);
380
 
381
    return retval;
382
}
383
 
384
 
385
/******************************************************************************
386
 *
387
 * FUNCTION:    AcpiOsUnmapMemory
388
 *
389
 * PARAMETERS:  where               Logical address of memory to be unmapped
390
 *              length              How much memory to unmap
391
 *
392
 * RETURN:      None.
393
 *
394
 * DESCRIPTION: Delete a previously created mapping.  Where and Length must
395
 *              correspond to a previous mapping exactly.
396
 *
397
 *****************************************************************************/
398
 
399
void
400
AcpiOsUnmapMemory (
401
    void                    *where,
402
    ACPI_SIZE               length)
403
{
404
 
405
    return;
406
}
407
 
408
 
409
/******************************************************************************
410
 *
411
 * FUNCTION:    AcpiOsAllocate
412
 *
413
 * PARAMETERS:  Size                Amount to allocate, in bytes
414
 *
415
 * RETURN:      Pointer to the new allocation.  Null on error.
416
 *
417
 * DESCRIPTION: Allocate memory.  Algorithm is dependent on the OS.
418
 *
419
 *****************************************************************************/
420
 
421
void *
422
AcpiOsAllocate (
423
    ACPI_SIZE               size)
424
{
425
    void                    *Mem;
426
 
427
 
428
    Mem = (void *) malloc ((size_t) size);
429
    return (Mem);
430
}
431
 
432
 
433
/******************************************************************************
434
 *
435
 * FUNCTION:    AcpiOsFree
436
 *
437
 * PARAMETERS:  mem                 Pointer to previously allocated memory
438
 *
439
 * RETURN:      None.
440
 *
441
 * DESCRIPTION: Free memory allocated via AcpiOsAllocate
442
 *
443
 *****************************************************************************/
444
 
445
void
446
AcpiOsFree (
447
    void                    *mem)
448
{
449
 
450
    free (mem);
451
}
452
 
453
 
454
/******************************************************************************
455
 *
456
 * FUNCTION:    AcpiOsCreateSemaphore
457
 *
458
 * PARAMETERS:  InitialUnits        - Units to be assigned to the new semaphore
459
 *              OutHandle           - Where a handle will be returned
460
 *
461
 * RETURN:      Status
462
 *
463
 * DESCRIPTION: Create an OS semaphore
464
 *
465
 *****************************************************************************/
466
 
467
ACPI_STATUS
468
AcpiOsCreateSemaphore (
469
    UINT32              MaxUnits,
470
    UINT32              InitialUnits,
471
    ACPI_HANDLE         *OutHandle)
472
{
473
 
474
 
475
 
476
    if (!OutHandle)
477
    {
478
        return (AE_BAD_PARAMETER);
479
    }
480
 
481
    *OutHandle = (ACPI_HANDLE) 1;
482
 
483
    return (AE_OK);
484
}
485
 
486
 
487
/******************************************************************************
488
 *
489
 * FUNCTION:    AcpiOsDeleteSemaphore
490
 *
491
 * PARAMETERS:  Handle              - Handle returned by AcpiOsCreateSemaphore
492
 *
493
 * RETURN:      Status
494
 *
495
 * DESCRIPTION: Delete an OS semaphore
496
 *
497
 *****************************************************************************/
498
 
499
ACPI_STATUS
500
AcpiOsDeleteSemaphore (
501
    ACPI_HANDLE         Handle)
502
{
503
 
504
    if (!Handle)
505
    {
506
        return (AE_BAD_PARAMETER);
507
    }
508
 
509
    return (AE_OK);
510
}
511
 
512
 
513
/******************************************************************************
514
 *
515
 * FUNCTION:    AcpiOsWaitSemaphore
516
 *
517
 * PARAMETERS:  Handle              - Handle returned by AcpiOsCreateSemaphore
518
 *              Units               - How many units to wait for
519
 *              Timeout             - How long to wait
520
 *
521
 * RETURN:      Status
522
 *
523
 * DESCRIPTION: Wait for units
524
 *
525
 *****************************************************************************/
526
 
527
ACPI_STATUS
528
AcpiOsWaitSemaphore (
529
    ACPI_HANDLE         Handle,
530
    UINT32              Units,
531
    UINT16              Timeout)
532
{
533
    ACPI_STATUS         Status = AE_OK;
534
 
535
#if 0
536
    if (!Sem)
537
    {
538
        return (AE_BAD_PARAMETER);
539
    }
540
 
541
    switch (Timeout)
542
    {
543
    /*
544
     * No Wait:
545
     * --------
546
     * A zero timeout value indicates that we shouldn't wait - just
547
     * acquire the semaphore if available otherwise return AE_TIME
548
     * (a.k.a. 'would block').
549
     */
550
    case 0:
551
 
552
        if (sem_trywait(Sem) == -1)
553
        {
554
            Status = (AE_TIME);
555
        }
556
        break;
557
 
558
    /* Wait Indefinitely */
559
 
560
    case ACPI_WAIT_FOREVER:
561
 
562
        if (sem_wait (Sem))
563
        {
564
            Status = (AE_TIME);
565
        }
566
        break;
567
 
568
    /* Wait with Timeout */
569
 
570
    default:
571
 
572
        T.tv_sec = Timeout / 1000;
573
        T.tv_nsec = (Timeout - (T.tv_sec * 1000)) * 1000000;
574
 
575
#ifdef ACPI_USE_ALTERNATE_TIMEOUT
576
        /*
577
         * Alternate timeout mechanism for environments where
578
         * sem_timedwait is not available or does not work properly.
579
         */
580
        while (Timeout)
581
        {
582
            if (sem_trywait (Sem) == 0)
583
            {
584
                /* Got the semaphore */
585
                return (AE_OK);
586
            }
587
            usleep (1000);  /* one millisecond */
588
            Timeout--;
589
        }
590
        Status = (AE_TIME);
591
#else
592
 
593
        if (sem_timedwait (Sem, &T))
594
        {
595
            Status = (AE_TIME);
596
        }
597
#endif
598
 
599
        break;
600
    }
601
#endif
602
 
603
    return (Status);
604
}
605
 
606
 
607
/******************************************************************************
608
 *
609
 * FUNCTION:    AcpiOsSignalSemaphore
610
 *
611
 * PARAMETERS:  Handle              - Handle returned by AcpiOsCreateSemaphore
612
 *              Units               - Number of units to send
613
 *
614
 * RETURN:      Status
615
 *
616
 * DESCRIPTION: Send units
617
 *
618
 *****************************************************************************/
619
 
620
ACPI_STATUS
621
AcpiOsSignalSemaphore (
622
    ACPI_HANDLE         Handle,
623
    UINT32              Units)
624
{
625
 
626
    return (AE_OK);
627
}
628
 
629
 
630
/******************************************************************************
631
 *
632
 * FUNCTION:    Spinlock interfaces
633
 *
634
 * DESCRIPTION: Map these interfaces to semaphore interfaces
635
 *
636
 *****************************************************************************/
637
 
638
ACPI_STATUS
639
AcpiOsCreateLock (
640
    ACPI_SPINLOCK           *OutHandle)
641
{
642
    if (!OutHandle)
643
    {
644
        return (AE_BAD_PARAMETER);
645
    }
646
 
647
    *OutHandle = (ACPI_HANDLE)malloc(sizeof(u32_t));
648
 
649
	if (*OutHandle == NULL)
650
		return AE_NO_MEMORY;
651
 
652
    *((UINT32*)(*OutHandle)) = 0;
653
	return AE_OK;
654
 
655
}
656
 
657
 
658
void
659
AcpiOsDeleteLock (
660
    ACPI_SPINLOCK           Handle)
661
{
662
    free (Handle);
663
}
664
 
665
 
666
ACPI_CPU_FLAGS
667
AcpiOsAcquireLock (
668
    ACPI_HANDLE             Handle)
669
{
670
    AcpiOsWaitSemaphore (Handle, 1, 0xFFFF);
671
    return (0);
672
}
673
 
674
 
675
void
676
AcpiOsReleaseLock (
677
    ACPI_SPINLOCK           Handle,
678
    ACPI_CPU_FLAGS          Flags)
679
{
680
    AcpiOsSignalSemaphore (Handle, 1);
681
}
682
 
683
 
684
/******************************************************************************
685
 *
686
 * FUNCTION:    AcpiOsInstallInterruptHandler
687
 *
688
 * PARAMETERS:  InterruptNumber     Level handler should respond to.
689
 *              Isr                 Address of the ACPI interrupt handler
690
 *              ExceptPtr           Where status is returned
691
 *
692
 * RETURN:      Handle to the newly installed handler.
693
 *
694
 * DESCRIPTION: Install an interrupt handler.  Used to install the ACPI
695
 *              OS-independent handler.
696
 *
697
 *****************************************************************************/
698
 
699
UINT32
700
AcpiOsInstallInterruptHandler (
701
    UINT32                  InterruptNumber,
702
    ACPI_OSD_HANDLER        ServiceRoutine,
703
    void                    *Context)
704
{
2187 Serge 705
    dbgprintf("%s irq %d\n", InterruptNumber );
1498 serge 706
    return (AE_OK);
707
}
708
 
709
 
710
/******************************************************************************
711
 *
712
 * FUNCTION:    AcpiOsRemoveInterruptHandler
713
 *
714
 * PARAMETERS:  Handle              Returned when handler was installed
715
 *
716
 * RETURN:      Status
717
 *
718
 * DESCRIPTION: Uninstalls an interrupt handler.
719
 *
720
 *****************************************************************************/
721
 
722
ACPI_STATUS
723
AcpiOsRemoveInterruptHandler (
724
    UINT32                  InterruptNumber,
725
    ACPI_OSD_HANDLER        ServiceRoutine)
726
{
727
 
728
    return (AE_OK);
729
}
730
 
731
 
732
/******************************************************************************
733
 *
734
 * FUNCTION:    AcpiOsExecute
735
 *
736
 * PARAMETERS:  Type            - Type of execution
737
 *              Function        - Address of the function to execute
738
 *              Context         - Passed as a parameter to the function
739
 *
740
 * RETURN:      Status.
741
 *
742
 * DESCRIPTION: Execute a new thread
743
 *
744
 *****************************************************************************/
745
 
746
ACPI_STATUS
747
AcpiOsExecute (
748
    ACPI_EXECUTE_TYPE       Type,
749
    ACPI_OSD_EXEC_CALLBACK  Function,
750
    void                    *Context)
751
{
752
//    pthread_t               thread;
753
//    int                     ret;
754
 
755
 
756
//    ret = pthread_create (&thread, NULL, (PTHREAD_CALLBACK) Function, Context);
757
//    if (ret)
758
//    {
759
//        AcpiOsPrintf("Create thread failed");
760
//    }
761
    return (0);
762
}
763
 
764
 
765
/******************************************************************************
766
 *
767
 * FUNCTION:    AcpiOsStall
768
 *
769
 * PARAMETERS:  microseconds        To sleep
770
 *
771
 * RETURN:      Blocks until sleep is completed.
772
 *
773
 * DESCRIPTION: Sleep at microsecond granularity
774
 *
775
 *****************************************************************************/
776
 
777
void
778
AcpiOsStall (
779
    UINT32                  microseconds)
780
{
781
 
782
    if (microseconds)
783
    {
784
        usleep (microseconds);
785
    }
786
}
787
 
788
 
789
/******************************************************************************
790
 *
791
 * FUNCTION:    AcpiOsSleep
792
 *
793
 * PARAMETERS:  milliseconds        To sleep
794
 *
795
 * RETURN:      Blocks until sleep is completed.
796
 *
797
 * DESCRIPTION: Sleep at millisecond granularity
798
 *
799
 *****************************************************************************/
800
 
801
void
802
AcpiOsSleep (
803
    UINT64                  milliseconds)
804
{
805
    delay(milliseconds / 8);
806
}
807
 
808
/******************************************************************************
809
 *
810
 * FUNCTION:    AcpiOsGetTimer
811
 *
812
 * PARAMETERS:  None
813
 *
814
 * RETURN:      Current time in 100 nanosecond units
815
 *
816
 * DESCRIPTION: Get the current system time
817
 *
818
 *****************************************************************************/
819
 
820
UINT64
821
AcpiOsGetTimer (void)
822
{
823
//    struct timeval          time;
824
 
825
 
826
//    gettimeofday (&time, NULL);
827
 
828
    /* Seconds * 10^7 = 100ns(10^-7), Microseconds(10^-6) * 10^1 = 100ns */
829
 
830
//    return (((UINT64) time.tv_sec * 10000000) + ((UINT64) time.tv_usec * 10));
831
 
832
    return 0;
833
}
834
 
835
 
836
/******************************************************************************
837
 *
838
 * FUNCTION:    AcpiOsValidateInterface
839
 *
840
 * PARAMETERS:  Interface           - Requested interface to be validated
841
 *
842
 * RETURN:      AE_OK if interface is supported, AE_SUPPORT otherwise
843
 *
844
 * DESCRIPTION: Match an interface string to the interfaces supported by the
845
 *              host. Strings originate from an AML call to the _OSI method.
846
 *
847
 *****************************************************************************/
848
 
849
ACPI_STATUS
850
AcpiOsValidateInterface (
851
    char                    *Interface)
852
{
853
 
854
    return (AE_SUPPORT);
855
}
856
 
857
 
858
/******************************************************************************
859
 *
860
 * FUNCTION:    AcpiOsReadPciConfiguration
861
 *
862
 * PARAMETERS:  PciId               Seg/Bus/Dev
863
 *              Register            Device Register
864
 *              Value               Buffer where value is placed
865
 *              Width               Number of bits
866
 *
867
 * RETURN:      Status
868
 *
869
 * DESCRIPTION: Read data from PCI configuration space
870
 *
871
 *****************************************************************************/
872
 
873
ACPI_STATUS
874
AcpiOsReadPciConfiguration (
875
    ACPI_PCI_ID             *PciId,
876
    UINT32                  Register,
877
    void                    *Value,
878
    UINT32                  Width)
879
{
880
    UINT32 devfn = ((PciId->Device & 0x1f)<<3)|(PciId->Function & 0x07);
881
 
882
    switch (Width)
883
    {
884
        case 8:
885
            *(UINT8 *)Value = PciRead8(PciId->Bus,devfn,Register);
886
			break;
887
		case 16:
888
            *(UINT16 *)Value = PciRead16(PciId->Bus,devfn,Register);
889
			break;
890
		case 32:
891
            *(UINT32 *)Value = PciRead32(PciId->Bus,devfn,Register);
892
			break;
893
		default:
894
            dbgprintf("AcpiOsReadPciConfiguration unhandled value width: %u\n",
895
                Width);
896
			return AE_ERROR;
897
	}
898
 
899
    return (AE_OK);
900
 
901
}
902
 
903
 
904
/******************************************************************************
905
 *
906
 * FUNCTION:    AcpiOsWritePciConfiguration
907
 *
908
 * PARAMETERS:  PciId               Seg/Bus/Dev
909
 *              Register            Device Register
910
 *              Value               Value to be written
911
 *              Width               Number of bits
912
 *
913
 * RETURN:      Status.
914
 *
915
 * DESCRIPTION: Write data to PCI configuration space
916
 *
917
 *****************************************************************************/
918
 
919
ACPI_STATUS
920
AcpiOsWritePciConfiguration (
921
    ACPI_PCI_ID             *PciId,
922
    UINT32                  Register,
923
    UINT64                  Value,
924
    UINT32                  Width)
925
{
926
    UINT32 devfn = ((PciId->Device & 0x1f)<<3)|(PciId->Function & 0x07);
927
 
928
    switch (Width)
929
    {
930
        case 8:
931
            PciWrite8(PciId->Bus,devfn,Register,Value);
932
			break;
933
		case 16:
934
            PciWrite16(PciId->Bus,devfn,Register,Value);
935
			break;
936
		case 32:
937
            PciWrite32(PciId->Bus,devfn,Register,Value);
938
			break;
939
		default:
940
            dbgprintf("AcpiOsReadPciConfiguration unhandled value width: %u\n",
941
                Width);
942
			return AE_ERROR;
943
	}
944
 
945
    return (AE_OK);
946
}
947
 
948
/* TEMPORARY STUB FUNCTION */
949
void
950
AcpiOsDerivePciId(
951
    ACPI_HANDLE             Device,
952
    ACPI_HANDLE             Region,
953
    ACPI_PCI_ID             **PciId)
954
{
955
 
956
}
957
 
958
 
959
/******************************************************************************
960
 *
961
 * FUNCTION:    AcpiOsReadPort
962
 *
963
 * PARAMETERS:  Address             Address of I/O port/register to read
964
 *              Value               Where value is placed
965
 *              Width               Number of bits
966
 *
967
 * RETURN:      Value read from port
968
 *
969
 * DESCRIPTION: Read data from an I/O port or register
970
 *
971
 *****************************************************************************/
972
 
973
ACPI_STATUS
974
AcpiOsReadPort (
975
    ACPI_IO_ADDRESS         Address,
976
    UINT32                  *Value,
977
    UINT32                  Width)
978
{
979
 
980
    switch (Width)
981
    {
982
    case 8:
983
        *Value = in8(Address);
984
        break;
985
 
986
    case 16:
987
        *Value = in16(Address);
988
        break;
989
 
990
    case 32:
991
        *Value = in32(Address);
992
        break;
993
 
994
    default:
995
        return (AE_BAD_PARAMETER);
996
    }
997
 
2187 Serge 998
    dbgprintf("%s %x, %x\n",__FUNCTION__, Address, *Value);
999
 
1498 serge 1000
    return (AE_OK);
1001
}
1002
 
1003
 
1004
/******************************************************************************
1005
 *
1006
 * FUNCTION:    AcpiOsWritePort
1007
 *
1008
 * PARAMETERS:  Address             Address of I/O port/register to write
1009
 *              Value               Value to write
1010
 *              Width               Number of bits
1011
 *
1012
 * RETURN:      None
1013
 *
1014
 * DESCRIPTION: Write data to an I/O port or register
1015
 *
1016
 *****************************************************************************/
1017
 
1018
ACPI_STATUS
1019
AcpiOsWritePort (
1020
    ACPI_IO_ADDRESS         Address,
1021
    UINT32                  Value,
1022
    UINT32                  Width)
1023
{
1024
 
1025
	switch (Width) {
1026
		case 8:
1027
            out8(Address, Value);
1028
			break;
1029
 
1030
		case 16:
1031
            out16(Address,Value);
1032
			break;
1033
 
1034
		case 32:
1035
            out32(Address,Value);
1036
			break;
1037
 
1038
		default:
1039
			return (AE_ERROR);
1040
	}
1041
 
2187 Serge 1042
    dbgprintf("%s %x, %x\n",__FUNCTION__, Address, Value);
1043
 
1498 serge 1044
	return (AE_OK);
1045
};
1046
 
1047
/******************************************************************************
1048
 *
1049
 * FUNCTION:    AcpiOsReadMemory
1050
 *
1051
 * PARAMETERS:  Address             Physical Memory Address to read
1052
 *              Value               Where value is placed
1053
 *              Width               Number of bits
1054
 *
1055
 * RETURN:      Value read from physical memory address
1056
 *
1057
 * DESCRIPTION: Read data from a physical memory address
1058
 *
1059
 *****************************************************************************/
1060
 
1061
ACPI_STATUS
1062
AcpiOsReadMemory (
1063
    ACPI_PHYSICAL_ADDRESS   Address,
1064
    UINT32                  *Value,
1065
    UINT32                  Width)
1066
{
2187 Serge 1067
    void        *memptr;
1068
    ACPI_STATUS  status = AE_ERROR;
1498 serge 1069
 
2187 Serge 1070
    dbgprintf("%s %x\n",__FUNCTION__, Address);
1498 serge 1071
 
2187 Serge 1072
    if( Address >= 0x400000)
1073
    {
1074
        memptr = AcpiOsMapMemory(Address, Width);
1075
 
1076
        if(memptr)
1077
        {
1078
            status = AE_OK;
1079
 
1080
            switch (Width)
1081
            {
1082
                case 8:
1083
                    *Value = *(UINT8*)Address;
1084
                    break;
1085
 
1086
                case 16:
1087
                    *Value = *(UINT16*)Address;
1088
                    break;
1089
 
1090
                case 32:
1091
                    *Value = *(UINT32*)Address;
1092
                    break;
1093
 
1094
                default:
1095
                    status = (AE_BAD_PARAMETER);
1096
            }
1097
            FreeKernelSpace(memptr);
1098
        }
1099
        return status;
1100
    }
1498 serge 1101
	else
1102
		Address+= 0x80000000;
1103
 
1104
    switch (Width)
1105
    {
2187 Serge 1106
        case 8:
1107
            *Value = *(UINT8*)Address;
1108
            break;
1498 serge 1109
 
2187 Serge 1110
        case 16:
1111
            *Value = *(UINT16*)Address;
1112
            break;
1113
 
1114
        case 32:
1115
            *Value = *(UINT32*)Address;
1116
            break;
1117
 
1118
        default:
1119
            return (AE_BAD_PARAMETER);
1498 serge 1120
    }
1121
    return (AE_OK);
1122
}
1123
 
1124
 
1125
/******************************************************************************
1126
 *
1127
 * FUNCTION:    AcpiOsWriteMemory
1128
 *
1129
 * PARAMETERS:  Address             Physical Memory Address to write
1130
 *              Value               Value to write
1131
 *              Width               Number of bits
1132
 *
1133
 * RETURN:      None
1134
 *
1135
 * DESCRIPTION: Write data to a physical memory address
1136
 *
1137
 *****************************************************************************/
1138
 
1139
ACPI_STATUS
1140
AcpiOsWriteMemory (
1141
    ACPI_PHYSICAL_ADDRESS   Address,
1142
    UINT32                  Value,
1143
    UINT32                  Width)
1144
{
1145
 
2187 Serge 1146
    void        *memptr;
1147
    ACPI_STATUS  status = AE_ERROR;
1498 serge 1148
 
2187 Serge 1149
    dbgprintf("%s %x, %x\n",__FUNCTION__, Address, Value);
1150
 
1151
    if( Address >= 0x400000)
1152
    {
1153
        memptr = AcpiOsMapMemory(Address, Width);
1154
 
1155
        if(memptr)
1156
        {
1157
            status = AE_OK;
1158
 
1159
            switch (Width)
1160
            {
1161
                case 8:
1162
                    *(UINT8*)Address = (UINT8)Value;
1163
                    break;
1164
 
1165
                case 16:
1166
                    *(UINT16*)Address = (UINT16)Value;
1167
                    break;
1168
 
1169
                case 32:
1170
                    *(UINT32*)Address = Value;
1171
                    break;
1172
 
1173
                default:
1174
                    status = (AE_BAD_PARAMETER);
1175
            }
1176
            FreeKernelSpace(memptr);
1177
        }
1178
        return status;
1179
    }
1498 serge 1180
	else
1181
		Address+= 0x80000000;
1182
 
1183
    switch (Width)
1184
    {
1185
    case 8:
2187 Serge 1186
        *(UINT8*)Address = (UINT8)Value;
1187
        break;
1188
 
1498 serge 1189
    case 16:
2187 Serge 1190
        *(UINT16*)Address = (UINT16)Value;
1191
        break;
1192
 
1498 serge 1193
    case 32:
1194
        *(UINT32*)Address = Value;
1195
        break;
1196
 
1197
    default:
1198
        return (AE_BAD_PARAMETER);
1199
    }
1200
 
1201
    return (AE_OK);
1202
 
1203
}
1204
 
1205
 
1206
/******************************************************************************
1207
 *
1208
 * FUNCTION:    AcpiOsReadable
1209
 *
1210
 * PARAMETERS:  Pointer             - Area to be verified
1211
 *              Length              - Size of area
1212
 *
1213
 * RETURN:      TRUE if readable for entire length
1214
 *
1215
 * DESCRIPTION: Verify that a pointer is valid for reading
1216
 *
1217
 *****************************************************************************/
1218
 
1219
BOOLEAN
1220
AcpiOsReadable (
1221
    void                    *Pointer,
1222
    ACPI_SIZE               Length)
1223
{
1224
 
1225
    return (TRUE);
1226
}
1227
 
1228
 
1229
/******************************************************************************
1230
 *
1231
 * FUNCTION:    AcpiOsWritable
1232
 *
1233
 * PARAMETERS:  Pointer             - Area to be verified
1234
 *              Length              - Size of area
1235
 *
1236
 * RETURN:      TRUE if writable for entire length
1237
 *
1238
 * DESCRIPTION: Verify that a pointer is valid for writing
1239
 *
1240
 *****************************************************************************/
1241
 
1242
BOOLEAN
1243
AcpiOsWritable (
1244
    void                    *Pointer,
1245
    ACPI_SIZE               Length)
1246
{
1247
 
1248
    return (TRUE);
1249
}
1250
 
1251
 
1252
/******************************************************************************
1253
 *
1254
 * FUNCTION:    AcpiOsGetThreadId
1255
 *
1256
 * PARAMETERS:  None
1257
 *
1258
 * RETURN:      Id of the running thread
1259
 *
1260
 * DESCRIPTION: Get the Id of the current (running) thread
1261
 *
1262
 * NOTE:        The environment header should contain this line:
1263
 *                  #define ACPI_THREAD_ID pthread_t
1264
 *
1265
 *****************************************************************************/
1266
 
1267
ACPI_THREAD_ID
1268
AcpiOsGetThreadId (void)
1269
{
1270
 
1271
    return ( 1 );
1272
}
1273
 
1274
 
1275
/******************************************************************************
1276
 *
1277
 * FUNCTION:    AcpiOsSignal
1278
 *
1279
 * PARAMETERS:  Function            ACPI CA signal function code
1280
 *              Info                Pointer to function-dependent structure
1281
 *
1282
 * RETURN:      Status
1283
 *
1284
 * DESCRIPTION: Miscellaneous functions. Example implementation only.
1285
 *
1286
 *****************************************************************************/
1287
 
1288
ACPI_STATUS
1289
AcpiOsSignal (
1290
    UINT32                  Function,
1291
    void                    *Info)
1292
{
1293
 
1294
    switch (Function)
1295
    {
1296
    case ACPI_SIGNAL_FATAL:
1297
        break;
1298
 
1299
    case ACPI_SIGNAL_BREAKPOINT:
1300
        break;
1301
 
1302
    default:
1303
        break;
1304
    }
1305
 
1306
    return (AE_OK);
1307
}
1308