From 0036d2fa62f001554d7bf5f36195ba2a3854b59d Mon Sep 17 00:00:00 2001 From: Moritz Hoffmann Date: Thu, 13 Aug 2015 15:40:33 +0200 Subject: [PATCH] Closes T154: pmap, kernel: Add support for write-combining on ia32/64 Signed-off-by: Moritz Hoffmann --- include/barrelfish/vregion.h | 3 ++- kernel/arch/x86/startup_x86.c | 22 ++++++++++++++++++++++ kernel/arch/x86_32/init.c | 3 +++ kernel/arch/x86_64/init.c | 3 +++ kernel/include/arch/x86/startup_x86.h | 2 ++ lib/barrelfish/target/x86_32/pmap_target.c | 4 ++++ lib/barrelfish/target/x86_64/pmap_target.c | 4 ++++ 7 files changed, 40 insertions(+), 1 deletions(-) diff --git a/include/barrelfish/vregion.h b/include/barrelfish/vregion.h index 6d2ef56..48c6f4b 100644 --- a/include/barrelfish/vregion.h +++ b/include/barrelfish/vregion.h @@ -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) diff --git a/kernel/arch/x86/startup_x86.c b/kernel/arch/x86/startup_x86.c index 616fe96..2b37549 100644 --- a/kernel/arch/x86/startup_x86.c +++ b/kernel/arch/x86/startup_x86.c @@ -38,6 +38,7 @@ #include #include #include +#include #ifdef __scc__ # include @@ -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"); +} diff --git a/kernel/arch/x86_32/init.c b/kernel/arch/x86_32/init.c index 37b083d..c051949 100644 --- a/kernel/arch/x86_32/init.c +++ b/kernel/arch/x86_32/init.c @@ -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(); diff --git a/kernel/arch/x86_64/init.c b/kernel/arch/x86_64/init.c index 7a8b5c9..2ac940d 100644 --- a/kernel/arch/x86_64/init.c +++ b/kernel/arch/x86_64/init.c @@ -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(); diff --git a/kernel/include/arch/x86/startup_x86.h b/kernel/include/arch/x86/startup_x86.h index 926da14..19de999 100644 --- a/kernel/include/arch/x86/startup_x86.h +++ b/kernel/include/arch/x86/startup_x86.h @@ -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 diff --git a/lib/barrelfish/target/x86_32/pmap_target.c b/lib/barrelfish/target/x86_32/pmap_target.c index 90ed6c5..d44bf44 100644 --- a/lib/barrelfish/target/x86_32/pmap_target.c +++ b/lib/barrelfish/target/x86_32/pmap_target.c @@ -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; diff --git a/lib/barrelfish/target/x86_64/pmap_target.c b/lib/barrelfish/target/x86_64/pmap_target.c index a0802d9..345c2de 100644 --- a/lib/barrelfish/target/x86_64/pmap_target.c +++ b/lib/barrelfish/target/x86_64/pmap_target.c @@ -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; -- 1.7.2.5