Merge the pciid work.
[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       1
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         struct mem_block *instance;
56         uint32_t          ht_loc;
57
58         uint32_t handle;
59         int      class;
60         int      engine;
61 };
62
63 #define NV_DMA_TARGET_VIDMEM 0
64 #define NV_DMA_TARGET_PCI    2
65 #define NV_DMA_TARGET_AGP    3
66 struct nouveau_fifo
67 {
68         int used;
69         /* owner of this fifo */
70         DRMFILE filp;
71         /* mapping of the fifo itself */
72         drm_local_map_t *map;
73         /* mapping of the regs controling the fifo */
74         drm_local_map_t *regs;
75         /* dma object for the command buffer itself */
76         struct nouveau_object *cmdbuf_obj;
77         /* objects belonging to this fifo */
78         struct nouveau_object *objs;
79 };
80
81 struct mem_block {
82         struct mem_block *next;
83         struct mem_block *prev;
84         uint64_t start;
85         uint64_t size;
86         DRMFILE filp;           /* 0: free, -1: heap, other: real files */
87         int flags;
88         drm_local_map_t *map;
89 };
90
91 struct nouveau_config {
92         struct {
93                 int location;
94                 int size;
95         } cmdbuf;
96 };
97
98 typedef struct drm_nouveau_private {
99         /* the card type, takes NV_* as values */
100         int card_type;
101         int flags;
102
103         drm_local_map_t *mmio;
104         drm_local_map_t *fb;
105
106         //TODO: Remove me, I'm bogus :)
107         int      cur_fifo;
108
109         struct nouveau_object *fb_obj;
110         int               cmdbuf_ch_size;
111         struct mem_block* cmdbuf_alloc;
112
113         int fifo_alloc_count;
114         struct nouveau_fifo fifos[NV_MAX_FIFO_NUMBER];
115
116         /* RAMFC and RAMRO offsets */
117         uint32_t ramht_offset;
118         uint32_t ramht_size;
119         uint32_t ramht_bits;
120         uint32_t ramfc_offset;
121         uint32_t ramfc_size;
122         uint32_t ramro_offset;
123         uint32_t ramro_size;
124
125         /* base physical adresses */
126         uint64_t fb_phys;
127         uint64_t agp_phys;
128
129         struct mem_block *agp_heap;
130         struct mem_block *fb_heap;
131         struct mem_block *fb_nomap_heap;
132         struct mem_block *ramin_heap;
133
134         struct nouveau_config config;
135 }
136 drm_nouveau_private_t;
137
138 /* nouveau_state.c */
139 extern void nouveau_preclose(drm_device_t * dev, DRMFILE filp);
140 extern int nouveau_load(struct drm_device *dev, unsigned long flags);
141 extern int nouveau_firstopen(struct drm_device *dev);
142 extern int nouveau_unload(struct drm_device *dev);
143 extern int nouveau_ioctl_getparam(DRM_IOCTL_ARGS);
144 extern int nouveau_ioctl_setparam(DRM_IOCTL_ARGS);
145 extern void nouveau_wait_for_idle(struct drm_device *dev);
146
147 /* nouveau_mem.c */
148 extern uint64_t          nouveau_mem_fb_amount(struct drm_device *dev);
149 extern void              nouveau_mem_release(DRMFILE filp, struct mem_block *heap);
150 extern int               nouveau_ioctl_mem_alloc(DRM_IOCTL_ARGS);
151 extern int               nouveau_ioctl_mem_free(DRM_IOCTL_ARGS);
152 extern struct mem_block* nouveau_mem_alloc(struct drm_device *dev, int alignment, uint64_t size, int flags, DRMFILE filp);
153 extern void              nouveau_mem_free(struct drm_device* dev, struct mem_block*);
154 extern int               nouveau_mem_init(struct drm_device *dev);
155 extern void              nouveau_mem_close(struct drm_device *dev);
156 extern int               nouveau_instmem_init(struct drm_device *dev,
157                                               uint32_t offset, uint32_t size);
158 extern struct mem_block* nouveau_instmem_alloc(struct drm_device *dev,
159                                                uint32_t size, uint32_t align);
160 extern void              nouveau_instmem_free(struct drm_device *dev,
161                                               struct mem_block *block);
162
163 /* nouveau_fifo.c */
164 extern int  nouveau_fifo_init(drm_device_t *dev);
165 extern int  nouveau_fifo_number(drm_device_t *dev);
166 extern void nouveau_fifo_cleanup(drm_device_t *dev, DRMFILE filp);
167 extern int  nouveau_fifo_id_get(drm_device_t *dev, DRMFILE filp);
168
169 /* nouveau_object.c */
170 extern void nouveau_object_cleanup(drm_device_t *dev, DRMFILE filp);
171 extern struct nouveau_object *nouveau_dma_object_create(drm_device_t *dev,
172                 uint32_t offset, uint32_t size, int access, uint32_t target);
173 extern int  nouveau_ioctl_object_init(DRM_IOCTL_ARGS);
174 extern int  nouveau_ioctl_dma_object_init(DRM_IOCTL_ARGS);
175 extern uint32_t nouveau_chip_instance_get(drm_device_t *dev, struct mem_block *mem);
176
177 /* nouveau_irq.c */
178 extern irqreturn_t nouveau_irq_handler(DRM_IRQ_ARGS);
179 extern void        nouveau_irq_preinstall(drm_device_t*);
180 extern void        nouveau_irq_postinstall(drm_device_t*);
181 extern void        nouveau_irq_uninstall(drm_device_t*);
182
183 extern long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
184                                 unsigned long arg);
185
186 #if defined(__powerpc__)
187 #define NV_READ(reg)        in_be32((void __iomem *)(dev_priv->mmio)->handle + (reg) )
188 #define NV_WRITE(reg,val)   out_be32((void __iomem *)(dev_priv->mmio)->handle + (reg) , (val) )
189 #else
190 #define NV_READ(reg)        DRM_READ32(  dev_priv->mmio, (reg) )
191 #define NV_WRITE(reg,val)   DRM_WRITE32( dev_priv->mmio, (reg), (val) )
192 #endif
193
194 #define INSTANCE_WR(mem,ofs,val) NV_WRITE(NV_RAMIN+(uint32_t)(mem)->start+((ofs)<<2),(val))
195 #define INSTANCE_RD(mem,ofs)     NV_READ(NV_RAMIN+(uint32_t)(mem)->start+((ofs)<<2))
196
197 #endif /* __NOUVEAU_DRV_H__ */
198