gma pipe_setup: Pass `Pipe_Config` down into scaler configuration

Instead of only passing the `Framebuffer` and `Cursor`, pass the whole
`Pipe_Config`, which includes scaling settings now.

Change-Id: I0081eed64b02b718bed71284023a55f7521eaf48
Signed-off-by: Nico Huber <nico.huber@secunet.com>
Reviewed-on: https://review.sourcearcade.org/c/libgfxinit/+/518
Reviewed-by: Thomas Heijligen <src@posteo.de>
Tested-by: Nico Huber <nico.h@gmx.de>
diff --git a/common/hw-gfx-gma-pipe_setup.adb b/common/hw-gfx-gma-pipe_setup.adb
index 8975778..11aac58 100644
--- a/common/hw-gfx-gma-pipe_setup.adb
+++ b/common/hw-gfx-gma-pipe_setup.adb
@@ -621,15 +621,15 @@
 
    procedure Setup_Skylake_Pipe_Scaler
      (Controller  : in     Controller_Type;
-      Mode        : in     HW.GFX.Mode_Type;
-      Framebuffer : in     HW.GFX.Framebuffer_Type)
+      Pipe_Cfg    : in     Pipe_Config;
+      Mode        : in     HW.GFX.Mode_Type)
    with
       Pre =>
-         Rotated_Width (Framebuffer) <= Mode.H_Visible and
-         Rotated_Height (Framebuffer) <= Mode.V_Visible
+         Rotated_Width (Pipe_Cfg.Framebuffer) <= Mode.H_Visible and
+         Rotated_Height (Pipe_Cfg.Framebuffer) <= Mode.V_Visible
    is
-      Width_In    : constant Width_Type   := Rotated_Width (Framebuffer);
-      Height_In   : constant Height_Type  := Rotated_Height (Framebuffer);
+      Width_In    : constant Width_Type   := Rotated_Width (Pipe_Cfg.Framebuffer);
+      Height_In   : constant Height_Type  := Rotated_Height (Pipe_Cfg.Framebuffer);
       Limits      : constant Pipe_Scaler_Limit_Config :=
         (if Config.Has_Skylake_Scaler_Limits then
             Skylake_Scaler_Limits (Controller, Width_In, Height_In)
@@ -646,7 +646,7 @@
          Height      => Height,
          Max_Width   => Pos32'Min (Limits.Horizontal, Mode.H_Visible),
          Max_Height  => Pos32'Min (Limits.Vertical, Mode.V_Visible),
-         Framebuffer => Framebuffer);
+         Framebuffer => Pipe_Cfg.Framebuffer);
 
       Registers.Write
         (Register => Controller.PS_CTRL_1,
@@ -663,12 +663,12 @@
 
    procedure Setup_Ironlake_Panel_Fitter
      (Controller  : in     Controller_Type;
-      Mode        : in     HW.GFX.Mode_Type;
-      Framebuffer : in     HW.GFX.Framebuffer_Type)
+      Pipe_Cfg    : in     Pipe_Config;
+      Mode        : in     HW.GFX.Mode_Type)
    with
       Pre =>
-         Rotated_Width (Framebuffer) <= Mode.H_Visible and
-         Rotated_Height (Framebuffer) <= Mode.V_Visible
+         Rotated_Width (Pipe_Cfg.Framebuffer) <= Mode.H_Visible and
+         Rotated_Height (Pipe_Cfg.Framebuffer) <= Mode.V_Visible
    is
       -- Force 1:1 mapping of panel fitter:pipe
       PF_Ctrl_Pipe_Sel : constant Word32 :=
@@ -690,7 +690,7 @@
          Height      => Height,
          Max_Width   => Mode.H_Visible,
          Max_Height  => Mode.V_Visible,
-         Framebuffer => Framebuffer);
+         Framebuffer => Pipe_Cfg.Framebuffer);
 
       -- Do not scale to odd width (at least Haswell has trouble with this).
       if Width < Mode.H_Visible and Width mod 2 = 1 then
@@ -807,21 +807,21 @@
 
    procedure Setup_Scaling
      (Controller  : in     Controller_Type;
-      Mode        : in     HW.GFX.Mode_Type;
-      Framebuffer : in     HW.GFX.Framebuffer_Type)
+      Pipe_Cfg    : in     Pipe_Config;
+      Mode        : in     HW.GFX.Mode_Type)
    with
       Pre =>
-         Rotated_Width (Framebuffer) <= Mode.H_Visible and
-         Rotated_Height (Framebuffer) <= Mode.V_Visible
+         Rotated_Width (Pipe_Cfg.Framebuffer) <= Mode.H_Visible and
+         Rotated_Height (Pipe_Cfg.Framebuffer) <= Mode.V_Visible
    is
    begin
-      if Requires_Scaling (Framebuffer, Mode) then
+      if Requires_Scaling (Pipe_Cfg.Framebuffer, Mode) then
          if Config.Has_Plane_Control then
-            Setup_Skylake_Pipe_Scaler (Controller, Mode, Framebuffer);
+            Setup_Skylake_Pipe_Scaler (Controller, Pipe_Cfg, Mode);
          elsif Config.Has_GMCH_PFIT_CONTROL then
-            Setup_Gmch_Panel_Fitter (Controller, Mode, Framebuffer);
+            Setup_Gmch_Panel_Fitter (Controller, Mode, Pipe_Cfg.Framebuffer);
          else
-            Setup_Ironlake_Panel_Fitter (Controller, Mode, Framebuffer);
+            Setup_Ironlake_Panel_Fitter (Controller, Pipe_Cfg, Mode);
          end if;
       else
          Panel_Fitter_Off (Controller);
