diff options
author | Ben Skeggs <bskeggs@redhat.com> | 2013-12-22 10:08:00 -0500 |
---|---|---|
committer | Ben Skeggs <bskeggs@redhat.com> | 2014-01-22 22:39:10 -0500 |
commit | ab606194d1f5821b0052823fc6b6330a029b3d95 (patch) | |
tree | a695e5aa88f04c7c452f8d81baf89ca0923c1fac | |
parent | 24a4ae86de89b5cbbf8530c371007383de9f2d58 (diff) |
drm/nouveau/instmem: tidy up the object class definition
Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
7 files changed, 127 insertions, 114 deletions
diff --git a/drivers/gpu/drm/nouveau/core/include/subdev/instmem.h b/drivers/gpu/drm/nouveau/core/include/subdev/instmem.h index 7c20478064e3..c1df26f3230c 100644 --- a/drivers/gpu/drm/nouveau/core/include/subdev/instmem.h +++ b/drivers/gpu/drm/nouveau/core/include/subdev/instmem.h | |||
@@ -23,21 +23,6 @@ nv_memobj(void *obj) | |||
23 | return obj; | 23 | return obj; |
24 | } | 24 | } |
25 | 25 | ||
26 | #define nouveau_instobj_create(p,e,o,d) \ | ||
27 | nouveau_instobj_create_((p), (e), (o), sizeof(**d), (void **)d) | ||
28 | #define nouveau_instobj_init(p) \ | ||
29 | nouveau_object_init(&(p)->base) | ||
30 | #define nouveau_instobj_fini(p,s) \ | ||
31 | nouveau_object_fini(&(p)->base, (s)) | ||
32 | |||
33 | int nouveau_instobj_create_(struct nouveau_object *, struct nouveau_object *, | ||
34 | struct nouveau_oclass *, int, void **); | ||
35 | void nouveau_instobj_destroy(struct nouveau_instobj *); | ||
36 | |||
37 | void _nouveau_instobj_dtor(struct nouveau_object *); | ||
38 | #define _nouveau_instobj_init nouveau_object_init | ||
39 | #define _nouveau_instobj_fini nouveau_object_fini | ||
40 | |||
41 | struct nouveau_instmem { | 26 | struct nouveau_instmem { |
42 | struct nouveau_subdev base; | 27 | struct nouveau_subdev base; |
43 | struct list_head list; | 28 | struct list_head list; |
diff --git a/drivers/gpu/drm/nouveau/core/subdev/instmem/base.c b/drivers/gpu/drm/nouveau/core/subdev/instmem/base.c index 5f5abf564ade..14706d9842ca 100644 --- a/drivers/gpu/drm/nouveau/core/subdev/instmem/base.c +++ b/drivers/gpu/drm/nouveau/core/subdev/instmem/base.c | |||
@@ -24,6 +24,23 @@ | |||
24 | 24 | ||
25 | #include "priv.h" | 25 | #include "priv.h" |
26 | 26 | ||
27 | /****************************************************************************** | ||
28 | * instmem object base implementation | ||
29 | *****************************************************************************/ | ||
30 | |||
31 | void | ||
32 | _nouveau_instobj_dtor(struct nouveau_object *object) | ||
33 | { | ||
34 | struct nouveau_instmem *imem = (void *)object->engine; | ||
35 | struct nouveau_instobj *iobj = (void *)object; | ||
36 | |||
37 | mutex_lock(&nv_subdev(imem)->mutex); | ||
38 | list_del(&iobj->head); | ||
39 | mutex_unlock(&nv_subdev(imem)->mutex); | ||
40 | |||
41 | return nouveau_object_destroy(&iobj->base); | ||
42 | } | ||
43 | |||
27 | int | 44 | int |
28 | nouveau_instobj_create_(struct nouveau_object *parent, | 45 | nouveau_instobj_create_(struct nouveau_object *parent, |
29 | struct nouveau_object *engine, | 46 | struct nouveau_object *engine, |
@@ -46,25 +63,6 @@ nouveau_instobj_create_(struct nouveau_object *parent, | |||
46 | return 0; | 63 | return 0; |
47 | } | 64 | } |
48 | 65 | ||
49 | void | ||
50 | nouveau_instobj_destroy(struct nouveau_instobj *iobj) | ||
51 | { | ||
52 | struct nouveau_subdev *subdev = nv_subdev(iobj->base.engine); | ||
53 | |||
54 | mutex_lock(&subdev->mutex); | ||
55 | list_del(&iobj->head); | ||
56 | mutex_unlock(&subdev->mutex); | ||
57 | |||
58 | return nouveau_object_destroy(&iobj->base); | ||
59 | } | ||
60 | |||
61 | void | ||
62 | _nouveau_instobj_dtor(struct nouveau_object *object) | ||
63 | { | ||
64 | struct nouveau_instobj *iobj = (void *)object; | ||
65 | return nouveau_instobj_destroy(iobj); | ||
66 | } | ||
67 | |||
68 | /****************************************************************************** | 66 | /****************************************************************************** |
69 | * instmem subdev base implementation | 67 | * instmem subdev base implementation |
70 | *****************************************************************************/ | 68 | *****************************************************************************/ |
@@ -76,14 +74,9 @@ nouveau_instmem_alloc(struct nouveau_instmem *imem, | |||
76 | { | 74 | { |
77 | struct nouveau_object *engine = nv_object(imem); | 75 | struct nouveau_object *engine = nv_object(imem); |
78 | struct nouveau_instmem_impl *impl = (void *)engine->oclass; | 76 | struct nouveau_instmem_impl *impl = (void *)engine->oclass; |
79 | int ret; | 77 | struct nouveau_instobj_args args = { .size = size, .align = align }; |
80 | 78 | return nouveau_object_ctor(parent, engine, impl->instobj, &args, | |
81 | ret = nouveau_object_ctor(parent, engine, impl->instobj, | 79 | sizeof(args), pobject); |
82 | (void *)(unsigned long)align, size, pobject); | ||
83 | if (ret) | ||
84 | return ret; | ||
85 | |||
86 | return 0; | ||
87 | } | 80 | } |
88 | 81 | ||
89 | int | 82 | int |
diff --git a/drivers/gpu/drm/nouveau/core/subdev/instmem/nv04.c b/drivers/gpu/drm/nouveau/core/subdev/instmem/nv04.c index 226809d2f297..7b64befee48f 100644 --- a/drivers/gpu/drm/nouveau/core/subdev/instmem/nv04.c +++ b/drivers/gpu/drm/nouveau/core/subdev/instmem/nv04.c | |||
@@ -24,6 +24,33 @@ | |||
24 | 24 | ||
25 | #include "nv04.h" | 25 | #include "nv04.h" |
26 | 26 | ||
27 | /****************************************************************************** | ||
28 | * instmem object implementation | ||
29 | *****************************************************************************/ | ||
30 | |||
31 | static u32 | ||
32 | nv04_instobj_rd32(struct nouveau_object *object, u64 addr) | ||
33 | { | ||
34 | struct nv04_instobj_priv *node = (void *)object; | ||
35 | return nv_ro32(object->engine, node->mem->offset + addr); | ||
36 | } | ||
37 | |||
38 | static void | ||
39 | nv04_instobj_wr32(struct nouveau_object *object, u64 addr, u32 data) | ||
40 | { | ||
41 | struct nv04_instobj_priv *node = (void *)object; | ||
42 | nv_wo32(object->engine, node->mem->offset + addr, data); | ||
43 | } | ||
44 | |||
45 | static void | ||
46 | nv04_instobj_dtor(struct nouveau_object *object) | ||
47 | { | ||
48 | struct nv04_instmem_priv *priv = (void *)object->engine; | ||
49 | struct nv04_instobj_priv *node = (void *)object; | ||
50 | nouveau_mm_free(&priv->heap, &node->mem); | ||
51 | nouveau_instobj_destroy(&node->base); | ||
52 | } | ||
53 | |||
27 | static int | 54 | static int |
28 | nv04_instobj_ctor(struct nouveau_object *parent, struct nouveau_object *engine, | 55 | nv04_instobj_ctor(struct nouveau_object *parent, struct nouveau_object *engine, |
29 | struct nouveau_oclass *oclass, void *data, u32 size, | 56 | struct nouveau_oclass *oclass, void *data, u32 size, |
@@ -31,18 +58,19 @@ nv04_instobj_ctor(struct nouveau_object *parent, struct nouveau_object *engine, | |||
31 | { | 58 | { |
32 | struct nv04_instmem_priv *priv = (void *)engine; | 59 | struct nv04_instmem_priv *priv = (void *)engine; |
33 | struct nv04_instobj_priv *node; | 60 | struct nv04_instobj_priv *node; |
34 | int ret, align; | 61 | struct nouveau_instobj_args *args = data; |
62 | int ret; | ||
35 | 63 | ||
36 | align = (unsigned long)data; | 64 | if (!args->align) |
37 | if (!align) | 65 | args->align = 1; |
38 | align = 1; | ||
39 | 66 | ||
40 | ret = nouveau_instobj_create(parent, engine, oclass, &node); | 67 | ret = nouveau_instobj_create(parent, engine, oclass, &node); |
41 | *pobject = nv_object(node); | 68 | *pobject = nv_object(node); |
42 | if (ret) | 69 | if (ret) |
43 | return ret; | 70 | return ret; |
44 | 71 | ||
45 | ret = nouveau_mm_head(&priv->heap, 1, size, size, align, &node->mem); | 72 | ret = nouveau_mm_head(&priv->heap, 1, args->size, args->size, |
73 | args->align, &node->mem); | ||
46 | if (ret) | 74 | if (ret) |
47 | return ret; | 75 | return ret; |
48 | 76 | ||
@@ -51,32 +79,9 @@ nv04_instobj_ctor(struct nouveau_object *parent, struct nouveau_object *engine, | |||
51 | return 0; | 79 | return 0; |
52 | } | 80 | } |
53 | 81 | ||
54 | static void | 82 | struct nouveau_instobj_impl |
55 | nv04_instobj_dtor(struct nouveau_object *object) | ||
56 | { | ||
57 | struct nv04_instmem_priv *priv = (void *)object->engine; | ||
58 | struct nv04_instobj_priv *node = (void *)object; | ||
59 | nouveau_mm_free(&priv->heap, &node->mem); | ||
60 | nouveau_instobj_destroy(&node->base); | ||
61 | } | ||
62 | |||
63 | static u32 | ||
64 | nv04_instobj_rd32(struct nouveau_object *object, u64 addr) | ||
65 | { | ||
66 | struct nv04_instobj_priv *node = (void *)object; | ||
67 | return nv_ro32(object->engine, node->mem->offset + addr); | ||
68 | } | ||
69 | |||
70 | static void | ||
71 | nv04_instobj_wr32(struct nouveau_object *object, u64 addr, u32 data) | ||
72 | { | ||
73 | struct nv04_instobj_priv *node = (void *)object; | ||
74 | nv_wo32(object->engine, node->mem->offset + addr, data); | ||
75 | } | ||
76 | |||
77 | struct nouveau_oclass | ||
78 | nv04_instobj_oclass = { | 83 | nv04_instobj_oclass = { |
79 | .ofuncs = &(struct nouveau_ofuncs) { | 84 | .base.ofuncs = &(struct nouveau_ofuncs) { |
80 | .ctor = nv04_instobj_ctor, | 85 | .ctor = nv04_instobj_ctor, |
81 | .dtor = nv04_instobj_dtor, | 86 | .dtor = nv04_instobj_dtor, |
82 | .init = _nouveau_instobj_init, | 87 | .init = _nouveau_instobj_init, |
@@ -173,5 +178,5 @@ nv04_instmem_oclass = &(struct nouveau_instmem_impl) { | |||
173 | .rd32 = nv04_instmem_rd32, | 178 | .rd32 = nv04_instmem_rd32, |
174 | .wr32 = nv04_instmem_wr32, | 179 | .wr32 = nv04_instmem_wr32, |
175 | }, | 180 | }, |
176 | .instobj = &nv04_instobj_oclass, | 181 | .instobj = &nv04_instobj_oclass.base, |
177 | }.base; | 182 | }.base; |
diff --git a/drivers/gpu/drm/nouveau/core/subdev/instmem/nv04.h b/drivers/gpu/drm/nouveau/core/subdev/instmem/nv04.h index fd866c4d441a..095fbc6fc099 100644 --- a/drivers/gpu/drm/nouveau/core/subdev/instmem/nv04.h +++ b/drivers/gpu/drm/nouveau/core/subdev/instmem/nv04.h | |||
@@ -7,7 +7,7 @@ | |||
7 | 7 | ||
8 | #include "priv.h" | 8 | #include "priv.h" |
9 | 9 | ||
10 | extern struct nouveau_oclass nv04_instobj_oclass; | 10 | extern struct nouveau_instobj_impl nv04_instobj_oclass; |
11 | 11 | ||
12 | struct nv04_instmem_priv { | 12 | struct nv04_instmem_priv { |
13 | struct nouveau_instmem base; | 13 | struct nouveau_instmem base; |
diff --git a/drivers/gpu/drm/nouveau/core/subdev/instmem/nv40.c b/drivers/gpu/drm/nouveau/core/subdev/instmem/nv40.c index 02ea5e060c49..ec0b9661d614 100644 --- a/drivers/gpu/drm/nouveau/core/subdev/instmem/nv40.c +++ b/drivers/gpu/drm/nouveau/core/subdev/instmem/nv40.c | |||
@@ -134,5 +134,5 @@ nv40_instmem_oclass = &(struct nouveau_instmem_impl) { | |||
134 | .rd32 = nv40_instmem_rd32, | 134 | .rd32 = nv40_instmem_rd32, |
135 | .wr32 = nv40_instmem_wr32, | 135 | .wr32 = nv40_instmem_wr32, |
136 | }, | 136 | }, |
137 | .instobj = &nv04_instobj_oclass, | 137 | .instobj = &nv04_instobj_oclass.base, |
138 | }.base; | 138 | }.base; |
diff --git a/drivers/gpu/drm/nouveau/core/subdev/instmem/nv50.c b/drivers/gpu/drm/nouveau/core/subdev/instmem/nv50.c index 57b7589b16fc..7cb3b098a08d 100644 --- a/drivers/gpu/drm/nouveau/core/subdev/instmem/nv50.c +++ b/drivers/gpu/drm/nouveau/core/subdev/instmem/nv50.c | |||
@@ -38,42 +38,9 @@ struct nv50_instobj_priv { | |||
38 | struct nouveau_mem *mem; | 38 | struct nouveau_mem *mem; |
39 | }; | 39 | }; |
40 | 40 | ||
41 | static int | 41 | /****************************************************************************** |
42 | nv50_instobj_ctor(struct nouveau_object *parent, struct nouveau_object *engine, | 42 | * instmem object implementation |
43 | struct nouveau_oclass *oclass, void *data, u32 size, | 43 | *****************************************************************************/ |
44 | struct nouveau_object **pobject) | ||
45 | { | ||
46 | struct nouveau_fb *pfb = nouveau_fb(parent); | ||
47 | struct nv50_instobj_priv *node; | ||
48 | u32 align = (unsigned long)data; | ||
49 | int ret; | ||
50 | |||
51 | size = max((size + 4095) & ~4095, (u32)4096); | ||
52 | align = max((align + 4095) & ~4095, (u32)4096); | ||
53 | |||
54 | ret = nouveau_instobj_create(parent, engine, oclass, &node); | ||
55 | *pobject = nv_object(node); | ||
56 | if (ret) | ||
57 | return ret; | ||
58 | |||
59 | ret = pfb->ram->get(pfb, size, align, 0, 0x800, &node->mem); | ||
60 | if (ret) | ||
61 | return ret; | ||
62 | |||
63 | node->base.addr = node->mem->offset; | ||
64 | node->base.size = node->mem->size << 12; | ||
65 | node->mem->page_shift = 12; | ||
66 | return 0; | ||
67 | } | ||
68 | |||
69 | static void | ||
70 | nv50_instobj_dtor(struct nouveau_object *object) | ||
71 | { | ||
72 | struct nv50_instobj_priv *node = (void *)object; | ||
73 | struct nouveau_fb *pfb = nouveau_fb(object); | ||
74 | pfb->ram->put(pfb, &node->mem); | ||
75 | nouveau_instobj_destroy(&node->base); | ||
76 | } | ||
77 | 44 | ||
78 | static u32 | 45 | static u32 |
79 | nv50_instobj_rd32(struct nouveau_object *object, u64 offset) | 46 | nv50_instobj_rd32(struct nouveau_object *object, u64 offset) |
@@ -113,9 +80,46 @@ nv50_instobj_wr32(struct nouveau_object *object, u64 offset, u32 data) | |||
113 | spin_unlock_irqrestore(&priv->lock, flags); | 80 | spin_unlock_irqrestore(&priv->lock, flags); |
114 | } | 81 | } |
115 | 82 | ||
116 | static struct nouveau_oclass | 83 | static void |
84 | nv50_instobj_dtor(struct nouveau_object *object) | ||
85 | { | ||
86 | struct nv50_instobj_priv *node = (void *)object; | ||
87 | struct nouveau_fb *pfb = nouveau_fb(object); | ||
88 | pfb->ram->put(pfb, &node->mem); | ||
89 | nouveau_instobj_destroy(&node->base); | ||
90 | } | ||
91 | |||
92 | static int | ||
93 | nv50_instobj_ctor(struct nouveau_object *parent, struct nouveau_object *engine, | ||
94 | struct nouveau_oclass *oclass, void *data, u32 size, | ||
95 | struct nouveau_object **pobject) | ||
96 | { | ||
97 | struct nouveau_fb *pfb = nouveau_fb(parent); | ||
98 | struct nouveau_instobj_args *args = data; | ||
99 | struct nv50_instobj_priv *node; | ||
100 | int ret; | ||
101 | |||
102 | args->size = max((args->size + 4095) & ~4095, (u32)4096); | ||
103 | args->align = max((args->align + 4095) & ~4095, (u32)4096); | ||
104 | |||
105 | ret = nouveau_instobj_create(parent, engine, oclass, &node); | ||
106 | *pobject = nv_object(node); | ||
107 | if (ret) | ||
108 | return ret; | ||
109 | |||
110 | ret = pfb->ram->get(pfb, args->size, args->align, 0, 0x800, &node->mem); | ||
111 | if (ret) | ||
112 | return ret; | ||
113 | |||
114 | node->base.addr = node->mem->offset; | ||
115 | node->base.size = node->mem->size << 12; | ||
116 | node->mem->page_shift = 12; | ||
117 | return 0; | ||
118 | } | ||
119 | |||
120 | static struct nouveau_instobj_impl | ||
117 | nv50_instobj_oclass = { | 121 | nv50_instobj_oclass = { |
118 | .ofuncs = &(struct nouveau_ofuncs) { | 122 | .base.ofuncs = &(struct nouveau_ofuncs) { |
119 | .ctor = nv50_instobj_ctor, | 123 | .ctor = nv50_instobj_ctor, |
120 | .dtor = nv50_instobj_dtor, | 124 | .dtor = nv50_instobj_dtor, |
121 | .init = _nouveau_instobj_init, | 125 | .init = _nouveau_instobj_init, |
@@ -163,5 +167,5 @@ nv50_instmem_oclass = &(struct nouveau_instmem_impl) { | |||
163 | .init = _nouveau_instmem_init, | 167 | .init = _nouveau_instmem_init, |
164 | .fini = nv50_instmem_fini, | 168 | .fini = nv50_instmem_fini, |
165 | }, | 169 | }, |
166 | .instobj = &nv50_instobj_oclass, | 170 | .instobj = &nv50_instobj_oclass.base, |
167 | }.base; | 171 | }.base; |
diff --git a/drivers/gpu/drm/nouveau/core/subdev/instmem/priv.h b/drivers/gpu/drm/nouveau/core/subdev/instmem/priv.h index 17c7874f3ab7..8d67dedc5bb2 100644 --- a/drivers/gpu/drm/nouveau/core/subdev/instmem/priv.h +++ b/drivers/gpu/drm/nouveau/core/subdev/instmem/priv.h | |||
@@ -3,6 +3,32 @@ | |||
3 | 3 | ||
4 | #include <subdev/instmem.h> | 4 | #include <subdev/instmem.h> |
5 | 5 | ||
6 | struct nouveau_instobj_impl { | ||
7 | struct nouveau_oclass base; | ||
8 | }; | ||
9 | |||
10 | struct nouveau_instobj_args { | ||
11 | u32 size; | ||
12 | u32 align; | ||
13 | }; | ||
14 | |||
15 | #define nouveau_instobj_create(p,e,o,d) \ | ||
16 | nouveau_instobj_create_((p), (e), (o), sizeof(**d), (void **)d) | ||
17 | #define nouveau_instobj_destroy(p) ({ \ | ||
18 | struct nouveau_instobj *iobj = (p); \ | ||
19 | _nouveau_instobj_dtor(nv_object(iobj)); \ | ||
20 | }) | ||
21 | #define nouveau_instobj_init(p) \ | ||
22 | nouveau_object_init(&(p)->base) | ||
23 | #define nouveau_instobj_fini(p,s) \ | ||
24 | nouveau_object_fini(&(p)->base, (s)) | ||
25 | |||
26 | int nouveau_instobj_create_(struct nouveau_object *, struct nouveau_object *, | ||
27 | struct nouveau_oclass *, int, void **); | ||
28 | void _nouveau_instobj_dtor(struct nouveau_object *); | ||
29 | #define _nouveau_instobj_init nouveau_object_init | ||
30 | #define _nouveau_instobj_fini nouveau_object_fini | ||
31 | |||
6 | struct nouveau_instmem_impl { | 32 | struct nouveau_instmem_impl { |
7 | struct nouveau_oclass base; | 33 | struct nouveau_oclass base; |
8 | struct nouveau_oclass *instobj; | 34 | struct nouveau_oclass *instobj; |