gma: Validate pipe configurations

Validate some properties of the pipe configuration before commit.
Currently checked:

  o No downscaling
  o Only 32bpp RGB
  o Stride must be a multiple of 64

Change-Id: Ibfc8617dbf433da33b1eb4012ecae08445600016
Signed-off-by: Nico Huber <nico.huber@secunet.com>
Reviewed-on: https://review.coreboot.org/17260
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
Tested-by: Nico Huber <nico.h@gmx.de>
Reviewed-by: Martin Roth <martinroth@google.com>
diff --git a/common/hw-gfx-gma.adb b/common/hw-gfx-gma.adb
index e6a5928..1c0919f 100644
--- a/common/hw-gfx-gma.adb
+++ b/common/hw-gfx-gma.adb
@@ -177,6 +177,23 @@
       DP_Info.Preferred_Link_Setting (Port_Cfg.FDI, Port_Cfg.Mode, Success);
    end Configure_FDI_Link;
 
+   function Validate_Config
+     (Framebuffer : Framebuffer_Type;
+      Port_Cfg    : Port_Config)
+      return Boolean
+   with Global => null
+   is
+   begin
+      -- No downscaling
+      -- Only 32bpp RGB
+      -- Stride must be a multiple of 64
+      return
+         Framebuffer.Width <= Pos32 (Port_Cfg.Mode.H_Visible) and
+         Framebuffer.Height <= Pos32 (Port_Cfg.Mode.V_Visible) and
+         Framebuffer.BPC = 8 and
+         Framebuffer.Stride mod 64 = 0;
+   end Validate_Config;
+
    procedure Fill_Port_Config
      (Port_Cfg :    out Port_Config;
       Configs  : in     Configs_Type;
@@ -524,6 +541,9 @@
             if New_Config.Port /= Disabled then
                Fill_Port_Config (Port_Cfg, Configs, I, Success);
 
+               Success := Success and then
+                           Validate_Config (New_Config.Framebuffer, Port_Cfg);
+
                if Success and then Wait_For_HPD (New_Config.Port) then
                   Check_HPD (Port_Cfg, New_Config.Port, Success);
                   Wait_For_HPD (New_Config.Port) := not Success;