linux-fbdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fbdev: fix framebuffer memory calculation for vesafb
@ 2004-10-04  1:23 Antonino A. Daplas
  2004-10-04 11:56 ` Gerd Knorr
  0 siblings, 1 reply; 3+ messages in thread
From: Antonino A. Daplas @ 2004-10-04  1:23 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Linux Fbdev development list, Gerd Knorr, Aurelien Jacobs

- use vesafb_fix.line_length * vesafb_defined.yres to calculate the minimum
  memory required for a video mode. From Aurelien Jacobs <aurel@gnuage.org>.

- separately calculate the memory required for a video mode, memory to be
  remapped, and total memory (for MTRR). From Gerd Knorr
  <kraxel@bytesex.org>.

- the 'vram' option is for memory to be remapped, not total memory.

Signed-off-by: Antonino Daplas <adaplas@pol.net>
---

 vesafb.c |   54 ++++++++++++++++++++++++++++++++----------------------
 1 files changed, 32 insertions(+), 22 deletions(-)

diff -uprN linux-2.6.9-rc3-mm1-orig/drivers/video/vesafb.c linux-2.6.9-rc3-mm1/drivers/video/vesafb.c
--- linux-2.6.9-rc3-mm1-orig/drivers/video/vesafb.c	2004-10-04 09:08:54.000000000 +0800
+++ linux-2.6.9-rc3-mm1/drivers/video/vesafb.c	2004-10-04 09:09:14.557736296 +0800
@@ -220,6 +220,9 @@ static int __init vesafb_probe(struct de
 	struct platform_device *dev = to_platform_device(device);
 	struct fb_info *info;
 	int i, err;
+	unsigned int size_vmode;
+	unsigned int size_remap;
+	unsigned int size_total;
 
 	if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
 		return -ENXIO;
@@ -231,32 +234,37 @@ static int __init vesafb_probe(struct de
 	vesafb_defined.xres = screen_info.lfb_width;
 	vesafb_defined.yres = screen_info.lfb_height;
 	vesafb_fix.line_length = screen_info.lfb_linelength;
-
-	/* Allocate enough memory for double buffering */
-	vesafb_fix.smem_len = screen_info.lfb_width * screen_info.lfb_height * vesafb_defined.bits_per_pixel >> 2;
-
-	/* check that we don't remap more memory than old cards have */
-	if (vesafb_fix.smem_len > (screen_info.lfb_size * 65536))
-		vesafb_fix.smem_len = screen_info.lfb_size * 65536;
-
-	/* Set video size according to vram boot option */
-	if (vram)
-		vesafb_fix.smem_len = vram * 1024 * 1024;
-
 	vesafb_fix.visual   = (vesafb_defined.bits_per_pixel == 8) ?
 		FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
 
-	/* limit framebuffer size to 16 MB.  Otherwise we'll eat tons of
-	 * kernel address space for nothing if the gfx card has alot of
-	 * memory (>= 128 MB isn't uncommon these days ...) */
-	if (vesafb_fix.smem_len > 16 * 1024 * 1024)
-		vesafb_fix.smem_len = 16 * 1024 * 1024;
+	/*   size_vmode -- that is the amount of memory needed for the
+	 *                 used video mode, i.e. the minimum amount of
+	 *                 memory we need. */
+	size_vmode = vesafb_fix.line_length * vesafb_defined.yres;
+
+	/*   size_total -- all video memory we have. Used for mtrr
+	 *                 entries and bounds checking. */
+	size_total = screen_info.lfb_size * 65536;
+	if (size_total < size_vmode)
+		size_total = size_vmode;
+
+	/*   size_remap -- the amount of video memory we are going to
+	 *                 use for vesafb.  With modern cards it is no
+	 *                 option to simply use size_total as that
+	 *                 wastes plenty of kernel address space. */
+	size_remap = size_vmode * 2;
+	if (vram)
+		size_remap = vram * 1024 * 1024;
+
+	if (size_remap > size_total)
+		size_remap = size_total;
+	vesafb_fix.smem_len = size_remap;
 
 #ifndef __i386__
 	screen_info.vesapm_seg = 0;
 #endif
 
-	if (!request_mem_region(vesafb_fix.smem_start, vesafb_fix.smem_len, "vesafb")) {
+	if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
 		printk(KERN_WARNING
 		       "vesafb: abort, cannot reserve video memory at 0x%lx\n",
 			vesafb_fix.smem_start);
@@ -281,8 +289,10 @@ static int __init vesafb_probe(struct de
 		goto err;
 	}
 
-	printk(KERN_INFO "vesafb: framebuffer at 0x%lx, mapped to 0x%p, size %dk\n",
-	       vesafb_fix.smem_start, info->screen_base, vesafb_fix.smem_len/1024);
+	printk(KERN_INFO "vesafb: framebuffer at 0x%lx, mapped to 0x%p, "
+	       "using %dk, total %dk\n",
+	       vesafb_fix.smem_start, info->screen_base,
+	       size_remap/1024, size_total/1024);
 	printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
 	       vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
 
@@ -362,7 +372,7 @@ static int __init vesafb_probe(struct de
 	request_region(0x3c0, 32, "vesafb");
 
 	if (mtrr) {
-		int temp_size = vesafb_fix.smem_len;
+		int temp_size = size_total;
 		/* Find the largest power-of-two */
 		while (temp_size & (temp_size - 1))
                 	temp_size &= (temp_size - 1);
@@ -393,7 +403,7 @@ static int __init vesafb_probe(struct de
 	return 0;
 err:
 	framebuffer_release(info);
-	release_mem_region(vesafb_fix.smem_start, vesafb_fix.smem_len);
+	release_mem_region(vesafb_fix.smem_start, size_total);
 	return err;
 }
 




-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl

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

* Re: [PATCH] fbdev: fix framebuffer memory calculation for vesafb
  2004-10-04  1:23 [PATCH] fbdev: fix framebuffer memory calculation for vesafb Antonino A. Daplas
@ 2004-10-04 11:56 ` Gerd Knorr
  2004-10-04 21:40   ` [PATCH] fbdev: split vesafb option vram into vtotal and vremap Antonino A. Daplas
  0 siblings, 1 reply; 3+ messages in thread
From: Gerd Knorr @ 2004-10-04 11:56 UTC (permalink / raw)
  To: adaplas; +Cc: Andrew Morton, Linux Fbdev development list, Aurelien Jacobs

> - separately calculate the memory required for a video mode, memory to be
>   remapped, and total memory (for MTRR). From Gerd Knorr
>   <kraxel@bytesex.org>.
> 
> - the 'vram' option is for memory to be remapped, not total memory.

IMHO the the only sane thing is to have two options for total + remapped
memory as well.  Otherwise we'll end up changing that back and forth like
it happened for the size calculation stuff for quite some time ...

The patch below does just that and also has the other vmode fix
(vmode = yres * linelength /* instead of yres * xres * depth >> 3 */).

  Gerd

Index: linux-2.6.9-rc3/drivers/video/vesafb.c
===================================================================
--- linux-2.6.9-rc3.orig/drivers/video/vesafb.c	2004-10-04 11:49:25.000000000 +0200
+++ linux-2.6.9-rc3/drivers/video/vesafb.c	2004-10-04 13:33:15.000000000 +0200
@@ -49,7 +49,8 @@ static struct fb_fix_screeninfo vesafb_f
 
 static int             inverse   = 0;
 static int             mtrr      = 1;
-static int	       vram __initdata = 0; /* Set amount of memory to be used */
+static int	       vram_remap __initdata = 0; /* Set amount of memory to be used */
+static int	       vram_total __initdata = 0; /* Set total amount of memory */
 static int             pmi_setpal = 0;	/* pmi for palette changes ??? */
 static int             ypan       = 0;  /* 0..nothing, 1..ypan, 2..ywrap */
 static unsigned short  *pmi_base  = NULL;
@@ -209,8 +210,10 @@ int __init vesafb_setup(char *options)
 			mtrr=1;
 		else if (! strcmp(this_opt, "nomtrr"))
 			mtrr=0;
-		else if (! strncmp(this_opt, "vram:", 5))
-			vram = simple_strtoul(this_opt+5, NULL, 0);
+		else if (! strncmp(this_opt, "vtotal:", 7))
+			vram_total = simple_strtoul(this_opt+7, NULL, 0);
+		else if (! strncmp(this_opt, "vremap:", 7))
+			vram_remap = simple_strtoul(this_opt+7, NULL, 0);
 	}
 	return 0;
 }
@@ -220,6 +223,9 @@ static int __init vesafb_probe(struct de
 	struct platform_device *dev = to_platform_device(device);
 	struct fb_info *info;
 	int i, err;
+	unsigned int size_vmode;
+	unsigned int size_remap;
+	unsigned int size_total;
 
 	if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
 		return -ENXIO;
@@ -231,32 +237,41 @@ static int __init vesafb_probe(struct de
 	vesafb_defined.xres = screen_info.lfb_width;
 	vesafb_defined.yres = screen_info.lfb_height;
 	vesafb_fix.line_length = screen_info.lfb_linelength;
-
-	/* Allocate enough memory for double buffering */
-	vesafb_fix.smem_len = screen_info.lfb_width * screen_info.lfb_height * vesafb_defined.bits_per_pixel >> 2;
-
-	/* check that we don't remap more memory than old cards have */
-	if (vesafb_fix.smem_len > (screen_info.lfb_size * 65536))
-		vesafb_fix.smem_len = screen_info.lfb_size * 65536;
-
-	/* Set video size according to vram boot option */
-	if (vram)
-		vesafb_fix.smem_len = vram * 1024 * 1024;
-
 	vesafb_fix.visual   = (vesafb_defined.bits_per_pixel == 8) ?
 		FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
 
-	/* limit framebuffer size to 16 MB.  Otherwise we'll eat tons of
-	 * kernel address space for nothing if the gfx card has alot of
-	 * memory (>= 128 MB isn't uncommon these days ...) */
-	if (vesafb_fix.smem_len > 16 * 1024 * 1024)
-		vesafb_fix.smem_len = 16 * 1024 * 1024;
+	/*   size_vmode -- that is the amount of memory needed for the
+	 *                 used video mode, i.e. the minimum amount of
+	 *                 memory we need. */
+	size_vmode = vesafb_defined.yres * vesafb_fix.line_length;
+
+	/*   size_total -- all video memory we have. Used for mtrr
+	 *                 entries, ressource allocation and bounds
+	 *                 checking. */
+	size_total = screen_info.lfb_size * 65536;
+	if (vram_total)
+		size_total = vram_total * 1024 * 1024;
+	if (size_total < size_vmode)
+		size_total = size_vmode;
+
+	/*   size_remap -- the amount of video memory we are going to
+	 *                 use for vesafb.  With modern cards it is no
+	 *                 option to simply use size_total as that
+	 *                 wastes plenty of kernel address space. */
+	size_remap  = size_vmode * 2;
+	if (vram_remap)
+		size_remap = vram_remap * 1024 * 1024;
+	if (size_remap < size_vmode)
+		size_remap = size_vmode;
+	if (size_remap > size_total)
+		size_remap = size_total;
+	vesafb_fix.smem_len = size_remap;
 
 #ifndef __i386__
 	screen_info.vesapm_seg = 0;
 #endif
 
-	if (!request_mem_region(vesafb_fix.smem_start, vesafb_fix.smem_len, "vesafb")) {
+	if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
 		printk(KERN_WARNING
 		       "vesafb: abort, cannot reserve video memory at 0x%lx\n",
 			vesafb_fix.smem_start);
@@ -281,8 +296,10 @@ static int __init vesafb_probe(struct de
 		goto err;
 	}
 
-	printk(KERN_INFO "vesafb: framebuffer at 0x%lx, mapped to 0x%p, size %dk\n",
-	       vesafb_fix.smem_start, info->screen_base, vesafb_fix.smem_len/1024);
+	printk(KERN_INFO "vesafb: framebuffer at 0x%lx, mapped to 0x%p, "
+	       "using %dk, total %dk\n",
+	       vesafb_fix.smem_start, info->screen_base,
+	       size_remap/1024, size_total/1024);
 	printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
 	       vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
 
@@ -362,7 +379,7 @@ static int __init vesafb_probe(struct de
 	request_region(0x3c0, 32, "vesafb");
 
 	if (mtrr) {
-		int temp_size = vesafb_fix.smem_len;
+		int temp_size = size_total;
 		/* Find the largest power-of-two */
 		while (temp_size & (temp_size - 1))
                 	temp_size &= (temp_size - 1);
@@ -393,7 +410,7 @@ static int __init vesafb_probe(struct de
 	return 0;
 err:
 	framebuffer_release(info);
-	release_mem_region(vesafb_fix.smem_start, vesafb_fix.smem_len);
+	release_mem_region(vesafb_fix.smem_start, size_total);
 	return err;
 }
 


-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl

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

* [PATCH] fbdev: split vesafb option vram into vtotal and vremap
  2004-10-04 11:56 ` Gerd Knorr
