All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 0/3] vesafb: remove theoretical MTRR uses
@ 2015-06-04 16:44 ` Luis R. Rodriguez
  0 siblings, 0 replies; 14+ messages in thread
From: Luis R. Rodriguez @ 2015-06-04 16:44 UTC (permalink / raw)
  To: tomi.valkeinen
  Cc: plagnioj, bp, hpa, linux-fbdev, luto, toshi.kani, sbsiddha,
	mingo, tglx, jgross, daniel.vetter, airlied, adaplas, robdclark,
	jg1.han, wsa, linux-kernel, Luis R. Rodriguez

From: "Luis R. Rodriguez" <mcgrof@suse.com>

Tomi,

This v4 fixes the issue of the use of the old use of
info->par for the pseudo_palette and our need to extend
it for the MTRR cookie by extending our proposed new
struct vesafb_par with the pseudo_palette and later
pointing info->pseudo_palette to it. This also means
we can simplify the allocation of the info when calling
framebuffer_alloc() by now just passing the size of our
struct vesafb_par.

Patch 1 is unmodified from v3 series, patch 2 does the
fixes mentioned above, and patch 3 might have small
changes to account for contextual changes.

Luis R. Rodriguez (3):
  video: fbdev: vesafb: only support MTRR_TYPE_WRCOMB
  video: fbdev: vesafb: add missing mtrr_del() for added MTRR
  video: fbdev: vesafb: use arch_phys_wc_add()

 drivers/video/fbdev/vesafb.c | 80 ++++++++++++++++----------------------------
 1 file changed, 28 insertions(+), 52 deletions(-)

-- 
2.3.2.209.gd67f9d5.dirty


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v4 0/3] vesafb: remove theoretical MTRR uses
@ 2015-06-04 16:44 ` Luis R. Rodriguez
  0 siblings, 0 replies; 14+ messages in thread
From: Luis R. Rodriguez @ 2015-06-04 16:44 UTC (permalink / raw)
  To: tomi.valkeinen
  Cc: plagnioj, bp, hpa, linux-fbdev, luto, toshi.kani, sbsiddha,
	mingo, tglx, jgross, daniel.vetter, airlied, adaplas, robdclark,
	jg1.han, wsa, linux-kernel, Luis R. Rodriguez

From: "Luis R. Rodriguez" <mcgrof@suse.com>

Tomi,

This v4 fixes the issue of the use of the old use of
info->par for the pseudo_palette and our need to extend
it for the MTRR cookie by extending our proposed new
struct vesafb_par with the pseudo_palette and later
pointing info->pseudo_palette to it. This also means
we can simplify the allocation of the info when calling
framebuffer_alloc() by now just passing the size of our
struct vesafb_par.

Patch 1 is unmodified from v3 series, patch 2 does the
fixes mentioned above, and patch 3 might have small
changes to account for contextual changes.

Luis R. Rodriguez (3):
  video: fbdev: vesafb: only support MTRR_TYPE_WRCOMB
  video: fbdev: vesafb: add missing mtrr_del() for added MTRR
  video: fbdev: vesafb: use arch_phys_wc_add()

 drivers/video/fbdev/vesafb.c | 80 ++++++++++++++++----------------------------
 1 file changed, 28 insertions(+), 52 deletions(-)

-- 
2.3.2.209.gd67f9d5.dirty


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH v4 1/3] video: fbdev: vesafb: only support MTRR_TYPE_WRCOMB
  2015-06-04 16:44 ` Luis R. Rodriguez
@ 2015-06-04 16:44   ` Luis R. Rodriguez
  -1 siblings, 0 replies; 14+ messages in thread
From: Luis R. Rodriguez @ 2015-06-04 16:44 UTC (permalink / raw)
  To: tomi.valkeinen
  Cc: plagnioj, bp, hpa, linux-fbdev, luto, toshi.kani, sbsiddha,
	mingo, tglx, jgross, daniel.vetter, airlied, adaplas, robdclark,
	jg1.han, wsa, linux-kernel, Luis R. Rodriguez, Linus Torvalds

From: "Luis R. Rodriguez" <mcgrof@suse.com>

No other video driver uses MTRR types except for MTRR_TYPE_WRCOMB,
the other MTRR types were implemented and supported here but with
no real good reason. The ioremap() APIs are architecture agnostic and
at least on x86 PAT is a new design that extends MTRRs and
can replace it in a much cleaner way, where so long as the
proper ioremap_wc() or variant API is used the right thing will
be done behind the scenes. This is the only driver left using the
other MTRR types -- and since there is no good reason for it now
rip them out.

Cc: Toshi Kani <toshi.kani@hp.com>
Cc: Suresh Siddha <sbsiddha@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
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: Tomi Valkeinen <tomi.valkeinen@ti.com>
Cc: Rob Clark <robdclark@gmail.com>
Cc: Jingoo Han <jg1.han@samsung.com>
Cc: Wolfram Sang <wsa@the-dreams.de>
Cc: linux-fbdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Luis R. Rodriguez <mcgrof@suse.com>
---
 drivers/video/fbdev/vesafb.c | 62 ++++++++++++--------------------------------
 1 file changed, 16 insertions(+), 46 deletions(-)

diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
index d79a0ac..191156b 100644
--- a/drivers/video/fbdev/vesafb.c
+++ b/drivers/video/fbdev/vesafb.c
@@ -404,60 +404,30 @@ static int vesafb_probe(struct platform_device *dev)
 	 * region already (FIXME) */
 	request_region(0x3c0, 32, "vesafb");
 
