[Nouveau] [libdrm v2 02/14] nouveau: move more abi16-specific logic into abi16.c
Ben Skeggs
skeggsb at gmail.com
Thu Nov 26 17:02:41 PST 2015
From: Ben Skeggs <bskeggs at redhat.com>
v2.
- add a comment about the (ab)use of nouveau_object::length
- add a comment about abi16_object() return values
Signed-off-by: Ben Skeggs <bskeggs at redhat.com>
---
nouveau/abi16.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
nouveau/nouveau.c | 56 +++++++----------------------------------------
nouveau/private.h | 7 ++----
3 files changed, 70 insertions(+), 58 deletions(-)
diff --git a/nouveau/abi16.c b/nouveau/abi16.c
index 59bc436..615aea2 100644
--- a/nouveau/abi16.c
+++ b/nouveau/abi16.c
@@ -33,7 +33,7 @@
#include "private.h"
-drm_private int
+static int
abi16_chan_nv04(struct nouveau_object *obj)
{
struct nouveau_device *dev = (struct nouveau_device *)obj->parent;
@@ -57,7 +57,7 @@ abi16_chan_nv04(struct nouveau_object *obj)
return 0;
}
-drm_private int
+static int
abi16_chan_nvc0(struct nouveau_object *obj)
{
struct nouveau_device *dev = (struct nouveau_device *)obj->parent;
@@ -78,7 +78,7 @@ abi16_chan_nvc0(struct nouveau_object *obj)
return 0;
}
-drm_private int
+static int
abi16_chan_nve0(struct nouveau_object *obj)
{
struct nouveau_device *dev = (struct nouveau_device *)obj->parent;
@@ -104,7 +104,7 @@ abi16_chan_nve0(struct nouveau_object *obj)
return 0;
}
-drm_private int
+static int
abi16_engobj(struct nouveau_object *obj)
{
struct drm_nouveau_grobj_alloc req = {
@@ -125,7 +125,7 @@ abi16_engobj(struct nouveau_object *obj)
return 0;
}
-drm_private int
+static int
abi16_ntfy(struct nouveau_object *obj)
{
struct nv04_notify *ntfy = obj->data;
@@ -149,6 +149,61 @@ abi16_ntfy(struct nouveau_object *obj)
}
drm_private void
+abi16_delete(struct nouveau_object *obj)
+{
+ struct nouveau_device *dev =
+ nouveau_object_find(obj, NOUVEAU_DEVICE_CLASS);
+ if (obj->oclass == NOUVEAU_FIFO_CHANNEL_CLASS) {
+ struct drm_nouveau_channel_free req;
+ req.channel = obj->handle;
+ drmCommandWrite(dev->fd, DRM_NOUVEAU_CHANNEL_FREE,
+ &req, sizeof(req));
+ } else {
+ struct drm_nouveau_gpuobj_free req;
+ req.channel = obj->parent->handle;
+ req.handle = obj->handle;
+ drmCommandWrite(dev->fd, DRM_NOUVEAU_GPUOBJ_FREE,
+ &req, sizeof(req));
+ }
+}
+
+drm_private bool
+abi16_object(struct nouveau_object *obj, int (**func)(struct nouveau_object *))
+{
+ struct nouveau_object *parent = obj->parent;
+
+ /* nouveau_object::length is (ab)used to determine whether the
+ * object is a legacy object (!=0), or a real NVIF object.
+ */
+ if ((parent->length != 0 && parent->oclass == NOUVEAU_DEVICE_CLASS)) {
+ if (obj->oclass == NOUVEAU_FIFO_CHANNEL_CLASS) {
+ struct nouveau_device *dev = (void *)parent;
+ if (dev->chipset < 0xc0)
+ *func = abi16_chan_nv04;
+ else
+ if (dev->chipset < 0xe0)
+ *func = abi16_chan_nvc0;
+ else
+ *func = abi16_chan_nve0;
+ return true;
+ }
+ } else
+ if ((parent->length != 0 &&
+ parent->oclass == NOUVEAU_FIFO_CHANNEL_CLASS)) {
+ if (obj->oclass == NOUVEAU_NOTIFIER_CLASS) {
+ *func = abi16_ntfy;
+ return true;
+ }
+
+ *func = abi16_engobj;
+ return false; /* try NVIF, if supported, before calling func */
+ }
+
+ *func = NULL;
+ return false;
+}
+
+drm_private void
abi16_bo_info(struct nouveau_bo *bo, struct drm_nouveau_gem_info *info)
{
struct nouveau_bo_priv *nvbo = nouveau_bo(bo);
diff --git a/nouveau/nouveau.c b/nouveau/nouveau.c
index 97fd77b..8a0be2f 100644
--- a/nouveau/nouveau.c
+++ b/nouveau/nouveau.c
@@ -135,6 +135,7 @@ nouveau_device_wrap(int fd, int close, struct nouveau_device **pdev)
nvdev->gart_limit_percent = 80;
DRMINITLISTHEAD(&nvdev->bo_list);
nvdev->base.object.oclass = NOUVEAU_DEVICE_CLASS;
+ nvdev->base.object.length = ~0;
nvdev->base.lib_version = 0x01000000;
nvdev->base.chipset = chipset;
nvdev->base.vram_size = vram;
@@ -251,8 +252,8 @@ nouveau_object_new(struct nouveau_object *parent, uint64_t handle,
uint32_t oclass, void *data, uint32_t length,
struct nouveau_object **pobj)
{
- struct nouveau_device *dev;
struct nouveau_object *obj;
+ int (*func)(struct nouveau_object *);
int ret = -EINVAL;
if (length == 0)
@@ -267,37 +268,9 @@ nouveau_object_new(struct nouveau_object *parent, uint64_t handle,
memcpy(obj->data, data, length);
*(struct nouveau_object **)obj->data = obj;
- dev = nouveau_object_find(obj, NOUVEAU_DEVICE_CLASS);
- switch (parent->oclass) {
- case NOUVEAU_DEVICE_CLASS:
- switch (obj->oclass) {
- case NOUVEAU_FIFO_CHANNEL_CLASS:
- {
- if (dev->chipset < 0xc0)
- ret = abi16_chan_nv04(obj);
- else
- if (dev->chipset < 0xe0)
- ret = abi16_chan_nvc0(obj);
- else
- ret = abi16_chan_nve0(obj);
- }
- break;
- default:
- break;
- }
- break;
- case NOUVEAU_FIFO_CHANNEL_CLASS:
- switch (obj->oclass) {
- case NOUVEAU_NOTIFIER_CLASS:
- ret = abi16_ntfy(obj);
- break;
- default:
- ret = abi16_engobj(obj);
- break;
- }
- default:
- break;
- }
+ abi16_object(obj, &func);
+ if (func)
+ ret = func(obj);
if (ret) {
free(obj);
@@ -312,24 +285,11 @@ void
nouveau_object_del(struct nouveau_object **pobj)
{
struct nouveau_object *obj = *pobj;
- struct nouveau_device *dev;
if (obj) {
- dev = nouveau_object_find(obj, NOUVEAU_DEVICE_CLASS);
- if (obj->oclass == NOUVEAU_FIFO_CHANNEL_CLASS) {
- struct drm_nouveau_channel_free req;
- req.channel = obj->handle;
- drmCommandWrite(dev->fd, DRM_NOUVEAU_CHANNEL_FREE,
- &req, sizeof(req));
- } else {
- struct drm_nouveau_gpuobj_free req;
- req.channel = obj->parent->handle;
- req.handle = obj->handle;
- drmCommandWrite(dev->fd, DRM_NOUVEAU_GPUOBJ_FREE,
- &req, sizeof(req));
- }
+ abi16_delete(obj);
+ free(obj);
+ *pobj = NULL;
}
- free(obj);
- *pobj = NULL;
}
void *
diff --git a/nouveau/private.h b/nouveau/private.h
index e9439f3..5f352a4 100644
--- a/nouveau/private.h
+++ b/nouveau/private.h
@@ -114,11 +114,8 @@ int
nouveau_device_open_existing(struct nouveau_device **, int, int, drm_context_t);
/* abi16.c */
-drm_private int abi16_chan_nv04(struct nouveau_object *);
-drm_private int abi16_chan_nvc0(struct nouveau_object *);
-drm_private int abi16_chan_nve0(struct nouveau_object *);
-drm_private int abi16_engobj(struct nouveau_object *);
-drm_private int abi16_ntfy(struct nouveau_object *);
+drm_private bool abi16_object(struct nouveau_object *, int (**)(struct nouveau_object *));
+drm_private void abi16_delete(struct nouveau_object *);
drm_private void abi16_bo_info(struct nouveau_bo *, struct drm_nouveau_gem_info *);
drm_private int abi16_bo_init(struct nouveau_bo *, uint32_t alignment,
union nouveau_bo_config *);
--
2.6.3
More information about the Nouveau
mailing list