Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
object.h
Go to the documentation of this file.
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 
23 #if CONFIG_NOUVEAU_DEBUG >= NV_DBG_PARANOIA
24 #define NOUVEAU_OBJECT_MAGIC 0x75ef0bad
25  struct list_head list;
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)
46  struct nouveau_oclass *, u32, int size, void **);
49 int nouveau_object_fini(struct nouveau_object *, bool suspend);
50 
52 
57 };
58 
59 #define nv_oclass(o) nv_object(o)->oclass
60 #define nv_hclass(o) nv_oclass(o)->handle
61 #define nv_iclass(o,i) (nv_hclass(o) & (i))
62 #define nv_mclass(o) nv_iclass(o, NV_OBJECT_CLASS)
63 
64 static inline struct nouveau_object *
65 nv_pclass(struct nouveau_object *parent, u32 oclass)
66 {
67  while (parent && !nv_iclass(parent, oclass))
68  parent = parent->parent;
69  return parent;
70 }
71 
74  int (*call)(struct nouveau_object *, u32, void *, u32);
75 };
76 
78  int (*ctor)(struct nouveau_object *, struct nouveau_object *,
79  struct nouveau_oclass *, void *data, u32 size,
80  struct nouveau_object **);
81  void (*dtor)(struct nouveau_object *);
82  int (*init)(struct nouveau_object *);
83  int (*fini)(struct nouveau_object *, bool suspend);
84  u8 (*rd08)(struct nouveau_object *, u32 offset);
85  u16 (*rd16)(struct nouveau_object *, u32 offset);
86  u32 (*rd32)(struct nouveau_object *, u32 offset);
90 };
91 
92 static inline struct nouveau_ofuncs *
93 nv_ofuncs(void *obj)
94 {
95  return nv_oclass(obj)->ofuncs;
96 }
97 
99  struct nouveau_oclass *, void *, u32,
100  struct nouveau_object **);
101 void nouveau_object_ref(struct nouveau_object *, struct nouveau_object **);
102 int nouveau_object_inc(struct nouveau_object *);
103 int nouveau_object_dec(struct nouveau_object *, bool suspend);
104 
105 int nouveau_object_new(struct nouveau_object *, u32 parent, u32 handle,
106  u16 oclass, void *data, u32 size,
107  struct nouveau_object **);
108 int nouveau_object_del(struct nouveau_object *, u32 parent, u32 handle);
109 void nouveau_object_debug(void);
110 
111 static inline int
112 nv_call(void *obj, u32 mthd, u32 data)
113 {
114  struct nouveau_omthds *method = nv_oclass(obj)->omthds;
115 
116  while (method && method->call) {
117  if (method->method == mthd)
118  return method->call(obj, mthd, &data, sizeof(data));
119  method++;
120  }
121 
122  return -EINVAL;
123 }
124 
125 static inline u8
126 nv_ro08(void *obj, u32 addr)
127 {
128  u8 data = nv_ofuncs(obj)->rd08(obj, addr);
129  nv_spam(obj, "nv_ro08 0x%08x 0x%02x\n", addr, data);
130  return data;
131 }
132 
133 static inline u16
134 nv_ro16(void *obj, u32 addr)
135 {
136  u16 data = nv_ofuncs(obj)->rd16(obj, addr);
137  nv_spam(obj, "nv_ro16 0x%08x 0x%04x\n", addr, data);
138  return data;
139 }
140 
141 static inline u32
142 nv_ro32(void *obj, u32 addr)
143 {
144  u32 data = nv_ofuncs(obj)->rd32(obj, addr);
145  nv_spam(obj, "nv_ro32 0x%08x 0x%08x\n", addr, data);
146  return data;
147 }
148 
149 static inline void
150 nv_wo08(void *obj, u32 addr, u8 data)
151 {
152  nv_spam(obj, "nv_wo08 0x%08x 0x%02x\n", addr, data);
153  nv_ofuncs(obj)->wr08(obj, addr, data);
154 }
155 
156 static inline void
157 nv_wo16(void *obj, u32 addr, u16 data)
158 {
159  nv_spam(obj, "nv_wo16 0x%08x 0x%04x\n", addr, data);
160  nv_ofuncs(obj)->wr16(obj, addr, data);
161 }
162 
163 static inline void
164 nv_wo32(void *obj, u32 addr, u32 data)
165 {
166  nv_spam(obj, "nv_wo32 0x%08x 0x%08x\n", addr, data);
167  nv_ofuncs(obj)->wr32(obj, addr, data);
168 }
169 
170 static inline u32
171 nv_mo32(void *obj, u32 addr, u32 mask, u32 data)
172 {
173  u32 temp = nv_ro32(obj, addr);
174  nv_wo32(obj, addr, (temp & ~mask) | data);
175  return temp;
176 }
177 
178 static inline int
179 nv_memcmp(void *obj, u32 addr, const char *str, u32 len)
180 {
181  unsigned char c1, c2;
182 
183  while (len--) {
184  c1 = nv_ro08(obj, addr++);
185  c2 = *(str++);
186  if (c1 != c2)
187  return c1 - c2;
188  }
189  return 0;
190 }
191 
192 #endif