1 #ifndef __NVKM_DEVICE_H__
2 #define __NVKM_DEVICE_H__
3 #include <core/engine.h>
4 #include <core/event.h>
9 /* All subdevs from DEVINIT to DEVINIT_LAST will be created before
10 * *any* of them are initialised. This subdev category is used
11 * for any subdevs that the VBIOS init table parsing may call out
18 NVDEV_SUBDEV_DEVINIT_LAST
= NVDEV_SUBDEV_I2C
,
20 /* This grouping of subdevs are initialised right after they've
21 * been created, and are allowed to assume any subdevs in the
22 * list above them exist and have been initialised.
40 NVDEV_ENGINE_DMAOBJ
= NVDEV_ENGINE_FIRST
,
66 struct nvkm_engine engine
;
68 const struct nvkm_device_func
*func
;
69 const struct nvkm_device_quirk
*quirk
;
76 struct list_head head
;
81 struct platform_device
*platformdev
;
85 struct nvkm_event event
;
89 const struct nvkm_device_chip
*chip
;
106 struct nvkm_oclass
*oclass
[NVDEV_SUBDEV_NR
];
109 struct notifier_block nb
;
112 struct nvkm_bar
*bar
;
113 struct nvkm_bios
*bios
;
114 struct nvkm_bus
*bus
;
115 struct nvkm_clk
*clk
;
116 struct nvkm_devinit
*devinit
;
118 struct nvkm_fuse
*fuse
;
119 struct nvkm_gpio
*gpio
;
120 struct nvkm_i2c
*i2c
;
121 struct nvkm_subdev
*ibus
;
122 struct nvkm_instmem
*imem
;
123 struct nvkm_ltc
*ltc
;
125 struct nvkm_mmu
*mmu
;
126 struct nvkm_subdev
*mxm
;
127 struct nvkm_pmu
*pmu
;
128 struct nvkm_therm
*therm
;
129 struct nvkm_timer
*timer
;
130 struct nvkm_volt
*volt
;
132 struct nvkm_engine
*bsp
;
133 struct nvkm_engine
*ce
[3];
134 struct nvkm_engine
*cipher
;
135 struct nvkm_disp
*disp
;
136 struct nvkm_dma
*dma
;
137 struct nvkm_fifo
*fifo
;
139 struct nvkm_engine
*ifb
;
140 struct nvkm_engine
*me
;
141 struct nvkm_engine
*mpeg
;
142 struct nvkm_engine
*msenc
;
143 struct nvkm_engine
*mspdec
;
144 struct nvkm_engine
*msppp
;
145 struct nvkm_engine
*msvld
;
147 struct nvkm_engine
*sec
;
149 struct nvkm_engine
*vic
;
150 struct nvkm_engine
*vp
;
152 struct nouveau_platform_gpu
*gpu
;
155 struct nvkm_subdev
*nvkm_device_subdev(struct nvkm_device
*, int index
);
156 struct nvkm_engine
*nvkm_device_engine(struct nvkm_device
*, int index
);
158 struct nvkm_device_func
{
159 struct nvkm_device_pci
*(*pci
)(struct nvkm_device
*);
160 struct nvkm_device_tegra
*(*tegra
)(struct nvkm_device
*);
161 void *(*dtor
)(struct nvkm_device
*);
162 int (*preinit
)(struct nvkm_device
*);
163 void (*fini
)(struct nvkm_device
*, bool suspend
);
166 struct nvkm_device_quirk
{
169 struct nvkm_device_chip
{
172 int (*bar
)(struct nvkm_device
*, int idx
, struct nvkm_bar
**);
173 int (*bios
)(struct nvkm_device
*, int idx
, struct nvkm_bios
**);
174 int (*bus
)(struct nvkm_device
*, int idx
, struct nvkm_bus
**);
175 int (*clk
)(struct nvkm_device
*, int idx
, struct nvkm_clk
**);
176 int (*devinit
)(struct nvkm_device
*, int idx
, struct nvkm_devinit
**);
177 int (*fb
)(struct nvkm_device
*, int idx
, struct nvkm_fb
**);
178 int (*fuse
)(struct nvkm_device
*, int idx
, struct nvkm_fuse
**);
179 int (*gpio
)(struct nvkm_device
*, int idx
, struct nvkm_gpio
**);
180 int (*i2c
)(struct nvkm_device
*, int idx
, struct nvkm_i2c
**);
181 int (*ibus
)(struct nvkm_device
*, int idx
, struct nvkm_subdev
**);
182 int (*imem
)(struct nvkm_device
*, int idx
, struct nvkm_instmem
**);
183 int (*ltc
)(struct nvkm_device
*, int idx
, struct nvkm_ltc
**);
184 int (*mc
)(struct nvkm_device
*, int idx
, struct nvkm_mc
**);
185 int (*mmu
)(struct nvkm_device
*, int idx
, struct nvkm_mmu
**);
186 int (*mxm
)(struct nvkm_device
*, int idx
, struct nvkm_subdev
**);
187 int (*pmu
)(struct nvkm_device
*, int idx
, struct nvkm_pmu
**);
188 int (*therm
)(struct nvkm_device
*, int idx
, struct nvkm_therm
**);
189 int (*timer
)(struct nvkm_device
*, int idx
, struct nvkm_timer
**);
190 int (*volt
)(struct nvkm_device
*, int idx
, struct nvkm_volt
**);
192 int (*bsp
)(struct nvkm_device
*, int idx
, struct nvkm_engine
**);
193 int (*ce
[3] )(struct nvkm_device
*, int idx
, struct nvkm_engine
**);
194 int (*cipher
)(struct nvkm_device
*, int idx
, struct nvkm_engine
**);
195 int (*disp
)(struct nvkm_device
*, int idx
, struct nvkm_disp
**);
196 int (*dma
)(struct nvkm_device
*, int idx
, struct nvkm_dma
**);
197 int (*fifo
)(struct nvkm_device
*, int idx
, struct nvkm_fifo
**);
198 int (*gr
)(struct nvkm_device
*, int idx
, struct nvkm_gr
**);
199 int (*ifb
)(struct nvkm_device
*, int idx
, struct nvkm_engine
**);
200 int (*me
)(struct nvkm_device
*, int idx
, struct nvkm_engine
**);
201 int (*mpeg
)(struct nvkm_device
*, int idx
, struct nvkm_engine
**);
202 int (*msenc
)(struct nvkm_device
*, int idx
, struct nvkm_engine
**);
203 int (*mspdec
)(struct nvkm_device
*, int idx
, struct nvkm_engine
**);
204 int (*msppp
)(struct nvkm_device
*, int idx
, struct nvkm_engine
**);
205 int (*msvld
)(struct nvkm_device
*, int idx
, struct nvkm_engine
**);
206 int (*pm
)(struct nvkm_device
*, int idx
, struct nvkm_pm
**);
207 int (*sec
)(struct nvkm_device
*, int idx
, struct nvkm_engine
**);
208 int (*sw
)(struct nvkm_device
*, int idx
, struct nvkm_sw
**);
209 int (*vic
)(struct nvkm_device
*, int idx
, struct nvkm_engine
**);
210 int (*vp
)(struct nvkm_device
*, int idx
, struct nvkm_engine
**);
213 struct nvkm_device
*nvkm_device_find(u64 name
);
214 int nvkm_device_list(u64
*name
, int size
);
216 /* privileged register interface accessor macros */
217 #define nvkm_rd08(d,a) ioread8((d)->pri + (a))
218 #define nvkm_rd16(d,a) ioread16_native((d)->pri + (a))
219 #define nvkm_rd32(d,a) ioread32_native((d)->pri + (a))
220 #define nvkm_wr08(d,a,v) iowrite8((v), (d)->pri + (a))
221 #define nvkm_wr16(d,a,v) iowrite16_native((v), (d)->pri + (a))
222 #define nvkm_wr32(d,a,v) iowrite32_native((v), (d)->pri + (a))
223 #define nvkm_mask(d,a,m,v) ({ \
224 struct nvkm_device *_device = (d); \
225 u32 _addr = (a), _temp = nvkm_rd32(_device, _addr); \
226 nvkm_wr32(_device, _addr, (_temp & ~(m)) | (v)); \
230 struct nvkm_device
*nv_device(void *obj
);
233 nv_device_match(struct nvkm_device
*device
, u16 dev
, u16 ven
, u16 sub
)
235 return device
->pdev
->device
== dev
&&
236 device
->pdev
->subsystem_vendor
== ven
&&
237 device
->pdev
->subsystem_device
== sub
;
241 nv_device_is_pci(struct nvkm_device
*device
)
243 return device
->pdev
!= NULL
;
247 nv_device_is_cpu_coherent(struct nvkm_device
*device
)
249 return (!IS_ENABLED(CONFIG_ARM
) && nv_device_is_pci(device
));
252 static inline struct device
*
253 nv_device_base(struct nvkm_device
*device
)
255 return nv_device_is_pci(device
) ? &device
->pdev
->dev
:
256 &device
->platformdev
->dev
;
260 nv_device_resource_start(struct nvkm_device
*device
, unsigned int bar
);
263 nv_device_resource_len(struct nvkm_device
*device
, unsigned int bar
);
266 nv_device_get_irq(struct nvkm_device
*device
, bool stall
);
268 struct platform_device
;
275 void nvkm_device_del(struct nvkm_device
**);
277 struct nvkm_device_oclass
{
278 int (*ctor
)(struct nvkm_device
*, const struct nvkm_oclass
*,
279 void *data
, u32 size
, struct nvkm_object
**);
280 struct nvkm_sclass base
;
283 extern const struct nvkm_sclass nvkm_udevice_sclass
;
286 #define nvdev_printk_(d,l,p,f,a...) do { \
287 struct nvkm_device *_device = (d); \
288 if (_device->engine.subdev.debug >= (l)) \
289 dev_##p(_device->dev, f, ##a); \
291 #define nvdev_printk(d,l,p,f,a...) nvdev_printk_((d), NV_DBG_##l, p, f, ##a)
292 #define nvdev_fatal(d,f,a...) nvdev_printk((d), FATAL, crit, f, ##a)
293 #define nvdev_error(d,f,a...) nvdev_printk((d), ERROR, err, f, ##a)
294 #define nvdev_warn(d,f,a...) nvdev_printk((d), WARN, notice, f, ##a)
295 #define nvdev_info(d,f,a...) nvdev_printk((d), INFO, info, f, ##a)
296 #define nvdev_debug(d,f,a...) nvdev_printk((d), DEBUG, info, f, ##a)
297 #define nvdev_trace(d,f,a...) nvdev_printk((d), TRACE, info, f, ##a)
298 #define nvdev_spam(d,f,a...) nvdev_printk((d), SPAM, dbg, f, ##a)