Skip to content

Commit a227202

Browse files
committed
pci: Convert PowerManagementCapabilities to deku bits
Signed-off-by: Andrew Jeffery <andrew@codeconstruct.com.au>
1 parent 5d7fe5d commit a227202

2 files changed

Lines changed: 12 additions & 18 deletions

File tree

src/nvme.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ enum AdminIoCqeGenericCommandStatus {
134134
InternalError = 0x06,
135135
InvalidNamespaceOrFormat = 0x0b,
136136
}
137-
unsafe impl Discriminant<u8> for AdminIoCqeGenericCommandStatus {}
138137

139138
impl From<DekuError> for AdminIoCqeGenericCommandStatus {
140139
fn from(err: DekuError) -> Self {

src/pcie.rs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ impl PciDeviceFunctionConfigurationSpace {
104104
d2: false,
105105
pme: 0,
106106
}
107-
}
108-
.into(),
107+
},
109108
pmcsr: 0,
110109
data: 0,
111110
}),
@@ -175,36 +174,32 @@ impl PciDeviceFunctionConfigurationSpaceBuilder {
175174
}
176175
}
177176

178-
#[derive(Debug)]
177+
#[derive(Debug, DekuRead, DekuWrite)]
178+
#[deku(bit_order = "lsb", ctx = "endian: Endian", endian = "endian")]
179179
pub struct PowerManagementCapabilities {
180+
#[deku(bits = "3")]
180181
version: u8,
182+
#[deku(bits = "1")]
181183
pme_clock: bool,
184+
#[deku(bits = "1")]
182185
ready_d0: bool,
186+
#[deku(bits = "1")]
183187
dsi: bool,
188+
#[deku(bits = "3")]
184189
aux_current: u8,
190+
#[deku(bits = "1")]
185191
d1: bool,
192+
#[deku(bits = "1")]
186193
d2: bool,
194+
#[deku(bits = "5")]
187195
pme: u8,
188196
}
189197

190-
impl From<PowerManagementCapabilities> for u16 {
191-
fn from(value: PowerManagementCapabilities) -> Self {
192-
((value.pme as u16 & 0xf) << 11)
193-
| ((value.d2 as u16) << 10)
194-
| ((value.d1 as u16) << 9)
195-
| ((value.aux_current as u16 & 0x7) << 6)
196-
| ((value.dsi as u16) << 5)
197-
| ((value.ready_d0 as u16) << 4)
198-
| ((value.pme_clock as u16) << 3)
199-
| (value.version as u16 & 0x7)
200-
}
201-
}
202-
203198
#[derive(Debug, DekuRead, DekuWrite)]
204199
#[deku(ctx = "endian: Endian", endian = "endian")]
205200
pub struct PciPowerManagementCapability {
206201
next: u8,
207-
pmc: u16,
202+
pmc: PowerManagementCapabilities,
208203
pmcsr: u16,
209204
#[deku(seek_from_current = "1")]
210205
data: u8,

0 commit comments

Comments
 (0)