2
2
3
3
use accessor:: Mapper ;
4
4
use bit_field:: BitField ;
5
- use core:: convert:: TryInto ;
6
5
7
6
/// Host Controller Capability Registers
8
7
#[ derive( Debug ) ]
@@ -105,23 +104,9 @@ impl InterfaceVersionNumber {
105
104
#[ derive( Copy , Clone ) ]
106
105
pub struct StructuralParameters1 ( u32 ) ;
107
106
impl StructuralParameters1 {
108
- /// Returns the number of available device slots.
109
- #[ must_use]
110
- pub fn number_of_device_slots ( self ) -> u8 {
111
- self . 0 . get_bits ( 0 ..=7 ) . try_into ( ) . unwrap ( )
112
- }
113
-
114
- /// Returns the number of interrupts implemented on HC.
115
- #[ must_use]
116
- pub fn number_of_interrupts ( self ) -> u16 {
117
- self . 0 . get_bits ( 8 ..=18 ) . try_into ( ) . unwrap ( )
118
- }
119
-
120
- /// Returns the number of ports.
121
- #[ must_use]
122
- pub fn number_of_ports ( self ) -> u8 {
123
- self . 0 . get_bits ( 24 ..=31 ) . try_into ( ) . unwrap ( )
124
- }
107
+ ro_field ! ( 0 ..=7 , number_of_device_slots, "Number of Device Slots" , u8 ) ;
108
+ ro_field ! ( 8 ..=18 , number_of_interrupts, "Number of Interrupts" , u16 ) ;
109
+ ro_field ! ( 24 ..=31 , number_of_ports, "Number of Ports" , u8 ) ;
125
110
}
126
111
impl_debug_from_methods ! {
127
112
StructuralParameters1 {
@@ -136,11 +121,12 @@ impl_debug_from_methods! {
136
121
#[ derive( Copy , Clone ) ]
137
122
pub struct StructuralParameters2 ( u32 ) ;
138
123
impl StructuralParameters2 {
139
- /// Returns the value of the Isochronous Scheduling Threshold field.
140
- #[ must_use]
141
- pub fn isochronous_scheduling_threshold ( self ) -> u8 {
142
- self . 0 . get_bits ( 0 ..=3 ) . try_into ( ) . unwrap ( )
143
- }
124
+ ro_field ! (
125
+ 0 ..=3 ,
126
+ isochronous_scheduling_threshold,
127
+ "Isochronous Scheduling Threshold" ,
128
+ u8
129
+ ) ;
144
130
145
131
/// Returns the maximum number of the elements the Event Ring Segment Table can contain.
146
132
///
@@ -188,17 +174,13 @@ impl_debug_from_methods! {
188
174
#[ derive( Copy , Clone ) ]
189
175
pub struct StructuralParameters3 ( u32 ) ;
190
176
impl StructuralParameters3 {
191
- /// Returns the value of the U1 Device Exit Latency field.
192
- #[ must_use]
193
- pub fn u1_device_exit_latency ( self ) -> u8 {
194
- self . 0 . get_bits ( 0 ..=7 ) . try_into ( ) . unwrap ( )
195
- }
196
-
197
- /// Returns the value of the U2 Device Exit Latency field.
198
- #[ must_use]
199
- pub fn u2_device_exit_latency ( self ) -> u16 {
200
- self . 0 . get_bits ( 16 ..=31 ) . try_into ( ) . unwrap ( )
201
- }
177
+ ro_field ! ( 0 ..=7 , u1_device_exit_latency, "U1 Device Exit Latency" , u8 ) ;
178
+ ro_field ! (
179
+ 16 ..=31 ,
180
+ u2_device_exit_latency,
181
+ "U2 Device Exit Latency" ,
182
+ u16
183
+ ) ;
202
184
}
203
185
impl_debug_from_methods ! {
204
186
StructuralParameters3 {
@@ -237,20 +219,18 @@ impl CapabilityParameters1 {
237
219
contiguous_frame_id_capability,
238
220
"Contiguous Frame ID Capability"
239
221
) ;
240
-
241
- /// Returns the value of the Maximum Primary Stream Array Size field.
242
- #[ must_use]
243
- pub fn maximum_primary_stream_array_size ( self ) -> u8 {
244
- self . 0 . get_bits ( 12 ..=15 ) . try_into ( ) . unwrap ( )
245
- }
246
-
247
- /// Returns the offset of the xHCI extended capability list from the MMIO base. If this value is
248
- /// zero, the list does not exist.
249
- /// The base address can be calculated by `(MMIO base) + (xECP) << 2`
250
- #[ must_use]
251
- pub fn xhci_extended_capabilities_pointer ( self ) -> u16 {
252
- self . 0 . get_bits ( 16 ..=31 ) . try_into ( ) . unwrap ( )
253
- }
222
+ ro_field ! (
223
+ 12 ..=15 ,
224
+ maximum_primary_stream_array_size,
225
+ "Maximum Primary Stream Array Size" ,
226
+ u8
227
+ ) ;
228
+ ro_field ! (
229
+ 16 ..=31 ,
230
+ xhci_extended_capabilities_pointer,
231
+ "xHCI Extended Capabilities Pointer" ,
232
+ u16
233
+ ) ;
254
234
}
255
235
impl_debug_from_methods ! {
256
236
CapabilityParameters1 {
0 commit comments