| Nico Huber | a455f0e | 2018-01-07 11:40:40 +0100 | [diff] [blame^] | 1 | with Ada.Numerics.Discrete_Random; |
| Nico Huber | fda2d6e | 2017-07-09 16:47:52 +0200 | [diff] [blame] | 2 | with Ada.Unchecked_Conversion; |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 3 | with Ada.Command_Line; |
| 4 | with Interfaces.C; |
| 5 | |
| Nico Huber | 3b654a0 | 2017-07-15 22:27:14 +0200 | [diff] [blame] | 6 | with HW.Time; |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 7 | with HW.Debug; |
| Nico Huber | fda2d6e | 2017-07-09 16:47:52 +0200 | [diff] [blame] | 8 | with HW.PCI.Dev; |
| 9 | with HW.MMIO_Range; |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 10 | with HW.GFX.GMA; |
| Nico Huber | 3b654a0 | 2017-07-15 22:27:14 +0200 | [diff] [blame] | 11 | with HW.GFX.GMA.Config; |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 12 | with HW.GFX.GMA.Display_Probing; |
| 13 | |
| Nico Huber | fda2d6e | 2017-07-09 16:47:52 +0200 | [diff] [blame] | 14 | package body HW.GFX.GMA.GFX_Test |
| 15 | is |
| 16 | pragma Disable_Atomic_Synchronization; |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 17 | |
| Nico Huber | a455f0e | 2018-01-07 11:40:40 +0100 | [diff] [blame^] | 18 | Primary_Delay_MS : constant := 8_000; |
| 19 | Secondary_Delay_MS : constant := 4_000; |
| 20 | Seed : constant := 12345; |
| 21 | |
| 22 | package Rand_P is new Ada.Numerics.Discrete_Random (Pos_Type); |
| 23 | Gen : Rand_P.Generator; |
| 24 | function Rand return Pos_Type is (Rand_P.Random (Gen)); |
| 25 | |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 26 | Start_X : constant := 0; |
| 27 | Start_Y : constant := 0; |
| 28 | |
| Nico Huber | fda2d6e | 2017-07-09 16:47:52 +0200 | [diff] [blame] | 29 | package Dev is new PCI.Dev (PCI.Address'(0, 2, 0)); |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 30 | |
| Nico Huber | 3b654a0 | 2017-07-15 22:27:14 +0200 | [diff] [blame] | 31 | type GTT_PTE_Type is mod 2 ** (Config.GTT_PTE_Size * 8); |
| 32 | type GTT_Registers_Type is array (GTT_Range) of GTT_PTE_Type; |
| 33 | package GTT is new MMIO_Range |
| 34 | (Base_Addr => 0, |
| 35 | Element_T => GTT_PTE_Type, |
| 36 | Index_T => GTT_Range, |
| 37 | Array_T => GTT_Registers_Type); |
| 38 | |
| 39 | GTT_Backup : GTT_Registers_Type; |
| 40 | |
| 41 | procedure Backup_GTT |
| 42 | is |
| 43 | begin |
| 44 | for Idx in GTT_Range loop |
| 45 | GTT.Read (GTT_Backup (Idx), Idx); |
| 46 | end loop; |
| 47 | end Backup_GTT; |
| 48 | |
| 49 | procedure Restore_GTT |
| 50 | is |
| 51 | begin |
| 52 | for Idx in GTT_Range loop |
| 53 | GTT.Write (Idx, GTT_Backup (Idx)); |
| 54 | end loop; |
| 55 | end Restore_GTT; |
| 56 | |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 57 | type Pixel_Type is record |
| 58 | Red : Byte; |
| 59 | Green : Byte; |
| 60 | Blue : Byte; |
| 61 | Alpha : Byte; |
| 62 | end record; |
| 63 | |
| 64 | for Pixel_Type use record |
| 65 | Blue at 0 range 0 .. 7; |
| 66 | Green at 1 range 0 .. 7; |
| 67 | Red at 2 range 0 .. 7; |
| 68 | Alpha at 3 range 0 .. 7; |
| 69 | end record; |
| 70 | |
| Nico Huber | 244ea7e | 2017-08-28 11:38:23 +0200 | [diff] [blame] | 71 | White : constant Pixel_Type := (255, 255, 255, 255); |
| 72 | Black : constant Pixel_Type := ( 0, 0, 0, 255); |
| 73 | Red : constant Pixel_Type := (255, 0, 0, 255); |
| 74 | Green : constant Pixel_Type := ( 0, 255, 0, 255); |
| 75 | Blue : constant Pixel_Type := ( 0, 0, 255, 255); |
| 76 | |
| Nico Huber | fda2d6e | 2017-07-09 16:47:52 +0200 | [diff] [blame] | 77 | function Pixel_To_Word (P : Pixel_Type) return Word32 |
| 78 | with |
| 79 | SPARK_Mode => Off |
| 80 | is |
| 81 | function To_Word is new Ada.Unchecked_Conversion (Pixel_Type, Word32); |
| 82 | begin |
| 83 | return To_Word (P); |
| 84 | end Pixel_To_Word; |
| 85 | |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 86 | Max_W : constant := 4096; |
| 87 | Max_H : constant := 2160; |
| 88 | FB_Align : constant := 16#0004_0000#; |
| Nico Huber | fda2d6e | 2017-07-09 16:47:52 +0200 | [diff] [blame] | 89 | subtype Screen_Index is Natural range |
| 90 | 0 .. 3 * (Max_W * Max_H + FB_Align / 4) - 1; |
| 91 | type Screen_Type is array (Screen_Index) of Word32; |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 92 | |
| Nico Huber | 34be654 | 2017-12-13 09:26:24 +0100 | [diff] [blame] | 93 | function Screen_Offset (FB : Framebuffer_Type) return Natural is |
| 94 | (Natural (Phys_Offset (FB) / 4)); |
| 95 | |
| Nico Huber | fda2d6e | 2017-07-09 16:47:52 +0200 | [diff] [blame] | 96 | package Screen is new MMIO_Range (0, Word32, Screen_Index, Screen_Type); |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 97 | |
| Nico Huber | 3b654a0 | 2017-07-15 22:27:14 +0200 | [diff] [blame] | 98 | Screen_Backup : Screen_Type; |
| 99 | |
| 100 | procedure Backup_Screen (FB : Framebuffer_Type) |
| 101 | is |
| Nico Huber | 34be654 | 2017-12-13 09:26:24 +0100 | [diff] [blame] | 102 | First : constant Screen_Index := Screen_Offset (FB); |
| Nico Huber | 3b654a0 | 2017-07-15 22:27:14 +0200 | [diff] [blame] | 103 | Last : constant Screen_Index := First + Natural (FB_Size (FB)) / 4 - 1; |
| 104 | begin |
| 105 | for Idx in Screen_Index range First .. Last loop |
| 106 | Screen.Read (Screen_Backup (Idx), Idx); |
| 107 | end loop; |
| 108 | end Backup_Screen; |
| 109 | |
| 110 | procedure Restore_Screen (FB : Framebuffer_Type) |
| 111 | is |
| Nico Huber | 34be654 | 2017-12-13 09:26:24 +0100 | [diff] [blame] | 112 | First : constant Screen_Index := Screen_Offset (FB); |
| Nico Huber | 3b654a0 | 2017-07-15 22:27:14 +0200 | [diff] [blame] | 113 | Last : constant Screen_Index := First + Natural (FB_Size (FB)) / 4 - 1; |
| 114 | begin |
| 115 | for Idx in Screen_Index range First .. Last loop |
| 116 | Screen.Write (Idx, Screen_Backup (Idx)); |
| 117 | end loop; |
| 118 | end Restore_Screen; |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 119 | |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 120 | function Drawing_Width (FB : Framebuffer_Type) return Natural is |
| 121 | (Natural (FB.Width + 2 * Start_X)); |
| 122 | |
| 123 | function Drawing_Height (FB : Framebuffer_Type) return Natural is |
| 124 | (Natural (FB.Height + 2 * Start_Y)); |
| 125 | |
| Nico Huber | 244ea7e | 2017-08-28 11:38:23 +0200 | [diff] [blame] | 126 | function Corner_Fill |
| 127 | (X, Y : Natural; |
| 128 | FB : Framebuffer_Type; |
| 129 | Pipe : Pipe_Index) |
| 130 | return Pixel_Type |
| 131 | is |
| 132 | Xrel : constant Integer := |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 133 | (if X < 32 then X else X - (Drawing_Width (FB) - 32)); |
| Nico Huber | 244ea7e | 2017-08-28 11:38:23 +0200 | [diff] [blame] | 134 | Yrel : constant Integer := |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 135 | (if Y < 32 then Y else Y - (Drawing_Height (FB) - 32)); |
| Nico Huber | 244ea7e | 2017-08-28 11:38:23 +0200 | [diff] [blame] | 136 | |
| 137 | function Color (Idx : Natural) return Pixel_Type is |
| 138 | (case (Idx + Pipe_Index'Pos (Pipe)) mod 4 is |
| 139 | when 0 => Blue, when 1 => Black, |
| 140 | when 3 => Green, when others => Red); |
| 141 | begin |
| 142 | return |
| 143 | (if Xrel mod 16 = 0 or Xrel = 31 or Yrel mod 16 = 0 or Yrel = 31 then |
| 144 | White |
| 145 | elsif Yrel < 16 then |
| 146 | (if Xrel < 16 then Color (0) else Color (1)) |
| 147 | else |
| 148 | (if Xrel < 16 then Color (3) else Color (2))); |
| 149 | end Corner_Fill; |
| 150 | |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 151 | function Fill |
| 152 | (X, Y : Natural; |
| 153 | Framebuffer : Framebuffer_Type; |
| Nico Huber | 244ea7e | 2017-08-28 11:38:23 +0200 | [diff] [blame] | 154 | Pipe : Pipe_Index) |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 155 | return Pixel_Type |
| 156 | is |
| 157 | use type HW.Byte; |
| 158 | |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 159 | Xp : constant Natural := X * 256 / Drawing_Width (Framebuffer); |
| 160 | Yp : constant Natural := Y * 256 / Drawing_Height (Framebuffer); |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 161 | Xn : constant Natural := 255 - Xp; |
| 162 | Yn : constant Natural := 255 - Yp; |
| 163 | |
| 164 | function Map (X, Y : Natural) return Byte is |
| 165 | begin |
| 166 | return Byte (X * Y / 255); |
| 167 | end Map; |
| 168 | begin |
| 169 | return |
| 170 | (case Pipe is |
| 171 | when GMA.Primary => (Map (Xn, Yn), Map (Xp, Yn), Map (Xp, Yp), 255), |
| 172 | when GMA.Secondary => (Map (Xn, Yp), Map (Xn, Yn), Map (Xp, Yn), 255), |
| 173 | when GMA.Tertiary => (Map (Xp, Yp), Map (Xn, Yp), Map (Xn, Yn), 255)); |
| 174 | end Fill; |
| 175 | |
| 176 | procedure Test_Screen |
| 177 | (Framebuffer : Framebuffer_Type; |
| 178 | Pipe : GMA.Pipe_Index) |
| 179 | is |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 180 | P : Pixel_Type; |
| 181 | -- We have pixel offset wheras the framebuffer has a byte offset |
| Nico Huber | 34be654 | 2017-12-13 09:26:24 +0100 | [diff] [blame] | 182 | Offset_Y : Natural := Screen_Offset (Framebuffer); |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 183 | Offset : Natural; |
| Nico Huber | 9ca69f1 | 2017-08-28 14:31:46 +0200 | [diff] [blame] | 184 | |
| 185 | function Top_Test (X, Y : Natural) return Boolean |
| 186 | is |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 187 | C : constant Natural := Drawing_Width (Framebuffer) / 2; |
| 188 | S_Y : constant Natural := 3 * (Y - Start_Y) / 2; |
| Nico Huber | 9ca69f1 | 2017-08-28 14:31:46 +0200 | [diff] [blame] | 189 | Left : constant Integer := X - C + S_Y; |
| 190 | Right : constant Integer := X - C - S_Y; |
| 191 | begin |
| 192 | return |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 193 | (Y - Start_Y) < 12 and |
| Nico Huber | 9ca69f1 | 2017-08-28 14:31:46 +0200 | [diff] [blame] | 194 | ((-1 <= Left and Left <= 0) or |
| 195 | (0 <= Right and Right <= 1)); |
| 196 | end Top_Test; |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 197 | begin |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 198 | for Y in 0 .. Drawing_Height (Framebuffer) - 1 loop |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 199 | Offset := Offset_Y; |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 200 | for X in 0 .. Drawing_Width (Framebuffer) - 1 loop |
| 201 | if (X < 32 or X >= Drawing_Width (Framebuffer) - 32) and |
| 202 | (Y < 32 or Y >= Drawing_Height (Framebuffer) - 32) |
| Nico Huber | 244ea7e | 2017-08-28 11:38:23 +0200 | [diff] [blame] | 203 | then |
| 204 | P := Corner_Fill (X, Y, Framebuffer, Pipe); |
| Nico Huber | 9ca69f1 | 2017-08-28 14:31:46 +0200 | [diff] [blame] | 205 | elsif Framebuffer.Rotation /= No_Rotation and then |
| 206 | Top_Test (X, Y) |
| 207 | then |
| 208 | P := White; |
| Nico Huber | 244ea7e | 2017-08-28 11:38:23 +0200 | [diff] [blame] | 209 | elsif Y mod 16 = 0 or X mod 16 = 0 then |
| 210 | P := Black; |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 211 | else |
| 212 | P := Fill (X, Y, Framebuffer, Pipe); |
| 213 | end if; |
| Nico Huber | fda2d6e | 2017-07-09 16:47:52 +0200 | [diff] [blame] | 214 | Screen.Write (Offset, Pixel_To_Word (P)); |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 215 | Offset := Offset + 1; |
| 216 | end loop; |
| 217 | Offset_Y := Offset_Y + Natural (Framebuffer.Stride); |
| 218 | end loop; |
| 219 | end Test_Screen; |
| 220 | |
| 221 | procedure Calc_Framebuffer |
| 222 | (FB : out Framebuffer_Type; |
| 223 | Mode : in Mode_Type; |
| Nico Huber | 88f3c98 | 2017-08-28 13:31:38 +0200 | [diff] [blame] | 224 | Rotation : in Rotation_Type; |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 225 | Offset : in out Word32) |
| 226 | is |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 227 | Width : constant Width_Type := Width_Type (Mode.H_Visible); |
| 228 | Height : constant Height_Type := Height_Type (Mode.V_Visible); |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 229 | begin |
| 230 | Offset := (Offset + FB_Align - 1) and not (FB_Align - 1); |
| Nico Huber | 88f3c98 | 2017-08-28 13:31:38 +0200 | [diff] [blame] | 231 | if Rotation = Rotated_90 or Rotation = Rotated_270 then |
| 232 | FB := |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 233 | (Width => Width_Type (Height), |
| 234 | Height => Height_Type (Width), |
| 235 | Start_X => Start_X, |
| 236 | Start_Y => Start_Y, |
| Nico Huber | 88f3c98 | 2017-08-28 13:31:38 +0200 | [diff] [blame] | 237 | BPC => 8, |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 238 | Stride => Div_Round_Up (Pos32 (Height + 2 * Start_X), 32) * 32, |
| 239 | V_Stride => Div_Round_Up (Pos32 (Width + 2 * Start_Y), 32) * 32, |
| Nico Huber | 88f3c98 | 2017-08-28 13:31:38 +0200 | [diff] [blame] | 240 | Tiling => Y_Tiled, |
| 241 | Rotation => Rotation, |
| Nico Huber | 34be654 | 2017-12-13 09:26:24 +0100 | [diff] [blame] | 242 | Offset => Offset + Word32 (GTT_Rotation_Offset) * GTT_Page_Size); |
| Nico Huber | 88f3c98 | 2017-08-28 13:31:38 +0200 | [diff] [blame] | 243 | else |
| 244 | FB := |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 245 | (Width => Width, |
| 246 | Height => Height, |
| 247 | Start_X => Start_X, |
| 248 | Start_Y => Start_Y, |
| Nico Huber | 88f3c98 | 2017-08-28 13:31:38 +0200 | [diff] [blame] | 249 | BPC => 8, |
| Nico Huber | 5ef4d60 | 2017-12-13 13:56:47 +0100 | [diff] [blame] | 250 | Stride => Div_Round_Up (Width + 2 * Start_X, 16) * 16, |
| 251 | V_Stride => Height + 2 * Start_Y, |
| Nico Huber | 88f3c98 | 2017-08-28 13:31:38 +0200 | [diff] [blame] | 252 | Tiling => Linear, |
| 253 | Rotation => Rotation, |
| 254 | Offset => Offset); |
| 255 | end if; |
| Nico Huber | b747049 | 2017-11-30 14:48:35 +0100 | [diff] [blame] | 256 | Offset := Offset + Word32 (FB_Size (FB)); |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 257 | end Calc_Framebuffer; |
| 258 | |
| Nico Huber | 3b654a0 | 2017-07-15 22:27:14 +0200 | [diff] [blame] | 259 | Pipes : GMA.Pipe_Configs; |
| 260 | |
| Nico Huber | 88f3c98 | 2017-08-28 13:31:38 +0200 | [diff] [blame] | 261 | procedure Prepare_Configs (Rotation : Rotation_Type) |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 262 | is |
| 263 | use type HW.GFX.GMA.Port_Type; |
| 264 | |
| Nico Huber | fda2d6e | 2017-07-09 16:47:52 +0200 | [diff] [blame] | 265 | Offset : Word32 := 0; |
| Nico Huber | 3b654a0 | 2017-07-15 22:27:14 +0200 | [diff] [blame] | 266 | Success : Boolean; |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 267 | begin |
| 268 | GMA.Display_Probing.Scan_Ports (Pipes); |
| 269 | |
| 270 | for Pipe in GMA.Pipe_Index loop |
| 271 | if Pipes (Pipe).Port /= GMA.Disabled then |
| 272 | Calc_Framebuffer |
| 273 | (FB => Pipes (Pipe).Framebuffer, |
| 274 | Mode => Pipes (Pipe).Mode, |
| Nico Huber | 88f3c98 | 2017-08-28 13:31:38 +0200 | [diff] [blame] | 275 | Rotation => Rotation, |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 276 | Offset => Offset); |
| Nico Huber | 3b654a0 | 2017-07-15 22:27:14 +0200 | [diff] [blame] | 277 | GMA.Setup_Default_FB |
| 278 | (FB => Pipes (Pipe).Framebuffer, |
| 279 | Clear => False, |
| 280 | Success => Success); |
| 281 | if not Success then |
| 282 | Pipes (Pipe).Port := GMA.Disabled; |
| 283 | end if; |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 284 | end if; |
| 285 | end loop; |
| 286 | |
| 287 | GMA.Dump_Configs (Pipes); |
| 288 | end Prepare_Configs; |
| 289 | |
| Nico Huber | 3b654a0 | 2017-07-15 22:27:14 +0200 | [diff] [blame] | 290 | procedure Print_Usage |
| 291 | is |
| 292 | begin |
| 293 | Debug.Put_Line |
| Nico Huber | 88f3c98 | 2017-08-28 13:31:38 +0200 | [diff] [blame] | 294 | ("Usage: " & Ada.Command_Line.Command_Name & |
| 295 | " <delay seconds>" & |
| 296 | " [(0|90|180|270)]"); |
| Nico Huber | 3b654a0 | 2017-07-15 22:27:14 +0200 | [diff] [blame] | 297 | Debug.New_Line; |
| 298 | end Print_Usage; |
| 299 | |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 300 | procedure Main |
| 301 | is |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 302 | use type HW.GFX.GMA.Port_Type; |
| Nico Huber | fda2d6e | 2017-07-09 16:47:52 +0200 | [diff] [blame] | 303 | use type HW.Word64; |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 304 | use type Interfaces.C.int; |
| 305 | |
| Nico Huber | fda2d6e | 2017-07-09 16:47:52 +0200 | [diff] [blame] | 306 | Res_Addr : Word64; |
| 307 | |
| Nico Huber | a455f0e | 2018-01-07 11:40:40 +0100 | [diff] [blame^] | 308 | Delay_MS : Natural; |
| Nico Huber | 88f3c98 | 2017-08-28 13:31:38 +0200 | [diff] [blame] | 309 | Rotation : Rotation_Type := No_Rotation; |
| Nico Huber | 3b654a0 | 2017-07-15 22:27:14 +0200 | [diff] [blame] | 310 | |
| Nico Huber | fda2d6e | 2017-07-09 16:47:52 +0200 | [diff] [blame] | 311 | Dev_Init, |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 312 | Initialized : Boolean; |
| 313 | |
| 314 | function iopl (level : Interfaces.C.int) return Interfaces.C.int; |
| 315 | pragma Import (C, iopl, "iopl"); |
| 316 | begin |
| Nico Huber | 88f3c98 | 2017-08-28 13:31:38 +0200 | [diff] [blame] | 317 | if Ada.Command_Line.Argument_Count < 1 then |
| Nico Huber | 3b654a0 | 2017-07-15 22:27:14 +0200 | [diff] [blame] | 318 | Print_Usage; |
| 319 | return; |
| 320 | end if; |
| 321 | |
| Nico Huber | a455f0e | 2018-01-07 11:40:40 +0100 | [diff] [blame^] | 322 | Delay_MS := Natural'Value (Ada.Command_Line.Argument (1)) * 1_000; |
| Nico Huber | 3b654a0 | 2017-07-15 22:27:14 +0200 | [diff] [blame] | 323 | |
| Nico Huber | 88f3c98 | 2017-08-28 13:31:38 +0200 | [diff] [blame] | 324 | if Ada.Command_Line.Argument_Count >= 2 then |
| 325 | declare |
| 326 | Rotation_Degree : constant String := Ada.Command_Line.Argument (2); |
| 327 | begin |
| 328 | if Rotation_Degree = "0" then Rotation := No_Rotation; |
| 329 | elsif Rotation_Degree = "90" then Rotation := Rotated_90; |
| 330 | elsif Rotation_Degree = "180" then Rotation := Rotated_180; |
| 331 | elsif Rotation_Degree = "270" then Rotation := Rotated_270; |
| 332 | else Print_Usage; return; end if; |
| 333 | end; |
| 334 | end if; |
| 335 | |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 336 | if iopl (3) /= 0 then |
| 337 | Debug.Put_Line ("Failed to change i/o privilege level."); |
| 338 | return; |
| 339 | end if; |
| 340 | |
| Nico Huber | fda2d6e | 2017-07-09 16:47:52 +0200 | [diff] [blame] | 341 | Dev.Initialize (Dev_Init); |
| 342 | if not Dev_Init then |
| 343 | Debug.Put_Line ("Failed to map PCI config."); |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 344 | return; |
| 345 | end if; |
| 346 | |
| Nico Huber | 3b654a0 | 2017-07-15 22:27:14 +0200 | [diff] [blame] | 347 | Dev.Map (Res_Addr, PCI.Res0, Offset => Config.GTT_Offset); |
| 348 | if Res_Addr = 0 then |
| 349 | Debug.Put_Line ("Failed to map PCI resource0."); |
| 350 | return; |
| 351 | end if; |
| 352 | GTT.Set_Base_Address (Res_Addr); |
| 353 | |
| Nico Huber | fda2d6e | 2017-07-09 16:47:52 +0200 | [diff] [blame] | 354 | Dev.Map (Res_Addr, PCI.Res2, WC => True); |
| 355 | if Res_Addr = 0 then |
| 356 | Debug.Put_Line ("Failed to map PCI resource2."); |
| 357 | return; |
| 358 | end if; |
| 359 | Screen.Set_Base_Address (Res_Addr); |
| 360 | |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 361 | GMA.Initialize |
| Nico Huber | 2b6f699 | 2017-07-09 18:11:34 +0200 | [diff] [blame] | 362 | (Clean_State => True, |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 363 | Success => Initialized); |
| 364 | |
| 365 | if Initialized then |
| Nico Huber | 3b654a0 | 2017-07-15 22:27:14 +0200 | [diff] [blame] | 366 | Backup_GTT; |
| 367 | |
| Nico Huber | 88f3c98 | 2017-08-28 13:31:38 +0200 | [diff] [blame] | 368 | Prepare_Configs (Rotation); |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 369 | |
| 370 | GMA.Update_Outputs (Pipes); |
| 371 | |
| 372 | for Pipe in GMA.Pipe_Index loop |
| 373 | if Pipes (Pipe).Port /= GMA.Disabled then |
| Nico Huber | 3b654a0 | 2017-07-15 22:27:14 +0200 | [diff] [blame] | 374 | Backup_Screen (Pipes (Pipe).Framebuffer); |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 375 | Test_Screen |
| 376 | (Framebuffer => Pipes (Pipe).Framebuffer, |
| 377 | Pipe => Pipe); |
| 378 | end if; |
| 379 | end loop; |
| Nico Huber | 3b654a0 | 2017-07-15 22:27:14 +0200 | [diff] [blame] | 380 | |
| Nico Huber | a455f0e | 2018-01-07 11:40:40 +0100 | [diff] [blame^] | 381 | if Delay_MS >= Primary_Delay_MS + Secondary_Delay_MS then |
| 382 | Time.M_Delay (Primary_Delay_MS); |
| 383 | Delay_MS := Delay_MS - Primary_Delay_MS; |
| 384 | declare |
| 385 | New_Pipes : GMA.Pipe_Configs := Pipes; |
| 386 | |
| 387 | function Rand_Div (Num : Pos_Type) return Pos_Type is |
| 388 | (case Rand mod 4 is |
| 389 | when 3 => Rand mod Num / 3, |
| 390 | when 2 => Rand mod Num / 2, |
| 391 | when 1 => Rand mod Num, |
| 392 | when others => 0); |
| 393 | begin |
| 394 | Rand_P.Reset (Gen, Seed); |
| 395 | while Delay_MS >= Secondary_Delay_MS loop |
| 396 | New_Pipes := Pipes; |
| 397 | for Pipe in GMA.Pipe_Index loop |
| 398 | exit when Pipes (Pipe).Port = Disabled; |
| 399 | declare |
| 400 | New_FB : Framebuffer_Type renames |
| 401 | New_Pipes (Pipe).Framebuffer; |
| 402 | Width : constant Width_Type := |
| 403 | Pipes (Pipe).Framebuffer.Width; |
| 404 | Height : constant Height_Type := |
| 405 | Pipes (Pipe).Framebuffer.Height; |
| 406 | begin |
| 407 | New_FB.Start_X := Pos_Type'Min |
| 408 | (Width - 320, Rand_Div (Width)); |
| 409 | New_FB.Start_Y := Pos_Type'Min |
| 410 | (Height - 320, Rand_Div (Height)); |
| 411 | New_FB.Width := Width_Type'Max |
| 412 | (320, Width - New_FB.Start_X - Rand_Div (Width)); |
| 413 | New_FB.Height := Height_Type'Max |
| 414 | (320, Height - New_FB.Start_Y - Rand_Div (Height)); |
| 415 | end; |
| 416 | end loop; |
| 417 | GMA.Dump_Configs (New_Pipes); |
| 418 | GMA.Update_Outputs (New_Pipes); |
| 419 | Time.M_Delay (Secondary_Delay_MS); |
| 420 | Delay_MS := Delay_MS - Secondary_Delay_MS; |
| 421 | end loop; |
| 422 | end; |
| 423 | end if; |
| 424 | Time.M_Delay (Delay_MS); |
| Nico Huber | 3b654a0 | 2017-07-15 22:27:14 +0200 | [diff] [blame] | 425 | |
| 426 | for Pipe in GMA.Pipe_Index loop |
| 427 | if Pipes (Pipe).Port /= GMA.Disabled then |
| 428 | Restore_Screen (Pipes (Pipe).Framebuffer); |
| 429 | end if; |
| 430 | end loop; |
| 431 | Restore_GTT; |
| Nico Huber | 1d0abe4 | 2017-03-05 14:14:09 +0100 | [diff] [blame] | 432 | end if; |
| 433 | end Main; |
| 434 | |
| Nico Huber | fda2d6e | 2017-07-09 16:47:52 +0200 | [diff] [blame] | 435 | end HW.GFX.GMA.GFX_Test; |