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