acpi_spec/
pptt.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4use crate::Table;
5use crate::packed_nums::u16_ne;
6use crate::packed_nums::u32_ne;
7use bitfield_struct::bitfield;
8use open_enum::open_enum;
9use zerocopy::FromBytes;
10use zerocopy::FromZeros;
11use zerocopy::Immutable;
12use zerocopy::IntoBytes;
13use zerocopy::KnownLayout;
14use zerocopy::Unaligned;
15
16/// PPTT table, used for describing the cache topology of a machine.
17#[repr(C)]
18#[derive(Copy, Clone, Debug, IntoBytes, Immutable, KnownLayout, FromBytes, Unaligned)]
19pub struct Pptt {}
20
21impl Table for Pptt {
22    const SIGNATURE: [u8; 4] = *b"PPTT";
23}
24
25open_enum! {
26    #[derive(IntoBytes, Immutable, KnownLayout, FromBytes, Unaligned)]
27    pub enum PpttType: u8 {
28        PROCESSOR = 0,
29        CACHE = 1,
30    }
31}
32
33#[repr(C)]
34#[derive(Copy, Clone, Debug, IntoBytes, Immutable, KnownLayout, FromBytes, Unaligned)]
35pub struct PpttProcessor {
36    pub typ: PpttType,
37    pub len: u8,
38    pub rsvd: [u8; 2],
39    pub flags: u32_ne,
40    pub parent: u32_ne,
41    pub acpi_processor_id: u32_ne,
42    pub num_private_resources: u32_ne,
43}
44
45#[bitfield(u32)]
46pub struct PpttProcessorFlags {
47    pub physical_package: bool,
48    pub acpi_processor_uid_valid: bool,
49    pub processor_is_a_thread: bool,
50    pub node_is_a_leaf: bool,
51    pub identical_implementation: bool,
52    #[bits(27)]
53    _rsvd: u32,
54}
55
56const _: () = assert!(size_of::<PpttProcessor>() == 20);
57
58impl PpttProcessor {
59    pub fn new(num_private_resources: u8) -> Self {
60        Self {
61            typ: PpttType::PROCESSOR,
62            len: size_of::<Self>() as u8 + num_private_resources * 4,
63            num_private_resources: (num_private_resources as u32).into(),
64            ..FromZeros::new_zeroed()
65        }
66    }
67}
68
69#[repr(C)]
70#[derive(Copy, Clone, Debug, IntoBytes, Immutable, KnownLayout, FromBytes, Unaligned)]
71pub struct PpttCache {
72    pub typ: PpttType,
73    pub len: u8,
74    pub rsvd: [u8; 2],
75    pub flags: u32_ne,
76    pub next_level: u32_ne,
77    pub size: u32_ne,
78    pub num_sets: u32_ne,
79    pub associativity: u8,
80    pub attributes: PpttCacheAttributes,
81    pub line_size: u16_ne,
82    pub cache_id: u32_ne,
83}
84
85const _: () = assert!(size_of::<PpttCache>() == 28);
86
87impl PpttCache {
88    pub fn new() -> Self {
89        Self {
90            typ: PpttType::CACHE,
91            len: size_of::<Self>() as u8,
92            ..FromZeros::new_zeroed()
93        }
94    }
95}
96
97#[bitfield(u32)]
98pub struct PpttCacheFlags {
99    pub size_valid: bool,
100    pub number_of_sets_valid: bool,
101    pub associativity_valid: bool,
102    pub allocation_type_valid: bool,
103    pub cache_type_valid: bool,
104    pub write_policy_valid: bool,
105    pub line_size_valid: bool,
106    pub cache_id_valid: bool,
107    #[bits(24)]
108    _rsvd: u32,
109}
110
111#[bitfield(u8)]
112#[derive(IntoBytes, Immutable, KnownLayout, FromBytes, Unaligned)]
113pub struct PpttCacheAttributes {
114    #[bits(2)]
115    pub allocation_type: u8,
116    #[bits(2)]
117    pub cache_type: u8,
118    pub write_through: bool,
119    #[bits(3)]
120    _rsvd: u8,
121}
122
123pub const PPTT_CACHE_TYPE_DATA: u8 = 0;
124pub const PPTT_CACHE_TYPE_INSTRUCTION: u8 = 1;
125pub const PPTT_CACHE_TYPE_UNIFIED: u8 = 3;