Skip to contentSkip to conversation

pxa: add 2d graphics driver

PATCH New Haojian Zhuang 1 participant 1 message Oct 18, 2009

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pxa: add 2d graphics driver

PXA3xx series provides 2D graphics function. It supports line draw, chroma key, scale, alpha blending, and so on.

---
 arch/arm/mach-pxa/include/mach/pxa3xx-gcu.h |   69 ++
 drivers/char/Kconfig                        |    6 +
 drivers/char/Makefile                       |    1 +
 drivers/char/pxa3xx-gcu.c                   | 1118 +++++++++++++++++++++++++++
 4 files changed, 1194 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/mach-pxa/include/mach/pxa3xx-gcu.h
 create mode 100644 drivers/char/pxa3xx-gcu.c
(quoted diff) +0 -0

b/arch/arm/mach-pxa/include/mach/pxa3xx-gcu.h
new file mode 100644
index 0000000..14e6b0a

arch/arm/mach-pxa/include/mach/pxa3xx-gcu.h new file +31 -0
@@ -0,0 +1,69 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifndef _PXA3xx_GCU_H
+#define _PXA3xx_GCU_H
+
+#define MAX_DEVICE_GMEM_SIZE		(16*1024*1024)
+#define MAX_CONTEXT_GMEM_SIZE		(16*1024*1024)
+
+#define GCU_RINGBUF_SIZE		(16384)
+#define GCU_SCRATCHREG_NR		(8)
+
+#include <asm/ioctl.h>
+
+#define PXA3xx_GCU_IO_SUBMIT		_IOW('2',  1, struct iovec *)
+#define PXA3xx_GCU_IO_SYNC		_IOW('2',  2, int)
+
+#define PXA3xx_GCU_IO_REQUEST_MEM	_IOW('2', 10, struct

pxa3xx_gcu_mem_request *)
+#define PXA3xx_GCU_IO_RELEASE_MEM _IOW('2', 11, unsigned long)
+#define PXA3xx_GCU_IO_FLUSH_MEM _IOW('2', 12, unsigned long)
+
+#define PXA3xx_GCU_IO_GET_BUS_ADDR _IOW('2', 20, unsigned long)
+
+/* #define PXA3xx_GCU_IO_QUERY_GCU _IOR('2', 20, struct m2d_gcu_stat *) */
+
+#define PXA3xx_GCU_GRAPHICS_MEM 0
+#define PXA3xx_GCU_FRAME_BUFFER 1
+#define PXA3xx_GCU_REGISTERS 2
+#define PXA3xx_GCU_RING_BUFFER 3
+
+#define PXA3xx_GCU_ATTR_COHERENT 0x00
+#define PXA3xx_GCU_ATTR_WRITECOMBINE 0x10
+#define PXA3xx_GCU_ATTR_CACHEABLE 0x20
+
+#define PXA3xx_GCU_MEM_REQ_TYPE(f) (f & 0x0f)
+#define PXA3xx_GCU_MEM_REQ_ATTR(f) (f & 0xf0)
+
+struct pxa3xx_gcu_mem_req {
+ unsigned int req_type;
+ unsigned int req_size;
+ unsigned long phys_addr;
+ unsigned long mmap_addr;
+ unsigned long mmap_size;
+};
+
+#define PXA3xx_GCU_SUBMIT_MODE_NDELAY (1 << 0)
+#define PXA3xx_GCU_SUBMIT_MODE_SYNC (1 << 1)
+
+struct pxa3xx_gcu_submit_req {
+ unsigned int mode;
+ void *base;
+ size_t len;
+};
+
+#endif
+

drivers/char/Kconfig +6 -0
index 08a6f50..a7c468c 100644
@@ -431,6 +431,12 @@ config SGI_MBCS
          If you have an SGI Altix with an attached SABrick
          say Y or M here, otherwise say N.
 
