radeon: fix tx_table[] entry
[mesa.git] / src / mesa / drivers / dri / radeon / radeon_cs_legacy.c
index 714d262812401d8699fcc2abd4bcec4bc86db1d3..f1addb299e241d18f4d94f416bace6ddbc12682d 100644 (file)
  */
 #include <errno.h>
 
-
-#include "common_context.h"
-#include "radeon_cs.h"
-#include "radeon_cs_legacy.h"
-#include "radeon_bo_legacy.h"
-
+#include "radeon_bocs_wrapper.h"
+#include "radeon_common.h"
 
 struct cs_manager_legacy {
     struct radeon_cs_manager    base;
@@ -44,6 +40,8 @@ struct cs_manager_legacy {
     /* hack for scratch stuff */
     uint32_t                    pending_age;
     uint32_t                    pending_count;
+
+
 };
 
 struct cs_reloc_legacy {
@@ -73,25 +71,6 @@ static struct radeon_cs *cs_create(struct radeon_cs_manager *csm,
     return cs;
 }
 
-int cs_write_dword(struct radeon_cs *cs, uint32_t dword)
-{
-    if (cs->cdw >= cs->ndw) {
-        uint32_t tmp, *ptr;
-        tmp = (cs->cdw + 1 + 0x3FF) & (~0x3FF);
-        ptr = (uint32_t*)realloc(cs->packets, 4 * tmp);
-        if (ptr == NULL) {
-            return -ENOMEM;
-        }
-        cs->packets = ptr;
-        cs->ndw = tmp;
-    }
-    cs->packets[cs->cdw++] = dword;
-    if (cs->section) {
-        cs->section_cdw++;
-    }
-    return 0;
-}
-
 static int cs_write_reloc(struct radeon_cs *cs,
                           struct radeon_bo *bo,
                           uint32_t read_domain,
@@ -190,6 +169,21 @@ static int cs_begin(struct radeon_cs *cs,
     cs->section_file = file;
     cs->section_func = func;
     cs->section_line = line;
+
+
+    if (cs->cdw + ndw > cs->ndw) {
+        uint32_t tmp, *ptr;
+       int num = (ndw > 0x3FF) ? ndw : 0x3FF;
+
+        tmp = (cs->cdw + 1 + num) & (~num);
+        ptr = (uint32_t*)realloc(cs->packets, 4 * tmp);
+        if (ptr == NULL) {
+            return -ENOMEM;
+        }
+        cs->packets = ptr;
+        cs->ndw = tmp;
+    }
+
     return 0;
 }
 
@@ -223,20 +217,29 @@ static int cs_process_relocs(struct radeon_cs *cs)
 
     csm = (struct cs_manager_legacy*)cs->csm;
     relocs = (struct cs_reloc_legacy *)cs->relocs;
-    for (i = 0; i < cs->crelocs; i++) {
-        for (j = 0; j < relocs[i].cindices; j++) {
+restart:
+    for (i = 0; i < cs->crelocs; i++) 
+    {
+        for (j = 0; j < relocs[i].cindices; j++) 
+        {
             uint32_t soffset, eoffset;
 
             r = radeon_bo_legacy_validate(relocs[i].base.bo,
                                            &soffset, &eoffset);
-            if (r) {
+               if (r == -EAGAIN)
+            {
+                    goto restart;
+            }
+            if (r) 
+            {
                 fprintf(stderr, "validated %p [0x%08X, 0x%08X]\n",
                         relocs[i].base.bo, soffset, eoffset);
                 return r;
             }
             cs->packets[relocs[i].indices[j]] += soffset;
-            if (cs->packets[relocs[i].indices[j]] >= eoffset) {
-                radeon_bo_debug(relocs[i].base.bo, 12);
+            if (cs->packets[relocs[i].indices[j]] >= eoffset) 
+            {
+             /*                radeon_bo_debug(relocs[i].base.bo, 12); */
                 fprintf(stderr, "validated %p [0x%08X, 0x%08X]\n",
                         relocs[i].base.bo, soffset, eoffset);
                 fprintf(stderr, "above end: %p 0x%08X 0x%08X\n",
@@ -265,14 +268,6 @@ static int cs_set_age(struct radeon_cs *cs)
     return 0;
 }
 
-static void dump_cmdbuf(struct radeon_cs *cs)
-{
-  int i;
-  for (i = 0; i < cs->cdw; i++){
-    fprintf(stderr,"%x: %08x\n", i, cs->packets[i]);
-  }
-
-}
 static int cs_emit(struct radeon_cs *cs)
 {
     struct cs_manager_legacy *csm = (struct cs_manager_legacy*)cs->csm;
@@ -283,9 +278,9 @@ static int cs_emit(struct radeon_cs *cs)
 
     csm->ctx->vtbl.emit_cs_header(cs, csm->ctx);
 
-
     /* append buffer age */
-    if (IS_R300_CLASS(csm->ctx->radeonScreen)) {
+    if ( IS_R300_CLASS(csm->ctx->radeonScreen) )
+    { 
       age.scratch.cmd_type = R300_CMD_SCRATCH;
       /* Scratch register 2 corresponds to what radeonGetAge polls */
       csm->pending_age = 0;
@@ -295,8 +290,7 @@ static int cs_emit(struct radeon_cs *cs)
       age.scratch.n_bufs = 1;
       age.scratch.flags = 0;
       radeon_cs_write_dword(cs, age.u);
-      radeon_cs_write_dword(cs, ull & 0xffffffff);
-      radeon_cs_write_dword(cs, ull >> 32);
+      radeon_cs_write_qword(cs, ull);
       radeon_cs_write_dword(cs, 0);
     }
 
@@ -315,21 +309,26 @@ static int cs_emit(struct radeon_cs *cs)
         cmd.boxes = (drm_clip_rect_t *) csm->ctx->pClipRects;
     }
 
-    //    dump_cmdbuf(cs);
+    //dump_cmdbuf(cs);
 
     r = drmCommandWrite(cs->csm->fd, DRM_RADEON_CMDBUF, &cmd, sizeof(cmd));
     if (r) {
         return r;
     }
-    if (!IS_R300_CLASS(csm->ctx->radeonScreen)) {
+    if ((!IS_R300_CLASS(csm->ctx->radeonScreen)) &&
+        (!IS_R600_CLASS(csm->ctx->radeonScreen))) { /* +r6/r7 : No irq for r6/r7 yet. */
        drm_radeon_irq_emit_t emit_cmd;
-       emit_cmd.irq_seq = &csm->pending_age;
+       emit_cmd.irq_seq = (int*)&csm->pending_age;
        r = drmCommandWrite(cs->csm->fd, DRM_RADEON_IRQ_EMIT, &emit_cmd, sizeof(emit_cmd));
        if (r) {
                return r;
        }
     }
     cs_set_age(cs);
+
+    cs->csm->read_used = 0;
+    cs->csm->vram_write_used = 0;
+    cs->csm->gart_write_used = 0;
     return 0;
 }
 
@@ -337,11 +336,10 @@ static void inline cs_free_reloc(void *relocs_p, int crelocs)
 {
     struct cs_reloc_legacy *relocs = relocs_p;
     int i;
-    if (relocs_p)
+    if (!relocs_p)
       return;
-    for (i = 0; i < crelocs; i++) {
+    for (i = 0; i < crelocs; i++)
       free(relocs[i].indices);
-    }
 }
 
 static int cs_destroy(struct radeon_cs *cs)
@@ -367,8 +365,9 @@ static int cs_erase(struct radeon_cs *cs)
 
 static int cs_need_flush(struct radeon_cs *cs)
 {
-    /* FIXME: we should get the texture heap size */
-    return (cs->relocs_total_size > (7*1024*1024));
+    /* this function used to flush when the BO usage got to
+     * a certain size, now the higher levels handle this better */
+    return 0;
 }
 
 static void cs_print(struct radeon_cs *cs, FILE *file)
@@ -377,7 +376,6 @@ static void cs_print(struct radeon_cs *cs, FILE *file)
 
 static struct radeon_cs_funcs  radeon_cs_legacy_funcs = {
     cs_create,
-    cs_write_dword,
     cs_write_reloc,
     cs_begin,
     cs_end,
@@ -385,7 +383,7 @@ static struct radeon_cs_funcs  radeon_cs_legacy_funcs = {
     cs_destroy,
     cs_erase,
     cs_need_flush,
-    cs_print
+    cs_print,
 };
 
 struct radeon_cs_manager *radeon_cs_manager_legacy_ctor(struct radeon_context *ctx)
@@ -408,3 +406,4 @@ void radeon_cs_manager_legacy_dtor(struct radeon_cs_manager *csm)
 {
     free(csm);
 }
+