1 #ifndef __NOUVEAU_SUBDEV_H__
2 #define __NOUVEAU_SUBDEV_H__
3
4 #include <core/object.h>
5
6 #define NV_SUBDEV_(sub,var) (NV_SUBDEV_CLASS | ((var) << 8) | (sub))
7 #define NV_SUBDEV(name,var) NV_SUBDEV_(NVDEV_SUBDEV_##name, (var))
8
9 struct nouveau_subdev {
10 struct nouveau_object base;
11 struct mutex mutex;
12 const char *name;
13 void __iomem *mmio;
14 u32 debug;
15 u32 unit;
16
17 void (*intr)(struct nouveau_subdev *);
18 };
19
20 static inline struct nouveau_subdev *
nv_subdev(void * obj)21 nv_subdev(void *obj)
22 {
23 #if CONFIG_NOUVEAU_DEBUG >= NV_DBG_PARANOIA
24 if (unlikely(!nv_iclass(obj, NV_SUBDEV_CLASS)))
25 nv_assert("BAD CAST -> NvSubDev, %08x", nv_hclass(obj));
26 #endif
27 return obj;
28 }
29
30 static inline int
nv_subidx(struct nouveau_object * object)31 nv_subidx(struct nouveau_object *object)
32 {
33 return nv_hclass(nv_subdev(object)) & 0xff;
34 }
35
36 #define nouveau_subdev_create(p,e,o,v,s,f,d) \
37 nouveau_subdev_create_((p), (e), (o), (v), (s), (f), \
38 sizeof(**d),(void **)d)
39
40 int nouveau_subdev_create_(struct nouveau_object *, struct nouveau_object *,
41 struct nouveau_oclass *, u32 pclass,
42 const char *sname, const char *fname,
43 int size, void **);
44 void nouveau_subdev_destroy(struct nouveau_subdev *);
45 int nouveau_subdev_init(struct nouveau_subdev *);
46 int nouveau_subdev_fini(struct nouveau_subdev *, bool suspend);
47 void nouveau_subdev_reset(struct nouveau_object *);
48
49 void _nouveau_subdev_dtor(struct nouveau_object *);
50 int _nouveau_subdev_init(struct nouveau_object *);
51 int _nouveau_subdev_fini(struct nouveau_object *, bool suspend);
52
53 #define s_printk(s,l,f,a...) do { \
54 if ((s)->debug >= OS_DBG_##l) { \
55 nv_printk((s)->base.parent, (s)->name, l, f, ##a); \
56 } \
57 } while(0)
58
59 static inline u8
nv_rd08(void * obj,u32 addr)60 nv_rd08(void *obj, u32 addr)
61 {
62 struct nouveau_subdev *subdev = nv_subdev(obj);
63 u8 data = ioread8(subdev->mmio + addr);
64 nv_spam(subdev, "nv_rd08 0x%06x 0x%02x\n", addr, data);
65 return data;
66 }
67
68 static inline u16
nv_rd16(void * obj,u32 addr)69 nv_rd16(void *obj, u32 addr)
70 {
71 struct nouveau_subdev *subdev = nv_subdev(obj);
72 u16 data = ioread16_native(subdev->mmio + addr);
73 nv_spam(subdev, "nv_rd16 0x%06x 0x%04x\n", addr, data);
74 return data;
75 }
76
77 static inline u32
nv_rd32(void * obj,u32 addr)78 nv_rd32(void *obj, u32 addr)
79 {
80 struct nouveau_subdev *subdev = nv_subdev(obj);
81 u32 data = ioread32_native(subdev->mmio + addr);
82 nv_spam(subdev, "nv_rd32 0x%06x 0x%08x\n", addr, data);
83 return data;
84 }
85
86 static inline void
nv_wr08(void * obj,u32 addr,u8 data)87 nv_wr08(void *obj, u32 addr, u8 data)
88 {
89 struct nouveau_subdev *subdev = nv_subdev(obj);
90 nv_spam(subdev, "nv_wr08 0x%06x 0x%02x\n", addr, data);
91 iowrite8(data, subdev->mmio + addr);
92 }
93
94 static inline void
nv_wr16(void * obj,u32 addr,u16 data)95 nv_wr16(void *obj, u32 addr, u16 data)
96 {
97 struct nouveau_subdev *subdev = nv_subdev(obj);
98 nv_spam(subdev, "nv_wr16 0x%06x 0x%04x\n", addr, data);
99 iowrite16_native(data, subdev->mmio + addr);
100 }
101
102 static inline void
nv_wr32(void * obj,u32 addr,u32 data)103 nv_wr32(void *obj, u32 addr, u32 data)
104 {
105 struct nouveau_subdev *subdev = nv_subdev(obj);
106 nv_spam(subdev, "nv_wr32 0x%06x 0x%08x\n", addr, data);
107 iowrite32_native(data, subdev->mmio + addr);
108 }
109
110 static inline u32
nv_mask(void * obj,u32 addr,u32 mask,u32 data)111 nv_mask(void *obj, u32 addr, u32 mask, u32 data)
112 {
113 u32 temp = nv_rd32(obj, addr);
114 nv_wr32(obj, addr, (temp & ~mask) | data);
115 return temp;
116 }
117
118 #endif
119