Nico Huber | 9bafc49 | 2020-05-18 23:33:28 +0200 | [diff] [blame] | 1 | -- SPDX-License-Identifier: GPL-2.0-only |
| 2 | |
Nico Huber | 2bc892c | 2019-01-01 22:28:47 +0100 | [diff] [blame] | 3 | with CB.Config; |
| 4 | |
| 5 | use CB; |
| 6 | |
Nico Huber | 542e948 | 2016-10-05 17:47:32 +0200 | [diff] [blame] | 7 | with HW.GFX; |
| 8 | with HW.GFX.Framebuffer_Filler; |
| 9 | with HW.GFX.GMA; |
Nico Huber | 989aae9 | 2017-03-08 23:03:01 +0100 | [diff] [blame] | 10 | with HW.GFX.GMA.Display_Probing; |
Nico Huber | 542e948 | 2016-10-05 17:47:32 +0200 | [diff] [blame] | 11 | |
| 12 | use HW.GFX; |
| 13 | use HW.GFX.GMA; |
Nico Huber | 989aae9 | 2017-03-08 23:03:01 +0100 | [diff] [blame] | 14 | use HW.GFX.GMA.Display_Probing; |
Nico Huber | 542e948 | 2016-10-05 17:47:32 +0200 | [diff] [blame] | 15 | |
| 16 | with GMA.Mainboard; |
| 17 | |
Nico Huber | 7458629 | 2019-02-18 01:21:11 +0100 | [diff] [blame] | 18 | package body GMA.GFX_Init |
Nico Huber | 542e948 | 2016-10-05 17:47:32 +0200 | [diff] [blame] | 19 | is |
| 20 | |
Nico Huber | 542e948 | 2016-10-05 17:47:32 +0200 | [diff] [blame] | 21 | ---------------------------------------------------------------------------- |
| 22 | |
Nico Huber | 504d1ef | 2017-07-16 16:40:41 +0200 | [diff] [blame] | 23 | procedure gfxinit (lightup_ok : out Interfaces.C.int) |
Nico Huber | 542e948 | 2016-10-05 17:47:32 +0200 | [diff] [blame] | 24 | is |
| 25 | use type pos32; |
Nico Huber | 504d1ef | 2017-07-16 16:40:41 +0200 | [diff] [blame] | 26 | use type word64; |
Patrick Rudolph | 92106b1 | 2020-02-19 12:54:06 +0100 | [diff] [blame] | 27 | use type word32; |
| 28 | use type Interfaces.C.size_t; |
Nico Huber | 542e948 | 2016-10-05 17:47:32 +0200 | [diff] [blame] | 29 | |
| 30 | ports : Port_List; |
Nico Huber | 989aae9 | 2017-03-08 23:03:01 +0100 | [diff] [blame] | 31 | configs : Pipe_Configs; |
Nico Huber | 542e948 | 2016-10-05 17:47:32 +0200 | [diff] [blame] | 32 | |
| 33 | success : boolean; |
| 34 | |
Patrick Rudolph | 92106b1 | 2020-02-19 12:54:06 +0100 | [diff] [blame] | 35 | linear_fb_addr : word64; |
| 36 | |
| 37 | fb : Framebuffer_Type; |
| 38 | |
Nico Huber | 2bc892c | 2019-01-01 22:28:47 +0100 | [diff] [blame] | 39 | min_h : pos32 := Config.LINEAR_FRAMEBUFFER_MAX_WIDTH; |
| 40 | min_v : pos32 := Config.LINEAR_FRAMEBUFFER_MAX_HEIGHT; |
Patrick Rudolph | 92106b1 | 2020-02-19 12:54:06 +0100 | [diff] [blame] | 41 | |
| 42 | fbinfo : Interfaces.C.size_t; |
| 43 | |
Nico Huber | 542e948 | 2016-10-05 17:47:32 +0200 | [diff] [blame] | 44 | begin |
| 45 | lightup_ok := 0; |
| 46 | |
Nico Huber | 504d1ef | 2017-07-16 16:40:41 +0200 | [diff] [blame] | 47 | HW.GFX.GMA.Initialize (Success => success); |
Nico Huber | 542e948 | 2016-10-05 17:47:32 +0200 | [diff] [blame] | 48 | |
| 49 | if success then |
| 50 | ports := Mainboard.ports; |
Nico Huber | 989aae9 | 2017-03-08 23:03:01 +0100 | [diff] [blame] | 51 | HW.GFX.GMA.Display_Probing.Scan_Ports (configs, ports); |
Nico Huber | 542e948 | 2016-10-05 17:47:32 +0200 | [diff] [blame] | 52 | |
| 53 | if configs (Primary).Port /= Disabled then |
Nico Huber | 989aae9 | 2017-03-08 23:03:01 +0100 | [diff] [blame] | 54 | for i in Pipe_Index loop |
Nico Huber | 542e948 | 2016-10-05 17:47:32 +0200 | [diff] [blame] | 55 | exit when configs (i).Port = Disabled; |
| 56 | |
Arthur Heymans | e956255 | 2018-12-19 14:42:00 +0100 | [diff] [blame] | 57 | min_h := pos32'min (min_h, configs (i).Mode.H_Visible); |
| 58 | min_v := pos32'min (min_v, configs (i).Mode.V_Visible); |
Nico Huber | 542e948 | 2016-10-05 17:47:32 +0200 | [diff] [blame] | 59 | end loop; |
| 60 | |
Nico Huber | 71cbd71 | 2018-03-29 15:15:10 +0200 | [diff] [blame] | 61 | 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 Huber | 0beb627 | 2018-03-29 15:21:59 +0200 | [diff] [blame] | 65 | fb.V_Stride := fb.Height; |
Nico Huber | 71cbd71 | 2018-03-29 15:15:10 +0200 | [diff] [blame] | 66 | |
Nico Huber | 989aae9 | 2017-03-08 23:03:01 +0100 | [diff] [blame] | 67 | for i in Pipe_Index loop |
Nico Huber | 542e948 | 2016-10-05 17:47:32 +0200 | [diff] [blame] | 68 | exit when configs (i).Port = Disabled; |
| 69 | |
Nico Huber | a4facf8 | 2016-11-08 12:29:50 +0100 | [diff] [blame] | 70 | configs (i).Framebuffer := fb; |
Nico Huber | 542e948 | 2016-10-05 17:47:32 +0200 | [diff] [blame] | 71 | end loop; |
| 72 | |
Jeremy Compostella | e02e918 | 2023-01-24 13:59:46 -0700 | [diff] [blame^] | 73 | pragma Debug (HW.GFX.GMA.Dump_Configs (configs)); |
Nico Huber | 542e948 | 2016-10-05 17:47:32 +0200 | [diff] [blame] | 74 | |
Nico Huber | 504d1ef | 2017-07-16 16:40:41 +0200 | [diff] [blame] | 75 | HW.GFX.GMA.Setup_Default_FB |
| 76 | (FB => fb, |
| 77 | Clear => true, |
| 78 | Success => success); |
Nico Huber | 542e948 | 2016-10-05 17:47:32 +0200 | [diff] [blame] | 79 | |
Nico Huber | 504d1ef | 2017-07-16 16:40:41 +0200 | [diff] [blame] | 80 | if success then |
| 81 | HW.GFX.GMA.Update_Outputs (configs); |
Nico Huber | 542e948 | 2016-10-05 17:47:32 +0200 | [diff] [blame] | 82 | |
Nico Huber | 504d1ef | 2017-07-16 16:40:41 +0200 | [diff] [blame] | 83 | HW.GFX.GMA.Map_Linear_FB (linear_fb_addr, fb); |
Patrick Rudolph | 92106b1 | 2020-02-19 12:54:06 +0100 | [diff] [blame] | 84 | 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 Huber | 504d1ef | 2017-07-16 16:40:41 +0200 | [diff] [blame] | 95 | end if; |
Nico Huber | 542e948 | 2016-10-05 17:47:32 +0200 | [diff] [blame] | 96 | end if; |
| 97 | end if; |
| 98 | end gfxinit; |
| 99 | |
Jeremy Compostella | 47f154c | 2022-12-01 15:55:06 -0700 | [diff] [blame] | 100 | procedure gfxstop (stop_ok : out Interfaces.C.int) |
| 101 | is |
| 102 | success : boolean; |
| 103 | begin |
| 104 | HW.GFX.GMA.Initialize (Clean_State => True, |
Elyes Haouas | 1a0a280 | 2023-01-19 06:59:45 +0100 | [diff] [blame] | 105 | Success => success); |
Jeremy Compostella | 47f154c | 2022-12-01 15:55:06 -0700 | [diff] [blame] | 106 | if success then |
| 107 | stop_ok := 1; |
| 108 | else |
| 109 | stop_ok := 0; |
| 110 | end if; |
| 111 | end gfxstop; |
| 112 | |
Nico Huber | 7458629 | 2019-02-18 01:21:11 +0100 | [diff] [blame] | 113 | end GMA.GFX_Init; |