gma: Refactor Hotplug_Detect() interface and usage

Checking for hotplug events should be done before any other work to
reduce load and (spurious) debug output. Therefor, use the simpler
`Port_Type` in the interface of `Hotplug_Detect()` so we don't have to
fill the whole `Port_Cfg` before checking for events.

Also, now that it's possible, factor the disabling of a single output
out of `Update_Outputs()`.

Change-Id: I2a0ba5530c8d511fa95f9cac12297ad428a40d77
Signed-off-by: Nico Huber <nico.huber@secunet.com>
Reviewed-on: https://review.coreboot.org/18119
Tested-by: Nico Huber <nico.h@gmx.de>
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
diff --git a/common/haswell_shared/hw-gfx-gma-port_detect.adb b/common/haswell_shared/hw-gfx-gma-port_detect.adb
index 9987aca..2f5854d 100644
--- a/common/haswell_shared/hw-gfx-gma-port_detect.adb
+++ b/common/haswell_shared/hw-gfx-gma-port_detect.adb
@@ -1,5 +1,5 @@
 --
--- Copyright (C) 2016 secunet Security Networks AG
+-- Copyright (C) 2016-2017 secunet Security Networks AG
 --
 -- This program is free software; you can redistribute it and/or modify
 -- it under the terms of the GNU General Public License as published by
@@ -14,6 +14,7 @@
 
 with HW.GFX.GMA.Config;
 with HW.GFX.GMA.Registers;
+with HW.GFX.GMA.Config_Helpers;
 
 package body HW.GFX.GMA.Port_Detect
 is
@@ -149,11 +150,13 @@
       end loop;
    end Initialize;
 
-   procedure Hotplug_Detect (Port_Cfg : in Port_Config; Detected : out Boolean)
+   procedure Hotplug_Detect (Port : in Active_Port_Type; Detected : out Boolean)
    is
       Ctl32 : Word32;
+      GPU_Port : constant GMA.GPU_Port :=
+         Config_Helpers.To_GPU_Port (Primary, Port);
    begin
-      if Port_Cfg.Display = VGA then
+      if Port = Analog then
          Registers.Read (Registers.PCH_ADPA, Ctl32, Verbose => False);
          Ctl32 := Ctl32 and PCH_ADPA_CRT_HPD_CHANNEL_MASK;
          Detected := Ctl32 = PCH_ADPA_CRT_HPD_CHANNEL_MASK;
@@ -162,7 +165,7 @@
               (Register => Registers.PCH_ADPA,
                Mask     => PCH_ADPA_CRT_HPD_CHANNEL_MASK);
          end if;
-      elsif Config.Has_HOTPLUG_CTL and then Port_Cfg.Port = DIGI_A then
+      elsif Config.Has_HOTPLUG_CTL and then GPU_Port = DIGI_A then
          Registers.Read (Registers.HOTPLUG_CTL, Ctl32, Verbose => False);
          Detected := (Ctl32 and HOTPLUG_CTL_DDI_A_HPD_LONG_DETECT) /= 0;
 
@@ -171,16 +174,15 @@
               (Register => Registers.HOTPLUG_CTL,
                Mask     => HOTPLUG_CTL_DDI_A_HPD_STATUS);
          end if;
-      elsif Port_Cfg.Port in DIGI_A .. DIGI_D then
+      elsif GPU_Port in DIGI_A .. DIGI_D then
          Registers.Read (Registers.SHOTPLUG_CTL, Ctl32, Verbose => False);
-         Detected :=
-           (Ctl32 and SHOTPLUG_CTL_LONG_DETECT (Port_Cfg.Port)) /= 0;
+         Detected := (Ctl32 and SHOTPLUG_CTL_LONG_DETECT (GPU_Port)) /= 0;
 
-         if (Ctl32 and SHOTPLUG_CTL_HPD_STATUS (Port_Cfg.Port)) /= 0 then
+         if (Ctl32 and SHOTPLUG_CTL_HPD_STATUS (GPU_Port)) /= 0 then
             Registers.Unset_And_Set_Mask
               (Register    => Registers.SHOTPLUG_CTL,
                Mask_Unset  => SHOTPLUG_CTL_DETECT_MASK,
-               Mask_Set    => SHOTPLUG_CTL_HPD_STATUS (Port_Cfg.Port));
+               Mask_Set    => SHOTPLUG_CTL_HPD_STATUS (GPU_Port));
          end if;
       else
          Detected := False;