Skip to content

Commit e2faf8a

Browse files
committed
mmio: Explicit read and write
Originally I thought that the compiler now reorders mmio accesses because the output of the system-test was scrambled. However, this was not the case. This is fixed in 178186b Nevertheless, we put a lot of work into that and it is cleaner. So keep that change.
1 parent 178186b commit e2faf8a

File tree

9 files changed

+463
-290
lines changed

9 files changed

+463
-290
lines changed
+14-30
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use crate::mmio_struct;
2+
13
// cfg_type values
24
/* Common configuration */
35
pub const VIRTIO_PCI_CAP_COMMON_CFG: u8 = 1;
@@ -19,35 +21,17 @@ pub const VIRTIO_PCI_CAP_SHARED_MEMORY_CFG: u8 = 8;
1921
#[allow(dead_code)]
2022
pub const VIRTIO_PCI_CAP_VENDOR_CFG: u8 = 9;
2123

22-
#[allow(dead_code, non_camel_case_types)]
23-
#[derive(Debug)]
24-
#[repr(packed)]
25-
pub(super) struct virtio_pci_cap {
26-
cap_vndr: u8, /* Generic PCI field: PCI_CAP_ID_VNDR */
27-
cap_next: u8, /* Generic PCI field: next ptr. */
28-
cap_len: u8, /* Generic PCI field: capability length */
29-
cfg_type: u8, /* Identifies the structure. */
30-
bar: u8, /* Where to find it. */
31-
id: u8, /* Multiple capabilities of the same type */
32-
padding: [u8; 2], /* Pad to full dword. */
33-
offset: u32, /* Offset within bar. */
34-
length: u32, /* Length of the structure, in bytes. */
35-
}
36-
37-
impl virtio_pci_cap {
38-
pub fn cfg_type(&self) -> u8 {
39-
self.cfg_type
40-
}
41-
42-
pub fn bar(&self) -> u8 {
43-
self.bar
44-
}
45-
46-
pub fn length(&self) -> u32 {
47-
self.length
48-
}
49-
50-
pub fn offset(&self) -> usize {
51-
self.offset as usize
24+
mmio_struct! {
25+
#[repr(packed)]
26+
struct virtio_pci_cap {
27+
cap_vndr: u8, /* Generic PCI field: PCI_CAP_ID_VNDR */
28+
cap_next: u8, /* Generic PCI field: next ptr. */
29+
cap_len: u8, /* Generic PCI field: capability length */
30+
cfg_type: u8, /* Identifies the structure. */
31+
bar: u8, /* Where to find it. */
32+
id: u8, /* Multiple capabilities of the same type */
33+
padding: [u8; 2], /* Pad to full dword. */
34+
offset: u32, /* Offset within bar. */
35+
length: u32, /* Length of the structure, in bytes. */
5236
}
5337
}

0 commit comments

Comments
 (0)