Skip to content

Commit

Permalink
display: contain all display init logic within display.c
Browse files Browse the repository at this point in the history
Display handling was spread across main.c, utils.c and display.c
with the addition of iDevice support. Condense all of this functionality
into display.c.

This also fixes a regression introduced in 869d2ae ("Skip over features
unsupported in A7-A11 SoCs."), which caused devices using dcpext to skip DCP
initialisation.

Signed-off-by: James Calligeros <[email protected]>
  • Loading branch information
chadmed committed Dec 22, 2024
1 parent dbafd05 commit 6229a1b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
28 changes: 21 additions & 7 deletions src/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ static dcp_dev_t *dcp;
static dcp_iboot_if_t *iboot;
static u64 fb_dva;
static u64 fb_size;
bool has_dcp;
bool display_is_external;
bool display_is_dptx;
bool display_needs_power_cycle;
Expand Down Expand Up @@ -244,14 +245,23 @@ static uintptr_t display_map_fb(uintptr_t iova, u64 paddr, u64 size)

const display_config_t *display_get_config(void)
{
const display_config_t *conf = NULL;

if (adt_is_compatible(adt, 0, "J473AP"))
return &display_config_m2;
conf = &display_config_m2;
else if (adt_is_compatible(adt, 0, "J474sAP") || adt_is_compatible(adt, 0, "J475cAP"))
return &display_config_m2_pro_max;
conf = &display_config_m2_pro_max;
else if (adt_is_compatible(adt, 0, "J180dAP") || adt_is_compatible(adt, 0, "J475dAP"))
return &display_config_m2_ultra;
conf = &display_config_m2_ultra;
else
return &display_config_m1;
conf = &display_config_m1;

has_dcp = adt_path_offset(adt, conf->dcp) > 0;
if (!has_dcp) {
return NULL;
}

return conf;
}

int display_start_dcp(void)
Expand All @@ -264,13 +274,13 @@ int display_start_dcp(void)
return 0;
#endif

const display_config_t *disp_cfg = display_get_config();

if (!has_dcp) {
printf("display: DCP not present\n");
printf("display: device has no DCP. Display will not be initialised.\n");
return -1;
}

const display_config_t *disp_cfg = display_get_config();

display_is_dptx = !!disp_cfg->dptx_phy[0];

dcp = dcp_init(disp_cfg);
Expand Down Expand Up @@ -655,6 +665,10 @@ int display_init(void)

void display_shutdown(dcp_shutdown_mode mode)
{
/* We have no DCP, so just exit */
if (!has_dcp)
return;

if (iboot) {
dcp_ib_shutdown(iboot);
switch (mode) {
Expand Down
4 changes: 1 addition & 3 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ void get_device_info(void)
printf(" Target: %s\n", target);

is_mac = !!strstr(model, "Mac");
has_dcp = adt_path_offset(adt, "/arm-io/dcp") > 0;

int chosen = adt_path_offset(adt, "/chosen");
if (chosen > 0) {
Expand Down Expand Up @@ -165,8 +164,7 @@ void m1n1_main(void)
display_init();
// Kick DCP to sleep, so dodgy monitors which cause reconnect cycles don't cause us to lose the
// framebuffer.
if (has_dcp)
display_shutdown(DCP_SLEEP_IF_EXTERNAL);
display_shutdown(DCP_SLEEP_IF_EXTERNAL);
// On idevice we need to always clear, because otherwise it looks scuffed on white devices
fb_init(!is_mac);
fb_display_logo();
Expand Down
2 changes: 1 addition & 1 deletion src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "vsprintf.h"
#include "xnuboot.h"

bool is_mac, has_dcp;
bool is_mac;

static char ascii(char s)
{
Expand Down
2 changes: 1 addition & 1 deletion src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ struct vector_args {

extern u32 board_id, chip_id;

extern bool is_mac, has_dcp;
extern bool is_mac;
extern bool cpufeat_actlr_el2, cpufeat_fast_ipi, cpufeat_mmu_sprr;
extern bool cpufeat_global_sleep, cpufeat_workaround_cyclone_cache;

Expand Down

0 comments on commit 6229a1b

Please sign in to comment.