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/broxton/hw-gfx-gma-power_and_clocks.adb b/common/broxton/hw-gfx-gma-power_and_clocks.adb
index f6576d9..77f6b35 100644
--- a/common/broxton/hw-gfx-gma-power_and_clocks.adb
+++ b/common/broxton/hw-gfx-gma-power_and_clocks.adb
@@ -17,6 +17,7 @@
with HW.Debug;
with HW.GFX.GMA.Config;
with HW.GFX.GMA.Registers;
+with HW.GFX.GMA.PCode;
with HW.GFX.GMA.Power_And_Clocks_Haswell;
with HW.GFX.GMA.DDI_Phy;
@@ -242,10 +243,19 @@
when others => CDCLK_CD2X_DIV_SEL_1); -- for CDClk = CDClk_Ref
CDCLK_CD2X_SSA_Precharge : constant Word32 :=
(if Freq >= 500_000_000 then CDCLK_CD2X_SSA_PRECHARGE_ENABLE else 0);
+
+ Success : Boolean;
begin
- Power_And_Clocks_Haswell.GT_Mailbox_Write
+ PCode.Mailbox_Write
(MBox => BXT_PCODE_CDCLK_CONTROL,
- Value => BXT_CDCLK_PREPARE_FOR_CHANGE);
+ Command => BXT_CDCLK_PREPARE_FOR_CHANGE,
+ Wait_Ready => True,
+ Success => Success);
+ if not Success then
+ pragma Debug (Debug.Put_Line
+ ("ERROR: PCODE didn't acknowledge frequency change."));
+ return;
+ end if;
Write
(Register => BXT_DE_PLL_ENABLE,
@@ -274,9 +284,9 @@
CDCLK_CD2X_SSA_Precharge or
CDCLK_CTL_CD_FREQ_DECIMAL (Freq));
- Power_And_Clocks_Haswell.GT_Mailbox_Write
- (MBox => BXT_PCODE_CDCLK_CONTROL,
- Value => Word32 ((Freq + (25_000_000 - 1)) / 25_000_000));
+ PCode.Mailbox_Write
+ (MBox => BXT_PCODE_CDCLK_CONTROL,
+ Command => Word64 ((Freq + (25_000_000 - 1)) / 25_000_000));
end Set_CDClk;
----------------------------------------------------------------------------