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 7
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 */
56 NV_NFORCE =0x10000000,
57 NV_NFORCE2 =0x20000000
60 #define NVOBJ_ENGINE_SW 0
61 #define NVOBJ_ENGINE_GR 1
62 #define NVOBJ_ENGINE_INT 0xdeadbeef
64 #define NVOBJ_FLAG_ALLOW_NO_REFS (1 << 0)
65 #define NVOBJ_FLAG_ZERO_ALLOC (1 << 1)
66 #define NVOBJ_FLAG_ZERO_FREE (1 << 2)
67 #define NVOBJ_FLAG_FAKE (1 << 3)
68 typedef struct nouveau_gpuobj {
69 struct nouveau_gpuobj *next;
70 struct nouveau_gpuobj *prev;
73 struct mem_block *im_pramin;
74 struct mem_block *im_backing;
83 typedef struct nouveau_gpuobj_ref {
84 struct nouveau_gpuobj_ref *next;
86 nouveau_gpuobj_t *gpuobj;
91 } nouveau_gpuobj_ref_t;
96 /* owner of this fifo */
98 /* mapping of the fifo itself */
100 /* mapping of the regs controling the fifo */
101 drm_local_map_t *regs;
103 /* DMA push buffer */
104 struct mem_block *cmdbuf_mem;
105 nouveau_gpuobj_ref_t *pushbuf;
106 uint32_t pushbuf_base;
108 /* Notifier memory */
109 struct mem_block *notifier_block;
110 struct mem_block *notifier_heap;
111 drm_local_map_t *notifier_map;
114 nouveau_gpuobj_ref_t *ramfc;
117 nouveau_gpuobj_ref_t *ramin_grctx;
118 uint32_t pgraph_ctx [340]; /* XXX dynamic alloc ? */
121 nouveau_gpuobj_ref_t *ramin; /* Private instmem */
122 struct mem_block *ramin_heap; /* Private PRAMIN heap */
123 nouveau_gpuobj_ref_t *ramht; /* Hash table */
124 nouveau_gpuobj_ref_t *ramht_refs; /* Objects referenced by RAMHT */
127 struct nouveau_config {
134 typedef struct nouveau_engine_func {
136 int (*init)(drm_device_t *dev);
137 void (*takedown)(drm_device_t *dev);
141 int (*init)(drm_device_t *dev);
142 void (*takedown)(drm_device_t *dev);
146 int (*init)(drm_device_t *dev);
147 void (*takedown)(drm_device_t *dev);
151 int (*init)(drm_device_t *);
152 void (*takedown)(drm_device_t *);
154 int (*create_context)(drm_device_t *, int channel);
155 void (*destroy_context)(drm_device_t *, int channel);
156 int (*load_context)(drm_device_t *, int channel);
157 int (*save_context)(drm_device_t *, int channel);
161 int (*init)(drm_device_t *);
162 void (*takedown)(drm_device_t *);
164 int (*create_context)(drm_device_t *, int channel);
165 void (*destroy_context)(drm_device_t *, int channel);
166 int (*load_context)(drm_device_t *, int channel);
167 int (*save_context)(drm_device_t *, int channel);
169 } nouveau_engine_func_t;
171 typedef struct drm_nouveau_private {
172 /* the card type, takes NV_* as values */
174 /* exact chipset, derived from NV_PMC_BOOT_0 */
178 drm_local_map_t *mmio;
180 drm_local_map_t *ramin; /* NV40 onwards */
182 int fifo_alloc_count;
183 struct nouveau_fifo fifos[NV_MAX_FIFO_NUMBER];
185 struct nouveau_engine_func Engine;
187 /* RAMIN configuration, RAMFC, RAMHT and RAMRO offsets */
188 nouveau_gpuobj_t *ramht;
190 uint32_t ramht_offset;
193 uint32_t ramfc_offset;
195 uint32_t ramro_offset;
198 /* base physical adresses */
200 uint64_t fb_available_size;
202 uint64_t agp_available_size;
204 /* the mtrr covering the FB */
207 struct mem_block *agp_heap;
208 struct mem_block *fb_heap;
209 struct mem_block *fb_nomap_heap;
210 struct mem_block *ramin_heap;
212 /* context table pointed to be NV_PGRAPH_CHANNEL_CTX_TABLE (0x400780) */
213 uint32_t ctx_table_size;
214 nouveau_gpuobj_ref_t *ctx_table;
216 struct nouveau_config config;
218 nouveau_gpuobj_t *gpuobj_all;
220 drm_nouveau_private_t;
222 /* nouveau_state.c */
223 extern void nouveau_preclose(drm_device_t * dev, DRMFILE filp);
224 extern int nouveau_load(struct drm_device *dev, unsigned long flags);
225 extern int nouveau_firstopen(struct drm_device *dev);
226 extern void nouveau_lastclose(struct drm_device *dev);
227 extern int nouveau_unload(struct drm_device *dev);
228 extern int nouveau_ioctl_getparam(DRM_IOCTL_ARGS);
229 extern int nouveau_ioctl_setparam(DRM_IOCTL_ARGS);
230 extern void nouveau_wait_for_idle(struct drm_device *dev);
231 extern int nouveau_ioctl_card_init(DRM_IOCTL_ARGS);
234 extern int nouveau_mem_init_heap(struct mem_block **,
235 uint64_t start, uint64_t size);
236 extern struct mem_block *nouveau_mem_alloc_block(struct mem_block *,
237 uint64_t size, int align2,
239 extern void nouveau_mem_takedown(struct mem_block **heap);
240 extern void nouveau_mem_free_block(struct mem_block *);
241 extern uint64_t nouveau_mem_fb_amount(struct drm_device *dev);
242 extern void nouveau_mem_release(DRMFILE filp, struct mem_block *heap);
243 extern int nouveau_ioctl_mem_alloc(DRM_IOCTL_ARGS);
244 extern int nouveau_ioctl_mem_free(DRM_IOCTL_ARGS);
245 extern struct mem_block* nouveau_mem_alloc(struct drm_device *dev, int alignment, uint64_t size, int flags, DRMFILE filp);
246 extern void nouveau_mem_free(struct drm_device* dev, struct mem_block*);
247 extern int nouveau_mem_init(struct drm_device *dev);
248 extern void nouveau_mem_close(struct drm_device *dev);
249 extern int nouveau_instmem_init(struct drm_device *dev);
250 extern struct mem_block* nouveau_instmem_alloc(struct drm_device *dev,
251 uint32_t size, uint32_t align);
252 extern void nouveau_instmem_free(struct drm_device *dev,
253 struct mem_block *block);
255 /* nouveau_notifier.c */
256 extern int nouveau_notifier_init_channel(drm_device_t *, int channel, DRMFILE);
257 extern void nouveau_notifier_takedown_channel(drm_device_t *, int channel);
258 extern int nouveau_notifier_alloc(drm_device_t *, int channel,
259 uint32_t handle, int cout, uint32_t *offset);
260 extern int nouveau_ioctl_notifier_alloc(DRM_IOCTL_ARGS);
263 extern int nouveau_fifo_init(drm_device_t *dev);
264 extern int nouveau_fifo_number(drm_device_t *dev);
265 extern int nouveau_fifo_ctx_size(drm_device_t *dev);
266 extern void nouveau_fifo_cleanup(drm_device_t *dev, DRMFILE filp);
267 extern int nouveau_fifo_owner(drm_device_t *dev, DRMFILE filp, int channel);
268 extern void nouveau_fifo_free(drm_device_t *dev, int channel);
270 /* nouveau_object.c */
271 extern void nouveau_gpuobj_takedown(drm_device_t *dev);
272 extern int nouveau_gpuobj_channel_init(drm_device_t *, int channel,
273 uint32_t vram_h, uint32_t tt_h);
274 extern void nouveau_gpuobj_channel_takedown(drm_device_t *, int channel);
275 extern int nouveau_gpuobj_new(drm_device_t *, int channel, int size, int align,
276 uint32_t flags, nouveau_gpuobj_t **);
277 extern int nouveau_gpuobj_del(drm_device_t *, nouveau_gpuobj_t **);
278 extern int nouveau_gpuobj_ref_add(drm_device_t *, int channel, uint32_t handle,
279 nouveau_gpuobj_t *, nouveau_gpuobj_ref_t **);
280 extern int nouveau_gpuobj_ref_del(drm_device_t *, nouveau_gpuobj_ref_t **);
281 extern int nouveau_gpuobj_new_ref(drm_device_t *, int chan_obj, int chan_ref,
282 uint32_t handle, int size, int align,
283 uint32_t flags, nouveau_gpuobj_ref_t **);
284 extern int nouveau_gpuobj_new_fake(drm_device_t *, uint32_t offset,
285 uint32_t size, uint32_t flags,
286 nouveau_gpuobj_t**, nouveau_gpuobj_ref_t**);
287 extern int nouveau_gpuobj_dma_new(drm_device_t *, int channel, int class,
288 uint64_t offset, uint64_t size,
289 int access, int target, nouveau_gpuobj_t **);
290 extern int nouveau_gpuobj_gr_new(drm_device_t *, int channel, int class,
291 nouveau_gpuobj_t **);
292 extern int nouveau_ioctl_grobj_alloc(DRM_IOCTL_ARGS);
295 extern irqreturn_t nouveau_irq_handler(DRM_IRQ_ARGS);
296 extern void nouveau_irq_preinstall(drm_device_t*);
297 extern void nouveau_irq_postinstall(drm_device_t*);
298 extern void nouveau_irq_uninstall(drm_device_t*);
301 extern int nv04_fb_init(drm_device_t *dev);
302 extern void nv04_fb_takedown(drm_device_t *dev);
305 extern int nv10_fb_init(drm_device_t *dev);
306 extern void nv10_fb_takedown(drm_device_t *dev);
309 extern int nv40_fb_init(drm_device_t *dev);
310 extern void nv40_fb_takedown(drm_device_t *dev);
313 extern int nv04_fifo_create_context(drm_device_t *dev, int channel);
314 extern void nv04_fifo_destroy_context(drm_device_t *dev, int channel);
315 extern int nv04_fifo_load_context(drm_device_t *dev, int channel);
316 extern int nv04_fifo_save_context(drm_device_t *dev, int channel);
319 extern int nv10_fifo_create_context(drm_device_t *dev, int channel);
320 extern void nv10_fifo_destroy_context(drm_device_t *dev, int channel);
321 extern int nv10_fifo_load_context(drm_device_t *dev, int channel);
322 extern int nv10_fifo_save_context(drm_device_t *dev, int channel);
325 extern int nv40_fifo_create_context(drm_device_t *, int channel);
326 extern void nv40_fifo_destroy_context(drm_device_t *, int channel);
327 extern int nv40_fifo_load_context(drm_device_t *, int channel);
328 extern int nv40_fifo_save_context(drm_device_t *, int channel);
331 extern int nv50_fifo_init(drm_device_t *);
332 extern void nv50_fifo_takedown(drm_device_t *);
333 extern int nv50_fifo_create_context(drm_device_t *, int channel);
334 extern void nv50_fifo_destroy_context(drm_device_t *, int channel);
335 extern int nv50_fifo_load_context(drm_device_t *, int channel);
336 extern int nv50_fifo_save_context(drm_device_t *, int channel);
339 extern void nouveau_nv04_context_switch(drm_device_t *dev);
340 extern int nv04_graph_init(drm_device_t *dev);
341 extern void nv04_graph_takedown(drm_device_t *dev);
342 extern int nv04_graph_create_context(drm_device_t *dev, int channel);
343 extern void nv04_graph_destroy_context(drm_device_t *dev, int channel);
344 extern int nv04_graph_load_context(drm_device_t *dev, int channel);
345 extern int nv04_graph_save_context(drm_device_t *dev, int channel);
348 extern void nouveau_nv10_context_switch(drm_device_t *dev);
349 extern int nv10_graph_init(drm_device_t *dev);
350 extern void nv10_graph_takedown(drm_device_t *dev);
351 extern int nv10_graph_create_context(drm_device_t *dev, int channel);
352 extern void nv10_graph_destroy_context(drm_device_t *dev, int channel);
353 extern int nv10_graph_load_context(drm_device_t *dev, int channel);
354 extern int nv10_graph_save_context(drm_device_t *dev, int channel);
357 extern void nouveau_nv20_context_switch(drm_device_t *dev);
358 extern int nv20_graph_init(drm_device_t *dev);
359 extern void nv20_graph_takedown(drm_device_t *dev);
360 extern int nv20_graph_create_context(drm_device_t *dev, int channel);
361 extern void nv20_graph_destroy_context(drm_device_t *dev, int channel);
362 extern int nv20_graph_load_context(drm_device_t *dev, int channel);
363 extern int nv20_graph_save_context(drm_device_t *dev, int channel);
366 extern int nv30_graph_init(drm_device_t *dev);
367 extern void nv30_graph_takedown(drm_device_t *dev);
368 extern int nv30_graph_create_context(drm_device_t *, int channel);
369 extern void nv30_graph_destroy_context(drm_device_t *, int channel);
370 extern int nv30_graph_load_context(drm_device_t *, int channel);
371 extern int nv30_graph_save_context(drm_device_t *, int channel);
374 extern int nv40_graph_init(drm_device_t *);
375 extern void nv40_graph_takedown(drm_device_t *);
376 extern int nv40_graph_create_context(drm_device_t *, int channel);
377 extern void nv40_graph_destroy_context(drm_device_t *, int channel);
378 extern int nv40_graph_load_context(drm_device_t *, int channel);
379 extern int nv40_graph_save_context(drm_device_t *, int channel);
382 extern int nv50_graph_init(drm_device_t *);
383 extern void nv50_graph_takedown(drm_device_t *);
384 extern int nv50_graph_create_context(drm_device_t *, int channel);
385 extern void nv50_graph_destroy_context(drm_device_t *, int channel);
386 extern int nv50_graph_load_context(drm_device_t *, int channel);
387 extern int nv50_graph_save_context(drm_device_t *, int channel);
390 extern int nv04_mc_init(drm_device_t *dev);
391 extern void nv04_mc_takedown(drm_device_t *dev);
394 extern int nv40_mc_init(drm_device_t *dev);
395 extern void nv40_mc_takedown(drm_device_t *dev);
398 extern int nv50_mc_init(drm_device_t *dev);
399 extern void nv50_mc_takedown(drm_device_t *dev);
402 extern int nv04_timer_init(drm_device_t *dev);
403 extern void nv04_timer_takedown(drm_device_t *dev);
405 extern long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
408 #if defined(__powerpc__)
409 #define NV_READ(reg) in_be32((void __iomem *)(dev_priv->mmio)->handle + (reg) )
410 #define NV_WRITE(reg,val) out_be32((void __iomem *)(dev_priv->mmio)->handle + (reg) , (val) )
412 #define NV_READ(reg) DRM_READ32( dev_priv->mmio, (reg) )
413 #define NV_WRITE(reg,val) DRM_WRITE32( dev_priv->mmio, (reg), (val) )
417 #if defined(__powerpc__)
418 #define NV_RI32(o) in_be32((void __iomem *)(dev_priv->ramin)->handle+(o))
419 #define NV_WI32(o,v) out_be32((void __iomem*)(dev_priv->ramin)->handle+(o), (v))
421 #define NV_RI32(o) DRM_READ32(dev_priv->ramin, (o))
422 #define NV_WI32(o,v) DRM_WRITE32(dev_priv->ramin, (o), (v))
425 #define INSTANCE_RD(o,i) NV_RI32((o)->im_pramin->start + ((i)<<2))
426 #define INSTANCE_WR(o,i,v) NV_WI32((o)->im_pramin->start + ((i)<<2), (v))
428 #endif /* __NOUVEAU_DRV_H__ */