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

drivers/video/fbdev/i740fb: Use arch_phys_wc_add() and pci_ioremap_wc_bar()

Convert the driver from using the x86-specific MTRR code to the
architecture-agnostic arch_phys_wc_add(). It will avoid MTRR if
write-combining is available, in order to take advantage of that
also ensure the ioremapped 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 it is being 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 ifdeffery 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);

Signed-off-by: Luis R. Rodriguez <mcgrof@suse.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Acked-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@amacapital.net>
Cc: Antonino Daplas <adaplas@gmail.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Benoit Taine <benoit.taine@lip6.fr>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Dave Airlie <airlied@redhat.com>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com>
Cc: Jingoo Han <jg1.han@samsung.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rob Clark <robdclark@gmail.com>
Cc: Suresh Siddha <sbsiddha@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: airlied@linux.ie
Cc: benh@kernel.crashing.org
Cc: dan.j.williams@intel.com
Cc: konrad.wilk@oracle.com
Cc: linux-fbdev@vger.kernel.org
Cc: linux-pci@vger.kernel.org
Cc: mst@redhat.com
Cc: toshi.kani@hp.com
Cc: vinod.koul@intel.com
Cc: xen-devel@lists.xensource.com
Link: http://lkml.kernel.org/r/1440443613-13696-3-git-send-email-mcgrof@do-not-panic.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>

authored by

Luis R. Rodriguez and committed by
Ingo Molnar
c1127098 c43996f4

+6 -29
+6 -29
drivers/video/fbdev/i740fb.c
··· 27 27 #include <linux/console.h> 28 28 #include <video/vga.h> 29 29 30 - #ifdef CONFIG_MTRR 31 - #include <asm/mtrr.h> 32 - #endif 33 - 34 30 #include "i740_reg.h" 35 31 36 32 static char *mode_option; 37 - 38 - #ifdef CONFIG_MTRR 39 33 static int mtrr = 1; 40 - #endif 41 34 42 35 struct i740fb_par { 43 36 unsigned char __iomem *regs; 44 37 bool has_sgram; 45 - #ifdef CONFIG_MTRR 46 - int mtrr_reg; 47 - #endif 38 + int wc_cookie; 48 39 bool ddc_registered; 49 40 struct i2c_adapter ddc_adapter; 50 41 struct i2c_algo_bit_data ddc_algo; ··· 1031 1040 goto err_request_regions; 1032 1041 } 1033 1042 1034 - info->screen_base = pci_ioremap_bar(dev, 0); 1043 + info->screen_base = pci_ioremap_wc_bar(dev, 0); 1035 1044 if (!info->screen_base) { 1036 1045 dev_err(info->device, "error remapping base\n"); 1037 1046 ret = -ENOMEM; ··· 1135 1144 1136 1145 fb_info(info, "%s frame buffer device\n", info->fix.id); 1137 1146 pci_set_drvdata(dev, info); 1138 - #ifdef CONFIG_MTRR 1139 - if (mtrr) { 1140 - par->mtrr_reg = -1; 1141 - par->mtrr_reg = mtrr_add(info->fix.smem_start, 1142 - info->fix.smem_len, MTRR_TYPE_WRCOMB, 1); 1143 - } 1144 - #endif 1147 + if (mtrr) 1148 + par->wc_cookie = arch_phys_wc_add(info->fix.smem_start, 1149 + info->fix.smem_len); 1145 1150 return 0; 1146 1151 1147 1152 err_reg_framebuffer: ··· 1164 1177 1165 1178 if (info) { 1166 1179 struct i740fb_par *par = info->par; 1167 - 1168 - #ifdef CONFIG_MTRR 1169 - if (par->mtrr_reg >= 0) { 1170 - mtrr_del(par->mtrr_reg, 0, 0); 1171 - par->mtrr_reg = -1; 1172 - } 1173 - #endif 1180 + arch_phys_wc_del(par->wc_cookie); 1174 1181 unregister_framebuffer(info); 1175 1182 fb_dealloc_cmap(&info->cmap); 1176 1183 if (par->ddc_registered) ··· 1268 1287 while ((opt = strsep(&options, ",")) != NULL) { 1269 1288 if (!*opt) 1270 1289 continue; 1271 - #ifdef CONFIG_MTRR 1272 1290 else if (!strncmp(opt, "mtrr:", 5)) 1273 1291 mtrr = simple_strtoul(opt + 5, NULL, 0); 1274 - #endif 1275 1292 else 1276 1293 mode_option = opt; 1277 1294 } ··· 1306 1327 module_param(mode_option, charp, 0444); 1307 1328 MODULE_PARM_DESC(mode_option, "Default video mode ('640x480-8@60', etc)"); 1308 1329 1309 - #ifdef CONFIG_MTRR 1310 1330 module_param(mtrr, int, 0444); 1311 1331 MODULE_PARM_DESC(mtrr, "Enable write-combining with MTRR (1=enable, 0=disable, default=1)"); 1312 - #endif