]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/gpu/drm/nouveau/core/include/core/object.h
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
[karo-tx-linux.git] / drivers / gpu / drm / nouveau / core / include / core / object.h
1 #ifndef __NOUVEAU_OBJECT_H__
2 #define __NOUVEAU_OBJECT_H__
3
4 #include <core/os.h>
5 #include <core/printk.h>
6
7 #define NV_PARENT_CLASS 0x80000000
8 #define NV_NAMEDB_CLASS 0x40000000
9 #define NV_CLIENT_CLASS 0x20000000
10 #define NV_SUBDEV_CLASS 0x10000000
11 #define NV_ENGINE_CLASS 0x08000000
12 #define NV_MEMOBJ_CLASS 0x04000000
13 #define NV_GPUOBJ_CLASS 0x02000000
14 #define NV_ENGCTX_CLASS 0x01000000
15 #define NV_OBJECT_CLASS 0x0000ffff
16
17 struct nouveau_object {
18         struct nouveau_oclass *oclass;
19         struct nouveau_object *parent;
20         struct nouveau_object *engine;
21         atomic_t refcount;
22         atomic_t usecount;
23 #if CONFIG_NOUVEAU_DEBUG >= NV_DBG_PARANOIA
24 #define NOUVEAU_OBJECT_MAGIC 0x75ef0bad
25         struct list_head list;
26         u32 _magic;
27 #endif
28 };
29
30 static inline struct nouveau_object *
31 nv_object(void *obj)
32 {
33 #if CONFIG_NOUVEAU_DEBUG >= NV_DBG_PARANOIA
34         if (likely(obj)) {
35                 struct nouveau_object *object = obj;
36                 if (unlikely(object->_magic != NOUVEAU_OBJECT_MAGIC))
37                         nv_assert("BAD CAST -> NvObject, invalid magic");
38         }
39 #endif
40         return obj;
41 }
42
43 #define nouveau_object_create(p,e,c,s,d)                                       \
44         nouveau_object_create_((p), (e), (c), (s), sizeof(**d), (void **)d)
45 int  nouveau_object_create_(struct nouveau_object *, struct nouveau_object *,
46                             struct nouveau_oclass *, u32, int size, void **);
47 void nouveau_object_destroy(struct nouveau_object *);
48 int  nouveau_object_init(struct nouveau_object *);
49 int  nouveau_object_fini(struct nouveau_object *, bool suspend);
50
51 extern struct nouveau_ofuncs nouveau_object_ofuncs;
52
53 /* Don't allocate dynamically, because lockdep needs lock_class_keys to be in
54  * ".data". */
55 struct nouveau_oclass {
56         u32 handle;
57         struct nouveau_ofuncs * const ofuncs;
58         struct nouveau_omthds * const omthds;
59         struct lock_class_key lock_class_key;
60 };
61
62 #define nv_oclass(o)    nv_object(o)->oclass
63 #define nv_hclass(o)    nv_oclass(o)->handle
64 #define nv_iclass(o,i) (nv_hclass(o) & (i))
65 #define nv_mclass(o)    nv_iclass(o, NV_OBJECT_CLASS)
66
67 static inline struct nouveau_object *
68 nv_pclass(struct nouveau_object *parent, u32 oclass)
69 {
70         while (parent && !nv_iclass(parent, oclass))
71                 parent = parent->parent;
72         return parent;
73 }
74
75 struct nouveau_omthds {
76         u32 start;
77         u32 limit;
78         int (*call)(struct nouveau_object *, u32, void *, u32);
79 };
80
81 struct nouveau_ofuncs {
82         int  (*ctor)(struct nouveau_object *, struct nouveau_object *,
83                      struct nouveau_oclass *, void *data, u32 size,
84                      struct nouveau_object **);
85         void (*dtor)(struct nouveau_object *);
86         int  (*init)(struct nouveau_object *);
87         int  (*fini)(struct nouveau_object *, bool suspend);
88         u8   (*rd08)(struct nouveau_object *, u64 offset);
89         u16  (*rd16)(struct nouveau_object *, u64 offset);
90         u32  (*rd32)(struct nouveau_object *, u64 offset);
91         void (*wr08)(struct nouveau_object *, u64 offset, u8 data);
92         void (*wr16)(struct nouveau_object *, u64 offset, u16 data);
93         void (*wr32)(struct nouveau_object *, u64 offset, u32 data);
94 };
95
96 static inline struct nouveau_ofuncs *
97 nv_ofuncs(void *obj)
98 {
99         return nv_oclass(obj)->ofuncs;
100 }
101
102 int  nouveau_object_ctor(struct nouveau_object *, struct nouveau_object *,
103                          struct nouveau_oclass *, void *, u32,
104                          struct nouveau_object **);
105 void nouveau_object_ref(struct nouveau_object *, struct nouveau_object **);
106 int nouveau_object_inc(struct nouveau_object *);
107 int nouveau_object_dec(struct nouveau_object *, bool suspend);
108
109 int nouveau_object_new(struct nouveau_object *, u32 parent, u32 handle,
110                        u16 oclass, void *data, u32 size,
111                        struct nouveau_object **);
112 int nouveau_object_del(struct nouveau_object *, u32 parent, u32 handle);
113 void nouveau_object_debug(void);
114
115 static inline int
116 nv_exec(void *obj, u32 mthd, void *data, u32 size)
117 {
118         struct nouveau_omthds *method = nv_oclass(obj)->omthds;
119
120         while (method && method->call) {
121                 if (mthd >= method->start && mthd <= method->limit)
122                         return method->call(obj, mthd, data, size);
123                 method++;
124         }
125
126         return -EINVAL;
127 }
128
129 static inline int
130 nv_call(void *obj, u32 mthd, u32 data)
131 {
132         return nv_exec(obj, mthd, &data, sizeof(data));
133 }
134
135 static inline u8
136 nv_ro08(void *obj, u64 addr)
137 {
138         u8 data = nv_ofuncs(obj)->rd08(obj, addr);
139         nv_spam(obj, "nv_ro08 0x%08x 0x%02x\n", addr, data);
140         return data;
141 }
142
143 static inline u16
144 nv_ro16(void *obj, u64 addr)
145 {
146         u16 data = nv_ofuncs(obj)->rd16(obj, addr);
147         nv_spam(obj, "nv_ro16 0x%08x 0x%04x\n", addr, data);
148         return data;
149 }
150
151 static inline u32
152 nv_ro32(void *obj, u64 addr)
153 {
154         u32 data = nv_ofuncs(obj)->rd32(obj, addr);
155         nv_spam(obj, "nv_ro32 0x%08x 0x%08x\n", addr, data);
156         return data;
157 }
158
159 static inline void
160 nv_wo08(void *obj, u64 addr, u8 data)
161 {
162         nv_spam(obj, "nv_wo08 0x%08x 0x%02x\n", addr, data);
163         nv_ofuncs(obj)->wr08(obj, addr, data);
164 }
165
166 static inline void
167 nv_wo16(void *obj, u64 addr, u16 data)
168 {
169         nv_spam(obj, "nv_wo16 0x%08x 0x%04x\n", addr, data);
170         nv_ofuncs(obj)->wr16(obj, addr, data);
171 }
172
173 static inline void
174 nv_wo32(void *obj, u64 addr, u32 data)
175 {
176         nv_spam(obj, "nv_wo32 0x%08x 0x%08x\n", addr, data);
177         nv_ofuncs(obj)->wr32(obj, addr, data);
178 }
179
180 static inline u32
181 nv_mo32(void *obj, u64 addr, u32 mask, u32 data)
182 {
183         u32 temp = nv_ro32(obj, addr);
184         nv_wo32(obj, addr, (temp & ~mask) | data);
185         return temp;
186 }
187
188 static inline int
189 nv_memcmp(void *obj, u32 addr, const char *str, u32 len)
190 {
191         unsigned char c1, c2;
192
193         while (len--) {
194                 c1 = nv_ro08(obj, addr++);
195                 c2 = *(str++);
196                 if (c1 != c2)
197                         return c1 - c2;
198         }
199         return 0;
200 }
201
202 #endif