Nico Huber has uploaded this change for review. ( https://review.coreboot.org/26849
Change subject: Use (Width|Height)_Type for modeline sizes ......................................................................
Use (Width|Height)_Type for modeline sizes
Saves us a lot of conversions and explicit contracts.
Change-Id: I32c06ca87b18c25e3c519fa608c4b9b36dbc0449 Signed-off-by: Nico Huber nico.h@gmx.de --- M common/hw-gfx-edid.adb M common/hw-gfx-gma-config.ads.template M common/hw-gfx-gma-pch-transcoder.adb M common/hw-gfx-gma-pipe_setup.adb M common/hw-gfx-gma-transcoder.adb M common/hw-gfx-gma.adb M common/hw-gfx-gma.ads M common/hw-gfx.ads M gfxtest/hw-gfx-gma-gfx_test.adb 9 files changed, 85 insertions(+), 96 deletions(-)
git pull ssh://review.coreboot.org:29418/libgfxinit refs/changes/49/26849/1
diff --git a/common/hw-gfx-edid.adb b/common/hw-gfx-edid.adb index 83e9cf6..f1fae58 100644 --- a/common/hw-gfx-edid.adb +++ b/common/hw-gfx-edid.adb @@ -18,7 +18,6 @@ with GNAT.Source_Info;
use type HW.Byte; -use type HW.Pos16; use type HW.Word16;
package body HW.GFX.EDID is @@ -138,14 +137,14 @@ begin Mode := Mode_Type' (Dotclock => Pos64 (Read_LE16 (Raw_EDID, Base)) * 10_000, - H_Visible => Pos16 (Read_12 (Base + 2, Base + 4, 4)), - H_Sync_Begin => Pos16 (Read_10 (Base + 8, Base + 11, 2)), - H_Sync_End => Pos16 (Read_10 (Base + 9, Base + 11, 4)), - H_Total => Pos16 (Read_12 (Base + 3, Base + 4, 8)), - V_Visible => Pos16 (Read_12 (Base + 5, Base + 7, 4)), - V_Sync_Begin => Pos16 (Read_6 (Base + 10, 4, Base + 11, 2)), - V_Sync_End => Pos16 (Read_6 (Base + 10, 0, Base + 11, 4)), - V_Total => Pos16 (Read_12 (Base + 6, Base + 7, 8)), + H_Visible => Width_Type (Read_12 (Base + 2, Base + 4, 4)), + H_Sync_Begin => Width_Type (Read_10 (Base + 8, Base + 11, 2)), + H_Sync_End => Width_Type (Read_10 (Base + 9, Base + 11, 4)), + H_Total => Width_Type (Read_12 (Base + 3, Base + 4, 8)), + V_Visible => Height_Type (Read_12 (Base + 5, Base + 7, 4)), + V_Sync_Begin => Height_Type (Read_6 (Base + 10, 4, Base + 11, 2)), + V_Sync_End => Height_Type (Read_6 (Base + 10, 0, Base + 11, 4)), + V_Total => Height_Type (Read_12 (Base + 6, Base + 7, 8)), H_Sync_Active_High => (Raw_EDID (Base + 17) and 16#02#) /= 0, V_Sync_Active_High => (Raw_EDID (Base + 17) and 16#04#) /= 0, BPC => diff --git a/common/hw-gfx-gma-config.ads.template b/common/hw-gfx-gma-config.ads.template index dba10aa..8a61d81 100644 --- a/common/hw-gfx-gma-config.ads.template +++ b/common/hw-gfx-gma-config.ads.template @@ -270,14 +270,14 @@ -- Maximum source width with enabled scaler. This only accounts -- for simple 1:1 pipe:scaler mappings.
- type Width_Per_Pipe is array (Pipe_Index) of Pos16; + type Width_Per_Pipe is array (Pipe_Index) of Width_Type;
Maximum_Scalable_Width : constant Width_Per_Pipe := (case CPU is when G45 => -- TODO: Is this true? (Primary => 4096, Secondary => 2048, - Tertiary => Pos16'First), + Tertiary => Pos32'First), when Ironlake..Haswell => (Primary => 4096, Secondary => 2048, diff --git a/common/hw-gfx-gma-pch-transcoder.adb b/common/hw-gfx-gma-pch-transcoder.adb index 29fbaf6..eb1715f 100644 --- a/common/hw-gfx-gma-pch-transcoder.adb +++ b/common/hw-gfx-gma-pch-transcoder.adb @@ -153,7 +153,7 @@ is Mode : constant Mode_Type := Port_Cfg.Mode;
- function Encode (LSW, MSW : Pos16) return Word32 is + function Encode (LSW, MSW : Pos32) return Word32 is begin return (Word32 (LSW) - 1) or ((Word32 (MSW) - 1) * 2 ** 16); end Encode; diff --git a/common/hw-gfx-gma-pipe_setup.adb b/common/hw-gfx-gma-pipe_setup.adb index e0be5fb..1be2a1a 100644 --- a/common/hw-gfx-gma-pipe_setup.adb +++ b/common/hw-gfx-gma-pipe_setup.adb @@ -146,7 +146,7 @@
---------------------------------------------------------------------------
- function Encode (LSW, MSW : Pos16) return Word32 is + function Encode (LSW, MSW : Pos32) return Word32 is begin return Shift_Left (Word32 (MSW) - 1, 16) or (Word32 (LSW) - 1); end Encode; @@ -220,8 +220,8 @@ if Config.Has_Plane_Control then declare Stride, Offset : Word32; - Width : constant Pos16 := Rotated_Width (FB); - Height : constant Pos16 := Rotated_Height (FB); + Width : constant Width_Type := Rotated_Width (FB); + Height : constant Width_Type := Rotated_Height (FB); begin if Rotation_90 (FB) then Stride := Word32 (FB_Pitch (FB.V_Stride, FB)); @@ -376,7 +376,7 @@ begin -- off-screen cursor needs special care if X <= -Width or Y <= -Width or - X >= Int32 (Rotated_Width (FB)) or Y >= Int32 (Rotated_Height (FB)) or + X >= Rotated_Width (FB) or Y >= Rotated_Height (FB) or X > Config.Maximum_Cursor_X or Y > Config.Maximum_Cursor_Y then X := -Width; @@ -394,29 +394,27 @@ ----------------------------------------------------------------------------
procedure Scale_Keep_Aspect - (Width : out Pos32; - Height : out Pos32; - Max_Width : in Pos32; - Max_Height : in Pos32; + (Width : out Width_Type; + Height : out Height_Type; + Max_Width : in Width_Type; + Max_Height : in Height_Type; Framebuffer : in Framebuffer_Type) with Pre => - Max_Width <= Pos32 (Pos16'Last) and - Max_Height <= Pos32 (Pos16'Last) and - Pos32 (Rotated_Width (Framebuffer)) <= Max_Width and - Pos32 (Rotated_Height (Framebuffer)) <= Max_Height, + Rotated_Width (Framebuffer) <= Max_Width and + Rotated_Height (Framebuffer) <= Max_Height, Post => Width <= Max_Width and Height <= Max_Height is - Src_Width : constant Pos32 := Pos32 (Rotated_Width (Framebuffer)); - Src_Height : constant Pos32 := Pos32 (Rotated_Height (Framebuffer)); + Src_Width : constant Width_Type := Rotated_Width (Framebuffer); + Src_Height : constant Height_Type := Rotated_Height (Framebuffer); begin case Scaling_Type (Src_Width, Src_Height, Max_Width, Max_Height) is when Letterbox => Width := Max_Width; Height := (Max_Width * Src_Height) / Src_Width; when Pillarbox => - pragma Assert ((Max_Height * Src_Width) / Src_Height <= Max_Width); + --pragma Assert ((Max_Height * Src_Width) / Src_Height <= Max_Width); Width := (Max_Height * Src_Width) / Src_Height; Height := Max_Height; when Uniform => @@ -441,8 +439,8 @@ (if Controller.PS_CTRL_2 /= Registers.Invalid_Register then PS_CTRL_SCALER_MODE_7X5_EXTENDED else 0);
- Width_In : constant Pos32 := Pos32 (Rotated_Width (Framebuffer)); - Height_In : constant Pos32 := Pos32 (Rotated_Height (Framebuffer)); + Width_In : constant Width_Type := Rotated_Width (Framebuffer); + Height_In : constant Height_Type := Rotated_Height (Framebuffer);
-- We can scale up to 2.99x horizontally: Horizontal_Limit : constant Pos32 := (Width_In * 299) / 100; @@ -457,15 +455,16 @@ else 299)) / 100;
- Width, Height : Pos32; + Width : Width_Type; + Height : Height_Type; begin -- Writes to WIN_SZ arm the PS registers.
Scale_Keep_Aspect (Width => Width, Height => Height, - Max_Width => Pos32'Min (Horizontal_Limit, Pos32 (Mode.H_Visible)), - Max_Height => Pos32'Min (Vertical_Limit, Pos32 (Mode.V_Visible)), + Max_Width => Pos32'Min (Horizontal_Limit, Mode.H_Visible), + Max_Height => Pos32'Min (Vertical_Limit, Mode.V_Visible), Framebuffer => Framebuffer);
Registers.Write @@ -474,8 +473,8 @@ Registers.Write (Register => Controller.PS_WIN_POS_1, Value => - Shift_Left (Word32 (Pos32 (Mode.H_Visible) - Width) / 2, 16) or - Word32 (Pos32 (Mode.V_Visible) - Height) / 2); + Shift_Left (Word32 (Mode.H_Visible - Width) / 2, 16) or + Word32 (Mode.V_Visible - Height) / 2); Registers.Write (Register => Controller.PS_WIN_SZ_1, Value => Shift_Left (Word32 (Width), 16) or Word32 (Height)); @@ -499,7 +498,8 @@ when Registers.PFC_CTL_1 => 2 * 2 ** 29, when others => 0) else 0);
- Width, Height : Pos32; + Width : Width_Type; + Height : Height_Type; X, Y : Int32; begin -- Writes to WIN_SZ arm the PF registers. @@ -507,21 +507,21 @@ Scale_Keep_Aspect (Width => Width, Height => Height, - Max_Width => Pos32 (Mode.H_Visible), - Max_Height => Pos32 (Mode.V_Visible), + Max_Width => Mode.H_Visible, + Max_Height => Mode.V_Visible, Framebuffer => Framebuffer);
-- Do not scale to odd width (at least Haswell has trouble with this). - if Width < Pos32 (Mode.H_Visible) and Width mod 2 = 1 then + if Width < Mode.H_Visible and Width mod 2 = 1 then Width := Width + 1; end if;
- X := (Int32 (Mode.H_Visible) - Width) / 2; - Y := (Int32 (Mode.V_Visible) - Height) / 2; + X := (Mode.H_Visible - Width) / 2; + Y := (Mode.V_Visible - Height) / 2;
-- Hardware is picky about minimal horizontal gaps. - if Pos32 (Mode.H_Visible) - Width <= 3 then - Width := Pos32(Mode.H_Visible); + if Mode.H_Visible - Width <= 3 then + Width := Mode.H_Visible; X := 0; end if;
diff --git a/common/hw-gfx-gma-transcoder.adb b/common/hw-gfx-gma-transcoder.adb index daa5deb..1e4952d 100644 --- a/common/hw-gfx-gma-transcoder.adb +++ b/common/hw-gfx-gma-transcoder.adb @@ -138,12 +138,7 @@
----------------------------------------------------------------------------
- function Encode (LSW, MSW : Pos16) return Word32 - is - pragma Warnings (GNAT, Off, """Integer_16"" is already use-visible *", - Reason => "Needed for older compiler versions"); - use type HW.Pos16; - pragma Warnings (GNAT, On, """Integer_16"" is already use-visible *"); + function Encode (LSW, MSW : Pos32) return Word32 is begin return Shift_Left (Word32 (MSW - 1), 16) or Word32 (LSW - 1); end Encode; diff --git a/common/hw-gfx-gma.adb b/common/hw-gfx-gma.adb index ab4e1e2..f135a5e 100644 --- a/common/hw-gfx-gma.adb +++ b/common/hw-gfx-gma.adb @@ -858,28 +858,28 @@ Debug.Put_Int64 (Configs (Pipe).Mode.Dotclock); Debug.Put_Line (","); Debug.Put (" H_Visible => "); - Debug.Put_Int16 (Configs (Pipe).Mode.H_Visible); + Debug.Put_Int32 (Configs (Pipe).Mode.H_Visible); Debug.Put_Line (","); Debug.Put (" H_Sync_Begin => "); - Debug.Put_Int16 (Configs (Pipe).Mode.H_Sync_Begin); + Debug.Put_Int32 (Configs (Pipe).Mode.H_Sync_Begin); Debug.Put_Line (","); Debug.Put (" H_Sync_End => "); - Debug.Put_Int16 (Configs (Pipe).Mode.H_Sync_End); + Debug.Put_Int32 (Configs (Pipe).Mode.H_Sync_End); Debug.Put_Line (","); Debug.Put (" H_Total => "); - Debug.Put_Int16 (Configs (Pipe).Mode.H_Total); + Debug.Put_Int32 (Configs (Pipe).Mode.H_Total); Debug.Put_Line (","); Debug.Put (" V_Visible => "); - Debug.Put_Int16 (Configs (Pipe).Mode.V_Visible); + Debug.Put_Int32 (Configs (Pipe).Mode.V_Visible); Debug.Put_Line (","); Debug.Put (" V_Sync_Begin => "); - Debug.Put_Int16 (Configs (Pipe).Mode.V_Sync_Begin); + Debug.Put_Int32 (Configs (Pipe).Mode.V_Sync_Begin); Debug.Put_Line (","); Debug.Put (" V_Sync_End => "); - Debug.Put_Int16 (Configs (Pipe).Mode.V_Sync_End); + Debug.Put_Int32 (Configs (Pipe).Mode.V_Sync_End); Debug.Put_Line (","); Debug.Put (" V_Total => "); - Debug.Put_Int16 (Configs (Pipe).Mode.V_Total); + Debug.Put_Int32 (Configs (Pipe).Mode.V_Total); Debug.Put_Line (","); Debug.Put_Line (" H_Sync_Active_High => " & (if Configs (Pipe).Mode.H_Sync_Active_High diff --git a/common/hw-gfx-gma.ads b/common/hw-gfx-gma.ads index 410f411..1f81ece 100644 --- a/common/hw-gfx-gma.ads +++ b/common/hw-gfx-gma.ads @@ -210,9 +210,9 @@
----------------------------------------------------------------------------
- Tile_Width : constant array (Tiling_Type) of Pos32 := + Tile_Width : constant array (Tiling_Type) of Width_Type := (Linear => 16, X_Tiled => 128, Y_Tiled => 32); - Tile_Rows : constant array (Tiling_Type) of Pos32 := + Tile_Rows : constant array (Tiling_Type) of Height_Type := (Linear => 1, X_Tiled => 8, Y_Tiled => 32);
function FB_Pitch (Px : Pos_Pixel_Type; FB : Framebuffer_Type) return Natural diff --git a/common/hw-gfx.ads b/common/hw-gfx.ads index beb111f..cff3e18 100644 --- a/common/hw-gfx.ads +++ b/common/hw-gfx.ads @@ -121,14 +121,14 @@ type Mode_Type is record Dotclock : Frequency_Type; - H_Visible : Pos16; - H_Sync_Begin : Pos16; - H_Sync_End : Pos16; - H_Total : Pos16; - V_Visible : Pos16; - V_Sync_Begin : Pos16; - V_Sync_End : Pos16; - V_Total : Pos16; + H_Visible : Width_Type; + H_Sync_Begin : Width_Type; + H_Sync_End : Width_Type; + H_Total : Width_Type; + V_Visible : Height_Type; + V_Sync_Begin : Height_Type; + V_Sync_End : Height_Type; + V_Total : Height_Type; H_Sync_Active_High : Boolean; V_Sync_Active_High : Boolean; BPC : BPC_Type; @@ -182,15 +182,15 @@ function Rotation_90 (FB : Framebuffer_Type) return Boolean is (FB.Rotation = Rotated_90 or FB.Rotation = Rotated_270);
- function Rotated_Width (FB : Framebuffer_Type) return Pos16 is - (if Rotation_90 (FB) then Pos16 (FB.Height) else Pos16 (FB.Width)); - function Rotated_Height (FB : Framebuffer_Type) return Pos16 is - (if Rotation_90 (FB) then Pos16 (FB.Width) else Pos16 (FB.Height)); + function Rotated_Width (FB : Framebuffer_Type) return Width_Type is + (if Rotation_90 (FB) then FB.Height else FB.Width); + function Rotated_Height (FB : Framebuffer_Type) return Height_Type is + (if Rotation_90 (FB) then FB.Width else FB.Height);
function Pixel_To_Bytes (Pixel : Pixel_Type; FB : Framebuffer_Type) return Int32 is (Pixel * Pos32 (FB.BPC) / (8 / 4)); - function FB_Size (FB : Framebuffer_Type) return Pos32 is - (Pixel_To_Bytes (FB.Stride * FB.V_Stride, FB)); + function FB_Size (FB : Framebuffer_Type) + return Pos32 is (Pixel_To_Bytes (FB.Stride * FB.V_Stride, FB));
function Requires_Scaling (FB : Framebuffer_Type; Mode : Mode_Type) return Boolean is @@ -198,22 +198,17 @@ Rotated_Height (FB) /= Mode.V_Visible);
type Scaling_Aspect is (Uniform, Letterbox, Pillarbox); - function Scaling_Type (Width, Height, Scaled_Width, Scaled_Height : Pos32) + function Scaling_Type + (Width : Width_Type; + Height : Height_Type; + Scaled_Width : Width_Type; + Scaled_Height : Height_Type) return Scaling_Aspect is (if Scaled_Width * Height < Scaled_Height * Width then Letterbox elsif Scaled_Width * Height > Scaled_Height * Width then Pillarbox - else Uniform) - with - Pre => - Width <= Pos32 (Pos16'Last) and - Height <= Pos32 (Pos16'Last) and - Scaled_Width <= Pos32 (Pos16'Last) and - Scaled_Height <= Pos32 (Pos16'Last); + else Uniform); function Scaling_Type (FB : Framebuffer_Type; Mode : Mode_Type) return Scaling_Aspect is (Scaling_Type - (Width => Pos32 (Rotated_Width (FB)), - Height => Pos32 (Rotated_Height (FB)), - Scaled_Width => Pos32 (Mode.H_Visible), - Scaled_Height => Pos32 (Mode.V_Visible))); + (Rotated_Width (FB), Rotated_Height (FB), Mode.H_Visible, Mode.V_Visible));
end HW.GFX; diff --git a/gfxtest/hw-gfx-gma-gfx_test.adb b/gfxtest/hw-gfx-gma-gfx_test.adb index d5071c6..6839dc3 100644 --- a/gfxtest/hw-gfx-gma-gfx_test.adb +++ b/gfxtest/hw-gfx-gma-gfx_test.adb @@ -267,19 +267,19 @@ Rotation : in Rotation_Type; Offset : in out Word32) is - Width : constant Width_Type := Width_Type (Mode.H_Visible); - Height : constant Height_Type := Height_Type (Mode.V_Visible); + Width : constant Width_Type := Mode.H_Visible; + Height : constant Height_Type := Mode.V_Visible; begin Offset := (Offset + FB_Align - 1) and not (FB_Align - 1); if Rotation = Rotated_90 or Rotation = Rotated_270 then FB := - (Width => Width_Type (Height), - Height => Height_Type (Width), + (Width => Height, + Height => Width, Start_X => Start_X, Start_Y => Start_Y, BPC => 8, - Stride => Div_Round_Up (Pos32 (Height + 2 * Start_X), 32) * 32, - V_Stride => Div_Round_Up (Pos32 (Width + 2 * Start_Y), 32) * 32, + Stride => Div_Round_Up (Height + 2 * Start_X, 32) * 32, + V_Stride => Div_Round_Up (Width + 2 * Start_Y, 32) * 32, Tiling => Y_Tiled, Rotation => Rotation, Offset => Offset + Word32 (GTT_Rotation_Offset) * GTT_Page_Size); @@ -401,8 +401,8 @@ declare C : Cursor_Type renames Pipes (Pipe).Cursor; FB : Framebuffer_Type renames Pipes (Pipe).Framebuffer; - Width : constant Int32 := Int32 (Rotated_Width (FB)); - Height : constant Int32 := Int32 (Rotated_Height (FB)); + Width : constant Width_Type := Rotated_Width (FB); + Height : constant Height_Type := Rotated_Height (FB); CS : Cursor_Script_Entry renames Cursor_Script (Natural (Cnt) mod (Cursor_Script'Last + 1)); begin @@ -480,8 +480,8 @@ C : Cursor_Type renames Pipes (Pipe).Cursor; CI : Cursor_Info renames Cursor_Infos (Pipe); FB : Framebuffer_Type renames Pipes (Pipe).Framebuffer; - Width : constant Int32 := Int32 (Rotated_Width (FB)); - Height : constant Int32 := Int32 (Rotated_Height (FB)); + Width : constant Width_Type := Rotated_Width (FB); + Height : constant Height_Type := Rotated_Height (FB);
Update : Boolean := False; begin @@ -649,8 +649,8 @@ New_FB.Height := Height_Type'Max (320, Height - New_FB.Start_Y - Rand_Div (Height));
- Cursor.Center_X := Int32 (Rotated_Width (New_FB)) / 2; - Cursor.Center_Y := Int32 (Rotated_Height (New_FB)) / 2; + Cursor.Center_X := Rotated_Width (New_FB) / 2; + Cursor.Center_Y := Rotated_Height (New_FB) / 2; GMA.Update_Cursor (Pipe, Cursor); end; end loop;