2022-01-16 19:29:36 +00:00
|
|
|
/* SPDX-License-Identifier: MIT */
|
|
|
|
|
|
|
|
#include "dcp.h"
|
|
|
|
#include "adt.h"
|
|
|
|
#include "malloc.h"
|
2022-05-31 16:54:11 +00:00
|
|
|
#include "pmgr.h"
|
2022-01-16 19:29:36 +00:00
|
|
|
#include "rtkit.h"
|
|
|
|
#include "utils.h"
|
|
|
|
|
|
|
|
dcp_dev_t *dcp_init(const char *dcp_path, const char *dcp_dart_path, const char *disp_dart_path)
|
|
|
|
{
|
2023-01-25 20:41:31 +00:00
|
|
|
u32 sid;
|
|
|
|
|
|
|
|
int node = adt_path_offset(adt, "/arm-io/dart-dcp/mapper-dcp");
|
|
|
|
if (node < 0) {
|
|
|
|
printf("dcp: mapper-dcp not found!\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (ADT_GETPROP(adt, node, "reg", &sid) < 0) {
|
|
|
|
printf("dcp: failed to read dart stream ID!\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2022-01-16 19:29:36 +00:00
|
|
|
dcp_dev_t *dcp = malloc(sizeof(dcp_dev_t));
|
|
|
|
if (!dcp)
|
|
|
|
return NULL;
|
|
|
|
|
2023-01-25 20:41:31 +00:00
|
|
|
dcp->dart_dcp = dart_init_adt(dcp_dart_path, 0, sid, true);
|
2022-01-16 19:29:36 +00:00
|
|
|
if (!dcp->dart_dcp) {
|
|
|
|
printf("dcp: failed to initialize DCP DART\n");
|
|
|
|
goto out_free;
|
|
|
|
}
|
2023-01-25 16:07:21 +00:00
|
|
|
u64 vm_base = dart_vm_base(dcp->dart_dcp);
|
2023-01-25 20:41:31 +00:00
|
|
|
dart_setup_pt_region(dcp->dart_dcp, dcp_dart_path, sid, vm_base);
|
2022-01-16 19:29:36 +00:00
|
|
|
|
|
|
|
dcp->dart_disp = dart_init_adt(disp_dart_path, 0, 0, true);
|
|
|
|
if (!dcp->dart_disp) {
|
|
|
|
printf("dcp: failed to initialize DISP DART\n");
|
|
|
|
goto out_dart_dcp;
|
|
|
|
}
|
2023-01-25 16:07:21 +00:00
|
|
|
// set disp0's page tables at dart-dcp's vm-base
|
|
|
|
dart_setup_pt_region(dcp->dart_disp, disp_dart_path, 0, vm_base);
|
2022-01-16 19:29:36 +00:00
|
|
|
|
2023-01-26 10:42:54 +00:00
|
|
|
dcp->iovad_dcp = iovad_init(vm_base + 0x10000000, vm_base + 0x20000000);
|
2022-01-16 19:29:36 +00:00
|
|
|
|
|
|
|
dcp->asc = asc_init(dcp_path);
|
|
|
|
if (!dcp->asc) {
|
|
|
|
printf("dcp: failed to initialize ASC\n");
|
|
|
|
goto out_iovad;
|
|
|
|
}
|
|
|
|
|
|
|
|
dcp->rtkit = rtkit_init("dcp", dcp->asc, dcp->dart_dcp, dcp->iovad_dcp, NULL);
|
|
|
|
if (!dcp->rtkit) {
|
|
|
|
printf("dcp: failed to initialize RTKit\n");
|
|
|
|
goto out_iovad;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!rtkit_boot(dcp->rtkit)) {
|
|
|
|
printf("dcp: failed to boot RTKit\n");
|
|
|
|
goto out_iovad;
|
|
|
|
}
|
|
|
|
|
2023-08-29 23:07:39 +00:00
|
|
|
dcp->afk = afk_epic_init(dcp->rtkit);
|
|
|
|
if (!dcp->afk) {
|
|
|
|
printf("dcp: failed to initialize AFK\n");
|
|
|
|
goto out_rtkit;
|
|
|
|
}
|
|
|
|
|
2022-01-16 19:29:36 +00:00
|
|
|
return dcp;
|
|
|
|
|
2023-08-29 23:07:39 +00:00
|
|
|
out_rtkit:
|
2022-05-31 15:51:47 +00:00
|
|
|
rtkit_quiesce(dcp->rtkit);
|
2022-01-16 19:29:36 +00:00
|
|
|
rtkit_free(dcp->rtkit);
|
|
|
|
out_iovad:
|
2022-03-29 11:10:32 +00:00
|
|
|
iovad_shutdown(dcp->iovad_dcp, dcp->dart_dcp);
|
2022-01-16 19:29:36 +00:00
|
|
|
dart_shutdown(dcp->dart_disp);
|
|
|
|
out_dart_dcp:
|
|
|
|
dart_shutdown(dcp->dart_dcp);
|
|
|
|
out_free:
|
|
|
|
free(dcp);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2022-05-31 16:54:11 +00:00
|
|
|
int dcp_shutdown(dcp_dev_t *dcp, bool sleep)
|
2022-01-16 19:29:36 +00:00
|
|
|
{
|
2023-08-29 23:07:39 +00:00
|
|
|
afk_epic_shutdown(dcp->afk);
|
2022-05-31 16:54:11 +00:00
|
|
|
if (sleep) {
|
|
|
|
rtkit_sleep(dcp->rtkit);
|
|
|
|
pmgr_reset(0, "DISP0_CPU0");
|
|
|
|
} else {
|
|
|
|
rtkit_quiesce(dcp->rtkit);
|
|
|
|
}
|
2022-01-16 19:29:36 +00:00
|
|
|
rtkit_free(dcp->rtkit);
|
|
|
|
dart_shutdown(dcp->dart_disp);
|
2022-03-29 11:10:32 +00:00
|
|
|
iovad_shutdown(dcp->iovad_dcp, dcp->dart_dcp);
|
2022-01-16 19:29:36 +00:00
|
|
|
dart_shutdown(dcp->dart_dcp);
|
|
|
|
free(dcp);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|