/****************************************************************************** * * Module Name: osminixxf - MINIX3 OSL interfaces * *****************************************************************************/ /* * Copyright (C) 2000 - 2014, Intel Corp. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions, and the following disclaimer, * without modification. * 2. Redistributions in binary form must reproduce at minimum a disclaimer * substantially similar to the "NO WARRANTY" disclaimer below * ("Disclaimer") and any redistribution must be conditioned upon * including a substantially similar Disclaimer requirement for further * binary redistribution. * 3. Neither the names of the above-listed copyright holders nor the names * of any contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * Alternatively, this software may be distributed under the terms of the * GNU General Public License ("GPL") version 2 as published by the Free * Software Foundation. * * NO WARRANTY * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGES. */ #include #include #include #include #include "acpi.h" #include "accommon.h" #include "amlcode.h" #include "acparser.h" #include "acdebug.h" #include #include extern struct machine machine; static u32_t pci_inb(u16_t port) { u32_t value; int s; if ((s=sys_inb(port, &value)) !=OK) printf("ACPI: warning, sys_inb failed: %d\n", s); return value; } static u32_t pci_inw(u16_t port) { u32_t value; int s; if ((s=sys_inw(port, &value)) !=OK) printf("ACPI: warning, sys_inw failed: %d\n", s); return value; } static u32_t pci_inl(u16_t port) { u32_t value; int s; if ((s=sys_inl(port, &value)) !=OK) printf("ACPI: warning, sys_inl failed: %d\n", s); return value; } static void pci_outb(u16_t port, u8_t value) { int s; if ((s=sys_outb(port, value)) !=OK) printf("ACPI: warning, sys_outb failed: %d\n", s); } static void pci_outw(u16_t port, u16_t value) { int s; if ((s=sys_outw(port, value)) !=OK) printf("ACPI: warning, sys_outw failed: %d\n", s); } static void pci_outl(u16_t port, u32_t value) { int s; if ((s=sys_outl(port, value)) !=OK) printf("ACPI: warning, sys_outl failed: %d\n", s); } /****************************************************************************** * * FUNCTION: AcpiOsInitialize, AcpiOsTerminate * * PARAMETERS: None * * RETURN: Status * * DESCRIPTION: Init and terminate. Nothing to do. * *****************************************************************************/ ACPI_STATUS AcpiOsInitialize (void) { return AE_OK; } ACPI_STATUS AcpiOsTerminate (void) { return AE_OK; } /****************************************************************************** * * FUNCTION: AcpiOsPredefinedOverride * * PARAMETERS: InitVal - Initial value of the predefined object * NewVal - The new value for the object * * RETURN: Status, pointer to value. Null pointer returned if not * overriding. * * DESCRIPTION: Allow the OS to override predefined names * *****************************************************************************/ ACPI_STATUS AcpiOsPredefinedOverride ( const ACPI_PREDEFINED_NAMES *InitVal, ACPI_STRING *NewVal) { *NewVal = NULL; return (AE_OK); } /****************************************************************************** * * FUNCTION: AcpiOsTableOverride * * PARAMETERS: ExistingTable - Header of current table (probably firmware) * NewTable - Where an entire new table is returned. * * RETURN: Status, pointer to new table. Null pointer returned if no * table is available to override * * DESCRIPTION: Return a different version of a table if one is available * *****************************************************************************/ ACPI_STATUS AcpiOsTableOverride ( ACPI_TABLE_HEADER *ExistingTable, ACPI_TABLE_HEADER **NewTable) { *NewTable = NULL; return (AE_OK); } /****************************************************************************** * * FUNCTION: AcpiOsReadable * * PARAMETERS: Pointer - Area to be verified * Length - Size of area * * RETURN: TRUE if readable for entire length * * DESCRIPTION: Verify that a pointer is valid for reading * *****************************************************************************/ BOOLEAN AcpiOsReadable ( void *Pointer, ACPI_SIZE Length) { panic("NOTIMPLEMENTED %s\n", __func__); return (TRUE); } /****************************************************************************** * * FUNCTION: AcpiOsWritable * * PARAMETERS: Pointer - Area to be verified * Length - Size of area * * RETURN: TRUE if writable for entire length * * DESCRIPTION: Verify that a pointer is valid for writing * *****************************************************************************/ BOOLEAN AcpiOsWritable ( void *Pointer, ACPI_SIZE Length) { panic("NOTIMPLEMENTED %s\n", __func__); return (TRUE); } /****************************************************************************** * * FUNCTION: AcpiOsPhysicalTableOverride * * PARAMETERS: ExistingTable - Header of current table (probably firmware) * NewAddress - Where new table address is returned * (Physical address) * NewTableLength - Where new table length is returned * * RETURN: Status, address/length of new table. Null pointer returned * if no table is available to override. * *****************************************************************************/ ACPI_STATUS AcpiOsPhysicalTableOverride ( ACPI_TABLE_HEADER *ExistingTable, ACPI_PHYSICAL_ADDRESS *NewAddress, UINT32 *NewTableLength) { *NewAddress = 0; return (AE_OK); } /****************************************************************************** * * FUNCTION: AcpiOsRedirectOutput * * PARAMETERS: Destination - An open file handle/pointer * * RETURN: None * * DESCRIPTION: Causes redirect of AcpiOsPrintf and AcpiOsVprintf * *****************************************************************************/ void AcpiOsRedirectOutput ( void *Destination) { panic("NOTIMPLEMENTED %s\n", __func__); } /****************************************************************************** * * FUNCTION: AcpiOsPrintf * * PARAMETERS: fmt, ... Standard printf format * * RETURN: None * * DESCRIPTION: Formatted output * *****************************************************************************/ void ACPI_INTERNAL_VAR_XFACE AcpiOsPrintf ( const char *Fmt, ...) { va_list Args; va_start (Args, Fmt); #ifdef ACPI_BF_DEBUG AcpiOsVprintf (Fmt, Args); #endif va_end (Args); return; } /****************************************************************************** * * FUNCTION: AcpiOsVprintf * * PARAMETERS: fmt Standard printf format * args Argument list * * RETURN: None * * DESCRIPTION: Formatted output with argument list pointer * *****************************************************************************/ void AcpiOsVprintf ( const char *Fmt, va_list Args) { printf("ACPI: "); vprintf (Fmt, Args); printf("\n"); } /****************************************************************************** * * FUNCTION: AcpiOsGetLine * * PARAMETERS: Buffer - Where to return the command line * BufferLength - Maximum length of Buffer * BytesRead - Where the actual byte count is returned * * RETURN: Status and actual bytes read * * DESCRIPTION: Get the next input line from the terminal. NOTE: For the * AcpiExec utility, we use the acgetline module instead to * provide line-editing and history support. * *****************************************************************************/ ACPI_STATUS AcpiOsGetLine ( char *Buffer, UINT32 BufferLength, UINT32 *BytesRead) { panic("NOTIMPLEMENTED %s\n", __func__); return 0; } /****************************************************************************** * * FUNCTION: AcpiOsMapMemory * * PARAMETERS: where Physical address of memory to be mapped * length How much memory to map * * RETURN: Pointer to mapped memory. Null on error. * * DESCRIPTION: Map physical memory into caller's address space * *****************************************************************************/ void * AcpiOsMapMemory ( ACPI_PHYSICAL_ADDRESS where, /* not page aligned */ ACPI_SIZE length) /* in bytes, not page-aligned */ { return vm_map_phys(SELF, (void *) where, length); } /****************************************************************************** * * FUNCTION: AcpiOsUnmapMemory * * PARAMETERS: where Logical address of memory to be unmapped * length How much memory to unmap * * RETURN: None. * * DESCRIPTION: Delete a previously created mapping. Where and Length must * correspond to a previous mapping exactly. * *****************************************************************************/ void AcpiOsUnmapMemory ( void *where, ACPI_SIZE length) { vm_unmap_phys(SELF, where, length); } /****************************************************************************** * * FUNCTION: AcpiOsAllocate * * PARAMETERS: Size Amount to allocate, in bytes * * RETURN: Pointer to the new allocation. Null on error. * * DESCRIPTION: Allocate memory. Algorithm is dependent on the OS. * *****************************************************************************/ void * AcpiOsAllocate ( ACPI_SIZE size) { void *Mem; Mem = (void *) malloc ((size_t) size); if (Mem == NULL) printf("AcpiOsAllocate out of memory\n"); return Mem; } /****************************************************************************** * * FUNCTION: AcpiOsFree * * PARAMETERS: mem Pointer to previously allocated memory * * RETURN: None. * * DESCRIPTION: Free memory allocated via AcpiOsAllocate * *****************************************************************************/ void AcpiOsFree ( void *mem) { free(mem); } /****************************************************************************** * * FUNCTION: AcpiOsCreateSemaphore * * PARAMETERS: InitialUnits - Units to be assigned to the new semaphore * OutHandle - Where a handle will be returned * * RETURN: Status * * DESCRIPTION: Create an OS semaphore * *****************************************************************************/ ACPI_STATUS AcpiOsCreateSemaphore ( UINT32 MaxUnits, UINT32 InitialUnits, ACPI_HANDLE *OutHandle) { *OutHandle = NULL; return AE_OK; } /****************************************************************************** * * FUNCTION: AcpiOsDeleteSemaphore * * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore * * RETURN: Status * * DESCRIPTION: Delete an OS semaphore * *****************************************************************************/ ACPI_STATUS AcpiOsDeleteSemaphore ( ACPI_HANDLE Handle) { return AE_OK; } /****************************************************************************** * * FUNCTION: AcpiOsWaitSemaphore * * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore * Units - How many units to wait for * Timeout - How long to wait * * RETURN: Status * * DESCRIPTION: Wait for units * *****************************************************************************/ ACPI_STATUS AcpiOsWaitSemaphore ( ACPI_HANDLE Handle, UINT32 Units, UINT16 Timeout) { return AE_OK; } /****************************************************************************** * * FUNCTION: AcpiOsSignalSemaphore * * PARAMETERS: Handle - Handle returned by AcpiOsCreateSemaphore * Units - Number of units to send * * RETURN: Status * * DESCRIPTION: Send units * *****************************************************************************/ ACPI_STATUS AcpiOsSignalSemaphore ( ACPI_HANDLE Handle, UINT32 Units) { return AE_OK; } ACPI_STATUS AcpiOsCreateLock ( ACPI_SPINLOCK *OutHandle) { *OutHandle = NULL; return AE_OK; } void AcpiOsDeleteLock ( ACPI_SPINLOCK Handle) { } ACPI_CPU_FLAGS AcpiOsAcquireLock ( ACPI_HANDLE Handle) { return (0); } void AcpiOsReleaseLock ( ACPI_SPINLOCK Handle, ACPI_CPU_FLAGS Flags) { } /****************************************************************************** * * FUNCTION: AcpiOsInstallInterruptHandler * * PARAMETERS: InterruptNumber Level handler should respond to. * Isr Address of the ACPI interrupt handler * ExceptPtr Where status is returned * * RETURN: Handle to the newly installed handler. * * DESCRIPTION: Install an interrupt handler. Used to install the ACPI * OS-independent handler. * *****************************************************************************/ UINT32 AcpiOsInstallInterruptHandler ( UINT32 InterruptNumber, ACPI_OSD_HANDLER ServiceRoutine, void *Context) { printf("ACPI: no support for power interrupt yet\n"); return AE_OK; } /****************************************************************************** * * FUNCTION: AcpiOsRemoveInterruptHandler * * PARAMETERS: Handle Returned when handler was installed * * RETURN: Status * * DESCRIPTION: Uninstalls an interrupt handler. * *****************************************************************************/ ACPI_STATUS AcpiOsRemoveInterruptHandler ( UINT32 InterruptNumber, ACPI_OSD_HANDLER ServiceRoutine) { printf("ACPI: no support for power interrupt yet\n"); return AE_OK; } /****************************************************************************** * * FUNCTION: AcpiOsExecute * * PARAMETERS: Type - Type of execution * Function - Address of the function to execute * Context - Passed as a parameter to the function * * RETURN: Status. * * DESCRIPTION: Execute a new thread * *****************************************************************************/ ACPI_STATUS AcpiOsExecute ( ACPI_EXECUTE_TYPE Type, ACPI_OSD_EXEC_CALLBACK Function, void *Context) { panic("NOTIMPLEMENTED %s\n", __func__); return AE_OK; } /****************************************************************************** * * FUNCTION: AcpiOsBreakpoint * * PARAMETERS: Msg Message to print * * RETURN: Status * * DESCRIPTION: Print a message and break to the debugger. * *****************************************************************************/ ACPI_STATUS AcpiOsBreakpoint ( char *Msg) { panic("NOTIMPLEMENTED %s\n", __func__); return AE_OK; } /****************************************************************************** * * FUNCTION: AcpiOsStall * * PARAMETERS: microseconds To sleep * * RETURN: Blocks until sleep is completed. * * DESCRIPTION: Sleep at microsecond granularity * *****************************************************************************/ void AcpiOsStall ( UINT32 microseconds) { if (microseconds > 0) usleep (microseconds); return; } /****************************************************************************** * * FUNCTION: AcpiOsSleep * * PARAMETERS: milliseconds To sleep * * RETURN: Blocks until sleep is completed. * * DESCRIPTION: Sleep at millisecond granularity * *****************************************************************************/ void AcpiOsSleep ( ACPI_INTEGER milliseconds) { if ((milliseconds / 1000) > 0) sleep (milliseconds / 1000); if ((milliseconds % 1000) > 0) usleep ((milliseconds % 1000) * 1000); return; } /****************************************************************************** * * FUNCTION: AcpiOsGetTimer * * PARAMETERS: None * * RETURN: Current time in 100 nanosecond units * * DESCRIPTION: Get the current system time * *****************************************************************************/ UINT64 AcpiOsGetTimer (void) { struct timeval time; gettimeofday (&time, NULL); return (((UINT64) time.tv_sec * 10000000) + ((UINT64) time.tv_usec * 10)); } /****************************************************************************** * * FUNCTION: AcpiOsValidateInterface * * PARAMETERS: Interface - Requested interface to be validated * * RETURN: AE_OK if interface is supported, AE_SUPPORT otherwise * * DESCRIPTION: Match an interface string to the interfaces supported by the * host. Strings originate from an AML call to the _OSI method. * *****************************************************************************/ ACPI_STATUS AcpiOsValidateInterface ( char *Interface) { return (AE_SUPPORT); } /* TEMPORARY STUB FUNCTION */ void AcpiOsDerivePciId( ACPI_HANDLE rhandle, ACPI_HANDLE chandle, ACPI_PCI_ID **PciId) { /* we do nothing here, we keep the PciId unchanged */ } /****************************************************************************** * * FUNCTION: AcpiOsReadPort * * PARAMETERS: Address Address of I/O port/register to read * Value Where value is placed * Width Number of bits * * RETURN: Value read from port * * DESCRIPTION: Read data from an I/O port or register * *****************************************************************************/ ACPI_STATUS AcpiOsReadPort ( ACPI_IO_ADDRESS Address, UINT32 *Value, UINT32 Width) { *Value = 0; switch (Width) { case 8: sys_inb(Address, Value); break; case 16: sys_inw(Address, Value); break; case 32: sys_inl(Address, Value); break; default: panic("unsupported width: %d", Width); } return AE_OK; } /****************************************************************************** * * FUNCTION: AcpiOsWritePort * * PARAMETERS: Address Address of I/O port/register to write * Value Value to write * Width Number of bits * * RETURN: None * * DESCRIPTION: Write data to an I/O port or register * *****************************************************************************/ ACPI_STATUS AcpiOsWritePort ( ACPI_IO_ADDRESS Address, UINT32 Value, UINT32 Width) { switch (Width) { case 8: sys_outb(Address, Value); break; case 16: sys_outw(Address, Value); break; case 32: sys_outl(Address, Value); break; default: panic("unsupported width: %d", Width); } return AE_OK; } /****************************************************************************** * * FUNCTION: AcpiOsReadMemory * * PARAMETERS: Address Physical Memory Address to read * Value Where value is placed * Width Number of bits * * RETURN: Value read from physical memory address * * DESCRIPTION: Read data from a physical memory address * *****************************************************************************/ ACPI_STATUS AcpiOsReadMemory ( ACPI_PHYSICAL_ADDRESS Address, UINT64 *Value, UINT32 Width) { /* FIXME this operation is ignored */ *Value = 0; return (AE_OK); } /****************************************************************************** * * FUNCTION: AcpiOsWriteMemory * * PARAMETERS: Address Physical Memory Address to write * Value Value to write * Width Number of bits * * RETURN: None * * DESCRIPTION: Write data to a physical memory address * *****************************************************************************/ ACPI_STATUS AcpiOsWriteMemory ( ACPI_PHYSICAL_ADDRESS Address, UINT64 Value, UINT32 Width) { /* FIXME this operation is ignored */ return (AE_OK); } ACPI_THREAD_ID AcpiOsGetThreadId(void) { return (ACPI_THREAD_ID) 1; } /****************************************************************************** * * FUNCTION: AcpiOsSignal * * PARAMETERS: Function ACPI CA signal function code * Info Pointer to function-dependent structure * * RETURN: Status * * DESCRIPTION: Miscellaneous functions * *****************************************************************************/ ACPI_STATUS AcpiOsSignal ( UINT32 Function, void *Info) { panic("NOTIMPLEMENTED %s\n", __func__); return (AE_OK); } /****************************************************************************** * * FUNCTION: AcpiOsGetRootPointer * * PARAMETERS: None * * RETURN: RSDP physical address * * DESCRIPTION: Gets the root pointer (RSDP) * *****************************************************************************/ ACPI_PHYSICAL_ADDRESS AcpiOsGetRootPointer ( void) { return machine.acpi_rsdp; } /****************************************************************************** * * FUNCTION: AcpiOsReadPciConfiguration * * PARAMETERS: PciId Seg/Bus/Dev * Register Device Register * Value Buffer where value is placed * Width Number of bits * * RETURN: Status * * DESCRIPTION: Read data from PCI configuration space * *****************************************************************************/ ACPI_STATUS AcpiOsReadPciConfiguration ( ACPI_PCI_ID *PciId, UINT32 Register, UINT64 *Value, UINT32 Width) { int err; switch (Width) { case 8: *(u8_t *)Value = PCII_RREG8_(PciId->Bus, PciId->Device, PciId->Function, Register); break; case 16: *(u16_t *)Value = PCII_RREG16_(PciId->Bus, PciId->Device, PciId->Function, Register); break; case 32: *(u32_t *)Value = PCII_RREG32_(PciId->Bus, PciId->Device, PciId->Function, Register); break; default: panic("NOT IMPLEMENTED\n"); } if (OK != (err = sys_outl(PCII_CONFADD, PCII_UNSEL))) printf("ACPI: warning, sys_outl failed: %d\n", err); return AE_OK; } /****************************************************************************** * * FUNCTION: AcpiOsWritePciConfiguration * * PARAMETERS: PciId Seg/Bus/Dev * Register Device Register * Value Value to be written * Width Number of bits * * RETURN: Status. * * DESCRIPTION: Write data to PCI configuration space * *****************************************************************************/ ACPI_STATUS AcpiOsWritePciConfiguration ( ACPI_PCI_ID *PciId, UINT32 Register, ACPI_INTEGER Value, UINT32 Width) { int err; switch (Width) { case 8: PCII_WREG8_(PciId->Bus, PciId->Device, PciId->Function, Register, Value); break; case 16: PCII_WREG16_(PciId->Bus, PciId->Device, PciId->Function, Register, Value); break; case 32: PCII_WREG32_(PciId->Bus, PciId->Device, PciId->Function, Register, Value); break; default: panic("NOT IMPLEMENTED\n"); } if (OK != (err = sys_outl(PCII_CONFADD, PCII_UNSEL))) printf("ACPI: warning, sys_outl failed: %d\n", err); return AE_OK; } /****************************************************************************** * * FUNCTION: AcpiOsWaitEventsComplete * * PARAMETERS: None * * RETURN: None * * DESCRIPTION: Wait for all asynchronous events to complete. This * implementation does nothing. * *****************************************************************************/ void AcpiOsWaitEventsComplete ( void) { return; }