gma: Add support for rotated framebuffers

As for the tiling, we enable support for rotated framebuffers on
platforms with Plane_Control. On every path where a rotated frame-
buffer may be expected, we have to exchange width and height in
case of 90 degree rotations. Beside the rotation setting itself,
the hardware needs to know the vertical stride instead of the hori-
zontal and a delicate page mapping in case of 90 degree rotations.
For that we divide the GTT space into two, the lower half contains
the linear mappings, the upper half mappings for a rotated scanout.

Change-Id: I1c901b7abc0fe7764bee87f6fda58ba9fa3f340d
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.coreboot.org/22711
Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
Tested-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
diff --git a/common/hw-gfx-gma.ads b/common/hw-gfx-gma.ads
index 9943e44..50a76a0 100644
--- a/common/hw-gfx-gma.ads
+++ b/common/hw-gfx-gma.ads
@@ -95,6 +95,8 @@
    GTT_Page_Size : constant := 4096;
    type GTT_Address_Type is mod 2 ** 39;
    subtype GTT_Range is Natural range 0 .. 16#8_0000# - 1;
+   GTT_Rotation_Offset : constant GTT_Range := GTT_Range'Last / 2 + 1;
+
    procedure Write_GTT
      (GTT_Page       : GTT_Range;
       Device_Address : GTT_Address_Type;
@@ -161,6 +163,8 @@
 
    Tile_Width : constant array (Tiling_Type) of Pos32 :=
      (Linear => 16, X_Tiled => 128, Y_Tiled => 32);
+   Tile_Rows : constant array (Tiling_Type) of Pos32 :=
+     (Linear => 1, X_Tiled => 8, Y_Tiled => 32);
 
    function FB_Pitch (Px : Pixel_Type; FB : Framebuffer_Type) return Natural is
      (Natural (Div_Round_Up
@@ -168,6 +172,8 @@
 
    function Valid_Stride (FB : Framebuffer_Type) return Boolean is
      (FB.Width <= FB.Stride and
-      Pixel_To_Bytes (FB.Stride, FB) mod (Tile_Width (FB.Tiling) * 4) = 0);
+      Pixel_To_Bytes (FB.Stride, FB) mod (Tile_Width (FB.Tiling) * 4) = 0 and
+      FB.Height <= FB.V_Stride and
+      FB.V_Stride mod Tile_Rows (FB.Tiling) = 0);
 
 end HW.GFX.GMA;