@@ -123,12 +123,12 @@ impl Pat {
123
123
pub const DEFAULT : [ PatMemoryType ; 8 ] = [
124
124
PatMemoryType :: WriteBack ,
125
125
PatMemoryType :: WriteThrough ,
126
- PatMemoryType :: Uncached ,
127
126
PatMemoryType :: Uncacheable ,
127
+ PatMemoryType :: StrongUncacheable ,
128
128
PatMemoryType :: WriteBack ,
129
129
PatMemoryType :: WriteThrough ,
130
- PatMemoryType :: Uncached ,
131
130
PatMemoryType :: Uncacheable ,
131
+ PatMemoryType :: StrongUncacheable ,
132
132
] ;
133
133
}
134
134
@@ -185,29 +185,29 @@ bitflags! {
185
185
/// Memory types used in the [PAT](Pat).
186
186
#[ repr( u8 ) ]
187
187
pub enum PatMemoryType {
188
- /// Disables caching .
189
- Uncacheable = 0x00 ,
190
- /// Uses a write combining cache policy.
188
+ /// Uncacheable (UC) .
189
+ StrongUncacheable = 0x00 ,
190
+ /// Uses a write combining (WC) cache policy.
191
191
WriteCombining = 0x01 ,
192
- /// Uses a write through cache policy.
192
+ /// Uses a write through (WT) cache policy.
193
193
WriteThrough = 0x04 ,
194
- /// Uses a write protected cache policy.
194
+ /// Uses a write protected (WP) cache policy.
195
195
WriteProtected = 0x05 ,
196
- /// Uses a write back cache policy.
196
+ /// Uses a write back (WB) cache policy.
197
197
WriteBack = 0x06 ,
198
- /// Same as uncacheable, but can be overridden by MTRRs.
199
- Uncached = 0x07 ,
198
+ /// Same as strong uncacheable, but can be overridden to be write combining by MTRRs (UC-) .
199
+ Uncacheable = 0x07 ,
200
200
}
201
201
impl PatMemoryType {
202
202
/// Converts from bits, returning `None` if the value is invalid.
203
203
pub const fn from_bits ( bits : u8 ) -> Option < Self > {
204
204
match bits {
205
- 0x00 => Some ( Self :: Uncacheable ) ,
205
+ 0x00 => Some ( Self :: StrongUncacheable ) ,
206
206
0x01 => Some ( Self :: WriteCombining ) ,
207
207
0x04 => Some ( Self :: WriteThrough ) ,
208
208
0x05 => Some ( Self :: WriteProtected ) ,
209
209
0x06 => Some ( Self :: WriteBack ) ,
210
- 0x07 => Some ( Self :: Uncached ) ,
210
+ 0x07 => Some ( Self :: Uncacheable ) ,
211
211
_ => None ,
212
212
}
213
213
}
@@ -701,12 +701,9 @@ mod x86_64 {
701
701
/// occur. Support can be detected using the `cpuid` instruction.
702
702
#[ inline]
703
703
pub fn read ( ) -> [ PatMemoryType ; 8 ] {
704
- let bits = unsafe { Self :: MSR . read ( ) } ;
705
- let mut flags = [ PatMemoryType :: Uncacheable ; 8 ] ;
706
- for ( i, flag) in flags. iter_mut ( ) . enumerate ( ) {
707
- * flag = PatMemoryType :: from_bits ( ( bits >> ( 8 * i) ) as u8 ) . unwrap ( ) ;
708
- }
709
- flags
704
+ unsafe { Self :: MSR . read ( ) }
705
+ . to_ne_bytes ( )
706
+ . map ( |bits| PatMemoryType :: from_bits ( bits) . unwrap ( ) )
710
707
}
711
708
712
709
/// Writes IA32_PAT.
@@ -721,10 +718,7 @@ mod x86_64 {
721
718
/// type.
722
719
#[ inline]
723
720
pub unsafe fn write ( table : [ PatMemoryType ; 8 ] ) {
724
- let mut bits = 0u64 ;
725
- for ( i, flag) in table. iter ( ) . enumerate ( ) {
726
- bits |= ( flag. bits ( ) as u64 ) << ( 8 * i) ;
727
- }
721
+ let bits = u64:: from_ne_bytes ( table. map ( PatMemoryType :: bits) ) ;
728
722
let mut msr = Self :: MSR ;
729
723
unsafe {
730
724
msr. write ( bits) ;
0 commit comments