a240d2c6ad9a15c5de9351915bb27da8bd423324
[linux-2.6-microblaze.git] / drivers / gpu / drm / nouveau / include / nvkm / core / device.h
1 /* SPDX-License-Identifier: MIT */
2 #ifndef __NVKM_DEVICE_H__
3 #define __NVKM_DEVICE_H__
4 #include <core/oclass.h>
5 #include <core/event.h>
6 enum nvkm_subdev_type;
7
8 #define nvkm_devidx nvkm_subdev_type
9
10 enum nvkm_device_type {
11         NVKM_DEVICE_PCI,
12         NVKM_DEVICE_AGP,
13         NVKM_DEVICE_PCIE,
14         NVKM_DEVICE_TEGRA,
15 };
16
17 struct nvkm_device {
18         const struct nvkm_device_func *func;
19         const struct nvkm_device_quirk *quirk;
20         struct device *dev;
21         enum nvkm_device_type type;
22         u64 handle;
23         const char *name;
24         const char *cfgopt;
25         const char *dbgopt;
26
27         struct list_head head;
28         struct mutex mutex;
29         int refcount;
30
31         void __iomem *pri;
32
33         struct nvkm_event event;
34
35         u64 disable_mask;
36         u32 debug;
37
38         const struct nvkm_device_chip *chip;
39         enum {
40                 NV_04    = 0x04,
41                 NV_10    = 0x10,
42                 NV_11    = 0x11,
43                 NV_20    = 0x20,
44                 NV_30    = 0x30,
45                 NV_40    = 0x40,
46                 NV_50    = 0x50,
47                 NV_C0    = 0xc0,
48                 NV_E0    = 0xe0,
49                 GM100    = 0x110,
50                 GP100    = 0x130,
51                 GV100    = 0x140,
52                 TU100    = 0x160,
53                 GA100    = 0x170,
54         } card_type;
55         u32 chipset;
56         u8  chiprev;
57         u32 crystal;
58
59         struct {
60                 struct notifier_block nb;
61         } acpi;
62
63         struct nvkm_pmu *pmu;
64         struct nvkm_therm *therm;
65         struct nvkm_timer *timer;
66         struct nvkm_top *top;
67         struct nvkm_volt *volt;
68
69         struct nvkm_engine *bsp;
70         struct nvkm_engine *ce[9];
71         struct nvkm_engine *cipher;
72         struct nvkm_disp *disp;
73         struct nvkm_dma *dma;
74         struct nvkm_fifo *fifo;
75         struct nvkm_gr *gr;
76         struct nvkm_engine *ifb;
77         struct nvkm_engine *me;
78         struct nvkm_engine *mpeg;
79         struct nvkm_engine *msenc;
80         struct nvkm_engine *mspdec;
81         struct nvkm_engine *msppp;
82         struct nvkm_engine *msvld;
83         struct nvkm_nvenc *nvenc[3];
84         struct nvkm_nvdec *nvdec[3];
85         struct nvkm_pm *pm;
86         struct nvkm_engine *sec;
87         struct nvkm_sec2 *sec2;
88         struct nvkm_sw *sw;
89         struct nvkm_engine *vic;
90         struct nvkm_engine *vp;
91
92 #define NVKM_LAYOUT_ONCE(type,data,ptr) data *ptr;
93 #define NVKM_LAYOUT_INST(type,data,ptr,cnt) data *ptr[cnt];
94 #include <core/layout.h>
95 #undef NVKM_LAYOUT_INST
96 #undef NVKM_LAYOUT_ONCE
97         struct list_head subdev;
98 };
99
100 struct nvkm_subdev *nvkm_device_subdev(struct nvkm_device *, int type, int inst);
101 struct nvkm_engine *nvkm_device_engine(struct nvkm_device *, int type, int inst);
102
103 struct nvkm_device_func {
104         struct nvkm_device_pci *(*pci)(struct nvkm_device *);
105         struct nvkm_device_tegra *(*tegra)(struct nvkm_device *);
106         void *(*dtor)(struct nvkm_device *);
107         int (*preinit)(struct nvkm_device *);
108         int (*init)(struct nvkm_device *);
109         void (*fini)(struct nvkm_device *, bool suspend);
110         resource_size_t (*resource_addr)(struct nvkm_device *, unsigned bar);
111         resource_size_t (*resource_size)(struct nvkm_device *, unsigned bar);
112         bool cpu_coherent;
113 };
114
115 struct nvkm_device_quirk {
116         u8 tv_pin_mask;
117         u8 tv_gpio;
118 };
119
120 struct nvkm_device_chip {
121         const char *name;
122 #define NVKM_LAYOUT_ONCE(type,data,ptr,...)                                                  \
123         struct {                                                                             \
124                 u32 inst;                                                                    \
125                 int (*ctor)(struct nvkm_device *, enum nvkm_subdev_type, int inst, data **); \
126         } ptr;
127 #define NVKM_LAYOUT_INST(A...) NVKM_LAYOUT_ONCE(A)
128 #include <core/layout.h>
129 #undef NVKM_LAYOUT_INST
130 #undef NVKM_LAYOUT_ONCE
131         int (*pmu     )(struct nvkm_device *, int idx, struct nvkm_pmu **);
132         int (*therm   )(struct nvkm_device *, int idx, struct nvkm_therm **);
133         int (*timer   )(struct nvkm_device *, int idx, struct nvkm_timer **);
134         int (*top     )(struct nvkm_device *, int idx, struct nvkm_top **);
135         int (*volt    )(struct nvkm_device *, int idx, struct nvkm_volt **);
136
137         int (*bsp     )(struct nvkm_device *, int idx, struct nvkm_engine **);
138         int (*ce[9]   )(struct nvkm_device *, int idx, struct nvkm_engine **);
139         int (*cipher  )(struct nvkm_device *, int idx, struct nvkm_engine **);
140         int (*disp    )(struct nvkm_device *, int idx, struct nvkm_disp **);
141         int (*dma     )(struct nvkm_device *, int idx, struct nvkm_dma **);
142         int (*fifo    )(struct nvkm_device *, int idx, struct nvkm_fifo **);
143         int (*gr      )(struct nvkm_device *, int idx, struct nvkm_gr **);
144         int (*ifb     )(struct nvkm_device *, int idx, struct nvkm_engine **);
145         int (*me      )(struct nvkm_device *, int idx, struct nvkm_engine **);
146         int (*mpeg    )(struct nvkm_device *, int idx, struct nvkm_engine **);
147         int (*msenc   )(struct nvkm_device *, int idx, struct nvkm_engine **);
148         int (*mspdec  )(struct nvkm_device *, int idx, struct nvkm_engine **);
149         int (*msppp   )(struct nvkm_device *, int idx, struct nvkm_engine **);
150         int (*msvld   )(struct nvkm_device *, int idx, struct nvkm_engine **);
151         int (*nvenc[3])(struct nvkm_device *, int idx, struct nvkm_nvenc **);
152         int (*nvdec[3])(struct nvkm_device *, int idx, struct nvkm_nvdec **);
153         int (*pm      )(struct nvkm_device *, int idx, struct nvkm_pm **);
154         int (*sec     )(struct nvkm_device *, int idx, struct nvkm_engine **);
155         int (*sec2    )(struct nvkm_device *, int idx, struct nvkm_sec2 **);
156         int (*sw      )(struct nvkm_device *, int idx, struct nvkm_sw **);
157         int (*vic     )(struct nvkm_device *, int idx, struct nvkm_engine **);
158         int (*vp      )(struct nvkm_device *, int idx, struct nvkm_engine **);
159 };
160
161 struct nvkm_device *nvkm_device_find(u64 name);
162 int nvkm_device_list(u64 *name, int size);
163
164 /* privileged register interface accessor macros */
165 #define nvkm_rd08(d,a) ioread8((d)->pri + (a))
166 #define nvkm_rd16(d,a) ioread16_native((d)->pri + (a))
167 #define nvkm_rd32(d,a) ioread32_native((d)->pri + (a))
168 #define nvkm_wr08(d,a,v) iowrite8((v), (d)->pri + (a))
169 #define nvkm_wr16(d,a,v) iowrite16_native((v), (d)->pri + (a))
170 #define nvkm_wr32(d,a,v) iowrite32_native((v), (d)->pri + (a))
171 #define nvkm_mask(d,a,m,v) ({                                                  \
172         struct nvkm_device *_device = (d);                                     \
173         u32 _addr = (a), _temp = nvkm_rd32(_device, _addr);                    \
174         nvkm_wr32(_device, _addr, (_temp & ~(m)) | (v));                       \
175         _temp;                                                                 \
176 })
177
178 void nvkm_device_del(struct nvkm_device **);
179
180 struct nvkm_device_oclass {
181         int (*ctor)(struct nvkm_device *, const struct nvkm_oclass *,
182                     void *data, u32 size, struct nvkm_object **);
183         struct nvkm_sclass base;
184 };
185
186 extern const struct nvkm_sclass nvkm_udevice_sclass;
187
188 /* device logging */
189 #define nvdev_printk_(d,l,p,f,a...) do {                                       \
190         const struct nvkm_device *_device = (d);                               \
191         if (_device->debug >= (l))                                             \
192                 dev_##p(_device->dev, f, ##a);                                 \
193 } while(0)
194 #define nvdev_printk(d,l,p,f,a...) nvdev_printk_((d), NV_DBG_##l, p, f, ##a)
195 #define nvdev_fatal(d,f,a...) nvdev_printk((d), FATAL,   crit, f, ##a)
196 #define nvdev_error(d,f,a...) nvdev_printk((d), ERROR,    err, f, ##a)
197 #define nvdev_warn(d,f,a...)  nvdev_printk((d),  WARN, notice, f, ##a)
198 #define nvdev_info(d,f,a...)  nvdev_printk((d),  INFO,   info, f, ##a)
199 #define nvdev_debug(d,f,a...) nvdev_printk((d), DEBUG,   info, f, ##a)
200 #define nvdev_trace(d,f,a...) nvdev_printk((d), TRACE,   info, f, ##a)
201 #define nvdev_spam(d,f,a...)  nvdev_printk((d),  SPAM,    dbg, f, ##a)
202 #endif