nouveau: NV04 PFIFO engtab functions
[platform/upstream/libdrm.git] / shared-core / nouveau_drv.h
1 /*
2  * Copyright 2005 Stephane Marchesin.
3  * All Rights Reserved.
4  *
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:
11  *
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
14  * Software.
15  *
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.
23  */
24
25 #ifndef __NOUVEAU_DRV_H__
26 #define __NOUVEAU_DRV_H__
27
28 #define DRIVER_AUTHOR           "Stephane Marchesin"
29 #define DRIVER_EMAIL            "dri-devel@lists.sourceforge.net"
30
31 #define DRIVER_NAME             "nouveau"
32 #define DRIVER_DESC             "nVidia Riva/TNT/GeForce"
33 #define DRIVER_DATE             "20060213"
34
35 #define DRIVER_MAJOR            0
36 #define DRIVER_MINOR            0
37 #define DRIVER_PATCHLEVEL       6
38
39 #define NOUVEAU_FAMILY   0x0000FFFF
40 #define NOUVEAU_FLAGS    0xFFFF0000
41
42 #include "nouveau_drm.h"
43 #include "nouveau_reg.h"
44
45 struct mem_block {
46         struct mem_block *next;
47         struct mem_block *prev;
48         uint64_t start;
49         uint64_t size;
50         DRMFILE filp;           /* 0: free, -1: heap, other: real files */
51         int flags;
52         drm_local_map_t *map;
53 };
54
55 enum nouveau_flags {
56         NV_NFORCE   =0x10000000,
57         NV_NFORCE2  =0x20000000
58 };
59
60 struct nouveau_object
61 {
62         struct nouveau_object *next;
63         struct nouveau_object *prev;
64         int channel;
65
66         struct mem_block *instance;
67         uint32_t          ht_loc;
68
69         uint32_t handle;
70         int      class;
71         int      engine;
72 };
73
74 struct nouveau_fifo
75 {
76         int used;
77         /* owner of this fifo */
78         DRMFILE filp;
79         /* mapping of the fifo itself */
80         drm_local_map_t *map;
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         uint32_t pushbuf_base;
87         /* PGRAPH context, for cards that keep it in RAMIN */
88         struct mem_block *ramin_grctx;
89         /* objects belonging to this fifo */
90         struct nouveau_object *objs;
91
92         /* XXX dynamic alloc ? */
93         uint32_t pgraph_ctx [340];
94 };
95
96 struct nouveau_config {
97         struct {
98                 int location;
99                 int size;
100         } cmdbuf;
101 };
102
103 typedef struct nouveau_engine_func {
104         struct {
105                 int     (*init)(drm_device_t *dev);
106                 void    (*takedown)(drm_device_t *dev);
107         } mc;
108
109         struct {
110                 int     (*init)(drm_device_t *dev);
111                 void    (*takedown)(drm_device_t *dev);
112         } timer;
113
114         struct {
115                 int     (*init)(drm_device_t *dev);
116                 void    (*takedown)(drm_device_t *dev);
117         } fb;
118
119         struct {
120                 int     (*init)(drm_device_t *);
121                 void    (*takedown)(drm_device_t *);
122
123                 int     (*create_context)(drm_device_t *, int channel);
124                 void    (*destroy_context)(drm_device_t *, int channel);
125                 int     (*load_context)(drm_device_t *, int channel);
126                 int     (*save_context)(drm_device_t *, int channel);
127         } graph;
128
129         struct {
130                 int     (*init)(drm_device_t *);
131                 void    (*takedown)(drm_device_t *);
132
133                 int     (*create_context)(drm_device_t *, int channel);
134                 void    (*destroy_context)(drm_device_t *, int channel);
135                 int     (*load_context)(drm_device_t *, int channel);
136                 int     (*save_context)(drm_device_t *, int channel);
137         } fifo;
138 } nouveau_engine_func_t;
139
140 typedef struct drm_nouveau_private {
141         /* the card type, takes NV_* as values */
142         int card_type;
143         /* exact chipset, derived from NV_PMC_BOOT_0 */
144         int chipset;
145         int flags;
146
147         drm_local_map_t *mmio;
148         drm_local_map_t *fb;
149         drm_local_map_t *ramin; /* NV40 onwards */
150
151         int fifo_alloc_count;
152         struct nouveau_fifo fifos[NV_MAX_FIFO_NUMBER];
153
154         struct nouveau_engine_func Engine;
155
156         /* RAMIN configuration, RAMFC, RAMHT and RAMRO offsets */
157         uint32_t ramin_size;
158         uint32_t ramht_offset;
159         uint32_t ramht_size;
160         uint32_t ramht_bits;
161         uint32_t ramfc_offset;
162         uint32_t ramfc_size;
163         uint32_t ramro_offset;
164         uint32_t ramro_size;
165
166         /* base physical adresses */
167         uint64_t fb_phys;
168         uint64_t fb_available_size;
169         uint64_t agp_phys;
170         uint64_t agp_available_size;
171
172         /* the mtrr covering the FB */
173         int fb_mtrr;
174
175         struct mem_block *agp_heap;
176         struct mem_block *fb_heap;
177         struct mem_block *fb_nomap_heap;
178         struct mem_block *ramin_heap;
179
180         /* context table pointed to be NV_PGRAPH_CHANNEL_CTX_TABLE (0x400780) */
181         uint32_t ctx_table_size;
182         struct mem_block *ctx_table;
183
184         struct nouveau_config config;
185 }
186 drm_nouveau_private_t;
187
188 /* nouveau_state.c */
189 extern void nouveau_preclose(drm_device_t * dev, DRMFILE filp);
190 extern int nouveau_load(struct drm_device *dev, unsigned long flags);
191 extern int nouveau_firstopen(struct drm_device *dev);
192 extern void nouveau_lastclose(struct drm_device *dev);
193 extern int nouveau_unload(struct drm_device *dev);
194 extern int nouveau_ioctl_getparam(DRM_IOCTL_ARGS);
195 extern int nouveau_ioctl_setparam(DRM_IOCTL_ARGS);
196 extern void nouveau_wait_for_idle(struct drm_device *dev);
197 extern int nouveau_ioctl_card_init(DRM_IOCTL_ARGS);
198
199 /* nouveau_mem.c */
200 extern uint64_t          nouveau_mem_fb_amount(struct drm_device *dev);
201 extern void              nouveau_mem_release(DRMFILE filp, struct mem_block *heap);
202 extern int               nouveau_ioctl_mem_alloc(DRM_IOCTL_ARGS);
203 extern int               nouveau_ioctl_mem_free(DRM_IOCTL_ARGS);
204 extern struct mem_block* nouveau_mem_alloc(struct drm_device *dev, int alignment, uint64_t size, int flags, DRMFILE filp);
205 extern void              nouveau_mem_free(struct drm_device* dev, struct mem_block*);
206 extern int               nouveau_mem_init(struct drm_device *dev);
207 extern void              nouveau_mem_close(struct drm_device *dev);
208 extern int               nouveau_instmem_init(struct drm_device *dev);
209 extern struct mem_block* nouveau_instmem_alloc(struct drm_device *dev,
210                                                uint32_t size, uint32_t align);
211 extern void              nouveau_instmem_free(struct drm_device *dev,
212                                               struct mem_block *block);
213 extern uint32_t          nouveau_instmem_r32(drm_nouveau_private_t *dev_priv,
214                                              struct mem_block *mem, int index);
215 extern void              nouveau_instmem_w32(drm_nouveau_private_t *dev_priv,
216                                              struct mem_block *mem, int index,
217                                              uint32_t val);
218
219 /* nouveau_fifo.c */
220 extern int  nouveau_fifo_init(drm_device_t *dev);
221 extern int  nouveau_fifo_number(drm_device_t *dev);
222 extern int  nouveau_fifo_ctx_size(drm_device_t *dev);
223 extern void nouveau_fifo_cleanup(drm_device_t *dev, DRMFILE filp);
224 extern int  nouveau_fifo_owner(drm_device_t *dev, DRMFILE filp, int channel);
225 extern void nouveau_fifo_free(drm_device_t *dev, int channel);
226
227 /* nouveau_object.c */
228 extern void nouveau_object_cleanup(drm_device_t *dev, int channel);
229 extern struct nouveau_object *
230 nouveau_object_gr_create(drm_device_t *dev, int channel, int class);
231 extern struct nouveau_object *
232 nouveau_object_dma_create(drm_device_t *dev, int channel, int class,
233                           uint32_t offset, uint32_t size,
234                           int access, int target);
235 extern void nouveau_object_free(drm_device_t *dev, struct nouveau_object *obj);
236 extern int  nouveau_ioctl_object_init(DRM_IOCTL_ARGS);
237 extern int  nouveau_ioctl_dma_object_init(DRM_IOCTL_ARGS);
238 extern uint32_t nouveau_chip_instance_get(drm_device_t *dev, struct mem_block *mem);
239
240 /* nouveau_irq.c */
241 extern irqreturn_t nouveau_irq_handler(DRM_IRQ_ARGS);
242 extern void        nouveau_irq_preinstall(drm_device_t*);
243 extern void        nouveau_irq_postinstall(drm_device_t*);
244 extern void        nouveau_irq_uninstall(drm_device_t*);
245
246 /* nv04_fb.c */
247 extern int  nv04_fb_init(drm_device_t *dev);
248 extern void nv04_fb_takedown(drm_device_t *dev);
249
250 /* nv10_fb.c */
251 extern int  nv10_fb_init(drm_device_t *dev);
252 extern void nv10_fb_takedown(drm_device_t *dev);
253
254 /* nv40_fb.c */
255 extern int  nv40_fb_init(drm_device_t *dev);
256 extern void nv40_fb_takedown(drm_device_t *dev);
257
258 /* nv04_fifo.c */
259 extern int  nv04_fifo_create_context(drm_device_t *dev, int channel);
260 extern void nv04_fifo_destroy_context(drm_device_t *dev, int channel);
261 extern int  nv04_fifo_load_context(drm_device_t *dev, int channel);
262 extern int  nv04_fifo_save_context(drm_device_t *dev, int channel);
263
264 /* nv40_fifo.c */
265 extern int  nv40_fifo_create_context(drm_device_t *, int channel);
266 extern void nv40_fifo_destroy_context(drm_device_t *, int channel);
267 extern int  nv40_fifo_load_context(drm_device_t *, int channel);
268 extern int  nv40_fifo_save_context(drm_device_t *, int channel);
269
270 /* nv04_graph.c */
271 extern void nouveau_nv04_context_switch(drm_device_t *dev);
272 extern int nv04_graph_init(drm_device_t *dev);
273 extern void nv04_graph_takedown(drm_device_t *dev);
274 extern int nv04_graph_context_create(drm_device_t *dev, int channel);
275
276 /* nv10_graph.c */
277 extern void nouveau_nv10_context_switch(drm_device_t *dev);
278 extern int nv10_graph_init(drm_device_t *dev);
279 extern void nv10_graph_takedown(drm_device_t *dev);
280 extern int nv10_graph_context_create(drm_device_t *dev, int channel);
281
282 /* nv20_graph.c */
283 extern void nouveau_nv20_context_switch(drm_device_t *dev);
284 extern int nv20_graph_init(drm_device_t *dev);
285 extern void nv20_graph_takedown(drm_device_t *dev);
286 extern int nv20_graph_context_create(drm_device_t *dev, int channel);
287
288 /* nv30_graph.c */
289 extern int nv30_graph_init(drm_device_t *dev);
290 extern void nv30_graph_takedown(drm_device_t *dev);
291 extern int nv30_graph_context_create(drm_device_t *dev, int channel);
292
293 /* nv40_graph.c */
294 extern int  nv40_graph_init(drm_device_t *);
295 extern void nv40_graph_takedown(drm_device_t *);
296 extern int  nv40_graph_create_context(drm_device_t *, int channel);
297 extern void nv40_graph_destroy_context(drm_device_t *, int channel);
298 extern int  nv40_graph_load_context(drm_device_t *, int channel);
299 extern int  nv40_graph_save_context(drm_device_t *, int channel);
300
301 /* nv04_mc.c */
302 extern int  nv04_mc_init(drm_device_t *dev);
303 extern void nv04_mc_takedown(drm_device_t *dev);
304
305 /* nv40_mc.c */
306 extern int  nv40_mc_init(drm_device_t *dev);
307 extern void nv40_mc_takedown(drm_device_t *dev);
308
309 /* nv04_timer.c */
310 extern int  nv04_timer_init(drm_device_t *dev);
311 extern void nv04_timer_takedown(drm_device_t *dev);
312
313 extern long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
314                                 unsigned long arg);
315
316 #if defined(__powerpc__)
317 #define NV_READ(reg)        in_be32((void __iomem *)(dev_priv->mmio)->handle + (reg) )
318 #define NV_WRITE(reg,val)   out_be32((void __iomem *)(dev_priv->mmio)->handle + (reg) , (val) )
319 #else
320 #define NV_READ(reg)        DRM_READ32(  dev_priv->mmio, (reg) )
321 #define NV_WRITE(reg,val)   DRM_WRITE32( dev_priv->mmio, (reg), (val) )
322 #endif
323
324 #define INSTANCE_WR(mem,ofs,val) nouveau_instmem_w32(dev_priv,(mem),(ofs),(val))
325 #define INSTANCE_RD(mem,ofs)     nouveau_instmem_r32(dev_priv,(mem),(ofs))
326
327 #endif /* __NOUVEAU_DRV_H__ */
328