nouveau: intrusive drm interface changes
[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       4
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
65         struct mem_block *instance;
66         uint32_t          ht_loc;
67
68         uint32_t handle;
69         int      class;
70         int      engine;
71 };
72
73 struct nouveau_fifo
74 {
75         int used;
76         /* owner of this fifo */
77         DRMFILE filp;
78         /* mapping of the fifo itself */
79         drm_local_map_t *map;
80         /* mapping of the regs controling the fifo */
81         drm_local_map_t *regs;
82         /* dma object for the command buffer itself */
83         struct mem_block      *cmdbuf_mem;
84         struct nouveau_object *cmdbuf_obj;
85         /* PGRAPH context, for cards that keep it in RAMIN */
86         struct mem_block *ramin_grctx;
87         /* objects belonging to this fifo */
88         struct nouveau_object *objs;
89
90         /* XXX dynamic alloc ? */
91         uint32_t pgraph_ctx [340];
92 };
93
94 struct nouveau_config {
95         struct {
96                 int location;
97                 int size;
98         } cmdbuf;
99 };
100
101 typedef struct drm_nouveau_private {
102         /* the card type, takes NV_* as values */
103         int card_type;
104         /* exact chipset, derived from NV_PMC_BOOT_0 */
105         int chipset;
106         int flags;
107
108         drm_local_map_t *mmio;
109         drm_local_map_t *fb;
110         drm_local_map_t *ramin; /* NV40 onwards */
111
112         //TODO: Remove me, I'm bogus :)
113         int      cur_fifo;
114
115         struct nouveau_object *fb_obj;
116         int               cmdbuf_ch_size;
117         struct mem_block* cmdbuf_alloc;
118
119         int fifo_alloc_count;
120         struct nouveau_fifo fifos[NV_MAX_FIFO_NUMBER];
121
122         /* RAMIN configuration, RAMFC, RAMHT and RAMRO offsets */
123         uint32_t ramin_size;
124         uint32_t ramht_offset;
125         uint32_t ramht_size;
126         uint32_t ramht_bits;
127         uint32_t ramfc_offset;
128         uint32_t ramfc_size;
129         uint32_t ramro_offset;
130         uint32_t ramro_size;
131
132         /* base physical adresses */
133         uint64_t fb_phys;
134         uint64_t fb_available_size;
135         uint64_t agp_phys;
136         uint64_t agp_available_size;
137
138         /* the mtrr covering the FB */
139         int fb_mtrr;
140
141         struct mem_block *agp_heap;
142         struct mem_block *fb_heap;
143         struct mem_block *fb_nomap_heap;
144         struct mem_block *ramin_heap;
145
146         /* context table pointed to be NV_PGRAPH_CHANNEL_CTX_TABLE (0x400780) */
147         uint32_t ctx_table_size;
148         struct mem_block *ctx_table;
149
150         struct nouveau_config config;
151 }
152 drm_nouveau_private_t;
153
154 /* nouveau_state.c */
155 extern void nouveau_preclose(drm_device_t * dev, DRMFILE filp);
156 extern int nouveau_load(struct drm_device *dev, unsigned long flags);
157 extern int nouveau_firstopen(struct drm_device *dev);
158 extern void nouveau_lastclose(struct drm_device *dev);
159 extern int nouveau_unload(struct drm_device *dev);
160 extern int nouveau_ioctl_getparam(DRM_IOCTL_ARGS);
161 extern int nouveau_ioctl_setparam(DRM_IOCTL_ARGS);
162 extern void nouveau_wait_for_idle(struct drm_device *dev);
163
164 /* nouveau_mem.c */
165 extern uint64_t          nouveau_mem_fb_amount(struct drm_device *dev);
166 extern void              nouveau_mem_release(DRMFILE filp, struct mem_block *heap);
167 extern int               nouveau_ioctl_mem_alloc(DRM_IOCTL_ARGS);
168 extern int               nouveau_ioctl_mem_free(DRM_IOCTL_ARGS);
169 extern struct mem_block* nouveau_mem_alloc(struct drm_device *dev, int alignment, uint64_t size, int flags, DRMFILE filp);
170 extern void              nouveau_mem_free(struct drm_device* dev, struct mem_block*);
171 extern int               nouveau_mem_init(struct drm_device *dev);
172 extern void              nouveau_mem_close(struct drm_device *dev);
173 extern int               nouveau_instmem_init(struct drm_device *dev,
174                                               uint32_t offset);
175 extern struct mem_block* nouveau_instmem_alloc(struct drm_device *dev,
176                                                uint32_t size, uint32_t align);
177 extern void              nouveau_instmem_free(struct drm_device *dev,
178                                               struct mem_block *block);
179 extern uint32_t          nouveau_instmem_r32(drm_nouveau_private_t *dev_priv,
180                                              struct mem_block *mem, int index);
181 extern void              nouveau_instmem_w32(drm_nouveau_private_t *dev_priv,
182                                              struct mem_block *mem, int index,
183                                              uint32_t val);
184
185 /* nouveau_fifo.c */
186 extern int  nouveau_fifo_init(drm_device_t *dev);
187 extern int  nouveau_fifo_number(drm_device_t *dev);
188 extern void nouveau_fifo_cleanup(drm_device_t *dev, DRMFILE filp);
189 extern int  nouveau_fifo_id_get(drm_device_t *dev, DRMFILE filp);
190 extern void nouveau_fifo_free(drm_device_t *dev, int channel);
191
192 /* nouveau_object.c */
193 extern void nouveau_object_cleanup(drm_device_t *dev, DRMFILE filp);
194 extern struct nouveau_object *
195 nouveau_dma_object_create(drm_device_t *dev, int class,
196                           uint32_t offset, uint32_t size,
197                           int access, int target);
198 extern int  nouveau_ioctl_object_init(DRM_IOCTL_ARGS);
199 extern int  nouveau_ioctl_dma_object_init(DRM_IOCTL_ARGS);
200 extern uint32_t nouveau_chip_instance_get(drm_device_t *dev, struct mem_block *mem);
201
202 /* nouveau_irq.c */
203 extern irqreturn_t nouveau_irq_handler(DRM_IRQ_ARGS);
204 extern void        nouveau_irq_preinstall(drm_device_t*);
205 extern void        nouveau_irq_postinstall(drm_device_t*);
206 extern void        nouveau_irq_uninstall(drm_device_t*);
207
208 /* nv04_graph.c */
209 extern void nouveau_nv04_context_switch(drm_device_t *dev);
210 extern int nv04_graph_init(drm_device_t *dev);
211 extern int nv04_graph_context_create(drm_device_t *dev, int channel);
212
213 /* nv10_graph.c */
214 extern void nouveau_nv10_context_switch(drm_device_t *dev);
215 extern int nv10_graph_init(drm_device_t *dev);
216 extern int nv10_graph_context_create(drm_device_t *dev, int channel);
217
218 /* nv20_graph.c */
219 extern void nouveau_nv20_context_switch(drm_device_t *dev);
220 extern int nv20_graph_init(drm_device_t *dev);
221 extern int nv20_graph_context_create(drm_device_t *dev, int channel);
222
223 /* nv30_graph.c */
224 extern int nv30_graph_init(drm_device_t *dev);
225 extern int nv30_graph_context_create(drm_device_t *dev, int channel);
226
227 /* nv40_graph.c */
228 extern int  nv40_graph_init(drm_device_t *dev);
229 extern int  nv40_graph_context_create(drm_device_t *dev, int channel);
230 extern void nv40_graph_context_save_current(drm_device_t *dev);
231 extern void nv40_graph_context_restore(drm_device_t *dev, int channel);
232
233 extern long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
234                                 unsigned long arg);
235
236 #if defined(__powerpc__)
237 #define NV_READ(reg)        in_be32((void __iomem *)(dev_priv->mmio)->handle + (reg) )
238 #define NV_WRITE(reg,val)   out_be32((void __iomem *)(dev_priv->mmio)->handle + (reg) , (val) )
239 #else
240 #define NV_READ(reg)        DRM_READ32(  dev_priv->mmio, (reg) )
241 #define NV_WRITE(reg,val)   DRM_WRITE32( dev_priv->mmio, (reg), (val) )
242 #endif
243
244 #define INSTANCE_WR(mem,ofs,val) nouveau_instmem_w32(dev_priv,(mem),(ofs),(val))
245 #define INSTANCE_RD(mem,ofs)     nouveau_instmem_r32(dev_priv,(mem),(ofs))
246
247 #endif /* __NOUVEAU_DRV_H__ */
248