blob: 2cfc017b994427e74858f1f0351a60079d6d53d0 [file] [log] [blame]
Nico Huber83693c82016-10-08 22:17:55 +02001--
2-- Copyright (C) 2015-2016 secunet Security Networks AG
Nico Huber194e57e2017-07-15 21:15:46 +02003-- Copyright (C) 2017 Nico Huber <nico.h@gmx.de>
Nico Huber83693c82016-10-08 22:17:55 +02004--
5-- This program is free software; you can redistribute it and/or modify
6-- it under the terms of the GNU General Public License as published by
Nico Huber125a29e2016-10-18 00:23:54 +02007-- the Free Software Foundation; either version 2 of the License, or
8-- (at your option) any later version.
Nico Huber83693c82016-10-08 22:17:55 +02009--
10-- This program is distributed in the hope that it will be useful,
11-- but WITHOUT ANY WARRANTY; without even the implied warranty of
12-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13-- GNU General Public License for more details.
14--
15
16with HW;
17
18use type HW.Pos64;
19use type HW.Word32;
20
21package HW.GFX is
22
Nico Huber0164b022017-08-24 15:12:51 +020023 -- such that the count of pixels in any framebuffer may fit
Nico Huber5ef4d602017-12-13 13:56:47 +010024 subtype Pixel_Type is Int32 range 0 .. 8192 * 8192;
25 subtype Pos_Pixel_Type is Pixel_Type range 1 .. Pixel_Type'Last;
Nico Huber0164b022017-08-24 15:12:51 +020026
Nico Huber865f1fa2018-06-05 12:26:41 +020027 -- assume at most 8 bytes per pixel
28 subtype Size_Type is Int32 range 0 .. Pixel_Type'Last * 8;
29
Nico Huberb7470492017-11-30 14:48:35 +010030 -- Allow same range for width and height (for rotated framebuffers)
Nico Huber7a740432018-05-30 13:58:27 +020031 subtype Width_Type is Pos32 range 1 .. 8192;
32 subtype Height_Type is Pos32 range 1 .. 8192;
33 subtype Position_Type is Int32 range 0 .. 4095;
Nico Huber83693c82016-10-08 22:17:55 +020034
35 Auto_BPC : constant := 5;
36 subtype BPC_Type is Int64 range Auto_BPC .. 16;
37
Nico Huber51375ad2017-08-24 14:44:06 +020038 type Tiling_Type is (Linear, X_Tiled, Y_Tiled);
Nico Huberb03c8f12017-08-25 13:29:08 +020039 subtype XY_Tiling is Tiling_Type range X_Tiled .. Y_Tiled;
Nico Huber51375ad2017-08-24 14:44:06 +020040
Nico Huberb7470492017-11-30 14:48:35 +010041 type Rotation_Type is (No_Rotation, Rotated_90, Rotated_180, Rotated_270);
42
Nico Huber83693c82016-10-08 22:17:55 +020043 type Framebuffer_Type is
44 record
Nico Huber51375ad2017-08-24 14:44:06 +020045 Width : Width_Type;
46 Height : Height_Type;
Nico Huber7a740432018-05-30 13:58:27 +020047 Start_X : Position_Type;
48 Start_Y : Position_Type;
Nico Huber51375ad2017-08-24 14:44:06 +020049 BPC : BPC_Type;
50 Stride : Width_Type;
Nico Huberb7470492017-11-30 14:48:35 +010051 V_Stride : Height_Type;
Nico Huber51375ad2017-08-24 14:44:06 +020052 Tiling : Tiling_Type;
Nico Huberb7470492017-11-30 14:48:35 +010053 Rotation : Rotation_Type;
Nico Huber51375ad2017-08-24 14:44:06 +020054 Offset : Word32;
Nico Huber83693c82016-10-08 22:17:55 +020055 end record;
56
57 Default_FB : constant Framebuffer_Type := Framebuffer_Type'
Nico Huber51375ad2017-08-24 14:44:06 +020058 (Width => 1,
59 Height => 1,
Nico Huber5ef4d602017-12-13 13:56:47 +010060 Start_X => 0,
61 Start_Y => 0,
Nico Huber51375ad2017-08-24 14:44:06 +020062 BPC => 8,
63 Stride => 1,
Nico Huberb7470492017-11-30 14:48:35 +010064 V_Stride => 1,
Nico Huber51375ad2017-08-24 14:44:06 +020065 Tiling => Linear,
Nico Huberb7470492017-11-30 14:48:35 +010066 Rotation => No_Rotation,
Nico Huber51375ad2017-08-24 14:44:06 +020067 Offset => 0);
Nico Huber83693c82016-10-08 22:17:55 +020068
Nico Huber6c10d362019-10-02 00:28:19 +020069 subtype Frequency_Type is Pos64 range 1_000_000 .. 2_500_000_000;
Nico Huber83693c82016-10-08 22:17:55 +020070
71 type DP_Lane_Count is (DP_Lane_Count_1, DP_Lane_Count_2, DP_Lane_Count_4);
72 subtype DP_Lane_Count_Type is Pos64 range 1 .. 4;
73 type DP_Lane_Count_Integers is array (DP_Lane_Count) of DP_Lane_Count_Type;
74 Lane_Count_As_Integer : constant DP_Lane_Count_Integers :=
75 DP_Lane_Count_Integers'
76 (DP_Lane_Count_1 => 1, DP_Lane_Count_2 => 2, DP_Lane_Count_4 => 4);
77
78 type DP_Bandwidth is (DP_Bandwidth_1_62, DP_Bandwidth_2_7, DP_Bandwidth_5_4);
79 for DP_Bandwidth use
80 (DP_Bandwidth_1_62 => 6, DP_Bandwidth_2_7 => 10, DP_Bandwidth_5_4 => 20);
81 for DP_Bandwidth'Size use 8;
82 subtype DP_Symbol_Rate_Type is Pos64 range 1 .. 810_000_000;
83 type DP_Symbol_Rate_Array is array (DP_Bandwidth) of DP_Symbol_Rate_Type;
84 DP_Symbol_Rate : constant DP_Symbol_Rate_Array := DP_Symbol_Rate_Array'
85 (DP_Bandwidth_1_62 => 162_000_000,
86 DP_Bandwidth_2_7 => 270_000_000,
87 DP_Bandwidth_5_4 => 540_000_000);
88
89 type DP_Caps is record
90 Rev : Word8;
91 Max_Link_Rate : DP_Bandwidth;
92 Max_Lane_Count : DP_Lane_Count;
93 TPS3_Supported : Boolean;
94 Enhanced_Framing : Boolean;
95 No_Aux_Handshake : Boolean;
96 Aux_RD_Interval : Word8;
97 end record;
98
99 type DP_Link is
100 record
101 Receiver_Caps : DP_Caps;
102 Lane_Count : DP_Lane_Count;
103 Bandwidth : DP_Bandwidth;
104 Enhanced_Framing : Boolean;
105 Opportunistic_Training : Boolean;
106 end record;
107 Default_DP : constant DP_Link := DP_Link'
108 (Receiver_Caps => DP_Caps'
109 (Rev => 16#00#,
110 Max_Link_Rate => DP_Bandwidth'First,
111 Max_Lane_Count => DP_Lane_Count'First,
112 TPS3_Supported => False,
113 Enhanced_Framing => False,
114 No_Aux_Handshake => False,
115 Aux_RD_Interval => 16#00#),
116 Lane_Count => DP_Lane_Count'First,
117 Bandwidth => DP_Bandwidth'First,
118 Enhanced_Framing => False,
119 Opportunistic_Training => False);
120
Nico Huber393aa8a2016-10-21 14:18:53 +0200121 type Display_Type is (None, LVDS, DP, HDMI, VGA);
122 subtype Internal_Type is Display_Type range None .. DP;
123
Nico Huber83693c82016-10-08 22:17:55 +0200124 type Mode_Type is
125 record
126 Dotclock : Frequency_Type;
Nico Huberc5c767a2018-06-03 01:09:04 +0200127 H_Visible : Width_Type;
128 H_Sync_Begin : Width_Type;
129 H_Sync_End : Width_Type;
130 H_Total : Width_Type;
131 V_Visible : Height_Type;
132 V_Sync_Begin : Height_Type;
133 V_Sync_End : Height_Type;
134 V_Total : Height_Type;
Nico Huber83693c82016-10-08 22:17:55 +0200135 H_Sync_Active_High : Boolean;
136 V_Sync_Active_High : Boolean;
137 BPC : BPC_Type;
138 end record;
139
140 ----------------------------------------------------------------------------
141 -- Constants
142 ----------------------------------------------------------------------------
143
144 -- modeline constants
145 -- Dotclock is calculated using: Refresh_Rate * H_Total * V_Total
146
147 M2560x1600_60 : constant Mode_Type := Mode_Type'
148 (60*(2720*1646), 2560, 2608, 2640, 2720, 1600, 1603, 1609, 1646, True, True, Auto_BPC);
149
150 M2560x1440_60 : constant Mode_Type := Mode_Type'
151 (60*(2720*1481), 2560, 2608, 2640, 2720, 1440, 1443, 1448, 1481, True, False, Auto_BPC);
152
153 M1920x1200_60 : constant Mode_Type := Mode_Type'
154 (60*(2080*1235), 1920, 1968, 2000, 2080, 1200, 1203, 1209, 1235, False, False, Auto_BPC);
155
156 M1920x1080_60 : constant Mode_Type := Mode_Type'
157 (60*(2185*1135), 1920, 2008, 2052, 2185, 1080, 1084, 1089, 1135, False, False, Auto_BPC);
158
159 M1680x1050_60 : constant Mode_Type := Mode_Type'
160 (60*(2256*1087), 1680, 1784, 1968, 2256, 1050, 1051, 1054, 1087, False, True, Auto_BPC);
161
162 M1600x1200_60 : constant Mode_Type := Mode_Type'
163 (60*(2160*1250), 1600, 1664, 1856, 2160, 1200, 1201, 1204, 1250, True, True, Auto_BPC);
164
165 M1600x900_60 : constant Mode_Type := Mode_Type'
166 (60*(2010*912), 1600, 1664, 1706, 2010, 900, 903, 906, 912, False, False, Auto_BPC);
167
168 M1440x900_60 : constant Mode_Type := Mode_Type'
169 (60*(1834*920), 1440, 1488, 1520, 1834, 900, 903, 909, 920, False, False, Auto_BPC);
170
171 M1366x768_60 : constant Mode_Type := Mode_Type'
172 (60*(1446*788), 1366, 1414, 1446, 1466, 768, 769, 773, 788, False, False, Auto_BPC);
173
174 M1280x1024_60 : constant Mode_Type := Mode_Type'
175 (60*(1712*1063), 1280, 1368, 1496, 1712, 1024, 1027, 1034, 1063, False, True, Auto_BPC);
176
177 M1024x768_60 : constant Mode_Type := Mode_Type'
178 (60*(1344*806), 1024, 1048, 1184, 1344, 768, 771, 777, 806, False, False, Auto_BPC);
179
180 Invalid_Mode : constant Mode_Type := Mode_Type'
181 (Frequency_Type'First, 1, 1, 1, 1, 1, 1, 1, 1, False, False, Auto_BPC);
182
Nico Huber3299ad52018-06-02 16:53:39 +0200183private
184
185 function Rotation_90 (FB : Framebuffer_Type) return Boolean is
186 (FB.Rotation = Rotated_90 or FB.Rotation = Rotated_270);
187
Nico Huberc5c767a2018-06-03 01:09:04 +0200188 function Rotated_Width (FB : Framebuffer_Type) return Width_Type is
189 (if Rotation_90 (FB) then FB.Height else FB.Width);
190 function Rotated_Height (FB : Framebuffer_Type) return Height_Type is
191 (if Rotation_90 (FB) then FB.Width else FB.Height);
Nico Huber3299ad52018-06-02 16:53:39 +0200192
193 function Pixel_To_Bytes (Pixel : Pixel_Type; FB : Framebuffer_Type)
Nico Huber865f1fa2018-06-05 12:26:41 +0200194 return Size_Type is (Pixel * Pos32 (FB.BPC) / (8 / 4));
Nico Huberc5c767a2018-06-03 01:09:04 +0200195 function FB_Size (FB : Framebuffer_Type)
196 return Pos32 is (Pixel_To_Bytes (FB.Stride * FB.V_Stride, FB));
Nico Huber3299ad52018-06-02 16:53:39 +0200197
Nico Huber71677462018-06-02 16:54:46 +0200198 function Requires_Scaling (FB : Framebuffer_Type; Mode : Mode_Type)
199 return Boolean is
200 (Rotated_Width (FB) /= Mode.H_Visible or
201 Rotated_Height (FB) /= Mode.V_Visible);
202
Nico Huberb217ece2018-06-02 16:56:35 +0200203 type Scaling_Aspect is (Uniform, Letterbox, Pillarbox);
Nico Huberc5c767a2018-06-03 01:09:04 +0200204 function Scaling_Type
205 (Width : Width_Type;
206 Height : Height_Type;
207 Scaled_Width : Width_Type;
208 Scaled_Height : Height_Type)
Nico Huberb217ece2018-06-02 16:56:35 +0200209 return Scaling_Aspect is
Nico Huberda1185e2018-06-03 01:07:46 +0200210 (if Scaled_Width * Height < Scaled_Height * Width then Letterbox
211 elsif Scaled_Width * Height > Scaled_Height * Width then Pillarbox
Nico Huberc5c767a2018-06-03 01:09:04 +0200212 else Uniform);
Nico Huberda1185e2018-06-03 01:07:46 +0200213 function Scaling_Type (FB : Framebuffer_Type; Mode : Mode_Type)
214 return Scaling_Aspect is (Scaling_Type
Nico Huberc5c767a2018-06-03 01:09:04 +0200215 (Rotated_Width (FB), Rotated_Height (FB), Mode.H_Visible, Mode.V_Visible));
Nico Huberb217ece2018-06-02 16:56:35 +0200216
Nico Huber83693c82016-10-08 22:17:55 +0200217end HW.GFX;