via_drv.h revision 1.1.1.4 1 /* $NetBSD: via_drv.h,v 1.1.1.4 2021/12/18 20:15:54 riastradh Exp $ */
2
3 /*
4 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
5 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sub license,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
25 */
26 #ifndef _VIA_DRV_H_
27 #define _VIA_DRV_H_
28
29 #include <linux/irqreturn.h>
30 #include <linux/jiffies.h>
31 #include <linux/sched.h>
32 #include <linux/sched/signal.h>
33 #include <linux/wait.h>
34
35 #include <drm/drm_ioctl.h>
36 #include <drm/drm_legacy.h>
37 #include <drm/drm_mm.h>
38 #include <drm/via_drm.h>
39
40 #define DRIVER_AUTHOR "Various"
41
42 #define DRIVER_NAME "via"
43 #define DRIVER_DESC "VIA Unichrome / Pro"
44 #define DRIVER_DATE "20070202"
45
46 #define DRIVER_MAJOR 2
47 #define DRIVER_MINOR 11
48 #define DRIVER_PATCHLEVEL 1
49
50 #include "via_verifier.h"
51
52 #include "via_dmablit.h"
53
54 #define VIA_PCI_BUF_SIZE 60000
55 #define VIA_FIRE_BUF_SIZE 1024
56 #define VIA_NUM_IRQS 4
57
58 typedef struct drm_via_ring_buffer {
59 drm_local_map_t map;
60 char *virtual_start;
61 } drm_via_ring_buffer_t;
62
63 typedef uint32_t maskarray_t[5];
64
65 typedef struct drm_via_irq {
66 atomic_t irq_received;
67 uint32_t pending_mask;
68 uint32_t enable_mask;
69 wait_queue_head_t irq_queue;
70 } drm_via_irq_t;
71
72 typedef struct drm_via_private {
73 drm_via_sarea_t *sarea_priv;
74 drm_local_map_t *sarea;
75 drm_local_map_t *fb;
76 drm_local_map_t *mmio;
77 unsigned long agpAddr;
78 wait_queue_head_t decoder_queue[VIA_NR_XVMC_LOCKS];
79 char *dma_ptr;
80 unsigned int dma_low;
81 unsigned int dma_high;
82 unsigned int dma_offset;
83 uint32_t dma_wrap;
84 volatile uint32_t *last_pause_ptr;
85 volatile uint32_t *hw_addr_ptr;
86 drm_via_ring_buffer_t ring;
87 ktime_t last_vblank;
88 int last_vblank_valid;
89 ktime_t nsec_per_vblank;
90 atomic_t vbl_received;
91 drm_via_state_t hc_state;
92 char pci_buf[VIA_PCI_BUF_SIZE];
93 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
94 uint32_t num_fire_offsets;
95 int chipset;
96 drm_via_irq_t via_irqs[VIA_NUM_IRQS];
97 unsigned num_irqs;
98 maskarray_t *irq_masks;
99 uint32_t irq_enable_mask;
100 uint32_t irq_pending_mask;
101 int *irq_map;
102 unsigned int idle_fault;
103 int vram_initialized;
104 struct drm_mm vram_mm;
105 int agp_initialized;
106 struct drm_mm agp_mm;
107 /** Mapping of userspace keys to mm objects */
108 struct idr object_idr;
109 unsigned long vram_offset;
110 unsigned long agp_offset;
111 drm_via_blitq_t blit_queues[VIA_NUM_BLIT_ENGINES];
112 uint32_t dma_diff;
113 } drm_via_private_t;
114
115 struct via_file_private {
116 struct list_head obj_list;
117 };
118
119 enum via_family {
120 VIA_OTHER = 0, /* Baseline */
121 VIA_PRO_GROUP_A, /* Another video engine and DMA commands */
122 VIA_DX9_0 /* Same video as pro_group_a, but 3D is unsupported */
123 };
124
125 /* VIA MMIO register access */
126 static inline u32 via_read(struct drm_via_private *dev_priv, u32 reg)
127 {
128 return readl((void __iomem *)(dev_priv->mmio->handle + reg));
129 }
130
131 static inline void via_write(struct drm_via_private *dev_priv, u32 reg,
132 u32 val)
133 {
134 writel(val, (void __iomem *)(dev_priv->mmio->handle + reg));
135 }
136
137 static inline void via_write8(struct drm_via_private *dev_priv, u32 reg,
138 u32 val)
139 {
140 writeb(val, (void __iomem *)(dev_priv->mmio->handle + reg));
141 }
142
143 static inline void via_write8_mask(struct drm_via_private *dev_priv,
144 u32 reg, u32 mask, u32 val)
145 {
146 u32 tmp;
147
148 tmp = readb((void __iomem *)(dev_priv->mmio->handle + reg));
149 tmp = (tmp & ~mask) | (val & mask);
150 writeb(tmp, (void __iomem *)(dev_priv->mmio->handle + reg));
151 }
152
153 /*
154 * Poll in a loop waiting for 'contidition' to be true.
155 * Note: A direct replacement with wait_event_interruptible_timeout()
156 * will not work unless driver is updated to emit wake_up()
157 * in relevant places that can impact the 'condition'
158 *
159 * Returns:
160 * ret keeps current value if 'condition' becomes true
161 * ret = -BUSY if timeout happens
162 * ret = -EINTR if a signal interrupted the waiting period
163 */
164 #define VIA_WAIT_ON( ret, queue, timeout, condition ) \
165 do { \
166 DECLARE_WAITQUEUE(entry, current); \
167 unsigned long end = jiffies + (timeout); \
168 add_wait_queue(&(queue), &entry); \
169 \
170 for (;;) { \
171 __set_current_state(TASK_INTERRUPTIBLE); \
172 if (condition) \
173 break; \
174 if (time_after_eq(jiffies, end)) { \
175 ret = -EBUSY; \
176 break; \
177 } \
178 schedule_timeout((HZ/100 > 1) ? HZ/100 : 1); \
179 if (signal_pending(current)) { \
180 ret = -EINTR; \
181 break; \
182 } \
183 } \
184 __set_current_state(TASK_RUNNING); \
185 remove_wait_queue(&(queue), &entry); \
186 } while (0)
187
188 extern const struct drm_ioctl_desc via_ioctls[];
189 extern int via_max_ioctl;
190
191 extern int via_fb_init(struct drm_device *dev, void *data, struct drm_file *file_priv);
192 extern int via_mem_alloc(struct drm_device *dev, void *data, struct drm_file *file_priv);
193 extern int via_mem_free(struct drm_device *dev, void *data, struct drm_file *file_priv);
194 extern int via_agp_init(struct drm_device *dev, void *data, struct drm_file *file_priv);
195 extern int via_map_init(struct drm_device *dev, void *data, struct drm_file *file_priv);
196 extern int via_decoder_futex(struct drm_device *dev, void *data, struct drm_file *file_priv);
197 extern int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv);
198 extern int via_dma_blit_sync(struct drm_device *dev, void *data, struct drm_file *file_priv);
199 extern int via_dma_blit(struct drm_device *dev, void *data, struct drm_file *file_priv);
200
201 extern int via_driver_load(struct drm_device *dev, unsigned long chipset);
202 extern void via_driver_unload(struct drm_device *dev);
203
204 extern int via_init_context(struct drm_device *dev, int context);
205 extern int via_final_context(struct drm_device *dev, int context);
206
207 extern int via_do_cleanup_map(struct drm_device *dev);
208 extern u32 via_get_vblank_counter(struct drm_device *dev, unsigned int pipe);
209 extern int via_enable_vblank(struct drm_device *dev, unsigned int pipe);
210 extern void via_disable_vblank(struct drm_device *dev, unsigned int pipe);
211
212 extern irqreturn_t via_driver_irq_handler(int irq, void *arg);
213 extern void via_driver_irq_preinstall(struct drm_device *dev);
214 extern int via_driver_irq_postinstall(struct drm_device *dev);
215 extern void via_driver_irq_uninstall(struct drm_device *dev);
216
217 extern int via_dma_cleanup(struct drm_device *dev);
218 extern void via_init_command_verifier(void);
219 extern int via_driver_dma_quiescent(struct drm_device *dev);
220 extern void via_init_futex(drm_via_private_t *dev_priv);
221 extern void via_cleanup_futex(drm_via_private_t *dev_priv);
222 extern void via_release_futex(drm_via_private_t *dev_priv, int context);
223
224 extern void via_reclaim_buffers_locked(struct drm_device *dev,
225 struct drm_file *file_priv);
226 extern void via_lastclose(struct drm_device *dev);
227
228 extern void via_dmablit_handler(struct drm_device *dev, int engine, int from_irq);
229 extern void via_init_dmablit(struct drm_device *dev);
230
231 #endif
232