diff options
author | François-Denis Gonthier <francois-denis.gonthier@opersys.com> | 2020-05-22 18:02:24 -0400 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-12-11 18:12:07 +0000 |
commit | cea0b84e41601c80c757e114eea704fe52e36869 (patch) | |
tree | 073f18c453cceb402f12e2bd36a298dc2b022528 /cros_gralloc | |
parent | 07f6209f745a496ab16c0d1e98516933241d1526 (diff) | |
download | minigbm-cea0b84e41601c80c757e114eea704fe52e36869.tar.gz |
Add vkms support
The vkms driver is used to get the Android to work on the BeagleBone
Black. Only a minimum amount of support is needed but the driver can
only be recognized by looking at card DRM nodes. The vkms driver does
not publish a render node.
We refactored the cros_gralloc_driver::init to test both the render
nodes and the card nodes.
Change-Id: Ie750aa45fc359ba7917919904693b1ab8088ad16
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/2213742
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Commit-Queue: Gurchetan Singh <gurchetansingh@chromium.org>
Diffstat (limited to 'cros_gralloc')
-rw-r--r-- | cros_gralloc/cros_gralloc_driver.cc | 95 |
1 files changed, 54 insertions, 41 deletions
diff --git a/cros_gralloc/cros_gralloc_driver.cc b/cros_gralloc/cros_gralloc_driver.cc index 259eae2..d9e6cf5 100644 --- a/cros_gralloc/cros_gralloc_driver.cc +++ b/cros_gralloc/cros_gralloc_driver.cc @@ -16,6 +16,16 @@ #include "../helpers.h" #include "../util.h" +// Constants taken from pipe_loader_drm.c in Mesa + +#define DRM_NUM_NODES 63 + +// DRM Render nodes start at 128 +#define DRM_RENDER_NODE_START 128 + +// DRM Card nodes start at 0 +#define DRM_CARD_NODE_START 0 + int memfd_create_wrapper(const char *name, unsigned int flags) { int fd; @@ -52,54 +62,57 @@ cros_gralloc_driver::~cros_gralloc_driver() } } +static struct driver *init_try_node(int idx, char const *str) +{ + int fd; + char *node; + struct driver *drv; + + if (asprintf(&node, str, DRM_DIR_NAME, idx) < 0) + return NULL; + + fd = open(node, O_RDWR, 0); + free(node); + + if (fd < 0) + return NULL; + + drv = drv_create(fd); + if (!drv) + close(fd); + + return drv; +} + int32_t cros_gralloc_driver::init() { /* - * Create a driver from rendernode while filtering out - * the specified undesired driver. + * Create a driver from render nodes first, then try card + * nodes. * * TODO(gsingh): Enable render nodes on udl/evdi. */ - int fd; - drmVersionPtr version; - char const *str = "%s/renderD%d"; - const char *undesired[2] = { "vgem", nullptr }; - uint32_t num_nodes = 63; - uint32_t min_node = 128; - uint32_t max_node = (min_node + num_nodes); - - for (uint32_t i = 0; i < ARRAY_SIZE(undesired); i++) { - for (uint32_t j = min_node; j < max_node; j++) { - char *node; - if (asprintf(&node, str, DRM_DIR_NAME, j) < 0) - continue; - - fd = open(node, O_RDWR | O_CLOEXEC); - free(node); - - if (fd < 0) - continue; - - version = drmGetVersion(fd); - if (!version) { - close(fd); - continue; - } - - if (undesired[i] && !strcmp(version->name, undesired[i])) { - close(fd); - drmFreeVersion(version); - continue; - } - - drmFreeVersion(version); - drv_ = drv_create(fd); - if (drv_) - return 0; - - close(fd); - } + char const *render_nodes_fmt = "%s/renderD%d"; + char const *card_nodes_fmt = "%s/card%d"; + uint32_t num_nodes = DRM_NUM_NODES; + uint32_t min_render_node = DRM_RENDER_NODE_START; + uint32_t max_render_node = (min_render_node + num_nodes); + uint32_t min_card_node = DRM_CARD_NODE_START; + uint32_t max_card_node = (min_card_node + num_nodes); + + // Try render nodes... + for (uint32_t i = min_render_node; i < max_render_node; i++) { + drv_ = init_try_node(i, render_nodes_fmt); + if (drv_) + return 0; + } + + // Try card nodes... for vkms mostly. + for (uint32_t i = min_card_node; i < max_card_node; i++) { + drv_ = init_try_node(i, card_nodes_fmt); + if (drv_) + return 0; } return -ENODEV; |