@@ -12,6 +12,7 @@ use crate::{
1212 Device , //
1313 } ,
1414 devres:: Devres ,
15+ impl_flags,
1516 io:: {
1617 self ,
1718 resource:: {
@@ -22,7 +23,6 @@ use crate::{
2223 IoRaw , //
2324 } ,
2425 prelude:: * ,
25- types:: declare_flags_type, //
2626} ;
2727
2828/// An IO request for a specific device and resource.
@@ -288,35 +288,36 @@ impl<const SIZE: usize> Deref for IoMem<SIZE> {
288288 }
289289}
290290
291- declare_flags_type ! {
291+ impl_flags ! (
292292 /// Flags to be used when remapping memory.
293- ///
294- /// They can be combined with the operators `|`, `&`, and `!`.
295- pub struct MemFlags ( crate :: ffi:: c_ulong) = 0 ;
296- }
297-
298- impl MemFlags {
299- /// Matches the default mapping for System RAM on the architecture.
300- ///
301- /// This is usually a read-allocate write-back cache. Moreover, if this flag is specified and
302- /// the requested remap region is RAM, memremap() will bypass establishing a new mapping and
303- /// instead return a pointer into the direct map.
304- pub const WB : MemFlags = MemFlags ( bindings:: MEMREMAP_WB as _ ) ;
305-
306- /// Establish a mapping whereby writes either bypass the cache or are written through to memory
307- /// and never exist in a cache-dirty state with respect to program visibility.
308- ///
309- /// Attempts to map System RAM with this mapping type will fail.
310- pub const WT : MemFlags = MemFlags ( bindings:: MEMREMAP_WT as _ ) ;
311- /// Establish a writecombine mapping, whereby writes may be coalesced together (e.g. in the
312- /// CPU's write buffers), but is otherwise uncached.
313- ///
314- /// Attempts to map System RAM with this mapping type will fail.
315- pub const WC : MemFlags = MemFlags ( bindings:: MEMREMAP_WC as _ ) ;
316-
317- // Note: Skipping MEMREMAP_ENC/DEC since they are under-documented and have zero
318- // users outside of arch/x86.
319- }
293+ #[ derive( Debug , Clone , Default , Copy , PartialEq , Eq ) ]
294+ pub struct MemFlags ( usize ) ;
295+
296+ /// Enum mirroring the C MEMREMAP_* eum values
297+ #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
298+ pub enum MemFlag {
299+ /// Matches the default mapping for System RAM on the architecture.
300+ ///
301+ /// This is usually a read-allocate write-back cache. Moreover, if this flag is specified and
302+ /// the requested remap region is RAM, memremap() will bypass establishing a new mapping and
303+ /// instead return a pointer into the direct map.
304+ WB = bindings:: MEMREMAP_WB as usize ,
305+
306+ /// Establish a mapping whereby writes either bypass the cache or are written through to memory
307+ /// and never exist in a cache-dirty state with respect to program visibility.
308+ ///
309+ /// Attempts to map System RAM with this mapping type will fail.
310+ WT = bindings:: MEMREMAP_WT as usize ,
311+
312+ /// Establish a writecombine mapping, whereby writes may be coalesced together (e.g. in the
313+ /// CPU's write buffers), but is otherwise uncached.
314+ ///
315+ /// Attempts to map System RAM with this mapping type will fail.
316+ WC = bindings:: MEMREMAP_WC as usize ,
317+ // Note: Skipping MEMREMAP_ENC/DEC since they are under-documented and have zero
318+ // users outside of arch/x86.
319+ }
320+ ) ;
320321
321322/// Represents a non-MMIO memory block. This is like [`IoMem`], but for cases where it is known
322323/// that the resource being mapped does not have I/O side effects.
@@ -337,19 +338,19 @@ impl Mem {
337338 /// to a different address.
338339 ///
339340 /// If multiple caching flags are specified, the different mapping types will be attempted in
340- /// the order [`MemFlags ::WB`], [`MemFlags ::WT`], [`MemFlags ::WC`].
341+ /// the order [`MemFlag ::WB`], [`MemFlag ::WT`], [`MemFlag ::WC`].
341342 ///
342343 /// # Flags
343344 ///
344- /// * [`MemFlags ::WB`]: Matches the default mapping for System RAM on the architecture.
345+ /// * [`MemFlag ::WB`]: Matches the default mapping for System RAM on the architecture.
345346 /// This is usually a read-allocate write-back cache. Moreover, if this flag is specified and
346347 /// the requested remap region is RAM, memremap() will bypass establishing a new mapping and
347348 /// instead return a pointer into the direct map.
348349 ///
349- /// * [`MemFlags ::WT`]: Establish a mapping whereby writes either bypass the cache or are written
350+ /// * [`MemFlag ::WT`]: Establish a mapping whereby writes either bypass the cache or are written
350351 /// through to memory and never exist in a cache-dirty state with respect to program visibility.
351352 /// Attempts to map System RAM with this mapping type will fail.
352- /// * [`MemFlags ::WC`]: Establish a writecombine mapping, whereby writes may be coalesced together
353+ /// * [`MemFlag ::WC`]: Establish a writecombine mapping, whereby writes may be coalesced together
353354 /// (e.g. in the CPU's write buffers), but is otherwise uncached. Attempts to map System RAM with
354355 /// this mapping type will fail.
355356 ///
@@ -361,7 +362,7 @@ impl Mem {
361362 pub unsafe fn try_new ( res : Resource , flags : MemFlags ) -> Result < Self > {
362363 let size: usize = res. size ( ) . try_into ( ) ?;
363364
364- let addr = unsafe { bindings:: memremap ( res. start ( ) , size, flags. as_raw ( ) ) } ;
365+ let addr = unsafe { bindings:: memremap ( res. start ( ) , size, flags. into ( ) ) } ;
365366 let ptr = NonNull :: new ( addr) . ok_or ( ENOMEM ) ?;
366367 // INVARIANT: `ptr` is non-null and was returned by `memremap`, so it is valid.
367368 Ok ( Self { ptr, size } )
0 commit comments