@@ -864,41 +864,40 @@
 
    procedure Setup_FB
      (Pipe        : Pipe_Index;
-      Mode        : Mode_Type;
-      Framebuffer : Framebuffer_Type)
+      Pipe_Cfg    : Pipe_Config;
+      Mode        : Mode_Type)
    is
       -- Enable dithering if framebuffer BPC differs from port BPC,
       -- as smooth gradients look really bad without.
-      Dither : constant Boolean := Framebuffer.BPC /= Mode.BPC;
+      Dither : constant Boolean := Pipe_Cfg.Framebuffer.BPC /= Mode.BPC;
    begin
       pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
 
       -- Disable the cursor first.
-      Update_Cursor (Pipe, Framebuffer, Default_Cursor);
+      Update_Cursor (Pipe, Pipe_Cfg.Framebuffer, Default_Cursor);
 
-      Setup_Display (Controllers (Pipe), Framebuffer, Mode.BPC, Dither);
-      Setup_Scaling (Controllers (Pipe), Mode, Framebuffer);
+      Setup_Display (Controllers (Pipe), Pipe_Cfg.Framebuffer, Mode.BPC, Dither);
+      Setup_Scaling (Controllers (Pipe), Pipe_Cfg, Mode);
    end Setup_FB;
 
    procedure On
      (Pipe        : Pipe_Index;
-      Port_Cfg    : Port_Config;
-      Framebuffer : Framebuffer_Type;
-      Cursor      : Cursor_Type)
+      Pipe_Cfg    : Pipe_Config;
+      Port_Cfg    : Port_Config)
    is
    begin
       pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
 
       Transcoder.Setup (Pipe, Port_Cfg);
 
-      Setup_FB (Pipe, Port_Cfg.Mode, Framebuffer);
-      Update_Cursor (Pipe, Framebuffer, Cursor);
+      Setup_FB (Pipe, Pipe_Cfg, Port_Cfg.Mode);
+      Update_Cursor (Pipe, Pipe_Cfg.Framebuffer, Pipe_Cfg.Cursor);
 
       Transcoder.On
         (Pipe     => Pipe,
          Port_Cfg => Port_Cfg,
-         Dither   => Framebuffer.BPC /= Port_Cfg.Mode.BPC,
-         Scale    => Requires_Scaling (Framebuffer, Port_Cfg.Mode));
+         Dither   => Pipe_Cfg.Framebuffer.BPC /= Port_Cfg.Mode.BPC,
+         Scale    => Requires_Scaling (Pipe_Cfg.Framebuffer, Port_Cfg.Mode));
    end On;
 
    ----------------------------------------------------------------------------
diff --git a/common/hw-gfx-gma-pipe_setup.ads b/common/hw-gfx-gma-pipe_setup.ads
index bdb1700..bbfef91 100644
--- a/common/hw-gfx-gma-pipe_setup.ads
+++ b/common/hw-gfx-gma-pipe_setup.ads
@@ -22,11 +22,10 @@
 
    procedure On
      (Pipe        : Pipe_Index;
-      Port_Cfg    : Port_Config;
-      Framebuffer : Framebuffer_Type;
-      Cursor      : Cursor_Type)
+      Pipe_Cfg    : Pipe_Config;
+      Port_Cfg    : Port_Config)
    with
-      Pre => Config_Helpers.Valid_FB (Framebuffer, Port_Cfg.Mode);
+      Pre => Config_Helpers.Valid_FB (Pipe_Cfg.Framebuffer, Port_Cfg.Mode);
 
    procedure Off (Pipe : Pipe_Index);
 
@@ -34,12 +33,16 @@
 
    procedure All_Off;
 
+   -- TODO: Passing `Pipe_Cfg` and `Mode` seems redundant. However,
+   --       the `Pipe_Cfg.Mode` is what the user requested and we
+   --       may have altered that in `Mode`. This should be refac-
+   --       tored to always have a single, synchronized `Mode`.
    procedure Setup_FB
      (Pipe        : Pipe_Index;
-      Mode        : Mode_Type;
-      Framebuffer : Framebuffer_Type)
+      Pipe_Cfg    : Pipe_Config;
+      Mode        : Mode_Type)
    with
-      Pre => Config_Helpers.Valid_FB (Framebuffer, Mode);
+      Pre => Config_Helpers.Valid_FB (Pipe_Cfg.Framebuffer, Mode);
 
    procedure Update_Cursor
      (Pipe     : Pipe_Index;
diff --git a/common/hw-gfx-gma.adb b/common/hw-gfx-gma.adb
index 2bc6554..33f8ef6 100644
--- a/common/hw-gfx-gma.adb
+++ b/common/hw-gfx-gma.adb
@@ -196,9 +196,8 @@
                if Success then
                   Display_Controller.On
                     (Pipe        => Pipe,
-                     Port_Cfg    => Port_Cfg,
-                     Framebuffer => Pipe_Cfg.Framebuffer,
-                     Cursor      => Pipe_Cfg.Cursor);
+                     Pipe_Cfg    => Pipe_Cfg,
+                     Port_Cfg    => Port_Cfg);
 
                   Connectors.Post_On
                     (Pipe     => Pipe,
@@ -391,7 +390,7 @@
                   Cur_Config.Framebuffer /= New_Config.Framebuffer
             then
                Display_Controller.Setup_FB
-                 (Pipe, New_Config.Mode, New_Config.Framebuffer);
+                 (Pipe, New_Config, New_Config.Mode);
                Display_Controller.Update_Cursor
                  (Pipe, New_Config.Framebuffer, New_Config.Cursor);
                Cur_Config := New_Config;