@ 2004-10-04 21:40   ` Antonino A. Daplas
  0 siblings, 0 replies; 3+ messages in thread
From: Antonino A. Daplas @ 2004-10-04 21:40 UTC (permalink / raw)
  To: Gerd Knorr, adaplas
  Cc: Andrew Morton, Linux Fbdev development list, Aurelien Jacobs

From Gerd Knorr <kraxel@bytesex.org>:

"IMHO the the only sane thing is to have two options for total + remapped
memory as well.  Otherwise we'll end up changing that back and forth like
it happened for the size calculation stuff for quite some time ...

The patch below does just that and also has the other vmode fix
(vmode = yres * linelength /* instead of yres * xres * depth >> 3 */)."

- Patched rediffed against 2.6.9-rc3-mm2.

- Modified documentation about the changes.

Signed-off-by: Antonino Daplas <adaplas@pol.net>
---

 Documentation/fb/vesafb.txt |    7 ++++++-
 drivers/video/vesafb.c      |   25 ++++++++++++++++---------
 2 files changed, 22 insertions(+), 10 deletions(-)

diff -uprN linux-2.6.9-rc3-mm2-orig/Documentation/fb/vesafb.txt linux-2.6.9-rc3-mm2/Documentation/fb/vesafb.txt
--- linux-2.6.9-rc3-mm2-orig/Documentation/fb/vesafb.txt	2004-10-05 05:25:09.672888064 +0800
+++ linux-2.6.9-rc3-mm2/Documentation/fb/vesafb.txt	2004-10-05 05:24:20.374382576 +0800
@@ -146,11 +146,16 @@ pmipal	Use the protected mode interface 
 
 mtrr	setup memory type range registers for the vesafb framebuffer.
 
-vram:n	remap 'n' MiB of video RAM. If 0 or not specified, remap memory
+vremap:n
+        remap 'n' MiB of video RAM. If 0 or not specified, remap memory
 	according to video mode. (2.5.66 patch/idea by Antonino Daplas
 	reversed to give override possibility (allocate more fb memory
 	than the kernel would) to 2.4 by tmb@iki.fi)
 
+vtotal:n
+        if the video BIOS of your card incorrectly determines the total
+        amount of video RAM, use this option to override the BIOS (in MiB).
+
 Have fun!
 
   Gerd
diff -uprN linux-2.6.9-rc3-mm2-orig/drivers/video/vesafb.c linux-2.6.9-rc3-mm2/drivers/video/vesafb.c
--- linux-2.6.9-rc3-mm2-orig/drivers/video/vesafb.c	2004-10-05 05:20:37.000000000 +0800
+++ linux-2.6.9-rc3-mm2/drivers/video/vesafb.c	2004-10-05 05:29:54.581575360 +0800
@@ -49,7 +49,8 @@ static struct fb_fix_screeninfo vesafb_f
 
 static int             inverse   = 0;
 static int             mtrr      = 1;
-static int	       vram __initdata = 0; /* Set amount of memory to be used */
+static int	       vram_remap __initdata = 0; /* Set amount of memory to be used */
+static int	       vram_total __initdata = 0; /* Set total amount of memory */
 static int             pmi_setpal = 0;	/* pmi for palette changes ??? */
 static int             ypan       = 0;  /* 0..nothing, 1..ypan, 2..ywrap */
 static unsigned short  *pmi_base  = NULL;
@@ -209,8 +210,10 @@ int __init vesafb_setup(char *options)
 			mtrr=1;
 		else if (! strcmp(this_opt, "nomtrr"))
 			mtrr=0;
-		else if (! strncmp(this_opt, "vram:", 5))
-			vram = simple_strtoul(this_opt+5, NULL, 0);
+		else if (! strncmp(this_opt, "vtotal:", 7))
+			vram_total = simple_strtoul(this_opt+7, NULL, 0);
+		else if (! strncmp(this_opt, "vremap:", 7))
+			vram_remap = simple_strtoul(this_opt+7, NULL, 0);
 	}
 	return 0;
 }
@@ -240,11 +243,14 @@ static int __init vesafb_probe(struct de
 	/*   size_vmode -- that is the amount of memory needed for the
 	 *                 used video mode, i.e. the minimum amount of
 	 *                 memory we need. */
-	size_vmode = vesafb_fix.line_length * vesafb_defined.yres;
+	size_vmode = vesafb_defined.yres * vesafb_fix.line_length;
 
 	/*   size_total -- all video memory we have. Used for mtrr
-	 *                 entries and bounds checking. */
+	 *                 entries, ressource allocation and bounds
+	 *                 checking. */
 	size_total = screen_info.lfb_size * 65536;
+	if (vram_total)
+		size_total = vram_total * 1024 * 1024;
 	if (size_total < size_vmode)
 		size_total = size_vmode;
 
@@ -252,10 +258,11 @@ static int __init vesafb_probe(struct de
 	 *                 use for vesafb.  With modern cards it is no
 	 *                 option to simply use size_total as that
 	 *                 wastes plenty of kernel address space. */
-	size_remap = size_vmode * 2;
-	if (vram)
-		size_remap = vram * 1024 * 1024;
-
+	size_remap  = size_vmode * 2;
+	if (vram_remap)
+		size_remap = vram_remap * 1024 * 1024;
+	if (size_remap < size_vmode)
+		size_remap = size_vmode;
 	if (size_remap > size_total)
 		size_remap = size_total;
 	vesafb_fix.smem_len = size_remap;




-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl

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

end of thread, other threads:[~2004-10-04 21:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-10-04  1:23 [PATCH] fbdev: fix framebuffer memory calculation for vesafb Antonino A. Daplas
2004-10-04 11:56 ` Gerd Knorr
2004-10-04 21:40   ` [PATCH] fbdev: split vesafb option vram into vtotal and vremap Antonino A. Daplas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).