+config PXA3xx_GCU
+	bool "PXA3xx Processor 2D Graphics Controller Driver"
+	depends on PXA3xx
+	help
+	  Enable graphics support on PXA3xx Processor series.
+
 source "drivers/serial/Kconfig"
 
 config UNIX98_PTYS
drivers/char/Makefile +1 -0
index 19a79dd..b0beced 100644
@@ -108,6 +108,7 @@ obj-$(CONFIG_HANGCHECK_TIMER)	+= hangcheck-timer.o
 obj-$(CONFIG_TCG_TPM)		+= tpm/
 
 obj-$(CONFIG_PS3_FLASH)		+= ps3flash.o
+obj-$(CONFIG_PXA3xx_GCU)	+= pxa3xx-gcu.o
 
 obj-$(CONFIG_JS_RTC)		+= js-rtc.o
 js-rtc-y = rtc.o
drivers/char/pxa3xx-gcu.c new file +709 -0

709 lines not on this page · raw message

pxa3xx_gcu_info *info)
+{
+ struct pxa3xx_gcu_context *context;
+
+ if (info == NULL)
+ return NULL;
+
+ context = kzalloc(sizeof(struct pxa3xx_gcu_context), GFP_KERNEL);
+ if (context == NULL)
+ return NULL;
+
+ context->info = info;
+ context->task = current;
+ context->alpha_set = 0;
+ context->trans_set = 0;
+ context->buffer_mode = 0x08;
+
+ INIT_LIST_HEAD(&context->mlist);
+
+ mutex_lock(&info->lock);
+ list_add_tail(&context->list, &info->list);
+ info->count++;
+ mutex_unlock(&info->lock);
+
+ return context;
+}
+
+static void __free_context(struct pxa3xx_gcu_context *context)
+{
+ struct pxa3xx_gcu_info *info;
+
+ if (context == NULL || context->info == NULL)
+ return;
+
+ info = context->info;
+ __release_mem(context, 0);
+ mutex_lock(&info->lock);
+ list_del(&context->list);
+ info->count--;
+ if (info->last == context)
+ info->last = NULL;
+ mutex_unlock(&info->lock);
+ kfree(context);
+}
+
+#ifdef CONFIG_PM
+static int pxa3xx_gcu_suspend(struct platform_device *pdev, pm_message_t state) +{
+ struct pxa3xx_gcu_info *info = platform_get_drvdata(pdev);
+
+ pxa3xx_gcu_wait_for_eeob(info);
+ if (info->last) {
+ mutex_lock(&info->lock);
+ __save_context(info->last);
+ mutex_unlock(&info->lock);
+ }
+ return 0;
+}
+
+static int pxa3xx_gcu_resume(struct platform_device *pdev)
+{
+ struct pxa3xx_gcu_info *info = platform_get_drvdata(pdev);
+
+ pxa3xx_gcu_reset(info);
+ if (info->last) {
+ mutex_lock(&info->lock);
+ __restore_context(info->last);
+ mutex_unlock(&info->lock);
+ }
+ return 0;
+}
+#endif
+
+static int pxa3xx_gcu_open(struct inode *inode, struct file *file) +{
+ struct pxa3xx_gcu_context *context = file->private_data;
+
+ if (context == NULL) {
+ if (priv_info == NULL)
+ return -EFAULT;
+ context = __create_context(priv_info);
+ if (context == NULL)
+ return -ENOMEM;
+ file->private_data = context;
+ }
+ return 0;
+}
+
+static int pxa3xx_gcu_release(struct inode *inode, struct file *file) +{
+ struct pxa3xx_gcu_context *context = file->private_data;
+
+ pxa3xx_gcu_wait_for_eeob(context->info);
+ __free_context(context);
+ return 0;
+}
+
+static int pxa3xx_gcu_ioctl(struct inode *inode, struct file *file,
+ unsigned int cmd, unsigned long arg)
+{
+ struct pxa3xx_gcu_context *context = file->private_data;
+ struct pxa3xx_gcu_info *info = (struct pxa3xx_gcu_info *)context->info;
+ struct pxa3xx_gcu_gmem *gmem = NULL;
+ struct pxa3xx_gcu_submit_req submit_req;
+ struct pxa3xx_gcu_mem_req mem_req;
+ struct vm_area_struct *vma = NULL;
+ void __user *uarg = (void *)arg;
+ int ret = 0;
+
+ if (info == NULL)
+ return -ENODEV;
+
+ switch (cmd) {
+ case PXA3xx_GCU_IO_REQUEST_MEM:
+ if (copy_from_user(&mem_req, uarg,
+ sizeof(struct pxa3xx_gcu_mem_req))) {
+ ret = -EFAULT;
+ goto out;
+ }
+ ret = __request_mem(context, &mem_req);
+ if (ret < 0)
+ goto out;
+ if (copy_to_user(uarg, &mem_req,
+ sizeof(struct pxa3xx_gcu_mem_req))) {
+ __release_mem(context, mem_req.mmap_addr);
+ ret = -EFAULT;
+ goto out;
+ }
+ break;
+ case PXA3xx_GCU_IO_RELEASE_MEM:
+ __release_mem(context, arg);
+ break;
+ case PXA3xx_GCU_IO_FLUSH_MEM:
+ list_for_each_entry(gmem, &context->mlist, list) {
+ if (gmem->gmem_uaddr == arg) {
+ dmac_flush_range((void *)arg, (void *)arg
+ + gmem->gmem_size);
+ outer_flush_range(gmem->gmem_phys_addr,
+ gmem->gmem_phys_addr
+ + gmem->gmem_size);
+ }
+ }
+ break;
+ case PXA3xx_GCU_IO_SUBMIT:
+ if (copy_from_user(&submit_req, uarg,
+ sizeof(struct pxa3xx_gcu_submit_req))) {
+ ret = -EFAULT;
+ goto out;
+ }
+ ret = pxa3xx_gcu_submit(context, &submit_req);
+ break;
+ case PXA3xx_GCU_IO_SYNC:
+ ret = pxa3xx_gcu_sync(context);
+ break;
+ case PXA3xx_GCU_IO_GET_BUS_ADDR:
+ /* assume user provided virtual memory are physical continous */
+ memset(&mem_req, 0, sizeof(struct pxa3xx_gcu_mem_req));
+ if (copy_from_user(&mem_req.mmap_addr, uarg,
+ sizeof(unsigned long))) {
+ ret = -EFAULT;
+ goto out;
+ }
+ vma = find_vma(current->mm, mem_req.mmap_addr);
+ if (vma == NULL) {
+ ret = -EINVAL;
+ goto out;
+ }
+ mem_req.phys_addr = (vma->vm_pgoff << PAGE_SHIFT)
+ + (mem_req.mmap_addr % PAGE_SIZE);
+ if (copy_to_user(uarg, &mem_req.phys_addr,
+ sizeof(unsigned long))) {
+ ret = -EFAULT;
+ goto out;
+ }
+ break;
+ default:
+ break;
+ }
+ return 0;
+out:
+ dev_dbg(info->dev, "%s, return value: %d\n", __func__, ret);
+ return ret;
+}
+
+static int pxa3xx_gcu_mmap(struct file *file, struct vm_area_struct *vma) +{
+ struct pxa3xx_gcu_context *context = file->private_data;
+ struct pxa3xx_gcu_gmem *gmem = NULL, *n = NULL;
+ unsigned long pg_off;
+ pgprot_t pgprot;
+
+ if (context == NULL)
+ return -ENODEV;
+
+ /* mmap() specifies the physical address as offset parameter */
+ list_for_each_entry_safe(gmem, n, &context->mlist, list) {
+ pg_off = gmem->gmem_phys_addr >> PAGE_SHIFT;
+ if (pg_off == vma->vm_pgoff)
+ break;
+ }
+ if (gmem == NULL)
+ return -ENOMEM;
+
+ switch (PXA3xx_GCU_MEM_REQ_ATTR(gmem->gmem_type)) {
+ case PXA3xx_GCU_ATTR_COHERENT:
+ pgprot = pgprot_noncached(vma->vm_page_prot);
+ break;
+ case PXA3xx_GCU_ATTR_WRITECOMBINE:
+ pgprot = pgprot_writecombine(vma->vm_page_prot);
+ break;
+ case PXA3xx_GCU_ATTR_CACHEABLE:
+ default:
+ pgprot = vma->vm_page_prot;
+ break;
+ }
+ vma->vm_page_prot = pgprot | PAGE_SHARED;
+ vma->vm_flags |= (VM_IO | VM_RESERVED);
+ if (remap_pfn_range(vma, vma->vm_start,

+			    gmem->gmem_phys_addr >> PAGE_SHIFT,
+			    vma->vm_end - vma->vm_start,
+			    vma->vm_page_prot))

+ return -EAGAIN;
+ gmem->gmem_uaddr = vma->vm_start;
+ dump_gmem(context);
+ dma_cache_maint((void *)gmem->gmem_virt_addr,
+ vma->vm_end - vma->vm_start,
+ DMA_BIDIRECTIONAL);
+ return 0;
+}
+
+static int pxa3xx_gcu_fsync(struct file *file, struct dentry *dentry,
+ int datasync)
+{
+ struct pxa3xx_gcu_context *context = file->private_data;
+
+ return pxa3xx_gcu_sync(context);
+}
+
+static struct file_operations pxa3xx_gcu_fops = {
+ .owner = THIS_MODULE,
+ .open = pxa3xx_gcu_open,
+ .release = pxa3xx_gcu_release,
+ .ioctl = pxa3xx_gcu_ioctl,
+ .mmap = pxa3xx_gcu_mmap,
+ .fsync = pxa3xx_gcu_fsync,
+};
+
+static struct miscdevice pxa3xx_gcu_miscdev = {
+ .minor = MISC_DYNAMIC_MINOR,
+ .name = "m2d",
+ .fops = &pxa3xx_gcu_fops,
+};
+
+static int pxa3xx_gcu_probe(struct platform_device *pdev) +{
+ struct pxa3xx_gcu_info *info;
+ struct resource *res;
+ int ret, size;
+
+ ret = misc_register(&pxa3xx_gcu_miscdev);
+ if (ret < 0) {
+ dev_err(&pdev->dev, "unable to register device /dev/m2d\n");
+ return ret;
+ }
+
+ info = kzalloc(sizeof(struct pxa3xx_gcu_info), GFP_KERNEL);
+ if (info == NULL) {
+ dev_err(&pdev->dev, "failed to allocate memory\n");
+ ret = -ENOMEM;
+ goto err;
+ }
+ info->pdev = pdev;
+
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (res == NULL) {
+ dev_err(&pdev->dev, "no resource definied for MEM\n");
+ ret = -ENXIO;
+ goto err_res;
+ }
+
+ res = request_mem_region(res->start, GCU_MAX_REG, pdev->name);
+ if (res == NULL) {
+ dev_err(&pdev->dev, "failed to request memory resource\n");
+ ret = -EBUSY;
+ goto err_res;
+ }
+
+ info->mmio_base = ioremap(res->start, GCU_MAX_REG);
+ if (info->mmio_base == NULL) {
+ dev_err(&pdev->dev, "failed to ioremap register\n");
+ ret = -ENOMEM;
+ goto err_map;
+ }
+
+ info->irq = platform_get_irq(pdev, 0);
+ if (info->irq < 0) {
+ dev_err(&pdev->dev, "failed to get IRQ\n");
+ ret = -ENXIO;
+ goto err_irq;
+ }
+ ret = request_irq(info->irq, pxa3xx_gcu_irq, IRQF_DISABLED,
+ pdev->name, info);
+ if (ret) {
+ dev_err(&pdev->dev, "failed to request GCU IRQ\n");
+ ret = -EBUSY;
+ goto err_irq;
+ }
+
+ info->ring_addr = dma_alloc_coherent(info->dev,
+ GCU_RINGBUF_SIZE + 256,
+ (dma_addr_t *)&info->ring_addr_dma,
+ GFP_KERNEL);
+ if (info->ring_addr == NULL) {
+ dev_err(&pdev->dev, "failed to allocate ring buffer\n");
+ ret = -ENOMEM;
+ goto err_mem;
+ }
+ size = ALIGN(info->ring_addr_dma, 256) - info->ring_addr_dma;
+ if (size > 0) {
+ info->ring_addr_dma += size;
+ info->ring_addr += size;
+ }
+ info->ring_tail_dma = info->ring_addr_dma;
+ info->ring_size = ALIGN(info->ring_addr_dma + GCU_RINGBUF_SIZE, 256)
+ - info->ring_addr_dma;
+ info->dev = &pdev->dev;
+
+ pxa3xx_gcu_reset(info);
+
+ mutex_init(&info->lock);
+ init_MUTEX(&info->submit_sem);
+ init_completion(&info->done);
+ INIT_LIST_HEAD(&info->list);
+
+ priv_info = info;
+
+ platform_set_drvdata(pdev, info);
+
+ dev_info(&pdev->dev, "2D Graphics Driver for PXA3xx\n");
+
+ return 0;
+err_mem:
+ free_irq(info->irq, info);
+err_irq:
+ iounmap(info->mmio_base);
+err_map:
+ release_mem_region(res->start, GCU_MAX_REG);
+err_res:
+ kfree(info);
+err:
+ misc_deregister(&pxa3xx_gcu_miscdev);
+ return ret;
+}
+
+static int pxa3xx_gcu_remove(struct platform_device *pdev) +{
+ struct pxa3xx_gcu_info *info = platform_get_drvdata(pdev);
+ unsigned int gccr;
+
+ /* Stop the graphics controller */
+ gccr = __raw_readl(info->mmio_base + GCCR);
+ if ((gccr & GCCR_STOP) == 0) {
+ gccr &= GCCR_MASK;
+ gccr |= GCCR_STOP;
+ }
+ __raw_writel(gccr, info->mmio_base + GCCR);
+
+ __raw_writel(0, info->mmio_base + GCRBLR);
+ __raw_writel(0, info->mmio_base + GCRBBR);
+ __raw_writel(0, info->mmio_base + GCRBTR);
+ dma_free_coherent(info->dev, info->ring_size, info->ring_addr,
+ (dma_addr_t)info->ring_addr_dma);
+ free_irq(info->irq, info);
+
+ misc_deregister(&pxa3xx_gcu_miscdev);
+
+ priv_info = NULL;
+
+ return 0;
+}
+
+static struct platform_driver pxa3xx_gcu_driver = {
+ .driver = {
+ .name = "pxa3xx-gcu",
+ .owner = THIS_MODULE,
+ },
+ .probe = pxa3xx_gcu_probe,
+ .remove = pxa3xx_gcu_remove,
+#ifdef CONFIG_PM
+ .suspend = pxa3xx_gcu_suspend,
+ .resume = pxa3xx_gcu_resume,
+#endif
+};
+
+static int __devinit pxa3xx_gcu_init(void)
+{
+ platform_driver_register(&pxa3xx_gcu_driver);
+
+ return 0;
+}
+
+static void __exit pxa3xx_gcu_exit(void)
+{
+ platform_driver_unregister(&pxa3xx_gcu_driver);
+}
+
+module_init(pxa3xx_gcu_init); +module_exit(pxa3xx_gcu_exit);
+MODULE_LICENSE("GPL");
+

Signature · 1 line
1.5.6.5