Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:09

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup RTEMSBSPsX8664AMD64
0007  *
0008  * @ingroup RTEMSBSPsX8664AMD64EFI
0009  *
0010  * @brief ACPICA OS Services Layer interfaces
0011  */
0012 
0013 /*
0014  * Copyright (C) 2024 Matheus Pecoraro
0015  *
0016  * Redistribution and use in source and binary forms, with or without
0017  * modification, are permitted provided that the following conditions
0018  * are met:
0019  * 1. Redistributions of source code must retain the above copyright
0020  *    notice, this list of conditions and the following disclaimer.
0021  * 2. Redistributions in binary form must reproduce the above copyright
0022  *    notice, this list of conditions and the following disclaimer in the
0023  *    documentation and/or other materials provided with the distribution.
0024  *
0025  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0026  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0027  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0028  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0029  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0030  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0031  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0032  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0033  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0034  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0035  * POSSIBILITY OF SUCH DAMAGE.
0036  */
0037 
0038 #include <acpi/acpica/acpi.h>
0039 
0040 #include <stdint.h>
0041 
0042 void* AcpiOsAllocate(ACPI_SIZE Size)
0043 {
0044   return malloc(Size);
0045 }
0046 
0047 void AcpiOsFree(void* Memory)
0048 {
0049   free(Memory);
0050 }
0051 
0052 void* AcpiOsMapMemory(ACPI_PHYSICAL_ADDRESS PhysicalAddress, ACPI_SIZE Length)
0053 {
0054   /* We have an identity map set up, simply return the address */
0055   return (void*) PhysicalAddress;
0056 }
0057 
0058 void AcpiOsUnmapMemory(void* LogicalAddress, ACPI_SIZE Length)
0059 {
0060   /* We have an identity map set up, do nothing */
0061   return;
0062 }
0063 
0064 ACPI_STATUS AcpiOsGetPhysicalAddress(
0065   void* LogicalAddress,
0066   ACPI_PHYSICAL_ADDRESS* PhysicalAddress
0067 )
0068 {
0069   /* We have an identity map set up, simply return the address */
0070   *PhysicalAddress = (uint64_t) LogicalAddress;
0071   return (AE_OK);
0072 }
0073 
0074 BOOLEAN AcpiOsReadable(void* Pointer, ACPI_SIZE Length)
0075 {
0076   return (TRUE);
0077 }
0078 
0079 BOOLEAN AcpiOsWritable(void* Pointer, ACPI_SIZE Length)
0080 {
0081   return (TRUE);
0082 }
0083 
0084 ACPI_STATUS AcpiOsReadMemory(
0085   ACPI_PHYSICAL_ADDRESS Address,
0086   UINT64* Value,
0087   UINT32 Width
0088 )
0089 {
0090   /* We have an identity map set up, simply use the physical address */
0091   switch (Width) {
0092   case 8:
0093     *Value = *(volatile uint8_t*) Address;
0094     break;
0095   case 16:
0096     *Value = *(volatile uint16_t*) Address;
0097     break;
0098   case 32:
0099     *Value = *(volatile uint32_t*) Address;
0100     break;
0101   case 64:
0102     *Value = *(volatile uint64_t*) Address;
0103     break;
0104   }
0105 
0106   return (AE_OK);
0107 }
0108 
0109 ACPI_STATUS AcpiOsWriteMemory(
0110   ACPI_PHYSICAL_ADDRESS Address,
0111   UINT64 Value,
0112   UINT32 Width
0113 )
0114 {
0115   /* We have an identity map set up, simply use the physical address */
0116   switch (Width) {
0117   case 8:
0118     *(volatile uint8_t*) Address = (uint8_t) Value;
0119     break;
0120   case 16:
0121     *(volatile uint16_t*) Address = (uint16_t) Value;
0122     break;
0123   case 32:
0124     *(volatile uint32_t*) Address = (uint32_t) Value;
0125     break;
0126   case 64:
0127     *(volatile uint64_t*) Address = (uint64_t) Value;
0128     break;
0129   }
0130 
0131   return (AE_OK);
0132 }