1 /******************************************************************************
5 * Some or all of this work - Copyright (c) 1999 - 2008, Intel Corp.
10 * 2.1. This is your license from Intel Corp. under its intellectual property
11 * rights. You may have additional license terms from the party that provided
12 * you this software, covering your right to use that party's intellectual
15 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
16 * copy of the source code appearing in this file ("Covered Code") an
17 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
18 * base code distributed originally by Intel ("Original Intel Code") to copy,
19 * make derivatives, distribute, use and display any portion of the Covered
20 * Code in any form, with the right to sublicense such rights; and
22 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
23 * license (with the right to sublicense), under only those claims of Intel
24 * patents that are infringed by the Original Intel Code, to make, use, sell,
25 * offer to sell, and import the Covered Code and derivative works thereof
26 * solely to the minimum extent necessary to exercise the above copyright
27 * license, and in no event shall the patent license extend to any additions
28 * to or modifications of the Original Intel Code. No other license or right
29 * is granted directly or by implication, estoppel or otherwise;
31 * The above copyright and patent license is granted only if the following
36 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
37 * Redistribution of source code of any substantial portion of the Covered
38 * Code or modification with rights to further distribute source must include
39 * the above Copyright Notice, the above License, this list of Conditions,
40 * and the following Disclaimer and Export Compliance provision. In addition,
41 * Licensee must cause all Covered Code to which Licensee contributes to
42 * contain a file documenting the changes Licensee made to create that Covered
43 * Code and the date of any change. Licensee must include in that file the
44 * documentation of any changes made by any predecessor Licensee. Licensee
45 * must include a prominent statement that the modification is derived,
46 * directly or indirectly, from Original Intel Code.
48 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
49 * Redistribution of source code of any substantial portion of the Covered
50 * Code or modification without rights to further distribute source must
51 * include the following Disclaimer and Export Compliance provision in the
52 * documentation and/or other materials provided with distribution. In
53 * addition, Licensee may not authorize further sublicense of source of any
54 * portion of the Covered Code, and must include terms to the effect that the
55 * license from Licensee to its licensee is limited to the intellectual
56 * property embodied in the software Licensee provides to its licensee, and
57 * not to intellectual property embodied in modifications its licensee may
60 * 3.3. Redistribution of Executable. Redistribution in executable form of any
61 * substantial portion of the Covered Code or modification must reproduce the
62 * above Copyright Notice, and the following Disclaimer and Export Compliance
63 * provision in the documentation and/or other materials provided with the
66 * 3.4. Intel retains all right, title, and interest in and to the Original
69 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
70 * Intel shall be used in advertising or otherwise to promote the sale, use or
71 * other dealings in products derived from or relating to the Covered Code
72 * without prior written authorization from Intel.
74 * 4. Disclaimer and Export Compliance
76 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
77 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
78 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
79 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
80 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
81 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
84 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
85 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
86 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
87 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
88 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
89 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
90 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
93 * 4.3. Licensee shall not export, either directly or indirectly, any of this
94 * software or system incorporating such software without first obtaining any
95 * required license or other approval from the U. S. Department of Commerce or
96 * any other agency or department of the United States Government. In the
97 * event Licensee exports any such software from the United States or
98 * re-exports any such software from a foreign destination, Licensee shall
99 * ensure that the distribution and export/re-export of the software is in
100 * compliance with all laws, regulations, orders, or other restrictions of the
101 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
102 * any of its subsidiaries will export/re-export any technical data, process,
103 * software, or service, directly or indirectly, to any country for which the
104 * United States government or any agency thereof requires an export license,
105 * other governmental approval, or letter of assurance, without first obtaining
106 * such license, approval or letter.
108 *****************************************************************************/
113 #include <sys/time.h>
116 #include "accommon.h"
118 #include "acparser.h"
121 #include <minix/driver.h>
122 #include <machine/pci_intel.h>
124 extern struct machine machine
;
127 static u32_t
pci_inb(u16_t port
) {
130 if ((s
=sys_inb(port
, &value
)) !=OK
)
131 printf("ACPI: warning, sys_inb failed: %d\n", s
);
135 static u32_t
pci_inw(u16_t port
) {
138 if ((s
=sys_inw(port
, &value
)) !=OK
)
139 printf("ACPI: warning, sys_inw failed: %d\n", s
);
143 static u32_t
pci_inl(u16_t port
) {
146 if ((s
=sys_inl(port
, &value
)) !=OK
)
147 printf("ACPI: warning, sys_inl failed: %d\n", s
);
151 static void pci_outb(u16_t port
, u8_t value
) {
153 if ((s
=sys_outb(port
, value
)) !=OK
)
154 printf("ACPI: warning, sys_outb failed: %d\n", s
);
157 static void pci_outw(u16_t port
, u16_t value
) {
159 if ((s
=sys_outw(port
, value
)) !=OK
)
160 printf("ACPI: warning, sys_outw failed: %d\n", s
);
163 static void pci_outl(u16_t port
, u32_t value
) {
165 if ((s
=sys_outl(port
, value
)) !=OK
)
166 printf("ACPI: warning, sys_outl failed: %d\n", s
);
169 /******************************************************************************
171 * FUNCTION: AcpiOsInitialize, AcpiOsTerminate
177 * DESCRIPTION: Init and terminate. Nothing to do.
179 *****************************************************************************/
182 AcpiOsInitialize (void)
189 AcpiOsTerminate (void)
195 /******************************************************************************
197 * FUNCTION: AcpiOsPredefinedOverride
199 * PARAMETERS: InitVal - Initial value of the predefined object
200 * NewVal - The new value for the object
202 * RETURN: Status, pointer to value. Null pointer returned if not
205 * DESCRIPTION: Allow the OS to override predefined names
207 *****************************************************************************/
210 AcpiOsPredefinedOverride (
211 const ACPI_PREDEFINED_NAMES
*InitVal
,
219 /******************************************************************************
221 * FUNCTION: AcpiOsTableOverride
223 * PARAMETERS: ExistingTable - Header of current table (probably firmware)
224 * NewTable - Where an entire new table is returned.
226 * RETURN: Status, pointer to new table. Null pointer returned if no
227 * table is available to override
229 * DESCRIPTION: Return a different version of a table if one is available
231 *****************************************************************************/
234 AcpiOsTableOverride (
235 ACPI_TABLE_HEADER
*ExistingTable
,
236 ACPI_TABLE_HEADER
**NewTable
)
243 /******************************************************************************
245 * FUNCTION: AcpiOsReadable
247 * PARAMETERS: Pointer - Area to be verified
248 * Length - Size of area
250 * RETURN: TRUE if readable for entire length
252 * DESCRIPTION: Verify that a pointer is valid for reading
254 *****************************************************************************/
261 panic("NOTIMPLEMENTED %s\n", __func__
);
267 /******************************************************************************
269 * FUNCTION: AcpiOsWritable
271 * PARAMETERS: Pointer - Area to be verified
272 * Length - Size of area
274 * RETURN: TRUE if writable for entire length
276 * DESCRIPTION: Verify that a pointer is valid for writing
278 *****************************************************************************/
285 panic("NOTIMPLEMENTED %s\n", __func__
);
291 /******************************************************************************
293 * FUNCTION: AcpiOsRedirectOutput
295 * PARAMETERS: Destination - An open file handle/pointer
299 * DESCRIPTION: Causes redirect of AcpiOsPrintf and AcpiOsVprintf
301 *****************************************************************************/
304 AcpiOsRedirectOutput (
307 panic("NOTIMPLEMENTED %s\n", __func__
);
311 /******************************************************************************
313 * FUNCTION: AcpiOsPrintf
315 * PARAMETERS: fmt, ... Standard printf format
319 * DESCRIPTION: Formatted output
321 *****************************************************************************/
323 void ACPI_INTERNAL_VAR_XFACE
331 va_start (Args
, Fmt
);
334 AcpiOsVprintf (Fmt
, Args
);
342 /******************************************************************************
344 * FUNCTION: AcpiOsVprintf
346 * PARAMETERS: fmt Standard printf format
351 * DESCRIPTION: Formatted output with argument list pointer
353 *****************************************************************************/
366 /******************************************************************************
368 * FUNCTION: AcpiOsGetLine
370 * PARAMETERS: fmt Standard printf format
373 * RETURN: Actual bytes read
375 * DESCRIPTION: Formatted input with argument list pointer
377 *****************************************************************************/
383 panic("NOTIMPLEMENTED %s\n", __func__
);
387 /******************************************************************************
389 * FUNCTION: AcpiOsMapMemory
391 * PARAMETERS: where Physical address of memory to be mapped
392 * length How much memory to map
394 * RETURN: Pointer to mapped memory. Null on error.
396 * DESCRIPTION: Map physical memory into caller's address space
398 *****************************************************************************/
402 ACPI_PHYSICAL_ADDRESS where
, /* not page aligned */
403 ACPI_SIZE length
) /* in bytes, not page-aligned */
405 ACPI_PHYSICAL_ADDRESS addr
;
409 addr
= where
& ~0xfff; /* align to 4k */
410 sdiff
= where
- addr
;
411 vir
= vm_map_phys(SELF
, (void *) addr
, length
+ sdiff
);
413 return (void *) ((char *)vir
+ sdiff
);
417 /******************************************************************************
419 * FUNCTION: AcpiOsUnmapMemory
421 * PARAMETERS: where Logical address of memory to be unmapped
422 * length How much memory to unmap
426 * DESCRIPTION: Delete a previously created mapping. Where and Length must
427 * correspond to a previous mapping exactly.
429 *****************************************************************************/
439 /******************************************************************************
441 * FUNCTION: AcpiOsAllocate
443 * PARAMETERS: Size Amount to allocate, in bytes
445 * RETURN: Pointer to the new allocation. Null on error.
447 * DESCRIPTION: Allocate memory. Algorithm is dependent on the OS.
449 *****************************************************************************/
458 Mem
= (void *) malloc ((size_t) size
);
460 printf("AcpiOsAllocate out of memory\n");
466 /******************************************************************************
468 * FUNCTION: AcpiOsFree
470 * PARAMETERS: mem Pointer to previously allocated memory
474 * DESCRIPTION: Free memory allocated via AcpiOsAllocate
476 *****************************************************************************/
486 /******************************************************************************
488 * FUNCTION: AcpiOsCreateSemaphore
490 * PARAMETERS: InitialUnits - Units to be assigned to the new semaphore
491 * OutHandle - Where a handle will be returned
495 * DESCRIPTION: Create an OS semaphore
497 *****************************************************************************/
500 AcpiOsCreateSemaphore (
503 ACPI_HANDLE
*OutHandle
)
509 /******************************************************************************
511 * FUNCTION: AcpiOsDeleteSemaphore
513 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore
517 * DESCRIPTION: Delete an OS semaphore
519 *****************************************************************************/
522 AcpiOsDeleteSemaphore (
529 /******************************************************************************
531 * FUNCTION: AcpiOsWaitSemaphore
533 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore
534 * Units - How many units to wait for
535 * Timeout - How long to wait
539 * DESCRIPTION: Wait for units
541 *****************************************************************************/
544 AcpiOsWaitSemaphore (
553 /******************************************************************************
555 * FUNCTION: AcpiOsSignalSemaphore
557 * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore
558 * Units - Number of units to send
562 * DESCRIPTION: Send units
564 *****************************************************************************/
567 AcpiOsSignalSemaphore (
577 ACPI_SPINLOCK
*OutHandle
)
585 ACPI_SPINLOCK Handle
)
600 ACPI_SPINLOCK Handle
,
601 ACPI_CPU_FLAGS Flags
)
606 /******************************************************************************
608 * FUNCTION: AcpiOsInstallInterruptHandler
610 * PARAMETERS: InterruptNumber Level handler should respond to.
611 * Isr Address of the ACPI interrupt handler
612 * ExceptPtr Where status is returned
614 * RETURN: Handle to the newly installed handler.
616 * DESCRIPTION: Install an interrupt handler. Used to install the ACPI
617 * OS-independent handler.
619 *****************************************************************************/
622 AcpiOsInstallInterruptHandler (
623 UINT32 InterruptNumber
,
624 ACPI_OSD_HANDLER ServiceRoutine
,
627 printf("AcpiOsInstallInterruptHandler NOT SUPPORTED\n");
632 /******************************************************************************
634 * FUNCTION: AcpiOsRemoveInterruptHandler
636 * PARAMETERS: Handle Returned when handler was installed
640 * DESCRIPTION: Uninstalls an interrupt handler.
642 *****************************************************************************/
645 AcpiOsRemoveInterruptHandler (
646 UINT32 InterruptNumber
,
647 ACPI_OSD_HANDLER ServiceRoutine
)
649 printf("AcpiOsRemoveInterruptHandler NOT SUPPORTED\n");
654 /******************************************************************************
656 * FUNCTION: AcpiOsExecute
658 * PARAMETERS: Type - Type of execution
659 * Function - Address of the function to execute
660 * Context - Passed as a parameter to the function
664 * DESCRIPTION: Execute a new thread
666 *****************************************************************************/
670 ACPI_EXECUTE_TYPE Type
,
671 ACPI_OSD_EXEC_CALLBACK Function
,
674 panic("NOTIMPLEMENTED %s\n", __func__
);
679 /******************************************************************************
681 * FUNCTION: AcpiOsBreakpoint
683 * PARAMETERS: Msg Message to print
687 * DESCRIPTION: Print a message and break to the debugger.
689 *****************************************************************************/
695 panic("NOTIMPLEMENTED %s\n", __func__
);
700 /******************************************************************************
702 * FUNCTION: AcpiOsStall
704 * PARAMETERS: microseconds To sleep
706 * RETURN: Blocks until sleep is completed.
708 * DESCRIPTION: Sleep at microsecond granularity
710 *****************************************************************************/
716 if (microseconds
> 0)
717 usleep (microseconds
);
723 /******************************************************************************
725 * FUNCTION: AcpiOsSleep
727 * PARAMETERS: milliseconds To sleep
729 * RETURN: Blocks until sleep is completed.
731 * DESCRIPTION: Sleep at millisecond granularity
733 *****************************************************************************/
737 ACPI_INTEGER milliseconds
)
739 if ((milliseconds
/ 1000) > 0)
740 sleep (milliseconds
/ 1000);
742 if ((milliseconds
% 1000) > 0)
743 usleep ((milliseconds
% 1000) * 1000);
748 /******************************************************************************
750 * FUNCTION: AcpiOsGetTimer
754 * RETURN: Current time in 100 nanosecond units
756 * DESCRIPTION: Get the current system time
758 *****************************************************************************/
761 AcpiOsGetTimer (void)
765 gettimeofday (&time
, NULL
);
766 return (((UINT64
) time
.tv_sec
* 10000000) +
767 ((UINT64
) time
.tv_usec
* 10));
771 /******************************************************************************
773 * FUNCTION: AcpiOsValidateInterface
775 * PARAMETERS: Interface - Requested interface to be validated
777 * RETURN: AE_OK if interface is supported, AE_SUPPORT otherwise
779 * DESCRIPTION: Match an interface string to the interfaces supported by the
780 * host. Strings originate from an AML call to the _OSI method.
782 *****************************************************************************/
785 AcpiOsValidateInterface (
792 /* TEMPORARY STUB FUNCTION */
799 /* we do nothing here, we keep the PciId unchanged */
803 /******************************************************************************
805 * FUNCTION: AcpiOsReadPort
807 * PARAMETERS: Address Address of I/O port/register to read
808 * Value Where value is placed
809 * Width Number of bits
811 * RETURN: Value read from port
813 * DESCRIPTION: Read data from an I/O port or register
815 *****************************************************************************/
819 ACPI_IO_ADDRESS Address
,
826 sys_inb(Address
, Value
);
829 sys_inw(Address
, Value
);
832 sys_inl(Address
, Value
);
839 /******************************************************************************
841 * FUNCTION: AcpiOsWritePort
843 * PARAMETERS: Address Address of I/O port/register to write
844 * Value Value to write
845 * Width Number of bits
849 * DESCRIPTION: Write data to an I/O port or register
851 *****************************************************************************/
855 ACPI_IO_ADDRESS Address
,
861 sys_outb(Address
, Value
);
864 sys_outw(Address
, Value
);
867 sys_outl(Address
, Value
);
875 /******************************************************************************
877 * FUNCTION: AcpiOsReadMemory
879 * PARAMETERS: Address Physical Memory Address to read
880 * Value Where value is placed
881 * Width Number of bits
883 * RETURN: Value read from physical memory address
885 * DESCRIPTION: Read data from a physical memory address
887 *****************************************************************************/
891 ACPI_PHYSICAL_ADDRESS Address
,
895 /* FIXME this operation is ignored */
902 /******************************************************************************
904 * FUNCTION: AcpiOsWriteMemory
906 * PARAMETERS: Address Physical Memory Address to write
907 * Value Value to write
908 * Width Number of bits
912 * DESCRIPTION: Write data to a physical memory address
914 *****************************************************************************/
918 ACPI_PHYSICAL_ADDRESS Address
,
922 /* FIXME this operation is ignored */
928 AcpiOsGetThreadId(void)
930 return (ACPI_THREAD_ID
) 1;
934 /******************************************************************************
936 * FUNCTION: AcpiOsSignal
938 * PARAMETERS: Function ACPI CA signal function code
939 * Info Pointer to function-dependent structure
943 * DESCRIPTION: Miscellaneous functions
945 *****************************************************************************/
952 panic("NOTIMPLEMENTED %s\n", __func__
);
956 /******************************************************************************
958 * FUNCTION: AcpiOsGetRootPointer
962 * RETURN: RSDP physical address
964 * DESCRIPTION: Gets the root pointer (RSDP)
966 *****************************************************************************/
968 ACPI_PHYSICAL_ADDRESS
AcpiOsGetRootPointer (
971 return machine
.acpi_rsdp
;
974 /******************************************************************************
976 * FUNCTION: AcpiOsReadPciConfiguration
978 * PARAMETERS: PciId Seg/Bus/Dev
979 * Register Device Register
980 * Value Buffer where value is placed
981 * Width Number of bits
985 * DESCRIPTION: Read data from PCI configuration space
987 *****************************************************************************/
990 AcpiOsReadPciConfiguration (
1000 *(u8_t
*)Value
= PCII_RREG8_(PciId
->Bus
, PciId
->Device
,
1001 PciId
->Function
, Register
);
1004 *(u16_t
*)Value
= PCII_RREG16_(PciId
->Bus
, PciId
->Device
,
1005 PciId
->Function
, Register
);
1008 *(u32_t
*)Value
= PCII_RREG32_(PciId
->Bus
, PciId
->Device
,
1009 PciId
->Function
, Register
);
1012 panic("NOT IMPLEMENTED\n");
1015 if (OK
!= (err
= sys_outl(PCII_CONFADD
, PCII_UNSEL
)))
1016 printf("ACPI: warning, sys_outl failed: %d\n", err
);
1022 /******************************************************************************
1024 * FUNCTION: AcpiOsWritePciConfiguration
1026 * PARAMETERS: PciId Seg/Bus/Dev
1027 * Register Device Register
1028 * Value Value to be written
1029 * Width Number of bits
1033 * DESCRIPTION: Write data to PCI configuration space
1035 *****************************************************************************/
1038 AcpiOsWritePciConfiguration (
1048 PCII_WREG8_(PciId
->Bus
, PciId
->Device
,
1049 PciId
->Function
, Register
, Value
);
1052 PCII_WREG16_(PciId
->Bus
, PciId
->Device
,
1053 PciId
->Function
, Register
, Value
);
1056 PCII_WREG32_(PciId
->Bus
, PciId
->Device
,
1057 PciId
->Function
, Register
, Value
);
1060 panic("NOT IMPLEMENTED\n");
1063 if (OK
!= (err
= sys_outl(PCII_CONFADD
, PCII_UNSEL
)))
1064 printf("ACPI: warning, sys_outl failed: %d\n", err
);