diff --git a/README.md b/README.md index 3b1fd59..a3a7787 100644 --- a/README.md +++ b/README.md @@ -85,8 +85,9 @@ What's in the image, and why: has it ask for the one arm64 guests use (245), and patches what the driver and its Metal plugin hardcode, so Metal offers the GPU families GPU-accelerated Chrome needs, and D32S8 depth/stencil textures. `--no-kexts` leaves them out, and the boot argument `-reimsvgpuoff` - turns the kext off. The apv-arm64-port kexts load after these, on macOS 26.4 and later - ([below](#apv-arm64-port)). There are no others: QEMU's `isa-applesmc` is the SMC. + turns the kext off. The apv-arm64-port kexts load after these, on macOS 26.4 and later, and + reims-vgpu-video's after those, on macOS 26.7 ([below](#the-kexts)). There are no others: + QEMU's `isa-applesmc` is the SMC. - **The drivers a VM boots with**: OpenRuntime, OpenHfsPlus (recovery images and installers are HFS+), OpenPartitionDxe (for older recovery images) and ResetNvramEntry. - **No boot picker**: OpenCore boots the default entry, the disk macOS last chose as its startup @@ -176,12 +177,28 @@ made) or, for `list`, the versions, or `{"event":"error","message":"…"}`. reims-util --json online-installer tahoe -o ~/vms/mac ``` -## The ReimsVgpu kext +## The kexts -`kext/` holds ReimsVgpu.kext's source. A kext builds on a Mac alone, while reims-util builds -anywhere, so the built kext is in the repository too, at `kext/ReimsVgpu.kext`, and that's the one -reims-util puts in its images. After changing the source, rebuild it on a Mac with Xcode, and -commit it with the change: +`kext/` holds the kexts reims-util puts in its images, built: a kext builds on a Mac alone, while +reims-util builds anywhere. Every image carries them by default, each set after the one before it: + +- **ReimsVgpu.kext**, with Lilu, on macOS 26 ([above](#opencore-and-ovmf)), built from its + source in `kext/`. +- **The apv-arm64-port kexts**, on macOS 26.4 and later, which drive reims-vgpu's GPU with kexts + of their own; older macOS 26 builds keep macOS's own driver with ReimsVgpu.kext. + `--no-apv-arm64-port` makes an image without them. +- **reims-vgpu-video's kexts**, on macOS 26.7, which drive the paravirtualized VideoToolbox + (106b:1a03) and M2 scaler (106b:1a0b) devices, when the VM's QEMU serves them: + AppleVideoToolboxParavirtualization.kext and AppleM2ScalerParavirtDriver.kext, Apple's arm64 + guest drivers ported to x86-64, and VtWaitPatch.kext, a Lilu plugin that keeps the x86-64 + VideoToolbox's waits for the host's replies from expiring at once on macOS 26.7.1 (25G241). The + two drivers link against apv-arm64-port's IOSurface mapper, so an image carries them only with + the apv-arm64-port kexts, from Darwin 25.6.0 on; a driver whose device the VM lacks loads and + matches nothing. `--no-video` makes an image without them. The two drivers are Apple's code, + ported, and are not for redistribution. + +After changing ReimsVgpu.kext's source, rebuild it on a Mac with Xcode, and commit the built kext +with the change: ```sh cd kext @@ -194,12 +211,6 @@ make LILU=path/to/Lilu.kext KERNEL_SDK=path/to/MacKernelSDK source builds the same bytes. `make` also writes `kext/sources.sha256`, what the kext was built from, and `cargo test` fails when the source no longer matches it. -## apv-arm64-port - -apv-arm64-port drives reims-vgpu's GPU on macOS 26.4 and later with kexts of its own, which every -image carries by default; older macOS 26 builds keep macOS's own driver with ReimsVgpu.kext. -`--no-apv-arm64-port` makes an image without them. - ## License reims-util is licensed under GPL-2.0-or-later OR LGPL-3.0-or-later; see [LICENSE](LICENSE). The diff --git a/build.rs b/build.rs index 9cf0066..dcf6b3c 100644 --- a/build.rs +++ b/build.rs @@ -1,8 +1,10 @@ //! Embeds the apv-arm64-port kexts, the seven bundles in kext/ that `SET` names, so the image -//! carries them as it carries ReimsVgpu.kext (src/opencore/apv_arm64_port.rs). Writes -//! `$OUT_DIR/apv_arm64_port.rs`: each file of each of them, by its path under kext/, with its -//! bytes, dotfiles left out. Nothing else in kext/ is read. With none of the seven there, nothing -//! is embedded; with only some, the build fails, as the seven load as one. +//! carries them as it carries ReimsVgpu.kext (src/opencore/apv_arm64_port.rs), and +//! reims-vgpu-video's kexts, the three that `VIDEO_SET` names, the same way +//! (src/opencore/video.rs). Writes `$OUT_DIR/apv_arm64_port.rs` and `$OUT_DIR/video.rs`: each +//! file of each bundle of the set, by its path under kext/, with its bytes, dotfiles left out. +//! Nothing else in kext/ is read. With none of a set there, nothing of it is embedded; with only +//! some, the build fails, as each set loads as one. //! //! The bundles are built without a path of the machine they were built on: the build fails when //! an embedded file holds `/Users/`, as an unstripped kext's debug map does. @@ -11,6 +13,7 @@ use std::fmt::Write as _; use std::path::{Path, PathBuf}; include!("src/opencore/apv_arm64_port_set.rs"); +include!("src/opencore/video_set.rs"); fn main() { if let Err(e) = run() { @@ -24,33 +27,53 @@ fn run() -> Result<(), String> { let dir = root.join("kext"); println!("cargo:rerun-if-changed=build.rs"); println!("cargo:rerun-if-changed=src/opencore/apv_arm64_port_set.rs"); + println!("cargo:rerun-if-changed=src/opencore/video_set.rs"); println!("cargo:rerun-if-changed=kext"); + let out = PathBuf::from(std::env::var("OUT_DIR").map_err(|e| e.to_string())?); + embed( + &dir, + &SET, + "apv-arm64-port", + "all seven", + &out.join("apv_arm64_port.rs"), + )?; + embed( + &dir, + &VIDEO_SET, + "video", + "all three", + &out.join("video.rs"), + ) +} - let present: Vec<&str> = SET +/// Writes `to`, the files of the bundles `set` names in `dir`: all of them or none, `what` naming +/// them in errors, and `whole` how many make the set. +fn embed(dir: &Path, set: &[&str], what: &str, whole: &str, to: &Path) -> Result<(), String> { + let present: Vec<&str> = set .iter() .copied() .filter(|b| dir.join(b).exists()) .collect(); - if !present.is_empty() && present.len() != SET.len() { - let missing: Vec<&str> = SET + if !present.is_empty() && present.len() != set.len() { + let missing: Vec<&str> = set .iter() .copied() .filter(|b| !present.contains(b)) .collect(); return Err(format!( - "partial apv-arm64-port set in kext/, without {}: deploy all seven", + "partial {what} set in kext/, without {}: deploy {whole}", missing.join(", ") )); } let mut files = Vec::new(); for b in &present { - walk(&dir, Path::new(b), &mut files)?; + walk(dir, Path::new(b), &mut files)?; } files.sort(); - let mut code = String::from( - "/// Each file of the apv-arm64-port kexts, by its path under kext/ (build.rs).\n\ - pub static FILES: &[(&str, &[u8])] = &[\n", + let mut code = format!( + "/// Each file of the {what} kexts, by its path under kext/ (build.rs).\n\ + pub static FILES: &[(&str, &[u8])] = &[\n" ); for f in &files { let path = dir.join(f); @@ -68,9 +91,7 @@ fn run() -> Result<(), String> { let _ = writeln!(code, " ({f:?}, include_bytes!({abs:?})),"); } code.push_str("];\n"); - let out = PathBuf::from(std::env::var("OUT_DIR").map_err(|e| e.to_string())?); - std::fs::write(out.join("apv_arm64_port.rs"), code) - .map_err(|e| format!("write apv_arm64_port.rs: {e}")) + std::fs::write(to, code).map_err(|e| format!("write {}: {e}", to.display())) } fn read_dir(dir: &Path) -> Result, String> { diff --git a/kext/AppleM2ScalerParavirtDriver.kext/Contents/Info.plist b/kext/AppleM2ScalerParavirtDriver.kext/Contents/Info.plist new file mode 100644 index 0000000..df23915 --- /dev/null +++ b/kext/AppleM2ScalerParavirtDriver.kext/Contents/Info.plist @@ -0,0 +1,102 @@ + + + + + BuildMachineOSBuild + 23A344017 + CFBundleDevelopmentRegion + English + CFBundleExecutable + AppleM2ScalerParavirtDriver + CFBundleGetInfoString + 9.0.5, Copyright Apple Inc. 2023 + CFBundleIdentifier + com.apple.driver.AppleM2ScalerParavirtDriver + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + Apple M2 Scaler Paravirtualized Driver + CFBundlePackageType + KEXT + CFBundleShortVersionString + 1.0.0 + CFBundleSignature + aapl + CFBundleSupportedPlatforms + + MacOSX + + CFBundleVersion + 1.0.0 + DTCompiler + com.apple.compilers.llvm.clang.1_0 + DTPlatformBuild + + DTPlatformName + macosx + DTPlatformVersion + 26.7 + DTSDKBuild + 25G221 + DTSDKName + macosx26.7.internal + DTXcode + 2630 + DTXcodeBuild + 17E6107 + IOKitPersonalities + + AppleM2ScalerParavirtDriver + + CFBundleIdentifier + com.apple.driver.AppleM2ScalerParavirtDriver + IOClass + AppleM2ScalerCSCDriver + IOProviderClass + AppleVirtIOTransport + IOVirtIOPrimaryMatch + 0x1a0b106b + + AppleM2ScalerParavirtDriver Transport + + CFBundleIdentifier + com.apple.driver.AppleVirtIO + IOClass + AppleVirtIOPCITransport + IOPCIPrimaryMatch + 0x1a0b106b + IOProviderClass + IOPCIDevice + + + LSMinimumSystemVersion + 26.7 + NSHumanReadableCopyright + Copyright © 2023 Apple Inc. All rights reserved. + OSBundleCompatibleVersion + 1.0 + OSBundleLibraries + + com.apple.driver.AppleVirtIO + 146.40.2 + com.apple.iokit.AppleParavirtIOSurface + 1.0 + com.apple.iokit.IOPCIFamily + 1.0.0b1 + com.apple.iokit.IOSurface + 52.7.0 + com.apple.kpi.bsd + 8.4.1 + com.apple.kpi.iokit + 8.4.1 + com.apple.kpi.libkern + 8.4.1 + com.apple.kpi.mach + 8.4.1 + com.apple.kpi.private + 8.0.0b1 + com.apple.kpi.unsupported + 8.0 + + + diff --git a/kext/AppleM2ScalerParavirtDriver.kext/Contents/MacOS/AppleM2ScalerParavirtDriver b/kext/AppleM2ScalerParavirtDriver.kext/Contents/MacOS/AppleM2ScalerParavirtDriver new file mode 100644 index 0000000..7766061 Binary files /dev/null and b/kext/AppleM2ScalerParavirtDriver.kext/Contents/MacOS/AppleM2ScalerParavirtDriver differ diff --git a/kext/AppleVideoToolboxParavirtualization.kext/Contents/Info.plist b/kext/AppleVideoToolboxParavirtualization.kext/Contents/Info.plist new file mode 100644 index 0000000..62f879f --- /dev/null +++ b/kext/AppleVideoToolboxParavirtualization.kext/Contents/Info.plist @@ -0,0 +1,88 @@ + + + + + BuildMachineOSBuild + 23A344017 + CFBundleDevelopmentRegion + en + CFBundleExecutable + AppleVideoToolboxParavirtualization + CFBundleIdentifier + com.apple.driver.AppleVideoToolboxParavirtualization + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + com.apple.driver.AppleVideoToolboxParavirtualization + CFBundlePackageType + KEXT + CFBundleShortVersionString + 15.0.0 + CFBundleSupportedPlatforms + + MacOSX + + CFBundleVersion + 15.0.0 + DTCompiler + com.apple.compilers.llvm.clang.1_0 + DTPlatformBuild + + DTPlatformName + macosx + DTPlatformVersion + 26.7 + DTSDKBuild + 25G221 + DTSDKName + macosx26.7.internal + DTXcode + 2630 + DTXcodeBuild + 17E6107 + IOKitPersonalities + + AppleVideoToolboxParavirtualization + + CFBundleIdentifier + com.apple.driver.AppleVideoToolboxParavirtualization + IOClass + AppleVideoToolboxParavirtualizationDriver + IOProviderClass + AppleVirtIOTransport + IOUserClientClass + AppleVideoToolboxParavirtualizationUserClient + IOVirtIOPrimaryMatch + 0x1a03106b + + AppleVideoToolboxParavirtualization Transport + + CFBundleIdentifier + com.apple.driver.AppleVirtIO + IOClass + AppleVirtIOPCITransport + IOPCIPrimaryMatch + 0x1a03106b + IOProviderClass + IOPCIDevice + + + LSMinimumSystemVersion + 26.7 + NSHumanReadableCopyright + Copyright © 2022-2025 Apple Inc. All rights reserved. + OSBundleLibraries + + com.apple.driver.AppleVirtIO + 146.40.2 + com.apple.iokit.AppleParavirtIOSurface + 1.0 + com.apple.iokit.IOSurface + 302.9 + com.apple.kpi.iokit + 15.5 + com.apple.kpi.libkern + 15.5 + + + diff --git a/kext/AppleVideoToolboxParavirtualization.kext/Contents/MacOS/AppleVideoToolboxParavirtualization b/kext/AppleVideoToolboxParavirtualization.kext/Contents/MacOS/AppleVideoToolboxParavirtualization new file mode 100644 index 0000000..be1f350 Binary files /dev/null and b/kext/AppleVideoToolboxParavirtualization.kext/Contents/MacOS/AppleVideoToolboxParavirtualization differ diff --git a/kext/VtWaitPatch.kext/Contents/Info.plist b/kext/VtWaitPatch.kext/Contents/Info.plist new file mode 100644 index 0000000..853f4a5 --- /dev/null +++ b/kext/VtWaitPatch.kext/Contents/Info.plist @@ -0,0 +1,53 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + VtWaitPatch + CFBundleIdentifier + com.steelbrain.VtWaitPatch + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + VtWaitPatch + CFBundlePackageType + KEXT + CFBundleShortVersionString + 0.1.0 + CFBundleVersion + 0.1.0 + IOKitPersonalities + + VtWaitPatch + + CFBundleIdentifier + com.steelbrain.VtWaitPatch + IOClass + VtWaitPatch + IOMatchCategory + VtWaitPatch + IOProviderClass + IOResources + IOResourceMatch + IOKit + + + OSBundleLibraries + + as.vit9696.Lilu + 1.7.2 + com.apple.kpi.bsd + 12.0.0 + com.apple.kpi.iokit + 12.0.0 + com.apple.kpi.libkern + 12.0.0 + com.apple.kpi.mach + 12.0.0 + + OSBundleRequired + Root + + diff --git a/kext/VtWaitPatch.kext/Contents/MacOS/VtWaitPatch b/kext/VtWaitPatch.kext/Contents/MacOS/VtWaitPatch new file mode 100755 index 0000000..6428d57 Binary files /dev/null and b/kext/VtWaitPatch.kext/Contents/MacOS/VtWaitPatch differ diff --git a/src/cli.rs b/src/cli.rs index 9d891f2..efe2259 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -108,13 +108,17 @@ pub struct OpencoreArgs { /// Show OpenCore's boot picker at every boot (by default OpenCore boots the default entry) #[arg(long)] pub show_picker: bool, - /// Leave out Lilu, ReimsVgpu.kext and the apv-arm64-port kexts, so macOS 26 drives - /// reims-vgpu's GPU with its driver as it is + /// Leave out Lilu, ReimsVgpu.kext, the apv-arm64-port kexts and reims-vgpu-video's, so + /// macOS 26 drives reims-vgpu's GPU with its driver as it is #[arg(long)] pub no_kexts: bool, - /// Leave out the apv-arm64-port kexts + /// Leave out the apv-arm64-port kexts, and with them reims-vgpu-video's, which link against + /// their mapper #[arg(long)] pub no_apv_arm64_port: bool, + /// Leave out reims-vgpu-video's kexts, the VideoToolbox and scaler devices' guest drivers + #[arg(long)] + pub no_video: bool, /// Write no OVMF files #[arg(long)] pub no_ovmf: bool, @@ -353,6 +357,7 @@ pub fn opencore_options(a: &OpencoreArgs) -> Result { kexts: !a.no_kexts, }, apv_arm64_port: !a.no_apv_arm64_port, + video: !a.no_video, ovmf_dir, }) } diff --git a/src/opencore/apv_arm64_port.rs b/src/opencore/apv_arm64_port.rs index e4035ce..c43c218 100644 --- a/src/opencore/apv_arm64_port.rs +++ b/src/opencore/apv_arm64_port.rs @@ -26,6 +26,17 @@ pub struct Kext<'a> { /// after those of the set its `OSBundleLibraries` names. Empty when `files` holds no kext; files /// beside the bundles are left out, and anything short of the exact set refused. pub fn set<'a>(files: &[(&'a str, &'a [u8])]) -> Result>> { + set_of(files, &SET, "apv-arm64-port", "all seven") +} + +/// The kexts `names` in `files`, taken as `set` takes apv-arm64-port's: `what` names them in its +/// errors, and `whole` says how many make the set. video.rs takes reims-vgpu-video's kexts so. +pub(super) fn set_of<'a>( + files: &[(&'a str, &'a [u8])], + names: &[&str], + what: &str, + whole: &str, +) -> Result>> { let mut bundles: BTreeMap<&str, Vec<(&str, &[u8])>> = BTreeMap::new(); for &(path, data) in files { let Some((bundle, rel)) = path.split_once('/') else { @@ -34,10 +45,10 @@ pub fn set<'a>(files: &[(&'a str, &'a [u8])]) -> Result>> { if !bundle.ends_with(".kext") || path.split('/').any(|c| c.starts_with('.')) { continue; } - if !SET.contains(&bundle) { + if !names.contains(&bundle) { bail!( - "kext/{bundle} is not one of the apv-arm64-port kexts ({})", - SET.join(", ") + "kext/{bundle} is not one of the {what} kexts ({})", + names.join(", ") ); } bundles.entry(bundle).or_default().push((rel, data)); @@ -45,14 +56,14 @@ pub fn set<'a>(files: &[(&'a str, &'a [u8])]) -> Result>> { if bundles.is_empty() { return Ok(Vec::new()); } - let missing: Vec<&str> = SET + let missing: Vec<&str> = names .iter() .copied() .filter(|b| !bundles.contains_key(b)) .collect(); if !missing.is_empty() { bail!( - "partial apv-arm64-port set in kext/, without {}: deploy all seven", + "partial {what} set in kext/, without {}: deploy {whole}", missing.join(", ") ); } @@ -60,7 +71,7 @@ pub fn set<'a>(files: &[(&'a str, &'a [u8])]) -> Result>> { for (bundle, files) in bundles { kexts.push(kext(bundle, files)?); } - order(kexts) + order(kexts, what) } fn kext<'a>(bundle: &'a str, files: Vec<(&'a str, &'a [u8])>) -> Result> { @@ -96,7 +107,7 @@ fn kext<'a>(bundle: &'a str, files: Vec<(&'a str, &'a [u8])>) -> Result } /// Orders the kexts so each comes after the ones it links against, and otherwise by name. -fn order(mut left: Vec>) -> Result>> { +fn order<'a>(mut left: Vec>, what: &str) -> Result>> { let ids: BTreeSet = left.iter().map(|k| k.identifier.clone()).collect(); let mut placed = BTreeSet::new(); let mut out = Vec::new(); @@ -109,7 +120,7 @@ fn order(mut left: Vec>) -> Result>> { let Some(i) = ready else { let names: Vec<&str> = left.iter().map(|k| k.bundle).collect(); bail!( - "the apv-arm64-port kexts {} link against each other in a cycle", + "the {what} kexts {} link against each other in a cycle", names.join(", ") ); }; @@ -125,7 +136,7 @@ pub(crate) mod tests { use super::*; /// A bundle's Info.plist: its identifier, executable and libraries. - fn info(id: &str, executable: Option<&str>, libraries: &[&str]) -> Vec { + pub(crate) fn info(id: &str, executable: Option<&str>, libraries: &[&str]) -> Vec { let mut d = plist::Dictionary::new(); d.insert("CFBundleIdentifier".into(), id.into()); if let Some(e) = executable { diff --git a/src/opencore/config.rs b/src/opencore/config.rs index 6a5dfc6..1ae9353 100644 --- a/src/opencore/config.rs +++ b/src/opencore/config.rs @@ -14,8 +14,8 @@ //! - on macOS 26, two kexts: Lilu, and its plugin ReimsVgpu (kext/), which has macOS's own driver //! for reims-vgpu's GPU negotiate the interface version arm64 guests use, and patches what the //! x86-64 driver and its Metal plugin hardcode; after them, the seven apv-arm64-port kexts -//! (apv_arm64_port.rs), on macOS 26.4 and later alone; no others, as QEMU's `isa-applesmc` is -//! the SMC; +//! (apv_arm64_port.rs), on macOS 26.4 and later alone; after those, reims-vgpu-video's three +//! (video.rs), on macOS 26.7 alone; no others, as QEMU's `isa-applesmc` is the SMC; //! - one ACPI table, the `EC` and `USBX` devices macOS looks for (acpi.rs); //! - CPUID leaf 1 reported as a Skylake-SP (family 6, model 85, stepping 4), a CPU every x86-64 //! macOS from 10.13 to 26 knows, whatever `-cpu` model the VM has; @@ -72,6 +72,10 @@ const KEXT_MAX_KERNEL: &str = "25.99.99"; /// The apv-arm64-port kexts load from macOS 26.4 on: on older builds, ReimsVgpu has macOS's own /// driver take the GPU. Where the set refuses at boot, it leaves the GPU to that driver too. const PORT_MIN_KERNEL: &str = "25.4.0"; +/// reims-vgpu-video's kexts load on macOS 26.7 (Darwin 25.6) alone, the release whose kernel +/// collections their links were checked against (its docs/kext-port.md), within the +/// apv-arm64-port kexts' bounds, as two of them link against its mapper. +const VIDEO_MIN_KERNEL: &str = "25.6.0"; /// Arguments for every boot: kernel symbols in panic logs, and no panics on a TLB shootdown or a /// timeout a vCPU took because the host descheduled it. @@ -100,8 +104,13 @@ pub struct Options { } /// The config.plist for `o`, from the release's `sample`. With `o.kexts`, `port` -/// (apv_arm64_port.rs) loads after Lilu and ReimsVgpu. -pub fn make(sample: &[u8], o: &Options, port: &[PortKext<'_>]) -> Result> { +/// (apv_arm64_port.rs) loads after Lilu and ReimsVgpu, and `video` (video.rs) after `port`. +pub fn make( + sample: &[u8], + o: &Options, + port: &[PortKext<'_>], + video: &[PortKext<'_>], +) -> Result> { let mut root: Value = plist::from_bytes(sample).context("read Sample.plist")?; let c = root .as_dictionary_mut() @@ -146,7 +155,7 @@ pub fn make(sample: &[u8], o: &Options, port: &[PortKext<'_>]) -> Result )?; let kexts = if o.kexts { - kernel_add(&template(c, &["Kernel", "Add"])?, port) + kernel_add(&template(c, &["Kernel", "Add"])?, port, video) } else { Vec::new() }; @@ -312,8 +321,8 @@ pub fn make(sample: &[u8], o: &Options, port: &[PortKext<'_>]) -> Result } /// Kernel > Add's entries, made from the sample's first: Lilu and ReimsVgpu for macOS 26, then -/// `port` for macOS 26.4 and later. -fn kernel_add(template: &Dictionary, port: &[PortKext<'_>]) -> Vec { +/// `port` for macOS 26.4 and later, then `video` for macOS 26.7. +fn kernel_add(template: &Dictionary, port: &[PortKext<'_>], video: &[PortKext<'_>]) -> Vec { let mut add = vec![ ( LILU.bundle, @@ -336,6 +345,14 @@ fn kernel_add(template: &Dictionary, port: &[PortKext<'_>]) -> Vec { format!("apv-arm64-port's {}", k.bundle.trim_end_matches(".kext")), )); } + for k in video { + add.push(( + k.bundle, + k.executable.as_deref(), + VIDEO_MIN_KERNEL, + format!("reims-vgpu-video's {}", k.bundle.trim_end_matches(".kext")), + )); + } add.into_iter() .map(|(bundle, executable, min_kernel, comment)| { let mut e = template.clone(); @@ -402,6 +419,7 @@ fn unhex(s: &str) -> Result> { mod tests { use super::*; use crate::opencore::apv_arm64_port as port; + use crate::opencore::video; fn fields(v: &Value, keys: &[&str]) -> Vec { let d = v.as_dictionary().unwrap(); @@ -424,7 +442,7 @@ mod tests { ]; // With none of the set in kext/, Lilu and ReimsVgpu alone. - let today = kernel_add(&template, &port::set(&[]).unwrap()); + let today = kernel_add(&template, &port::set(&[]).unwrap(), &[]); let want = |b: &str, x: &str| { [b, x, KEXT_MIN_KERNEL, KEXT_MAX_KERNEL, "x86_64"].map(str::to_string) }; @@ -440,7 +458,7 @@ mod tests { // no path. let files = port::tests::fixture(); let set = port::set(&port::tests::refs(&files)).unwrap(); - let all = kernel_add(&template, &set); + let all = kernel_add(&template, &set, &[]); assert_eq!(all.len(), 9); assert_eq!(all[..2], today[..]); for (e, k) in all[2..].iter().zip(&set) { @@ -452,5 +470,22 @@ mod tests { assert!(fields(e, &["Comment"])[0].starts_with("apv-arm64-port's ")); } assert!(all.iter().any(|e| fields(e, &keys)[1].is_empty())); + + // With reims-vgpu-video's kexts too, they follow the set in their order, from macOS 26.7. + let video_files = video::tests::fixture(); + let video_set = video::set(&port::tests::refs(&video_files)).unwrap(); + let with_video = kernel_add(&template, &set, &video_set); + assert_eq!(with_video.len(), 12); + assert_eq!(with_video[..9], all[..]); + for (e, k) in with_video[9..].iter().zip(&video_set) { + let f = fields(e, &keys); + assert_eq!(f[0], k.bundle); + assert_eq!( + f[1], + format!("Contents/MacOS/{}", k.bundle.trim_end_matches(".kext")) + ); + assert_eq!(f[2..], [VIDEO_MIN_KERNEL, KEXT_MAX_KERNEL, "x86_64"]); + assert!(fields(e, &["Comment"])[0].starts_with("reims-vgpu-video's ")); + } } } diff --git a/src/opencore/mod.rs b/src/opencore/mod.rs index 49b4cd5..2128eed 100644 --- a/src/opencore/mod.rs +++ b/src/opencore/mod.rs @@ -1,14 +1,15 @@ //! The OpenCore boot image: a 128 MiB GPT disk whose EFI system partition holds a pinned //! OpenCore release, the drivers and ACPI table a VM needs, the picker's icons and the boot chime //! from a pinned commit of OcBinaryData, a pinned Lilu release and its plugin ReimsVgpu.kext -//! (kext/), the apv-arm64-port kexts (apv_arm64_port.rs), and a `config.plist` made for a q35 VM -//! (config.rs) with an SMBIOS identity of its own (smbios.rs). OVMF goes beside it (ovmf.rs), -//! where reims-ctl looks for it. +//! (kext/), the apv-arm64-port kexts (apv_arm64_port.rs), reims-vgpu-video's kexts (video.rs), +//! and a `config.plist` made for a q35 VM (config.rs) with an SMBIOS identity of its own +//! (smbios.rs). OVMF goes beside it (ovmf.rs), where reims-ctl looks for it. pub mod acpi; pub mod apv_arm64_port; pub mod config; pub mod smbios; +pub mod video; use crate::cache::{self, Pinned}; use crate::image::{self, Data, Format}; @@ -62,6 +63,9 @@ pub struct Options { pub config: config::Options, /// The apv-arm64-port kexts too, when kext/ holds them; with `config.kexts` alone. pub apv_arm64_port: bool, + /// reims-vgpu-video's kexts too, when kext/ holds them; with the apv-arm64-port kexts alone, + /// whose IOSurface mapper they link against. + pub video: bool, /// Where OVMF's files go, or None to write none. pub ovmf_dir: Option, } @@ -74,6 +78,8 @@ pub struct Outputs { pub smbios: smbios::Smbios, /// Whether the image carries the apv-arm64-port kexts. pub apv_arm64_port: bool, + /// Whether the image carries reims-vgpu-video's kexts. + pub video: bool, pub ovmf: Option, } @@ -87,6 +93,11 @@ pub fn build(o: &Options, r: &dyn Reporter) -> Result { } else { Vec::new() }; + let video = if !port.is_empty() && o.video { + video::set(video::FILES)? + } else { + Vec::new() + }; let lilu_path = if o.config.kexts { let p = cache::fetch(&LILU_RELEASE, r)?; progress::check(r)?; @@ -95,12 +106,12 @@ pub fn build(o: &Options, r: &dyn Reporter) -> Result { None }; r.step(&format!("Building the OpenCore {VERSION} image")); - let mut files = files(&zip_path, &o.config, &port)?; + let mut files = files(&zip_path, &o.config, &port, &video)?; files.extend(resources(&resources_path, o.config.graphical_picker)?); if let Some(p) = &lilu_path { files.extend(kexts(p)?); } - for k in &port { + for k in port.iter().chain(&video) { for (p, d) in &k.files { files.push((format!("EFI/OC/Kexts/{}/{p}", k.bundle), d.to_vec())); } @@ -132,6 +143,7 @@ pub fn build(o: &Options, r: &dyn Reporter) -> Result { opencore: VERSION, smbios: o.config.smbios.clone(), apv_arm64_port: !port.is_empty(), + video: !video.is_empty(), ovmf, }) } @@ -141,6 +153,7 @@ fn files( zip_path: &Path, c: &config::Options, port: &[apv_arm64_port::Kext<'_>], + video: &[apv_arm64_port::Kext<'_>], ) -> Result)>> { let f = std::fs::File::open(zip_path).with_context(|| format!("open {}", zip_path.display()))?; @@ -173,7 +186,7 @@ fn files( let sample = read("Docs/Sample.plist")?; files.push(( "EFI/OC/config.plist".into(), - config::make(&sample, c, port)?, + config::make(&sample, c, port, video)?, )); files.push(( format!("EFI/OC/ACPI/{}", acpi::FILE_NAME), diff --git a/src/opencore/video.rs b/src/opencore/video.rs new file mode 100644 index 0000000..48436e5 --- /dev/null +++ b/src/opencore/video.rs @@ -0,0 +1,107 @@ +//! reims-vgpu-video's kexts: three bundles, which load as one, after the apv-arm64-port kexts, on +//! macOS 26.7 (Darwin 25.6) alone. kext/ holds them as built, under their own names: the +//! reims-vgpu-video project builds them (its docs/kext-port.md), and build.rs embeds them. +//! - AppleVideoToolboxParavirtualization.kext, the guest driver of the paravirtualized +//! VideoToolbox device (106b:1a03), Apple's arm64 kext ported to x86-64; +//! - AppleM2ScalerParavirtDriver.kext, the M2 scaler device's (106b:1a0b), ported the same way; +//! - VtWaitPatch.kext, a Lilu plugin of reims-vgpu-video's own, which patches the x86-64 guest's +//! VideoToolbox so that its 10 s waits for the host's replies do not expire at once. It patches +//! macOS 26.7.1 (25G241) alone, and leaves any other build as it is. +//! +//! The two drivers link against apv-arm64-port's IOSurface mapper, so an image carries them only +//! with the apv-arm64-port kexts, and only where kext/ holds them; `--no-video` makes one without +//! them. A driver whose device the VM lacks loads and matches nothing. + +use super::apv_arm64_port::{Kext, set_of}; +use anyhow::Result; + +include!(concat!(env!("OUT_DIR"), "/video.rs")); + +include!("video_set.rs"); + +/// The video kexts in `files` (each by its path under kext/), in the order OpenCore loads them. +/// Empty when `files` holds none of them; anything short of the three refused. +pub fn set<'a>(files: &[(&'a str, &'a [u8])]) -> Result>> { + set_of(files, &VIDEO_SET, "video", "all three") +} + +#[cfg(test)] +pub(crate) mod tests { + use super::*; + use crate::opencore::apv_arm64_port::tests::{info, refs}; + + /// The three, linked as they are: the drivers against the mapper and Apple's families, the + /// plugin against Lilu, none against each other. + pub(crate) fn fixture() -> Vec<(String, Vec)> { + let mapper = "com.apple.iokit.AppleParavirtIOSurface"; + let kexts: [(&str, &str, &[&str]); 3] = [ + ( + "AppleVideoToolboxParavirtualization", + "com.apple.driver.AppleVideoToolboxParavirtualization", + &[mapper, "com.apple.driver.AppleVirtIO"], + ), + ( + "AppleM2ScalerParavirtDriver", + "com.apple.driver.AppleM2ScalerParavirtDriver", + &[mapper, "com.apple.iokit.IOPCIFamily"], + ), + ("VtWaitPatch", "t.vtwait", &["as.vit9696.Lilu"]), + ]; + let mut files = Vec::new(); + for (name, id, libraries) in kexts { + files.push(( + format!("{name}.kext/Contents/Info.plist"), + info(id, Some(name), libraries), + )); + files.push((format!("{name}.kext/Contents/MacOS/{name}"), vec![0xcf])); + } + files + } + + #[test] + fn ordered_by_name() { + let files = fixture(); + let kexts = set(&refs(&files)).unwrap(); + let bundles: Vec<&str> = kexts.iter().map(|k| k.bundle).collect(); + assert_eq!( + bundles, + [ + "AppleM2ScalerParavirtDriver.kext", + "AppleVideoToolboxParavirtualization.kext", + "VtWaitPatch.kext", + ] + ); + for k in &kexts { + assert_eq!( + k.executable.as_deref(), + Some(k.bundle.trim_end_matches(".kext")) + ); + } + } + + #[test] + fn part_of_the_set_refused() { + let mut files = fixture(); + files.retain(|(p, _)| !p.starts_with("VtWaitPatch.kext/")); + let e = set(&refs(&files)).unwrap_err().to_string(); + assert!(e.contains("without VtWaitPatch.kext"), "{e}"); + } + + #[test] + fn other_kexts_refused() { + let mut files = fixture(); + files.push(( + "AppleParavirtIOSurface.kext/Contents/Info.plist".into(), + info("x", None, &[]), + )); + let e = set(&refs(&files)).unwrap_err().to_string(); + assert!(e.contains("not one of the video kexts"), "{e}"); + } + + /// What kext/ holds of the three is the whole of it, or nothing. + #[test] + fn embedded_set_whole() { + let kexts = set(FILES).unwrap(); + assert!(kexts.is_empty() || kexts.len() == VIDEO_SET.len()); + } +} diff --git a/src/opencore/video_set.rs b/src/opencore/video_set.rs new file mode 100644 index 0000000..574b98a --- /dev/null +++ b/src/opencore/video_set.rs @@ -0,0 +1,8 @@ +/// reims-vgpu-video's three bundles, in kext/ under their own names, which load as one: the +/// VideoToolbox and scaler devices' guest drivers, and the Lilu plugin their x86-64 guests need. +/// build.rs and video.rs both include this list. +pub const VIDEO_SET: [&str; 3] = [ + "AppleVideoToolboxParavirtualization.kext", + "AppleM2ScalerParavirtDriver.kext", + "VtWaitPatch.kext", +]; diff --git a/src/tui.rs b/src/tui.rs index de127fd..3e1861a 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -274,6 +274,7 @@ impl App { show_picker: form.toggle(8), no_kexts: false, no_apv_arm64_port: false, + no_video: false, no_ovmf: !form.toggle(3), ovmf_dir: None, };