[Spice-devel,xf86,qxl,driver,2/5] qxl_pre_init: fix calculation of available video memory

Submitted by Uri Lublin on Jan. 17, 2013, 2:26 p.m.

Details

Message ID c819c0c6b1f80cde00fb61893facbf01ebedad09.1358430965.git.uril@redhat.com
State New
Headers show

Not browsing as part of any series.

Commit Message

Uri Lublin Jan. 17, 2013, 2:26 p.m.
Don't forget to substract monitors_config area.

Memory map of qxl RAM looks something like the following:
---------------------
|                   |
| Surface0 Area     |
|                   |
---------------------
|                   |
|                   |
| Video Pages       |
|                   |
|                   |
---------------------
| Monitors Config   |
---------------------
| RAM Header        |
---------------------
---
 src/qxl_driver.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/qxl_driver.c b/src/qxl_driver.c
index e289c70..1a253d2 100644
--- a/src/qxl_driver.c
+++ b/src/qxl_driver.c
@@ -2453,7 +2453,13 @@  qxl_pre_init (ScrnInfoPtr pScrn, int flags)
 #else
     xspice_init_qxl_ram (qxl); /* initialize the rings */
 #endif
-    pScrn->videoRam = (qxl->rom->num_pages * 4096) / 1024;
+
+#define DIV_ROUND_UP(n, a) (((n) + (a) - 1) / (a))
+#define BYTES_TO_KB(bytes) DIV_ROUND_UP(bytes, 1024)
+#define PAGES_TO_KB(pages) ((pages) * getpagesize() / 1024)
+
+    pScrn->videoRam = PAGES_TO_KB(qxl->rom->num_pages)
+                      - BYTES_TO_KB(qxl->monitors_config_size);
     xf86DrvMsg (scrnIndex, X_INFO, "%d KB of video RAM\n", pScrn->videoRam);
     xf86DrvMsg (scrnIndex, X_INFO, "%d surfaces\n", qxl->rom->n_surfaces);