Skip to content

Commit

Permalink
v4p: wait for dma_fd on close
Browse files Browse the repository at this point in the history
  • Loading branch information
mdevaev committed Mar 10, 2024
1 parent 646afbf commit c4cf4f0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
19 changes: 16 additions & 3 deletions src/v4p/drm.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ us_drm_s *us_drm_init(void) {
US_CALLOC(run, 1);
run->fd = -1;
run->status_fd = -1;
run->has_vsync = true;
run->dpms_state = -1;
run->has_vsync = true;
run->exposing_dma_fd = -1;
run->ft = us_frametext_init();

us_drm_s *drm;
Expand Down Expand Up @@ -161,8 +162,9 @@ int us_drm_open(us_drm_s *drm, const us_device_s *dev) {
goto error;
}

run->unplugged_reported = false;
run->opened_for_stub = (stub > 0);
run->exposing_dma_fd = -1;
run->unplugged_reported = false;
_D_LOG_INFO("Opened for %s ...", (run->opened_for_stub ? "STUB" : "DMA"));
return stub;

Expand All @@ -182,6 +184,14 @@ int us_drm_open(us_drm_s *drm, const us_device_s *dev) {
void us_drm_close(us_drm_s *drm) {
us_drm_runtime_s *const run = drm->run;

if (run->exposing_dma_fd >= 0) {
// Нужно подождать, пока dma_fd не освободится, прежде чем прерывать процесс.
// Просто на всякий случай.
assert(run->fd >= 0);
us_drm_wait_for_vsync(drm);
run->exposing_dma_fd = -1;
}

if (run->saved_crtc != NULL) {
_D_LOG_DEBUG("Restoring CRTC ...");
if (drmModeSetCrtc(run->fd,
Expand Down Expand Up @@ -221,8 +231,8 @@ void us_drm_close(us_drm_s *drm) {
US_CLOSE_FD(run->fd);

run->crtc_id = 0;
run->has_vsync = true;
run->dpms_state = -1;
run->has_vsync = true;
run->stub_n_buf = 0;

if (say) {
Expand Down Expand Up @@ -291,6 +301,7 @@ static void _drm_vsync_callback(int fd, uint n_frame, uint sec, uint usec, void
(void)usec;
us_drm_buffer_s *const buf = v_buf;
*buf->ctx.has_vsync = true;
*buf->ctx.exposing_dma_fd = -1;
_D_LOG_DEBUG("Got VSync signal");
}

Expand Down Expand Up @@ -387,6 +398,7 @@ int us_drm_expose_dma(us_drm_s *drm, const us_hw_buffer_s *hw) {
_D_LOG_PERROR("Can't expose DMA framebuffer n_buf=%u ...", run->stub_n_buf);
}
_D_LOG_DEBUG("Exposed DMA framebuffer n_buf=%u", run->stub_n_buf);
run->exposing_dma_fd = hw->dma_fd;
return retval;
}

Expand Down Expand Up @@ -458,6 +470,7 @@ static int _drm_init_buffers(us_drm_s *drm, const us_device_s *dev) {
us_drm_buffer_s *const buf = &run->bufs[n_buf];

buf->ctx.has_vsync = &run->has_vsync;
buf->ctx.exposing_dma_fd = &run->exposing_dma_fd;

u32 handles[4] = {0};
u32 strides[4] = {0};
Expand Down
4 changes: 3 additions & 1 deletion src/v4p/drm.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ typedef struct {
bool dumb_created;
bool fb_added;
struct {
bool *has_vsync;
bool *has_vsync;
int *exposing_dma_fd;
} ctx;
} us_drm_buffer_s;

Expand All @@ -64,6 +65,7 @@ typedef struct {
int dpms_state;
bool opened_for_stub;
bool has_vsync;
int exposing_dma_fd;
uint stub_n_buf;
bool unplugged_reported;
us_frametext_s *ft;
Expand Down

0 comments on commit c4cf4f0

Please sign in to comment.