From 1ec5b45797ba374e2d076c815d7a9896f04bf297 Mon Sep 17 00:00:00 2001 From: Grazvydas Ignotas Date: Fri, 4 Jul 2014 00:47:08 +0300 Subject: [PATCH] fixes for bc_cat --- Makefile | 2 +- pvr/bc_cat.c | 42 ++++++++++++++++++++++-------------------- pvr/deviceclass.c | 14 ++++++++++++-- pvr/sysinfo.h | 2 +- 4 files changed, 36 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index 92787d4..4783eff 100644 --- a/Makefile +++ b/Makefile @@ -3,4 +3,4 @@ MAKECMDGOALS = all endif $(MAKECMDGOALS): - make -C pvr $@ + $(MAKE) -C pvr $@ diff --git a/pvr/bc_cat.c b/pvr/bc_cat.c index 53de981..698c1b3 100644 --- a/pvr/bc_cat.c +++ b/pvr/bc_cat.c @@ -369,6 +369,7 @@ static PVRSRV_ERROR BC_DestroyBuffers(int id) } BCFreeKernelMem(psDevInfo->psSystemBuffer); + psDevInfo->psSystemBuffer = NULL; psDevInfo->ui32NumBuffers = 0; psDevInfo->sBufferInfo.pixelformat = PVRSRV_PIXEL_FORMAT_UNKNOWN; @@ -497,7 +498,7 @@ static PVRSRV_ERROR BC_Unregister(int id) static int __init bc_cat_init(void) { struct device *bc_dev; - int id; + int id = 0; /* texture buffer width should be multiple of 8 for OMAP3 ES3.x, * or 32 for ES2.x */ @@ -511,9 +512,8 @@ static int __init bc_cat_init(void) } bc_class = class_create(THIS_MODULE, DEVNAME); - if (IS_ERR(bc_class)) { - printk(KERN_ERR DRVNAME ": upable to create device class\n"); + printk(KERN_ERR DRVNAME ": unable to create device class\n"); goto ExitUnregister; } @@ -529,18 +529,23 @@ static int __init bc_cat_init(void) if (BC_Register(id) != PVRSRV_OK) { printk (KERN_ERR DRVNAME ": can't register BC service %d\n", id); if (id > 0) { - /* lets live with the drivers that we were able to create soi + /* let's live with the drivers that we were able to create so * far, even though it isn't as many as we'd like */ + device_destroy(bc_class, MKDEV(major, id)); break; } - goto ExitUnregister; + goto ExitDestroyClass; } } return 0; ExitDestroyClass: + for (; id >= 0; id--) { + BC_Unregister(id); + device_destroy(bc_class, MKDEV(major, id)); + } class_destroy(bc_class); ExitUnregister: unregister_chrdev(major, DEVNAME); @@ -554,12 +559,10 @@ static void __exit bc_cat_cleanup(void) for (id = 0; id < DEVICE_COUNT; id++) { if (BC_DestroyBuffers(id) != PVRSRV_OK) { - printk(KERN_ERR DRVNAME ": can't free texture buffers\n"); - return; + printk(KERN_ERR DRVNAME ": can't free texture buffers, dev %d\n", id); } if (BC_Unregister(id) != PVRSRV_OK) { - printk(KERN_ERR DRVNAME ": can't un-register BC service\n"); - return; + printk(KERN_ERR DRVNAME ": can't un-register BC service, dev %d\n", id); } device_destroy(bc_class, MKDEV(major, id)); } @@ -583,17 +586,16 @@ static PVRSRV_ERROR BCAllocContigMemory(IMG_UINT32 ui32Size, IMG_CPU_VIRTADDR *pLinAddr, IMG_CPU_PHYADDR *pPhysAddr) { - IMG_VOID *pvLinAddr; - gfp_t mask = GFP_KERNEL; - - pvLinAddr = alloc_pages_exact(ui32Size, mask); -/* printk("pvLinAddr=%p, ui32Size=%ld\n", pvLinAddr, ui32Size);*/ - - if (pvLinAddr == IMG_NULL) - return PVRSRV_ERROR_OUT_OF_MEMORY; + dma_addr_t dma; + void *pvLinAddr; - pPhysAddr->uiAddr = virt_to_phys(pvLinAddr); + pvLinAddr = dma_alloc_coherent(NULL, ui32Size, &dma, GFP_KERNEL); + if (pvLinAddr == NULL) + { + return PVRSRV_ERROR_OUT_OF_MEMORY; + } + pPhysAddr->uiAddr = dma; *pLinAddr = pvLinAddr; return PVRSRV_OK; @@ -604,7 +606,7 @@ static IMG_VOID BCFreeContigMemory(IMG_UINT32 ui32Size, IMG_CPU_VIRTADDR LinAddr, IMG_CPU_PHYADDR PhysAddr) { - free_pages_exact(LinAddr, ui32Size); + dma_free_coherent(NULL, ui32Size, LinAddr, (dma_addr_t)PhysAddr.uiAddr); } static IMG_SYS_PHYADDR CpuPAddrToSysPAddrBC(IMG_CPU_PHYADDR cpu_paddr) @@ -716,7 +718,7 @@ static long bc_ioctl(struct file *file, return -EFAULT; idx = params->input; - if (idx < 0 || idx > devinfo->ui32NumBuffers) { + if (idx < 0 || idx >= devinfo->ui32NumBuffers) { printk(KERN_ERR DRVNAME ": BCIOGET_BUFFERADDR - idx out of range\n"); return -EINVAL; diff --git a/pvr/deviceclass.c b/pvr/deviceclass.c index d7f3f21..2f50679 100644 --- a/pvr/deviceclass.c +++ b/pvr/deviceclass.c @@ -196,7 +196,12 @@ static enum PVRSRV_ERROR PVRSRVRegisterDCDeviceKM( psDeviceNode->sDevId.eDeviceClass = PVRSRV_DEVICE_CLASS_DISPLAY; psDeviceNode->psSysData = psSysData; - AllocateDeviceID(psSysData, &psDeviceNode->sDevId.ui32DeviceIndex); + if (AllocateDeviceID(psSysData, + &psDeviceNode->sDevId.ui32DeviceIndex) != PVRSRV_OK) { + PVR_DPF(PVR_DBG_ERROR, + "PVRSRVRegisterDCDeviceKM: Failed deviceId alloc"); + goto ErrorExit; + } psDCInfo->ui32DeviceID = psDeviceNode->sDevId.ui32DeviceIndex; if (pui32DeviceID) *pui32DeviceID = psDeviceNode->sDevId.ui32DeviceIndex; @@ -341,7 +346,12 @@ static enum PVRSRV_ERROR PVRSRVRegisterBCDeviceKM( psDeviceNode->sDevId.eDeviceClass = PVRSRV_DEVICE_CLASS_BUFFER; psDeviceNode->psSysData = psSysData; - AllocateDeviceID(psSysData, &psDeviceNode->sDevId.ui32DeviceIndex); + if (AllocateDeviceID(psSysData, + &psDeviceNode->sDevId.ui32DeviceIndex) != PVRSRV_OK) { + PVR_DPF(PVR_DBG_ERROR, + "PVRSRVRegisterBCDeviceKM: Failed deviceId alloc"); + goto ErrorExit; + } psBCInfo->ui32DeviceID = psDeviceNode->sDevId.ui32DeviceIndex; if (pui32DeviceID) *pui32DeviceID = psDeviceNode->sDevId.ui32DeviceIndex; diff --git a/pvr/sysinfo.h b/pvr/sysinfo.h index 2af219d..643959c 100644 --- a/pvr/sysinfo.h +++ b/pvr/sysinfo.h @@ -35,7 +35,7 @@ enum SYS_DEVICE_TYPE { SYS_DEVICE_FORCE_I16 = 0x7fff }; -#define SYS_DEVICE_COUNT 3 +#define SYS_DEVICE_COUNT 15 #define PRM_REG32(offset) (offset) #define CM_REG32(offset) (offset) -- 2.39.2