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 10
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 struct drm_file *file_priv; /* NULL: 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 list_head list;
73 struct mem_block *im_pramin;
74 struct mem_block *im_backing;
83 void (*dtor)(struct drm_device *, struct nouveau_gpuobj *);
87 struct nouveau_gpuobj_ref {
88 struct list_head list;
90 struct nouveau_gpuobj *gpuobj;
97 struct nouveau_channel
99 struct drm_device *dev;
102 /* owner of this fifo */
103 struct drm_file *file_priv;
104 /* mapping of the fifo itself */
105 drm_local_map_t *map;
106 /* mapping of the regs controling the fifo */
107 drm_local_map_t *regs;
110 uint32_t next_sequence;
112 /* DMA push buffer */
113 struct nouveau_gpuobj_ref *pushbuf;
114 struct mem_block *pushbuf_mem;
115 uint32_t pushbuf_base;
117 /* FIFO user control regs */
118 uint32_t user, user_size;
123 /* Notifier memory */
124 struct mem_block *notifier_block;
125 struct mem_block *notifier_heap;
126 drm_local_map_t *notifier_map;
129 struct nouveau_gpuobj_ref *ramfc;
132 /* XXX may be merge 2 pointers as private data ??? */
133 struct nouveau_gpuobj_ref *ramin_grctx;
137 struct nouveau_gpuobj *vm_pd;
138 struct nouveau_gpuobj_ref *vm_gart_pt;
139 struct nouveau_gpuobj_ref *vm_vram_pt;
142 struct nouveau_gpuobj_ref *ramin; /* Private instmem */
143 struct mem_block *ramin_heap; /* Private PRAMIN heap */
144 struct nouveau_gpuobj_ref *ramht; /* Hash table */
145 struct list_head ramht_refs; /* Objects referenced by RAMHT */
148 struct nouveau_drm_channel {
149 struct nouveau_channel *chan;
152 int max, put, cur, free;
154 volatile uint32_t *pushbuf;
157 uint32_t notify0_offset;
160 uint32_t m2mf_dma_source;
161 uint32_t m2mf_dma_destin;
164 struct nouveau_config {
171 struct nouveau_instmem_engine {
174 int (*init)(struct drm_device *dev);
175 void (*takedown)(struct drm_device *dev);
177 int (*populate)(struct drm_device *, struct nouveau_gpuobj *,
179 void (*clear)(struct drm_device *, struct nouveau_gpuobj *);
180 int (*bind)(struct drm_device *, struct nouveau_gpuobj *);
181 int (*unbind)(struct drm_device *, struct nouveau_gpuobj *);
184 struct nouveau_mc_engine {
185 int (*init)(struct drm_device *dev);
186 void (*takedown)(struct drm_device *dev);
189 struct nouveau_timer_engine {
190 int (*init)(struct drm_device *dev);
191 void (*takedown)(struct drm_device *dev);
192 uint64_t (*read)(struct drm_device *dev);
195 struct nouveau_fb_engine {
196 int (*init)(struct drm_device *dev);
197 void (*takedown)(struct drm_device *dev);
200 struct nouveau_fifo_engine {
205 int (*init)(struct drm_device *);
206 void (*takedown)(struct drm_device *);
208 int (*channel_id)(struct drm_device *);
210 int (*create_context)(struct nouveau_channel *);
211 void (*destroy_context)(struct nouveau_channel *);
212 int (*load_context)(struct nouveau_channel *);
213 int (*save_context)(struct nouveau_channel *);
216 struct nouveau_pgraph_engine {
217 int (*init)(struct drm_device *);
218 void (*takedown)(struct drm_device *);
220 int (*create_context)(struct nouveau_channel *);
221 void (*destroy_context)(struct nouveau_channel *);
222 int (*load_context)(struct nouveau_channel *);
223 int (*save_context)(struct nouveau_channel *);
226 struct nouveau_engine {
227 struct nouveau_instmem_engine instmem;
228 struct nouveau_mc_engine mc;
229 struct nouveau_timer_engine timer;
230 struct nouveau_fb_engine fb;
231 struct nouveau_pgraph_engine graph;
232 struct nouveau_fifo_engine fifo;
235 #define NOUVEAU_MAX_CHANNEL_NR 128
236 struct drm_nouveau_private {
238 NOUVEAU_CARD_INIT_DOWN,
239 NOUVEAU_CARD_INIT_DONE,
240 NOUVEAU_CARD_INIT_FAILED
245 /* the card type, takes NV_* as values */
247 /* exact chipset, derived from NV_PMC_BOOT_0 */
251 drm_local_map_t *mmio;
253 drm_local_map_t *ramin; /* NV40 onwards */
255 int fifo_alloc_count;
256 struct nouveau_channel *fifos[NOUVEAU_MAX_CHANNEL_NR];
258 struct nouveau_engine Engine;
259 struct nouveau_drm_channel channel;
261 /* RAMIN configuration, RAMFC, RAMHT and RAMRO offsets */
262 struct nouveau_gpuobj *ramht;
263 uint32_t ramin_rsvd_vram;
264 uint32_t ramht_offset;
267 uint32_t ramfc_offset;
269 uint32_t ramro_offset;
272 /* base physical adresses */
274 uint64_t fb_available_size;
278 NOUVEAU_GART_NONE = 0,
285 struct nouveau_gpuobj *sg_ctxdma;
286 struct page *sg_dummy_page;
287 dma_addr_t sg_dummy_bus;
290 struct drm_ttm_backend *sg_be;
291 unsigned long sg_handle;
294 /* G8x global VRAM page table */
295 struct nouveau_gpuobj *vm_vram_pt;
297 /* the mtrr covering the FB */
300 struct mem_block *agp_heap;
301 struct mem_block *fb_heap;
302 struct mem_block *fb_nomap_heap;
303 struct mem_block *ramin_heap;
304 struct mem_block *pci_heap;
306 /* context table pointed to be NV_PGRAPH_CHANNEL_CTX_TABLE (0x400780) */
307 uint32_t ctx_table_size;
308 struct nouveau_gpuobj_ref *ctx_table;
310 struct nouveau_config config;
312 struct list_head gpuobj_list;
315 #define NOUVEAU_CHECK_INITIALISED_WITH_RETURN do { \
316 struct drm_nouveau_private *nv = dev->dev_private; \
317 if (nv->init_state != NOUVEAU_CARD_INIT_DONE) { \
318 DRM_ERROR("called without init\n"); \
323 #define NOUVEAU_GET_USER_CHANNEL_WITH_RETURN(id,cl,ch) do { \
324 struct drm_nouveau_private *nv = dev->dev_private; \
325 if (!nouveau_fifo_owner(dev, (cl), (id))) { \
326 DRM_ERROR("pid %d doesn't own channel %d\n", \
327 DRM_CURRENTPID, (id)); \
330 (ch) = nv->fifos[(id)]; \
333 /* nouveau_state.c */
334 extern void nouveau_preclose(struct drm_device *dev, struct drm_file *);
335 extern int nouveau_load(struct drm_device *, unsigned long flags);
336 extern int nouveau_firstopen(struct drm_device *);
337 extern void nouveau_lastclose(struct drm_device *);
338 extern int nouveau_unload(struct drm_device *);
339 extern int nouveau_ioctl_getparam(struct drm_device *, void *data,
341 extern int nouveau_ioctl_setparam(struct drm_device *, void *data,
343 extern void nouveau_wait_for_idle(struct drm_device *);
344 extern int nouveau_card_init(struct drm_device *);
345 extern int nouveau_ioctl_card_init(struct drm_device *, void *data,
349 extern int nouveau_mem_init_heap(struct mem_block **, uint64_t start,
351 extern struct mem_block *nouveau_mem_alloc_block(struct mem_block *,
352 uint64_t size, int align2,
354 extern void nouveau_mem_takedown(struct mem_block **heap);
355 extern void nouveau_mem_free_block(struct mem_block *);
356 extern uint64_t nouveau_mem_fb_amount(struct drm_device *);
357 extern void nouveau_mem_release(struct drm_file *, struct mem_block *heap);
358 extern int nouveau_ioctl_mem_alloc(struct drm_device *, void *data,
360 extern int nouveau_ioctl_mem_free(struct drm_device *, void *data,
362 extern struct mem_block* nouveau_mem_alloc(struct drm_device *,
363 int alignment, uint64_t size,
364 int flags, struct drm_file *);
365 extern void nouveau_mem_free(struct drm_device *dev, struct mem_block*);
366 extern int nouveau_mem_init(struct drm_device *);
367 extern int nouveau_mem_init_ttm(struct drm_device *);
368 extern void nouveau_mem_close(struct drm_device *);
370 /* nouveau_notifier.c */
371 extern int nouveau_notifier_init_channel(struct nouveau_channel *);
372 extern void nouveau_notifier_takedown_channel(struct nouveau_channel *);
373 extern int nouveau_notifier_alloc(struct nouveau_channel *, uint32_t handle,
374 int cout, uint32_t *offset);
375 extern int nouveau_ioctl_notifier_alloc(struct drm_device *, void *data,
377 extern int nouveau_ioctl_notifier_free(struct drm_device *, void *data,
381 extern int nouveau_fifo_init(struct drm_device *);
382 extern int nouveau_fifo_ctx_size(struct drm_device *);
383 extern void nouveau_fifo_cleanup(struct drm_device *, struct drm_file *);
384 extern int nouveau_fifo_owner(struct drm_device *, struct drm_file *,
386 extern int nouveau_fifo_alloc(struct drm_device *dev,
387 struct nouveau_channel **chan,
388 struct drm_file *file_priv,
389 struct mem_block *pushbuf,
390 uint32_t fb_ctxdma, uint32_t tt_ctxdma);
391 extern void nouveau_fifo_free(struct nouveau_channel *);
393 /* nouveau_object.c */
394 extern int nouveau_gpuobj_early_init(struct drm_device *);
395 extern int nouveau_gpuobj_init(struct drm_device *);
396 extern void nouveau_gpuobj_takedown(struct drm_device *);
397 extern void nouveau_gpuobj_late_takedown(struct drm_device *);
398 extern int nouveau_gpuobj_channel_init(struct nouveau_channel *,
399 uint32_t vram_h, uint32_t tt_h);
400 extern void nouveau_gpuobj_channel_takedown(struct nouveau_channel *);
401 extern int nouveau_gpuobj_new(struct drm_device *, struct nouveau_channel *,
402 int size, int align, uint32_t flags,
403 struct nouveau_gpuobj **);
404 extern int nouveau_gpuobj_del(struct drm_device *, struct nouveau_gpuobj **);
405 extern int nouveau_gpuobj_ref_add(struct drm_device *, struct nouveau_channel *,
406 uint32_t handle, struct nouveau_gpuobj *,
407 struct nouveau_gpuobj_ref **);
408 extern int nouveau_gpuobj_ref_del(struct drm_device *,
409 struct nouveau_gpuobj_ref **);
410 extern int nouveau_gpuobj_ref_find(struct nouveau_channel *, uint32_t handle,
411 struct nouveau_gpuobj_ref **ref_ret);
412 extern int nouveau_gpuobj_new_ref(struct drm_device *,
413 struct nouveau_channel *alloc_chan,
414 struct nouveau_channel *ref_chan,
415 uint32_t handle, int size, int align,
416 uint32_t flags, struct nouveau_gpuobj_ref **);
417 extern int nouveau_gpuobj_new_fake(struct drm_device *,
418 uint32_t p_offset, uint32_t b_offset,
419 uint32_t size, uint32_t flags,
420 struct nouveau_gpuobj **,
421 struct nouveau_gpuobj_ref**);
422 extern int nouveau_gpuobj_dma_new(struct nouveau_channel *, int class,
423 uint64_t offset, uint64_t size, int access,
424 int target, struct nouveau_gpuobj **);
425 extern int nouveau_gpuobj_gart_dma_new(struct nouveau_channel *,
426 uint64_t offset, uint64_t size,
427 int access, struct nouveau_gpuobj **,
429 extern int nouveau_gpuobj_gr_new(struct nouveau_channel *, int class,
430 struct nouveau_gpuobj **);
431 extern int nouveau_ioctl_grobj_alloc(struct drm_device *, void *data,
433 extern int nouveau_ioctl_gpuobj_free(struct drm_device *, void *data,
437 extern irqreturn_t nouveau_irq_handler(DRM_IRQ_ARGS);
438 extern void nouveau_irq_preinstall(struct drm_device *);
439 extern int nouveau_irq_postinstall(struct drm_device *);
440 extern void nouveau_irq_uninstall(struct drm_device *);
442 /* nouveau_sgdma.c */
443 extern int nouveau_sgdma_init(struct drm_device *);
444 extern void nouveau_sgdma_takedown(struct drm_device *);
445 extern int nouveau_sgdma_get_page(struct drm_device *, uint32_t offset,
447 extern struct drm_ttm_backend *nouveau_sgdma_init_ttm(struct drm_device *);
448 extern int nouveau_sgdma_nottm_hack_init(struct drm_device *);
449 extern void nouveau_sgdma_nottm_hack_takedown(struct drm_device *);
452 extern int nouveau_dma_channel_init(struct drm_device *);
453 extern void nouveau_dma_channel_takedown(struct drm_device *);
454 extern int nouveau_dma_wait(struct drm_device *, int size);
457 extern int nv04_fb_init(struct drm_device *);
458 extern void nv04_fb_takedown(struct drm_device *);
461 extern int nv10_fb_init(struct drm_device *);
462 extern void nv10_fb_takedown(struct drm_device *);
465 extern int nv40_fb_init(struct drm_device *);
466 extern void nv40_fb_takedown(struct drm_device *);
469 extern int nv04_fifo_channel_id(struct drm_device *);
470 extern int nv04_fifo_create_context(struct nouveau_channel *);
471 extern void nv04_fifo_destroy_context(struct nouveau_channel *);
472 extern int nv04_fifo_load_context(struct nouveau_channel *);
473 extern int nv04_fifo_save_context(struct nouveau_channel *);
476 extern int nv10_fifo_channel_id(struct drm_device *);
477 extern int nv10_fifo_create_context(struct nouveau_channel *);
478 extern void nv10_fifo_destroy_context(struct nouveau_channel *);
479 extern int nv10_fifo_load_context(struct nouveau_channel *);
480 extern int nv10_fifo_save_context(struct nouveau_channel *);
483 extern int nv40_fifo_init(struct drm_device *);
484 extern int nv40_fifo_create_context(struct nouveau_channel *);
485 extern void nv40_fifo_destroy_context(struct nouveau_channel *);
486 extern int nv40_fifo_load_context(struct nouveau_channel *);
487 extern int nv40_fifo_save_context(struct nouveau_channel *);
490 extern int nv50_fifo_init(struct drm_device *);
491 extern void nv50_fifo_takedown(struct drm_device *);
492 extern int nv50_fifo_channel_id(struct drm_device *);
493 extern int nv50_fifo_create_context(struct nouveau_channel *);
494 extern void nv50_fifo_destroy_context(struct nouveau_channel *);
495 extern int nv50_fifo_load_context(struct nouveau_channel *);
496 extern int nv50_fifo_save_context(struct nouveau_channel *);
499 extern void nouveau_nv04_context_switch(struct drm_device *);
500 extern int nv04_graph_init(struct drm_device *);
501 extern void nv04_graph_takedown(struct drm_device *);
502 extern int nv04_graph_create_context(struct nouveau_channel *);
503 extern void nv04_graph_destroy_context(struct nouveau_channel *);
504 extern int nv04_graph_load_context(struct nouveau_channel *);
505 extern int nv04_graph_save_context(struct nouveau_channel *);
508 extern void nouveau_nv10_context_switch(struct drm_device *);
509 extern int nv10_graph_init(struct drm_device *);
510 extern void nv10_graph_takedown(struct drm_device *);
511 extern int nv10_graph_create_context(struct nouveau_channel *);
512 extern void nv10_graph_destroy_context(struct nouveau_channel *);
513 extern int nv10_graph_load_context(struct nouveau_channel *);
514 extern int nv10_graph_save_context(struct nouveau_channel *);
517 extern int nv20_graph_create_context(struct nouveau_channel *);
518 extern void nv20_graph_destroy_context(struct nouveau_channel *);
519 extern int nv20_graph_load_context(struct nouveau_channel *);
520 extern int nv20_graph_save_context(struct nouveau_channel *);
521 extern int nv20_graph_init(struct drm_device *);
522 extern void nv20_graph_takedown(struct drm_device *);
523 extern int nv30_graph_init(struct drm_device *);
526 extern int nv40_graph_init(struct drm_device *);
527 extern void nv40_graph_takedown(struct drm_device *);
528 extern int nv40_graph_create_context(struct nouveau_channel *);
529 extern void nv40_graph_destroy_context(struct nouveau_channel *);
530 extern int nv40_graph_load_context(struct nouveau_channel *);
531 extern int nv40_graph_save_context(struct nouveau_channel *);
534 extern int nv50_graph_init(struct drm_device *);
535 extern void nv50_graph_takedown(struct drm_device *);
536 extern int nv50_graph_create_context(struct nouveau_channel *);
537 extern void nv50_graph_destroy_context(struct nouveau_channel *);
538 extern int nv50_graph_load_context(struct nouveau_channel *);
539 extern int nv50_graph_save_context(struct nouveau_channel *);
542 extern int nv04_instmem_init(struct drm_device *);
543 extern void nv04_instmem_takedown(struct drm_device *);
544 extern int nv04_instmem_populate(struct drm_device *, struct nouveau_gpuobj *,
546 extern void nv04_instmem_clear(struct drm_device *, struct nouveau_gpuobj *);
547 extern int nv04_instmem_bind(struct drm_device *, struct nouveau_gpuobj *);
548 extern int nv04_instmem_unbind(struct drm_device *, struct nouveau_gpuobj *);
551 extern int nv50_instmem_init(struct drm_device *);
552 extern void nv50_instmem_takedown(struct drm_device *);
553 extern int nv50_instmem_populate(struct drm_device *, struct nouveau_gpuobj *,
555 extern void nv50_instmem_clear(struct drm_device *, struct nouveau_gpuobj *);
556 extern int nv50_instmem_bind(struct drm_device *, struct nouveau_gpuobj *);
557 extern int nv50_instmem_unbind(struct drm_device *, struct nouveau_gpuobj *);
560 extern int nv04_mc_init(struct drm_device *);
561 extern void nv04_mc_takedown(struct drm_device *);
564 extern int nv40_mc_init(struct drm_device *);
565 extern void nv40_mc_takedown(struct drm_device *);
568 extern int nv50_mc_init(struct drm_device *);
569 extern void nv50_mc_takedown(struct drm_device *);
572 extern int nv04_timer_init(struct drm_device *);
573 extern uint64_t nv04_timer_read(struct drm_device *);
574 extern void nv04_timer_takedown(struct drm_device *);
576 extern long nouveau_compat_ioctl(struct file *file, unsigned int cmd,
579 /* nouveau_buffer.c */
580 extern struct drm_bo_driver nouveau_bo_driver;
582 /* nouveau_fence.c */
583 extern struct drm_fence_driver nouveau_fence_driver;
584 extern void nouveau_fence_handler(struct drm_device *dev, int channel);
586 #if defined(__powerpc__)
587 #define NV_READ(reg) in_be32((void __iomem *)(dev_priv->mmio)->handle + (reg) )
588 #define NV_WRITE(reg,val) out_be32((void __iomem *)(dev_priv->mmio)->handle + (reg) , (val) )
590 #define NV_READ(reg) DRM_READ32( dev_priv->mmio, (reg) )
591 #define NV_WRITE(reg,val) DRM_WRITE32( dev_priv->mmio, (reg), (val) )
595 #if defined(__powerpc__)
596 #define NV_RI32(o) in_be32((void __iomem *)(dev_priv->ramin)->handle+(o))
597 #define NV_WI32(o,v) out_be32((void __iomem*)(dev_priv->ramin)->handle+(o), (v))
599 #define NV_RI32(o) DRM_READ32(dev_priv->ramin, (o))
600 #define NV_WI32(o,v) DRM_WRITE32(dev_priv->ramin, (o), (v))
603 #define INSTANCE_RD(o,i) NV_RI32((o)->im_pramin->start + ((i)<<2))
604 #define INSTANCE_WR(o,i,v) NV_WI32((o)->im_pramin->start + ((i)<<2), (v))
606 #endif /* __NOUVEAU_DRV_H__ */