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.
27 #include <linux/irqreturn.h>
28 #include <linux/jiffies.h>
29 #include <linux/sched.h>
30 #include <linux/sched/signal.h>
31 #include <linux/wait.h>
33 #include <drm/drm_ioctl.h>
34 #include <drm/drm_legacy.h>
35 #include <drm/drm_mm.h>
36 #include <drm/via_drm.h>
38 #define DRIVER_AUTHOR "Various"
40 #define DRIVER_NAME "via"
41 #define DRIVER_DESC "VIA Unichrome / Pro"
42 #define DRIVER_DATE "20070202"
44 #define DRIVER_MAJOR 2
45 #define DRIVER_MINOR 11
46 #define DRIVER_PATCHLEVEL 1
48 #include "via_verifier.h"
50 #include "via_dmablit.h"
52 #define VIA_PCI_BUF_SIZE 60000
53 #define VIA_FIRE_BUF_SIZE 1024
54 #define VIA_NUM_IRQS 4
56 typedef struct drm_via_ring_buffer
{
59 } drm_via_ring_buffer_t
;
61 typedef uint32_t maskarray_t
[5];
63 typedef struct drm_via_irq
{
64 atomic_t irq_received
;
65 uint32_t pending_mask
;
67 wait_queue_head_t irq_queue
;
70 typedef struct drm_via_private
{
71 drm_via_sarea_t
*sarea_priv
;
72 drm_local_map_t
*sarea
;
74 drm_local_map_t
*mmio
;
75 unsigned long agpAddr
;
76 wait_queue_head_t decoder_queue
[VIA_NR_XVMC_LOCKS
];
79 unsigned int dma_high
;
80 unsigned int dma_offset
;
82 volatile uint32_t *last_pause_ptr
;
83 volatile uint32_t *hw_addr_ptr
;
84 drm_via_ring_buffer_t ring
;
86 int last_vblank_valid
;
87 ktime_t nsec_per_vblank
;
88 atomic_t vbl_received
;
89 drm_via_state_t hc_state
;
90 char pci_buf
[VIA_PCI_BUF_SIZE
];
91 const uint32_t *fire_offsets
[VIA_FIRE_BUF_SIZE
];
92 uint32_t num_fire_offsets
;
94 drm_via_irq_t via_irqs
[VIA_NUM_IRQS
];
96 maskarray_t
*irq_masks
;
97 uint32_t irq_enable_mask
;
98 uint32_t irq_pending_mask
;
100 unsigned int idle_fault
;
101 int vram_initialized
;
102 struct drm_mm vram_mm
;
104 struct drm_mm agp_mm
;
105 /** Mapping of userspace keys to mm objects */
106 struct idr object_idr
;
107 unsigned long vram_offset
;
108 unsigned long agp_offset
;
109 drm_via_blitq_t blit_queues
[VIA_NUM_BLIT_ENGINES
];
113 struct via_file_private
{
114 struct list_head obj_list
;
118 VIA_OTHER
= 0, /* Baseline */
119 VIA_PRO_GROUP_A
, /* Another video engine and DMA commands */
120 VIA_DX9_0
/* Same video as pro_group_a, but 3D is unsupported */
123 /* VIA MMIO register access */
124 static inline u32
via_read(struct drm_via_private
*dev_priv
, u32 reg
)
126 return readl((void __iomem
*)(dev_priv
->mmio
->handle
+ reg
));
129 static inline void via_write(struct drm_via_private
*dev_priv
, u32 reg
,
132 writel(val
, (void __iomem
*)(dev_priv
->mmio
->handle
+ reg
));
135 static inline void via_write8(struct drm_via_private
*dev_priv
, u32 reg
,
138 writeb(val
, (void __iomem
*)(dev_priv
->mmio
->handle
+ reg
));
141 static inline void via_write8_mask(struct drm_via_private
*dev_priv
,
142 u32 reg
, u32 mask
, u32 val
)
146 tmp
= readb((void __iomem
*)(dev_priv
->mmio
->handle
+ reg
));
147 tmp
= (tmp
& ~mask
) | (val
& mask
);
148 writeb(tmp
, (void __iomem
*)(dev_priv
->mmio
->handle
+ reg
));
152 * Poll in a loop waiting for 'contidition' to be true.
153 * Note: A direct replacement with wait_event_interruptible_timeout()
154 * will not work unless driver is updated to emit wake_up()
155 * in relevant places that can impact the 'condition'
158 * ret keeps current value if 'condition' becomes true
159 * ret = -BUSY if timeout happens
160 * ret = -EINTR if a signal interrupted the waiting period
162 #define VIA_WAIT_ON( ret, queue, timeout, condition ) \
164 DECLARE_WAITQUEUE(entry, current); \
165 unsigned long end = jiffies + (timeout); \
166 add_wait_queue(&(queue), &entry); \
169 __set_current_state(TASK_INTERRUPTIBLE); \
172 if (time_after_eq(jiffies, end)) { \
176 schedule_timeout((HZ/100 > 1) ? HZ/100 : 1); \
177 if (signal_pending(current)) { \
182 __set_current_state(TASK_RUNNING); \
183 remove_wait_queue(&(queue), &entry); \
186 extern const struct drm_ioctl_desc via_ioctls
[];
187 extern int via_max_ioctl
;
189 extern int via_fb_init(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
);
190 extern int via_mem_alloc(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
);
191 extern int via_mem_free(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
);
192 extern int via_agp_init(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
);
193 extern int via_map_init(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
);
194 extern int via_decoder_futex(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
);
195 extern int via_wait_irq(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
);
196 extern int via_dma_blit_sync(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
);
197 extern int via_dma_blit(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
);
199 extern int via_driver_load(struct drm_device
*dev
, unsigned long chipset
);
200 extern void via_driver_unload(struct drm_device
*dev
);
202 extern int via_init_context(struct drm_device
*dev
, int context
);
203 extern int via_final_context(struct drm_device
*dev
, int context
);
205 extern int via_do_cleanup_map(struct drm_device
*dev
);
206 extern u32
via_get_vblank_counter(struct drm_device
*dev
, unsigned int pipe
);
207 extern int via_enable_vblank(struct drm_device
*dev
, unsigned int pipe
);
208 extern void via_disable_vblank(struct drm_device
*dev
, unsigned int pipe
);
210 extern irqreturn_t
via_driver_irq_handler(int irq
, void *arg
);
211 extern void via_driver_irq_preinstall(struct drm_device
*dev
);
212 extern int via_driver_irq_postinstall(struct drm_device
*dev
);
213 extern void via_driver_irq_uninstall(struct drm_device
*dev
);
215 extern int via_dma_cleanup(struct drm_device
*dev
);
216 extern void via_init_command_verifier(void);
217 extern int via_driver_dma_quiescent(struct drm_device
*dev
);
218 extern void via_init_futex(drm_via_private_t
*dev_priv
);
219 extern void via_cleanup_futex(drm_via_private_t
*dev_priv
);
220 extern void via_release_futex(drm_via_private_t
*dev_priv
, int context
);
222 extern void via_reclaim_buffers_locked(struct drm_device
*dev
,
223 struct drm_file
*file_priv
);
224 extern void via_lastclose(struct drm_device
*dev
);
226 extern void via_dmablit_handler(struct drm_device
*dev
, int engine
, int from_irq
);
227 extern void via_init_dmablit(struct drm_device
*dev
);