Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
0003  * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
0004  *
0005  * Permission is hereby granted, free of charge, to any person obtaining a
0006  * copy of this software and associated documentation files (the "Software"),
0007  * to deal in the Software without restriction, including without limitation
0008  * the rights to use, copy, modify, merge, publish, distribute, sub license,
0009  * and/or sell copies of the Software, and to permit persons to whom the
0010  * Software is furnished to do so, subject to the following conditions:
0011  *
0012  * The above copyright notice and this permission notice (including the
0013  * next paragraph) shall be included in all copies or substantial portions
0014  * of the Software.
0015  *
0016  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0017  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0018  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
0019  * VIA, S3 GRAPHICS, AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
0020  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0021  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
0022  * DEALINGS IN THE SOFTWARE.
0023  */
0024 #ifndef _VIA_DRV_H_
0025 #define _VIA_DRV_H_
0026 
0027 #include <linux/irqreturn.h>
0028 #include <linux/jiffies.h>
0029 #include <linux/sched.h>
0030 #include <linux/sched/signal.h>
0031 #include <linux/wait.h>
0032 
0033 #include <drm/drm_ioctl.h>
0034 #include <drm/drm_legacy.h>
0035 #include <drm/drm_mm.h>
0036 #include <drm/via_drm.h>
0037 
0038 #define DRIVER_AUTHOR   "Various"
0039 
0040 #define DRIVER_NAME     "via"
0041 #define DRIVER_DESC     "VIA Unichrome / Pro"
0042 #define DRIVER_DATE     "20070202"
0043 
0044 #define DRIVER_MAJOR        2
0045 #define DRIVER_MINOR        11
0046 #define DRIVER_PATCHLEVEL   1
0047 
0048 #include "via_verifier.h"
0049 
0050 #include "via_dmablit.h"
0051 
0052 #define VIA_PCI_BUF_SIZE 60000
0053 #define VIA_FIRE_BUF_SIZE  1024
0054 #define VIA_NUM_IRQS 4
0055 
0056 typedef struct drm_via_ring_buffer {
0057     drm_local_map_t map;
0058     char *virtual_start;
0059 } drm_via_ring_buffer_t;
0060 
0061 typedef uint32_t maskarray_t[5];
0062 
0063 typedef struct drm_via_irq {
0064     atomic_t irq_received;
0065     uint32_t pending_mask;
0066     uint32_t enable_mask;
0067     wait_queue_head_t irq_queue;
0068 } drm_via_irq_t;
0069 
0070 typedef struct drm_via_private {
0071     drm_via_sarea_t *sarea_priv;
0072     drm_local_map_t *sarea;
0073     drm_local_map_t *fb;
0074     drm_local_map_t *mmio;
0075     unsigned long agpAddr;
0076     wait_queue_head_t decoder_queue[VIA_NR_XVMC_LOCKS];
0077     char *dma_ptr;
0078     unsigned int dma_low;
0079     unsigned int dma_high;
0080     unsigned int dma_offset;
0081     uint32_t dma_wrap;
0082     volatile uint32_t *last_pause_ptr;
0083     volatile uint32_t *hw_addr_ptr;
0084     drm_via_ring_buffer_t ring;
0085     ktime_t last_vblank;
0086     int last_vblank_valid;
0087     ktime_t nsec_per_vblank;
0088     atomic_t vbl_received;
0089     drm_via_state_t hc_state;
0090     char pci_buf[VIA_PCI_BUF_SIZE];
0091     const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
0092     uint32_t num_fire_offsets;
0093     int chipset;
0094     drm_via_irq_t via_irqs[VIA_NUM_IRQS];
0095     unsigned num_irqs;
0096     maskarray_t *irq_masks;
0097     uint32_t irq_enable_mask;
0098     uint32_t irq_pending_mask;
0099     int *irq_map;
0100     unsigned int idle_fault;
0101     int vram_initialized;
0102     struct drm_mm vram_mm;
0103     int agp_initialized;
0104     struct drm_mm agp_mm;
0105     /** Mapping of userspace keys to mm objects */
0106     struct idr object_idr;
0107     unsigned long vram_offset;
0108     unsigned long agp_offset;
0109     drm_via_blitq_t blit_queues[VIA_NUM_BLIT_ENGINES];
0110     uint32_t dma_diff;
0111 } drm_via_private_t;
0112 
0113 struct via_file_private {
0114     struct list_head obj_list;
0115 };
0116 
0117 enum via_family {
0118   VIA_OTHER = 0,     /* Baseline */
0119   VIA_PRO_GROUP_A,   /* Another video engine and DMA commands */
0120   VIA_DX9_0          /* Same video as pro_group_a, but 3D is unsupported */
0121 };
0122 
0123 /* VIA MMIO register access */
0124 static inline u32 via_read(struct drm_via_private *dev_priv, u32 reg)
0125 {
0126     return readl((void __iomem *)(dev_priv->mmio->handle + reg));
0127 }
0128 
0129 static inline void via_write(struct drm_via_private *dev_priv, u32 reg,
0130                  u32 val)
0131 {
0132     writel(val, (void __iomem *)(dev_priv->mmio->handle + reg));
0133 }
0134 
0135 static inline void via_write8(struct drm_via_private *dev_priv, u32 reg,
0136                   u32 val)
0137 {
0138     writeb(val, (void __iomem *)(dev_priv->mmio->handle + reg));
0139 }
0140 
0141 static inline void via_write8_mask(struct drm_via_private *dev_priv,
0142                    u32 reg, u32 mask, u32 val)
0143 {
0144     u32 tmp;
0145 
0146     tmp = readb((void __iomem *)(dev_priv->mmio->handle + reg));
0147     tmp = (tmp & ~mask) | (val & mask);
0148     writeb(tmp, (void __iomem *)(dev_priv->mmio->handle + reg));
0149 }
0150 
0151 /*
0152  * Poll in a loop waiting for 'contidition' to be true.
0153  * Note: A direct replacement with wait_event_interruptible_timeout()
0154  *       will not work unless driver is updated to emit wake_up()
0155  *       in relevant places that can impact the 'condition'
0156  *
0157  * Returns:
0158  *   ret keeps current value if 'condition' becomes true
0159  *   ret = -BUSY if timeout happens
0160  *   ret = -EINTR if a signal interrupted the waiting period
0161  */
0162 #define VIA_WAIT_ON( ret, queue, timeout, condition )       \
0163 do {                                \
0164     DECLARE_WAITQUEUE(entry, current);          \
0165     unsigned long end = jiffies + (timeout);        \
0166     add_wait_queue(&(queue), &entry);           \
0167                                 \
0168     for (;;) {                      \
0169         __set_current_state(TASK_INTERRUPTIBLE);    \
0170         if (condition)                  \
0171             break;                  \
0172         if (time_after_eq(jiffies, end)) {      \
0173             ret = -EBUSY;               \
0174             break;                  \
0175         }                       \
0176         schedule_timeout((HZ/100 > 1) ? HZ/100 : 1);    \
0177         if (signal_pending(current)) {          \
0178             ret = -EINTR;               \
0179             break;                  \
0180         }                       \
0181     }                           \
0182     __set_current_state(TASK_RUNNING);          \
0183     remove_wait_queue(&(queue), &entry);            \
0184 } while (0)
0185 
0186 extern const struct drm_ioctl_desc via_ioctls[];
0187 extern int via_max_ioctl;
0188 
0189 extern int via_fb_init(struct drm_device *dev, void *data, struct drm_file *file_priv);
0190 extern int via_mem_alloc(struct drm_device *dev, void *data, struct drm_file *file_priv);
0191 extern int via_mem_free(struct drm_device *dev, void *data, struct drm_file *file_priv);
0192 extern int via_agp_init(struct drm_device *dev, void *data, struct drm_file *file_priv);
0193 extern int via_map_init(struct drm_device *dev, void *data, struct drm_file *file_priv);
0194 extern int via_decoder_futex(struct drm_device *dev, void *data, struct drm_file *file_priv);
0195 extern int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv);
0196 extern int via_dma_blit_sync(struct drm_device *dev, void *data, struct drm_file *file_priv);
0197 extern int via_dma_blit(struct drm_device *dev, void *data, struct drm_file *file_priv);
0198 
0199 extern int via_driver_load(struct drm_device *dev, unsigned long chipset);
0200 extern void via_driver_unload(struct drm_device *dev);
0201 
0202 extern int via_init_context(struct drm_device *dev, int context);
0203 extern int via_final_context(struct drm_device *dev, int context);
0204 
0205 extern int via_do_cleanup_map(struct drm_device *dev);
0206 extern u32 via_get_vblank_counter(struct drm_device *dev, unsigned int pipe);
0207 extern int via_enable_vblank(struct drm_device *dev, unsigned int pipe);
0208 extern void via_disable_vblank(struct drm_device *dev, unsigned int pipe);
0209 
0210 extern irqreturn_t via_driver_irq_handler(int irq, void *arg);
0211 extern void via_driver_irq_preinstall(struct drm_device *dev);
0212 extern int via_driver_irq_postinstall(struct drm_device *dev);
0213 extern void via_driver_irq_uninstall(struct drm_device *dev);
0214 
0215 extern int via_dma_cleanup(struct drm_device *dev);
0216 extern void via_init_command_verifier(void);
0217 extern int via_driver_dma_quiescent(struct drm_device *dev);
0218 extern void via_init_futex(drm_via_private_t *dev_priv);
0219 extern void via_cleanup_futex(drm_via_private_t *dev_priv);
0220 extern void via_release_futex(drm_via_private_t *dev_priv, int context);
0221 
0222 extern void via_reclaim_buffers_locked(struct drm_device *dev,
0223                        struct drm_file *file_priv);
0224 extern void via_lastclose(struct drm_device *dev);
0225 
0226 extern void via_dmablit_handler(struct drm_device *dev, int engine, int from_irq);
0227 extern void via_init_dmablit(struct drm_device *dev);
0228 
0229 #endif