--- cvs/xc/programs/Xserver/hw/xfree86/drivers/ati/radeon_driver.c	2005-11-09 01:15:42.000000000 +0000
+++ radeon_driver.c	2005-11-09 01:39:52.000000000 +0000
@@ -2363,6 +2363,9 @@
     EntityInfoPtr  pEnt   = info->pEnt;
     GDevPtr        dev    = pEnt->device;
     MessageType    from;
+    unsigned long int RamDetected	= 0;	
+    /*According with struct fb_fix_screeninfo smem_len it's __u32,
+    * but this unsigned long is enough to hold value of RAM*/
     unsigned char *RADEONMMIO = info->MMIO;
 #ifdef XF86DRI
     const char *s;
@@ -2677,8 +2680,12 @@
 
 				/* Read registers used to determine options */
     from                     = X_PROBED;
-    if (info->FBDev)
+    if (info->FBDev)  {
 	pScrn->videoRam      = fbdevHWGetVidmem(pScrn) / 1024;
+	RamDetected = (unsigned long int) pScrn->videoRam;
+	/*Real Memory Size, VideoRam is always greater or equal
+	* to zero so no more checks*/
+	}
     else if ((info->ChipFamily == CHIP_FAMILY_RS100) ||
 	     (info->ChipFamily == CHIP_FAMILY_RS200) ||
 	     (info->ChipFamily == CHIP_FAMILY_RS300)) {
@@ -2687,6 +2694,8 @@
 	pScrn->videoRam = (((tom >> 16) -
 			    (tom & 0xffff) + 1) << 6);
 
+        RamDetected = (unsigned long int) pScrn->videoRam;
+
 	OUTREG(RADEON_CONFIG_MEMSIZE, pScrn->videoRam * 1024);
     } else {
         /* There are different HDP mapping schemes depending on single/multi funciton setting,
@@ -2695,6 +2704,7 @@
          * 128M is configured as invisible FB to CPU that can only be accessed from chip side.
          */
         pScrn->videoRam      = INREG(RADEON_CONFIG_MEMSIZE) / 1024;
+        RamDetected = (unsigned long int) pScrn->videoRam;
         if (pScrn->videoRam > 128*1024) pScrn->videoRam = 128*1024;
         if ((info->ChipFamily == CHIP_FAMILY_RV350) ||
             (info->ChipFamily == CHIP_FAMILY_RV380) ||
@@ -2727,18 +2737,26 @@
     info->BusCntl            = INREG(RADEON_BUS_CNTL);
 
     RADEONGetVRamType(pScrn);
-
-    if (dev->videoRam) {
+/*This was already a little discussed, does Override VideoRAM should be enabled??
+* Make a check if value is greater than detected Ram, and if it's greater than 128MB.
+* If driver is limited to 128MB, no bother to make VideoRAM bigger*/
+    if ((dev->videoRam <= 128*1024) && ((unsigned long int)dev->videoRam <= RamDetected))
+	{
 	xf86DrvMsg(pScrn->scrnIndex, X_INFO,
-		   "Video RAM override, using %d kB instead of %d kB\n",
+		   "Video RAM override, using %d kByte instead of %d kByte\n",
 		   dev->videoRam,
 		   pScrn->videoRam);
 	from             = X_CONFIG;
 	pScrn->videoRam  = dev->videoRam;
     }
-
+    else {
+	xf86DrvMsg(pScrn->scrnIndex, X_INFO,
+		   "Video RAM override ignored, Video RAM value %d kByte is too big\n",
+		   dev->videoRam);
+   }
     xf86DrvMsg(pScrn->scrnIndex, from,
-	       "VideoRAM: %d kByte (%d bit %s SDRAM)\n", pScrn->videoRam, info->RamWidth, info->IsDDR?"DDR":"SDR");
+	       "VideoRAM: Detected %ld kByte, using %d kByte (%d bit %s SDRAM)\n",
+		RamDetected, pScrn->videoRam, info->RamWidth, info->IsDDR?"DDR":"SDR");
 
     /* FIXME: For now, split FB into two equal sections. This should
      * be able to be adjusted by user with a config option. */
