hwc: rgz: Workaround for hdmi hotplug crash with 2D blitter enabled

When the hdmi cable is connected a hotplug event is triggered, this
forces the DSS to exhaust the pipes available in most situations
so the 2D blitter is used to handle some layers.

When the cable is connected/disconnected it's highly possible a
geometry change doesn't happen right away (or it may not happen)
leading the region data to be invalid and not recalculated for an
instant, this ends up in sending to the blitter incorrect src
rectangle origins and sizes, most of the time this leads to L3
errors making the system unstable and unable to recover.

Rebased from p-ics-mr1:
104249c hwc: rgz: Workaround for hdmi hotplug crash with 2D blitter enabled

Change-Id: Ie1675d0a0dd03e69fac80dd51cee006fcd6f8791
Signed-off-by: Gustavo Diaz Prado <a0273371@ti.com>
(cherry picked from commit d5907246f792b70e82db195b1c5fb5c1c5be9d5d)
diff --git a/hwc/rgz_2d.c b/hwc/rgz_2d.c
index 444db7f..9e2dcea 100644
--- a/hwc/rgz_2d.c
+++ b/hwc/rgz_2d.c
@@ -689,10 +689,12 @@
         return -1;
     }
 
+#if 0
     /* If there is already region data avoid parsing it again */
     if (rgz->state & RGZ_REGION_DATA) {
         return 0;
     }
+#endif
 
     int layerno = rgz->rgz_layerno;
 
@@ -1622,11 +1624,23 @@
     return 0;
 }
 
+/* Reset the values needed for every frame, except the dirty region handles */
+static void rgz_reset(rgz_t *rgz){
+    if (!rgz)
+        return;
+    if (rgz->hregions)
+        free(rgz->hregions);
+    rgz->hregions = NULL;
+    rgz->nhregions = 0;
+    rgz->state = 0;
+}
+
 int rgz_in(rgz_in_params_t *p, rgz_t *rgz)
 {
     int rv = -1;
     switch (p->op) {
     case RGZ_IN_HWC:
+        rgz_reset(rgz);
         rv = rgz_in_hwccheck(p, rgz);
         if (rv == RGZ_ALL)
             rv = rgz_in_hwc(p, rgz) ? 0 : RGZ_ALL;