2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
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:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
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.
28 #define DRIVER_AUTHOR "Various"
30 #define DRIVER_NAME "via"
31 #define DRIVER_DESC "VIA Unichrome / Pro"
33 #include "via_verifier.h"
40 #define CMDBUF_ALIGNMENT_SIZE (0x100)
41 #define CMDBUF_ALIGNMENT_MASK (0x0ff)
43 /* defines for VIA 3D registers */
44 #define VIA_REG_STATUS 0x400
45 #define VIA_REG_TRANSET 0x43C
46 #define VIA_REG_TRANSPACE 0x440
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 */
56 #if defined(__linux__)
57 #include "via_dmablit.h"
60 * This define and all its references can be removed when
61 * the DMA blit code has been implemented for FreeBSD.
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
69 #define VIA_PCI_BUF_SIZE 60000
70 #define VIA_FIRE_BUF_SIZE 1024
71 #define VIA_NUM_IRQS 4
73 typedef struct drm_via_ring_buffer {
76 } drm_via_ring_buffer_t;
78 typedef uint32_t maskarray_t[5];
80 typedef struct drm_via_irq {
81 atomic_t irq_received;
82 uint32_t pending_mask;
84 wait_queue_head_t irq_queue;
87 typedef struct drm_via_private {
88 drm_via_sarea_t *sarea_priv;
89 drm_local_map_t *sarea;
91 drm_local_map_t *mmio;
92 unsigned long agpAddr;
93 wait_queue_head_t decoder_queue[VIA_NR_XVMC_LOCKS];
96 unsigned int dma_high;
97 unsigned int dma_offset;
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;
111 drm_via_irq_t via_irqs[VIA_NUM_IRQS];
113 maskarray_t *irq_masks;
114 uint32_t irq_enable_mask;
115 uint32_t irq_pending_mask;
117 /* Memory manager stuff */
118 #ifdef VIA_HAVE_CORE_MM
119 unsigned int idle_fault;
120 struct drm_sman sman;
121 int vram_initialized;
123 unsigned long vram_offset;
124 unsigned long agp_offset;
126 #ifdef VIA_HAVE_DMABLIT
127 drm_via_blitq_t blit_queues[VIA_NUM_BLIT_ENGINES];
130 #ifdef VIA_HAVE_FENCE
131 spinlock_t fence_lock;
132 uint32_t emit_0_sequence;
134 struct timer_list fence_timer;
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 */
144 /* VIA MMIO register access */
145 #define VIA_BASE ((dev_priv->mmio))
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)
152 extern struct drm_ioctl_desc via_ioctls[];
153 extern int via_max_ioctl;
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 );
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);
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);
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);
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);
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);
191 extern int via_init_context(struct drm_device * dev, int context);
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);
199 #ifdef VIA_HAVE_BUFFER
200 extern struct drm_ttm_backend *via_create_ttm_backend_entry(struct drm_device *dev);
201 extern int via_fence_types(struct drm_buffer_object *bo, uint32_t *fclass,
203 extern int via_invalidate_caches(struct drm_device *dev, uint64_t buffer_flags);
204 extern int via_init_mem_type(struct drm_device *dev, uint32_t type,
205 struct drm_mem_type_manager *man);
206 extern uint64_t via_evict_flags(struct drm_buffer_object *bo);
207 extern int via_move(struct drm_buffer_object *bo, int evict,
208 int no_wait, struct drm_bo_mem_reg *new_mem);