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