18c2ecf20Sopenharmony_ci/* via_dmablit.h -- PCI DMA BitBlt support for the VIA Unichrome/Pro
28c2ecf20Sopenharmony_ci *
38c2ecf20Sopenharmony_ci * Copyright 2005 Thomas Hellstrom.
48c2ecf20Sopenharmony_ci * All Rights Reserved.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
78c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
88c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation
98c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sub license,
108c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
118c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
128c2ecf20Sopenharmony_ci *
138c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice (including the
148c2ecf20Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions
158c2ecf20Sopenharmony_ci * of the Software.
168c2ecf20Sopenharmony_ci *
178c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
188c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
198c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
208c2ecf20Sopenharmony_ci * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
218c2ecf20Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
228c2ecf20Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
238c2ecf20Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE.
248c2ecf20Sopenharmony_ci *
258c2ecf20Sopenharmony_ci * Authors:
268c2ecf20Sopenharmony_ci *    Thomas Hellstrom.
278c2ecf20Sopenharmony_ci *    Register info from Digeo Inc.
288c2ecf20Sopenharmony_ci */
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci#ifndef _VIA_DMABLIT_H
318c2ecf20Sopenharmony_ci#define _VIA_DMABLIT_H
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci#include <linux/dma-mapping.h>
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#define VIA_NUM_BLIT_ENGINES 2
368c2ecf20Sopenharmony_ci#define VIA_NUM_BLIT_SLOTS 8
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_cistruct _drm_via_descriptor;
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_citypedef struct _drm_via_sg_info {
418c2ecf20Sopenharmony_ci	struct page **pages;
428c2ecf20Sopenharmony_ci	unsigned long num_pages;
438c2ecf20Sopenharmony_ci	struct _drm_via_descriptor **desc_pages;
448c2ecf20Sopenharmony_ci	int num_desc_pages;
458c2ecf20Sopenharmony_ci	int num_desc;
468c2ecf20Sopenharmony_ci	enum dma_data_direction direction;
478c2ecf20Sopenharmony_ci	unsigned char *bounce_buffer;
488c2ecf20Sopenharmony_ci	dma_addr_t chain_start;
498c2ecf20Sopenharmony_ci	uint32_t free_on_sequence;
508c2ecf20Sopenharmony_ci	unsigned int descriptors_per_page;
518c2ecf20Sopenharmony_ci	int aborted;
528c2ecf20Sopenharmony_ci	enum {
538c2ecf20Sopenharmony_ci		dr_via_device_mapped,
548c2ecf20Sopenharmony_ci		dr_via_desc_pages_alloc,
558c2ecf20Sopenharmony_ci		dr_via_pages_locked,
568c2ecf20Sopenharmony_ci		dr_via_pages_alloc,
578c2ecf20Sopenharmony_ci		dr_via_sg_init
588c2ecf20Sopenharmony_ci	} state;
598c2ecf20Sopenharmony_ci} drm_via_sg_info_t;
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_citypedef struct _drm_via_blitq {
628c2ecf20Sopenharmony_ci	struct drm_device *dev;
638c2ecf20Sopenharmony_ci	uint32_t cur_blit_handle;
648c2ecf20Sopenharmony_ci	uint32_t done_blit_handle;
658c2ecf20Sopenharmony_ci	unsigned serviced;
668c2ecf20Sopenharmony_ci	unsigned head;
678c2ecf20Sopenharmony_ci	unsigned cur;
688c2ecf20Sopenharmony_ci	unsigned num_free;
698c2ecf20Sopenharmony_ci	unsigned num_outstanding;
708c2ecf20Sopenharmony_ci	unsigned long end;
718c2ecf20Sopenharmony_ci	int aborting;
728c2ecf20Sopenharmony_ci	int is_active;
738c2ecf20Sopenharmony_ci	drm_via_sg_info_t *blits[VIA_NUM_BLIT_SLOTS];
748c2ecf20Sopenharmony_ci	spinlock_t blit_lock;
758c2ecf20Sopenharmony_ci	wait_queue_head_t blit_queue[VIA_NUM_BLIT_SLOTS];
768c2ecf20Sopenharmony_ci	wait_queue_head_t busy_queue;
778c2ecf20Sopenharmony_ci	struct work_struct wq;
788c2ecf20Sopenharmony_ci	struct timer_list poll_timer;
798c2ecf20Sopenharmony_ci} drm_via_blitq_t;
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci/*
838c2ecf20Sopenharmony_ci *  PCI DMA Registers
848c2ecf20Sopenharmony_ci *  Channels 2 & 3 don't seem to be implemented in hardware.
858c2ecf20Sopenharmony_ci */
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci#define VIA_PCI_DMA_MAR0            0xE40   /* Memory Address Register of Channel 0 */
888c2ecf20Sopenharmony_ci#define VIA_PCI_DMA_DAR0            0xE44   /* Device Address Register of Channel 0 */
898c2ecf20Sopenharmony_ci#define VIA_PCI_DMA_BCR0            0xE48   /* Byte Count Register of Channel 0 */
908c2ecf20Sopenharmony_ci#define VIA_PCI_DMA_DPR0            0xE4C   /* Descriptor Pointer Register of Channel 0 */
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci#define VIA_PCI_DMA_MAR1            0xE50   /* Memory Address Register of Channel 1 */
938c2ecf20Sopenharmony_ci#define VIA_PCI_DMA_DAR1            0xE54   /* Device Address Register of Channel 1 */
948c2ecf20Sopenharmony_ci#define VIA_PCI_DMA_BCR1            0xE58   /* Byte Count Register of Channel 1 */
958c2ecf20Sopenharmony_ci#define VIA_PCI_DMA_DPR1            0xE5C   /* Descriptor Pointer Register of Channel 1 */
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci#define VIA_PCI_DMA_MAR2            0xE60   /* Memory Address Register of Channel 2 */
988c2ecf20Sopenharmony_ci#define VIA_PCI_DMA_DAR2            0xE64   /* Device Address Register of Channel 2 */
998c2ecf20Sopenharmony_ci#define VIA_PCI_DMA_BCR2            0xE68   /* Byte Count Register of Channel 2 */
1008c2ecf20Sopenharmony_ci#define VIA_PCI_DMA_DPR2            0xE6C   /* Descriptor Pointer Register of Channel 2 */
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci#define VIA_PCI_DMA_MAR3            0xE70   /* Memory Address Register of Channel 3 */
1038c2ecf20Sopenharmony_ci#define VIA_PCI_DMA_DAR3            0xE74   /* Device Address Register of Channel 3 */
1048c2ecf20Sopenharmony_ci#define VIA_PCI_DMA_BCR3            0xE78   /* Byte Count Register of Channel 3 */
1058c2ecf20Sopenharmony_ci#define VIA_PCI_DMA_DPR3            0xE7C   /* Descriptor Pointer Register of Channel 3 */
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci#define VIA_PCI_DMA_MR0             0xE80   /* Mode Register of Channel 0 */
1088c2ecf20Sopenharmony_ci#define VIA_PCI_DMA_MR1             0xE84   /* Mode Register of Channel 1 */
1098c2ecf20Sopenharmony_ci#define VIA_PCI_DMA_MR2             0xE88   /* Mode Register of Channel 2 */
1108c2ecf20Sopenharmony_ci#define VIA_PCI_DMA_MR3             0xE8C   /* Mode Register of Channel 3 */
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci#define VIA_PCI_DMA_CSR0            0xE90   /* Command/Status Register of Channel 0 */
1138c2ecf20Sopenharmony_ci#define VIA_PCI_DMA_CSR1            0xE94   /* Command/Status Register of Channel 1 */
1148c2ecf20Sopenharmony_ci#define VIA_PCI_DMA_CSR2            0xE98   /* Command/Status Register of Channel 2 */
1158c2ecf20Sopenharmony_ci#define VIA_PCI_DMA_CSR3            0xE9C   /* Command/Status Register of Channel 3 */
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci#define VIA_PCI_DMA_PTR             0xEA0   /* Priority Type Register */
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ci/* Define for DMA engine */
1208c2ecf20Sopenharmony_ci/* DPR */
1218c2ecf20Sopenharmony_ci#define VIA_DMA_DPR_EC		(1<<1)	/* end of chain */
1228c2ecf20Sopenharmony_ci#define VIA_DMA_DPR_DDIE	(1<<2)	/* descriptor done interrupt enable */
1238c2ecf20Sopenharmony_ci#define VIA_DMA_DPR_DT		(1<<3)	/* direction of transfer (RO) */
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci/* MR */
1268c2ecf20Sopenharmony_ci#define VIA_DMA_MR_CM		(1<<0)	/* chaining mode */
1278c2ecf20Sopenharmony_ci#define VIA_DMA_MR_TDIE		(1<<1)	/* transfer done interrupt enable */
1288c2ecf20Sopenharmony_ci#define VIA_DMA_MR_HENDMACMD		(1<<7) /* ? */
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_ci/* CSR */
1318c2ecf20Sopenharmony_ci#define VIA_DMA_CSR_DE		(1<<0)	/* DMA enable */
1328c2ecf20Sopenharmony_ci#define VIA_DMA_CSR_TS		(1<<1)	/* transfer start */
1338c2ecf20Sopenharmony_ci#define VIA_DMA_CSR_TA		(1<<2)	/* transfer abort */
1348c2ecf20Sopenharmony_ci#define VIA_DMA_CSR_TD		(1<<3)	/* transfer done */
1358c2ecf20Sopenharmony_ci#define VIA_DMA_CSR_DD		(1<<4)	/* descriptor done */
1368c2ecf20Sopenharmony_ci#define VIA_DMA_DPR_EC          (1<<1)  /* end of chain */
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_ci#endif
141