2 * Copyright 2005 Stephane Marchesin.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
25 #ifndef __NOUVEAU_DRV_H__
26 #define __NOUVEAU_DRV_H__
28 #define DRIVER_AUTHOR "Stephane Marchesin"
29 #define DRIVER_EMAIL "dri-devel@lists.sourceforge.net"
31 #define DRIVER_NAME "nouveau"
32 #define DRIVER_DESC "nVidia Riva/TNT/GeForce"
33 #define DRIVER_DATE "20060213"
35 #define DRIVER_MAJOR 0
36 #define DRIVER_MINOR 0
37 #define DRIVER_PATCHLEVEL 9
39 #define NOUVEAU_FAMILY 0x0000FFFF
40 #define NOUVEAU_FLAGS 0xFFFF0000
42 #include "nouveau_drm.h"
43 #include "nouveau_reg.h"
46 struct mem_block *next;
47 struct mem_block *prev;
50 DRMFILE filp; /* 0: free, -1: heap, other: real files */
53 drm_handle_t map_handle;
57 NV_NFORCE =0x10000000,
58 NV_NFORCE2 =0x20000000
61 #define NVOBJ_ENGINE_SW 0
62 #define NVOBJ_ENGINE_GR 1
63 #define NVOBJ_ENGINE_INT 0xdeadbeef
65 #define NVOBJ_FLAG_ALLOW_NO_REFS (1 << 0)
66 #define NVOBJ_FLAG_ZERO_ALLOC (1 << 1)
67 #define NVOBJ_FLAG_ZERO_FREE (1 << 2)
68 #define NVOBJ_FLAG_FAKE (1 << 3)
69 struct nouveau_gpuobj {
70 struct nouveau_gpuobj *next;
71 struct nouveau_gpuobj *prev;
74 struct mem_block *im_pramin;
75 struct mem_block *im_backing;
85 struct nouveau_gpuobj_ref {
86 struct nouveau_gpuobj_ref *next;
88 struct nouveau_gpuobj *gpuobj;
97 /* owner of this fifo */
99 /* mapping of the fifo itself */
100 drm_local_map_t *map;
101 /* mapping of the regs controling the fifo */
102 drm_local_map_t *regs;
104 /* DMA push buffer */
105 struct nouveau_gpuobj_ref *pushbuf;
106 struct mem_block *pushbuf_mem;
107 uint32_t pushbuf_base;
109 /* Notifier memory */
110 struct mem_block *notifier_block;
111 struct mem_block *notifier_heap;
112 drm_local_map_t *notifier_map;
115 struct nouveau_gpuobj_ref *ramfc;
118 struct nouveau_gpuobj_ref *ramin_grctx;
119 uint32_t pgraph_ctx [340]; /* XXX dynamic alloc ? */
122 struct nouveau_gpuobj *vm_pd;
123 struct nouveau_gpuobj_ref *vm_gart_pt;
126 struct nouveau_gpuobj_ref *ramin; /* Private instmem */
127 struct mem_block *ramin_heap; /* Private PRAMIN heap */
128 struct nouveau_gpuobj_ref *ramht; /* Hash table */
129 struct nouveau_gpuobj_ref *ramht_refs; /* Objects referenced by RAMHT */
132 struct nouveau_config {
139 struct nouveau_engine_func {
143 int (*init)(struct drm_device *dev);
144 void (*takedown)(struct drm_device *dev);
146 int (*populate)(struct drm_device *, struct nouveau_gpuobj *,
148 void (*clear)(struct drm_device *, struct nouveau_gpuobj *);
149 int (*bind)(struct drm_device *, struct nouveau_gpuobj *);
150 int (*unbind)(struct drm_device *, struct nouveau_gpuobj *);
154 int (*init)(struct drm_device *dev);
155 void (*takedown)(struct drm_device *dev);
159 int (*init)(struct drm_device *dev);
160 void (*takedown)(struct drm_device *dev);
164 int (*init)(struct drm_device *dev);
165 void (*takedown)(struct drm_device *dev);
169 int (*init)(struct drm_device *);
170 void (*takedown)(struct drm_device *);
172 int (*create_context)(struct drm_device *, int channel);
173 void (*destroy_context)(struct drm_device *, int channel);
174 int (*load_context)(struct drm_device *, int channel);
175 int (*save_context)(struct drm_device *, int channel);
181 int (*init)(struct drm_device *);
182 void (*takedown)(struct drm_device *);
184 int (*create_context)(struct drm_device *, int channel);
185 void (*destroy_context)(struct drm_device *, int channel);
186 int (*load_context)(struct drm_device *, int channel);
187 int (*save_context)(struct drm_device *, int channel);
191 struct drm_nouveau_private {
193 NOUVEAU_CARD_INIT_DOWN,
194 NOUVEAU_CARD_INIT_DONE,
195 NOUVEAU_CARD_INIT_FAILED
198 /* the card type, takes NV_* as values */
200 /* exact chipset, derived from NV_PMC_BOOT_0 */
204 drm_local_map_t *mmio;
206 drm_local_map_t *ramin; /* NV40 onwards */
208 int fifo_alloc_count;
209 struct nouveau_fifo *fifos[NV_MAX_FIFO_NUMBER];
211 struct nouveau_engine_func Engine;
213 /* RAMIN configuration, RAMFC, RAMHT and RAMRO offsets */
214 struct nouveau_gpuobj *ramht;
215 uint32_t ramin_rsvd_vram;
216 uint32_t ramht_offset;
219 uint32_t ramfc_offset;
221 uint32_t ramro_offset;
224 /* base physical adresses */
226 uint64_t fb_available_size;
230 NOUVEAU_GART_NONE = 0,
237 struct nouveau_gpuobj *sg_ctxdma;
238 struct page *sg_dummy_page;
239 dma_addr_t sg_dummy_bus;
242 struct drm_ttm_backend *sg_be;
243 unsigned long sg_handle;
246 /* the mtrr covering the FB */
249 struct mem_block *agp_heap;
250 struct mem_block *fb_heap;
251 struct mem_block *fb_nomap_heap;
252 struct mem_block *ramin_heap;
253 struct mem_block *pci_heap;
255 /* context table pointed to be NV_PGRAPH_CHANNEL_CTX_TABLE (0x400780) */
256 uint32_t ctx_table_size;
257 struct nouveau_gpuobj_ref *ctx_table;
259 struct nouveau_config config;
261 struct nouveau_gpuobj *gpuobj_all;
264 /* nouveau_state.c */
265 extern void nouveau_preclose(struct drm_device * dev, DRMFILE filp);
266 extern int nouveau_load(struct drm_device *dev, unsigned long flags);
267 extern int nouveau_firstopen(struct drm_device *dev);
268 extern void nouveau_lastclose(struct drm_device *dev);
269 extern int nouveau_unload(struct drm_device *dev);
270 extern int nouveau_ioctl_getparam(DRM_IOCTL_ARGS);
271 extern int nouveau_ioctl_setparam(DRM_IOCTL_ARGS);
272 extern void nouveau_wait_for_idle(struct drm_device *dev);
273 extern int nouveau_ioctl_card_init(DRM_IOCTL_ARGS);
276 extern int nouveau_mem_init_heap(struct mem_block **,
277 uint64_t start, uint64_t size);
278 extern struct mem_block *nouveau_mem_alloc_block(struct mem_block *,
279 uint64_t size, int align2,
281 extern void nouveau_mem_takedown(struct mem_block **heap);
282 extern void nouveau_mem_free_block(struct mem_block *);
283 extern uint64_t nouveau_mem_fb_amount(struct drm_device *dev);
284 extern void nouveau_mem_release(DRMFILE filp, struct mem_block *heap);
285 extern int nouveau_ioctl_mem_alloc(DRM_IOCTL_ARGS);
286 extern int nouveau_ioctl_mem_free(DRM_IOCTL_ARGS);
287 extern struct mem_block* nouveau_mem_alloc(struct drm_device *dev, int alignment, uint64_t size, int flags, DRMFILE filp);
288 extern void nouveau_mem_free(struct drm_device* dev, struct mem_block*);
289 extern int nouveau_mem_init(struct drm_device *dev);
290 extern void nouveau_mem_close(struct drm_device *dev);
292 /* nouveau_notifier.c */
293 extern int nouveau_notifier_init_channel(struct drm_device *, int channel, DRMFILE);
294 extern void nouveau_notifier_takedown_channel(struct drm_device *, int channel);
295 extern int nouveau_notifier_alloc(struct drm_device *, int channel,
296 uint32_t handle, int cout, uint32_t *offset);
297 extern int nouveau_ioctl_notifier_alloc(DRM_IOCTL_ARGS);
300 extern int nouveau_fifo_init(struct drm_device *dev);
301 extern int nouveau_fifo_number(struct drm_device *dev);
302 extern int nouveau_fifo_ctx_size(struct drm_device *dev);
303 extern void nouveau_fifo_cleanup(struct drm_device *dev, DRMFILE filp);
304 extern int nouveau_fifo_owner(struct drm_device *dev, DRMFILE filp, int channel);
305 extern void nouveau_fifo_free(struct drm_device *dev, int channel);
307 /* nouveau_object.c */
308 extern void nouveau_gpuobj_takedown(struct drm_device *dev);
309 extern int nouveau_gpuobj_channel_init(struct drm_device *, int channel,
310 uint32_t vram_h, uint32_t tt_h);
311 extern void nouveau_gpuobj_channel_takedown(struct drm_device *, int channel);
312 extern int nouveau_gpuobj_new(struct drm_device *, int channel, int size, int align,
313 uint32_t flags, struct nouveau_gpuobj **);
314 extern int nouveau_gpuobj_del(struct drm_device *, struct nouveau_gpuobj **);
315 extern int nouveau_gpuobj_ref_add(struct drm_device *, int channel, uint32_t handle,
316 struct nouveau_gpuobj *,
317 struct nouveau_gpuobj_ref **);
318 extern int nouveau_gpuobj_ref_del(struct drm_device *, struct nouveau_gpuobj_ref **);
319 extern int nouveau_gpuobj_new_ref(struct drm_device *, int chan_obj, int chan_ref,
320 uint32_t handle, int size, int align,
321 uint32_t flags, struct nouveau_gpuobj_ref **);
322 extern int nouveau_gpuobj_new_fake(struct drm_device *, uint32_t offset,
323 uint32_t size, uint32_t flags,
324 struct nouveau_gpuobj**,
325 struct nouveau_gpuobj_ref**);
326 extern int nouveau_gpuobj_dma_new(struct drm_device *, int channel, int class,
327 uint64_t offset, uint64_t size,
328 int access, int target,
329 struct nouveau_gpuobj **);
330 extern int nouveau_gpuobj_gart_dma_new(struct drm_device *, int channel,
331 uint64_t offset, uint64_t size,
332 int access, struct nouveau_gpuobj **,
334 extern int nouveau_gpuobj_gr_new(struct drm_device *, int channel, int class,
335 struct nouveau_gpuobj **);
336 extern int nouveau_ioctl_grobj_alloc(DRM_IOCTL_ARGS);
339 extern irqreturn_t nouveau_irq_handler(DRM_IRQ_ARGS);
340 extern void nouveau_irq_preinstall(struct drm_device*);
341 extern void nouveau_irq_postinstall(struct drm_device*);
342 extern void nouveau_irq_uninstall(struct drm_device*);
344 /* nouveau_sgdma.c */
345 extern int nouveau_sgdma_init(struct drm_device *);
346 extern void nouveau_sgdma_takedown(struct drm_device *);
347 extern struct drm_ttm_backend *nouveau_sgdma_init_ttm(struct drm_device *);
348 extern int nouveau_sgdma_nottm_hack_init(struct drm_device *);
349 extern void nouveau_sgdma_nottm_hack_takedown(struct drm_device *);
352 extern int nv04_fb_init(struct drm_device *dev);
353 extern void nv04_fb_takedown(struct drm_device *dev);
356 extern int nv10_fb_init(struct drm_device *dev);
357 extern void nv10_fb_takedown(struct drm_device *dev);
360 extern int nv40_fb_init(struct drm_device *dev);
361 extern void nv40_fb_takedown(struct drm_device *dev);
364 extern int nv04_fifo_create_context(struct drm_device *dev, int channel);
365 extern void nv04_fifo_destroy_context(struct drm_device *dev, int channel);
366 extern int nv04_fifo_load_context(struct drm_device *dev, int channel);
367 extern int nv04_fifo_save_context(struct drm_device *dev, int channel);
370 extern int nv10_fifo_create_context(struct drm_device *dev, int channel);
371 extern void nv10_fifo_destroy_context(struct drm_device *dev, int channel);
372 extern int nv10_fifo_load_context(struct drm_device *dev, int channel);
373 extern int nv10_fifo_save_context(struct drm_device *dev, int channel);
376 extern int nv40_fifo_create_context(struct drm_device *, int channel);
377 extern void nv40_fifo_destroy_context(struct drm_device *, int channel);
378 extern int nv40_fifo_load_context(struct drm_device *, int channel);
379 extern int nv40_fifo_save_context(struct drm_device *, int channel);
382 extern int nv50_fifo_init(struct drm_device *);
383 extern void nv50_fifo_takedown(struct drm_device *);
384 extern int nv50_fifo_create_context(struct drm_device *, int channel);
385 extern void nv50_fifo_destroy_context(struct drm_device *, int channel);
386 extern int nv50_fifo_load_context(struct drm_device *, int channel);
387 extern int nv50_fifo_save_context(struct drm_device *, int channel);
390 extern void nouveau_nv04_context_switch(struct drm_device *dev);
391 extern int nv04_graph_init(struct drm_device *dev);
392 extern void nv04_graph_takedown(struct drm_device *dev);
393 extern int nv04_graph_create_context(struct drm_device *dev, int channel);
394 extern void nv04_graph_destroy_context(struct drm_device *dev, int channel);
395 extern int nv04_graph_load_context(struct drm_device *dev, int channel);
396 extern int nv04_graph_save_context(struct drm_device *dev, int channel);
399 extern void nouveau_nv10_context_switch(struct drm_device *dev);
400 extern int nv10_graph_init(struct drm_device *dev);
401 extern void nv10_graph_takedown(struct drm_device *dev);
402 extern int nv10_graph_create_context(struct drm_device *dev, int channel);
403 extern void nv10_graph_destroy_context(struct drm_device *dev, int channel);
404 extern int nv10_graph_load_context(struct drm_device *dev, int channel);
405 extern int nv10_graph_save_context(struct drm_device *dev, int channel);
408 extern void nouveau_nv20_context_switch(struct drm_device *dev);
409 extern int nv20_graph_init(struct drm_device *dev);
410 extern void nv20_graph_takedown(struct drm_device *dev);
411 extern int nv20_graph_create_context(struct drm_device *dev, int channel);
412 extern void nv20_graph_destroy_context(struct drm_device *dev, int channel);
413 extern int nv20_graph_load_context(struct drm_device *dev, int channel);
414 extern int nv20_graph_save_context(struct drm_device *dev, int channel);
417 extern int nv30_graph_init(struct drm_device *dev);
418 extern void nv30_graph_takedown(struct drm_device *dev);
419 extern int nv30_graph_create_context(struct drm_device *, int channel);
420 extern void nv30_graph_destroy_context(struct drm_device *, int channel);
421 extern int nv30_graph_load_context(struct drm_device *, int channel);
422 extern int nv30_graph_save_context(struct drm_device *, int channel);
425 extern int nv40_graph_init(struct drm_device *);
426 extern void nv40_graph_takedown(struct drm_device *);
427 extern int nv40_graph_create_context(struct drm_device *, int channel);
428 extern void nv40_graph_destroy_context(struct drm_device *, int channel);
429 extern int nv40_graph_load_context(struct drm_device *, int channel);
430 extern int nv40_graph_save_context(struct drm_device *, int channel);
433 extern int nv50_graph_init(struct drm_device *);
434 extern void nv50_graph_takedown(struct drm_device *);
435 extern int nv50_graph_create_context(struct drm_device *, int channel);
436 extern void nv50_graph_destroy_context(struct drm_device *, int channel);
437 extern int nv50_graph_load_context(struct drm_device *, int channel);
438 extern int nv50_graph_save_context(struct drm_device *, int channel);
441 extern int nv04_instmem_init(struct drm_device *dev);
442 extern void nv04_instmem_takedown(struct drm_device *dev);
443 extern int nv04_instmem_populate(struct drm_device*, struct nouveau_gpuobj*,
445 extern void nv04_instmem_clear(struct drm_device*, struct nouveau_gpuobj*);
446 extern int nv04_instmem_bind(struct drm_device*, struct nouveau_gpuobj*);
447 extern int nv04_instmem_unbind(struct drm_device*, struct nouveau_gpuobj*);
450 extern int nv50_instmem_init(struct drm_device *dev);
451 extern void nv50_instmem_takedown(struct drm_device *dev);
452 extern int nv50_instmem_populate(struct drm_device*, struct nouveau_gpuobj*,
454 extern void nv50_instmem_clear(struct drm_device*, struct nouveau_gpuobj*);
455 extern int nv50_instmem_bind(struct drm_device*, struct nouveau_gpuobj*);
456 extern int nv50_instmem_unbind(struct drm_device*, struct nouveau_gpuobj*);
459 extern int nv04_mc_init(struct drm_device *dev);
460 extern void nv04_mc_takedown(struct drm_device *dev);
463 extern int nv40_mc_init(struct drm_device *dev);
464 extern void nv40_mc_takedown(struct drm_device *dev);
467 extern int nv50_mc_init(struct drm_device *dev);
468 extern void nv50_mc_takedown(struct drm_device *dev);
471 extern int nv04_timer_init(struct drm_device *dev);
472 extern void nv04_timer_takedown(struct drm_device *dev);
474 extern long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
477 #if defined(__powerpc__)
478 #define NV_READ(reg) in_be32((void __iomem *)(dev_priv->mmio)->handle + (reg) )
479 #define NV_WRITE(reg,val) out_be32((void __iomem *)(dev_priv->mmio)->handle + (reg) , (val) )
481 #define NV_READ(reg) DRM_READ32( dev_priv->mmio, (reg) )
482 #define NV_WRITE(reg,val) DRM_WRITE32( dev_priv->mmio, (reg), (val) )
486 #if defined(__powerpc__)
487 #define NV_RI32(o) in_be32((void __iomem *)(dev_priv->ramin)->handle+(o))
488 #define NV_WI32(o,v) out_be32((void __iomem*)(dev_priv->ramin)->handle+(o), (v))
490 #define NV_RI32(o) DRM_READ32(dev_priv->ramin, (o))
491 #define NV_WI32(o,v) DRM_WRITE32(dev_priv->ramin, (o), (v))
494 #define INSTANCE_RD(o,i) NV_RI32((o)->im_pramin->start + ((i)<<2))
495 #define INSTANCE_WR(o,i,v) NV_WI32((o)->im_pramin->start + ((i)<<2), (v))
497 #endif /* __NOUVEAU_DRV_H__ */