blob: 893a65090c36e7f08eb834856b25a0f2c3442938 [file] [log] [blame]
Dave Airlie22f579c2005-06-28 22:48:56 +10001/*
2 * Copyright 1998-2003 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2003 S3 Graphics, Inc. All Rights Reserved.
4 *
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:
11 *
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
14 * of the Software.
15 *
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.
23 */
24#ifndef _VIA_DRV_H_
25#define _VIA_DRV_H_
26
David Howells760285e2012-10-02 18:01:07 +010027#include <drm/drm_mm.h>
Dave Airlie92514242005-11-12 21:52:46 +110028#define DRIVER_AUTHOR "Various"
Dave Airlie22f579c2005-06-28 22:48:56 +100029
30#define DRIVER_NAME "via"
31#define DRIVER_DESC "VIA Unichrome / Pro"
Thomas Hellstroma0a6dd02007-05-08 15:47:41 +100032#define DRIVER_DATE "20070202"
Dave Airlie22f579c2005-06-28 22:48:56 +100033
34#define DRIVER_MAJOR 2
Thomas Hellstrom9b8d9d02007-01-08 21:21:41 +110035#define DRIVER_MINOR 11
Thomas Hellstroma0a6dd02007-05-08 15:47:41 +100036#define DRIVER_PATCHLEVEL 1
Dave Airlie22f579c2005-06-28 22:48:56 +100037
38#include "via_verifier.h"
39
Dave Airlie92514242005-11-12 21:52:46 +110040#include "via_dmablit.h"
41
Dave Airlie22f579c2005-06-28 22:48:56 +100042#define VIA_PCI_BUF_SIZE 60000
43#define VIA_FIRE_BUF_SIZE 1024
Dave Airlie92514242005-11-12 21:52:46 +110044#define VIA_NUM_IRQS 4
Dave Airlie22f579c2005-06-28 22:48:56 +100045
Dave Airlie22f579c2005-06-28 22:48:56 +100046typedef struct drm_via_ring_buffer {
Dave Airlie92514242005-11-12 21:52:46 +110047 drm_local_map_t map;
Dave Airlie22f579c2005-06-28 22:48:56 +100048 char *virtual_start;
49} drm_via_ring_buffer_t;
50
51typedef uint32_t maskarray_t[5];
52
53typedef struct drm_via_irq {
54 atomic_t irq_received;
55 uint32_t pending_mask;
56 uint32_t enable_mask;
57 wait_queue_head_t irq_queue;
58} drm_via_irq_t;
Dave Airlieb5e89ed2005-09-25 14:28:13 +100059
Dave Airlie22f579c2005-06-28 22:48:56 +100060typedef struct drm_via_private {
61 drm_via_sarea_t *sarea_priv;
Dave Airlie92514242005-11-12 21:52:46 +110062 drm_local_map_t *sarea;
63 drm_local_map_t *fb;
64 drm_local_map_t *mmio;
Dave Airlie22f579c2005-06-28 22:48:56 +100065 unsigned long agpAddr;
66 wait_queue_head_t decoder_queue[VIA_NR_XVMC_LOCKS];
67 char *dma_ptr;
68 unsigned int dma_low;
69 unsigned int dma_high;
70 unsigned int dma_offset;
71 uint32_t dma_wrap;
72 volatile uint32_t *last_pause_ptr;
73 volatile uint32_t *hw_addr_ptr;
74 drm_via_ring_buffer_t ring;
Dave Airlieb5e89ed2005-09-25 14:28:13 +100075 struct timeval last_vblank;
76 int last_vblank_valid;
77 unsigned usec_per_vblank;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -070078 atomic_t vbl_received;
Dave Airlie22f579c2005-06-28 22:48:56 +100079 drm_via_state_t hc_state;
80 char pci_buf[VIA_PCI_BUF_SIZE];
81 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
82 uint32_t num_fire_offsets;
Thomas Hellstrom689692e2007-01-08 21:19:57 +110083 int chipset;
Dave Airlie22f579c2005-06-28 22:48:56 +100084 drm_via_irq_t via_irqs[VIA_NUM_IRQS];
85 unsigned num_irqs;
86 maskarray_t *irq_masks;
Dave Airlieb5e89ed2005-09-25 14:28:13 +100087 uint32_t irq_enable_mask;
88 uint32_t irq_pending_mask;
Dave Airlie92514242005-11-12 21:52:46 +110089 int *irq_map;
Thomas Hellstromce65a442006-08-07 22:03:22 +100090 unsigned int idle_fault;
Thomas Hellstromce65a442006-08-07 22:03:22 +100091 int vram_initialized;
Daniel Vetter977b4f62011-10-26 22:21:13 +020092 struct drm_mm vram_mm;
Thomas Hellstromce65a442006-08-07 22:03:22 +100093 int agp_initialized;
Daniel Vetter977b4f62011-10-26 22:21:13 +020094 struct drm_mm agp_mm;
Daniel Vetter77ee8f32011-10-25 17:55:31 +020095 /** Mapping of userspace keys to mm objects */
96 struct idr object_idr;
Thomas Hellstromce65a442006-08-07 22:03:22 +100097 unsigned long vram_offset;
98 unsigned long agp_offset;
Dave Airlie92514242005-11-12 21:52:46 +110099 drm_via_blitq_t blit_queues[VIA_NUM_BLIT_ENGINES];
Thomas Hellstroma0a6dd02007-05-08 15:47:41 +1000100 uint32_t dma_diff;
Dave Airlie22f579c2005-06-28 22:48:56 +1000101} drm_via_private_t;
102
Dave Airlie92514242005-11-12 21:52:46 +1100103enum via_family {
Thomas Hellstrom689692e2007-01-08 21:19:57 +1100104 VIA_OTHER = 0, /* Baseline */
105 VIA_PRO_GROUP_A, /* Another video engine and DMA commands */
106 VIA_DX9_0 /* Same video as pro_group_a, but 3D is unsupported */
Dave Airlie92514242005-11-12 21:52:46 +1100107};
108
Dave Airlie22f579c2005-06-28 22:48:56 +1000109/* VIA MMIO register access */
110#define VIA_BASE ((dev_priv->mmio))
111
112#define VIA_READ(reg) DRM_READ32(VIA_BASE, reg)
Nicolas Kaiser58c1e852010-07-11 15:32:42 +0200113#define VIA_WRITE(reg, val) DRM_WRITE32(VIA_BASE, reg, val)
Dave Airlie22f579c2005-06-28 22:48:56 +1000114#define VIA_READ8(reg) DRM_READ8(VIA_BASE, reg)
Nicolas Kaiser58c1e852010-07-11 15:32:42 +0200115#define VIA_WRITE8(reg, val) DRM_WRITE8(VIA_BASE, reg, val)
Dave Airlie22f579c2005-06-28 22:48:56 +1000116
Eric Anholtc153f452007-09-03 12:06:45 +1000117extern struct drm_ioctl_desc via_ioctls[];
Dave Airlie92514242005-11-12 21:52:46 +1100118extern int via_max_ioctl;
119
Eric Anholtc153f452007-09-03 12:06:45 +1000120extern int via_fb_init(struct drm_device *dev, void *data, struct drm_file *file_priv);
121extern int via_mem_alloc(struct drm_device *dev, void *data, struct drm_file *file_priv);
122extern int via_mem_free(struct drm_device *dev, void *data, struct drm_file *file_priv);
123extern int via_agp_init(struct drm_device *dev, void *data, struct drm_file *file_priv);
124extern int via_map_init(struct drm_device *dev, void *data, struct drm_file *file_priv);
125extern int via_decoder_futex(struct drm_device *dev, void *data, struct drm_file *file_priv);
126extern int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv);
Nicolas Kaiser58c1e852010-07-11 15:32:42 +0200127extern int via_dma_blit_sync(struct drm_device *dev, void *data, struct drm_file *file_priv);
128extern int via_dma_blit(struct drm_device *dev, void *data, struct drm_file *file_priv);
Dave Airlie92514242005-11-12 21:52:46 +1100129
Dave Airlie84b1fd12007-07-11 15:53:27 +1000130extern int via_driver_load(struct drm_device *dev, unsigned long chipset);
131extern int via_driver_unload(struct drm_device *dev);
Dave Airlie92514242005-11-12 21:52:46 +1100132
Nicolas Kaiser58c1e852010-07-11 15:32:42 +0200133extern int via_init_context(struct drm_device *dev, int context);
134extern int via_final_context(struct drm_device *dev, int context);
Dave Airlie22f579c2005-06-28 22:48:56 +1000135
Nicolas Kaiser58c1e852010-07-11 15:32:42 +0200136extern int via_do_cleanup_map(struct drm_device *dev);
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700137extern u32 via_get_vblank_counter(struct drm_device *dev, int crtc);
138extern int via_enable_vblank(struct drm_device *dev, int crtc);
139extern void via_disable_vblank(struct drm_device *dev, int crtc);
Dave Airlie22f579c2005-06-28 22:48:56 +1000140
141extern irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS);
Nicolas Kaiser58c1e852010-07-11 15:32:42 +0200142extern void via_driver_irq_preinstall(struct drm_device *dev);
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700143extern int via_driver_irq_postinstall(struct drm_device *dev);
Nicolas Kaiser58c1e852010-07-11 15:32:42 +0200144extern void via_driver_irq_uninstall(struct drm_device *dev);
Dave Airlie22f579c2005-06-28 22:48:56 +1000145
Nicolas Kaiser58c1e852010-07-11 15:32:42 +0200146extern int via_dma_cleanup(struct drm_device *dev);
Dave Airlie22f579c2005-06-28 22:48:56 +1000147extern void via_init_command_verifier(void);
Nicolas Kaiser58c1e852010-07-11 15:32:42 +0200148extern int via_driver_dma_quiescent(struct drm_device *dev);
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700149extern void via_init_futex(drm_via_private_t *dev_priv);
150extern void via_cleanup_futex(drm_via_private_t *dev_priv);
151extern void via_release_futex(drm_via_private_t *dev_priv, int context);
Dave Airlie22f579c2005-06-28 22:48:56 +1000152
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700153extern void via_reclaim_buffers_locked(struct drm_device *dev,
154 struct drm_file *file_priv);
Dave Airlie84b1fd12007-07-11 15:53:27 +1000155extern void via_lastclose(struct drm_device *dev);
Thomas Hellstromce65a442006-08-07 22:03:22 +1000156
Dave Airlie84b1fd12007-07-11 15:53:27 +1000157extern void via_dmablit_handler(struct drm_device *dev, int engine, int from_irq);
158extern void via_init_dmablit(struct drm_device *dev);
Dave Airlieb3a83632005-09-30 18:37:36 +1000159
Dave Airlie22f579c2005-06-28 22:48:56 +1000160#endif