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
67 #define VIA_PCI_BUF_SIZE 60000
68 #define VIA_FIRE_BUF_SIZE 1024
69 #define VIA_NUM_IRQS 4
71 typedef struct drm_via_ring_buffer {
74 } drm_via_ring_buffer_t;
76 typedef uint32_t maskarray_t[5];
78 typedef struct drm_via_irq {
79 atomic_t irq_received;
80 uint32_t pending_mask;
82 wait_queue_head_t irq_queue;
85 typedef struct drm_via_private {
86 drm_via_sarea_t *sarea_priv;
87 drm_local_map_t *sarea;
89 drm_local_map_t *mmio;
90 unsigned long agpAddr;
91 wait_queue_head_t decoder_queue[VIA_NR_XVMC_LOCKS];
94 unsigned int dma_high;
95 unsigned int dma_offset;
97 volatile uint32_t *last_pause_ptr;
98 volatile uint32_t *hw_addr_ptr;
99 drm_via_ring_buffer_t ring;
100 struct timeval last_vblank;
101 int last_vblank_valid;
102 unsigned usec_per_vblank;
103 atomic_t vbl_received;
104 drm_via_state_t hc_state;
105 char pci_buf[VIA_PCI_BUF_SIZE];
106 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
107 uint32_t num_fire_offsets;
109 drm_via_irq_t via_irqs[VIA_NUM_IRQS];
111 maskarray_t *irq_masks;
112 uint32_t irq_enable_mask;
113 uint32_t irq_pending_mask;
115 /* Memory manager stuff */
116 #ifdef VIA_HAVE_CORE_MM
117 unsigned int idle_fault;
118 struct drm_sman sman;
119 int vram_initialized;
121 unsigned long vram_offset;
122 unsigned long agp_offset;
124 #ifdef VIA_HAVE_DMABLIT
125 drm_via_blitq_t blit_queues[VIA_NUM_BLIT_ENGINES];
128 #ifdef VIA_HAVE_FENCE
129 spinlock_t fence_lock;
130 uint32_t emit_0_sequence;
132 struct timer_list fence_timer;
137 VIA_OTHER = 0, /* Baseline */
138 VIA_PRO_GROUP_A, /* Another video engine and DMA commands */
139 VIA_DX9_0 /* Same video as pro_group_a, but 3D is unsupported */
142 /* VIA MMIO register access */
143 #define VIA_BASE ((dev_priv->mmio))
145 #define VIA_READ(reg) DRM_READ32(VIA_BASE, reg)
146 #define VIA_WRITE(reg,val) DRM_WRITE32(VIA_BASE, reg, val)
147 #define VIA_READ8(reg) DRM_READ8(VIA_BASE, reg)
148 #define VIA_WRITE8(reg,val) DRM_WRITE8(VIA_BASE, reg, val)
150 extern struct drm_ioctl_desc via_ioctls[];
151 extern int via_max_ioctl;
153 extern int via_fb_init(struct drm_device *dev, void *data, struct drm_file *file_priv);
154 extern int via_mem_alloc(struct drm_device *dev, void *data, struct drm_file *file_priv);
155 extern int via_mem_free(struct drm_device *dev, void *data, struct drm_file *file_priv);
156 extern int via_agp_init(struct drm_device *dev, void *data, struct drm_file *file_priv);
157 extern int via_map_init(struct drm_device *dev, void *data, struct drm_file *file_priv);
158 extern int via_decoder_futex(struct drm_device *dev, void *data, struct drm_file *file_priv);
159 extern int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv);
160 extern int via_dma_blit_sync( struct drm_device *dev, void *data, struct drm_file *file_priv );
161 extern int via_dma_blit( struct drm_device *dev, void *data, struct drm_file *file_priv );
163 extern int via_driver_load(struct drm_device *dev, unsigned long chipset);
164 extern int via_driver_unload(struct drm_device *dev);
165 extern int via_final_context(struct drm_device * dev, int context);
167 extern int via_do_cleanup_map(struct drm_device * dev);
168 extern u32 via_get_vblank_counter(struct drm_device *dev, int crtc);
169 extern int via_enable_vblank(struct drm_device *dev, int crtc);
170 extern void via_disable_vblank(struct drm_device *dev, int crtc);
172 extern irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS);
173 extern void via_driver_irq_preinstall(struct drm_device * dev);
174 extern int via_driver_irq_postinstall(struct drm_device * dev);
175 extern void via_driver_irq_uninstall(struct drm_device * dev);
177 extern int via_dma_cleanup(struct drm_device * dev);
178 extern void via_init_command_verifier(void);
179 extern int via_driver_dma_quiescent(struct drm_device * dev);
180 extern void via_init_futex(drm_via_private_t *dev_priv);
181 extern void via_cleanup_futex(drm_via_private_t *dev_priv);
182 extern void via_release_futex(drm_via_private_t *dev_priv, int context);
184 #ifdef VIA_HAVE_CORE_MM
185 extern void via_reclaim_buffers_locked(struct drm_device *dev,
186 struct drm_file *file_priv);
187 extern void via_lastclose(struct drm_device *dev);
189 extern int via_init_context(struct drm_device * dev, int context);
192 #ifdef VIA_HAVE_DMABLIT
193 extern void via_dmablit_handler(struct drm_device *dev, int engine, int from_irq);
194 extern void via_init_dmablit(struct drm_device *dev);