gma: Set tiled framebuffers up through Plane_Control

On platforms with Plane_Control registers (Broxton/Skylake+) we can
use X and Y tiled framebuffers for scanout (older platforms support
X tiling only). As our main use case is 90° rotation with Y tiled
framebuffers, we implement it for the newer platforms only for now.

We also set up a fence register for linear access to the tiled frame-
buffer through the aperture.

Change-Id: I913c82f62fd28b681a06ce13f41160a07e559799
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.coreboot.org/22709
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
Tested-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
diff --git a/common/hw-gfx-gma.adb b/common/hw-gfx-gma.adb
index 3d174c7..e4ad3b3 100644
--- a/common/hw-gfx-gma.adb
+++ b/common/hw-gfx-gma.adb
@@ -479,7 +479,7 @@
 
    -- Check basics and that it fits in GTT
    function Valid_FB (FB : Framebuffer_Type) return Boolean is
-     (FB.Width <= FB.Stride and FB_Last_Page (FB) <= GTT_Range'Last);
+     (Valid_Stride (FB) and FB_Last_Page (FB) <= GTT_Range'Last);
 
    -- Also check that we don't overflow the GTT's 39-bit space
    -- (always true with a 32-bit base)
@@ -626,6 +626,20 @@
          Success := Phys_Base /= GMA_Phys_Base_Mask and Phys_Base /= 0;
          pragma Debug (not Success, Debug.Put_Line
            ("Failed to read stolen memory base."));
+
+         if Success then
+            if FB.Tiling in XY_Tiling then
+               Registers.Add_Fence
+                 (First_Page  => FB_First_Page (FB),
+                  Last_Page   => FB_Last_Page (FB),
+                  Tiling      => FB.Tiling,
+                  Pitch       => FB_Pitch (FB.Stride, FB),
+                  Success     => Success);
+            end if;
+            pragma Debug (not Success, Debug.Put_Line
+              ("Tiled framebuffer but no fence regs available."));
+         end if;
+
          if Success then
             Setup_Default_GTT (FB, Phys_Base);
          end if;