blob: 420dc6e7d17eec7c1dfaf06a2a976e89d9015530 [file] [log] [blame]
Nico Huber9bafc492020-05-18 23:33:28 +02001-- SPDX-License-Identifier: GPL-2.0-only
2
Nico Huber2bc892c2019-01-01 22:28:47 +01003with CB.Config;
4
5use CB;
6
Nico Huber542e9482016-10-05 17:47:32 +02007with HW.GFX;
8with HW.GFX.Framebuffer_Filler;
9with HW.GFX.GMA;
Nico Huber989aae92017-03-08 23:03:01 +010010with HW.GFX.GMA.Display_Probing;
Nico Huber542e9482016-10-05 17:47:32 +020011
12use HW.GFX;
13use HW.GFX.GMA;
Nico Huber989aae92017-03-08 23:03:01 +010014use HW.GFX.GMA.Display_Probing;
Nico Huber542e9482016-10-05 17:47:32 +020015
16with GMA.Mainboard;
17
Nico Huber74586292019-02-18 01:21:11 +010018package body GMA.GFX_Init
Nico Huber542e9482016-10-05 17:47:32 +020019is
20
Nico Huber542e9482016-10-05 17:47:32 +020021 ----------------------------------------------------------------------------
22
Nico Huber504d1ef2017-07-16 16:40:41 +020023 procedure gfxinit (lightup_ok : out Interfaces.C.int)
Nico Huber542e9482016-10-05 17:47:32 +020024 is
25 use type pos32;
Nico Huber504d1ef2017-07-16 16:40:41 +020026 use type word64;
Patrick Rudolph92106b12020-02-19 12:54:06 +010027 use type word32;
28 use type Interfaces.C.size_t;
Nico Huber542e9482016-10-05 17:47:32 +020029
30 ports : Port_List;
Nico Huber989aae92017-03-08 23:03:01 +010031 configs : Pipe_Configs;
Nico Huber542e9482016-10-05 17:47:32 +020032
33 success : boolean;
34
Patrick Rudolph92106b12020-02-19 12:54:06 +010035 linear_fb_addr : word64;
36
37 fb : Framebuffer_Type;
38
Nico Huber2bc892c2019-01-01 22:28:47 +010039 min_h : pos32 := Config.LINEAR_FRAMEBUFFER_MAX_WIDTH;
40 min_v : pos32 := Config.LINEAR_FRAMEBUFFER_MAX_HEIGHT;
Patrick Rudolph92106b12020-02-19 12:54:06 +010041
42 fbinfo : Interfaces.C.size_t;
43
Nico Huber542e9482016-10-05 17:47:32 +020044 begin
45 lightup_ok := 0;
46
Nico Huber504d1ef2017-07-16 16:40:41 +020047 HW.GFX.GMA.Initialize (Success => success);
Nico Huber542e9482016-10-05 17:47:32 +020048
49 if success then
50 ports := Mainboard.ports;
Nico Huber989aae92017-03-08 23:03:01 +010051 HW.GFX.GMA.Display_Probing.Scan_Ports (configs, ports);
Nico Huber542e9482016-10-05 17:47:32 +020052
53 if configs (Primary).Port /= Disabled then
Nico Huber989aae92017-03-08 23:03:01 +010054 for i in Pipe_Index loop
Nico Huber542e9482016-10-05 17:47:32 +020055 exit when configs (i).Port = Disabled;
56
Arthur Heymanse9562552018-12-19 14:42:00 +010057 min_h := pos32'min (min_h, configs (i).Mode.H_Visible);
58 min_v := pos32'min (min_v, configs (i).Mode.V_Visible);
Nico Huber542e9482016-10-05 17:47:32 +020059 end loop;
60
Nico Huber71cbd712018-03-29 15:15:10 +020061 fb := configs (Primary).Framebuffer;
62 fb.Width := Width_Type (min_h);
63 fb.Height := Height_Type (min_v);
64 fb.Stride := Div_Round_Up (fb.Width, 16) * 16;
Nico Huber0beb6272018-03-29 15:21:59 +020065 fb.V_Stride := fb.Height;
Nico Huber71cbd712018-03-29 15:15:10 +020066
Nico Huber989aae92017-03-08 23:03:01 +010067 for i in Pipe_Index loop
Nico Huber542e9482016-10-05 17:47:32 +020068 exit when configs (i).Port = Disabled;
69
Nico Hubera4facf82016-11-08 12:29:50 +010070 configs (i).Framebuffer := fb;
Nico Huber542e9482016-10-05 17:47:32 +020071 end loop;
72
Jeremy Compostellae02e9182023-01-24 13:59:46 -070073 pragma Debug (HW.GFX.GMA.Dump_Configs (configs));
Nico Huber542e9482016-10-05 17:47:32 +020074
Nico Huber504d1ef2017-07-16 16:40:41 +020075 HW.GFX.GMA.Setup_Default_FB
76 (FB => fb,
77 Clear => true,
78 Success => success);
Nico Huber542e9482016-10-05 17:47:32 +020079
Nico Huber504d1ef2017-07-16 16:40:41 +020080 if success then
81 HW.GFX.GMA.Update_Outputs (configs);
Nico Huber542e9482016-10-05 17:47:32 +020082
Nico Huber504d1ef2017-07-16 16:40:41 +020083 HW.GFX.GMA.Map_Linear_FB (linear_fb_addr, fb);
Patrick Rudolph92106b12020-02-19 12:54:06 +010084 if linear_fb_addr /= 0 then
85 fbinfo := c_fb_add_framebuffer_info
86 (fb_addr => Interfaces.C.size_t (linear_fb_addr),
87 x_resolution => word32 (fb.Width),
88 y_resolution => word32 (fb.Height),
89 bytes_per_line => word32 (fb.Stride) * 4,
90 bits_per_pixel => 32);
91 if fbinfo /= 0 then
92 lightup_ok := 1;
93 end if;
94 end if;
Nico Huber504d1ef2017-07-16 16:40:41 +020095 end if;
Nico Huber542e9482016-10-05 17:47:32 +020096 end if;
97 end if;
98 end gfxinit;
99
Jeremy Compostella47f154c2022-12-01 15:55:06 -0700100 procedure gfxstop (stop_ok : out Interfaces.C.int)
101 is
102 success : boolean;
103 begin
104 HW.GFX.GMA.Initialize (Clean_State => True,
Elyes Haouas1a0a2802023-01-19 06:59:45 +0100105 Success => success);
Jeremy Compostella47f154c2022-12-01 15:55:06 -0700106 if success then
107 stop_ok := 1;
108 else
109 stop_ok := 0;
110 end if;
111 end gfxstop;
112
Nico Huber74586292019-02-18 01:21:11 +0100113end GMA.GFX_Init;