Merge tag 'acpi-3.13-fixup' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael...
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / drm / nouveau / core / include / subdev / instmem.h
1 #ifndef __NOUVEAU_INSTMEM_H__
2 #define __NOUVEAU_INSTMEM_H__
3
4 #include <core/subdev.h>
5 #include <core/device.h>
6 #include <core/mm.h>
7
8 struct nouveau_instobj {
9         struct nouveau_object base;
10         struct list_head head;
11         u32 *suspend;
12         u64 addr;
13         u32 size;
14 };
15
16 static inline struct nouveau_instobj *
17 nv_memobj(void *obj)
18 {
19 #if CONFIG_NOUVEAU_DEBUG >= NV_DBG_PARANOIA
20         if (unlikely(!nv_iclass(obj, NV_MEMOBJ_CLASS)))
21                 nv_assert("BAD CAST -> NvMemObj, %08x", nv_hclass(obj));
22 #endif
23         return obj;
24 }
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 {
42         struct nouveau_subdev base;
43         struct list_head list;
44
45         u32 reserved;
46         int (*alloc)(struct nouveau_instmem *, struct nouveau_object *,
47                      u32 size, u32 align, struct nouveau_object **);
48 };
49
50 static inline struct nouveau_instmem *
51 nouveau_instmem(void *obj)
52 {
53         /* nv04/nv40 impls need to create objects in their constructor,
54          * which is before the subdev pointer is valid
55          */
56         if (nv_iclass(obj, NV_SUBDEV_CLASS) &&
57             nv_subidx(obj) == NVDEV_SUBDEV_INSTMEM)
58                 return obj;
59
60         return (void *)nv_device(obj)->subdev[NVDEV_SUBDEV_INSTMEM];
61 }
62
63 #define nouveau_instmem_create(p,e,o,d)                                        \
64         nouveau_instmem_create_((p), (e), (o), sizeof(**d), (void **)d)
65 #define nouveau_instmem_destroy(p)                                             \
66         nouveau_subdev_destroy(&(p)->base)
67 int nouveau_instmem_create_(struct nouveau_object *, struct nouveau_object *,
68                             struct nouveau_oclass *, int, void **);
69 int nouveau_instmem_init(struct nouveau_instmem *);
70 int nouveau_instmem_fini(struct nouveau_instmem *, bool);
71
72 #define _nouveau_instmem_dtor _nouveau_subdev_dtor
73 int _nouveau_instmem_init(struct nouveau_object *);
74 int _nouveau_instmem_fini(struct nouveau_object *, bool);
75
76 extern struct nouveau_oclass nv04_instmem_oclass;
77 extern struct nouveau_oclass nv40_instmem_oclass;
78 extern struct nouveau_oclass nv50_instmem_oclass;
79
80 #endif