🔥 Delete apple-gfx's option ROM from firmware and the dist tree

apple-gfx-pci loaded ReimsVgpu.rom, its UEFI driver, as its default romfile;
with apple-gfx gone the driver, its sources and its build go, and cargo xtask
dist installs no ROM and names none in reims-vgpu.pc (QEMU stops reading its
optionrom variable). The firmware builds only the reims-graphics device's ROM,
which reims-ctl carries: OptionRom.S keeps the layout ReimsGraphicsRom.S
includes, with no apple-gfx-pci identity to fall back on.

The prebuilt ROM's bytes are unchanged (sha256 749434f8, rebuilt on the Mac):
only its record moves, for the Makefile and the two assembler files it names.
This commit is contained in:
Anees Iqbal committed 2026-11-07 18:21:42 -08:00
1 parent 110b53637b
commit 9da252e40b
13 files changed
+80 -1598

No files matched your search

+2 -2
View File
@@ -2,8 +2,8 @@
# repository root.
#
# make the library as a plain library (cargo xtask dist) in
# target/dist: libreims_vgpu.a and .dylib, reims_vgpu.h,
# reims-vgpu.pc and the option ROM
# target/dist: libreims_vgpu.a and .dylib, reims_vgpu.h and
# reims-vgpu.pc
# make qemu the library as a plain library (cargo xtask dist), then
# vendor/qemu's qemu-system-aarch64 with apple-gfx on its C API,
# linked statically through pkg-config, in build/qemu
+13 -32
View File
@@ -1,10 +1,9 @@
# The option ROMs: each PCI device's UEFI driver (src/), linked as an x86-64
# EFI boot-service driver and packaged as a PCI option ROM
# (docs/architecture.md 11.4). ReimsVgpu is apple-gfx-pci's; ReimsGraphics is
# the reims-graphics device's (docs/graphics-kext/design.md), built on the
# host's wire protocol header in ../crates/reims-graphics/include.
# The option ROM: the reims-graphics device's UEFI driver (src/), linked as an
# x86-64 EFI boot-service driver and packaged as a PCI option ROM
# (docs/graphics-kext/design.md), built on the host's wire protocol header in
# ../crates/reims-graphics/include.
#
# make build/ReimsVgpu.{efi,rom} and build/ReimsGraphics.{efi,rom}
# make build/ReimsGraphics.{efi,rom}
# make prebuilt on a Mac, also prebuilt/ReimsGraphics.rom, which reims-ctl carries, and
# prebuilt/ReimsGraphics.toml, the sha256 of the files it was built from
# (prebuilt.sh): commit both with a change to what the ROM is built from
@@ -13,22 +12,15 @@
# (cargo xtask check runs it)
# make clean remove build/
#
# BUILD moves the output: cargo xtask dist runs `make rom` with BUILD set to
# <target>/firmware. Needs clang and lld (on macOS, Homebrew's: brew install
# lld). The ROM's bytes are the compiler's: Xcode's clang and Linux's build
# different ones from the same sources.
# BUILD moves the output. Needs clang and lld (on macOS, Homebrew's: brew
# install lld). The ROM's bytes are the compiler's: Xcode's clang and Linux's
# build different ones from the same sources.
CC = clang
LD = lld-link
ROMLD = ld.lld
BUILD = build
NAME = ReimsVgpu
SOURCES = \
src/ReimsVgpu.c \
src/GraphicsOutput.c \
src/ComponentName.c
TARGET = --target=x86_64-unknown-windows
@@ -40,11 +32,9 @@ CFLAGS = $(TARGET) -Os -ffreestanding -fshort-wchar -funsigned-char \
-Wall -Wextra -Werror -Wno-unused-parameter
LDFLAGS = /nologo /nodefaultlib /dll /driver /base:0 /machine:x64 \
/subsystem:efi_boot_service_driver /entry:ReimsVgpuEntryPoint \
/subsystem:efi_boot_service_driver /entry:ReimsGraphicsEntryPoint \
/opt:ref /align:32 /filealign:32 /Brepro
OBJECTS = $(patsubst src/%,$(BUILD)/obj/%.obj,$(basename $(SOURCES)))
GNAME = ReimsGraphics
WIRE = ../crates/reims-graphics/include
@@ -65,26 +55,17 @@ GSOURCES = \
src/ReimsGraphicsName.c
GOBJECTS = $(patsubst src/%,$(BUILD)/obj/%.obj,$(basename $(GSOURCES)))
GLDFLAGS = $(filter-out /entry:%,$(LDFLAGS)) /entry:ReimsGraphicsEntryPoint
$(GOBJECTS): CFLAGS += -I$(WIRE)
all: rom
efi: $(BUILD)/$(NAME).efi $(BUILD)/$(GNAME).efi
efi: $(BUILD)/$(GNAME).efi
rom: $(BUILD)/$(NAME).rom $(BUILD)/$(GNAME).rom
rom: $(BUILD)/$(GNAME).rom
# OptionRom.S lays out the ROM header around the linked image; ld.lld
# flattens it to raw bytes.
$(BUILD)/$(NAME).rom: src/OptionRom.S src/ReimsVgpu.h $(BUILD)/$(NAME).efi
$(CC) --target=x86_64-unknown-none-elf -DEFI_IMAGE='"$(BUILD)/$(NAME).efi"' \
-c $< -o $(BUILD)/obj/OptionRom.o
$(ROMLD) --oformat binary -o $@ $(BUILD)/obj/OptionRom.o
$(BUILD)/$(NAME).efi: $(OBJECTS)
$(LD) $(LDFLAGS) /out:$@ $^
$(BUILD)/$(GNAME).rom: src/ReimsGraphicsRom.S src/OptionRom.S \
$(WIRE)/reims_graphics_wire.h $(BUILD)/$(GNAME).efi
$(CC) --target=x86_64-unknown-none-elf $(GROMDEFS) -DEFI_IMAGE='"$(BUILD)/$(GNAME).efi"' \
@@ -92,7 +73,7 @@ $(BUILD)/$(GNAME).rom: src/ReimsGraphicsRom.S src/OptionRom.S \
$(ROMLD) --oformat binary -o $@ $(BUILD)/obj/ReimsGraphicsRom.o
$(BUILD)/$(GNAME).efi: $(GOBJECTS)
$(LD) $(GLDFLAGS) /out:$@ $^
$(LD) $(LDFLAGS) /out:$@ $^
$(BUILD)/obj/%.obj: src/%.c
@mkdir -p $(@D)
@@ -109,4 +90,4 @@ clean:
.PHONY: all efi rom prebuilt prebuilt-check clean
-include $(OBJECTS:.obj=.d) $(GOBJECTS:.obj=.d)
-include $(GOBJECTS:.obj=.d)
+3 -3
View File
@@ -7,11 +7,11 @@ rom = "749434f87f562895548f60681cd4cd8bf6cc0d0e967ac2fea297674426709161"
[sources]
"crates/reims-graphics/include/reims_graphics_wire.h" = "a28de4b1304289dac62317e6e552e6289ab46c21393170ca2785109443a18ceb"
"firmware/Makefile" = "dfdc68504271e09cec05f2408c7a73c7fa2487f20ffef0944fe20b078ae3b322"
"firmware/src/OptionRom.S" = "54cb57ea2e5b4ac67e1627f5251314d56c4792a376a9c535deb661f0e29714a4"
"firmware/Makefile" = "4801350156e36154dcc7bbb0e7c89e4e618cfc942b1e9ee499d284576d85ebb3"
"firmware/src/OptionRom.S" = "b910fe61a880580996a81134fba75900d3a9f48ca266e76fe2d6b8eb5a011eb9"
"firmware/src/ReimsGraphics.c" = "554751ff15edbdf69a038d5b2aefd8315b9c54610c090c0890d9c72b13dacdef"
"firmware/src/ReimsGraphics.h" = "83e3439b9baf9c06ee75c57537792770efa7a5cb07e22bf1fb47f6ffef7af169"
"firmware/src/ReimsGraphicsName.c" = "107e7e34240a3942dcd410b701768ab81013f42932783b7fa90fcefc3f815f19"
"firmware/src/ReimsGraphicsOutput.c" = "c35ed747684d90c2b195d95613d79111a9f7c0777654f5f027ed9951bdd7a112"
"firmware/src/ReimsGraphicsRom.S" = "db1211cc9d4b40628d101a7377eeeebfefc57820ec5fd1a72fffefb90c2ed2bb"
"firmware/src/ReimsGraphicsRom.S" = "7b0482515ec151272c609b8a2c343476c525aa1f916997df0999e5eeaf42474c"
"firmware/src/Uefi.h" = "d9b349424b645428c114d141b0ca7c4b92ccef573803e16eea501258eb5572ee"
-279
View File
@@ -1,279 +0,0 @@
/** @file
Component Name and Component Name 2 protocols.
**/
#include "ReimsVgpu.h"
//
// A name and the semicolon-separated languages it is offered in.
//
typedef struct {
CHAR8 *Language;
CHAR16 *UnicodeString;
} EFI_UNICODE_STRING_TABLE;
EFI_COMPONENT_NAME_PROTOCOL gReimsVgpuComponentName = {
ReimsVgpuComponentNameGetDriverName,
ReimsVgpuComponentNameGetControllerName,
"eng"
};
EFI_COMPONENT_NAME2_PROTOCOL gReimsVgpuComponentName2 = {
(EFI_COMPONENT_NAME2_GET_DRIVER_NAME)ReimsVgpuComponentNameGetDriverName,
(EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME)ReimsVgpuComponentNameGetControllerName,
"en"
};
EFI_UNICODE_STRING_TABLE mReimsVgpuDriverNameTable[] = {
{ "eng;en", L"Reims vGPU Driver" },
{ NULL, NULL }
};
EFI_UNICODE_STRING_TABLE mReimsVgpuControllerNameTable[] = {
{ "eng;en", L"Reims vGPU" },
{ NULL, NULL }
};
/**
Compare up to Length characters of two ASCII strings.
@return The difference between the first mismatched characters, or zero
if the strings match up to Length characters.
**/
STATIC
INTN
AsciiStrnCmp (
IN CONST CHAR8 *FirstString,
IN CONST CHAR8 *SecondString,
IN UINTN Length
)
{
if (Length == 0) {
return 0;
}
while ((*FirstString != '\0') &&
(*SecondString != '\0') &&
(*FirstString == *SecondString) &&
(Length > 1))
{
FirstString++;
SecondString++;
Length--;
}
return *FirstString - *SecondString;
}
/**
Compare two three-character ISO 639-2 language codes.
**/
STATIC
BOOLEAN
CompareIso639LanguageCode (
IN CONST CHAR8 *Language1,
IN CONST CHAR8 *Language2
)
{
return (BOOLEAN)((Language1[0] == Language2[0]) &&
(Language1[1] == Language2[1]) &&
(Language1[2] == Language2[2]));
}
/**
Test whether TargetLanguage appears in a semicolon-separated list of
RFC 4646 language codes.
**/
STATIC
EFI_STATUS
IsLanguageSupported (
IN CONST CHAR8 *SupportedLanguages,
IN CONST CHAR8 *TargetLanguage
)
{
UINTN Index;
while (*SupportedLanguages != 0) {
for (Index = 0; SupportedLanguages[Index] != 0 && SupportedLanguages[Index] != ';'; Index++) {
}
if ((AsciiStrnCmp (SupportedLanguages, TargetLanguage, Index) == 0) && (TargetLanguage[Index] == 0)) {
return EFI_SUCCESS;
}
SupportedLanguages += Index;
for ( ; *SupportedLanguages != 0 && *SupportedLanguages == ';'; SupportedLanguages++) {
}
}
return EFI_UNSUPPORTED;
}
/**
Find the string for Language in UnicodeStringTable. Language must also be
listed in SupportedLanguages, which uses ISO 639-2 codes when
Iso639Language is TRUE and RFC 4646 codes otherwise.
**/
STATIC
EFI_STATUS
LookupUnicodeString2 (
IN CONST CHAR8 *Language,
IN CONST CHAR8 *SupportedLanguages,
IN CONST EFI_UNICODE_STRING_TABLE *UnicodeStringTable,
OUT CHAR16 **UnicodeString,
IN BOOLEAN Iso639Language
)
{
BOOLEAN Found;
UINTN Index;
CHAR8 *LanguageString;
if ((Language == NULL) || (UnicodeString == NULL)) {
return EFI_INVALID_PARAMETER;
}
if ((SupportedLanguages == NULL) || (UnicodeStringTable == NULL)) {
return EFI_UNSUPPORTED;
}
Found = FALSE;
if (Iso639Language) {
while (*SupportedLanguages != 0) {
if (CompareIso639LanguageCode (Language, SupportedLanguages)) {
Found = TRUE;
break;
}
SupportedLanguages += 3;
}
} else {
//
// The arguments are passed in this order, so the list that is split at
// semicolons is Language, and SupportedLanguages must equal one of its
// elements.
//
Found = !IsLanguageSupported (Language, SupportedLanguages);
}
if (!Found) {
return EFI_UNSUPPORTED;
}
//
// Each table entry lists its languages separated by semicolons.
//
while (UnicodeStringTable->Language != NULL) {
LanguageString = UnicodeStringTable->Language;
while (0 != *LanguageString) {
for (Index = 0; LanguageString[Index] != 0 && LanguageString[Index] != ';'; Index++) {
}
if (AsciiStrnCmp (LanguageString, Language, Index) == 0) {
*UnicodeString = UnicodeStringTable->UnicodeString;
return EFI_SUCCESS;
}
LanguageString += Index;
for (Index = 0; LanguageString[Index] != 0 && LanguageString[Index] == ';'; Index++) {
}
}
UnicodeStringTable++;
}
return EFI_UNSUPPORTED;
}
/**
Test whether ControllerHandle is already managed by the driver that owns
DriverBindingHandle through ProtocolGuid.
**/
STATIC
EFI_STATUS
EfiTestManagedDevice (
IN CONST EFI_HANDLE ControllerHandle,
IN CONST EFI_HANDLE DriverBindingHandle,
IN CONST EFI_GUID *ProtocolGuid
)
{
EFI_STATUS Status;
VOID *ManagedInterface;
Status = gBS->OpenProtocol (
ControllerHandle,
(EFI_GUID *)ProtocolGuid,
&ManagedInterface,
DriverBindingHandle,
ControllerHandle,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (!EFI_ERROR (Status)) {
gBS->CloseProtocol (
ControllerHandle,
(EFI_GUID *)ProtocolGuid,
DriverBindingHandle,
ControllerHandle
);
return EFI_UNSUPPORTED;
}
if (Status != EFI_ALREADY_STARTED) {
return EFI_UNSUPPORTED;
}
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
ReimsVgpuComponentNameGetDriverName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN CHAR8 *Language,
OUT CHAR16 **DriverName
)
{
return LookupUnicodeString2 (
Language,
This->SupportedLanguages,
mReimsVgpuDriverNameTable,
DriverName,
(BOOLEAN)(This == &gReimsVgpuComponentName)
);
}
EFI_STATUS
EFIAPI
ReimsVgpuComponentNameGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language,
OUT CHAR16 **ControllerName
)
{
EFI_STATUS Status;
//
// Only the controller itself has a name.
//
if (ChildHandle != NULL) {
return EFI_UNSUPPORTED;
}
Status = EfiTestManagedDevice (
ControllerHandle,
gReimsVgpuDriverBinding.DriverBindingHandle,
&gEfiPciIoProtocolGuid
);
if (EFI_ERROR (Status)) {
return Status;
}
return LookupUnicodeString2 (
Language,
This->SupportedLanguages,
mReimsVgpuControllerNameTable,
ControllerName,
(BOOLEAN)(This == &gReimsVgpuComponentName)
);
}
-306
View File
@@ -1,306 +0,0 @@
/** @file
Graphics Output Protocol on a linear 32-bit frame buffer.
**/
#include "ReimsVgpu.h"
//
// A rectangle copy between two surfaces, each described by its row pitch in
// bytes and the pixel coordinates of the rectangle's first corner.
//
typedef struct {
UINT32 SourcePitch;
UINT32 SourceX;
UINT32 SourceY;
UINT32 Width;
UINT32 Height;
UINT32 DestinationPitch;
UINT32 DestinationX;
UINT32 DestinationY;
} REIMS_VGPU_BLT_RECT;
STATIC
VOID
ReimsVgpuSetModeInformation (
OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info
)
{
Info->Version = 0;
Info->PixelFormat = PixelBlueGreenRedReserved8BitPerColor;
Info->PixelInformation.RedMask = 0xFF000000;
Info->PixelInformation.GreenMask = 0x00FF0000;
Info->PixelInformation.BlueMask = 0x0000FF00;
Info->PixelInformation.ReservedMask = 0x000000FF;
Info->PixelsPerScanLine = Info->HorizontalResolution;
}
/**
Publish the frame buffer for the mode just stored in Mode->Info.
**/
STATIC
VOID
ReimsVgpuUpdateMode (
IN REIMS_VGPU_PRIVATE_DATA *Private,
IN EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *Mode
)
{
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
Info = Mode->Info;
ReimsVgpuSetModeInformation (Info);
Mode->FrameBufferBase = Private->FrameBufferBase;
Mode->FrameBufferSize = Info->HorizontalResolution * Info->VerticalResolution * 4;
}
EFI_STATUS
EFIAPI
ReimsVgpuGraphicsOutputQueryMode (
IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
IN UINT32 ModeNumber,
OUT UINTN *SizeOfInfo,
OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **Info
)
{
REIMS_VGPU_PRIVATE_DATA *Private;
Private = REIMS_VGPU_PRIVATE_DATA_FROM_GRAPHICS_OUTPUT_THIS (This);
if ((Info == NULL) || (SizeOfInfo == NULL) || (ModeNumber >= This->Mode->MaxMode)) {
return EFI_INVALID_PARAMETER;
}
*Info = AllocateRuntimePool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION));
if (*Info == NULL) {
return EFI_OUT_OF_RESOURCES;
}
*SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);
(*Info)->HorizontalResolution = Private->ModeTable[ModeNumber].Width;
(*Info)->VerticalResolution = Private->ModeTable[ModeNumber].Height;
ReimsVgpuSetModeInformation (*Info);
return EFI_SUCCESS;
}
EFI_STATUS
EFIAPI
ReimsVgpuGraphicsOutputSetMode (
IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
IN UINT32 ModeNumber
)
{
REIMS_VGPU_PRIVATE_DATA *Private;
Private = REIMS_VGPU_PRIVATE_DATA_FROM_GRAPHICS_OUTPUT_THIS (This);
if (ModeNumber >= This->Mode->MaxMode) {
return EFI_UNSUPPORTED;
}
This->Mode->Mode = ModeNumber;
This->Mode->Info->HorizontalResolution = Private->ModeTable[ModeNumber].Width;
This->Mode->Info->VerticalResolution = Private->ModeTable[ModeNumber].Height;
This->Mode->SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);
ReimsVgpuUpdateMode (Private, This->Mode);
ReimsVgpuWriteRegister (Private->PciIo, REIMS_VGPU_REG_EFI_DEPTH, Private->ModeTable[ModeNumber].BitsPerPixel);
ReimsVgpuWriteRegister (
Private->PciIo,
REIMS_VGPU_REG_EFI_MODE,
(Private->ModeTable[ModeNumber].Width & 0xFFFF) | (Private->ModeTable[ModeNumber].Height << 16)
);
return EFI_SUCCESS;
}
/**
Copy a rectangle of 32-bit pixels between two surfaces.
**/
STATIC
VOID
ReimsVgpuCopyRect (
IN UINT8 *Source,
OUT UINT8 *Destination,
IN REIMS_VGPU_BLT_RECT Rect
)
{
UINT32 X;
UINT32 Y;
UINT32 SourceX;
UINT32 SourceY;
UINT32 DestinationX;
UINT32 DestinationY;
UINT8 *SourceRow;
UINT8 *DestinationRow;
for (Y = 0; Y < Rect.Height; Y++) {
SourceY = Rect.SourceY + Y;
DestinationY = Rect.DestinationY + Y;
SourceRow = Source + SourceY * Rect.SourcePitch;
DestinationRow = Destination + DestinationY * Rect.DestinationPitch;
for (X = 0; X < Rect.Width; X++) {
SourceX = Rect.SourceX + X;
DestinationX = Rect.DestinationX + X;
*(UINT32 *)(DestinationRow + DestinationX * sizeof (UINT32)) =
*(UINT32 *)(SourceRow + SourceX * sizeof (UINT32));
}
}
}
/**
Copy a rectangle within one surface. Rows and columns are walked backward
when the destination lies after the source.
**/
STATIC
VOID
ReimsVgpuMoveRect (
IN OUT UINT8 *Buffer,
IN REIMS_VGPU_BLT_RECT Rect
)
{
UINT32 StartDestinationX;
UINT32 StartSourceX;
UINT32 StartSourceY;
UINT32 StartDestinationY;
UINT32 X;
UINT32 Y;
UINT32 OffsetX;
UINT32 OffsetY;
UINT32 SourceX;
UINT32 SourceY;
UINT32 DestinationX;
UINT32 DestinationY;
UINT32 *SourceRow;
UINT32 *DestinationRow;
if (Rect.SourceX < Rect.DestinationX) {
StartSourceX = Rect.SourceX + Rect.Width;
StartDestinationX = StartSourceX + Rect.Width;
} else {
StartSourceX = Rect.SourceX;
StartDestinationX = Rect.DestinationX;
}
if (Rect.SourceY < Rect.DestinationY) {
StartSourceY = Rect.SourceY + Rect.Height;
StartDestinationY = StartSourceY + Rect.Height;
} else {
StartSourceY = Rect.SourceY;
StartDestinationY = Rect.DestinationY;
}
for (Y = 0; Y < Rect.Height; Y++) {
OffsetY = (Rect.SourceY < Rect.DestinationY) ? -Y : Y;
SourceY = StartSourceY + OffsetY;
DestinationY = StartDestinationY + OffsetY;
SourceRow = (UINT32 *)((UINTN)Buffer + SourceY * Rect.SourcePitch);
DestinationRow = (UINT32 *)((UINTN)Buffer + DestinationY * Rect.DestinationPitch);
for (X = 0; X < Rect.Width; X++) {
OffsetX = (Rect.SourceX < Rect.DestinationX) ? -X : X;
SourceX = StartSourceX + OffsetX;
DestinationX = StartDestinationX + OffsetX;
DestinationRow[DestinationX] = SourceRow[SourceX];
}
}
}
EFI_STATUS
EFIAPI
ReimsVgpuGraphicsOutputBlt (
IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer OPTIONAL,
IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation,
IN UINTN SourceX,
IN UINTN SourceY,
IN UINTN DestinationX,
IN UINTN DestinationY,
IN UINTN Width,
IN UINTN Height,
IN UINTN Delta OPTIONAL
)
{
REIMS_VGPU_PRIVATE_DATA *Private;
REIMS_VGPU_BLT_RECT Rect;
UINT32 X;
UINT32 Y;
EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Row;
Private = REIMS_VGPU_PRIVATE_DATA_FROM_GRAPHICS_OUTPUT_THIS (This);
switch (BltOperation) {
case EfiBltVideoFill:
Y = MAX_UINT32;
while (++Y < Height) {
Row = (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)((UINT8 *)Private->FrameBuffer +
(UINT32)(DestinationY + Y) * This->Mode->Info->HorizontalResolution * 4);
for (X = 0; X < Width; X++) {
Row[(UINT32)(DestinationX + X)] = *BltBuffer;
}
}
break;
case EfiBltVideoToBltBuffer:
Rect.SourcePitch = This->Mode->Info->HorizontalResolution * 4;
Rect.SourceX = (UINT32)SourceX;
Rect.SourceY = (UINT32)SourceY;
Rect.Width = (UINT32)Width;
Rect.Height = (UINT32)Height;
Rect.DestinationPitch = (UINT32)((Delta != 0) ? Delta : Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
Rect.DestinationX = (UINT32)DestinationX;
Rect.DestinationY = (UINT32)DestinationY;
ReimsVgpuCopyRect (Private->FrameBuffer, (UINT8 *)BltBuffer, Rect);
break;
case EfiBltBufferToVideo:
Rect.SourcePitch = (UINT32)((Delta != 0) ? Delta : Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
Rect.SourceX = (UINT32)SourceX;
Rect.SourceY = (UINT32)SourceY;
Rect.Width = (UINT32)Width;
Rect.Height = (UINT32)Height;
Rect.DestinationPitch = This->Mode->Info->HorizontalResolution * 4;
Rect.DestinationX = (UINT32)DestinationX;
Rect.DestinationY = (UINT32)DestinationY;
ReimsVgpuCopyRect ((UINT8 *)BltBuffer, Private->FrameBuffer, Rect);
break;
case EfiBltVideoToVideo:
Rect.SourcePitch = This->Mode->Info->HorizontalResolution * 4;
Rect.SourceX = (UINT32)SourceX;
Rect.SourceY = (UINT32)SourceY;
Rect.Width = (UINT32)Width;
Rect.Height = (UINT32)Height;
Rect.DestinationPitch = This->Mode->Info->HorizontalResolution * 4;
Rect.DestinationX = (UINT32)DestinationX;
Rect.DestinationY = (UINT32)DestinationY;
ReimsVgpuMoveRect (Private->FrameBuffer, Rect);
break;
default:
return EFI_INVALID_PARAMETER;
}
return EFI_SUCCESS;
}
VOID
ReimsVgpuGraphicsOutputConstructor (
IN REIMS_VGPU_PRIVATE_DATA *Private
)
{
EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
GraphicsOutput = &Private->GraphicsOutput;
GraphicsOutput->QueryMode = ReimsVgpuGraphicsOutputQueryMode;
GraphicsOutput->SetMode = ReimsVgpuGraphicsOutputSetMode;
GraphicsOutput->Blt = ReimsVgpuGraphicsOutputBlt;
GraphicsOutput->Mode = &Private->GraphicsOutputMode;
GraphicsOutput->Mode->MaxMode = Private->MaxMode;
GraphicsOutput->Mode->Mode = 0;
GraphicsOutput->Mode->Info = &Private->ModeInformation;
GraphicsOutput->Mode->SizeOfInfo = sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION);
ReimsVgpuGraphicsOutputSetMode (GraphicsOutput, 0);
}
+3 -11
View File
@@ -3,19 +3,11 @@
3.0, UEFI specification 14.4.2): the EFI expansion ROM header, the PCI data
structure, the image itself, and 0xFF padding to a multiple of 512 bytes.
The Makefile assembles this with EFI_IMAGE set to the linked image's path
and flattens the result to raw bytes. It is the apple-gfx-pci device's ROM
unless an including file defines ROM_VENDOR_ID, ROM_DEVICE_ID and
ROM_CLASS_CODE for another device first.
The Makefile assembles it, through ReimsGraphicsRom.S, with EFI_IMAGE set to
the linked image's path and ROM_VENDOR_ID, ROM_DEVICE_ID and ROM_CLASS_CODE
to the device's PCI identity, and flattens the result to raw bytes.
**/
#ifndef ROM_VENDOR_ID
#include "ReimsVgpu.h"
#define ROM_VENDOR_ID REIMS_VGPU_VENDOR_ID
#define ROM_DEVICE_ID REIMS_VGPU_DEVICE_ID
#define ROM_CLASS_CODE REIMS_VGPU_CLASS_CODE
#endif
#define ROM_BLOCKS ((RomEnd - RomStart) / 512)
.section .rom, "a"
+1 -1
View File
@@ -5,7 +5,7 @@
Its PCI identity (ROM_VENDOR_ID, ROM_DEVICE_ID and ROM_CLASS_CODE) comes from
the host wire header. That header is generated C and cannot be assembled, so
the Makefile reads the three values from it with the preprocessor and passes
them in; OptionRom.S then takes them in place of apple-gfx-pci's.
them in.
**/
#include "OptionRom.S"
-619
View File
@@ -1,619 +0,0 @@
/** @file
Entry point and driver binding for the paravirtualized GPU: device
detection, mode discovery, frame buffer setup, and Graphics Output
installation.
**/
#include "ReimsVgpu.h"
EFI_HANDLE gImageHandle;
EFI_BOOT_SERVICES *gBS;
STATIC EFI_DEVICE_PATH_UTILITIES_PROTOCOL *mDevicePathUtilities;
EFI_GUID gEfiDevicePathProtocolGuid = EFI_DEVICE_PATH_PROTOCOL_GUID;
EFI_GUID gEfiDevicePathUtilitiesProtocolGuid = EFI_DEVICE_PATH_UTILITIES_PROTOCOL_GUID;
EFI_GUID gEfiDriverBindingProtocolGuid = EFI_DRIVER_BINDING_PROTOCOL_GUID;
EFI_GUID gEfiComponentNameProtocolGuid = EFI_COMPONENT_NAME_PROTOCOL_GUID;
EFI_GUID gEfiComponentName2ProtocolGuid = EFI_COMPONENT_NAME2_PROTOCOL_GUID;
EFI_GUID gEfiDriverSupportedEfiVersionProtocolGuid = EFI_DRIVER_SUPPORTED_EFI_VERSION_PROTOCOL_GUID;
EFI_GUID gEfiPciIoProtocolGuid = EFI_PCI_IO_PROTOCOL_GUID;
EFI_GUID gEfiGraphicsOutputProtocolGuid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
//
// Modes offered when the device does not report a usable mode list: one
// each for 16:10, 16:9, and 4:3.
//
STATIC CONST REIMS_VGPU_MODE mReimsVgpuDefaultModes[] = {
{ 1920, 1200, 32 },
{ 1920, 1080, 32 },
{ 1600, 1200, 32 }
};
EFI_DRIVER_SUPPORTED_EFI_VERSION_PROTOCOL gReimsVgpuSupportedEfiVersion = {
sizeof (EFI_DRIVER_SUPPORTED_EFI_VERSION_PROTOCOL),
0
};
/**
Allocate pool memory of MemoryType, or return NULL on failure.
**/
STATIC
VOID *
InternalAllocatePool (
IN EFI_MEMORY_TYPE MemoryType,
IN UINTN AllocationSize
)
{
EFI_STATUS Status;
VOID *Memory;
Status = gBS->AllocatePool (MemoryType, AllocationSize, &Memory);
if (EFI_ERROR (Status)) {
Memory = NULL;
}
return Memory;
}
VOID *
AllocateRuntimePool (
IN UINTN AllocationSize
)
{
return InternalAllocatePool (EfiRuntimeServicesData, AllocationSize);
}
STATIC
VOID *
AllocateZeroPool (
IN UINTN AllocationSize
)
{
UINT8 *Memory;
UINTN Index;
Memory = InternalAllocatePool (EfiBootServicesData, AllocationSize);
if (Memory != NULL) {
for (Index = 0; Index < AllocationSize; Index++) {
Memory[Index] = 0;
}
}
return Memory;
}
STATIC
VOID
FreePool (
IN VOID *Buffer
)
{
gBS->FreePool (Buffer);
}
/**
Check whether Controller is the paravirtualized GPU.
**/
EFI_STATUS
EFIAPI
ReimsVgpuDriverBindingSupported (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
{
EFI_STATUS Status;
EFI_PCI_IO_PROTOCOL *PciIo;
PCI_TYPE00 Pci;
Status = gBS->OpenProtocol (
Controller,
&gEfiPciIoProtocolGuid,
(VOID **)&PciIo,
This->DriverBindingHandle,
Controller,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
return Status;
}
Status = PciIo->Pci.Read (
PciIo,
EfiPciIoWidthUint32,
0,
sizeof (Pci) / sizeof (UINT32),
&Pci
);
if (!EFI_ERROR (Status)) {
if ((Pci.Hdr.VendorId == REIMS_VGPU_VENDOR_ID) &&
(Pci.Hdr.DeviceId == REIMS_VGPU_DEVICE_ID))
{
Status = EFI_SUCCESS;
} else {
Status = EFI_UNSUPPORTED;
}
}
gBS->CloseProtocol (
Controller,
&gEfiPciIoProtocolGuid,
This->DriverBindingHandle,
Controller
);
return Status;
}
/**
Bind to Controller: read the device's mode list, allocate and map a frame
buffer large enough for the largest mode, and install Device Path and
Graphics Output protocols on a child handle.
**/
/**
Write a 32-bit device register in BAR 0.
**/
VOID
ReimsVgpuWriteRegister (
IN EFI_PCI_IO_PROTOCOL *PciIo,
IN UINT64 Offset,
IN UINT32 Value
)
{
PciIo->Mem.Write (PciIo, EfiPciIoWidthUint32, 0, Offset, 1, &Value);
}
/**
Read a 32-bit device register in BAR 0.
**/
STATIC
VOID
ReimsVgpuReadRegister (
IN EFI_PCI_IO_PROTOCOL *PciIo,
IN UINT64 Offset,
OUT UINT32 *Value
)
{
PciIo->Mem.Read (PciIo, EfiPciIoWidthUint32, 0, Offset, 1, Value);
}
/**
Check that the frame buffer's dword at Index reads back through the frame
buffer BAR: a pattern written into the buffer, then its complement. The
dword is restored.
**/
STATIC
BOOLEAN
ReimsVgpuFrameBufferReadsBack (
IN REIMS_VGPU_PRIVATE_DATA *Private,
IN UINT32 Index
)
{
STATIC CONST UINT32 Patterns[] = { 0x5AA5C33C, 0xA55A3CC3 };
volatile UINT32 *Buffer;
UINT32 Original;
UINT32 Value;
UINTN Pattern;
BOOLEAN ReadsBack;
EFI_STATUS Status;
Buffer = (volatile UINT32 *)Private->FrameBuffer;
Original = Buffer[Index];
ReadsBack = TRUE;
for (Pattern = 0; Pattern < ARRAY_SIZE (Patterns) && ReadsBack; Pattern++) {
Buffer[Index] = Patterns[Pattern];
//
// The store is visible before the read through the BAR, another
// address of the same memory.
//
__asm__ __volatile__ ("mfence" ::: "memory");
Status = Private->PciIo->Mem.Read (
Private->PciIo,
EfiPciIoWidthUint32,
REIMS_VGPU_FRAMEBUFFER_BAR,
(UINT64)Index * sizeof (UINT32),
1,
&Value
);
ReadsBack = !EFI_ERROR (Status) && (Value == Patterns[Pattern]);
}
Buffer[Index] = Original;
return ReadsBack;
}
/**
The frame buffer's address for the Graphics Output Protocol: the frame
buffer BAR's, where the device shows the Size bytes of the frame buffer
there, or else the frame buffer's own in guest RAM.
The BAR is used when it is a memory BAR of at least Size bytes, below
4 GiB with no address translation, and the buffer's first and last dwords
read back through it. QEMU's apple-gfx-pci makes BAR 2 an alias of the RAM
the EFI display's registers name, once they are written.
**/
STATIC
EFI_PHYSICAL_ADDRESS
ReimsVgpuFrameBufferBase (
IN REIMS_VGPU_PRIVATE_DATA *Private,
IN UINT32 Size
)
{
EFI_STATUS Status;
EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Bar;
EFI_PHYSICAL_ADDRESS BarBase;
BOOLEAN Usable;
Status = Private->PciIo->GetBarAttributes (
Private->PciIo,
REIMS_VGPU_FRAMEBUFFER_BAR,
NULL,
(VOID **)&Bar
);
if (EFI_ERROR (Status)) {
return Private->FrameBufferDeviceAddress;
}
BarBase = Bar->AddrRangeMin;
Usable = (Bar->Desc == ACPI_ADDRESS_SPACE_DESCRIPTOR) &&
(Bar->ResType == ACPI_ADDRESS_SPACE_TYPE_MEM) &&
(Bar->AddrTranslationOffset == 0) &&
(Bar->AddrLen >= Size) &&
(BarBase < SIZE_4GB) &&
(Size <= SIZE_4GB - BarBase);
FreePool (Bar);
if (!Usable ||
!ReimsVgpuFrameBufferReadsBack (Private, 0) ||
!ReimsVgpuFrameBufferReadsBack (Private, Size / sizeof (UINT32) - 1))
{
return Private->FrameBufferDeviceAddress;
}
return BarBase;
}
EFI_STATUS
EFIAPI
ReimsVgpuDriverBindingStart (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
)
{
EFI_STATUS Status;
REIMS_VGPU_PRIVATE_DATA *Private;
EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
ACPI_ADR_DEVICE_PATH AcpiDeviceNode;
UINTN Index;
UINT32 Size;
UINT32 MaxSize;
UINTN MapSize;
Private = AllocateZeroPool (sizeof (REIMS_VGPU_PRIVATE_DATA));
if (Private == NULL) {
return EFI_OUT_OF_RESOURCES;
}
Private->Signature = REIMS_VGPU_PRIVATE_DATA_SIGNATURE;
Private->Handle = NULL;
Status = gBS->OpenProtocol (
Controller,
&gEfiPciIoProtocolGuid,
(VOID **)&Private->PciIo,
This->DriverBindingHandle,
Controller,
EFI_OPEN_PROTOCOL_BY_DRIVER
);
if (EFI_ERROR (Status)) {
return Status;
}
Status = Private->PciIo->Attributes (
Private->PciIo,
EfiPciIoAttributeOperationGet,
0,
&Private->OriginalPciAttributes
);
if (EFI_ERROR (Status)) {
return Status;
}
Status = Private->PciIo->Attributes (
Private->PciIo,
EfiPciIoAttributeOperationEnable,
EFI_PCI_DEVICE_ENABLE,
NULL
);
if (EFI_ERROR (Status)) {
return Status;
}
Status = gBS->HandleProtocol (
Controller,
&gEfiDevicePathProtocolGuid,
(VOID **)&ParentDevicePath
);
if (EFI_ERROR (Status)) {
return Status;
}
UINT32 ModeCount;
//
// A resolution of all ones means the list changed while it was being
// read, so start over.
//
ReimsVgpuWriteRegister (Private->PciIo, REIMS_VGPU_REG_EFI_ENABLE, 1);
Retry:
if (Private->ModeTable != NULL) {
FreePool (Private->ModeTable);
Private->ModeTable = NULL;
Private->MaxMode = 0;
}
ReimsVgpuReadRegister (Private->PciIo, REIMS_VGPU_REG_EFI_MODE_COUNT, &ModeCount);
if ((ModeCount > 0) && (ModeCount <= REIMS_VGPU_MAX_MODES)) {
Private->ModeTable = AllocateZeroPool (ModeCount * sizeof (REIMS_VGPU_MODE));
if (Private->ModeTable == NULL) {
return EFI_OUT_OF_RESOURCES;
}
Private->MaxMode = ModeCount;
for (Index = 0; Index < ModeCount; Index++) {
UINT32 Resolution;
UINT32 Width;
UINT32 Height;
ReimsVgpuWriteRegister (Private->PciIo, REIMS_VGPU_REG_EFI_MODE_SELECT, (UINT32)Index);
ReimsVgpuReadRegister (Private->PciIo, REIMS_VGPU_REG_EFI_MODE_VALUE, &Resolution);
if (Resolution == 0xFFFFFFFF) {
goto Retry;
}
Height = Resolution >> 16;
Width = Resolution & 0xFFFF;
Private->ModeTable[Index].Width = Width;
Private->ModeTable[Index].Height = Height;
Private->ModeTable[Index].BitsPerPixel = 32;
}
} else {
Private->ModeTable = AllocateZeroPool (sizeof (mReimsVgpuDefaultModes));
if (Private->ModeTable == NULL) {
return EFI_OUT_OF_RESOURCES;
}
Private->MaxMode = ARRAY_SIZE (mReimsVgpuDefaultModes);
for (Index = 0; Index < Private->MaxMode; Index++) {
Private->ModeTable[Index] = mReimsVgpuDefaultModes[Index];
}
}
//
// Size the frame buffer for the largest mode.
//
MaxSize = 0;
for (Index = 0; Index < Private->MaxMode; Index++) {
Size = Private->ModeTable[Index].Width * Private->ModeTable[Index].Height *
(Private->ModeTable[Index].BitsPerPixel / 8);
MaxSize = MAX (Size, MaxSize);
}
Size = (MaxSize + EFI_PAGE_MASK) & ~EFI_PAGE_MASK;
//
// Runtime services data, which the OS keeps past ExitBootServices: the
// device presents these pages, and the frame buffer BAR shows them. macOS's
// boot.efi may move runtime data, which would leave both on the old pages,
// unless the loader keeps it in place, as OpenCore's AvoidRuntimeDefrag
// quirk does.
//
Status = Private->PciIo->AllocateBuffer (
Private->PciIo,
AllocateAnyPages,
EfiRuntimeServicesData,
EFI_SIZE_TO_PAGES (Size),
&Private->FrameBuffer,
0
);
if (EFI_ERROR (Status)) {
return Status;
}
MapSize = Size;
Status = Private->PciIo->Map (
Private->PciIo,
EfiPciIoOperationBusMasterCommonBuffer,
Private->FrameBuffer,
&MapSize,
&Private->FrameBufferDeviceAddress,
&Private->FrameBufferMapping
);
if (!EFI_ERROR (Status) && (MapSize != Size)) {
Private->PciIo->Unmap (Private->PciIo, Private->FrameBufferMapping);
Status = EFI_OUT_OF_RESOURCES;
}
if (EFI_ERROR (Status)) {
Private->PciIo->FreeBuffer (Private->PciIo, EFI_SIZE_TO_PAGES (Size), &Private->FrameBuffer);
return Status;
}
//
// These are in 4 KiB pages, the x86-64 guest's, which the device counts when
// the library is built for x86-64 (docs/architecture.md 11.4).
//
ReimsVgpuWriteRegister (Private->PciIo, REIMS_VGPU_REG_EFI_START, (UINT32)(Private->FrameBufferDeviceAddress >> EFI_PAGE_SHIFT));
ReimsVgpuWriteRegister (Private->PciIo, REIMS_VGPU_REG_EFI_LENGTH, Size);
//
// The device keeps presenting the buffer in RAM; the Graphics Output
// Protocol gives the frame buffer BAR's address where the BAR shows it. An
// OS with no driver of the device's own (macOS's installers and recovery)
// takes the boot frame buffer over only inside one of the device's BARs.
//
Private->FrameBufferBase = ReimsVgpuFrameBufferBase (Private, Size);
//
// The Graphics Output child is an ACPI _ADR node below the controller.
//
AcpiDeviceNode.Header.Type = ACPI_DEVICE_PATH;
AcpiDeviceNode.Header.SubType = ACPI_ADR_DP;
AcpiDeviceNode.ADR = ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_OTHER, 0, 0);
AcpiDeviceNode.Header.Length[0] = (UINT8)sizeof (ACPI_ADR_DEVICE_PATH);
AcpiDeviceNode.Header.Length[1] = 0;
Private->GopDevicePath = mDevicePathUtilities->AppendDeviceNode (ParentDevicePath, &AcpiDeviceNode.Header);
Private->Handle = NULL;
Status = gBS->InstallMultipleProtocolInterfaces (
&Private->Handle,
&gEfiDevicePathProtocolGuid,
Private->GopDevicePath,
NULL
);
if (EFI_ERROR (Status)) {
return Status;
}
Status = gBS->OpenProtocol (
Controller,
&gEfiPciIoProtocolGuid,
(VOID **)&Private->PciIo,
gImageHandle,
Private->Handle,
EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
);
if (EFI_ERROR (Status)) {
return Status;
}
ReimsVgpuGraphicsOutputConstructor (Private);
Status = gBS->InstallMultipleProtocolInterfaces (
&Private->Handle,
&gEfiGraphicsOutputProtocolGuid,
&Private->GraphicsOutput,
NULL
);
return Status;
}
/**
Remove the Graphics Output child and release its resources.
**/
EFI_STATUS
EFIAPI
ReimsVgpuDriverBindingStop (
IN EFI_DRIVER_BINDING_PROTOCOL *This,
IN EFI_HANDLE Controller,
IN UINTN NumberOfChildren,
IN EFI_HANDLE *ChildHandleBuffer
)
{
EFI_STATUS Status;
EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
REIMS_VGPU_PRIVATE_DATA *Private;
Status = gBS->OpenProtocol (
ChildHandleBuffer[0],
&gEfiPciIoProtocolGuid,
(VOID **)&GraphicsOutput,
gImageHandle,
Controller,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
Private = REIMS_VGPU_PRIVATE_DATA_FROM_GRAPHICS_OUTPUT_THIS (GraphicsOutput);
if (!EFI_ERROR (Status)) {
return Status;
}
if (NumberOfChildren == 0) {
gBS->CloseProtocol (
Controller,
&gEfiPciIoProtocolGuid,
gImageHandle,
Controller
);
return EFI_SUCCESS;
}
gBS->UninstallMultipleProtocolInterfaces (
&Private->Handle,
&gEfiDevicePathProtocolGuid,
Private->GopDevicePath,
&gEfiGraphicsOutputProtocolGuid,
&Private->GraphicsOutput,
NULL
);
gBS->CloseProtocol (
Controller,
&gEfiPciIoProtocolGuid,
gImageHandle,
Private->Handle
);
FreePool (Private->GopDevicePath);
FreePool (Private);
return EFI_SUCCESS;
}
EFI_DRIVER_BINDING_PROTOCOL gReimsVgpuDriverBinding = {
ReimsVgpuDriverBindingSupported,
ReimsVgpuDriverBindingStart,
ReimsVgpuDriverBindingStop,
0x10,
NULL,
NULL
};
/**
Image entry point. Locate the Device Path Utilities protocol, then install
the driver's protocols on its image handle. Only the status of the last
install is returned; the lookup and the first install are not checked.
**/
EFI_STATUS
EFIAPI
ReimsVgpuEntryPoint (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;
gImageHandle = ImageHandle;
gBS = SystemTable->BootServices;
gBS->LocateProtocol (
&gEfiDevicePathUtilitiesProtocolGuid,
NULL,
(VOID **)&mDevicePathUtilities
);
gReimsVgpuDriverBinding.ImageHandle = ImageHandle;
gReimsVgpuDriverBinding.DriverBindingHandle = ImageHandle;
gBS->InstallMultipleProtocolInterfaces (
&gReimsVgpuDriverBinding.DriverBindingHandle,
&gEfiDriverBindingProtocolGuid,
&gReimsVgpuDriverBinding,
&gEfiComponentNameProtocolGuid,
&gReimsVgpuComponentName,
&gEfiComponentName2ProtocolGuid,
&gReimsVgpuComponentName2,
NULL
);
gReimsVgpuSupportedEfiVersion.FirmwareVersion = EFI_2_10_SYSTEM_TABLE_REVISION;
Status = gBS->InstallMultipleProtocolInterfaces (
&ImageHandle,
&gEfiDriverSupportedEfiVersionProtocolGuid,
&gReimsVgpuSupportedEfiVersion,
NULL
);
return Status;
}
-117
View File
@@ -1,117 +0,0 @@
/** @file
Private data and interfaces of the paravirtualized GPU driver.
**/
#ifndef REIMS_VGPU_H_
#define REIMS_VGPU_H_
//
// The device's PCI identity, checked by the driver binding and written into
// the option ROM header. OptionRom.S includes this header for these values
// only, so everything below them is C.
//
#define REIMS_VGPU_VENDOR_ID 0x106B
#define REIMS_VGPU_DEVICE_ID 0xEEEE
#define REIMS_VGPU_CLASS_CODE 0x030200
#ifndef __ASSEMBLER__
#include "Uefi.h"
//
// The EFI display's 32-bit registers in memory BAR 0, named as the device
// names them (docs/testing.md sections 6.2 and 6.22).
//
#define REIMS_VGPU_REG_EFI_ENABLE 0x1200 // nonzero enables the EFI display
#define REIMS_VGPU_REG_EFI_MODE_COUNT 0x1204 // the display's mode count
#define REIMS_VGPU_REG_EFI_MODE_SELECT 0x1208 // selects the mode 0x120C reads
#define REIMS_VGPU_REG_EFI_MODE_VALUE 0x120C // width | height << 16; all ones out of range
#define REIMS_VGPU_REG_EFI_START 0x1210 // the framebuffer's start, in guest pages (4 KiB on x86-64)
#define REIMS_VGPU_REG_EFI_LENGTH 0x1214 // bytes: whole guest pages, at most 64 MiB
#define REIMS_VGPU_REG_EFI_DEPTH 0x1218 // bits per pixel: only 32 presents
#define REIMS_VGPU_REG_EFI_MODE 0x121C // width | height << 16
#define REIMS_VGPU_MAX_MODES 127
//
// The memory BAR through which QEMU's apple-gfx-pci shows the frame buffer
// the EFI display's registers name: the Graphics Output Protocol gives its
// address when the buffer reads back through it (docs/architecture.md 11.4).
//
#define REIMS_VGPU_FRAMEBUFFER_BAR 2
typedef struct {
UINT32 Width;
UINT32 Height;
UINT32 BitsPerPixel;
} REIMS_VGPU_MODE;
#define REIMS_VGPU_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('R', 'V', 'G', 'P')
typedef struct {
UINTN Signature;
EFI_HANDLE Handle;
EFI_PCI_IO_PROTOCOL *PciIo;
UINT64 OriginalPciAttributes;
EFI_DEVICE_PATH_PROTOCOL *GopDevicePath;
EFI_GRAPHICS_OUTPUT_PROTOCOL GraphicsOutput;
EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE GraphicsOutputMode;
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION ModeInformation;
UINT64 Reserved[4];
REIMS_VGPU_MODE *ModeTable;
UINT32 MaxMode;
VOID *FrameBuffer;
EFI_PHYSICAL_ADDRESS FrameBufferDeviceAddress;
VOID *FrameBufferMapping;
EFI_PHYSICAL_ADDRESS FrameBufferBase; // the Graphics Output Protocol's
} REIMS_VGPU_PRIVATE_DATA;
#define REIMS_VGPU_PRIVATE_DATA_FROM_GRAPHICS_OUTPUT_THIS(a) \
BASE_CR (a, REIMS_VGPU_PRIVATE_DATA, GraphicsOutput)
extern EFI_HANDLE gImageHandle;
extern EFI_BOOT_SERVICES *gBS;
extern EFI_DRIVER_BINDING_PROTOCOL gReimsVgpuDriverBinding;
extern EFI_COMPONENT_NAME_PROTOCOL gReimsVgpuComponentName;
extern EFI_COMPONENT_NAME2_PROTOCOL gReimsVgpuComponentName2;
extern EFI_DRIVER_SUPPORTED_EFI_VERSION_PROTOCOL gReimsVgpuSupportedEfiVersion;
EFI_STATUS
EFIAPI
ReimsVgpuComponentNameGetDriverName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN CHAR8 *Language,
OUT CHAR16 **DriverName
);
EFI_STATUS
EFIAPI
ReimsVgpuComponentNameGetControllerName (
IN EFI_COMPONENT_NAME_PROTOCOL *This,
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE ChildHandle OPTIONAL,
IN CHAR8 *Language,
OUT CHAR16 **ControllerName
);
VOID *
AllocateRuntimePool (
IN UINTN AllocationSize
);
VOID
ReimsVgpuWriteRegister (
IN EFI_PCI_IO_PROTOCOL *PciIo,
IN UINT64 Offset,
IN UINT32 Value
);
VOID
ReimsVgpuGraphicsOutputConstructor (
IN REIMS_VGPU_PRIVATE_DATA *Private
);
#endif // __ASSEMBLER__
#endif
+11 -41
View File
@@ -7,15 +7,11 @@
//! How each OS builds and names them is its own module's: `macos`, `linux`.
//! - `include/reims_vgpu.h`, the committed header.
//! - `lib/pkgconfig/reims-vgpu.pc`. Its `Libs.private` names every library a static link of the
//! archive needs; its `optionrom` variable names the ROM below.
//! - `share/reims-vgpu/ReimsVgpu.rom`: the EFI option ROM, the driver in [`FIRMWARE`] built by
//! its own Makefile (clang and lld) into `<target>/firmware`. QEMU's `apple-gfx-pci` loads it
//! as its default `romfile`.
//! archive needs.
//! - `share/doc/reims-vgpu/`: the license, `LICENSE` and the texts in `LICENSES/` it points at,
//! copied from the repository under the same names ([`install_license`]).
//!
//! QEMU (`make qemu`) and the smoke link the archive; the suite's runner links the dylib, and
//! loads it from the tree when it runs.
//! QEMU (`make qemu`) links the archive; the C API's tests link the shared library.
//!
//! `--platform vulkan` builds the library on the Vulkan platform instead (`reims-vgpu-c`'s
//! `vulkan` feature, architecture 2.2), into `<target>/dist-vulkan` unless `--out` says
@@ -42,12 +38,6 @@ pub const LIB: &str = "reims_vgpu";
pub const PACKAGE: &str = "reims-vgpu";
/// The header, under the name it is committed and installed with.
pub const HEADER: &str = "reims_vgpu.h";
/// The option ROM's file name: the firmware's build output, and its name in `share/reims-vgpu`
/// and in QEMU's data directory.
pub const ROM: &str = "ReimsVgpu.rom";
/// The EFI driver the option ROM packages, in the repository, and the directory under the target
/// dir it is built into.
pub const FIRMWARE: &str = "firmware";
/// The file that states the license, in the repository and in the tree's [`doc_dir`].
pub const LICENSE: &str = "LICENSE";
/// The directory of the license's texts, `<SPDX identifier>.txt` each, in the repository and in
@@ -146,15 +136,6 @@ pub fn c_api_args(o: &Options) -> Vec<String> {
args
}
/// The `make` arguments that build the option ROM from `firmware`, the driver's directory, into
/// `build`.
pub fn firmware_args(firmware: &Path, build: &Path) -> Vec<String> {
let mut args = strs_with(&["-C"], firmware);
args.push(format!("BUILD={}", build.display()));
args.push("rom".to_owned());
args
}
/// `reims-vgpu.pc`. Its prefix is the file's grandparent directory (`${pcfiledir}`), so the tree
/// can be moved.
pub fn pc_file(version: &str, libs_private: &[String]) -> String {
@@ -163,11 +144,9 @@ pub fn pc_file(version: &str, libs_private: &[String]) -> String {
prefix=${{pcfiledir}}/../..\n\
libdir=${{prefix}}/lib\n\
includedir=${{prefix}}/include\n\
# The EFI option ROM for the PCI device, 106b:eeee.\n\
optionrom=${{prefix}}/share/{PACKAGE}/{ROM}\n\
\n\
Name: {PACKAGE}\n\
Description: The host side of the paravirtualized GPU that macOS guests drive\n\
Description: The host side of the reims-graphics device, the GPU macOS guests drive\n\
Version: {version}\n\
Libs: -L${{libdir}} -l{LIB}\n\
Libs.private: {}\n\
@@ -177,14 +156,13 @@ pub fn pc_file(version: &str, libs_private: &[String]) -> String {
}
/// The files `dist` writes under its output directory, relative to it: the archive, the shared
/// library (`native::SHARED_LIBRARY_EXTENSION`), the package, the header and the ROM.
pub fn layout() -> [String; 5] {
/// library (`native::SHARED_LIBRARY_EXTENSION`), the package and the header.
pub fn layout() -> [String; 4] {
[
format!("lib/lib{LIB}.a"),
format!("lib/lib{LIB}.{}", native::SHARED_LIBRARY_EXTENSION),
format!("lib/pkgconfig/{PACKAGE}.pc"),
format!("include/{HEADER}"),
format!("share/{PACKAGE}/{ROM}"),
]
}
@@ -231,8 +209,7 @@ pub fn cmd_dist(args: &[String]) -> Res<bool> {
let target = target_dir(&mut System)?;
let o = parse_args(args, &target)?;
let header = repo_root().join("crates/reims-vgpu-c/include").join(HEADER);
let firmware = repo_root().join(FIRMWARE);
let out = native::dist(&mut System, &o, &target, &header, &firmware)?;
let out = native::dist(&mut System, &o, &target, &header)?;
let license = install_license(&repo_root(), &out)?;
for p in layout().into_iter().chain(license) {
println!("dist: {}", out.join(p).display());
@@ -384,21 +361,12 @@ mod tests {
}
#[test]
fn firmware_args_build_the_rom_into_the_build_dir() {
assert_eq!(
firmware_args(Path::new("/r/firmware"), Path::new("/t/firmware")).join(" "),
"-C /r/firmware BUILD=/t/firmware rom"
);
}
#[test]
fn pc_file_links_the_library_and_names_the_rom() {
fn pc_file_links_the_library() {
let pc = pc_file("1.2.3", &strs(&["-framework", "Metal", "-lobjc"]));
for line in [
"prefix=${pcfiledir}/../..",
"libdir=${prefix}/lib",
"includedir=${prefix}/include",
"optionrom=${prefix}/share/reims-vgpu/ReimsVgpu.rom",
"Name: reims-vgpu",
"Version: 1.2.3",
"Libs: -L${libdir} -lreims_vgpu",
@@ -489,10 +457,12 @@ mod tests {
#[test]
fn layout_matches_what_the_pc_file_names() {
let pc = pc_file("0", &[]);
let [archive, _shared, pcpath, header, rom] = layout();
let [archive, _shared, pcpath, header] = layout();
assert_eq!(archive, "lib/libreims_vgpu.a");
assert_eq!(pcpath, "lib/pkgconfig/reims-vgpu.pc");
assert_eq!(header, "include/reims_vgpu.h");
assert!(pc.contains(&format!("${{prefix}}/{rom}")));
assert!(
pc.contains("libdir=${prefix}/lib\n") && pc.contains("includedir=${prefix}/include\n")
);
}
}
+23 -112
View File
@@ -1,8 +1,7 @@
//! `cargo xtask dist` on Linux: the library on the Vulkan platform, the only one Linux builds.
//! The shared library is `lib/libreims_vgpu.so`, whose soname is its own name; nothing is signed
//! and nothing has an install name. `Libs.private` is what rustc prints for linking the archive
//! (`--print native-static-libs`). The ROM is built here, by the host's clang, so its bytes are
//! that compiler's, not the Mac's: `dist` prints its sha256 and the clang that built it.
//! (`--print native-static-libs`).
//!
//! The library's shaders are metallibs that only a Mac compiles: the build copies those the
//! repository holds (`crates/reims-vgpu-vulkan/metallibs`), or those in the directory
@@ -20,10 +19,7 @@
use std::path::{Path, PathBuf};
use super::{
FIRMWARE, LIB, Options, Platform, ROM, c_api_args, firmware_args, install, layout, pc_file,
strs, strs_with, write,
};
use super::{LIB, Options, Platform, c_api_args, install, layout, pc_file, strs, strs_with, write};
use crate::tools::Tools;
use crate::util::Res;
@@ -85,15 +81,9 @@ pub fn native_static_libs(cargo: &str) -> Res<Vec<String>> {
Ok(libs)
}
/// Builds and writes the tree with `tools`; `header` is the committed header and `firmware` the
/// option ROM's driver. Returns the output directory.
pub fn dist(
tools: &mut dyn Tools,
o: &Options,
target_dir: &Path,
header: &Path,
firmware: &Path,
) -> Res<PathBuf> {
/// Builds and writes the tree with `tools`; `header` is the committed header. Returns the output
/// directory.
pub fn dist(tools: &mut dyn Tools, o: &Options, target_dir: &Path, header: &Path) -> Res<PathBuf> {
if o.platform == Platform::Metal {
return Err(
"--platform metal: the Metal platform is macOS only; on Linux the library is built \
@@ -101,15 +91,10 @@ pub fn dist(
.to_owned(),
);
}
// The ROM first: it takes a second, and a host without lld fails before the library builds.
let firmware_build = target_dir.join(FIRMWARE);
tools
.run("make", &firmware_args(firmware, &firmware_build))
.map_err(|e| format!("{e}: the option ROM did not build (it needs clang and lld)"))?;
let cargo = std::env::var("CARGO").unwrap_or_else(|_| "cargo".to_owned());
tools.run(&cargo, &cargo_args(o))?;
let built = target_dir.join(o.profile.dir());
let [archive, shared, pc, include, rom] = layout().map(|p| o.out.join(p));
let [archive, shared, pc, include] = layout().map(|p| o.out.join(p));
localize(
tools,
@@ -123,8 +108,6 @@ pub fn dist(
// in the target dir, not the one installed.
let libs = native_static_libs(&tools.output(&cargo, &static_libs_args(o))?)?;
write(&pc, &pc_file(env!("CARGO_PKG_VERSION"), &libs))?;
install(&firmware_build.join(ROM), &rom, 0o644)?;
println!("{}", rom_line(tools, &rom)?);
Ok(o.out.clone())
}
@@ -220,19 +203,6 @@ fn set_mode(file: &Path, mode: u32) -> Res<()> {
.map_err(|e| format!("{}: {e}", file.display()))
}
/// The line that names the ROM a boot used: its sha256 and the clang that built it. The ROM's
/// bytes depend on the compiler, so a ROM built here differs from the Mac's, and from one an
/// earlier clang built.
fn rom_line(tools: &mut dyn Tools, rom: &Path) -> Res<String> {
let sha = tools.output("sha256sum", &strs_with(&[], rom))?;
let clang = tools.output("clang", &strs(&["--version"]))?;
Ok(format!(
"dist: {ROM} sha256 {}, built by {}",
sha.split_whitespace().next().unwrap_or_default(),
clang.lines().next().unwrap_or_default()
))
}
#[cfg(test)]
mod tests {
use super::super::parse_args;
@@ -306,42 +276,20 @@ mod tests {
assert!(e.contains("names no library"), "{e}");
}
#[test]
fn rom_line_names_the_roms_hash_and_compiler() {
struct Answers;
impl Tools for Answers {
fn run(&mut self, _: &str, _: &[String]) -> Res<()> {
Ok(())
}
fn output(&mut self, program: &str, _: &[String]) -> Res<String> {
Ok(match program {
"sha256sum" => "9b4d4a9d /t/ReimsVgpu.rom".to_owned(),
_ => "clang version 23.1.1\nTarget: x86_64-pc-linux-gnu".to_owned(),
})
}
}
assert_eq!(
rom_line(&mut Answers, Path::new("/t/ReimsVgpu.rom")).unwrap(),
"dist: ReimsVgpu.rom sha256 9b4d4a9d, built by clang version 23.1.1"
);
}
#[test]
fn layout_names_the_shared_object() {
assert_eq!(layout()[1], "lib/libreims_vgpu.so");
}
/// A tree the build would write: the libraries Cargo built, the header and the ROM.
fn built(name: &str) -> (PathBuf, PathBuf, PathBuf, PathBuf) {
/// A tree the build would write: the libraries Cargo built and the header.
fn built(name: &str) -> (PathBuf, PathBuf, PathBuf) {
let root = tmp(name);
let target = root.join("target");
put(&target.join("release/libreims_vgpu_c.a"), "archive");
put(&target.join("release/libreims_vgpu_c.so"), "shared");
let header = root.join("reims_vgpu.h");
put(&header, "header");
// What the firmware's make writes.
put(&target.join("firmware/ReimsVgpu.rom"), "rom");
(root.clone(), target, header, root.join("firmware"))
(root.clone(), target, header)
}
/// The programs as `dist` runs them: each call recorded; `ar` writes the archive it names,
@@ -378,8 +326,6 @@ mod tests {
Ok(match program {
"nm" if last.ends_with(".o") => self.object.clone(),
"nm" => self.archive.clone(),
"sha256sum" => "9b4d4a9d ReimsVgpu.rom".to_owned(),
"clang" => "clang version 23.1.1".to_owned(),
_ => answer,
})
}
@@ -394,26 +340,24 @@ mod tests {
#[test]
fn dist_writes_the_tree_with_rustcs_libraries() {
let (root, target, header, firmware) = built("tree");
let (root, target, header) = built("tree");
let o = options(&[], &target);
// A previous tree's files are replaced.
put(&o.out.join("lib/libreims_vgpu.so"), "old");
put(&o.out.join("lib/libreims_vgpu.a"), "old");
let mut tools = Programs::new(OBJECT, LOCALIZED_ARCHIVE);
let out = dist(&mut tools, &o, &target, &header, &firmware).unwrap();
let out = dist(&mut tools, &o, &target, &header).unwrap();
assert_eq!(out, target.join("dist-vulkan"));
let read = |p: &str| std::fs::read_to_string(out.join(p)).unwrap();
assert_eq!(read("lib/libreims_vgpu.a"), "localized");
assert_eq!(read("lib/libreims_vgpu.so"), "shared");
assert_eq!(read("include/reims_vgpu.h"), "header");
assert_eq!(read("share/reims-vgpu/ReimsVgpu.rom"), "rom");
assert!(
read("lib/pkgconfig/reims-vgpu.pc")
.contains("Libs.private: -lgcc_s -lutil -lrt -lpthread -lm -ldl -lc\n")
);
assert_eq!(mode(&out.join("lib/libreims_vgpu.so")), 0o755);
assert_eq!(mode(&out.join("lib/libreims_vgpu.a")), 0o644);
assert_eq!(mode(&out.join("share/reims-vgpu/ReimsVgpu.rom")), 0o644);
let work = target.join("dist-localized");
let keep = work.join("keep-global-symbols");
assert_eq!(
@@ -423,21 +367,13 @@ mod tests {
let object = work.join("reims_vgpu.o");
let archive = out.join("lib/libreims_vgpu.a");
let calls = tools.log.lines();
assert_eq!(
calls[0],
format!(
"make -C {} BUILD={} rom",
firmware.display(),
target.join("firmware").display()
)
);
assert!(
calls[1].ends_with(" -- -C link-arg=-Wl,-soname,libreims_vgpu.so"),
calls[0].ends_with(" -- -C link-arg=-Wl,-soname,libreims_vgpu.so"),
"{}",
calls[1]
calls[0]
);
assert_eq!(
calls[2..7],
calls[1..6],
[
format!(
"ld -r --whole-archive {} -o {}",
@@ -455,32 +391,23 @@ mod tests {
]
);
assert!(
calls[7].ends_with(" -- --print native-static-libs"),
calls[6].ends_with(" -- --print native-static-libs"),
"{}",
calls[7]
);
assert_eq!(
calls[8..],
[
format!(
"sha256sum {}",
out.join("share/reims-vgpu/ReimsVgpu.rom").display()
),
"clang --version".to_owned(),
]
calls[6]
);
assert_eq!(calls.len(), 7, "{calls:?}");
std::fs::remove_dir_all(&root).unwrap();
}
/// A global the archive still defines besides the C API's fails the dist, naming it
#[test]
fn dist_fails_where_the_archive_keeps_another_global() {
let (root, target, header, firmware) = built("leak");
let (root, target, header) = built("leak");
let o = options(&[], &target);
let leaky = "libreims_vgpu.a[reims_vgpu.o]:\nrvg_graphics_device_create T 1000 20\n\
SDL_Init T 2000 40\n";
let mut tools = Programs::new(OBJECT, leaky);
let e = dist(&mut tools, &o, &target, &header, &firmware).unwrap_err();
let e = dist(&mut tools, &o, &target, &header).unwrap_err();
assert!(e.contains("1 global symbols besides the C API's"), "{e}");
assert!(e.contains("SDL_Init"), "{e}");
std::fs::remove_dir_all(&root).unwrap();
@@ -489,10 +416,10 @@ mod tests {
/// An object with no `rvg_` function is refused before anything is made local
#[test]
fn dist_refuses_an_archive_without_the_c_api() {
let (root, target, header, firmware) = built("noapi");
let (root, target, header) = built("noapi");
let o = options(&[], &target);
let mut tools = Programs::new("SDL_Init T 2000 40\n", LOCALIZED_ARCHIVE);
let e = dist(&mut tools, &o, &target, &header, &firmware).unwrap_err();
let e = dist(&mut tools, &o, &target, &header).unwrap_err();
assert!(e.contains("defines no rvg_ function"), "{e}");
assert!(
!tools.log.lines().iter().any(|l| l.starts_with("objcopy")),
@@ -514,29 +441,13 @@ mod tests {
#[test]
fn dist_refuses_metal_before_building() {
let (root, target, header, firmware) = built("refusals");
let (root, target, header) = built("refusals");
let mut log = Log::default();
let metal = options(&["--platform", "metal"], &target);
let e = dist(&mut log, &metal, &target, &header, &firmware).unwrap_err();
let e = dist(&mut log, &metal, &target, &header).unwrap_err();
assert!(e.contains("--platform metal"), "{e}");
assert!(log.calls.is_empty(), "{:?}", log.calls);
assert!(!metal.out.exists());
std::fs::remove_dir_all(&root).unwrap();
}
#[test]
fn dist_stops_before_the_library_when_the_rom_does_not_build() {
let (root, target, header, firmware) = built("norom");
let o = options(&[], &target);
let mut log = Log {
fail: Some("make"),
..Log::default()
};
let e = dist(&mut log, &o, &target, &header, &firmware).unwrap_err();
assert!(e.contains("make failed"), "{e}");
assert!(e.contains("clang and lld"), "{e}");
assert_eq!(log.calls.len(), 1, "{:?}", log.calls);
assert!(!o.out.exists());
std::fs::remove_dir_all(&root).unwrap();
}
}
+23 -74
View File
@@ -37,10 +37,7 @@
use std::path::{Path, PathBuf};
use super::{
FIRMWARE, LIB, Options, Platform, ROM, c_api_args, firmware_args, install, layout, pc_file,
strs, strs_with, write,
};
use super::{LIB, Options, Platform, c_api_args, install, layout, pc_file, strs, strs_with, write};
use crate::tools::Tools;
use crate::util::Res;
@@ -183,15 +180,9 @@ pub fn libs_private(otool: &str, own: &str) -> Res<Vec<String>> {
Ok(libs)
}
/// Builds and writes the tree with `tools`; `header` is the committed header and `firmware` the
/// option ROM's driver. Returns the output directory.
pub fn dist(
tools: &mut dyn Tools,
o: &Options,
target_dir: &Path,
header: &Path,
firmware: &Path,
) -> Res<PathBuf> {
/// Builds and writes the tree with `tools`; `header` is the committed header. Returns the output
/// directory.
pub fn dist(tools: &mut dyn Tools, o: &Options, target_dir: &Path, header: &Path) -> Res<PathBuf> {
if !cfg!(target_arch = "aarch64") {
return Err("the library is arm64 macOS only".to_owned());
}
@@ -201,13 +192,6 @@ pub fn dist(
flags that give SDL's Objective-C classes the library's names: unset it"
));
}
// The ROM first: it takes a second, and a host without lld fails before the library builds.
let firmware_build = target_dir.join(FIRMWARE);
tools
.run("make", &firmware_args(firmware, &firmware_build))
.map_err(|e| {
format!("{e}: the option ROM did not build (it needs clang and lld: brew install lld)")
})?;
let cargo = std::env::var("CARGO").unwrap_or_else(|_| "cargo".to_owned());
// SDL builds again where the flags it was last built with here are not today's, or unknown.
// The stamp is written once the archive is checked, so an SDL the flags did not reach is
@@ -221,7 +205,7 @@ pub fn dist(
}
tools.run(&cargo, &cargo_args(o))?;
let built = target_dir.join(o.profile.dir());
let [archive, dylib, pc, include, rom] = layout().map(|p| o.out.join(p));
let [archive, dylib, pc, include] = layout().map(|p| o.out.join(p));
localize(
tools,
@@ -241,7 +225,6 @@ pub fn dist(
let otool = tools.output("xcrun", &strs_with(&["otool", "-L"], &dylib))?;
let libs = libs_private(&otool, INSTALL_NAME)?;
write(&pc, &pc_file(env!("CARGO_PKG_VERSION"), &libs))?;
install(&firmware_build.join(ROM), &rom, 0o644)?;
Ok(o.out.clone())
}
@@ -530,39 +513,35 @@ mod tests {
}
}
/// A tree the build would write: the libraries Cargo built, the header and the ROM.
fn built(name: &str) -> (PathBuf, PathBuf, PathBuf, PathBuf) {
/// A tree the build would write: the libraries Cargo built and the header.
fn built(name: &str) -> (PathBuf, PathBuf, PathBuf) {
let root = tmp(name);
let target = root.join("target");
put(&target.join("release/libreims_vgpu_c.a"), "archive");
put(&target.join("release/libreims_vgpu_c.dylib"), "dylib");
let header = root.join("reims_vgpu.h");
put(&header, "header");
// What the firmware's make writes.
put(&target.join("firmware/ReimsVgpu.rom"), "rom");
(root.clone(), target, header, root.join("firmware"))
(root.clone(), target, header)
}
#[test]
fn dist_writes_the_tree_and_renames_the_dylib() {
let (root, target, header, firmware) = built("tree");
let (root, target, header) = built("tree");
let o = parse_args(&[], &target).unwrap();
// A previous tree's files are replaced.
put(&o.out.join("lib/libreims_vgpu.a"), "old");
let mut tools = Programs::new(LOCALIZED_ARCHIVE);
let out = dist(&mut tools, &o, &target, &header, &firmware).unwrap();
let out = dist(&mut tools, &o, &target, &header).unwrap();
assert_eq!(out, target.join("dist"));
let read = |p: &str| std::fs::read_to_string(out.join(p)).unwrap();
assert_eq!(read("lib/libreims_vgpu.a"), "localized");
assert_eq!(read("lib/libreims_vgpu.dylib"), "dylib");
assert_eq!(read("include/reims_vgpu.h"), "header");
assert_eq!(read("share/reims-vgpu/ReimsVgpu.rom"), "rom");
assert!(read("lib/pkgconfig/reims-vgpu.pc").contains(
"Libs.private: -weak_framework AppKit -framework Metal -lSystem -liconv -lobjc\n"
));
assert_eq!(mode(&out.join("lib/libreims_vgpu.dylib")), 0o755);
assert_eq!(mode(&out.join("lib/libreims_vgpu.a")), 0o644);
assert_eq!(mode(&out.join("share/reims-vgpu/ReimsVgpu.rom")), 0o644);
let dylib = out.join("lib/libreims_vgpu.dylib");
let d = dylib.to_str().unwrap();
let work = target.join("dist-localized");
@@ -572,21 +551,13 @@ mod tests {
let packed = work.join("libreims_vgpu.a");
let archive = out.join("lib/libreims_vgpu.a");
let calls = tools.log.lines();
assert_eq!(
calls[0],
format!(
"make -C {} BUILD={} rom",
firmware.display(),
target.join("firmware").display()
)
);
// SDL builds again, as no flags are known for it here.
assert!(
calls[1].ends_with(" clean --profile release -p sdl3-sys"),
calls[0].ends_with(" clean --profile release -p sdl3-sys"),
"{}",
calls[1]
calls[0]
);
assert!(calls[2].ends_with(&format!(
assert!(calls[1].ends_with(&format!(
" build --profile release -p reims-vgpu-c --lib \
--config env.MACOSX_DEPLOYMENT_TARGET=\"11.0\" {}",
renames()
@@ -596,7 +567,7 @@ mod tests {
sdl_cflags()
);
assert_eq!(
calls[3..],
calls[2..],
[
format!(
"xcrun ld -r -arch arm64 -platform_version macos 11.0 11.0 \
@@ -622,7 +593,7 @@ mod tests {
/// SDL is not built again where it was built with today's flags, and is where with others
#[test]
fn dist_rebuilds_sdl_only_for_other_flags() {
let (root, target, header, firmware) = built("stamp");
let (root, target, header) = built("stamp");
let o = parse_args(&[], &target).unwrap();
let stamp = target.join("dist-localized/sdl-cflags-release");
let cleans = |tools: &Programs| {
@@ -635,11 +606,11 @@ mod tests {
};
put(&stamp, &sdl_cflags());
let mut tools = Programs::new(LOCALIZED_ARCHIVE);
dist(&mut tools, &o, &target, &header, &firmware).unwrap();
dist(&mut tools, &o, &target, &header).unwrap();
assert_eq!(cleans(&tools), 0);
put(&stamp, "-DSDL3Window=OtherSDL3Window");
let mut tools = Programs::new(LOCALIZED_ARCHIVE);
dist(&mut tools, &o, &target, &header, &firmware).unwrap();
dist(&mut tools, &o, &target, &header).unwrap();
assert_eq!(cleans(&tools), 1);
assert_eq!(std::fs::read_to_string(&stamp).unwrap(), sdl_cflags());
std::fs::remove_dir_all(&root).unwrap();
@@ -648,12 +619,12 @@ mod tests {
/// A global the archive still defines besides the C API's fails the dist, naming it
#[test]
fn dist_fails_where_the_archive_keeps_another_global() {
let (root, target, header, firmware) = built("leak");
let (root, target, header) = built("leak");
let o = parse_args(&[], &target).unwrap();
let leaky = "libreims_vgpu.a[reims_vgpu.o]:\n_rvg_graphics_device_create T 1000 20\n\
_SDL_Init T 2000 40\n";
let mut tools = Programs::new(leaky);
let e = dist(&mut tools, &o, &target, &header, &firmware).unwrap_err();
let e = dist(&mut tools, &o, &target, &header).unwrap_err();
assert!(e.contains("1 global symbols besides the C API's"), "{e}");
assert!(e.contains("_SDL_Init"), "{e}");
std::fs::remove_dir_all(&root).unwrap();
@@ -662,7 +633,7 @@ mod tests {
/// A class that keeps an SDL name, static or not, fails the dist, naming it
#[test]
fn dist_fails_where_a_class_keeps_sdls_name() {
let (root, target, header, firmware) = built("class");
let (root, target, header) = built("class");
let o = parse_args(&[], &target).unwrap();
for class in ["SDL3Window", "Cocoa_PasteboardDataProvider", "SDL4Window"] {
let named = format!(
@@ -670,7 +641,7 @@ mod tests {
_OBJC_CLASS_$_{class} s 3000 28\n"
);
let mut tools = Programs::new(&named);
let e = dist(&mut tools, &o, &target, &header, &firmware).unwrap_err();
let e = dist(&mut tools, &o, &target, &header).unwrap_err();
assert!(e.contains("1 Objective-C classes under SDL's names"), "{e}");
assert!(e.contains(class), "{e}");
}
@@ -680,33 +651,11 @@ mod tests {
/// An archive with no `rvg_` function is refused
#[test]
fn dist_refuses_an_archive_without_the_c_api() {
let (root, target, header, firmware) = built("noapi");
let (root, target, header) = built("noapi");
let o = parse_args(&[], &target).unwrap();
let mut tools = Programs::new("libreims_vgpu.a[reims_vgpu.o]:\n_SDL_Init t 2000 40\n");
let e = dist(&mut tools, &o, &target, &header, &firmware).unwrap_err();
let e = dist(&mut tools, &o, &target, &header).unwrap_err();
assert!(e.contains("defines no _rvg_ function"), "{e}");
std::fs::remove_dir_all(&root).unwrap();
}
#[test]
fn dist_stops_before_the_library_when_the_rom_does_not_build() {
let root = tmp("norom");
let target = root.join("target");
put(&target.join("release/libreims_vgpu_c.a"), "archive");
put(&target.join("release/libreims_vgpu_c.dylib"), "dylib");
let header = root.join("reims_vgpu.h");
put(&header, "header");
let o = parse_args(&[], &target).unwrap();
let mut log = Log {
answer: OTOOL.to_owned(),
fail: Some("make"),
..Log::default()
};
let e = dist(&mut log, &o, &target, &header, &root.join("firmware")).unwrap_err();
assert!(e.contains("make failed"), "{e}");
assert!(e.contains("brew install lld"), "{e}");
assert_eq!(log.calls.len(), 1, "{:?}", log.calls);
assert!(!o.out.exists());
std::fs::remove_dir_all(&root).unwrap();
}
}
+1 -1
View File
@@ -36,7 +36,7 @@ const COMMANDS: &[Command] = &[
},
Command {
name: "dist",
about: "the library as a plain library in target/dist: libreims_vgpu.a and .dylib, reims_vgpu.h, reims-vgpu.pc and the option ROM built from firmware/; --profile <p>, --out DIR, --platform vulkan (the proof of concept, in target/dist-vulkan)",
about: "the library as a plain library in target/dist: libreims_vgpu.a and .dylib, reims_vgpu.h and reims-vgpu.pc; --profile <p>, --out DIR, --platform vulkan (the proof of concept, in target/dist-vulkan)",
run: dist::cmd_dist,
},
Command {