Skip to content

Commit

Permalink
buffer: Require environment variable to enable CMA
Browse files Browse the repository at this point in the history
To enable CMA on a Raspberry Pi, wayvnc must be run with the environment
variable WAYVNC_CMA=/dev/dma_heap/linux,cma

Using CMA at the hardcoded path where it's available is not always
the right thing to do.
  • Loading branch information
any1 committed Dec 2, 2024
1 parent 0c56fa3 commit 19ef01b
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
#ifdef HAVE_LINUX_DMA_HEAP
#include <linux/dma-buf.h>
#include <linux/dma-heap.h>

#define LINUX_CMA_PATH "/dev/dma_heap/linux,cma"
#endif // HAVE_LINUX_DMA_HEAP
#endif // ENABLE_SCREENCOPY_DMABUF

Expand Down Expand Up @@ -181,14 +179,18 @@ struct wv_buffer* wv_buffer_create_shm(const struct wv_buffer_config* config)

#ifdef ENABLE_SCREENCOPY_DMABUF
#ifdef HAVE_LINUX_DMA_HEAP
static bool have_linux_cma(void)
static const char *get_cma_path(void)
{
return access(LINUX_CMA_PATH, R_OK | W_OK) == 0;
static const char *path;
if (path)
return path;
path = getenv("WAYVNC_CMA");
return path;
}

static int linux_cma_alloc(size_t size)
{
int fd = open(LINUX_CMA_PATH, O_RDWR | O_CLOEXEC, 0);
int fd = open(get_cma_path(), O_RDWR | O_CLOEXEC, 0);
if (fd < 0) {
nvnc_log(NVNC_LOG_ERROR, "Failed to open CMA device: %m");
return -1;
Expand Down Expand Up @@ -299,18 +301,17 @@ static struct wv_buffer* wv_buffer_create_dmabuf(
}

#ifdef HAVE_LINUX_DMA_HEAP
self->bo = have_linux_cma() ?
create_cma_gbm_bo(config->width, config->height,
config->format, gbm) :
gbm_bo_create_with_modifiers2(gbm->dev, config->width,
config->height, config->format,
if (get_cma_path()) {
self->bo = create_cma_gbm_bo(config->width, config->height,
config->format, gbm);
} else
#endif
{
self->bo = gbm_bo_create_with_modifiers2(gbm->dev,
config->width, config->height, config->format,
config->modifiers, config->n_modifiers,
GBM_BO_USE_RENDERING);
#else
self->bo = gbm_bo_create_with_modifiers2(gbm->dev, config->width,
config->height, config->format, config->modifiers,
config->n_modifiers, GBM_BO_USE_RENDERING);
#endif
}

if (!self->bo)
goto bo_failure;
Expand Down

0 comments on commit 19ef01b

Please sign in to comment.