OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
AppleRamDisk.h File Reference
#include <Protocol/BlockIo.h>
#include <Protocol/DevicePath.h>

Go to the source code of this file.

Data Structures

struct  APPLE_RAM_DISK_PROTOCOL
 
struct  APPLE_RAM_DISK
 
struct  APPLE_RAM_DISK_INSTANCE
 

Macros

#define APPLE_RAM_DISK_PROTOCOL_GUID
 
#define APPLE_DMG_BOOT_PROTOCOL_REVISION   3
 
#define APPLE_RAM_DISK_EXTENT_SIGNATURE   0x544E5458444D4152ULL
 
#define APPLE_RAM_DISK_EXTENT_VERSION   0x10000U
 
#define APPLE_RAM_DISK_MAX_EXTENTS   0xFE
 
#define APPLE_RAM_DISK_INSTANCE_SIGNATURE   0x444D4152U
 
#define APPLE_RAM_DISK_DEFAULT_SIZE   0xA00000U
 

Typedefs

struct { 
 
   UINT64   Start 
 
   UINT64   Length 
 
APPLE_RAM_DISK_EXTENT 
 
struct { 
 
   UINT64   Signature 
 
   UINT32   Version 
 
   UINT32   ExtentCount 
 
   APPLE_RAM_DISK_EXTENT   Extents [APPLE_RAM_DISK_MAX_EXTENTS
 
   UINT64   Reserved 
 
   UINT64   Signature2 
 
APPLE_RAM_DISK_EXTENT_TABLE 
 
struct { 
 
   UINT64   ExtentCount 
 
   UINT64   Reserved1 
 
   UINT64   DiskSize 
 
   APPLE_RAM_DISK_EXTENT   Extents [APPLE_RAM_DISK_MAX_EXTENTS
 
   UINT64   Reserved2 
 
   APPLE_RAM_DISK_EXTENT_TABLE   ExtentTable 
 
APPLE_RAM_DISK_CONTEXT 
 
struct { 
 
   VENDOR_DEVICE_PATH   Vendor 
 
   UINT32   Counter 
 
APPLE_RAM_DISK_DP_VENDOR 
 
struct { 
 
   APPLE_RAM_DISK_DP_VENDOR   Vendor 
 
   MEMMAP_DEVICE_PATH   MemMap 
 
APPLE_RAM_DISK_DP_HEADER 
 
struct { 
 
   APPLE_RAM_DISK_DP_VENDOR   Vendor 
 
   MEMMAP_DEVICE_PATH   MemMap 
 
   EFI_DEVICE_PATH_PROTOCOL   End 
 
APPLE_RAM_DISK_DP 
 
typedef EFI_STATUS(EFIAPI * APPLE_RAM_DISK_CREATE) (IN UINT64 BlockCount OPTIONAL, IN UINT32 BlockSize OPTIONAL, IN BOOLEAN AllocateMemory, IN BOOLEAN ReserveMemory, OUT EFI_HANDLE *Handle)
 
typedef EFI_STATUS(EFIAPI * APPLE_RAM_DISK_DESTROY) (IN EFI_HANDLE Handle)
 
typedef EFI_STATUS(EFIAPI * APPLE_RAM_DISK_GET_CONTEXT) (IN EFI_HANDLE Handle, OUT APPLE_RAM_DISK_CONTEXT *Context)
 

Functions

 STATIC_ASSERT (sizeof(APPLE_RAM_DISK_DP_VENDOR)==24, "Invalid APPLE_RAM_DISK_DP_VENDOR size")
 
 STATIC_ASSERT (sizeof(APPLE_RAM_DISK_DP)==52, "Invalid APPLE_RAM_DISK_DP size")
 
 STATIC_ASSERT (sizeof(APPLE_RAM_DISK_EXTENT)==16, "Invalid APPLE_RAM_DISK_EXTENT size")
 
 STATIC_ASSERT (sizeof(APPLE_RAM_DISK_EXTENT_TABLE)==4096, "Invalid APPLE_RAM_DISK_EXTENT_TABLE size")
 
 STATIC_ASSERT (sizeof(APPLE_RAM_DISK_CONTEXT)==8192, "Invalid APPLE_RAM_DISK_CONTEXT size")
 

Variables

EFI_GUID gAppleRamDiskProtocolGuid
 

Detailed Description

Apple RAM Disk protocol.

Copyright (C) 2019, vit9696. 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 AppleRamDisk.h.

Macro Definition Documentation

◆ APPLE_DMG_BOOT_PROTOCOL_REVISION

#define APPLE_DMG_BOOT_PROTOCOL_REVISION   3

Apple RAM Disk protocol revision.

Definition at line 32 of file AppleRamDisk.h.

◆ APPLE_RAM_DISK_DEFAULT_SIZE

#define APPLE_RAM_DISK_DEFAULT_SIZE   0xA00000U

RAM Disk default size. This value is used when allocating APPLE_RAM_DISK structure.

Definition at line 305 of file AppleRamDisk.h.

◆ APPLE_RAM_DISK_EXTENT_SIGNATURE

#define APPLE_RAM_DISK_EXTENT_SIGNATURE   0x544E5458444D4152ULL

RAM Disk extent signature, "RAMDXTNT".

Definition at line 37 of file AppleRamDisk.h.

◆ APPLE_RAM_DISK_EXTENT_VERSION

#define APPLE_RAM_DISK_EXTENT_VERSION   0x10000U

RAM Disk extent version.

Definition at line 42 of file AppleRamDisk.h.

◆ APPLE_RAM_DISK_INSTANCE_SIGNATURE

#define APPLE_RAM_DISK_INSTANCE_SIGNATURE   0x444D4152U

Vit: Below come the implementation specific details, which probably do not belong here. Since this is the only way to initialize RAM disk when it was not allocated at creation time, I put it here for now. RAM Disk instance signature, "RAMD".

Definition at line 299 of file AppleRamDisk.h.

◆ APPLE_RAM_DISK_MAX_EXTENTS

#define APPLE_RAM_DISK_MAX_EXTENTS   0xFE

RAM Disk maximum extent count.

Definition at line 47 of file AppleRamDisk.h.

◆ APPLE_RAM_DISK_PROTOCOL_GUID

#define APPLE_RAM_DISK_PROTOCOL_GUID
Value:
{ 0x957932CC, 0x7E8E, 0x433B, \
{ 0x8F, 0x41, 0xD3, 0x91, 0xEA, 0x3C, 0x10, 0xF8 } }

Apple RAM Disk protocol GUID. 957932CC-7E8E-433B-8F41-D391EA3C10F8

Definition at line 25 of file AppleRamDisk.h.

Typedef Documentation

◆ [struct]

typedef PACKED struct { ... } APPLE_RAM_DISK_CONTEXT

RAM Disk protocol context. This might be called scatter pool.

◆ APPLE_RAM_DISK_CREATE

typedef EFI_STATUS(EFIAPI * APPLE_RAM_DISK_CREATE) (IN UINT64 BlockCount OPTIONAL, IN UINT32 BlockSize OPTIONAL, IN BOOLEAN AllocateMemory, IN BOOLEAN ReserveMemory, OUT EFI_HANDLE *Handle)

Create new RAM disk providing relevant protocols:

  • gEfiDevicePathProtocolGuid
  • gEfiBlockIoProtocolGuid
  • gAppleRamDiskProtocolGuid (as NULL)

When AllocateMemory is TRUE, a writeable RAM disk is created. Its contents are initially zeroed, and then may be modified through normal writing and via RAM Disk context, which is accessible through GetRamDiskContext.

When AllocateMemory is FALSE, a read only RAM disk is created. Its contents are not allocated but reported to be all zero. MemMap StartingAddresss will be 0 and EndingAddress will be sizeof (APPLE_RAM_DISK_EXTENT_TABLE). Vit: Since no context is allocated, there is no way to initialise this disk image except in an implementatation specific way. AllocateMemory = FALSE is never used, so it may be a bug.

Parameters
[in]BlockCountBlock amount, ignored if AllocateMemory is FALSE.
[in]BlockSizeBlock size, ignored if AllocateMemory is FALSE.
[in]AllocateMemoryAllocate disk memory.
[in]ReserveMemoryMark memory as EfiACPIMemoryNVS, otherwise EfiBootServicesData.
[in]HandleResulting handle.
Return values
EFI_SUCCESSRAM disk was successfully created.
EFI_OUT_OF_RESOURCESRequested RAM disk of more than SIZE_16TB.
EFI_OUT_OF_RESOURCESMemory allocation error happened.
EFI_INVALID_PARAMETERToo many extents are needed for the allocation.
EFI_BUFFER_TOO_SMALLNot enough extents to allocate context extent.

Definition at line 225 of file AppleRamDisk.h.

◆ APPLE_RAM_DISK_DESTROY

typedef EFI_STATUS(EFIAPI * APPLE_RAM_DISK_DESTROY) (IN EFI_HANDLE Handle)

Destroy RAM disk freeing resources and uninstalling relevant protocols:

  • gEfiDevicePathProtocolGuid
  • gEfiBlockIoProtocolGuid
  • gAppleRamDiskProtocolGuid
  • gTDMApprovedGuid
Parameters
[in]HandleRAM disk handle.
Return values
EFI_INVALID_PARAMETERNot a RAM disk handle.
EFI_NOT_FOUNDMissing Block I/O protocol.
EFI_SUCCESSDestroyed successfully.

Definition at line 248 of file AppleRamDisk.h.

◆ [struct]

typedef PACKED struct { ... } APPLE_RAM_DISK_DP

RAM Disk device path, 52 bytes in total.

◆ [struct]

typedef PACKED struct { ... } APPLE_RAM_DISK_DP_HEADER

RAM Disk device path header for endpoint devices.

◆ [struct]

typedef PACKED struct { ... } APPLE_RAM_DISK_DP_VENDOR

RAM Disk vendor device path, 24 bytes in total.

◆ [struct]

typedef PACKED struct { ... } APPLE_RAM_DISK_EXTENT

RAM Disk extent. When automatically allocating at RAM disk creation, extents are created on demand as long as contiguous memory is found in the firmware.

Please note, that this must match IOAddressRange type in XNU, which can be found in iokit/IOKit/IOTypes.h.

◆ [struct]

typedef PACKED struct { ... } APPLE_RAM_DISK_EXTENT_TABLE

RAM Disk externally accessible header containing references to extents.

◆ APPLE_RAM_DISK_GET_CONTEXT

typedef EFI_STATUS(EFIAPI * APPLE_RAM_DISK_GET_CONTEXT) (IN EFI_HANDLE Handle, OUT APPLE_RAM_DISK_CONTEXT *Context)

Obtain RAM disk context. Context exists only for "allocated" RAM disks, i.e. disks created with AllocateMemory = TRUE. When an unallocated RAM disk is created, NULL Context will be returned.

Parameters
[in]HandleRAM disk handle.
[out]ContextRAM disk context.
Return values
EFI_INVALID_PARAMETERNot a RAM disk handle.
EFI_NOT_FOUNDMissing Block I/O protocol.
EFI_SUCCESSObtained NULL or non-NULL context successfully.

Definition at line 266 of file AppleRamDisk.h.

Function Documentation

◆ STATIC_ASSERT() [1/5]

STATIC_ASSERT ( sizeof(APPLE_RAM_DISK_CONTEXT) = =8192,
"Invalid APPLE_RAM_DISK_CONTEXT size"  )

◆ STATIC_ASSERT() [2/5]

STATIC_ASSERT ( sizeof(APPLE_RAM_DISK_DP) = =52,
"Invalid APPLE_RAM_DISK_DP size"  )

◆ STATIC_ASSERT() [3/5]

STATIC_ASSERT ( sizeof(APPLE_RAM_DISK_DP_VENDOR) = =24,
"Invalid APPLE_RAM_DISK_DP_VENDOR size"  )

◆ STATIC_ASSERT() [4/5]

STATIC_ASSERT ( sizeof(APPLE_RAM_DISK_EXTENT) = =16,
"Invalid APPLE_RAM_DISK_EXTENT size"  )

◆ STATIC_ASSERT() [5/5]

STATIC_ASSERT ( sizeof(APPLE_RAM_DISK_EXTENT_TABLE) = =4096,
"Invalid APPLE_RAM_DISK_EXTENT_TABLE size"  )

Variable Documentation

◆ Counter

UINT32 Counter

Globally incremented counter to make every path unique.

Definition at line 150 of file AppleRamDisk.h.

◆ DiskSize

UINT64 DiskSize

Total addressible disk size specified at creation.

Definition at line 116 of file AppleRamDisk.h.

◆ End

EFI_DEVICE_PATH_PROTOCOL End

Device path end.

Definition at line 191 of file AppleRamDisk.h.

◆ ExtentCount

UINT64 ExtentCount

Externally visible amount of extents.

Internally visible amount of extents.

Definition at line 86 of file AppleRamDisk.h.

◆ Extents

Externally visible extent array.

Internally visible extent array.

Definition at line 90 of file AppleRamDisk.h.

◆ ExtentTable

Normal extent table.

Definition at line 128 of file AppleRamDisk.h.

◆ gAppleRamDiskProtocolGuid

EFI_GUID gAppleRamDiskProtocolGuid
extern

◆ Length

UINT64 Length

Actual size of the extent. Allocated area size may be >= Length.

Definition at line 68 of file AppleRamDisk.h.

◆ MemMap

MEMMAP_DEVICE_PATH MemMap

Memmap device path.

Definition at line 164 of file AppleRamDisk.h.

◆ Reserved

UINT64 Reserved

Currently reserved or rather unknown.

Definition at line 94 of file AppleRamDisk.h.

◆ Reserved1

UINT64 Reserved1

Currently reserved or rather unknown. Padding?

Definition at line 112 of file AppleRamDisk.h.

◆ Reserved2

UINT64 Reserved2

Currently reserved or rather unknown. Padding?

Definition at line 124 of file AppleRamDisk.h.

◆ Signature

UINT64 Signature

Set to APPLE_RAM_DISK_EXTENT_SIGNATURE.

Definition at line 78 of file AppleRamDisk.h.

◆ Signature2

UINT64 Signature2

Set to APPLE_RAM_DISK_EXTENT_SIGNATURE.

Definition at line 98 of file AppleRamDisk.h.

◆ Start

UINT64 Start

Extentent address pointing to a sequence of allocated pages from EfiACPIMemoryNVS or EfiBootServicesData depending on RamDisk init.

Definition at line 64 of file AppleRamDisk.h.

◆ Vendor

Vendor device path. Type = HARDWARE_DEVICE_PATH. Subtype = HW_VENDOR_DP. Length = sizeof (VENDOR_DEVICE_PATH) + sizeof (UINT32). Guid = APPLE_RAM_DISK_PROTOCOL_GUID.

Vendor device path.

Vendor device path with APPLE_RAM_DISK_PROTOCOL_GUID. Type = HARDWARE_DEVICE_PATH. Subtype = HW_MEMMAP_DP. Length = sizeof (APPLE_RAM_DISK_ENTRY_DP). StartingAddresss = APPLE_RAM_DISK_EXTENT_TABLE pointer. EndingAddress = StartingAddresss + sizeof (APPLE_RAM_DISK_EXTENT_TABLE). MemoryType = EfiACPIMemoryNVS or EfiBootServicesData as allocated.

Note: EndingAddress, per UEFI specification and edk2 implementation, is supposed to be the top usable address, not the top of the buffer. Perhaps there is a mistake here.

Definition at line 146 of file AppleRamDisk.h.

◆ Version

UINT32 Version ( void )

Set to APPLE_RAM_DISK_EXTENT_VERSION.

Definition at line 82 of file AppleRamDisk.h.