GNU Linux-libre 4.14.290-gnu1
[releases.git] / drivers / gpu / drm / nouveau / include / nvkm / core / device.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __NVKM_DEVICE_H__
3 #define __NVKM_DEVICE_H__
4 #include <core/event.h>
5 #include <core/object.h>
6
7 enum nvkm_devidx {
8         NVKM_SUBDEV_PCI,
9         NVKM_SUBDEV_VBIOS,
10         NVKM_SUBDEV_DEVINIT,
11         NVKM_SUBDEV_TOP,
12         NVKM_SUBDEV_IBUS,
13         NVKM_SUBDEV_GPIO,
14         NVKM_SUBDEV_I2C,
15         NVKM_SUBDEV_FUSE,
16         NVKM_SUBDEV_MXM,
17         NVKM_SUBDEV_MC,
18         NVKM_SUBDEV_BUS,
19         NVKM_SUBDEV_TIMER,
20         NVKM_SUBDEV_INSTMEM,
21         NVKM_SUBDEV_FB,
22         NVKM_SUBDEV_LTC,
23         NVKM_SUBDEV_MMU,
24         NVKM_SUBDEV_BAR,
25         NVKM_SUBDEV_PMU,
26         NVKM_SUBDEV_VOLT,
27         NVKM_SUBDEV_ICCSENSE,
28         NVKM_SUBDEV_THERM,
29         NVKM_SUBDEV_CLK,
30         NVKM_SUBDEV_SECBOOT,
31
32         NVKM_ENGINE_BSP,
33
34         NVKM_ENGINE_CE0,
35         NVKM_ENGINE_CE1,
36         NVKM_ENGINE_CE2,
37         NVKM_ENGINE_CE3,
38         NVKM_ENGINE_CE4,
39         NVKM_ENGINE_CE5,
40         NVKM_ENGINE_CE_LAST = NVKM_ENGINE_CE5,
41
42         NVKM_ENGINE_CIPHER,
43         NVKM_ENGINE_DISP,
44         NVKM_ENGINE_DMAOBJ,
45         NVKM_ENGINE_FIFO,
46         NVKM_ENGINE_GR,
47         NVKM_ENGINE_IFB,
48         NVKM_ENGINE_ME,
49         NVKM_ENGINE_MPEG,
50         NVKM_ENGINE_MSENC,
51         NVKM_ENGINE_MSPDEC,
52         NVKM_ENGINE_MSPPP,
53         NVKM_ENGINE_MSVLD,
54
55         NVKM_ENGINE_NVENC0,
56         NVKM_ENGINE_NVENC1,
57         NVKM_ENGINE_NVENC2,
58         NVKM_ENGINE_NVENC_LAST = NVKM_ENGINE_NVENC2,
59
60         NVKM_ENGINE_NVDEC,
61         NVKM_ENGINE_PM,
62         NVKM_ENGINE_SEC,
63         NVKM_ENGINE_SEC2,
64         NVKM_ENGINE_SW,
65         NVKM_ENGINE_VIC,
66         NVKM_ENGINE_VP,
67
68         NVKM_SUBDEV_NR
69 };
70
71 enum nvkm_device_type {
72         NVKM_DEVICE_PCI,
73         NVKM_DEVICE_AGP,
74         NVKM_DEVICE_PCIE,
75         NVKM_DEVICE_TEGRA,
76 };
77
78 struct nvkm_device {
79         const struct nvkm_device_func *func;
80         const struct nvkm_device_quirk *quirk;
81         struct device *dev;
82         enum nvkm_device_type type;
83         u64 handle;
84         const char *name;
85         const char *cfgopt;
86         const char *dbgopt;
87
88         struct list_head head;
89         struct mutex mutex;
90         int refcount;
91
92         void __iomem *pri;
93
94         struct nvkm_event event;
95
96         u64 disable_mask;
97         u32 debug;
98
99         const struct nvkm_device_chip *chip;
100         enum {
101                 NV_04    = 0x04,
102                 NV_10    = 0x10,
103                 NV_11    = 0x11,
104                 NV_20    = 0x20,
105                 NV_30    = 0x30,
106                 NV_40    = 0x40,
107                 NV_50    = 0x50,
108                 NV_C0    = 0xc0,
109                 NV_E0    = 0xe0,
110                 GM100    = 0x110,
111                 GP100    = 0x130,
112         } card_type;
113         u32 chipset;
114         u8  chiprev;
115         u32 crystal;
116
117         struct {
118                 struct notifier_block nb;
119         } acpi;
120
121         struct nvkm_bar *bar;
122         struct nvkm_bios *bios;
123         struct nvkm_bus *bus;
124         struct nvkm_clk *clk;
125         struct nvkm_devinit *devinit;
126         struct nvkm_fb *fb;
127         struct nvkm_fuse *fuse;
128         struct nvkm_gpio *gpio;
129         struct nvkm_i2c *i2c;
130         struct nvkm_subdev *ibus;
131         struct nvkm_iccsense *iccsense;
132         struct nvkm_instmem *imem;
133         struct nvkm_ltc *ltc;
134         struct nvkm_mc *mc;
135         struct nvkm_mmu *mmu;
136         struct nvkm_subdev *mxm;
137         struct nvkm_pci *pci;
138         struct nvkm_pmu *pmu;
139         struct nvkm_secboot *secboot;
140         struct nvkm_therm *therm;
141         struct nvkm_timer *timer;
142         struct nvkm_top *top;
143         struct nvkm_volt *volt;
144
145         struct nvkm_engine *bsp;
146         struct nvkm_engine *ce[6];
147         struct nvkm_engine *cipher;
148         struct nvkm_disp *disp;
149         struct nvkm_dma *dma;
150         struct nvkm_fifo *fifo;
151         struct nvkm_gr *gr;
152         struct nvkm_engine *ifb;
153         struct nvkm_engine *me;
154         struct nvkm_engine *mpeg;
155         struct nvkm_engine *msenc;
156         struct nvkm_engine *mspdec;
157         struct nvkm_engine *msppp;
158         struct nvkm_engine *msvld;
159         struct nvkm_engine *nvenc[3];
160         struct nvkm_nvdec *nvdec;
161         struct nvkm_pm *pm;
162         struct nvkm_engine *sec;
163         struct nvkm_sec2 *sec2;
164         struct nvkm_sw *sw;
165         struct nvkm_engine *vic;
166         struct nvkm_engine *vp;
167 };
168
169 struct nvkm_subdev *nvkm_device_subdev(struct nvkm_device *, int index);
170 struct nvkm_engine *nvkm_device_engine(struct nvkm_device *, int index);
171
172 struct nvkm_device_func {
173         struct nvkm_device_pci *(*pci)(struct nvkm_device *);
174         struct nvkm_device_tegra *(*tegra)(struct nvkm_device *);
175         void *(*dtor)(struct nvkm_device *);
176         int (*preinit)(struct nvkm_device *);
177         int (*init)(struct nvkm_device *);
178         void (*fini)(struct nvkm_device *, bool suspend);
179         resource_size_t (*resource_addr)(struct nvkm_device *, unsigned bar);
180         resource_size_t (*resource_size)(struct nvkm_device *, unsigned bar);
181         bool cpu_coherent;
182 };
183
184 struct nvkm_device_quirk {
185         u8 tv_pin_mask;
186         u8 tv_gpio;
187 };
188
189 struct nvkm_device_chip {
190         const char *name;
191
192         int (*bar     )(struct nvkm_device *, int idx, struct nvkm_bar **);
193         int (*bios    )(struct nvkm_device *, int idx, struct nvkm_bios **);
194         int (*bus     )(struct nvkm_device *, int idx, struct nvkm_bus **);
195         int (*clk     )(struct nvkm_device *, int idx, struct nvkm_clk **);
196         int (*devinit )(struct nvkm_device *, int idx, struct nvkm_devinit **);
197         int (*fb      )(struct nvkm_device *, int idx, struct nvkm_fb **);
198         int (*fuse    )(struct nvkm_device *, int idx, struct nvkm_fuse **);
199         int (*gpio    )(struct nvkm_device *, int idx, struct nvkm_gpio **);
200         int (*i2c     )(struct nvkm_device *, int idx, struct nvkm_i2c **);
201         int (*ibus    )(struct nvkm_device *, int idx, struct nvkm_subdev **);
202         int (*iccsense)(struct nvkm_device *, int idx, struct nvkm_iccsense **);
203         int (*imem    )(struct nvkm_device *, int idx, struct nvkm_instmem **);
204         int (*ltc     )(struct nvkm_device *, int idx, struct nvkm_ltc **);
205         int (*mc      )(struct nvkm_device *, int idx, struct nvkm_mc **);
206         int (*mmu     )(struct nvkm_device *, int idx, struct nvkm_mmu **);
207         int (*mxm     )(struct nvkm_device *, int idx, struct nvkm_subdev **);
208         int (*pci     )(struct nvkm_device *, int idx, struct nvkm_pci **);
209         int (*pmu     )(struct nvkm_device *, int idx, struct nvkm_pmu **);
210         int (*secboot )(struct nvkm_device *, int idx, struct nvkm_secboot **);
211         int (*therm   )(struct nvkm_device *, int idx, struct nvkm_therm **);
212         int (*timer   )(struct nvkm_device *, int idx, struct nvkm_timer **);
213         int (*top     )(struct nvkm_device *, int idx, struct nvkm_top **);
214         int (*volt    )(struct nvkm_device *, int idx, struct nvkm_volt **);
215
216         int (*bsp     )(struct nvkm_device *, int idx, struct nvkm_engine **);
217         int (*ce[6]   )(struct nvkm_device *, int idx, struct nvkm_engine **);
218         int (*cipher  )(struct nvkm_device *, int idx, struct nvkm_engine **);
219         int (*disp    )(struct nvkm_device *, int idx, struct nvkm_disp **);
220         int (*dma     )(struct nvkm_device *, int idx, struct nvkm_dma **);
221         int (*fifo    )(struct nvkm_device *, int idx, struct nvkm_fifo **);
222         int (*gr      )(struct nvkm_device *, int idx, struct nvkm_gr **);
223         int (*ifb     )(struct nvkm_device *, int idx, struct nvkm_engine **);
224         int (*me      )(struct nvkm_device *, int idx, struct nvkm_engine **);
225         int (*mpeg    )(struct nvkm_device *, int idx, struct nvkm_engine **);
226         int (*msenc   )(struct nvkm_device *, int idx, struct nvkm_engine **);
227         int (*mspdec  )(struct nvkm_device *, int idx, struct nvkm_engine **);
228         int (*msppp   )(struct nvkm_device *, int idx, struct nvkm_engine **);
229         int (*msvld   )(struct nvkm_device *, int idx, struct nvkm_engine **);
230         int (*nvenc[3])(struct nvkm_device *, int idx, struct nvkm_engine **);
231         int (*nvdec   )(struct nvkm_device *, int idx, struct nvkm_nvdec **);
232         int (*pm      )(struct nvkm_device *, int idx, struct nvkm_pm **);
233         int (*sec     )(struct nvkm_device *, int idx, struct nvkm_engine **);
234         int (*sec2    )(struct nvkm_device *, int idx, struct nvkm_sec2 **);
235         int (*sw      )(struct nvkm_device *, int idx, struct nvkm_sw **);
236         int (*vic     )(struct nvkm_device *, int idx, struct nvkm_engine **);
237         int (*vp      )(struct nvkm_device *, int idx, struct nvkm_engine **);
238 };
239
240 struct nvkm_device *nvkm_device_find(u64 name);
241 int nvkm_device_list(u64 *name, int size);
242
243 /* privileged register interface accessor macros */
244 #define nvkm_rd08(d,a) ioread8((d)->pri + (a))
245 #define nvkm_rd16(d,a) ioread16_native((d)->pri + (a))
246 #define nvkm_rd32(d,a) ioread32_native((d)->pri + (a))
247 #define nvkm_wr08(d,a,v) iowrite8((v), (d)->pri + (a))
248 #define nvkm_wr16(d,a,v) iowrite16_native((v), (d)->pri + (a))
249 #define nvkm_wr32(d,a,v) iowrite32_native((v), (d)->pri + (a))
250 #define nvkm_mask(d,a,m,v) ({                                                  \
251         struct nvkm_device *_device = (d);                                     \
252         u32 _addr = (a), _temp = nvkm_rd32(_device, _addr);                    \
253         nvkm_wr32(_device, _addr, (_temp & ~(m)) | (v));                       \
254         _temp;                                                                 \
255 })
256
257 void nvkm_device_del(struct nvkm_device **);
258
259 struct nvkm_device_oclass {
260         int (*ctor)(struct nvkm_device *, const struct nvkm_oclass *,
261                     void *data, u32 size, struct nvkm_object **);
262         struct nvkm_sclass base;
263 };
264
265 extern const struct nvkm_sclass nvkm_udevice_sclass;
266
267 /* device logging */
268 #define nvdev_printk_(d,l,p,f,a...) do {                                       \
269         const struct nvkm_device *_device = (d);                               \
270         if (_device->debug >= (l))                                             \
271                 dev_##p(_device->dev, f, ##a);                                 \
272 } while(0)
273 #define nvdev_printk(d,l,p,f,a...) nvdev_printk_((d), NV_DBG_##l, p, f, ##a)
274 #define nvdev_fatal(d,f,a...) nvdev_printk((d), FATAL,   crit, f, ##a)
275 #define nvdev_error(d,f,a...) nvdev_printk((d), ERROR,    err, f, ##a)
276 #define nvdev_warn(d,f,a...)  nvdev_printk((d),  WARN, notice, f, ##a)
277 #define nvdev_info(d,f,a...)  nvdev_printk((d),  INFO,   info, f, ##a)
278 #define nvdev_debug(d,f,a...) nvdev_printk((d), DEBUG,   info, f, ##a)
279 #define nvdev_trace(d,f,a...) nvdev_printk((d), TRACE,   info, f, ##a)
280 #define nvdev_spam(d,f,a...)  nvdev_printk((d),  SPAM,    dbg, f, ##a)
281 #endif