+	if (mtrr == 3) {
 #ifdef CONFIG_MTRR
-	if (mtrr) {
 		unsigned int temp_size = size_total;
-		unsigned int type = 0;
+		int rc;
 
-		switch (mtrr) {
-		case 1:
-			type = MTRR_TYPE_UNCACHABLE;
-			break;
-		case 2:
-			type = MTRR_TYPE_WRBACK;
-			break;
-		case 3:
-			type = MTRR_TYPE_WRCOMB;
-			break;
-		case 4:
-			type = MTRR_TYPE_WRTHROUGH;
-			break;
-		default:
-			type = 0;
-			break;
-		}
-
-		if (type) {
-			int rc;
-
-			/* Find the largest power-of-two */
-			temp_size = roundup_pow_of_two(temp_size);
+		/* Find the largest power-of-two */
+		temp_size = roundup_pow_of_two(temp_size);
 
-			/* Try and find a power of two to add */
-			do {
-				rc = mtrr_add(vesafb_fix.smem_start, temp_size,
-					      type, 1);
-				temp_size >>= 1;
-			} while (temp_size >= PAGE_SIZE && rc == -EINVAL);
-		}
-	}
+		/* Try and find a power of two to add */
+		do {
+			rc = mtrr_add(vesafb_fix.smem_start, temp_size,
+				      MTRR_TYPE_WRCOMB, 1);
+			temp_size >>= 1;
+		} while (temp_size >= PAGE_SIZE && rc == -EINVAL);
 #endif
-	
-	switch (mtrr) {
-	case 1: /* uncachable */
-		info->screen_base = ioremap_nocache(vesafb_fix.smem_start, vesafb_fix.smem_len);
-		break;
-	case 2: /* write-back */
-		info->screen_base = ioremap_cache(vesafb_fix.smem_start, vesafb_fix.smem_len);
-		break;
-	case 3: /* write-combining */
 		info->screen_base = ioremap_wc(vesafb_fix.smem_start, vesafb_fix.smem_len);
-		break;
-	case 4: /* write-through */
-	default:
+	} else {
+#ifdef CONFIG_MTRR
+		if (mtrr && mtrr != 3)
+			WARN_ONCE(1, "Only MTRR_TYPE_WRCOMB (3) make sense\n");
+#endif
 		info->screen_base = ioremap(vesafb_fix.smem_start, vesafb_fix.smem_len);
-		break;
 	}
+
 	if (!info->screen_base) {
 		printk(KERN_ERR
 		       "vesafb: abort, cannot ioremap video memory 0x%x @ 0x%lx\n",
-- 
2.3.2.209.gd67f9d5.dirty


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v4 1/3] video: fbdev: vesafb: only support MTRR_TYPE_WRCOMB
@ 2015-06-04 16:44   ` Luis R. Rodriguez
  0 siblings, 0 replies; 14+ messages in thread
From: Luis R. Rodriguez @ 2015-06-04 16:44 UTC (permalink / raw)
  To: tomi.valkeinen
  Cc: plagnioj, bp, hpa, linux-fbdev, luto, toshi.kani, sbsiddha,
	mingo, tglx, jgross, daniel.vetter, airlied, adaplas, robdclark,
	jg1.han, wsa, linux-kernel, Luis R. Rodriguez, Linus Torvalds

From: "Luis R. Rodriguez" <mcgrof@suse.com>

No other video driver uses MTRR types except for MTRR_TYPE_WRCOMB,
the other MTRR types were implemented and supported here but with
no real good reason. The ioremap() APIs are architecture agnostic and
at least on x86 PAT is a new design that extends MTRRs and
can replace it in a much cleaner way, where so long as the
proper ioremap_wc() or variant API is used the right thing will
be done behind the scenes. This is the only driver left using the
other MTRR types -- and since there is no good reason for it now
rip them out.

Cc: Toshi Kani <toshi.kani@hp.com>
Cc: Suresh Siddha <sbsiddha@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
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: Tomi Valkeinen <tomi.valkeinen@ti.com>
Cc: Rob Clark <robdclark@gmail.com>
Cc: Jingoo Han <jg1.han@samsung.com>
Cc: Wolfram Sang <wsa@the-dreams.de>
Cc: linux-fbdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Luis R. Rodriguez <mcgrof@suse.com>
---
 drivers/video/fbdev/vesafb.c | 62 ++++++++++++--------------------------------
 1 file changed, 16 insertions(+), 46 deletions(-)

diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
index d79a0ac..191156b 100644
--- a/drivers/video/fbdev/vesafb.c
+++ b/drivers/video/fbdev/vesafb.c
@@ -404,60 +404,30 @@ static int vesafb_probe(struct platform_device *dev)
 	 * region already (FIXME) */
 	request_region(0x3c0, 32, "vesafb");
 
+	if (mtrr = 3) {
 #ifdef CONFIG_MTRR
-	if (mtrr) {
 		unsigned int temp_size = size_total;
-		unsigned int type = 0;
+		int rc;
 
-		switch (mtrr) {
-		case 1:
-			type = MTRR_TYPE_UNCACHABLE;
-			break;
-		case 2:
-			type = MTRR_TYPE_WRBACK;
-			break;
-		case 3:
-			type = MTRR_TYPE_WRCOMB;
-			break;
-		case 4:
-			type = MTRR_TYPE_WRTHROUGH;
-			break;
-		default:
-			type = 0;
-			break;
-		}
-
-		if (type) {
-			int rc;
-
-			/* Find the largest power-of-two */
-			temp_size = roundup_pow_of_two(temp_size);
+		/* Find the largest power-of-two */
+		temp_size = roundup_pow_of_two(temp_size);
 
-			/* Try and find a power of two to add */
-			do {
-				rc = mtrr_add(vesafb_fix.smem_start, temp_size,
-					      type, 1);
-				temp_size >>= 1;
-			} while (temp_size >= PAGE_SIZE && rc = -EINVAL);
-		}
-	}
+		/* Try and find a power of two to add */
+		do {
+			rc = mtrr_add(vesafb_fix.smem_start, temp_size,
+				      MTRR_TYPE_WRCOMB, 1);
+			temp_size >>= 1;
+		} while (temp_size >= PAGE_SIZE && rc = -EINVAL);
 #endif
-	
-	switch (mtrr) {
-	case 1: /* uncachable */
-		info->screen_base = ioremap_nocache(vesafb_fix.smem_start, vesafb_fix.smem_len);
-		break;
-	case 2: /* write-back */
-		info->screen_base = ioremap_cache(vesafb_fix.smem_start, vesafb_fix.smem_len);
-		break;
-	case 3: /* write-combining */
 		info->screen_base = ioremap_wc(vesafb_fix.smem_start, vesafb_fix.smem_len);
-		break;
-	case 4: /* write-through */
-	default:
+	} else {
+#ifdef CONFIG_MTRR
+		if (mtrr && mtrr != 3)
+			WARN_ONCE(1, "Only MTRR_TYPE_WRCOMB (3) make sense\n");
+#endif
 		info->screen_base = ioremap(vesafb_fix.smem_start, vesafb_fix.smem_len);
-		break;
 	}
+
 	if (!info->screen_base) {
 		printk(KERN_ERR
 		       "vesafb: abort, cannot ioremap video memory 0x%x @ 0x%lx\n",
-- 
2.3.2.209.gd67f9d5.dirty


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v4 2/3] video: fbdev: vesafb: add missing mtrr_del() for added MTRR
  2015-06-04 16:44 ` Luis R. Rodriguez
@ 2015-06-04 16:44   ` Luis R. Rodriguez
  -1 siblings, 0 replies; 14+ messages in thread
From: Luis R. Rodriguez @ 2015-06-04 16:44 UTC (permalink / raw)
  To: tomi.valkeinen
  Cc: plagnioj, bp, hpa, linux-fbdev, luto, toshi.kani, sbsiddha,
	mingo, tglx, jgross, daniel.vetter, airlied, adaplas, robdclark,
	jg1.han, wsa, linux-kernel, Luis R. Rodriguez

From: "Luis R. Rodriguez" <mcgrof@suse.com>

The MTRR added was never being deleted, in order to store the
MTRR cookie we need to make use of the private info->par so we
create a struct for this. This driver was already using the extra
space typically used for info->par for the info->pseudo_palette
which typically used stuffed on driver's own private structs
(the respective info->par), so we just move the pseudo_palette
into the private struct as well.

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: Rob Clark <robdclark@gmail.com>
Cc: Jingoo Han <jg1.han@samsung.com>
Cc: Wolfram Sang <wsa@the-dreams.de>
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>
---
 drivers/video/fbdev/vesafb.c | 33 ++++++++++++++++++++++++++-------
 1 file changed, 26 insertions(+), 7 deletions(-)

diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
index 191156b..3db3908 100644
--- a/drivers/video/fbdev/vesafb.c
+++ b/drivers/video/fbdev/vesafb.c
@@ -29,6 +29,11 @@
 
 /* --------------------------------------------------------------------- */
 
+struct vesafb_par {
+	u32 pseudo_palette[256];
+	int wc_cookie;
+};
+
 static struct fb_var_screeninfo vesafb_defined = {
 	.activate	= FB_ACTIVATE_NOW,
 	.height		= -1,
@@ -175,7 +180,16 @@ static int vesafb_setcolreg(unsigned regno, unsigned red, unsigned green,
 
 static void vesafb_destroy(struct fb_info *info)
 {
+#ifdef CONFIG_MTRR
+	struct vesafb_par *par = info->par;
+#endif
+
 	fb_dealloc_cmap(&info->cmap);
+
+#ifdef CONFIG_MTRR
+	if (par->wc_cookie >= 0)
+		mtrr_del(par->wc_cookie, 0, 0);
+#endif
 	if (info->screen_base)
 		iounmap(info->screen_base);
 	release_mem_region(info->apertures->ranges[0].base, info->apertures->ranges[0].size);
@@ -228,6 +242,7 @@ static int vesafb_setup(char *options)
 static int vesafb_probe(struct platform_device *dev)
 {
 	struct fb_info *info;
+	struct vesafb_par *par;
 	int i, err;
 	unsigned int size_vmode;
 	unsigned int size_remap;
@@ -291,14 +306,14 @@ static int vesafb_probe(struct platform_device *dev)
 		   spaces our resource handlers simply don't know about */
 	}
 
-	info = framebuffer_alloc(sizeof(u32) * 256, &dev->dev);
+	info = framebuffer_alloc(sizeof(struct vesafb_par), &dev->dev);
 	if (!info) {
 		release_mem_region(vesafb_fix.smem_start, size_total);
 		return -ENOMEM;
 	}
 	platform_set_drvdata(dev, info);
-	info->pseudo_palette = info->par;
-	info->par = NULL;
+	par = info->par;
+	info->pseudo_palette = par->pseudo_palette;
 
 	/* set vesafb aperture size for generic probing */
 	info->apertures = alloc_apertures(1);
@@ -407,17 +422,17 @@ static int vesafb_probe(struct platform_device *dev)
 	if (mtrr == 3) {
 #ifdef CONFIG_MTRR
 		unsigned int temp_size = size_total;
-		int rc;
 
 		/* Find the largest power-of-two */
 		temp_size = roundup_pow_of_two(temp_size);
 
 		/* Try and find a power of two to add */
 		do {
-			rc = mtrr_add(vesafb_fix.smem_start, temp_size,
-				      MTRR_TYPE_WRCOMB, 1);
+			par->wc_cookie = mtrr_add(vesafb_fix.smem_start,
+						  temp_size,
+						  MTRR_TYPE_WRCOMB, 1);
 			temp_size >>= 1;
-		} while (temp_size >= PAGE_SIZE && rc == -EINVAL);
+		} while (temp_size >= PAGE_SIZE && par->wc_cookie == -EINVAL);
 #endif
 		info->screen_base = ioremap_wc(vesafb_fix.smem_start, vesafb_fix.smem_len);
 	} else {
@@ -462,6 +477,10 @@ static int vesafb_probe(struct platform_device *dev)
 	fb_info(info, "%s frame buffer device\n", info->fix.id);
 	return 0;
 err:
+#ifdef CONFIG_MTRR
+	if (par->wc_cookie >= 0)
+		mtrr_del(par->wc_cookie, 0, 0);
+#endif
 	if (info->screen_base)
 		iounmap(info->screen_base);
 	framebuffer_release(info);
-- 
2.3.2.209.gd67f9d5.dirty


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v4 2/3] video: fbdev: vesafb: add missing mtrr_del() for added MTRR
@ 2015-06-04 16:44   ` Luis R. Rodriguez
  0 siblings, 0 replies; 14+ messages in thread
From: Luis R. Rodriguez @ 2015-06-04 16:44 UTC (permalink / raw)
  To: tomi.valkeinen
  Cc: plagnioj, bp, hpa, linux-fbdev, luto, toshi.kani, sbsiddha,
	mingo, tglx, jgross, daniel.vetter, airlied, adaplas, robdclark,
	jg1.han, wsa, linux-kernel, Luis R. Rodriguez

From: "Luis R. Rodriguez" <mcgrof@suse.com>

The MTRR added was never being deleted, in order to store the
MTRR cookie we need to make use of the private info->par so we
create a struct for this. This driver was already using the extra
space typically used for info->par for the info->pseudo_palette
which typically used stuffed on driver's own private structs
(the respective info->par), so we just move the pseudo_palette
into the private struct as well.

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: Rob Clark <robdclark@gmail.com>
Cc: Jingoo Han <jg1.han@samsung.com>
Cc: Wolfram Sang <wsa@the-dreams.de>
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>
---
 drivers/video/fbdev/vesafb.c | 33 ++++++++++++++++++++++++++-------
 1 file changed, 26 insertions(+), 7 deletions(-)

diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
index 191156b..3db3908 100644
--- a/drivers/video/fbdev/vesafb.c
+++ b/drivers/video/fbdev/vesafb.c
@@ -29,6 +29,11 @@
 
 /* --------------------------------------------------------------------- */
 
+struct vesafb_par {
+	u32 pseudo_palette[256];
+	int wc_cookie;
+};
+
 static struct fb_var_screeninfo vesafb_defined = {
 	.activate	= FB_ACTIVATE_NOW,
 	.height		= -1,
@@ -175,7 +180,16 @@ static int vesafb_setcolreg(unsigned regno, unsigned red, unsigned green,
 
 static void vesafb_destroy(struct fb_info *info)
 {
+#ifdef CONFIG_MTRR
+	struct vesafb_par *par = info->par;
+#endif
+
 	fb_dealloc_cmap(&info->cmap);
+
+#ifdef CONFIG_MTRR
+	if (par->wc_cookie >= 0)
+		mtrr_del(par->wc_cookie, 0, 0);
+#endif
 	if (info->screen_base)
 		iounmap(info->screen_base);
 	release_mem_region(info->apertures->ranges[0].base, info->apertures->ranges[0].size);
@@ -228,6 +242,7 @@ static int vesafb_setup(char *options)
 static int vesafb_probe(struct platform_device *dev)
 {
 	struct fb_info *info;
+	struct vesafb_par *par;
 	int i, err;
 	unsigned int size_vmode;
 	unsigned int size_remap;
@@ -291,14 +306,14 @@ static int vesafb_probe(struct platform_device *dev)
 		   spaces our resource handlers simply don't know about */
 	}
 
-	info = framebuffer_alloc(sizeof(u32) * 256, &dev->dev);
+	info = framebuffer_alloc(sizeof(struct vesafb_par), &dev->dev);
 	if (!info) {
 		release_mem_region(vesafb_fix.smem_start, size_total);
 		return -ENOMEM;
 	}
 	platform_set_drvdata(dev, info);
-	info->pseudo_palette = info->par;
-	info->par = NULL;
+	par = info->par;
+	info->pseudo_palette = par->pseudo_palette;
 
 	/* set vesafb aperture size for generic probing */
 	info->apertures = alloc_apertures(1);
@@ -407,17 +422,17 @@ static int vesafb_probe(struct platform_device *dev)
 	if (mtrr = 3) {
 #ifdef CONFIG_MTRR
 		unsigned int temp_size = size_total;
-		int rc;
 
 		/* Find the largest power-of-two */
 		temp_size = roundup_pow_of_two(temp_size);
 
 		/* Try and find a power of two to add */
 		do {
-			rc = mtrr_add(vesafb_fix.smem_start, temp_size,
-				      MTRR_TYPE_WRCOMB, 1);
+			par->wc_cookie = mtrr_add(vesafb_fix.smem_start,
+						  temp_size,
+						  MTRR_TYPE_WRCOMB, 1);
 			temp_size >>= 1;
-		} while (temp_size >= PAGE_SIZE && rc = -EINVAL);
+		} while (temp_size >= PAGE_SIZE && par->wc_cookie = -EINVAL);
 #endif
 		info->screen_base = ioremap_wc(vesafb_fix.smem_start, vesafb_fix.smem_len);
 	} else {
@@ -462,6 +477,10 @@ static int vesafb_probe(struct platform_device *dev)
 	fb_info(info, "%s frame buffer device\n", info->fix.id);
 	return 0;
 err:
+#ifdef CONFIG_MTRR
+	if (par->wc_cookie >= 0)
+		mtrr_del(par->wc_cookie, 0, 0);
+#endif
 	if (info->screen_base)
 		iounmap(info->screen_base);
 	framebuffer_release(info);
-- 
2.3.2.209.gd67f9d5.dirty


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v4 3/3] video: fbdev: vesafb: use arch_phys_wc_add()
  2015-06-04 16:44 ` Luis R. Rodriguez
@ 2015-06-04 16:44   ` Luis R. Rodriguez
  -1 siblings, 0 replies; 14+ messages in thread
From: Luis R. Rodriguez @ 2015-06-04 16:44 UTC (permalink / raw)
  To: tomi.valkeinen
  Cc: plagnioj, bp, hpa, linux-fbdev, luto, toshi.kani, sbsiddha,
	mingo, tglx, jgross, daniel.vetter, airlied, adaplas, robdclark,
	jg1.han, wsa, linux-kernel, Luis R. Rodriguez

From: "Luis R. Rodriguez" <mcgrof@suse.com>

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>
---
 drivers/video/fbdev/vesafb.c | 29 ++++++++---------------------
 1 file changed, 8 insertions(+), 21 deletions(-)

diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
index 3db3908..528fe91 100644
--- a/drivers/video/fbdev/vesafb.c
+++ b/drivers/video/fbdev/vesafb.c
@@ -19,10 +19,9 @@
 #include <linux/init.h>
 #include <linux/platform_device.h>
 #include <linux/screen_info.h>
+#include <linux/io.h>
 
 #include <video/vga.h>
-#include <asm/io.h>
-#include <asm/mtrr.h>
 
 #define dac_reg	(0x3c8)
 #define dac_val	(0x3c9)
@@ -180,16 +179,10 @@ static int vesafb_setcolreg(unsigned regno, unsigned red, unsigned green,
 
 static void vesafb_destroy(struct fb_info *info)
 {
-#ifdef CONFIG_MTRR
 	struct vesafb_par *par = info->par;
-#endif
 
 	fb_dealloc_cmap(&info->cmap);
-
-#ifdef CONFIG_MTRR
-	if (par->wc_cookie >= 0)
-		mtrr_del(par->wc_cookie, 0, 0);
-#endif
+	arch_phys_wc_del(par->wc_cookie);
 	if (info->screen_base)
 		iounmap(info->screen_base);
 	release_mem_region(info->apertures->ranges[0].base, info->apertures->ranges[0].size);
@@ -420,7 +413,6 @@ static int vesafb_probe(struct platform_device *dev)
 	request_region(0x3c0, 32, "vesafb");
 
 	if (mtrr == 3) {
-#ifdef CONFIG_MTRR
 		unsigned int temp_size = size_total;
 
 		/* Find the largest power-of-two */
@@ -428,18 +420,16 @@ static int vesafb_probe(struct platform_device *dev)
 
 		/* Try and find a power of two to add */
 		do {
-			par->wc_cookie = mtrr_add(vesafb_fix.smem_start,
-						  temp_size,
-						  MTRR_TYPE_WRCOMB, 1);
+			par->wc_cookie =
+				arch_phys_wc_add(vesafb_fix.smem_start,
+						 temp_size);
 			temp_size >>= 1;
-		} while (temp_size >= PAGE_SIZE && par->wc_cookie == -EINVAL);
-#endif
+		} while (temp_size >= PAGE_SIZE && par->wc_cookie < 0);
+
 		info->screen_base = ioremap_wc(vesafb_fix.smem_start, vesafb_fix.smem_len);
 	} else {
-#ifdef CONFIG_MTRR
 		if (mtrr && mtrr != 3)
 			WARN_ONCE(1, "Only MTRR_TYPE_WRCOMB (3) make sense\n");
-#endif
 		info->screen_base = ioremap(vesafb_fix.smem_start, vesafb_fix.smem_len);
 	}
 
@@ -477,10 +467,7 @@ static int vesafb_probe(struct platform_device *dev)
 	fb_info(info, "%s frame buffer device\n", info->fix.id);
 	return 0;
 err:
-#ifdef CONFIG_MTRR
-	if (par->wc_cookie >= 0)
-		mtrr_del(par->wc_cookie, 0, 0);
-#endif
+	arch_phys_wc_del(par->wc_cookie);
 	if (info->screen_base)
 		iounmap(info->screen_base);
 	framebuffer_release(info);
-- 
2.3.2.209.gd67f9d5.dirty


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH v4 3/3] video: fbdev: vesafb: use arch_phys_wc_add()
@ 2015-06-04 16:44   ` Luis R. Rodriguez
  0 siblings, 0 replies; 14+ messages in thread
From: Luis R. Rodriguez @ 2015-06-04 16:44 UTC (permalink / raw)
  To: tomi.valkeinen
  Cc: plagnioj, bp, hpa, linux-fbdev, luto, toshi.kani, sbsiddha,
	mingo, tglx, jgross, daniel.vetter, airlied, adaplas, robdclark,
	jg1.han, wsa, linux-kernel, Luis R. Rodriguez

From: "Luis R. Rodriguez" <mcgrof@suse.com>

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>
---
 drivers/video/fbdev/vesafb.c | 29 ++++++++---------------------
 1 file changed, 8 insertions(+), 21 deletions(-)

diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
index 3db3908..528fe91 100644
--- a/drivers/video/fbdev/vesafb.c
+++ b/drivers/video/fbdev/vesafb.c
@@ -19,10 +19,9 @@
 #include <linux/init.h>
 #include <linux/platform_device.h>
 #include <linux/screen_info.h>
+#include <linux/io.h>
 
 #include <video/vga.h>
-#include <asm/io.h>
-#include <asm/mtrr.h>
 
 #define dac_reg	(0x3c8)
 #define dac_val	(0x3c9)
@@ -180,16 +179,10 @@ static int vesafb_setcolreg(unsigned regno, unsigned red, unsigned green,
 
 static void vesafb_destroy(struct fb_info *info)
 {
-#ifdef CONFIG_MTRR
 	struct vesafb_par *par = info->par;
-#endif
 
 	fb_dealloc_cmap(&info->cmap);
-
-#ifdef CONFIG_MTRR
-	if (par->wc_cookie >= 0)
-		mtrr_del(par->wc_cookie, 0, 0);
-#endif
+	arch_phys_wc_del(par->wc_cookie);
 	if (info->screen_base)
 		iounmap(info->screen_base);
 	release_mem_region(info->apertures->ranges[0].base, info->apertures->ranges[0].size);
@@ -420,7 +413,6 @@ static int vesafb_probe(struct platform_device *dev)
 	request_region(0x3c0, 32, "vesafb");
 
 	if (mtrr = 3) {
-#ifdef CONFIG_MTRR
 		unsigned int temp_size = size_total;
 
 		/* Find the largest power-of-two */
@@ -428,18 +420,16 @@ static int vesafb_probe(struct platform_device *dev)
 
 		/* Try and find a power of two to add */
 		do {
-			par->wc_cookie = mtrr_add(vesafb_fix.smem_start,
-						  temp_size,
-						  MTRR_TYPE_WRCOMB, 1);
+			par->wc_cookie +				arch_phys_wc_add(vesafb_fix.smem_start,
+						 temp_size);
 			temp_size >>= 1;
-		} while (temp_size >= PAGE_SIZE && par->wc_cookie = -EINVAL);
-#endif
+		} while (temp_size >= PAGE_SIZE && par->wc_cookie < 0);
+
 		info->screen_base = ioremap_wc(vesafb_fix.smem_start, vesafb_fix.smem_len);
 	} else {
-#ifdef CONFIG_MTRR
 		if (mtrr && mtrr != 3)
 			WARN_ONCE(1, "Only MTRR_TYPE_WRCOMB (3) make sense\n");
-#endif
 		info->screen_base = ioremap(vesafb_fix.smem_start, vesafb_fix.smem_len);
 	}
 
@@ -477,10 +467,7 @@ static int vesafb_probe(struct platform_device *dev)
 	fb_info(info, "%s frame buffer device\n", info->fix.id);
 	return 0;
 err:
-#ifdef CONFIG_MTRR
-	if (par->wc_cookie >= 0)
-		mtrr_del(par->wc_cookie, 0, 0);
-#endif
+	arch_phys_wc_del(par->wc_cookie);
 	if (info->screen_base)
 		iounmap(info->screen_base);
 	framebuffer_release(info);
-- 
2.3.2.209.gd67f9d5.dirty


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH v4 3/3] video: fbdev: vesafb: use arch_phys_wc_add()
  2015-06-04 16:44   ` Luis R. Rodriguez
@ 2015-06-12  9:04     ` Tomi Valkeinen
  -1 siblings, 0 replies; 14+ messages in thread
From: Tomi Valkeinen @ 2015-06-12  9:04 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: plagnioj, bp, hpa, linux-fbdev, luto, toshi.kani, sbsiddha,
	mingo, tglx, jgross, daniel.vetter, airlied, adaplas, robdclark,
	jg1.han, wsa, linux-kernel, Luis R. Rodriguez

[-- Attachment #1: Type: text/plain, Size: 5383 bytes --]



On 04/06/15 19:44, Luis R. Rodriguez wrote:
> From: "Luis R. Rodriguez" <mcgrof@suse.com>
> 
> 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>
> ---
>  drivers/video/fbdev/vesafb.c | 29 ++++++++---------------------
>  1 file changed, 8 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
> index 3db3908..528fe91 100644
> --- a/drivers/video/fbdev/vesafb.c
> +++ b/drivers/video/fbdev/vesafb.c
> @@ -19,10 +19,9 @@
>  #include <linux/init.h>
>  #include <linux/platform_device.h>
>  #include <linux/screen_info.h>
> +#include <linux/io.h>
>  
>  #include <video/vga.h>
> -#include <asm/io.h>
> -#include <asm/mtrr.h>
>  
>  #define dac_reg	(0x3c8)
>  #define dac_val	(0x3c9)
> @@ -180,16 +179,10 @@ static int vesafb_setcolreg(unsigned regno, unsigned red, unsigned green,
>  
>  static void vesafb_destroy(struct fb_info *info)
>  {
> -#ifdef CONFIG_MTRR
>  	struct vesafb_par *par = info->par;
> -#endif
>  
>  	fb_dealloc_cmap(&info->cmap);
> -
> -#ifdef CONFIG_MTRR
> -	if (par->wc_cookie >= 0)
> -		mtrr_del(par->wc_cookie, 0, 0);
> -#endif
> +	arch_phys_wc_del(par->wc_cookie);
>  	if (info->screen_base)
>  		iounmap(info->screen_base);
>  	release_mem_region(info->apertures->ranges[0].base, info->apertures->ranges[0].size);
> @@ -420,7 +413,6 @@ static int vesafb_probe(struct platform_device *dev)
>  	request_region(0x3c0, 32, "vesafb");
>  
>  	if (mtrr == 3) {
> -#ifdef CONFIG_MTRR
>  		unsigned int temp_size = size_total;
>  
>  		/* Find the largest power-of-two */
> @@ -428,18 +420,16 @@ static int vesafb_probe(struct platform_device *dev)
>  
>  		/* Try and find a power of two to add */
>  		do {
> -			par->wc_cookie = mtrr_add(vesafb_fix.smem_start,
> -						  temp_size,
> -						  MTRR_TYPE_WRCOMB, 1);
> +			par->wc_cookie =
> +				arch_phys_wc_add(vesafb_fix.smem_start,
> +						 temp_size);
>  			temp_size >>= 1;
> -		} while (temp_size >= PAGE_SIZE && par->wc_cookie == -EINVAL);
> -#endif
> +		} while (temp_size >= PAGE_SIZE && par->wc_cookie < 0);
> +

Looks like arch_phys_wc_add prints a warning if it fails, and the above
loop may retry it many (?) times. Probably not a big issue, but may be
somewhat confusing.

 Tomi


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v4 3/3] video: fbdev: vesafb: use arch_phys_wc_add()
@ 2015-06-12  9:04     ` Tomi Valkeinen
  0 siblings, 0 replies; 14+ messages in thread
From: Tomi Valkeinen @ 2015-06-12  9:04 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: plagnioj, bp, hpa, linux-fbdev, luto, toshi.kani, sbsiddha,
	mingo, tglx, jgross, daniel.vetter, airlied, adaplas, robdclark,
	jg1.han, wsa, linux-kernel, Luis R. Rodriguez

[-- Attachment #1: Type: text/plain, Size: 5383 bytes --]



On 04/06/15 19:44, Luis R. Rodriguez wrote:
> From: "Luis R. Rodriguez" <mcgrof@suse.com>
> 
> 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>
> ---
>  drivers/video/fbdev/vesafb.c | 29 ++++++++---------------------
>  1 file changed, 8 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
> index 3db3908..528fe91 100644
> --- a/drivers/video/fbdev/vesafb.c
> +++ b/drivers/video/fbdev/vesafb.c
> @@ -19,10 +19,9 @@
>  #include <linux/init.h>
>  #include <linux/platform_device.h>
>  #include <linux/screen_info.h>
> +#include <linux/io.h>
>  
>  #include <video/vga.h>
> -#include <asm/io.h>
> -#include <asm/mtrr.h>
>  
>  #define dac_reg	(0x3c8)
>  #define dac_val	(0x3c9)
> @@ -180,16 +179,10 @@ static int vesafb_setcolreg(unsigned regno, unsigned red, unsigned green,
>  
>  static void vesafb_destroy(struct fb_info *info)
>  {
> -#ifdef CONFIG_MTRR
>  	struct vesafb_par *par = info->par;
> -#endif
>  
>  	fb_dealloc_cmap(&info->cmap);
> -
> -#ifdef CONFIG_MTRR
> -	if (par->wc_cookie >= 0)
> -		mtrr_del(par->wc_cookie, 0, 0);
> -#endif
> +	arch_phys_wc_del(par->wc_cookie);
>  	if (info->screen_base)
>  		iounmap(info->screen_base);
>  	release_mem_region(info->apertures->ranges[0].base, info->apertures->ranges[0].size);
> @@ -420,7 +413,6 @@ static int vesafb_probe(struct platform_device *dev)
>  	request_region(0x3c0, 32, "vesafb");
>  
>  	if (mtrr == 3) {
> -#ifdef CONFIG_MTRR
>  		unsigned int temp_size = size_total;
>  
>  		/* Find the largest power-of-two */
> @@ -428,18 +420,16 @@ static int vesafb_probe(struct platform_device *dev)
>  
>  		/* Try and find a power of two to add */
>  		do {
> -			par->wc_cookie = mtrr_add(vesafb_fix.smem_start,
> -						  temp_size,
> -						  MTRR_TYPE_WRCOMB, 1);
> +			par->wc_cookie =
> +				arch_phys_wc_add(vesafb_fix.smem_start,
> +						 temp_size);
>  			temp_size >>= 1;
> -		} while (temp_size >= PAGE_SIZE && par->wc_cookie == -EINVAL);
> -#endif
> +		} while (temp_size >= PAGE_SIZE && par->wc_cookie < 0);
> +

Looks like arch_phys_wc_add prints a warning if it fails, and the above
loop may retry it many (?) times. Probably not a big issue, but may be
somewhat confusing.

 Tomi


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v4 3/3] video: fbdev: vesafb: use arch_phys_wc_add()
  2015-06-12  9:04     ` Tomi Valkeinen
@ 2015-06-15 22:27       ` Luis R. Rodriguez
  -1 siblings, 0 replies; 14+ messages in thread
From: Luis R. Rodriguez @ 2015-06-15 22:27 UTC (permalink / raw)
  To: Tomi Valkeinen
  Cc: Luis R. Rodriguez, plagnioj, bp, hpa, linux-fbdev, luto,
	toshi.kani, sbsiddha, mingo, tglx, jgross, daniel.vetter,
	airlied, adaplas, robdclark, jg1.han, wsa, linux-kernel

On Fri, Jun 12, 2015 at 12:04:14PM +0300, Tomi Valkeinen wrote:
> 
> 
> On 04/06/15 19:44, Luis R. Rodriguez wrote:
> > From: "Luis R. Rodriguez" <mcgrof@suse.com>
> > 
> > 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>
> > ---
> >  drivers/video/fbdev/vesafb.c | 29 ++++++++---------------------
> >  1 file changed, 8 insertions(+), 21 deletions(-)
> > 
> > diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
> > index 3db3908..528fe91 100644
> > --- a/drivers/video/fbdev/vesafb.c
> > +++ b/drivers/video/fbdev/vesafb.c
> > @@ -19,10 +19,9 @@
> >  #include <linux/init.h>
> >  #include <linux/platform_device.h>
> >  #include <linux/screen_info.h>
> > +#include <linux/io.h>
> >  
> >  #include <video/vga.h>
> > -#include <asm/io.h>
> > -#include <asm/mtrr.h>
> >  
> >  #define dac_reg	(0x3c8)
> >  #define dac_val	(0x3c9)
> > @@ -180,16 +179,10 @@ static int vesafb_setcolreg(unsigned regno, unsigned red, unsigned green,
> >  
> >  static void vesafb_destroy(struct fb_info *info)
> >  {
> > -#ifdef CONFIG_MTRR
> >  	struct vesafb_par *par = info->par;
> > -#endif
> >  
> >  	fb_dealloc_cmap(&info->cmap);
> > -
> > -#ifdef CONFIG_MTRR
> > -	if (par->wc_cookie >= 0)
> > -		mtrr_del(par->wc_cookie, 0, 0);
> > -#endif
> > +	arch_phys_wc_del(par->wc_cookie);
> >  	if (info->screen_base)
> >  		iounmap(info->screen_base);
> >  	release_mem_region(info->apertures->ranges[0].base, info->apertures->ranges[0].size);
> > @@ -420,7 +413,6 @@ static int vesafb_probe(struct platform_device *dev)
> >  	request_region(0x3c0, 32, "vesafb");
> >  
> >  	if (mtrr == 3) {
> > -#ifdef CONFIG_MTRR
> >  		unsigned int temp_size = size_total;
> >  
> >  		/* Find the largest power-of-two */
> > @@ -428,18 +420,16 @@ static int vesafb_probe(struct platform_device *dev)
> >  
> >  		/* Try and find a power of two to add */
> >  		do {
> > -			par->wc_cookie = mtrr_add(vesafb_fix.smem_start,
> > -						  temp_size,
> > -						  MTRR_TYPE_WRCOMB, 1);
> > +			par->wc_cookie =
> > +				arch_phys_wc_add(vesafb_fix.smem_start,
> > +						 temp_size);
> >  			temp_size >>= 1;
> > -		} while (temp_size >= PAGE_SIZE && par->wc_cookie == -EINVAL);
> > -#endif
> > +		} while (temp_size >= PAGE_SIZE && par->wc_cookie < 0);
> > +
> 
> Looks like arch_phys_wc_add prints a warning if it fails, and the above
> loop may retry it many (?) times. Probably not a big issue, but may be
> somewhat confusing.

On most systems arch_phys_wc_add() won't ever run so I think that's a
fair compromise to reach as we phase out MTRR. If we really wanted
to fix this one could generalize the whole loop control stuff and use
a new arch_phys API to generalize all that code as tons of drivers
borrow the same logic. I decided this was pointless as we're phasing
this out anyway and this code will simply be a no-op on most systems
now.

Let me know if you have any other preference or ideas.

  Luis

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v4 3/3] video: fbdev: vesafb: use arch_phys_wc_add()
@ 2015-06-15 22:27       ` Luis R. Rodriguez
  0 siblings, 0 replies; 14+ messages in thread
From: Luis R. Rodriguez @ 2015-06-15 22:27 UTC (permalink / raw)
  To: Tomi Valkeinen
  Cc: Luis R. Rodriguez, plagnioj, bp, hpa, linux-fbdev, luto,
	toshi.kani, sbsiddha, mingo, tglx, jgross, daniel.vetter,
	airlied, adaplas, robdclark, jg1.han, wsa, linux-kernel

On Fri, Jun 12, 2015 at 12:04:14PM +0300, Tomi Valkeinen wrote:
> 
> 
> On 04/06/15 19:44, Luis R. Rodriguez wrote:
> > From: "Luis R. Rodriguez" <mcgrof@suse.com>
> > 
> > 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>
> > ---
> >  drivers/video/fbdev/vesafb.c | 29 ++++++++---------------------
> >  1 file changed, 8 insertions(+), 21 deletions(-)
> > 
> > diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
> > index 3db3908..528fe91 100644
> > --- a/drivers/video/fbdev/vesafb.c
> > +++ b/drivers/video/fbdev/vesafb.c
> > @@ -19,10 +19,9 @@
> >  #include <linux/init.h>
> >  #include <linux/platform_device.h>
> >  #include <linux/screen_info.h>
> > +#include <linux/io.h>
> >  
> >  #include <video/vga.h>
> > -#include <asm/io.h>
> > -#include <asm/mtrr.h>
> >  
> >  #define dac_reg	(0x3c8)
> >  #define dac_val	(0x3c9)
> > @@ -180,16 +179,10 @@ static int vesafb_setcolreg(unsigned regno, unsigned red, unsigned green,
> >  
> >  static void vesafb_destroy(struct fb_info *info)
> >  {
> > -#ifdef CONFIG_MTRR
> >  	struct vesafb_par *par = info->par;
> > -#endif
> >  
> >  	fb_dealloc_cmap(&info->cmap);
> > -
> > -#ifdef CONFIG_MTRR
> > -	if (par->wc_cookie >= 0)
> > -		mtrr_del(par->wc_cookie, 0, 0);
> > -#endif
> > +	arch_phys_wc_del(par->wc_cookie);
> >  	if (info->screen_base)
> >  		iounmap(info->screen_base);
> >  	release_mem_region(info->apertures->ranges[0].base, info->apertures->ranges[0].size);
> > @@ -420,7 +413,6 @@ static int vesafb_probe(struct platform_device *dev)
> >  	request_region(0x3c0, 32, "vesafb");
> >  
> >  	if (mtrr = 3) {
> > -#ifdef CONFIG_MTRR
> >  		unsigned int temp_size = size_total;
> >  
> >  		/* Find the largest power-of-two */
> > @@ -428,18 +420,16 @@ static int vesafb_probe(struct platform_device *dev)
> >  
> >  		/* Try and find a power of two to add */
> >  		do {
> > -			par->wc_cookie = mtrr_add(vesafb_fix.smem_start,
> > -						  temp_size,
> > -						  MTRR_TYPE_WRCOMB, 1);
> > +			par->wc_cookie > > +				arch_phys_wc_add(vesafb_fix.smem_start,
> > +						 temp_size);
> >  			temp_size >>= 1;
> > -		} while (temp_size >= PAGE_SIZE && par->wc_cookie = -EINVAL);
> > -#endif
> > +		} while (temp_size >= PAGE_SIZE && par->wc_cookie < 0);
> > +
> 
> Looks like arch_phys_wc_add prints a warning if it fails, and the above
> loop may retry it many (?) times. Probably not a big issue, but may be
> somewhat confusing.

On most systems arch_phys_wc_add() won't ever run so I think that's a
fair compromise to reach as we phase out MTRR. If we really wanted
to fix this one could generalize the whole loop control stuff and use
a new arch_phys API to generalize all that code as tons of drivers
borrow the same logic. I decided this was pointless as we're phasing
this out anyway and this code will simply be a no-op on most systems
now.

Let me know if you have any other preference or ideas.

  Luis

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v4 3/3] video: fbdev: vesafb: use arch_phys_wc_add()
  2015-06-15 22:27       ` Luis R. Rodriguez
@ 2015-06-16  6:43         ` Tomi Valkeinen
  -1 siblings, 0 replies; 14+ messages in thread
From: Tomi Valkeinen @ 2015-06-16  6:43 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: Luis R. Rodriguez, plagnioj, bp, hpa, linux-fbdev, luto,
	toshi.kani, sbsiddha, mingo, tglx, jgross, daniel.vetter,
	airlied, adaplas, robdclark, jg1.han, wsa, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 6362 bytes --]



On 16/06/15 01:27, Luis R. Rodriguez wrote:
> On Fri, Jun 12, 2015 at 12:04:14PM +0300, Tomi Valkeinen wrote:
>>
>>
>> On 04/06/15 19:44, Luis R. Rodriguez wrote:
>>> From: "Luis R. Rodriguez" <mcgrof@suse.com>
>>>
>>> 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>
>>> ---
>>>  drivers/video/fbdev/vesafb.c | 29 ++++++++---------------------
>>>  1 file changed, 8 insertions(+), 21 deletions(-)
>>>
>>> diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
>>> index 3db3908..528fe91 100644
>>> --- a/drivers/video/fbdev/vesafb.c
>>> +++ b/drivers/video/fbdev/vesafb.c
>>> @@ -19,10 +19,9 @@
>>>  #include <linux/init.h>
>>>  #include <linux/platform_device.h>
>>>  #include <linux/screen_info.h>
>>> +#include <linux/io.h>
>>>  
>>>  #include <video/vga.h>
>>> -#include <asm/io.h>
>>> -#include <asm/mtrr.h>
>>>  
>>>  #define dac_reg	(0x3c8)
>>>  #define dac_val	(0x3c9)
>>> @@ -180,16 +179,10 @@ static int vesafb_setcolreg(unsigned regno, unsigned red, unsigned green,
>>>  
>>>  static void vesafb_destroy(struct fb_info *info)
>>>  {
>>> -#ifdef CONFIG_MTRR
>>>  	struct vesafb_par *par = info->par;
>>> -#endif
>>>  
>>>  	fb_dealloc_cmap(&info->cmap);
>>> -
>>> -#ifdef CONFIG_MTRR
>>> -	if (par->wc_cookie >= 0)
>>> -		mtrr_del(par->wc_cookie, 0, 0);
>>> -#endif
>>> +	arch_phys_wc_del(par->wc_cookie);
>>>  	if (info->screen_base)
>>>  		iounmap(info->screen_base);
>>>  	release_mem_region(info->apertures->ranges[0].base, info->apertures->ranges[0].size);
>>> @@ -420,7 +413,6 @@ static int vesafb_probe(struct platform_device *dev)
>>>  	request_region(0x3c0, 32, "vesafb");
>>>  
>>>  	if (mtrr == 3) {
>>> -#ifdef CONFIG_MTRR
>>>  		unsigned int temp_size = size_total;
>>>  
>>>  		/* Find the largest power-of-two */
>>> @@ -428,18 +420,16 @@ static int vesafb_probe(struct platform_device *dev)
>>>  
>>>  		/* Try and find a power of two to add */
>>>  		do {
>>> -			par->wc_cookie = mtrr_add(vesafb_fix.smem_start,
>>> -						  temp_size,
>>> -						  MTRR_TYPE_WRCOMB, 1);
>>> +			par->wc_cookie =
>>> +				arch_phys_wc_add(vesafb_fix.smem_start,
>>> +						 temp_size);
>>>  			temp_size >>= 1;
>>> -		} while (temp_size >= PAGE_SIZE && par->wc_cookie == -EINVAL);
>>> -#endif
>>> +		} while (temp_size >= PAGE_SIZE && par->wc_cookie < 0);
>>> +
>>
>> Looks like arch_phys_wc_add prints a warning if it fails, and the above
>> loop may retry it many (?) times. Probably not a big issue, but may be
>> somewhat confusing.
> 
> On most systems arch_phys_wc_add() won't ever run so I think that's a
> fair compromise to reach as we phase out MTRR. If we really wanted
> to fix this one could generalize the whole loop control stuff and use
> a new arch_phys API to generalize all that code as tons of drivers
> borrow the same logic. I decided this was pointless as we're phasing
> this out anyway and this code will simply be a no-op on most systems
> now.
> 
> Let me know if you have any other preference or ideas.

Ok, sounds fine to me. I'll queue these for 4.2.

 Tomi


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH v4 3/3] video: fbdev: vesafb: use arch_phys_wc_add()
@ 2015-06-16  6:43         ` Tomi Valkeinen
  0 siblings, 0 replies; 14+ messages in thread
From: Tomi Valkeinen @ 2015-06-16  6:43 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: Luis R. Rodriguez, plagnioj, bp, hpa, linux-fbdev, luto,
	toshi.kani, sbsiddha, mingo, tglx, jgross, daniel.vetter,
	airlied, adaplas, robdclark, jg1.han, wsa, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 6362 bytes --]



On 16/06/15 01:27, Luis R. Rodriguez wrote:
> On Fri, Jun 12, 2015 at 12:04:14PM +0300, Tomi Valkeinen wrote:
>>
>>
>> On 04/06/15 19:44, Luis R. Rodriguez wrote:
>>> From: "Luis R. Rodriguez" <mcgrof@suse.com>
>>>
>>> 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>
>>> ---
>>>  drivers/video/fbdev/vesafb.c | 29 ++++++++---------------------
>>>  1 file changed, 8 insertions(+), 21 deletions(-)
>>>
>>> diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
>>> index 3db3908..528fe91 100644
>>> --- a/drivers/video/fbdev/vesafb.c
>>> +++ b/drivers/video/fbdev/vesafb.c
>>> @@ -19,10 +19,9 @@
>>>  #include <linux/init.h>
>>>  #include <linux/platform_device.h>
>>>  #include <linux/screen_info.h>
>>> +#include <linux/io.h>
>>>  
>>>  #include <video/vga.h>
>>> -#include <asm/io.h>
>>> -#include <asm/mtrr.h>
>>>  
>>>  #define dac_reg	(0x3c8)
>>>  #define dac_val	(0x3c9)
>>> @@ -180,16 +179,10 @@ static int vesafb_setcolreg(unsigned regno, unsigned red, unsigned green,
>>>  
>>>  static void vesafb_destroy(struct fb_info *info)
>>>  {
>>> -#ifdef CONFIG_MTRR
>>>  	struct vesafb_par *par = info->par;
>>> -#endif
>>>  
>>>  	fb_dealloc_cmap(&info->cmap);
>>> -
>>> -#ifdef CONFIG_MTRR
>>> -	if (par->wc_cookie >= 0)
>>> -		mtrr_del(par->wc_cookie, 0, 0);
>>> -#endif
>>> +	arch_phys_wc_del(par->wc_cookie);
>>>  	if (info->screen_base)
>>>  		iounmap(info->screen_base);
>>>  	release_mem_region(info->apertures->ranges[0].base, info->apertures->ranges[0].size);
>>> @@ -420,7 +413,6 @@ static int vesafb_probe(struct platform_device *dev)
>>>  	request_region(0x3c0, 32, "vesafb");
>>>  
>>>  	if (mtrr == 3) {
>>> -#ifdef CONFIG_MTRR
>>>  		unsigned int temp_size = size_total;
>>>  
>>>  		/* Find the largest power-of-two */
>>> @@ -428,18 +420,16 @@ static int vesafb_probe(struct platform_device *dev)
>>>  
>>>  		/* Try and find a power of two to add */
>>>  		do {
>>> -			par->wc_cookie = mtrr_add(vesafb_fix.smem_start,
>>> -						  temp_size,
>>> -						  MTRR_TYPE_WRCOMB, 1);
>>> +			par->wc_cookie =
>>> +				arch_phys_wc_add(vesafb_fix.smem_start,
>>> +						 temp_size);
>>>  			temp_size >>= 1;
>>> -		} while (temp_size >= PAGE_SIZE && par->wc_cookie == -EINVAL);
>>> -#endif
>>> +		} while (temp_size >= PAGE_SIZE && par->wc_cookie < 0);
>>> +
>>
>> Looks like arch_phys_wc_add prints a warning if it fails, and the above
>> loop may retry it many (?) times. Probably not a big issue, but may be
>> somewhat confusing.
> 
> On most systems arch_phys_wc_add() won't ever run so I think that's a
> fair compromise to reach as we phase out MTRR. If we really wanted
> to fix this one could generalize the whole loop control stuff and use
> a new arch_phys API to generalize all that code as tons of drivers
> borrow the same logic. I decided this was pointless as we're phasing
> this out anyway and this code will simply be a no-op on most systems
> now.
> 
> Let me know if you have any other preference or ideas.

Ok, sounds fine to me. I'll queue these for 4.2.

 Tomi


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2015-06-16  6:44 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-04 16:44 [PATCH v4 0/3] vesafb: remove theoretical MTRR uses Luis R. Rodriguez
2015-06-04 16:44 ` Luis R. Rodriguez
2015-06-04 16:44 ` [PATCH v4 1/3] video: fbdev: vesafb: only support MTRR_TYPE_WRCOMB Luis R. Rodriguez
2015-06-04 16:44   ` Luis R. Rodriguez
2015-06-04 16:44 ` [PATCH v4 2/3] video: fbdev: vesafb: add missing mtrr_del() for added MTRR Luis R. Rodriguez
2015-06-04 16:44   ` Luis R. Rodriguez
2015-06-04 16:44 ` [PATCH v4 3/3] video: fbdev: vesafb: use arch_phys_wc_add() Luis R. Rodriguez
2015-06-04 16:44   ` Luis R. Rodriguez
2015-06-12  9:04   ` Tomi Valkeinen
2015-06-12  9:04     ` Tomi Valkeinen
2015-06-15 22:27     ` Luis R. Rodriguez
2015-06-15 22:27       ` Luis R. Rodriguez
2015-06-16  6:43       ` Tomi Valkeinen
2015-06-16  6:43         ` Tomi Valkeinen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.