OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
OcAppleRamDiskLib.c File Reference
#include <Uefi.h>
#include <Guid/OcVariable.h>
#include <Protocol/AppleRamDisk.h>
#include <Library/BaseMemoryLib.h>
#include <Library/BaseOverflowLib.h>
#include <Library/OcDebugLogLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/OcAppleRamDiskLib.h>
#include <Library/OcFileLib.h>
#include <Library/OcMemoryLib.h>
#include <Library/OcMiscLib.h>
#include <Library/OcCryptoLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/UefiLib.h>

Go to the source code of this file.

Macros

#define INTERNAL_ASSERT_EXTENT_TABLE_VALID(ExtentTable)
 

Functions

STATIC VOID InternalAddAllocatedArea (IN OUT APPLE_RAM_DISK_EXTENT_TABLE **ExtentTable, IN EFI_PHYSICAL_ADDRESS AllocatedArea, IN UINTN AllocatedAreaSize)
 
STATIC UINTN InternalAllocateRemainingSize (IN EFI_PHYSICAL_ADDRESS BaseAddress, IN EFI_PHYSICAL_ADDRESS TopAddress, IN EFI_MEMORY_TYPE MemoryType, IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap, IN UINTN MemoryMapSize, IN UINTN DescriptorSize, IN UINTN RemainingSize, IN OUT APPLE_RAM_DISK_EXTENT_TABLE **ExtentTable)
 
STATIC CONST APPLE_RAM_DISK_EXTENT_TABLEInternalAppleRamDiskAllocate (IN UINTN Size, IN EFI_MEMORY_TYPE MemoryType, IN BOOLEAN PreferHighMem)
 
CONST APPLE_RAM_DISK_EXTENT_TABLEOcAppleRamDiskAllocate (IN UINTN Size, IN EFI_MEMORY_TYPE MemoryType)
 
BOOLEAN OcAppleRamDiskRead (IN CONST APPLE_RAM_DISK_EXTENT_TABLE *ExtentTable, IN UINTN Offset, IN UINTN Size, OUT VOID *Buffer)
 
BOOLEAN OcAppleRamDiskWrite (IN CONST APPLE_RAM_DISK_EXTENT_TABLE *ExtentTable, IN UINTN Offset, IN UINTN Size, IN CONST VOID *Buffer)
 
BOOLEAN OcAppleRamDiskLoadFile (IN CONST APPLE_RAM_DISK_EXTENT_TABLE *ExtentTable, IN EFI_FILE_PROTOCOL *File, IN UINTN FileSize)
 
VOID OcAppleRamDiskFree (IN CONST APPLE_RAM_DISK_EXTENT_TABLE *ExtentTable)
 

Detailed Description

Apple RAM Disk library.

Copyright (C) 2019, Download-Fritz. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php.

THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

Definition in file OcAppleRamDiskLib.c.

Macro Definition Documentation

◆ INTERNAL_ASSERT_EXTENT_TABLE_VALID

#define INTERNAL_ASSERT_EXTENT_TABLE_VALID ( ExtentTable)
Value:
ASSERT ((ExtentTable)->Reserved == 0); \
ASSERT ((ExtentTable)->ExtentCount > 0); \
UINT8 Reserved[430]
Definition Apm.h:39
#define ARRAY_SIZE(Array)
Definition AppleMacEfi.h:34
UINT32 Version
#define APPLE_RAM_DISK_EXTENT_SIGNATURE
APPLE_RAM_DISK_EXTENT Extents[APPLE_RAM_DISK_MAX_EXTENTS]
UINT64 Signature2
APPLE_RAM_DISK_EXTENT_TABLE ExtentTable
#define APPLE_RAM_DISK_EXTENT_VERSION
UINT32 ExtentCount
UINT8 Signature[8]
Definition BiosId.h:67
#define ASSERT(x)
Definition coder.h:55

Definition at line 34 of file OcAppleRamDiskLib.c.

Function Documentation

◆ InternalAddAllocatedArea()

STATIC VOID InternalAddAllocatedArea ( IN OUT APPLE_RAM_DISK_EXTENT_TABLE ** ExtentTable,
IN EFI_PHYSICAL_ADDRESS AllocatedArea,
IN UINTN AllocatedAreaSize )

Insert allocated area into extent list. If no extent list was created, then it gets allocated.

Parameters
[in,out]ExtentTableExtent table, potentially pointing to NULL.
[in]AllocatedAreaAllocated area of 1 or more pages. @paran[in] AllocatedAreaSize Actual size of allocated area in bytes.

