summaryrefslogtreecommitdiff
path: root/etnaviv
diff options
context:
space:
mode:
authorChristian Gmeiner <christian.gmeiner@gmail.com>2016-11-13 21:29:22 +0100
committerChristian Gmeiner <christian.gmeiner@gmail.com>2016-11-20 15:58:28 +0100
commitbefb6429f03072b128a55360c1cf57f7b4d47b67 (patch)
treebe4ec384bea15f490dd84731e769752dc2a6f7d1 /etnaviv
parenta14d6a6a43742cfad7ab346bf9168eb893881816 (diff)
etnaviv: add API to create etna_device from private dup() fd
Like etna_device_new() but creates it's own private dup() of the fd which is close()d when the device is finalized. Signed-off-by: Christian Gmeiner <christian.gmeiner@gmail.com> Acked-by: Eric Anholt <eric@anholt.net>
Diffstat (limited to 'etnaviv')
-rwxr-xr-xetnaviv/etnaviv-symbol-check1
-rw-r--r--etnaviv/etnaviv_device.c18
-rw-r--r--etnaviv/etnaviv_drmif.h1
-rw-r--r--etnaviv/etnaviv_priv.h2
4 files changed, 22 insertions, 0 deletions
diff --git a/etnaviv/etnaviv-symbol-check b/etnaviv/etnaviv-symbol-check
index 378e073e..72f2bc50 100755
--- a/etnaviv/etnaviv-symbol-check
+++ b/etnaviv/etnaviv-symbol-check
@@ -11,6 +11,7 @@ _end
_fini
_init
etna_device_new
+etna_device_new_dup
etna_device_ref
etna_device_del
etna_device_fd
diff --git a/etnaviv/etnaviv_device.c b/etnaviv/etnaviv_device.c
index b7163609..3ce92030 100644
--- a/etnaviv/etnaviv_device.c
+++ b/etnaviv/etnaviv_device.c
@@ -61,6 +61,21 @@ struct etna_device *etna_device_new(int fd)
return dev;
}
+/* like etna_device_new() but creates it's own private dup() of the fd
+ * which is close()d when the device is finalized. */
+struct etna_device *etna_device_new_dup(int fd)
+{
+ int dup_fd = dup(fd);
+ struct etna_device *dev = etna_device_new(dup_fd);
+
+ if (dev)
+ dev->closefd = 1;
+ else
+ close(dup_fd);
+
+ return dev;
+}
+
struct etna_device *etna_device_ref(struct etna_device *dev)
{
atomic_inc(&dev->refcnt);
@@ -74,6 +89,9 @@ static void etna_device_del_impl(struct etna_device *dev)
drmHashDestroy(dev->handle_table);
drmHashDestroy(dev->name_table);
+ if (dev->closefd)
+ close(dev->fd);
+
free(dev);
}
diff --git a/etnaviv/etnaviv_drmif.h b/etnaviv/etnaviv_drmif.h
index 3a5cb51b..fe9d5dbf 100644
--- a/etnaviv/etnaviv_drmif.h
+++ b/etnaviv/etnaviv_drmif.h
@@ -84,6 +84,7 @@ enum etna_param_id {
*/
struct etna_device *etna_device_new(int fd);
+struct etna_device *etna_device_new_dup(int fd);
struct etna_device *etna_device_ref(struct etna_device *dev);
void etna_device_del(struct etna_device *dev);
int etna_device_fd(struct etna_device *dev);
diff --git a/etnaviv/etnaviv_priv.h b/etnaviv/etnaviv_priv.h
index 6bb0c8dc..eb62ed33 100644
--- a/etnaviv/etnaviv_priv.h
+++ b/etnaviv/etnaviv_priv.h
@@ -93,6 +93,8 @@ struct etna_device {
void *handle_table, *name_table;
struct etna_bo_cache bo_cache;
+
+ int closefd; /* call close(fd) upon destruction */
};
drm_private void etna_bo_cache_init(struct etna_bo_cache *cache);