gma pcode: Move and revise mailbox handling
Unify the PCODE mailbox implementations (Linux' i915 uses the same
implementation since Sandy Bridge, too) and add `Wait` and `Success`
parameters so we can act correctly if something failed. This adds
a lot of boilerplate. But we keep it contained in the new package
`PCode` and the code outside it looks cleaner and handles errors
more gracefully.
In GNATprove, we track state of the mailbox' readiness in a ghost
variable `Mailbox_Ready`. This allows us to skip the initial wait
loop if we know that we already waited at the end of a previous
call. The first call to a mailbox procedure has to be made with
`Wait_Ready => True`.
Also, start to experiment with a `use` clause for the `Register`
package. It allows us to write a little more condensed code, with-
out sacrificing much (in this program we can expect that `Read`/
`Write` means register access?) So far it looks good?
Change-Id: I5daa3effb7ab774e4a35bd8794b0f67f57e4caa4
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.coreboot.org/c/libgfxinit/+/35710
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
diff --git a/common/haswell_shared/hw-gfx-gma-power_and_clocks_haswell.adb b/common/haswell_shared/hw-gfx-gma-power_and_clocks_haswell.adb
index 1c23254..332c3df 100644
--- a/common/haswell_shared/hw-gfx-gma-power_and_clocks_haswell.adb
+++ b/common/haswell_shared/hw-gfx-gma-power_and_clocks_haswell.adb
@@ -17,6 +17,7 @@
with HW.Time;
with HW.Debug;
with HW.GFX.GMA.Config;
+with HW.GFX.GMA.PCode;
with HW.GFX.GMA.Registers;
package body HW.GFX.GMA.Power_And_Clocks_Haswell is
@@ -55,8 +56,6 @@
IPS_CTL_ENABLE : constant := 1 * 2 ** 31;
DISPLAY_IPS_CONTROL : constant := 16#19#;
- GT_MAILBOX_READY : constant := 1 * 2 ** 31;
-
----------------------------------------------------------------------------
procedure PSR_Off
@@ -88,18 +87,6 @@
----------------------------------------------------------------------------
- procedure GT_Mailbox_Write (MBox : Word32; Value : Word32) is
- begin
- pragma Debug (Debug.Put_Line (GNAT.Source_Info.Enclosing_Entity));
-
- Registers.Wait_Unset_Mask (Registers.GT_MAILBOX, GT_MAILBOX_READY);
- Registers.Write (Registers.GT_MAILBOX_DATA, Value);
- Registers.Write (Registers.GT_MAILBOX, GT_MAILBOX_READY or MBox);
-
- Registers.Wait_Unset_Mask (Registers.GT_MAILBOX, GT_MAILBOX_READY);
- Registers.Write (Registers.GT_MAILBOX_DATA, 0);
- end GT_Mailbox_Write;
-
procedure IPS_Off
is
Enabled : Boolean;
@@ -110,7 +97,7 @@
Registers.Is_Set_Mask (Registers.IPS_CTL, IPS_CTL_ENABLE, Enabled);
if Enabled then
if Config.Has_IPS_CTL_Mailbox then
- GT_Mailbox_Write (DISPLAY_IPS_CONTROL, 0);
+ PCode.Mailbox_Write (DISPLAY_IPS_CONTROL, 0, Wait_Ready => True);
Registers.Wait_Unset_Mask
(Register => Registers.IPS_CTL,
Mask => IPS_CTL_ENABLE,