OSDN Git Service

mach64: fix after vblank-rework
[android-x86/external-libdrm.git] / shared-core / via_drv.h
1 /*
2  * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3  * Copyright 2001-2003 S3 Graphics, Inc. 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, sub license,
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
13  * next paragraph) shall be included in all copies or substantial portions
14  * of the 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 NON-INFRINGEMENT. IN NO EVENT SHALL
19  * VIA, S3 GRAPHICS, 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 OTHER
22  * DEALINGS IN THE SOFTWARE.
23  */
24 #ifndef _VIA_DRV_H_
25 #define _VIA_DRV_H_
26
27 #include "drm_sman.h"
28 #define DRIVER_AUTHOR   "Various"
29
30 #define DRIVER_NAME             "via"
31 #define DRIVER_DESC             "VIA Unichrome / Pro"
32
33 #include "via_verifier.h"
34
35 /*
36  * Registers go here.
37  */
38
39
40 #define CMDBUF_ALIGNMENT_SIZE   (0x100)
41 #define CMDBUF_ALIGNMENT_MASK   (0x0ff)
42
43 /* defines for VIA 3D registers */
44 #define VIA_REG_STATUS          0x400
45 #define VIA_REG_TRANSET         0x43C
46 #define VIA_REG_TRANSPACE       0x440
47
48 /* VIA_REG_STATUS(0x400): Engine Status */
49 #define VIA_CMD_RGTR_BUSY       0x00000080      /* Command Regulator is busy */
50 #define VIA_2D_ENG_BUSY         0x00000001      /* 2D Engine is busy */
51 #define VIA_3D_ENG_BUSY         0x00000002      /* 3D Engine is busy */
52 #define VIA_VR_QUEUE_BUSY       0x00020000      /* Virtual Queue is busy */
53
54
55
56 #if defined(__linux__)
57 #include "via_dmablit.h"
58
59 /*
60  * This define and all its references can be removed when
61  * the DMA blit code has been implemented for FreeBSD.
62  */
63 #define VIA_HAVE_DMABLIT 1
64 #define VIA_HAVE_CORE_MM 1
65 #define VIA_HAVE_FENCE   1
66 #define VIA_HAVE_BUFFER  1
67 #endif
68
69 #define VIA_PCI_BUF_SIZE 60000
70 #define VIA_FIRE_BUF_SIZE  1024
71 #define VIA_NUM_IRQS 4
72
73 typedef struct drm_via_ring_buffer {
74         drm_local_map_t map;
75         char *virtual_start;
76 } drm_via_ring_buffer_t;
77
78 typedef uint32_t maskarray_t[5];
79
80 typedef struct drm_via_irq {
81         atomic_t irq_received;
82         uint32_t pending_mask;
83         uint32_t enable_mask;
84         wait_queue_head_t irq_queue;
85 } drm_via_irq_t;
86
87 typedef struct drm_via_private {
88         drm_via_sarea_t *sarea_priv;
89         drm_local_map_t *sarea;
90         drm_local_map_t *fb;
91         drm_local_map_t *mmio;
92         unsigned long agpAddr;
93         wait_queue_head_t decoder_queue[VIA_NR_XVMC_LOCKS];
94         char *dma_ptr;
95         unsigned int dma_low;
96         unsigned int dma_high;
97         unsigned int dma_offset;
98         uint32_t dma_wrap;
99         volatile uint32_t *last_pause_ptr;
100         volatile uint32_t *hw_addr_ptr;
101         drm_via_ring_buffer_t ring;
102         struct timeval last_vblank;
103         int last_vblank_valid;
104         unsigned usec_per_vblank;
105         atomic_t vbl_received;
106         drm_via_state_t hc_state;
107         char pci_buf[VIA_PCI_BUF_SIZE];
108         const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
109         uint32_t num_fire_offsets;
110         int chipset;
111         drm_via_irq_t via_irqs[VIA_NUM_IRQS];
112         unsigned num_irqs;
113         maskarray_t *irq_masks;
114         uint32_t irq_enable_mask;
115         uint32_t irq_pending_mask;
116         int *irq_map;
117         /* Memory manager stuff */
118 #ifdef VIA_HAVE_CORE_MM
119         unsigned int idle_fault;
120         struct drm_sman sman;
121         int vram_initialized;
122         int agp_initialized;
123         unsigned long vram_offset;
124         unsigned long agp_offset;
125 #endif
126 #ifdef VIA_HAVE_DMABLIT
127         drm_via_blitq_t blit_queues[VIA_NUM_BLIT_ENGINES];
128 #endif
129         uint32_t dma_diff;
130 #ifdef VIA_HAVE_FENCE
131         spinlock_t fence_lock;
132         uint32_t emit_0_sequence;
133         int have_idlelock;
134         struct timer_list fence_timer;
135 #endif
136 } drm_via_private_t;
137
138 enum via_family {
139   VIA_OTHER = 0,     /* Baseline */
140   VIA_PRO_GROUP_A,   /* Another video engine and DMA commands */
141   VIA_DX9_0          /* Same video as pro_group_a, but 3D is unsupported */
142 };
143
144 /* VIA MMIO register access */
145 #define VIA_BASE ((dev_priv->mmio))
146
147 #define VIA_READ(reg)           DRM_READ32(VIA_BASE, reg)
148 #define VIA_WRITE(reg,val)      DRM_WRITE32(VIA_BASE, reg, val)
149 #define VIA_READ8(reg)          DRM_READ8(VIA_BASE, reg)
150 #define VIA_WRITE8(reg,val)     DRM_WRITE8(VIA_BASE, reg, val)
151
152 extern struct drm_ioctl_desc via_ioctls[];
153 extern int via_max_ioctl;
154
155 extern int via_fb_init(struct drm_device *dev, void *data, struct drm_file *file_priv);
156 extern int via_mem_alloc(struct drm_device *dev, void *data, struct drm_file *file_priv);
157 extern int via_mem_free(struct drm_device *dev, void *data, struct drm_file *file_priv);
158 extern int via_agp_init(struct drm_device *dev, void *data, struct drm_file *file_priv);
159 extern int via_map_init(struct drm_device *dev, void *data, struct drm_file *file_priv);
160 extern int via_decoder_futex(struct drm_device *dev, void *data, struct drm_file *file_priv);
161 extern int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv);
162 extern int via_dma_blit_sync( struct drm_device *dev, void *data, struct drm_file *file_priv );
163 extern int via_dma_blit( struct drm_device *dev, void *data, struct drm_file *file_priv );
164
165 extern int via_driver_load(struct drm_device *dev, unsigned long chipset);
166 extern int via_driver_unload(struct drm_device *dev);
167 extern int via_final_context(struct drm_device * dev, int context);
168
169 extern int via_do_cleanup_map(struct drm_device * dev);
170 extern u32 via_get_vblank_counter(struct drm_device *dev, int crtc);
171 extern int via_enable_vblank(struct drm_device *dev, int crtc);
172 extern void via_disable_vblank(struct drm_device *dev, int crtc);
173
174 extern irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS);
175 extern void via_driver_irq_preinstall(struct drm_device * dev);
176 extern int via_driver_irq_postinstall(struct drm_device * dev);
177 extern void via_driver_irq_uninstall(struct drm_device * dev);
178
179 extern int via_dma_cleanup(struct drm_device * dev);
180 extern void via_init_command_verifier(void);
181 extern int via_driver_dma_quiescent(struct drm_device * dev);
182 extern void via_init_futex(drm_via_private_t *dev_priv);
183 extern void via_cleanup_futex(drm_via_private_t *dev_priv);
184 extern void via_release_futex(drm_via_private_t *dev_priv, int context);
185
186 #ifdef VIA_HAVE_CORE_MM
187 extern void via_reclaim_buffers_locked(struct drm_device *dev,
188                                        struct drm_file *file_priv);
189 extern void via_lastclose(struct drm_device *dev);
190 #else
191 extern int via_init_context(struct drm_device * dev, int context);
192 #endif
193
194 #ifdef VIA_HAVE_DMABLIT
195 extern void via_dmablit_handler(struct drm_device *dev, int engine, int from_irq);
196 extern void via_init_dmablit(struct drm_device *dev);
197 #endif
198
199 #ifdef VIA_HAVE_FENCE
200 extern void via_fence_timer(unsigned long data);
201 extern void via_poke_flush(struct drm_device * dev, uint32_t class);
202 extern int via_fence_emit_sequence(struct drm_device * dev, uint32_t class,
203                                    uint32_t flags,
204                                    uint32_t * sequence,
205                                    uint32_t * native_type);
206 extern int via_fence_has_irq(struct drm_device * dev, uint32_t class,
207                              uint32_t flags);
208 #endif
209
210 #ifdef VIA_HAVE_BUFFER
211 extern struct drm_ttm_backend *via_create_ttm_backend_entry(struct drm_device *dev);
212 extern int via_fence_types(struct drm_buffer_object *bo, uint32_t *fclass,
213                            uint32_t *type);
214 extern int via_invalidate_caches(struct drm_device *dev, uint64_t buffer_flags);
215 extern int via_init_mem_type(struct drm_device *dev, uint32_t type,
216                                struct drm_mem_type_manager *man);
217 extern uint64_t via_evict_flags(struct drm_buffer_object *bo);
218 extern int via_move(struct drm_buffer_object *bo, int evict,
219                 int no_wait, struct drm_bo_mem_reg *new_mem);
220 #endif
221
222 #endif