blob: f09f9dc99318129fc76baa5f6baea93bb36d2e4e [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
Nico Huber83693c82016-10-08 22:17:55 +020016package HW.GFX is
17
Nico Huber0164b022017-08-24 15:12:51 +020018 -- such that the count of pixels in any framebuffer may fit
Nico Huber5ef4d602017-12-13 13:56:47 +010019 subtype Pixel_Type is Int32 range 0 .. 8192 * 8192;
20 subtype Pos_Pixel_Type is Pixel_Type range 1 .. Pixel_Type'Last;
Nico Huber0164b022017-08-24 15:12:51 +020021
Nico Huber865f1fa2018-06-05 12:26:41 +020022 -- assume at most 8 bytes per pixel
23 subtype Size_Type is Int32 range 0 .. Pixel_Type'Last * 8;
24
Nico Huberb7470492017-11-30 14:48:35 +010025 -- Allow same range for width and height (for rotated framebuffers)
Nico Huber7a740432018-05-30 13:58:27 +020026 subtype Width_Type is Pos32 range 1 .. 8192;
27 subtype Height_Type is Pos32 range 1 .. 8192;
28 subtype Position_Type is Int32 range 0 .. 4095;
Nico Huber83693c82016-10-08 22:17:55 +020029
30 Auto_BPC : constant := 5;
31 subtype BPC_Type is Int64 range Auto_BPC .. 16;
32
Nico Huber51375ad2017-08-24 14:44:06 +020033 type Tiling_Type is (Linear, X_Tiled, Y_Tiled);
Nico Huberb03c8f12017-08-25 13:29:08 +020034 subtype XY_Tiling is Tiling_Type range X_Tiled .. Y_Tiled;
Nico Huber51375ad2017-08-24 14:44:06 +020035
Nico Huberb7470492017-11-30 14:48:35 +010036 type Rotation_Type is (No_Rotation, Rotated_90, Rotated_180, Rotated_270);
37
Nico Huber83693c82016-10-08 22:17:55 +020038 type Framebuffer_Type is
39 record
Nico Huber51375ad2017-08-24 14:44:06 +020040 Width : Width_Type;
41 Height : Height_Type;
Nico Huber7a740432018-05-30 13:58:27 +020042 Start_X : Position_Type;
43 Start_Y : Position_Type;
Nico Huber51375ad2017-08-24 14:44:06 +020044 BPC : BPC_Type;
45 Stride : Width_Type;
Nico Huberb7470492017-11-30 14:48:35 +010046 V_Stride : Height_Type;
Nico Huber51375ad2017-08-24 14:44:06 +020047 Tiling : Tiling_Type;
Nico Huberb7470492017-11-30 14:48:35 +010048 Rotation : Rotation_Type;
Nico Huber51375ad2017-08-24 14:44:06 +020049 Offset : Word32;
Nico Huber83693c82016-10-08 22:17:55 +020050 end record;
51
52 Default_FB : constant Framebuffer_Type := Framebuffer_Type'
Nico Huber51375ad2017-08-24 14:44:06 +020053 (Width => 1,
54 Height => 1,
Nico Huber5ef4d602017-12-13 13:56:47 +010055 Start_X => 0,
56 Start_Y => 0,
Nico Huber51375ad2017-08-24 14:44:06 +020057 BPC => 8,
58 Stride => 1,
Nico Huberb7470492017-11-30 14:48:35 +010059 V_Stride => 1,
Nico Huber51375ad2017-08-24 14:44:06 +020060 Tiling => Linear,
Nico Huberb7470492017-11-30 14:48:35 +010061 Rotation => No_Rotation,
Nico Huber51375ad2017-08-24 14:44:06 +020062 Offset => 0);
Nico Huber83693c82016-10-08 22:17:55 +020063
Nico Huber6c10d362019-10-02 00:28:19 +020064 subtype Frequency_Type is Pos64 range 1_000_000 .. 2_500_000_000;
Nico Huber83693c82016-10-08 22:17:55 +020065
66 type DP_Lane_Count is (DP_Lane_Count_1, DP_Lane_Count_2, DP_Lane_Count_4);
67 subtype DP_Lane_Count_Type is Pos64 range 1 .. 4;
68 type DP_Lane_Count_Integers is array (DP_Lane_Count) of DP_Lane_Count_Type;
69 Lane_Count_As_Integer : constant DP_Lane_Count_Integers :=
70 DP_Lane_Count_Integers'
71 (DP_Lane_Count_1 => 1, DP_Lane_Count_2 => 2, DP_Lane_Count_4 => 4);
72
73 type DP_Bandwidth is (DP_Bandwidth_1_62, DP_Bandwidth_2_7, DP_Bandwidth_5_4);
74 for DP_Bandwidth use
75 (DP_Bandwidth_1_62 => 6, DP_Bandwidth_2_7 => 10, DP_Bandwidth_5_4 => 20);
76 for DP_Bandwidth'Size use 8;
77 subtype DP_Symbol_Rate_Type is Pos64 range 1 .. 810_000_000;
78 type DP_Symbol_Rate_Array is array (DP_Bandwidth) of DP_Symbol_Rate_Type;
79 DP_Symbol_Rate : constant DP_Symbol_Rate_Array := DP_Symbol_Rate_Array'
80 (DP_Bandwidth_1_62 => 162_000_000,
81 DP_Bandwidth_2_7 => 270_000_000,
82 DP_Bandwidth_5_4 => 540_000_000);
83
84 type DP_Caps is record
85 Rev : Word8;
86 Max_Link_Rate : DP_Bandwidth;
87 Max_Lane_Count : DP_Lane_Count;
88 TPS3_Supported : Boolean;
89 Enhanced_Framing : Boolean;
90 No_Aux_Handshake : Boolean;
91 Aux_RD_Interval : Word8;
92 end record;
93
94 type DP_Link is
95 record
96 Receiver_Caps : DP_Caps;
97 Lane_Count : DP_Lane_Count;
98 Bandwidth : DP_Bandwidth;
99 Enhanced_Framing : Boolean;
100 Opportunistic_Training : Boolean;
101 end record;
102 Default_DP : constant DP_Link := DP_Link'
103 (Receiver_Caps => DP_Caps'
104 (Rev => 16#00#,
105 Max_Link_Rate => DP_Bandwidth'First,
106 Max_Lane_Count => DP_Lane_Count'First,
107 TPS3_Supported => False,
108 Enhanced_Framing => False,
109 No_Aux_Handshake => False,
110 Aux_RD_Interval => 16#00#),
111 Lane_Count => DP_Lane_Count'First,
112 Bandwidth => DP_Bandwidth'First,
113 Enhanced_Framing => False,
114 Opportunistic_Training => False);
115
Nico Huber393aa8a2016-10-21 14:18:53 +0200116 type Display_Type is (None, LVDS, DP, HDMI, VGA);
117 subtype Internal_Type is Display_Type range None .. DP;
118
Nico Huber83693c82016-10-08 22:17:55 +0200119 type Mode_Type is
120 record
121 Dotclock : Frequency_Type;
Nico Huberc5c767a2018-06-03 01:09:04 +0200122 H_Visible : Width_Type;
123 H_Sync_Begin : Width_Type;
124 H_Sync_End : Width_Type;
125 H_Total : Width_Type;
126 V_Visible : Height_Type;
127 V_Sync_Begin : Height_Type;
128 V_Sync_End : Height_Type;
129 V_Total : Height_Type;
Nico Huber83693c82016-10-08 22:17:55 +0200130 H_Sync_Active_High : Boolean;
131 V_Sync_Active_High : Boolean;
132 BPC : BPC_Type;
133 end record;
134
135 ----------------------------------------------------------------------------
136 -- Constants
137 ----------------------------------------------------------------------------
138
139 -- modeline constants
140 -- Dotclock is calculated using: Refresh_Rate * H_Total * V_Total
141
142 M2560x1600_60 : constant Mode_Type := Mode_Type'
143 (60*(2720*1646), 2560, 2608, 2640, 2720, 1600, 1603, 1609, 1646, True, True, Auto_BPC);
144
145 M2560x1440_60 : constant Mode_Type := Mode_Type'
146 (60*(2720*1481), 2560, 2608, 2640, 2720, 1440, 1443, 1448, 1481, True, False, Auto_BPC);
147
148 M1920x1200_60 : constant Mode_Type := Mode_Type'
149 (60*(2080*1235), 1920, 1968, 2000, 2080, 1200, 1203, 1209, 1235, False, False, Auto_BPC);
150
151 M1920x1080_60 : constant Mode_Type := Mode_Type'
152 (60*(2185*1135), 1920, 2008, 2052, 2185, 1080, 1084, 1089, 1135, False, False, Auto_BPC);
153
154 M1680x1050_60 : constant Mode_Type := Mode_Type'
155 (60*(2256*1087), 1680, 1784, 1968, 2256, 1050, 1051, 1054, 1087, False, True, Auto_BPC);
156
157 M1600x1200_60 : constant Mode_Type := Mode_Type'
158 (60*(2160*1250), 1600, 1664, 1856, 2160, 1200, 1201, 1204, 1250, True, True, Auto_BPC);
159
160 M1600x900_60 : constant Mode_Type := Mode_Type'
161 (60*(2010*912), 1600, 1664, 1706, 2010, 900, 903, 906, 912, False, False, Auto_BPC);
162
163 M1440x900_60 : constant Mode_Type := Mode_Type'
164 (60*(1834*920), 1440, 1488, 1520, 1834, 900, 903, 909, 920, False, False, Auto_BPC);
165
166 M1366x768_60 : constant Mode_Type := Mode_Type'
167 (60*(1446*788), 1366, 1414, 1446, 1466, 768, 769, 773, 788, False, False, Auto_BPC);
168
169 M1280x1024_60 : constant Mode_Type := Mode_Type'
170 (60*(1712*1063), 1280, 1368, 1496, 1712, 1024, 1027, 1034, 1063, False, True, Auto_BPC);
171
172 M1024x768_60 : constant Mode_Type := Mode_Type'
173 (60*(1344*806), 1024, 1048, 1184, 1344, 768, 771, 777, 806, False, False, Auto_BPC);
174
175 Invalid_Mode : constant Mode_Type := Mode_Type'
176 (Frequency_Type'First, 1, 1, 1, 1, 1, 1, 1, 1, False, False, Auto_BPC);
177
Nico Huber3299ad52018-06-02 16:53:39 +0200178private
179
180 function Rotation_90 (FB : Framebuffer_Type) return Boolean is
181 (FB.Rotation = Rotated_90 or FB.Rotation = Rotated_270);
182
Nico Huberc5c767a2018-06-03 01:09:04 +0200183 function Rotated_Width (FB : Framebuffer_Type) return Width_Type is
184 (if Rotation_90 (FB) then FB.Height else FB.Width);
185 function Rotated_Height (FB : Framebuffer_Type) return Height_Type is
186 (if Rotation_90 (FB) then FB.Width else FB.Height);
Nico Huber3299ad52018-06-02 16:53:39 +0200187
188 function Pixel_To_Bytes (Pixel : Pixel_Type; FB : Framebuffer_Type)
Nico Huber865f1fa2018-06-05 12:26:41 +0200189 return Size_Type is (Pixel * Pos32 (FB.BPC) / (8 / 4));
Nico Huberc5c767a2018-06-03 01:09:04 +0200190 function FB_Size (FB : Framebuffer_Type)
191 return Pos32 is (Pixel_To_Bytes (FB.Stride * FB.V_Stride, FB));
Nico Huber3299ad52018-06-02 16:53:39 +0200192
Nico Huber71677462018-06-02 16:54:46 +0200193 function Requires_Scaling (FB : Framebuffer_Type; Mode : Mode_Type)
194 return Boolean is
195 (Rotated_Width (FB) /= Mode.H_Visible or
196 Rotated_Height (FB) /= Mode.V_Visible);
197
Nico Huberb217ece2018-06-02 16:56:35 +0200198 type Scaling_Aspect is (Uniform, Letterbox, Pillarbox);
Nico Huberc5c767a2018-06-03 01:09:04 +0200199 function Scaling_Type
200 (Width : Width_Type;
201 Height : Height_Type;
202 Scaled_Width : Width_Type;
203 Scaled_Height : Height_Type)
Nico Huberb217ece2018-06-02 16:56:35 +0200204 return Scaling_Aspect is
Nico Huberda1185e2018-06-03 01:07:46 +0200205 (if Scaled_Width * Height < Scaled_Height * Width then Letterbox
206 elsif Scaled_Width * Height > Scaled_Height * Width then Pillarbox
Nico Huberc5c767a2018-06-03 01:09:04 +0200207 else Uniform);
Nico Huberda1185e2018-06-03 01:07:46 +0200208 function Scaling_Type (FB : Framebuffer_Type; Mode : Mode_Type)
209 return Scaling_Aspect is (Scaling_Type
Nico Huberc5c767a2018-06-03 01:09:04 +0200210 (Rotated_Width (FB), Rotated_Height (FB), Mode.H_Visible, Mode.V_Visible));
Nico Huberb217ece2018-06-02 16:56:35 +0200211
Nico Huber83693c82016-10-08 22:17:55 +0200212end HW.GFX;