Skip to content

Commit

Permalink
Add host startup options support to Grapefruit (#1984)
Browse files Browse the repository at this point in the history
This is part of #1983
  • Loading branch information
mkeeter authored Jan 21, 2025
1 parent 1c9803c commit 6b8a7f8
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/grapefruit/app.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ max-sizes = {flash = 8192, ram = 2048}
start = true
# task-slots is explicitly empty: packrat should not send IPCs!
task-slots = []
features = ["grapefruit", "boot-kmdb"]

[tasks.hiffy]
name = "task-hiffy"
Expand Down
1 change: 1 addition & 0 deletions task/packrat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ build-util = { path = "../../build/util" }

[features]
gimlet = ["drv-cpu-seq-api"]
grapefruit = []
boot-kmdb = []
no-ipc-counters = ["idol/no-counters"]

Expand Down
46 changes: 46 additions & 0 deletions task/packrat/src/grapefruit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

//! Grapefruit-specific packrat data.
use task_packrat_api::HostStartupOptions;

pub(crate) struct GrapefruitData {
host_startup_options: HostStartupOptions,
}

const fn default_host_startup_options() -> HostStartupOptions {
if cfg!(feature = "boot-kmdb") {
// We have to do this because const fn.
let bits = HostStartupOptions::STARTUP_KMDB.bits()
| HostStartupOptions::STARTUP_PROM.bits()
| HostStartupOptions::STARTUP_VERBOSE.bits()
| HostStartupOptions::STARTUP_BOOT_RAMDISK.bits();
match HostStartupOptions::from_bits(bits) {
Some(options) => options,
None => panic!("must be valid at compile-time"),
}
} else {
HostStartupOptions::empty()
}
}

impl GrapefruitData {
pub(crate) fn new() -> Self {
Self {
host_startup_options: default_host_startup_options(),
}
}

pub(crate) fn host_startup_options(&self) -> HostStartupOptions {
self.host_startup_options
}

pub(crate) fn set_host_startup_options(
&mut self,
options: HostStartupOptions,
) {
self.host_startup_options = options;
}
}
33 changes: 31 additions & 2 deletions task/packrat/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ use userlib::RecvMessage;
#[cfg(feature = "gimlet")]
mod gimlet;

#[cfg(feature = "grapefruit")]
mod grapefruit;

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[allow(dead_code)] // not all variants are used, depending on cargo features
enum Trace {
Expand Down Expand Up @@ -111,6 +114,8 @@ fn main() -> ! {
identity,
#[cfg(feature = "gimlet")]
gimlet_data: gimlet::GimletData::new(gimlet_bufs),
#[cfg(feature = "grapefruit")]
grapefruit_data: grapefruit::GrapefruitData::new(),
};

let mut buffer = [0; idl::INCOMING_SIZE];
Expand All @@ -124,6 +129,8 @@ struct ServerImpl {
identity: &'static mut Option<VpdIdentity>,
#[cfg(feature = "gimlet")]
gimlet_data: gimlet::GimletData,
#[cfg(feature = "grapefruit")]
grapefruit_data: grapefruit::GrapefruitData,
}

impl ServerImpl {
Expand Down Expand Up @@ -204,7 +211,15 @@ impl idl::InOrderPackratImpl for ServerImpl {
Ok(self.gimlet_data.host_startup_options())
}

#[cfg(not(feature = "gimlet"))]
#[cfg(feature = "grapefruit")]
fn get_next_boot_host_startup_options(
&mut self,
_: &RecvMessage,
) -> Result<HostStartupOptions, RequestError<Infallible>> {
Ok(self.grapefruit_data.host_startup_options())
}

#[cfg(not(any(feature = "gimlet", feature = "grapefruit")))]
fn get_next_boot_host_startup_options(
&mut self,
_: &RecvMessage,
Expand All @@ -228,7 +243,21 @@ impl idl::InOrderPackratImpl for ServerImpl {
Ok(())
}

#[cfg(not(feature = "gimlet"))]
#[cfg(feature = "grapefruit")]
fn set_next_boot_host_startup_options(
&mut self,
_: &RecvMessage,
host_startup_options: HostStartupOptions,
) -> Result<(), RequestError<Infallible>> {
ringbuf_entry!(Trace::SetNextBootHostStartupOptions(
host_startup_options
));
self.grapefruit_data
.set_host_startup_options(host_startup_options);
Ok(())
}

#[cfg(not(any(feature = "gimlet", feature = "grapefruit")))]
fn set_next_boot_host_startup_options(
&mut self,
_: &RecvMessage,
Expand Down

0 comments on commit 6b8a7f8

Please sign in to comment.