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

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

This driver uses the same area for MTRR and 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: Antonino Daplas <adaplas@gmail.com>
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: 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
3b213c2f f2081b81

+7 -37
+1 -6
drivers/video/fbdev/nvidia/nv_type.h
··· 148 148 u32 forceCRTC; 149 149 u32 open_count; 150 150 u8 DDCBase; 151 - #ifdef CONFIG_MTRR 152 - struct { 153 - int vram; 154 - int vram_valid; 155 - } mtrr; 156 - #endif 151 + int wc_cookie; 157 152 struct nvidia_i2c_chan chan[3]; 158 153 159 154 volatile u32 __iomem *REGS;
+6 -31
drivers/video/fbdev/nvidia/nvidia.c
··· 21 21 #include <linux/pci.h> 22 22 #include <linux/console.h> 23 23 #include <linux/backlight.h> 24 - #ifdef CONFIG_MTRR 25 - #include <asm/mtrr.h> 26 - #endif 27 24 #ifdef CONFIG_BOOTX_TEXT 28 25 #include <asm/btext.h> 29 26 #endif ··· 73 76 static int vram = 0; 74 77 static int bpp = 8; 75 78 static int reverse_i2c; 76 - #ifdef CONFIG_MTRR 77 79 static bool nomtrr = false; 78 - #endif 79 80 #ifdef CONFIG_PMAC_BACKLIGHT 80 81 static int backlight = 1; 81 82 #else ··· 1356 1361 par->ScratchBufferStart = par->FbUsableSize - par->ScratchBufferSize; 1357 1362 par->CursorStart = par->FbUsableSize + (32 * 1024); 1358 1363 1359 - info->screen_base = ioremap(nvidiafb_fix.smem_start, par->FbMapSize); 1364 + info->screen_base = ioremap_wc(nvidiafb_fix.smem_start, 1365 + par->FbMapSize); 1360 1366 info->screen_size = par->FbUsableSize; 1361 1367 nvidiafb_fix.smem_len = par->RamAmountKBytes * 1024; 1362 1368 ··· 1368 1372 1369 1373 par->FbStart = info->screen_base; 1370 1374 1371 - #ifdef CONFIG_MTRR 1372 - if (!nomtrr) { 1373 - par->mtrr.vram = mtrr_add(nvidiafb_fix.smem_start, 1374 - par->RamAmountKBytes * 1024, 1375 - MTRR_TYPE_WRCOMB, 1); 1376 - if (par->mtrr.vram < 0) { 1377 - printk(KERN_ERR PFX "unable to setup MTRR\n"); 1378 - } else { 1379 - par->mtrr.vram_valid = 1; 1380 - /* let there be speed */ 1381 - printk(KERN_INFO PFX "MTRR set to ON\n"); 1382 - } 1383 - } 1384 - #endif /* CONFIG_MTRR */ 1375 + if (!nomtrr) 1376 + par->wc_cookie = arch_phys_wc_add(nvidiafb_fix.smem_start, 1377 + par->RamAmountKBytes * 1024); 1385 1378 1386 1379 info->fbops = &nvidia_fb_ops; 1387 1380 info->fix = nvidiafb_fix; ··· 1428 1443 unregister_framebuffer(info); 1429 1444 1430 1445 nvidia_bl_exit(par); 1431 - 1432 - #ifdef CONFIG_MTRR 1433 - if (par->mtrr.vram_valid) 1434 - mtrr_del(par->mtrr.vram, info->fix.smem_start, 1435 - info->fix.smem_len); 1436 - #endif /* CONFIG_MTRR */ 1437 - 1446 + arch_phys_wc_del(par->wc_cookie); 1438 1447 iounmap(info->screen_base); 1439 1448 fb_destroy_modedb(info->monspecs.modedb); 1440 1449 nvidia_delete_i2c_busses(par); ··· 1480 1501 vram = simple_strtoul(this_opt+5, NULL, 0); 1481 1502 } else if (!strncmp(this_opt, "backlight:", 10)) { 1482 1503 backlight = simple_strtoul(this_opt+10, NULL, 0); 1483 - #ifdef CONFIG_MTRR 1484 1504 } else if (!strncmp(this_opt, "nomtrr", 6)) { 1485 1505 nomtrr = true; 1486 - #endif 1487 1506 } else if (!strncmp(this_opt, "fpdither:", 9)) { 1488 1507 fpdither = simple_strtol(this_opt+9, NULL, 0); 1489 1508 } else if (!strncmp(this_opt, "bpp:", 4)) { ··· 1569 1592 "(default=8)"); 1570 1593 module_param(reverse_i2c, int, 0); 1571 1594 MODULE_PARM_DESC(reverse_i2c, "reverse port assignment of the i2c bus"); 1572 - #ifdef CONFIG_MTRR 1573 1595 module_param(nomtrr, bool, false); 1574 1596 MODULE_PARM_DESC(nomtrr, "Disables MTRR support (0 or 1=disabled) " 1575 1597 "(default=0)"); 1576 - #endif 1577 1598 1578 1599 MODULE_AUTHOR("Antonino Daplas"); 1579 1600 MODULE_DESCRIPTION("Framebuffer driver for nVidia graphics chipset");