Closes T154: pmap, kernel: Add support for write-combining on ia32/64
authorMoritz Hoffmann <moritz.hoffmann@inf.ethz.ch>
Thu, 13 Aug 2015 13:40:33 +0000 (15:40 +0200)
committerMoritz Hoffmann <moritz.hoffmann@inf.ethz.ch>
Thu, 13 Aug 2015 13:45:19 +0000 (15:45 +0200)
Signed-off-by: Moritz Hoffmann <moritz.hoffmann@inf.ethz.ch>

include/barrelfish/vregion.h
kernel/arch/x86/startup_x86.c
kernel/arch/x86_32/init.c
kernel/arch/x86_64/init.c
kernel/include/arch/x86/startup_x86.h
lib/barrelfish/target/x86_32/pmap_target.c
lib/barrelfish/target/x86_64/pmap_target.c

index 6d2ef56..48c6f4b 100644 (file)
@@ -30,7 +30,8 @@ __BEGIN_DECLS
 // XXX: figure out how to do this arch-independent(?) -SG, 2014-06-16
 #define VREGION_FLAGS_LARGE    0x40 // Map large pages, if possible
 #define VREGION_FLAGS_HUGE     0x80 // Map huge pages, if possible
-#define VREGION_FLAGS_MASK     0xff // Mask of all individual VREGION_FLAGS
+#define VREGION_FLAGS_WRITE_COMBINING   0x100 // Write-combining caching
+#define VREGION_FLAGS_MASK     0x1ff // Mask of all individual VREGION_FLAGS
 
 #define VREGION_FLAGS_READ_WRITE \
     (VREGION_FLAGS_READ | VREGION_FLAGS_WRITE)
index 616fe96..2b37549 100644 (file)
@@ -38,6 +38,7 @@
 #include <arch/x86/apic.h>
 #include <target/x86/barrelfish_kpi/coredata_target.h>
 #include <arch/x86/startup_x86.h>
+#include <dev/ia32_dev.h>
 
 #ifdef __scc__
 #       include <rck.h>
@@ -632,3 +633,24 @@ void kernel_startup(void)
     //}
     panic("Error spawning init!");
 }
+
+/*
+ * Configure the IA32_PAT_MSR register such that PA4 is write-combining and
+ * PA5 is write-protect.
+ */
+void configure_page_attribute_table(void)
+{
+    ia32_t ia32;
+    ia32_cr_pat_t pat;
+
+    ia32_initialize(&ia32);
+
+    pat = ia32_cr_pat_rd(&ia32);
+
+    pat = ia32_cr_pat_pa4_insert(pat, ia32_wc);
+    pat = ia32_cr_pat_pa5_insert(pat, ia32_wp);
+
+    ia32_cr_pat_wr(&ia32, pat);
+
+    debug(SUBSYS_STARTUP, "Configured IA32_PAT_MSR.\n");
+}
index 37b083d..c051949 100644 (file)
@@ -582,6 +582,9 @@ static void  __attribute__ ((noreturn, noinline)) text_init(void)
     // Check/Enable MONITOR/MWAIT opcodes
     enable_monitor_mwait();
 
+    // Setup Page Attribute Table MSR
+    configure_page_attribute_table();
+
     // Call main kernel startup function -- this should never return
     kernel_startup();
 
index 7a8b5c9..2ac940d 100644 (file)
@@ -532,6 +532,9 @@ static void  __attribute__ ((noreturn, noinline)) text_init(void)
     // Check/Enable MONITOR/MWAIT opcodes
     enable_monitor_mwait();
 
+    // Setup Page Attribute Table MSR
+    configure_page_attribute_table();
+
     // Call main kernel startup function -- this should never return
     kernel_startup();
 
index 926da14..19de999 100644 (file)
@@ -69,4 +69,6 @@ static inline void start_ap_signal(void)
     *ap_wait = AP_STARTED;
 }
 
+void configure_page_attribute_table(void);
+
 #endif // __STARTUP_X86_H
index 90ed6c5..d44bf44 100644 (file)
@@ -57,6 +57,10 @@ static paging_x86_32_flags_t vregion_to_pmap_flag(vregion_flags_t vregion_flags)
         if (vregion_flags & VREGION_FLAGS_NOCACHE) {
             pmap_flags |= X86_32_PTABLE_CACHE_DISABLED;
         }
+        else if (vregion_flags & VREGION_FLAGS_WRITE_COMBINING) {
+            // PA4 is configured as write-combining
+            pmap_flags |= PTABLE_ATTR_INDEX;
+        }
 #ifdef __scc__
         if (vregion_flags & VREGION_FLAGS_MPB) {
             pmap_flags |= SCC_PTABLE_MESSAGE_BUFFER;
index a0802d9..345c2de 100644 (file)
@@ -56,6 +56,10 @@ static paging_x86_64_flags_t vregion_to_pmap_flag(vregion_flags_t vregion_flags)
         if (vregion_flags & VREGION_FLAGS_NOCACHE) {
             pmap_flags |= PTABLE_CACHE_DISABLED;
         }
+        else if (vregion_flags & VREGION_FLAGS_WRITE_COMBINING) {
+            // PA4 is configured as write-combining
+            pmap_flags |= PTABLE_ATTR_INDEX;
+        }
     }
 
     return pmap_flags;