gma: Refactor Update_Outputs()

In Update_Outputs(), we used to have two steps, iterating over
all available pipes: We disabled all pipes whose mode changed
or that would be disabled otherwise. Then, we enabled all pipes
with new modes.

As checks for validity of the configurations were only done on
demand in the second step, that left us with no knowledge about
what configs would actually be tried. To make this information
available for future work, we add a validation step before the
existing two. That gives us:

 1. Validate all new configs
 2. Disable pipes
    - whose mode changed
    - that were disconnected
    - whose config didn't validate
 3. Enable/update pipes with new configs

This way, we can make global decisions ahead of 2. and 3. based
on the remaining, _valid_ configurations.

We had to turn Pipe_Setup.Scaler_Available() into a Reserve_Scaler()
so we can keep track which new configuration gets to use a scaler.
G45 is still the only case where we have less scalers than pipes
available. To keep that transparent to Update_Outputs() we add the
opaque type `Scaler_Reservation`.

The `Loop_Invariant` of 1. allows us to keep the validation
in mind, to satisfy pre-conditions of the various steps ahead.
To not lose the validation, Fill_Port_Config() needs a post
condition and a little restructuring to prove it.

Change-Id: I079ae8f85c821a272b5d095c1ef437ee804aa9ac
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.coreboot.org/c/libgfxinit/+/35528
Reviewed-by: Arthur Heymans <arthur@aheymans.xyz>
diff --git a/common/hw-gfx-gma-pipe_setup.ads b/common/hw-gfx-gma-pipe_setup.ads
index 3ecb6dd..960e70f 100644
--- a/common/hw-gfx-gma-pipe_setup.ads
+++ b/common/hw-gfx-gma-pipe_setup.ads
@@ -51,10 +51,22 @@
       FB       : Framebuffer_Type;
       Cursor   : Cursor_Type);
 
-   procedure Scaler_Available (Available : out Boolean; Pipe : Pipe_Index);
+   type Scaler_Reservation is private;
+   Null_Scaler_Reservation : constant Scaler_Reservation;
+   procedure Reserve_Scaler
+     (Success     :    out Boolean;
+      Reservation : in out Scaler_Reservation;
+      Pipe        : in     Pipe_Index);
 
 private
 
+   type Scaler_Reservation is record
+      Reserved : Boolean;
+      Pipe     : Pipe_Index;
+   end record;
+   Null_Scaler_Reservation : constant Scaler_Reservation :=
+     (Reserved => False, Pipe => Pipe_Index'First);
+
    subtype WM_Levels is Natural range 0 .. 7;
    type PLANE_WM_Type is array (WM_Levels) of Registers.Registers_Index;