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

video: fbdev: pm2fb: 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: Rob Clark <robdclark@gmail.com>
Cc: Jingoo Han <jg1.han@samsung.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
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: Andy Lutomirski <luto@amacapital.net>
Cc: Dave Airlie <airlied@redhat.com>
Cc: Antonino Daplas <adaplas@gmail.com>
Cc: Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com>
Cc: Tomi Valkeinen <tomi.valkeinen@ti.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
f8f05cdc 775a8a56

+5 -26
+5 -26
drivers/video/fbdev/pm2fb.c
··· 38 38 #include <linux/fb.h> 39 39 #include <linux/init.h> 40 40 #include <linux/pci.h> 41 - #ifdef CONFIG_MTRR 42 - #include <asm/mtrr.h> 43 - #endif 44 - 45 41 #include <video/permedia2.h> 46 42 #include <video/cvisionppc.h> 47 43 ··· 77 81 static bool lowhsync; 78 82 static bool lowvsync; 79 83 static bool noaccel; 80 - /* mtrr option */ 81 - #ifdef CONFIG_MTRR 82 84 static bool nomtrr; 83 - #endif 84 85 85 86 /* 86 87 * The hardware state of the graphics card that isn't part of the ··· 93 100 u32 mem_control; /* MemControl reg at probe */ 94 101 u32 boot_address; /* BootAddress reg at probe */ 95 102 u32 palette[16]; 96 - int mtrr_handle; 103 + int wc_cookie; 97 104 }; 98 105 99 106 /* ··· 1630 1637 goto err_exit_mmio; 1631 1638 } 1632 1639 info->screen_base = 1633 - ioremap_nocache(pm2fb_fix.smem_start, pm2fb_fix.smem_len); 1640 + ioremap_wc(pm2fb_fix.smem_start, pm2fb_fix.smem_len); 1634 1641 if (!info->screen_base) { 1635 1642 printk(KERN_WARNING "pm2fb: Can't ioremap smem area.\n"); 1636 1643 release_mem_region(pm2fb_fix.smem_start, pm2fb_fix.smem_len); 1637 1644 goto err_exit_mmio; 1638 1645 } 1639 1646 1640 - #ifdef CONFIG_MTRR 1641 - default_par->mtrr_handle = -1; 1642 1647 if (!nomtrr) 1643 - default_par->mtrr_handle = 1644 - mtrr_add(pm2fb_fix.smem_start, 1645 - pm2fb_fix.smem_len, 1646 - MTRR_TYPE_WRCOMB, 1); 1647 - #endif 1648 + default_par->wc_cookie = arch_phys_wc_add(pm2fb_fix.smem_start, 1649 + pm2fb_fix.smem_len); 1648 1650 1649 1651 info->fbops = &pm2fb_ops; 1650 1652 info->fix = pm2fb_fix; ··· 1721 1733 struct pm2fb_par *par = info->par; 1722 1734 1723 1735 unregister_framebuffer(info); 1724 - 1725 - #ifdef CONFIG_MTRR 1726 - if (par->mtrr_handle >= 0) 1727 - mtrr_del(par->mtrr_handle, info->fix.smem_start, 1728 - info->fix.smem_len); 1729 - #endif /* CONFIG_MTRR */ 1736 + arch_phys_wc_del(par->wc_cookie); 1730 1737 iounmap(info->screen_base); 1731 1738 release_mem_region(fix->smem_start, fix->smem_len); 1732 1739 iounmap(par->v_regs); ··· 1774 1791 lowvsync = 1; 1775 1792 else if (!strncmp(this_opt, "hwcursor=", 9)) 1776 1793 hwcursor = simple_strtoul(this_opt + 9, NULL, 0); 1777 - #ifdef CONFIG_MTRR 1778 1794 else if (!strncmp(this_opt, "nomtrr", 6)) 1779 1795 nomtrr = 1; 1780 - #endif 1781 1796 else if (!strncmp(this_opt, "noaccel", 7)) 1782 1797 noaccel = 1; 1783 1798 else ··· 1828 1847 module_param(hwcursor, int, 0644); 1829 1848 MODULE_PARM_DESC(hwcursor, "Enable hardware cursor " 1830 1849 "(1=enable, 0=disable, default=1)"); 1831 - #ifdef CONFIG_MTRR 1832 1850 module_param(nomtrr, bool, 0); 1833 1851 MODULE_PARM_DESC(nomtrr, "Disable MTRR support (0 or 1=disabled) (default=0)"); 1834 - #endif 1835 1852 1836 1853 MODULE_AUTHOR("Jim Hague <jim.hague@acm.org>"); 1837 1854 MODULE_DESCRIPTION("Permedia2 framebuffer device driver");