Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

video: fbdev: intelfb: use arch_phys_wc_add() and ioremap_wc()

Although this driver gives the framebuffer layer a different
size for the framebuffer it uses the entire aperture PCI BAR
size for the MTRR. Since the framebuffer is included in that
range and MTRR was used on the entire PCI BAR WC will have
been preferred on that range as well. This propagates the
WC preference on the same entire PCI BAR.

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() (see commit
de33c442e titled "x86 PAT: fix performance drop for glx,
use UC minus for ioremap(), ioremap_nocache() and
pci_mmap_page_range()")

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);

Generated-by: Coccinelle SmPL
Cc: Maik Broemme <mbroemme@plusserver.de>
Cc: Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com>
Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>
Cc: Suresh Siddha <sbsiddha@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Juergen Gross <jgross@suse.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Dave Airlie <airlied@redhat.com>
Cc: Antonino Daplas <adaplas@gmail.com>
Cc: linux-fbdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Luis R. Rodriguez <mcgrof@suse.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>

authored by

Luis R. Rodriguez and committed by
Tomi Valkeinen
78084dcf 05314098

+5 -37
+1 -3
drivers/video/fbdev/intelfb/intelfb.h
··· 285 285 /* use a gart reserved fb mem */ 286 286 u8 fbmem_gart; 287 287 288 - /* mtrr support */ 289 - int mtrr_reg; 290 - u32 has_mtrr; 288 + int wc_cookie; 291 289 292 290 /* heap data */ 293 291 struct intelfb_heap_data aperture;
+4 -34
drivers/video/fbdev/intelfb/intelfbdrv.c
··· 124 124 125 125 #include <asm/io.h> 126 126 127 - #ifdef CONFIG_MTRR 128 - #include <asm/mtrr.h> 129 - #endif 130 - 131 127 #include "intelfb.h" 132 128 #include "intelfbhw.h" 133 129 #include "../edid.h" ··· 407 411 module_exit(intelfb_exit); 408 412 409 413 /*************************************************************** 410 - * mtrr support functions * 411 - ***************************************************************/ 412 - 413 - #ifdef CONFIG_MTRR 414 - static inline void set_mtrr(struct intelfb_info *dinfo) 415 - { 416 - dinfo->mtrr_reg = mtrr_add(dinfo->aperture.physical, 417 - dinfo->aperture.size, MTRR_TYPE_WRCOMB, 1); 418 - if (dinfo->mtrr_reg < 0) { 419 - ERR_MSG("unable to set MTRR\n"); 420 - return; 421 - } 422 - dinfo->has_mtrr = 1; 423 - } 424 - static inline void unset_mtrr(struct intelfb_info *dinfo) 425 - { 426 - if (dinfo->has_mtrr) 427 - mtrr_del(dinfo->mtrr_reg, dinfo->aperture.physical, 428 - dinfo->aperture.size); 429 - } 430 - #else 431 - #define set_mtrr(x) WRN_MSG("MTRR is disabled in the kernel\n") 432 - 433 - #define unset_mtrr(x) do { } while (0) 434 - #endif /* CONFIG_MTRR */ 435 - 436 - /*************************************************************** 437 414 * driver init / cleanup * 438 415 ***************************************************************/ 439 416 ··· 425 456 if (dinfo->registered) 426 457 unregister_framebuffer(dinfo->info); 427 458 428 - unset_mtrr(dinfo); 459 + arch_phys_wc_del(dinfo->wc_cookie); 429 460 430 461 if (dinfo->fbmem_gart && dinfo->gtt_fb_mem) { 431 462 agp_unbind_memory(dinfo->gtt_fb_mem); ··· 644 675 /* Allocate memories (which aren't stolen) */ 645 676 /* Map the fb and MMIO regions */ 646 677 /* ioremap only up to the end of used aperture */ 647 - dinfo->aperture.virtual = (u8 __iomem *)ioremap_nocache 678 + dinfo->aperture.virtual = (u8 __iomem *)ioremap_wc 648 679 (dinfo->aperture.physical, ((offset + dinfo->fb.offset) << 12) 649 680 + dinfo->fb.size); 650 681 if (!dinfo->aperture.virtual) { ··· 741 772 agp_backend_release(bridge); 742 773 743 774 if (mtrr) 744 - set_mtrr(dinfo); 775 + dinfo->wc_cookie = arch_phys_wc_add(dinfo->aperture.physical, 776 + dinfo->aperture.size); 745 777 746 778 DBG_MSG("fb: 0x%x(+ 0x%x)/0x%x (0x%p)\n", 747 779 dinfo->fb.physical, dinfo->fb.offset, dinfo->fb.size,