nouveau: simplify PRAMIN access
[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       7
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         /* notifier memory */
88         struct mem_block *notifier_block;
89         struct mem_block *notifier_heap;
90         drm_local_map_t  *notifier_map;
91         /* PGRAPH context, for cards that keep it in RAMIN */
92         struct mem_block *ramin_grctx;
93         /* objects belonging to this fifo */
94         struct nouveau_object *objs;
95
96         /* XXX dynamic alloc ? */
97         uint32_t pgraph_ctx [340];
98 };
99
100 struct nouveau_config {
101         struct {
102                 int location;
103                 int size;
104         } cmdbuf;
105 };
106
107 typedef struct nouveau_engine_func {
108         struct {
109                 int     (*init)(drm_device_t *dev);
110                 void    (*takedown)(drm_device_t *dev);
111         } mc;
112
113         struct {
114                 int     (*init)(drm_device_t *dev);
115                 void    (*takedown)(drm_device_t *dev);
116         } timer;
117
118         struct {
119                 int     (*init)(drm_device_t *dev);
120                 void    (*takedown)(drm_device_t *dev);
121         } fb;
122
123         struct {
124                 int     (*init)(drm_device_t *);
125                 void    (*takedown)(drm_device_t *);
126
127                 int     (*create_context)(drm_device_t *, int channel);
128                 void    (*destroy_context)(drm_device_t *, int channel);
129                 int     (*load_context)(drm_device_t *, int channel);
130                 int     (*save_context)(drm_device_t *, int channel);
131         } graph;
132
133         struct {
134                 int     (*init)(drm_device_t *);
135                 void    (*takedown)(drm_device_t *);
136
137                 int     (*create_context)(drm_device_t *, int channel);
138                 void    (*destroy_context)(drm_device_t *, int channel);
139                 int     (*load_context)(drm_device_t *, int channel);
140                 int     (*save_context)(drm_device_t *, int channel);
141         } fifo;
142 } nouveau_engine_func_t;
143
144 typedef struct drm_nouveau_private {
145         /* the card type, takes NV_* as values */
146         int card_type;
147         /* exact chipset, derived from NV_PMC_BOOT_0 */
148         int chipset;
149         int flags;
150
151         drm_local_map_t *mmio;
152         drm_local_map_t *fb;
153         drm_local_map_t *ramin; /* NV40 onwards */
154
155         int fifo_alloc_count;
156         struct nouveau_fifo fifos[NV_MAX_FIFO_NUMBER];
157
158         struct nouveau_engine_func Engine;
159
160         /* RAMIN configuration, RAMFC, RAMHT and RAMRO offsets */
161         uint32_t ramin_size;
162         uint32_t ramht_offset;
163         uint32_t ramht_size;
164         uint32_t ramht_bits;
165         uint32_t ramfc_offset;
166         uint32_t ramfc_size;
167         uint32_t ramro_offset;
168         uint32_t ramro_size;
169
170         /* base physical adresses */
171         uint64_t fb_phys;
172         uint64_t fb_available_size;
173         uint64_t agp_phys;
174         uint64_t agp_available_size;
175
176         /* the mtrr covering the FB */
177         int fb_mtrr;
178
179         struct mem_block *agp_heap;
180         struct mem_block *fb_heap;
181         struct mem_block *fb_nomap_heap;
182         struct mem_block *ramin_heap;
183
184         /* context table pointed to be NV_PGRAPH_CHANNEL_CTX_TABLE (0x400780) */
185         uint32_t ctx_table_size;
186         struct mem_block *ctx_table;
187
188         struct nouveau_config config;
189 }
190 drm_nouveau_private_t;
191
192 /* nouveau_state.c */
193 extern void nouveau_preclose(drm_device_t * dev, DRMFILE filp);
194 extern int nouveau_load(struct drm_device *dev, unsigned long flags);
195 extern int nouveau_firstopen(struct drm_device *dev);
196 extern void nouveau_lastclose(struct drm_device *dev);
197 extern int nouveau_unload(struct drm_device *dev);
198 extern int nouveau_ioctl_getparam(DRM_IOCTL_ARGS);
199 extern int nouveau_ioctl_setparam(DRM_IOCTL_ARGS);
200 extern void nouveau_wait_for_idle(struct drm_device *dev);
201 extern int nouveau_ioctl_card_init(DRM_IOCTL_ARGS);
202
203 /* nouveau_mem.c */
204 extern int               nouveau_mem_init_heap(struct mem_block **,
205                                                uint64_t start, uint64_t size);
206 extern struct mem_block *nouveau_mem_alloc_block(struct mem_block *,
207                                                  uint64_t size, int align2,
208                                                  DRMFILE);
209 extern void              nouveau_mem_free_block(struct mem_block *);
210 extern uint64_t          nouveau_mem_fb_amount(struct drm_device *dev);
211 extern void              nouveau_mem_release(DRMFILE filp, struct mem_block *heap);
212 extern int               nouveau_ioctl_mem_alloc(DRM_IOCTL_ARGS);
213 extern int               nouveau_ioctl_mem_free(DRM_IOCTL_ARGS);
214 extern struct mem_block* nouveau_mem_alloc(struct drm_device *dev, int alignment, uint64_t size, int flags, DRMFILE filp);
215 extern void              nouveau_mem_free(struct drm_device* dev, struct mem_block*);
216 extern int               nouveau_mem_init(struct drm_device *dev);
217 extern void              nouveau_mem_close(struct drm_device *dev);
218 extern int               nouveau_instmem_init(struct drm_device *dev);
219 extern struct mem_block* nouveau_instmem_alloc(struct drm_device *dev,
220                                                uint32_t size, uint32_t align);
221 extern void              nouveau_instmem_free(struct drm_device *dev,
222                                               struct mem_block *block);
223
224 /* nouveau_notifier.c */
225 extern int  nouveau_notifier_init_channel(drm_device_t *, int channel, DRMFILE);
226 extern void nouveau_notifier_takedown_channel(drm_device_t *, int channel);
227 extern int  nouveau_notifier_alloc(drm_device_t *, int channel,
228                                    uint32_t handle, int cout, uint32_t *offset);
229 extern int  nouveau_ioctl_notifier_alloc(DRM_IOCTL_ARGS);
230
231 /* nouveau_fifo.c */
232 extern int  nouveau_fifo_init(drm_device_t *dev);
233 extern int  nouveau_fifo_number(drm_device_t *dev);
234 extern int  nouveau_fifo_ctx_size(drm_device_t *dev);
235 extern void nouveau_fifo_cleanup(drm_device_t *dev, DRMFILE filp);
236 extern int  nouveau_fifo_owner(drm_device_t *dev, DRMFILE filp, int channel);
237 extern void nouveau_fifo_free(drm_device_t *dev, int channel);
238
239 /* nouveau_object.c */
240 extern int  nouveau_object_init_channel(drm_device_t *, int channel,
241                                         uint32_t vram_handle,
242                                         uint32_t tt_handle);
243 extern void nouveau_object_takedown_channel(drm_device_t *dev, int channel);
244 extern void nouveau_object_cleanup(drm_device_t *dev, int channel);
245 extern int  nouveau_ht_object_insert(drm_device_t *, int channel,
246                                      uint32_t handle, struct nouveau_object *);
247 extern struct nouveau_object *
248 nouveau_object_gr_create(drm_device_t *dev, int channel, int class);
249 extern struct nouveau_object *
250 nouveau_object_dma_create(drm_device_t *dev, int channel, int class,
251                           uint32_t offset, uint32_t size,
252                           int access, int target);
253 extern void nouveau_object_free(drm_device_t *dev, struct nouveau_object *obj);
254 extern int  nouveau_ioctl_grobj_alloc(DRM_IOCTL_ARGS);
255 extern uint32_t nouveau_chip_instance_get(drm_device_t *dev, struct mem_block *mem);
256
257 /* nouveau_irq.c */
258 extern irqreturn_t nouveau_irq_handler(DRM_IRQ_ARGS);
259 extern void        nouveau_irq_preinstall(drm_device_t*);
260 extern void        nouveau_irq_postinstall(drm_device_t*);
261 extern void        nouveau_irq_uninstall(drm_device_t*);
262
263 /* nv04_fb.c */
264 extern int  nv04_fb_init(drm_device_t *dev);
265 extern void nv04_fb_takedown(drm_device_t *dev);
266
267 /* nv10_fb.c */
268 extern int  nv10_fb_init(drm_device_t *dev);
269 extern void nv10_fb_takedown(drm_device_t *dev);
270
271 /* nv40_fb.c */
272 extern int  nv40_fb_init(drm_device_t *dev);
273 extern void nv40_fb_takedown(drm_device_t *dev);
274
275 /* nv04_fifo.c */
276 extern int  nv04_fifo_create_context(drm_device_t *dev, int channel);
277 extern void nv04_fifo_destroy_context(drm_device_t *dev, int channel);
278 extern int  nv04_fifo_load_context(drm_device_t *dev, int channel);
279 extern int  nv04_fifo_save_context(drm_device_t *dev, int channel);
280
281 /* nv10_fifo.c */
282 extern int  nv10_fifo_create_context(drm_device_t *dev, int channel);
283 extern void nv10_fifo_destroy_context(drm_device_t *dev, int channel);
284 extern int  nv10_fifo_load_context(drm_device_t *dev, int channel);
285 extern int  nv10_fifo_save_context(drm_device_t *dev, int channel);
286
287 /* nv40_fifo.c */
288 extern int  nv40_fifo_create_context(drm_device_t *, int channel);
289 extern void nv40_fifo_destroy_context(drm_device_t *, int channel);
290 extern int  nv40_fifo_load_context(drm_device_t *, int channel);
291 extern int  nv40_fifo_save_context(drm_device_t *, int channel);
292
293 /* nv50_fifo.c */
294 extern int  nv50_fifo_init(drm_device_t *);
295 extern void nv50_fifo_takedown(drm_device_t *);
296 extern int  nv50_fifo_create_context(drm_device_t *, int channel);
297 extern void nv50_fifo_destroy_context(drm_device_t *, int channel);
298 extern int  nv50_fifo_load_context(drm_device_t *, int channel);
299 extern int  nv50_fifo_save_context(drm_device_t *, int channel);
300
301 /* nv04_graph.c */
302 extern void nouveau_nv04_context_switch(drm_device_t *dev);
303 extern int  nv04_graph_init(drm_device_t *dev);
304 extern void nv04_graph_takedown(drm_device_t *dev);
305 extern int  nv04_graph_create_context(drm_device_t *dev, int channel);
306 extern void nv04_graph_destroy_context(drm_device_t *dev, int channel);
307 extern int  nv04_graph_load_context(drm_device_t *dev, int channel);
308 extern int  nv04_graph_save_context(drm_device_t *dev, int channel);
309
310 /* nv10_graph.c */
311 extern void nouveau_nv10_context_switch(drm_device_t *dev);
312 extern int  nv10_graph_init(drm_device_t *dev);
313 extern void nv10_graph_takedown(drm_device_t *dev);
314 extern int  nv10_graph_create_context(drm_device_t *dev, int channel);
315 extern void nv10_graph_destroy_context(drm_device_t *dev, int channel);
316 extern int  nv10_graph_load_context(drm_device_t *dev, int channel);
317 extern int  nv10_graph_save_context(drm_device_t *dev, int channel);
318
319 /* nv20_graph.c */
320 extern void nouveau_nv20_context_switch(drm_device_t *dev);
321 extern int  nv20_graph_init(drm_device_t *dev);
322 extern void nv20_graph_takedown(drm_device_t *dev);
323 extern int  nv20_graph_create_context(drm_device_t *dev, int channel);
324 extern void nv20_graph_destroy_context(drm_device_t *dev, int channel);
325 extern int  nv20_graph_load_context(drm_device_t *dev, int channel);
326 extern int  nv20_graph_save_context(drm_device_t *dev, int channel);
327
328 /* nv30_graph.c */
329 extern int  nv30_graph_init(drm_device_t *dev);
330 extern void nv30_graph_takedown(drm_device_t *dev);
331 extern int  nv30_graph_create_context(drm_device_t *, int channel);
332 extern void nv30_graph_destroy_context(drm_device_t *, int channel);
333 extern int  nv30_graph_load_context(drm_device_t *, int channel);
334 extern int  nv30_graph_save_context(drm_device_t *, int channel);
335
336 /* nv40_graph.c */
337 extern int  nv40_graph_init(drm_device_t *);
338 extern void nv40_graph_takedown(drm_device_t *);
339 extern int  nv40_graph_create_context(drm_device_t *, int channel);
340 extern void nv40_graph_destroy_context(drm_device_t *, int channel);
341 extern int  nv40_graph_load_context(drm_device_t *, int channel);
342 extern int  nv40_graph_save_context(drm_device_t *, int channel);
343
344 /* nv50_graph.c */
345 extern int  nv50_graph_init(drm_device_t *);
346 extern void nv50_graph_takedown(drm_device_t *);
347 extern int  nv50_graph_create_context(drm_device_t *, int channel);
348 extern void nv50_graph_destroy_context(drm_device_t *, int channel);
349 extern int  nv50_graph_load_context(drm_device_t *, int channel);
350 extern int  nv50_graph_save_context(drm_device_t *, int channel);
351
352 /* nv04_mc.c */
353 extern int  nv04_mc_init(drm_device_t *dev);
354 extern void nv04_mc_takedown(drm_device_t *dev);
355
356 /* nv40_mc.c */
357 extern int  nv40_mc_init(drm_device_t *dev);
358 extern void nv40_mc_takedown(drm_device_t *dev);
359
360 /* nv50_mc.c */
361 extern int  nv50_mc_init(drm_device_t *dev);
362 extern void nv50_mc_takedown(drm_device_t *dev);
363
364 /* nv04_timer.c */
365 extern int  nv04_timer_init(drm_device_t *dev);
366 extern void nv04_timer_takedown(drm_device_t *dev);
367
368 extern long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
369                                 unsigned long arg);
370
371 #if defined(__powerpc__)
372 #define NV_READ(reg)        in_be32((void __iomem *)(dev_priv->mmio)->handle + (reg) )
373 #define NV_WRITE(reg,val)   out_be32((void __iomem *)(dev_priv->mmio)->handle + (reg) , (val) )
374 #else
375 #define NV_READ(reg)        DRM_READ32(  dev_priv->mmio, (reg) )
376 #define NV_WRITE(reg,val)   DRM_WRITE32( dev_priv->mmio, (reg), (val) )
377 #endif
378
379 /* PRAMIN access */
380 #if defined(__powerpc__)
381 #define NV_RI32(o) in_be32((void __iomem *)(dev_priv->ramin)->handle+(o))
382 #define NV_WI32(o,v) out_be32((void __iomem*)(dev_priv->ramin)->handle+(o), (v))
383 #else
384 #define NV_RI32(o) DRM_READ32(dev_priv->ramin, (o))
385 #define NV_WI32(o,v) DRM_WRITE32(dev_priv->ramin, (o), (v))
386 #endif
387
388 #define INSTANCE_RD(o,i) NV_RI32((o)->start + ((i)<<2))
389 #define INSTANCE_WR(o,i,v) NV_WI32((o)->start + ((i)<<2), (v))
390
391 #endif /* __NOUVEAU_DRV_H__ */
392