Skip to content

Commit c5c767a

Browse files
committed
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> Reviewed-on: https://review.coreboot.org/26849 Reviewed-by: Arthur Heymans <arthur@aheymans.xyz>
1 parent da1185e commit c5c767a

9 files changed

Lines changed: 87 additions & 100 deletions

common/hw-gfx-edid.adb

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ with HW.Debug;
1818
with GNAT.Source_Info;
1919

2020
use type HW.Byte;
21-
use type HW.Pos16;
2221
use type HW.Word16;
2322

2423
package body HW.GFX.EDID is
@@ -138,14 +137,14 @@ package body HW.GFX.EDID is
138137
begin
139138
Mode := Mode_Type'
140139
(Dotclock => Pos64 (Read_LE16 (Raw_EDID, Base)) * 10_000,
141-
H_Visible => Pos16 (Read_12 (Base + 2, Base + 4, 4)),
142-
H_Sync_Begin => Pos16 (Read_10 (Base + 8, Base + 11, 2)),
143-
H_Sync_End => Pos16 (Read_10 (Base + 9, Base + 11, 4)),
144-
H_Total => Pos16 (Read_12 (Base + 3, Base + 4, 8)),
145-
V_Visible => Pos16 (Read_12 (Base + 5, Base + 7, 4)),
146-
V_Sync_Begin => Pos16 (Read_6 (Base + 10, 4, Base + 11, 2)),
147-
V_Sync_End => Pos16 (Read_6 (Base + 10, 0, Base + 11, 4)),
148-
V_Total => Pos16 (Read_12 (Base + 6, Base + 7, 8)),
140+
H_Visible => Width_Type (Read_12 (Base + 2, Base + 4, 4)),
141+
H_Sync_Begin => Width_Type (Read_10 (Base + 8, Base + 11, 2)),
142+
H_Sync_End => Width_Type (Read_10 (Base + 9, Base + 11, 4)),
143+
H_Total => Width_Type (Read_12 (Base + 3, Base + 4, 8)),
144+
V_Visible => Height_Type (Read_12 (Base + 5, Base + 7, 4)),
145+
V_Sync_Begin => Height_Type (Read_6 (Base + 10, 4, Base + 11, 2)),
146+
V_Sync_End => Height_Type (Read_6 (Base + 10, 0, Base + 11, 4)),
147+
V_Total => Height_Type (Read_12 (Base + 6, Base + 7, 8)),
149148
H_Sync_Active_High => (Raw_EDID (Base + 17) and 16#02#) /= 0,
150149
V_Sync_Active_High => (Raw_EDID (Base + 17) and 16#04#) /= 0,
151150
BPC =>

common/hw-gfx-gma-config.ads.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,14 +270,14 @@ is
270270
-- Maximum source width with enabled scaler. This only accounts
271271
-- for simple 1:1 pipe:scaler mappings.
272272

273-
type Width_Per_Pipe is array (Pipe_Index) of Pos16;
273+
type Width_Per_Pipe is array (Pipe_Index) of Width_Type;
274274

275275
Maximum_Scalable_Width : constant Width_Per_Pipe :=
276276
(case CPU is
277277
when G45 => -- TODO: Is this true?
278278
(Primary => 4096,
279279
Secondary => 2048,
280-
Tertiary => Pos16'First),
280+
Tertiary => Pos32'First),
281281
when Ironlake..Haswell =>
282282
(Primary => 4096,
283283
Secondary => 2048,

common/hw-gfx-gma-pch-transcoder.adb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ package body HW.GFX.GMA.PCH.Transcoder is
153153
is
154154
Mode : constant Mode_Type := Port_Cfg.Mode;
155155

156-
function Encode (LSW, MSW : Pos16) return Word32 is
156+
function Encode (LSW, MSW : Pos32) return Word32 is
157157
begin
158158
return (Word32 (LSW) - 1) or ((Word32 (MSW) - 1) * 2 ** 16);
159159
end Encode;

common/hw-gfx-gma-pipe_setup.adb

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ package body HW.GFX.GMA.Pipe_Setup is
146146

147147
---------------------------------------------------------------------------
148148

149-
function Encode (LSW, MSW : Pos16) return Word32 is
149+
function Encode (LSW, MSW : Pos32) return Word32 is
150150
begin
151151
return Shift_Left (Word32 (MSW) - 1, 16) or (Word32 (LSW) - 1);
152152
end Encode;
@@ -220,8 +220,8 @@ package body HW.GFX.GMA.Pipe_Setup is
220220
if Config.Has_Plane_Control then
221221
declare
222222
Stride, Offset : Word32;
223-
Width : constant Pos16 := Rotated_Width (FB);
224-
Height : constant Pos16 := Rotated_Height (FB);
223+
Width : constant Width_Type := Rotated_Width (FB);
224+
Height : constant Width_Type := Rotated_Height (FB);
225225
begin
226226
if Rotation_90 (FB) then
227227
Stride := Word32 (FB_Pitch (FB.V_Stride, FB));
@@ -376,7 +376,7 @@ package body HW.GFX.GMA.Pipe_Setup is
376376
begin
377377
-- off-screen cursor needs special care
378378
if X <= -Width or Y <= -Width or
379-
X >= Int32 (Rotated_Width (FB)) or Y >= Int32 (Rotated_Height (FB)) or
379+
X >= Rotated_Width (FB) or Y >= Rotated_Height (FB) or
380380
X > Config.Maximum_Cursor_X or Y > Config.Maximum_Cursor_Y
381381
then
382382
X := -Width;
@@ -393,31 +393,27 @@ package body HW.GFX.GMA.Pipe_Setup is
393393

394394
----------------------------------------------------------------------------
395395

396-
function Scale (Val, Max, Num, Denom : Pos32)
397-
return Pos32 is ((Val * Num) / Denom)
396+
function Scale (Val, Max, Num, Denom : Width_Type)
397+
return Width_Type is ((Val * Num) / Denom)
398398
with
399-
Pre =>
400-
Val * Num <= Int32'Last and Denom <= Num and
401-
Val * Num < Max * Denom,
399+
Pre => Denom <= Num and Val * Num < Max * Denom,
402400
Post => Scale'Result < Max;
403401

404402
procedure Scale_Keep_Aspect
405-
(Width : out Pos32;
406-
Height : out Pos32;
407-
Max_Width : in Pos32;
408-
Max_Height : in Pos32;
403+
(Width : out Width_Type;
404+
Height : out Height_Type;
405+
Max_Width : in Width_Type;
406+
Max_Height : in Height_Type;
409407
Framebuffer : in Framebuffer_Type)
410408
with
411409
Pre =>
412-
Max_Width <= Pos32 (Pos16'Last) and
413-
Max_Height <= Pos32 (Pos16'Last) and
414-
Pos32 (Rotated_Width (Framebuffer)) <= Max_Width and
415-
Pos32 (Rotated_Height (Framebuffer)) <= Max_Height,
410+
Rotated_Width (Framebuffer) <= Max_Width and
411+
Rotated_Height (Framebuffer) <= Max_Height,
416412
Post =>
417413
Width <= Max_Width and Height <= Max_Height
418414
is
419-
Src_Width : constant Pos32 := Pos32 (Rotated_Width (Framebuffer));
420-
Src_Height : constant Pos32 := Pos32 (Rotated_Height (Framebuffer));
415+
Src_Width : constant Width_Type := Rotated_Width (Framebuffer);
416+
Src_Height : constant Height_Type := Rotated_Height (Framebuffer);
421417
begin
422418
case Scaling_Type (Src_Width, Src_Height, Max_Width, Max_Height) is
423419
when Letterbox =>
@@ -448,8 +444,8 @@ package body HW.GFX.GMA.Pipe_Setup is
448444
(if Controller.PS_CTRL_2 /= Registers.Invalid_Register then
449445
PS_CTRL_SCALER_MODE_7X5_EXTENDED else 0);
450446

451-
Width_In : constant Pos32 := Pos32 (Rotated_Width (Framebuffer));
452-
Height_In : constant Pos32 := Pos32 (Rotated_Height (Framebuffer));
447+
Width_In : constant Width_Type := Rotated_Width (Framebuffer);
448+
Height_In : constant Height_Type := Rotated_Height (Framebuffer);
453449

454450
-- We can scale up to 2.99x horizontally:
455451
Horizontal_Limit : constant Pos32 := (Width_In * 299) / 100;
@@ -464,15 +460,16 @@ package body HW.GFX.GMA.Pipe_Setup is
464460
else
465461
299)) / 100;
466462

467-
Width, Height : Pos32;
463+
Width : Width_Type;
464+
Height : Height_Type;
468465
begin
469466
-- Writes to WIN_SZ arm the PS registers.
470467

471468
Scale_Keep_Aspect
472469
(Width => Width,
473470
Height => Height,
474-
Max_Width => Pos32'Min (Horizontal_Limit, Pos32 (Mode.H_Visible)),
475-
Max_Height => Pos32'Min (Vertical_Limit, Pos32 (Mode.V_Visible)),
471+
Max_Width => Pos32'Min (Horizontal_Limit, Mode.H_Visible),
472+
Max_Height => Pos32'Min (Vertical_Limit, Mode.V_Visible),
476473
Framebuffer => Framebuffer);
477474

478475
Registers.Write
@@ -481,8 +478,8 @@ package body HW.GFX.GMA.Pipe_Setup is
481478
Registers.Write
482479
(Register => Controller.PS_WIN_POS_1,
483480
Value =>
484-
Shift_Left (Word32 (Pos32 (Mode.H_Visible) - Width) / 2, 16) or
485-
Word32 (Pos32 (Mode.V_Visible) - Height) / 2);
481+
Shift_Left (Word32 (Mode.H_Visible - Width) / 2, 16) or
482+
Word32 (Mode.V_Visible - Height) / 2);
486483
Registers.Write
487484
(Register => Controller.PS_WIN_SZ_1,
488485
Value => Shift_Left (Word32 (Width), 16) or Word32 (Height));
@@ -506,29 +503,30 @@ package body HW.GFX.GMA.Pipe_Setup is
506503
when Registers.PFC_CTL_1 => 2 * 2 ** 29,
507504
when others => 0) else 0);
508505

509-
Width, Height : Pos32;
506+
Width : Width_Type;
507+
Height : Height_Type;
510508
X, Y : Int32;
511509
begin
512510
-- Writes to WIN_SZ arm the PF registers.
513511

514512
Scale_Keep_Aspect
515513
(Width => Width,
516514
Height => Height,
517-
Max_Width => Pos32 (Mode.H_Visible),
518-
Max_Height => Pos32 (Mode.V_Visible),
515+
Max_Width => Mode.H_Visible,
516+
Max_Height => Mode.V_Visible,
519517
Framebuffer => Framebuffer);
520518

521519
-- Do not scale to odd width (at least Haswell has trouble with this).
522-
if Width < Pos32 (Mode.H_Visible) and Width mod 2 = 1 then
520+
if Width < Mode.H_Visible and Width mod 2 = 1 then
523521
Width := Width + 1;
524522
end if;
525523

526-
X := (Int32 (Mode.H_Visible) - Width) / 2;
527-
Y := (Int32 (Mode.V_Visible) - Height) / 2;
524+
X := (Mode.H_Visible - Width) / 2;
525+
Y := (Mode.V_Visible - Height) / 2;
528526

529527
-- Hardware is picky about minimal horizontal gaps.
530-
if Pos32 (Mode.H_Visible) - Width <= 3 then
531-
Width := Pos32(Mode.H_Visible);
528+
if Mode.H_Visible - Width <= 3 then
529+
Width := Mode.H_Visible;
532530
X := 0;
533531
end if;
534532

common/hw-gfx-gma-transcoder.adb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,7 @@ package body HW.GFX.GMA.Transcoder is
138138

139139
----------------------------------------------------------------------------
140140

141-
function Encode (LSW, MSW : Pos16) return Word32
142-
is
143-
pragma Warnings (GNAT, Off, """Integer_16"" is already use-visible *",
144-
Reason => "Needed for older compiler versions");
145-
use type HW.Pos16;
146-
pragma Warnings (GNAT, On, """Integer_16"" is already use-visible *");
141+
function Encode (LSW, MSW : Pos32) return Word32 is
147142
begin
148143
return Shift_Left (Word32 (MSW - 1), 16) or Word32 (LSW - 1);
149144
end Encode;

common/hw-gfx-gma.adb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -858,28 +858,28 @@ is
858858
Debug.Put_Int64 (Configs (Pipe).Mode.Dotclock);
859859
Debug.Put_Line (",");
860860
Debug.Put (" H_Visible => ");
861-
Debug.Put_Int16 (Configs (Pipe).Mode.H_Visible);
861+
Debug.Put_Int32 (Configs (Pipe).Mode.H_Visible);
862862
Debug.Put_Line (",");
863863
Debug.Put (" H_Sync_Begin => ");
864-
Debug.Put_Int16 (Configs (Pipe).Mode.H_Sync_Begin);
864+
Debug.Put_Int32 (Configs (Pipe).Mode.H_Sync_Begin);
865865
Debug.Put_Line (",");
866866
Debug.Put (" H_Sync_End => ");
867-
Debug.Put_Int16 (Configs (Pipe).Mode.H_Sync_End);
867+
Debug.Put_Int32 (Configs (Pipe).Mode.H_Sync_End);
868868
Debug.Put_Line (",");
869869
Debug.Put (" H_Total => ");
870-
Debug.Put_Int16 (Configs (Pipe).Mode.H_Total);
870+
Debug.Put_Int32 (Configs (Pipe).Mode.H_Total);
871871
Debug.Put_Line (",");
872872
Debug.Put (" V_Visible => ");
873-
Debug.Put_Int16 (Configs (Pipe).Mode.V_Visible);
873+
Debug.Put_Int32 (Configs (Pipe).Mode.V_Visible);
874874
Debug.Put_Line (",");
875875
Debug.Put (" V_Sync_Begin => ");
876-
Debug.Put_Int16 (Configs (Pipe).Mode.V_Sync_Begin);
876+
Debug.Put_Int32 (Configs (Pipe).Mode.V_Sync_Begin);
877877
Debug.Put_Line (",");
878878
Debug.Put (" V_Sync_End => ");
879-
Debug.Put_Int16 (Configs (Pipe).Mode.V_Sync_End);
879+
Debug.Put_Int32 (Configs (Pipe).Mode.V_Sync_End);
880880
Debug.Put_Line (",");
881881
Debug.Put (" V_Total => ");
882-
Debug.Put_Int16 (Configs (Pipe).Mode.V_Total);
882+
Debug.Put_Int32 (Configs (Pipe).Mode.V_Total);
883883
Debug.Put_Line (",");
884884
Debug.Put_Line (" H_Sync_Active_High => " &
885885
(if Configs (Pipe).Mode.H_Sync_Active_High

common/hw-gfx-gma.ads

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ private
210210

211211
----------------------------------------------------------------------------
212212

213-
Tile_Width : constant array (Tiling_Type) of Pos32 :=
213+
Tile_Width : constant array (Tiling_Type) of Width_Type :=
214214
(Linear => 16, X_Tiled => 128, Y_Tiled => 32);
215-
Tile_Rows : constant array (Tiling_Type) of Pos32 :=
215+
Tile_Rows : constant array (Tiling_Type) of Height_Type :=
216216
(Linear => 1, X_Tiled => 8, Y_Tiled => 32);
217217

218218
function FB_Pitch (Px : Pos_Pixel_Type; FB : Framebuffer_Type) return Natural

common/hw-gfx.ads

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,14 @@ package HW.GFX is
121121
type Mode_Type is
122122
record
123123
Dotclock : Frequency_Type;
124-
H_Visible : Pos16;
125-
H_Sync_Begin : Pos16;
126-
H_Sync_End : Pos16;
127-
H_Total : Pos16;
128-
V_Visible : Pos16;
129-
V_Sync_Begin : Pos16;
130-
V_Sync_End : Pos16;
131-
V_Total : Pos16;
124+
H_Visible : Width_Type;
125+
H_Sync_Begin : Width_Type;
126+
H_Sync_End : Width_Type;
127+
H_Total : Width_Type;
128+
V_Visible : Height_Type;
129+
V_Sync_Begin : Height_Type;
130+
V_Sync_End : Height_Type;
131+
V_Total : Height_Type;
132132
H_Sync_Active_High : Boolean;
133133
V_Sync_Active_High : Boolean;
134134
BPC : BPC_Type;
@@ -182,38 +182,33 @@ private
182182
function Rotation_90 (FB : Framebuffer_Type) return Boolean is
183183
(FB.Rotation = Rotated_90 or FB.Rotation = Rotated_270);
184184

185-
function Rotated_Width (FB : Framebuffer_Type) return Pos16 is
186-
(if Rotation_90 (FB) then Pos16 (FB.Height) else Pos16 (FB.Width));
187-
function Rotated_Height (FB : Framebuffer_Type) return Pos16 is
188-
(if Rotation_90 (FB) then Pos16 (FB.Width) else Pos16 (FB.Height));
185+
function Rotated_Width (FB : Framebuffer_Type) return Width_Type is
186+
(if Rotation_90 (FB) then FB.Height else FB.Width);
187+
function Rotated_Height (FB : Framebuffer_Type) return Height_Type is
188+
(if Rotation_90 (FB) then FB.Width else FB.Height);
189189

190190
function Pixel_To_Bytes (Pixel : Pixel_Type; FB : Framebuffer_Type)
191191
return Int32 is (Pixel * Pos32 (FB.BPC) / (8 / 4));
192-
function FB_Size (FB : Framebuffer_Type) return Pos32 is
193-
(Pixel_To_Bytes (FB.Stride * FB.V_Stride, FB));
192+
function FB_Size (FB : Framebuffer_Type)
193+
return Pos32 is (Pixel_To_Bytes (FB.Stride * FB.V_Stride, FB));
194194

195195
function Requires_Scaling (FB : Framebuffer_Type; Mode : Mode_Type)
196196
return Boolean is
197197
(Rotated_Width (FB) /= Mode.H_Visible or
198198
Rotated_Height (FB) /= Mode.V_Visible);
199199

200200
type Scaling_Aspect is (Uniform, Letterbox, Pillarbox);
201-
function Scaling_Type (Width, Height, Scaled_Width, Scaled_Height : Pos32)
201+
function Scaling_Type
202+
(Width : Width_Type;
203+
Height : Height_Type;
204+
Scaled_Width : Width_Type;
205+
Scaled_Height : Height_Type)
202206
return Scaling_Aspect is
203207
(if Scaled_Width * Height < Scaled_Height * Width then Letterbox
204208
elsif Scaled_Width * Height > Scaled_Height * Width then Pillarbox
205-
else Uniform)
206-
with
207-
Pre =>
208-
Width <= Pos32 (Pos16'Last) and
209-
Height <= Pos32 (Pos16'Last) and
210-
Scaled_Width <= Pos32 (Pos16'Last) and
211-
Scaled_Height <= Pos32 (Pos16'Last);
209+
else Uniform);
212210
function Scaling_Type (FB : Framebuffer_Type; Mode : Mode_Type)
213211
return Scaling_Aspect is (Scaling_Type
214-
(Width => Pos32 (Rotated_Width (FB)),
215-
Height => Pos32 (Rotated_Height (FB)),
216-
Scaled_Width => Pos32 (Mode.H_Visible),
217-
Scaled_Height => Pos32 (Mode.V_Visible)));
212+
(Rotated_Width (FB), Rotated_Height (FB), Mode.H_Visible, Mode.V_Visible));
218213

219214
end HW.GFX;

0 commit comments

Comments
 (0)