Skip to content

Commit bcd6efc

Browse files
committed
Add LastPostCode component details to SP5 host CPU
1 parent 2dc17d2 commit bcd6efc

File tree

15 files changed

+159
-63
lines changed

15 files changed

+159
-63
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/cosmo/base.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ max-sizes = {flash = 131072, ram = 16384 }
181181
stacksize = 2600
182182
start = true
183183
task-slots = ["sys", "i2c_driver", {spi_front = "spi3_driver"}, "jefe", "packrat", "auxflash", "spartan7_loader", "hf"]
184-
uses = ["mmio_sequencer", "mmio_info"]
184+
uses = ["mmio_sequencer", "mmio_info", "mmio_espi"]
185185
notifications = ["timer", "vcore", "seq-irq"]
186186

187187
[tasks.ignition_flash]

app/grapefruit/base.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ max-sizes = {flash = 131072, ram = 16384 }
181181
stacksize = 2600
182182
start = true
183183
task-slots = ["sys", "jefe", "packrat", "spartan7_loader"]
184-
uses = ["mmio_sgpio"]
184+
uses = ["mmio_sgpio", "mmio_espi"]
185185

186186
[tasks.spartan7_loader]
187187
name = "drv-spartan7-loader"

build/fpga-regmap/src/lib.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ pub fn build_peripheral(
449449
else {
450450
panic!("nodes within register must be fields, not {c:?}");
451451
};
452+
let desc = Some(desc.as_str()).filter(|s| !s.is_empty());
452453
let msb = u32::try_from(*msb).unwrap();
453454
let lsb = u32::try_from(*lsb).unwrap();
454455
let setter: syn::Ident =
@@ -458,9 +459,10 @@ pub fn build_peripheral(
458459
syn::parse_str(&inst_name.to_snake_case()).unwrap();
459460
if lsb == msb {
460461
if sw_access.is_write() {
462+
let doc = desc.into_iter();
461463
struct_fns.push(quote! {
462464
#[inline]
463-
#[doc = #desc]
465+
#(#[doc = #doc])*
464466
pub fn #setter(&self, t: bool) {
465467
let mut d = self.get_raw();
466468
if t {
@@ -473,9 +475,10 @@ pub fn build_peripheral(
473475
});
474476
}
475477
if sw_access.is_read() {
478+
let doc = desc.into_iter();
476479
struct_fns.push(quote! {
477480
#[inline]
478-
#[doc = #desc]
481+
#(#[doc = #doc])*
479482
pub fn #getter(&self) -> bool {
480483
let d = self.get_raw();
481484
(d & (1 << #msb)) != 0
@@ -535,9 +538,10 @@ pub fn build_peripheral(
535538
}
536539
});
537540
if sw_access.is_write() {
541+
let doc = desc.into_iter();
538542
struct_fns.push(quote! {
539543
#[inline]
540-
#[doc = #desc]
544+
#(#[doc = #doc])*
541545
pub fn #setter(&self, t: #ty) {
542546
let mut d = self.get_raw();
543547
d &= !(#mask << #lsb);
@@ -547,9 +551,10 @@ pub fn build_peripheral(
547551
});
548552
}
549553
if sw_access.is_read() {
554+
let doc = desc.into_iter();
550555
struct_fns.push(quote! {
551556
#[inline]
552-
#[doc = #desc]
557+
#(#[doc = #doc])*
553558
pub fn #getter(&self) -> Result<#ty, #raw_ty> {
554559
let d = self.get_raw();
555560
let t = ((d >> #lsb) & #mask) as #raw_ty;
@@ -576,9 +581,10 @@ pub fn build_peripheral(
576581
};
577582
let ty: syn::Ident = syn::parse_str(ty).unwrap();
578583
if sw_access.is_write() {
584+
let doc = desc.into_iter();
579585
struct_fns.push(quote! {
580586
#[inline]
581-
#[doc = #desc]
587+
#(#[doc = #doc])*
582588
pub fn #setter(&self, t: #ty) {
583589
let mut d = self.get_raw();
584590
d &= !(#mask << #lsb);
@@ -588,9 +594,10 @@ pub fn build_peripheral(
588594
});
589595
}
590596
if sw_access.is_read() {
597+
let doc = desc.into_iter();
591598
struct_fns.push(quote! {
592599
#[inline]
593-
#[doc = #desc]
600+
#(#[doc = #doc])*
594601
pub fn #getter(&self) -> #ty {
595602
let d = self.get_raw();
596603
((d >> #lsb) & #mask) as #ty

drv/cosmo-seq-server/build.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
4040
idol::server::ServerStyle::InOrder,
4141
)?;
4242

43-
let out_file = out_dir.join("fmc_sequencer.rs");
43+
let out_file = out_dir.join("fmc_periph.rs");
4444
let mut file = std::fs::File::create(out_file)?;
45-
for periph in ["sequencer", "info"] {
45+
for periph in ["sequencer", "info", "espi"] {
4646
write!(
4747
&mut file,
48-
"{}",
48+
"pub mod {periph} {{\n{}\n}}",
4949
build_fpga_regmap::fpga_peripheral(
5050
periph,
5151
"drv_spartan7_loader_api::Spartan7Token"

drv/cosmo-seq-server/src/main.rs

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,17 @@ enum Trace {
5252
Programmed,
5353

5454
Startup {
55-
early_power_rdbks: fmc_periph::EarlyPowerRdbksView,
55+
early_power_rdbks: fmc_sequencer::EarlyPowerRdbksView,
5656
},
5757
RegStateValues {
58-
seq_api_status: fmc_periph::SeqApiStatusView,
59-
seq_raw_status: fmc_periph::SeqRawStatusView,
60-
nic_api_status: fmc_periph::NicApiStatusView,
61-
nic_raw_status: fmc_periph::NicRawStatusView,
58+
seq_api_status: fmc_sequencer::SeqApiStatusView,
59+
seq_raw_status: fmc_sequencer::SeqRawStatusView,
60+
nic_api_status: fmc_sequencer::NicApiStatusView,
61+
nic_raw_status: fmc_sequencer::NicRawStatusView,
6262
},
6363
RegPgValues {
64-
rail_pgs: fmc_periph::RailPgsView,
65-
rail_pgs_max_hold: fmc_periph::RailPgsMaxHoldView,
64+
rail_pgs: fmc_sequencer::RailPgsView,
65+
rail_pgs_max_hold: fmc_sequencer::RailPgsMaxHoldView,
6666
},
6767
SetState {
6868
prev: Option<PowerState>,
@@ -73,12 +73,12 @@ enum Trace {
7373
},
7474
UnexpectedPowerOff {
7575
our_state: PowerState,
76-
seq_state: Result<fmc_periph::A0Sm, u8>,
76+
seq_state: Result<fmc_sequencer::A0Sm, u8>,
7777
},
7878
SequencerInterrupt {
7979
our_state: PowerState,
80-
seq_state: Result<fmc_periph::A0Sm, u8>,
81-
ifr: fmc_periph::IfrView,
80+
seq_state: Result<fmc_sequencer::A0Sm, u8>,
81+
ifr: fmc_sequencer::IfrView,
8282
},
8383
PowerDownError(drv_cpu_seq_api::SeqError),
8484
Coretype {
@@ -155,8 +155,8 @@ use gpio_irq_pins::SEQ_IRQ;
155155

156156
/// Helper type which includes both sequencer and NIC state machine states
157157
struct StateMachineStates {
158-
seq: Result<fmc_periph::A0Sm, u8>,
159-
nic: Result<fmc_periph::NicSm, u8>,
158+
seq: Result<fmc_sequencer::A0Sm, u8>,
159+
nic: Result<fmc_sequencer::NicSm, u8>,
160160
}
161161

162162
#[export_name = "main"]
@@ -260,7 +260,7 @@ fn init(packrat: Packrat) -> Result<ServerImpl, SeqError> {
260260

261261
// Set up the checksum registers for the Spartan7 FPGA
262262
let token = loader.get_token();
263-
let info = fmc_periph::Info::new(token);
263+
let info = fmc_periph::info::Info::new(token);
264264
let short_checksum = gen::SPARTAN7_FPGA_BITSTREAM_CHECKSUM[..4]
265265
.try_into()
266266
.unwrap();
@@ -298,8 +298,7 @@ fn init(packrat: Packrat) -> Result<ServerImpl, SeqError> {
298298
// Turn on the chassis LED!
299299
sys.gpio_set(SP_CHASSIS_STATUS_LED);
300300

301-
let token = loader.get_token();
302-
Ok(ServerImpl::new(token, packrat))
301+
Ok(ServerImpl::new(loader, packrat))
303302
}
304303

305304
/// Configures the front FPGA pins and holds it in reset
@@ -376,7 +375,8 @@ struct ServerImpl {
376375
jefe: Jefe,
377376
sys: Sys,
378377
hf: HostFlash,
379-
seq: fmc_periph::Sequencer,
378+
seq: fmc_sequencer::Sequencer,
379+
espi: fmc_periph::espi::Espi,
380380
vcore: VCore,
381381
/// Static buffer for encoding ereports. This is a static so that we don't
382382
/// have it on the stack when encoding ereports.
@@ -387,11 +387,14 @@ const EREPORT_BUF_LEN: usize = 256;
387387

388388
impl ServerImpl {
389389
fn new(
390-
token: drv_spartan7_loader_api::Spartan7Token,
390+
loader: drv_spartan7_loader_api::Spartan7Loader,
391391
packrat: Packrat,
392392
) -> Self {
393393
let now = sys_get_timer().now;
394-
let seq = fmc_periph::Sequencer::new(token);
394+
395+
let seq = fmc_sequencer::Sequencer::new(loader.get_token());
396+
let espi = fmc_periph::espi::Espi::new(loader.get_token());
397+
395398
ringbuf_entry!(Trace::Startup {
396399
early_power_rdbks: (&seq.early_power_rdbks).into(),
397400
});
@@ -417,6 +420,7 @@ impl ServerImpl {
417420
sys: Sys::from(SYS.get_task_id()),
418421
hf: HostFlash::from(HF.get_task_id()),
419422
seq,
423+
espi,
420424
vcore: VCore::new(I2C.get_task_id(), packrat),
421425
ereport_buf,
422426
}
@@ -464,7 +468,7 @@ impl ServerImpl {
464468
now,
465469
});
466470

467-
use fmc_periph::A0Sm;
471+
use fmc_sequencer::A0Sm;
468472
match (self.get_state_impl(), state) {
469473
(PowerState::A2, PowerState::A0) => {
470474
// Reset edge counters in the sequencer
@@ -881,6 +885,13 @@ impl idl::InOrderSequencerImpl for ServerImpl {
881885
idol_runtime::ClientError::BadMessageContents,
882886
))
883887
}
888+
889+
fn last_post_code(
890+
&mut self,
891+
_: &RecvMessage,
892+
) -> Result<u32, RequestError<core::convert::Infallible>> {
893+
Ok(self.espi.last_post_code.payload())
894+
}
884895
}
885896

886897
impl NotificationHandler for ServerImpl {
@@ -897,7 +908,7 @@ impl NotificationHandler for ServerImpl {
897908
return;
898909
}
899910
let state = self.log_state_registers();
900-
use fmc_periph::{A0Sm, NicSm};
911+
use fmc_sequencer::{A0Sm, NicSm};
901912

902913
// Detect when the NIC comes online
903914
// TODO: should we handle the NIC powering down while the main CPU
@@ -940,8 +951,9 @@ mod gen {
940951
}
941952

942953
mod fmc_periph {
943-
include!(concat!(env!("OUT_DIR"), "/fmc_sequencer.rs"));
954+
include!(concat!(env!("OUT_DIR"), "/fmc_periph.rs"));
944955
}
956+
use fmc_periph::sequencer as fmc_sequencer;
945957

946958
include!(concat!(env!("OUT_DIR"), "/notifications.rs"));
947959
include!(concat!(env!("OUT_DIR"), "/gpio_irq_pins.rs"));

drv/gimlet-seq-server/src/main.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,15 @@ impl<S: SpiServer> idl::InOrderSequencerImpl for ServerImpl<S> {
11351135

11361136
Ok(buf)
11371137
}
1138+
1139+
fn last_post_code(
1140+
&mut self,
1141+
_: &RecvMessage,
1142+
) -> Result<u32, RequestError<core::convert::Infallible>> {
1143+
Err(RequestError::Fail(
1144+
idol_runtime::ClientError::BadMessageContents,
1145+
))
1146+
}
11381147
}
11391148

11401149
fn read_spd_data_and_load_packrat(

drv/grapefruit-seq-server/build.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,18 @@ fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
1212
)?;
1313

1414
let out_dir = build_util::out_dir();
15-
let out_file = out_dir.join("fmc_sgpio.rs");
15+
let out_file = out_dir.join("fmc_periph.rs");
1616
let mut file = std::fs::File::create(out_file)?;
17-
write!(
18-
&mut file,
19-
"{}",
20-
build_fpga_regmap::fpga_peripheral(
21-
"sgpio",
22-
"drv_spartan7_loader_api::Spartan7Token"
23-
)?
24-
)?;
17+
for p in ["sgpio", "espi"] {
18+
write!(
19+
&mut file,
20+
"pub mod {p} {{\n{}\n}}",
21+
build_fpga_regmap::fpga_peripheral(
22+
p,
23+
"drv_spartan7_loader_api::Spartan7Token"
24+
)?
25+
)?;
26+
}
2527

2628
Ok(())
2729
}

drv/grapefruit-seq-server/src/main.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ fn main() -> ! {
7575
#[allow(unused)]
7676
struct ServerImpl {
7777
jefe: Jefe,
78-
sgpio: fmc_periph::Sgpio,
78+
sgpio: fmc_periph::sgpio::Sgpio,
79+
espi: fmc_periph::espi::Espi,
7980
}
8081

8182
impl ServerImpl {
@@ -96,7 +97,8 @@ impl ServerImpl {
9697

9798
let server = Self {
9899
jefe: Jefe::from(JEFE.get_task_id()),
99-
sgpio: fmc_periph::Sgpio::new(loader.get_token()),
100+
sgpio: fmc_periph::sgpio::Sgpio::new(loader.get_token()),
101+
espi: fmc_periph::espi::Espi::new(loader.get_token()),
100102
};
101103

102104
// Note that we don't use `Self::set_state_impl` here, as that will
@@ -184,6 +186,13 @@ impl idl::InOrderSequencerImpl for ServerImpl {
184186
) -> Result<[u8; 64], RequestError<core::convert::Infallible>> {
185187
Ok([0; 64])
186188
}
189+
190+
fn last_post_code(
191+
&mut self,
192+
_: &RecvMessage,
193+
) -> Result<u32, RequestError<core::convert::Infallible>> {
194+
Ok(self.espi.last_post_code.payload())
195+
}
187196
}
188197

189198
impl NotificationHandler for ServerImpl {
@@ -202,5 +211,5 @@ mod idl {
202211
}
203212

204213
mod fmc_periph {
205-
include!(concat!(env!("OUT_DIR"), "/fmc_sgpio.rs"));
214+
include!(concat!(env!("OUT_DIR"), "/fmc_periph.rs"));
206215
}

drv/mock-gimlet-seq-server/src/main.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@ impl idl::InOrderSequencerImpl for ServerImpl {
103103
) -> Result<[u8; 64], RequestError<core::convert::Infallible>> {
104104
Ok([0; 64])
105105
}
106+
107+
fn last_post_code(
108+
&mut self,
109+
_: &RecvMessage,
110+
) -> Result<u32, RequestError<core::convert::Infallible>> {
111+
Err(RequestError::Fail(
112+
idol_runtime::ClientError::BadMessageContents,
113+
))
114+
}
106115
}
107116

108117
impl NotificationHandler for ServerImpl {

0 commit comments

Comments
 (0)