Skip to content

Commit 34c9c7c

Browse files
committed
feat(tdx): add struct and const definitions for TDVF
Signed-off-by: Changyuan Lyu <changyuanl@google.com>
1 parent b4f5cde commit 34c9c7c

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

alioth/src/firmware/ovmf/ovmf_x86_64/ovmf_x86_64.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
pub mod sev;
16+
pub mod tdx;
1617

1718
use zerocopy::FromBytes;
1819

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright 2026 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
16+
17+
use crate::firmware::ovmf::x86_64::GUID_SIZE;
18+
use crate::{bitflags, consts};
19+
20+
pub const GUID_TDX_METADATA_OFFSET: [u8; GUID_SIZE] = [
21+
0x35, 0x65, 0x7a, 0xe4, 0x4a, 0x98, 0x98, 0x47, 0x86, 0x5e, 0x46, 0x85, 0xa7, 0xbf, 0x8e, 0xc2,
22+
];
23+
pub const TDVF_SIGNATURE: u32 = u32::from_le_bytes(*b"TDVF");
24+
pub const TDVF_VERSION: u32 = 1;
25+
26+
#[repr(C)]
27+
#[derive(Debug, Clone, Default, KnownLayout, Immutable, FromBytes, IntoBytes)]
28+
pub struct TdvfMetadata {
29+
pub signature: u32,
30+
pub length: u32,
31+
pub version: u32,
32+
pub number_of_entries: u32,
33+
}
34+
35+
consts! {
36+
#[derive(Default, KnownLayout, Immutable, FromBytes, IntoBytes)]
37+
pub struct TdvfSectionType(u32) {
38+
BFV = 0;
39+
CFV = 1;
40+
TD_HOB = 2;
41+
TEMP_MEM = 3;
42+
}
43+
}
44+
45+
bitflags! {
46+
#[derive(Default, KnownLayout, Immutable, FromBytes, IntoBytes)]
47+
pub struct TdvfSectionAttribute(u32) {
48+
MR_EXTEND = 1 << 0;
49+
PAGE_AUG = 1 << 1;
50+
}
51+
}
52+
53+
#[repr(C)]
54+
#[derive(Debug, Clone, Default, KnownLayout, Immutable, FromBytes, IntoBytes)]
55+
pub struct TdxMetadataSection {
56+
pub data_offset: u32,
57+
pub raw_data_size: u32,
58+
pub memory_address: u64,
59+
pub memory_data_size: u64,
60+
pub r#type: TdvfSectionType,
61+
pub attributes: TdvfSectionAttribute,
62+
}

0 commit comments

Comments
 (0)