Definition at line 52 of file OcAppleRamDiskLib.c.

◆ InternalAllocateRemainingSize()

STATIC UINTN InternalAllocateRemainingSize ( IN EFI_PHYSICAL_ADDRESS BaseAddress,
IN EFI_PHYSICAL_ADDRESS TopAddress,
IN EFI_MEMORY_TYPE MemoryType,
IN OUT EFI_MEMORY_DESCRIPTOR * MemoryMap,
IN UINTN MemoryMapSize,
IN UINTN DescriptorSize,
IN UINTN RemainingSize,
IN OUT APPLE_RAM_DISK_EXTENT_TABLE ** ExtentTable )

Perform allocation of RemainingSize data with biggest contiguous area first strategy. Allocation extent map is put to the first allocated extent.

Parameters
[in]BaseAddressStarting allocation address.
[in]TopAddressEnding allocation address.
[in]MemoryTypeRequested memory type.
[in,out]MemoryMapCurrent memory map modified as we go.
[in]MemoryMapSizeCurrent memory map size.
[in]DescriptorSizeCurrent memory map descriptor size.
[in]RemainingSizeRemaining size to allocate.
[in,out]ExtentTableUpdated pointer to allocated area.
Return values
Sizeof allocated data.

Definition at line 112 of file OcAppleRamDiskLib.c.

◆ InternalAppleRamDiskAllocate()

STATIC CONST APPLE_RAM_DISK_EXTENT_TABLE * InternalAppleRamDiskAllocate ( IN UINTN Size,
IN EFI_MEMORY_TYPE MemoryType,
IN BOOLEAN PreferHighMem )

Request allocation of Size bytes in extents table. Extents are put to the first allocated page.

  1. Retrieve actual memory mapping.
  2. Do allocation at BASE_4GB if requested.
  3. Do additional allocation at any address if still have pages to allocate.
Parameters
[in]SizeRequested memory size.
[in]MemoryTypeRequested memory type.
[in]PreferHighMemTry to allocate in upper 4GB first.
Return values
Allocatedextent table.

Definition at line 237 of file OcAppleRamDiskLib.c.

◆ OcAppleRamDiskAllocate()

CONST APPLE_RAM_DISK_EXTENT_TABLE * OcAppleRamDiskAllocate ( IN UINTN Size,
IN EFI_MEMORY_TYPE MemoryType )

Request allocation of Size bytes in extents table.

Parameters
[in]SizeRequested memory size.
[in]MemoryTypeRequested memory type.
Return values
Allocatedextent table.

Definition at line 322 of file OcAppleRamDiskLib.c.

◆ OcAppleRamDiskFree()

VOID OcAppleRamDiskFree ( IN CONST APPLE_RAM_DISK_EXTENT_TABLE * ExtentTable)

Free RAM disk.

Parameters
[in]ExtentTableAllocated extent table.

Definition at line 602 of file OcAppleRamDiskLib.c.

◆ OcAppleRamDiskLoadFile()

BOOLEAN OcAppleRamDiskLoadFile ( IN CONST APPLE_RAM_DISK_EXTENT_TABLE * ExtentTable,
IN EFI_FILE_PROTOCOL * File,
IN UINTN FileSize )

Definition at line 472 of file OcAppleRamDiskLib.c.

◆ OcAppleRamDiskRead()

BOOLEAN OcAppleRamDiskRead ( IN CONST APPLE_RAM_DISK_EXTENT_TABLE * ExtentTable,
IN UINTN Offset,
IN UINTN Size,
OUT VOID * Buffer )

Read RAM disk data.

Parameters
[in]ExtentTableAllocated extent table.
[in]OffsetOffset in RAM disk.
[in]SizeAmount of data to read.
[out]BufferResulting data.
Return values
TRUEon success.

Definition at line 354 of file OcAppleRamDiskLib.c.

◆ OcAppleRamDiskWrite()

BOOLEAN OcAppleRamDiskWrite ( IN CONST APPLE_RAM_DISK_EXTENT_TABLE * ExtentTable,
IN UINTN Offset,
IN UINTN Size,
IN CONST VOID * Buffer )

Write RAM disk data.

Parameters
[in]ExtentTableAllocated extent table.
[in]OffsetOffset in RAM disk.
[in]SizeAmount of data to write.
[in]BufferSource data.
Return values
TRUEon success.

Definition at line 413 of file OcAppleRamDiskLib.c.