via_drv.h revision 1.4.18.1 1 /* $NetBSD: via_drv.h,v 1.4.18.1 2019/06/10 22:08:28 christos 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 <drm/drm_mm.h>
30 #include <drm/drm_legacy.h>
31
32 #define DRIVER_AUTHOR "Various"
33
34 #define DRIVER_NAME "via"
35 #define DRIVER_DESC "VIA Unichrome / Pro"
36 #define DRIVER_DATE "20070202"
37
38 #define DRIVER_MAJOR 2
39 #define DRIVER_MINOR 11
40 #define DRIVER_PATCHLEVEL 1
41
42 #include "via_verifier.h"
43
44 #include "via_dmablit.h"
45
46 #define VIA_PCI_BUF_SIZE 60000
47 #define VIA_FIRE_BUF_SIZE 1024
48 #define VIA_NUM_IRQS 4
49
50 typedef struct drm_via_ring_buffer {
51 drm_local_map_t map;
52 char *virtual_start;
53 } drm_via_ring_buffer_t;
54
55 typedef uint32_t maskarray_t[5];
56
57 typedef struct drm_via_irq {
58 #ifdef __NetBSD__
59 spinlock_t irq_lock;
60 unsigned irq_received;
61 #else
62 atomic_t irq_received;
63 #endif
64 uint32_t pending_mask;
65 uint32_t enable_mask;
66 #ifdef __NetBSD__
67 drm_waitqueue_t irq_queue;
68 #else
69 wait_queue_head_t irq_queue;
70 #endif
71 } drm_via_irq_t;
72
73 typedef struct drm_via_private {
74 drm_via_sarea_t *sarea_priv;
75 drm_local_map_t *sarea;
76 drm_local_map_t *fb;
77 drm_local_map_t *mmio;
78 unsigned long agpAddr;
79 #ifdef __NetBSD__
80 spinlock_t decoder_lock[VIA_NR_XVMC_LOCKS];
81 drm_waitqueue_t decoder_queue[VIA_NR_XVMC_LOCKS];
82 #else
83 wait_queue_head_t decoder_queue[VIA_NR_XVMC_LOCKS];
84 #endif
85 char *dma_ptr;
86 unsigned int dma_low;
87 unsigned int dma_high;
88 unsigned int dma_offset;
89 uint32_t dma_wrap;
90 volatile uint32_t *last_pause_ptr;
91 volatile uint32_t *hw_addr_ptr;
92 drm_via_ring_buffer_t ring;
93 struct timeval last_vblank;
94 int last_vblank_valid;
95 unsigned usec_per_vblank;
96 atomic_t vbl_received;
97 drm_via_state_t hc_state;
98 char pci_buf[VIA_PCI_BUF_SIZE];
99 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
100 uint32_t num_fire_offsets;
101 int chipset;
102 drm_via_irq_t via_irqs[VIA_NUM_IRQS];
103 unsigned num_irqs;
104 maskarray_t *irq_masks;
105 uint32_t irq_enable_mask;
106 uint32_t irq_pending_mask;
107 int *irq_map;
108 unsigned int idle_fault;
109 int vram_initialized;
110 struct drm_mm vram_mm;
111 int agp_initialized;
112 struct drm_mm agp_mm;
113 /** Mapping of userspace keys to mm objects */
114 struct idr object_idr;
115 unsigned long vram_offset;
116 unsigned long agp_offset;
117 drm_via_blitq_t blit_queues[VIA_NUM_BLIT_ENGINES];
118 uint32_t dma_diff;
119 } drm_via_private_t;
120
121 struct via_file_private {
122 struct list_head obj_list;
123 };
124
125 enum via_family {
126 VIA_OTHER = 0, /* Baseline */
127 VIA_PRO_GROUP_A, /* Another video engine and DMA commands */
128 VIA_DX9_0 /* Same video as pro_group_a, but 3D is unsupported */
129 };
130
131 /* VIA MMIO register access */
132 #define VIA_BASE ((dev_priv->mmio))
133
134 #define VIA_READ(reg) DRM_READ32(VIA_BASE, reg)
135 #define VIA_WRITE(reg, val) DRM_WRITE32(VIA_BASE, reg, val)
136 #define VIA_READ8(reg) DRM_READ8(VIA_BASE, reg)
137 #define VIA_WRITE8(reg, val) DRM_WRITE8(VIA_BASE, reg, val)
138
139 extern const struct drm_ioctl_desc via_ioctls[];
140 extern int via_max_ioctl;
141
142 extern int via_fb_init(struct drm_device *dev, void *data, struct drm_file *file_priv);
143 extern int via_mem_alloc(struct drm_device *dev, void *data, struct drm_file *file_priv);
144 extern int via_mem_free(struct drm_device *dev, void *data, struct drm_file *file_priv);
145 extern int via_agp_init(struct drm_device *dev, void *data, struct drm_file *file_priv);
146 extern int via_map_init(struct drm_device *dev, void *data, struct drm_file *file_priv);
147 extern int via_decoder_futex(struct drm_device *dev, void *data, struct drm_file *file_priv);
148 extern int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv);
149 extern int via_dma_blit_sync(struct drm_device *dev, void *data, struct drm_file *file_priv);
150 extern int via_dma_blit(struct drm_device *dev, void *data, struct drm_file *file_priv);
151
152 extern int via_driver_load(struct drm_device *dev, unsigned long chipset);
153 extern int via_driver_unload(struct drm_device *dev);
154
155 extern int via_init_context(struct drm_device *dev, int context);
156 extern int via_final_context(struct drm_device *dev, int context);
157
158 extern int via_do_cleanup_map(struct drm_device *dev);
159 extern u32 via_get_vblank_counter(struct drm_device *dev, unsigned int pipe);
160 extern int via_enable_vblank(struct drm_device *dev, unsigned int pipe);
161 extern void via_disable_vblank(struct drm_device *dev, unsigned int pipe);
162
163 extern irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS);
164 extern void via_driver_irq_preinstall(struct drm_device *dev);
165 extern int via_driver_irq_postinstall(struct drm_device *dev);
166 extern void via_driver_irq_uninstall(struct drm_device *dev);
167
168 extern int via_dma_cleanup(struct drm_device *dev);
169 extern void via_init_command_verifier(void);
170 extern int via_driver_dma_quiescent(struct drm_device *dev);
171 extern void via_init_futex(drm_via_private_t *dev_priv);
172 extern void via_cleanup_futex(drm_via_private_t *dev_priv);
173 extern void via_release_futex(drm_via_private_t *dev_priv, int context);
174
175 extern void via_reclaim_buffers_locked(struct drm_device *dev,
176 struct drm_file *file_priv);
177 extern void via_lastclose(struct drm_device *dev);
178
179 extern void via_dmablit_handler(struct drm_device *dev, int engine, int from_irq);
180 extern void via_init_dmablit(struct drm_device *dev);
181
182 #endif
183