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

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

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() (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: Thomas Winischhofer <thomas@winischhofer.net>
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
2cff6406 4d811d6c

+7 -22
+1 -1
drivers/video/fbdev/sis/sis.h
··· 458 458 459 459 unsigned char *bios_abase; 460 460 461 - int mtrr; 461 + int wc_cookie; 462 462 463 463 u32 sisfb_mem; 464 464
+6 -21
drivers/video/fbdev/sis/sis_main.c
··· 53 53 #include <linux/types.h> 54 54 #include <linux/uaccess.h> 55 55 #include <asm/io.h> 56 - #ifdef CONFIG_MTRR 57 - #include <asm/mtrr.h> 58 - #endif 59 56 60 57 #include "sis.h" 61 58 #include "sis_main.h" ··· 4127 4130 if (*mapsize < (min << 20)) 4128 4131 return; 4129 4132 4130 - ivideo->video_vbase = ioremap(ivideo->video_base, (*mapsize)); 4133 + ivideo->video_vbase = ioremap_wc(ivideo->video_base, (*mapsize)); 4131 4134 4132 4135 if(!ivideo->video_vbase) { 4133 4136 printk(KERN_ERR 4134 4137 "sisfb: Unable to map maximum video RAM for size detection\n"); 4135 4138 (*mapsize) >>= 1; 4136 - while((!(ivideo->video_vbase = ioremap(ivideo->video_base, (*mapsize))))) { 4139 + while((!(ivideo->video_vbase = ioremap_wc(ivideo->video_base, (*mapsize))))) { 4137 4140 (*mapsize) >>= 1; 4138 4141 if((*mapsize) < (min << 20)) 4139 4142 break; ··· 6183 6186 goto error_2; 6184 6187 } 6185 6188 6186 - ivideo->video_vbase = ioremap(ivideo->video_base, ivideo->video_size); 6189 + ivideo->video_vbase = ioremap_wc(ivideo->video_base, ivideo->video_size); 6187 6190 ivideo->SiS_Pr.VideoMemoryAddress = ivideo->video_vbase; 6188 6191 if(!ivideo->video_vbase) { 6189 6192 printk(KERN_ERR "sisfb: Fatal error: Unable to map framebuffer memory\n"); ··· 6250 6253 /* Used for clearing the screen only, therefore respect our mem limit */ 6251 6254 ivideo->SiS_Pr.VideoMemoryAddress += ivideo->video_offset; 6252 6255 ivideo->SiS_Pr.VideoMemorySize = ivideo->sisfb_mem; 6253 - 6254 - ivideo->mtrr = -1; 6255 6256 6256 6257 ivideo->vbflags = 0; 6257 6258 ivideo->lcddefmodeidx = DEFAULT_LCDMODE; ··· 6438 6443 6439 6444 printk(KERN_DEBUG "sisfb: Initial vbflags 0x%x\n", (int)ivideo->vbflags); 6440 6445 6441 - #ifdef CONFIG_MTRR 6442 - ivideo->mtrr = mtrr_add(ivideo->video_base, ivideo->video_size, 6443 - MTRR_TYPE_WRCOMB, 1); 6444 - if(ivideo->mtrr < 0) { 6445 - printk(KERN_DEBUG "sisfb: Failed to add MTRRs\n"); 6446 - } 6447 - #endif 6448 - 6446 + ivideo->wc_cookie = arch_phys_wc_add(ivideo->video_base, 6447 + ivideo->video_size); 6449 6448 if(register_framebuffer(sis_fb_info) < 0) { 6450 6449 printk(KERN_ERR "sisfb: Fatal error: Failed to register framebuffer\n"); 6451 6450 ret = -EINVAL; ··· 6496 6507 6497 6508 pci_dev_put(ivideo->nbridge); 6498 6509 6499 - #ifdef CONFIG_MTRR 6500 - /* Release MTRR region */ 6501 - if(ivideo->mtrr >= 0) 6502 - mtrr_del(ivideo->mtrr, ivideo->video_base, ivideo->video_size); 6503 - #endif 6510 + arch_phys_wc_del(ivideo->wc_cookie); 6504 6511 6505 6512 /* If device was disabled when starting, disable 6506 6513 * it when quitting.