Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
add tdisp to emu test.
Browse files Browse the repository at this point in the history
Signed-off-by: Yang, Longlong <[email protected]>
  • Loading branch information
longlongyang committed Nov 2, 2023
1 parent 1cdaa66 commit 3b822ff
Show file tree
Hide file tree
Showing 64 changed files with 3,891 additions and 3,326 deletions.
15 changes: 15 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ members = [
"executor",
"sys_time",
"idekm",
"tdisp",
"test/spdm-requester-emu",
"test/spdm-responder-emu",
"test/spdmlib-test",
Expand Down Expand Up @@ -65,7 +66,6 @@ exclude = [
"external/ring",
"external/webpki",
"fuzz-target/",
"tdisp"
]

resolver = "2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub const PCI_IDE_KM_INSTANCE: VendorDefinedStruct = VendorDefinedStruct {
vendor_context: 0,
};

fn pci_ide_km_rsp_dispatcher(
pub fn pci_ide_km_rsp_dispatcher(
_vendor_context: usize,
vendor_defined_req_payload_struct: &VendorDefinedReqPayloadStruct,
) -> SpdmResult<VendorDefinedRspPayloadStruct> {
Expand Down
9 changes: 6 additions & 3 deletions tdisp/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "tdisp"
license = "BSD-2-Clause-Patent"
version = "0.1.0"
version = "0.2.0"
authors = [
"Jiewen Yao <[email protected]>",
"Xiaoyu Lu <[email protected]>",
Expand All @@ -12,12 +12,15 @@ edition = "2018"
[dev-dependencies]

[build-dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
spin = { version = "0.9.8", optional = true }

[dependencies]
codec = { path = "../codec" }
bitflags = "1.2.1"
zeroize = { version = "1.5.0", features = ["zeroize_derive"]}
spdmlib = { path = "../spdmlib", default-features = false, features = ["spdm-ring"]}

conquer-once = { version = "0.3.2", default-features = false }
spin = { version = "0.9.8" }

[features]
86 changes: 86 additions & 0 deletions tdisp/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Copyright (c) 2023 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0 or MIT

use serde::Deserialize;
use std::env;
use std::io::Write;
use std::path::Path;
use std::{fs, fs::File};

#[derive(Debug, PartialEq, Deserialize)]
struct TdispConfig {
max_mmio_range_count: usize,
max_device_report_buffer_size: usize,
max_report_portion_length: usize,
max_device_specific_info_size: usize,
}

impl TdispConfig {
fn validate_content(&self) {
// All rust fixed-size arrays require non-negative compile-time constant sizes.
// This will be checked by the compiler thus no need to check again here.

// TODO: add more sanity checks if needed.
}
}

macro_rules! TEMPLATE {
() => {
"// Copyright (c) 2023 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0 or MIT
//
// Automatically generated by build scripts.
// It is not intended for manual editing.
// Please kindly configure via etc/config.json instead.
pub const MAX_MMIO_RANGE_COUNT: usize = {max_mmio_range_count};
pub const MAX_DEVICE_SPECIFIC_INFO_LEN: usize = {max_device_specific_info_len};
pub const MAX_PORTION_LENGTH: usize = {max_portion_length};
pub const MAX_DEVICE_REPORT_BUFFER: usize = {max_device_report_buffer};
"
};
}

const TDISP_CONFIG_ENV: &str = "TDISP_CONFIG";
const TDISP_CONFIG_JSON_DEFAULT_PATH: &str = "etc/config.json";
const TDISP_CONFIG_RS_OUT_DIR: &str = "src";
const TDISP_CONFIG_RS_OUT_FILE_NAME: &str = "config.rs";

fn main() {
// Read and parse the TDISP configuration file.
let tdisp_config_json_file_path =
env::var(TDISP_CONFIG_ENV).unwrap_or_else(|_| TDISP_CONFIG_JSON_DEFAULT_PATH.to_string());
let tdisp_config_json_file = File::open(tdisp_config_json_file_path)
.expect("The TDISP configuration file does not exist");
let tdisp_config: TdispConfig = serde_json::from_reader(tdisp_config_json_file)
.expect("It is not a valid SPDM configuration file.");

// Do sanity checks.
tdisp_config.validate_content();

// Generate config .rs file from the template and JSON inputs, then write to fs.
let mut to_generate = Vec::new();
write!(
&mut to_generate,
TEMPLATE!(),
max_mmio_range_count = tdisp_config.max_mmio_range_count,
max_device_specific_info_len = tdisp_config.max_device_specific_info_size,
max_portion_length = tdisp_config.max_report_portion_length,
max_device_report_buffer = tdisp_config.max_device_report_buffer_size,
)
.expect("Failed to generate configuration code from the template and JSON config");

let dest_path = Path::new(TDISP_CONFIG_RS_OUT_DIR).join(TDISP_CONFIG_RS_OUT_FILE_NAME);
fs::write(dest_path, to_generate).unwrap();

// Re-run the build script if the files at the given paths or envs have changed.
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=../Cargo.lock");
println!("cargo:rerun-if-changed={}", TDISP_CONFIG_JSON_DEFAULT_PATH);
println!("cargo:rerun-if-env-changed={}", TDISP_CONFIG_ENV);
}
7 changes: 7 additions & 0 deletions tdisp/etc/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"__usage": "This helps generate compile-time constant sizes for TDISP arrays. See src/config.rs generated for details.",
"max_mmio_range_count": 4,
"max_device_report_buffer_size": 1024,
"max_report_portion_length": 256,
"max_device_specific_info_size": 256
}
24 changes: 0 additions & 24 deletions tdisp/src/common.rs

This file was deleted.

21 changes: 12 additions & 9 deletions tdisp/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// Copyright (c) 2022 Intel Corporation
// Copyright (c) 2023 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0 or MIT
//
// Automatically generated by build scripts.
// It is not intended for manual editing.
// Please kindly configure via etc/config.json instead.

pub const MAX_MMIO_RANGE_COUNT: usize = 4;

pub const MAX_DEVICE_SPECIFIC_INFO_LEN: usize = 256;

pub const MAX_PORTION_LENGTH: usize = 256;

pub const MAX_VERSION_COUNT: usize = 2;
pub const MAX_MESSAGE_INTERNAL_BUFFER_SIZE: usize = 0xA000;
pub const MAX_MMIO_RANGE_COUNT: usize = 2;
pub const MAX_DEVICE_SPECIFIC_INFORMATION_LENGTH: usize = 0xA000;
pub const MAX_EXTENDED_ERROR_DATA_LENGTH: usize = 0xA000;
pub const MAX_VENDOR_ID_LEN: usize = 0x20;
pub const MAX_VENDOR_DATA_LENGTH: usize = 0xA000;
pub const MAX_TDISP_MESSAGE_SIZE: usize = 0x1000;
pub const MAX_DEVICE_REPORT_BUFFER: usize = 1024;
110 changes: 0 additions & 110 deletions tdisp/src/context.rs

This file was deleted.

18 changes: 0 additions & 18 deletions tdisp/src/device.rs

This file was deleted.

16 changes: 7 additions & 9 deletions tdisp/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
// Copyright (c) 2022 Intel Corporation
// Copyright (c) 2023 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0 or MIT

#![forbid(unsafe_code)]
#![cfg_attr(not(feature = "std"), no_std)]

#[macro_use]
extern crate bitflags;

pub mod common;
pub mod config;
pub mod context;
pub mod device;
pub mod message;
pub mod state_machine;
pub mod tdisp_codec;
pub mod tdisp_requester;
pub mod tdisp_responder;
pub mod pci_tdisp;
pub mod pci_tdisp_requester;
pub mod pci_tdisp_responder;
Loading

0 comments on commit 3b822ff

Please sign in to comment.