From 9d545d17e784f4d7d8911088eeccd53c7bcf6459 Mon Sep 17 00:00:00 2001
From: Matt Borgerson <contact@mborgerson.com>
Date: Thu, 4 Mar 2021 20:45:24 -0700
Subject: [PATCH] nv2a: Relax stall conditions on pusher

---
 hw/xbox/nv2a/pfifo.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/hw/xbox/nv2a/pfifo.c b/hw/xbox/nv2a/pfifo.c
index d686e8cb33..28af1d5cb5 100644
--- a/hw/xbox/nv2a/pfifo.c
+++ b/hw/xbox/nv2a/pfifo.c
@@ -137,7 +137,7 @@ static bool pfifo_stall_for_flip(NV2AState *d)
     return should_stall;
 }
 
-static bool pfifo_should_stall(NV2AState *d)
+static bool pfifo_puller_should_stall(NV2AState *d)
 {
     return pfifo_stall_for_flip(d) || atomic_read(&d->pgraph.waiting_for_nop) ||
            atomic_read(&d->pgraph.waiting_for_context_switch) ||
@@ -148,7 +148,7 @@ static ssize_t pfifo_run_puller(NV2AState *d, uint32_t method_entry,
                                 uint32_t parameter, uint32_t *parameters,
                                 size_t num_words_available)
 {
-    if (pfifo_should_stall(d)) {
+    if (pfifo_puller_should_stall(d)) {
         return -1;
     }
 
@@ -236,6 +236,12 @@ static ssize_t pfifo_run_puller(NV2AState *d, uint32_t method_entry,
     return num_proc;
 }
 
+static bool pfifo_pusher_should_stall(NV2AState *d)
+{
+    return !pgraph_can_fifo_access(d) ||
+           atomic_read(&d->pgraph.waiting_for_nop);
+}
+
 static void pfifo_run_pusher(NV2AState *d)
 {
     uint32_t *push0 = &d->pfifo.regs[NV_PFIFO_CACHE1_PUSH0];
@@ -279,7 +285,7 @@ static void pfifo_run_pusher(NV2AState *d)
     hwaddr dma_len;
     uint8_t *dma = nv_dma_map(d, dma_instance, &dma_len);
 
-    while (!pfifo_should_stall(d)) {
+    while (!pfifo_pusher_should_stall(d)) {
         uint32_t dma_get_v = *dma_get;
         uint32_t dma_put_v = *dma_put;
         if (dma_get_v == dma_put_v) break;