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

video: fbdev: vesafb: use arch_phys_wc_add()

This driver uses the same area for MTRR as for the ioremap_wc(), if
anything it just uses a smaller size in case MTRR reservation fails.
ioremap_wc() API is already used to take advantage of architecture
write-combining when available.

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.

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: Toshi Kani <toshi.kani@hp.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: Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com>
Cc: Rob Clark <robdclark@gmail.com>
Cc: Jingoo Han <jg1.han@samsung.com>
Cc: Wolfram Sang <wsa@the-dreams.de>
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>
Signed-off-by: Tomi Valkeinen <tomi.valkeinen@ti.com>

authored by

Luis R. Rodriguez and committed by
Tomi Valkeinen
127b0c94 6b41f27d

+8 -21
+8 -21
drivers/video/fbdev/vesafb.c
··· 19 19 #include <linux/init.h> 20 20 #include <linux/platform_device.h> 21 21 #include <linux/screen_info.h> 22 + #include <linux/io.h> 22 23 23 24 #include <video/vga.h> 24 - #include <asm/io.h> 25 - #include <asm/mtrr.h> 26 25 27 26 #define dac_reg (0x3c8) 28 27 #define dac_val (0x3c9) ··· 179 180 180 181 static void vesafb_destroy(struct fb_info *info) 181 182 { 182 - #ifdef CONFIG_MTRR 183 183 struct vesafb_par *par = info->par; 184 - #endif 185 184 186 185 fb_dealloc_cmap(&info->cmap); 187 - 188 - #ifdef CONFIG_MTRR 189 - if (par->wc_cookie >= 0) 190 - mtrr_del(par->wc_cookie, 0, 0); 191 - #endif 186 + arch_phys_wc_del(par->wc_cookie); 192 187 if (info->screen_base) 193 188 iounmap(info->screen_base); 194 189 release_mem_region(info->apertures->ranges[0].base, info->apertures->ranges[0].size); ··· 413 420 request_region(0x3c0, 32, "vesafb"); 414 421 415 422 if (mtrr == 3) { 416 - #ifdef CONFIG_MTRR 417 423 unsigned int temp_size = size_total; 418 424 419 425 /* Find the largest power-of-two */ ··· 420 428 421 429 /* Try and find a power of two to add */ 422 430 do { 423 - par->wc_cookie = mtrr_add(vesafb_fix.smem_start, 424 - temp_size, 425 - MTRR_TYPE_WRCOMB, 1); 431 + par->wc_cookie = 432 + arch_phys_wc_add(vesafb_fix.smem_start, 433 + temp_size); 426 434 temp_size >>= 1; 427 - } while (temp_size >= PAGE_SIZE && par->wc_cookie == -EINVAL); 428 - #endif 435 + } while (temp_size >= PAGE_SIZE && par->wc_cookie < 0); 436 + 429 437 info->screen_base = ioremap_wc(vesafb_fix.smem_start, vesafb_fix.smem_len); 430 438 } else { 431 - #ifdef CONFIG_MTRR 432 439 if (mtrr && mtrr != 3) 433 440 WARN_ONCE(1, "Only MTRR_TYPE_WRCOMB (3) make sense\n"); 434 - #endif 435 441 info->screen_base = ioremap(vesafb_fix.smem_start, vesafb_fix.smem_len); 436 442 } 437 443 ··· 467 477 fb_info(info, "%s frame buffer device\n", info->fix.id); 468 478 return 0; 469 479 err: 470 - #ifdef CONFIG_MTRR 471 - if (par->wc_cookie >= 0) 472 - mtrr_del(par->wc_cookie, 0, 0); 473 - #endif 480 + arch_phys_wc_del(par->wc_cookie); 474 481 if (info->screen_base) 475 482 iounmap(info->screen_base); 476 483 framebuffer_release(info);