1 /**********************************************************************
3 * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful but, except
10 * as otherwise stated in writing, without any warranty; without even the
11 * implied warranty of merchantability or fitness for a particular purpose.
12 * See the GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
21 * Contact Information:
22 * Imagination Technologies Ltd. <gpl-support@imgtec.com>
23 * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK
25 ******************************************************************************/
27 #include <linux/kernel.h>
28 #include <linux/module.h>
30 #include <linux/uaccess.h>
33 #include <linux/dma-mapping.h>
35 #include "kernelbuffer.h"
36 #include "bufferclass_example.h"
37 #include "bufferclass_example_linux.h"
38 #include "bufferclass_example_private.h"
39 #include "pvrmodule.h"
41 #define DEVNAME "bc_example"
42 #define DRVNAME DEVNAME
44 MODULE_SUPPORTED_DEVICE(DEVNAME);
46 static int AssignedMajorNumber;
48 #define unref__ __attribute__ ((unused))
52 void *BCAllocKernelMem(u32 ui32Size)
54 return kmalloc(ui32Size, GFP_KERNEL);
57 void BCFreeKernelMem(void *pvMem)
62 enum PVRSRV_ERROR BCAllocContigMemory(u32 ui32Size, void *unref__ * phMemHandle,
63 void __iomem **pLinAddr,
64 struct IMG_CPU_PHYADDR *pPhysAddr)
69 pvLinAddr = dma_alloc_coherent(NULL, ui32Size, &dma, GFP_KERNEL);
71 if (pvLinAddr == NULL)
72 return PVRSRV_ERROR_OUT_OF_MEMORY;
74 pPhysAddr->uiAddr = dma;
75 *pLinAddr = (void __force __iomem *)pvLinAddr;
80 void BCFreeContigMemory(u32 ui32Size, void *unref__ hMemHandle,
81 void __iomem *LinAddr, struct IMG_CPU_PHYADDR PhysAddr)
83 dma_free_coherent(NULL, ui32Size, (void __force *)LinAddr,
84 (dma_addr_t)PhysAddr.uiAddr);
87 struct IMG_SYS_PHYADDR CpuPAddrToSysPAddrBC(struct IMG_CPU_PHYADDR cpu_paddr)
89 struct IMG_SYS_PHYADDR sys_paddr;
91 sys_paddr.uiAddr = cpu_paddr.uiAddr;
95 struct IMG_CPU_PHYADDR SysPAddrToCpuPAddrBC(struct IMG_SYS_PHYADDR sys_paddr)
98 struct IMG_CPU_PHYADDR cpu_paddr;
100 cpu_paddr.uiAddr = sys_paddr.uiAddr;
104 enum PVRSRV_ERROR BCOpenPVRServices(void **phPVRServices)
107 *phPVRServices = NULL;
111 enum PVRSRV_ERROR BCClosePVRServices(void *unref__ hPVRServices)
117 enum PVRSRV_ERROR BCGetLibFuncAddr(void *unref__ hExtDrv, char *szFunctionName,
118 IMG_BOOL (**ppfnFuncTable)(struct PVRSRV_BC_BUFFER2SRV_KMJTABLE *))
120 if (strcmp("PVRGetBufferClassJTable", szFunctionName) != 0)
121 return PVRSRV_ERROR_INVALID_PARAMS;
123 *ppfnFuncTable = PVRGetBufferClassJTable;
128 static int BC_Example_Bridge(struct inode *inode, struct file *file,
129 unsigned int cmd, unsigned long arg)
132 int command = _IOC_NR(cmd);
133 struct BC_Example_ioctl_package __user *psBridge =
134 (struct BC_Example_ioctl_package __user *)arg;
137 (VERIFY_WRITE, psBridge, sizeof(struct BC_Example_ioctl_package)))
141 case _IOC_NR(BC_Example_ioctl_fill_buffer):
142 if (FillBuffer(psBridge->inputparam) == -1)
145 case _IOC_NR(BC_Example_ioctl_get_buffer_count):
146 if (GetBufferCount(&psBridge->outputparam) == -1)
156 static const struct file_operations bufferclass_example_fops = {
157 .ioctl = BC_Example_Bridge,
160 static int __init BC_Example_ModInit(void)
162 AssignedMajorNumber =
163 register_chrdev(0, DEVNAME, &bufferclass_example_fops);
165 if (AssignedMajorNumber <= 0) {
166 printk(KERN_ERR DRVNAME
167 ": BC_Example_ModInit: unable to get major number\n");
171 #if defined(CONFIG_PVR_DEBUG_EXTRA)
172 printk(KERN_ERR DRVNAME ": BC_Example_ModInit: major device %d\n",
173 AssignedMajorNumber);
177 if (BC_Example_Init() != PVRSRV_OK) {
178 printk(KERN_ERR DRVNAME
179 ": BC_Example_ModInit: can't init device\n");
186 unregister_chrdev(AssignedMajorNumber, DEVNAME);
191 static void __exit BC_Example_ModCleanup(void)
193 unregister_chrdev(AssignedMajorNumber, DEVNAME);
195 if (BC_Example_Deinit() != PVRSRV_OK)
196 printk(KERN_ERR DRVNAME
197 ": BC_Example_ModCleanup: can't deinit device\n");
201 module_init(BC_Example_ModInit);
202 module_exit(BC_Example_ModCleanup);