Skip to content

Commit 3248158

Browse files
mkroeningIsaacWoods
authored andcommitted
feat: don't take explicit references to ConfigRegionAccess
Signed-off-by: Martin Kröning <martin.kroening@eonerc.rwth-aachen.de>
1 parent 566ef4f commit 3248158

File tree

4 files changed

+37
-37
lines changed

4 files changed

+37
-37
lines changed

src/capability/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl PciCapability {
6464
id: u8,
6565
address: PciCapabilityAddress,
6666
extension: u16,
67-
access: &impl ConfigRegionAccess,
67+
access: impl ConfigRegionAccess,
6868
) -> Option<PciCapability> {
6969
match id {
7070
0x00 => None, // null capability

src/capability/msi.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,33 +82,33 @@ impl MsiCapability {
8282
self.multiple_message_capable
8383
}
8484

85-
pub fn ctrl(&self, access: &impl ConfigRegionAccess) -> u32 {
85+
pub fn ctrl(&self, access: impl ConfigRegionAccess) -> u32 {
8686
unsafe { access.read(self.address.address, self.address.offset) }
8787
}
8888

8989
/// Is MSI capability enabled?
90-
pub fn is_enabled(&self, access: &impl ConfigRegionAccess) -> bool {
90+
pub fn is_enabled(&self, access: impl ConfigRegionAccess) -> bool {
9191
let reg = unsafe { access.read(self.address.address, self.address.offset) };
9292
reg.get_bit(16)
9393
}
9494

9595
/// Enable or disable MSI capability
96-
pub fn set_enabled(&self, enabled: bool, access: &impl ConfigRegionAccess) {
96+
pub fn set_enabled(&self, enabled: bool, access: impl ConfigRegionAccess) {
9797
let mut reg = unsafe { access.read(self.address.address, self.address.offset) };
9898
reg.set_bit(16, enabled);
9999
unsafe { access.write(self.address.address, self.address.offset, reg) };
100100
}
101101

102102
/// Set how many interrupts the device will use. If requested count is bigger than supported count,
103103
/// the second will be used.
104-
pub fn set_multiple_message_enable(&self, data: MultipleMessageSupport, access: &impl ConfigRegionAccess) {
104+
pub fn set_multiple_message_enable(&self, data: MultipleMessageSupport, access: impl ConfigRegionAccess) {
105105
let mut reg = unsafe { access.read(self.address.address, self.address.offset) };
106106
reg.set_bits(4..7, (data.min(self.multiple_message_capable)) as u32);
107107
unsafe { access.write(self.address.address, self.address.offset, reg) };
108108
}
109109

110110
/// Return how many interrupts the device is using
111-
pub fn get_multiple_message_enable(&self, access: &impl ConfigRegionAccess) -> MultipleMessageSupport {
111+
pub fn get_multiple_message_enable(&self, access: impl ConfigRegionAccess) -> MultipleMessageSupport {
112112
let reg = unsafe { access.read(self.address.address, self.address.offset) };
113113
MultipleMessageSupport::try_from(reg.get_bits(4..7) as u8).unwrap_or(MultipleMessageSupport::Int1)
114114
}
@@ -125,7 +125,7 @@ impl MsiCapability {
125125
address: u32,
126126
vector: u8,
127127
trigger_mode: TriggerMode,
128-
access: &impl ConfigRegionAccess,
128+
access: impl ConfigRegionAccess,
129129
) {
130130
unsafe { access.write(self.address.address, self.address.offset + 0x4, address) }
131131
let data_offset = if self.is_64bit { 0xC } else { 0x8 };
@@ -140,7 +140,7 @@ impl MsiCapability {
140140
/// # Note
141141
/// Only supported on when device supports 64-bit addressing and per-vector masking. Otherwise
142142
/// returns `0`
143-
pub fn get_message_mask(&self, access: &impl ConfigRegionAccess) -> u32 {
143+
pub fn get_message_mask(&self, access: impl ConfigRegionAccess) -> u32 {
144144
if self.is_64bit && self.per_vector_masking {
145145
unsafe { access.read(self.address.address, self.address.offset + 0x10) }
146146
} else {
@@ -153,7 +153,7 @@ impl MsiCapability {
153153
/// # Note
154154
/// Only supported on when device supports 64-bit addressing and per-vector masking. Otherwise
155155
/// will do nothing
156-
pub fn set_message_mask(&self, access: &impl ConfigRegionAccess, mask: u32) {
156+
pub fn set_message_mask(&self, access: impl ConfigRegionAccess, mask: u32) {
157157
if self.is_64bit && self.per_vector_masking {
158158
unsafe { access.write(self.address.address, self.address.offset + 0x10, mask) }
159159
}
@@ -163,7 +163,7 @@ impl MsiCapability {
163163
///
164164
/// # Note
165165
/// Only supported on when device supports 64-bit addressing. Otherwise will return `0`
166-
pub fn get_pending(&self, access: &impl ConfigRegionAccess) -> u32 {
166+
pub fn get_pending(&self, access: impl ConfigRegionAccess) -> u32 {
167167
if self.is_64bit {
168168
unsafe { access.read(self.address.address, self.address.offset + 0x14) }
169169
} else {

src/capability/msix.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl MsixCapability {
1616
pub(crate) fn new(
1717
address: PciCapabilityAddress,
1818
control: u16,
19-
access: &impl ConfigRegionAccess,
19+
access: impl ConfigRegionAccess,
2020
) -> MsixCapability {
2121
let table_size = control.get_bits(0..11) + 1;
2222
let table = unsafe { access.read(address.address, address.offset + 0x04) };
@@ -31,7 +31,7 @@ impl MsixCapability {
3131
/// `[MsixCapability::table_bar]` and `[MsixCapability::table_offset]`. The caller is therefore
3232
/// responsible for configuring this separately, as this crate does not have access to
3333
/// arbitrary physical memory.
34-
pub fn set_enabled(&mut self, enabled: bool, access: &impl ConfigRegionAccess) {
34+
pub fn set_enabled(&mut self, enabled: bool, access: impl ConfigRegionAccess) {
3535
let mut control = unsafe { access.read(self.address.address, self.address.offset) };
3636
control.set_bit(31, enabled);
3737
unsafe {

src/lib.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,12 @@ impl PciHeader {
146146
PciHeader(address)
147147
}
148148

149-
pub fn id(&self, access: &impl ConfigRegionAccess) -> (VendorId, DeviceId) {
149+
pub fn id(&self, access: impl ConfigRegionAccess) -> (VendorId, DeviceId) {
150150
let id = unsafe { access.read(self.0, 0x00) };
151151
(id.get_bits(0..16) as VendorId, id.get_bits(16..32) as DeviceId)
152152
}
153153

154-
pub fn header_type(&self, access: &impl ConfigRegionAccess) -> HeaderType {
154+
pub fn header_type(&self, access: impl ConfigRegionAccess) -> HeaderType {
155155
/*
156156
* Read bits 0..=6 of the Header Type. Bit 7 dictates whether the device has multiple functions and so
157157
* isn't returned here.
@@ -164,7 +164,7 @@ impl PciHeader {
164164
}
165165
}
166166

167-
pub fn has_multiple_functions(&self, access: &impl ConfigRegionAccess) -> bool {
167+
pub fn has_multiple_functions(&self, access: impl ConfigRegionAccess) -> bool {
168168
/*
169169
* Reads bit 7 of the Header Type, which is 1 if the device has multiple functions.
170170
*/
@@ -173,7 +173,7 @@ impl PciHeader {
173173

174174
pub fn revision_and_class(
175175
&self,
176-
access: &impl ConfigRegionAccess,
176+
access: impl ConfigRegionAccess,
177177
) -> (DeviceRevision, BaseClass, SubClass, Interface) {
178178
let field = unsafe { access.read(self.0, 0x08) };
179179
(
@@ -184,17 +184,17 @@ impl PciHeader {
184184
)
185185
}
186186

187-
pub fn status(&self, access: &impl ConfigRegionAccess) -> StatusRegister {
187+
pub fn status(&self, access: impl ConfigRegionAccess) -> StatusRegister {
188188
let data = unsafe { access.read(self.0, 0x4).get_bits(16..32) };
189189
StatusRegister::new(data as u16)
190190
}
191191

192-
pub fn command(&self, access: &impl ConfigRegionAccess) -> CommandRegister {
192+
pub fn command(&self, access: impl ConfigRegionAccess) -> CommandRegister {
193193
let data = unsafe { access.read(self.0, 0x4).get_bits(0..16) };
194194
CommandRegister::from_bits_retain(data as u16)
195195
}
196196

197-
pub fn update_command<F>(&self, access: &impl ConfigRegionAccess, f: F)
197+
pub fn update_command<F>(&self, access: impl ConfigRegionAccess, f: F)
198198
where
199199
F: FnOnce(CommandRegister) -> CommandRegister,
200200
{
@@ -256,7 +256,7 @@ impl PciHeader {
256256
pub struct EndpointHeader(PciAddress);
257257

258258
impl EndpointHeader {
259-
pub fn from_header(header: PciHeader, access: &impl ConfigRegionAccess) -> Option<EndpointHeader> {
259+
pub fn from_header(header: PciHeader, access: impl ConfigRegionAccess) -> Option<EndpointHeader> {
260260
match header.header_type(access) {
261261
HeaderType::Endpoint => Some(EndpointHeader(header.0)),
262262
_ => None,
@@ -267,23 +267,23 @@ impl EndpointHeader {
267267
PciHeader(self.0)
268268
}
269269

270-
pub fn status(&self, access: &impl ConfigRegionAccess) -> StatusRegister {
270+
pub fn status(&self, access: impl ConfigRegionAccess) -> StatusRegister {
271271
self.header().status(access)
272272
}
273273

274-
pub fn command(&self, access: &impl ConfigRegionAccess) -> CommandRegister {
274+
pub fn command(&self, access: impl ConfigRegionAccess) -> CommandRegister {
275275
self.header().command(access)
276276
}
277277

278-
pub fn update_command<F>(&self, access: &impl ConfigRegionAccess, f: F)
278+
pub fn update_command<F>(&self, access: impl ConfigRegionAccess, f: F)
279279
where
280280
F: FnOnce(CommandRegister) -> CommandRegister,
281281
{
282282
self.header().update_command(access, f);
283283
}
284284

285-
pub fn capability_pointer(&self, access: &impl ConfigRegionAccess) -> u16 {
286-
let status = self.status(access);
285+
pub fn capability_pointer(&self, access: impl ConfigRegionAccess) -> u16 {
286+
let status = self.status(&access);
287287
if status.has_capability_list() {
288288
unsafe { access.read(self.0, 0x34).get_bits(0..8) as u16 }
289289
} else {
@@ -296,7 +296,7 @@ impl EndpointHeader {
296296
CapabilityIterator::new(self.0, pointer, access)
297297
}
298298

299-
pub fn subsystem(&self, access: &impl ConfigRegionAccess) -> (SubsystemId, SubsystemVendorId) {
299+
pub fn subsystem(&self, access: impl ConfigRegionAccess) -> (SubsystemId, SubsystemVendorId) {
300300
let data = unsafe { access.read(self.0, 0x2c) };
301301
(data.get_bits(16..32) as u16, data.get_bits(0..16) as u16)
302302
}
@@ -306,7 +306,7 @@ impl EndpointHeader {
306306
/// ### Note
307307
/// 64-bit memory BARs use two slots, so if one is decoded in e.g. slot #0, this method should not be called
308308
/// for slot #1
309-
pub fn bar(&self, slot: u8, access: &impl ConfigRegionAccess) -> Option<Bar> {
309+
pub fn bar(&self, slot: u8, access: impl ConfigRegionAccess) -> Option<Bar> {
310310
if slot >= 6 {
311311
return None;
312312
}
@@ -397,10 +397,10 @@ impl EndpointHeader {
397397
pub unsafe fn write_bar(
398398
&mut self,
399399
slot: u8,
400-
access: &impl ConfigRegionAccess,
400+
access: impl ConfigRegionAccess,
401401
value: usize,
402402
) -> Result<(), BarWriteError> {
403-
match self.bar(slot, access) {
403+
match self.bar(slot, &access) {
404404
Some(Bar::Memory64 { .. }) => {
405405
let offset = 0x10 + (slot as u16) * 4;
406406
unsafe {
@@ -424,7 +424,7 @@ impl EndpointHeader {
424424
}
425425
}
426426

427-
pub fn interrupt(&self, access: &impl ConfigRegionAccess) -> (InterruptPin, InterruptLine) {
427+
pub fn interrupt(&self, access: impl ConfigRegionAccess) -> (InterruptPin, InterruptLine) {
428428
// According to the PCI Express Specification 4.0, Min_Gnt/Max_Lat registers
429429
// must be read-only and hardwired to 00h.
430430
let data = unsafe { access.read(self.0, 0x3c) };
@@ -494,7 +494,7 @@ impl EndpointHeader {
494494
pub struct PciPciBridgeHeader(PciAddress);
495495

496496
impl PciPciBridgeHeader {
497-
pub fn from_header(header: PciHeader, access: &impl ConfigRegionAccess) -> Option<PciPciBridgeHeader> {
497+
pub fn from_header(header: PciHeader, access: impl ConfigRegionAccess) -> Option<PciPciBridgeHeader> {
498498
match header.header_type(access) {
499499
HeaderType::PciPciBridge => Some(PciPciBridgeHeader(header.0)),
500500
_ => None,
@@ -505,32 +505,32 @@ impl PciPciBridgeHeader {
505505
PciHeader(self.0)
506506
}
507507

508-
pub fn status(&self, access: &impl ConfigRegionAccess) -> StatusRegister {
508+
pub fn status(&self, access: impl ConfigRegionAccess) -> StatusRegister {
509509
self.header().status(access)
510510
}
511511

512-
pub fn command(&self, access: &impl ConfigRegionAccess) -> CommandRegister {
512+
pub fn command(&self, access: impl ConfigRegionAccess) -> CommandRegister {
513513
self.header().command(access)
514514
}
515515

516-
pub fn update_command<F>(&self, access: &impl ConfigRegionAccess, f: F)
516+
pub fn update_command<F>(&self, access: impl ConfigRegionAccess, f: F)
517517
where
518518
F: FnOnce(CommandRegister) -> CommandRegister,
519519
{
520520
self.header().update_command(access, f);
521521
}
522522

523-
pub fn primary_bus_number(&self, access: &impl ConfigRegionAccess) -> u8 {
523+
pub fn primary_bus_number(&self, access: impl ConfigRegionAccess) -> u8 {
524524
let data = unsafe { access.read(self.0, 0x18).get_bits(0..8) };
525525
data as u8
526526
}
527527

528-
pub fn secondary_bus_number(&self, access: &impl ConfigRegionAccess) -> u8 {
528+
pub fn secondary_bus_number(&self, access: impl ConfigRegionAccess) -> u8 {
529529
let data = unsafe { access.read(self.0, 0x18).get_bits(8..16) };
530530
data as u8
531531
}
532532

533-
pub fn subordinate_bus_number(&self, access: &impl ConfigRegionAccess) -> u8 {
533+
pub fn subordinate_bus_number(&self, access: impl ConfigRegionAccess) -> u8 {
534534
let data = unsafe { access.read(self.0, 0x18).get_bits(16..24) };
535535
data as u8
536536
}

0 commit comments

Comments
 (0)