gma: Add cursor infrastructure

Allow ARGB cursors of 64x64, 128x128 or 256x256 pixels. Valid positions
depend a lot on the hardware generation, so we'll accept arbitrary
integer values in the interface and filter them internally. An out of
bounds cursor will simply be invisible.

It's unclear if the parameters also apply to other GFX hardware. Thus,
we keep the types in the GMA sub-package for now.

Change-Id: I1a380037ac91ba2beeb33c27a6882eb5caa126f9
Signed-off-by: Nico Huber <nico.huber@secunet.com>
Reviewed-on: https://review.coreboot.org/23185
Tested-by: Nico Huber <nico.h@gmx.de>
Reviewed-by: Arthur Heymans <arthur@aheymans.xyz>
diff --git a/common/hw-gfx-gma-config.ads.template b/common/hw-gfx-gma-config.ads.template
index 46e2782..dcfcb4e 100644
--- a/common/hw-gfx-gma-config.ads.template
+++ b/common/hw-gfx-gma-config.ads.template
@@ -286,6 +286,13 @@
             Secondary   => 4096,
             Tertiary    => 4096));
 
+   -- Maximum X position of hardware cursors
+   Maximum_Cursor_X : constant := (case CPU is
+                                    when G45 .. Ivybridge      => 4095,
+                                    when Haswell .. Skylake    => 8191);
+
+   Maximum_Cursor_Y : constant := 4095;
+
    ----------------------------------------------------------------------------
 
    -- FIXME: Unknown for Broxton, Linux' i915 contains a fixme too :-D
diff --git a/common/hw-gfx-gma-display_probing.adb b/common/hw-gfx-gma-display_probing.adb
index 96cf536..ab6c05f 100644
--- a/common/hw-gfx-gma-display_probing.adb
+++ b/common/hw-gfx-gma-display_probing.adb
@@ -189,6 +189,7 @@
       Configs := (Pipe_Index =>
                     (Port        => Disabled,
                      Mode        => Invalid_Mode,
+                     Cursor      => Default_Cursor,
                      Framebuffer => Default_FB));
 
       -- Turn panel on early to probe other ports during the power on delay.
diff --git a/common/hw-gfx-gma.adb b/common/hw-gfx-gma.adb
index 8ece078..f4bd214 100644
--- a/common/hw-gfx-gma.adb
+++ b/common/hw-gfx-gma.adb
@@ -386,6 +386,7 @@
         (others => Pipe_Config'
            (Port        => Disabled,
             Framebuffer => HW.GFX.Default_FB,
+            Cursor      => Default_Cursor,
             Mode        => HW.GFX.Invalid_Mode));
       PLLs.Initialize;
 
@@ -476,10 +477,12 @@
         (Primary =>
            (Port        => Analog,
             Framebuffer => HW.GFX.Default_FB,
+            Cursor      => Default_Cursor,
             Mode        => HW.GFX.Invalid_Mode),
          others =>
            (Port        => Disabled,
             Framebuffer => HW.GFX.Default_FB,
+            Cursor      => Default_Cursor,
             Mode        => HW.GFX.Invalid_Mode));
    begin
       Power_And_Clocks.Power_Up (Cur_Configs, Fake_Config);
diff --git a/common/hw-gfx-gma.ads b/common/hw-gfx-gma.ads
index 824a59e..d6c5572 100644
--- a/common/hw-gfx-gma.ads
+++ b/common/hw-gfx-gma.ads
@@ -29,6 +29,11 @@
       Config_State)
 is
 
+   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;
+
    type CPU_Type is
      (G45,
       Ironlake,
@@ -52,9 +57,30 @@
       HDMI3, -- or DVI
       Analog);
 
+   type Cursor_Mode is (No_Cursor, ARGB_Cursor);
+   type Cursor_Size is (Cursor_64x64, Cursor_128x128, Cursor_256x256);
+   Cursor_Width : constant array (Cursor_Size) of Width_Type := (64, 128, 256);
+
+   subtype Cursor_Pos is Int32 range Int32'First / 2 .. Int32'Last / 2;
+
+   type Cursor_Type is record
+      Mode        : Cursor_Mode;
+      Size        : Cursor_Size;
+      Center_X    : Cursor_Pos;
+      Center_Y    : Cursor_Pos;
+      GTT_Offset  : GTT_Range;
+   end record;
+   Default_Cursor : constant Cursor_Type :=
+     (Mode        => No_Cursor,
+      Size        => Cursor_Size'First,
+      Center_X    => 0,
+      Center_Y    => 0,
+      GTT_Offset  => 0);
+
    type Pipe_Config is record
       Port        : Port_Type;
       Framebuffer : Framebuffer_Type;
+      Cursor      : Cursor_Type;
       Mode        : Mode_Type;
    end record;
    type Pipe_Index is (Primary, Secondary, Tertiary);
@@ -93,11 +119,6 @@
                     Reason => "It's only used for debugging");
    procedure Dump_Configs (Configs : Pipe_Configs);
 
-   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;