mtrr/x86/drivers: bury MTRR
Subsystems (34)
cover mtrr/x86/drivers: bury MTRR
From: "Luis R. Rodriguez" <[email protected]>
When a system has PAT support enabled you don't need to be using MTRRs. Andy had added arch_phys_wc_add() long ago to help with this but not all drivers were converted over. We have to take care to only convert drivers where we know that the proper ioremap_wc() API has been used. Doing this requires a bit of work on verifying the driver split out the ioremap'd areas -- and if not doing that ourselves. Verifying a driver uses the same areas can be hard but with a bit of love Coccinelle can help with that.
We're motivated to change drivers for a few reasons:
1) Take advantage of PAT when available
2) Help with the goal of eventually using _PAGE_CACHE_UC over _PAGE_CACHE_UC_MINUS on x86 on ioremap_nocache() (de33c442e)
3) Bury MTRR code away from drivers as it is architecture specific
While working on the conversion I noticed a few things.
a) Run time disabling of MTRR
Some systems can technically have both PAT and MTRR enabled and even if they support it, a system may end up not enabling MTRR. There are a few reasons why this can happen but the code right now doesn't address this well. This leads to another point: PAT code right now is not a first class citizen on x86 -- pat_init() depends on MTRR code so we can't actually enable PAT without building MTRR. Doing this requires quite a bit more work so let this serve as a starting point for conversation if we want to address that.
b) Driver work and required ioremap split
In order to take advantage of PAT device drivers that were using MTRR must make sure that the area that was using MTRR is ioremap'd separately. Fortunately a lot of drivers already do this, but there's quite a bit of drivers that require some love to get that happen. This leaves us needing to expose an last resort API to annotate this and also avoid a regression on performance for systems that may have PAT but can't yet move away from using MTRR. To find the drivers that need love check out __arch_phys_wc_add(). For a good example driver where the work was done refer to the atyfb driver fixes.
c) Missing APIs for write-combining
There's a few API calls missing to take advantage of write-combining, this series add those.
d) Further framebuffer driver MTRR usage simplication
We can simplify MTRR usage by having the framebuffer core add the MTRR by passing a flag when register_framebuffer() is called, this could for instance be done on very few drivers where the smem_len and smem_start are both used for the ioremap_wc() and also for the arch_phys_wc_add(). Coccinelle can be easily used to do a transformation here. I didn't do that here given that it does not work for all device drivers *and* DRM drivers already have something similar. Lastly this technically could also be done on some other generic helper --- but figured its best we review that here. One reason to *not* do this is that tons of framebuffer drivers have mtrr options exposed -- we'd need to generalize those and provide a port ... or deal with the fact that we are going to remove all that.
Luis R. Rodriguez (47):
x86: mtrr: annotate mtrr_type_lookup() is only implemented on
generic_mtrr_ops
x86: mtrr: generalize run time disabling of MTRR
devres: add devm_ioremap_wc()
pci: add pci_ioremap_wc_bar()
pci: add pci_iomap_wc() variants
mtrr: add __arch_phys_wc_add()
video: fbdev: atyfb: move framebuffer length fudging to helper
video: fbdev: atyfb: clarify ioremap() base and length used
vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around
video: fbdev: atyfb: use arch_phys_wc_add() and ioremap_wc() IB/qib: add acounting for MTRR
IB/qib: use arch_phys_wc_add()
IB/ipath: add counting for MTRR
IB/ipath: use __arch_phys_wc_add()
[media] media: ivtv: use __arch_phys_wc_add()
fusion: use __arch_phys_wc_add()
video: fbdev: vesafb: only support MTRR_TYPE_WRCOMB
vidoe: fbdev: vesafb: add missing mtrr_del() for added MTRR
video: fbdev: vesafb: use arch_phys_wc_add()
mtrr: avoid ifdef'ery with phys_wc_to_mtrr_index()
ethernet: myri10ge: use arch_phys_wc_add()
staging: sm750fb: use arch_phys_wc_add() and ioremap_wc()
staging: xgifb: use arch_phys_wc_add() and ioremap_wc()
video: fbdev: arkfb: use arch_phys_wc_add() and pci_iomap_wc()
video: fbdev: radeonfb: use arch_phys_wc_add() and ioremap_wc()
video: fbdev: gbefb: add missing mtrr_del() calls
video: fbdev: gbefb: use arch_phys_wc_add() and devm_ioremap_wc()
video: fbdev: intelfb: use arch_phys_wc_add() and ioremap_wc()
video: fbdev: matrox: use arch_phys_wc_add() and ioremap_wc()
video: fbdev: neofb: use arch_phys_wc_add() and ioremap_wc()
video: fbdev: s3fb: use arch_phys_wc_add() and pci_iomap_wc()
video: fbdev: nvidia: use arch_phys_wc_add() and ioremap_wc()
video: fbdev: savagefb: use arch_phys_wc_add() and ioremap_wc()
video: fbdev: sisfb: use arch_phys_wc_add() and ioremap_wc()
video: fbdev: aty: use arch_phys_wc_add() and ioremap_wc()
video: fbdev: i810: use arch_phys_wc_add() and ioremap_wc()
video: fbdev: i740fb: use arch_phys_wc_add() and pci_ioremap_wc_bar()
video: fbdev: kyrofb: use arch_phys_wc_add() and pci_ioremap_wc_bar()
video: fbdev: pm2fb: use arch_phys_wc_add() and ioremap_wc()
video: fbdev: pm3fb: use arch_phys_wc_add() and ioremap_wc()
video: fbdev: rivafb: use arch_phys_wc_add() and ioremap_wc()
video: fbdev: tdfxfb: use arch_phys_wc_add() and ioremap_wc()
video: fbdev: vt8623fb: use arch_phys_wc_add() and pci_iomap_wc()
video: fbdev: atmel_lcdfb: use ioremap_wc() for framebuffer
video: fbdev: geode gxfb: use ioremap_wc() for framebuffer
video: fbdev: gxt4500: use pci_ioremap_wc_bar() for framebuffer
mtrr: bury MTRR - unexport mtrr_add() and mtrr_del()
Documentation/driver-model/devres.txt | 1 + arch/x86/include/asm/io.h | 6 ++ arch/x86/include/asm/mtrr.h | 7 +- arch/x86/kernel/cpu/mtrr/cleanup.c | 2 +- arch/x86/kernel/cpu/mtrr/generic.c | 7 +- arch/x86/kernel/cpu/mtrr/if.c | 3 + arch/x86/kernel/cpu/mtrr/main.c | 73 +++++++++++++------ drivers/gpu/drm/drm_ioctl.c | 14 +--- drivers/infiniband/hw/ipath/ipath_driver.c | 7 +- drivers/infiniband/hw/ipath/ipath_kernel.h | 4 +- drivers/infiniband/hw/ipath/ipath_wc_x86_64.c | 47 +++++-------- drivers/infiniband/hw/qib/qib_wc_x86_64.c | 31 ++------ drivers/media/pci/ivtv/ivtvfb.c | 51 ++++---------- drivers/message/fusion/mptbase.c | 19 ++--- drivers/message/fusion/mptbase.h | 2 +- drivers/net/ethernet/myricom/myri10ge/myri10ge.c | 36 +++------- drivers/pci/pci.c | 14 ++++ drivers/staging/sm750fb/sm750.c | 34 ++------- drivers/staging/sm750fb/sm750.h | 3 - drivers/staging/sm750fb/sm750_hw.c | 3 +- drivers/staging/xgifb/XGI_main_26.c | 27 ++----- drivers/video/fbdev/arkfb.c | 36 ++-------- drivers/video/fbdev/atmel_lcdfb.c | 3 +- drivers/video/fbdev/aty/aty128fb.c | 36 ++-------- drivers/video/fbdev/aty/atyfb.h | 5 +- drivers/video/fbdev/aty/atyfb_base.c | 90 ++++++++---------------- drivers/video/fbdev/aty/radeon_base.c | 29 ++------ drivers/video/fbdev/aty/radeonfb.h | 2 +- drivers/video/fbdev/gbefb.c | 18 +++-- drivers/video/fbdev/geode/gxfb_core.c | 3 +- drivers/video/fbdev/gxt4500.c | 2 +- drivers/video/fbdev/i740fb.c | 35 ++------- drivers/video/fbdev/i810/i810.h | 3 +- drivers/video/fbdev/i810/i810_main.c | 11 +-- drivers/video/fbdev/i810/i810_main.h | 26 ------- drivers/video/fbdev/intelfb/intelfb.h | 4 +- drivers/video/fbdev/intelfb/intelfbdrv.c | 38 ++-------- drivers/video/fbdev/kyro/fbdev.c | 33 +++------ drivers/video/fbdev/matrox/matroxfb_base.c | 36 ++++------ drivers/video/fbdev/matrox/matroxfb_base.h | 27 +------ drivers/video/fbdev/neofb.c | 26 ++----- drivers/video/fbdev/nvidia/nv_type.h | 7 +- drivers/video/fbdev/nvidia/nvidia.c | 37 ++-------- drivers/video/fbdev/pm2fb.c | 31 ++------ drivers/video/fbdev/pm3fb.c | 30 ++------ drivers/video/fbdev/riva/fbdev.c | 39 ++-------- drivers/video/fbdev/riva/rivafb.h | 4 +- drivers/video/fbdev/s3fb.c | 35 ++------- drivers/video/fbdev/savage/savagefb.h | 4 +- drivers/video/fbdev/savage/savagefb_driver.c | 17 +---- drivers/video/fbdev/sis/sis.h | 2 +- drivers/video/fbdev/sis/sis_main.c | 27 ++----- drivers/video/fbdev/tdfxfb.c | 41 ++--------- drivers/video/fbdev/vesafb.c | 77 +++++++------------- drivers/video/fbdev/vt8623fb.c | 31 ++------ include/asm-generic/pci_iomap.h | 14 ++++ include/linux/io.h | 12 ++++ include/linux/pci.h | 1 + include/video/kyro.h | 4 +- include/video/neomagic.h | 5 +- include/video/tdfx.h | 2 +- lib/devres.c | 29 ++++++++ lib/pci_iomap.c | 61 ++++++++++++++++ 63 files changed, 463 insertions(+), 901 deletions(-)
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
PATCH 1/47 x86: mtrr: annotate mtrr_type_lookup() is only implemented on generic_mtrr_ops
From: "Luis R. Rodriguez" <[email protected]>
There area few users of mtrr_type_lookup(), including PAT. Note that PAT can be in theory enabled without MTRR fully kicking in, such is the case with Xen.
--- arch/x86/kernel/cpu/mtrr/generic.c | 2 ++ 1 file changed, 2 insertions(+)
arch/x86/kernel/cpu/mtrr/generic.c +2 -0
@@ -230,6 +230,8 @@ u8 mtrr_type_lookup(u64 start, u64 end)int repeat;u64 partial_end; +/* XXX: Currently only implemented on generic_mtrr_ops */ + type =__mtrr_type_lookup (start, end, &partial_end, &repeat);/*
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
PATCH 2/47 x86: mtrr: generalize run time disabling of MTRR
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
It is possible to enable CONFIG_MTRR and up with it disabled at run time and yet CONFIG_X86_PAT continues to kick through fully functionally. This can happen for instance on Xen where MTRR is not supported but PAT is, this can happen now on Linux as of commit 47591df50 by Juergen introduced as of v3.19.
Technically we should assume the proper CPU bits would be set to disable MTRR but we can't always rely on this. At least on the Xen Hypervisor for instance only X86_FEATURE_MTRR was disabled as of Xen 4.4 through Xen commit 586ab6a [0], but not X86_FEATURE_K6_MTRR, X86_FEATURE_CENTAUR_MCR, or X86_FEATURE_CYRIX_ARR for instance.
x86 mtrr code relies on quite a bit of checks for mtrr_if being set to check to see if MTRR did get set up, instead of using that lets provide a generic setter which when set we know MTRR is enabled. This also adds a few checks where they were not before which could potentially safeguard ourselves against incorrect usage of MTRR where this was not desirable.
Where possible match error codes as if MTRR was disabled on arch/x86/include/asm/mtrr.h.
Lastly, since disabling MTRR can happen at run time and we could end up with PAT enabled best record now on our logs when MTRR is disabled.
[0] ~/devel/xen (git::stable-4.5)$ git describe --contains 586ab6a 4.4.0-rc1~18
--- arch/x86/include/asm/mtrr.h | 2 ++ arch/x86/kernel/cpu/mtrr/cleanup.c | 2 +- arch/x86/kernel/cpu/mtrr/generic.c | 5 +++-- arch/x86/kernel/cpu/mtrr/if.c | 3 +++ arch/x86/kernel/cpu/mtrr/main.c | 31 ++++++++++++++++++++++--------- 5 files changed, 31 insertions(+), 12 deletions(-)
arch/x86/include/asm/mtrr.h +2 -0
@@ -31,6 +31,7 @@* arch_phys_wc_add and arch_phys_wc_del. */ # ifdef CONFIG_MTRR +extern int mtrr_enabled;extern u8 mtrr_type_lookup (u64 addr,u64 end);extern void mtrr_save_fixed_ranges (void *);extern void mtrr_save_state (void );
@@ -50,6 +51,7 @@ extern int mtrr_trim_uncached_memory(unsigned long end_pfn);extern int amd_special_default_mtrr (void );extern int phys_wc_to_mtrr_index (int handle);# else +static const int mtrr_enabled;static inline u8 mtrr_type_lookup (u64 addr,u64 end) {/*
arch/x86/kernel/cpu/mtrr/cleanup.c +1 -1
@@ -880,7 +880,7 @@ int __init mtrr_trim_uncached_memory(unsigned long end_pfn)* Make sure we only trim uncachable memory on machines that * support the Intel MTRR architecture: */ -if (!is_cpu (INTEL ) || disable_mtrr_trim) +if (!is_cpu (INTEL ) || disable_mtrr_trim || !mtrr_enabled)return 0 ;rdmsr (MSR_MTRRdefType, def, dummy);
arch/x86/kernel/cpu/mtrr/generic.c +3 -2
@@ -116,7 +116,8 @@ static u8 __mtrr_type_lookup(u64 start, u64 end, u64 *partial_end, int *repeat)u8 prev_match, curr_match; *repeat =0 ; -if (!mtrr_state_set) +/* generic_mtrr_ops is only set for generic_mtrr_ops */ +if (!mtrr_state_set || !mtrr_enabled)return 0xFF ;if (!mtrr_state.enabled)
@@ -290,7 +291,7 @@ static void get_fixed_ranges(mtrr_type *frs)void mtrr_save_fixed_ranges (void *info) { -if (cpu_has_mtrr) +if (mtrr_enabled && cpu_has_mtrr)get_fixed_ranges (mtrr_state.fixed_ranges); }
arch/x86/kernel/cpu/mtrr/if.c +3 -0
@@ -436,6 +436,9 @@ static int __init mtrr_if_init(void) {struct cpuinfo_x86 *c = &boot_cpu_data; +if (!mtrr_enabled) +return 0 ; + if ((!cpu_has(c, X86_FEATURE_MTRR)) && (!cpu_has(c, X86_FEATURE_K6_MTRR)) && (!cpu_has(c, X86_FEATURE_CYRIX_ARR)) &&
arch/x86/kernel/cpu/mtrr/main.c +22 -9
@@ -59,6 +59,7 @@#define MTRR_TO_PHYS_WC_OFFSET 1000u32 num_var_ranges; +int mtrr_enabled;unsigned int mtrr_usage_table[MTRR_MAX_VAR_RANGES ];static DEFINE_MUTEX (mtrr_mutex);
@@ -84,6 +85,9 @@ static int have_wrcomb(void) {struct pci_dev *dev; +if (!mtrr_enabled) +return 0 ; + dev =pci_get_class (PCI_CLASS_BRIDGE_HOST <<8 ,NULL );if (dev !=NULL ) {/*
@@ -286,7 +290,7 @@ int mtrr_add_page(unsigned long base, unsigned long size,int i, replace, error;mtrr_type ltype; -if (!mtrr_if) +if (!mtrr_enabled)return -ENXIO ; error = mtrr_if->validate_add_page (base, size, type);
@@ -388,6 +392,8 @@ int mtrr_add_page(unsigned long base, unsigned long size,static int mtrr_check (unsigned long base,unsigned long size) { +if (!mtrr_enabled) +return -ENODEV ;if ((base & (PAGE_SIZE -1 )) || (size & (PAGE_SIZE -1 ))) {pr_warning ("mtrr: size and base must be multiples of 4 kiB\n" );pr_debug ("mtrr: size: 0x%lx base: 0x%lx\n" , size, base);
@@ -463,8 +469,8 @@ int mtrr_del_page(int reg, unsigned long base, unsigned long size)unsigned long lbase, lsize;int error = -EINVAL ; -if (!mtrr_if) -return -ENXIO ; +if (!mtrr_enabled) +return -ENODEV ; max = num_var_ranges;/* No CPU hotplug when we change MTRR entries */
@@ -523,6 +529,8 @@ int mtrr_del_page(int reg, unsigned long base, unsigned long size)*/ int mtrr_del (int reg,unsigned long base,unsigned long size) { +if (!mtrr_enabled) +return -ENODEV ;if (mtrr_check (base, size))return -EINVAL ;return mtrr_del_page (reg, base >>PAGE_SHIFT , size >>PAGE_SHIFT );
@@ -545,7 +553,7 @@ int arch_phys_wc_add(unsigned long base, unsigned long size) {int ret; -if (pat_enabled) +if (pat_enabled || !mtrr_enabled)return 0 ;/* Success! (We don't need to do anything.) */ ret =mtrr_add (base, size,MTRR_TYPE_WRCOMB , true);
@@ -734,6 +742,7 @@ void __init mtrr_bp_init(void) }if (mtrr_if) { + mtrr_enabled = true;set_num_var_ranges ();init_table ();if (use_intel ()) {
@@ -744,12 +753,13 @@ void __init mtrr_bp_init(void) mtrr_if->set_all (); } } - } + }else +pr_info ("mtrr: system does not support MTRR\n" ); }void mtrr_ap_init (void ) { -if (!use_intel () || mtrr_aps_delayed_init) +if (!use_intel () || mtrr_aps_delayed_init || !mtrr_enabled)return ;/* * Ideally we should hold mtrr_mutex here to avoid mtrr entries
@@ -774,6 +784,9 @@ void mtrr_save_state(void) {int first_cpu; +if (!mtrr_enabled) +return ; +get_online_cpus (); first_cpu =cpumask_first (cpu_online_mask);smp_call_function_single (first_cpu, mtrr_save_fixed_ranges,NULL ,1 );
@@ -782,7 +795,7 @@ void mtrr_save_state(void)void set_mtrr_aps_delayed_init (void ) { -if (!use_intel ()) +if (!use_intel () || !mtrr_enabled)return ; mtrr_aps_delayed_init = true;
@@ -810,7 +823,7 @@ void mtrr_aps_init(void)void mtrr_bp_restore (void ) { -if (!use_intel ()) +if (!use_intel () || !mtrr_enabled)return ; mtrr_if->set_all ();
@@ -818,7 +831,7 @@ void mtrr_bp_restore(void)static int __init mtrr_init_finialize (void ) { -if (!mtrr_if) +if (!mtrr_enabled)return 0 ;if (use_intel ()) {
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
Re: [PATCH v1 02/47] x86: mtrr: generalize run time disabling of MTRR
Quoted 5 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
It is possible to enable
CONFIG_MTRRand up with it disabled at run time and yetCONFIG_X86_PATcontinues to kick through fully functionally. This can happen
s/fully/full/ ?
Quoted 3 lines
for instance on Xen where MTRR is not supported but PAT is, this can happen now on Linux as of commit
47591df50by Juergen introduced as of v3.19.
s/3.19/4.0/
Quoted 8 lines
Technically we should assume the proper CPU bits would be set to disable MTRR but we can't always rely on this. At least on the Xen Hypervisor for instance only
X86_FEATURE_MTRRwas disabled as of Xen 4.4 through Xen commit 586ab6a [0], but notX86_FEATURE_K6_MTRR,X86_FEATURE_CENTAUR_MCR, orX86_FEATURE_CYRIX_ARRfor instance.
Oh, could you send an patch for that to Xen please?
Quoted 5 lines
x86 mtrr code relies on quite a bit of checks for
mtrr_ifbeing set to check to see if MTRR did get set up, instead of using that lets provide a generic setter which when set we know MTRR is enabled. This
s/we know MTRR is enabled/will let us know that MTRR is enabled/
Quoted 195 lines
also adds a few checks where they were not before which could potentially safeguard ourselves against incorrect usage of MTRR where this was not desirable.
Where possible match error codes as if MTRR was disabled on
arch/x86/include/asm/mtrr.h.Lastly, since disabling MTRR can happen at run time and we could end up with PAT enabled best record now on our logs when MTRR is disabled.
[0] ~/devel/xen (git::stable-4.5)$ git describe --contains 586ab6a 4.4.0-rc1~18
Cc Andy Lutomirski <[email protected]>Cc Suresh Siddha <[email protected]>Cc Venkatesh Pallipadi <[email protected]>Cc Ingo Molnar <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Juergen Gross <[email protected]>Cc Daniel Vetter <[email protected]>Cc Dave Airlie <[email protected]>Cc Antonino Daplas <[email protected]>Cc Jean-Christophe Plagniol-Villard <[email protected]>Cc Tomi Valkeinen <[email protected]>Cc Dave Hansen <[email protected]>Cc Stefan Bader <[email protected]>Cc Roger Pau Monné <[email protected]>Signed-off-by Luis R. Rodriguez <[email protected]>--- arch/x86/include/asm/mtrr.h | 2 ++ arch/x86/kernel/cpu/mtrr/cleanup.c | 2 +- arch/x86/kernel/cpu/mtrr/generic.c | 5 +++-- arch/x86/kernel/cpu/mtrr/if.c | 3 +++ arch/x86/kernel/cpu/mtrr/main.c | 31 ++++++++++++++++++++++--------- 5 files changed, 31 insertions(+), 12 deletions(-)arch/x86/include/asm/mtrr.h +2
-0@@ -31,6 +31,7 @@* arch_phys_wc_add and arch_phys_wc_del. */ # ifdef CONFIG_MTRR +extern int mtrr_enabled;extern u8 mtrr_type_lookup (u64 addr,u64 end);extern void mtrr_save_fixed_ranges (void *);extern void mtrr_save_state (void );@@ -50,6 +51,7 @@ extern int mtrr_trim_uncached_memory(unsigned long end_pfn);extern int amd_special_default_mtrr (void );extern int phys_wc_to_mtrr_index (int handle);# else +static const int mtrr_enabled;static inline u8 mtrr_type_lookup (u64 addr,u64 end) {/* arch/x86/kernel/cpu/mtrr/cleanup.c +1
-1@@ -880,7 +880,7 @@ int __init mtrr_trim_uncached_memory(unsigned long end_pfn)* Make sure we only trim uncachable memory on machines that * support the Intel MTRR architecture: */ -if (!is_cpu (INTEL ) || disable_mtrr_trim) +if (!is_cpu (INTEL ) || disable_mtrr_trim || !mtrr_enabled)return 0 ;rdmsr (MSR_MTRRdefType, def, dummy);arch/x86/kernel/cpu/mtrr/generic.c +3
-2@@ -116,7 +116,8 @@ static u8 __mtrr_type_lookup(u64 start, u64 end, u64 *partial_end, int *repeat)u8 prev_match, curr_match; *repeat =0 ; -if (!mtrr_state_set) +/* generic_mtrr_ops is only set for generic_mtrr_ops */ +if (!mtrr_state_set || !mtrr_enabled)return 0xFF ;if (!mtrr_state.enabled)@@ -290,7 +291,7 @@ static void get_fixed_ranges(mtrr_type *frs)void mtrr_save_fixed_ranges (void *info) { -if (cpu_has_mtrr) +if (mtrr_enabled && cpu_has_mtrr)get_fixed_ranges (mtrr_state.fixed_ranges); }arch/x86/kernel/cpu/mtrr/if.c +3
-0@@ -436,6 +436,9 @@ static int __init mtrr_if_init(void) {struct cpuinfo_x86 *c = &boot_cpu_data; +if (!mtrr_enabled) +return 0 ; + if ((!cpu_has(c, X86_FEATURE_MTRR)) && (!cpu_has(c, X86_FEATURE_K6_MTRR)) && (!cpu_has(c, X86_FEATURE_CYRIX_ARR)) &&arch/x86/kernel/cpu/mtrr/main.c +13
-4@@ -59,6 +59,7 @@#define MTRR_TO_PHYS_WC_OFFSET 1000u32 num_var_ranges; +int mtrr_enabled;unsigned int mtrr_usage_table[MTRR_MAX_VAR_RANGES ];static DEFINE_MUTEX (mtrr_mutex);@@ -84,6 +85,9 @@ static int have_wrcomb(void) {struct pci_dev *dev; +if (!mtrr_enabled) +return 0 ; + dev =pci_get_class (PCI_CLASS_BRIDGE_HOST <<8 ,NULL );if (dev !=NULL ) {/* @@ -286,7 +290,7 @@ int mtrr_add_page(unsigned long base, unsigned long size,int i, replace, error;mtrr_type ltype; -if (!mtrr_if) +if (!mtrr_enabled)return -ENXIO ; error = mtrr_if->validate_add_page (base, size, type);@@ -388,6 +392,8 @@ int mtrr_add_page(unsigned long base, unsigned long size,static int mtrr_check (unsigned long base,unsigned long size) { +if (!mtrr_enabled) +return -ENODEV ;if ((base & (PAGE_SIZE -1 )) || (size & (PAGE_SIZE -1 ))) {pr_warning ("mtrr: size and base must be multiples of 4 kiB\n" );pr_debug ("mtrr: size: 0x%lx base: 0x%lx\n" , size, base);@@ -463,8 +469,8 @@ int mtrr_del_page(int reg, unsigned long base, unsigned long size)unsigned long lbase, lsize;int error = -EINVAL ; -if (!mtrr_if) -return -ENXIO ; +if (!mtrr_enabled) +return -ENODEV ; max = num_var_ranges;/* No CPU hotplug when we change MTRR entries */ @@ -523,6 +529,8 @@ int mtrr_del_page(int reg, unsigned long base, unsigned long size)*/ int mtrr_del (int reg,unsigned long base,unsigned long size) { +if (!mtrr_enabled) +return -ENODEV ;if (mtrr_check (base, size))return -EINVAL ;return mtrr_del_page (reg, base >>PAGE_SHIFT , size >>PAGE_SHIFT );@@ -545,7 +553,7 @@ int arch_phys_wc_add(unsigned long base, unsigned long size) {int ret; -if (pat_enabled) +if (pat_enabled || !mtrr_enabled)return 0 ;/* Success! (We don't need to do anything.) */ ret =mtrr_add (base, size,MTRR_TYPE_WRCOMB , true);@@ -734,6 +742,7 @@ void __init mtrr_bp_init(void) }if (mtrr_if) { + mtrr_enabled = true;set_num_var_ranges ();init_table ();if (use_intel ()) {
arch/x86/kernel/cpu/mtrr/main.c void __init mtrr_bp_init(void) · line 757
Quoted 6 lines
arch/x86/kernel/cpu/mtrr/main.c +2
-1@@ -744,12 +753,13 @@ void __init mtrr_bp_init(void) mtrr_if->set_all (); } } - } + }else +pr_info ("mtrr: system does not support MTRR\n" );
'pr_warn' ?
Quoted 49 lines
arch/x86/kernel/cpu/mtrr/main.c +7
-4}void mtrr_ap_init (void ) { -if (!use_intel () || mtrr_aps_delayed_init) +if (!use_intel () || mtrr_aps_delayed_init || !mtrr_enabled)return ;/* * Ideally we should hold mtrr_mutex here to avoid mtrr entries @@ -774,6 +784,9 @@ void mtrr_save_state(void) {int first_cpu; +if (!mtrr_enabled) +return ; +get_online_cpus (); first_cpu =cpumask_first (cpu_online_mask);smp_call_function_single (first_cpu, mtrr_save_fixed_ranges,NULL ,1 );@@ -782,7 +795,7 @@ void mtrr_save_state(void)void set_mtrr_aps_delayed_init (void ) { -if (!use_intel ()) +if (!use_intel () || !mtrr_enabled)return ; mtrr_aps_delayed_init = true;@@ -810,7 +823,7 @@ void mtrr_aps_init(void)void mtrr_bp_restore (void ) { -if (!use_intel ()) +if (!use_intel () || !mtrr_enabled)return ; mtrr_if->set_all ();@@ -818,7 +831,7 @@ void mtrr_bp_restore(void)static int __init mtrr_init_finialize (void ) { -if (!mtrr_if) +if (!mtrr_enabled)return 0 ;if (use_intel ()) {Signature · 1 line
2.3.2.209.gd67f9d5.dirty
Re: [PATCH v1 02/47] x86: mtrr: generalize run time disabling of MTRR
Quoted 7 lines · Konrad Rzeszutek Wilk
Quoted 5 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
It is possible to enable
CONFIG_MTRRand up with it disabled at run time and yetCONFIG_X86_PATcontinues to kick through fully functionally. This can happen
Quoted 8 lines
s/fully/full/ ?
Quoted 3 lines
for instance on Xen where MTRR is not supported but PAT is, this can happen now on Linux as of commit
47591df50by Juergen introduced as of v3.19.s/3.19/4.0/
No, 3.19 is correct.
Juergen
Quoted 277 lines
Quoted 8 lines
Technically we should assume the proper CPU bits would be set to disable MTRR but we can't always rely on this. At least on the Xen Hypervisor for instance only
X86_FEATURE_MTRRwas disabled as of Xen 4.4 through Xen commit 586ab6a [0], but notX86_FEATURE_K6_MTRR,X86_FEATURE_CENTAUR_MCR, orX86_FEATURE_CYRIX_ARRfor instance.Oh, could you send an patch for that to Xen please?
Quoted 5 lines
x86 mtrr code relies on quite a bit of checks for
mtrr_ifbeing set to check to see if MTRR did get set up, instead of using that lets provide a generic setter which when set we know MTRR is enabled. Thiss/we know MTRR is enabled/will let us know that MTRR is enabled/
Quoted 195 lines
also adds a few checks where they were not before which could potentially safeguard ourselves against incorrect usage of MTRR where this was not desirable.
Where possible match error codes as if MTRR was disabled on
arch/x86/include/asm/mtrr.h.Lastly, since disabling MTRR can happen at run time and we could end up with PAT enabled best record now on our logs when MTRR is disabled.
[0] ~/devel/xen (git::stable-4.5)$ git describe --contains 586ab6a 4.4.0-rc1~18
Cc Andy Lutomirski <[email protected]>Cc Suresh Siddha <[email protected]>Cc Venkatesh Pallipadi <[email protected]>Cc Ingo Molnar <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Juergen Gross <[email protected]>Cc Daniel Vetter <[email protected]>Cc Dave Airlie <[email protected]>Cc Antonino Daplas <[email protected]>Cc Jean-Christophe Plagniol-Villard <[email protected]>Cc Tomi Valkeinen <[email protected]>Cc Dave Hansen <[email protected]>Cc Stefan Bader <[email protected]>Cc Roger Pau Monné <[email protected]>Signed-off-by Luis R. Rodriguez <[email protected]>--- arch/x86/include/asm/mtrr.h | 2 ++ arch/x86/kernel/cpu/mtrr/cleanup.c | 2 +- arch/x86/kernel/cpu/mtrr/generic.c | 5 +++-- arch/x86/kernel/cpu/mtrr/if.c | 3 +++ arch/x86/kernel/cpu/mtrr/main.c | 31 ++++++++++++++++++++++--------- 5 files changed, 31 insertions(+), 12 deletions(-)arch/x86/include/asm/mtrr.h +2
-0@@ -31,6 +31,7 @@* arch_phys_wc_add and arch_phys_wc_del. */ # ifdef CONFIG_MTRR +extern int mtrr_enabled;extern u8 mtrr_type_lookup (u64 addr,u64 end);extern void mtrr_save_fixed_ranges (void *);extern void mtrr_save_state (void );@@ -50,6 +51,7 @@ extern int mtrr_trim_uncached_memory(unsigned long end_pfn);extern int amd_special_default_mtrr (void );extern int phys_wc_to_mtrr_index (int handle);# else +static const int mtrr_enabled;static inline u8 mtrr_type_lookup (u64 addr,u64 end) {/* arch/x86/kernel/cpu/mtrr/cleanup.c +1
-1@@ -880,7 +880,7 @@ int __init mtrr_trim_uncached_memory(unsigned long end_pfn)* Make sure we only trim uncachable memory on machines that * support the Intel MTRR architecture: */ -if (!is_cpu (INTEL ) || disable_mtrr_trim) +if (!is_cpu (INTEL ) || disable_mtrr_trim || !mtrr_enabled)return 0 ;rdmsr (MSR_MTRRdefType, def, dummy);arch/x86/kernel/cpu/mtrr/generic.c +3
-2@@ -116,7 +116,8 @@ static u8 __mtrr_type_lookup(u64 start, u64 end, u64 *partial_end, int *repeat)u8 prev_match, curr_match; *repeat =0 ; -if (!mtrr_state_set) +/* generic_mtrr_ops is only set for generic_mtrr_ops */ +if (!mtrr_state_set || !mtrr_enabled)return 0xFF ;if (!mtrr_state.enabled)@@ -290,7 +291,7 @@ static void get_fixed_ranges(mtrr_type *frs)void mtrr_save_fixed_ranges (void *info) { -if (cpu_has_mtrr) +if (mtrr_enabled && cpu_has_mtrr)get_fixed_ranges (mtrr_state.fixed_ranges); }arch/x86/kernel/cpu/mtrr/if.c +3
-0@@ -436,6 +436,9 @@ static int __init mtrr_if_init(void) {struct cpuinfo_x86 *c = &boot_cpu_data; +if (!mtrr_enabled) +return 0 ; + if ((!cpu_has(c, X86_FEATURE_MTRR)) && (!cpu_has(c, X86_FEATURE_K6_MTRR)) && (!cpu_has(c, X86_FEATURE_CYRIX_ARR)) &&arch/x86/kernel/cpu/mtrr/main.c +13
-4@@ -59,6 +59,7 @@#define MTRR_TO_PHYS_WC_OFFSET 1000u32 num_var_ranges; +int mtrr_enabled;unsigned int mtrr_usage_table[MTRR_MAX_VAR_RANGES ];static DEFINE_MUTEX (mtrr_mutex);@@ -84,6 +85,9 @@ static int have_wrcomb(void) {struct pci_dev *dev; +if (!mtrr_enabled) +return 0 ; + dev =pci_get_class (PCI_CLASS_BRIDGE_HOST <<8 ,NULL );if (dev !=NULL ) {/* @@ -286,7 +290,7 @@ int mtrr_add_page(unsigned long base, unsigned long size,int i, replace, error;mtrr_type ltype; -if (!mtrr_if) +if (!mtrr_enabled)return -ENXIO ; error = mtrr_if->validate_add_page (base, size, type);@@ -388,6 +392,8 @@ int mtrr_add_page(unsigned long base, unsigned long size,static int mtrr_check (unsigned long base,unsigned long size) { +if (!mtrr_enabled) +return -ENODEV ;if ((base & (PAGE_SIZE -1 )) || (size & (PAGE_SIZE -1 ))) {pr_warning ("mtrr: size and base must be multiples of 4 kiB\n" );pr_debug ("mtrr: size: 0x%lx base: 0x%lx\n" , size, base);@@ -463,8 +469,8 @@ int mtrr_del_page(int reg, unsigned long base, unsigned long size)unsigned long lbase, lsize;int error = -EINVAL ; -if (!mtrr_if) -return -ENXIO ; +if (!mtrr_enabled) +return -ENODEV ; max = num_var_ranges;/* No CPU hotplug when we change MTRR entries */ @@ -523,6 +529,8 @@ int mtrr_del_page(int reg, unsigned long base, unsigned long size)*/ int mtrr_del (int reg,unsigned long base,unsigned long size) { +if (!mtrr_enabled) +return -ENODEV ;if (mtrr_check (base, size))return -EINVAL ;return mtrr_del_page (reg, base >>PAGE_SHIFT , size >>PAGE_SHIFT );@@ -545,7 +553,7 @@ int arch_phys_wc_add(unsigned long base, unsigned long size) {int ret; -if (pat_enabled) +if (pat_enabled || !mtrr_enabled)return 0 ;/* Success! (We don't need to do anything.) */ ret =mtrr_add (base, size,MTRR_TYPE_WRCOMB , true);@@ -734,6 +742,7 @@ void __init mtrr_bp_init(void) }if (mtrr_if) { + mtrr_enabled = true;set_num_var_ranges ();init_table ();if (use_intel ()) {arch/x86/kernel/cpu/mtrr/main.c void __init mtrr_bp_init(void) · line 757
Quoted 6 lines
arch/x86/kernel/cpu/mtrr/main.c +2
-1@@ -744,12 +753,13 @@ void __init mtrr_bp_init(void) mtrr_if->set_all (); } } - } + }else +pr_info ("mtrr: system does not support MTRR\n" );'
pr_warn' ?Quoted 47 lines
arch/x86/kernel/cpu/mtrr/main.c +7
-5}void mtrr_ap_init (void ) { -if (!use_intel () || mtrr_aps_delayed_init) +if (!use_intel () || mtrr_aps_delayed_init || !mtrr_enabled)return ;/* * Ideally we should hold mtrr_mutex here to avoid mtrr entries @@ -774,6 +784,9 @@ void mtrr_save_state(void) {int first_cpu; +if (!mtrr_enabled) +return ; +get_online_cpus (); first_cpu =cpumask_first (cpu_online_mask);smp_call_function_single (first_cpu, mtrr_save_fixed_ranges,NULL ,1 );@@ -782,7 +795,7 @@ void mtrr_save_state(void)void set_mtrr_aps_delayed_init (void ) { -if (!use_intel ()) +if (!use_intel () || !mtrr_enabled)return ; mtrr_aps_delayed_init = true;@@ -810,7 +823,7 @@ void mtrr_aps_init(void)void mtrr_bp_restore (void ) { -if (!use_intel ()) +if (!use_intel () || !mtrr_enabled)return ; mtrr_if->set_all ();@@ -818,7 +831,7 @@ void mtrr_bp_restore(void)static int __init mtrr_init_finialize (void ) { -if (!mtrr_if) +if (!mtrr_enabled)return 0 ;if (use_intel ()) { --Quoted 2 lines
2.3.2.209.gd67f9d5.dirty
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v1 02/47] x86: mtrr: generalize run time disabling of MTRR
In reply to Konrad Rzeszutek WilkQuoted 8 lines · Konrad Rzeszutek Wilk
Quoted 5 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
It is possible to enable
CONFIG_MTRRand up with it disabled at run time and yetCONFIG_X86_PATcontinues to kick through fully functionally. This can happens/fully/full/ ?
I'll rephrase this to:
---
It is possible to enable CONFIG_MTRR and up with it disabled at run time and yet CONFIG_X86_PAT continues to kick through with all functionally enabled. This can happen for instance on Xen where MTRR is not supported but PAT is, this can happen now on Linux as of commit 47591df50 by Juergen introduced as of v3.19.
---
Which BTW I had also mentioned on the cover letter that this is a good time to address if we want to make PAT then a first class citizen, to detangle it from depending on MTRR. If so I can do that later.
Quoted 9 lines
Quoted 7 lines
Technically we should assume the proper CPU bits would be set to disable MTRR but we can't always rely on this. At least on the Xen Hypervisor for instance only
X86_FEATURE_MTRRwas disabled as of Xen 4.4 through Xen commit 586ab6a [0], but notX86_FEATURE_K6_MTRR,X86_FEATURE_CENTAUR_MCR, orX86_FEATURE_CYRIX_ARRfor instance.Oh, could you send an patch for that to Xen please?
Done.
Quoted 6 lines
Quoted 4 lines
x86 mtrr code relies on quite a bit of checks for
mtrr_ifbeing set to check to see if MTRR did get set up, instead of using that lets provide a generic setter which when set we know MTRR is enabled. Thiss/we know MTRR is enabled/will let us know that MTRR is enabled/
Amended.
Luis
Bjorn Helgaas
maintainerRe: [PATCH v1 02/47] x86: mtrr: generalize run time disabling of MTRR
Quoted 9 lines · Luis R. Rodriguez
I'll rephrase this to:
---
It is possible to enableCONFIG_MTRRand up with it disabled at run time and yetCONFIG_X86_PATcontinues to kick through with all functionally enabled. This can happen for instance on Xen where MTRR is not supported but PAT is, this can happen now on Linux as of commit47591df50by Juergen introduced as of v3.19.
I still can't parse this. What does "up with it disabled at run time" mean? And "... continues to kick through"? Probably some idiomatic usage I'm just too old to understand :)
Please use the conventional citation format:
47591df50512 ("xen: Support Xen pv-domains using PAT")
A one-character typo in a SHA1 makes it completely useless, so it's nice to have the summary line both for readability and a bit of redundancy.
Bjorn
Re: [PATCH v1 02/47] x86: mtrr: generalize run time disabling of MTRR
Quoted 13 lines · Bjorn Helgaas
Quoted 9 lines · Luis R. Rodriguez
I'll rephrase this to:
---
It is possible to enableCONFIG_MTRRand up with it disabled at run time and yetCONFIG_X86_PATcontinues to kick through with all functionally enabled. This can happen for instance on Xen where MTRR is not supported but PAT is, this can happen now on Linux as of commit47591df50by Juergen introduced as of v3.19.
Quoted 2 lines
I still can't parse this. What does "up with it disabled at run time" mean?
It means that technically even if your CPU/BIOS/system did support MTRR if you use a kernel with MTRR support enabled you might end up with a situation where under one situation MTRR might be enabled and at another run time scenario with the same exact kernel and system you will end up with MTRR disabled. Such is the case for example when booting with Xen, which disables the CPU bits on the hypervisor code. If you boot the same system without Xen you'll get MTRR.
Quoted 2 lines
And "... continues to kick through"? Probably some idiomatic
usage I'm just too old to understand :)
That means for example that in both the above circumstances even if MTRR went disabled at run time with Xen, the kernel went through with getting PAT enabled.
Quoted 7 lines
Please use the conventional citation format:
47591df50512("xen: Support Xen pv-domains using PAT")A one-character typo in a SHA1 makes it completely useless, so it's nice to have the summary line both for readability and a bit of redundancy.
Sure, fixed.
Luis
Bjorn Helgaas
maintainerRe: [PATCH v1 02/47] x86: mtrr: generalize run time disabling of MTRR
Quoted 17 lines · Luis R. Rodriguez
Quoted 13 lines · Bjorn Helgaas
Quoted 9 lines · Luis R. Rodriguez
I'll rephrase this to:
---
It is possible to enableCONFIG_MTRRand up with it disabled at run time and yetCONFIG_X86_PATcontinues to kick through with all functionally enabled. This can happen for instance on Xen where MTRR is not supported but PAT is, this can happen now on Linux as of commit47591df50by Juergen introduced as of v3.19.Quoted 2 lines
I still can't parse this. What does "up with it disabled at run time" mean?
Quoted 7 lines
It means that technically even if your CPU/BIOS/system did support MTRR if you use a kernel with MTRR support enabled you might end up with a situation where under one situation MTRR might be enabled and at another run time scenario with the same exact kernel and system you will end up with MTRR disabled. Such is the case for example when booting with Xen, which disables the CPU bits on the hypervisor code. If you boot the same system without Xen you'll get MTRR.
Your text is missing some words. You seem to be using "up" as a verb, but it's not a verb. Maybe you meant "end up"? Even then, it wouldn't make sense for CONFIG_MTRR to be "disabled at run time" because CONFIG_MTRR is a compile-time switch. The MTRR *functionality* could certainly be disabled at run-time, but not CONFIG_MTRR itself.
Quoted 6 lines
Quoted 2 lines
And "... continues to kick through"? Probably some idiomatic
usage I'm just too old to understand :)That means for example that in both the above circumstances even if MTRR went disabled at run time with Xen, the kernel went through with getting PAT enabled.
"CONFIG_X86_PAT continues to kick through" doesn't seem a very precise way of describing this. But maybe it's enough for experts in this area (which I'm not).
Bjorn
Re: [PATCH v1 02/47] x86: mtrr: generalize run time disabling of MTRR
Quoted 26 lines · Bjorn Helgaas
Quoted 17 lines · Luis R. Rodriguez
Quoted 13 lines · Bjorn Helgaas
Quoted 9 lines · Luis R. Rodriguez
I'll rephrase this to:
---
It is possible to enableCONFIG_MTRRand up with it disabled at run time and yetCONFIG_X86_PATcontinues to kick through with all functionally enabled. This can happen for instance on Xen where MTRR is not supported but PAT is, this can happen now on Linux as of commit47591df50by Juergen introduced as of v3.19.Quoted 2 lines
I still can't parse this. What does "up with it disabled at run time" mean?
Quoted 7 lines
It means that technically even if your CPU/BIOS/system did support MTRR if you use a kernel with MTRR support enabled you might end up with a situation where under one situation MTRR might be enabled and at another run time scenario with the same exact kernel and system you will end up with MTRR disabled. Such is the case for example when booting with Xen, which disables the CPU bits on the hypervisor code. If you boot the same system without Xen you'll get MTRR.
Quoted 2 lines
Your text is missing some words. You seem to be using "up" as a verb, but it's not a verb. Maybe you meant "end up"?
Indeed.
Quoted 5 lines
Even then, it
wouldn't make sense forCONFIG_MTRRto be "disabled at run time" becauseCONFIG_MTRRis a compile-time switch. The MTRR *functionality* could certainly be disabled at run-time, but notCONFIG_MTRRitself.
I'll clarify.
Quoted 10 lines
Quoted 6 lines
Quoted 2 lines
And "... continues to kick through"? Probably some idiomatic
usage I'm just too old to understand :)That means for example that in both the above circumstances even if MTRR went disabled at run time with Xen, the kernel went through with getting PAT enabled.
"
CONFIG_X86_PATcontinues to kick through" doesn't seem a very precise way of describing this. But maybe it's enough for experts in this area (which I'm not).
I've rephrased this to:
---
It is possible to enable CONFIG_MTRR and CONFIG_X86_PAT and end up with a system with MTRR functionality disabled PAT functionality enabled. This can happen for instance on Xen where MTRR is not supported but PAT is. This can happen on Linux as of commit 47591df50 ("xen: Support Xen pv-domains using PAT") by Juergen, introduced as of v3.19.
---
Luis
Bjorn Helgaas
maintainerRe: [PATCH v1 02/47] x86: mtrr: generalize run time disabling of MTRR
Quoted 4 lines · Luis R. Rodriguez
---
It is possible to enableCONFIG_MTRRandCONFIG_X86_PATand end up with a system with MTRR functionality disabled PAT functionality enabled.
This is missing a conjunction or something in "MTRR functionality disabled PAT functionality."
Bjorn
Re: [Xen-devel] [PATCH v1 02/47] x86: mtrr: generalize run time disabling of MTRR
Quoted 9 lines · Bjorn Helgaas
Quoted 4 lines · Luis R. Rodriguez
---
It is possible to enableCONFIG_MTRRandCONFIG_X86_PATand end up with a system with MTRR functionality disabled PAT functionality enabled.This is missing a conjunction or something in "MTRR functionality disabled PAT functionality."
"and PAT functionality" -- fixed. Thanks.
Luis
Re: [PATCH v1 02/47] x86: mtrr: generalize run time disabling of MTRR
In reply to Luis R. RodriguezOn Fri, 2015-03-20 at 16:17 -0700, Luis R. Rodriguez wrote:
:
arch/x86/kernel/cpu/mtrr/main.c void __init mtrr_bp_init(void) · line 748
Quoted 8 lines
arch/x86/kernel/cpu/mtrr/main.c +1
-0@@ -734,6 +742,7 @@ void __init mtrr_bp_init(void) }if (mtrr_if) { + mtrr_enabled = true;set_num_var_ranges ();init_table ();if (use_intel ()) {
get_mtrr_state();
After setting mtrr_enabled to true, get_mtrr_state() reads MSR_MTRRdefType and sets 'mtrr_state.enabled', which also indicates if MTRRs are enabled or not on the system. So, potentially, we could have a case that mtrr_enabled is set to true, but mtrr_state.enabled is set to disabled when MTRRs are disabled by BIOS.
Thanks,
-Toshi
ps.
I recently cleaned up this part of the MTRR code in the patch below, which is currently available in the -mm & -next trees.
https://lkml.org/lkml/2015/3/24/1063
Re: [PATCH v1 02/47] x86: mtrr: generalize run time disabling of MTRR
Quoted 12 lines · Toshi Kani
On Fri, 2015-03-20 at 16:17 -0700, Luis R. Rodriguez wrote:
:arch/x86/kernel/cpu/mtrr/main.c void __init mtrr_bp_init(void) · line 748
Quoted 8 lines
arch/x86/kernel/cpu/mtrr/main.c +1
-0@@ -734,6 +742,7 @@ void __init mtrr_bp_init(void) }if (mtrr_if) { + mtrr_enabled = true;set_num_var_ranges ();init_table ();if (use_intel ()) {get_mtrr_state();
Quoted 5 lines
After setting
mtrr_enabledto true,get_mtrr_state()readsMSR_MTRRdefTypeand sets 'mtrr_state.enabled', which also indicates if MTRRs are enabled or not on the system. So, potentially, we could have a case thatmtrr_enabledis set to true, but mtrr_state.enabled is set to disabled when MTRRs are disabled by BIOS.
Thanks for the review, in this case then we should update mtrr_enabled to false.
Quoted 4 lines
ps.
I recently cleaned up this part of the MTRR code in the patch below, which is currently available in the -mm & -next trees.
https://lkml.org/lkml/2015/3/24/1063
Great I will rebase and work with that and try to address this consideration you have raised.
Luis
Re: [PATCH v1 02/47] x86: mtrr: generalize run time disabling of MTRR
Quoted 21 lines · Luis R. Rodriguez
Quoted 12 lines · Toshi Kani
On Fri, 2015-03-20 at 16:17 -0700, Luis R. Rodriguez wrote:
:Review void __init mtrr_bp_init(void) · line 748
Quoted 8 lines
(quoted diff) +1
-0@@ -734,6 +742,7 @@ void __init mtrr_bp_init(void) } if (mtrr_if) { + mtrr_enabled = true; set_num_var_ranges(); init_table(); if (use_intel()) {get_mtrr_state();Quoted 5 lines
After setting
mtrr_enabledto true,get_mtrr_state()readsMSR_MTRRdefTypeand sets 'mtrr_state.enabled', which also indicates if MTRRs are enabled or not on the system. So, potentially, we could have a case thatmtrr_enabledis set to true, but mtrr_state.enabled is set to disabled when MTRRs are disabled by BIOS.Thanks for the review, in this case then we should update
mtrr_enabledto false.
Quoted 7 lines
Quoted 4 lines
ps.
I recently cleaned up this part of the MTRR code in the patch below, which is currently available in the -mm & -next trees.
https://lkml.org/lkml/2015/3/24/1063Great I will rebase and work with that and try to address this consideration you have raised.
OK I'll mesh in this change as well in my next respin:
arch/x86/kernel/cpu/mtrr/generic.c +3 -1
@@ -438,7 +438,7 @@ static void __init print_mtrr_state(void) }/* Grab all of the MTRR state for this CPU into *state */ -void __init get_mtrr_state (void ) +bool __init get_mtrr_state (void ) {struct mtrr_var_range *vrs;unsigned long flags;
@@ -482,6 +482,8 @@ void __init get_mtrr_state(void)post_set ();local_irq_restore (flags); + +return !!mtrr_state.enabled; }/* Some BIOS's are messed up and don't set all MTRRs the same! */
arch/x86/kernel/cpu/mtrr/main.c +6 -1
@@ -734,22 +742,25 @@ void __init mtrr_bp_init(void) }if (mtrr_if) { + mtrr_enabled = true;set_num_var_ranges ();init_table ();if (use_intel ()) { -get_mtrr_state (); +/* BIOS may override */ + mtrr_enabled =get_mtrr_state ();if (mtrr_cleanup (phys_addr)) { changed_by_mtrr_cleanup =1 ;
@@ -745,11 +755,14 @@ void __init mtrr_bp_init(void) } } } + +if (!mtrr_enabled) +pr_info ("mtrr: system does not support MTRR\n" ); }
arch/x86/kernel/cpu/mtrr/mtrr.h +1 -1
@@ -51,7 +51,7 @@ void set_mtrr_prepare_save(struct set_mtrr_context *ctxt);void fill_mtrr_var_range (unsigned int index,u32 base_lo,u32 base_hi,u32 mask_lo,u32 mask_hi); -void get_mtrr_state (void ); +bool get_mtrr_state (void );extern void set_mtrr_ops (const struct mtrr_ops *ops);
Re: [PATCH v1 02/47] x86: mtrr: generalize run time disabling of MTRR
Quoted 46 lines · Luis R. Rodriguez
Quoted 21 lines · Luis R. Rodriguez
Quoted 12 lines · Toshi Kani
On Fri, 2015-03-20 at 16:17 -0700, Luis R. Rodriguez wrote:
:arch/x86/kernel/cpu/mtrr/main.c void __init mtrr_bp_init(void) · line 748
Quoted 8 lines
arch/x86/kernel/cpu/mtrr/main.c +1
-0@@ -734,6 +742,7 @@ void __init mtrr_bp_init(void) }if (mtrr_if) { + mtrr_enabled = true;set_num_var_ranges ();init_table ();if (use_intel ()) {get_mtrr_state();Quoted 5 lines
After setting
mtrr_enabledto true,get_mtrr_state()readsMSR_MTRRdefTypeand sets 'mtrr_state.enabled', which also indicates if MTRRs are enabled or not on the system. So, potentially, we could have a case thatmtrr_enabledis set to true, but mtrr_state.enabled is set to disabled when MTRRs are disabled by BIOS.Thanks for the review, in this case then we should update
mtrr_enabledto false.Quoted 7 lines
Quoted 4 lines
ps.
I recently cleaned up this part of the MTRR code in the patch below, which is currently available in the -mm & -next trees.
https://lkml.org/lkml/2015/3/24/1063Great I will rebase and work with that and try to address this consideration you have raised.
OK I'll mesh in this change as well in my next respin:
arch/x86/kernel/cpu/mtrr/generic.c +1
-1@@ -438,7 +438,7 @@ static void __init print_mtrr_state(void) }/* Grab all of the MTRR state for this CPU into *state */ -void __init get_mtrr_state (void ) +bool __init get_mtrr_state (void ) {struct mtrr_var_range *vrs;unsigned long flags;
arch/x86/kernel/cpu/mtrr/generic.c void __init get_mtrr_state(void) · line 486
Quoted 5 lines
arch/x86/kernel/cpu/mtrr/generic.c +2
-0@@ -482,6 +482,8 @@ void __init get_mtrr_state(void)post_set ();local_irq_restore (flags); + +return !!mtrr_state.enabled;
This should be:
return mtrr_state.enabled & MTRR_STATE_MTRR_ENABLED;
because the MTRR_STATE_MTRR_FIXED_ENABLED flag is ignored when the MTRR_STATE_MTRR_ENABLED flag is clear.
Thanks,
-Toshi
Re: [PATCH v1 02/47] x86: mtrr: generalize run time disabling of MTRR
Quoted 54 lines · Toshi Kani
Quoted 46 lines · Luis R. Rodriguez
Quoted 21 lines · Luis R. Rodriguez
Quoted 12 lines · Toshi Kani
On Fri, 2015-03-20 at 16:17 -0700, Luis R. Rodriguez wrote:
:arch/x86/kernel/cpu/mtrr/main.c void __init mtrr_bp_init(void) · line 748
Quoted 8 lines
arch/x86/kernel/cpu/mtrr/main.c +1
-0@@ -734,6 +742,7 @@ void __init mtrr_bp_init(void) }if (mtrr_if) { + mtrr_enabled = true;set_num_var_ranges ();init_table ();if (use_intel ()) {get_mtrr_state();Quoted 5 lines
After setting
mtrr_enabledto true,get_mtrr_state()readsMSR_MTRRdefTypeand sets 'mtrr_state.enabled', which also indicates if MTRRs are enabled or not on the system. So, potentially, we could have a case thatmtrr_enabledis set to true, but mtrr_state.enabled is set to disabled when MTRRs are disabled by BIOS.Thanks for the review, in this case then we should update
mtrr_enabledto false.Quoted 7 lines
Quoted 4 lines
ps.
I recently cleaned up this part of the MTRR code in the patch below, which is currently available in the -mm & -next trees.
https://lkml.org/lkml/2015/3/24/1063Great I will rebase and work with that and try to address this consideration you have raised.
OK I'll mesh in this change as well in my next respin:
arch/x86/kernel/cpu/mtrr/generic.c +1
-1@@ -438,7 +438,7 @@ static void __init print_mtrr_state(void) }/* Grab all of the MTRR state for this CPU into *state */ -void __init get_mtrr_state (void ) +bool __init get_mtrr_state (void ) {struct mtrr_var_range *vrs;unsigned long flags;arch/x86/kernel/cpu/mtrr/generic.c void __init get_mtrr_state(void) · line 486
Quoted 5 lines
arch/x86/kernel/cpu/mtrr/generic.c +2
-0@@ -482,6 +482,8 @@ void __init get_mtrr_state(void)post_set ();local_irq_restore (flags); + +return !!mtrr_state.enabled;This should be:
Quoted 4 lines
return mtrr_state.enabled & MTRR_STATE_MTRR_ENABLED;because the
MTRR_STATE_MTRR_FIXED_ENABLEDflag is ignored when theMTRR_STATE_MTRR_ENABLEDflag is clear.
Thanks, I've used
return !!(mtrr_state.enabled & MTRR_STATE_MTRR_ENABLED);
Amended.
Luis
PATCH 3/47 devres: add devm_ioremap_wc()
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
We have devm_ioremap_nocache() but no devm_ioremap_wc() so add that. This will be used later.
--- Documentation/driver-model/devres.txt | 1 + include/linux/io.h | 2 ++ lib/devres.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+)
Documentation/driver-model/devres.txt +1 -0
@@ -276,6 +276,7 @@ IOMAP devm_ioport_unmap() devm_ioremap() devm_ioremap_nocache() + devm_ioremap_wc() devm_ioremap_resource() : checks resource, requests memory region, ioremaps devm_iounmap() pcim_iomap()
include/linux/io.h +2 -0
@@ -72,6 +72,8 @@ void __iomem *devm_ioremap(struct device *dev, resource_size_t offset, resource_size_t size);void __iomem *devm_ioremap_nocache (struct device *dev,resource_size_t offset,resource_size_t size); +void __iomem *devm_ioremap_wc (struct device *dev,resource_size_t offset, +resource_size_t size);void devm_iounmap (struct device *dev,void __iomem *addr);int check_signature (const volatile void __iomem *io_addr,const unsigned char *signature,int length);
lib/devres.c +29 -0
@@ -72,6 +72,35 @@ void __iomem *devm_ioremap_nocache(struct device *dev, resource_size_t offset,EXPORT_SYMBOL (devm_ioremap_nocache);/** +* devm_ioremap_wc - Managed ioremap_wc() +* @dev: Generic device to remap IO address for +* @offset: BUS offset to map +* @size: Size of map +* +* Managed ioremap_wc(). Map is automatically unmapped on driver +* detach. +*/ +void __iomem *devm_ioremap_wc (struct device *dev,resource_size_t offset, +resource_size_t size) +{ +void __iomem **ptr, *addr; + + ptr =devres_alloc (devm_ioremap_release,sizeof (*ptr),GFP_KERNEL ); +if (!ptr) +return NULL ; + + addr =ioremap_wc (offset, size); +if (addr) { + *ptr = addr; +devres_add (dev, ptr); + }else +devres_free (ptr); + +return addr; +} +EXPORT_SYMBOL_GPL (devm_ioremap_wc); + +/** * devm_iounmap - Managed iounmap() * @dev: Generic device to unmap for * @addr: Address to unmap
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
Re: [PATCH v1 03/47] devres: add devm_ioremap_wc()
Quoted 5 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
We have
devm_ioremap_nocache()but nodevm_ioremap_wc()so add that. This will be used later.
Quoted 14 lines
Cc Suresh Siddha <[email protected]>Cc Venkatesh Pallipadi <[email protected]>Cc Ingo Molnar <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Juergen Gross <[email protected]>Cc Daniel Vetter <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Dave Airlie <[email protected]>Cc Antonino Daplas <[email protected]>Cc Jean-Christophe Plagniol-Villard <[email protected]>Cc Tomi Valkeinen <[email protected]>Signed-off-by Luis R. Rodriguez <[email protected]>
Looks good to me.
Quoted 74 lines
--- Documentation/driver-model/devres.txt | 1 + include/linux/io.h | 2 ++ lib/devres.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+)Documentation/driver-model/devres.txt +1
-0@@ -276,6 +276,7 @@ IOMAP devm_ioport_unmap() devm_ioremap() devm_ioremap_nocache() + devm_ioremap_wc() devm_ioremap_resource() : checks resource, requests memory region, ioremaps devm_iounmap() pcim_iomap()include/linux/io.h +2
-0@@ -72,6 +72,8 @@ void __iomem *devm_ioremap(struct device *dev, resource_size_t offset, resource_size_t size);void __iomem *devm_ioremap_nocache (struct device *dev,resource_size_t offset,resource_size_t size); +void __iomem *devm_ioremap_wc (struct device *dev,resource_size_t offset, +resource_size_t size);void devm_iounmap (struct device *dev,void __iomem *addr);int check_signature (const volatile void __iomem *io_addr,const unsigned char *signature,int length);lib/devres.c +29
-1@@ -72,6 +72,35 @@ void __iomem *devm_ioremap_nocache(struct device *dev, resource_size_t offset,EXPORT_SYMBOL (devm_ioremap_nocache);/** +* devm_ioremap_wc - Managed ioremap_wc() +* @dev: Generic device to remap IO address for +* @offset: BUS offset to map +* @size: Size of map +* +* Managed ioremap_wc(). Map is automatically unmapped on driver +* detach. +*/ +void __iomem *devm_ioremap_wc (struct device *dev,resource_size_t offset, +resource_size_t size) +{ +void __iomem **ptr, *addr; + + ptr =devres_alloc (devm_ioremap_release,sizeof (*ptr),GFP_KERNEL ); +if (!ptr) +return NULL ; + + addr =ioremap_wc (offset, size); +if (addr) { + *ptr = addr; +devres_add (dev, ptr); + }else +devres_free (ptr); + +return addr; +} +EXPORT_SYMBOL_GPL (devm_ioremap_wc); + +/** * devm_iounmap - Managed iounmap() * @dev: Generic device to unmap for * @addr: Address to unmap -- 2.3.2.209.gd67f9d5.dirty
Signature · 2 lines
Andy Lutomirski AMA Capital Management, LLC
Re: [PATCH v1 03/47] devres: add devm_ioremap_wc()
Quoted 22 lines · Andy Lutomirski
Quoted 5 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
We have
devm_ioremap_nocache()but nodevm_ioremap_wc()so add that. This will be used later.Quoted 14 lines
Cc Suresh Siddha <[email protected]>Cc Venkatesh Pallipadi <[email protected]>Cc Ingo Molnar <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Juergen Gross <[email protected]>Cc Daniel Vetter <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Dave Airlie <[email protected]>Cc Antonino Daplas <[email protected]>Cc Jean-Christophe Plagniol-Villard <[email protected]>Cc Tomi Valkeinen <[email protected]>Signed-off-by Luis R. Rodriguez <[email protected]>
Quoted 1 line
Looks good to me.
Thanks, I'll peg a Reviewed-by.
Luis
Re: [PATCH v1 03/47] devres: add devm_ioremap_wc()
In reply to Andy LutomirskiQuoted 22 lines · Andy Lutomirski
Quoted 5 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
We have
devm_ioremap_nocache()but nodevm_ioremap_wc()so add that. This will be used later.Quoted 14 lines
Cc Suresh Siddha <[email protected]>Cc Venkatesh Pallipadi <[email protected]>Cc Ingo Molnar <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Juergen Gross <[email protected]>Cc Daniel Vetter <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Dave Airlie <[email protected]>Cc Antonino Daplas <[email protected]>Cc Jean-Christophe Plagniol-Villard <[email protected]>Cc Tomi Valkeinen <[email protected]>Signed-off-by Luis R. Rodriguez <[email protected]>
Quoted 1 line
Looks good to me.
Thanks, I'll peg a Reviewed-by.
Luis
Re: [PATCH v1 03/47] devres: add devm_ioremap_wc()
In reply to Luis R. RodriguezQuoted 5 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
We have
devm_ioremap_nocache()but nodevm_ioremap_wc()so add that. This will be used later.
Quoted 14 lines
Cc Suresh Siddha <[email protected]>Cc Venkatesh Pallipadi <[email protected]>Cc Ingo Molnar <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Juergen Gross <[email protected]>Cc Daniel Vetter <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Dave Airlie <[email protected]>Cc Antonino Daplas <[email protected]>Cc Jean-Christophe Plagniol-Villard <[email protected]>Cc Tomi Valkeinen <[email protected]>Signed-off-by Luis R. Rodriguez <[email protected]>
Looks good to me.
Quoted 74 lines
--- Documentation/driver-model/devres.txt | 1 + include/linux/io.h | 2 ++ lib/devres.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+)Documentation/driver-model/devres.txt +1
-0@@ -276,6 +276,7 @@ IOMAP devm_ioport_unmap() devm_ioremap() devm_ioremap_nocache() + devm_ioremap_wc() devm_ioremap_resource() : checks resource, requests memory region, ioremaps devm_iounmap() pcim_iomap()include/linux/io.h +2
-0@@ -72,6 +72,8 @@ void __iomem *devm_ioremap(struct device *dev, resource_size_t offset, resource_size_t size);void __iomem *devm_ioremap_nocache (struct device *dev,resource_size_t offset,resource_size_t size); +void __iomem *devm_ioremap_wc (struct device *dev,resource_size_t offset, +resource_size_t size);void devm_iounmap (struct device *dev,void __iomem *addr);int check_signature (const volatile void __iomem *io_addr,const unsigned char *signature,int length);lib/devres.c +29
-1@@ -72,6 +72,35 @@ void __iomem *devm_ioremap_nocache(struct device *dev, resource_size_t offset,EXPORT_SYMBOL (devm_ioremap_nocache);/** +* devm_ioremap_wc - Managed ioremap_wc() +* @dev: Generic device to remap IO address for +* @offset: BUS offset to map +* @size: Size of map +* +* Managed ioremap_wc(). Map is automatically unmapped on driver +* detach. +*/ +void __iomem *devm_ioremap_wc (struct device *dev,resource_size_t offset, +resource_size_t size) +{ +void __iomem **ptr, *addr; + + ptr =devres_alloc (devm_ioremap_release,sizeof (*ptr),GFP_KERNEL ); +if (!ptr) +return NULL ; + + addr =ioremap_wc (offset, size); +if (addr) { + *ptr = addr; +devres_add (dev, ptr); + }else +devres_free (ptr); + +return addr; +} +EXPORT_SYMBOL_GPL (devm_ioremap_wc); + +/** * devm_iounmap - Managed iounmap() * @dev: Generic device to unmap for * @addr: Address to unmap -- 2.3.2.209.gd67f9d5.dirty
Signature · 2 lines
Andy Lutomirski AMA Capital Management, LLC
PATCH 3/47 devres: add devm_ioremap_wc()
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
We have devm_ioremap_nocache() but no devm_ioremap_wc() so add that. This will be used later.
--- Documentation/driver-model/devres.txt | 1 + include/linux/io.h | 2 ++ lib/devres.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+)
Documentation/driver-model/devres.txt +1 -0
@@ -276,6 +276,7 @@ IOMAP devm_ioport_unmap() devm_ioremap() devm_ioremap_nocache() + devm_ioremap_wc() devm_ioremap_resource() : checks resource, requests memory region, ioremaps devm_iounmap() pcim_iomap()
include/linux/io.h +2 -0
@@ -72,6 +72,8 @@ void __iomem *devm_ioremap(struct device *dev, resource_size_t offset, resource_size_t size);void __iomem *devm_ioremap_nocache (struct device *dev,resource_size_t offset,resource_size_t size); +void __iomem *devm_ioremap_wc (struct device *dev,resource_size_t offset, +resource_size_t size);void devm_iounmap (struct device *dev,void __iomem *addr);int check_signature (const volatile void __iomem *io_addr,const unsigned char *signature,int length);
lib/devres.c +29 -0
@@ -72,6 +72,35 @@ void __iomem *devm_ioremap_nocache(struct device *dev, resource_size_t offset,EXPORT_SYMBOL (devm_ioremap_nocache);/** +* devm_ioremap_wc - Managed ioremap_wc() +* @dev: Generic device to remap IO address for +* @offset: BUS offset to map +* @size: Size of map +* +* Managed ioremap_wc(). Map is automatically unmapped on driver +* detach. +*/ +void __iomem *devm_ioremap_wc (struct device *dev,resource_size_t offset, +resource_size_t size) +{ +void __iomem **ptr, *addr; + + ptr =devres_alloc (devm_ioremap_release,sizeof (*ptr),GFP_KERNEL ); +if (!ptr) +return NULL ; + + addr =ioremap_wc (offset, size); +if (addr) { + *ptr = addr; +devres_add (dev, ptr); + }else +devres_free (ptr); + +return addr; +} +EXPORT_SYMBOL_GPL (devm_ioremap_wc); + +/** * devm_iounmap - Managed iounmap() * @dev: Generic device to unmap for * @addr: Address to unmap
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
PATCH 4/47 pci: add pci_ioremap_wc_bar()
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
This lets drivers take advanate of PAT when available. This should help with the transition of converting video drivers over to ioremap_wc() to help with the goal of eventually using _PAGE_CACHE_UC over _PAGE_CACHE_UC_MINUS on x86 on ioremap_nocache() (de33c442e)
--- drivers/pci/pci.c | 14 ++++++++++++++ include/linux/pci.h | 1 + 2 files changed, 15 insertions(+)
drivers/pci/pci.c +14 -0
@@ -137,6 +137,20 @@ void __iomem *pci_ioremap_bar(struct pci_dev *pdev, int bar) pci_resource_len(pdev, bar)); }EXPORT_SYMBOL_GPL (pci_ioremap_bar); + +void __iomem *pci_ioremap_wc_bar (struct pci_dev *pdev,int bar) +{ +/* +* Make sure the BAR is actually a memory resource, not an IO resource +*/ +if (!(pci_resource_flags (pdev, bar) &IORESOURCE_MEM )) { +WARN_ON (1 ); +return NULL ; + } +return ioremap_wc (pci_resource_start (pdev, bar), +pci_resource_len (pdev, bar)); +} +EXPORT_SYMBOL_GPL (pci_ioremap_wc_bar);#endif #define PCI_FIND_CAP_TTL 48
include/linux/pci.h +1 -0
@@ -1667,6 +1667,7 @@ static inline void pci_mmcfg_late_init(void) { }int pci_ext_cfg_avail (void );void __iomem *pci_ioremap_bar (struct pci_dev *pdev,int bar); +void __iomem *pci_ioremap_wc_bar (struct pci_dev *pdev,int bar);#ifdef CONFIG_PCI_IOV int pci_enable_sriov (struct pci_dev *dev,int nr_virtfn);
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
Re: [PATCH v1 04/47] pci: add pci_ioremap_wc_bar()
Quoted 35 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
This lets drivers take advanate of PAT when available. This should help with the transition of converting video drivers over to
ioremap_wc()to help with the goal of eventually using_PAGE_CACHE_UCover_PAGE_CACHE_UC_MINUSon x86 onioremap_nocache()(de33c442e)Cc Suresh Siddha <[email protected]>Cc Venkatesh Pallipadi <[email protected]>Cc Ingo Molnar <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Juergen Gross <[email protected]>Cc Daniel Vetter <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Dave Airlie <[email protected]>Cc Antonino Daplas <[email protected]>Cc Jean-Christophe Plagniol-Villard <[email protected]>Cc Tomi Valkeinen <[email protected]>Signed-off-by Luis R. Rodriguez <[email protected]>--- drivers/pci/pci.c | 14 ++++++++++++++ include/linux/pci.h | 1 + 2 files changed, 15 insertions(+)drivers/pci/pci.c +0
-0@@ -137,6 +137,20 @@ void __iomem *pci_ioremap_bar(struct pci_dev *pdev, int bar) pci_resource_len(pdev, bar)); }EXPORT_SYMBOL_GPL (pci_ioremap_bar);
drivers/pci/pci.c void __iomem *pci_ioremap_bar(struct pci_dev *pdev, int bar) · line 149
Quoted 10 lines
drivers/pci/pci.c +10
-0+ +void __iomem *pci_ioremap_wc_bar (struct pci_dev *pdev,int bar) +{ +/* +* Make sure the BAR is actually a memory resource, not an IO resource +*/ +if (!(pci_resource_flags (pdev, bar) &IORESOURCE_MEM )) { +WARN_ON (1 ); +return NULL ; + }
if (WARN_ON(...))?
--Andy
Re: [PATCH v1 04/47] pci: add pci_ioremap_wc_bar()
Quoted 41 lines · Andy Lutomirski
Quoted 39 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
This lets drivers take advanate of PAT when available. This should help with the transition of converting video drivers over to
ioremap_wc()to help with the goal of eventually using_PAGE_CACHE_UCover_PAGE_CACHE_UC_MINUSon x86 onioremap_nocache()(de33c442e)Cc Suresh Siddha <[email protected]>Cc Venkatesh Pallipadi <[email protected]>Cc Ingo Molnar <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Juergen Gross <[email protected]>Cc Daniel Vetter <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Dave Airlie <[email protected]>Cc Antonino Daplas <[email protected]>Cc Jean-Christophe Plagniol-Villard <[email protected]>Cc Tomi Valkeinen <[email protected]>Signed-off-by Luis R. Rodriguez <[email protected]>--- drivers/pci/pci.c | 14 ++++++++++++++ include/linux/pci.h | 1 + 2 files changed, 15 insertions(+)drivers/pci/pci.c +4
-0@@ -137,6 +137,20 @@ void __iomem *pci_ioremap_bar(struct pci_dev *pdev, int bar) pci_resource_len(pdev, bar)); }EXPORT_SYMBOL_GPL (pci_ioremap_bar); + +void __iomem *pci_ioremap_wc_bar (struct pci_dev *pdev,int bar) +{ +/*
Quoted 8 lines
drivers/pci/pci.c void __iomem *pci_ioremap_bar(struct pci_dev *pdev, int bar) · line 149
Quoted 6 lines
drivers/pci/pci.c +6
-0+* Make sure the BAR is actually a memory resource, not an IO resource +*/ +if (!(pci_resource_flags (pdev, bar) &IORESOURCE_MEM )) { +WARN_ON (1 ); +return NULL ; + }if (
WARN_ON(...))?
Sure, they are equivalent however this follows the same exact style as pci_ioremap_bar() so if we change this one might as well change the style of pci_ioremap_bar() as well. Let me know if there is any preference. I personally don't mind the extra line as it shortens the check.
Luis
Re: [PATCH v1 04/47] pci: add pci_ioremap_wc_bar()
In reply to Andy LutomirskiQuoted 41 lines · Andy Lutomirski
Quoted 39 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
This lets drivers take advanate of PAT when available. This should help with the transition of converting video drivers over to
ioremap_wc()to help with the goal of eventually using_PAGE_CACHE_UCover_PAGE_CACHE_UC_MINUSon x86 onioremap_nocache()(de33c442e)Cc Suresh Siddha <[email protected]>Cc Venkatesh Pallipadi <[email protected]>Cc Ingo Molnar <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Juergen Gross <[email protected]>Cc Daniel Vetter <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Dave Airlie <[email protected]>Cc Antonino Daplas <[email protected]>Cc Jean-Christophe Plagniol-Villard <[email protected]>Cc Tomi Valkeinen <[email protected]>Signed-off-by Luis R. Rodriguez <[email protected]>--- drivers/pci/pci.c | 14 ++++++++++++++ include/linux/pci.h | 1 + 2 files changed, 15 insertions(+)drivers/pci/pci.c +4
-0@@ -137,6 +137,20 @@ void __iomem *pci_ioremap_bar(struct pci_dev *pdev, int bar) pci_resource_len(pdev, bar)); }EXPORT_SYMBOL_GPL (pci_ioremap_bar); + +void __iomem *pci_ioremap_wc_bar (struct pci_dev *pdev,int bar) +{ +/*
Quoted 8 lines
drivers/pci/pci.c void __iomem *pci_ioremap_bar(struct pci_dev *pdev, int bar) · line 149
Quoted 6 lines
drivers/pci/pci.c +6
-0+* Make sure the BAR is actually a memory resource, not an IO resource +*/ +if (!(pci_resource_flags (pdev, bar) &IORESOURCE_MEM )) { +WARN_ON (1 ); +return NULL ; + }if (
WARN_ON(...))?
Sure, they are equivalent however this follows the same exact style as pci_ioremap_bar() so if we change this one might as well change the style of pci_ioremap_bar() as well. Let me know if there is any preference. I personally don't mind the extra line as it shortens the check.
Luis
Re: [PATCH v1 04/47] pci: add pci_ioremap_wc_bar()
In reply to Luis R. RodriguezQuoted 35 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
This lets drivers take advanate of PAT when available. This should help with the transition of converting video drivers over to
ioremap_wc()to help with the goal of eventually using_PAGE_CACHE_UCover_PAGE_CACHE_UC_MINUSon x86 onioremap_nocache()(de33c442e)Cc Suresh Siddha <[email protected]>Cc Venkatesh Pallipadi <[email protected]>Cc Ingo Molnar <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Juergen Gross <[email protected]>Cc Daniel Vetter <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Dave Airlie <[email protected]>Cc Antonino Daplas <[email protected]>Cc Jean-Christophe Plagniol-Villard <[email protected]>Cc Tomi Valkeinen <[email protected]>Signed-off-by Luis R. Rodriguez <[email protected]>--- drivers/pci/pci.c | 14 ++++++++++++++ include/linux/pci.h | 1 + 2 files changed, 15 insertions(+)drivers/pci/pci.c +0
-0@@ -137,6 +137,20 @@ void __iomem *pci_ioremap_bar(struct pci_dev *pdev, int bar) pci_resource_len(pdev, bar)); }EXPORT_SYMBOL_GPL (pci_ioremap_bar);
drivers/pci/pci.c void __iomem *pci_ioremap_bar(struct pci_dev *pdev, int bar) · line 149
Quoted 10 lines
drivers/pci/pci.c +10
-0+ +void __iomem *pci_ioremap_wc_bar (struct pci_dev *pdev,int bar) +{ +/* +* Make sure the BAR is actually a memory resource, not an IO resource +*/ +if (!(pci_resource_flags (pdev, bar) &IORESOURCE_MEM )) { +WARN_ON (1 ); +return NULL ; + }
if (WARN_ON(...))?
--Andy
Re: [Xen-devel] [PATCH v1 04/47] pci: add pci_ioremap_wc_bar()
In reply to Luis R. RodriguezQuoted 3 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
This lets drivers take advanate of PAT when available. This
s/advanate/advantage/
Quoted 4 lines
should help with the transition of converting video drivers over to
ioremap_wc()to help with the goal of eventually using_PAGE_CACHE_UCover_PAGE_CACHE_UC_MINUSon x86 onioremap_nocache()(de33c442e)
Please mention the title of the patch too:
"x86 PAT: fix performance drop for glx, use UC minus for ioremap(), ioremap_nocache() and pci_mmap_page_range()"
Quoted 26 lines
Cc Suresh Siddha <[email protected]>Cc Venkatesh Pallipadi <[email protected]>Cc Ingo Molnar <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Juergen Gross <[email protected]>Cc Daniel Vetter <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Dave Airlie <[email protected]>Cc Antonino Daplas <[email protected]>Cc Jean-Christophe Plagniol-Villard <[email protected]>Cc Tomi Valkeinen <[email protected]>Signed-off-by Luis R. Rodriguez <[email protected]>--- drivers/pci/pci.c | 14 ++++++++++++++ include/linux/pci.h | 1 + 2 files changed, 15 insertions(+)drivers/pci/pci.c +0
-0@@ -137,6 +137,20 @@ void __iomem *pci_ioremap_bar(struct pci_dev *pdev, int bar) pci_resource_len(pdev, bar));
drivers/pci/pci.c void __iomem *pci_ioremap_bar(struct pci_dev *pdev, int bar) · line 147
Quoted 10 lines
drivers/pci/pci.c +8
-0}EXPORT_SYMBOL_GPL (pci_ioremap_bar); + +void __iomem *pci_ioremap_wc_bar (struct pci_dev *pdev,int bar) +{ +/* +* Make sure the BAR is actually a memory resource, not an IO resource +*/ +if (!(pci_resource_flags (pdev, bar) &IORESOURCE_MEM )) { +WARN_ON (1 );
Would it be better to use dev_warn ? That way you can see which BDF it is?
Thought WARN will give a nice stack-trace that should easily point to the driver so perhaps not.. Either way - up to you.
Quoted 29 lines
drivers/pci/pci.c +6
-0+ return NULL; + } +return ioremap_wc (pci_resource_start (pdev, bar), +pci_resource_len (pdev, bar)); +} +EXPORT_SYMBOL_GPL (pci_ioremap_wc_bar);#endif #define PCI_FIND_CAP_TTL 48include/linux/pci.h +1
-0@@ -1667,6 +1667,7 @@ static inline void pci_mmcfg_late_init(void) { }int pci_ext_cfg_avail (void );void __iomem *pci_ioremap_bar (struct pci_dev *pdev,int bar); +void __iomem *pci_ioremap_wc_bar (struct pci_dev *pdev,int bar);#ifdef CONFIG_PCI_IOV int pci_enable_sriov (struct pci_dev *dev,int nr_virtfn);Signature · 7 lines
2.3.2.209.gd67f9d5.dirty _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [Xen-devel] [PATCH v1 04/47] pci: add pci_ioremap_wc_bar()
Quoted 6 lines · Konrad Rzeszutek Wilk
Quoted 3 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
This lets drivers take advanate of PAT when available. This
s/advanate/advantage/
Amended.
Quoted 8 lines
Quoted 4 lines
should help with the transition of converting video drivers over to
ioremap_wc()to help with the goal of eventually using_PAGE_CACHE_UCover_PAGE_CACHE_UC_MINUSon x86 onioremap_nocache()(de33c442e)Please mention the title of the patch too:
"x86 PAT: fix performance drop for glx, use UC minus for
ioremap(),ioremap_nocache()andpci_mmap_page_range()"
Added.
Quoted 39 lines
Quoted 26 lines
Cc Suresh Siddha <[email protected]>Cc Venkatesh Pallipadi <[email protected]>Cc Ingo Molnar <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Juergen Gross <[email protected]>Cc Daniel Vetter <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Dave Airlie <[email protected]>Cc Antonino Daplas <[email protected]>Cc Jean-Christophe Plagniol-Villard <[email protected]>Cc Tomi Valkeinen <[email protected]>Signed-off-by Luis R. Rodriguez <[email protected]>--- drivers/pci/pci.c | 14 ++++++++++++++ include/linux/pci.h | 1 + 2 files changed, 15 insertions(+)drivers/pci/pci.c +0
-0@@ -137,6 +137,20 @@ void __iomem *pci_ioremap_bar(struct pci_dev *pdev, int bar) pci_resource_len(pdev, bar));drivers/pci/pci.c void __iomem *pci_ioremap_bar(struct pci_dev *pdev, int bar) · line 147
Quoted 10 lines
drivers/pci/pci.c +8
-0}EXPORT_SYMBOL_GPL (pci_ioremap_bar); + +void __iomem *pci_ioremap_wc_bar (struct pci_dev *pdev,int bar) +{ +/* +* Make sure the BAR is actually a memory resource, not an IO resource +*/ +if (!(pci_resource_flags (pdev, bar) &IORESOURCE_MEM )) { +WARN_ON (1 );Would it be better to use
dev_warn? That way you can see which BDF it is?
Quoted 2 lines
Thought WARN will give a nice stack-trace that should easily point to the driver so perhaps not.. Either way - up to you.
I'm sticking to the style and use as with pci_ioremap_bar(). Whatever we pick we should make both use the same. More information is always better and since we do have dev_warn(), it would be nice to use that however within its use on both pci_ioremap_wc_bar() and pci_ioremap_bar() we have a use of the pdev with pci_resource_flags() and I believe if pdev is NULL we'd get a NULL dereference (dev_driver_string() is used), so it would seem it might be best to stick with a simple WARN_ON(). Arjan, any preference? Obviously if pdev is NULL your driver is dumb but as folks develop drivers this should be expected.
Luis
Re: [PATCH v1 04/47] pci: add pci_ioremap_wc_bar()
In reply to Konrad Rzeszutek WilkQuoted 6 lines · Konrad Rzeszutek Wilk
Quoted 3 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
This lets drivers take advanate of PAT when available. This
s/advanate/advantage/
Amended.
Quoted 8 lines
Quoted 4 lines
should help with the transition of converting video drivers over to
ioremap_wc()to help with the goal of eventually using_PAGE_CACHE_UCover_PAGE_CACHE_UC_MINUSon x86 onioremap_nocache()(de33c442e)Please mention the title of the patch too:
"x86 PAT: fix performance drop for glx, use UC minus for
ioremap(),ioremap_nocache()andpci_mmap_page_range()"
Added.
Quoted 39 lines
Quoted 26 lines
Cc Suresh Siddha <[email protected]>Cc Venkatesh Pallipadi <[email protected]>Cc Ingo Molnar <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Juergen Gross <[email protected]>Cc Daniel Vetter <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Dave Airlie <[email protected]>Cc Antonino Daplas <[email protected]>Cc Jean-Christophe Plagniol-Villard <[email protected]>Cc Tomi Valkeinen <[email protected]>Signed-off-by Luis R. Rodriguez <[email protected]>--- drivers/pci/pci.c | 14 ++++++++++++++ include/linux/pci.h | 1 + 2 files changed, 15 insertions(+)drivers/pci/pci.c +0
-0@@ -137,6 +137,20 @@ void __iomem *pci_ioremap_bar(struct pci_dev *pdev, int bar) pci_resource_len(pdev, bar));drivers/pci/pci.c void __iomem *pci_ioremap_bar(struct pci_dev *pdev, int bar) · line 147
Quoted 10 lines
drivers/pci/pci.c +8
-0}EXPORT_SYMBOL_GPL (pci_ioremap_bar); + +void __iomem *pci_ioremap_wc_bar (struct pci_dev *pdev,int bar) +{ +/* +* Make sure the BAR is actually a memory resource, not an IO resource +*/ +if (!(pci_resource_flags (pdev, bar) &IORESOURCE_MEM )) { +WARN_ON (1 );Would it be better to use
dev_warn? That way you can see which BDF it is?
Quoted 2 lines
Thought WARN will give a nice stack-trace that should easily point to the driver so perhaps not.. Either way - up to you.
I'm sticking to the style and use as with pci_ioremap_bar(). Whatever we pick we should make both use the same. More information is always better and since we do have dev_warn(), it would be nice to use that however within its use on both pci_ioremap_wc_bar() and pci_ioremap_bar() we have a use of the pdev with pci_resource_flags() and I believe if pdev is NULL we'd get a NULL dereference (dev_driver_string() is used), so it would seem it might be best to stick with a simple WARN_ON(). Arjan, any preference? Obviously if pdev is NULL your driver is dumb but as folks develop drivers this should be expected.
Luis
Re: [PATCH v1 04/47] pci: add pci_ioremap_wc_bar()
In reply to Luis R. RodriguezQuoted 3 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
This lets drivers take advanate of PAT when available. This
s/advanate/advantage/
Quoted 4 lines
should help with the transition of converting video drivers over to
ioremap_wc()to help with the goal of eventually using_PAGE_CACHE_UCover_PAGE_CACHE_UC_MINUSon x86 onioremap_nocache()(de33c442e)
Please mention the title of the patch too:
"x86 PAT: fix performance drop for glx, use UC minus for ioremap(), ioremap_nocache() and pci_mmap_page_range()"
Quoted 26 lines
Cc Suresh Siddha <[email protected]>Cc Venkatesh Pallipadi <[email protected]>Cc Ingo Molnar <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Juergen Gross <[email protected]>Cc Daniel Vetter <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Dave Airlie <[email protected]>Cc Antonino Daplas <[email protected]>Cc Jean-Christophe Plagniol-Villard <[email protected]>Cc Tomi Valkeinen <[email protected]>Signed-off-by Luis R. Rodriguez <[email protected]>--- drivers/pci/pci.c | 14 ++++++++++++++ include/linux/pci.h | 1 + 2 files changed, 15 insertions(+)drivers/pci/pci.c +0
-0@@ -137,6 +137,20 @@ void __iomem *pci_ioremap_bar(struct pci_dev *pdev, int bar) pci_resource_len(pdev, bar));
drivers/pci/pci.c void __iomem *pci_ioremap_bar(struct pci_dev *pdev, int bar) · line 147
Quoted 10 lines
drivers/pci/pci.c +8
-0}EXPORT_SYMBOL_GPL (pci_ioremap_bar); + +void __iomem *pci_ioremap_wc_bar (struct pci_dev *pdev,int bar) +{ +/* +* Make sure the BAR is actually a memory resource, not an IO resource +*/ +if (!(pci_resource_flags (pdev, bar) &IORESOURCE_MEM )) { +WARN_ON (1 );
Would it be better to use dev_warn ? That way you can see which BDF it is?
Thought WARN will give a nice stack-trace that should easily point to the driver so perhaps not.. Either way - up to you.
Quoted 29 lines
drivers/pci/pci.c +6
-0+ return NULL; + } +return ioremap_wc (pci_resource_start (pdev, bar), +pci_resource_len (pdev, bar)); +} +EXPORT_SYMBOL_GPL (pci_ioremap_wc_bar);#endif #define PCI_FIND_CAP_TTL 48include/linux/pci.h +1
-0@@ -1667,6 +1667,7 @@ static inline void pci_mmcfg_late_init(void) { }int pci_ext_cfg_avail (void );void __iomem *pci_ioremap_bar (struct pci_dev *pdev,int bar); +void __iomem *pci_ioremap_wc_bar (struct pci_dev *pdev,int bar);#ifdef CONFIG_PCI_IOV int pci_enable_sriov (struct pci_dev *dev,int nr_virtfn);Signature · 7 lines
2.3.2.209.gd67f9d5.dirty _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH 4/47 pci: add pci_ioremap_wc_bar()
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
This lets drivers take advanate of PAT when available. This should help with the transition of converting video drivers over to ioremap_wc() to help with the goal of eventually using _PAGE_CACHE_UC over _PAGE_CACHE_UC_MINUS on x86 on ioremap_nocache() (de33c442e)
--- drivers/pci/pci.c | 14 ++++++++++++++ include/linux/pci.h | 1 + 2 files changed, 15 insertions(+)
drivers/pci/pci.c +14 -0
@@ -137,6 +137,20 @@ void __iomem *pci_ioremap_bar(struct pci_dev *pdev, int bar) pci_resource_len(pdev, bar)); }EXPORT_SYMBOL_GPL (pci_ioremap_bar); + +void __iomem *pci_ioremap_wc_bar (struct pci_dev *pdev,int bar) +{ +/* +* Make sure the BAR is actually a memory resource, not an IO resource +*/ +if (!(pci_resource_flags (pdev, bar) &IORESOURCE_MEM )) { +WARN_ON (1 ); +return NULL ; + } +return ioremap_wc (pci_resource_start (pdev, bar), +pci_resource_len (pdev, bar)); +} +EXPORT_SYMBOL_GPL (pci_ioremap_wc_bar);#endif #define PCI_FIND_CAP_TTL 48
include/linux/pci.h +1 -0
@@ -1667,6 +1667,7 @@ static inline void pci_mmcfg_late_init(void) { }int pci_ext_cfg_avail (void );void __iomem *pci_ioremap_bar (struct pci_dev *pdev,int bar); +void __iomem *pci_ioremap_wc_bar (struct pci_dev *pdev,int bar);#ifdef CONFIG_PCI_IOV int pci_enable_sriov (struct pci_dev *dev,int nr_virtfn);
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
PATCH 5/47 pci: add pci_iomap_wc() variants
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
This allows drivers to take advantage of write-combining when possible. Ideally we'd have pci_read_bases() just peg an IORESOURCE_WC flag for us but where exactly video devices memory lie varies *largely* and at times things are mixed with MMIO registers, sometimes we can address the changes in drivers, other times the change requires intrusive changes.
Although there is also arch_phys_wc_add() that makes use of architecture specific write-combinging alternatives (MTRR on x86 when a system does not have PAT) we void polluting pci_iomap() space with it and force drivers and subsystems that want to use it to be explicit.
There are a few motivations for this:
a) Take advantage of PAT when available
b) Help bury MTRR code away, MTRR is architecture specific and on x86 its replaced by PAT
c) Help with the goal of eventually using _PAGE_CACHE_UC over _PAGE_CACHE_UC_MINUS on x86 on ioremap_nocache() (de33c442e)
--- include/asm-generic/pci_iomap.h | 14 ++++++++++ lib/pci_iomap.c | 61 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+)
include/asm-generic/pci_iomap.h +14 -0
@@ -15,9 +15,13 @@ struct pci_dev;#ifdef CONFIG_PCI /* Create a virtual mapping cookie for a PCI BAR (memory or IO) */ extern void __iomem *pci_iomap (struct pci_dev *dev,int bar,unsigned long max); +extern void __iomem *pci_iomap_wc (struct pci_dev *dev,int bar,unsigned long max);extern void __iomem *pci_iomap_range (struct pci_dev *dev,int bar,unsigned long offset,unsigned long maxlen); +extern void __iomem *pci_iomap_wc_range (struct pci_dev *dev,int bar, +unsigned long offset, +unsigned long maxlen);/* Create a virtual mapping cookie for a port on a given PCI device. * Do not call this directly, it exists to make it easier for architectures * to override */
@@ -34,12 +38,22 @@ static inline void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned lonreturn NULL ; } +static inline void __iomem *pci_iomap_wc (struct pci_dev *dev,int bar,unsigned long max) +{ +return NULL ; +}static inline void __iomem *pci_iomap_range (struct pci_dev *dev,int bar,unsigned long offset,unsigned long maxlen) {return NULL ; } +static inline void __iomem *pci_iomap_wc_range (struct pci_dev *dev,int bar, +unsigned long offset, +unsigned long maxlen) +{ +return NULL ; +}#endif #endif /* __ASM_GENERIC_IO_H */
lib/pci_iomap.c +61 -0
71 lines not on this page · raw message
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
Bjorn Helgaas
maintainerRe: [PATCH v1 05/47] pci: add pci_iomap_wc() variants
Hi Luis,
This seems OK to me, but I'm curious about a few things.
Quoted 5 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
This allows drivers to take advantage of write-combining when possible. Ideally we'd have
pci_read_bases()just peg anIORESOURCE_WCflag for us
We do set IORESOURCE_PREFETCH. Do you mean something different?
Quoted 5 lines
but where exactly
video devices memory lie varies *largely* and at times things are mixed with MMIO registers, sometimes we can address the changes in drivers, other times the change requires intrusive changes.
What does a video device address have to do with this? I do see that if a BAR maps only a frame buffer, the device might be able to mark it prefetchable, while if the BAR mapped both a frame buffer and some registers, it might not be able to make it prefetchable. But that doesn't seem like it depends on the *address*.
pci_iomap_range() already makes a cacheable mapping if IORESOURCE_CACHEABLE; I'm guessing that you would like it to automatically use WC if the BAR if IORESOURCE_PREFETCH, e.g.,
if (flags & IORESOURCE_CACHEABLE)
return ioremap(start, len);
if (flags & IORESOURCE_PREFETCH)
return ioremap_wc(start, len);
return ioremap_nocache(start, len);Is there a reason not to do that?
Quoted 25 lines
Although there is also
arch_phys_wc_add()that makes use of architecture specific write-combinging alternatives (MTRR on x86 when a system does not have PAT) we void pollutingpci_iomap()space with it and force drivers and subsystems that want to use it to be explicit.There are a few motivations for this:
a) Take advantage of PAT when available
b) Help bury MTRR code away, MTRR is architecture specific and on x86 its replaced by PAT
c) Help with the goal of eventually using
_PAGE_CACHE_UCover_PAGE_CACHE_UC_MINUSon x86 onioremap_nocache()(de33c442e)
...lib/pci_iomap.c +8
-0+void __iomem *pci_iomap_wc_range (struct pci_dev *dev, +int bar, +unsigned long offset, +unsigned long maxlen) +{ +resource_size_t start =pci_resource_start (dev, bar); +resource_size_t len =pci_resource_len (dev, bar); +unsigned long flags =pci_resource_flags (dev, bar);
lib/pci_iomap.c void __iomem *pci_iomap_range(struct pci_dev *dev, · line 87
Quoted 10 lines
lib/pci_iomap.c +10
-0+ +if (len <= offset || !start) +return NULL ; + len -= offset; + start += offset; +if (maxlen && len > maxlen) + len = maxlen; +if (flags &IORESOURCE_IO ) +return __pci_ioport_map (dev, start, len); +if (flags &IORESOURCE_MEM )
Should we log a note in dmesg if the BAR is *not* IORESOURCE_PREFETCH?
I know the driver might know it's safe even if the device didn't mark
the BAR as prefetchable, but it does seem like an easy way for a driver to shoot itself in the foot.
Quoted 4 lines
lib/pci_iomap.c +4
-0+return ioremap_wc (start, len); +/* What? */ +return NULL ; +}
Re: [PATCH v1 05/47] pci: add pci_iomap_wc() variants
Quoted 3 lines · Bjorn Helgaas
Hi Luis,
This seems OK to me,
Great.
Quoted 11 lines
but I'm curious about a few things.
Quoted 5 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
This allows drivers to take advantage of write-combining when possible. Ideally we'd have
pci_read_bases()just peg anIORESOURCE_WCflag for usWe do set
IORESOURCE_PREFETCH. Do you mean something different?
I did not think we had a WC IORESOURCE flag. Are you saying that we can use IORESOURCE_PREFETCH for that purpose? If so then great. As I read a PCI BAR can have PCI_BASE_ADDRESS_MEM_PREFETCH and when that's the case we peg IORESOURCE_PREFETCH. That seems to be what I want indeed. Questions below.
Quoted 11 lines
Quoted 5 lines
but where exactly
video devices memory lie varies *largely* and at times things are mixed with MMIO registers, sometimes we can address the changes in drivers, other times the change requires intrusive changes.What does a video device address have to do with this? I do see that if a BAR maps only a frame buffer, the device might be able to mark it prefetchable, while if the BAR mapped both a frame buffer and some registers, it might not be able to make it prefetchable. But that doesn't seem like it depends on the *address*.
I meant the offsets for each of those, either registers or framebuffer, and that typically they are mixed (primarily on older devices), so indeed your summary of the problem is what I meant. Let's remember that we are trying to take advantage of PAT here when available and avoid MTRR in that case, do we know that the same PCI BARs that have always historically used MTRRs had IORESOURCE_PREFETCH set, is that a fair assumption ? I realize they are different things -- but its precisely why I ask.
Quoted 9 lines
pci_iomap_range()already makes a cacheable mapping ifIORESOURCE_CACHEABLE; I'm guessing that you would like it to automatically use WC if the BAR ifIORESOURCE_PREFETCH, e.g.,if (flags & IORESOURCE_CACHEABLE) return ioremap(start, len); if (flags & IORESOURCE_PREFETCH) return ioremap_wc(start, len); return ioremap_nocache(start, len);
Indeed, that's exactly what I think we should strive towards.
Quoted 1 line
Is there a reason not to do that?
This depends on the exact defintion of IORESOURCE_PREFETCH and PCI_BASE_ADDRESS_MEM_PREFETCH and how they are used all over and accross *all devices*. This didn't look promising for starters:
include/uapi/linux/pci_regs.h:#define PCI_BASE_ADDRESS_MEM_PREFETCH 0x08 /* prefetchable? */
PCI_BASE_ADDRESS_MEM_PREFETCH seems to be BAR specific, so a few questions:
1) Can we rest assured for instance that if we check for PCI_BASE_ADDRESS_MEM_PREFETCH and if set that it will *only* be set on a full PCI BAR if the full PCI BAR does want WC? If not this can regress functionality. That seems risky. It however would not be risky if we used another API that did look for IORESOURCE_PREFETCH and if so use ioremap_wc() -- that way only drivers we know that do use the full PCI bar would use this API. There's a bit of a problem with this though:
2) Do we know that if a *full PCI BAR* is used for WC that PCI_BASE_ADDRESS_MEM_PREFETCH *was* definitely set for the PCI BAR? If so then the API usage would be restricted only to devices that we know *do* adhere to this. That reduces the possible uses for older drivers and can create regressions if used loosely without verification... but..
3) If from now on we get folks to commit to uset PCI_BASE_ADDRESS_MEM_PREFETCH for full PCI BARs that do want WC perhaps newer devices / drivers will use this very consistently ? Can we bank on that and is it worth it ?
4) If a PCI BAR *does not* have PCI_BASE_ADDRESS_MEM_PREFETCH do we know it must not never want WC ?
If we don't have certainty on any of the above I'm afraid we can't do much right now but perhaps we can push towards better use of PCI_BASE_ADDRESS_MEM_PREFETCH and hope folks will only use this for the full PCI BAR only if WC is desired.
Thoughts?
Quoted 32 lines
Quoted 32 lines
Although there is also
arch_phys_wc_add()that makes use of architecture specific write-combinging alternatives (MTRR on x86 when a system does not have PAT) we void pollutingpci_iomap()space with it and force drivers and subsystems that want to use it to be explicit.There are a few motivations for this:
a) Take advantage of PAT when available
b) Help bury MTRR code away, MTRR is architecture specific and on x86 its replaced by PAT
c) Help with the goal of eventually using
_PAGE_CACHE_UCover_PAGE_CACHE_UC_MINUSon x86 onioremap_nocache()(de33c442e)
...lib/pci_iomap.c +15
-0+void __iomem *pci_iomap_wc_range (struct pci_dev *dev, +int bar, +unsigned long offset, +unsigned long maxlen) +{ +resource_size_t start =pci_resource_start (dev, bar); +resource_size_t len =pci_resource_len (dev, bar); +unsigned long flags =pci_resource_flags (dev, bar); + +if (len <= offset || !start) +return NULL ; + len -= offset; + start += offset; +if (maxlen && len > maxlen) + len = maxlen;
Quoted 8 lines
lib/pci_iomap.c void __iomem *pci_iomap_range(struct pci_dev *dev, · line 87
Quoted 3 lines
lib/pci_iomap.c +3
-0+if (flags &IORESOURCE_IO ) +return __pci_ioport_map (dev, start, len); +if (flags &IORESOURCE_MEM )Should we log a note in dmesg if the BAR is *not*
IORESOURCE_PREFETCH?
I know the driver might know it's safe even if the device didn't mark
the BAR as prefetchable, but it does seem like an easy way for a driver to shoot itself in the foot.
You tell me. I would fear this may not be consistent and we'd end up having bug reports open for something that has historically been a non-issue. The above questions can help us gauge the risk of this.
Luis
Re: [PATCH v1 05/47] pci: add pci_iomap_wc() variants
Quoted 84 lines · Luis R. Rodriguez
Quoted 3 lines · Bjorn Helgaas
Hi Luis,
This seems OK to me,
Great.
Quoted 11 lines
but I'm curious about a few things.
Quoted 5 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
This allows drivers to take advantage of write-combining when possible. Ideally we'd have
pci_read_bases()just peg anIORESOURCE_WCflag for usWe do set
IORESOURCE_PREFETCH. Do you mean something different?I did not think we had a WC IORESOURCE flag. Are you saying that we can use
IORESOURCE_PREFETCHfor that purpose? If so then great. As I read a PCI BAR can havePCI_BASE_ADDRESS_MEM_PREFETCHand when that's the case we pegIORESOURCE_PREFETCH. That seems to be what I want indeed. Questions below.Quoted 11 lines
Quoted 5 lines
but where exactly
video devices memory lie varies *largely* and at times things are mixed with MMIO registers, sometimes we can address the changes in drivers, other times the change requires intrusive changes.What does a video device address have to do with this? I do see that if a BAR maps only a frame buffer, the device might be able to mark it prefetchable, while if the BAR mapped both a frame buffer and some registers, it might not be able to make it prefetchable. But that doesn't seem like it depends on the *address*.
I meant the offsets for each of those, either registers or framebuffer, and that typically they are mixed (primarily on older devices), so indeed your summary of the problem is what I meant. Let's remember that we are trying to take advantage of PAT here when available and avoid MTRR in that case, do we know that the same PCI BARs that have always historically used MTRRs had
IORESOURCE_PREFETCHset, is that a fair assumption ? I realize they are different things -- but its precisely why I ask.Quoted 9 lines
pci_iomap_range()already makes a cacheable mapping ifIORESOURCE_CACHEABLE; I'm guessing that you would like it to automatically use WC if the BAR ifIORESOURCE_PREFETCH, e.g.,if (flags & IORESOURCE_CACHEABLE) return ioremap(start, len); if (flags & IORESOURCE_PREFETCH) return ioremap_wc(start, len); return ioremap_nocache(start, len);Indeed, that's exactly what I think we should strive towards.
Quoted 1 line
Is there a reason not to do that?
This depends on the exact defintion of
IORESOURCE_PREFETCHandPCI_BASE_ADDRESS_MEM_PREFETCHand how they are used all over and accross *all devices*. This didn't look promising for starters:include/uapi/linux/pci_regs.h:#define
PCI_BASE_ADDRESS_MEM_PREFETCH0x08/* prefetchable? */
PCI_BASE_ADDRESS_MEM_PREFETCHseems to be BAR specific, so a few questions:1) Can we rest assured for instance that if we check for
PCI_BASE_ADDRESS_MEM_PREFETCHand if set that it will *only* be set on a full PCI BAR if the full PCI BAR does want WC? If not this can regress functionality. That seems risky. It however would not be risky if we used another API that did look forIORESOURCE_PREFETCHand if so useioremap_wc()-- that way only drivers we know that do use the full PCI bar would use this API. There's a bit of a problem with this though:2) Do we know that if a *full PCI BAR* is used for WC that
PCI_BASE_ADDRESS_MEM_PREFETCH*was* definitely set for the PCI BAR? If so then the API usage would be restricted only to devices that we know *do* adhere to this. That reduces the possible uses for older drivers and can create regressions if used loosely without verification... but..3) If from now on we get folks to commit to uset
PCI_BASE_ADDRESS_MEM_PREFETCHfor full PCI BARs that do want WC perhaps newer devices / drivers will use this very consistently ? Can we bank on that and is it worth it ?
Quoted 8 lines
4) If a PCI BAR *does not* have
PCI_BASE_ADDRESS_MEM_PREFETCHdo we know it must not never want WC ?If we don't have certainty on any of the above I'm afraid we can't do much right now but perhaps we can push towards better use of
PCI_BASE_ADDRESS_MEM_PREFETCHand hope folks will only use this for the full PCI BAR only if WC is desired.Thoughts?
Bjorn, now that you're done schooling me on English, any thoughts on the above?
Quoted 41 lines
Quoted 32 lines
Quoted 32 lines
Although there is also
arch_phys_wc_add()that makes use of architecture specific write-combinging alternatives (MTRR on x86 when a system does not have PAT) we void pollutingpci_iomap()space with it and force drivers and subsystems that want to use it to be explicit.There are a few motivations for this:
a) Take advantage of PAT when available
b) Help bury MTRR code away, MTRR is architecture specific and on x86 its replaced by PAT
c) Help with the goal of eventually using
_PAGE_CACHE_UCover_PAGE_CACHE_UC_MINUSon x86 onioremap_nocache()(de33c442e)
...lib/pci_iomap.c +15
-0+void __iomem *pci_iomap_wc_range (struct pci_dev *dev, +int bar, +unsigned long offset, +unsigned long maxlen) +{ +resource_size_t start =pci_resource_start (dev, bar); +resource_size_t len =pci_resource_len (dev, bar); +unsigned long flags =pci_resource_flags (dev, bar); + +if (len <= offset || !start) +return NULL ; + len -= offset; + start += offset; +if (maxlen && len > maxlen) + len = maxlen;Quoted 8 lines
lib/pci_iomap.c void __iomem *pci_iomap_range(struct pci_dev *dev, · line 87
Quoted 3 lines
lib/pci_iomap.c +3
-0+if (flags &IORESOURCE_IO ) +return __pci_ioport_map (dev, start, len); +if (flags &IORESOURCE_MEM )Should we log a note in dmesg if the BAR is *not*
IORESOURCE_PREFETCH?
I know the driver might know it's safe even if the device didn't mark
the BAR as prefetchable, but it does seem like an easy way for a driver to shoot itself in the foot.
Quoted 3 lines
You tell me. I would fear this may not be consistent and we'd end up having bug reports open for something that has historically been a non-issue. The above questions can help us gauge the risk of this.
Now, I'll tell you what I *think* but these are just guestimates (TM):
* Likely PCI_BASE_ADDRESS_MEM_PREFETCH can implate IORESOURCE_PREFETCH and use of ioremap_wc() on a full PCI BAR only, but this strict definition likely cannot be 100% guaranteed and could break some devices. We need something a bit more concrete and well known so that next generation industry standards embrace and let us in the kernel automatically detect specific ranges and their respective page attribute requirements. Might be good to address here x86 and ARM families
Curious: Sarah, how does USB address these different different page attribute needs on USB 3.0?
Luis
Re: [PATCH v1 05/47] pci: add pci_iomap_wc() variants
Quoted 75 lines · Luis R. Rodriguez
Quoted 74 lines · Luis R. Rodriguez
Quoted 3 lines · Bjorn Helgaas
Hi Luis,
This seems OK to me,
Great.
Quoted 11 lines
but I'm curious about a few things.
Quoted 5 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
This allows drivers to take advantage of write-combining when possible. Ideally we'd have
pci_read_bases()just peg anIORESOURCE_WCflag for usWe do set
IORESOURCE_PREFETCH. Do you mean something different?I did not think we had a WC IORESOURCE flag. Are you saying that we can use
IORESOURCE_PREFETCHfor that purpose? If so then great. As I read a PCI BAR can havePCI_BASE_ADDRESS_MEM_PREFETCHand when that's the case we pegIORESOURCE_PREFETCH. That seems to be what I want indeed. Questions below.Quoted 11 lines
Quoted 5 lines
but where exactly
video devices memory lie varies *largely* and at times things are mixed with MMIO registers, sometimes we can address the changes in drivers, other times the change requires intrusive changes.What does a video device address have to do with this? I do see that if a BAR maps only a frame buffer, the device might be able to mark it prefetchable, while if the BAR mapped both a frame buffer and some registers, it might not be able to make it prefetchable. But that doesn't seem like it depends on the *address*.
I meant the offsets for each of those, either registers or framebuffer, and that typically they are mixed (primarily on older devices), so indeed your summary of the problem is what I meant. Let's remember that we are trying to take advantage of PAT here when available and avoid MTRR in that case, do we know that the same PCI BARs that have always historically used MTRRs had
IORESOURCE_PREFETCHset, is that a fair assumption ? I realize they are different things -- but its precisely why I ask.Quoted 9 lines
pci_iomap_range()already makes a cacheable mapping ifIORESOURCE_CACHEABLE; I'm guessing that you would like it to automatically use WC if the BAR ifIORESOURCE_PREFETCH, e.g.,if (flags & IORESOURCE_CACHEABLE) return ioremap(start, len); if (flags & IORESOURCE_PREFETCH) return ioremap_wc(start, len); return ioremap_nocache(start, len);Indeed, that's exactly what I think we should strive towards.
Quoted 1 line
Is there a reason not to do that?
This depends on the exact defintion of
IORESOURCE_PREFETCHandPCI_BASE_ADDRESS_MEM_PREFETCHand how they are used all over and accross *all devices*. This didn't look promising for starters:include/uapi/linux/pci_regs.h:#define
PCI_BASE_ADDRESS_MEM_PREFETCH0x08/* prefetchable? */
PCI_BASE_ADDRESS_MEM_PREFETCHseems to be BAR specific, so a few questions:1) Can we rest assured for instance that if we check for
PCI_BASE_ADDRESS_MEM_PREFETCHand if set that it will *only* be set on a full PCI BAR if the full PCI BAR does want WC? If not this can regress functionality. That seems risky. It however would not be risky if we used another API that did look forIORESOURCE_PREFETCHand if so useioremap_wc()-- that way only drivers we know that do use the full PCI bar would use this API. There's a bit of a problem with this though:
Quoted 6 lines
Quoted 6 lines
2) Do we know that if a *full PCI BAR* is used for WC that
PCI_BASE_ADDRESS_MEM_PREFETCH*was* definitely set for the PCI BAR? If so then the API usage would be restricted only to devices that we know *do* adhere to this. That reduces the possible uses for older drivers and can create regressions if used loosely without verification... but..
In theory, PCI spec says this about prefetch memory:
Bridges are permitted to merge writes into this range (refer to Section 3.2.6).
Exceptions could be:
- devices not behind a bridge (e.g. intergrated in a root complex)
- devices behind a virtual bridge from same vendor (which know bridge won't prefetch)
I worry that WC might also cause more reordering though. I don't remember this is true, off-hand. Bridges can only reorder transactions according to very specific rules.
Quoted 3 lines
Quoted 3 lines
3) If from now on we get folks to commit to uset
PCI_BASE_ADDRESS_MEM_PREFETCHfor full PCI BARs that do want WC perhaps newer devices / drivers will use this very consistently ? Can we bank on that and is it worth it ?
Unfortunately there's a separate good reason to set memory as prefetcheable:
it's the only way to get 64 bit addresses for devices behind bridges. So WC might be *safe* for prefetch BARs, but might not be a good idea.
Quoted 3 lines
Quoted 3 lines
4) If a PCI BAR *does not* have
PCI_BASE_ADDRESS_MEM_PREFETCHdo we know it must not never want WC ?
That's not true I think. It means device can't allow prefetch but maybe it does allow combining.
Quoted 69 lines
Quoted 6 lines
If we don't have certainty on any of the above I'm afraid we can't do much right now but perhaps we can push towards better use of
PCI_BASE_ADDRESS_MEM_PREFETCHand hope folks will only use this for the full PCI BAR only if WC is desired.Thoughts?
Bjorn, now that you're done schooling me on English, any thoughts on the above?
Quoted 41 lines
Quoted 32 lines
Quoted 32 lines
Although there is also
arch_phys_wc_add()that makes use of architecture specific write-combinging alternatives (MTRR on x86 when a system does not have PAT) we void pollutingpci_iomap()space with it and force drivers and subsystems that want to use it to be explicit.There are a few motivations for this:
a) Take advantage of PAT when available
b) Help bury MTRR code away, MTRR is architecture specific and on x86 its replaced by PAT
c) Help with the goal of eventually using
_PAGE_CACHE_UCover_PAGE_CACHE_UC_MINUSon x86 onioremap_nocache()(de33c442e)
...lib/pci_iomap.c +15
-0+void __iomem *pci_iomap_wc_range (struct pci_dev *dev, +int bar, +unsigned long offset, +unsigned long maxlen) +{ +resource_size_t start =pci_resource_start (dev, bar); +resource_size_t len =pci_resource_len (dev, bar); +unsigned long flags =pci_resource_flags (dev, bar); + +if (len <= offset || !start) +return NULL ; + len -= offset; + start += offset; +if (maxlen && len > maxlen) + len = maxlen;Quoted 8 lines
lib/pci_iomap.c void __iomem *pci_iomap_range(struct pci_dev *dev, · line 87
Quoted 3 lines
lib/pci_iomap.c +3
-0+if (flags &IORESOURCE_IO ) +return __pci_ioport_map (dev, start, len); +if (flags &IORESOURCE_MEM )Should we log a note in dmesg if the BAR is *not*
IORESOURCE_PREFETCH?
I know the driver might know it's safe even if the device didn't mark
the BAR as prefetchable, but it does seem like an easy way for a driver to shoot itself in the foot.Quoted 3 lines
You tell me. I would fear this may not be consistent and we'd end up having bug reports open for something that has historically been a non-issue. The above questions can help us gauge the risk of this.
Now, I'll tell you what I *think* but these are just guestimates (TM):
* Likely
PCI_BASE_ADDRESS_MEM_PREFETCHcan implateIORESOURCE_PREFETCHand use ofioremap_wc()on a full PCI BAR only, but this strict definition likely cannot be 100% guaranteed and could break some devices. We need something a bit more concrete and well known so that next generation industry standards embrace and let us in the kernel automatically detect specific ranges and their respective page attribute requirements. Might be good to address here x86 and ARM familiesCurious: Sarah, how does USB address these different different page attribute needs on USB 3.0?
Luis
Re: [PATCH v1 05/47] pci: add pci_iomap_wc() variants
In reply to Luis R. RodriguezQuoted 75 lines · Luis R. Rodriguez
Quoted 74 lines · Luis R. Rodriguez
Quoted 3 lines · Bjorn Helgaas
Hi Luis,
This seems OK to me,
Great.
Quoted 11 lines
but I'm curious about a few things.
Quoted 5 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
This allows drivers to take advantage of write-combining when possible. Ideally we'd have
pci_read_bases()just peg anIORESOURCE_WCflag for usWe do set
IORESOURCE_PREFETCH. Do you mean something different?I did not think we had a WC IORESOURCE flag. Are you saying that we can use
IORESOURCE_PREFETCHfor that purpose? If so then great. As I read a PCI BAR can havePCI_BASE_ADDRESS_MEM_PREFETCHand when that's the case we pegIORESOURCE_PREFETCH. That seems to be what I want indeed. Questions below.Quoted 11 lines
Quoted 5 lines
but where exactly
video devices memory lie varies *largely* and at times things are mixed with MMIO registers, sometimes we can address the changes in drivers, other times the change requires intrusive changes.What does a video device address have to do with this? I do see that if a BAR maps only a frame buffer, the device might be able to mark it prefetchable, while if the BAR mapped both a frame buffer and some registers, it might not be able to make it prefetchable. But that doesn't seem like it depends on the *address*.
I meant the offsets for each of those, either registers or framebuffer, and that typically they are mixed (primarily on older devices), so indeed your summary of the problem is what I meant. Let's remember that we are trying to take advantage of PAT here when available and avoid MTRR in that case, do we know that the same PCI BARs that have always historically used MTRRs had
IORESOURCE_PREFETCHset, is that a fair assumption ? I realize they are different things -- but its precisely why I ask.Quoted 9 lines
pci_iomap_range()already makes a cacheable mapping ifIORESOURCE_CACHEABLE; I'm guessing that you would like it to automatically use WC if the BAR ifIORESOURCE_PREFETCH, e.g.,if (flags & IORESOURCE_CACHEABLE) return ioremap(start, len); if (flags & IORESOURCE_PREFETCH) return ioremap_wc(start, len); return ioremap_nocache(start, len);Indeed, that's exactly what I think we should strive towards.
Quoted 1 line
Is there a reason not to do that?
This depends on the exact defintion of
IORESOURCE_PREFETCHandPCI_BASE_ADDRESS_MEM_PREFETCHand how they are used all over and accross *all devices*. This didn't look promising for starters:include/uapi/linux/pci_regs.h:#define
PCI_BASE_ADDRESS_MEM_PREFETCH0x08/* prefetchable? */
PCI_BASE_ADDRESS_MEM_PREFETCHseems to be BAR specific, so a few questions:1) Can we rest assured for instance that if we check for
PCI_BASE_ADDRESS_MEM_PREFETCHand if set that it will *only* be set on a full PCI BAR if the full PCI BAR does want WC? If not this can regress functionality. That seems risky. It however would not be risky if we used another API that did look forIORESOURCE_PREFETCHand if so useioremap_wc()-- that way only drivers we know that do use the full PCI bar would use this API. There's a bit of a problem with this though:
Quoted 6 lines
Quoted 6 lines
2) Do we know that if a *full PCI BAR* is used for WC that
PCI_BASE_ADDRESS_MEM_PREFETCH*was* definitely set for the PCI BAR? If so then the API usage would be restricted only to devices that we know *do* adhere to this. That reduces the possible uses for older drivers and can create regressions if used loosely without verification... but..
In theory, PCI spec says this about prefetch memory:
Bridges are permitted to merge writes into this range (refer to Section 3.2.6).
Exceptions could be:
- devices not behind a bridge (e.g. intergrated in a root complex)
- devices behind a virtual bridge from same vendor (which know bridge won't prefetch)
I worry that WC might also cause more reordering though. I don't remember this is true, off-hand. Bridges can only reorder transactions according to very specific rules.
Quoted 3 lines
Quoted 3 lines
3) If from now on we get folks to commit to uset
PCI_BASE_ADDRESS_MEM_PREFETCHfor full PCI BARs that do want WC perhaps newer devices / drivers will use this very consistently ? Can we bank on that and is it worth it ?
Unfortunately there's a separate good reason to set memory as prefetcheable:
it's the only way to get 64 bit addresses for devices behind bridges. So WC might be *safe* for prefetch BARs, but might not be a good idea.
Quoted 3 lines
Quoted 3 lines
4) If a PCI BAR *does not* have
PCI_BASE_ADDRESS_MEM_PREFETCHdo we know it must not never want WC ?
That's not true I think. It means device can't allow prefetch but maybe it does allow combining.
Quoted 69 lines
Quoted 6 lines
If we don't have certainty on any of the above I'm afraid we can't do much right now but perhaps we can push towards better use of
PCI_BASE_ADDRESS_MEM_PREFETCHand hope folks will only use this for the full PCI BAR only if WC is desired.Thoughts?
Bjorn, now that you're done schooling me on English, any thoughts on the above?
Quoted 41 lines
Quoted 32 lines
Quoted 32 lines
Although there is also
arch_phys_wc_add()that makes use of architecture specific write-combinging alternatives (MTRR on x86 when a system does not have PAT) we void pollutingpci_iomap()space with it and force drivers and subsystems that want to use it to be explicit.There are a few motivations for this:
a) Take advantage of PAT when available
b) Help bury MTRR code away, MTRR is architecture specific and on x86 its replaced by PAT
c) Help with the goal of eventually using
_PAGE_CACHE_UCover_PAGE_CACHE_UC_MINUSon x86 onioremap_nocache()(de33c442e)
...lib/pci_iomap.c +15
-0+void __iomem *pci_iomap_wc_range (struct pci_dev *dev, +int bar, +unsigned long offset, +unsigned long maxlen) +{ +resource_size_t start =pci_resource_start (dev, bar); +resource_size_t len =pci_resource_len (dev, bar); +unsigned long flags =pci_resource_flags (dev, bar); + +if (len <= offset || !start) +return NULL ; + len -= offset; + start += offset; +if (maxlen && len > maxlen) + len = maxlen;Quoted 8 lines
lib/pci_iomap.c void __iomem *pci_iomap_range(struct pci_dev *dev, · line 87
Quoted 3 lines
lib/pci_iomap.c +3
-0+if (flags &IORESOURCE_IO ) +return __pci_ioport_map (dev, start, len); +if (flags &IORESOURCE_MEM )Should we log a note in dmesg if the BAR is *not*
IORESOURCE_PREFETCH?
I know the driver might know it's safe even if the device didn't mark
the BAR as prefetchable, but it does seem like an easy way for a driver to shoot itself in the foot.Quoted 3 lines
You tell me. I would fear this may not be consistent and we'd end up having bug reports open for something that has historically been a non-issue. The above questions can help us gauge the risk of this.
Now, I'll tell you what I *think* but these are just guestimates (TM):
* Likely
PCI_BASE_ADDRESS_MEM_PREFETCHcan implateIORESOURCE_PREFETCHand use ofioremap_wc()on a full PCI BAR only, but this strict definition likely cannot be 100% guaranteed and could break some devices. We need something a bit more concrete and well known so that next generation industry standards embrace and let us in the kernel automatically detect specific ranges and their respective page attribute requirements. Might be good to address here x86 and ARM familiesCurious: Sarah, how does USB address these different different page attribute needs on USB 3.0?
Luis
Re: [PATCH v1 05/47] pci: add pci_iomap_wc() variants
In reply to Luis R. RodriguezQuoted 84 lines · Luis R. Rodriguez
Quoted 3 lines · Bjorn Helgaas
Hi Luis,
This seems OK to me,
Great.
Quoted 11 lines
but I'm curious about a few things.
Quoted 5 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
This allows drivers to take advantage of write-combining when possible. Ideally we'd have
pci_read_bases()just peg anIORESOURCE_WCflag for usWe do set
IORESOURCE_PREFETCH. Do you mean something different?I did not think we had a WC IORESOURCE flag. Are you saying that we can use
IORESOURCE_PREFETCHfor that purpose? If so then great. As I read a PCI BAR can havePCI_BASE_ADDRESS_MEM_PREFETCHand when that's the case we pegIORESOURCE_PREFETCH. That seems to be what I want indeed. Questions below.Quoted 11 lines
Quoted 5 lines
but where exactly
video devices memory lie varies *largely* and at times things are mixed with MMIO registers, sometimes we can address the changes in drivers, other times the change requires intrusive changes.What does a video device address have to do with this? I do see that if a BAR maps only a frame buffer, the device might be able to mark it prefetchable, while if the BAR mapped both a frame buffer and some registers, it might not be able to make it prefetchable. But that doesn't seem like it depends on the *address*.
I meant the offsets for each of those, either registers or framebuffer, and that typically they are mixed (primarily on older devices), so indeed your summary of the problem is what I meant. Let's remember that we are trying to take advantage of PAT here when available and avoid MTRR in that case, do we know that the same PCI BARs that have always historically used MTRRs had
IORESOURCE_PREFETCHset, is that a fair assumption ? I realize they are different things -- but its precisely why I ask.Quoted 9 lines
pci_iomap_range()already makes a cacheable mapping ifIORESOURCE_CACHEABLE; I'm guessing that you would like it to automatically use WC if the BAR ifIORESOURCE_PREFETCH, e.g.,if (flags & IORESOURCE_CACHEABLE) return ioremap(start, len); if (flags & IORESOURCE_PREFETCH) return ioremap_wc(start, len); return ioremap_nocache(start, len);Indeed, that's exactly what I think we should strive towards.
Quoted 1 line
Is there a reason not to do that?
This depends on the exact defintion of
IORESOURCE_PREFETCHandPCI_BASE_ADDRESS_MEM_PREFETCHand how they are used all over and accross *all devices*. This didn't look promising for starters:include/uapi/linux/pci_regs.h:#define
PCI_BASE_ADDRESS_MEM_PREFETCH0x08/* prefetchable? */
PCI_BASE_ADDRESS_MEM_PREFETCHseems to be BAR specific, so a few questions:1) Can we rest assured for instance that if we check for
PCI_BASE_ADDRESS_MEM_PREFETCHand if set that it will *only* be set on a full PCI BAR if the full PCI BAR does want WC? If not this can regress functionality. That seems risky. It however would not be risky if we used another API that did look forIORESOURCE_PREFETCHand if so useioremap_wc()-- that way only drivers we know that do use the full PCI bar would use this API. There's a bit of a problem with this though:2) Do we know that if a *full PCI BAR* is used for WC that
PCI_BASE_ADDRESS_MEM_PREFETCH*was* definitely set for the PCI BAR? If so then the API usage would be restricted only to devices that we know *do* adhere to this. That reduces the possible uses for older drivers and can create regressions if used loosely without verification... but..3) If from now on we get folks to commit to uset
PCI_BASE_ADDRESS_MEM_PREFETCHfor full PCI BARs that do want WC perhaps newer devices / drivers will use this very consistently ? Can we bank on that and is it worth it ?
Quoted 8 lines
4) If a PCI BAR *does not* have
PCI_BASE_ADDRESS_MEM_PREFETCHdo we know it must not never want WC ?If we don't have certainty on any of the above I'm afraid we can't do much right now but perhaps we can push towards better use of
PCI_BASE_ADDRESS_MEM_PREFETCHand hope folks will only use this for the full PCI BAR only if WC is desired.Thoughts?
Bjorn, now that you're done schooling me on English, any thoughts on the above?
Quoted 41 lines
Quoted 32 lines
Quoted 32 lines
Although there is also
arch_phys_wc_add()that makes use of architecture specific write-combinging alternatives (MTRR on x86 when a system does not have PAT) we void pollutingpci_iomap()space with it and force drivers and subsystems that want to use it to be explicit.There are a few motivations for this:
a) Take advantage of PAT when available
b) Help bury MTRR code away, MTRR is architecture specific and on x86 its replaced by PAT
c) Help with the goal of eventually using
_PAGE_CACHE_UCover_PAGE_CACHE_UC_MINUSon x86 onioremap_nocache()(de33c442e)
...lib/pci_iomap.c +15
-0+void __iomem *pci_iomap_wc_range (struct pci_dev *dev, +int bar, +unsigned long offset, +unsigned long maxlen) +{ +resource_size_t start =pci_resource_start (dev, bar); +resource_size_t len =pci_resource_len (dev, bar); +unsigned long flags =pci_resource_flags (dev, bar); + +if (len <= offset || !start) +return NULL ; + len -= offset; + start += offset; +if (maxlen && len > maxlen) + len = maxlen;Quoted 8 lines
lib/pci_iomap.c void __iomem *pci_iomap_range(struct pci_dev *dev, · line 87
Quoted 3 lines
lib/pci_iomap.c +3
-0+if (flags &IORESOURCE_IO ) +return __pci_ioport_map (dev, start, len); +if (flags &IORESOURCE_MEM )Should we log a note in dmesg if the BAR is *not*
IORESOURCE_PREFETCH?
I know the driver might know it's safe even if the device didn't mark
the BAR as prefetchable, but it does seem like an easy way for a driver to shoot itself in the foot.
Quoted 3 lines
You tell me. I would fear this may not be consistent and we'd end up having bug reports open for something that has historically been a non-issue. The above questions can help us gauge the risk of this.
Now, I'll tell you what I *think* but these are just guestimates (TM):
* Likely PCI_BASE_ADDRESS_MEM_PREFETCH can implate IORESOURCE_PREFETCH and use of ioremap_wc() on a full PCI BAR only, but this strict definition likely cannot be 100% guaranteed and could break some devices. We need something a bit more concrete and well known so that next generation industry standards embrace and let us in the kernel automatically detect specific ranges and their respective page attribute requirements. Might be good to address here x86 and ARM families
Curious: Sarah, how does USB address these different different page attribute needs on USB 3.0?
Luis
Re: [PATCH v1 05/47] pci: add pci_iomap_wc() variants
In reply to Bjorn HelgaasQuoted 3 lines · Bjorn Helgaas
Hi Luis,
This seems OK to me,
Great.
Quoted 11 lines
but I'm curious about a few things.
Quoted 5 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
This allows drivers to take advantage of write-combining when possible. Ideally we'd have
pci_read_bases()just peg anIORESOURCE_WCflag for usWe do set
IORESOURCE_PREFETCH. Do you mean something different?
I did not think we had a WC IORESOURCE flag. Are you saying that we can use IORESOURCE_PREFETCH for that purpose? If so then great. As I read a PCI BAR can have PCI_BASE_ADDRESS_MEM_PREFETCH and when that's the case we peg IORESOURCE_PREFETCH. That seems to be what I want indeed. Questions below.
Quoted 11 lines
Quoted 5 lines
but where exactly
video devices memory lie varies *largely* and at times things are mixed with MMIO registers, sometimes we can address the changes in drivers, other times the change requires intrusive changes.What does a video device address have to do with this? I do see that if a BAR maps only a frame buffer, the device might be able to mark it prefetchable, while if the BAR mapped both a frame buffer and some registers, it might not be able to make it prefetchable. But that doesn't seem like it depends on the *address*.
I meant the offsets for each of those, either registers or framebuffer, and that typically they are mixed (primarily on older devices), so indeed your summary of the problem is what I meant. Let's remember that we are trying to take advantage of PAT here when available and avoid MTRR in that case, do we know that the same PCI BARs that have always historically used MTRRs had IORESOURCE_PREFETCH set, is that a fair assumption ? I realize they are different things -- but its precisely why I ask.
Quoted 9 lines
pci_iomap_range()already makes a cacheable mapping ifIORESOURCE_CACHEABLE; I'm guessing that you would like it to automatically use WC if the BAR ifIORESOURCE_PREFETCH, e.g.,if (flags & IORESOURCE_CACHEABLE) return ioremap(start, len); if (flags & IORESOURCE_PREFETCH) return ioremap_wc(start, len); return ioremap_nocache(start, len);
Indeed, that's exactly what I think we should strive towards.
Quoted 1 line
Is there a reason not to do that?
This depends on the exact defintion of IORESOURCE_PREFETCH and PCI_BASE_ADDRESS_MEM_PREFETCH and how they are used all over and accross *all devices*. This didn't look promising for starters:
include/uapi/linux/pci_regs.h:#define PCI_BASE_ADDRESS_MEM_PREFETCH 0x08 /* prefetchable? */
PCI_BASE_ADDRESS_MEM_PREFETCH seems to be BAR specific, so a few questions:
1) Can we rest assured for instance that if we check for PCI_BASE_ADDRESS_MEM_PREFETCH and if set that it will *only* be set on a full PCI BAR if the full PCI BAR does want WC? If not this can regress functionality. That seems risky. It however would not be risky if we used another API that did look for IORESOURCE_PREFETCH and if so use ioremap_wc() -- that way only drivers we know that do use the full PCI bar would use this API. There's a bit of a problem with this though:
2) Do we know that if a *full PCI BAR* is used for WC that PCI_BASE_ADDRESS_MEM_PREFETCH *was* definitely set for the PCI BAR? If so then the API usage would be restricted only to devices that we know *do* adhere to this. That reduces the possible uses for older drivers and can create regressions if used loosely without verification... but..
3) If from now on we get folks to commit to uset PCI_BASE_ADDRESS_MEM_PREFETCH for full PCI BARs that do want WC perhaps newer devices / drivers will use this very consistently ? Can we bank on that and is it worth it ?
4) If a PCI BAR *does not* have PCI_BASE_ADDRESS_MEM_PREFETCH do we know it must not never want WC ?
If we don't have certainty on any of the above I'm afraid we can't do much right now but perhaps we can push towards better use of PCI_BASE_ADDRESS_MEM_PREFETCH and hope folks will only use this for the full PCI BAR only if WC is desired.
Thoughts?
Quoted 32 lines
Quoted 32 lines
Although there is also
arch_phys_wc_add()that makes use of architecture specific write-combinging alternatives (MTRR on x86 when a system does not have PAT) we void pollutingpci_iomap()space with it and force drivers and subsystems that want to use it to be explicit.There are a few motivations for this:
a) Take advantage of PAT when available
b) Help bury MTRR code away, MTRR is architecture specific and on x86 its replaced by PAT
c) Help with the goal of eventually using
_PAGE_CACHE_UCover_PAGE_CACHE_UC_MINUSon x86 onioremap_nocache()(de33c442e)
...lib/pci_iomap.c +15
-0+void __iomem *pci_iomap_wc_range (struct pci_dev *dev, +int bar, +unsigned long offset, +unsigned long maxlen) +{ +resource_size_t start =pci_resource_start (dev, bar); +resource_size_t len =pci_resource_len (dev, bar); +unsigned long flags =pci_resource_flags (dev, bar); + +if (len <= offset || !start) +return NULL ; + len -= offset; + start += offset; +if (maxlen && len > maxlen) + len = maxlen;
Quoted 8 lines
lib/pci_iomap.c void __iomem *pci_iomap_range(struct pci_dev *dev, · line 87
Quoted 3 lines
lib/pci_iomap.c +3
-0+if (flags &IORESOURCE_IO ) +return __pci_ioport_map (dev, start, len); +if (flags &IORESOURCE_MEM )Should we log a note in dmesg if the BAR is *not*
IORESOURCE_PREFETCH?
I know the driver might know it's safe even if the device didn't mark
the BAR as prefetchable, but it does seem like an easy way for a driver to shoot itself in the foot.
You tell me. I would fear this may not be consistent and we'd end up having bug reports open for something that has historically been a non-issue. The above questions can help us gauge the risk of this.
Luis
Re: [PATCH v1 05/47] pci: add pci_iomap_wc() variants
In reply to Bjorn HelgaasOn Mon, 2015-03-23 at 12:20 -0500, Bjorn Helgaas wrote:
:
Quoted 6 lines
pci_iomap_range()already makes a cacheable mapping ifIORESOURCE_CACHEABLE; I'm guessing that you would like it to automatically use WC if the BAR ifIORESOURCE_PREFETCH, e.g.,if (flags & IORESOURCE_CACHEABLE) return ioremap(start, len);
Is this supposed to be ioremap_cache()? ioremap() is the same as ioremap_nocache() at least on x86 per arch/x86/include/asm/io.h.
Quoted 4 lines
if (flags & IORESOURCE_PREFETCH)
return ioremap_wc(start, len);
return ioremap_nocache(start, len);-Toshi
Re: [PATCH v1 05/47] pci: add pci_iomap_wc() variants
In reply to Bjorn HelgaasQuoted 11 lines · Bjorn Helgaas
pci_iomap_range()already makes a cacheable mapping ifIORESOURCE_CACHEABLE; I'm guessing that you would like it to automatically use WC if the BAR ifIORESOURCE_PREFETCH, e.g.,if (flags & IORESOURCE_CACHEABLE) return ioremap(start, len); if (flags & IORESOURCE_PREFETCH) return ioremap_wc(start, len); return ioremap_nocache(start, len);Is there a reason not to do that?
I think that's wrong and will break a bunch of things.
PCI prefetch bit merely means bridges can combine writes and prefetch reads. Prefetch does not affect ordering rules and does not allow writes to be collapsed.
WC is stronger: it allows collapsing and changes ordering rules.
WC can also hurt latency as small writes are buffered.
To summarise, driver needs to know what it's doing, we can't set WC in the pci core automatically.
Signature · 1 line
MST
Re: [PATCH v1 05/47] pci: add pci_iomap_wc() variants
Quoted 2 lines · Michael S. Tsirkin
To summarise, driver needs to know what it's doing, we can't set WC in the pci core automatically.
Thanks, I'll document this and proceed with device driver helpers to aid with this.
Luis
Re: [PATCH v1 05/47] pci: add pci_iomap_wc() variants
In reply to Luis R. RodriguezQuoted 10 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
This allows drivers to take advantage of write-combining when possible. Ideally we'd have
pci_read_bases()just peg anIORESOURCE_WCflag for us but where exactly video devices memory lie varies *largely* and at times things are mixed with MMIO registers, sometimes we can address the changes in drivers, other times the change requires intrusive changes.
Quoted 2 lines
Although there is also
arch_phys_wc_add()that makes use of architecture specific write-combinging alternatives (MTRR on
combinging?
Quoted 99 lines
x86 when a system does not have PAT) we void polluting
pci_iomap()space with it and force drivers and subsystems that want to use it to be explicit.There are a few motivations for this:
a) Take advantage of PAT when available
b) Help bury MTRR code away, MTRR is architecture specific and on x86 its replaced by PAT
c) Help with the goal of eventually using
_PAGE_CACHE_UCover_PAGE_CACHE_UC_MINUSon x86 onioremap_nocache()(de33c442e)Cc Andy Lutomirski <[email protected]>Cc Suresh Siddha <[email protected]>Cc Venkatesh Pallipadi <[email protected]>Cc Ingo Molnar <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Juergen Gross <[email protected]>Cc Daniel Vetter <[email protected]>Cc Dave Airlie <[email protected]>Cc Bjorn Helgaas <[email protected]>Cc Antonino Daplas <[email protected]>Cc Jean-Christophe Plagniol-Villard <[email protected]>Cc Tomi Valkeinen <[email protected]>Cc Dave Hansen <[email protected]>Cc Arnd Bergmann <[email protected]>Cc Michael S. Tsirkin <[email protected]>Cc Stefan Bader <[email protected]>Cc Roger Pau Monné <[email protected]>Signed-off-by Luis R. Rodriguez <[email protected]>--- include/asm-generic/pci_iomap.h | 14 ++++++++++ lib/pci_iomap.c | 61 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+)include/asm-generic/pci_iomap.h +14
-0@@ -15,9 +15,13 @@ struct pci_dev;#ifdef CONFIG_PCI /* Create a virtual mapping cookie for a PCI BAR (memory or IO) */ extern void __iomem *pci_iomap (struct pci_dev *dev,int bar,unsigned long max); +extern void __iomem *pci_iomap_wc (struct pci_dev *dev,int bar,unsigned long max);extern void __iomem *pci_iomap_range (struct pci_dev *dev,int bar,unsigned long offset,unsigned long maxlen); +extern void __iomem *pci_iomap_wc_range (struct pci_dev *dev,int bar, +unsigned long offset, +unsigned long maxlen);/* Create a virtual mapping cookie for a port on a given PCI device. * Do not call this directly, it exists to make it easier for architectures * to override */ @@ -34,12 +38,22 @@ static inline void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned lonreturn NULL ; } +static inline void __iomem *pci_iomap_wc (struct pci_dev *dev,int bar,unsigned long max) +{ +return NULL ; +}static inline void __iomem *pci_iomap_range (struct pci_dev *dev,int bar,unsigned long offset,unsigned long maxlen) {return NULL ; } +static inline void __iomem *pci_iomap_wc_range (struct pci_dev *dev,int bar, +unsigned long offset, +unsigned long maxlen) +{ +return NULL ; +}#endif #endif /* __ASM_GENERIC_IO_H */ lib/pci_iomap.c +4
-0@@ -52,6 +52,46 @@ void __iomem *pci_iomap_range(struct pci_dev *dev,EXPORT_SYMBOL (pci_iomap_range);/** +* pci_iomap_wc_range - create a virtual WC mapping cookie for a PCI BAR +* @dev: PCI device that owns the BAR +* @bar: BAR number +* @offset: map memory at the given offset in BAR
lib/pci_iomap.c void __iomem *pci_iomap_range(struct pci_dev *dev, · line 68
Quoted 10 lines
lib/pci_iomap.c +10
-0+* @maxlen: max length of the memory to map +* +* Using this function you will get a __iomem address to your device BAR. +* You can access it using ioread*() and iowrite*(). These functions hide +* the details if this is a MMIO or PIO address space and will just do what +* you expect from them in the correct way. When possible write combining +* is used. +* +* @maxlen specifies the maximum length to map. If you want to get access to +* the complete BAR from offset to the end, pass %0 here.
s/%0/0 ? Or is that some special syntax?
Quoted 58 lines
lib/pci_iomap.c +47
-0+* */ +void __iomem *pci_iomap_wc_range (struct pci_dev *dev, +int bar, +unsigned long offset, +unsigned long maxlen) +{ +resource_size_t start =pci_resource_start (dev, bar); +resource_size_t len =pci_resource_len (dev, bar); +unsigned long flags =pci_resource_flags (dev, bar); + +if (len <= offset || !start) +return NULL ; + len -= offset; + start += offset; +if (maxlen && len > maxlen) + len = maxlen; +if (flags &IORESOURCE_IO ) +return __pci_ioport_map (dev, start, len); +if (flags &IORESOURCE_MEM ) +return ioremap_wc (start, len); +/* What? */ +return NULL ; +} +EXPORT_SYMBOL_GPL (pci_iomap_wc_range); + +/** * pci_iomap - create a virtual mapping cookie for a PCI BAR * @dev: PCI device that owns the BAR * @bar: BAR number @@ -70,4 +110,25 @@ void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long maxlen) return pci_iomap_range(dev, bar, 0, maxlen); }EXPORT_SYMBOL (pci_iomap); + +/** +* pci_iomap_wc - create a virtual WC mapping cookie for a PCI BAR +* @dev: PCI device that owns the BAR +* @bar: BAR number +* @maxlen: length of the memory to map +* +* Using this function you will get a __iomem address to your device BAR. +* You can access it using ioread*() and iowrite*(). These functions hide +* the details if this is a MMIO or PIO address space and will just do what +* you expect from them in the correct way. When possible write combining +* is used. +* +* @maxlen specifies the maximum length to map. If you want to get access to +* the complete BAR without checking for its length first, pass %0 here. +* */ +void __iomem *pci_iomap_wc (struct pci_dev *dev,int bar,unsigned long maxlen) +{ +return pci_iomap_wc_range (dev, bar,0 , maxlen); +} +EXPORT_SYMBOL_GPL (pci_iomap_wc);#endif /* CONFIG_PCI */ Signature · 1 line
2.3.2.209.gd67f9d5.dirty
Re: [PATCH v1 05/47] pci: add pci_iomap_wc() variants
Quoted 11 lines · Konrad Rzeszutek Wilk
Quoted 10 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
This allows drivers to take advantage of write-combining when possible. Ideally we'd have
pci_read_bases()just peg anIORESOURCE_WCflag for us but where exactly video devices memory lie varies *largely* and at times things are mixed with MMIO registers, sometimes we can address the changes in drivers, other times the change requires intrusive changes.
Quoted 4 lines
Quoted 2 lines
Although there is also
arch_phys_wc_add()that makes use of architecture specific write-combinging alternatives (MTRR oncombinging?
Amended.
Quoted 16 lines
Quoted 16 lines
lib/pci_iomap.c +8
-0@@ -52,6 +52,46 @@ void __iomem *pci_iomap_range(struct pci_dev *dev,EXPORT_SYMBOL (pci_iomap_range);/** +* pci_iomap_wc_range - create a virtual WC mapping cookie for a PCI BAR +* @dev: PCI device that owns the BAR +* @bar: BAR number +* @offset: map memory at the given offset in BAR +* @maxlen: max length of the memory to map +* +* Using this function you will get a __iomem address to your device BAR. +* You can access it using ioread*() and iowrite*(). These functions hide
Quoted 8 lines
lib/pci_iomap.c void __iomem *pci_iomap_range(struct pci_dev *dev, · line 68
Quoted 6 lines
lib/pci_iomap.c +6
-0+* the details if this is a MMIO or PIO address space and will just do what +* you expect from them in the correct way. When possible write combining +* is used. +* +* @maxlen specifies the maximum length to map. If you want to get access to +* the complete BAR from offset to the end, pass %0 here. s/%0/0 ? Or is that some special syntax?
This copies the syntax of pci_iomap_range() which also uses %0, and as per Documentation/kernel-doc-nano-HOWTO.txt % is used for constants. See:
scripts/kernel-doc -man -function pci_iomap_range lib/pci_iomap.c | nroff -man | less
Luis
PATCH 6/47 mtrr: add __arch_phys_wc_add()
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
Ideally on systems using PAT we can expect a swift transition away from MTRR. There can be a few exceptions to this, one is where device drivers are known to exist on PATs with errata, another situation is observed on old device drivers where devices had combined MMIO register access with whatever area they typically later wanted to end up using MTRR for on the same PCI BAR. This situation can still be addressed by splitting up ioremap'd PCI BAR into two ioremap'd calls, one for MMIO registers, and another for whatever is desirable for write-combining -- in order to accomplish this though quite a bit of driver restructuring is required.
Device drivers which are known to require large amount of re-work in order to split ioremap'd areas can use __arch_phys_wc_add() to avoid regressions when PAT is enabled.
For a good example driver where things are neatly split up on a PCI BAR refer the infiniband qib driver. For a good example of a driver where good amount of work is required refer to the infiniband ipath driver.
This is *only* a transitive API -- and as such no new drivers are ever expected to use this.
--- arch/x86/include/asm/io.h | 4 ++++ arch/x86/kernel/cpu/mtrr/main.c | 36 +++++++++++++++++++++++++++++------- include/linux/io.h | 4 ++++ 3 files changed, 37 insertions(+), 7 deletions(-)
arch/x86/include/asm/io.h +4 -0
@@ -338,6 +338,10 @@ extern bool xen_biovec_phys_mergeable(const struct bio_vec *vec1,#define IO_SPACE_LIMIT 0xffff#ifdef CONFIG_MTRR +extern int __must_check __arch_phys_wc_add (unsigned long base, +unsigned long size); +#define __arch_phys_wc_add __arch_phys_wc_add +extern int __must_check arch_phys_wc_add (unsigned long base,unsigned long size);extern void arch_phys_wc_del (int handle);
arch/x86/kernel/cpu/mtrr/main.c +29 -7
@@ -538,23 +538,24 @@ int mtrr_del(int reg, unsigned long base, unsigned long size)EXPORT_SYMBOL (mtrr_del);/** -* arch_phys_wc_add - add a WC MTRR and handle errors if PAT is unavailable +* __arch_phys_wc_add - add a WC MTRR even if PAT is available * @base: Physical base address * @size: Size of region * -* If PAT is available, this does nothing. If PAT is unavailable, it -* attempts to add a WC MTRR covering size bytes starting at base and -* logs an error if this fails. +* We typically do not want to use MTRR if PAT is available but there +* are some drivers which require significant work to get this to work +* properly. This call should only be used by those drivers where it is +* clear that hard work is required to modify them to use arch_phys_wc_add() * * Drivers must store the return value to pass to mtrr_del_wc_if_needed, * but drivers should not try to interpret that return value. */ -int arch_phys_wc_add (unsigned long base,unsigned long size) +int __arch_phys_wc_add (unsigned long base,unsigned long size) {int ret; -if (pat_enabled || !mtrr_enabled) -return 0 ;/* Success! (We don't need to do anything.) */ +if (!mtrr_enabled) +return 0 ; ret =mtrr_add (base, size,MTRR_TYPE_WRCOMB , true);if (ret <0 ) {
@@ -564,6 +565,27 @@ int arch_phys_wc_add(unsigned long base, unsigned long size) }return ret +MTRR_TO_PHYS_WC_OFFSET ; } +EXPORT_SYMBOL_GPL (__arch_phys_wc_add); + +/** +* arch_phys_wc_add - add a WC MTRR and handle errors if PAT is unavailable +* @base: Physical base address +* @size: Size of region +* +* If PAT is available, this does nothing. If PAT is unavailable, it +* attempts to add a WC MTRR covering size bytes starting at base and +* logs an error if this fails. +* +* Drivers must store the return value to pass to mtrr_del_wc_if_needed, +* but drivers should not try to interpret that return value. +*/ +int arch_phys_wc_add (unsigned long base,unsigned long size) +{ +if (pat_enabled || !mtrr_enabled) +return 0 ;/* Success! (We don't need to do anything.) */ + +return __arch_phys_wc_add (base, size); +}EXPORT_SYMBOL (arch_phys_wc_add);/*
include/linux/io.h +4 -0
@@ -111,6 +111,10 @@ static inline void arch_phys_wc_del(int handle) }#define arch_phys_wc_add arch_phys_wc_add +#ifndef __arch_phys_wc_add +#define __arch_phys_wc_add arch_phys_wc_add +#endif +#endif #endif /* _LINUX_IO_H */
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
Re: [PATCH v1 06/47] mtrr: add __arch_phys_wc_add()
Quoted 21 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
Ideally on systems using PAT we can expect a swift transition away from MTRR. There can be a few exceptions to this, one is where device drivers are known to exist on PATs with errata, another situation is observed on old device drivers where devices had combined MMIO register access with whatever area they typically later wanted to end up using MTRR for on the same PCI BAR. This situation can still be addressed by splitting up ioremap'd PCI BAR into two ioremap'd calls, one for MMIO registers, and another for whatever is desirable for write-combining -- in order to accomplish this though quite a bit of driver restructuring is required.
Device drivers which are known to require large amount of re-work in order to split ioremap'd areas can use
__arch_phys_wc_add()to avoid regressions when PAT is enabled.
Quoted 8 lines
For a good example driver where things are neatly split up on a PCI BAR refer the infiniband qib driver. For a good example of a driver where good amount of work is required refer to the infiniband ipath driver.
This is *only* a transitive API -- and as such no new drivers are ever expected to use this.
What's the exact layout that this helps? I'm sceptical that this can ever be correct.
Is there some awful driver that has a large ioremap that's supposed to contain multiple different memtypes? If so, can we ioremap + set_page_xyz instead?
--Andy
Re: [PATCH v1 06/47] mtrr: add __arch_phys_wc_add()
Quoted 29 lines · Andy Lutomirski
Quoted 27 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
Ideally on systems using PAT we can expect a swift transition away from MTRR. There can be a few exceptions to this, one is where device drivers are known to exist on PATs with errata, another situation is observed on old device drivers where devices had combined MMIO register access with whatever area they typically later wanted to end up using MTRR for on the same PCI BAR. This situation can still be addressed by splitting up ioremap'd PCI BAR into two ioremap'd calls, one for MMIO registers, and another for whatever is desirable for write-combining -- in order to accomplish this though quite a bit of driver restructuring is required.
Device drivers which are known to require large amount of re-work in order to split ioremap'd areas can use
__arch_phys_wc_add()to avoid regressions when PAT is enabled.For a good example driver where things are neatly split up on a PCI BAR refer the infiniband qib driver. For a good example of a driver where good amount of work is required refer to the infiniband ipath driver.
Quoted 8 lines
Quoted 2 lines
This is *only* a transitive API -- and as such no new drivers are ever expected to use this.
What's the exact layout that this helps? I'm sceptical that this can ever be correct.
Is there some awful driver that has a large ioremap that's supposed to contain multiple different memtypes?
Yes, I cc'd you just now on one where I made changes on a driver which uses one PCI with mixed memtypes and uses MTRR to hole in WC. A transition to arch_phys_wc_add() is therefore not possible if PAT is enabled as it would regress those drivers by making the MTRR WC hole trick non functional. The changes are non trivial and so in this series I supplied changes on one driver only to show the effort required. The other drivers which required this were:
Driver File
------------------------------------------------------------
fusion drivers/message/fusion/mptbase.c
ivtv drivers/media/pci/ivtv/ivtvfb.c
ipath drivers/infiniband/hw/ipath/ipath_driver.c
This series makes those drivers use __arch_phys_wc_add() more as a transitory phase in hopes we can address the proper split as with the atyfb illustrates. For ipath the changes required have a nice template with the qib driver as they share very similar driver structure, the qib driver *did* do the nice split.
Quoted 1 line
If so, can we ioremap +
set_page_xyzinstead?
I'm not sure I see which call we'd use. Care to provide an example patch alternative for the atyfb as a case in point alternative to the work required to do the split?
Luis
Re: [PATCH v1 06/47] mtrr: add __arch_phys_wc_add()
Quoted 59 lines · Luis R. Rodriguez
Quoted 29 lines · Andy Lutomirski
Quoted 27 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
Ideally on systems using PAT we can expect a swift transition away from MTRR. There can be a few exceptions to this, one is where device drivers are known to exist on PATs with errata, another situation is observed on old device drivers where devices had combined MMIO register access with whatever area they typically later wanted to end up using MTRR for on the same PCI BAR. This situation can still be addressed by splitting up ioremap'd PCI BAR into two ioremap'd calls, one for MMIO registers, and another for whatever is desirable for write-combining -- in order to accomplish this though quite a bit of driver restructuring is required.
Device drivers which are known to require large amount of re-work in order to split ioremap'd areas can use
__arch_phys_wc_add()to avoid regressions when PAT is enabled.For a good example driver where things are neatly split up on a PCI BAR refer the infiniband qib driver. For a good example of a driver where good amount of work is required refer to the infiniband ipath driver.
Quoted 8 lines
Quoted 2 lines
This is *only* a transitive API -- and as such no new drivers are ever expected to use this.
What's the exact layout that this helps? I'm sceptical that this can ever be correct.
Is there some awful driver that has a large ioremap that's supposed to contain multiple different memtypes?
Yes, I cc'd you just now on one where I made changes on a driver which uses one PCI with mixed memtypes and uses MTRR to hole in WC. A transition to
arch_phys_wc_add()is therefore not possible if PAT is enabled as it would regress those drivers by making the MTRR WC hole trick non functional. The changes are non trivial and so in this series I supplied changes on one driver only to show the effort required. The other drivers which required this were:Driver File
------------------------------------------------------------fusion drivers/message/fusion/mptbase.c ivtv drivers/media/pci/ivtv/ivtvfb.c ipath drivers/infiniband/hw/ipath/ipath_driver.cThis series makes those drivers use
__arch_phys_wc_add()more as a transitory phase in hopes we can address the proper split as with the atyfb illustrates. For ipath the changes required have a nice template with the qib driver as they share very similar driver structure, the qib driver *did* do the nice split.
Quoted 6 lines
Quoted 1 line
If so, can we ioremap +
set_page_xyzinstead?I'm not sure I see which call we'd use. Care to provide an example patch alternative for the atyfb as a case in point alternative to the work required to do the split?
I'm still confused. Would it be insufficient to ioremap_nocache the whole thing and then call set_memory_wc on parts of it? (Sorry, set_page_xyz was a typo.)
--Andy
Signature · 2 lines
Andy Lutomirski AMA Capital Management, LLC
Re: [PATCH v1 06/47] mtrr: add __arch_phys_wc_add()
Quoted 62 lines · Andy Lutomirski
Quoted 61 lines · Luis R. Rodriguez
Quoted 29 lines · Andy Lutomirski
Quoted 27 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
Ideally on systems using PAT we can expect a swift transition away from MTRR. There can be a few exceptions to this, one is where device drivers are known to exist on PATs with errata, another situation is observed on old device drivers where devices had combined MMIO register access with whatever area they typically later wanted to end up using MTRR for on the same PCI BAR. This situation can still be addressed by splitting up ioremap'd PCI BAR into two ioremap'd calls, one for MMIO registers, and another for whatever is desirable for write-combining -- in order to accomplish this though quite a bit of driver restructuring is required.
Device drivers which are known to require large amount of re-work in order to split ioremap'd areas can use
__arch_phys_wc_add()to avoid regressions when PAT is enabled.For a good example driver where things are neatly split up on a PCI BAR refer the infiniband qib driver. For a good example of a driver where good amount of work is required refer to the infiniband ipath driver.
Quoted 8 lines
Quoted 2 lines
This is *only* a transitive API -- and as such no new drivers are ever expected to use this.
What's the exact layout that this helps? I'm sceptical that this can ever be correct.
Is there some awful driver that has a large ioremap that's supposed to contain multiple different memtypes?
Yes, I cc'd you just now on one where I made changes on a driver which uses one PCI with mixed memtypes and uses MTRR to hole in WC. A transition to
arch_phys_wc_add()is therefore not possible if PAT is enabled as it would regress those drivers by making the MTRR WC hole trick non functional. The changes are non trivial and so in this series I supplied changes on one driver only to show the effort required. The other drivers which required this were:Driver File
------------------------------------------------------------fusion drivers/message/fusion/mptbase.c ivtv drivers/media/pci/ivtv/ivtvfb.c ipath drivers/infiniband/hw/ipath/ipath_driver.cThis series makes those drivers use
__arch_phys_wc_add()more as a transitory phase in hopes we can address the proper split as with the atyfb illustrates. For ipath the changes required have a nice template with the qib driver as they share very similar driver structure, the qib driver *did* do the nice split.Quoted 1 line
If so, can we ioremap +
set_page_xyzinstead?
Quoted 8 lines
Quoted 4 lines
I'm not sure I see which call we'd use. Care to provide an example patch alternative for the atyfb as a case in point alternative to the work required to do the split?
I'm still confused. Would it be insufficient to
ioremap_nocachethe whole thing and then callset_memory_wcon parts of it? (Sorry,set_page_xyzwas a typo.)
I think that would be a sexy alternative.
In this driver's case the thing is a bit messy as it not only used the WC MTRR for a hole but it also then used a UC MTRR on top of it all, so since I already tried to address the split, and if we address the power of 2 woes, I think it'd be best to try to remove the UC MTRR and just avoid set_page_wc() in this driver's case, but for the other cases (fusion, ivtv, ipath) I think this makes sense.
Thoughts?
Luis
Re: [PATCH v1 06/47] mtrr: add __arch_phys_wc_add()
Quoted 74 lines · Luis R. Rodriguez
Quoted 62 lines · Andy Lutomirski
Quoted 61 lines · Luis R. Rodriguez
Quoted 29 lines · Andy Lutomirski
Quoted 27 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
Ideally on systems using PAT we can expect a swift transition away from MTRR. There can be a few exceptions to this, one is where device drivers are known to exist on PATs with errata, another situation is observed on old device drivers where devices had combined MMIO register access with whatever area they typically later wanted to end up using MTRR for on the same PCI BAR. This situation can still be addressed by splitting up ioremap'd PCI BAR into two ioremap'd calls, one for MMIO registers, and another for whatever is desirable for write-combining -- in order to accomplish this though quite a bit of driver restructuring is required.
Device drivers which are known to require large amount of re-work in order to split ioremap'd areas can use
__arch_phys_wc_add()to avoid regressions when PAT is enabled.For a good example driver where things are neatly split up on a PCI BAR refer the infiniband qib driver. For a good example of a driver where good amount of work is required refer to the infiniband ipath driver.
Quoted 8 lines
Quoted 2 lines
This is *only* a transitive API -- and as such no new drivers are ever expected to use this.
What's the exact layout that this helps? I'm sceptical that this can ever be correct.
Is there some awful driver that has a large ioremap that's supposed to contain multiple different memtypes?
Yes, I cc'd you just now on one where I made changes on a driver which uses one PCI with mixed memtypes and uses MTRR to hole in WC. A transition to
arch_phys_wc_add()is therefore not possible if PAT is enabled as it would regress those drivers by making the MTRR WC hole trick non functional. The changes are non trivial and so in this series I supplied changes on one driver only to show the effort required. The other drivers which required this were:Driver File
------------------------------------------------------------fusion drivers/message/fusion/mptbase.c ivtv drivers/media/pci/ivtv/ivtvfb.c ipath drivers/infiniband/hw/ipath/ipath_driver.cThis series makes those drivers use
__arch_phys_wc_add()more as a transitory phase in hopes we can address the proper split as with the atyfb illustrates. For ipath the changes required have a nice template with the qib driver as they share very similar driver structure, the qib driver *did* do the nice split.Quoted 1 line
If so, can we ioremap +
set_page_xyzinstead?Quoted 8 lines
Quoted 4 lines
I'm not sure I see which call we'd use. Care to provide an example patch alternative for the atyfb as a case in point alternative to the work required to do the split?
I'm still confused. Would it be insufficient to
ioremap_nocachethe whole thing and then callset_memory_wcon parts of it? (Sorry,set_page_xyzwas a typo.)I think that would be a sexy alternative.
Quoted 8 lines
In this driver's case the thing is a bit messy as it not only used the WC MTRR for a hole but it also then used a UC MTRR on top of it all, so since I already tried to address the split, and if we address the power of 2 woes, I think it'd be best to try to remove the UC MTRR and just avoid
set_page_wc()in this driver's case, but for the other cases (fusion, ivtv, ipath) I think this makes sense.Thoughts?
Once that WC MTRR is in place, I think you really need UC and not UC- if you want to override it. Otherwise I agree with all of this.
--Andy
Re: [PATCH v1 06/47] mtrr: add __arch_phys_wc_add()
Quoted 82 lines · Andy Lutomirski
Quoted 81 lines · Luis R. Rodriguez
Quoted 62 lines · Andy Lutomirski
Quoted 61 lines · Luis R. Rodriguez
Quoted 29 lines · Andy Lutomirski
Quoted 27 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
Ideally on systems using PAT we can expect a swift transition away from MTRR. There can be a few exceptions to this, one is where device drivers are known to exist on PATs with errata, another situation is observed on old device drivers where devices had combined MMIO register access with whatever area they typically later wanted to end up using MTRR for on the same PCI BAR. This situation can still be addressed by splitting up ioremap'd PCI BAR into two ioremap'd calls, one for MMIO registers, and another for whatever is desirable for write-combining -- in order to accomplish this though quite a bit of driver restructuring is required.
Device drivers which are known to require large amount of re-work in order to split ioremap'd areas can use
__arch_phys_wc_add()to avoid regressions when PAT is enabled.For a good example driver where things are neatly split up on a PCI BAR refer the infiniband qib driver. For a good example of a driver where good amount of work is required refer to the infiniband ipath driver.
Quoted 8 lines
Quoted 2 lines
This is *only* a transitive API -- and as such no new drivers are ever expected to use this.
What's the exact layout that this helps? I'm sceptical that this can ever be correct.
Is there some awful driver that has a large ioremap that's supposed to contain multiple different memtypes?
Yes, I cc'd you just now on one where I made changes on a driver which uses one PCI with mixed memtypes and uses MTRR to hole in WC. A transition to
arch_phys_wc_add()is therefore not possible if PAT is enabled as it would regress those drivers by making the MTRR WC hole trick non functional. The changes are non trivial and so in this series I supplied changes on one driver only to show the effort required. The other drivers which required this were:Driver File
------------------------------------------------------------fusion drivers/message/fusion/mptbase.c ivtv drivers/media/pci/ivtv/ivtvfb.c ipath drivers/infiniband/hw/ipath/ipath_driver.cThis series makes those drivers use
__arch_phys_wc_add()more as a transitory phase in hopes we can address the proper split as with the atyfb illustrates. For ipath the changes required have a nice template with the qib driver as they share very similar driver structure, the qib driver *did* do the nice split.Quoted 1 line
If so, can we ioremap +
set_page_xyzinstead?Quoted 8 lines
Quoted 4 lines
I'm not sure I see which call we'd use. Care to provide an example patch alternative for the atyfb as a case in point alternative to the work required to do the split?
I'm still confused. Would it be insufficient to
ioremap_nocachethe whole thing and then callset_memory_wcon parts of it? (Sorry,set_page_xyzwas a typo.)I think that would be a sexy alternative.
In this driver's case the thing is a bit messy as it not only used the WC MTRR for a hole but it also then used a UC MTRR on top of it all, so since I already tried to address the split, and if we address the power of 2 woes, I think it'd be best to try to remove the UC MTRR and just avoid
set_page_wc()in this driver's case, but for the other cases (fusion, ivtv, ipath) I think this makes sense.
Quoted 4 lines
Quoted 1 line
Thoughts?
Once that WC MTRR is in place, I think you really need UC and not UC- if you want to override it. Otherwise I agree with all of this.
Do you mean that the UC MTRR work around that was in place might not have really been effective? Not quite sure what you mean. I don't think I follow.
Luis
Re: [PATCH v1 06/47] mtrr: add __arch_phys_wc_add()
Quoted 83 lines · Luis R. Rodriguez
Quoted 82 lines · Andy Lutomirski
Quoted 81 lines · Luis R. Rodriguez
Quoted 62 lines · Andy Lutomirski
Quoted 61 lines · Luis R. Rodriguez
Quoted 29 lines · Andy Lutomirski
Quoted 27 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
Ideally on systems using PAT we can expect a swift transition away from MTRR. There can be a few exceptions to this, one is where device drivers are known to exist on PATs with errata, another situation is observed on old device drivers where devices had combined MMIO register access with whatever area they typically later wanted to end up using MTRR for on the same PCI BAR. This situation can still be addressed by splitting up ioremap'd PCI BAR into two ioremap'd calls, one for MMIO registers, and another for whatever is desirable for write-combining -- in order to accomplish this though quite a bit of driver restructuring is required.
Device drivers which are known to require large amount of re-work in order to split ioremap'd areas can use
__arch_phys_wc_add()to avoid regressions when PAT is enabled.For a good example driver where things are neatly split up on a PCI BAR refer the infiniband qib driver. For a good example of a driver where good amount of work is required refer to the infiniband ipath driver.
Quoted 8 lines
Quoted 2 lines
This is *only* a transitive API -- and as such no new drivers are ever expected to use this.
What's the exact layout that this helps? I'm sceptical that this can ever be correct.
Is there some awful driver that has a large ioremap that's supposed to contain multiple different memtypes?
Yes, I cc'd you just now on one where I made changes on a driver which uses one PCI with mixed memtypes and uses MTRR to hole in WC. A transition to
arch_phys_wc_add()is therefore not possible if PAT is enabled as it would regress those drivers by making the MTRR WC hole trick non functional. The changes are non trivial and so in this series I supplied changes on one driver only to show the effort required. The other drivers which required this were:Driver File
------------------------------------------------------------fusion drivers/message/fusion/mptbase.c ivtv drivers/media/pci/ivtv/ivtvfb.c ipath drivers/infiniband/hw/ipath/ipath_driver.cThis series makes those drivers use
__arch_phys_wc_add()more as a transitory phase in hopes we can address the proper split as with the atyfb illustrates. For ipath the changes required have a nice template with the qib driver as they share very similar driver structure, the qib driver *did* do the nice split.Quoted 1 line
If so, can we ioremap +
set_page_xyzinstead?Quoted 8 lines
Quoted 4 lines
I'm not sure I see which call we'd use. Care to provide an example patch alternative for the atyfb as a case in point alternative to the work required to do the split?
I'm still confused. Would it be insufficient to
ioremap_nocachethe whole thing and then callset_memory_wcon parts of it? (Sorry,set_page_xyzwas a typo.)I think that would be a sexy alternative.
In this driver's case the thing is a bit messy as it not only used the WC MTRR for a hole but it also then used a UC MTRR on top of it all, so since I already tried to address the split, and if we address the power of 2 woes, I think it'd be best to try to remove the UC MTRR and just avoid
set_page_wc()in this driver's case, but for the other cases (fusion, ivtv, ipath) I think this makes sense.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Thoughts?
Once that WC MTRR is in place, I think you really need UC and not UC- if you want to override it. Otherwise I agree with all of this.
Do you mean that the UC MTRR work around that was in place might not have really been effective? Not quite sure what you mean. I don't think I follow.
I mean that the UC MTRR that overrides the WC MTRR was probably fine (I hope smaller MTRRs override larger MTRRs). But we should just ditch UC MTRRs entirely, and setting UC in the page tables would work on all CPUs *if we supported that*. We'd need to add a couple trivial helpers to do that.
--Andy
Quoted 2 lines
Luis
Signature · 2 lines
Andy Lutomirski AMA Capital Management, LLC
Re: [PATCH v1 06/47] mtrr: add __arch_phys_wc_add()
Quoted 89 lines · Andy Lutomirski
Quoted 88 lines · Luis R. Rodriguez
Quoted 86 lines · Andy Lutomirski
Quoted 74 lines · Luis R. Rodriguez
Quoted 62 lines · Andy Lutomirski
Quoted 61 lines · Luis R. Rodriguez
Quoted 29 lines · Andy Lutomirski
Quoted 27 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
Ideally on systems using PAT we can expect a swift transition away from MTRR. There can be a few exceptions to this, one is where device drivers are known to exist on PATs with errata, another situation is observed on old device drivers where devices had combined MMIO register access with whatever area they typically later wanted to end up using MTRR for on the same PCI BAR. This situation can still be addressed by splitting up ioremap'd PCI BAR into two ioremap'd calls, one for MMIO registers, and another for whatever is desirable for write-combining -- in order to accomplish this though quite a bit of driver restructuring is required.
Device drivers which are known to require large amount of re-work in order to split ioremap'd areas can use
__arch_phys_wc_add()to avoid regressions when PAT is enabled.For a good example driver where things are neatly split up on a PCI BAR refer the infiniband qib driver. For a good example of a driver where good amount of work is required refer to the infiniband ipath driver.
Quoted 8 lines
Quoted 2 lines
This is *only* a transitive API -- and as such no new drivers are ever expected to use this.
What's the exact layout that this helps? I'm sceptical that this can ever be correct.
Is there some awful driver that has a large ioremap that's supposed to contain multiple different memtypes?
Yes, I cc'd you just now on one where I made changes on a driver which uses one PCI with mixed memtypes and uses MTRR to hole in WC. A transition to
arch_phys_wc_add()is therefore not possible if PAT is enabled as it would regress those drivers by making the MTRR WC hole trick non functional. The changes are non trivial and so in this series I supplied changes on one driver only to show the effort required. The other drivers which required this were:Driver File
------------------------------------------------------------fusion drivers/message/fusion/mptbase.c ivtv drivers/media/pci/ivtv/ivtvfb.c ipath drivers/infiniband/hw/ipath/ipath_driver.cThis series makes those drivers use
__arch_phys_wc_add()more as a transitory phase in hopes we can address the proper split as with the atyfb illustrates. For ipath the changes required have a nice template with the qib driver as they share very similar driver structure, the qib driver *did* do the nice split.Quoted 1 line
If so, can we ioremap +
set_page_xyzinstead?Quoted 8 lines
Quoted 4 lines
I'm not sure I see which call we'd use. Care to provide an example patch alternative for the atyfb as a case in point alternative to the work required to do the split?
I'm still confused. Would it be insufficient to
ioremap_nocachethe whole thing and then callset_memory_wcon parts of it? (Sorry,set_page_xyzwas a typo.)I think that would be a sexy alternative.
Quoted 8 lines
In this driver's case the thing is a bit messy as it not only used the WC MTRR for a hole but it also then used a UC MTRR on top of it all, so since I already tried to address the split, and if we address the power of 2 woes, I think it'd be best to try to remove the UC MTRR and just avoid
set_page_wc()in this driver's case, but for the other cases (fusion, ivtv, ipath) I think this makes sense.Thoughts?
Once that WC MTRR is in place, I think you really need UC and not UC- if you want to override it. Otherwise I agree with all of this.
Quoted 7 lines
Quoted 3 lines
Do you mean that the UC MTRR work around that was in place might not have really been effective? Not quite sure what you mean. I don't think I follow.
I mean that the UC MTRR that overrides the WC MTRR was probably fine (I hope smaller MTRRs override larger MTRRs). But we should just ditch UC MTRRs entirely,
Agreed, this series does that, and this patch addresses the last UC MTRR ;)
Quoted 2 lines
and setting UC in the page tables would work on all CPUs *if we supported that*. We'd need to add a couple trivial helpers to do that.
OK please check my latest reply and if you do not mind clarify what you mean there as I am not sure if we're on the same page (no pun) here. I don't quite follow this last statement.
Luis
Re: [PATCH v1 06/47] mtrr: add __arch_phys_wc_add()
In reply to Andy LutomirskiQuoted 89 lines · Andy Lutomirski
Quoted 88 lines · Luis R. Rodriguez
Quoted 86 lines · Andy Lutomirski
Quoted 74 lines · Luis R. Rodriguez
Quoted 62 lines · Andy Lutomirski
Quoted 61 lines · Luis R. Rodriguez
Quoted 29 lines · Andy Lutomirski
Quoted 27 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
Ideally on systems using PAT we can expect a swift transition away from MTRR. There can be a few exceptions to this, one is where device drivers are known to exist on PATs with errata, another situation is observed on old device drivers where devices had combined MMIO register access with whatever area they typically later wanted to end up using MTRR for on the same PCI BAR. This situation can still be addressed by splitting up ioremap'd PCI BAR into two ioremap'd calls, one for MMIO registers, and another for whatever is desirable for write-combining -- in order to accomplish this though quite a bit of driver restructuring is required.
Device drivers which are known to require large amount of re-work in order to split ioremap'd areas can use
__arch_phys_wc_add()to avoid regressions when PAT is enabled.For a good example driver where things are neatly split up on a PCI BAR refer the infiniband qib driver. For a good example of a driver where good amount of work is required refer to the infiniband ipath driver.
Quoted 8 lines
Quoted 2 lines
This is *only* a transitive API -- and as such no new drivers are ever expected to use this.
What's the exact layout that this helps? I'm sceptical that this can ever be correct.
Is there some awful driver that has a large ioremap that's supposed to contain multiple different memtypes?
Yes, I cc'd you just now on one where I made changes on a driver which uses one PCI with mixed memtypes and uses MTRR to hole in WC. A transition to
arch_phys_wc_add()is therefore not possible if PAT is enabled as it would regress those drivers by making the MTRR WC hole trick non functional. The changes are non trivial and so in this series I supplied changes on one driver only to show the effort required. The other drivers which required this were:Driver File
------------------------------------------------------------fusion drivers/message/fusion/mptbase.c ivtv drivers/media/pci/ivtv/ivtvfb.c ipath drivers/infiniband/hw/ipath/ipath_driver.cThis series makes those drivers use
__arch_phys_wc_add()more as a transitory phase in hopes we can address the proper split as with the atyfb illustrates. For ipath the changes required have a nice template with the qib driver as they share very similar driver structure, the qib driver *did* do the nice split.Quoted 1 line
If so, can we ioremap +
set_page_xyzinstead?Quoted 8 lines
Quoted 4 lines
I'm not sure I see which call we'd use. Care to provide an example patch alternative for the atyfb as a case in point alternative to the work required to do the split?
I'm still confused. Would it be insufficient to
ioremap_nocachethe whole thing and then callset_memory_wcon parts of it? (Sorry,set_page_xyzwas a typo.)I think that would be a sexy alternative.
Quoted 8 lines
In this driver's case the thing is a bit messy as it not only used the WC MTRR for a hole but it also then used a UC MTRR on top of it all, so since I already tried to address the split, and if we address the power of 2 woes, I think it'd be best to try to remove the UC MTRR and just avoid
set_page_wc()in this driver's case, but for the other cases (fusion, ivtv, ipath) I think this makes sense.Thoughts?
Once that WC MTRR is in place, I think you really need UC and not UC- if you want to override it. Otherwise I agree with all of this.
Quoted 7 lines
Quoted 3 lines
Do you mean that the UC MTRR work around that was in place might not have really been effective? Not quite sure what you mean. I don't think I follow.
I mean that the UC MTRR that overrides the WC MTRR was probably fine (I hope smaller MTRRs override larger MTRRs). But we should just ditch UC MTRRs entirely,
Agreed, this series does that, and this patch addresses the last UC MTRR ;)
Quoted 2 lines
and setting UC in the page tables would work on all CPUs *if we supported that*. We'd need to add a couple trivial helpers to do that.
OK please check my latest reply and if you do not mind clarify what you mean there as I am not sure if we're on the same page (no pun) here. I don't quite follow this last statement.
Luis
Re: [PATCH v1 06/47] mtrr: add __arch_phys_wc_add()
In reply to Luis R. RodriguezQuoted 83 lines · Luis R. Rodriguez
Quoted 82 lines · Andy Lutomirski
Quoted 81 lines · Luis R. Rodriguez
Quoted 62 lines · Andy Lutomirski
Quoted 61 lines · Luis R. Rodriguez
Quoted 29 lines · Andy Lutomirski
Quoted 27 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
Ideally on systems using PAT we can expect a swift transition away from MTRR. There can be a few exceptions to this, one is where device drivers are known to exist on PATs with errata, another situation is observed on old device drivers where devices had combined MMIO register access with whatever area they typically later wanted to end up using MTRR for on the same PCI BAR. This situation can still be addressed by splitting up ioremap'd PCI BAR into two ioremap'd calls, one for MMIO registers, and another for whatever is desirable for write-combining -- in order to accomplish this though quite a bit of driver restructuring is required.
Device drivers which are known to require large amount of re-work in order to split ioremap'd areas can use
__arch_phys_wc_add()to avoid regressions when PAT is enabled.For a good example driver where things are neatly split up on a PCI BAR refer the infiniband qib driver. For a good example of a driver where good amount of work is required refer to the infiniband ipath driver.
Quoted 8 lines
Quoted 2 lines
This is *only* a transitive API -- and as such no new drivers are ever expected to use this.
What's the exact layout that this helps? I'm sceptical that this can ever be correct.
Is there some awful driver that has a large ioremap that's supposed to contain multiple different memtypes?
Yes, I cc'd you just now on one where I made changes on a driver which uses one PCI with mixed memtypes and uses MTRR to hole in WC. A transition to
arch_phys_wc_add()is therefore not possible if PAT is enabled as it would regress those drivers by making the MTRR WC hole trick non functional. The changes are non trivial and so in this series I supplied changes on one driver only to show the effort required. The other drivers which required this were:Driver File
------------------------------------------------------------fusion drivers/message/fusion/mptbase.c ivtv drivers/media/pci/ivtv/ivtvfb.c ipath drivers/infiniband/hw/ipath/ipath_driver.cThis series makes those drivers use
__arch_phys_wc_add()more as a transitory phase in hopes we can address the proper split as with the atyfb illustrates. For ipath the changes required have a nice template with the qib driver as they share very similar driver structure, the qib driver *did* do the nice split.Quoted 1 line
If so, can we ioremap +
set_page_xyzinstead?Quoted 8 lines
Quoted 4 lines
I'm not sure I see which call we'd use. Care to provide an example patch alternative for the atyfb as a case in point alternative to the work required to do the split?
I'm still confused. Would it be insufficient to
ioremap_nocachethe whole thing and then callset_memory_wcon parts of it? (Sorry,set_page_xyzwas a typo.)I think that would be a sexy alternative.
In this driver's case the thing is a bit messy as it not only used the WC MTRR for a hole but it also then used a UC MTRR on top of it all, so since I already tried to address the split, and if we address the power of 2 woes, I think it'd be best to try to remove the UC MTRR and just avoid
set_page_wc()in this driver's case, but for the other cases (fusion, ivtv, ipath) I think this makes sense.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Thoughts?
Once that WC MTRR is in place, I think you really need UC and not UC- if you want to override it. Otherwise I agree with all of this.
Do you mean that the UC MTRR work around that was in place might not have really been effective? Not quite sure what you mean. I don't think I follow.
I mean that the UC MTRR that overrides the WC MTRR was probably fine (I hope smaller MTRRs override larger MTRRs). But we should just ditch UC MTRRs entirely, and setting UC in the page tables would work on all CPUs *if we supported that*. We'd need to add a couple trivial helpers to do that.
--Andy
Quoted 2 lines
Luis
Signature · 2 lines
Andy Lutomirski AMA Capital Management, LLC
Re: [PATCH v1 06/47] mtrr: add __arch_phys_wc_add()
In reply to Andy LutomirskiQuoted 82 lines · Andy Lutomirski
Quoted 81 lines · Luis R. Rodriguez
Quoted 62 lines · Andy Lutomirski
Quoted 61 lines · Luis R. Rodriguez
Quoted 29 lines · Andy Lutomirski
Quoted 27 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
Ideally on systems using PAT we can expect a swift transition away from MTRR. There can be a few exceptions to this, one is where device drivers are known to exist on PATs with errata, another situation is observed on old device drivers where devices had combined MMIO register access with whatever area they typically later wanted to end up using MTRR for on the same PCI BAR. This situation can still be addressed by splitting up ioremap'd PCI BAR into two ioremap'd calls, one for MMIO registers, and another for whatever is desirable for write-combining -- in order to accomplish this though quite a bit of driver restructuring is required.
Device drivers which are known to require large amount of re-work in order to split ioremap'd areas can use
__arch_phys_wc_add()to avoid regressions when PAT is enabled.For a good example driver where things are neatly split up on a PCI BAR refer the infiniband qib driver. For a good example of a driver where good amount of work is required refer to the infiniband ipath driver.
Quoted 8 lines
Quoted 2 lines
This is *only* a transitive API -- and as such no new drivers are ever expected to use this.
What's the exact layout that this helps? I'm sceptical that this can ever be correct.
Is there some awful driver that has a large ioremap that's supposed to contain multiple different memtypes?
Yes, I cc'd you just now on one where I made changes on a driver which uses one PCI with mixed memtypes and uses MTRR to hole in WC. A transition to
arch_phys_wc_add()is therefore not possible if PAT is enabled as it would regress those drivers by making the MTRR WC hole trick non functional. The changes are non trivial and so in this series I supplied changes on one driver only to show the effort required. The other drivers which required this were:Driver File
------------------------------------------------------------fusion drivers/message/fusion/mptbase.c ivtv drivers/media/pci/ivtv/ivtvfb.c ipath drivers/infiniband/hw/ipath/ipath_driver.cThis series makes those drivers use
__arch_phys_wc_add()more as a transitory phase in hopes we can address the proper split as with the atyfb illustrates. For ipath the changes required have a nice template with the qib driver as they share very similar driver structure, the qib driver *did* do the nice split.Quoted 1 line
If so, can we ioremap +
set_page_xyzinstead?Quoted 8 lines
Quoted 4 lines
I'm not sure I see which call we'd use. Care to provide an example patch alternative for the atyfb as a case in point alternative to the work required to do the split?
I'm still confused. Would it be insufficient to
ioremap_nocachethe whole thing and then callset_memory_wcon parts of it? (Sorry,set_page_xyzwas a typo.)I think that would be a sexy alternative.
In this driver's case the thing is a bit messy as it not only used the WC MTRR for a hole but it also then used a UC MTRR on top of it all, so since I already tried to address the split, and if we address the power of 2 woes, I think it'd be best to try to remove the UC MTRR and just avoid
set_page_wc()in this driver's case, but for the other cases (fusion, ivtv, ipath) I think this makes sense.
Quoted 4 lines
Quoted 1 line
Thoughts?
Once that WC MTRR is in place, I think you really need UC and not UC- if you want to override it. Otherwise I agree with all of this.
Do you mean that the UC MTRR work around that was in place might not have really been effective? Not quite sure what you mean. I don't think I follow.
Luis
Re: [PATCH v1 06/47] mtrr: add __arch_phys_wc_add()
In reply to Luis R. RodriguezQuoted 74 lines · Luis R. Rodriguez
Quoted 62 lines · Andy Lutomirski
Quoted 61 lines · Luis R. Rodriguez
Quoted 29 lines · Andy Lutomirski
Quoted 27 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
Ideally on systems using PAT we can expect a swift transition away from MTRR. There can be a few exceptions to this, one is where device drivers are known to exist on PATs with errata, another situation is observed on old device drivers where devices had combined MMIO register access with whatever area they typically later wanted to end up using MTRR for on the same PCI BAR. This situation can still be addressed by splitting up ioremap'd PCI BAR into two ioremap'd calls, one for MMIO registers, and another for whatever is desirable for write-combining -- in order to accomplish this though quite a bit of driver restructuring is required.
Device drivers which are known to require large amount of re-work in order to split ioremap'd areas can use
__arch_phys_wc_add()to avoid regressions when PAT is enabled.For a good example driver where things are neatly split up on a PCI BAR refer the infiniband qib driver. For a good example of a driver where good amount of work is required refer to the infiniband ipath driver.
Quoted 8 lines
Quoted 2 lines
This is *only* a transitive API -- and as such no new drivers are ever expected to use this.
What's the exact layout that this helps? I'm sceptical that this can ever be correct.
Is there some awful driver that has a large ioremap that's supposed to contain multiple different memtypes?
Yes, I cc'd you just now on one where I made changes on a driver which uses one PCI with mixed memtypes and uses MTRR to hole in WC. A transition to
arch_phys_wc_add()is therefore not possible if PAT is enabled as it would regress those drivers by making the MTRR WC hole trick non functional. The changes are non trivial and so in this series I supplied changes on one driver only to show the effort required. The other drivers which required this were:Driver File
------------------------------------------------------------fusion drivers/message/fusion/mptbase.c ivtv drivers/media/pci/ivtv/ivtvfb.c ipath drivers/infiniband/hw/ipath/ipath_driver.cThis series makes those drivers use
__arch_phys_wc_add()more as a transitory phase in hopes we can address the proper split as with the atyfb illustrates. For ipath the changes required have a nice template with the qib driver as they share very similar driver structure, the qib driver *did* do the nice split.Quoted 1 line
If so, can we ioremap +
set_page_xyzinstead?Quoted 8 lines
Quoted 4 lines
I'm not sure I see which call we'd use. Care to provide an example patch alternative for the atyfb as a case in point alternative to the work required to do the split?
I'm still confused. Would it be insufficient to
ioremap_nocachethe whole thing and then callset_memory_wcon parts of it? (Sorry,set_page_xyzwas a typo.)I think that would be a sexy alternative.
Quoted 8 lines
In this driver's case the thing is a bit messy as it not only used the WC MTRR for a hole but it also then used a UC MTRR on top of it all, so since I already tried to address the split, and if we address the power of 2 woes, I think it'd be best to try to remove the UC MTRR and just avoid
set_page_wc()in this driver's case, but for the other cases (fusion, ivtv, ipath) I think this makes sense.Thoughts?
Once that WC MTRR is in place, I think you really need UC and not UC- if you want to override it. Otherwise I agree with all of this.
--Andy
Re: [PATCH v1 06/47] mtrr: add __arch_phys_wc_add()
In reply to Andy LutomirskiQuoted 62 lines · Andy Lutomirski
Quoted 61 lines · Luis R. Rodriguez
Quoted 29 lines · Andy Lutomirski
Quoted 27 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
Ideally on systems using PAT we can expect a swift transition away from MTRR. There can be a few exceptions to this, one is where device drivers are known to exist on PATs with errata, another situation is observed on old device drivers where devices had combined MMIO register access with whatever area they typically later wanted to end up using MTRR for on the same PCI BAR. This situation can still be addressed by splitting up ioremap'd PCI BAR into two ioremap'd calls, one for MMIO registers, and another for whatever is desirable for write-combining -- in order to accomplish this though quite a bit of driver restructuring is required.
Device drivers which are known to require large amount of re-work in order to split ioremap'd areas can use
__arch_phys_wc_add()to avoid regressions when PAT is enabled.For a good example driver where things are neatly split up on a PCI BAR refer the infiniband qib driver. For a good example of a driver where good amount of work is required refer to the infiniband ipath driver.
Quoted 8 lines
Quoted 2 lines
This is *only* a transitive API -- and as such no new drivers are ever expected to use this.
What's the exact layout that this helps? I'm sceptical that this can ever be correct.
Is there some awful driver that has a large ioremap that's supposed to contain multiple different memtypes?
Yes, I cc'd you just now on one where I made changes on a driver which uses one PCI with mixed memtypes and uses MTRR to hole in WC. A transition to
arch_phys_wc_add()is therefore not possible if PAT is enabled as it would regress those drivers by making the MTRR WC hole trick non functional. The changes are non trivial and so in this series I supplied changes on one driver only to show the effort required. The other drivers which required this were:Driver File
------------------------------------------------------------fusion drivers/message/fusion/mptbase.c ivtv drivers/media/pci/ivtv/ivtvfb.c ipath drivers/infiniband/hw/ipath/ipath_driver.cThis series makes those drivers use
__arch_phys_wc_add()more as a transitory phase in hopes we can address the proper split as with the atyfb illustrates. For ipath the changes required have a nice template with the qib driver as they share very similar driver structure, the qib driver *did* do the nice split.Quoted 1 line
If so, can we ioremap +
set_page_xyzinstead?
Quoted 8 lines
Quoted 4 lines
I'm not sure I see which call we'd use. Care to provide an example patch alternative for the atyfb as a case in point alternative to the work required to do the split?
I'm still confused. Would it be insufficient to
ioremap_nocachethe whole thing and then callset_memory_wcon parts of it? (Sorry,set_page_xyzwas a typo.)
I think that would be a sexy alternative.
In this driver's case the thing is a bit messy as it not only used the WC MTRR for a hole but it also then used a UC MTRR on top of it all, so since I already tried to address the split, and if we address the power of 2 woes, I think it'd be best to try to remove the UC MTRR and just avoid set_page_wc() in this driver's case, but for the other cases (fusion, ivtv, ipath) I think this makes sense.
Thoughts?
Luis
Re: [PATCH v1 06/47] mtrr: add __arch_phys_wc_add()
In reply to Luis R. RodriguezQuoted 59 lines · Luis R. Rodriguez
Quoted 29 lines · Andy Lutomirski
Quoted 27 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
Ideally on systems using PAT we can expect a swift transition away from MTRR. There can be a few exceptions to this, one is where device drivers are known to exist on PATs with errata, another situation is observed on old device drivers where devices had combined MMIO register access with whatever area they typically later wanted to end up using MTRR for on the same PCI BAR. This situation can still be addressed by splitting up ioremap'd PCI BAR into two ioremap'd calls, one for MMIO registers, and another for whatever is desirable for write-combining -- in order to accomplish this though quite a bit of driver restructuring is required.
Device drivers which are known to require large amount of re-work in order to split ioremap'd areas can use
__arch_phys_wc_add()to avoid regressions when PAT is enabled.For a good example driver where things are neatly split up on a PCI BAR refer the infiniband qib driver. For a good example of a driver where good amount of work is required refer to the infiniband ipath driver.
Quoted 8 lines
Quoted 2 lines
This is *only* a transitive API -- and as such no new drivers are ever expected to use this.
What's the exact layout that this helps? I'm sceptical that this can ever be correct.
Is there some awful driver that has a large ioremap that's supposed to contain multiple different memtypes?
Yes, I cc'd you just now on one where I made changes on a driver which uses one PCI with mixed memtypes and uses MTRR to hole in WC. A transition to
arch_phys_wc_add()is therefore not possible if PAT is enabled as it would regress those drivers by making the MTRR WC hole trick non functional. The changes are non trivial and so in this series I supplied changes on one driver only to show the effort required. The other drivers which required this were:Driver File
------------------------------------------------------------fusion drivers/message/fusion/mptbase.c ivtv drivers/media/pci/ivtv/ivtvfb.c ipath drivers/infiniband/hw/ipath/ipath_driver.cThis series makes those drivers use
__arch_phys_wc_add()more as a transitory phase in hopes we can address the proper split as with the atyfb illustrates. For ipath the changes required have a nice template with the qib driver as they share very similar driver structure, the qib driver *did* do the nice split.
Quoted 6 lines
Quoted 1 line
If so, can we ioremap +
set_page_xyzinstead?I'm not sure I see which call we'd use. Care to provide an example patch alternative for the atyfb as a case in point alternative to the work required to do the split?
I'm still confused. Would it be insufficient to ioremap_nocache the whole thing and then call set_memory_wc on parts of it? (Sorry, set_page_xyz was a typo.)
--Andy
Signature · 2 lines
Andy Lutomirski AMA Capital Management, LLC
Re: [PATCH v1 06/47] mtrr: add __arch_phys_wc_add()
In reply to Andy LutomirskiQuoted 29 lines · Andy Lutomirski
Quoted 27 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
Ideally on systems using PAT we can expect a swift transition away from MTRR. There can be a few exceptions to this, one is where device drivers are known to exist on PATs with errata, another situation is observed on old device drivers where devices had combined MMIO register access with whatever area they typically later wanted to end up using MTRR for on the same PCI BAR. This situation can still be addressed by splitting up ioremap'd PCI BAR into two ioremap'd calls, one for MMIO registers, and another for whatever is desirable for write-combining -- in order to accomplish this though quite a bit of driver restructuring is required.
Device drivers which are known to require large amount of re-work in order to split ioremap'd areas can use
__arch_phys_wc_add()to avoid regressions when PAT is enabled.For a good example driver where things are neatly split up on a PCI BAR refer the infiniband qib driver. For a good example of a driver where good amount of work is required refer to the infiniband ipath driver.
Quoted 8 lines
Quoted 2 lines
This is *only* a transitive API -- and as such no new drivers are ever expected to use this.
What's the exact layout that this helps? I'm sceptical that this can ever be correct.
Is there some awful driver that has a large ioremap that's supposed to contain multiple different memtypes?
Yes, I cc'd you just now on one where I made changes on a driver which uses one PCI with mixed memtypes and uses MTRR to hole in WC. A transition to arch_phys_wc_add() is therefore not possible if PAT is enabled as it would regress those drivers by making the MTRR WC hole trick non functional. The changes are non trivial and so in this series I supplied changes on one driver only to show the effort required. The other drivers which required this were:
Driver File
------------------------------------------------------------
fusion drivers/message/fusion/mptbase.c
ivtv drivers/media/pci/ivtv/ivtvfb.c
ipath drivers/infiniband/hw/ipath/ipath_driver.c
This series makes those drivers use __arch_phys_wc_add() more as a transitory phase in hopes we can address the proper split as with the atyfb illustrates. For ipath the changes required have a nice template with the qib driver as they share very similar driver structure, the qib driver *did* do the nice split.
Quoted 1 line
If so, can we ioremap +
set_page_xyzinstead?
I'm not sure I see which call we'd use. Care to provide an example patch alternative for the atyfb as a case in point alternative to the work required to do the split?
Luis
Re: [PATCH v1 06/47] mtrr: add __arch_phys_wc_add()
In reply to Luis R. RodriguezQuoted 21 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
Ideally on systems using PAT we can expect a swift transition away from MTRR. There can be a few exceptions to this, one is where device drivers are known to exist on PATs with errata, another situation is observed on old device drivers where devices had combined MMIO register access with whatever area they typically later wanted to end up using MTRR for on the same PCI BAR. This situation can still be addressed by splitting up ioremap'd PCI BAR into two ioremap'd calls, one for MMIO registers, and another for whatever is desirable for write-combining -- in order to accomplish this though quite a bit of driver restructuring is required.
Device drivers which are known to require large amount of re-work in order to split ioremap'd areas can use
__arch_phys_wc_add()to avoid regressions when PAT is enabled.
Quoted 8 lines
For a good example driver where things are neatly split up on a PCI BAR refer the infiniband qib driver. For a good example of a driver where good amount of work is required refer to the infiniband ipath driver.
This is *only* a transitive API -- and as such no new drivers are ever expected to use this.
What's the exact layout that this helps? I'm sceptical that this can ever be correct.
Is there some awful driver that has a large ioremap that's supposed to contain multiple different memtypes? If so, can we ioremap + set_page_xyz instead?
--Andy
Bjorn Helgaas
maintainerRe: [PATCH v1 06/47] mtrr: add __arch_phys_wc_add()
In reply to Luis R. RodriguezQuoted 6 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
Ideally on systems using PAT we can expect a swift transition away from MTRR. There can be a few exceptions to this, one is where device drivers are known to exist on PATs with errata,
This probably makes sense to someone steeped in MTRR and PAT, but not otherwise. "One exception is where drivers are known to exist on PATs with errata"? The drivers exist, independent of PAT/MTRR/errata. Do you mean there are drivers that can't be converted from MTRR to PAT because some PATs are broken?
I don't really know anything about MTRR or PAT; I'm just trying to figure out how to parse this paragraph.
Quoted 16 lines
another situation is observed on
old device drivers where devices had combined MMIO register access with whatever area they typically later wanted to end up using MTRR for on the same PCI BAR. This situation can still be addressed by splitting up ioremap'd PCI BAR into two ioremap'd calls, one for MMIO registers, and another for whatever is desirable for write-combining -- in order to accomplish this though quite a bit of driver restructuring is required.Device drivers which are known to require large amount of re-work in order to split ioremap'd areas can use
__arch_phys_wc_add()to avoid regressions when PAT is enabled.
Quoted 8 lines
For a good example driver where things are neatly split up on a PCI BAR refer the infiniband qib driver. For a good example of a driver where good amount of work is required refer to the infiniband ipath driver.
This is *only* a transitive API -- and as such no new drivers are ever expected to use this.
"transient"? Do you mean you intend to remove this API in the near future?
Bjorn
Re: [PATCH v1 06/47] mtrr: add __arch_phys_wc_add()
Quoted 9 lines · Bjorn Helgaas
Quoted 6 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
Ideally on systems using PAT we can expect a swift transition away from MTRR. There can be a few exceptions to this, one is where device drivers are known to exist on PATs with errata,
Quoted 5 lines
This probably makes sense to someone steeped in MTRR and PAT, but not otherwise. "One exception is where drivers are known to exist on PATs with errata"? The drivers exist, independent of PAT/MTRR/errata. Do you mean there are drivers that can't be converted from MTRR to PAT because some PATs are broken?
Well there is that but it seems we have motivation to address the PAT broken systems so this would be one of the lower priority reasons to consider adding this API. The more important reason is below.
Quoted 2 lines
I don't really know anything about MTRR or PAT; I'm just trying to figure out how to parse this paragraph.
Sure.
Quoted 22 lines
Quoted 22 lines
another situation is observed on
old device drivers where devices had combined MMIO register access with whatever area they typically later wanted to end up using MTRR for on the same PCI BAR. This situation can still be addressed by splitting up ioremap'd PCI BAR into two ioremap'd calls, one for MMIO registers, and another for whatever is desirable for write-combining -- in order to accomplish this though quite a bit of driver restructuring is required.Device drivers which are known to require large amount of re-work in order to split ioremap'd areas can use
__arch_phys_wc_add()to avoid regressions when PAT is enabled.For a good example driver where things are neatly split up on a PCI BAR refer the infiniband qib driver. For a good example of a driver where good amount of work is required refer to the infiniband ipath driver.
Quoted 4 lines
Quoted 2 lines
This is *only* a transitive API -- and as such no new drivers are ever expected to use this.
"transient"? Do you mean you intend to remove this API in the near future?
That's correct, the problem is that in order to use PAT cleanly we'd need to change these drivers to not overlap ioremap'd areas otherwise things can get quite complex, and changing the way we do the ioremap() calls on a driver might require a bit of work. The atyfb driver changes I did are an example of the types of changes that are expected. In the most complex worst cases there are MTRR "hole" tricks used, and as can be observed with the atyfb driver changes there are a series of things to consider when this is done specially in light of eventually making strong UC the default instead of UC-.
I might be able to work around not adding this API by reviewing the users I had in this series again and seeing if something similar to what I will do on atyfb can be done in the meantime by using ioremap_uc(). Its not clear to me yet.
Luis
Bjorn Helgaas
maintainerRe: [PATCH v1 06/47] mtrr: add __arch_phys_wc_add()
[-cc Venkatesh, Suresh]
Quoted 5 lines · Luis R. Rodriguez
Quoted 3 lines · Bjorn Helgaas
Quoted 1 line · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
This is *only* a transitive API -- and as such no new drivers are ever expected to use this.
"transient"? Do you mean you intend to remove this API in the near future?
That's correct, the problem is that in order to use PAT cleanly we'd need to change these drivers ...
I was just trying to ask whether you intended to write "transient" instead of "transitive." But I'm not doing a very good job :)
Bjorn
Re: [PATCH v1 06/47] mtrr: add __arch_phys_wc_add()
Quoted 11 lines · Bjorn Helgaas
[-cc Venkatesh, Suresh]
Quoted 8 lines · Luis R. Rodriguez
Quoted 7 lines · Bjorn Helgaas
Quoted 4 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
This is *only* a transitive API -- and as such no new drivers are ever expected to use this.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
"transient"? Do you mean you intend to remove this API in the near future?
That's correct, the problem is that in order to use PAT cleanly we'd need to change these drivers ...
I was just trying to ask whether you intended to write "transient" instead of "transitive." But I'm not doing a very good job :)
Yes, corrected, thanks.
Luis
Re: [PATCH v1 06/47] mtrr: add __arch_phys_wc_add()
In reply to Bjorn HelgaasQuoted 11 lines · Bjorn Helgaas
[-cc Venkatesh, Suresh]
Quoted 8 lines · Luis R. Rodriguez
Quoted 7 lines · Bjorn Helgaas
Quoted 4 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
This is *only* a transitive API -- and as such no new drivers are ever expected to use this.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
"transient"? Do you mean you intend to remove this API in the near future?
That's correct, the problem is that in order to use PAT cleanly we'd need to change these drivers ...
I was just trying to ask whether you intended to write "transient" instead of "transitive." But I'm not doing a very good job :)
Yes, corrected, thanks.
Luis
Bjorn Helgaas
maintainerRe: [PATCH v1 06/47] mtrr: add __arch_phys_wc_add()
In reply to Luis R. Rodriguez[-cc Venkatesh, Suresh]
Quoted 5 lines · Luis R. Rodriguez
Quoted 3 lines · Bjorn Helgaas
Quoted 1 line · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
This is *only* a transitive API -- and as such no new drivers are ever expected to use this.
"transient"? Do you mean you intend to remove this API in the near future?
That's correct, the problem is that in order to use PAT cleanly we'd need to change these drivers ...
I was just trying to ask whether you intended to write "transient" instead of "transitive." But I'm not doing a very good job :)
Bjorn
Re: [PATCH v1 06/47] mtrr: add __arch_phys_wc_add()
In reply to Bjorn HelgaasQuoted 9 lines · Bjorn Helgaas
Quoted 6 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
Ideally on systems using PAT we can expect a swift transition away from MTRR. There can be a few exceptions to this, one is where device drivers are known to exist on PATs with errata,
Quoted 5 lines
This probably makes sense to someone steeped in MTRR and PAT, but not otherwise. "One exception is where drivers are known to exist on PATs with errata"? The drivers exist, independent of PAT/MTRR/errata. Do you mean there are drivers that can't be converted from MTRR to PAT because some PATs are broken?
Well there is that but it seems we have motivation to address the PAT broken systems so this would be one of the lower priority reasons to consider adding this API. The more important reason is below.
Quoted 2 lines
I don't really know anything about MTRR or PAT; I'm just trying to figure out how to parse this paragraph.
Sure.
Quoted 22 lines
Quoted 22 lines
another situation is observed on
old device drivers where devices had combined MMIO register access with whatever area they typically later wanted to end up using MTRR for on the same PCI BAR. This situation can still be addressed by splitting up ioremap'd PCI BAR into two ioremap'd calls, one for MMIO registers, and another for whatever is desirable for write-combining -- in order to accomplish this though quite a bit of driver restructuring is required.Device drivers which are known to require large amount of re-work in order to split ioremap'd areas can use
__arch_phys_wc_add()to avoid regressions when PAT is enabled.For a good example driver where things are neatly split up on a PCI BAR refer the infiniband qib driver. For a good example of a driver where good amount of work is required refer to the infiniband ipath driver.
Quoted 4 lines
Quoted 2 lines
This is *only* a transitive API -- and as such no new drivers are ever expected to use this.
"transient"? Do you mean you intend to remove this API in the near future?
That's correct, the problem is that in order to use PAT cleanly we'd need to change these drivers to not overlap ioremap'd areas otherwise things can get quite complex, and changing the way we do the ioremap() calls on a driver might require a bit of work. The atyfb driver changes I did are an example of the types of changes that are expected. In the most complex worst cases there are MTRR "hole" tricks used, and as can be observed with the atyfb driver changes there are a series of things to consider when this is done specially in light of eventually making strong UC the default instead of UC-.
I might be able to work around not adding this API by reviewing the users I had in this series again and seeing if something similar to what I will do on atyfb can be done in the meantime by using ioremap_uc(). Its not clear to me yet.
Luis
Bjorn Helgaas
maintainerRe: [PATCH v1 06/47] mtrr: add __arch_phys_wc_add()
In reply to Luis R. RodriguezQuoted 6 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
Ideally on systems using PAT we can expect a swift transition away from MTRR. There can be a few exceptions to this, one is where device drivers are known to exist on PATs with errata,
This probably makes sense to someone steeped in MTRR and PAT, but not otherwise. "One exception is where drivers are known to exist on PATs with errata"? The drivers exist, independent of PAT/MTRR/errata. Do you mean there are drivers that can't be converted from MTRR to PAT because some PATs are broken?
I don't really know anything about MTRR or PAT; I'm just trying to figure out how to parse this paragraph.
Quoted 16 lines
another situation is observed on
old device drivers where devices had combined MMIO register access with whatever area they typically later wanted to end up using MTRR for on the same PCI BAR. This situation can still be addressed by splitting up ioremap'd PCI BAR into two ioremap'd calls, one for MMIO registers, and another for whatever is desirable for write-combining -- in order to accomplish this though quite a bit of driver restructuring is required.Device drivers which are known to require large amount of re-work in order to split ioremap'd areas can use
__arch_phys_wc_add()to avoid regressions when PAT is enabled.
Quoted 8 lines
For a good example driver where things are neatly split up on a PCI BAR refer the infiniband qib driver. For a good example of a driver where good amount of work is required refer to the infiniband ipath driver.
This is *only* a transitive API -- and as such no new drivers are ever expected to use this.
"transient"? Do you mean you intend to remove this API in the near future?
Bjorn
PATCH 6/47 mtrr: add __arch_phys_wc_add()
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
Ideally on systems using PAT we can expect a swift transition away from MTRR. There can be a few exceptions to this, one is where device drivers are known to exist on PATs with errata, another situation is observed on old device drivers where devices had combined MMIO register access with whatever area they typically later wanted to end up using MTRR for on the same PCI BAR. This situation can still be addressed by splitting up ioremap'd PCI BAR into two ioremap'd calls, one for MMIO registers, and another for whatever is desirable for write-combining -- in order to accomplish this though quite a bit of driver restructuring is required.
Device drivers which are known to require large amount of re-work in order to split ioremap'd areas can use __arch_phys_wc_add() to avoid regressions when PAT is enabled.
For a good example driver where things are neatly split up on a PCI BAR refer the infiniband qib driver. For a good example of a driver where good amount of work is required refer to the infiniband ipath driver.
This is *only* a transitive API -- and as such no new drivers are ever expected to use this.
--- arch/x86/include/asm/io.h | 4 ++++ arch/x86/kernel/cpu/mtrr/main.c | 36 +++++++++++++++++++++++++++++------- include/linux/io.h | 4 ++++ 3 files changed, 37 insertions(+), 7 deletions(-)
arch/x86/include/asm/io.h +4 -0
@@ -338,6 +338,10 @@ extern bool xen_biovec_phys_mergeable(const struct bio_vec *vec1,#define IO_SPACE_LIMIT 0xffff#ifdef CONFIG_MTRR +extern int __must_check __arch_phys_wc_add (unsigned long base, +unsigned long size); +#define __arch_phys_wc_add __arch_phys_wc_add +extern int __must_check arch_phys_wc_add (unsigned long base,unsigned long size);extern void arch_phys_wc_del (int handle);
arch/x86/kernel/cpu/mtrr/main.c +29 -7
@@ -538,23 +538,24 @@ int mtrr_del(int reg, unsigned long base, unsigned long size)EXPORT_SYMBOL (mtrr_del);/** -* arch_phys_wc_add - add a WC MTRR and handle errors if PAT is unavailable +* __arch_phys_wc_add - add a WC MTRR even if PAT is available * @base: Physical base address * @size: Size of region * -* If PAT is available, this does nothing. If PAT is unavailable, it -* attempts to add a WC MTRR covering size bytes starting at base and -* logs an error if this fails. +* We typically do not want to use MTRR if PAT is available but there +* are some drivers which require significant work to get this to work +* properly. This call should only be used by those drivers where it is +* clear that hard work is required to modify them to use arch_phys_wc_add() * * Drivers must store the return value to pass to mtrr_del_wc_if_needed, * but drivers should not try to interpret that return value. */ -int arch_phys_wc_add (unsigned long base,unsigned long size) +int __arch_phys_wc_add (unsigned long base,unsigned long size) {int ret; -if (pat_enabled || !mtrr_enabled) -return 0 ;/* Success! (We don't need to do anything.) */ +if (!mtrr_enabled) +return 0 ; ret =mtrr_add (base, size,MTRR_TYPE_WRCOMB , true);if (ret <0 ) {
@@ -564,6 +565,27 @@ int arch_phys_wc_add(unsigned long base, unsigned long size) }return ret +MTRR_TO_PHYS_WC_OFFSET ; } +EXPORT_SYMBOL_GPL (__arch_phys_wc_add); + +/** +* arch_phys_wc_add - add a WC MTRR and handle errors if PAT is unavailable +* @base: Physical base address +* @size: Size of region +* +* If PAT is available, this does nothing. If PAT is unavailable, it +* attempts to add a WC MTRR covering size bytes starting at base and +* logs an error if this fails. +* +* Drivers must store the return value to pass to mtrr_del_wc_if_needed, +* but drivers should not try to interpret that return value. +*/ +int arch_phys_wc_add (unsigned long base,unsigned long size) +{ +if (pat_enabled || !mtrr_enabled) +return 0 ;/* Success! (We don't need to do anything.) */ + +return __arch_phys_wc_add (base, size); +}EXPORT_SYMBOL (arch_phys_wc_add);/*
include/linux/io.h +4 -0
@@ -111,6 +111,10 @@ static inline void arch_phys_wc_del(int handle) }#define arch_phys_wc_add arch_phys_wc_add +#ifndef __arch_phys_wc_add +#define __arch_phys_wc_add arch_phys_wc_add +#endif +#endif #endif /* _LINUX_IO_H */
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
PATCH 7/47 video: fbdev: atyfb: move framebuffer length fudging to helper
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
The size of the framebuffer to be used needs to
be fudged to account for the different type of
devices that are out there. This captures what
is required to do well, we'll resuse this later.
This has no functional changes.
--- drivers/video/fbdev/aty/atyfb_base.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-)
drivers/video/fbdev/aty/atyfb_base.c +15 -8
@@ -427,6 +427,20 @@ static struct {#endif /* CONFIG_FB_ATY_CT */ }; +/* +* Last page of 8 MB (4 MB on ISA) aperture is MMIO, +* unless the auxiliary register aperture is used. +*/ +static void aty_fudge_framebuffer_len (struct fb_info *info) +{ +struct atyfb_par *par = (struct atyfb_par *) info->par; + +if (!par->aux_start && + (info->fix.smem_len =0x800000 || + (par->bus_type =ISA && info->fix.smem_len =0x400000 ))) + info->fix.smem_len -=GUI_RESERVE ; +} +static int correct_chipset (struct atyfb_par *par) {u8 rev;
@@ -2603,14 +2617,7 @@ static int aty_init(struct fb_info *info)if (par->pll_ops->resume_pll) par->pll_ops->resume_pll (info, &par->pll); -/* -* Last page of 8 MB (4 MB on ISA) aperture is MMIO, -* unless the auxiliary register aperture is used. -*/ -if (!par->aux_start && - (info->fix.smem_len =0x800000 || - (par->bus_type =ISA && info->fix.smem_len =0x400000 ))) - info->fix.smem_len -=GUI_RESERVE ; +aty_fudge_framebuffer_len (info);/* * Disable register access through the linear aperture
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
PATCH 7/47 video: fbdev: atyfb: move framebuffer length fudging to helper
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
The size of the framebuffer to be used needs to
be fudged to account for the different type of
devices that are out there. This captures what
is required to do well, we'll resuse this later.
This has no functional changes.
--- drivers/video/fbdev/aty/atyfb_base.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-)
drivers/video/fbdev/aty/atyfb_base.c +15 -8
@@ -427,6 +427,20 @@ static struct {#endif /* CONFIG_FB_ATY_CT */ }; +/* +* Last page of 8 MB (4 MB on ISA) aperture is MMIO, +* unless the auxiliary register aperture is used. +*/ +static void aty_fudge_framebuffer_len (struct fb_info *info) +{ +struct atyfb_par *par = (struct atyfb_par *) info->par; + +if (!par->aux_start && + (info->fix.smem_len ==0x800000 || + (par->bus_type ==ISA && info->fix.smem_len ==0x400000 ))) + info->fix.smem_len -=GUI_RESERVE ; +} +static int correct_chipset (struct atyfb_par *par) {u8 rev;
@@ -2603,14 +2617,7 @@ static int aty_init(struct fb_info *info)if (par->pll_ops->resume_pll) par->pll_ops->resume_pll (info, &par->pll); -/* -* Last page of 8 MB (4 MB on ISA) aperture is MMIO, -* unless the auxiliary register aperture is used. -*/ -if (!par->aux_start && - (info->fix.smem_len ==0x800000 || - (par->bus_type ==ISA && info->fix.smem_len ==0x400000 ))) - info->fix.smem_len -=GUI_RESERVE ; +aty_fudge_framebuffer_len (info);/* * Disable register access through the linear aperture
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
PATCH 8/47 video: fbdev: atyfb: clarify ioremap() base and length used
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
This has no functional changes, it just adjusts the ioremap() call for the framebuffer to use the same values we later use for the framebuffer, this will make it easier to review the next change.
The size of the framebuffer varies but since this is for PCI we *know* this defaults to 0x800000. atyfb_setup_generic() is *only* used on PCI probe.
--- drivers/video/fbdev/aty/atyfb_base.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/video/fbdev/aty/atyfb_base.c +3 -1
@@ -3489,7 +3489,9 @@ static int atyfb_setup_generic(struct pci_dev *pdev, struct fb_info *info,/* Map in frame buffer */ info->fix.smem_start = addr; - info->screen_base =ioremap (addr,0x800000 ); + info->fix.smem_len =0x800000 ; + + info->screen_base =ioremap (info->fix.smem_start, info->fix.smem_len);if (info->screen_base =NULL ) { ret = -ENOMEM ; goto atyfb_setup_generic_fail;
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
PATCH 8/47 video: fbdev: atyfb: clarify ioremap() base and length used
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
This has no functional changes, it just adjusts the ioremap() call for the framebuffer to use the same values we later use for the framebuffer, this will make it easier to review the next change.
The size of the framebuffer varies but since this is for PCI we *know* this defaults to 0x800000. atyfb_setup_generic() is *only* used on PCI probe.
--- drivers/video/fbdev/aty/atyfb_base.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/video/fbdev/aty/atyfb_base.c +3 -1
@@ -3489,7 +3489,9 @@ static int atyfb_setup_generic(struct pci_dev *pdev, struct fb_info *info,/* Map in frame buffer */ info->fix.smem_start = addr; - info->screen_base =ioremap (addr,0x800000 ); + info->fix.smem_len =0x800000 ; + + info->screen_base =ioremap (info->fix.smem_start, info->fix.smem_len);if (info->screen_base ==NULL ) { ret = -ENOMEM ; goto atyfb_setup_generic_fail;
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
PATCH 9/47 vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
The atyfb driver uses an MTRR work around since some cards use the same PCI BAR for the framebuffer and MMIO. In such cards the last page is used for MMIO, the rest for the framebuffer, so on those cards we ioremap() the MMIO page alone, then again ioremap() the full framebuffer including the MMIO space *and* ___then___ use an MTRR with MTRR_TYPE_WRCOMB on the full PCI BAR... and finally "hole" in an MTRR_TYPE_UNCACHABLE MTRR only for MMIO.
This is a terrible fucking work around, and should by no means be necessary however evidence through a large series of conversion of drivers to ioremap_wc() for the framebuffer shows that around the time MTRR started becoming popular devices did not have things lined up for easily separating the framebuffer and MMIO register access. In some cases a driver requires significant intrusive changes in order to make the split for an ioremap() for MMIO registers and another ioremap_wc() for the framebuffer, at other times a bit of careful study of the driver suffices. This example driver falls into the later category.
We can replace the MTRR MTRR_TYPE_UNCACHABLE
work around by using ioremap_nocache(), the length of the MMIO space should already be correct. The other part we need to correct is ensuring we ioremap() for the framebuffer only the required size. Since the ioremap() happens early on probe for PCI devices before aty_init() where we typically adjust the length and know how to do it, we can fix this by pegging the bus type as PCI on PCI probe, and finally fudging and framebuffer length just as we do on aty_init().
The last thing we do must do to remain sane is ensure we use the info->fix.smem_start and info->fix.smem_len for the framebuffer MTRR as we know that is always well adjusted. The *one* concern here would be if the MTRR is not in units of 4K __but__ we already know that in the PCI case this cannot happen, in the shared space setting the MTRR would be up to 0x7ff000 and assuming a 4K page:
; 0x7ff000 / 0x1000
2047
Also, internally when MTRR is used mtrr_add() will use mtrr_check() and that should splat a warning when the MTRR base and size are not compatible with what is expected for MTRR usage.
This fix lets us nuke the MTRR_TYPE_UNCACHABLE MTRR "hole".
--- drivers/video/fbdev/aty/atyfb.h | 1 - drivers/video/fbdev/aty/atyfb_base.c | 28 ++++++---------------------- 2 files changed, 6 insertions(+), 23 deletions(-)
drivers/video/fbdev/aty/atyfb.h +0 -1
@@ -184,7 +184,6 @@ struct atyfb_par {spinlock_t int_lock;#ifdef CONFIG_MTRR int mtrr_aper; -int mtrr_reg;#endif u32 mem_cntl;struct crtc saved_crtc;
drivers/video/fbdev/aty/atyfb_base.c +6 -22
@@ -2630,21 +2630,10 @@ static int aty_init(struct fb_info *info)#ifdef CONFIG_MTRR par->mtrr_aper =-1 ; - par->mtrr_reg =-1 ;if (!nomtrr) { -/* Cover the whole resource. */ - par->mtrr_aper =mtrr_add (par->res_start, par->res_size, + par->mtrr_aper =mtrr_add (info->fix.smem_start, + info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 ); -if (par->mtrr_aper >=0 && !par->aux_start) { -/* Make a hole for mmio. */ - par->mtrr_reg =mtrr_add (par->res_start +0x800000 - -GUI_RESERVE ,GUI_RESERVE , -MTRR_TYPE_UNCACHABLE ,1 ); -if (par->mtrr_reg <0 ) { -mtrr_del (par->mtrr_aper,0 ,0 ); - par->mtrr_aper =-1 ; - } - } }#endif
@@ -2776,10 +2765,6 @@ aty_init_exit: par->pll_ops->set_pll (info, &par->saved_pll);#ifdef CONFIG_MTRR -if (par->mtrr_reg >=0 ) { -mtrr_del (par->mtrr_reg,0 ,0 ); - par->mtrr_reg =-1 ; - }if (par->mtrr_aper >=0 ) {mtrr_del (par->mtrr_aper,0 ,0 ); par->mtrr_aper =-1 ;
@@ -3466,7 +3451,7 @@ static int atyfb_setup_generic(struct pci_dev *pdev, struct fb_info *info, } info->fix.mmio_start = raddr; - par->ati_regbase =ioremap (info->fix.mmio_start,0x1000 ); + par->ati_regbase =ioremap_nocache (info->fix.mmio_start,0x1000 );if (par->ati_regbase =NULL )return -ENOMEM ;
@@ -3491,6 +3476,8 @@ static int atyfb_setup_generic(struct pci_dev *pdev, struct fb_info *info, info->fix.smem_start = addr; info->fix.smem_len =0x800000 ; +aty_fudge_framebuffer_len (info); + info->screen_base =ioremap (info->fix.smem_start, info->fix.smem_len);if (info->screen_base =NULL ) { ret = -ENOMEM ;
@@ -3563,6 +3550,7 @@ static int atyfb_pci_probe(struct pci_dev *pdev,return -ENOMEM ; } par = info->par; + par->bus_type =PCI ; info->fix = atyfb_fix; info->device = &pdev->dev; par->pci_id = pdev->device;
@@ -3732,10 +3720,6 @@ static void atyfb_remove(struct fb_info *info)#endif #ifdef CONFIG_MTRR -if (par->mtrr_reg >=0 ) { -mtrr_del (par->mtrr_reg,0 ,0 ); - par->mtrr_reg =-1 ; - }if (par->mtrr_aper >=0 ) {mtrr_del (par->mtrr_aper,0 ,0 ); par->mtrr_aper =-1 ;
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
Re: [PATCH v1 09/47] vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around
Quoted 121 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
The atyfb driver uses an MTRR work around since some cards use the same PCI BAR for the framebuffer and MMIO. In such cards the last page is used for MMIO, the rest for the framebuffer, so on those cards we
ioremap()the MMIO page alone, then againioremap()the full framebuffer including the MMIO space *and*___then___use an MTRR withMTRR_TYPE_WRCOMBon the full PCI BAR... and finally "hole" in anMTRR_TYPE_UNCACHABLEMTRR only for MMIO.This is a terrible fucking work around, and should by no means be necessary however evidence through a large series of conversion of drivers to
ioremap_wc()for the framebuffer shows that around the time MTRR started becoming popular devices did not have things lined up for easily separating the framebuffer and MMIO register access. In some cases a driver requires significant intrusive changes in order to make the split for anioremap()for MMIO registers and anotherioremap_wc()for the framebuffer, at other times a bit of careful study of the driver suffices. This example driver falls into the later category.We can replace the MTRR
MTRR_TYPE_UNCACHABLE
work around by usingioremap_nocache(), the length of the MMIO space should already be correct. The other part we need to correct is ensuring weioremap()for the framebuffer only the required size. Since theioremap()happens early on probe for PCI devices beforeaty_init()where we typically adjust the length and know how to do it, we can fix this by pegging the bus type as PCI on PCI probe, and finally fudging and framebuffer length just as we do onaty_init().The last thing we do must do to remain sane is ensure we use the
info->fix.smem_startandinfo->fix.smem_lenfor the framebuffer MTRR as we know that is always well adjusted. The *one* concern here would be if the MTRR is not in units of 4K__but__we already know that in the PCI case this cannot happen, in the shared space setting the MTRR would be up to0x7ff000and assuming a 4K page:;
0x7ff000/0x10002047Also, internally when MTRR is used
mtrr_add()will usemtrr_check()and that should splat a warning when the MTRR base and size are not compatible with what is expected for MTRR usage.This fix lets us nuke the
MTRR_TYPE_UNCACHABLEMTRR "hole".Cc Suresh Siddha <[email protected]>Cc Venkatesh Pallipadi <[email protected]>Cc Ingo Molnar <[email protected]>Cc Linus Torvalds <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Juergen Gross <[email protected]>Cc Daniel Vetter <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Dave Airlie <[email protected]>Cc Antonino Daplas <[email protected]>Cc Jean-Christophe Plagniol-Villard <[email protected]>Cc Tomi Valkeinen <[email protected]>Signed-off-by Luis R. Rodriguez <[email protected]>--- drivers/video/fbdev/aty/atyfb.h | 1 - drivers/video/fbdev/aty/atyfb_base.c | 28 ++++++---------------------- 2 files changed, 6 insertions(+), 23 deletions(-)drivers/video/fbdev/aty/atyfb.h +0
-1@@ -184,7 +184,6 @@ struct atyfb_par {spinlock_t int_lock;#ifdef CONFIG_MTRR int mtrr_aper; -int mtrr_reg;#endif u32 mem_cntl;struct crtc saved_crtc;drivers/video/fbdev/aty/atyfb_base.c +2
-17@@ -2630,21 +2630,10 @@ static int aty_init(struct fb_info *info)#ifdef CONFIG_MTRR par->mtrr_aper =-1 ; - par->mtrr_reg =-1 ;if (!nomtrr) { -/* Cover the whole resource. */ - par->mtrr_aper =mtrr_add (par->res_start, par->res_size, + par->mtrr_aper =mtrr_add (info->fix.smem_start, + info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 ); -if (par->mtrr_aper >=0 && !par->aux_start) { -/* Make a hole for mmio. */ - par->mtrr_reg =mtrr_add (par->res_start +0x800000 - -GUI_RESERVE ,GUI_RESERVE , -MTRR_TYPE_UNCACHABLE ,1 ); -if (par->mtrr_reg <0 ) { -mtrr_del (par->mtrr_aper,0 ,0 ); - par->mtrr_aper =-1 ; - } - } }#endif @@ -2776,10 +2765,6 @@ aty_init_exit: par->pll_ops->set_pll (info, &par->saved_pll);#ifdef CONFIG_MTRR -if (par->mtrr_reg >=0 ) { -mtrr_del (par->mtrr_reg,0 ,0 ); - par->mtrr_reg =-1 ; - }if (par->mtrr_aper >=0 ) {mtrr_del (par->mtrr_aper,0 ,0 ); par->mtrr_aper =-1 ;
drivers/video/fbdev/aty/atyfb_base.c static int atyfb_setup_generic(struct pci_dev *pdev, struct fb_info *info, · line 3454
Quoted 5 lines
drivers/video/fbdev/aty/atyfb_base.c +1
-1@@ -3466,7 +3451,7 @@ static int atyfb_setup_generic(struct pci_dev *pdev, struct fb_info *info, } info->fix.mmio_start = raddr; - par->ati_regbase =ioremap (info->fix.mmio_start,0x1000 ); + par->ati_regbase =ioremap_nocache (info->fix.mmio_start,0x1000 );
Double-check me, but I think that ioremap_nocache + WC MTRR = WC. I think we might need ioremap_nocache_me_harder (or maybe ioremap_x86_uc if you prefer that bikeshed color) for this.
Re: [PATCH v1 09/47] vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around
Quoted 44 lines · Andy Lutomirski
Quoted 42 lines · Luis R. Rodriguez
drivers/video/fbdev/aty/atyfb_base.c +2
-17@@ -2630,21 +2630,10 @@ static int aty_init(struct fb_info *info)#ifdef CONFIG_MTRR par->mtrr_aper =-1 ; - par->mtrr_reg =-1 ;if (!nomtrr) { -/* Cover the whole resource. */ - par->mtrr_aper =mtrr_add (par->res_start, par->res_size, + par->mtrr_aper =mtrr_add (info->fix.smem_start, + info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 ); -if (par->mtrr_aper >=0 && !par->aux_start) { -/* Make a hole for mmio. */ - par->mtrr_reg =mtrr_add (par->res_start +0x800000 - -GUI_RESERVE ,GUI_RESERVE , -MTRR_TYPE_UNCACHABLE ,1 ); -if (par->mtrr_reg <0 ) { -mtrr_del (par->mtrr_aper,0 ,0 ); - par->mtrr_aper =-1 ; - } - } }#endif @@ -2776,10 +2765,6 @@ aty_init_exit: par->pll_ops->set_pll (info, &par->saved_pll);#ifdef CONFIG_MTRR -if (par->mtrr_reg >=0 ) { -mtrr_del (par->mtrr_reg,0 ,0 ); - par->mtrr_reg =-1 ; - }if (par->mtrr_aper >=0 ) {mtrr_del (par->mtrr_aper,0 ,0 ); par->mtrr_aper =-1 ;@@ -3466,7 +3451,7 @@ static int atyfb_setup_generic(struct pci_dev *pdev, struct fb_info *info, }
Quoted 5 lines
drivers/video/fbdev/aty/atyfb_base.c static int atyfb_setup_generic(struct pci_dev *pdev, struct fb_info *info, · line 3454
Quoted 3 lines
drivers/video/fbdev/aty/atyfb_base.c +1
-1info->fix.mmio_start = raddr; - par->ati_regbase =ioremap (info->fix.mmio_start,0x1000 ); + par->ati_regbase =ioremap_nocache (info->fix.mmio_start,0x1000 );Double-check me, but I think that
ioremap_nocache+ WC MTRR = WC.
Precicely, in this case the WC hole was obtained by using MTRR WC. This patch removes that WC hole trick and now we can be explciit about only wanting ioremap_nocache() on the registers, that is WC is not desired here and is not used. The patch does not highlight the fact that there was left in place another ioremap() call for the framebuffer:
info->screen_base = ioremap(info->fix.smem_start, info->fix.smem_len);
That is the one that later after this patch we use ioremap_wc() for. This patch just removes the hole solution. That's all.
Luis
Re: [PATCH v1 09/47] vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around
Quoted 57 lines · Luis R. Rodriguez
Quoted 44 lines · Andy Lutomirski
Quoted 42 lines · Luis R. Rodriguez
drivers/video/fbdev/aty/atyfb_base.c +2
-17@@ -2630,21 +2630,10 @@ static int aty_init(struct fb_info *info)#ifdef CONFIG_MTRR par->mtrr_aper =-1 ; - par->mtrr_reg =-1 ;if (!nomtrr) { -/* Cover the whole resource. */ - par->mtrr_aper =mtrr_add (par->res_start, par->res_size, + par->mtrr_aper =mtrr_add (info->fix.smem_start, + info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 ); -if (par->mtrr_aper >=0 && !par->aux_start) { -/* Make a hole for mmio. */ - par->mtrr_reg =mtrr_add (par->res_start +0x800000 - -GUI_RESERVE ,GUI_RESERVE , -MTRR_TYPE_UNCACHABLE ,1 ); -if (par->mtrr_reg <0 ) { -mtrr_del (par->mtrr_aper,0 ,0 ); - par->mtrr_aper =-1 ; - } - } }#endif @@ -2776,10 +2765,6 @@ aty_init_exit: par->pll_ops->set_pll (info, &par->saved_pll);#ifdef CONFIG_MTRR -if (par->mtrr_reg >=0 ) { -mtrr_del (par->mtrr_reg,0 ,0 ); - par->mtrr_reg =-1 ; - }if (par->mtrr_aper >=0 ) {mtrr_del (par->mtrr_aper,0 ,0 ); par->mtrr_aper =-1 ;@@ -3466,7 +3451,7 @@ static int atyfb_setup_generic(struct pci_dev *pdev, struct fb_info *info, }Quoted 5 lines
drivers/video/fbdev/aty/atyfb_base.c static int atyfb_setup_generic(struct pci_dev *pdev, struct fb_info *info, · line 3454
Quoted 3 lines
drivers/video/fbdev/aty/atyfb_base.c +1
-1info->fix.mmio_start = raddr; - par->ati_regbase =ioremap (info->fix.mmio_start,0x1000 ); + par->ati_regbase =ioremap_nocache (info->fix.mmio_start,0x1000 );Double-check me, but I think that
ioremap_nocache+ WC MTRR = WC.Precicely, in this case the WC hole was obtained by using MTRR WC. This patch removes that WC hole trick and now we can be explciit about only wanting
ioremap_nocache()on the registers, that is WC is not desired here and is not used. The patch does not highlight the fact that there was left in place anotherioremap()call for the framebuffer:
Quoted 5 lines
info->screen_base=ioremap(info->fix.smem_start, info->fix.smem_len);That is the one that later after this patch we use
ioremap_wc()for. This patch just removes the hole solution. That's all.
I don't understand.
If I read it right, there's a 2^n byte BAR. You're requesting WC for the whole think using arch_phys_wc_add. On a PAT system that has no effect and all is well. On a non-PAT system, it adds an MTRR. That means that you need to override the MTRR somehow for the mmio regs, and UC- won't do the trick.
Or am I missing something here?
--Andy
Quoted 1 line
Luis
Signature · 2 lines
Andy Lutomirski AMA Capital Management, LLC
Re: [PATCH v1 09/47] vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around
Quoted 60 lines · Andy Lutomirski
Quoted 59 lines · Luis R. Rodriguez
Quoted 44 lines · Andy Lutomirski
Quoted 42 lines · Luis R. Rodriguez
drivers/video/fbdev/aty/atyfb_base.c +2
-17@@ -2630,21 +2630,10 @@ static int aty_init(struct fb_info *info)#ifdef CONFIG_MTRR par->mtrr_aper =-1 ; - par->mtrr_reg =-1 ;if (!nomtrr) { -/* Cover the whole resource. */ - par->mtrr_aper =mtrr_add (par->res_start, par->res_size, + par->mtrr_aper =mtrr_add (info->fix.smem_start, + info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 ); -if (par->mtrr_aper >=0 && !par->aux_start) { -/* Make a hole for mmio. */ - par->mtrr_reg =mtrr_add (par->res_start +0x800000 - -GUI_RESERVE ,GUI_RESERVE , -MTRR_TYPE_UNCACHABLE ,1 ); -if (par->mtrr_reg <0 ) { -mtrr_del (par->mtrr_aper,0 ,0 ); - par->mtrr_aper =-1 ; - } - } }#endif @@ -2776,10 +2765,6 @@ aty_init_exit: par->pll_ops->set_pll (info, &par->saved_pll);#ifdef CONFIG_MTRR -if (par->mtrr_reg >=0 ) { -mtrr_del (par->mtrr_reg,0 ,0 ); - par->mtrr_reg =-1 ; - }if (par->mtrr_aper >=0 ) {mtrr_del (par->mtrr_aper,0 ,0 ); par->mtrr_aper =-1 ;@@ -3466,7 +3451,7 @@ static int atyfb_setup_generic(struct pci_dev *pdev, struct fb_info *info, }Quoted 5 lines
drivers/video/fbdev/aty/atyfb_base.c static int atyfb_setup_generic(struct pci_dev *pdev, struct fb_info *info, · line 3454
Quoted 3 lines
drivers/video/fbdev/aty/atyfb_base.c +1
-1info->fix.mmio_start = raddr; - par->ati_regbase =ioremap (info->fix.mmio_start,0x1000 ); + par->ati_regbase =ioremap_nocache (info->fix.mmio_start,0x1000 );Double-check me, but I think that
ioremap_nocache+ WC MTRR = WC.Precicely, in this case the WC hole was obtained by using MTRR WC. This patch removes that WC hole trick and now we can be explciit about only wanting
ioremap_nocache()on the registers, that is WC is not desired here and is not used. The patch does not highlight the fact that there was left in place anotherioremap()call for the framebuffer:
info->screen_base=ioremap(info->fix.smem_start, info->fix.smem_len);
Quoted 8 lines
Quoted 3 lines
That is the one that later after this patch we use
ioremap_wc()for. This patch just removes the hole solution. That's all.I don't understand.
If I read it right, there's a 2^n byte BAR. You're requesting WC for the whole think using
arch_phys_wc_add.
I believe there is a misunderstanding of order of changes.
Let's split when we use mtrr_add() Vs arch_phys_wc_add() to avoid confusion as in this patch we don't yet use arch_phys_wc_add(). That is done in the next patch.
The commit log describes best the state of affairs prior to this patch:
The atyfb driver uses an MTRR work around since some cards use the same PCI BAR for the framebuffer and MMIO. In such cards the last page is used for MMIO, the rest for the framebuffer, so on those cards we ioremap() the MMIO page alone, then again ioremap() the full framebuffer including the MMIO space *and* ___then___ use an MTRR with MTRR_TYPE_WRCOMB on the full PCI BAR... and finally "hole" in an MTRR_TYPE_UNCACHABLE MTRR only for MMIO.
Then this patch drops the MTRR_TYPE_UNCACHABLE rewrite thing and instead corrects the ioremap() call for the framebuffer to only be called for the framebuffer alone. For the MMIO area we adjust to use then ioremap_nocache(). The MTRR left is now only *for the framebuffer* and it should not be touching the MMIO area. So the MMIO area has its own ioremap_nocache() area alone, the framebuffer is left with an ioremap() followed by an mtrr_add() call.
The next patch replaces the mtrr_add() with arch_phys_wc_add() and then also uses ioremap_wc().
Quoted 1 line
On a PAT system that has no effect and all is well.
Yeah we're not doing arch_phys_wc_add() on the entire PCI BAR. That was dumb, this fixes that, and on this patch mtrr_add() is still used.
Quoted 3 lines
On a non-PAT system, it adds an MTRR. That
means that you need to override the MTRR somehow for the mmio regs, and UC- won't do the trick.
We don't need to solve that problem here as the MTRR should only be for the framebuffer.
Luis
Re: [PATCH v1 09/47] vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around
In reply to Andy LutomirskiQuoted 60 lines · Andy Lutomirski
Quoted 59 lines · Luis R. Rodriguez
Quoted 44 lines · Andy Lutomirski
Quoted 42 lines · Luis R. Rodriguez
drivers/video/fbdev/aty/atyfb_base.c +2
-17@@ -2630,21 +2630,10 @@ static int aty_init(struct fb_info *info)#ifdef CONFIG_MTRR par->mtrr_aper =-1 ; - par->mtrr_reg =-1 ;if (!nomtrr) { -/* Cover the whole resource. */ - par->mtrr_aper =mtrr_add (par->res_start, par->res_size, + par->mtrr_aper =mtrr_add (info->fix.smem_start, + info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 ); -if (par->mtrr_aper >=0 && !par->aux_start) { -/* Make a hole for mmio. */ - par->mtrr_reg =mtrr_add (par->res_start +0x800000 - -GUI_RESERVE ,GUI_RESERVE , -MTRR_TYPE_UNCACHABLE ,1 ); -if (par->mtrr_reg <0 ) { -mtrr_del (par->mtrr_aper,0 ,0 ); - par->mtrr_aper =-1 ; - } - } }#endif @@ -2776,10 +2765,6 @@ aty_init_exit: par->pll_ops->set_pll (info, &par->saved_pll);#ifdef CONFIG_MTRR -if (par->mtrr_reg >=0 ) { -mtrr_del (par->mtrr_reg,0 ,0 ); - par->mtrr_reg =-1 ; - }if (par->mtrr_aper >=0 ) {mtrr_del (par->mtrr_aper,0 ,0 ); par->mtrr_aper =-1 ;@@ -3466,7 +3451,7 @@ static int atyfb_setup_generic(struct pci_dev *pdev, struct fb_info *info, }Quoted 5 lines
drivers/video/fbdev/aty/atyfb_base.c static int atyfb_setup_generic(struct pci_dev *pdev, struct fb_info *info, · line 3454
Quoted 3 lines
drivers/video/fbdev/aty/atyfb_base.c +1
-1info->fix.mmio_start = raddr; - par->ati_regbase =ioremap (info->fix.mmio_start,0x1000 ); + par->ati_regbase =ioremap_nocache (info->fix.mmio_start,0x1000 );Double-check me, but I think that
ioremap_nocache+ WC MTRR = WC.Precicely, in this case the WC hole was obtained by using MTRR WC. This patch removes that WC hole trick and now we can be explciit about only wanting
ioremap_nocache()on the registers, that is WC is not desired here and is not used. The patch does not highlight the fact that there was left in place anotherioremap()call for the framebuffer:
info->screen_base=ioremap(info->fix.smem_start, info->fix.smem_len);
Quoted 8 lines
Quoted 3 lines
That is the one that later after this patch we use
ioremap_wc()for. This patch just removes the hole solution. That's all.I don't understand.
If I read it right, there's a 2^n byte BAR. You're requesting WC for the whole think using
arch_phys_wc_add.
I believe there is a misunderstanding of order of changes.
Let's split when we use mtrr_add() Vs arch_phys_wc_add() to avoid confusion as in this patch we don't yet use arch_phys_wc_add(). That is done in the next patch.
The commit log describes best the state of affairs prior to this patch:
The atyfb driver uses an MTRR work around since some cards use the same PCI BAR for the framebuffer and MMIO. In such cards the last page is used for MMIO, the rest for the framebuffer, so on those cards we ioremap() the MMIO page alone, then again ioremap() the full framebuffer including the MMIO space *and* ___then___ use an MTRR with MTRR_TYPE_WRCOMB on the full PCI BAR... and finally "hole" in an MTRR_TYPE_UNCACHABLE MTRR only for MMIO.
Then this patch drops the MTRR_TYPE_UNCACHABLE rewrite thing and instead corrects the ioremap() call for the framebuffer to only be called for the framebuffer alone. For the MMIO area we adjust to use then ioremap_nocache(). The MTRR left is now only *for the framebuffer* and it should not be touching the MMIO area. So the MMIO area has its own ioremap_nocache() area alone, the framebuffer is left with an ioremap() followed by an mtrr_add() call.
The next patch replaces the mtrr_add() with arch_phys_wc_add() and then also uses ioremap_wc().
Quoted 1 line
On a PAT system that has no effect and all is well.
Yeah we're not doing arch_phys_wc_add() on the entire PCI BAR. That was dumb, this fixes that, and on this patch mtrr_add() is still used.
Quoted 3 lines
On a non-PAT system, it adds an MTRR. That
means that you need to override the MTRR somehow for the mmio regs, and UC- won't do the trick.
We don't need to solve that problem here as the MTRR should only be for the framebuffer.
Luis
Re: [PATCH v1 09/47] vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around
In reply to Luis R. RodriguezQuoted 57 lines · Luis R. Rodriguez
Quoted 44 lines · Andy Lutomirski
Quoted 42 lines · Luis R. Rodriguez
drivers/video/fbdev/aty/atyfb_base.c +2
-17@@ -2630,21 +2630,10 @@ static int aty_init(struct fb_info *info)#ifdef CONFIG_MTRR par->mtrr_aper =-1 ; - par->mtrr_reg =-1 ;if (!nomtrr) { -/* Cover the whole resource. */ - par->mtrr_aper =mtrr_add (par->res_start, par->res_size, + par->mtrr_aper =mtrr_add (info->fix.smem_start, + info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 ); -if (par->mtrr_aper >=0 && !par->aux_start) { -/* Make a hole for mmio. */ - par->mtrr_reg =mtrr_add (par->res_start +0x800000 - -GUI_RESERVE ,GUI_RESERVE , -MTRR_TYPE_UNCACHABLE ,1 ); -if (par->mtrr_reg <0 ) { -mtrr_del (par->mtrr_aper,0 ,0 ); - par->mtrr_aper =-1 ; - } - } }#endif @@ -2776,10 +2765,6 @@ aty_init_exit: par->pll_ops->set_pll (info, &par->saved_pll);#ifdef CONFIG_MTRR -if (par->mtrr_reg >=0 ) { -mtrr_del (par->mtrr_reg,0 ,0 ); - par->mtrr_reg =-1 ; - }if (par->mtrr_aper >=0 ) {mtrr_del (par->mtrr_aper,0 ,0 ); par->mtrr_aper =-1 ;@@ -3466,7 +3451,7 @@ static int atyfb_setup_generic(struct pci_dev *pdev, struct fb_info *info, }Quoted 5 lines
drivers/video/fbdev/aty/atyfb_base.c static int atyfb_setup_generic(struct pci_dev *pdev, struct fb_info *info, · line 3454
Quoted 3 lines
drivers/video/fbdev/aty/atyfb_base.c +1
-1info->fix.mmio_start = raddr; - par->ati_regbase =ioremap (info->fix.mmio_start,0x1000 ); + par->ati_regbase =ioremap_nocache (info->fix.mmio_start,0x1000 );Double-check me, but I think that
ioremap_nocache+ WC MTRR = WC.Precicely, in this case the WC hole was obtained by using MTRR WC. This patch removes that WC hole trick and now we can be explciit about only wanting
ioremap_nocache()on the registers, that is WC is not desired here and is not used. The patch does not highlight the fact that there was left in place anotherioremap()call for the framebuffer:
Quoted 5 lines
info->screen_base=ioremap(info->fix.smem_start, info->fix.smem_len);That is the one that later after this patch we use
ioremap_wc()for. This patch just removes the hole solution. That's all.
I don't understand.
If I read it right, there's a 2^n byte BAR. You're requesting WC for the whole think using arch_phys_wc_add. On a PAT system that has no effect and all is well. On a non-PAT system, it adds an MTRR. That means that you need to override the MTRR somehow for the mmio regs, and UC- won't do the trick.
Or am I missing something here?
--Andy
Quoted 1 line
Luis
Signature · 2 lines
Andy Lutomirski AMA Capital Management, LLC
Re: [PATCH v1 09/47] vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around
In reply to Andy LutomirskiQuoted 44 lines · Andy Lutomirski
Quoted 42 lines · Luis R. Rodriguez
drivers/video/fbdev/aty/atyfb_base.c +2
-17@@ -2630,21 +2630,10 @@ static int aty_init(struct fb_info *info)#ifdef CONFIG_MTRR par->mtrr_aper =-1 ; - par->mtrr_reg =-1 ;if (!nomtrr) { -/* Cover the whole resource. */ - par->mtrr_aper =mtrr_add (par->res_start, par->res_size, + par->mtrr_aper =mtrr_add (info->fix.smem_start, + info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 ); -if (par->mtrr_aper >=0 && !par->aux_start) { -/* Make a hole for mmio. */ - par->mtrr_reg =mtrr_add (par->res_start +0x800000 - -GUI_RESERVE ,GUI_RESERVE , -MTRR_TYPE_UNCACHABLE ,1 ); -if (par->mtrr_reg <0 ) { -mtrr_del (par->mtrr_aper,0 ,0 ); - par->mtrr_aper =-1 ; - } - } }#endif @@ -2776,10 +2765,6 @@ aty_init_exit: par->pll_ops->set_pll (info, &par->saved_pll);#ifdef CONFIG_MTRR -if (par->mtrr_reg >=0 ) { -mtrr_del (par->mtrr_reg,0 ,0 ); - par->mtrr_reg =-1 ; - }if (par->mtrr_aper >=0 ) {mtrr_del (par->mtrr_aper,0 ,0 ); par->mtrr_aper =-1 ;@@ -3466,7 +3451,7 @@ static int atyfb_setup_generic(struct pci_dev *pdev, struct fb_info *info, }
Quoted 5 lines
drivers/video/fbdev/aty/atyfb_base.c static int atyfb_setup_generic(struct pci_dev *pdev, struct fb_info *info, · line 3454
Quoted 3 lines
drivers/video/fbdev/aty/atyfb_base.c +1
-1info->fix.mmio_start = raddr; - par->ati_regbase =ioremap (info->fix.mmio_start,0x1000 ); + par->ati_regbase =ioremap_nocache (info->fix.mmio_start,0x1000 );Double-check me, but I think that
ioremap_nocache+ WC MTRR = WC.
Precicely, in this case the WC hole was obtained by using MTRR WC. This patch removes that WC hole trick and now we can be explciit about only wanting ioremap_nocache() on the registers, that is WC is not desired here and is not used. The patch does not highlight the fact that there was left in place another ioremap() call for the framebuffer:
info->screen_base = ioremap(info->fix.smem_start, info->fix.smem_len);
That is the one that later after this patch we use ioremap_wc() for. This patch just removes the hole solution. That's all.
Luis
Re: [PATCH v1 09/47] vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around
In reply to Luis R. RodriguezQuoted 121 lines · Luis R. Rodriguez
From: "Luis R. Rodriguez" <[email protected]>
The atyfb driver uses an MTRR work around since some cards use the same PCI BAR for the framebuffer and MMIO. In such cards the last page is used for MMIO, the rest for the framebuffer, so on those cards we
ioremap()the MMIO page alone, then againioremap()the full framebuffer including the MMIO space *and*___then___use an MTRR withMTRR_TYPE_WRCOMBon the full PCI BAR... and finally "hole" in anMTRR_TYPE_UNCACHABLEMTRR only for MMIO.This is a terrible fucking work around, and should by no means be necessary however evidence through a large series of conversion of drivers to
ioremap_wc()for the framebuffer shows that around the time MTRR started becoming popular devices did not have things lined up for easily separating the framebuffer and MMIO register access. In some cases a driver requires significant intrusive changes in order to make the split for anioremap()for MMIO registers and anotherioremap_wc()for the framebuffer, at other times a bit of careful study of the driver suffices. This example driver falls into the later category.We can replace the MTRR
MTRR_TYPE_UNCACHABLE
work around by usingioremap_nocache(), the length of the MMIO space should already be correct. The other part we need to correct is ensuring weioremap()for the framebuffer only the required size. Since theioremap()happens early on probe for PCI devices beforeaty_init()where we typically adjust the length and know how to do it, we can fix this by pegging the bus type as PCI on PCI probe, and finally fudging and framebuffer length just as we do onaty_init().The last thing we do must do to remain sane is ensure we use the
info->fix.smem_startandinfo->fix.smem_lenfor the framebuffer MTRR as we know that is always well adjusted. The *one* concern here would be if the MTRR is not in units of 4K__but__we already know that in the PCI case this cannot happen, in the shared space setting the MTRR would be up to0x7ff000and assuming a 4K page:;
0x7ff000/0x10002047Also, internally when MTRR is used
mtrr_add()will usemtrr_check()and that should splat a warning when the MTRR base and size are not compatible with what is expected for MTRR usage.This fix lets us nuke the
MTRR_TYPE_UNCACHABLEMTRR "hole".Cc Suresh Siddha <[email protected]>Cc Venkatesh Pallipadi <[email protected]>Cc Ingo Molnar <[email protected]>Cc Linus Torvalds <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Juergen Gross <[email protected]>Cc Daniel Vetter <[email protected]>Cc Andy Lutomirski <[email protected]>Cc Dave Airlie <[email protected]>Cc Antonino Daplas <[email protected]>Cc Jean-Christophe Plagniol-Villard <[email protected]>Cc Tomi Valkeinen <[email protected]>Signed-off-by Luis R. Rodriguez <[email protected]>--- drivers/video/fbdev/aty/atyfb.h | 1 - drivers/video/fbdev/aty/atyfb_base.c | 28 ++++++---------------------- 2 files changed, 6 insertions(+), 23 deletions(-)drivers/video/fbdev/aty/atyfb.h +0
-1@@ -184,7 +184,6 @@ struct atyfb_par {spinlock_t int_lock;#ifdef CONFIG_MTRR int mtrr_aper; -int mtrr_reg;#endif u32 mem_cntl;struct crtc saved_crtc;drivers/video/fbdev/aty/atyfb_base.c +2
-17@@ -2630,21 +2630,10 @@ static int aty_init(struct fb_info *info)#ifdef CONFIG_MTRR par->mtrr_aper =-1 ; - par->mtrr_reg =-1 ;if (!nomtrr) { -/* Cover the whole resource. */ - par->mtrr_aper =mtrr_add (par->res_start, par->res_size, + par->mtrr_aper =mtrr_add (info->fix.smem_start, + info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 ); -if (par->mtrr_aper >=0 && !par->aux_start) { -/* Make a hole for mmio. */ - par->mtrr_reg =mtrr_add (par->res_start +0x800000 - -GUI_RESERVE ,GUI_RESERVE , -MTRR_TYPE_UNCACHABLE ,1 ); -if (par->mtrr_reg <0 ) { -mtrr_del (par->mtrr_aper,0 ,0 ); - par->mtrr_aper =-1 ; - } - } }#endif @@ -2776,10 +2765,6 @@ aty_init_exit: par->pll_ops->set_pll (info, &par->saved_pll);#ifdef CONFIG_MTRR -if (par->mtrr_reg >=0 ) { -mtrr_del (par->mtrr_reg,0 ,0 ); - par->mtrr_reg =-1 ; - }if (par->mtrr_aper >=0 ) {mtrr_del (par->mtrr_aper,0 ,0 ); par->mtrr_aper =-1 ;
drivers/video/fbdev/aty/atyfb_base.c static int atyfb_setup_generic(struct pci_dev *pdev, struct fb_info *info, · line 3454
Quoted 5 lines
drivers/video/fbdev/aty/atyfb_base.c +1
-1@@ -3466,7 +3451,7 @@ static int atyfb_setup_generic(struct pci_dev *pdev, struct fb_info *info, } info->fix.mmio_start = raddr; - par->ati_regbase =ioremap (info->fix.mmio_start,0x1000 ); + par->ati_regbase =ioremap_nocache (info->fix.mmio_start,0x1000 );
Double-check me, but I think that ioremap_nocache + WC MTRR = WC. I think we might need ioremap_nocache_me_harder (or maybe ioremap_x86_uc if you prefer that bikeshed color) for this.
Re: [PATCH v1 09/47] vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around
In reply to Luis R. RodriguezQuoted 5 lines · Luis R. Rodriguez
drivers/video/fbdev/aty/atyfb_base.c +0
-0
drivers/video/fbdev/aty/atyfb_base.c static int aty_init(struct fb_info *info) · line 2636
Quoted 10 lines
drivers/video/fbdev/aty/atyfb_base.c +2
-3@@ -2630,21 +2630,10 @@ static int aty_init(struct fb_info *info)#ifdef CONFIG_MTRR par->mtrr_aper =-1 ; - par->mtrr_reg =-1 ;if (!nomtrr) { -/* Cover the whole resource. */ - par->mtrr_aper =mtrr_add (par->res_start, par->res_size, + par->mtrr_aper =mtrr_add (info->fix.smem_start, + info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 );
MTRRs need power of two size, so how is this supposed to work?
Quoted 68 lines
drivers/video/fbdev/aty/atyfb_base.c +4
-19-if (par->mtrr_aper >=0 && !par->aux_start) { -/* Make a hole for mmio. */ - par->mtrr_reg =mtrr_add (par->res_start +0x800000 - -GUI_RESERVE ,GUI_RESERVE , -MTRR_TYPE_UNCACHABLE ,1 ); -if (par->mtrr_reg <0 ) { -mtrr_del (par->mtrr_aper,0 ,0 ); - par->mtrr_aper =-1 ; - } - } }#endif @@ -2776,10 +2765,6 @@ aty_init_exit: par->pll_ops->set_pll (info, &par->saved_pll);#ifdef CONFIG_MTRR -if (par->mtrr_reg >=0 ) { -mtrr_del (par->mtrr_reg,0 ,0 ); - par->mtrr_reg =-1 ; - }if (par->mtrr_aper >=0 ) {mtrr_del (par->mtrr_aper,0 ,0 ); par->mtrr_aper =-1 ;@@ -3466,7 +3451,7 @@ static int atyfb_setup_generic(struct pci_dev *pdev, struct fb_info *info, } info->fix.mmio_start = raddr; - par->ati_regbase =ioremap (info->fix.mmio_start,0x1000 ); + par->ati_regbase =ioremap_nocache (info->fix.mmio_start,0x1000 );if (par->ati_regbase =NULL )return -ENOMEM ;@@ -3491,6 +3476,8 @@ static int atyfb_setup_generic(struct pci_dev *pdev, struct fb_info *info, info->fix.smem_start = addr; info->fix.smem_len =0x800000 ; +aty_fudge_framebuffer_len (info); + info->screen_base =ioremap (info->fix.smem_start, info->fix.smem_len);if (info->screen_base =NULL ) { ret = -ENOMEM ;@@ -3563,6 +3550,7 @@ static int atyfb_pci_probe(struct pci_dev *pdev,return -ENOMEM ; } par = info->par; + par->bus_type =PCI ; info->fix = atyfb_fix; info->device = &pdev->dev; par->pci_id = pdev->device;@@ -3732,10 +3720,6 @@ static void atyfb_remove(struct fb_info *info)#endif #ifdef CONFIG_MTRR -if (par->mtrr_reg >=0 ) { -mtrr_del (par->mtrr_reg,0 ,0 ); - par->mtrr_reg =-1 ; - }if (par->mtrr_aper >=0 ) {mtrr_del (par->mtrr_aper,0 ,0 ); par->mtrr_aper =-1 ;Signature · 6 lines
2.3.2.209.gd67f9d5.dirty -- To unsubscribe from this list: send the line "unsubscribe linux-fbdev" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 3 lines
Ville Syrjälä [email protected] http://www.sci.fi/~syrjala/
Re: [PATCH v1 09/47] vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around
Quoted 7 lines · Ville Syrjälä
Quoted 6 lines · Luis R. Rodriguez
drivers/video/fbdev/aty/atyfb_base.c +0
-0@@ -2630,21 +2630,10 @@ static int aty_init(struct fb_info *info)
Quoted 11 lines
drivers/video/fbdev/aty/atyfb_base.c static int aty_init(struct fb_info *info) · line 2636
Quoted 9 lines
drivers/video/fbdev/aty/atyfb_base.c +2
-3#ifdef CONFIG_MTRR par->mtrr_aper =-1 ; - par->mtrr_reg =-1 ;if (!nomtrr) { -/* Cover the whole resource. */ - par->mtrr_aper =mtrr_add (par->res_start, par->res_size, + par->mtrr_aper =mtrr_add (info->fix.smem_start, + info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 );MTRRs need power of two size, so how is this supposed to work?
Still waiting for an answer...
Quoted 74 lines
Quoted 69 lines
drivers/video/fbdev/aty/atyfb_base.c +4
-19-if (par->mtrr_aper >=0 && !par->aux_start) { -/* Make a hole for mmio. */ - par->mtrr_reg =mtrr_add (par->res_start +0x800000 - -GUI_RESERVE ,GUI_RESERVE , -MTRR_TYPE_UNCACHABLE ,1 ); -if (par->mtrr_reg <0 ) { -mtrr_del (par->mtrr_aper,0 ,0 ); - par->mtrr_aper =-1 ; - } - } }#endif @@ -2776,10 +2765,6 @@ aty_init_exit: par->pll_ops->set_pll (info, &par->saved_pll);#ifdef CONFIG_MTRR -if (par->mtrr_reg >=0 ) { -mtrr_del (par->mtrr_reg,0 ,0 ); - par->mtrr_reg =-1 ; - }if (par->mtrr_aper >=0 ) {mtrr_del (par->mtrr_aper,0 ,0 ); par->mtrr_aper =-1 ;@@ -3466,7 +3451,7 @@ static int atyfb_setup_generic(struct pci_dev *pdev, struct fb_info *info, } info->fix.mmio_start = raddr; - par->ati_regbase =ioremap (info->fix.mmio_start,0x1000 ); + par->ati_regbase =ioremap_nocache (info->fix.mmio_start,0x1000 );if (par->ati_regbase =NULL )return -ENOMEM ;@@ -3491,6 +3476,8 @@ static int atyfb_setup_generic(struct pci_dev *pdev, struct fb_info *info, info->fix.smem_start = addr; info->fix.smem_len =0x800000 ; +aty_fudge_framebuffer_len (info); + info->screen_base =ioremap (info->fix.smem_start, info->fix.smem_len);if (info->screen_base =NULL ) { ret = -ENOMEM ;@@ -3563,6 +3550,7 @@ static int atyfb_pci_probe(struct pci_dev *pdev,return -ENOMEM ; } par = info->par; + par->bus_type =PCI ; info->fix = atyfb_fix; info->device = &pdev->dev; par->pci_id = pdev->device;@@ -3732,10 +3720,6 @@ static void atyfb_remove(struct fb_info *info)#endif #ifdef CONFIG_MTRR -if (par->mtrr_reg >=0 ) { -mtrr_del (par->mtrr_reg,0 ,0 ); - par->mtrr_reg =-1 ; - }if (par->mtrr_aper >=0 ) {mtrr_del (par->mtrr_aper,0 ,0 ); par->mtrr_aper =-1 ;Signature · 6 lines
2.3.2.209.gd67f9d5.dirty -- To unsubscribe from this list: send the line "unsubscribe linux-fbdev" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.htmlSignature · 3 lines
Ville Syrjälä [email protected] http://www.sci.fi/~syrjala/
Signature · 3 lines
Ville Syrjälä [email protected] http://www.sci.fi/~syrjala/
Re: [PATCH v1 09/47] vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around
Quoted 20 lines · Ville Syrjälä
Quoted 7 lines · Ville Syrjälä
Quoted 6 lines · Luis R. Rodriguez
drivers/video/fbdev/aty/atyfb_base.c +0
-0@@ -2630,21 +2630,10 @@ static int aty_init(struct fb_info *info)Quoted 11 lines
drivers/video/fbdev/aty/atyfb_base.c static int aty_init(struct fb_info *info) · line 2636
Quoted 9 lines
drivers/video/fbdev/aty/atyfb_base.c +2
-3#ifdef CONFIG_MTRR par->mtrr_aper =-1 ; - par->mtrr_reg =-1 ;if (!nomtrr) { -/* Cover the whole resource. */ - par->mtrr_aper =mtrr_add (par->res_start, par->res_size, + par->mtrr_aper =mtrr_add (info->fix.smem_start, + info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 );MTRRs need power of two size, so how is this supposed to work?
Quoted 1 line
Still waiting for an answer...
Sorry was in the desert for a bit, I'm back now.
Luis
Re: [PATCH v1 09/47] vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around
In reply to Ville SyrjäläQuoted 20 lines · Ville Syrjälä
Quoted 7 lines · Ville Syrjälä
Quoted 6 lines · Luis R. Rodriguez
drivers/video/fbdev/aty/atyfb_base.c +0
-0@@ -2630,21 +2630,10 @@ static int aty_init(struct fb_info *info)Quoted 11 lines
drivers/video/fbdev/aty/atyfb_base.c static int aty_init(struct fb_info *info) · line 2636
Quoted 9 lines
drivers/video/fbdev/aty/atyfb_base.c +2
-3#ifdef CONFIG_MTRR par->mtrr_aper =-1 ; - par->mtrr_reg =-1 ;if (!nomtrr) { -/* Cover the whole resource. */ - par->mtrr_aper =mtrr_add (par->res_start, par->res_size, + par->mtrr_aper =mtrr_add (info->fix.smem_start, + info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 );MTRRs need power of two size, so how is this supposed to work?
Quoted 1 line
Still waiting for an answer...
Sorry was in the desert for a bit, I'm back now.
Luis
Re: [PATCH v1 09/47] vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around
In reply to Ville SyrjäläQuoted 7 lines · Ville Syrjälä
Quoted 6 lines · Luis R. Rodriguez
drivers/video/fbdev/aty/atyfb_base.c +0
-0@@ -2630,21 +2630,10 @@ static int aty_init(struct fb_info *info)
Quoted 11 lines
drivers/video/fbdev/aty/atyfb_base.c static int aty_init(struct fb_info *info) · line 2636
Quoted 9 lines
drivers/video/fbdev/aty/atyfb_base.c +2
-3#ifdef CONFIG_MTRR par->mtrr_aper =-1 ; - par->mtrr_reg =-1 ;if (!nomtrr) { -/* Cover the whole resource. */ - par->mtrr_aper =mtrr_add (par->res_start, par->res_size, + par->mtrr_aper =mtrr_add (info->fix.smem_start, + info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 );MTRRs need power of two size, so how is this supposed to work?
Still waiting for an answer...
Quoted 74 lines
Quoted 69 lines
drivers/video/fbdev/aty/atyfb_base.c +4
-19-if (par->mtrr_aper >=0 && !par->aux_start) { -/* Make a hole for mmio. */ - par->mtrr_reg =mtrr_add (par->res_start +0x800000 - -GUI_RESERVE ,GUI_RESERVE , -MTRR_TYPE_UNCACHABLE ,1 ); -if (par->mtrr_reg <0 ) { -mtrr_del (par->mtrr_aper,0 ,0 ); - par->mtrr_aper =-1 ; - } - } }#endif @@ -2776,10 +2765,6 @@ aty_init_exit: par->pll_ops->set_pll (info, &par->saved_pll);#ifdef CONFIG_MTRR -if (par->mtrr_reg >=0 ) { -mtrr_del (par->mtrr_reg,0 ,0 ); - par->mtrr_reg =-1 ; - }if (par->mtrr_aper >=0 ) {mtrr_del (par->mtrr_aper,0 ,0 ); par->mtrr_aper =-1 ;@@ -3466,7 +3451,7 @@ static int atyfb_setup_generic(struct pci_dev *pdev, struct fb_info *info, } info->fix.mmio_start = raddr; - par->ati_regbase =ioremap (info->fix.mmio_start,0x1000 ); + par->ati_regbase =ioremap_nocache (info->fix.mmio_start,0x1000 );if (par->ati_regbase ==NULL )return -ENOMEM ;@@ -3491,6 +3476,8 @@ static int atyfb_setup_generic(struct pci_dev *pdev, struct fb_info *info, info->fix.smem_start = addr; info->fix.smem_len =0x800000 ; +aty_fudge_framebuffer_len (info); + info->screen_base =ioremap (info->fix.smem_start, info->fix.smem_len);if (info->screen_base ==NULL ) { ret = -ENOMEM ;@@ -3563,6 +3550,7 @@ static int atyfb_pci_probe(struct pci_dev *pdev,return -ENOMEM ; } par = info->par; + par->bus_type =PCI ; info->fix = atyfb_fix; info->device = &pdev->dev; par->pci_id = pdev->device;@@ -3732,10 +3720,6 @@ static void atyfb_remove(struct fb_info *info)#endif #ifdef CONFIG_MTRR -if (par->mtrr_reg >=0 ) { -mtrr_del (par->mtrr_reg,0 ,0 ); - par->mtrr_reg =-1 ; - }if (par->mtrr_aper >=0 ) {mtrr_del (par->mtrr_aper,0 ,0 ); par->mtrr_aper =-1 ;Signature · 6 lines
2.3.2.209.gd67f9d5.dirty -- To unsubscribe from this list: send the line "unsubscribe linux-fbdev" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.htmlSignature · 3 lines
Ville Syrjälä [email protected] http://www.sci.fi/~syrjala/
Signature · 3 lines
Ville Syrjälä [email protected] http://www.sci.fi/~syrjala/
Re: [PATCH v1 09/47] vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around
In reply to Ville SyrjäläQuoted 7 lines · Ville Syrjälä
Quoted 6 lines · Luis R. Rodriguez
drivers/video/fbdev/aty/atyfb_base.c +0
-0@@ -2630,21 +2630,10 @@ static int aty_init(struct fb_info *info)
Quoted 11 lines
drivers/video/fbdev/aty/atyfb_base.c static int aty_init(struct fb_info *info) · line 2636
Quoted 9 lines
drivers/video/fbdev/aty/atyfb_base.c +2
-3#ifdef CONFIG_MTRR par->mtrr_aper =-1 ; - par->mtrr_reg =-1 ;if (!nomtrr) { -/* Cover the whole resource. */ - par->mtrr_aper =mtrr_add (par->res_start, par->res_size, + par->mtrr_aper =mtrr_add (info->fix.smem_start, + info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 );MTRRs need power of two size, so how is this supposed to work?
As per mtrr_add_page() [0] the base and size are just supposed to be in units of 4 KiB, although the practice is to use powers of 2 in *some* drivers this is not standardized and by no means recorded as a requirement. Obviously powers of 2 will work too and you'd end up neatly aligned as well. mtrr_add() will use mtrr_check() to verify the the same requirement. Furthermore, as per my commit log message:
---
The last thing we do must do to remain sane is ensure we use the info->fix.smem_start and info->fix.smem_len for the framebuffer MTRR as we know that is always well adjusted. The *one* concern here would be if the MTRR is not in units of 4K __but__ we already know that in the PCI case this cannot happen, in the shared space setting the MTRR would be up to 0x7ff000 and assuming a 4K page:
; 0x7ff000 / 0x1000
2047
Also, internally when MTRR is used mtrr_add() will use mtrr_check() and that should splat a warning when the MTRR base and size are not compatible with what is expected for MTRR usage.
---
If any of this is too risky we can use the __arch_phys_wc_add() (or as Andy suggested perhaps use set_page_* stuff, although I am still evaluating this) but I did this change to show the effort required for a change when the registers / framebuffer is on the same PCI BAR but at different offsets.
[0] scripts/kernel-doc -man -function mtrr_add_page arch/x86/kernel/cpu/mtrr/main.c | nroff -man | less
Luis
Re: [PATCH v1 09/47] vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around
Quoted 20 lines · Luis R. Rodriguez
Quoted 7 lines · Ville Syrjälä
Quoted 6 lines · Luis R. Rodriguez
drivers/video/fbdev/aty/atyfb_base.c +0
-0@@ -2630,21 +2630,10 @@ static int aty_init(struct fb_info *info)Quoted 11 lines
drivers/video/fbdev/aty/atyfb_base.c static int aty_init(struct fb_info *info) · line 2636
Quoted 9 lines
drivers/video/fbdev/aty/atyfb_base.c +2
-3#ifdef CONFIG_MTRR par->mtrr_aper =-1 ; - par->mtrr_reg =-1 ;if (!nomtrr) { -/* Cover the whole resource. */ - par->mtrr_aper =mtrr_add (par->res_start, par->res_size, + par->mtrr_aper =mtrr_add (info->fix.smem_start, + info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 );MTRRs need power of two size, so how is this supposed to work?
Quoted 6 lines
As per
mtrr_add_page()[0] the base and size are just supposed to be in units of 4 KiB, although the practice is to use powers of 2 in *some* drivers this is not standardized and by no means recorded as a requirement. Obviously powers of 2 will work too and you'd end up neatly aligned as well.mtrr_add()will usemtrr_check()to verify the the same requirement. Furthermore, as per my commit log message:
Whatever the code may or may not do, the x86 architecture uses power-of-two MTRR sizes. So I'm confused.
--Andy
Quoted 26 lines
---
The last thing we do must do to remain sane is ensure we use theinfo->fix.smem_startandinfo->fix.smem_lenfor the framebuffer MTRR as we know that is always well adjusted. The *one* concern here would be if the MTRR is not in units of 4K__but__we already know that in the PCI case this cannot happen, in the shared space setting the MTRR would be up to0x7ff000and assuming a 4K page:;
0x7ff000/0x1000
2047Also, internally when MTRR is used
mtrr_add()will usemtrr_check()and that should splat a warning when the MTRR base and size are not compatible with what is expected for MTRR usage.
---If any of this is too risky we can use the
__arch_phys_wc_add()(or as Andy suggested perhaps use set_page_* stuff, although I am still evaluating this) but I did this change to show the effort required for a change when the registers / framebuffer is on the same PCI BAR but at different offsets.[0]
scripts/kernel-doc-man -functionmtrr_add_pagearch/x86/kernel/cpu/mtrr/main.c| nroff -man | lessLuis
Signature · 2 lines
Andy Lutomirski AMA Capital Management, LLC
Re: [PATCH v1 09/47] vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around
Quoted 28 lines · Andy Lutomirski
Quoted 20 lines · Luis R. Rodriguez
Quoted 7 lines · Ville Syrjälä
Quoted 6 lines · Luis R. Rodriguez
drivers/video/fbdev/aty/atyfb_base.c +0
-0@@ -2630,21 +2630,10 @@ static int aty_init(struct fb_info *info)Quoted 11 lines
drivers/video/fbdev/aty/atyfb_base.c static int aty_init(struct fb_info *info) · line 2636
Quoted 9 lines
drivers/video/fbdev/aty/atyfb_base.c +2
-3#ifdef CONFIG_MTRR par->mtrr_aper =-1 ; - par->mtrr_reg =-1 ;if (!nomtrr) { -/* Cover the whole resource. */ - par->mtrr_aper =mtrr_add (par->res_start, par->res_size, + par->mtrr_aper =mtrr_add (info->fix.smem_start, + info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 );MTRRs need power of two size, so how is this supposed to work?
Quoted 6 lines
As per
mtrr_add_page()[0] the base and size are just supposed to be in units of 4 KiB, although the practice is to use powers of 2 in *some* drivers this is not standardized and by no means recorded as a requirement. Obviously powers of 2 will work too and you'd end up neatly aligned as well.mtrr_add()will usemtrr_check()to verify the the same requirement. Furthermore, as per my commit log message:
Quoted 2 lines
Whatever the code may or may not do, the x86 architecture uses power-of-two MTRR sizes. So I'm confused.
There should be no confusion, I simply did not know that *was* the requirement for x86, if that is the case we should add a check for that and perhaps generalize a helper that does the power of two helper changes, the cleanest I found was the vesafb driver solution.
Thoughts?
Luis
Re: [PATCH v1 09/47] vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around
Quoted 32 lines · Luis R. Rodriguez
Quoted 28 lines · Andy Lutomirski
Quoted 20 lines · Luis R. Rodriguez
Quoted 7 lines · Ville Syrjälä
Quoted 6 lines · Luis R. Rodriguez
drivers/video/fbdev/aty/atyfb_base.c +0
-0@@ -2630,21 +2630,10 @@ static int aty_init(struct fb_info *info)Quoted 11 lines
drivers/video/fbdev/aty/atyfb_base.c static int aty_init(struct fb_info *info) · line 2636
Quoted 9 lines
drivers/video/fbdev/aty/atyfb_base.c +2
-3#ifdef CONFIG_MTRR par->mtrr_aper =-1 ; - par->mtrr_reg =-1 ;if (!nomtrr) { -/* Cover the whole resource. */ - par->mtrr_aper =mtrr_add (par->res_start, par->res_size, + par->mtrr_aper =mtrr_add (info->fix.smem_start, + info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 );MTRRs need power of two size, so how is this supposed to work?
Quoted 6 lines
As per
mtrr_add_page()[0] the base and size are just supposed to be in units of 4 KiB, although the practice is to use powers of 2 in *some* drivers this is not standardized and by no means recorded as a requirement. Obviously powers of 2 will work too and you'd end up neatly aligned as well.mtrr_add()will usemtrr_check()to verify the the same requirement. Furthermore, as per my commit log message:Quoted 2 lines
Whatever the code may or may not do, the x86 architecture uses power-of-two MTRR sizes. So I'm confused.
Quoted 6 lines
There should be no confusion, I simply did not know that *was* the requirement for x86, if that is the case we should add a check for that and perhaps generalize a helper that does the power of two helper changes, the cleanest I found was the vesafb driver solution.
Thoughts?
The vesafb solution is bad since you'll only end up covering only the first 4MB of the framebuffer instead of the almost 8MB you want. Which in practice will mean throwing away half the VRAM since you really don't want the massive performance hit from accessing it as UC. And that would mean giving up decent display resolutions as well :(
And the other option of trying to cover the remainder with multiple ever smaller MTRRs doesn't work either since you'll run out of MTRRs very quickly.
This is precisely why I used the hole method in atyfb in the first place.
I don't really like the idea of any new mtrr code not supporting that use case, especially as these things tend to be present in older machines where PAT isn't an option.
Signature · 3 lines
Ville Syrjälä [email protected] http://www.sci.fi/~syrjala/
Re: [PATCH v1 09/47] vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around
Quoted 50 lines · Ville Syrj채l채
Quoted 32 lines · Luis R. Rodriguez
Quoted 28 lines · Andy Lutomirski
Quoted 20 lines · Luis R. Rodriguez
Quoted 7 lines · Ville Syrj채l채
Quoted 6 lines · Luis R. Rodriguez
drivers/video/fbdev/aty/atyfb_base.c +0
-0@@ -2630,21 +2630,10 @@ static int aty_init(struct fb_info *info)Quoted 11 lines
drivers/video/fbdev/aty/atyfb_base.c static int aty_init(struct fb_info *info) · line 2636
Quoted 9 lines
drivers/video/fbdev/aty/atyfb_base.c +2
-3#ifdef CONFIG_MTRR par->mtrr_aper =-1 ; - par->mtrr_reg =-1 ;if (!nomtrr) { -/* Cover the whole resource. */ - par->mtrr_aper =mtrr_add (par->res_start, par->res_size, + par->mtrr_aper =mtrr_add (info->fix.smem_start, + info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 );MTRRs need power of two size, so how is this supposed to work?
Quoted 6 lines
As per
mtrr_add_page()[0] the base and size are just supposed to be in units of 4 KiB, although the practice is to use powers of 2 in *some* drivers this is not standardized and by no means recorded as a requirement. Obviously powers of 2 will work too and you'd end up neatly aligned as well.mtrr_add()will usemtrr_check()to verify the the same requirement. Furthermore, as per my commit log message:Quoted 2 lines
Whatever the code may or may not do, the x86 architecture uses power-of-two MTRR sizes. So I'm confused.
Quoted 6 lines
There should be no confusion, I simply did not know that *was* the requirement for x86, if that is the case we should add a check for that and perhaps generalize a helper that does the power of two helper changes, the cleanest I found was the vesafb driver solution.
Thoughts?
The vesafb solution is bad since you'll only end up covering only the first 4MB of the framebuffer instead of the almost 8MB you want. Which in practice will mean throwing away half the VRAM since you really don't want the massive performance hit from accessing it as UC. And that would mean giving up decent display resolutions as well :(
And the other option of trying to cover the remainder with multiple ever smaller MTRRs doesn't work either since you'll run out of MTRRs very quickly.
Quoted 6 lines
This is precisely why I used the hole method in atyfb in the first place.
I don't really like the idea of any new mtrr code not supporting that use case, especially as these things tend to be present in older machines where PAT isn't an option.
According to the Intel SDM, volume 3, section 11.5.2.1, table 11-6, non-PAT CPUs that have a WC MTRR, PCD = 1, and PWT = 1 (aka UC) have an effective memory type of UC. Hence my suggestion to add ioremap_x86_uc and/or set_memory_x86_uc to punch a UC hole in an otherwise WC MTRR-covered region.
ioremap_nocache is UC- (even on non-PAT unless I misunderstood how this stuff works), so ioremap_nocache by itself isn't good enough.
--Andy
--
To unsubscribe from this list: send the line "unsubscribe linux-fbdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v1 09/47] vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around
Quoted 58 lines · Andy Lutomirski
Quoted 50 lines · Ville Syrjälä
Quoted 32 lines · Luis R. Rodriguez
Quoted 28 lines · Andy Lutomirski
Quoted 20 lines · Luis R. Rodriguez
Quoted 7 lines · Ville Syrjälä
Quoted 6 lines · Luis R. Rodriguez
drivers/video/fbdev/aty/atyfb_base.c +0
-0@@ -2630,21 +2630,10 @@ static int aty_init(struct fb_info *info)Quoted 11 lines
drivers/video/fbdev/aty/atyfb_base.c static int aty_init(struct fb_info *info) · line 2636
Quoted 9 lines
drivers/video/fbdev/aty/atyfb_base.c +2
-3#ifdef CONFIG_MTRR par->mtrr_aper =-1 ; - par->mtrr_reg =-1 ;if (!nomtrr) { -/* Cover the whole resource. */ - par->mtrr_aper =mtrr_add (par->res_start, par->res_size, + par->mtrr_aper =mtrr_add (info->fix.smem_start, + info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 );MTRRs need power of two size, so how is this supposed to work?
Quoted 6 lines
As per
mtrr_add_page()[0] the base and size are just supposed to be in units of 4 KiB, although the practice is to use powers of 2 in *some* drivers this is not standardized and by no means recorded as a requirement. Obviously powers of 2 will work too and you'd end up neatly aligned as well.mtrr_add()will usemtrr_check()to verify the the same requirement. Furthermore, as per my commit log message:Quoted 2 lines
Whatever the code may or may not do, the x86 architecture uses power-of-two MTRR sizes. So I'm confused.
Quoted 6 lines
There should be no confusion, I simply did not know that *was* the requirement for x86, if that is the case we should add a check for that and perhaps generalize a helper that does the power of two helper changes, the cleanest I found was the vesafb driver solution.
Thoughts?
The vesafb solution is bad since you'll only end up covering only the first 4MB of the framebuffer instead of the almost 8MB you want. Which in practice will mean throwing away half the VRAM since you really don't want the massive performance hit from accessing it as UC. And that would mean giving up decent display resolutions as well :(
And the other option of trying to cover the remainder with multiple ever smaller MTRRs doesn't work either since you'll run out of MTRRs very quickly.
Quoted 6 lines
This is precisely why I used the hole method in atyfb in the first place.
I don't really like the idea of any new mtrr code not supporting that use case, especially as these things tend to be present in older machines where PAT isn't an option.
Quoted 5 lines
According to the Intel SDM, volume 3, section 11.5.2.1, table 11-6, non-PAT CPUs that have a WC MTRR, PCD = 1, and PWT = 1 (aka UC) have an effective memory type of UC. Hence my suggestion to add
ioremap_x86_ucand/orset_memory_x86_ucto punch a UC hole in an otherwise WC MTRR-covered region.
OK I think I get it now.
And I take it this would hopefully only be used for non-PAT systems? Would there be a use case for PAT systems? I wonder if we can wrap this under some APIs to make it clean and hide this dirty thing behind the scenes, it seems a fragile and error prone and my hope would be that we won't need more specialization in this area for PAT systems.
Quoted 2 lines
ioremap_nocacheis UC- (even on non-PAT unless I misunderstood how this stuff works), soioremap_nocacheby itself isn't good enough.
Thanks for the clarification.
Luis
Re: [PATCH v1 09/47] vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around
Quoted 65 lines · Luis R. Rodriguez
Quoted 58 lines · Andy Lutomirski
Quoted 50 lines · Ville Syrjälä
Quoted 32 lines · Luis R. Rodriguez
Quoted 28 lines · Andy Lutomirski
Quoted 20 lines · Luis R. Rodriguez
Quoted 7 lines · Ville Syrjälä
Quoted 6 lines · Luis R. Rodriguez
drivers/video/fbdev/aty/atyfb_base.c +0
-0@@ -2630,21 +2630,10 @@ static int aty_init(struct fb_info *info)Quoted 11 lines
drivers/video/fbdev/aty/atyfb_base.c static int aty_init(struct fb_info *info) · line 2636
Quoted 9 lines
drivers/video/fbdev/aty/atyfb_base.c +2
-3#ifdef CONFIG_MTRR par->mtrr_aper =-1 ; - par->mtrr_reg =-1 ;if (!nomtrr) { -/* Cover the whole resource. */ - par->mtrr_aper =mtrr_add (par->res_start, par->res_size, + par->mtrr_aper =mtrr_add (info->fix.smem_start, + info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 );MTRRs need power of two size, so how is this supposed to work?
Quoted 6 lines
As per
mtrr_add_page()[0] the base and size are just supposed to be in units of 4 KiB, although the practice is to use powers of 2 in *some* drivers this is not standardized and by no means recorded as a requirement. Obviously powers of 2 will work too and you'd end up neatly aligned as well.mtrr_add()will usemtrr_check()to verify the the same requirement. Furthermore, as per my commit log message:Quoted 2 lines
Whatever the code may or may not do, the x86 architecture uses power-of-two MTRR sizes. So I'm confused.
Quoted 6 lines
There should be no confusion, I simply did not know that *was* the requirement for x86, if that is the case we should add a check for that and perhaps generalize a helper that does the power of two helper changes, the cleanest I found was the vesafb driver solution.
Thoughts?
The vesafb solution is bad since you'll only end up covering only the first 4MB of the framebuffer instead of the almost 8MB you want. Which in practice will mean throwing away half the VRAM since you really don't want the massive performance hit from accessing it as UC. And that would mean giving up decent display resolutions as well :(
And the other option of trying to cover the remainder with multiple ever smaller MTRRs doesn't work either since you'll run out of MTRRs very quickly.
Quoted 6 lines
This is precisely why I used the hole method in atyfb in the first place.
I don't really like the idea of any new mtrr code not supporting that use case, especially as these things tend to be present in older machines where PAT isn't an option.
Quoted 5 lines
According to the Intel SDM, volume 3, section 11.5.2.1, table 11-6, non-PAT CPUs that have a WC MTRR, PCD = 1, and PWT = 1 (aka UC) have an effective memory type of UC. Hence my suggestion to add
ioremap_x86_ucand/orset_memory_x86_ucto punch a UC hole in an otherwise WC MTRR-covered region.
Quoted 8 lines
OK I think I get it now.
And I take it this would hopefully only be used for non-PAT systems? Would there be a use case for PAT systems? I wonder if we can wrap this under some APIs to make it clean and hide this dirty thing behind the scenes, it seems a fragile and error prone and my hope would be that we won't need more specialization in this area for PAT systems.
One potential complication is kernel vs. userspace mmap. MTRR applies to the physical address, but PAT applies to the virtual address, so with the WC MTRR you get WC for userspace "for free" as well. Also the userspace mmaps request will have the length of smem_len (at most), so it won't be the nice power of two in that case.
Also on PAT systems w/o a BIOS provided WC MTRR, the fbdev mmap seems to be total crap at the moment. IIRC I have a patch to fix things a bit...
From 4e6d70d223f35953c8a11a58cf3376a8a001fa4f Mon Sep 17 00:00:00 2001
From: Ville Syrjala <[email protected]>
Date: Fri, 15 Apr 2011 04:02:43 +0300
Subject: [PATCH] fb: writecombine fb
--- drivers/video/fbdev/core/fbmem.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/video/fbdev/core/fbmem.c +11 -1
@@ -1396,6 +1396,7 @@ fb_mmap(struct file *file, struct vm_area_struct * vma)unsigned long mmio_pgoff;unsigned long start;u32 len; +bool mmio = false;if (!info)return -ENODEV ;
@@ -1426,11 +1427,20 @@ fb_mmap(struct file *file, struct vm_area_struct * vma) vma->vm_pgoff -= mmio_pgoff; start = info->fix.mmio_start; len = info->fix.mmio_len; + mmio = true; }mutex_unlock (&info->mm_lock); +if (!mmio) { + vma->vm_page_prot =vm_get_page_prot (vma->vm_flags); + vma->vm_page_prot =pgprot_writecombine (vma->vm_page_prot); + +if (!vm_iomap_memory (vma, start, len)) +return 0 ; + } + vma->vm_page_prot =vm_get_page_prot (vma->vm_flags); -fb_pgprotect (file, vma, start); + vma->vm_page_prot =pgprot_noncached (vma->vm_page_prot);return vm_iomap_memory (vma, start, len); }
Perhaps it's time I tried to send that upstream properly :P
Signature · 3 lines
Ville Syrjälä [email protected] http://www.sci.fi/~syrjala/
Re: [PATCH v1 09/47] vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around
Quoted 56 lines · Ville Syrjälä
Quoted 55 lines · Luis R. Rodriguez
Quoted 54 lines · Andy Lutomirski
Quoted 53 lines · Ville Syrjälä
Quoted 32 lines · Luis R. Rodriguez
Quoted 28 lines · Andy Lutomirski
Quoted 20 lines · Luis R. Rodriguez
Quoted 7 lines · Ville Syrjälä
Quoted 6 lines · Luis R. Rodriguez
drivers/video/fbdev/aty/atyfb_base.c +0
-0@@ -2630,21 +2630,10 @@ static int aty_init(struct fb_info *info)Quoted 11 lines
drivers/video/fbdev/aty/atyfb_base.c static int aty_init(struct fb_info *info) · line 2636
Quoted 9 lines
drivers/video/fbdev/aty/atyfb_base.c +2
-3#ifdef CONFIG_MTRR par->mtrr_aper =-1 ; - par->mtrr_reg =-1 ;if (!nomtrr) { -/* Cover the whole resource. */ - par->mtrr_aper =mtrr_add (par->res_start, par->res_size, + par->mtrr_aper =mtrr_add (info->fix.smem_start, + info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 );MTRRs need power of two size, so how is this supposed to work?
Quoted 6 lines
As per
mtrr_add_page()[0] the base and size are just supposed to be in units of 4 KiB, although the practice is to use powers of 2 in *some* drivers this is not standardized and by no means recorded as a requirement. Obviously powers of 2 will work too and you'd end up neatly aligned as well.mtrr_add()will usemtrr_check()to verify the the same requirement. Furthermore, as per my commit log message:Quoted 2 lines
Whatever the code may or may not do, the x86 architecture uses power-of-two MTRR sizes. So I'm confused.
Quoted 6 lines
There should be no confusion, I simply did not know that *was* the requirement for x86, if that is the case we should add a check for that and perhaps generalize a helper that does the power of two helper changes, the cleanest I found was the vesafb driver solution.
Thoughts?
The vesafb solution is bad since you'll only end up covering only the first 4MB of the framebuffer instead of the almost 8MB you want. Which in practice will mean throwing away half the VRAM since you really don't want the massive performance hit from accessing it as UC. And that would mean giving up decent display resolutions as well :(
And the other option of trying to cover the remainder with multiple ever smaller MTRRs doesn't work either since you'll run out of MTRRs very quickly.
This is precisely why I used the hole method in atyfb in the first place.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
I don't really like the idea of any new mtrr code not supporting that use case, especially as these things tend to be present in older machines where PAT isn't an option.
According to the Intel SDM, volume 3, section 11.5.2.1, table 11-6, non-PAT CPUs that have a WC MTRR, PCD = 1, and PWT = 1 (aka UC) have an effective memory type of UC.
This is true but non-PAT systems that use just ioremap() will default to _PAGE_CACHE_MODE_UC_MINUS, not _PAGE_CACHE_MODE_UC, and _PAGE_CACHE_MODE_UC_MINUS on Linux has PCD = 1, PWT = 0. The list comes from:
uint16_t __cachemode2pte_tbl[_PAGE_CACHE_MODE_NUM] = {
[_PAGE_CACHE_MODE_WB ] = 0 | 0 ,
[_PAGE_CACHE_MODE_WC ] = _PAGE_PWT | 0 ,
[_PAGE_CACHE_MODE_UC_MINUS] = 0 | _PAGE_PCD,
[_PAGE_CACHE_MODE_UC ] = _PAGE_PWT | _PAGE_PCD,
[_PAGE_CACHE_MODE_WT ] = 0 | _PAGE_PCD,
[_PAGE_CACHE_MODE_WP ] = 0 | _PAGE_PCD, };
This can better be read here:
PAT
|PCD ||PWT ||| 000 WB _PAGE_CACHE_MODE_WB 001 WC _PAGE_CACHE_MODE_WC 010 UC- _PAGE_CACHE_MODE_UC_MINUS 011 UC _PAGE_CACHE_MODE_UC
On x86 ioremap() defaults to ioremap_nocache() and right now that uses _PAGE_CACHE_MODE_UC_MINUS not _PAGE_CACHE_MODE_UC. We have two cases to consider for non-PAT systems then:
a) Right now as ioremap() and ioremap_nocache() default to _PAGE_CACHE_MODE_UC_MINUS on x86. In this case using a WC MTRR seems to use PWT=0, PCD=1, and table table 11-6 on non-PAT systems seems to place this situation as "implementation defined" and not encouraged.
a) when commit de33c442e "x86 PAT: fix performance drop for glx, use UC minus for ioremap(), ioremap_nocache() and pci_mmap_page_range()" gets reverted and we use _PAGE_CACHE_MODE_UC by default. In this case on x86 for both ioremap() and ioremap_nocache() as they will both default to _PAGE_CACHE_MODE_UC we'll end up as you note with an effective memory type of UC.
If I've understood this correctly then neither of these situations are good and its just by chance that on some systems situation a) has lead to proper WC.
On a PAT system we have a bit different combinatorial results (based on Table 11-7):
a) Right now ioremap() and ioremap_nocache() defaulting to _PAGE_CACHE_MODE_UC_MINUS yields + MTRR WC = WC
b) When commit de33c442e gets reverted _PAGE_CACHE_MODE_UC + MTRR WC = UC
So to be clear right now atyfb should work fine on PAT systems with de33c442e in place, once reverted as-is right now we'd end up with UC effective memory type.
For both PAT and non-PAT systems when commit de33c442e gets reverted we'd end up with UC as the effective memory type for atyfb. Right now it shoud work on PAT systems and by chance its suspected to work on non-PAT systems. We want to phase MTRR though, specially to avoid all this insane combinatorial nightmware.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Hence my suggestion to add
ioremap_x86_ucand/orset_memory_x86_ucto punch a UC hole in an otherwise WC MTRR-covered region.
To be clear I think you mean then that ioremap_x86_uc() would help us avoid the jumps between combinatorial issues with MTRR on PAT / non-PAT systems before and after commit de33c442e gets reverted. So for instance if we had on the atyfb driver:
ioremap_x86_uc(PCI BAR)ioremap_wc(framebuffer)arch_phys_add_wc(PCI BAR)
On non-PAT systems on the MMIO region with PWT=1, PCD=1 we'd end up with UC. Sadly though since _PAGE_CACHE_WC on non-PAT has PWT=1, PCD=0, the WC MTRR that follows would mean we'd end up with another grey area (but similar to before as technically an effectivethe memory type of WC).
On PAT systems the above would not use MTRRs but we'd be counting on overlapping memory types -- its not clear if aliasing here is a problem.
Also Intel SDM, volume 3, section "11.11.4 Range Size and Alignment Requirement" describes that: "the minimum range size is 4 KiB, the base address must be on a 4 KiB boundary. For ranges greater than 4 KiB each range must be of length 2^n and its base address must be alinged on a 2^n boundary where n is a value equal or greatar then 12. The base-address alignment value cannot be less than its length. For example, an 8-KiB range cannot be aligned on a 4-KiB boundary. It must be aligned on at least an 8-KiB boundary"
So to answer my own question: indeed, our framebuffer base address must be aligned on a 2^n boundary, the size also has to be a power of 2. MTRR supports fixed range sizes and variable range sizes, in case of the MMIO that does not need to abide by the power of 2 rule as a fixed range size of 4 KiB could be used although upon review ouf our own implemetnation its unclear if that is what is used for 4 KiB sized MTRRs.
Hence my arch_phys_add_wc(PCI BAR) as above.
Quoted 3 lines
Quoted 3 lines
OK I think I get it now.
And I take it this would hopefully only be used for non-PAT systems?
Since we likely could care to use ioremap_x86_uc() on PAT systems as well we could make the effective for both PAT and non-PAT obviously then. Later when we get ioremap() to default to strong UC we could drop ioremap_x86_uc() as we'd only need it as transitory until then -- that is unless we want perhaps a strong UC ioremap primitive which is always following strong UC when available regardless of these default transitions.
The big issue I see here is simply the combinatorial issues, so I do think its best to annotate these corner cases well and avoid them.
Quoted 9 lines
Quoted 5 lines
Would there be a use case for PAT systems? I wonder if we can wrap this under some APIs to make it clean and hide this dirty thing behind the scenes, it seems a fragile and error prone and my hope would be that we won't need more specialization in this area for PAT systems.
One potential complication is kernel vs. userspace mmap. MTRR applies to the physical address, but PAT applies to the virtual address, so with the WC MTRR you get WC for userspace "for free" as well.
What is the performance impact of having the conversion being done by the kernel? Has anyone done measurements? If significant can't the subsystem mmap() cache the phys address for PAT? Shouldn't the TLB take care of those considerations for us? If this is generally desirable shouldn't we just generalize the cache for devices for O(1) access through a generic API?
Can the difference, other than a possible performance hit, implicate a userspace visible change?
If the performance / userspace effect is neglibable then I'd expect the gains from cleaner code / APIs to outweight the cons. After all the goal is to streamline PAT when possible here.
Quoted 3 lines
Also the
userspace mmaps request will have the length ofsmem_len(at most), so it won't be the nice power of two in that case.
Does that length change implicate a userspace visible change?
Quoted 2 lines
Also on PAT systems w/o a BIOS provided WC MTRR, the fbdev mmap seems to be total crap at the moment. IIRC I have a patch to fix things a bit...
Isn't that becuase of the lack of the ioremap_wc()'s? You seem to be alternatively doing this with pgprot_writecombine(), more on this strategy below though.
Quoted 44 lines
From
4e6d70d223f35953c8a11a58cf3376a8a001fa4fMon Sep 17 00:00:00 2001
From: Ville Syrjala <[email protected]>
Date: Fri, 15 Apr 2011 04:02:43 +0300
Subject: [PATCH] fb: writecombine fb--- drivers/video/fbdev/core/fbmem.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)drivers/video/fbdev/core/fbmem.c +11
-1@@ -1396,6 +1396,7 @@ fb_mmap(struct file *file, struct vm_area_struct * vma)unsigned long mmio_pgoff;unsigned long start;u32 len; +bool mmio = false;if (!info)return -ENODEV ;@@ -1426,11 +1427,20 @@ fb_mmap(struct file *file, struct vm_area_struct * vma) vma->vm_pgoff -= mmio_pgoff; start = info->fix.mmio_start; len = info->fix.mmio_len; + mmio = true; }mutex_unlock (&info->mm_lock); +if (!mmio) { + vma->vm_page_prot =vm_get_page_prot (vma->vm_flags); + vma->vm_page_prot =pgprot_writecombine (vma->vm_page_prot); + +if (!vm_iomap_memory (vma, start, len)) +return 0 ; + } + vma->vm_page_prot =vm_get_page_prot (vma->vm_flags); -fb_pgprotect (file, vma, start); + vma->vm_page_prot =pgprot_noncached (vma->vm_page_prot);return vm_iomap_memory (vma, start, len); }
Quoted 1 line
Perhaps it's time I tried to send that upstream properly :P
Lets assume drivers all have ioremap_wc() on the framebuffer, would the the above not be needed then (disregarding the corner cases such as atyfb)?
If your goal is to generalize a place to make framebuffer WC instead of doing that at mmap() why not do it at register_framebuffer() time and do it only once? I suspect all this might also be easier to do and generalize after this series.
So as we can see from this series there are tons of drivers that can safely be moved to use ioremap_wc() already, provided there are no regressions with the simple ioremap_wc() / arch_phys_wc_add() switch. There are only a few corner cases to address after that. Addressing both of these *first* would simplify the code and gramatically make it a bit more consistent while trying to avoid a generalized regression. I believe a generalized solution is definitely in order but we also should first address the corner cases.
So how about we:
a) convert all drivers over that are safe to convert to ioremap_wc() / arch_phys_add_wc()
b) address all corner cases and try to avoid further combinatorial issues
c) after a while push for reverting de33c442e
d) generalize a solution / for framebuffer
Ideally as I mentioned in the other thread with Bjorn we could even have the WC be done further below for us but it was very unclear if we could accomplish this due the definition of the PCI flags, the way we'd use it and the way they could be integrated on hardware by manufacturers. I think generalizing things under the frambuffer code would be good intermediate step but I think we need to phase this in in light of the corner cases, combinatorial issues with PAT / non-PAT and eventual reverting goals of commit de33c442e in order to generalize strong UC.
Luis
Re: [PATCH v1 09/47] vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around
Quoted 188 lines · Luis R. Rodriguez
Quoted 56 lines · Ville Syrjälä
Quoted 55 lines · Luis R. Rodriguez
Quoted 54 lines · Andy Lutomirski
Quoted 53 lines · Ville Syrjälä
Quoted 32 lines · Luis R. Rodriguez
Quoted 28 lines · Andy Lutomirski
Quoted 20 lines · Luis R. Rodriguez
Quoted 7 lines · Ville Syrjälä
Quoted 6 lines · Luis R. Rodriguez
drivers/video/fbdev/aty/atyfb_base.c +0
-0@@ -2630,21 +2630,10 @@ static int aty_init(struct fb_info *info)Quoted 11 lines
drivers/video/fbdev/aty/atyfb_base.c static int aty_init(struct fb_info *info) · line 2636
Quoted 9 lines
drivers/video/fbdev/aty/atyfb_base.c +2
-3#ifdef CONFIG_MTRR par->mtrr_aper =-1 ; - par->mtrr_reg =-1 ;if (!nomtrr) { -/* Cover the whole resource. */ - par->mtrr_aper =mtrr_add (par->res_start, par->res_size, + par->mtrr_aper =mtrr_add (info->fix.smem_start, + info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 );MTRRs need power of two size, so how is this supposed to work?
Quoted 6 lines
As per
mtrr_add_page()[0] the base and size are just supposed to be in units of 4 KiB, although the practice is to use powers of 2 in *some* drivers this is not standardized and by no means recorded as a requirement. Obviously powers of 2 will work too and you'd end up neatly aligned as well.mtrr_add()will usemtrr_check()to verify the the same requirement. Furthermore, as per my commit log message:Quoted 2 lines
Whatever the code may or may not do, the x86 architecture uses power-of-two MTRR sizes. So I'm confused.
Quoted 6 lines
There should be no confusion, I simply did not know that *was* the requirement for x86, if that is the case we should add a check for that and perhaps generalize a helper that does the power of two helper changes, the cleanest I found was the vesafb driver solution.
Thoughts?
The vesafb solution is bad since you'll only end up covering only the first 4MB of the framebuffer instead of the almost 8MB you want. Which in practice will mean throwing away half the VRAM since you really don't want the massive performance hit from accessing it as UC. And that would mean giving up decent display resolutions as well :(
And the other option of trying to cover the remainder with multiple ever smaller MTRRs doesn't work either since you'll run out of MTRRs very quickly.
This is precisely why I used the hole method in atyfb in the first place.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
I don't really like the idea of any new mtrr code not supporting that use case, especially as these things tend to be present in older machines where PAT isn't an option.
According to the Intel SDM, volume 3, section 11.5.2.1, table 11-6, non-PAT CPUs that have a WC MTRR, PCD = 1, and PWT = 1 (aka UC) have an effective memory type of UC.
This is true but non-PAT systems that use just
ioremap()will default to_PAGE_CACHE_MODE_UC_MINUS, not_PAGE_CACHE_MODE_UC, and_PAGE_CACHE_MODE_UC_MINUSon Linux has PCD = 1, PWT = 0. The list comes from:
uint16_t__cachemode2pte_tbl[_PAGE_CACHE_MODE_NUM] = {[_PAGE_CACHE_MODE_WB ] = 0 | 0 , [_PAGE_CACHE_MODE_WC ] = _PAGE_PWT | 0 , [_PAGE_CACHE_MODE_UC_MINUS] = 0 | _PAGE_PCD, [_PAGE_CACHE_MODE_UC ] = _PAGE_PWT | _PAGE_PCD, [_PAGE_CACHE_MODE_WT ] = 0 | _PAGE_PCD, [_PAGE_CACHE_MODE_WP ] = 0 | _PAGE_PCD,};
This can better be read here:
PAT
|PCD ||PWT ||| 000 WB _PAGE_CACHE_MODE_WB 001 WC _PAGE_CACHE_MODE_WC 010 UC- _PAGE_CACHE_MODE_UC_MINUS 011 UC _PAGE_CACHE_MODE_UCOn x86
ioremap()defaults toioremap_nocache()and right now that uses_PAGE_CACHE_MODE_UC_MINUSnot_PAGE_CACHE_MODE_UC. We have two cases to consider for non-PAT systems then:a) Right now as
ioremap()andioremap_nocache()default to_PAGE_CACHE_MODE_UC_MINUSon x86. In this case using a WC MTRR seems to use PWT=0, PCD=1, and table table 11-6 on non-PAT systems seems to place this situation as "implementation defined" and not encouraged.a) when commit
de33c442e"x86 PAT: fix performance drop for glx, use UC minus forioremap(),ioremap_nocache()andpci_mmap_page_range()" gets reverted and we use_PAGE_CACHE_MODE_UCby default. In this case on x86 for bothioremap()andioremap_nocache()as they will both default to_PAGE_CACHE_MODE_UCwe'll end up as you note with an effective memory type of UC.If I've understood this correctly then neither of these situations are good and its just by chance that on some systems situation a) has lead to proper WC.
On a PAT system we have a bit different combinatorial results (based on Table 11-7):
a) Right now
ioremap()andioremap_nocache()defaulting to_PAGE_CACHE_MODE_UC_MINUSyields + MTRR WC = WCb) When commit
de33c442egets reverted_PAGE_CACHE_MODE_UC+ MTRR WC = UCSo to be clear right now atyfb should work fine on PAT systems with
de33c442ein place, once reverted as-is right now we'd end up with UC effective memory type.For both PAT and non-PAT systems when commit
de33c442egets reverted we'd end up with UC as the effective memory type for atyfb. Right now it shoud work on PAT systems and by chance its suspected to work on non-PAT systems. We want to phase MTRR though, specially to avoid all this insane combinatorial nightmware.Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Hence my suggestion to add
ioremap_x86_ucand/orset_memory_x86_ucto punch a UC hole in an otherwise WC MTRR-covered region.To be clear I think you mean then that
ioremap_x86_uc()would help us avoid the jumps between combinatorial issues with MTRR on PAT / non-PAT systems before and after commitde33c442egets reverted. So for instance if we had on the atyfb driver:
ioremap_x86_uc(PCI BAR)ioremap_wc(framebuffer)arch_phys_add_wc(PCI BAR)On non-PAT systems on the MMIO region with PWT=1, PCD=1 we'd end up with UC. Sadly though since
_PAGE_CACHE_WCon non-PAT has PWT=1, PCD=0, the WC MTRR that follows would mean we'd end up with another grey area (but similar to before as technically an effectivethe memory type of WC).On PAT systems the above would not use MTRRs but we'd be counting on overlapping memory types -- its not clear if aliasing here is a problem.
Also Intel SDM, volume 3, section "11.11.4 Range Size and Alignment Requirement" describes that: "the minimum range size is 4 KiB, the base address must be on a 4 KiB boundary. For ranges greater than 4 KiB each range must be of length 2^n and its base address must be alinged on a 2^n boundary where n is a value equal or greatar then 12. The base-address alignment value cannot be less than its length. For example, an 8-KiB range cannot be aligned on a 4-KiB boundary. It must be aligned on at least an 8-KiB boundary"
So to answer my own question: indeed, our framebuffer base address must be aligned on a 2^n boundary, the size also has to be a power of 2. MTRR supports fixed range sizes and variable range sizes, in case of the MMIO that does not need to abide by the power of 2 rule as a fixed range size of 4 KiB could be used although upon review ouf our own implemetnation its unclear if that is what is used for 4 KiB sized MTRRs.
Hence my
arch_phys_add_wc(PCI BAR)as above.Quoted 3 lines
Quoted 3 lines
OK I think I get it now.
And I take it this would hopefully only be used for non-PAT systems?
Since we likely could care to use
ioremap_x86_uc()on PAT systems as well we could make the effective for both PAT and non-PAT obviously then. Later when we getioremap()to default to strong UC we could dropioremap_x86_uc()as we'd only need it as transitory until then -- that is unless we want perhaps a strong UC ioremap primitive which is always following strong UC when available regardless of these default transitions.The big issue I see here is simply the combinatorial issues, so I do think its best to annotate these corner cases well and avoid them.
Quoted 9 lines
Quoted 5 lines
Would there be a use case for PAT systems? I wonder if we can wrap this under some APIs to make it clean and hide this dirty thing behind the scenes, it seems a fragile and error prone and my hope would be that we won't need more specialization in this area for PAT systems.
One potential complication is kernel vs. userspace mmap. MTRR applies to the physical address, but PAT applies to the virtual address, so with the WC MTRR you get WC for userspace "for free" as well.
Quoted 5 lines
What is the performance impact of having the conversion being done by the kernel? Has anyone done measurements? If significant can't the subsystem
mmap()cache the phys address for PAT? Shouldn't the TLB take care of those considerations for us? If this is generally desirable shouldn't we just generalize the cache for devices for O(1) access through a generic API?
We're pretty much required to keep the PTE memory types consistent for aliasses of the same page. I think that the x86 pageattr code is supposed to take care of this. IOW, if everything is working right, then the supposedly uncached mmap should either fail, be promoted to WC, or cause the existing WC map to degrade to UC. The code is really overcomplicated right now.
--Andy
Re: [PATCH v1 09/47] vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around
Quoted 189 lines · Andy Lutomirski
Quoted 188 lines · Luis R. Rodriguez
Quoted 56 lines · Ville Syrjälä
Quoted 55 lines · Luis R. Rodriguez
Quoted 54 lines · Andy Lutomirski
Quoted 53 lines · Ville Syrjälä
Quoted 32 lines · Luis R. Rodriguez
Quoted 28 lines · Andy Lutomirski
Quoted 20 lines · Luis R. Rodriguez
Quoted 7 lines · Ville Syrjälä
Quoted 6 lines · Luis R. Rodriguez
drivers/video/fbdev/aty/atyfb_base.c +0
-0@@ -2630,21 +2630,10 @@ static int aty_init(struct fb_info *info)Quoted 11 lines
drivers/video/fbdev/aty/atyfb_base.c static int aty_init(struct fb_info *info) · line 2636
Quoted 9 lines
drivers/video/fbdev/aty/atyfb_base.c +2
-3#ifdef CONFIG_MTRR par->mtrr_aper =-1 ; - par->mtrr_reg =-1 ;if (!nomtrr) { -/* Cover the whole resource. */ - par->mtrr_aper =mtrr_add (par->res_start, par->res_size, + par->mtrr_aper =mtrr_add (info->fix.smem_start, + info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 );MTRRs need power of two size, so how is this supposed to work?
Quoted 6 lines
As per
mtrr_add_page()[0] the base and size are just supposed to be in units of 4 KiB, although the practice is to use powers of 2 in *some* drivers this is not standardized and by no means recorded as a requirement. Obviously powers of 2 will work too and you'd end up neatly aligned as well.mtrr_add()will usemtrr_check()to verify the the same requirement. Furthermore, as per my commit log message:Quoted 2 lines
Whatever the code may or may not do, the x86 architecture uses power-of-two MTRR sizes. So I'm confused.
Quoted 6 lines
There should be no confusion, I simply did not know that *was* the requirement for x86, if that is the case we should add a check for that and perhaps generalize a helper that does the power of two helper changes, the cleanest I found was the vesafb driver solution.
Thoughts?
The vesafb solution is bad since you'll only end up covering only the first 4MB of the framebuffer instead of the almost 8MB you want. Which in practice will mean throwing away half the VRAM since you really don't want the massive performance hit from accessing it as UC. And that would mean giving up decent display resolutions as well :(
And the other option of trying to cover the remainder with multiple ever smaller MTRRs doesn't work either since you'll run out of MTRRs very quickly.
This is precisely why I used the hole method in atyfb in the first place.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
I don't really like the idea of any new mtrr code not supporting that use case, especially as these things tend to be present in older machines where PAT isn't an option.
According to the Intel SDM, volume 3, section 11.5.2.1, table 11-6, non-PAT CPUs that have a WC MTRR, PCD = 1, and PWT = 1 (aka UC) have an effective memory type of UC.
This is true but non-PAT systems that use just
ioremap()will default to_PAGE_CACHE_MODE_UC_MINUS, not_PAGE_CACHE_MODE_UC, and_PAGE_CACHE_MODE_UC_MINUSon Linux has PCD = 1, PWT = 0. The list comes from:
uint16_t__cachemode2pte_tbl[_PAGE_CACHE_MODE_NUM] = {[_PAGE_CACHE_MODE_WB ] = 0 | 0 , [_PAGE_CACHE_MODE_WC ] = _PAGE_PWT | 0 , [_PAGE_CACHE_MODE_UC_MINUS] = 0 | _PAGE_PCD, [_PAGE_CACHE_MODE_UC ] = _PAGE_PWT | _PAGE_PCD, [_PAGE_CACHE_MODE_WT ] = 0 | _PAGE_PCD, [_PAGE_CACHE_MODE_WP ] = 0 | _PAGE_PCD,};
This can better be read here:
PAT
|PCD ||PWT ||| 000 WB _PAGE_CACHE_MODE_WB 001 WC _PAGE_CACHE_MODE_WC 010 UC- _PAGE_CACHE_MODE_UC_MINUS 011 UC _PAGE_CACHE_MODE_UCOn x86
ioremap()defaults toioremap_nocache()and right now that uses_PAGE_CACHE_MODE_UC_MINUSnot_PAGE_CACHE_MODE_UC. We have two cases to consider for non-PAT systems then:a) Right now as
ioremap()andioremap_nocache()default to_PAGE_CACHE_MODE_UC_MINUSon x86. In this case using a WC MTRR seems to use PWT=0, PCD=1, and table table 11-6 on non-PAT systems seems to place this situation as "implementation defined" and not encouraged.a) when commit
de33c442e"x86 PAT: fix performance drop for glx, use UC minus forioremap(),ioremap_nocache()andpci_mmap_page_range()" gets reverted and we use_PAGE_CACHE_MODE_UCby default. In this case on x86 for bothioremap()andioremap_nocache()as they will both default to_PAGE_CACHE_MODE_UCwe'll end up as you note with an effective memory type of UC.If I've understood this correctly then neither of these situations are good and its just by chance that on some systems situation a) has lead to proper WC.
On a PAT system we have a bit different combinatorial results (based on Table 11-7):
a) Right now
ioremap()andioremap_nocache()defaulting to_PAGE_CACHE_MODE_UC_MINUSyields + MTRR WC = WCb) When commit
de33c442egets reverted_PAGE_CACHE_MODE_UC+ MTRR WC = UCSo to be clear right now atyfb should work fine on PAT systems with
de33c442ein place, once reverted as-is right now we'd end up with UC effective memory type.For both PAT and non-PAT systems when commit
de33c442egets reverted we'd end up with UC as the effective memory type for atyfb. Right now it shoud work on PAT systems and by chance its suspected to work on non-PAT systems. We want to phase MTRR though, specially to avoid all this insane combinatorial nightmware.Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Hence my suggestion to add
ioremap_x86_ucand/orset_memory_x86_ucto punch a UC hole in an otherwise WC MTRR-covered region.To be clear I think you mean then that
ioremap_x86_uc()would help us avoid the jumps between combinatorial issues with MTRR on PAT / non-PAT systems before and after commitde33c442egets reverted. So for instance if we had on the atyfb driver:
ioremap_x86_uc(PCI BAR)ioremap_wc(framebuffer)arch_phys_add_wc(PCI BAR)On non-PAT systems on the MMIO region with PWT=1, PCD=1 we'd end up with UC. Sadly though since
_PAGE_CACHE_WCon non-PAT has PWT=1, PCD=0, the WC MTRR that follows would mean we'd end up with another grey area (but similar to before as technically an effectivethe memory type of WC).On PAT systems the above would not use MTRRs but we'd be counting on overlapping memory types -- its not clear if aliasing here is a problem.
Also Intel SDM, volume 3, section "11.11.4 Range Size and Alignment Requirement" describes that: "the minimum range size is 4 KiB, the base address must be on a 4 KiB boundary. For ranges greater than 4 KiB each range must be of length 2^n and its base address must be alinged on a 2^n boundary where n is a value equal or greatar then 12. The base-address alignment value cannot be less than its length. For example, an 8-KiB range cannot be aligned on a 4-KiB boundary. It must be aligned on at least an 8-KiB boundary"
So to answer my own question: indeed, our framebuffer base address must be aligned on a 2^n boundary, the size also has to be a power of 2. MTRR supports fixed range sizes and variable range sizes, in case of the MMIO that does not need to abide by the power of 2 rule as a fixed range size of 4 KiB could be used although upon review ouf our own implemetnation its unclear if that is what is used for 4 KiB sized MTRRs.
Hence my
arch_phys_add_wc(PCI BAR)as above.Quoted 3 lines
Quoted 3 lines
OK I think I get it now.
And I take it this would hopefully only be used for non-PAT systems?
Since we likely could care to use
ioremap_x86_uc()on PAT systems as well we could make the effective for both PAT and non-PAT obviously then. Later when we getioremap()to default to strong UC we could dropioremap_x86_uc()as we'd only need it as transitory until then -- that is unless we want perhaps a strong UC ioremap primitive which is always following strong UC when available regardless of these default transitions.The big issue I see here is simply the combinatorial issues, so I do think its best to annotate these corner cases well and avoid them.
Quoted 9 lines
Quoted 5 lines
Would there be a use case for PAT systems? I wonder if we can wrap this under some APIs to make it clean and hide this dirty thing behind the scenes, it seems a fragile and error prone and my hope would be that we won't need more specialization in this area for PAT systems.
One potential complication is kernel vs. userspace mmap. MTRR applies to the physical address, but PAT applies to the virtual address, so with the WC MTRR you get WC for userspace "for free" as well.
Quoted 8 lines
Quoted 5 lines
What is the performance impact of having the conversion being done by the kernel? Has anyone done measurements? If significant can't the subsystem
mmap()cache the phys address for PAT? Shouldn't the TLB take care of those considerations for us? If this is generally desirable shouldn't we just generalize the cache for devices for O(1) access through a generic API?We're pretty much required to keep the PTE memory types consistent for aliasses of the same page.
Hrm, OK so overlapping ioremap() calls should be frowed upon?
I think its important to clarify the few different scenarios we have for atyfb, both for today when uc- is default and when uc becomes the default. I'll also clarify what this series originally tried to do but the issues that size requirements prohibit us to do along with combinatorial issues that would also be present when and if uc becomes default. Finally I'll clarify what I am thinking we should do in light of all this.
_______________________________________________________________________
| | | |_______________________________________________________|_____________|
\______________________________________________________/ \____________/
Framebuffer (8 MiB) MMIO (4 KiB)
Currently we have:
Page_cache_mode's _PAGE_CACHE_MODE_ is removed below for brevity. The atyfb PCI BAR is condensed to:
Frambuffer,MMIO
Keeping in mind:
Intel SDM, volume 3, section 11.5.2.1, table 11-6 (NonPAT combinatorial)
Intel SDM, volume 3, section 11.5.2.2, table 11-7 (PAT combinatorial)
Linux PCD, PWT bits:
PAT
|PCD ||PWT ||| 000 WB _PAGE_CACHE_MODE_WB 001 WC _PAGE_CACHE_MODE_WC 010 UC- _PAGE_CACHE_MODE_UC_MINUS 011 UC _PAGE_CACHE_MODE_UC
(*) below denotes grey area as per SDM, implementation-defined (%) below denotes not posislbe due to size / base requirements of MTRRs (+) below denotes combinatorial issue
Non-PAT systems use PCD, PWT values, their respective bit settings for these are given although internally we use _PAGE_CACHE_MODE* on the ioremap* calls for both non-PAT and PAT. For instance _PAGE_CACHE_MODE_UC_MINUS is 10 for PCD=1, PWT=0.
Today we have:
--------------------------------------------------------------------
Calls | Page_cache_mode | Effective memtype |
------------------------|---------------------|---------------------
| Non-PAT | PAT | Non-PAT | PAT |
--------------------------------------------------------------------
ioremap(MMIO) | xxx, 10 | xxx, UC- | xxx, UC | xxx, UC- |
ioremap(PCI BAR) | 10 , 10 | UC-, UC- | UC, UC | UC-, UC- | MTRR WC(PCI BAR) | 10 , 10 | UC-, UC- | WC*, WC* | WC , WC |
MTRR UC(MMIO) | 10 , 10 | UC-, UC- | WC*, UC | WC , UC |
--------------------------------------------------------------------
If today we revert commit de33c442e and UC becomes default this would run into the combinatorial issue:
--------------------------------------------------------------------
Calls | Page_cache_mode | Effective memtype |
------------------------|---------------------|---------------------
| Non-PAT | PAT | Non-PAT | PAT |
--------------------------------------------------------------------
ioremap(MMIO) | xxx, 11 | xxx, UC | xxx, UC | xxx, UC |
ioremap(PCI BAR) | 11 , 11 | UC , UC | UC, UC | UC , UC | MTRR WC(PCI BAR) | 11 , 11 | UC, UC | UC+, UC+ | UC+, UC+ |
MTRR UC(MMIO) | 11 , 11 | UC, UC | UC+, UC | UC+, UC |
--------------------------------------------------------------------
We ideally would like to do the following but can't because of the restriction of having to use powers of two for both size and base address for MTRRs, we'd have two steps, one with mtrr_add, and another with arch_phys_add_wc(). This is what this series was proposing for atyfb.
With mtrr_add():
--------------------------------------------------------------------
Calls | Page_cache_mode | Effective memtype |
------------------------|---------------------|---------------------
| Non-PAT | PAT | Non-PAT | PAT |
--------------------------------------------------------------------ioremap_nocache(MMIO) | xxx, 10 | xxx, UC- | xxx, UC | xxx, UC- |ioremap_wc(fb) | 01 , 10 | WC , UC- | UC , UC | WC , UC- |
MTRR WC(fb) | 01 , 10 | UC-, WC | WC%*,UC | WC%, UC- |
--------------------------------------------------------------------
Then we'd change this to arch_phys_add_wc():
--------------------------------------------------------------------
Calls | Page_cache_mode | Effective memtype |
------------------------|---------------------|---------------------
| Non-PAT | PAT | Non-PAT | PAT |
--------------------------------------------------------------------ioremap_nocache(MMIO) | xxx, 10 | xxx, UC- | xxx, UC | UC-, UC- |ioremap_wc(fb) | 01 , 10 | WC , UC- | UC , UC | WC , UC- |arch_phys_add_wc(fb) | 01 , 10 | WC , WC | WC%*,UC | WC , UC- |
--------------------------------------------------------------------
With the above code as well we have to consider the issues if we revert commit de33c442e and UC becomes default, we'd run into then both the size issue and also a grey area:
With mtrr_add():
--------------------------------------------------------------------
Calls | Page_cache_mode | Effective memtype |
------------------------|---------------------|---------------------
| Non-PAT | PAT | Non-PAT | PAT |
--------------------------------------------------------------------ioremap_nocache(MMIO) | xxx, 11 | xxx, UC | xxx, UC | xxx, UC |ioremap_wc(fb) | 01 , 11 | WC , UC | UC , UC | WC , UC |
MTRR WC(fb) | 01 , 11 | WC , UC | WC%* ,UC | WC , UC |
--------------------------------------------------------------------
Then with arch_phys_add_wc():
--------------------------------------------------------------------
Calls | Page_cache_mode | Effective memtype |
------------------------|---------------------|---------------------
| Non-PAT | PAT | Non-PAT | PAT |
--------------------------------------------------------------------ioremap_nocache(MMIO) | xxx, 11 | xxx, UC | xxx, UC | xxx, UC |ioremap_wc(fb) | 01 , 11 | WC , UC | UC , UC | WC , UC |arch_phys_add_wc(fb) | 01 , 11 | WC , UC | WC%*,UC | WC , UC |
--------------------------------------------------------------------
So what we *could* do then if we add ioremap_uc() (use strong UC always), then override the framebuffer area with wc, and finally use MTRR on the full PCI BAR, relying on that strong UC won't let the MTRR override the earlier UC on the MMIO area. There is a grey area here for non-PAT systemes but that is also the case as-is today.
--------------------------------------------------------------------
Calls | Page_cache_mode | Effective memtype |
------------------------|---------------------|---------------------
| Non-PAT | PAT | Non-PAT | PAT |
--------------------------------------------------------------------ioremap_uc(PCI BAR) | 11 , 11 | UC , UC | UC , UC | UC , UC |ioremap_wc(fb) | 01 , 11 | WC , UC | UC , UC | WC , UC |MTRR_WC(PCI BAR) | 01 , 11 | WC , UC | WC*, UC | WC , UC |
--------------------------------------------------------------------
Finally with the arch_phys_add_wc() we'd end up with:
--------------------------------------------------------------------
Calls | Page_cache_mode | Effective memtype |
------------------------|---------------------|---------------------
| Non-PAT | PAT | Non-PAT | PAT |
--------------------------------------------------------------------ioremap_uc(PCI BAR) | 11 , 11 | UC , UC | UC , UC | UC , UC |ioremap_wc(fb) | 01 , 11 | WC , UC | UC , UC | WC , UC |
arch_phys_add_wc(PCIBAR)| 01 , 11 | WC , UC | WC*, UC | WC , UC |
--------------------------------------------------------------------
In this case a revert of de33c442e won't have any effect as the driver was already well prepared for it by using ioremap_uc().
Quoted 5 lines
I think that the x86 pageattr code is
supposed to take care of this. IOW, if everything is working right, then the supposedly uncached mmap should either fail, be promoted to WC, or cause the existing WC map to degrade to UC. The code is really overcomplicated right now.
Yeah aliasing things are not clear for the above picture for me, someone who is knee-deep in this can likely confirm of any issues with the above pictures. But most importrantly if we believe however that the last two sets above don't have any issues then I think we can move forward. Since we only have a few drivers that need special handling I think it makes sense to treat them specially and document this strategy for the "hole" work around.
Thoughts?
Luis
Re: [PATCH v1 09/47] vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around
Quoted 370 lines · Luis R. Rodriguez
Quoted 189 lines · Andy Lutomirski
Quoted 188 lines · Luis R. Rodriguez
Quoted 56 lines · Ville Syrjälä
Quoted 55 lines · Luis R. Rodriguez
Quoted 54 lines · Andy Lutomirski
Quoted 53 lines · Ville Syrjälä
Quoted 32 lines · Luis R. Rodriguez
Quoted 28 lines · Andy Lutomirski
Quoted 20 lines · Luis R. Rodriguez
Quoted 7 lines · Ville Syrjälä
Quoted 6 lines · Luis R. Rodriguez
drivers/video/fbdev/aty/atyfb_base.c +0
-0@@ -2630,21 +2630,10 @@ static int aty_init(struct fb_info *info)Quoted 11 lines
drivers/video/fbdev/aty/atyfb_base.c static int aty_init(struct fb_info *info) · line 2636
Quoted 9 lines
drivers/video/fbdev/aty/atyfb_base.c +2
-3#ifdef CONFIG_MTRR par->mtrr_aper =-1 ; - par->mtrr_reg =-1 ;if (!nomtrr) { -/* Cover the whole resource. */ - par->mtrr_aper =mtrr_add (par->res_start, par->res_size, + par->mtrr_aper =mtrr_add (info->fix.smem_start, + info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 );MTRRs need power of two size, so how is this supposed to work?
Quoted 6 lines
As per
mtrr_add_page()[0] the base and size are just supposed to be in units of 4 KiB, although the practice is to use powers of 2 in *some* drivers this is not standardized and by no means recorded as a requirement. Obviously powers of 2 will work too and you'd end up neatly aligned as well.mtrr_add()will usemtrr_check()to verify the the same requirement. Furthermore, as per my commit log message:Quoted 2 lines
Whatever the code may or may not do, the x86 architecture uses power-of-two MTRR sizes. So I'm confused.
Quoted 6 lines
There should be no confusion, I simply did not know that *was* the requirement for x86, if that is the case we should add a check for that and perhaps generalize a helper that does the power of two helper changes, the cleanest I found was the vesafb driver solution.
Thoughts?
The vesafb solution is bad since you'll only end up covering only the first 4MB of the framebuffer instead of the almost 8MB you want. Which in practice will mean throwing away half the VRAM since you really don't want the massive performance hit from accessing it as UC. And that would mean giving up decent display resolutions as well :(
And the other option of trying to cover the remainder with multiple ever smaller MTRRs doesn't work either since you'll run out of MTRRs very quickly.
This is precisely why I used the hole method in atyfb in the first place.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
I don't really like the idea of any new mtrr code not supporting that use case, especially as these things tend to be present in older machines where PAT isn't an option.
According to the Intel SDM, volume 3, section 11.5.2.1, table 11-6, non-PAT CPUs that have a WC MTRR, PCD = 1, and PWT = 1 (aka UC) have an effective memory type of UC.
This is true but non-PAT systems that use just
ioremap()will default to_PAGE_CACHE_MODE_UC_MINUS, not_PAGE_CACHE_MODE_UC, and_PAGE_CACHE_MODE_UC_MINUSon Linux has PCD = 1, PWT = 0. The list comes from:
uint16_t__cachemode2pte_tbl[_PAGE_CACHE_MODE_NUM] = {[_PAGE_CACHE_MODE_WB ] = 0 | 0 , [_PAGE_CACHE_MODE_WC ] = _PAGE_PWT | 0 , [_PAGE_CACHE_MODE_UC_MINUS] = 0 | _PAGE_PCD, [_PAGE_CACHE_MODE_UC ] = _PAGE_PWT | _PAGE_PCD, [_PAGE_CACHE_MODE_WT ] = 0 | _PAGE_PCD, [_PAGE_CACHE_MODE_WP ] = 0 | _PAGE_PCD,};
This can better be read here:
PAT
|PCD ||PWT ||| 000 WB _PAGE_CACHE_MODE_WB 001 WC _PAGE_CACHE_MODE_WC 010 UC- _PAGE_CACHE_MODE_UC_MINUS 011 UC _PAGE_CACHE_MODE_UCOn x86
ioremap()defaults toioremap_nocache()and right now that uses_PAGE_CACHE_MODE_UC_MINUSnot_PAGE_CACHE_MODE_UC. We have two cases to consider for non-PAT systems then:a) Right now as
ioremap()andioremap_nocache()default to_PAGE_CACHE_MODE_UC_MINUSon x86. In this case using a WC MTRR seems to use PWT=0, PCD=1, and table table 11-6 on non-PAT systems seems to place this situation as "implementation defined" and not encouraged.a) when commit
de33c442e"x86 PAT: fix performance drop for glx, use UC minus forioremap(),ioremap_nocache()andpci_mmap_page_range()" gets reverted and we use_PAGE_CACHE_MODE_UCby default. In this case on x86 for bothioremap()andioremap_nocache()as they will both default to_PAGE_CACHE_MODE_UCwe'll end up as you note with an effective memory type of UC.If I've understood this correctly then neither of these situations are good and its just by chance that on some systems situation a) has lead to proper WC.
On a PAT system we have a bit different combinatorial results (based on Table 11-7):
a) Right now
ioremap()andioremap_nocache()defaulting to_PAGE_CACHE_MODE_UC_MINUSyields + MTRR WC = WCb) When commit
de33c442egets reverted_PAGE_CACHE_MODE_UC+ MTRR WC = UCSo to be clear right now atyfb should work fine on PAT systems with
de33c442ein place, once reverted as-is right now we'd end up with UC effective memory type.For both PAT and non-PAT systems when commit
de33c442egets reverted we'd end up with UC as the effective memory type for atyfb. Right now it shoud work on PAT systems and by chance its suspected to work on non-PAT systems. We want to phase MTRR though, specially to avoid all this insane combinatorial nightmware.Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Hence my suggestion to add
ioremap_x86_ucand/orset_memory_x86_ucto punch a UC hole in an otherwise WC MTRR-covered region.To be clear I think you mean then that
ioremap_x86_uc()would help us avoid the jumps between combinatorial issues with MTRR on PAT / non-PAT systems before and after commitde33c442egets reverted. So for instance if we had on the atyfb driver:
ioremap_x86_uc(PCI BAR)ioremap_wc(framebuffer)arch_phys_add_wc(PCI BAR)On non-PAT systems on the MMIO region with PWT=1, PCD=1 we'd end up with UC. Sadly though since
_PAGE_CACHE_WCon non-PAT has PWT=1, PCD=0, the WC MTRR that follows would mean we'd end up with another grey area (but similar to before as technically an effectivethe memory type of WC).On PAT systems the above would not use MTRRs but we'd be counting on overlapping memory types -- its not clear if aliasing here is a problem.
Also Intel SDM, volume 3, section "11.11.4 Range Size and Alignment Requirement" describes that: "the minimum range size is 4 KiB, the base address must be on a 4 KiB boundary. For ranges greater than 4 KiB each range must be of length 2^n and its base address must be alinged on a 2^n boundary where n is a value equal or greatar then 12. The base-address alignment value cannot be less than its length. For example, an 8-KiB range cannot be aligned on a 4-KiB boundary. It must be aligned on at least an 8-KiB boundary"
So to answer my own question: indeed, our framebuffer base address must be aligned on a 2^n boundary, the size also has to be a power of 2. MTRR supports fixed range sizes and variable range sizes, in case of the MMIO that does not need to abide by the power of 2 rule as a fixed range size of 4 KiB could be used although upon review ouf our own implemetnation its unclear if that is what is used for 4 KiB sized MTRRs.
Hence my
arch_phys_add_wc(PCI BAR)as above.Quoted 3 lines
Quoted 3 lines
OK I think I get it now.
And I take it this would hopefully only be used for non-PAT systems?
Since we likely could care to use
ioremap_x86_uc()on PAT systems as well we could make the effective for both PAT and non-PAT obviously then. Later when we getioremap()to default to strong UC we could dropioremap_x86_uc()as we'd only need it as transitory until then -- that is unless we want perhaps a strong UC ioremap primitive which is always following strong UC when available regardless of these default transitions.The big issue I see here is simply the combinatorial issues, so I do think its best to annotate these corner cases well and avoid them.
Quoted 9 lines
Quoted 5 lines
Would there be a use case for PAT systems? I wonder if we can wrap this under some APIs to make it clean and hide this dirty thing behind the scenes, it seems a fragile and error prone and my hope would be that we won't need more specialization in this area for PAT systems.
One potential complication is kernel vs. userspace mmap. MTRR applies to the physical address, but PAT applies to the virtual address, so with the WC MTRR you get WC for userspace "for free" as well.
Quoted 8 lines
Quoted 5 lines
What is the performance impact of having the conversion being done by the kernel? Has anyone done measurements? If significant can't the subsystem
mmap()cache the phys address for PAT? Shouldn't the TLB take care of those considerations for us? If this is generally desirable shouldn't we just generalize the cache for devices for O(1) access through a generic API?We're pretty much required to keep the PTE memory types consistent for aliasses of the same page.
Hrm, OK so overlapping
ioremap()calls should be frowed upon?I think its important to clarify the few different scenarios we have for atyfb, both for today when uc- is default and when uc becomes the default. I'll also clarify what this series originally tried to do but the issues that size requirements prohibit us to do along with combinatorial issues that would also be present when and if uc becomes default. Finally I'll clarify what I am thinking we should do in light of all this.
_______________________________________________________________________
| | | |_______________________________________________________|_____________|\______________________________________________________/ \____________/
Framebuffer (8 MiB) MMIO (4 KiB)
Currently we have:
Page_cache_mode's _PAGE_CACHE_MODE_ is removed below for brevity. The atyfb PCI BAR is condensed to:
Frambuffer,MMIO
Keeping in mind:
Intel SDM, volume 3, section 11.5.2.1, table 11-6 (NonPAT combinatorial)
Intel SDM, volume 3, section 11.5.2.2, table 11-7 (PAT combinatorial)Linux PCD, PWT bits:
PAT
|PCD ||PWT ||| 000 WB _PAGE_CACHE_MODE_WB 001 WC _PAGE_CACHE_MODE_WC 010 UC- _PAGE_CACHE_MODE_UC_MINUS 011 UC _PAGE_CACHE_MODE_UC(*) below denotes grey area as per SDM, implementation-defined (%) below denotes not posislbe due to size / base requirements of MTRRs (+) below denotes combinatorial issueNon-PAT systems use PCD, PWT values, their respective bit settings for these are given although internally we use _PAGE_CACHE_MODE* on the ioremap* calls for both non-PAT and PAT. For instance
_PAGE_CACHE_MODE_UC_MINUSis 10 for PCD=1, PWT=0.Today we have:
--------------------------------------------------------------------
Calls | Page_cache_mode | Effective memtype | ------------------------|---------------------|--------------------- | Non-PAT | PAT | Non-PAT | PAT | -------------------------------------------------------------------- ioremap(MMIO) | xxx, 10 | xxx, UC- | xxx, UC | xxx, UC- | ioremap(PCI BAR) | 10 , 10 | UC-, UC- | UC, UC | UC-, UC- | MTRR WC(PCI BAR) | 10 , 10 | UC-, UC- | WC*, WC* | WC , WC | MTRR UC(MMIO) | 10 , 10 | UC-, UC- | WC*, UC | WC , UC |--------------------------------------------------------------------
If today we revert commit
de33c442eand UC becomes default this would run into the combinatorial issue:--------------------------------------------------------------------
Calls | Page_cache_mode | Effective memtype | ------------------------|---------------------|--------------------- | Non-PAT | PAT | Non-PAT | PAT | -------------------------------------------------------------------- ioremap(MMIO) | xxx, 11 | xxx, UC | xxx, UC | xxx, UC | ioremap(PCI BAR) | 11 , 11 | UC , UC | UC, UC | UC , UC | MTRR WC(PCI BAR) | 11 , 11 | UC, UC | UC+, UC+ | UC+, UC+ | MTRR UC(MMIO) | 11 , 11 | UC, UC | UC+, UC | UC+, UC |--------------------------------------------------------------------
We ideally would like to do the following but can't because of the restriction of having to use powers of two for both size and base address for MTRRs, we'd have two steps, one with
mtrr_add, and another witharch_phys_add_wc(). This is what this series was proposing for atyfb.With
mtrr_add():--------------------------------------------------------------------
Calls | Page_cache_mode | Effective memtype | ------------------------|---------------------|--------------------- | Non-PAT | PAT | Non-PAT | PAT | -------------------------------------------------------------------- ioremap_nocache(MMIO) | xxx, 10 | xxx, UC- | xxx, UC | xxx, UC- | ioremap_wc(fb) | 01 , 10 | WC , UC- | UC , UC | WC , UC- | MTRR WC(fb) | 01 , 10 | UC-, WC | WC%*,UC | WC%, UC- |--------------------------------------------------------------------
Then we'd change this to
arch_phys_add_wc():--------------------------------------------------------------------
Calls | Page_cache_mode | Effective memtype | ------------------------|---------------------|--------------------- | Non-PAT | PAT | Non-PAT | PAT | -------------------------------------------------------------------- ioremap_nocache(MMIO) | xxx, 10 | xxx, UC- | xxx, UC | UC-, UC- | ioremap_wc(fb) | 01 , 10 | WC , UC- | UC , UC | WC , UC- | arch_phys_add_wc(fb) | 01 , 10 | WC , WC | WC%*,UC | WC , UC- |--------------------------------------------------------------------
With the above code as well we have to consider the issues if we revert commit
de33c442eand UC becomes default, we'd run into then both the size issue and also a grey area:With
mtrr_add():--------------------------------------------------------------------
Calls | Page_cache_mode | Effective memtype | ------------------------|---------------------|--------------------- | Non-PAT | PAT | Non-PAT | PAT | -------------------------------------------------------------------- ioremap_nocache(MMIO) | xxx, 11 | xxx, UC | xxx, UC | xxx, UC | ioremap_wc(fb) | 01 , 11 | WC , UC | UC , UC | WC , UC | MTRR WC(fb) | 01 , 11 | WC , UC | WC%* ,UC | WC , UC |--------------------------------------------------------------------
Then with
arch_phys_add_wc():--------------------------------------------------------------------
Calls | Page_cache_mode | Effective memtype | ------------------------|---------------------|--------------------- | Non-PAT | PAT | Non-PAT | PAT | -------------------------------------------------------------------- ioremap_nocache(MMIO) | xxx, 11 | xxx, UC | xxx, UC | xxx, UC | ioremap_wc(fb) | 01 , 11 | WC , UC | UC , UC | WC , UC | arch_phys_add_wc(fb) | 01 , 11 | WC , UC | WC%*,UC | WC , UC |--------------------------------------------------------------------
So what we *could* do then if we add
ioremap_uc()(use strong UC always), then override the framebuffer area with wc, and finally use MTRR on the full PCI BAR, relying on that strong UC won't let the MTRR override the earlier UC on the MMIO area. There is a grey area here for non-PAT systemes but that is also the case as-is today.--------------------------------------------------------------------
Calls | Page_cache_mode | Effective memtype | ------------------------|---------------------|--------------------- | Non-PAT | PAT | Non-PAT | PAT | -------------------------------------------------------------------- ioremap_uc(PCI BAR) | 11 , 11 | UC , UC | UC , UC | UC , UC | ioremap_wc(fb) | 01 , 11 | WC , UC | UC , UC | WC , UC | MTRR_WC(PCI BAR) | 01 , 11 | WC , UC | WC*, UC | WC , UC |--------------------------------------------------------------------
Finally with the
arch_phys_add_wc()we'd end up with:--------------------------------------------------------------------
Calls | Page_cache_mode | Effective memtype | ------------------------|---------------------|--------------------- | Non-PAT | PAT | Non-PAT | PAT | -------------------------------------------------------------------- ioremap_uc(PCI BAR) | 11 , 11 | UC , UC | UC , UC | UC , UC | ioremap_wc(fb) | 01 , 11 | WC , UC | UC , UC | WC , UC | arch_phys_add_wc(PCIBAR)| 01 , 11 | WC , UC | WC*, UC | WC , UC |--------------------------------------------------------------------
In this case a revert of
de33c442ewon't have any effect as the driver was already well prepared for it by usingioremap_uc().Quoted 5 lines
I think that the x86 pageattr code is
supposed to take care of this. IOW, if everything is working right, then the supposedly uncached mmap should either fail, be promoted to WC, or cause the existing WC map to degrade to UC. The code is really overcomplicated right now.
Quoted 7 lines
Yeah aliasing things are not clear for the above picture for me, someone who is knee-deep in this can likely confirm of any issues with the above pictures. But most importrantly if we believe however that the last two sets above don't have any issues then I think we can move forward. Since we only have a few drivers that need special handling I think it makes sense to treat them specially and document this strategy for the "hole" work around.
Seems reaonable to me.
--Andy
Quoted 3 lines
Thoughts?
Luis
Signature · 2 lines
Andy Lutomirski AMA Capital Management, LLC
Re: [PATCH v1 09/47] vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around
In reply to Luis R. RodriguezQuoted 370 lines · Luis R. Rodriguez
Quoted 189 lines · Andy Lutomirski
Quoted 188 lines · Luis R. Rodriguez
Quoted 56 lines · Ville Syrjälä
Quoted 55 lines · Luis R. Rodriguez
Quoted 54 lines · Andy Lutomirski
Quoted 53 lines · Ville Syrjälä
Quoted 32 lines · Luis R. Rodriguez
Quoted 28 lines · Andy Lutomirski
Quoted 20 lines · Luis R. Rodriguez
Quoted 7 lines · Ville Syrjälä
Quoted 6 lines · Luis R. Rodriguez
drivers/video/fbdev/aty/atyfb_base.c +0
-0@@ -2630,21 +2630,10 @@ static int aty_init(struct fb_info *info)Quoted 11 lines
drivers/video/fbdev/aty/atyfb_base.c static int aty_init(struct fb_info *info) · line 2636
Quoted 9 lines
drivers/video/fbdev/aty/atyfb_base.c +2
-3#ifdef CONFIG_MTRR par->mtrr_aper =-1 ; - par->mtrr_reg =-1 ;if (!nomtrr) { -/* Cover the whole resource. */ - par->mtrr_aper =mtrr_add (par->res_start, par->res_size, + par->mtrr_aper =mtrr_add (info->fix.smem_start, + info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 );MTRRs need power of two size, so how is this supposed to work?
Quoted 6 lines
As per
mtrr_add_page()[0] the base and size are just supposed to be in units of 4 KiB, although the practice is to use powers of 2 in *some* drivers this is not standardized and by no means recorded as a requirement. Obviously powers of 2 will work too and you'd end up neatly aligned as well.mtrr_add()will usemtrr_check()to verify the the same requirement. Furthermore, as per my commit log message:Quoted 2 lines
Whatever the code may or may not do, the x86 architecture uses power-of-two MTRR sizes. So I'm confused.
Quoted 6 lines
There should be no confusion, I simply did not know that *was* the requirement for x86, if that is the case we should add a check for that and perhaps generalize a helper that does the power of two helper changes, the cleanest I found was the vesafb driver solution.
Thoughts?
The vesafb solution is bad since you'll only end up covering only the first 4MB of the framebuffer instead of the almost 8MB you want. Which in practice will mean throwing away half the VRAM since you really don't want the massive performance hit from accessing it as UC. And that would mean giving up decent display resolutions as well :(
And the other option of trying to cover the remainder with multiple ever smaller MTRRs doesn't work either since you'll run out of MTRRs very quickly.
This is precisely why I used the hole method in atyfb in the first place.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
I don't really like the idea of any new mtrr code not supporting that use case, especially as these things tend to be present in older machines where PAT isn't an option.
According to the Intel SDM, volume 3, section 11.5.2.1, table 11-6, non-PAT CPUs that have a WC MTRR, PCD = 1, and PWT = 1 (aka UC) have an effective memory type of UC.
This is true but non-PAT systems that use just
ioremap()will default to_PAGE_CACHE_MODE_UC_MINUS, not_PAGE_CACHE_MODE_UC, and_PAGE_CACHE_MODE_UC_MINUSon Linux has PCD = 1, PWT = 0. The list comes from:
uint16_t__cachemode2pte_tbl[_PAGE_CACHE_MODE_NUM] = {[_PAGE_CACHE_MODE_WB ] = 0 | 0 , [_PAGE_CACHE_MODE_WC ] = _PAGE_PWT | 0 , [_PAGE_CACHE_MODE_UC_MINUS] = 0 | _PAGE_PCD, [_PAGE_CACHE_MODE_UC ] = _PAGE_PWT | _PAGE_PCD, [_PAGE_CACHE_MODE_WT ] = 0 | _PAGE_PCD, [_PAGE_CACHE_MODE_WP ] = 0 | _PAGE_PCD,};
This can better be read here:
PAT
|PCD ||PWT ||| 000 WB _PAGE_CACHE_MODE_WB 001 WC _PAGE_CACHE_MODE_WC 010 UC- _PAGE_CACHE_MODE_UC_MINUS 011 UC _PAGE_CACHE_MODE_UCOn x86
ioremap()defaults toioremap_nocache()and right now that uses_PAGE_CACHE_MODE_UC_MINUSnot_PAGE_CACHE_MODE_UC. We have two cases to consider for non-PAT systems then:a) Right now as
ioremap()andioremap_nocache()default to_PAGE_CACHE_MODE_UC_MINUSon x86. In this case using a WC MTRR seems to use PWT=0, PCD=1, and table table 11-6 on non-PAT systems seems to place this situation as "implementation defined" and not encouraged.a) when commit
de33c442e"x86 PAT: fix performance drop for glx, use UC minus forioremap(),ioremap_nocache()andpci_mmap_page_range()" gets reverted and we use_PAGE_CACHE_MODE_UCby default. In this case on x86 for bothioremap()andioremap_nocache()as they will both default to_PAGE_CACHE_MODE_UCwe'll end up as you note with an effective memory type of UC.If I've understood this correctly then neither of these situations are good and its just by chance that on some systems situation a) has lead to proper WC.
On a PAT system we have a bit different combinatorial results (based on Table 11-7):
a) Right now
ioremap()andioremap_nocache()defaulting to_PAGE_CACHE_MODE_UC_MINUSyields + MTRR WC = WCb) When commit
de33c442egets reverted_PAGE_CACHE_MODE_UC+ MTRR WC = UCSo to be clear right now atyfb should work fine on PAT systems with
de33c442ein place, once reverted as-is right now we'd end up with UC effective memory type.For both PAT and non-PAT systems when commit
de33c442egets reverted we'd end up with UC as the effective memory type for atyfb. Right now it shoud work on PAT systems and by chance its suspected to work on non-PAT systems. We want to phase MTRR though, specially to avoid all this insane combinatorial nightmware.Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Hence my suggestion to add
ioremap_x86_ucand/orset_memory_x86_ucto punch a UC hole in an otherwise WC MTRR-covered region.To be clear I think you mean then that
ioremap_x86_uc()would help us avoid the jumps between combinatorial issues with MTRR on PAT / non-PAT systems before and after commitde33c442egets reverted. So for instance if we had on the atyfb driver:
ioremap_x86_uc(PCI BAR)ioremap_wc(framebuffer)arch_phys_add_wc(PCI BAR)On non-PAT systems on the MMIO region with PWT=1, PCD=1 we'd end up with UC. Sadly though since
_PAGE_CACHE_WCon non-PAT has PWT=1, PCD=0, the WC MTRR that follows would mean we'd end up with another grey area (but similar to before as technically an effectivethe memory type of WC).On PAT systems the above would not use MTRRs but we'd be counting on overlapping memory types -- its not clear if aliasing here is a problem.
Also Intel SDM, volume 3, section "11.11.4 Range Size and Alignment Requirement" describes that: "the minimum range size is 4 KiB, the base address must be on a 4 KiB boundary. For ranges greater than 4 KiB each range must be of length 2^n and its base address must be alinged on a 2^n boundary where n is a value equal or greatar then 12. The base-address alignment value cannot be less than its length. For example, an 8-KiB range cannot be aligned on a 4-KiB boundary. It must be aligned on at least an 8-KiB boundary"
So to answer my own question: indeed, our framebuffer base address must be aligned on a 2^n boundary, the size also has to be a power of 2. MTRR supports fixed range sizes and variable range sizes, in case of the MMIO that does not need to abide by the power of 2 rule as a fixed range size of 4 KiB could be used although upon review ouf our own implemetnation its unclear if that is what is used for 4 KiB sized MTRRs.
Hence my
arch_phys_add_wc(PCI BAR)as above.Quoted 3 lines
Quoted 3 lines
OK I think I get it now.
And I take it this would hopefully only be used for non-PAT systems?
Since we likely could care to use
ioremap_x86_uc()on PAT systems as well we could make the effective for both PAT and non-PAT obviously then. Later when we getioremap()to default to strong UC we could dropioremap_x86_uc()as we'd only need it as transitory until then -- that is unless we want perhaps a strong UC ioremap primitive which is always following strong UC when available regardless of these default transitions.The big issue I see here is simply the combinatorial issues, so I do think its best to annotate these corner cases well and avoid them.
Quoted 9 lines
Quoted 5 lines
Would there be a use case for PAT systems? I wonder if we can wrap this under some APIs to make it clean and hide this dirty thing behind the scenes, it seems a fragile and error prone and my hope would be that we won't need more specialization in this area for PAT systems.
One potential complication is kernel vs. userspace mmap. MTRR applies to the physical address, but PAT applies to the virtual address, so with the WC MTRR you get WC for userspace "for free" as well.
Quoted 8 lines
Quoted 5 lines
What is the performance impact of having the conversion being done by the kernel? Has anyone done measurements? If significant can't the subsystem
mmap()cache the phys address for PAT? Shouldn't the TLB take care of those considerations for us? If this is generally desirable shouldn't we just generalize the cache for devices for O(1) access through a generic API?We're pretty much required to keep the PTE memory types consistent for aliasses of the same page.
Hrm, OK so overlapping
ioremap()calls should be frowed upon?I think its important to clarify the few different scenarios we have for atyfb, both for today when uc- is default and when uc becomes the default. I'll also clarify what this series originally tried to do but the issues that size requirements prohibit us to do along with combinatorial issues that would also be present when and if uc becomes default. Finally I'll clarify what I am thinking we should do in light of all this.
_______________________________________________________________________
| | | |_______________________________________________________|_____________|\______________________________________________________/ \____________/
Framebuffer (8 MiB) MMIO (4 KiB)
Currently we have:
Page_cache_mode's _PAGE_CACHE_MODE_ is removed below for brevity. The atyfb PCI BAR is condensed to:
Frambuffer,MMIO
Keeping in mind:
Intel SDM, volume 3, section 11.5.2.1, table 11-6 (NonPAT combinatorial)
Intel SDM, volume 3, section 11.5.2.2, table 11-7 (PAT combinatorial)Linux PCD, PWT bits:
PAT
|PCD ||PWT ||| 000 WB _PAGE_CACHE_MODE_WB 001 WC _PAGE_CACHE_MODE_WC 010 UC- _PAGE_CACHE_MODE_UC_MINUS 011 UC _PAGE_CACHE_MODE_UC(*) below denotes grey area as per SDM, implementation-defined (%) below denotes not posislbe due to size / base requirements of MTRRs (+) below denotes combinatorial issueNon-PAT systems use PCD, PWT values, their respective bit settings for these are given although internally we use _PAGE_CACHE_MODE* on the ioremap* calls for both non-PAT and PAT. For instance
_PAGE_CACHE_MODE_UC_MINUSis 10 for PCD=1, PWT=0.Today we have:
--------------------------------------------------------------------
Calls | Page_cache_mode | Effective memtype | ------------------------|---------------------|--------------------- | Non-PAT | PAT | Non-PAT | PAT | -------------------------------------------------------------------- ioremap(MMIO) | xxx, 10 | xxx, UC- | xxx, UC | xxx, UC- | ioremap(PCI BAR) | 10 , 10 | UC-, UC- | UC, UC | UC-, UC- | MTRR WC(PCI BAR) | 10 , 10 | UC-, UC- | WC*, WC* | WC , WC | MTRR UC(MMIO) | 10 , 10 | UC-, UC- | WC*, UC | WC , UC |--------------------------------------------------------------------
If today we revert commit
de33c442eand UC becomes default this would run into the combinatorial issue:--------------------------------------------------------------------
Calls | Page_cache_mode | Effective memtype | ------------------------|---------------------|--------------------- | Non-PAT | PAT | Non-PAT | PAT | -------------------------------------------------------------------- ioremap(MMIO) | xxx, 11 | xxx, UC | xxx, UC | xxx, UC | ioremap(PCI BAR) | 11 , 11 | UC , UC | UC, UC | UC , UC | MTRR WC(PCI BAR) | 11 , 11 | UC, UC | UC+, UC+ | UC+, UC+ | MTRR UC(MMIO) | 11 , 11 | UC, UC | UC+, UC | UC+, UC |--------------------------------------------------------------------
We ideally would like to do the following but can't because of the restriction of having to use powers of two for both size and base address for MTRRs, we'd have two steps, one with
mtrr_add, and another witharch_phys_add_wc(). This is what this series was proposing for atyfb.With
mtrr_add():--------------------------------------------------------------------
Calls | Page_cache_mode | Effective memtype | ------------------------|---------------------|--------------------- | Non-PAT | PAT | Non-PAT | PAT | -------------------------------------------------------------------- ioremap_nocache(MMIO) | xxx, 10 | xxx, UC- | xxx, UC | xxx, UC- | ioremap_wc(fb) | 01 , 10 | WC , UC- | UC , UC | WC , UC- | MTRR WC(fb) | 01 , 10 | UC-, WC | WC%*,UC | WC%, UC- |--------------------------------------------------------------------
Then we'd change this to
arch_phys_add_wc():--------------------------------------------------------------------
Calls | Page_cache_mode | Effective memtype | ------------------------|---------------------|--------------------- | Non-PAT | PAT | Non-PAT | PAT | -------------------------------------------------------------------- ioremap_nocache(MMIO) | xxx, 10 | xxx, UC- | xxx, UC | UC-, UC- | ioremap_wc(fb) | 01 , 10 | WC , UC- | UC , UC | WC , UC- | arch_phys_add_wc(fb) | 01 , 10 | WC , WC | WC%*,UC | WC , UC- |--------------------------------------------------------------------
With the above code as well we have to consider the issues if we revert commit
de33c442eand UC becomes default, we'd run into then both the size issue and also a grey area:With
mtrr_add():--------------------------------------------------------------------
Calls | Page_cache_mode | Effective memtype | ------------------------|---------------------|--------------------- | Non-PAT | PAT | Non-PAT | PAT | -------------------------------------------------------------------- ioremap_nocache(MMIO) | xxx, 11 | xxx, UC | xxx, UC | xxx, UC | ioremap_wc(fb) | 01 , 11 | WC , UC | UC , UC | WC , UC | MTRR WC(fb) | 01 , 11 | WC , UC | WC%* ,UC | WC , UC |--------------------------------------------------------------------
Then with
arch_phys_add_wc():--------------------------------------------------------------------
Calls | Page_cache_mode | Effective memtype | ------------------------|---------------------|--------------------- | Non-PAT | PAT | Non-PAT | PAT | -------------------------------------------------------------------- ioremap_nocache(MMIO) | xxx, 11 | xxx, UC | xxx, UC | xxx, UC | ioremap_wc(fb) | 01 , 11 | WC , UC | UC , UC | WC , UC | arch_phys_add_wc(fb) | 01 , 11 | WC , UC | WC%*,UC | WC , UC |--------------------------------------------------------------------
So what we *could* do then if we add
ioremap_uc()(use strong UC always), then override the framebuffer area with wc, and finally use MTRR on the full PCI BAR, relying on that strong UC won't let the MTRR override the earlier UC on the MMIO area. There is a grey area here for non-PAT systemes but that is also the case as-is today.--------------------------------------------------------------------
Calls | Page_cache_mode | Effective memtype | ------------------------|---------------------|--------------------- | Non-PAT | PAT | Non-PAT | PAT | -------------------------------------------------------------------- ioremap_uc(PCI BAR) | 11 , 11 | UC , UC | UC , UC | UC , UC | ioremap_wc(fb) | 01 , 11 | WC , UC | UC , UC | WC , UC | MTRR_WC(PCI BAR) | 01 , 11 | WC , UC | WC*, UC | WC , UC |--------------------------------------------------------------------
Finally with the
arch_phys_add_wc()we'd end up with:--------------------------------------------------------------------
Calls | Page_cache_mode | Effective memtype | ------------------------|---------------------|--------------------- | Non-PAT | PAT | Non-PAT | PAT | -------------------------------------------------------------------- ioremap_uc(PCI BAR) | 11 , 11 | UC , UC | UC , UC | UC , UC | ioremap_wc(fb) | 01 , 11 | WC , UC | UC , UC | WC , UC | arch_phys_add_wc(PCIBAR)| 01 , 11 | WC , UC | WC*, UC | WC , UC |--------------------------------------------------------------------
In this case a revert of
de33c442ewon't have any effect as the driver was already well prepared for it by usingioremap_uc().Quoted 5 lines
I think that the x86 pageattr code is
supposed to take care of this. IOW, if everything is working right, then the supposedly uncached mmap should either fail, be promoted to WC, or cause the existing WC map to degrade to UC. The code is really overcomplicated right now.
Quoted 7 lines
Yeah aliasing things are not clear for the above picture for me, someone who is knee-deep in this can likely confirm of any issues with the above pictures. But most importrantly if we believe however that the last two sets above don't have any issues then I think we can move forward. Since we only have a few drivers that need special handling I think it makes sense to treat them specially and document this strategy for the "hole" work around.
Seems reaonable to me.
--Andy
Quoted 3 lines
Thoughts?
Luis
Signature · 7 lines
Andy Lutomirski AMA Capital Management, LLC _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v1 09/47] vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around
In reply to Andy LutomirskiQuoted 189 lines · Andy Lutomirski
Quoted 188 lines · Luis R. Rodriguez
Quoted 56 lines · Ville Syrjälä
Quoted 55 lines · Luis R. Rodriguez
Quoted 54 lines · Andy Lutomirski
Quoted 53 lines · Ville Syrjälä
Quoted 32 lines · Luis R. Rodriguez
Quoted 28 lines · Andy Lutomirski
Quoted 20 lines · Luis R. Rodriguez
Quoted 7 lines · Ville Syrjälä
Quoted 6 lines · Luis R. Rodriguez
drivers/video/fbdev/aty/atyfb_base.c +0
-0@@ -2630,21 +2630,10 @@ static int aty_init(struct fb_info *info)Quoted 11 lines
drivers/video/fbdev/aty/atyfb_base.c static int aty_init(struct fb_info *info) · line 2636
Quoted 9 lines
drivers/video/fbdev/aty/atyfb_base.c +2
-3#ifdef CONFIG_MTRR par->mtrr_aper =-1 ; - par->mtrr_reg =-1 ;if (!nomtrr) { -/* Cover the whole resource. */ - par->mtrr_aper =mtrr_add (par->res_start, par->res_size, + par->mtrr_aper =mtrr_add (info->fix.smem_start, + info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 );MTRRs need power of two size, so how is this supposed to work?
Quoted 6 lines
As per
mtrr_add_page()[0] the base and size are just supposed to be in units of 4 KiB, although the practice is to use powers of 2 in *some* drivers this is not standardized and by no means recorded as a requirement. Obviously powers of 2 will work too and you'd end up neatly aligned as well.mtrr_add()will usemtrr_check()to verify the the same requirement. Furthermore, as per my commit log message:Quoted 2 lines
Whatever the code may or may not do, the x86 architecture uses power-of-two MTRR sizes. So I'm confused.
Quoted 6 lines
There should be no confusion, I simply did not know that *was* the requirement for x86, if that is the case we should add a check for that and perhaps generalize a helper that does the power of two helper changes, the cleanest I found was the vesafb driver solution.
Thoughts?
The vesafb solution is bad since you'll only end up covering only the first 4MB of the framebuffer instead of the almost 8MB you want. Which in practice will mean throwing away half the VRAM since you really don't want the massive performance hit from accessing it as UC. And that would mean giving up decent display resolutions as well :(
And the other option of trying to cover the remainder with multiple ever smaller MTRRs doesn't work either since you'll run out of MTRRs very quickly.
This is precisely why I used the hole method in atyfb in the first place.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
I don't really like the idea of any new mtrr code not supporting that use case, especially as these things tend to be present in older machines where PAT isn't an option.
According to the Intel SDM, volume 3, section 11.5.2.1, table 11-6, non-PAT CPUs that have a WC MTRR, PCD = 1, and PWT = 1 (aka UC) have an effective memory type of UC.
This is true but non-PAT systems that use just
ioremap()will default to_PAGE_CACHE_MODE_UC_MINUS, not_PAGE_CACHE_MODE_UC, and_PAGE_CACHE_MODE_UC_MINUSon Linux has PCD = 1, PWT = 0. The list comes from:
uint16_t__cachemode2pte_tbl[_PAGE_CACHE_MODE_NUM] = {[_PAGE_CACHE_MODE_WB ] = 0 | 0 , [_PAGE_CACHE_MODE_WC ] = _PAGE_PWT | 0 , [_PAGE_CACHE_MODE_UC_MINUS] = 0 | _PAGE_PCD, [_PAGE_CACHE_MODE_UC ] = _PAGE_PWT | _PAGE_PCD, [_PAGE_CACHE_MODE_WT ] = 0 | _PAGE_PCD, [_PAGE_CACHE_MODE_WP ] = 0 | _PAGE_PCD,};
This can better be read here:
PAT
|PCD ||PWT ||| 000 WB _PAGE_CACHE_MODE_WB 001 WC _PAGE_CACHE_MODE_WC 010 UC- _PAGE_CACHE_MODE_UC_MINUS 011 UC _PAGE_CACHE_MODE_UCOn x86
ioremap()defaults toioremap_nocache()and right now that uses_PAGE_CACHE_MODE_UC_MINUSnot_PAGE_CACHE_MODE_UC. We have two cases to consider for non-PAT systems then:a) Right now as
ioremap()andioremap_nocache()default to_PAGE_CACHE_MODE_UC_MINUSon x86. In this case using a WC MTRR seems to use PWT=0, PCD=1, and table table 11-6 on non-PAT systems seems to place this situation as "implementation defined" and not encouraged.a) when commit
de33c442e"x86 PAT: fix performance drop for glx, use UC minus forioremap(),ioremap_nocache()andpci_mmap_page_range()" gets reverted and we use_PAGE_CACHE_MODE_UCby default. In this case on x86 for bothioremap()andioremap_nocache()as they will both default to_PAGE_CACHE_MODE_UCwe'll end up as you note with an effective memory type of UC.If I've understood this correctly then neither of these situations are good and its just by chance that on some systems situation a) has lead to proper WC.
On a PAT system we have a bit different combinatorial results (based on Table 11-7):
a) Right now
ioremap()andioremap_nocache()defaulting to_PAGE_CACHE_MODE_UC_MINUSyields + MTRR WC = WCb) When commit
de33c442egets reverted_PAGE_CACHE_MODE_UC+ MTRR WC = UCSo to be clear right now atyfb should work fine on PAT systems with
de33c442ein place, once reverted as-is right now we'd end up with UC effective memory type.For both PAT and non-PAT systems when commit
de33c442egets reverted we'd end up with UC as the effective memory type for atyfb. Right now it shoud work on PAT systems and by chance its suspected to work on non-PAT systems. We want to phase MTRR though, specially to avoid all this insane combinatorial nightmware.Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Hence my suggestion to add
ioremap_x86_ucand/orset_memory_x86_ucto punch a UC hole in an otherwise WC MTRR-covered region.To be clear I think you mean then that
ioremap_x86_uc()would help us avoid the jumps between combinatorial issues with MTRR on PAT / non-PAT systems before and after commitde33c442egets reverted. So for instance if we had on the atyfb driver:
ioremap_x86_uc(PCI BAR)ioremap_wc(framebuffer)arch_phys_add_wc(PCI BAR)On non-PAT systems on the MMIO region with PWT=1, PCD=1 we'd end up with UC. Sadly though since
_PAGE_CACHE_WCon non-PAT has PWT=1, PCD=0, the WC MTRR that follows would mean we'd end up with another grey area (but similar to before as technically an effectivethe memory type of WC).On PAT systems the above would not use MTRRs but we'd be counting on overlapping memory types -- its not clear if aliasing here is a problem.
Also Intel SDM, volume 3, section "11.11.4 Range Size and Alignment Requirement" describes that: "the minimum range size is 4 KiB, the base address must be on a 4 KiB boundary. For ranges greater than 4 KiB each range must be of length 2^n and its base address must be alinged on a 2^n boundary where n is a value equal or greatar then 12. The base-address alignment value cannot be less than its length. For example, an 8-KiB range cannot be aligned on a 4-KiB boundary. It must be aligned on at least an 8-KiB boundary"
So to answer my own question: indeed, our framebuffer base address must be aligned on a 2^n boundary, the size also has to be a power of 2. MTRR supports fixed range sizes and variable range sizes, in case of the MMIO that does not need to abide by the power of 2 rule as a fixed range size of 4 KiB could be used although upon review ouf our own implemetnation its unclear if that is what is used for 4 KiB sized MTRRs.
Hence my
arch_phys_add_wc(PCI BAR)as above.Quoted 3 lines
Quoted 3 lines
OK I think I get it now.
And I take it this would hopefully only be used for non-PAT systems?
Since we likely could care to use
ioremap_x86_uc()on PAT systems as well we could make the effective for both PAT and non-PAT obviously then. Later when we getioremap()to default to strong UC we could dropioremap_x86_uc()as we'd only need it as transitory until then -- that is unless we want perhaps a strong UC ioremap primitive which is always following strong UC when available regardless of these default transitions.The big issue I see here is simply the combinatorial issues, so I do think its best to annotate these corner cases well and avoid them.
Quoted 9 lines
Quoted 5 lines
Would there be a use case for PAT systems? I wonder if we can wrap this under some APIs to make it clean and hide this dirty thing behind the scenes, it seems a fragile and error prone and my hope would be that we won't need more specialization in this area for PAT systems.
One potential complication is kernel vs. userspace mmap. MTRR applies to the physical address, but PAT applies to the virtual address, so with the WC MTRR you get WC for userspace "for free" as well.
Quoted 8 lines
Quoted 5 lines
What is the performance impact of having the conversion being done by the kernel? Has anyone done measurements? If significant can't the subsystem
mmap()cache the phys address for PAT? Shouldn't the TLB take care of those considerations for us? If this is generally desirable shouldn't we just generalize the cache for devices for O(1) access through a generic API?We're pretty much required to keep the PTE memory types consistent for aliasses of the same page.
Hrm, OK so overlapping ioremap() calls should be frowed upon?
I think its important to clarify the few different scenarios we have for atyfb, both for today when uc- is default and when uc becomes the default. I'll also clarify what this series originally tried to do but the issues that size requirements prohibit us to do along with combinatorial issues that would also be present when and if uc becomes default. Finally I'll clarify what I am thinking we should do in light of all this.
_______________________________________________________________________
| | | |_______________________________________________________|_____________|
\______________________________________________________/ \____________/
Framebuffer (8 MiB) MMIO (4 KiB)
Currently we have:
Page_cache_mode's _PAGE_CACHE_MODE_ is removed below for brevity. The atyfb PCI BAR is condensed to:
Frambuffer,MMIO
Keeping in mind:
Intel SDM, volume 3, section 11.5.2.1, table 11-6 (NonPAT combinatorial)
Intel SDM, volume 3, section 11.5.2.2, table 11-7 (PAT combinatorial)
Linux PCD, PWT bits:
PAT
|PCD ||PWT ||| 000 WB _PAGE_CACHE_MODE_WB 001 WC _PAGE_CACHE_MODE_WC 010 UC- _PAGE_CACHE_MODE_UC_MINUS 011 UC _PAGE_CACHE_MODE_UC
(*) below denotes grey area as per SDM, implementation-defined (%) below denotes not posislbe due to size / base requirements of MTRRs (+) below denotes combinatorial issue
Non-PAT systems use PCD, PWT values, their respective bit settings for these are given although internally we use _PAGE_CACHE_MODE* on the ioremap* calls for both non-PAT and PAT. For instance _PAGE_CACHE_MODE_UC_MINUS is 10 for PCD=1, PWT=0.
Today we have:
--------------------------------------------------------------------
Calls | Page_cache_mode | Effective memtype |
------------------------|---------------------|---------------------
| Non-PAT | PAT | Non-PAT | PAT |
--------------------------------------------------------------------
ioremap(MMIO) | xxx, 10 | xxx, UC- | xxx, UC | xxx, UC- |
ioremap(PCI BAR) | 10 , 10 | UC-, UC- | UC, UC | UC-, UC- | MTRR WC(PCI BAR) | 10 , 10 | UC-, UC- | WC*, WC* | WC , WC |
MTRR UC(MMIO) | 10 , 10 | UC-, UC- | WC*, UC | WC , UC |
--------------------------------------------------------------------
If today we revert commit de33c442e and UC becomes default this would run into the combinatorial issue:
--------------------------------------------------------------------
Calls | Page_cache_mode | Effective memtype |
------------------------|---------------------|---------------------
| Non-PAT | PAT | Non-PAT | PAT |
--------------------------------------------------------------------
ioremap(MMIO) | xxx, 11 | xxx, UC | xxx, UC | xxx, UC |
ioremap(PCI BAR) | 11 , 11 | UC , UC | UC, UC | UC , UC | MTRR WC(PCI BAR) | 11 , 11 | UC, UC | UC+, UC+ | UC+, UC+ |
MTRR UC(MMIO) | 11 , 11 | UC, UC | UC+, UC | UC+, UC |
--------------------------------------------------------------------
We ideally would like to do the following but can't because of the restriction of having to use powers of two for both size and base address for MTRRs, we'd have two steps, one with mtrr_add, and another with arch_phys_add_wc(). This is what this series was proposing for atyfb.
With mtrr_add():
--------------------------------------------------------------------
Calls | Page_cache_mode | Effective memtype |
------------------------|---------------------|---------------------
| Non-PAT | PAT | Non-PAT | PAT |
--------------------------------------------------------------------ioremap_nocache(MMIO) | xxx, 10 | xxx, UC- | xxx, UC | xxx, UC- |ioremap_wc(fb) | 01 , 10 | WC , UC- | UC , UC | WC , UC- |
MTRR WC(fb) | 01 , 10 | UC-, WC | WC%*,UC | WC%, UC- |
--------------------------------------------------------------------
Then we'd change this to arch_phys_add_wc():
--------------------------------------------------------------------
Calls | Page_cache_mode | Effective memtype |
------------------------|---------------------|---------------------
| Non-PAT | PAT | Non-PAT | PAT |
--------------------------------------------------------------------ioremap_nocache(MMIO) | xxx, 10 | xxx, UC- | xxx, UC | UC-, UC- |ioremap_wc(fb) | 01 , 10 | WC , UC- | UC , UC | WC , UC- |arch_phys_add_wc(fb) | 01 , 10 | WC , WC | WC%*,UC | WC , UC- |
--------------------------------------------------------------------
With the above code as well we have to consider the issues if we revert commit de33c442e and UC becomes default, we'd run into then both the size issue and also a grey area:
With mtrr_add():
--------------------------------------------------------------------
Calls | Page_cache_mode | Effective memtype |
------------------------|---------------------|---------------------
| Non-PAT | PAT | Non-PAT | PAT |
--------------------------------------------------------------------ioremap_nocache(MMIO) | xxx, 11 | xxx, UC | xxx, UC | xxx, UC |ioremap_wc(fb) | 01 , 11 | WC , UC | UC , UC | WC , UC |
MTRR WC(fb) | 01 , 11 | WC , UC | WC%* ,UC | WC , UC |
--------------------------------------------------------------------
Then with arch_phys_add_wc():
--------------------------------------------------------------------
Calls | Page_cache_mode | Effective memtype |
------------------------|---------------------|---------------------
| Non-PAT | PAT | Non-PAT | PAT |
--------------------------------------------------------------------ioremap_nocache(MMIO) | xxx, 11 | xxx, UC | xxx, UC | xxx, UC |ioremap_wc(fb) | 01 , 11 | WC , UC | UC , UC | WC , UC |arch_phys_add_wc(fb) | 01 , 11 | WC , UC | WC%*,UC | WC , UC |
--------------------------------------------------------------------
So what we *could* do then if we add ioremap_uc() (use strong UC always), then override the framebuffer area with wc, and finally use MTRR on the full PCI BAR, relying on that strong UC won't let the MTRR override the earlier UC on the MMIO area. There is a grey area here for non-PAT systemes but that is also the case as-is today.
--------------------------------------------------------------------
Calls | Page_cache_mode | Effective memtype |
------------------------|---------------------|---------------------
| Non-PAT | PAT | Non-PAT | PAT |
--------------------------------------------------------------------ioremap_uc(PCI BAR) | 11 , 11 | UC , UC | UC , UC | UC , UC |ioremap_wc(fb) | 01 , 11 | WC , UC | UC , UC | WC , UC |MTRR_WC(PCI BAR) | 01 , 11 | WC , UC | WC*, UC | WC , UC |
--------------------------------------------------------------------
Finally with the arch_phys_add_wc() we'd end up with:
--------------------------------------------------------------------
Calls | Page_cache_mode | Effective memtype |
------------------------|---------------------|---------------------
| Non-PAT | PAT | Non-PAT | PAT |
--------------------------------------------------------------------ioremap_uc(PCI BAR) | 11 , 11 | UC , UC | UC , UC | UC , UC |ioremap_wc(fb) | 01 , 11 | WC , UC | UC , UC | WC , UC |
arch_phys_add_wc(PCIBAR)| 01 , 11 | WC , UC | WC*, UC | WC , UC |
--------------------------------------------------------------------
In this case a revert of de33c442e won't have any effect as the driver was already well prepared for it by using ioremap_uc().
Quoted 5 lines
I think that the x86 pageattr code is
supposed to take care of this. IOW, if everything is working right, then the supposedly uncached mmap should either fail, be promoted to WC, or cause the existing WC map to degrade to UC. The code is really overcomplicated right now.
Yeah aliasing things are not clear for the above picture for me, someone who is knee-deep in this can likely confirm of any issues with the above pictures. But most importrantly if we believe however that the last two sets above don't have any issues then I think we can move forward. Since we only have a few drivers that need special handling I think it makes sense to treat them specially and document this strategy for the "hole" work around.
Thoughts?
Luis
Re: [PATCH v1 09/47] vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around
In reply to Luis R. RodriguezQuoted 188 lines · Luis R. Rodriguez
Quoted 56 lines · Ville Syrjälä
Quoted 55 lines · Luis R. Rodriguez
Quoted 54 lines · Andy Lutomirski
Quoted 53 lines · Ville Syrjälä
Quoted 32 lines · Luis R. Rodriguez
Quoted 28 lines · Andy Lutomirski
Quoted 20 lines · Luis R. Rodriguez
Quoted 7 lines · Ville Syrjälä
Quoted 6 lines · Luis R. Rodriguez
drivers/video/fbdev/aty/atyfb_base.c +0
-0@@ -2630,21 +2630,10 @@ static int aty_init(struct fb_info *info)Quoted 11 lines
drivers/video/fbdev/aty/atyfb_base.c static int aty_init(struct fb_info *info) · line 2636
Quoted 9 lines
drivers/video/fbdev/aty/atyfb_base.c +2
-3#ifdef CONFIG_MTRR par->mtrr_aper =-1 ; - par->mtrr_reg =-1 ;if (!nomtrr) { -/* Cover the whole resource. */ - par->mtrr_aper =mtrr_add (par->res_start, par->res_size, + par->mtrr_aper =mtrr_add (info->fix.smem_start, + info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 );MTRRs need power of two size, so how is this supposed to work?
Quoted 6 lines
As per
mtrr_add_page()[0] the base and size are just supposed to be in units of 4 KiB, although the practice is to use powers of 2 in *some* drivers this is not standardized and by no means recorded as a requirement. Obviously powers of 2 will work too and you'd end up neatly aligned as well.mtrr_add()will usemtrr_check()to verify the the same requirement. Furthermore, as per my commit log message:Quoted 2 lines
Whatever the code may or may not do, the x86 architecture uses power-of-two MTRR sizes. So I'm confused.
Quoted 6 lines
There should be no confusion, I simply did not know that *was* the requirement for x86, if that is the case we should add a check for that and perhaps generalize a helper that does the power of two helper changes, the cleanest I found was the vesafb driver solution.
Thoughts?
The vesafb solution is bad since you'll only end up covering only the first 4MB of the framebuffer instead of the almost 8MB you want. Which in practice will mean throwing away half the VRAM since you really don't want the massive performance hit from accessing it as UC. And that would mean giving up decent display resolutions as well :(
And the other option of trying to cover the remainder with multiple ever smaller MTRRs doesn't work either since you'll run out of MTRRs very quickly.
This is precisely why I used the hole method in atyfb in the first place.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
I don't really like the idea of any new mtrr code not supporting that use case, especially as these things tend to be present in older machines where PAT isn't an option.
According to the Intel SDM, volume 3, section 11.5.2.1, table 11-6, non-PAT CPUs that have a WC MTRR, PCD = 1, and PWT = 1 (aka UC) have an effective memory type of UC.
This is true but non-PAT systems that use just
ioremap()will default to_PAGE_CACHE_MODE_UC_MINUS, not_PAGE_CACHE_MODE_UC, and_PAGE_CACHE_MODE_UC_MINUSon Linux has PCD = 1, PWT = 0. The list comes from:
uint16_t__cachemode2pte_tbl[_PAGE_CACHE_MODE_NUM] = {[_PAGE_CACHE_MODE_WB ] = 0 | 0 , [_PAGE_CACHE_MODE_WC ] = _PAGE_PWT | 0 , [_PAGE_CACHE_MODE_UC_MINUS] = 0 | _PAGE_PCD, [_PAGE_CACHE_MODE_UC ] = _PAGE_PWT | _PAGE_PCD, [_PAGE_CACHE_MODE_WT ] = 0 | _PAGE_PCD, [_PAGE_CACHE_MODE_WP ] = 0 | _PAGE_PCD,};
This can better be read here:
PAT
|PCD ||PWT ||| 000 WB _PAGE_CACHE_MODE_WB 001 WC _PAGE_CACHE_MODE_WC 010 UC- _PAGE_CACHE_MODE_UC_MINUS 011 UC _PAGE_CACHE_MODE_UCOn x86
ioremap()defaults toioremap_nocache()and right now that uses_PAGE_CACHE_MODE_UC_MINUSnot_PAGE_CACHE_MODE_UC. We have two cases to consider for non-PAT systems then:a) Right now as
ioremap()andioremap_nocache()default to_PAGE_CACHE_MODE_UC_MINUSon x86. In this case using a WC MTRR seems to use PWT=0, PCD=1, and table table 11-6 on non-PAT systems seems to place this situation as "implementation defined" and not encouraged.a) when commit
de33c442e"x86 PAT: fix performance drop for glx, use UC minus forioremap(),ioremap_nocache()andpci_mmap_page_range()" gets reverted and we use_PAGE_CACHE_MODE_UCby default. In this case on x86 for bothioremap()andioremap_nocache()as they will both default to_PAGE_CACHE_MODE_UCwe'll end up as you note with an effective memory type of UC.If I've understood this correctly then neither of these situations are good and its just by chance that on some systems situation a) has lead to proper WC.
On a PAT system we have a bit different combinatorial results (based on Table 11-7):
a) Right now
ioremap()andioremap_nocache()defaulting to_PAGE_CACHE_MODE_UC_MINUSyields + MTRR WC = WCb) When commit
de33c442egets reverted_PAGE_CACHE_MODE_UC+ MTRR WC = UCSo to be clear right now atyfb should work fine on PAT systems with
de33c442ein place, once reverted as-is right now we'd end up with UC effective memory type.For both PAT and non-PAT systems when commit
de33c442egets reverted we'd end up with UC as the effective memory type for atyfb. Right now it shoud work on PAT systems and by chance its suspected to work on non-PAT systems. We want to phase MTRR though, specially to avoid all this insane combinatorial nightmware.Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Hence my suggestion to add
ioremap_x86_ucand/orset_memory_x86_ucto punch a UC hole in an otherwise WC MTRR-covered region.To be clear I think you mean then that
ioremap_x86_uc()would help us avoid the jumps between combinatorial issues with MTRR on PAT / non-PAT systems before and after commitde33c442egets reverted. So for instance if we had on the atyfb driver:
ioremap_x86_uc(PCI BAR)ioremap_wc(framebuffer)arch_phys_add_wc(PCI BAR)On non-PAT systems on the MMIO region with PWT=1, PCD=1 we'd end up with UC. Sadly though since
_PAGE_CACHE_WCon non-PAT has PWT=1, PCD=0, the WC MTRR that follows would mean we'd end up with another grey area (but similar to before as technically an effectivethe memory type of WC).On PAT systems the above would not use MTRRs but we'd be counting on overlapping memory types -- its not clear if aliasing here is a problem.
Also Intel SDM, volume 3, section "11.11.4 Range Size and Alignment Requirement" describes that: "the minimum range size is 4 KiB, the base address must be on a 4 KiB boundary. For ranges greater than 4 KiB each range must be of length 2^n and its base address must be alinged on a 2^n boundary where n is a value equal or greatar then 12. The base-address alignment value cannot be less than its length. For example, an 8-KiB range cannot be aligned on a 4-KiB boundary. It must be aligned on at least an 8-KiB boundary"
So to answer my own question: indeed, our framebuffer base address must be aligned on a 2^n boundary, the size also has to be a power of 2. MTRR supports fixed range sizes and variable range sizes, in case of the MMIO that does not need to abide by the power of 2 rule as a fixed range size of 4 KiB could be used although upon review ouf our own implemetnation its unclear if that is what is used for 4 KiB sized MTRRs.
Hence my
arch_phys_add_wc(PCI BAR)as above.Quoted 3 lines
Quoted 3 lines
OK I think I get it now.
And I take it this would hopefully only be used for non-PAT systems?
Since we likely could care to use
ioremap_x86_uc()on PAT systems as well we could make the effective for both PAT and non-PAT obviously then. Later when we getioremap()to default to strong UC we could dropioremap_x86_uc()as we'd only need it as transitory until then -- that is unless we want perhaps a strong UC ioremap primitive which is always following strong UC when available regardless of these default transitions.The big issue I see here is simply the combinatorial issues, so I do think its best to annotate these corner cases well and avoid them.
Quoted 9 lines
Quoted 5 lines
Would there be a use case for PAT systems? I wonder if we can wrap this under some APIs to make it clean and hide this dirty thing behind the scenes, it seems a fragile and error prone and my hope would be that we won't need more specialization in this area for PAT systems.
One potential complication is kernel vs. userspace mmap. MTRR applies to the physical address, but PAT applies to the virtual address, so with the WC MTRR you get WC for userspace "for free" as well.
Quoted 5 lines
What is the performance impact of having the conversion being done by the kernel? Has anyone done measurements? If significant can't the subsystem
mmap()cache the phys address for PAT? Shouldn't the TLB take care of those considerations for us? If this is generally desirable shouldn't we just generalize the cache for devices for O(1) access through a generic API?
We're pretty much required to keep the PTE memory types consistent for aliasses of the same page. I think that the x86 pageattr code is supposed to take care of this. IOW, if everything is working right, then the supposedly uncached mmap should either fail, be promoted to WC, or cause the existing WC map to degrade to UC. The code is really overcomplicated right now.
--Andy
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v1 09/47] vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around
In reply to Ville SyrjäläQuoted 56 lines · Ville Syrjälä
Quoted 55 lines · Luis R. Rodriguez
Quoted 54 lines · Andy Lutomirski
Quoted 53 lines · Ville Syrjälä
Quoted 32 lines · Luis R. Rodriguez
Quoted 28 lines · Andy Lutomirski
Quoted 20 lines · Luis R. Rodriguez
Quoted 7 lines · Ville Syrjälä
Quoted 6 lines · Luis R. Rodriguez
drivers/video/fbdev/aty/atyfb_base.c +0
-0@@ -2630,21 +2630,10 @@ static int aty_init(struct fb_info *info)Quoted 11 lines
drivers/video/fbdev/aty/atyfb_base.c static int aty_init(struct fb_info *info) · line 2636
Quoted 9 lines
drivers/video/fbdev/aty/atyfb_base.c +2
-3#ifdef CONFIG_MTRR par->mtrr_aper =-1 ; - par->mtrr_reg =-1 ;if (!nomtrr) { -/* Cover the whole resource. */ - par->mtrr_aper =mtrr_add (par->res_start, par->res_size, + par->mtrr_aper =mtrr_add (info->fix.smem_start, + info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 );MTRRs need power of two size, so how is this supposed to work?
Quoted 6 lines
As per
mtrr_add_page()[0] the base and size are just supposed to be in units of 4 KiB, although the practice is to use powers of 2 in *some* drivers this is not standardized and by no means recorded as a requirement. Obviously powers of 2 will work too and you'd end up neatly aligned as well.mtrr_add()will usemtrr_check()to verify the the same requirement. Furthermore, as per my commit log message:Quoted 2 lines
Whatever the code may or may not do, the x86 architecture uses power-of-two MTRR sizes. So I'm confused.
Quoted 6 lines
There should be no confusion, I simply did not know that *was* the requirement for x86, if that is the case we should add a check for that and perhaps generalize a helper that does the power of two helper changes, the cleanest I found was the vesafb driver solution.
Thoughts?
The vesafb solution is bad since you'll only end up covering only the first 4MB of the framebuffer instead of the almost 8MB you want. Which in practice will mean throwing away half the VRAM since you really don't want the massive performance hit from accessing it as UC. And that would mean giving up decent display resolutions as well :(
And the other option of trying to cover the remainder with multiple ever smaller MTRRs doesn't work either since you'll run out of MTRRs very quickly.
This is precisely why I used the hole method in atyfb in the first place.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
I don't really like the idea of any new mtrr code not supporting that use case, especially as these things tend to be present in older machines where PAT isn't an option.
According to the Intel SDM, volume 3, section 11.5.2.1, table 11-6, non-PAT CPUs that have a WC MTRR, PCD = 1, and PWT = 1 (aka UC) have an effective memory type of UC.
This is true but non-PAT systems that use just ioremap() will default to _PAGE_CACHE_MODE_UC_MINUS, not _PAGE_CACHE_MODE_UC, and _PAGE_CACHE_MODE_UC_MINUS on Linux has PCD = 1, PWT = 0. The list comes from:
uint16_t __cachemode2pte_tbl[_PAGE_CACHE_MODE_NUM] = {
[_PAGE_CACHE_MODE_WB ] = 0 | 0 ,
[_PAGE_CACHE_MODE_WC ] = _PAGE_PWT | 0 ,
[_PAGE_CACHE_MODE_UC_MINUS] = 0 | _PAGE_PCD,
[_PAGE_CACHE_MODE_UC ] = _PAGE_PWT | _PAGE_PCD,
[_PAGE_CACHE_MODE_WT ] = 0 | _PAGE_PCD,
[_PAGE_CACHE_MODE_WP ] = 0 | _PAGE_PCD, };
This can better be read here:
PAT
|PCD ||PWT ||| 000 WB _PAGE_CACHE_MODE_WB 001 WC _PAGE_CACHE_MODE_WC 010 UC- _PAGE_CACHE_MODE_UC_MINUS 011 UC _PAGE_CACHE_MODE_UC
On x86 ioremap() defaults to ioremap_nocache() and right now that uses _PAGE_CACHE_MODE_UC_MINUS not _PAGE_CACHE_MODE_UC. We have two cases to consider for non-PAT systems then:
a) Right now as ioremap() and ioremap_nocache() default to _PAGE_CACHE_MODE_UC_MINUS on x86. In this case using a WC MTRR seems to use PWT=0, PCD=1, and table table 11-6 on non-PAT systems seems to place this situation as "implementation defined" and not encouraged.
a) when commit de33c442e "x86 PAT: fix performance drop for glx, use UC minus for ioremap(), ioremap_nocache() and pci_mmap_page_range()" gets reverted and we use _PAGE_CACHE_MODE_UC by default. In this case on x86 for both ioremap() and ioremap_nocache() as they will both default to _PAGE_CACHE_MODE_UC we'll end up as you note with an effective memory type of UC.
If I've understood this correctly then neither of these situations are good and its just by chance that on some systems situation a) has lead to proper WC.
On a PAT system we have a bit different combinatorial results (based on Table 11-7):
a) Right now ioremap() and ioremap_nocache() defaulting to _PAGE_CACHE_MODE_UC_MINUS yields + MTRR WC = WC
b) When commit de33c442e gets reverted _PAGE_CACHE_MODE_UC + MTRR WC = UC
So to be clear right now atyfb should work fine on PAT systems with de33c442e in place, once reverted as-is right now we'd end up with UC effective memory type.
For both PAT and non-PAT systems when commit de33c442e gets reverted we'd end up with UC as the effective memory type for atyfb. Right now it shoud work on PAT systems and by chance its suspected to work on non-PAT systems. We want to phase MTRR though, specially to avoid all this insane combinatorial nightmware.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Hence my suggestion to add
ioremap_x86_ucand/orset_memory_x86_ucto punch a UC hole in an otherwise WC MTRR-covered region.
To be clear I think you mean then that ioremap_x86_uc() would help us avoid the jumps between combinatorial issues with MTRR on PAT / non-PAT systems before and after commit de33c442e gets reverted. So for instance if we had on the atyfb driver:
ioremap_x86_uc(PCI BAR)ioremap_wc(framebuffer)arch_phys_add_wc(PCI BAR)
On non-PAT systems on the MMIO region with PWT=1, PCD=1 we'd end up with UC. Sadly though since _PAGE_CACHE_WC on non-PAT has PWT=1, PCD=0, the WC MTRR that follows would mean we'd end up with another grey area (but similar to before as technically an effectivethe memory type of WC).
On PAT systems the above would not use MTRRs but we'd be counting on overlapping memory types -- its not clear if aliasing here is a problem.
Also Intel SDM, volume 3, section "11.11.4 Range Size and Alignment Requirement" describes that: "the minimum range size is 4 KiB, the base address must be on a 4 KiB boundary. For ranges greater than 4 KiB each range must be of length 2^n and its base address must be alinged on a 2^n boundary where n is a value equal or greatar then 12. The base-address alignment value cannot be less than its length. For example, an 8-KiB range cannot be aligned on a 4-KiB boundary. It must be aligned on at least an 8-KiB boundary"
So to answer my own question: indeed, our framebuffer base address must be aligned on a 2^n boundary, the size also has to be a power of 2. MTRR supports fixed range sizes and variable range sizes, in case of the MMIO that does not need to abide by the power of 2 rule as a fixed range size of 4 KiB could be used although upon review ouf our own implemetnation its unclear if that is what is used for 4 KiB sized MTRRs.
Hence my arch_phys_add_wc(PCI BAR) as above.
Quoted 3 lines
Quoted 3 lines
OK I think I get it now.
And I take it this would hopefully only be used for non-PAT systems?
Since we likely could care to use ioremap_x86_uc() on PAT systems as well we could make the effective for both PAT and non-PAT obviously then. Later when we get ioremap() to default to strong UC we could drop ioremap_x86_uc() as we'd only need it as transitory until then -- that is unless we want perhaps a strong UC ioremap primitive which is always following strong UC when available regardless of these default transitions.
The big issue I see here is simply the combinatorial issues, so I do think its best to annotate these corner cases well and avoid them.
Quoted 9 lines
Quoted 5 lines
Would there be a use case for PAT systems? I wonder if we can wrap this under some APIs to make it clean and hide this dirty thing behind the scenes, it seems a fragile and error prone and my hope would be that we won't need more specialization in this area for PAT systems.
One potential complication is kernel vs. userspace mmap. MTRR applies to the physical address, but PAT applies to the virtual address, so with the WC MTRR you get WC for userspace "for free" as well.
What is the performance impact of having the conversion being done by the kernel? Has anyone done measurements? If significant can't the subsystem mmap() cache the phys address for PAT? Shouldn't the TLB take care of those considerations for us? If this is generally desirable shouldn't we just generalize the cache for devices for O(1) access through a generic API?
Can the difference, other than a possible performance hit, implicate a userspace visible change?
If the performance / userspace effect is neglibable then I'd expect the gains from cleaner code / APIs to outweight the cons. After all the goal is to streamline PAT when possible here.
Quoted 3 lines
Also the
userspace mmaps request will have the length ofsmem_len(at most), so it won't be the nice power of two in that case.
Does that length change implicate a userspace visible change?
Quoted 2 lines
Also on PAT systems w/o a BIOS provided WC MTRR, the fbdev mmap seems to be total crap at the moment. IIRC I have a patch to fix things a bit...
Isn't that becuase of the lack of the ioremap_wc()'s? You seem to be alternatively doing this with pgprot_writecombine(), more on this strategy below though.
Quoted 44 lines
From
4e6d70d223f35953c8a11a58cf3376a8a001fa4fMon Sep 17 00:00:00 2001
From: Ville Syrjala <[email protected]>
Date: Fri, 15 Apr 2011 04:02:43 +0300
Subject: [PATCH] fb: writecombine fb--- drivers/video/fbdev/core/fbmem.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)drivers/video/fbdev/core/fbmem.c +11
-1@@ -1396,6 +1396,7 @@ fb_mmap(struct file *file, struct vm_area_struct * vma)unsigned long mmio_pgoff;unsigned long start;u32 len; +bool mmio = false;if (!info)return -ENODEV ;@@ -1426,11 +1427,20 @@ fb_mmap(struct file *file, struct vm_area_struct * vma) vma->vm_pgoff -= mmio_pgoff; start = info->fix.mmio_start; len = info->fix.mmio_len; + mmio = true; }mutex_unlock (&info->mm_lock); +if (!mmio) { + vma->vm_page_prot =vm_get_page_prot (vma->vm_flags); + vma->vm_page_prot =pgprot_writecombine (vma->vm_page_prot); + +if (!vm_iomap_memory (vma, start, len)) +return 0 ; + } + vma->vm_page_prot =vm_get_page_prot (vma->vm_flags); -fb_pgprotect (file, vma, start); + vma->vm_page_prot =pgprot_noncached (vma->vm_page_prot);return vm_iomap_memory (vma, start, len); }
Quoted 1 line
Perhaps it's time I tried to send that upstream properly :P
Lets assume drivers all have ioremap_wc() on the framebuffer, would the the above not be needed then (disregarding the corner cases such as atyfb)?
If your goal is to generalize a place to make framebuffer WC instead of doing that at mmap() why not do it at register_framebuffer() time and do it only once? I suspect all this might also be easier to do and generalize after this series.
So as we can see from this series there are tons of drivers that can safely be moved to use ioremap_wc() already, provided there are no regressions with the simple ioremap_wc() / arch_phys_wc_add() switch. There are only a few corner cases to address after that. Addressing both of these *first* would simplify the code and gramatically make it a bit more consistent while trying to avoid a generalized regression. I believe a generalized solution is definitely in order but we also should first address the corner cases.
So how about we:
a) convert all drivers over that are safe to convert to ioremap_wc() / arch_phys_add_wc()
b) address all corner cases and try to avoid further combinatorial issues
c) after a while push for reverting de33c442e
d) generalize a solution / for framebuffer
Ideally as I mentioned in the other thread with Bjorn we could even have the WC be done further below for us but it was very unclear if we could accomplish this due the definition of the PCI flags, the way we'd use it and the way they could be integrated on hardware by manufacturers. I think generalizing things under the frambuffer code would be good intermediate step but I think we need to phase this in in light of the corner cases, combinatorial issues with PAT / non-PAT and eventual reverting goals of commit de33c442e in order to generalize strong UC.
Luis
Re: [PATCH v1 09/47] vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around
In reply to Luis R. RodriguezQuoted 65 lines · Luis R. Rodriguez
Quoted 58 lines · Andy Lutomirski
Quoted 50 lines · Ville Syrjälä
Quoted 32 lines · Luis R. Rodriguez
Quoted 28 lines · Andy Lutomirski
Quoted 20 lines · Luis R. Rodriguez
Quoted 7 lines · Ville Syrjälä
Quoted 6 lines · Luis R. Rodriguez
drivers/video/fbdev/aty/atyfb_base.c +0
-0@@ -2630,21 +2630,10 @@ static int aty_init(struct fb_info *info)Quoted 11 lines
drivers/video/fbdev/aty/atyfb_base.c static int aty_init(struct fb_info *info) · line 2636
Quoted 9 lines
drivers/video/fbdev/aty/atyfb_base.c +2
-3#ifdef CONFIG_MTRR par->mtrr_aper =-1 ; - par->mtrr_reg =-1 ;if (!nomtrr) { -/* Cover the whole resource. */ - par->mtrr_aper =mtrr_add (par->res_start, par->res_size, + par->mtrr_aper =mtrr_add (info->fix.smem_start, + info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 );MTRRs need power of two size, so how is this supposed to work?
Quoted 6 lines
As per
mtrr_add_page()[0] the base and size are just supposed to be in units of 4 KiB, although the practice is to use powers of 2 in *some* drivers this is not standardized and by no means recorded as a requirement. Obviously powers of 2 will work too and you'd end up neatly aligned as well.mtrr_add()will usemtrr_check()to verify the the same requirement. Furthermore, as per my commit log message:Quoted 2 lines
Whatever the code may or may not do, the x86 architecture uses power-of-two MTRR sizes. So I'm confused.
Quoted 6 lines
There should be no confusion, I simply did not know that *was* the requirement for x86, if that is the case we should add a check for that and perhaps generalize a helper that does the power of two helper changes, the cleanest I found was the vesafb driver solution.
Thoughts?
The vesafb solution is bad since you'll only end up covering only the first 4MB of the framebuffer instead of the almost 8MB you want. Which in practice will mean throwing away half the VRAM since you really don't want the massive performance hit from accessing it as UC. And that would mean giving up decent display resolutions as well :(
And the other option of trying to cover the remainder with multiple ever smaller MTRRs doesn't work either since you'll run out of MTRRs very quickly.
Quoted 6 lines
This is precisely why I used the hole method in atyfb in the first place.
I don't really like the idea of any new mtrr code not supporting that use case, especially as these things tend to be present in older machines where PAT isn't an option.
Quoted 5 lines
According to the Intel SDM, volume 3, section 11.5.2.1, table 11-6, non-PAT CPUs that have a WC MTRR, PCD = 1, and PWT = 1 (aka UC) have an effective memory type of UC. Hence my suggestion to add
ioremap_x86_ucand/orset_memory_x86_ucto punch a UC hole in an otherwise WC MTRR-covered region.
Quoted 8 lines
OK I think I get it now.
And I take it this would hopefully only be used for non-PAT systems? Would there be a use case for PAT systems? I wonder if we can wrap this under some APIs to make it clean and hide this dirty thing behind the scenes, it seems a fragile and error prone and my hope would be that we won't need more specialization in this area for PAT systems.
One potential complication is kernel vs. userspace mmap. MTRR applies to the physical address, but PAT applies to the virtual address, so with the WC MTRR you get WC for userspace "for free" as well. Also the userspace mmaps request will have the length of smem_len (at most), so it won't be the nice power of two in that case.
Also on PAT systems w/o a BIOS provided WC MTRR, the fbdev mmap seems to be total crap at the moment. IIRC I have a patch to fix things a bit...
Quoted 1 line
From
4e6d70d223f35953c8a11a58cf3376a8a001fa4fMon Sep 17 00:00:00 2001
From: Ville Syrjala <[email protected]>
Date: Fri, 15 Apr 2011 04:02:43 +0300
Subject: [PATCH] fb: writecombine fb
--- drivers/video/fbdev/core/fbmem.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/video/fbdev/core/fbmem.c +11 -1
@@ -1396,6 +1396,7 @@ fb_mmap(struct file *file, struct vm_area_struct * vma)unsigned long mmio_pgoff;unsigned long start;u32 len; +bool mmio = false;if (!info)return -ENODEV ;
@@ -1426,11 +1427,20 @@ fb_mmap(struct file *file, struct vm_area_struct * vma) vma->vm_pgoff -= mmio_pgoff; start = info->fix.mmio_start; len = info->fix.mmio_len; + mmio = true; }mutex_unlock (&info->mm_lock); +if (!mmio) { + vma->vm_page_prot =vm_get_page_prot (vma->vm_flags); + vma->vm_page_prot =pgprot_writecombine (vma->vm_page_prot); + +if (!vm_iomap_memory (vma, start, len)) +return 0 ; + } + vma->vm_page_prot =vm_get_page_prot (vma->vm_flags); -fb_pgprotect (file, vma, start); + vma->vm_page_prot =pgprot_noncached (vma->vm_page_prot);return vm_iomap_memory (vma, start, len); }
Perhaps it's time I tried to send that upstream properly :P
Signature · 3 lines
Ville Syrjälä [email protected] http://www.sci.fi/~syrjala/
Re: [PATCH v1 09/47] vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around
In reply to Andy LutomirskiQuoted 58 lines · Andy Lutomirski
Quoted 50 lines · Ville Syrjälä
Quoted 32 lines · Luis R. Rodriguez
Quoted 28 lines · Andy Lutomirski
Quoted 20 lines · Luis R. Rodriguez
Quoted 7 lines · Ville Syrjälä
Quoted 6 lines · Luis R. Rodriguez
drivers/video/fbdev/aty/atyfb_base.c +0
-0@@ -2630,21 +2630,10 @@ static int aty_init(struct fb_info *info)Quoted 11 lines
drivers/video/fbdev/aty/atyfb_base.c static int aty_init(struct fb_info *info) · line 2636
Quoted 9 lines
drivers/video/fbdev/aty/atyfb_base.c +2
-3#ifdef CONFIG_MTRR par->mtrr_aper =-1 ; - par->mtrr_reg =-1 ;if (!nomtrr) { -/* Cover the whole resource. */ - par->mtrr_aper =mtrr_add (par->res_start, par->res_size, + par->mtrr_aper =mtrr_add (info->fix.smem_start, + info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 );MTRRs need power of two size, so how is this supposed to work?
Quoted 6 lines
As per
mtrr_add_page()[0] the base and size are just supposed to be in units of 4 KiB, although the practice is to use powers of 2 in *some* drivers this is not standardized and by no means recorded as a requirement. Obviously powers of 2 will work too and you'd end up neatly aligned as well.mtrr_add()will usemtrr_check()to verify the the same requirement. Furthermore, as per my commit log message:Quoted 2 lines
Whatever the code may or may not do, the x86 architecture uses power-of-two MTRR sizes. So I'm confused.
Quoted 6 lines
There should be no confusion, I simply did not know that *was* the requirement for x86, if that is the case we should add a check for that and perhaps generalize a helper that does the power of two helper changes, the cleanest I found was the vesafb driver solution.
Thoughts?
The vesafb solution is bad since you'll only end up covering only the first 4MB of the framebuffer instead of the almost 8MB you want. Which in practice will mean throwing away half the VRAM since you really don't want the massive performance hit from accessing it as UC. And that would mean giving up decent display resolutions as well :(
And the other option of trying to cover the remainder with multiple ever smaller MTRRs doesn't work either since you'll run out of MTRRs very quickly.
Quoted 6 lines
This is precisely why I used the hole method in atyfb in the first place.
I don't really like the idea of any new mtrr code not supporting that use case, especially as these things tend to be present in older machines where PAT isn't an option.
Quoted 5 lines
According to the Intel SDM, volume 3, section 11.5.2.1, table 11-6, non-PAT CPUs that have a WC MTRR, PCD = 1, and PWT = 1 (aka UC) have an effective memory type of UC. Hence my suggestion to add
ioremap_x86_ucand/orset_memory_x86_ucto punch a UC hole in an otherwise WC MTRR-covered region.
OK I think I get it now.
And I take it this would hopefully only be used for non-PAT systems? Would there be a use case for PAT systems? I wonder if we can wrap this under some APIs to make it clean and hide this dirty thing behind the scenes, it seems a fragile and error prone and my hope would be that we won't need more specialization in this area for PAT systems.
Quoted 2 lines
ioremap_nocacheis UC- (even on non-PAT unless I misunderstood how this stuff works), soioremap_nocacheby itself isn't good enough.
Thanks for the clarification.
Luis
Re: [PATCH v1 09/47] vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around
In reply to Ville SyrjäläQuoted 50 lines · Ville Syrjälä
Quoted 32 lines · Luis R. Rodriguez
Quoted 28 lines · Andy Lutomirski
Quoted 20 lines · Luis R. Rodriguez
Quoted 7 lines · Ville Syrjälä
Quoted 6 lines · Luis R. Rodriguez
drivers/video/fbdev/aty/atyfb_base.c +0
-0@@ -2630,21 +2630,10 @@ static int aty_init(struct fb_info *info)Quoted 11 lines
drivers/video/fbdev/aty/atyfb_base.c static int aty_init(struct fb_info *info) · line 2636
Quoted 9 lines
drivers/video/fbdev/aty/atyfb_base.c +2
-3#ifdef CONFIG_MTRR par->mtrr_aper =-1 ; - par->mtrr_reg =-1 ;if (!nomtrr) { -/* Cover the whole resource. */ - par->mtrr_aper =mtrr_add (par->res_start, par->res_size, + par->mtrr_aper =mtrr_add (info->fix.smem_start, + info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 );MTRRs need power of two size, so how is this supposed to work?
Quoted 6 lines
As per
mtrr_add_page()[0] the base and size are just supposed to be in units of 4 KiB, although the practice is to use powers of 2 in *some* drivers this is not standardized and by no means recorded as a requirement. Obviously powers of 2 will work too and you'd end up neatly aligned as well.mtrr_add()will usemtrr_check()to verify the the same requirement. Furthermore, as per my commit log message:Quoted 2 lines
Whatever the code may or may not do, the x86 architecture uses power-of-two MTRR sizes. So I'm confused.
Quoted 6 lines
There should be no confusion, I simply did not know that *was* the requirement for x86, if that is the case we should add a check for that and perhaps generalize a helper that does the power of two helper changes, the cleanest I found was the vesafb driver solution.
Thoughts?
The vesafb solution is bad since you'll only end up covering only the first 4MB of the framebuffer instead of the almost 8MB you want. Which in practice will mean throwing away half the VRAM since you really don't want the massive performance hit from accessing it as UC. And that would mean giving up decent display resolutions as well :(
And the other option of trying to cover the remainder with multiple ever smaller MTRRs doesn't work either since you'll run out of MTRRs very quickly.
Quoted 6 lines
This is precisely why I used the hole method in atyfb in the first place.
I don't really like the idea of any new mtrr code not supporting that use case, especially as these things tend to be present in older machines where PAT isn't an option.
According to the Intel SDM, volume 3, section 11.5.2.1, table 11-6, non-PAT CPUs that have a WC MTRR, PCD = 1, and PWT = 1 (aka UC) have an effective memory type of UC. Hence my suggestion to add ioremap_x86_uc and/or set_memory_x86_uc to punch a UC hole in an otherwise WC MTRR-covered region.
ioremap_nocache is UC- (even on non-PAT unless I misunderstood how this stuff works), so ioremap_nocache by itself isn't good enough.
--Andy
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v1 09/47] vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around
In reply to Ville SyrjäläQuoted 38 lines · Ville Syrjälä
Quoted 37 lines · Luis R. Rodriguez
Quoted 28 lines · Andy Lutomirski
Quoted 20 lines · Luis R. Rodriguez
Quoted 7 lines · Ville Syrjälä
Quoted 6 lines · Luis R. Rodriguez
drivers/video/fbdev/aty/atyfb_base.c +0
-0@@ -2630,21 +2630,10 @@ static int aty_init(struct fb_info *info)Quoted 11 lines
drivers/video/fbdev/aty/atyfb_base.c static int aty_init(struct fb_info *info) · line 2636
Quoted 9 lines
drivers/video/fbdev/aty/atyfb_base.c +2
-3#ifdef CONFIG_MTRR par->mtrr_aper =-1 ; - par->mtrr_reg =-1 ;if (!nomtrr) { -/* Cover the whole resource. */ - par->mtrr_aper =mtrr_add (par->res_start, par->res_size, + par->mtrr_aper =mtrr_add (info->fix.smem_start, + info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 );MTRRs need power of two size, so how is this supposed to work?
Quoted 6 lines
As per
mtrr_add_page()[0] the base and size are just supposed to be in units of 4 KiB, although the practice is to use powers of 2 in *some* drivers this is not standardized and by no means recorded as a requirement. Obviously powers of 2 will work too and you'd end up neatly aligned as well.mtrr_add()will usemtrr_check()to verify the the same requirement. Furthermore, as per my commit log message:Quoted 2 lines
Whatever the code may or may not do, the x86 architecture uses power-of-two MTRR sizes. So I'm confused.
There should be no confusion, I simply did not know that *was* the requirement for x86, if that is the case we should add a check for that and perhaps generalize a helper that does the power of two helper changes, the cleanest I found was the vesafb driver solution.
Quoted 4 lines
Quoted 1 line
Thoughts?
The vesafb solution is bad since you'll only end up covering only the first 4MB of the framebuffer instead of the almost 8MB you want.
OK so the power of 2 requirement implicates us *having* to use a large MTRR that includes the MMIo region in the shared PCI case?
Andy, Ville, are we 100% certain about this power of two requirement? Is that for the base and size or just the size?
Luis
Re: [PATCH v1 09/47] vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around
In reply to Ville SyrjäläQuoted 38 lines · Ville Syrjälä
Quoted 37 lines · Luis R. Rodriguez
Quoted 28 lines · Andy Lutomirski
Quoted 20 lines · Luis R. Rodriguez
Quoted 7 lines · Ville Syrjälä
Quoted 6 lines · Luis R. Rodriguez
drivers/video/fbdev/aty/atyfb_base.c +0
-0@@ -2630,21 +2630,10 @@ static int aty_init(struct fb_info *info)Quoted 11 lines
drivers/video/fbdev/aty/atyfb_base.c static int aty_init(struct fb_info *info) · line 2636
Quoted 9 lines
drivers/video/fbdev/aty/atyfb_base.c +2
-3#ifdef CONFIG_MTRR par->mtrr_aper =-1 ; - par->mtrr_reg =-1 ;if (!nomtrr) { -/* Cover the whole resource. */ - par->mtrr_aper =mtrr_add (par->res_start, par->res_size, + par->mtrr_aper =mtrr_add (info->fix.smem_start, + info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 );MTRRs need power of two size, so how is this supposed to work?
Quoted 6 lines
As per
mtrr_add_page()[0] the base and size are just supposed to be in units of 4 KiB, although the practice is to use powers of 2 in *some* drivers this is not standardized and by no means recorded as a requirement. Obviously powers of 2 will work too and you'd end up neatly aligned as well.mtrr_add()will usemtrr_check()to verify the the same requirement. Furthermore, as per my commit log message:Quoted 2 lines
Whatever the code may or may not do, the x86 architecture uses power-of-two MTRR sizes. So I'm confused.
There should be no confusion, I simply did not know that *was* the requirement for x86, if that is the case we should add a check for that and perhaps generalize a helper that does the power of two helper changes, the cleanest I found was the vesafb driver solution.
Quoted 4 lines
Quoted 1 line
Thoughts?
The vesafb solution is bad since you'll only end up covering only the first 4MB of the framebuffer instead of the almost 8MB you want.
OK so the power of 2 requirement implicates us *having* to use a large MTRR that includes the MMIo region in the shared PCI case?
Andy, Ville, are we 100% certain about this power of two requirement? Is that for the base and size or just the size?
Luis
Re: [PATCH v1 09/47] vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around
In reply to Luis R. RodriguezQuoted 32 lines · Luis R. Rodriguez
Quoted 28 lines · Andy Lutomirski
Quoted 20 lines · Luis R. Rodriguez
Quoted 7 lines · Ville Syrjälä
Quoted 6 lines · Luis R. Rodriguez
drivers/video/fbdev/aty/atyfb_base.c +0
-0@@ -2630,21 +2630,10 @@ static int aty_init(struct fb_info *info)Quoted 11 lines
drivers/video/fbdev/aty/atyfb_base.c static int aty_init(struct fb_info *info) · line 2636
Quoted 9 lines
drivers/video/fbdev/aty/atyfb_base.c +2
-3#ifdef CONFIG_MTRR par->mtrr_aper =-1 ; - par->mtrr_reg =-1 ;if (!nomtrr) { -/* Cover the whole resource. */ - par->mtrr_aper =mtrr_add (par->res_start, par->res_size, + par->mtrr_aper =mtrr_add (info->fix.smem_start, + info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 );MTRRs need power of two size, so how is this supposed to work?
Quoted 6 lines
As per
mtrr_add_page()[0] the base and size are just supposed to be in units of 4 KiB, although the practice is to use powers of 2 in *some* drivers this is not standardized and by no means recorded as a requirement. Obviously powers of 2 will work too and you'd end up neatly aligned as well.mtrr_add()will usemtrr_check()to verify the the same requirement. Furthermore, as per my commit log message:Quoted 2 lines
Whatever the code may or may not do, the x86 architecture uses power-of-two MTRR sizes. So I'm confused.
Quoted 6 lines
There should be no confusion, I simply did not know that *was* the requirement for x86, if that is the case we should add a check for that and perhaps generalize a helper that does the power of two helper changes, the cleanest I found was the vesafb driver solution.
Thoughts?
The vesafb solution is bad since you'll only end up covering only the first 4MB of the framebuffer instead of the almost 8MB you want. Which in practice will mean throwing away half the VRAM since you really don't want the massive performance hit from accessing it as UC. And that would mean giving up decent display resolutions as well :(
And the other option of trying to cover the remainder with multiple ever smaller MTRRs doesn't work either since you'll run out of MTRRs very quickly.
This is precisely why I used the hole method in atyfb in the first place.
I don't really like the idea of any new mtrr code not supporting that use case, especially as these things tend to be present in older machines where PAT isn't an option.
Signature · 3 lines
Ville Syrjälä [email protected] http://www.sci.fi/~syrjala/
Re: [PATCH v1 09/47] vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around
In reply to Andy LutomirskiQuoted 28 lines · Andy Lutomirski
Quoted 20 lines · Luis R. Rodriguez
Quoted 7 lines · Ville Syrjälä
Quoted 6 lines · Luis R. Rodriguez
drivers/video/fbdev/aty/atyfb_base.c +0
-0@@ -2630,21 +2630,10 @@ static int aty_init(struct fb_info *info)Quoted 11 lines
drivers/video/fbdev/aty/atyfb_base.c static int aty_init(struct fb_info *info) · line 2636
Quoted 9 lines
drivers/video/fbdev/aty/atyfb_base.c +2
-3#ifdef CONFIG_MTRR par->mtrr_aper =-1 ; - par->mtrr_reg =-1 ;if (!nomtrr) { -/* Cover the whole resource. */ - par->mtrr_aper =mtrr_add (par->res_start, par->res_size, + par->mtrr_aper =mtrr_add (info->fix.smem_start, + info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 );MTRRs need power of two size, so how is this supposed to work?
Quoted 6 lines
As per
mtrr_add_page()[0] the base and size are just supposed to be in units of 4 KiB, although the practice is to use powers of 2 in *some* drivers this is not standardized and by no means recorded as a requirement. Obviously powers of 2 will work too and you'd end up neatly aligned as well.mtrr_add()will usemtrr_check()to verify the the same requirement. Furthermore, as per my commit log message:
Quoted 2 lines
Whatever the code may or may not do, the x86 architecture uses power-of-two MTRR sizes. So I'm confused.
There should be no confusion, I simply did not know that *was* the requirement for x86, if that is the case we should add a check for that and perhaps generalize a helper that does the power of two helper changes, the cleanest I found was the vesafb driver solution.
Thoughts?
Luis
Re: [PATCH v1 09/47] vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around
In reply to Luis R. RodriguezQuoted 20 lines · Luis R. Rodriguez
Quoted 7 lines · Ville Syrjälä
Quoted 6 lines · Luis R. Rodriguez
drivers/video/fbdev/aty/atyfb_base.c +0
-0@@ -2630,21 +2630,10 @@ static int aty_init(struct fb_info *info)Quoted 11 lines
drivers/video/fbdev/aty/atyfb_base.c static int aty_init(struct fb_info *info) · line 2636
Quoted 9 lines
drivers/video/fbdev/aty/atyfb_base.c +2
-3#ifdef CONFIG_MTRR par->mtrr_aper =-1 ; - par->mtrr_reg =-1 ;if (!nomtrr) { -/* Cover the whole resource. */ - par->mtrr_aper =mtrr_add (par->res_start, par->res_size, + par->mtrr_aper =mtrr_add (info->fix.smem_start, + info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 );MTRRs need power of two size, so how is this supposed to work?
Quoted 6 lines
As per
mtrr_add_page()[0] the base and size are just supposed to be in units of 4 KiB, although the practice is to use powers of 2 in *some* drivers this is not standardized and by no means recorded as a requirement. Obviously powers of 2 will work too and you'd end up neatly aligned as well.mtrr_add()will usemtrr_check()to verify the the same requirement. Furthermore, as per my commit log message:
Whatever the code may or may not do, the x86 architecture uses power-of-two MTRR sizes. So I'm confused.
--Andy
Quoted 26 lines
---
The last thing we do must do to remain sane is ensure we use theinfo->fix.smem_startandinfo->fix.smem_lenfor the framebuffer MTRR as we know that is always well adjusted. The *one* concern here would be if the MTRR is not in units of 4K__but__we already know that in the PCI case this cannot happen, in the shared space setting the MTRR would be up to0x7ff000and assuming a 4K page:;
0x7ff000/0x1000
2047Also, internally when MTRR is used
mtrr_add()will usemtrr_check()and that should splat a warning when the MTRR base and size are not compatible with what is expected for MTRR usage.
---If any of this is too risky we can use the
__arch_phys_wc_add()(or as Andy suggested perhaps use set_page_* stuff, although I am still evaluating this) but I did this change to show the effort required for a change when the registers / framebuffer is on the same PCI BAR but at different offsets.[0]
scripts/kernel-doc-man -functionmtrr_add_pagearch/x86/kernel/cpu/mtrr/main.c| nroff -man | lessLuis
Signature · 7 lines
Andy Lutomirski AMA Capital Management, LLC _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v1 09/47] vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around
In reply to Ville SyrjäläQuoted 7 lines · Ville Syrjälä
Quoted 6 lines · Luis R. Rodriguez
drivers/video/fbdev/aty/atyfb_base.c +0
-0@@ -2630,21 +2630,10 @@ static int aty_init(struct fb_info *info)
Quoted 11 lines
drivers/video/fbdev/aty/atyfb_base.c static int aty_init(struct fb_info *info) · line 2636
Quoted 9 lines
drivers/video/fbdev/aty/atyfb_base.c +2
-3#ifdef CONFIG_MTRR par->mtrr_aper =-1 ; - par->mtrr_reg =-1 ;if (!nomtrr) { -/* Cover the whole resource. */ - par->mtrr_aper =mtrr_add (par->res_start, par->res_size, + par->mtrr_aper =mtrr_add (info->fix.smem_start, + info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 );MTRRs need power of two size, so how is this supposed to work?
As per mtrr_add_page() [0] the base and size are just supposed to be in units of 4 KiB, although the practice is to use powers of 2 in *some* drivers this is not standardized and by no means recorded as a requirement. Obviously powers of 2 will work too and you'd end up neatly aligned as well. mtrr_add() will use mtrr_check() to verify the the same requirement. Furthermore, as per my commit log message:
---
The last thing we do must do to remain sane is ensure we use the info->fix.smem_start and info->fix.smem_len for the framebuffer MTRR as we know that is always well adjusted. The *one* concern here would be if the MTRR is not in units of 4K __but__ we already know that in the PCI case this cannot happen, in the shared space setting the MTRR would be up to 0x7ff000 and assuming a 4K page:
; 0x7ff000 / 0x1000
2047
Also, internally when MTRR is used mtrr_add() will use mtrr_check() and that should splat a warning when the MTRR base and size are not compatible with what is expected for MTRR usage.
---
If any of this is too risky we can use the __arch_phys_wc_add() (or as Andy suggested perhaps use set_page_* stuff, although I am still evaluating this) but I did this change to show the effort required for a change when the registers / framebuffer is on the same PCI BAR but at different offsets.
[0] scripts/kernel-doc -man -function mtrr_add_page arch/x86/kernel/cpu/mtrr/main.c | nroff -man | less
Luis
Re: [PATCH v1 09/47] vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around
In reply to Luis R. RodriguezQuoted 5 lines · Luis R. Rodriguez
drivers/video/fbdev/aty/atyfb_base.c +0
-0
drivers/video/fbdev/aty/atyfb_base.c static int aty_init(struct fb_info *info) · line 2636
Quoted 10 lines
drivers/video/fbdev/aty/atyfb_base.c +2
-3@@ -2630,21 +2630,10 @@ static int aty_init(struct fb_info *info)#ifdef CONFIG_MTRR par->mtrr_aper =-1 ; - par->mtrr_reg =-1 ;if (!nomtrr) { -/* Cover the whole resource. */ - par->mtrr_aper =mtrr_add (par->res_start, par->res_size, + par->mtrr_aper =mtrr_add (info->fix.smem_start, + info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 );
MTRRs need power of two size, so how is this supposed to work?
Quoted 68 lines
drivers/video/fbdev/aty/atyfb_base.c +4
-19-if (par->mtrr_aper >=0 && !par->aux_start) { -/* Make a hole for mmio. */ - par->mtrr_reg =mtrr_add (par->res_start +0x800000 - -GUI_RESERVE ,GUI_RESERVE , -MTRR_TYPE_UNCACHABLE ,1 ); -if (par->mtrr_reg <0 ) { -mtrr_del (par->mtrr_aper,0 ,0 ); - par->mtrr_aper =-1 ; - } - } }#endif @@ -2776,10 +2765,6 @@ aty_init_exit: par->pll_ops->set_pll (info, &par->saved_pll);#ifdef CONFIG_MTRR -if (par->mtrr_reg >=0 ) { -mtrr_del (par->mtrr_reg,0 ,0 ); - par->mtrr_reg =-1 ; - }if (par->mtrr_aper >=0 ) {mtrr_del (par->mtrr_aper,0 ,0 ); par->mtrr_aper =-1 ;@@ -3466,7 +3451,7 @@ static int atyfb_setup_generic(struct pci_dev *pdev, struct fb_info *info, } info->fix.mmio_start = raddr; - par->ati_regbase =ioremap (info->fix.mmio_start,0x1000 ); + par->ati_regbase =ioremap_nocache (info->fix.mmio_start,0x1000 );if (par->ati_regbase ==NULL )return -ENOMEM ;@@ -3491,6 +3476,8 @@ static int atyfb_setup_generic(struct pci_dev *pdev, struct fb_info *info, info->fix.smem_start = addr; info->fix.smem_len =0x800000 ; +aty_fudge_framebuffer_len (info); + info->screen_base =ioremap (info->fix.smem_start, info->fix.smem_len);if (info->screen_base ==NULL ) { ret = -ENOMEM ;@@ -3563,6 +3550,7 @@ static int atyfb_pci_probe(struct pci_dev *pdev,return -ENOMEM ; } par = info->par; + par->bus_type =PCI ; info->fix = atyfb_fix; info->device = &pdev->dev; par->pci_id = pdev->device;@@ -3732,10 +3720,6 @@ static void atyfb_remove(struct fb_info *info)#endif #ifdef CONFIG_MTRR -if (par->mtrr_reg >=0 ) { -mtrr_del (par->mtrr_reg,0 ,0 ); - par->mtrr_reg =-1 ; - }if (par->mtrr_aper >=0 ) {mtrr_del (par->mtrr_aper,0 ,0 ); par->mtrr_aper =-1 ;Signature · 6 lines
2.3.2.209.gd67f9d5.dirty -- To unsubscribe from this list: send the line "unsubscribe linux-fbdev" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 3 lines
Ville Syrjälä [email protected] http://www.sci.fi/~syrjala/
PATCH 9/47 vidoe: fbdev: atyfb: remove and fix MTRR MMIO "hole" work around
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
The atyfb driver uses an MTRR work around since some cards use the same PCI BAR for the framebuffer and MMIO. In such cards the last page is used for MMIO, the rest for the framebuffer, so on those cards we ioremap() the MMIO page alone, then again ioremap() the full framebuffer including the MMIO space *and* ___then___ use an MTRR with MTRR_TYPE_WRCOMB on the full PCI BAR... and finally "hole" in an MTRR_TYPE_UNCACHABLE MTRR only for MMIO.
This is a terrible fucking work around, and should by no means be necessary however evidence through a large series of conversion of drivers to ioremap_wc() for the framebuffer shows that around the time MTRR started becoming popular devices did not have things lined up for easily separating the framebuffer and MMIO register access. In some cases a driver requires significant intrusive changes in order to make the split for an ioremap() for MMIO registers and another ioremap_wc() for the framebuffer, at other times a bit of careful study of the driver suffices. This example driver falls into the later category.
We can replace the MTRR MTRR_TYPE_UNCACHABLE
work around by using ioremap_nocache(), the length of the MMIO space should already be correct. The other part we need to correct is ensuring we ioremap() for the framebuffer only the required size. Since the ioremap() happens early on probe for PCI devices before aty_init() where we typically adjust the length and know how to do it, we can fix this by pegging the bus type as PCI on PCI probe, and finally fudging and framebuffer length just as we do on aty_init().
The last thing we do must do to remain sane is ensure we use the info->fix.smem_start and info->fix.smem_len for the framebuffer MTRR as we know that is always well adjusted. The *one* concern here would be if the MTRR is not in units of 4K __but__ we already know that in the PCI case this cannot happen, in the shared space setting the MTRR would be up to 0x7ff000 and assuming a 4K page:
; 0x7ff000 / 0x1000
2047
Also, internally when MTRR is used mtrr_add() will use mtrr_check() and that should splat a warning when the MTRR base and size are not compatible with what is expected for MTRR usage.
This fix lets us nuke the MTRR_TYPE_UNCACHABLE MTRR "hole".
--- drivers/video/fbdev/aty/atyfb.h | 1 - drivers/video/fbdev/aty/atyfb_base.c | 28 ++++++---------------------- 2 files changed, 6 insertions(+), 23 deletions(-)
drivers/video/fbdev/aty/atyfb.h +0 -1
@@ -184,7 +184,6 @@ struct atyfb_par {spinlock_t int_lock;#ifdef CONFIG_MTRR int mtrr_aper; -int mtrr_reg;#endif u32 mem_cntl;struct crtc saved_crtc;
drivers/video/fbdev/aty/atyfb_base.c +6 -22
@@ -2630,21 +2630,10 @@ static int aty_init(struct fb_info *info)#ifdef CONFIG_MTRR par->mtrr_aper =-1 ; - par->mtrr_reg =-1 ;if (!nomtrr) { -/* Cover the whole resource. */ - par->mtrr_aper =mtrr_add (par->res_start, par->res_size, + par->mtrr_aper =mtrr_add (info->fix.smem_start, + info->fix.smem_len,MTRR_TYPE_WRCOMB ,1 ); -if (par->mtrr_aper >=0 && !par->aux_start) { -/* Make a hole for mmio. */ - par->mtrr_reg =mtrr_add (par->res_start +0x800000 - -GUI_RESERVE ,GUI_RESERVE , -MTRR_TYPE_UNCACHABLE ,1 ); -if (par->mtrr_reg <0 ) { -mtrr_del (par->mtrr_aper,0 ,0 ); - par->mtrr_aper =-1 ; - } - } }#endif
@@ -2776,10 +2765,6 @@ aty_init_exit: par->pll_ops->set_pll (info, &par->saved_pll);#ifdef CONFIG_MTRR -if (par->mtrr_reg >=0 ) { -mtrr_del (par->mtrr_reg,0 ,0 ); - par->mtrr_reg =-1 ; - }if (par->mtrr_aper >=0 ) {mtrr_del (par->mtrr_aper,0 ,0 ); par->mtrr_aper =-1 ;
@@ -3466,7 +3451,7 @@ static int atyfb_setup_generic(struct pci_dev *pdev, struct fb_info *info, } info->fix.mmio_start = raddr; - par->ati_regbase =ioremap (info->fix.mmio_start,0x1000 ); + par->ati_regbase =ioremap_nocache (info->fix.mmio_start,0x1000 );if (par->ati_regbase ==NULL )return -ENOMEM ;
@@ -3491,6 +3476,8 @@ static int atyfb_setup_generic(struct pci_dev *pdev, struct fb_info *info, info->fix.smem_start = addr; info->fix.smem_len =0x800000 ; +aty_fudge_framebuffer_len (info); + info->screen_base =ioremap (info->fix.smem_start, info->fix.smem_len);if (info->screen_base ==NULL ) { ret = -ENOMEM ;
@@ -3563,6 +3550,7 @@ static int atyfb_pci_probe(struct pci_dev *pdev,return -ENOMEM ; } par = info->par; + par->bus_type =PCI ; info->fix = atyfb_fix; info->device = &pdev->dev; par->pci_id = pdev->device;
@@ -3732,10 +3720,6 @@ static void atyfb_remove(struct fb_info *info)#endif #ifdef CONFIG_MTRR -if (par->mtrr_reg >=0 ) { -mtrr_del (par->mtrr_reg,0 ,0 ); - par->mtrr_reg =-1 ; - }if (par->mtrr_aper >=0 ) {mtrr_del (par->mtrr_aper,0 ,0 ); par->mtrr_aper =-1 ;
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
PATCH 10/47 video: fbdev: atyfb: use arch_phys_wc_add() and ioremap_wc()
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
This driver uses the same area for MTRR as for the ioremap(). Convert the driver from using the x86 specific MTRR code to the architecture agnostic arch_phys_wc_add(). arch_phys_wc_add() will avoid MTRR if write-combining is available, in order to take advantage of that also ensure the ioremap'd area is requested as write-combining.
There are a few motivations for this:
a) Take advantage of PAT when available
b) Help bury MTRR code away, MTRR is architecture specific and on x86 its replaced by PAT
c) Help with the goal of eventually using _PAGE_CACHE_UC over _PAGE_CACHE_UC_MINUS on x86 on ioremap_nocache() (de33c442e)
The conversion done is expressed by the following Coccinelle SmPL patch, it additionally required manual intervention to address all the #ifdery and removal of redundant things which arch_phys_wc_add() already addresses such as verbose message about when MTRR fails and doing nothing when we didn't get an MTRR.
@ mtrr_found @
expression index, base, size;
@@
-index = mtrr_add(base, size, MTRR_TYPE_WRCOMB, 1); +index = arch_phys_wc_add(base, size);
@ mtrr_rm depends on mtrr_found @
expression mtrr_found.index, mtrr_found.base, mtrr_found.size; @@
-mtrr_del(index, base, size);
+arch_phys_wc_del(index);
@ mtrr_rm_zero_arg depends on mtrr_found @
expression mtrr_found.index;
@@
-mtrr_del(index, 0, 0);
+arch_phys_wc_del(index);
@ mtrr_rm_fb_info depends on mtrr_found @
struct fb_info *info;
expression mtrr_found.index;
@@
-mtrr_del(index, info->fix.smem_start, info->fix.smem_len); +arch_phys_wc_del(index);
@ ioremap_replace_nocache depends on mtrr_found @
struct fb_info *info;
expression base, size;
@@
-info->screen_base = ioremap_nocache(base, size);
+info->screen_base = ioremap_wc(base, size);
@ ioremap_replace_default depends on mtrr_found @
struct fb_info *info;
expression base, size;
@@
-info->screen_base = ioremap(base, size);
+info->screen_base = ioremap_wc(base, size);
--- drivers/video/fbdev/aty/atyfb.h | 4 +--- drivers/video/fbdev/aty/atyfb_base.c | 41 +++++++++--------------------------- 2 files changed, 11 insertions(+), 34 deletions(-)
drivers/video/fbdev/aty/atyfb.h +1 -3
@@ -182,9 +182,7 @@ struct atyfb_par {unsigned long irq_flags;unsigned int irq;spinlock_t int_lock; -#ifdef CONFIG_MTRR -int mtrr_aper; -#endif +int wc_cookie;u32 mem_cntl;struct crtc saved_crtc;union aty_pll saved_pll;
drivers/video/fbdev/aty/atyfb_base.c +10 -31
98 lines not on this page · raw message
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
PATCH 10/47 video: fbdev: atyfb: use arch_phys_wc_add() and ioremap_wc()
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
This driver uses the same area for MTRR as for the ioremap(). Convert the driver from using the x86 specific MTRR code to the architecture agnostic arch_phys_wc_add(). arch_phys_wc_add() will avoid MTRR if write-combining is available, in order to take advantage of that also ensure the ioremap'd area is requested as write-combining.
There are a few motivations for this:
a) Take advantage of PAT when available
b) Help bury MTRR code away, MTRR is architecture specific and on x86 its replaced by PAT
c) Help with the goal of eventually using _PAGE_CACHE_UC over _PAGE_CACHE_UC_MINUS on x86 on ioremap_nocache() (de33c442e)
The conversion done is expressed by the following Coccinelle SmPL patch, it additionally required manual intervention to address all the #ifdery and removal of redundant things which arch_phys_wc_add() already addresses such as verbose message about when MTRR fails and doing nothing when we didn't get an MTRR.
@ mtrr_found @
expression index, base, size;
@@
-index = mtrr_add(base, size, MTRR_TYPE_WRCOMB, 1); +index = arch_phys_wc_add(base, size);
@ mtrr_rm depends on mtrr_found @
expression mtrr_found.index, mtrr_found.base, mtrr_found.size; @@
-mtrr_del(index, base, size);
+arch_phys_wc_del(index);
@ mtrr_rm_zero_arg depends on mtrr_found @
expression mtrr_found.index;
@@
-mtrr_del(index, 0, 0);
+arch_phys_wc_del(index);
@ mtrr_rm_fb_info depends on mtrr_found @
struct fb_info *info;
expression mtrr_found.index;
@@
-mtrr_del(index, info->fix.smem_start, info->fix.smem_len); +arch_phys_wc_del(index);
@ ioremap_replace_nocache depends on mtrr_found @
struct fb_info *info;
expression base, size;
@@
-info->screen_base = ioremap_nocache(base, size);
+info->screen_base = ioremap_wc(base, size);
@ ioremap_replace_default depends on mtrr_found @
struct fb_info *info;
expression base, size;
@@
-info->screen_base = ioremap(base, size);
+info->screen_base = ioremap_wc(base, size);
--- drivers/video/fbdev/aty/atyfb.h | 4 +--- drivers/video/fbdev/aty/atyfb_base.c | 41 +++++++++--------------------------- 2 files changed, 11 insertions(+), 34 deletions(-)
drivers/video/fbdev/aty/atyfb.h +1 -3
@@ -182,9 +182,7 @@ struct atyfb_par {unsigned long irq_flags;unsigned int irq;spinlock_t int_lock; -#ifdef CONFIG_MTRR -int mtrr_aper; -#endif +int wc_cookie;u32 mem_cntl;struct crtc saved_crtc;union aty_pll saved_pll;
drivers/video/fbdev/aty/atyfb_base.c +10 -31
98 lines not on this page · raw message
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
PATCH 11/47 IB/qib: add acounting for MTRR
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
There is no good reason not to, we eventually delete it as well.
--- drivers/infiniband/hw/qib/qib_wc_x86_64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/hw/qib/qib_wc_x86_64.c +1 -1
@@ -118,7 +118,7 @@ int qib_enable_wc(struct qib_devdata *dd)if (!ret) {int cookie; - cookie =mtrr_add (pioaddr, piolen,MTRR_TYPE_WRCOMB ,0 ); + cookie =mtrr_add (pioaddr, piolen,MTRR_TYPE_WRCOMB ,1 );if (cookie <0 ) { { qib_devinfo(dd->pcidev,
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
PATCH 11/47 IB/qib: add acounting for MTRR
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
There is no good reason not to, we eventually delete it as well.
--- drivers/infiniband/hw/qib/qib_wc_x86_64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/hw/qib/qib_wc_x86_64.c +1 -1
@@ -118,7 +118,7 @@ int qib_enable_wc(struct qib_devdata *dd)if (!ret) {int cookie; - cookie =mtrr_add (pioaddr, piolen,MTRR_TYPE_WRCOMB ,0 ); + cookie =mtrr_add (pioaddr, piolen,MTRR_TYPE_WRCOMB ,1 );if (cookie <0 ) { { qib_devinfo(dd->pcidev,
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
PATCH 12/47 IB/qib: use arch_phys_wc_add()
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
This driver already makes use of ioremap_wc() on PIO buffers, so convert it to use arch_phys_wc_add().
--- drivers/infiniband/hw/qib/qib_wc_x86_64.c | 31 ++++--------------------------- 1 file changed, 4 insertions(+), 27 deletions(-)
drivers/infiniband/hw/qib/qib_wc_x86_64.c +4 -27
@@ -116,21 +116,9 @@ int qib_enable_wc(struct qib_devdata *dd) }if (!ret) { -int cookie; - - cookie =mtrr_add (pioaddr, piolen,MTRR_TYPE_WRCOMB ,1 ); -if (cookie <0 ) { - { -qib_devinfo (dd->pcidev, -"mtrr_add() WC for PIO bufs failed (%d)\n" , - cookie); - ret = -EINVAL ; - } - }else { - dd->wc_cookie = cookie; - dd->wc_base = (unsigned long ) pioaddr; - dd->wc_len = (unsigned long ) piolen; - } + dd->wc_cookie =arch_phys_wc_add (pioaddr, piolen); +if (dd->wc_cookie <0 ) + ret = -EINVAL ; }return ret;
@@ -142,18 +130,7 @@ int qib_enable_wc(struct qib_devdata *dd)*/ void qib_disable_wc (struct qib_devdata *dd) { -if (dd->wc_cookie) { -int r; - - r =mtrr_del (dd->wc_cookie, dd->wc_base, - dd->wc_len); -if (r <0 ) -qib_devinfo (dd->pcidev, -"mtrr_del(%lx, %lx, %lx) failed: %d\n" , - dd->wc_cookie, dd->wc_base, - dd->wc_len, r); - dd->wc_cookie =0 ;/* even on failure */ - } +arch_phys_wc_del (dd->wc_cookie); }/**
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
PATCH 13/47 IB/ipath: add counting for MTRR
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
There is no good reason not to, we eventually delete it as well.
--- drivers/infiniband/hw/ipath/ipath_wc_x86_64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/hw/ipath/ipath_wc_x86_64.c +1 -1
@@ -127,7 +127,7 @@ int ipath_enable_wc(struct ipath_devdata *dd)"(addr %llx, len=0x%llx)\n" , (unsigned long long ) pioaddr, (unsigned long long) piolen); - cookie =mtrr_add (pioaddr, piolen,MTRR_TYPE_WRCOMB ,0 ); + cookie =mtrr_add (pioaddr, piolen,MTRR_TYPE_WRCOMB ,1 );if (cookie <0 ) { { dev_info(&dd->pcidev->dev,
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
PATCH 13/47 IB/ipath: add counting for MTRR
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
There is no good reason not to, we eventually delete it as well.
--- drivers/infiniband/hw/ipath/ipath_wc_x86_64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/hw/ipath/ipath_wc_x86_64.c +1 -1
@@ -127,7 +127,7 @@ int ipath_enable_wc(struct ipath_devdata *dd)"(addr %llx, len=0x%llx)\n" , (unsigned long long ) pioaddr, (unsigned long long) piolen); - cookie =mtrr_add (pioaddr, piolen,MTRR_TYPE_WRCOMB ,0 ); + cookie =mtrr_add (pioaddr, piolen,MTRR_TYPE_WRCOMB ,1 );if (cookie <0 ) { { dev_info(&dd->pcidev->dev,
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
PATCH 14/47 IB/ipath: use __arch_phys_wc_add()
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
This driver sadly does not have the MMIO registers and WC desired areas (PIO buffers in this case) properly split up and addressing a split is considerable work, as such this such requires using the __arch_phys_wc_add() call to ensure write combining is enforced using MTRR on x86 even when PAT is available.
--- drivers/infiniband/hw/ipath/ipath_driver.c | 7 ++-- drivers/infiniband/hw/ipath/ipath_kernel.h | 4 +-- drivers/infiniband/hw/ipath/ipath_wc_x86_64.c | 47 ++++++++++----------------- 3 files changed, 20 insertions(+), 38 deletions(-)
drivers/infiniband/hw/ipath/ipath_driver.c +2 -5
@@ -542,6 +542,7 @@ static int ipath_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) dd->ipath_kregbase =__ioremap (addr, len, (_PAGE_NO_CACHE|_PAGE_WRITETHRU));#else +/* XXX: split pio on a separate ioremap_wc() */ dd->ipath_kregbase =ioremap_nocache (addr, len);#endif
@@ -587,12 +588,8 @@ static int ipath_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) ret =ipath_enable_wc (dd); -if (ret) { -ipath_dev_err (dd,"Write combining not enabled " -"(err %d): performance may be poor\n" , - -ret); +if (ret) ret =0 ; - }ipath_verify_pioperf (dd);
drivers/infiniband/hw/ipath/ipath_kernel.h +1 -3
@@ -463,9 +463,7 @@ struct ipath_devdata {/* offset in HT config space of slave/primary interface block */ u8 ipath_ht_slave_off;/* for write combining settings */ -unsigned long ipath_wc_cookie; -unsigned long ipath_wc_base; -unsigned long ipath_wc_len; +int wc_cookie;/* ref count for each pkey */ atomic_t ipath_pkeyrefs[4 ];/* shadow copy of struct page *'s for exp tid pages */
drivers/infiniband/hw/ipath/ipath_wc_x86_64.c +17 -30
67 lines not on this page · raw message
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
PATCH 15/47 media: ivtv: use __arch_phys_wc_add()
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
Sadly this driver requires a bit of work in order
to use ioremap_wc() on the range currently used
for MTRR write-combining. We'd need to ensure twoioremap() calls are done. Annotate this.
--- drivers/media/pci/ivtv/ivtvfb.c | 51 +++++++++++------------------------------ 1 file changed, 14 insertions(+), 37 deletions(-)
drivers/media/pci/ivtv/ivtvfb.c +14 -37
@@ -44,10 +44,6 @@#include <linux/ivtvfb.h> #include <linux/slab.h> -#ifdef CONFIG_MTRR -#include <asm/mtrr.h> -#endif -#include "ivtv-driver.h" #include "ivtv-cards.h" #include "ivtv-i2c.h"
@@ -155,12 +151,11 @@ struct osd_info {/* Buffer size */ u32 video_buffer_size; -#ifdef CONFIG_MTRR /* video_base rounded down as required by hardware MTRRs */ unsigned long fb_start_aligned_physaddr;/* video_base rounded up as required by hardware MTRRs */ unsigned long fb_end_aligned_physaddr; -#endif +int wc_cookie;/* Store the buffer offset */ int set_osd_coords_x;
@@ -1099,6 +1094,8 @@ static int ivtvfb_init_vidmode(struct ivtv *itv)static int ivtvfb_init_io (struct ivtv *itv) {struct osd_info *oi = itv->osd_info; +/* Find the largest power of two that maps the whole buffer */ +int size_shift =31 ;mutex_lock (&itv->serialize_lock);if (ivtv_init_on_first_open (itv)) {
@@ -1132,29 +1129,16 @@ static int ivtvfb_init_io(struct ivtv *itv) oi->video_pbase, oi->video_vbase, oi->video_buffer_size / 1024); -#ifdef CONFIG_MTRR - { -/* Find the largest power of two that maps the whole buffer */ -int size_shift =31 ; - -while (!(oi->video_buffer_size & (1 << size_shift))) { - size_shift--; - } - size_shift++; - oi->fb_start_aligned_physaddr = oi->video_pbase & ~((1 << size_shift) -1 ); - oi->fb_end_aligned_physaddr = oi->video_pbase + oi->video_buffer_size; - oi->fb_end_aligned_physaddr += (1 << size_shift) -1 ; - oi->fb_end_aligned_physaddr &= ~((1 << size_shift) -1 ); -if (mtrr_add (oi->fb_start_aligned_physaddr, - oi->fb_end_aligned_physaddr - oi->fb_start_aligned_physaddr, -MTRR_TYPE_WRCOMB ,1 ) <0 ) { -IVTVFB_INFO ("disabled mttr\n" ); - oi->fb_start_aligned_physaddr =0 ; - oi->fb_end_aligned_physaddr =0 ; - } - } -#endif - +while (!(oi->video_buffer_size & (1 << size_shift))) + size_shift--; + size_shift++; + oi->fb_start_aligned_physaddr = oi->video_pbase & ~((1 << size_shift) -1 ); + oi->fb_end_aligned_physaddr = oi->video_pbase + oi->video_buffer_size; + oi->fb_end_aligned_physaddr += (1 << size_shift) -1 ; + oi->fb_end_aligned_physaddr &= ~((1 << size_shift) -1 ); + oi->wc_cookie =__arch_phys_wc_add (oi->fb_start_aligned_physaddr, + oi->fb_end_aligned_physaddr - + oi->fb_start_aligned_physaddr);/* Blank the entire osd. */ memset_io (oi->video_vbase,0 , oi->video_buffer_size);
@@ -1172,14 +1156,7 @@ static void ivtvfb_release_buffers (struct ivtv *itv)/* Release pseudo palette */ kfree (oi->ivtvfb_info.pseudo_palette); - -#ifdef CONFIG_MTRR -if (oi->fb_end_aligned_physaddr) { -mtrr_del (-1 , oi->fb_start_aligned_physaddr, - oi->fb_end_aligned_physaddr - oi->fb_start_aligned_physaddr); - } -#endif - +arch_phys_wc_del (oi->wc_cookie);kfree (oi); itv->osd_info =NULL ; }
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
PATCH 16/47 fusion: use __arch_phys_wc_add()
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
If and when this gets enabled the driver should address using ioremap_wc() on the same area, that could require a bit of work as it would mean a split with two ioremap'd areas. Annotate this.
--- drivers/message/fusion/mptbase.c | 19 ++++--------------- drivers/message/fusion/mptbase.h | 2 +- 2 files changed, 5 insertions(+), 16 deletions(-)
drivers/message/fusion/mptbase.c +4 -15
@@ -59,10 +59,6 @@#include <linux/delay.h> #include <linux/interrupt.h> /* needed for in_interrupt() proto */ #include <linux/dma-mapping.h> -#include <asm/io.h> -#ifdef CONFIG_MTRR -#include <asm/mtrr.h> -#endif #include <linux/kthread.h> #include <scsi/scsi_host.h>
@@ -2820,11 +2816,8 @@ mpt_adapter_dispose(MPT_ADAPTER *ioc)pci_disable_device (ioc->pcidev);pci_release_selected_regions (ioc->pcidev, ioc->bars); -#if defined(CONFIG_MTRR ) &&0 -if (ioc->mtrr_reg >0 ) { -mtrr_del (ioc->mtrr_reg,0 ,0 ); -dprintk (ioc,printk (MYIOC_s_INFO_FMT"MTRR region de-registered\n" , ioc->name)); - } +#if 0 +__arch_phys_wc_del (ioc->wc_cookie);#endif /* Zap the adapter lookup ptr! */
@@ -4512,17 +4505,13 @@ PrimeIocFifos(MPT_ADAPTER *ioc) ioc->req_frames_low_dma = (u32) (alloc_dma &0xFFFFFFFF ); -#if defined(CONFIG_MTRR ) &&0 +#if 0 /* * Enable Write Combining MTRR for IOC's memory region. * (at least as much as we can; "size and base must be * multiples of 4 kiB" */ - ioc->mtrr_reg =mtrr_add (ioc->req_frames_dma, - sz, -MTRR_TYPE_WRCOMB ,1 ); -dprintk (ioc,printk (MYIOC_s_DEBUG_FMT"MTRR region registered (base:size=%08x:%x)\n" , - ioc->name, ioc->req_frames_dma, sz)); + ioc->wc_cookie =arch_phys_wc_add (ioc->req_frames_dma, sz);#endif for (i =0 ; i < ioc->req_depth; i++) {
drivers/message/fusion/mptbase.h +1 -1
@@ -671,7 +671,7 @@ typedef struct _MPT_ADAPTERu8 *HostPageBuffer;/* SAS - host page buffer support */ u32 HostPageBuffer_sz;dma_addr_t HostPageBuffer_dma; -int mtrr_reg; +int wc_cookie;struct pci_dev *pcidev;/* struct pci_dev pointer */ int bars;/* bitmask of BAR's that must be configured */ int msi_enable;
Signature · 1 line
2.3.2.209.gd67f9d5.dirty
PATCH 16/47 fusion: use __arch_phys_wc_add()
In reply to Luis R. RodriguezFrom: "Luis R. Rodriguez" <[email protected]>
If and when this gets enabled the driver should address using ioremap_wc() on the same area, that could require a bit of work as it would mean a split with two ioremap'd areas. Annotate this.
--- drivers/message/fusion/mptbase.c | 19 ++++--------------- drivers/message/fusion/mptbase.h | 2 +- 2 files changed, 5 insertions(+), 16 deletions(-)
drivers/message/fusion/mptbase.c +4 -15
@@ -59,10 +59,6 @@#include <linux/delay.h> #include <linux/interrupt.h> /* needed for in_interrupt() proto */ #include <linux/dma-mapping.h> -#include <asm/io.h> -#ifdef CONFIG_MTRR -#include <asm/mtrr.h> -#endif #include <linux/kthread.h> #include <scsi/scsi_host.h>
@@ -2820,11 +2816,8 @@ mpt_adapter_dispose(MPT_ADAPTER *ioc)pci_disable_device (ioc->pcidev);pci_release_selected_regions (ioc->pcidev, ioc->bars); -#if defined(CONFIG_MTRR ) &&0 -if (ioc->mtrr_reg >0 ) { -mtrr_del (ioc->mtrr_reg,0 ,0 ); -dprintk (ioc,printk (MYIOC_s_INFO_FMT"MTRR region de-registered\n" , ioc->name)); - } +#if 0 +__arch_phys_wc_del (ioc->wc_cookie);#endif /* Zap the adapter lookup ptr! */
@@ -4512,17 +4505,13 @@ PrimeIocFifos(MPT_ADAPTER *ioc) ioc->req_frames_low_dma = (u32) (alloc_dma &0xFFFFFFFF ); -#if defined(CONFIG_MTRR ) &&0 +#if 0 /* * Enable Write Combining MTRR for IOC's memory region. * (at least as much as we can; "size and base must be * multiples of 4 kiB" */ - ioc->mtrr_reg =mtrr_add (ioc->req_frames_dma, - sz, -MTRR_TYPE_WRCOMB ,1 ); -dprintk (ioc,printk (MYIOC_s_DEBUG_FMT"MTRR region registered (base:size=%08x:%x)\n" , - ioc->name, ioc->req_frames_dma, sz)); + ioc->wc_cookie =arch_phys_wc_add (ioc->req_frames_dma, sz);#endif for (i =0 ; i < ioc->req_depth; i++) {
drivers/message/fusion/mptbase.h +1 -1
@@ -671,7 +671,7 @@ typedef struct _MPT_ADAPTERu8 *HostPageBuffer;/* SAS - host page buffer support */ u32 HostPageBuffer_sz;dma_addr_t HostPageBuffer_dma; -int mtrr_reg; +int wc_cookie;struct pci_dev *pcidev;/* struct pci_dev pointer */ int bars;/* bitmask of BAR's that must be configured */ int msi_enable;
Signature · 1 line
2.3.2.209.gd67f9d5.dirty