Merge branch 'master' of git+ssh://marcheu@git.freedesktop.org/git/mesa/drm into...
[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            1
36 #define DRIVER_MINOR            0
37 #define DRIVER_PATCHLEVEL       0
38
39 #define NOUVEAU_FAMILY   0x0000FFFF
40 #define NOUVEAU_FLAGS    0xFFFF0000
41
42 #include "nouveau_drm.h"
43 #include "nouveau_reg.h"
44
45 enum nouveau_flags {
46         NV_NFORCE   =0x10000000,
47         NV_NFORCE2  =0x20000000
48 };
49
50 struct nouveau_object
51 {
52         struct nouveau_object *next;
53         struct nouveau_object *prev;
54
55         uint32_t handle;
56         int      class;
57         int      engine;
58         uint32_t instance;
59         uint32_t ht_loc;
60 };
61
62 #define NV_DMA_TARGET_VIDMEM 0
63 #define NV_DMA_TARGET_PCI    2
64 #define NV_DMA_TARGET_AGP    3
65 struct nouveau_fifo
66 {
67         int used;
68         /* owner of this fifo */
69         DRMFILE filp;
70         /* mapping of the fifo itself */
71         drm_local_map_t *map;
72         /* mapping of the regs controling the fifo */
73         drm_local_map_t *regs;
74         /* objects belonging to this fifo */
75         struct nouveau_object *objs;
76 };
77
78 struct nouveau_object_store
79 {
80         int ht_bits;
81         int ht_size;
82         int ht_base;
83
84         uint32_t *inst_bmap;
85         uint32_t first_instance;
86         int      num_instance;
87         int      free_instance;
88 };
89
90 struct mem_block {
91         struct mem_block *next;
92         struct mem_block *prev;
93         uint64_t start;
94         uint64_t size;
95         DRMFILE filp;           /* 0: free, -1: heap, other: real files */
96         int flags;
97         drm_local_map_t *map;
98 };
99
100 struct nouveau_config {
101         struct {
102                 int location;
103                 int size;
104         } cmdbuf;
105 };
106
107 typedef struct drm_nouveau_private {
108         /* the card type, takes NV_* as values */
109         int card_type;
110         int flags;
111
112         drm_local_map_t *mmio;
113         drm_local_map_t *fb;
114
115         int      cur_fifo;
116
117         struct nouveau_object *fb_obj;
118         struct nouveau_object *cmdbuf_obj;
119         int               cmdbuf_ch_size;
120         struct mem_block* cmdbuf_alloc;
121
122         struct nouveau_fifo fifos[NV_MAX_FIFO_NUMBER];
123         struct nouveau_object_store objs;
124         /* RAMFC and RAMRO offsets */
125         uint32_t ramfc_offset;
126         uint32_t ramro_offset;
127
128         struct mem_block *agp_heap;
129         struct mem_block *fb_heap;
130         struct mem_block *fb_nomap_heap;
131
132         struct nouveau_config config;
133 }
134 drm_nouveau_private_t;
135
136 /* nouveau_state.c */
137 extern void nouveau_preclose(drm_device_t * dev, DRMFILE filp);
138 extern int nouveau_load(struct drm_device *dev, unsigned long flags);
139 extern int nouveau_firstopen(struct drm_device *dev);
140 extern int nouveau_unload(struct drm_device *dev);
141 extern int nouveau_ioctl_getparam(DRM_IOCTL_ARGS);
142 extern int nouveau_ioctl_setparam(DRM_IOCTL_ARGS);
143 extern void nouveau_wait_for_idle(struct drm_device *dev);
144
145 /* nouveau_mem.c */
146 extern uint64_t          nouveau_mem_fb_amount(struct drm_device *dev);
147 extern void              nouveau_mem_release(DRMFILE filp, struct mem_block *heap);
148 extern int               nouveau_ioctl_mem_alloc(DRM_IOCTL_ARGS);
149 extern int               nouveau_ioctl_mem_free(DRM_IOCTL_ARGS);
150 extern struct mem_block* nouveau_mem_alloc(struct drm_device *dev, int alignment, uint64_t size, int flags, DRMFILE filp);
151 extern void              nouveau_mem_free(struct drm_device* dev, struct mem_block*);
152 extern int               nouveau_mem_init(struct drm_device *dev);
153 extern void              nouveau_mem_close(struct drm_device *dev);
154
155 /* nouveau_fifo.c */
156 extern int  nouveau_fifo_number(drm_device_t *dev);
157 extern void nouveau_fifo_cleanup(drm_device_t *dev, DRMFILE filp);
158 extern int  nouveau_fifo_id_get(drm_device_t *dev, DRMFILE filp);
159
160 /* nouveau_object.c */
161 extern void nouveau_hash_table_init(drm_device_t *dev);
162 extern void nouveau_object_cleanup(drm_device_t *dev, DRMFILE filp);
163 extern struct nouveau_object *nouveau_dma_object_create(drm_device_t *dev,
164                 uint32_t offset, uint32_t size, int access, uint32_t target);
165 extern int  nouveau_ioctl_object_init(DRM_IOCTL_ARGS);
166 extern int  nouveau_ioctl_dma_object_init(DRM_IOCTL_ARGS);
167
168 /* nouveau_irq.c */
169 extern irqreturn_t nouveau_irq_handler(DRM_IRQ_ARGS);
170 extern void        nouveau_irq_preinstall(drm_device_t*);
171 extern void        nouveau_irq_postinstall(drm_device_t*);
172 extern void        nouveau_irq_uninstall(drm_device_t*);
173
174 extern long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
175                                 unsigned long arg);
176
177 #if defined(__powerpc__)
178 #define NV_READ(reg)        in_be32((void __iomem *)(dev_priv->mmio)->handle + (reg) )
179 #define NV_WRITE(reg,val)   out_be32((void __iomem *)(dev_priv->mmio)->handle + (reg) , (val) )
180 #else
181 #define NV_READ(reg)        DRM_READ32(  dev_priv->mmio, (reg) )
182 #define NV_WRITE(reg,val)   DRM_WRITE32( dev_priv->mmio, (reg), (val) )
183 #endif
184
185 #endif /* __NOUVEAU_DRV_H__ */
186