etnaviv: drm: don't cache mmap offset
authorLucas Stach <l.stach@pengutronix.de>
Thu, 6 Jan 2022 20:38:43 +0000 (21:38 +0100)
committerMarge Bot <emma+marge@anholt.net>
Sun, 3 Jul 2022 17:41:55 +0000 (17:41 +0000)
The mmap offset is the only information we currently get from
DRM_ETNAVIV_GEM_INFO and there is no point in storing this
offset after the mapping has been established. Reduce the
shared mutable state on the etna_bo by inlining fetching the
offset into etna_bo_map.

Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14466>

src/etnaviv/drm/etnaviv_bo.c
src/etnaviv/drm/etnaviv_priv.h

index fc91990..b0a3dfa 100644 (file)
@@ -220,26 +220,6 @@ struct etna_bo *etna_bo_ref(struct etna_bo *bo)
        return bo;
 }
 
-/* get buffer info */
-static int get_buffer_info(struct etna_bo *bo)
-{
-       int ret;
-       struct drm_etnaviv_gem_info req = {
-               .handle = bo->handle,
-       };
-
-       ret = drmCommandWriteRead(bo->dev->fd, DRM_ETNAVIV_GEM_INFO,
-                       &req, sizeof(req));
-       if (ret) {
-               return ret;
-       }
-
-       /* really all we need for now is mmap offset */
-       bo->offset = req.offset;
-
-       return 0;
-}
-
 /* import a buffer object from DRI2 name */
 struct etna_bo *etna_bo_from_name(struct etna_device *dev,
                uint32_t name)
@@ -407,12 +387,18 @@ uint32_t etna_bo_gpu_va(struct etna_bo *bo)
 void *etna_bo_map(struct etna_bo *bo)
 {
        if (!bo->map) {
-               if (!bo->offset) {
-                       get_buffer_info(bo);
-               }
+               int ret;
+               struct drm_etnaviv_gem_info req = {
+                       .handle = bo->handle,
+               };
+
+               ret = drmCommandWriteRead(bo->dev->fd, DRM_ETNAVIV_GEM_INFO,
+                                       &req, sizeof(req));
+               if (ret)
+                       return NULL;
 
                bo->map = os_mmap(0, bo->size, PROT_READ | PROT_WRITE,
-                                 MAP_SHARED, bo->dev->fd, bo->offset);
+                                 MAP_SHARED, bo->dev->fd, req.offset);
                if (bo->map == MAP_FAILED) {
                        ERROR_MSG("mmap failed: %s", strerror(errno));
                        bo->map = NULL;
index 3cd380f..d9233a1 100644 (file)
@@ -109,7 +109,6 @@ struct etna_bo {
        uint32_t        handle;
        uint32_t        flags;
        uint32_t        name;           /* flink global handle (DRI2 name) */
-       uint64_t        offset;         /* offset to mmap() */
        uint32_t        va;             /* GPU virtual address */
        int             refcnt;