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 5
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
62 struct nouveau_object *next;
63 struct nouveau_object *prev;
66 struct mem_block *instance;
77 /* owner of this fifo */
79 /* mapping of the fifo itself */
81 /* mapping of the regs controling the fifo */
82 drm_local_map_t *regs;
83 /* dma object for the command buffer itself */
84 struct mem_block *cmdbuf_mem;
85 struct nouveau_object *cmdbuf_obj;
86 /* PGRAPH context, for cards that keep it in RAMIN */
87 struct mem_block *ramin_grctx;
88 /* objects belonging to this fifo */
89 struct nouveau_object *objs;
91 /* XXX dynamic alloc ? */
92 uint32_t pgraph_ctx [340];
95 struct nouveau_config {
102 typedef struct drm_nouveau_private {
103 /* the card type, takes NV_* as values */
105 /* exact chipset, derived from NV_PMC_BOOT_0 */
109 drm_local_map_t *mmio;
111 drm_local_map_t *ramin; /* NV40 onwards */
113 int fifo_alloc_count;
114 struct nouveau_fifo fifos[NV_MAX_FIFO_NUMBER];
116 /* RAMIN configuration, RAMFC, RAMHT and RAMRO offsets */
118 uint32_t ramht_offset;
121 uint32_t ramfc_offset;
123 uint32_t ramro_offset;
126 /* base physical adresses */
128 uint64_t fb_available_size;
130 uint64_t agp_available_size;
132 /* the mtrr covering the FB */
135 struct mem_block *agp_heap;
136 struct mem_block *fb_heap;
137 struct mem_block *fb_nomap_heap;
138 struct mem_block *ramin_heap;
140 /* context table pointed to be NV_PGRAPH_CHANNEL_CTX_TABLE (0x400780) */
141 uint32_t ctx_table_size;
142 struct mem_block *ctx_table;
144 struct nouveau_config config;
146 drm_nouveau_private_t;
148 /* nouveau_state.c */
149 extern void nouveau_preclose(drm_device_t * dev, DRMFILE filp);
150 extern int nouveau_load(struct drm_device *dev, unsigned long flags);
151 extern int nouveau_firstopen(struct drm_device *dev);
152 extern void nouveau_lastclose(struct drm_device *dev);
153 extern int nouveau_unload(struct drm_device *dev);
154 extern int nouveau_ioctl_getparam(DRM_IOCTL_ARGS);
155 extern int nouveau_ioctl_setparam(DRM_IOCTL_ARGS);
156 extern void nouveau_wait_for_idle(struct drm_device *dev);
159 extern uint64_t nouveau_mem_fb_amount(struct drm_device *dev);
160 extern void nouveau_mem_release(DRMFILE filp, struct mem_block *heap);
161 extern int nouveau_ioctl_mem_alloc(DRM_IOCTL_ARGS);
162 extern int nouveau_ioctl_mem_free(DRM_IOCTL_ARGS);
163 extern struct mem_block* nouveau_mem_alloc(struct drm_device *dev, int alignment, uint64_t size, int flags, DRMFILE filp);
164 extern void nouveau_mem_free(struct drm_device* dev, struct mem_block*);
165 extern int nouveau_mem_init(struct drm_device *dev);
166 extern void nouveau_mem_close(struct drm_device *dev);
167 extern int nouveau_instmem_init(struct drm_device *dev,
169 extern struct mem_block* nouveau_instmem_alloc(struct drm_device *dev,
170 uint32_t size, uint32_t align);
171 extern void nouveau_instmem_free(struct drm_device *dev,
172 struct mem_block *block);
173 extern uint32_t nouveau_instmem_r32(drm_nouveau_private_t *dev_priv,
174 struct mem_block *mem, int index);
175 extern void nouveau_instmem_w32(drm_nouveau_private_t *dev_priv,
176 struct mem_block *mem, int index,
180 extern int nouveau_fifo_init(drm_device_t *dev);
181 extern int nouveau_fifo_number(drm_device_t *dev);
182 extern void nouveau_fifo_cleanup(drm_device_t *dev, DRMFILE filp);
183 extern int nouveau_fifo_owner(drm_device_t *dev, DRMFILE filp, int channel);
184 extern void nouveau_fifo_free(drm_device_t *dev, int channel);
186 /* nouveau_object.c */
187 extern void nouveau_object_cleanup(drm_device_t *dev, int channel);
188 extern struct nouveau_object *
189 nouveau_object_gr_create(drm_device_t *dev, int channel, int class);
190 extern struct nouveau_object *
191 nouveau_object_dma_create(drm_device_t *dev, int channel, int class,
192 uint32_t offset, uint32_t size,
193 int access, int target);
194 extern void nouveau_object_free(drm_device_t *dev, struct nouveau_object *obj);
195 extern int nouveau_ioctl_object_init(DRM_IOCTL_ARGS);
196 extern int nouveau_ioctl_dma_object_init(DRM_IOCTL_ARGS);
197 extern uint32_t nouveau_chip_instance_get(drm_device_t *dev, struct mem_block *mem);
200 extern irqreturn_t nouveau_irq_handler(DRM_IRQ_ARGS);
201 extern void nouveau_irq_preinstall(drm_device_t*);
202 extern void nouveau_irq_postinstall(drm_device_t*);
203 extern void nouveau_irq_uninstall(drm_device_t*);
206 extern void nouveau_nv04_context_switch(drm_device_t *dev);
207 extern int nv04_graph_init(drm_device_t *dev);
208 extern int nv04_graph_context_create(drm_device_t *dev, int channel);
211 extern void nouveau_nv10_context_switch(drm_device_t *dev);
212 extern int nv10_graph_init(drm_device_t *dev);
213 extern int nv10_graph_context_create(drm_device_t *dev, int channel);
216 extern void nouveau_nv20_context_switch(drm_device_t *dev);
217 extern int nv20_graph_init(drm_device_t *dev);
218 extern int nv20_graph_context_create(drm_device_t *dev, int channel);
221 extern int nv30_graph_init(drm_device_t *dev);
222 extern int nv30_graph_context_create(drm_device_t *dev, int channel);
225 extern int nv40_graph_init(drm_device_t *dev);
226 extern int nv40_graph_context_create(drm_device_t *dev, int channel);
227 extern void nv40_graph_context_save_current(drm_device_t *dev);
228 extern void nv40_graph_context_restore(drm_device_t *dev, int channel);
230 extern long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
233 #if defined(__powerpc__)
234 #define NV_READ(reg) in_be32((void __iomem *)(dev_priv->mmio)->handle + (reg) )
235 #define NV_WRITE(reg,val) out_be32((void __iomem *)(dev_priv->mmio)->handle + (reg) , (val) )
237 #define NV_READ(reg) DRM_READ32( dev_priv->mmio, (reg) )
238 #define NV_WRITE(reg,val) DRM_WRITE32( dev_priv->mmio, (reg), (val) )
241 #define INSTANCE_WR(mem,ofs,val) nouveau_instmem_w32(dev_priv,(mem),(ofs),(val))
242 #define INSTANCE_RD(mem,ofs) nouveau_instmem_r32(dev_priv,(mem),(ofs))
244 #endif /* __NOUVEAU_DRV_H__ */