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);