1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
use super::capability::RuntimeRegisterSpaceOffset;
use accessor::Mapper;
use bit_field::BitField;
use core::convert::TryFrom;
use core::convert::TryInto;
#[derive(Debug)]
pub struct Runtime<M>
where
M: Mapper,
{
pub mfindex: accessor::Single<MicroframeIndexRegister, M>,
}
impl<M> Runtime<M>
where
M: Mapper,
{
pub unsafe fn new(mmio_base: usize, rtoff: RuntimeRegisterSpaceOffset, mapper: M) -> Self {
let base = mmio_base + usize::try_from(rtoff.get()).unwrap();
Self {
mfindex: accessor::Single::new(base, mapper),
}
}
}
#[repr(transparent)]
#[derive(Copy, Clone)]
pub struct MicroframeIndexRegister(u32);
impl MicroframeIndexRegister {
#[must_use]
pub fn microframe_index(self) -> u16 {
self.0.get_bits(0..=13).try_into().unwrap()
}
}
impl_debug_from_methods! {
MicroframeIndexRegister {
microframe_index,
}
}
#[repr(C)]
#[derive(Copy, Clone, Debug)]
pub struct InterruptRegisterSet {
pub iman: InterrupterManagementRegister,
pub imod: InterrupterModerationRegister,
pub erstsz: EventRingSegmentTableSizeRegister,
_rsvd: u32,
pub erstba: EventRingSegmentTableBaseAddressRegister,
pub erdp: EventRingDequeuePointerRegister,
}
impl InterruptRegisterSet {
pub unsafe fn new<M>(
mmio_base: usize,
rtoff: RuntimeRegisterSpaceOffset,
mapper: M,
) -> accessor::Array<Self, M>
where
M: Mapper,
{
const NUM_INTERRUPT_REGISTER_SET: usize = 1024;
let base = mmio_base + usize::try_from(rtoff.get()).unwrap() + 0x20;
accessor::Array::new(base, NUM_INTERRUPT_REGISTER_SET, mapper)
}
}
#[repr(transparent)]
#[derive(Copy, Clone)]
pub struct InterrupterManagementRegister(u32);
impl InterrupterManagementRegister {
#[must_use]
pub fn interrupt_pending(self) -> bool {
self.0.get_bit(0)
}
pub fn clear_interrupt_pending(&mut self) {
self.0.set_bit(0, true);
}
#[must_use]
pub fn interrupt_enable(self) -> bool {
self.0.get_bit(1)
}
pub fn set_interrupt_enable(&mut self, b: bool) {
self.0.set_bit(1, b);
}
}
impl_debug_from_methods! {
InterrupterManagementRegister {
interrupt_pending,
interrupt_enable,
}
}
#[repr(transparent)]
#[derive(Copy, Clone)]
pub struct InterrupterModerationRegister(u32);
impl InterrupterModerationRegister {
#[must_use]
pub fn interrupt_moderation_interval(self) -> u16 {
self.0.get_bits(0..=15).try_into().unwrap()
}
pub fn set_interrupt_moderation_interval(&mut self, interval: u16) {
self.0.set_bits(0..=15, interval.into());
}
#[must_use]
pub fn interrupt_moderation_counter(self) -> u16 {
self.0.get_bits(16..=31).try_into().unwrap()
}
pub fn set_interrupt_moderation_counter(&mut self, counter: u16) {
self.0.set_bits(16..=31, counter.into());
}
}
impl_debug_from_methods! {
InterrupterModerationRegister{
interrupt_moderation_interval,
interrupt_moderation_counter,
}
}
#[repr(transparent)]
#[derive(Copy, Clone, Debug)]
pub struct EventRingSegmentTableSizeRegister(u32);
impl EventRingSegmentTableSizeRegister {
pub fn set(&mut self, s: u16) {
self.0 = s.into();
}
}
#[repr(transparent)]
#[derive(Copy, Clone, Debug)]
pub struct EventRingSegmentTableBaseAddressRegister(u64);
impl EventRingSegmentTableBaseAddressRegister {
pub fn set(&mut self, a: u64) {
assert!(a.trailing_zeros() >= 6);
self.0 = a;
}
}
#[repr(transparent)]
#[derive(Copy, Clone)]
pub struct EventRingDequeuePointerRegister(u64);
impl EventRingDequeuePointerRegister {
#[must_use]
pub fn dequeue_erst_segment_index(self) -> u8 {
self.0.get_bits(0..=2).try_into().unwrap()
}
pub fn set_dequeue_erst_segment_index(&mut self, i: u8) {
self.0.set_bits(0..=2, i.into());
}
#[must_use]
pub fn event_handler_busy(self) -> bool {
self.0.get_bit(3)
}
pub fn clear_event_handler_busy(&mut self) {
self.0.set_bit(3, true);
}
#[must_use]
pub fn event_ring_dequeue_pointer(self) -> u64 {
self.0 & 0b1111
}
pub fn set_event_ring_dequeue_pointer(&mut self, p: u64) {
assert!(p.trailing_zeros() >= 4);
self.0 = p;
}
}
impl_debug_from_methods! {
EventRingDequeuePointerRegister{
dequeue_erst_segment_index,
event_handler_busy,
event_ring_dequeue_pointer
}
}