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 "pvr_bridge_km.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,
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 = pvLinAddr;
80 void BCFreeContigMemory(u32 ui32Size, void *unref__ hMemHandle,
81 void *LinAddr, struct IMG_CPU_PHYADDR PhysAddr)
83 dma_free_coherent(NULL, ui32Size, 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)
106 *phPVRServices = NULL;
110 enum PVRSRV_ERROR BCClosePVRServices(void *unref__ hPVRServices)
116 enum PVRSRV_ERROR BCGetLibFuncAddr(void *unref__ hExtDrv, char *szFunctionName,
117 IMG_BOOL (**ppfnFuncTable)(struct PVRSRV_BC_BUFFER2SRV_KMJTABLE *))
119 if (strcmp("PVRGetBufferClassJTable", szFunctionName) != 0)
120 return PVRSRV_ERROR_INVALID_PARAMS;
122 *ppfnFuncTable = PVRGetBufferClassJTable;
127 int BC_Example_Bridge(struct inode *inode, struct file *file, unsigned int cmd,
131 int command = _IOC_NR(cmd);
132 struct BC_Example_ioctl_package *psBridge =
133 (struct BC_Example_ioctl_package *)arg;
136 (VERIFY_WRITE, psBridge, sizeof(struct BC_Example_ioctl_package)))
140 case _IOC_NR(BC_Example_ioctl_fill_buffer):
142 if (FillBuffer(psBridge->inputparam) == -1)
146 case _IOC_NR(BC_Example_ioctl_get_buffer_count):
148 if (GetBufferCount(&psBridge->outputparam) == -1)
160 const static struct file_operations bufferclass_example_fops = {
161 .ioctl = BC_Example_Bridge,
164 static int __init BC_Example_ModInit(void)
168 AssignedMajorNumber =
169 register_chrdev(0, DEVNAME, &bufferclass_example_fops);
171 if (AssignedMajorNumber <= 0) {
172 printk(KERN_ERR DRVNAME
173 ": BC_Example_ModInit: unable to get major number\n");
178 printk(KERN_ERR DRVNAME ": BC_Example_ModInit: major device %d\n",
179 AssignedMajorNumber);
183 if (BC_Example_Init() != PVRSRV_OK) {
184 printk(KERN_ERR DRVNAME
185 ": BC_Example_ModInit: can't init device\n");
192 unregister_chrdev(AssignedMajorNumber, DEVNAME);
197 static void __exit BC_Example_ModCleanup(void)
199 unregister_chrdev(AssignedMajorNumber, DEVNAME);
201 if (BC_Example_Deinit() != PVRSRV_OK)
202 printk(KERN_ERR DRVNAME
203 ": BC_Example_ModCleanup: can't deinit device\n");
207 module_init(BC_Example_ModInit);
208 module_exit(BC_Example_ModCleanup);