nouveau: make use of nouveau_drm::fd instead of nouveau_device::fd

The latter is deprecated, and will not be valid for newer clients.

v2.
- split out nouveau_object_find removal

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
Tested-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
main
Ben Skeggs 2015-11-24 11:00:53 +10:00
parent cdf9029f5f
commit 4283e3f656
3 changed files with 40 additions and 31 deletions

View File

@ -38,7 +38,7 @@
static int static int
abi16_chan_nv04(struct nouveau_object *obj) abi16_chan_nv04(struct nouveau_object *obj)
{ {
struct nouveau_device *dev = (struct nouveau_device *)obj->parent; struct nouveau_drm *drm = nouveau_drm(obj);
struct nv04_fifo *nv04 = obj->data; struct nv04_fifo *nv04 = obj->data;
struct drm_nouveau_channel_alloc req = { struct drm_nouveau_channel_alloc req = {
.fb_ctxdma_handle = nv04->vram, .fb_ctxdma_handle = nv04->vram,
@ -46,7 +46,7 @@ abi16_chan_nv04(struct nouveau_object *obj)
}; };
int ret; int ret;
ret = drmCommandWriteRead(dev->fd, DRM_NOUVEAU_CHANNEL_ALLOC, ret = drmCommandWriteRead(drm->fd, DRM_NOUVEAU_CHANNEL_ALLOC,
&req, sizeof(req)); &req, sizeof(req));
if (ret) if (ret)
return ret; return ret;
@ -62,12 +62,12 @@ abi16_chan_nv04(struct nouveau_object *obj)
static int static int
abi16_chan_nvc0(struct nouveau_object *obj) abi16_chan_nvc0(struct nouveau_object *obj)
{ {
struct nouveau_device *dev = (struct nouveau_device *)obj->parent; struct nouveau_drm *drm = nouveau_drm(obj);
struct drm_nouveau_channel_alloc req = {}; struct drm_nouveau_channel_alloc req = {};
struct nvc0_fifo *nvc0 = obj->data; struct nvc0_fifo *nvc0 = obj->data;
int ret; int ret;
ret = drmCommandWriteRead(dev->fd, DRM_NOUVEAU_CHANNEL_ALLOC, ret = drmCommandWriteRead(drm->fd, DRM_NOUVEAU_CHANNEL_ALLOC,
&req, sizeof(req)); &req, sizeof(req));
if (ret) if (ret)
return ret; return ret;
@ -83,7 +83,7 @@ abi16_chan_nvc0(struct nouveau_object *obj)
static int static int
abi16_chan_nve0(struct nouveau_object *obj) abi16_chan_nve0(struct nouveau_object *obj)
{ {
struct nouveau_device *dev = (struct nouveau_device *)obj->parent; struct nouveau_drm *drm = nouveau_drm(obj);
struct drm_nouveau_channel_alloc req = {}; struct drm_nouveau_channel_alloc req = {};
struct nve0_fifo *nve0 = obj->data; struct nve0_fifo *nve0 = obj->data;
int ret; int ret;
@ -93,7 +93,7 @@ abi16_chan_nve0(struct nouveau_object *obj)
req.tt_ctxdma_handle = nve0->engine; req.tt_ctxdma_handle = nve0->engine;
} }
ret = drmCommandWriteRead(dev->fd, DRM_NOUVEAU_CHANNEL_ALLOC, ret = drmCommandWriteRead(drm->fd, DRM_NOUVEAU_CHANNEL_ALLOC,
&req, sizeof(req)); &req, sizeof(req));
if (ret) if (ret)
return ret; return ret;
@ -109,12 +109,12 @@ abi16_chan_nve0(struct nouveau_object *obj)
static int static int
abi16_engobj(struct nouveau_object *obj) abi16_engobj(struct nouveau_object *obj)
{ {
struct nouveau_drm *drm = nouveau_drm(obj);
struct drm_nouveau_grobj_alloc req = { struct drm_nouveau_grobj_alloc req = {
.channel = obj->parent->handle, .channel = obj->parent->handle,
.handle = obj->handle, .handle = obj->handle,
.class = obj->oclass, .class = obj->oclass,
}; };
struct nouveau_device *dev;
int ret; int ret;
/* Older kernel versions did not have the concept of nouveau- /* Older kernel versions did not have the concept of nouveau-
@ -138,8 +138,7 @@ abi16_engobj(struct nouveau_object *obj)
break; break;
} }
dev = nouveau_object_find(obj, NOUVEAU_DEVICE_CLASS); ret = drmCommandWrite(drm->fd, DRM_NOUVEAU_GROBJ_ALLOC,
ret = drmCommandWrite(dev->fd, DRM_NOUVEAU_GROBJ_ALLOC,
&req, sizeof(req)); &req, sizeof(req));
if (ret) if (ret)
return ret; return ret;
@ -151,17 +150,16 @@ abi16_engobj(struct nouveau_object *obj)
static int static int
abi16_ntfy(struct nouveau_object *obj) abi16_ntfy(struct nouveau_object *obj)
{ {
struct nouveau_drm *drm = nouveau_drm(obj);
struct nv04_notify *ntfy = obj->data; struct nv04_notify *ntfy = obj->data;
struct drm_nouveau_notifierobj_alloc req = { struct drm_nouveau_notifierobj_alloc req = {
.channel = obj->parent->handle, .channel = obj->parent->handle,
.handle = ntfy->object->handle, .handle = ntfy->object->handle,
.size = ntfy->length, .size = ntfy->length,
}; };
struct nouveau_device *dev;
int ret; int ret;
dev = nouveau_object_find(obj, NOUVEAU_DEVICE_CLASS); ret = drmCommandWriteRead(drm->fd, DRM_NOUVEAU_NOTIFIEROBJ_ALLOC,
ret = drmCommandWriteRead(dev->fd, DRM_NOUVEAU_NOTIFIEROBJ_ALLOC,
&req, sizeof(req)); &req, sizeof(req));
if (ret) if (ret)
return ret; return ret;
@ -223,18 +221,17 @@ abi16_sclass(struct nouveau_object *obj, struct nouveau_sclass **psclass)
drm_private void drm_private void
abi16_delete(struct nouveau_object *obj) abi16_delete(struct nouveau_object *obj)
{ {
struct nouveau_device *dev = struct nouveau_drm *drm = nouveau_drm(obj);
nouveau_object_find(obj, NOUVEAU_DEVICE_CLASS);
if (obj->oclass == NOUVEAU_FIFO_CHANNEL_CLASS) { if (obj->oclass == NOUVEAU_FIFO_CHANNEL_CLASS) {
struct drm_nouveau_channel_free req; struct drm_nouveau_channel_free req;
req.channel = obj->handle; req.channel = obj->handle;
drmCommandWrite(dev->fd, DRM_NOUVEAU_CHANNEL_FREE, drmCommandWrite(drm->fd, DRM_NOUVEAU_CHANNEL_FREE,
&req, sizeof(req)); &req, sizeof(req));
} else { } else {
struct drm_nouveau_gpuobj_free req; struct drm_nouveau_gpuobj_free req;
req.channel = obj->parent->handle; req.channel = obj->parent->handle;
req.handle = obj->handle; req.handle = obj->handle;
drmCommandWrite(dev->fd, DRM_NOUVEAU_GPUOBJ_FREE, drmCommandWrite(drm->fd, DRM_NOUVEAU_GPUOBJ_FREE,
&req, sizeof(req)); &req, sizeof(req));
} }
} }
@ -314,6 +311,7 @@ abi16_bo_init(struct nouveau_bo *bo, uint32_t alignment,
union nouveau_bo_config *config) union nouveau_bo_config *config)
{ {
struct nouveau_device *dev = bo->device; struct nouveau_device *dev = bo->device;
struct nouveau_drm *drm = nouveau_drm(&dev->object);
struct drm_nouveau_gem_new req = {}; struct drm_nouveau_gem_new req = {};
struct drm_nouveau_gem_info *info = &req.info; struct drm_nouveau_gem_info *info = &req.info;
int ret; int ret;
@ -356,7 +354,7 @@ abi16_bo_init(struct nouveau_bo *bo, uint32_t alignment,
if (!nouveau_device(dev)->have_bo_usage) if (!nouveau_device(dev)->have_bo_usage)
info->tile_flags &= 0x0000ff00; info->tile_flags &= 0x0000ff00;
ret = drmCommandWriteRead(dev->fd, DRM_NOUVEAU_GEM_NEW, ret = drmCommandWriteRead(drm->fd, DRM_NOUVEAU_GEM_NEW,
&req, sizeof(req)); &req, sizeof(req));
if (ret == 0) if (ret == 0)
abi16_bo_info(bo, &req.info); abi16_bo_info(bo, &req.info);

View File

@ -345,8 +345,9 @@ nouveau_device_del(struct nouveau_device **pdev)
int int
nouveau_getparam(struct nouveau_device *dev, uint64_t param, uint64_t *value) nouveau_getparam(struct nouveau_device *dev, uint64_t param, uint64_t *value)
{ {
struct nouveau_drm *drm = nouveau_drm(&dev->object);
struct drm_nouveau_getparam r = { .param = param }; struct drm_nouveau_getparam r = { .param = param };
int fd = dev->fd, ret = int fd = drm->fd, ret =
drmCommandWriteRead(fd, DRM_NOUVEAU_GETPARAM, &r, sizeof(r)); drmCommandWriteRead(fd, DRM_NOUVEAU_GETPARAM, &r, sizeof(r));
*value = r.value; *value = r.value;
return ret; return ret;
@ -355,8 +356,9 @@ nouveau_getparam(struct nouveau_device *dev, uint64_t param, uint64_t *value)
int int
nouveau_setparam(struct nouveau_device *dev, uint64_t param, uint64_t value) nouveau_setparam(struct nouveau_device *dev, uint64_t param, uint64_t value)
{ {
struct nouveau_drm *drm = nouveau_drm(&dev->object);
struct drm_nouveau_setparam r = { .param = param, .value = value }; struct drm_nouveau_setparam r = { .param = param, .value = value };
return drmCommandWrite(dev->fd, DRM_NOUVEAU_SETPARAM, &r, sizeof(r)); return drmCommandWrite(drm->fd, DRM_NOUVEAU_SETPARAM, &r, sizeof(r));
} }
int int
@ -417,6 +419,7 @@ nouveau_client_del(struct nouveau_client **pclient)
static void static void
nouveau_bo_del(struct nouveau_bo *bo) nouveau_bo_del(struct nouveau_bo *bo)
{ {
struct nouveau_drm *drm = nouveau_drm(&bo->device->object);
struct nouveau_device_priv *nvdev = nouveau_device(bo->device); struct nouveau_device_priv *nvdev = nouveau_device(bo->device);
struct nouveau_bo_priv *nvbo = nouveau_bo(bo); struct nouveau_bo_priv *nvbo = nouveau_bo(bo);
struct drm_gem_close req = { .handle = bo->handle }; struct drm_gem_close req = { .handle = bo->handle };
@ -433,11 +436,11 @@ nouveau_bo_del(struct nouveau_bo *bo)
* might cause the bo to be closed accidentally while * might cause the bo to be closed accidentally while
* re-importing. * re-importing.
*/ */
drmIoctl(bo->device->fd, DRM_IOCTL_GEM_CLOSE, &req); drmIoctl(drm->fd, DRM_IOCTL_GEM_CLOSE, &req);
} }
pthread_mutex_unlock(&nvdev->lock); pthread_mutex_unlock(&nvdev->lock);
} else { } else {
drmIoctl(bo->device->fd, DRM_IOCTL_GEM_CLOSE, &req); drmIoctl(drm->fd, DRM_IOCTL_GEM_CLOSE, &req);
} }
if (bo->map) if (bo->map)
drm_munmap(bo->map, bo->size); drm_munmap(bo->map, bo->size);
@ -474,6 +477,7 @@ static int
nouveau_bo_wrap_locked(struct nouveau_device *dev, uint32_t handle, nouveau_bo_wrap_locked(struct nouveau_device *dev, uint32_t handle,
struct nouveau_bo **pbo, int name) struct nouveau_bo **pbo, int name)
{ {
struct nouveau_drm *drm = nouveau_drm(&dev->object);
struct nouveau_device_priv *nvdev = nouveau_device(dev); struct nouveau_device_priv *nvdev = nouveau_device(dev);
struct drm_nouveau_gem_info req = { .handle = handle }; struct drm_nouveau_gem_info req = { .handle = handle };
struct nouveau_bo_priv *nvbo; struct nouveau_bo_priv *nvbo;
@ -503,7 +507,7 @@ nouveau_bo_wrap_locked(struct nouveau_device *dev, uint32_t handle,
} }
} }
ret = drmCommandWriteRead(dev->fd, DRM_NOUVEAU_GEM_INFO, ret = drmCommandWriteRead(drm->fd, DRM_NOUVEAU_GEM_INFO,
&req, sizeof(req)); &req, sizeof(req));
if (ret) if (ret)
return ret; return ret;
@ -550,6 +554,7 @@ int
nouveau_bo_name_ref(struct nouveau_device *dev, uint32_t name, nouveau_bo_name_ref(struct nouveau_device *dev, uint32_t name,
struct nouveau_bo **pbo) struct nouveau_bo **pbo)
{ {
struct nouveau_drm *drm = nouveau_drm(&dev->object);
struct nouveau_device_priv *nvdev = nouveau_device(dev); struct nouveau_device_priv *nvdev = nouveau_device(dev);
struct nouveau_bo_priv *nvbo; struct nouveau_bo_priv *nvbo;
struct drm_gem_open req = { .name = name }; struct drm_gem_open req = { .name = name };
@ -565,7 +570,7 @@ nouveau_bo_name_ref(struct nouveau_device *dev, uint32_t name,
} }
} }
ret = drmIoctl(dev->fd, DRM_IOCTL_GEM_OPEN, &req); ret = drmIoctl(drm->fd, DRM_IOCTL_GEM_OPEN, &req);
if (ret == 0) { if (ret == 0) {
ret = nouveau_bo_wrap_locked(dev, req.handle, pbo, name); ret = nouveau_bo_wrap_locked(dev, req.handle, pbo, name);
} }
@ -578,11 +583,12 @@ int
nouveau_bo_name_get(struct nouveau_bo *bo, uint32_t *name) nouveau_bo_name_get(struct nouveau_bo *bo, uint32_t *name)
{ {
struct drm_gem_flink req = { .handle = bo->handle }; struct drm_gem_flink req = { .handle = bo->handle };
struct nouveau_drm *drm = nouveau_drm(&bo->device->object);
struct nouveau_bo_priv *nvbo = nouveau_bo(bo); struct nouveau_bo_priv *nvbo = nouveau_bo(bo);
*name = nvbo->name; *name = nvbo->name;
if (!*name) { if (!*name) {
int ret = drmIoctl(bo->device->fd, DRM_IOCTL_GEM_FLINK, &req); int ret = drmIoctl(drm->fd, DRM_IOCTL_GEM_FLINK, &req);
if (ret) { if (ret) {
*name = 0; *name = 0;
@ -613,6 +619,7 @@ int
nouveau_bo_prime_handle_ref(struct nouveau_device *dev, int prime_fd, nouveau_bo_prime_handle_ref(struct nouveau_device *dev, int prime_fd,
struct nouveau_bo **bo) struct nouveau_bo **bo)
{ {
struct nouveau_drm *drm = nouveau_drm(&dev->object);
struct nouveau_device_priv *nvdev = nouveau_device(dev); struct nouveau_device_priv *nvdev = nouveau_device(dev);
int ret; int ret;
unsigned int handle; unsigned int handle;
@ -620,7 +627,7 @@ nouveau_bo_prime_handle_ref(struct nouveau_device *dev, int prime_fd,
nouveau_bo_ref(NULL, bo); nouveau_bo_ref(NULL, bo);
pthread_mutex_lock(&nvdev->lock); pthread_mutex_lock(&nvdev->lock);
ret = drmPrimeFDToHandle(dev->fd, prime_fd, &handle); ret = drmPrimeFDToHandle(drm->fd, prime_fd, &handle);
if (ret == 0) { if (ret == 0) {
ret = nouveau_bo_wrap_locked(dev, handle, bo, 0); ret = nouveau_bo_wrap_locked(dev, handle, bo, 0);
} }
@ -631,10 +638,11 @@ nouveau_bo_prime_handle_ref(struct nouveau_device *dev, int prime_fd,
int int
nouveau_bo_set_prime(struct nouveau_bo *bo, int *prime_fd) nouveau_bo_set_prime(struct nouveau_bo *bo, int *prime_fd)
{ {
struct nouveau_drm *drm = nouveau_drm(&bo->device->object);
struct nouveau_bo_priv *nvbo = nouveau_bo(bo); struct nouveau_bo_priv *nvbo = nouveau_bo(bo);
int ret; int ret;
ret = drmPrimeHandleToFD(bo->device->fd, nvbo->base.handle, DRM_CLOEXEC, prime_fd); ret = drmPrimeHandleToFD(drm->fd, nvbo->base.handle, DRM_CLOEXEC, prime_fd);
if (ret) if (ret)
return ret; return ret;
@ -646,6 +654,7 @@ int
nouveau_bo_wait(struct nouveau_bo *bo, uint32_t access, nouveau_bo_wait(struct nouveau_bo *bo, uint32_t access,
struct nouveau_client *client) struct nouveau_client *client)
{ {
struct nouveau_drm *drm = nouveau_drm(&bo->device->object);
struct nouveau_bo_priv *nvbo = nouveau_bo(bo); struct nouveau_bo_priv *nvbo = nouveau_bo(bo);
struct drm_nouveau_gem_cpu_prep req; struct drm_nouveau_gem_cpu_prep req;
struct nouveau_pushbuf *push; struct nouveau_pushbuf *push;
@ -669,7 +678,7 @@ nouveau_bo_wait(struct nouveau_bo *bo, uint32_t access,
if (access & NOUVEAU_BO_NOBLOCK) if (access & NOUVEAU_BO_NOBLOCK)
req.flags |= NOUVEAU_GEM_CPU_PREP_NOWAIT; req.flags |= NOUVEAU_GEM_CPU_PREP_NOWAIT;
ret = drmCommandWrite(bo->device->fd, DRM_NOUVEAU_GEM_CPU_PREP, ret = drmCommandWrite(drm->fd, DRM_NOUVEAU_GEM_CPU_PREP,
&req, sizeof(req)); &req, sizeof(req));
if (ret == 0) if (ret == 0)
nvbo->access = 0; nvbo->access = 0;
@ -680,10 +689,11 @@ int
nouveau_bo_map(struct nouveau_bo *bo, uint32_t access, nouveau_bo_map(struct nouveau_bo *bo, uint32_t access,
struct nouveau_client *client) struct nouveau_client *client)
{ {
struct nouveau_drm *drm = nouveau_drm(&bo->device->object);
struct nouveau_bo_priv *nvbo = nouveau_bo(bo); struct nouveau_bo_priv *nvbo = nouveau_bo(bo);
if (bo->map == NULL) { if (bo->map == NULL) {
bo->map = drm_mmap(0, bo->size, PROT_READ | PROT_WRITE, bo->map = drm_mmap(0, bo->size, PROT_READ | PROT_WRITE,
MAP_SHARED, bo->device->fd, nvbo->map_handle); MAP_SHARED, drm->fd, nvbo->map_handle);
if (bo->map == MAP_FAILED) { if (bo->map == MAP_FAILED) {
bo->map = NULL; bo->map = NULL;
return -errno; return -errno;

View File

@ -312,6 +312,7 @@ pushbuf_submit(struct nouveau_pushbuf *push, struct nouveau_object *chan)
struct nouveau_pushbuf_priv *nvpb = nouveau_pushbuf(push); struct nouveau_pushbuf_priv *nvpb = nouveau_pushbuf(push);
struct nouveau_pushbuf_krec *krec = nvpb->list; struct nouveau_pushbuf_krec *krec = nvpb->list;
struct nouveau_device *dev = push->client->device; struct nouveau_device *dev = push->client->device;
struct nouveau_drm *drm = nouveau_drm(&dev->object);
struct drm_nouveau_gem_pushbuf_bo_presumed *info; struct drm_nouveau_gem_pushbuf_bo_presumed *info;
struct drm_nouveau_gem_pushbuf_bo *kref; struct drm_nouveau_gem_pushbuf_bo *kref;
struct drm_nouveau_gem_pushbuf req; struct drm_nouveau_gem_pushbuf req;
@ -345,7 +346,7 @@ pushbuf_submit(struct nouveau_pushbuf *push, struct nouveau_object *chan)
pushbuf_dump(krec, krec_id++, fifo->channel); pushbuf_dump(krec, krec_id++, fifo->channel);
#ifndef SIMULATE #ifndef SIMULATE
ret = drmCommandWriteRead(dev->fd, DRM_NOUVEAU_GEM_PUSHBUF, ret = drmCommandWriteRead(drm->fd, DRM_NOUVEAU_GEM_PUSHBUF,
&req, sizeof(req)); &req, sizeof(req));
nvpb->suffix0 = req.suffix0; nvpb->suffix0 = req.suffix0;
nvpb->suffix1 = req.suffix1; nvpb->suffix1 = req.suffix1;
@ -536,7 +537,7 @@ nouveau_pushbuf_new(struct nouveau_client *client, struct nouveau_object *chan,
int nr, uint32_t size, bool immediate, int nr, uint32_t size, bool immediate,
struct nouveau_pushbuf **ppush) struct nouveau_pushbuf **ppush)
{ {
struct nouveau_device *dev = client->device; struct nouveau_drm *drm = nouveau_drm(&client->device->object);
struct nouveau_fifo *fifo = chan->data; struct nouveau_fifo *fifo = chan->data;
struct nouveau_pushbuf_priv *nvpb; struct nouveau_pushbuf_priv *nvpb;
struct nouveau_pushbuf *push; struct nouveau_pushbuf *push;
@ -551,7 +552,7 @@ nouveau_pushbuf_new(struct nouveau_client *client, struct nouveau_object *chan,
*/ */
req.channel = fifo->channel; req.channel = fifo->channel;
req.nr_push = 0; req.nr_push = 0;
ret = drmCommandWriteRead(dev->fd, DRM_NOUVEAU_GEM_PUSHBUF, ret = drmCommandWriteRead(drm->fd, DRM_NOUVEAU_GEM_PUSHBUF,
&req, sizeof(req)); &req, sizeof(req));
if (ret) if (ret)
return ret; return ret;