| 1 |
-- SPDX-License-Identifier: GPL-2.0-only |
| 2 |
|
| 3 |
with CB.Config; |
| 4 |
|
| 5 |
use CB; |
| 6 |
|
| 7 |
with HW.GFX; |
| 8 |
with HW.GFX.Framebuffer_Filler; |
| 9 |
with HW.GFX.GMA; |
| 10 |
with HW.GFX.GMA.Display_Probing; |
| 11 |
|
| 12 |
use HW.GFX; |
| 13 |
use HW.GFX.GMA; |
| 14 |
use HW.GFX.GMA.Display_Probing; |
| 15 |
|
| 16 |
with GMA.Mainboard; |
| 17 |
|
| 18 |
package body GMA.GFX_Init |
| 19 |
is |
| 20 |
|
| 21 |
configs : Pipe_Configs; |
| 22 |
---------------------------------------------------------------------------- |
| 23 |
|
| 24 |
procedure Screen_Rotation (rotation : out Rotation_Type) |
| 25 |
is |
| 26 |
begin |
| 27 |
rotation := |
| 28 |
(case Config.DEFAULT_SCREEN_ROTATION_INT is |
| 29 |
when 90 => Rotated_90, |
| 30 |
when 180 => Rotated_180, |
| 31 |
when 270 => Rotated_270, |
| 32 |
when others => No_Rotation); |
| 33 |
end Screen_Rotation; |
| 34 |
|
| 35 |
procedure gfxinit (lightup_ok : out Interfaces.C.int) |
| 36 |
is |
| 37 |
use type pos32; |
| 38 |
use type word64; |
| 39 |
use type word32; |
| 40 |
use type Interfaces.C.size_t; |
| 41 |
use type Interfaces.C.int; |
| 42 |
|
| 43 |
ports : Port_List; |
| 44 |
|
| 45 |
success : boolean; |
| 46 |
|
| 47 |
linear_fb_addr : word64; |
| 48 |
|
| 49 |
fb : Framebuffer_Type; |
| 50 |
|
| 51 |
min_h : pos32 := Config.LINEAR_FRAMEBUFFER_MAX_WIDTH; |
| 52 |
min_v : pos32 := Config.LINEAR_FRAMEBUFFER_MAX_HEIGHT; |
| 53 |
|
| 54 |
fbinfo : Interfaces.C.int; |
| 55 |
|
| 56 |
begin |
| 57 |
lightup_ok := 0; |
| 58 |
|
| 59 |
HW.GFX.GMA.Initialize (Success => success); |
| 60 |
|
| 61 |
if success then |
| 62 |
ports := Mainboard.ports; |
| 63 |
HW.GFX.GMA.Display_Probing.Scan_Ports (configs, ports); |
| 64 |
|
| 65 |
if configs (Primary).Port /= Disabled then |
| 66 |
for i in Pipe_Index loop |
| 67 |
exit when configs (i).Port = Disabled; |
| 68 |
|
| 69 |
min_h := pos32'min (min_h, configs (i).Mode.H_Visible); |
| 70 |
min_v := pos32'min (min_v, configs (i).Mode.V_Visible); |
| 71 |
end loop; |
| 72 |
|
| 73 |
fb := configs (Primary).Framebuffer; |
| 74 |
Screen_Rotation (fb.Rotation); |
| 75 |
|
| 76 |
if fb.Rotation = Rotated_90 or fb.Rotation = Rotated_270 then |
| 77 |
fb.Width := Width_Type (min_v); |
| 78 |
fb.Height := Height_Type (min_h); |
| 79 |
fb.Stride := Div_Round_Up (fb.Width, 32) * 32; |
| 80 |
fb.V_Stride := Div_Round_Up (fb.Height, 32) * 32; |
| 81 |
fb.Tiling := Y_Tiled; |
| 82 |
fb.Offset := word32 (GTT_Rotation_Offset) * GTT_Page_Size; |
| 83 |
else |
| 84 |
fb.Width := Width_Type (min_h); |
| 85 |
fb.Height := Height_Type (min_v); |
| 86 |
fb.Stride := Div_Round_Up (fb.Width, 16) * 16; |
| 87 |
fb.V_Stride := fb.Height; |
| 88 |
end if; |
| 89 |
|
| 90 |
for i in Pipe_Index loop |
| 91 |
exit when configs (i).Port = Disabled; |
| 92 |
|
| 93 |
configs (i).Framebuffer := fb; |
| 94 |
end loop; |
| 95 |
|
| 96 |
pragma Debug (HW.GFX.GMA.Dump_Configs (configs)); |
| 97 |
|
| 98 |
HW.GFX.GMA.Setup_Default_FB |
| 99 |
(FB => fb, |
| 100 |
Clear => true, |
| 101 |
Success => success); |
| 102 |
|
| 103 |
if success then |
| 104 |
HW.GFX.GMA.Update_Outputs (configs); |
| 105 |
|
| 106 |
HW.GFX.GMA.Map_Linear_FB (linear_fb_addr, fb); |
| 107 |
if linear_fb_addr /= 0 then |
| 108 |
fbinfo := C_Fb_Add_Framebuffer_Info_Simple |
| 109 |
(fb_addr => Interfaces.C.size_t (linear_fb_addr), |
| 110 |
x_resolution => word32 (fb.Width), |
| 111 |
y_resolution => word32 (fb.Height), |
| 112 |
bytes_per_line => word32 (fb.Stride) * 4, |
| 113 |
bits_per_pixel => 32); |
| 114 |
if fbinfo /= 0 then |
| 115 |
lightup_ok := 1; |
| 116 |
end if; |
| 117 |
end if; |
| 118 |
end if; |
| 119 |
end if; |
| 120 |
end if; |
| 121 |
end gfxinit; |
| 122 |
|
| 123 |
procedure gfxstop |
| 124 |
is |
| 125 |
begin |
| 126 |
if configs (Primary).Port /= Disabled then |
| 127 |
for i in Pipe_Index loop |
| 128 |
configs (i).Port := Disabled; |
| 129 |
end loop; |
| 130 |
HW.GFX.GMA.Update_Outputs (configs); |
| 131 |
end if; |
| 132 |
end gfxstop; |
| 133 |
|
| 134 |
end GMA.GFX_Init; |