summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile3
-rw-r--r--drv.c6
-rw-r--r--msm.c92
3 files changed, 87 insertions, 14 deletions
diff --git a/Makefile b/Makefile
index a01433e..e9fb7e9 100644
--- a/Makefile
+++ b/Makefile
@@ -31,6 +31,9 @@ endif
ifdef DRV_ROCKCHIP
CFLAGS += $(shell $(PKG_CONFIG) --cflags libdrm_rockchip)
endif
+ifdef DRV_MSM
+ CFLAGS += $(shell $(PKG_CONFIG) --cflags libdrm_msm)
+endif
CPPFLAGS += $(PC_CFLAGS)
LDLIBS += $(PC_LIBS)
diff --git a/drv.c b/drv.c
index bf0b4c1..aa1e6d9 100644
--- a/drv.c
+++ b/drv.c
@@ -53,7 +53,9 @@ extern const struct backend backend_udl;
#ifdef DRV_VC4
extern const struct backend backend_vc4;
#endif
+#ifdef DRV_MSM
extern const struct backend backend_msm;
+#endif
extern const struct backend backend_vgem;
extern const struct backend backend_virtio_gpu;
@@ -68,7 +70,6 @@ static const struct backend *drv_get_backend(int fd)
return NULL;
const struct backend *backend_list[] = {
- &backend_msm,
#ifdef DRV_AMDGPU
&backend_amdgpu,
#endif
@@ -102,6 +103,9 @@ static const struct backend *drv_get_backend(int fd)
#ifdef DRV_VC4
&backend_vc4,
#endif
+#ifdef DRV_MSM
+ &backend_msm,
+#endif
&backend_vgem, &backend_virtio_gpu,
};
diff --git a/msm.c b/msm.c
index 4db24e0..e51ba04 100644
--- a/msm.c
+++ b/msm.c
@@ -3,30 +3,96 @@
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
+#ifdef DRV_MSM
+#include <errno.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
#include <sys/mman.h>
+#include <msm_drm.h>
#include <xf86drm.h>
#include "drv_priv.h"
#include "helpers.h"
#include "util.h"
-static const uint32_t render_target_formats[] = { DRM_FORMAT_ARGB8888, DRM_FORMAT_XRGB8888 };
+static const uint32_t render_target_formats[] = {DRM_FORMAT_ARGB8888,
+ DRM_FORMAT_XRGB8888};
-static int msm_init(struct driver *drv)
-{
- drv_add_combinations(drv, render_target_formats, ARRAY_SIZE(render_target_formats),
- &LINEAR_METADATA, BO_USE_RENDER_MASK);
+static int msm_init(struct driver* drv) {
+ drv_add_combinations(drv, render_target_formats,
+ ARRAY_SIZE(render_target_formats), &LINEAR_METADATA,
+ BO_USE_RENDER_MASK);
- return drv_modify_linear_combinations(drv);
+ return drv_modify_linear_combinations(drv);
+}
+
+/* msm_bo_create will create linear buffers for now */
+static int msm_bo_create(struct bo* bo, uint32_t width, uint32_t height,
+ uint32_t format, uint64_t use_flags) {
+ struct drm_msm_gem_new req;
+ uint32_t size, stride;
+ int ret = 1;
+ uint32_t alignw, alignh;
+
+ alignw = ALIGN(width, 32);
+ alignh = ALIGN(height, 32);
+
+ /* Get stride and size of BO */
+ stride = drv_stride_from_format(format, alignw, 0);
+ size = drv_size_from_format(format, stride, alignh, 0);
+
+ memset(&req, 0, sizeof(req));
+ req.flags = MSM_BO_WC | MSM_BO_SCANOUT;
+ req.size = size;
+
+ ret = drmIoctl(bo->drv->fd, DRM_IOCTL_MSM_GEM_NEW, &req);
+ if (ret) {
+ fprintf(stderr,
+ "drv: DRM_IOCTL_MSM_GEM_NEW failed (size = %u) (ret = %d)\n", size,
+ ret);
+ return ret;
+ }
+
+ bo->handles[0].u32 = req.handle;
+ bo->offsets[0] = 0;
+ bo->total_size = bo->sizes[0] = size;
+ bo->strides[0] = stride;
+
+ return 0;
+}
+
+static void* msm_bo_map(struct bo* bo, struct vma* vma, size_t plane,
+ uint32_t map_flags) {
+ int ret;
+ struct drm_msm_gem_info req;
+ void* addr;
+
+ memset(&req, 0, sizeof(req));
+ req.handle = bo->handles[0].u32;
+
+ ret = drmIoctl(bo->drv->fd, DRM_IOCTL_MSM_GEM_INFO, &req);
+ if (ret) {
+ fprintf(stderr, "drv: DRM_IOCLT_MSM_GEM_INFO failed ret = %d\n", ret);
+ return MAP_FAILED;
+ }
+
+ addr = mmap(0, bo->total_size, drv_get_prot(map_flags), MAP_SHARED,
+ bo->drv->fd, req.offset);
+
+ vma->length = bo->total_size;
+
+ return addr;
}
const struct backend backend_msm = {
- .name = "msm",
- .init = msm_init,
- .bo_create = drv_dumb_bo_create,
- .bo_destroy = drv_gem_bo_destroy,
- .bo_import = drv_prime_bo_import,
- .bo_map = drv_dumb_bo_map,
- .bo_unmap = drv_bo_munmap,
+ .name = "msm",
+ .init = msm_init,
+ .bo_create = msm_bo_create,
+ .bo_destroy = drv_gem_bo_destroy,
+ .bo_import = drv_prime_bo_import,
+ .bo_map = msm_bo_map,
+ .bo_unmap = drv_bo_munmap,
};
+#endif