+++ /dev/null
-/**********************************************************************
- *
- * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful but, except
- * as otherwise stated in writing, 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.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK
- *
- ******************************************************************************/
-
-#if !defined(__PVR_DRM_SHARED_H__)
-#define __PVR_DRM_SHARED_H__
-
-#if defined(SUPPORT_DRI_DRM)
-
-#define PVR_DRM_SRVKM_CMD 0x12
-#define PVR_DRM_DISP_CMD 0x13
-#define PVR_DRM_BC_CMD 0x14
-#define PVR_DRM_IS_MASTER_CMD 0x15
-#define PVR_DRM_UNPRIV_CMD 0x16
-#define PVR_DRM_DBGDRV_CMD 0x1E
-
-#define PVR_DRM_UNPRIV_INIT_SUCCESFUL 0
-#define PVR_DRM_UNPRIV_BUSID_TYPE 1
-#define PVR_DRM_UNPRIV_BUSID_FIELD 2
-
-#define PVR_DRM_BUS_TYPE_PCI 0
-
-#define PVR_DRM_PCI_DOMAIN 0
-#define PVR_DRM_PCI_BUS 1
-#define PVR_DRM_PCI_DEV 2
-#define PVR_DRM_PCI_FUNC 3
-
-#endif
-
-#endif
-
-
+++ /dev/null
-/**********************************************************************
- *
- * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful but, except
- * as otherwise stated in writing, 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.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK
- *
- ******************************************************************************/
-
-#ifndef _ENV_DATA_
-#define _ENV_DATA_
-
-#include <linux/interrupt.h>
-#include <linux/pci.h>
-
-#if defined(PVR_LINUX_MISR_USING_WORKQUEUE) || defined(PVR_LINUX_MISR_USING_PRIVATE_WORKQUEUE)
-#include <linux/workqueue.h>
-#endif
-
-#define PVRSRV_MAX_BRIDGE_IN_SIZE 0x1000
-#define PVRSRV_MAX_BRIDGE_OUT_SIZE 0x1000
-
-typedef struct _PVR_PCI_DEV_TAG
-{
- struct pci_dev *psPCIDev;
- HOST_PCI_INIT_FLAGS ePCIFlags;
- IMG_BOOL abPCIResourceInUse[DEVICE_COUNT_RESOURCE];
-} PVR_PCI_DEV;
-
-typedef struct _ENV_DATA_TAG
-{
- IMG_VOID *pvBridgeData;
- struct pm_dev *psPowerDevice;
- IMG_BOOL bLISRInstalled;
- IMG_BOOL bMISRInstalled;
- IMG_UINT32 ui32IRQ;
- IMG_VOID *pvISRCookie;
-#if defined(PVR_LINUX_MISR_USING_PRIVATE_WORKQUEUE)
- struct workqueue_struct *psWorkQueue;
-#endif
-#if defined(PVR_LINUX_MISR_USING_WORKQUEUE) || defined(PVR_LINUX_MISR_USING_PRIVATE_WORKQUEUE)
- struct work_struct sMISRWork;
- IMG_VOID *pvMISRData;
-#else
- struct tasklet_struct sMISRTasklet;
-#endif
-} ENV_DATA;
-
-#endif
+++ /dev/null
-/**********************************************************************
- *
- * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful but, except
- * as otherwise stated in writing, 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.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK
- *
- ******************************************************************************/
-
-#ifndef __ENV_PERPROC_H__
-#define __ENV_PERPROC_H__
-
-#include <linux/list.h>
-#include <linux/proc_fs.h>
-
-#include "services.h"
-#include "handle.h"
-
-typedef struct _PVRSRV_ENV_PER_PROCESS_DATA_
-{
- IMG_HANDLE hBlockAlloc;
- struct proc_dir_entry *psProcDir;
-#if defined(SUPPORT_DRI_DRM) && defined(PVR_SECURE_DRM_AUTH_EXPORT)
- struct list_head sDRMAuthListHead;
-#endif
-} PVRSRV_ENV_PER_PROCESS_DATA;
-
-IMG_VOID RemovePerProcessProcDir(PVRSRV_ENV_PER_PROCESS_DATA *psEnvPerProc);
-
-PVRSRV_ERROR LinuxMMapPerProcessConnect(PVRSRV_ENV_PER_PROCESS_DATA *psEnvPerProc);
-
-IMG_VOID LinuxMMapPerProcessDisconnect(PVRSRV_ENV_PER_PROCESS_DATA *psEnvPerProc);
-
-PVRSRV_ERROR LinuxMMapPerProcessHandleOptions(PVRSRV_HANDLE_BASE *psHandleBase);
-
-IMG_HANDLE LinuxTerminatingProcessPrivateData(IMG_VOID);
-
-#endif
-
+++ /dev/null
-/**********************************************************************
- *
- * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful but, except
- * as otherwise stated in writing, 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.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK
- *
- ******************************************************************************/
-
-#include <linux/version.h>
-#include <asm/io.h>
-#include <asm/page.h>
-#include <asm/system.h>
-#include <linux/mm.h>
-#include <linux/slab.h>
-#include <linux/vmalloc.h>
-#include <linux/delay.h>
-#include <linux/pci.h>
-
-#include <linux/string.h>
-#include <linux/sched.h>
-#include <linux/interrupt.h>
-#include <asm/hardirq.h>
-#include <linux/timer.h>
-#include <linux/capability.h>
-#include <linux/sched.h>
-#include <asm/uaccess.h>
-
-#include "img_types.h"
-#include "services_headers.h"
-#include "mm.h"
-#include "pvrmmap.h"
-#include "mmap.h"
-#include "env_data.h"
-#include "proc.h"
-#include "lock.h"
-
-typedef struct PVRSRV_LINUX_EVENT_OBJECT_LIST_TAG
-{
- rwlock_t sLock;
- struct list_head sList;
-
-} PVRSRV_LINUX_EVENT_OBJECT_LIST;
-
-
-typedef struct PVRSRV_LINUX_EVENT_OBJECT_TAG
-{
- atomic_t sTimeStamp;
- IMG_UINT32 ui32TimeStampPrevious;
-#if defined(PVR_DEBUG_EXT)
- IMG_UINT ui32Stats;
-#endif
- wait_queue_head_t sWait;
- struct list_head sList;
- IMG_HANDLE hResItem;
- PVRSRV_LINUX_EVENT_OBJECT_LIST *psLinuxEventObjectList;
-} PVRSRV_LINUX_EVENT_OBJECT;
-
-PVRSRV_ERROR LinuxEventObjectListCreate(IMG_HANDLE *phEventObjectList)
-{
- PVRSRV_LINUX_EVENT_OBJECT_LIST *psEvenObjectList;
-
- if(OSAllocMem(PVRSRV_OS_NON_PAGEABLE_HEAP, sizeof(PVRSRV_LINUX_EVENT_OBJECT_LIST),
- (IMG_VOID **)&psEvenObjectList, IMG_NULL,
- "Linux Event Object List") != PVRSRV_OK)
- {
- PVR_DPF((PVR_DBG_ERROR, "LinuxEventObjectCreate: failed to allocate memory for event list"));
- return PVRSRV_ERROR_OUT_OF_MEMORY;
- }
-
- INIT_LIST_HEAD(&psEvenObjectList->sList);
-
- rwlock_init(&psEvenObjectList->sLock);
-
- *phEventObjectList = (IMG_HANDLE *) psEvenObjectList;
-
- return PVRSRV_OK;
-}
-
-PVRSRV_ERROR LinuxEventObjectListDestroy(IMG_HANDLE hEventObjectList)
-{
-
- PVRSRV_LINUX_EVENT_OBJECT_LIST *psEvenObjectList = (PVRSRV_LINUX_EVENT_OBJECT_LIST *) hEventObjectList ;
-
- if(psEvenObjectList)
- {
- if (!list_empty(&psEvenObjectList->sList))
- {
- PVR_DPF((PVR_DBG_ERROR, "LinuxEventObjectListDestroy: Event List is not empty"));
- return PVRSRV_ERROR_GENERIC;
- }
- OSFreeMem(PVRSRV_OS_NON_PAGEABLE_HEAP, sizeof(PVRSRV_LINUX_EVENT_OBJECT_LIST), psEvenObjectList, IMG_NULL);
-
- }
- return PVRSRV_OK;
-}
-
-
-PVRSRV_ERROR LinuxEventObjectDelete(IMG_HANDLE hOSEventObjectList, IMG_HANDLE hOSEventObject)
-{
- if(hOSEventObjectList)
- {
- if(hOSEventObject)
- {
- PVRSRV_LINUX_EVENT_OBJECT *psLinuxEventObject = (PVRSRV_LINUX_EVENT_OBJECT *)hOSEventObject;
-#if defined(PVR_DEBUG_EXT)
- PVR_DPF((PVR_DBG_MESSAGE, "LinuxEventObjectListDelete: Event object waits: %lu", psLinuxEventObject->ui32Stats));
-#endif
- if(ResManFreeResByPtr(psLinuxEventObject->hResItem) != PVRSRV_OK)
- {
- return PVRSRV_ERROR_GENERIC;
- }
-
- return PVRSRV_OK;
- }
- }
- return PVRSRV_ERROR_GENERIC;
-
-}
-
-static PVRSRV_ERROR LinuxEventObjectDeleteCallback(IMG_PVOID pvParam, IMG_UINT32 ui32Param)
-{
- PVRSRV_LINUX_EVENT_OBJECT *psLinuxEventObject = pvParam;
- PVRSRV_LINUX_EVENT_OBJECT_LIST *psLinuxEventObjectList = psLinuxEventObject->psLinuxEventObjectList;
-
- PVR_UNREFERENCED_PARAMETER(ui32Param);
-
- write_lock_bh(&psLinuxEventObjectList->sLock);
- list_del(&psLinuxEventObject->sList);
- write_unlock_bh(&psLinuxEventObjectList->sLock);
-
-#if defined(PVR_DEBUG_EXT)
- PVR_DPF((PVR_DBG_MESSAGE, "LinuxEventObjectDeleteCallback: Event object waits: %lu", psLinuxEventObject->ui32Stats));
-#endif
-
- OSFreeMem(PVRSRV_OS_NON_PAGEABLE_HEAP, sizeof(PVRSRV_LINUX_EVENT_OBJECT), psLinuxEventObject, IMG_NULL);
-
-
- return PVRSRV_OK;
-}
-PVRSRV_ERROR LinuxEventObjectAdd(IMG_HANDLE hOSEventObjectList, IMG_HANDLE *phOSEventObject)
- {
- PVRSRV_LINUX_EVENT_OBJECT *psLinuxEventObject;
- PVRSRV_LINUX_EVENT_OBJECT_LIST *psLinuxEventObjectList = (PVRSRV_LINUX_EVENT_OBJECT_LIST*)hOSEventObjectList;
- IMG_UINT32 ui32PID = OSGetCurrentProcessIDKM();
- PVRSRV_PER_PROCESS_DATA *psPerProc;
-
- psPerProc = PVRSRVPerProcessData(ui32PID);
- if (psPerProc == IMG_NULL)
- {
- PVR_DPF((PVR_DBG_ERROR, "LinuxEventObjectAdd: Couldn't find per-process data"));
- return PVRSRV_ERROR_OUT_OF_MEMORY;
- }
-
-
- if(OSAllocMem(PVRSRV_OS_NON_PAGEABLE_HEAP, sizeof(PVRSRV_LINUX_EVENT_OBJECT),
- (IMG_VOID **)&psLinuxEventObject, IMG_NULL,
- "Linux Event Object") != PVRSRV_OK)
- {
- PVR_DPF((PVR_DBG_ERROR, "LinuxEventObjectAdd: failed to allocate memory "));
- return PVRSRV_ERROR_OUT_OF_MEMORY;
- }
-
- INIT_LIST_HEAD(&psLinuxEventObject->sList);
-
- atomic_set(&psLinuxEventObject->sTimeStamp, 0);
- psLinuxEventObject->ui32TimeStampPrevious = 0;
-
-#if defined(PVR_DEBUG_EXT)
- psLinuxEventObject->ui32Stats = 0;
-#endif
- init_waitqueue_head(&psLinuxEventObject->sWait);
-
- psLinuxEventObject->psLinuxEventObjectList = psLinuxEventObjectList;
-
- psLinuxEventObject->hResItem = ResManRegisterRes(psPerProc->hResManContext,
- RESMAN_TYPE_EVENT_OBJECT,
- psLinuxEventObject,
- 0,
- &LinuxEventObjectDeleteCallback);
-
- write_lock_bh(&psLinuxEventObjectList->sLock);
- list_add(&psLinuxEventObject->sList, &psLinuxEventObjectList->sList);
- write_unlock_bh(&psLinuxEventObjectList->sLock);
-
- *phOSEventObject = psLinuxEventObject;
-
- return PVRSRV_OK;
-}
-
-PVRSRV_ERROR LinuxEventObjectSignal(IMG_HANDLE hOSEventObjectList)
-{
- PVRSRV_LINUX_EVENT_OBJECT *psLinuxEventObject;
- PVRSRV_LINUX_EVENT_OBJECT_LIST *psLinuxEventObjectList = (PVRSRV_LINUX_EVENT_OBJECT_LIST*)hOSEventObjectList;
- struct list_head *psListEntry, *psListEntryTemp, *psList;
- psList = &psLinuxEventObjectList->sList;
-
- list_for_each_safe(psListEntry, psListEntryTemp, psList)
- {
-
- psLinuxEventObject = (PVRSRV_LINUX_EVENT_OBJECT *)list_entry(psListEntry, PVRSRV_LINUX_EVENT_OBJECT, sList);
-
- atomic_inc(&psLinuxEventObject->sTimeStamp);
- wake_up_interruptible(&psLinuxEventObject->sWait);
- }
-
- return PVRSRV_OK;
-
-}
-
-PVRSRV_ERROR LinuxEventObjectWait(IMG_HANDLE hOSEventObject, IMG_UINT32 ui32MSTimeout)
-{
- IMG_UINT32 ui32TimeStamp;
- DEFINE_WAIT(sWait);
-
- PVRSRV_LINUX_EVENT_OBJECT *psLinuxEventObject = (PVRSRV_LINUX_EVENT_OBJECT *) hOSEventObject;
-
- IMG_UINT32 ui32TimeOutJiffies = msecs_to_jiffies(ui32MSTimeout);
-
- do
- {
- prepare_to_wait(&psLinuxEventObject->sWait, &sWait, TASK_INTERRUPTIBLE);
- ui32TimeStamp = atomic_read(&psLinuxEventObject->sTimeStamp);
-
- if(psLinuxEventObject->ui32TimeStampPrevious != ui32TimeStamp)
- {
- break;
- }
-
- mutex_unlock(&gPVRSRVLock);
-
- ui32TimeOutJiffies = (IMG_UINT32)schedule_timeout((IMG_INT32)ui32TimeOutJiffies);
-
- mutex_lock(&gPVRSRVLock);
-#if defined(PVR_DEBUG_EXT)
- psLinuxEventObject->ui32Stats++;
-#endif
-
-
- } while (ui32TimeOutJiffies);
-
- finish_wait(&psLinuxEventObject->sWait, &sWait);
-
- psLinuxEventObject->ui32TimeStampPrevious = ui32TimeStamp;
-
- return ui32TimeOutJiffies ? PVRSRV_OK : PVRSRV_ERROR_TIMEOUT;
-
-}
-
+++ /dev/null
-/**********************************************************************
- *
- * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful but, except
- * as otherwise stated in writing, 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.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK
- *
- ******************************************************************************/
-
-PVRSRV_ERROR LinuxEventObjectListCreate(IMG_HANDLE *phEventObjectList);
-PVRSRV_ERROR LinuxEventObjectListDestroy(IMG_HANDLE hEventObjectList);
-PVRSRV_ERROR LinuxEventObjectAdd(IMG_HANDLE hOSEventObjectList, IMG_HANDLE *phOSEventObject);
-PVRSRV_ERROR LinuxEventObjectDelete(IMG_HANDLE hOSEventObjectList, IMG_HANDLE hOSEventObject);
-PVRSRV_ERROR LinuxEventObjectSignal(IMG_HANDLE hOSEventObjectList);
-PVRSRV_ERROR LinuxEventObjectWait(IMG_HANDLE hOSEventObject, IMG_UINT32 ui32MSTimeout);
+++ /dev/null
-/**********************************************************************
- *
- * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful but, except
- * as otherwise stated in writing, 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.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK
- *
- ******************************************************************************/
-
-#ifndef __LINKAGE_H__
-#define __LINKAGE_H__
-
-#if !defined(SUPPORT_DRI_DRM)
-IMG_INT32 PVRSRV_BridgeDispatchKM(struct file *file, IMG_UINT cmd, IMG_UINT32 arg);
-#endif
-
-IMG_VOID PVRDPFInit(IMG_VOID);
-PVRSRV_ERROR PVROSFuncInit(IMG_VOID);
-IMG_VOID PVROSFuncDeInit(IMG_VOID);
-
-#ifdef PVR_DEBUG_EXT
-IMG_INT PVRDebugProcSetLevel(struct file *file, const IMG_CHAR *buffer, IMG_UINT32 count, IMG_VOID *data);
-IMG_VOID PVRDebugSetLevel(IMG_UINT32 uDebugLevel);
-
-#ifdef PVR_PROC_USE_SEQ_FILE
-void ProcSeqShowDebugLevel(struct seq_file *sfile,void* el);
-#else
-IMG_INT PVRDebugProcGetLevel(IMG_CHAR *page, IMG_CHAR **start, off_t off, IMG_INT count, IMG_INT *eof, IMG_VOID *data);
-#endif
-
-#ifdef PVR_MANUAL_POWER_CONTROL
-IMG_INT PVRProcSetPowerLevel(struct file *file, const IMG_CHAR *buffer, IMG_UINT32 count, IMG_VOID *data);
-
-#ifdef PVR_PROC_USE_SEQ_FILE
-void ProcSeqShowPowerLevel(struct seq_file *sfile,void* el);
-#else
-IMG_INT PVRProcGetPowerLevel(IMG_CHAR *page, IMG_CHAR **start, off_t off, IMG_INT count, IMG_INT *eof, IMG_VOID *data);
-#endif
-
-
-#endif
-#endif
-
-#endif
+++ /dev/null
-/**********************************************************************
- *
- * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful but, except
- * as otherwise stated in writing, 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.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK
- *
- ******************************************************************************/
-
-#ifndef __LOCK_H__
-#define __LOCK_H__
-
-#include <linux/mutex.h>
-
-extern struct mutex gPVRSRVLock;
-
-#endif
+++ /dev/null
-/**********************************************************************
- *
- * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful but, except
- * as otherwise stated in writing, 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.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK
- *
- ******************************************************************************/
-
-#include <linux/mm.h>
-#include <linux/vmalloc.h>
-#include <asm/io.h>
-#include <linux/slab.h>
-#include <linux/highmem.h>
-#include <linux/sched.h>
-#include <linux/mutex.h>
-
-#include "img_defs.h"
-#include "services.h"
-#include "servicesint.h"
-#include "syscommon.h"
-#include "mutils.h"
-#include "mm.h"
-#include "pvrmmap.h"
-#include "mmap.h"
-#include "osfunc.h"
-#include "pvr_debug.h"
-#include "proc.h"
-#include "lock.h"
-
-
-static struct kmem_cache *linux_mem_area_cache;
-
-int linux_mm_init(void)
-{
- linux_mem_area_cache = kmem_cache_create("img-mm", sizeof(LinuxMemArea), 0, 0, NULL);
-
- if (!linux_mem_area_cache)
- {
- pr_err("%s: failed to allocate kmem_cache", __FUNCTION__);
- return -ENOMEM;
- }
- return 0;
-}
-
-void linux_mm_cleanup(void)
-{
- if (linux_mem_area_cache)
- {
- kmem_cache_destroy(linux_mem_area_cache);
- linux_mem_area_cache = NULL;
- }
-}
-
-void *vmalloc_wrapper(u32 bytes, u32 alloc_flags)
-{
- /*
- * FIXME: This function creates a memory alias
- * of a page, with a mismatching PAT type.
- * This wants to be fixed most likely.
- */
- pgprot_t pgprot_flags;
-
- switch(alloc_flags & PVRSRV_HAP_CACHETYPE_MASK)
- {
- case PVRSRV_HAP_CACHED:
- pgprot_flags = PAGE_KERNEL;
- break;
- case PVRSRV_HAP_WRITECOMBINE:
- pgprot_flags = PGPROT_WC(PAGE_KERNEL);
- break;
- case PVRSRV_HAP_UNCACHED:
- pgprot_flags = PGPROT_UC(PAGE_KERNEL);
- break;
- default:
- WARN(1, "unknown mapping flags=0x%08x", alloc_flags);
- return NULL;
- }
-
-
- return __vmalloc(bytes, GFP_KERNEL | __GFP_HIGHMEM, pgprot_flags);
-}
-
-LinuxMemArea *vmalloc_linux_mem_area(u32 bytes, u32 area_flags)
-{
- LinuxMemArea *mem_area;
- void *vptr;
-
- mem_area = kmem_cache_alloc(linux_mem_area_cache, GFP_KERNEL);
-
- if (!mem_area)
- goto failed;
-
- vptr = vmalloc_wrapper(bytes, area_flags);
- if (!vptr)
- goto failed;
-
- mem_area->eAreaType = LINUX_MEM_AREA_VMALLOC;
- mem_area->uData.sVmalloc.pvVmallocAddress = vptr;
- mem_area->ui32ByteSize = bytes;
- mem_area->ui32AreaFlags = area_flags;
- mem_area->bMMapRegistered = IMG_FALSE;
- INIT_LIST_HEAD(&mem_area->sMMapOffsetStructList);
-
- return mem_area;
-
-failed:
- pr_err("%s: failed!", __FUNCTION__);
- if (mem_area)
- kmem_cache_free(linux_mem_area_cache, mem_area);
- return NULL;
-}
-
-
-void __iomem *ioremap_wrapper(resource_size_t address,
- u32 bytes, u32 mapping_flags)
-{
- void __iomem *cookie;
-
- switch(mapping_flags & PVRSRV_HAP_CACHETYPE_MASK)
- {
- case PVRSRV_HAP_CACHED:
- cookie = ioremap_cache(address, bytes);
- break;
- case PVRSRV_HAP_WRITECOMBINE:
- cookie = ioremap_wc(address, bytes);
- break;
- case PVRSRV_HAP_UNCACHED:
- cookie = ioremap_nocache(address, bytes);
- break;
- default:
- pr_err("ioremap_wrapper: unknown mapping flags");
- return NULL;
- }
-
- return cookie;
-}
-
-LinuxMemArea *
-ioremap_linux_mem_area(resource_size_t address, u32 bytes, u32 area_flags)
-{
- LinuxMemArea *mem_area;
- void __iomem *cookie;
-
- mem_area = kmem_cache_alloc(linux_mem_area_cache, GFP_KERNEL);
- if (!mem_area)
- return NULL;
-
- cookie = ioremap_wrapper(address, bytes, area_flags);
- if (!cookie)
- {
- kmem_cache_free(linux_mem_area_cache, mem_area);
- return NULL;
- }
-
- mem_area->eAreaType = LINUX_MEM_AREA_IOREMAP;
- mem_area->uData.sIORemap.pvIORemapCookie = cookie;
- mem_area->uData.sIORemap.CPUPhysAddr = address;
- mem_area->ui32ByteSize = bytes;
- mem_area->ui32AreaFlags = area_flags;
- mem_area->bMMapRegistered = IMG_FALSE;
- INIT_LIST_HEAD(&mem_area->sMMapOffsetStructList);
-
- return mem_area;
-}
-
-
-static IMG_BOOL
-TreatExternalPagesAsContiguous(IMG_SYS_PHYADDR *psSysPhysAddr, u32 ui32Bytes, IMG_BOOL bPhysContig)
-{
- u32 ui32;
- u32 ui32AddrChk;
- u32 ui32NumPages = RANGE_TO_PAGES(ui32Bytes);
-
- for (ui32 = 0, ui32AddrChk = psSysPhysAddr[0].uiAddr;
- ui32 < ui32NumPages;
- ui32++, ui32AddrChk = (bPhysContig) ? (ui32AddrChk + PAGE_SIZE) : psSysPhysAddr[ui32].uiAddr)
- {
- if (!pfn_valid(PHYS_TO_PFN(ui32AddrChk)))
- {
- break;
- }
- }
- if (ui32 == ui32NumPages)
- {
- return IMG_FALSE;
- }
-
- if (!bPhysContig)
- {
- for (ui32 = 0, ui32AddrChk = psSysPhysAddr[0].uiAddr;
- ui32 < ui32NumPages;
- ui32++, ui32AddrChk += PAGE_SIZE)
- {
- if (psSysPhysAddr[ui32].uiAddr != ui32AddrChk)
- {
- return IMG_FALSE;
- }
- }
- }
-
- return IMG_TRUE;
-}
-
-
-LinuxMemArea *NewExternalKVLinuxMemArea(IMG_SYS_PHYADDR *pBasePAddr, void *pvCPUVAddr, u32 bytes, IMG_BOOL bPhysContig, u32 area_flags)
-{
- LinuxMemArea *mem_area;
-
- mem_area = kmem_cache_alloc(linux_mem_area_cache, GFP_KERNEL);
-
- if (!mem_area)
- return NULL;
-
- mem_area->eAreaType = LINUX_MEM_AREA_EXTERNAL_KV;
- mem_area->uData.sExternalKV.pvExternalKV = pvCPUVAddr;
- mem_area->uData.sExternalKV.bPhysContig = (IMG_BOOL)(bPhysContig || TreatExternalPagesAsContiguous(pBasePAddr, bytes, bPhysContig));
-
- if (mem_area->uData.sExternalKV.bPhysContig)
- mem_area->uData.sExternalKV.uPhysAddr.SysPhysAddr = *pBasePAddr;
- else
- mem_area->uData.sExternalKV.uPhysAddr.pSysPhysAddr = pBasePAddr;
-
- mem_area->ui32ByteSize = bytes;
- mem_area->ui32AreaFlags = area_flags;
- mem_area->bMMapRegistered = IMG_FALSE;
- INIT_LIST_HEAD(&mem_area->sMMapOffsetStructList);
-
- return mem_area;
-}
-
-LinuxMemArea *
-NewIOLinuxMemArea(resource_size_t address, u32 bytes, u32 area_flags)
-{
- LinuxMemArea *mem_area;
-
- mem_area = kmem_cache_alloc(linux_mem_area_cache, GFP_KERNEL);
-
- if (!mem_area)
- return NULL;
-
- mem_area->eAreaType = LINUX_MEM_AREA_IO;
- mem_area->uData.sIO.CPUPhysAddr = address;
- mem_area->ui32ByteSize = bytes;
- mem_area->ui32AreaFlags = area_flags;
- mem_area->bMMapRegistered = IMG_FALSE;
- INIT_LIST_HEAD(&mem_area->sMMapOffsetStructList);
-
- return mem_area;
-}
-
-
-LinuxMemArea * alloc_pages_linux_mem_area(u32 bytes, u32 area_flags)
-{
- LinuxMemArea *mem_area;
- int page_count;
- struct page **page_list;
- IMG_HANDLE hBlockPageList;
- int i;
- PVRSRV_ERROR eError;
-
- mem_area = kmem_cache_alloc(linux_mem_area_cache, GFP_KERNEL);
- if (!mem_area)
- goto failed_area_alloc;
-
-
- page_count = RANGE_TO_PAGES(bytes);
-
- eError = OSAllocMem(0, sizeof(*page_list) * page_count, (void **)&page_list, &hBlockPageList,
- "Array of pages");
-
- if(eError != PVRSRV_OK)
- goto failed_page_list_alloc;
-
- for(i=0; i<page_count; i++)
- {
- page_list[i] = alloc_pages(GFP_KERNEL | __GFP_HIGHMEM, 0);
- if(!page_list[i])
- goto failed_alloc_pages;
- }
-
- mem_area->eAreaType = LINUX_MEM_AREA_ALLOC_PAGES;
- mem_area->uData.sPageList.pvPageList = page_list;
- mem_area->uData.sPageList.hBlockPageList = hBlockPageList;
- mem_area->ui32ByteSize = bytes;
- mem_area->ui32AreaFlags = area_flags;
- mem_area->bMMapRegistered = IMG_FALSE;
- INIT_LIST_HEAD(&mem_area->sMMapOffsetStructList);
-
- return mem_area;
-
-failed_alloc_pages:
- for(i--; i >= 0; i--)
- __free_pages(page_list[i], 0);
-
- OSFreeMem(0, sizeof(*page_list) * page_count, page_list, hBlockPageList);
- mem_area->uData.sPageList.pvPageList = NULL;
-failed_page_list_alloc:
- kmem_cache_free(linux_mem_area_cache, mem_area);
-failed_area_alloc:
- pr_debug("%s: failed", __FUNCTION__);
-
- return NULL;
-}
-
-
-void free_pages_linux_mem_area(LinuxMemArea *mem_area)
-{
- u32 page_count;
- struct page **page_list;
- IMG_HANDLE hBlockPageList;
- int i;
-
- BUG_ON(!mem_area);
-
-
- page_count = RANGE_TO_PAGES(mem_area->ui32ByteSize);
- page_list = mem_area->uData.sPageList.pvPageList;
- hBlockPageList = mem_area->uData.sPageList.hBlockPageList;
-
- for(i = 0; i < page_count; i++)
- __free_pages(page_list[i], 0);
-
-
- OSFreeMem(0, sizeof(*page_list) * page_count, page_list, hBlockPageList);
- mem_area->uData.sPageList.pvPageList = NULL;
-}
-
-
-struct page* LinuxMemAreaOffsetToPage(LinuxMemArea *mem_area, u32 offset)
-{
- u32 page_index;
- u8 *addr;
-
- switch(mem_area->eAreaType)
- {
- case LINUX_MEM_AREA_ALLOC_PAGES:
- page_index = PHYS_TO_PFN(offset);
- return mem_area->uData.sPageList.pvPageList[page_index];
-
- case LINUX_MEM_AREA_VMALLOC:
- addr = mem_area->uData.sVmalloc.pvVmallocAddress;
- addr += offset;
- return vmalloc_to_page(addr);
-
- case LINUX_MEM_AREA_SUB_ALLOC:
- return LinuxMemAreaOffsetToPage(mem_area->uData.sSubAlloc.psParentLinuxMemArea,
- mem_area->uData.sSubAlloc.ui32ByteOffset
- + offset);
- default:
- pr_err("%s: Unsupported request for struct page from LinuxMemArea with type=%s",
- __FUNCTION__, LinuxMemAreaTypeToString(mem_area->eAreaType));
- return NULL;
- }
-}
-
-
-LinuxMemArea *NewSubLinuxMemArea(LinuxMemArea *parent, u32 offset, u32 bytes)
-{
- LinuxMemArea *mem_area;
-
- BUG_ON(offset+bytes > parent->ui32ByteSize);
-
- mem_area = kmem_cache_alloc(linux_mem_area_cache, GFP_KERNEL);
- if (!mem_area)
- return NULL;
-
- mem_area->eAreaType = LINUX_MEM_AREA_SUB_ALLOC;
- mem_area->uData.sSubAlloc.psParentLinuxMemArea = parent;
- mem_area->uData.sSubAlloc.ui32ByteOffset = offset;
- mem_area->ui32ByteSize = bytes;
- mem_area->ui32AreaFlags = parent->ui32AreaFlags;
- mem_area->bMMapRegistered = IMG_FALSE;
- INIT_LIST_HEAD(&mem_area->sMMapOffsetStructList);
-
- return mem_area;
-}
-
-
-void LinuxMemAreaDeepFree(LinuxMemArea *mem_area)
-{
- /* FIXME: call vfree and co direct, and free the mem area centrally at the end */
- switch(mem_area->eAreaType)
- {
- case LINUX_MEM_AREA_VMALLOC:
- vfree(mem_area->uData.sVmalloc.pvVmallocAddress);
- break;
- case LINUX_MEM_AREA_ALLOC_PAGES:
- free_pages_linux_mem_area(mem_area);
- break;
- case LINUX_MEM_AREA_IOREMAP:
- iounmap(mem_area->uData.sIORemap.pvIORemapCookie);
- break;
- case LINUX_MEM_AREA_EXTERNAL_KV:
- case LINUX_MEM_AREA_IO:
- case LINUX_MEM_AREA_SUB_ALLOC:
- break;
- default:
- pr_debug("%s: Unknown are type (%d)\n",
- __FUNCTION__, mem_area->eAreaType);
- break;
- }
- kmem_cache_free(linux_mem_area_cache, mem_area);
-}
-
-
-void * LinuxMemAreaToCpuVAddr(LinuxMemArea *mem_area)
-{
- switch(mem_area->eAreaType)
- {
- case LINUX_MEM_AREA_VMALLOC:
- return mem_area->uData.sVmalloc.pvVmallocAddress;
- case LINUX_MEM_AREA_IOREMAP:
- return mem_area->uData.sIORemap.pvIORemapCookie;
- case LINUX_MEM_AREA_EXTERNAL_KV:
- return mem_area->uData.sExternalKV.pvExternalKV;
- case LINUX_MEM_AREA_SUB_ALLOC:
- {
- char *addr = LinuxMemAreaToCpuVAddr(mem_area->uData.sSubAlloc.psParentLinuxMemArea);
- if (!addr)
- return NULL;
- return addr + mem_area->uData.sSubAlloc.ui32ByteOffset;
- }
- default:
- return NULL;
- }
-}
-
-
-resource_size_t LinuxMemAreaToCpuPAddr(LinuxMemArea *mem_area, u32 offset)
-{
- resource_size_t address;
-
- address = 0;
-
- switch(mem_area->eAreaType)
- {
- case LINUX_MEM_AREA_IOREMAP:
- {
- address = mem_area->uData.sIORemap.CPUPhysAddr;
- address += offset;
- break;
- }
- case LINUX_MEM_AREA_EXTERNAL_KV:
- {
- if (mem_area->uData.sExternalKV.bPhysContig)
- {
- IMG_CPU_PHYADDR CpuPAddr = SysSysPAddrToCpuPAddr(mem_area->uData.sExternalKV.uPhysAddr.SysPhysAddr);
- address = CpuPAddr.uiAddr + offset;
- } else {
- u32 page_index = PHYS_TO_PFN(offset);
- IMG_SYS_PHYADDR SysPAddr = mem_area->uData.sExternalKV.uPhysAddr.pSysPhysAddr[page_index];
- IMG_CPU_PHYADDR CpuPAddr = SysSysPAddrToCpuPAddr(SysPAddr);
- address = CpuPAddr.uiAddr + ADDR_TO_PAGE_OFFSET(offset);
- }
- break;
- }
- case LINUX_MEM_AREA_IO:
- {
- address = mem_area->uData.sIO.CPUPhysAddr;
- address += offset;
- break;
- }
- case LINUX_MEM_AREA_VMALLOC:
- {
- char *vaddr;
- vaddr = mem_area->uData.sVmalloc.pvVmallocAddress;
- vaddr += offset;
- address = VMallocToPhys(vaddr);
- break;
- }
- case LINUX_MEM_AREA_ALLOC_PAGES:
- {
- struct page *page;
- u32 page_index = PHYS_TO_PFN(offset);
- page = mem_area->uData.sPageList.pvPageList[page_index];
- address = page_to_phys(page);
- address += ADDR_TO_PAGE_OFFSET(offset);
- break;
- }
- case LINUX_MEM_AREA_SUB_ALLOC:
- {
- IMG_CPU_PHYADDR CpuPAddr =
- OSMemHandleToCpuPAddr(mem_area->uData.sSubAlloc.psParentLinuxMemArea,
- mem_area->uData.sSubAlloc.ui32ByteOffset
- + offset);
-
- address = CpuPAddr.uiAddr;
- break;
- }
- default:
- pr_debug("%s: Unknown LinuxMemArea type (%d)\n",
- __FUNCTION__, mem_area->eAreaType);
- break;
- }
-
- BUG_ON(!address);
- return address;
-}
-
-
-IMG_BOOL LinuxMemAreaPhysIsContig(LinuxMemArea *mem_area)
-{
- switch(mem_area->eAreaType)
- {
- case LINUX_MEM_AREA_IOREMAP:
- case LINUX_MEM_AREA_IO:
- return IMG_TRUE;
-
- case LINUX_MEM_AREA_EXTERNAL_KV:
- return mem_area->uData.sExternalKV.bPhysContig;
-
- case LINUX_MEM_AREA_VMALLOC:
- case LINUX_MEM_AREA_ALLOC_PAGES:
- return IMG_FALSE;
-
- case LINUX_MEM_AREA_SUB_ALLOC:
-
- return LinuxMemAreaPhysIsContig(mem_area->uData.sSubAlloc.psParentLinuxMemArea);
-
- default:
- pr_debug("%s: Unknown LinuxMemArea type (%d)\n",
- __FUNCTION__, mem_area->eAreaType);
- break;
- }
- return IMG_FALSE;
-}
-
-
-const char *
-LinuxMemAreaTypeToString(LINUX_MEM_AREA_TYPE eMemAreaType)
-{
-
- switch(eMemAreaType)
- {
- case LINUX_MEM_AREA_IOREMAP:
- return "LINUX_MEM_AREA_IOREMAP";
- case LINUX_MEM_AREA_EXTERNAL_KV:
- return "LINUX_MEM_AREA_EXTERNAL_KV";
- case LINUX_MEM_AREA_IO:
- return "LINUX_MEM_AREA_IO";
- case LINUX_MEM_AREA_VMALLOC:
- return "LINUX_MEM_AREA_VMALLOC";
- case LINUX_MEM_AREA_SUB_ALLOC:
- return "LINUX_MEM_AREA_SUB_ALLOC";
- case LINUX_MEM_AREA_ALLOC_PAGES:
- return "LINUX_MEM_AREA_ALLOC_PAGES";
- default:
- BUG();
- }
-
- return "";
-}
+++ /dev/null
-/**********************************************************************
- *
- * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful but, except
- * as otherwise stated in writing, 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.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK
- *
- ******************************************************************************/
-
-#ifndef __IMG_LINUX_MM_H__
-#define __IMG_LINUX_MM_H__
-
-#include <linux/slab.h>
-#include <linux/mm.h>
-#include <linux/list.h>
-#include <linux/types.h>
-
-#include <asm/io.h>
-
-#define PHYS_TO_PFN(phys) ((phys) >> PAGE_SHIFT)
-#define PFN_TO_PHYS(pfn) ((pfn) << PAGE_SHIFT)
-
-#define RANGE_TO_PAGES(range) (((range) + (PAGE_SIZE - 1)) >> PAGE_SHIFT)
-
-#define ADDR_TO_PAGE_OFFSET(addr) (((unsigned long)(addr)) & (PAGE_SIZE - 1))
-
-static inline u32 VMallocToPhys(void *pCpuVAddr)
-{
- return (page_to_phys(vmalloc_to_page(pCpuVAddr)) + ADDR_TO_PAGE_OFFSET(pCpuVAddr));
-
-}
-
-typedef enum {
- LINUX_MEM_AREA_IOREMAP,
- LINUX_MEM_AREA_EXTERNAL_KV,
- LINUX_MEM_AREA_IO,
- LINUX_MEM_AREA_VMALLOC,
- LINUX_MEM_AREA_ALLOC_PAGES,
- LINUX_MEM_AREA_SUB_ALLOC,
- LINUX_MEM_AREA_TYPE_COUNT
-}LINUX_MEM_AREA_TYPE;
-
-typedef struct _LinuxMemArea LinuxMemArea;
-
-
-struct _LinuxMemArea {
- LINUX_MEM_AREA_TYPE eAreaType;
- union _uData
- {
- struct _sIORemap
- {
-
- resource_size_t CPUPhysAddr;
- void *pvIORemapCookie;
- }sIORemap;
- struct _sExternalKV
- {
-
- IMG_BOOL bPhysContig;
- union {
-
- IMG_SYS_PHYADDR SysPhysAddr;
- IMG_SYS_PHYADDR *pSysPhysAddr;
- } uPhysAddr;
- void *pvExternalKV;
- }sExternalKV;
- struct _sIO
- {
- resource_size_t CPUPhysAddr;
- }sIO;
- struct _sVmalloc
- {
-
- void *pvVmallocAddress;
- }sVmalloc;
- struct _sPageList
- {
-
- struct page **pvPageList;
- IMG_HANDLE hBlockPageList;
- }sPageList;
- struct _sSubAlloc
- {
-
- LinuxMemArea *psParentLinuxMemArea;
- u32 ui32ByteOffset;
- }sSubAlloc;
- }uData;
-
- u32 ui32ByteSize;
-
- u32 ui32AreaFlags;
-
- IMG_BOOL bMMapRegistered;
-
-
- struct list_head sMMapItem;
-
-
- struct list_head sMMapOffsetStructList;
-};
-
-int linux_mm_init(void);
-
-
-void linux_mm_cleanup(void);
-
-void *vmalloc_wrapper(u32 bytes, u32 alloc_flags);
-
-LinuxMemArea *vmalloc_linux_mem_area(u32 bytes, u32 area_flags);
-
-
-void *ioremap_wrapper(resource_size_t address, u32 bytes, u32 mapping_flags);
-
-
-LinuxMemArea *ioremap_linux_mem_area(resource_size_t address, u32 bytes, u32 area_flags);
-
-
-LinuxMemArea *NewExternalKVLinuxMemArea(IMG_SYS_PHYADDR *pBasePAddr, void *pvCPUVAddr, u32 ui32Bytes, IMG_BOOL bPhysContig, u32 ui32AreaFlags);
-
-
-struct page *LinuxMemAreaOffsetToPage(LinuxMemArea *psLinuxMemArea, u32 ui32ByteOffset);
-
-
-LinuxMemArea *NewIOLinuxMemArea(resource_size_t address, u32 ui32Bytes, u32 ui32AreaFlags);
-
-
-LinuxMemArea *alloc_pages_linux_mem_area(u32 ui32Bytes, u32 ui32AreaFlags);
-
-
-void free_pages_linux_mem_area(LinuxMemArea *psLinuxMemArea);
-
-
-LinuxMemArea *NewSubLinuxMemArea(LinuxMemArea *psParentLinuxMemArea,
- u32 ui32ByteOffset,
- u32 ui32Bytes);
-
-
-void LinuxMemAreaDeepFree(LinuxMemArea *psLinuxMemArea);
-
-
-void *LinuxMemAreaToCpuVAddr(LinuxMemArea *psLinuxMemArea);
-
-
-resource_size_t LinuxMemAreaToCpuPAddr(LinuxMemArea *mem_area, u32 offset);
-
-
-#define LinuxMemAreaToCpuPFN(psLinuxMemArea, ui32ByteOffset) PHYS_TO_PFN(LinuxMemAreaToCpuPAddr(psLinuxMemArea, ui32ByteOffset))
-
-IMG_BOOL LinuxMemAreaPhysIsContig(LinuxMemArea *psLinuxMemArea);
-
-static inline LinuxMemArea *
-LinuxMemAreaRoot(LinuxMemArea *psLinuxMemArea)
-{
- if(psLinuxMemArea->eAreaType == LINUX_MEM_AREA_SUB_ALLOC)
- {
- return psLinuxMemArea->uData.sSubAlloc.psParentLinuxMemArea;
- }
- else
- {
- return psLinuxMemArea;
- }
-}
-
-
-static inline LINUX_MEM_AREA_TYPE
-LinuxMemAreaRootType(LinuxMemArea *psLinuxMemArea)
-{
- return LinuxMemAreaRoot(psLinuxMemArea)->eAreaType;
-}
-
-
-const IMG_CHAR *LinuxMemAreaTypeToString(LINUX_MEM_AREA_TYPE eMemAreaType);
-
-
-#if defined(PVR_DEBUG_EXT)
-const IMG_CHAR *HAPFlagsToString(u32 ui32Flags);
-#endif
-
-#endif
-
+++ /dev/null
-/**********************************************************************
- *
- * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful but, except
- * as otherwise stated in writing, 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.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK
- *
- ******************************************************************************/
-
-#include <linux/version.h>
-#include <linux/mm.h>
-#include <linux/module.h>
-#include <linux/vmalloc.h>
-#include <linux/slab.h>
-#include <linux/mutex.h>
-#include <asm/io.h>
-#include <asm/page.h>
-#include <asm/shmparam.h>
-#include <asm/pgtable.h>
-#include <linux/sched.h>
-#include <asm/current.h>
-#if defined(SUPPORT_DRI_DRM)
-#include <drm/drmP.h>
-#endif
-
-#include "img_defs.h"
-#include "services.h"
-#include "servicesint.h"
-#include "pvrmmap.h"
-#include "mutils.h"
-#include "mmap.h"
-#include "mm.h"
-#include "pvr_debug.h"
-#include "osfunc.h"
-#include "proc.h"
-#include "handle.h"
-#include "perproc.h"
-#include "env_perproc.h"
-#include "bridged_support.h"
-#if defined(SUPPORT_DRI_DRM)
-#include "pvr_drm.h"
-#endif
-
-#if !defined(PVR_SECURE_HANDLES)
-#error "The mmap code requires PVR_SECURE_HANDLES"
-#endif
-
-static struct mutex g_sMMapMutex;
-
-static struct kmem_cache *g_psMemmapCache = NULL;
-static LIST_HEAD(g_sMMapAreaList);
-static LIST_HEAD(g_sMMapOffsetStructList);
-
-
-#define FIRST_PHYSICAL_PFN 0
-#define LAST_PHYSICAL_PFN 0x7fffffffUL
-#define FIRST_SPECIAL_PFN (LAST_PHYSICAL_PFN + 1)
-#define LAST_SPECIAL_PFN 0xffffffffUL
-
-#define MAX_MMAP_HANDLE 0x7fffffffUL
-
-static inline IMG_BOOL
-PFNIsPhysical(IMG_UINT32 pfn)
-{
-
- return ((pfn >= FIRST_PHYSICAL_PFN) && (pfn <= LAST_PHYSICAL_PFN)) ? IMG_TRUE : IMG_FALSE;
-}
-
-static inline IMG_BOOL
-PFNIsSpecial(IMG_UINT32 pfn)
-{
-
- return ((pfn >= FIRST_SPECIAL_PFN) && (pfn <= LAST_SPECIAL_PFN)) ? IMG_TRUE : IMG_FALSE;
-}
-
-static inline IMG_HANDLE
-MMapOffsetToHandle(IMG_UINT32 pfn)
-{
- if (PFNIsPhysical(pfn))
- {
- PVR_ASSERT(PFNIsPhysical(pfn));
- return IMG_NULL;
- }
-
- return (IMG_HANDLE)(pfn - FIRST_SPECIAL_PFN);
-}
-
-static inline IMG_UINT32
-HandleToMMapOffset(IMG_HANDLE hHandle)
-{
- IMG_UINT32 ulHandle = (IMG_UINT32)hHandle;
-
- if (PFNIsSpecial(ulHandle))
- {
- PVR_ASSERT(PFNIsSpecial(ulHandle));
- return 0;
- }
-
- return ulHandle + FIRST_SPECIAL_PFN;
-}
-
-static inline IMG_BOOL
-LinuxMemAreaUsesPhysicalMap(LinuxMemArea *psLinuxMemArea)
-{
- return LinuxMemAreaPhysIsContig(psLinuxMemArea);
-}
-
-static inline IMG_UINT32
-GetCurrentThreadID(IMG_VOID)
-{
- return (IMG_UINT32)current->pid;
-}
-
-static PKV_OFFSET_STRUCT
-CreateOffsetStruct(LinuxMemArea *psLinuxMemArea, IMG_UINT32 ui32Offset, IMG_UINT32 ui32RealByteSize)
-{
- PKV_OFFSET_STRUCT psOffsetStruct;
-#if defined(PVR_DEBUG_EXT)
- const IMG_CHAR *pszName = LinuxMemAreaTypeToString(LinuxMemAreaRootType(psLinuxMemArea));
-#endif
-
-#if defined(PVR_DEBUG_EXT)
- PVR_DPF((PVR_DBG_MESSAGE,
- "%s(%s, psLinuxMemArea: 0x%p, ui32AllocFlags: 0x%8lx)",
- __FUNCTION__, pszName, psLinuxMemArea, psLinuxMemArea->ui32AreaFlags));
-#endif
-
- PVR_ASSERT(psLinuxMemArea->eAreaType != LINUX_MEM_AREA_SUB_ALLOC || LinuxMemAreaRoot(psLinuxMemArea)->eAreaType != LINUX_MEM_AREA_SUB_ALLOC);
-
- PVR_ASSERT(psLinuxMemArea->bMMapRegistered);
-
- psOffsetStruct = kmem_cache_alloc(g_psMemmapCache, GFP_KERNEL);
- if(psOffsetStruct == IMG_NULL)
- {
- PVR_DPF((PVR_DBG_ERROR,"PVRMMapRegisterArea: Couldn't alloc another mapping record from cache"));
- return IMG_NULL;
- }
-
- psOffsetStruct->ui32MMapOffset = ui32Offset;
-
- psOffsetStruct->psLinuxMemArea = psLinuxMemArea;
-
- psOffsetStruct->ui32Mapped = 0;
-
- psOffsetStruct->ui32RealByteSize = ui32RealByteSize;
-
-
- psOffsetStruct->ui32TID = GetCurrentThreadID();
-
- psOffsetStruct->ui32PID = OSGetCurrentProcessIDKM();
-
- psOffsetStruct->bOnMMapList = IMG_FALSE;
-
- psOffsetStruct->ui32RefCount = 0;
-
- psOffsetStruct->ui32UserVAddr = 0;
-
- list_add_tail(&psOffsetStruct->sAreaItem, &psLinuxMemArea->sMMapOffsetStructList);
-
- return psOffsetStruct;
-}
-
-
-static IMG_VOID
-DestroyOffsetStruct(PKV_OFFSET_STRUCT psOffsetStruct)
-{
- list_del(&psOffsetStruct->sAreaItem);
-
- if (psOffsetStruct->bOnMMapList)
- {
- list_del(&psOffsetStruct->sMMapItem);
- }
-
- PVR_DPF((PVR_DBG_MESSAGE, "%s: Table entry: "
- "psLinuxMemArea=0x%08lX, CpuPAddr=0x%08lX", __FUNCTION__,
- psOffsetStruct->psLinuxMemArea,
- LinuxMemAreaToCpuPAddr(psOffsetStruct->psLinuxMemArea, 0)));
-
- kmem_cache_free(g_psMemmapCache, psOffsetStruct);
-}
-
-
-static inline IMG_VOID
-DetermineUsersSizeAndByteOffset(LinuxMemArea *psLinuxMemArea,
- IMG_UINT32 *pui32RealByteSize,
- IMG_UINT32 *pui32ByteOffset)
-{
- IMG_UINT32 ui32PageAlignmentOffset;
- IMG_CPU_PHYADDR CpuPAddr;
-
- CpuPAddr.uiAddr = LinuxMemAreaToCpuPAddr(psLinuxMemArea, 0);
- ui32PageAlignmentOffset = ADDR_TO_PAGE_OFFSET(CpuPAddr.uiAddr);
-
- *pui32ByteOffset = ui32PageAlignmentOffset;
-
- *pui32RealByteSize = PAGE_ALIGN(psLinuxMemArea->ui32ByteSize + ui32PageAlignmentOffset);
-}
-
-
-PVRSRV_ERROR
-PVRMMapOSMemHandleToMMapData(PVRSRV_PER_PROCESS_DATA *psPerProc,
- IMG_HANDLE hMHandle,
- IMG_UINT32 *pui32MMapOffset,
- IMG_UINT32 *pui32ByteOffset,
- IMG_UINT32 *pui32RealByteSize,
- IMG_UINT32 *pui32UserVAddr)
-{
- LinuxMemArea *psLinuxMemArea;
- PKV_OFFSET_STRUCT psOffsetStruct;
- IMG_HANDLE hOSMemHandle;
- PVRSRV_ERROR eError;
-
- mutex_lock(&g_sMMapMutex);
-
- PVR_ASSERT(PVRSRVGetMaxHandle(psPerProc->psHandleBase) <= MAX_MMAP_HANDLE);
-
- eError = PVRSRVLookupOSMemHandle(psPerProc->psHandleBase, &hOSMemHandle, hMHandle);
- if (eError != PVRSRV_OK)
- {
- PVR_DPF((PVR_DBG_ERROR, "%s: Lookup of handle 0x%lx failed", __FUNCTION__, hMHandle));
-
- goto exit_unlock;
- }
-
- psLinuxMemArea = (LinuxMemArea *)hOSMemHandle;
-
- DetermineUsersSizeAndByteOffset(psLinuxMemArea,
- pui32RealByteSize,
- pui32ByteOffset);
-
-
- list_for_each_entry(psOffsetStruct, &psLinuxMemArea->sMMapOffsetStructList, sAreaItem)
- {
- if (psPerProc->ui32PID == psOffsetStruct->ui32PID)
- {
-
- PVR_ASSERT(*pui32RealByteSize == psOffsetStruct->ui32RealByteSize);
-
- *pui32MMapOffset = psOffsetStruct->ui32MMapOffset;
- *pui32UserVAddr = psOffsetStruct->ui32UserVAddr;
- psOffsetStruct->ui32RefCount++;
-
- eError = PVRSRV_OK;
- goto exit_unlock;
- }
- }
-
-
- *pui32UserVAddr = 0;
-
- if (LinuxMemAreaUsesPhysicalMap(psLinuxMemArea))
- {
- *pui32MMapOffset = LinuxMemAreaToCpuPFN(psLinuxMemArea, 0);
- PVR_ASSERT(PFNIsPhysical(*pui32MMapOffset));
- }
- else
- {
- *pui32MMapOffset = HandleToMMapOffset(hMHandle);
- PVR_ASSERT(PFNIsSpecial(*pui32MMapOffset));
- }
-
- psOffsetStruct = CreateOffsetStruct(psLinuxMemArea, *pui32MMapOffset, *pui32RealByteSize);
- if (psOffsetStruct == IMG_NULL)
- {
- eError = PVRSRV_ERROR_OUT_OF_MEMORY;
- goto exit_unlock;
- }
-
-
- list_add_tail(&psOffsetStruct->sMMapItem, &g_sMMapOffsetStructList);
-
- psOffsetStruct->bOnMMapList = IMG_TRUE;
-
- psOffsetStruct->ui32RefCount++;
-
- eError = PVRSRV_OK;
-
-exit_unlock:
- mutex_unlock(&g_sMMapMutex);
-
- return eError;
-}
-
-
-PVRSRV_ERROR
-PVRMMapReleaseMMapData(PVRSRV_PER_PROCESS_DATA *psPerProc,
- IMG_HANDLE hMHandle,
- IMG_BOOL *pbMUnmap,
- IMG_UINT32 *pui32RealByteSize,
- IMG_UINT32 *pui32UserVAddr)
-{
- LinuxMemArea *psLinuxMemArea;
- PKV_OFFSET_STRUCT psOffsetStruct;
- IMG_HANDLE hOSMemHandle;
- PVRSRV_ERROR eError;
- IMG_UINT32 ui32PID = OSGetCurrentProcessIDKM();
-
- mutex_lock(&g_sMMapMutex);
-
- PVR_ASSERT(PVRSRVGetMaxHandle(psPerProc->psHandleBase) <= MAX_MMAP_HANDLE);
-
- eError = PVRSRVLookupOSMemHandle(psPerProc->psHandleBase, &hOSMemHandle, hMHandle);
- if (eError != PVRSRV_OK)
- {
- PVR_DPF((PVR_DBG_ERROR, "%s: Lookup of handle 0x%lx failed", __FUNCTION__, hMHandle));
-
- goto exit_unlock;
- }
-
- psLinuxMemArea = (LinuxMemArea *)hOSMemHandle;
-
-
- list_for_each_entry(psOffsetStruct, &psLinuxMemArea->sMMapOffsetStructList, sAreaItem)
- {
- if (psOffsetStruct->ui32PID == ui32PID)
- {
- if (psOffsetStruct->ui32RefCount == 0)
- {
- PVR_DPF((PVR_DBG_ERROR, "%s: Attempt to release mmap data with zero reference count for offset struct 0x%p, memory area 0x%p", __FUNCTION__, psOffsetStruct, psLinuxMemArea));
- eError = PVRSRV_ERROR_GENERIC;
- goto exit_unlock;
- }
-
- psOffsetStruct->ui32RefCount--;
-
- *pbMUnmap = (IMG_BOOL)((psOffsetStruct->ui32RefCount == 0) && (psOffsetStruct->ui32UserVAddr != 0));
-
- *pui32UserVAddr = (*pbMUnmap) ? psOffsetStruct->ui32UserVAddr : 0;
- *pui32RealByteSize = (*pbMUnmap) ? psOffsetStruct->ui32RealByteSize : 0;
-
- eError = PVRSRV_OK;
- goto exit_unlock;
- }
- }
-
-
- PVR_DPF((PVR_DBG_ERROR, "%s: Mapping data not found for handle 0x%lx (memory area 0x%p)", __FUNCTION__, hMHandle, psLinuxMemArea));
-
- eError = PVRSRV_ERROR_GENERIC;
-
-exit_unlock:
- mutex_unlock(&g_sMMapMutex);
-
- return eError;
-}
-
-static inline PKV_OFFSET_STRUCT
-FindOffsetStructByOffset(IMG_UINT32 ui32Offset, IMG_UINT32 ui32RealByteSize)
-{
- PKV_OFFSET_STRUCT psOffsetStruct;
- IMG_UINT32 ui32TID = GetCurrentThreadID();
- IMG_UINT32 ui32PID = OSGetCurrentProcessIDKM();
-
- list_for_each_entry(psOffsetStruct, &g_sMMapOffsetStructList, sMMapItem)
- {
- if (ui32Offset == psOffsetStruct->ui32MMapOffset && ui32RealByteSize == psOffsetStruct->ui32RealByteSize && psOffsetStruct->ui32PID == ui32PID)
- {
-
- if (!PFNIsPhysical(ui32Offset) || psOffsetStruct->ui32TID == ui32TID)
- {
- return psOffsetStruct;
- }
- }
- }
-
- return IMG_NULL;
-}
-
-
-static IMG_BOOL
-DoMapToUser(LinuxMemArea *psLinuxMemArea,
- struct vm_area_struct* ps_vma,
- IMG_UINT32 ui32ByteOffset)
-{
- IMG_UINT32 ui32ByteSize;
-
- if (psLinuxMemArea->eAreaType == LINUX_MEM_AREA_SUB_ALLOC)
- {
- return DoMapToUser(LinuxMemAreaRoot(psLinuxMemArea),
- ps_vma,
- psLinuxMemArea->uData.sSubAlloc.ui32ByteOffset + ui32ByteOffset);
- }
-
-
- ui32ByteSize = ps_vma->vm_end - ps_vma->vm_start;
- PVR_ASSERT(ADDR_TO_PAGE_OFFSET(ui32ByteSize) == 0);
-
-#if defined (__sparc__)
-
-#error "SPARC not supported"
-#endif
-
- if (PFNIsPhysical(ps_vma->vm_pgoff))
- {
- IMG_INT result;
-
- PVR_ASSERT(LinuxMemAreaPhysIsContig(psLinuxMemArea));
- PVR_ASSERT(LinuxMemAreaToCpuPFN(psLinuxMemArea, ui32ByteOffset) == ps_vma->vm_pgoff);
-
-
- result = io_remap_pfn_range(ps_vma, ps_vma->vm_start, ps_vma->vm_pgoff, ui32ByteSize, ps_vma->vm_page_prot);
-
- if(result == 0)
- {
- return IMG_TRUE;
- }
-
- PVR_DPF((PVR_DBG_MESSAGE, "%s: Failed to map contiguous physical address range (%d), trying non-contiguous path", __FUNCTION__, result));
- }
-
- {
-
- IMG_UINT32 ulVMAPos;
- IMG_UINT32 ui32ByteEnd = ui32ByteOffset + ui32ByteSize;
- IMG_UINT32 ui32PA;
-
-
- for(ui32PA = ui32ByteOffset; ui32PA < ui32ByteEnd; ui32PA += PAGE_SIZE)
- {
- IMG_UINT32 pfn = LinuxMemAreaToCpuPFN(psLinuxMemArea, ui32PA);
-
- if (!pfn_valid(pfn))
- {
- PVR_DPF((PVR_DBG_ERROR,"%s: Error - PFN invalid: 0x%lx", __FUNCTION__, pfn));
- return IMG_FALSE;
- }
- }
-
-
- ulVMAPos = ps_vma->vm_start;
- for(ui32PA = ui32ByteOffset; ui32PA < ui32ByteEnd; ui32PA += PAGE_SIZE)
- {
- IMG_UINT32 pfn;
- struct page *psPage;
- IMG_INT result;
-
- pfn = LinuxMemAreaToCpuPFN(psLinuxMemArea, ui32PA);
- PVR_ASSERT(pfn_valid(pfn));
-
- psPage = pfn_to_page(pfn);
-
- result = vm_insert_page(ps_vma, ulVMAPos, psPage);
- if(result != 0)
- {
- PVR_DPF((PVR_DBG_ERROR,"%s: Error - vm_insert_page failed (%d)", __FUNCTION__, result));
- return IMG_FALSE;
- }
- ulVMAPos += PAGE_SIZE;
- }
- }
-
- return IMG_TRUE;
-}
-
-
-static IMG_VOID
-MMapVOpenNoLock(struct vm_area_struct* ps_vma)
-{
- PKV_OFFSET_STRUCT psOffsetStruct = (PKV_OFFSET_STRUCT)ps_vma->vm_private_data;
- PVR_ASSERT(psOffsetStruct != IMG_NULL)
- psOffsetStruct->ui32Mapped++;
- PVR_ASSERT(!psOffsetStruct->bOnMMapList);
-
- if (psOffsetStruct->ui32Mapped > 1)
- {
- PVR_DPF((PVR_DBG_WARNING, "%s: Offset structure 0x%p is being shared across processes (psOffsetStruct->ui32Mapped: %lu)", __FUNCTION__, psOffsetStruct, psOffsetStruct->ui32Mapped));
- PVR_ASSERT((ps_vma->vm_flags & VM_DONTCOPY) == 0);
- }
-
-}
-
-
-static void
-MMapVOpen(struct vm_area_struct* ps_vma)
-{
- mutex_lock(&g_sMMapMutex);
-
- MMapVOpenNoLock(ps_vma);
-
- mutex_unlock(&g_sMMapMutex);
-}
-
-
-static IMG_VOID
-MMapVCloseNoLock(struct vm_area_struct* ps_vma)
-{
- PKV_OFFSET_STRUCT psOffsetStruct = (PKV_OFFSET_STRUCT)ps_vma->vm_private_data;
- PVR_ASSERT(psOffsetStruct != IMG_NULL)
-
- PVR_ASSERT(!psOffsetStruct->bOnMMapList);
- psOffsetStruct->ui32Mapped--;
- if (psOffsetStruct->ui32Mapped == 0)
- {
- if (psOffsetStruct->ui32RefCount != 0)
- {
- PVR_DPF((PVR_DBG_MESSAGE, "%s: psOffsetStruct 0x%p has non-zero reference count (ui32RefCount = %lu). User mode address of start of mapping: 0x%lx", __FUNCTION__, psOffsetStruct, psOffsetStruct->ui32RefCount, psOffsetStruct->ui32UserVAddr));
- }
-
- DestroyOffsetStruct(psOffsetStruct);
- }
-
- ps_vma->vm_private_data = NULL;
-
-}
-
-static void
-MMapVClose(struct vm_area_struct* ps_vma)
-{
- mutex_lock(&g_sMMapMutex);
-
- MMapVCloseNoLock(ps_vma);
-
- mutex_unlock(&g_sMMapMutex);
-}
-
-
-static struct vm_operations_struct MMapIOOps =
-{
- .open=MMapVOpen,
- .close=MMapVClose
-};
-
-
-int
-PVRMMap(struct file* pFile, struct vm_area_struct* ps_vma)
-{
- IMG_UINT32 ui32ByteSize;
- PKV_OFFSET_STRUCT psOffsetStruct;
- int iRetVal = 0;
-
- PVR_UNREFERENCED_PARAMETER(pFile);
-
- mutex_lock(&g_sMMapMutex);
-
- ui32ByteSize = ps_vma->vm_end - ps_vma->vm_start;
-
- PVR_DPF((PVR_DBG_MESSAGE, "%s: Received mmap(2) request with ui32MMapOffset 0x%08lx,"
- " and ui32ByteSize %ld(0x%08lx)",
- __FUNCTION__,
- ps_vma->vm_pgoff,
- ui32ByteSize, ui32ByteSize));
-
- psOffsetStruct = FindOffsetStructByOffset(ps_vma->vm_pgoff, ui32ByteSize);
- if (psOffsetStruct == IMG_NULL)
- {
-#if defined(SUPPORT_DRI_DRM)
- mutex_unlock(&g_sMMapMutex);
-
-
- return drm_mmap(pFile, ps_vma);
-#else
- PVR_UNREFERENCED_PARAMETER(pFile);
-
- PVR_DPF((PVR_DBG_ERROR,
- "%s: Attempted to mmap unregistered area at vm_pgoff %ld",
- __FUNCTION__, ps_vma->vm_pgoff));
- iRetVal = -EINVAL;
-#endif
- goto unlock_and_return;
- }
- list_del(&psOffsetStruct->sMMapItem);
- psOffsetStruct->bOnMMapList = IMG_FALSE;
-
-
- if (((ps_vma->vm_flags & VM_WRITE) != 0) &&
- ((ps_vma->vm_flags & VM_SHARED) == 0))
- {
- PVR_DPF((PVR_DBG_ERROR, "%s: Cannot mmap non-shareable writable areas", __FUNCTION__));
- iRetVal = -EINVAL;
- goto unlock_and_return;
- }
-
- PVR_DPF((PVR_DBG_MESSAGE, "%s: Mapped psLinuxMemArea 0x%p\n",
- __FUNCTION__, psOffsetStruct->psLinuxMemArea));
-
- ps_vma->vm_flags |= VM_RESERVED;
- ps_vma->vm_flags |= VM_IO;
-
-
- ps_vma->vm_flags |= VM_DONTEXPAND;
-
-
- ps_vma->vm_flags |= VM_DONTCOPY;
-
- ps_vma->vm_private_data = (void *)psOffsetStruct;
-
- switch(psOffsetStruct->psLinuxMemArea->ui32AreaFlags & PVRSRV_HAP_CACHETYPE_MASK)
- {
- case PVRSRV_HAP_CACHED:
-
- break;
- case PVRSRV_HAP_WRITECOMBINE:
- ps_vma->vm_page_prot = PGPROT_WC(ps_vma->vm_page_prot);
- break;
- case PVRSRV_HAP_UNCACHED:
- ps_vma->vm_page_prot = PGPROT_UC(ps_vma->vm_page_prot);
- break;
- default:
- PVR_DPF((PVR_DBG_ERROR, "%s: unknown cache type", __FUNCTION__));
- iRetVal = -EINVAL;
- goto unlock_and_return;
- }
-
-
- ps_vma->vm_ops = &MMapIOOps;
-
- if(!DoMapToUser(psOffsetStruct->psLinuxMemArea, ps_vma, 0))
- {
- iRetVal = -EAGAIN;
- goto unlock_and_return;
- }
-
- PVR_ASSERT(psOffsetStruct->ui32UserVAddr == 0)
-
- psOffsetStruct->ui32UserVAddr = ps_vma->vm_start;
-
-
- MMapVOpenNoLock(ps_vma);
-
- PVR_DPF((PVR_DBG_MESSAGE, "%s: Mapped area at offset 0x%08lx\n",
- __FUNCTION__, ps_vma->vm_pgoff));
-
-unlock_and_return:
- if (iRetVal != 0 && psOffsetStruct != IMG_NULL)
- {
- DestroyOffsetStruct(psOffsetStruct);
- }
-
- mutex_unlock(&g_sMMapMutex);
-
- return iRetVal;
-}
-
-
-
-
-PVRSRV_ERROR
-PVRMMapRegisterArea(LinuxMemArea *psLinuxMemArea)
-{
- PVRSRV_ERROR eError;
-#if defined(PVR_DEBUG_EXT)
- const IMG_CHAR *pszName = LinuxMemAreaTypeToString(LinuxMemAreaRootType(psLinuxMemArea));
-#endif
-
- mutex_lock(&g_sMMapMutex);
-
-#if defined(PVR_DEBUG_EXT)
- PVR_DPF((PVR_DBG_MESSAGE,
- "%s(%s, psLinuxMemArea 0x%p, ui32AllocFlags 0x%8lx)",
- __FUNCTION__, pszName, psLinuxMemArea, psLinuxMemArea->ui32AreaFlags));
-#endif
-
- PVR_ASSERT(psLinuxMemArea->eAreaType != LINUX_MEM_AREA_SUB_ALLOC || LinuxMemAreaRoot(psLinuxMemArea)->eAreaType != LINUX_MEM_AREA_SUB_ALLOC);
-
-
- if(psLinuxMemArea->bMMapRegistered)
- {
- PVR_DPF((PVR_DBG_ERROR, "%s: psLinuxMemArea 0x%p is already registered",
- __FUNCTION__, psLinuxMemArea));
- eError = PVRSRV_ERROR_INVALID_PARAMS;
- goto exit_unlock;
- }
-
- list_add_tail(&psLinuxMemArea->sMMapItem, &g_sMMapAreaList);
-
- psLinuxMemArea->bMMapRegistered = IMG_TRUE;
-
- eError = PVRSRV_OK;
-
-exit_unlock:
- mutex_unlock(&g_sMMapMutex);
-
- return eError;
-}
-
-
-PVRSRV_ERROR
-PVRMMapRemoveRegisteredArea(LinuxMemArea *psLinuxMemArea)
-{
- PVRSRV_ERROR eError;
- PKV_OFFSET_STRUCT psOffsetStruct, psTmpOffsetStruct;
-
- mutex_lock(&g_sMMapMutex);
-
- PVR_ASSERT(psLinuxMemArea->bMMapRegistered);
-
- list_for_each_entry_safe(psOffsetStruct, psTmpOffsetStruct, &psLinuxMemArea->sMMapOffsetStructList, sAreaItem)
- {
- if (psOffsetStruct->ui32Mapped != 0)
- {
- PVR_DPF((PVR_DBG_ERROR, "%s: psOffsetStruct 0x%p for memory area 0x0x%p is still mapped; psOffsetStruct->ui32Mapped %lu", __FUNCTION__, psOffsetStruct, psLinuxMemArea, psOffsetStruct->ui32Mapped));
- eError = PVRSRV_ERROR_GENERIC;
- goto exit_unlock;
- }
- else
- {
-
- PVR_DPF((PVR_DBG_WARNING, "%s: psOffsetStruct 0x%p was never mapped", __FUNCTION__, psOffsetStruct));
- }
-
- PVR_ASSERT((psOffsetStruct->ui32Mapped == 0) && psOffsetStruct->bOnMMapList);
-
- DestroyOffsetStruct(psOffsetStruct);
- }
-
- list_del(&psLinuxMemArea->sMMapItem);
-
- psLinuxMemArea->bMMapRegistered = IMG_FALSE;
-
- eError = PVRSRV_OK;
-
-exit_unlock:
- mutex_unlock(&g_sMMapMutex);
- return eError;
-}
-
-
-PVRSRV_ERROR
-LinuxMMapPerProcessConnect(PVRSRV_ENV_PER_PROCESS_DATA *psEnvPerProc)
-{
- PVR_UNREFERENCED_PARAMETER(psEnvPerProc);
-
- return PVRSRV_OK;
-}
-
-IMG_VOID
-LinuxMMapPerProcessDisconnect(PVRSRV_ENV_PER_PROCESS_DATA *psEnvPerProc)
-{
- PKV_OFFSET_STRUCT psOffsetStruct, psTmpOffsetStruct;
- IMG_BOOL bWarn = IMG_FALSE;
- IMG_UINT32 ui32PID = OSGetCurrentProcessIDKM();
-
- PVR_UNREFERENCED_PARAMETER(psEnvPerProc);
-
- mutex_lock(&g_sMMapMutex);
-
- list_for_each_entry_safe(psOffsetStruct, psTmpOffsetStruct, &g_sMMapOffsetStructList, sMMapItem)
- {
- if (psOffsetStruct->ui32PID == ui32PID)
- {
- if (!bWarn)
- {
- PVR_DPF((PVR_DBG_WARNING, "%s: process has unmapped offset structures. Removing them", __FUNCTION__));
- bWarn = IMG_TRUE;
- }
- PVR_ASSERT(psOffsetStruct->ui32Mapped == 0);
- PVR_ASSERT(psOffsetStruct->bOnMMapList);
-
- DestroyOffsetStruct(psOffsetStruct);
- }
- }
-
- mutex_unlock(&g_sMMapMutex);
-}
-
-
-PVRSRV_ERROR LinuxMMapPerProcessHandleOptions(PVRSRV_HANDLE_BASE *psHandleBase)
-{
- PVRSRV_ERROR eError;
-
- eError = PVRSRVSetMaxHandle(psHandleBase, MAX_MMAP_HANDLE);
- if (eError != PVRSRV_OK)
- {
- PVR_DPF((PVR_DBG_ERROR,"%s: failed to set handle limit (%d)", __FUNCTION__, eError));
- return eError;
- }
-
- return eError;
-}
-
-
-IMG_VOID
-PVRMMapInit(IMG_VOID)
-{
- mutex_init(&g_sMMapMutex);
-
- g_psMemmapCache = kmem_cache_create("img-mmap", sizeof(KV_OFFSET_STRUCT), 0, 0, NULL);
- if (!g_psMemmapCache)
- {
- PVR_DPF((PVR_DBG_ERROR,"%s: failed to allocate kmem_cache", __FUNCTION__));
- goto error;
- }
-
- return;
-
-error:
- PVRMMapCleanup();
- return;
-}
-
-
-IMG_VOID
-PVRMMapCleanup(IMG_VOID)
-{
- PVRSRV_ERROR eError;
-
- if (!list_empty(&g_sMMapAreaList))
- {
- LinuxMemArea *psLinuxMemArea, *psTmpMemArea;
-
- PVR_DPF((PVR_DBG_ERROR, "%s: Memory areas are still registered with MMap", __FUNCTION__));
-
- PVR_TRACE(("%s: Unregistering memory areas", __FUNCTION__));
- list_for_each_entry_safe(psLinuxMemArea, psTmpMemArea, &g_sMMapAreaList, sMMapItem)
- {
- eError = PVRMMapRemoveRegisteredArea(psLinuxMemArea);
- if (eError != PVRSRV_OK)
- {
- PVR_DPF((PVR_DBG_ERROR, "%s: PVRMMapRemoveRegisteredArea failed (%d)", __FUNCTION__, eError));
- }
- PVR_ASSERT(eError == PVRSRV_OK);
-
- LinuxMemAreaDeepFree(psLinuxMemArea);
- }
- }
- PVR_ASSERT(list_empty((&g_sMMapAreaList)));
-
- if(g_psMemmapCache)
- {
- kmem_cache_destroy(g_psMemmapCache);
- g_psMemmapCache = NULL;
- }
-}
+++ /dev/null
-/**********************************************************************
- *
- * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful but, except
- * as otherwise stated in writing, 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.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK
- *
- ******************************************************************************/
-
-#if !defined(__MMAP_H__)
-#define __MMAP_H__
-
-#include <linux/mm.h>
-#include <linux/list.h>
-
-#include "perproc.h"
-#include "mm.h"
-
-typedef struct KV_OFFSET_STRUCT_TAG
-{
-
- IMG_UINT32 ui32Mapped;
-
-
- IMG_UINT32 ui32MMapOffset;
-
- IMG_UINT32 ui32RealByteSize;
-
-
- LinuxMemArea *psLinuxMemArea;
-
-
- IMG_UINT32 ui32TID;
-
-
- IMG_UINT32 ui32PID;
-
-
- IMG_BOOL bOnMMapList;
-
-
- IMG_UINT32 ui32RefCount;
-
-
- IMG_UINT32 ui32UserVAddr;
-
-
- struct list_head sMMapItem;
-
-
- struct list_head sAreaItem;
-}KV_OFFSET_STRUCT, *PKV_OFFSET_STRUCT;
-
-
-
-IMG_VOID PVRMMapInit(IMG_VOID);
-
-
-IMG_VOID PVRMMapCleanup(IMG_VOID);
-
-
-PVRSRV_ERROR PVRMMapRegisterArea(LinuxMemArea *psLinuxMemArea);
-
-
-PVRSRV_ERROR PVRMMapRemoveRegisteredArea(LinuxMemArea *psLinuxMemArea);
-
-
-PVRSRV_ERROR PVRMMapOSMemHandleToMMapData(PVRSRV_PER_PROCESS_DATA *psPerProc,
- IMG_HANDLE hMHandle,
- IMG_UINT32 *pui32MMapOffset,
- IMG_UINT32 *pui32ByteOffset,
- IMG_UINT32 *pui32RealByteSize, IMG_UINT32 *pui32UserVAddr);
-
-PVRSRV_ERROR
-PVRMMapReleaseMMapData(PVRSRV_PER_PROCESS_DATA *psPerProc,
- IMG_HANDLE hMHandle,
- IMG_BOOL *pbMUnmap,
- IMG_UINT32 *pui32RealByteSize,
- IMG_UINT32 *pui32UserVAddr);
-
-int PVRMMap(struct file* pFile, struct vm_area_struct* ps_vma);
-
-
-#endif
-
+++ /dev/null
-/**********************************************************************
- *
- * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful but, except
- * as otherwise stated in writing, 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.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK
- *
- ******************************************************************************/
-
-#if !defined(SUPPORT_DRI_DRM)
-
- #if defined(LDM_PLATFORM)
- #define PVR_LDM_PLATFORM_MODULE
- #define PVR_LDM_MODULE
- #else
- #if defined(LDM_PCI)
- #define PVR_LDM_PCI_MODULE
- #define PVR_LDM_MODULE
- #endif
- #endif
-#endif
-
-#include <linux/init.h>
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/version.h>
-#include <linux/fs.h>
-#include <linux/proc_fs.h>
-#include <linux/mutex.h>
-
-#if defined(SUPPORT_DRI_DRM)
-#include <drm/drmP.h>
-#if defined(PVR_SECURE_DRM_AUTH_EXPORT)
-#include "env_perproc.h"
-#endif
-#endif
-
-#if defined(PVR_LDM_PLATFORM_MODULE)
-#include <linux/platform_device.h>
-#endif
-
-#if defined(PVR_LDM_PCI_MODULE)
-#include <linux/pci.h>
-#endif
-
-#if defined(PVR_DEBUG_EXT) && defined(PVR_MANUAL_POWER_CONTROL)
-#include <asm/uaccess.h>
-#endif
-
-#include "img_defs.h"
-#include "services.h"
-#include "kerneldisplay.h"
-#include "kernelbuffer.h"
-#include "syscommon.h"
-#include "pvrmmap.h"
-#include "mutils.h"
-#include "mm.h"
-#include "mmap.h"
-#include "pvr_debug.h"
-#include "srvkm.h"
-#include "perproc.h"
-#include "handle.h"
-#include "pvr_bridge_km.h"
-#include "proc.h"
-#include "pvrmodule.h"
-#include "private_data.h"
-#include "lock.h"
-#include "linkage.h"
-
-#if defined(SUPPORT_DRI_DRM)
-#include "pvr_drm.h"
-#endif
-#define DRVNAME "pvrsrvkm"
-#define DEVNAME "pvrsrvkm"
-
-#if defined(SUPPORT_DRI_DRM)
-#define PRIVATE_DATA(pFile) ((pFile)->driver_priv)
-#else
-#define PRIVATE_DATA(pFile) ((pFile)->private_data)
-#endif
-
-MODULE_SUPPORTED_DEVICE(DEVNAME);
-#ifdef PVR_DEBUG_EXT
-static IMG_INT debug = DBGPRIV_WARNING;
-#include <linux/moduleparam.h>
-module_param(debug, int, 0);
-#endif
-
-
-extern IMG_BOOL PVRGetDisplayClassJTable(PVRSRV_DC_DISP2SRV_KMJTABLE *psJTable);
-extern IMG_BOOL PVRGetBufferClassJTable(PVRSRV_BC_BUFFER2SRV_KMJTABLE *psJTable);
-
-/*EXPORT_SYMBOL(PVRGetDisplayClassJTable); */
-/*EXPORT_SYMBOL(PVRGetBufferClassJTable); */
-
-
-#if defined(PVR_LDM_MODULE)
-static struct class *psPvrClass;
-#endif
-
-#if !defined(SUPPORT_DRI_DRM)
-static IMG_INT AssignedMajorNumber;
-
-static IMG_INT PVRSRVOpen(struct inode* pInode, struct file* pFile);
-static IMG_INT PVRSRVRelease(struct inode* pInode, struct file* pFile);
-
-static struct file_operations pvrsrv_fops = {
- .owner=THIS_MODULE,
- .unlocked_ioctl=PVRSRV_BridgeDispatchKM,
- .open=PVRSRVOpen,
- .release=PVRSRVRelease,
- .mmap=PVRMMap,
-};
-#endif
-
-struct mutex gPVRSRVLock;
-
-IMG_UINT32 gui32ReleasePID;
-
-#if defined(PVR_DEBUG_EXT) && defined(PVR_MANUAL_POWER_CONTROL)
-static IMG_UINT32 gPVRPowerLevel;
-#endif
-
-#if defined(PVR_LDM_MODULE)
-
-#if defined(PVR_LDM_PLATFORM_MODULE)
-#define LDM_DEV struct platform_device
-#define LDM_DRV struct platform_driver
-#endif
-
-#if defined(PVR_LDM_PCI_MODULE)
-#define LDM_DEV struct pci_dev
-#define LDM_DRV struct pci_driver
-#endif
-
-#if defined(PVR_LDM_PLATFORM_MODULE)
-static IMG_INT PVRSRVDriverRemove(LDM_DEV *device);
-static IMG_INT PVRSRVDriverProbe(LDM_DEV *device);
-#endif
-#if defined(PVR_LDM_PCI_MODULE)
-static IMG_VOID PVRSRVDriverRemove(LDM_DEV *device);
-static IMG_INT PVRSRVDriverProbe(LDM_DEV *device, const struct pci_device_id *id);
-#endif
-static IMG_INT PVRSRVDriverSuspend(LDM_DEV *device, pm_message_t state);
-static IMG_VOID PVRSRVDriverShutdown(LDM_DEV *device);
-static IMG_INT PVRSRVDriverResume(LDM_DEV *device);
-
-#if defined(PVR_LDM_PCI_MODULE)
-struct pci_device_id powervr_id_table[] __devinitdata = {
- { PCI_DEVICE(SYS_SGX_DEV_VENDOR_ID, SYS_SGX_DEV_DEVICE_ID) },
- { 0 }
-};
-
-MODULE_DEVICE_TABLE(pci, powervr_id_table);
-#endif
-
-static LDM_DRV powervr_driver = {
-#if defined(PVR_LDM_PLATFORM_MODULE)
- .driver = {
- .name = DRVNAME,
- },
-#endif
-#if defined(PVR_LDM_PCI_MODULE)
- .name = DRVNAME,
- .id_table = powervr_id_table,
-#endif
- .probe = PVRSRVDriverProbe,
-#if defined(PVR_LDM_PLATFORM_MODULE)
- .remove = PVRSRVDriverRemove,
-#endif
-#if defined(PVR_LDM_PCI_MODULE)
- .remove = __devexit_p(PVRSRVDriverRemove),
-#endif
- .suspend = PVRSRVDriverSuspend,
- .resume = PVRSRVDriverResume,
- .shutdown = PVRSRVDriverShutdown,
-};
-
-LDM_DEV *gpsPVRLDMDev;
-
-#if defined(MODULE) && defined(PVR_LDM_PLATFORM_MODULE)
-
-static IMG_VOID PVRSRVDeviceRelease(struct device *pDevice)
-{
- PVR_UNREFERENCED_PARAMETER(pDevice);
-}
-
-static struct platform_device powervr_device = {
- .name = DEVNAME,
- .id = -1,
- .dev = {
- .release = PVRSRVDeviceRelease
- }
-};
-
-#endif
-
-#if defined(PVR_LDM_PLATFORM_MODULE)
-static IMG_INT PVRSRVDriverProbe(LDM_DEV *pDevice)
-#endif
-#if defined(PVR_LDM_PCI_MODULE)
-static IMG_INT __devinit PVRSRVDriverProbe(LDM_DEV *pDevice, const struct pci_device_id *id)
-#endif
-{
- SYS_DATA *psSysData;
-
- PVR_TRACE(("PVRSRVDriverProbe(pDevice=%p)", pDevice));
-
-#if 0
-
- if (PerDeviceSysInitialise((IMG_PVOID)pDevice) != PVRSRV_OK)
- {
- return -EINVAL;
- }
-#endif
-
- if (SysAcquireData(&psSysData) != PVRSRV_OK)
- {
- gpsPVRLDMDev = pDevice;
-
- if (SysInitialise() != PVRSRV_OK)
- {
- return -ENODEV;
- }
- }
-
- return 0;
-}
-
-
-#if defined (PVR_LDM_PLATFORM_MODULE)
-static IMG_INT PVRSRVDriverRemove(LDM_DEV *pDevice)
-#endif
-#if defined(PVR_LDM_PCI_MODULE)
-static IMG_VOID __devexit PVRSRVDriverRemove(LDM_DEV *pDevice)
-#endif
-{
- SYS_DATA *psSysData;
-
- PVR_TRACE(("PVRSRVDriverRemove(pDevice=%p)", pDevice));
-
- if (SysAcquireData(&psSysData) == PVRSRV_OK)
- {
-#if defined(PVR_DEBUG_EXT) && defined(PVR_MANUAL_POWER_CONTROL)
- if (gPVRPowerLevel != 0)
- {
- if (PVRSRVSetPowerStateKM(PVRSRV_SYS_POWER_STATE_D0) == PVRSRV_OK)
- {
- gPVRPowerLevel = 0;
- }
- }
-#endif
- SysDeinitialise(psSysData);
-
- gpsPVRLDMDev = IMG_NULL;
- }
-
-#if 0
- if (PerDeviceSysDeInitialise((IMG_PVOID)pDevice) != PVRSRV_OK)
- {
- return -EINVAL;
- }
-#endif
-
-#if defined (PVR_LDM_PLATFORM_MODULE)
- return 0;
-#endif
-#if defined (PVR_LDM_PCI_MODULE)
- return;
-#endif
-}
-
-
-static IMG_VOID PVRSRVDriverShutdown(LDM_DEV *pDevice)
-{
- PVR_TRACE(("PVRSRVDriverShutdown(pDevice=%p)", pDevice));
-
- (IMG_VOID) PVRSRVSetPowerStateKM(PVRSRV_SYS_POWER_STATE_D3);
-}
-
-#endif
-
-
-#if defined(PVR_LDM_MODULE) || defined(SUPPORT_DRI_DRM)
-#if defined(SUPPORT_DRI_DRM)
-IMG_INT PVRSRVDriverSuspend(struct drm_device *pDevice, pm_message_t state)
-#else
-static IMG_INT PVRSRVDriverSuspend(LDM_DEV *pDevice, pm_message_t state)
-#endif
-{
-#if !(defined(PVR_DEBUG_EXT) && defined(PVR_MANUAL_POWER_CONTROL) && !defined(SUPPORT_DRI_DRM))
- PVR_TRACE(( "PVRSRVDriverSuspend(pDevice=%p)", pDevice));
- printk(KERN_ALERT "PVRSRVDriverSuspend(pDevice=%p)", pDevice);
-
- if (PVRSRVSetPowerStateKM(PVRSRV_SYS_POWER_STATE_D3) != PVRSRV_OK)
- {
- return -EINVAL;
- }
-#endif
- return 0;
-}
-
-
-#if defined(SUPPORT_DRI_DRM)
-IMG_INT PVRSRVDriverResume(struct drm_device *pDevice)
-#else
-static IMG_INT PVRSRVDriverResume(LDM_DEV *pDevice)
-#endif
-{
-#if !(defined(PVR_DEBUG_EXT) && defined(PVR_MANUAL_POWER_CONTROL) && !defined(SUPPORT_DRI_DRM))
- PVR_TRACE(("PVRSRVDriverResume(pDevice=%p)", pDevice));
- printk(KERN_ALERT "PVRSRVDriverResume(pDevice=%p)", pDevice);
-
- if (PVRSRVSetPowerStateKM(PVRSRV_SYS_POWER_STATE_D0) != PVRSRV_OK)
- {
- return -EINVAL;
- }
-#endif
- return 0;
-}
-#endif
-
-
-#if defined(PVR_DEBUG_EXT) && defined(PVR_MANUAL_POWER_CONTROL) && !defined(SUPPORT_DRI_DRM)
-IMG_INT PVRProcSetPowerLevel(struct file *file, const IMG_CHAR *buffer, IMG_UINT32 count, IMG_VOID *data)
-{
- IMG_CHAR data_buffer[2];
- IMG_UINT32 PVRPowerLevel;
-
- if (count != sizeof(data_buffer))
- {
- return -EINVAL;
- }
- else
- {
- if (copy_from_user(data_buffer, buffer, count))
- return -EINVAL;
- if (data_buffer[count - 1] != '\n')
- return -EINVAL;
- PVRPowerLevel = data_buffer[0] - '0';
- if (PVRPowerLevel != gPVRPowerLevel)
- {
- if (PVRPowerLevel != 0)
- {
- if (PVRSRVSetPowerStateKM(PVRSRV_SYS_POWER_STATE_D3) != PVRSRV_OK)
- {
- return -EINVAL;
- }
- }
- else
- {
- if (PVRSRVSetPowerStateKM(PVRSRV_SYS_POWER_STATE_D0) != PVRSRV_OK)
- {
- return -EINVAL;
- }
- }
-
- gPVRPowerLevel = PVRPowerLevel;
- }
- }
- return (count);
-}
-
-#ifdef PVR_PROC_USE_SEQ_FILE
-void ProcSeqShowPowerLevel(struct seq_file *sfile,void* el)
-{
- seq_printf(sfile, "%lu\n", gPVRPowerLevel);
-}
-
-#else
-IMG_INT PVRProcGetPowerLevel(IMG_CHAR *page, IMG_CHAR **start, off_t off, IMG_INT count, IMG_INT *eof, IMG_VOID *data)
-{
- if (off == 0) {
- *start = (IMG_CHAR *)1;
- return printAppend(page, count, 0, "%lu\n", gPVRPowerLevel);
- }
- *eof = 1;
- return 0;
-}
-#endif
-
-#endif
-
-#if defined(SUPPORT_DRI_DRM)
-IMG_INT PVRSRVOpen(struct drm_device unref__ *dev, struct drm_file *pFile)
-#else
-static IMG_INT PVRSRVOpen(struct inode unref__ * pInode, struct file *pFile)
-#endif
-{
- PVRSRV_FILE_PRIVATE_DATA *psPrivateData;
- IMG_HANDLE hBlockAlloc;
- IMG_INT iRet = -ENOMEM;
- PVRSRV_ERROR eError;
- IMG_UINT32 ui32PID;
-#if defined(SUPPORT_DRI_DRM) && defined(PVR_SECURE_DRM_AUTH_EXPORT)
- PVRSRV_ENV_PER_PROCESS_DATA *psEnvPerProc;
-#endif
-
-#if defined(SUPPORT_DRI_DRM)
- PVR_UNREFERENCED_PARAMETER(dev);
-#else
- PVR_UNREFERENCED_PARAMETER(pInode);
-#endif
-
- mutex_lock(&gPVRSRVLock);
-
- ui32PID = OSGetCurrentProcessIDKM();
-
- if (PVRSRVProcessConnect(ui32PID) != PVRSRV_OK)
- goto err_unlock;
-
-#if defined(SUPPORT_DRI_DRM) && defined(PVR_SECURE_DRM_AUTH_EXPORT)
- psEnvPerProc = PVRSRVPerProcessPrivateData(ui32PID);
- if (psEnvPerProc == IMG_NULL)
- {
- PVR_DPF((PVR_DBG_ERROR, "%s: No per-process private data", __FUNCTION__));
- goto err_unlock;
- }
-#endif
-
- eError = OSAllocMem(PVRSRV_OS_NON_PAGEABLE_HEAP,
- sizeof(PVRSRV_FILE_PRIVATE_DATA),
- (IMG_PVOID *)&psPrivateData,
- &hBlockAlloc,
- "File Private Data");
-
- if(eError != PVRSRV_OK)
- goto err_unlock;
-
-#if defined(PVR_SECURE_FD_EXPORT)
- psPrivateData->hKernelMemInfo = NULL;
-#endif
-#if defined(SUPPORT_DRI_DRM) && defined(PVR_SECURE_DRM_AUTH_EXPORT)
- psPrivateData->psDRMFile = pFile;
-
- list_add_tail(&psPrivateData->sDRMAuthListItem, &psEnvPerProc->sDRMAuthListHead);
-#endif
- psPrivateData->ui32OpenPID = ui32PID;
- psPrivateData->hBlockAlloc = hBlockAlloc;
- PRIVATE_DATA(pFile) = psPrivateData;
- iRet = 0;
-err_unlock:
- mutex_unlock(&gPVRSRVLock);
- return iRet;
-}
-
-
-#if defined(SUPPORT_DRI_DRM)
-IMG_INT PVRSRVRelease(struct drm_device unref__ *dev, struct drm_file *pFile)
-#else
-static IMG_INT PVRSRVRelease(struct inode unref__ * pInode, struct file *pFile)
-#endif
-{
- PVRSRV_FILE_PRIVATE_DATA *psPrivateData;
-
-#if defined(SUPPORT_DRI_DRM)
- PVR_UNREFERENCED_PARAMETER(dev);
-#else
- PVR_UNREFERENCED_PARAMETER(pInode);
-#endif
-
- mutex_lock(&gPVRSRVLock);
-
- psPrivateData = PRIVATE_DATA(pFile);
-
-#if defined(SUPPORT_DRI_DRM) && defined(PVR_SECURE_DRM_AUTH_EXPORT)
- list_del(&psPrivateData->sDRMAuthListItem);
-#endif
-
-
- gui32ReleasePID = psPrivateData->ui32OpenPID;
- PVRSRVProcessDisconnect(psPrivateData->ui32OpenPID);
- gui32ReleasePID = 0;
-
- OSFreeMem(PVRSRV_OS_NON_PAGEABLE_HEAP,
- sizeof(PVRSRV_FILE_PRIVATE_DATA),
- psPrivateData, psPrivateData->hBlockAlloc);
- PRIVATE_DATA(pFile) = NULL;
-
- mutex_unlock(&gPVRSRVLock);
- return 0;
-}
-
-
-#if defined(SUPPORT_DRI_DRM)
-IMG_INT PVRCore_Init(IMG_VOID)
-#else
-static IMG_INT __init PVRCore_Init(IMG_VOID)
-#endif
-{
- IMG_INT error;
-#if !defined(PVR_LDM_MODULE)
- PVRSRV_ERROR eError;
-#else
- struct device *psDev;
-#endif
-
-#if !defined(SUPPORT_DRI_DRM)
-
- PVRDPFInit();
-#endif
- PVR_TRACE(("PVRCore_Init"));
-
- mutex_init(&gPVRSRVLock);
-
-#ifdef PVR_DEBUG_EXT
- PVRDebugSetLevel(debug);
-#endif
-
- if (CreateProcEntries ())
- {
- error = -ENOMEM;
- return error;
- }
-
- if (PVROSFuncInit() != PVRSRV_OK)
- {
- error = -ENOMEM;
- goto init_failed;
- }
-
- PVRLinuxMUtilsInit();
-
- if (linux_mm_init())
- {
- error = -ENOMEM;
- goto init_failed;
- }
-
- LinuxBridgeInit();
-
- PVRMMapInit();
-
-#if defined(PVR_LDM_MODULE)
-
-#if defined(PVR_LDM_PLATFORM_MODULE)
- if ((error = platform_driver_register(&powervr_driver)) != 0)
- {
- PVR_DPF((PVR_DBG_ERROR, "PVRCore_Init: unable to register platform driver (%d)", error));
-
- goto init_failed;
- }
-
-#if defined(MODULE)
- if ((error = platform_device_register(&powervr_device)) != 0)
- {
- platform_driver_unregister(&powervr_driver);
-
- PVR_DPF((PVR_DBG_ERROR, "PVRCore_Init: unable to register platform device (%d)", error));
-
- goto init_failed;
- }
-#endif
-#endif
-
-#if defined(PVR_LDM_PCI_MODULE)
- if ((error = pci_register_driver(&powervr_driver)) != 0)
- {
- PVR_DPF((PVR_DBG_ERROR, "PVRCore_Init: unable to register PCI driver (%d)", error));
-
- goto init_failed;
- }
-#endif
-
-#else
-
- if ((eError = SysInitialise()) != PVRSRV_OK)
- {
- error = -ENODEV;
-#if defined(TCF_REV) && (TCF_REV == 110)
- if(eError == PVRSRV_ERROR_NOT_SUPPORTED)
- {
- printk("\nAtlas wrapper (FPGA image) version mismatch");
- error = -ENODEV;
- }
-#endif
- goto init_failed;
- }
-#endif
-
-#if !defined(SUPPORT_DRI_DRM)
- AssignedMajorNumber = register_chrdev(0, DEVNAME, &pvrsrv_fops);
-
- if (AssignedMajorNumber <= 0)
- {
- PVR_DPF((PVR_DBG_ERROR, "PVRCore_Init: unable to get major number"));
-
- error = -EBUSY;
- goto sys_deinit;
- }
-
- PVR_TRACE(("PVRCore_Init: major device %d", AssignedMajorNumber));
-#endif
-
-#if defined(PVR_LDM_MODULE)
-
- psPvrClass = class_create(THIS_MODULE, "pvr");
-
- if (IS_ERR(psPvrClass))
- {
- PVR_DPF((PVR_DBG_ERROR, "PVRCore_Init: unable to create class (%ld)", PTR_ERR(psPvrClass)));
- error = -EBUSY;
- goto unregister_device;
- }
-
- psDev = device_create(psPvrClass, NULL, MKDEV(AssignedMajorNumber, 0), NULL, DEVNAME);
- if (IS_ERR(psDev))
- {
- PVR_DPF((PVR_DBG_ERROR, "PVRCore_Init: unable to create device (%ld)", PTR_ERR(psDev)));
- error = -EBUSY;
- goto destroy_class;
- }
-#endif
-
- return 0;
-
-#if defined(PVR_LDM_MODULE)
-destroy_class:
- class_destroy(psPvrClass);
-unregister_device:
- unregister_chrdev((IMG_UINT)AssignedMajorNumber, DRVNAME);
-#endif
-#if !defined(SUPPORT_DRI_DRM)
-sys_deinit:
-#endif
-#if defined(PVR_LDM_MODULE)
-#if defined(PVR_LDM_PCI_MODULE)
- pci_unregister_driver(&powervr_driver);
-#endif
-
-#if defined (PVR_LDM_PLATFORM_MODULE)
-#if defined (MODULE)
- platform_device_unregister(&powervr_device);
-#endif
- platform_driver_unregister(&powervr_driver);
-#endif
-
-#else
-
- {
- SYS_DATA *psSysData;
-
- SysAcquireData(&psSysData);
- if (psSysData != IMG_NULL)
- {
- SysDeinitialise(psSysData);
- }
- }
-#endif
-init_failed:
- PVRMMapCleanup();
- linux_mm_cleanup();
- LinuxBridgeDeInit();
- PVROSFuncDeInit();
- RemoveProcEntries();
-
- return error;
-
-}
-
-
-#if defined(SUPPORT_DRI_DRM)
-IMG_VOID PVRCore_Cleanup(IMG_VOID)
-#else
-static IMG_VOID __exit PVRCore_Cleanup(IMG_VOID)
-#endif
-{
- SYS_DATA *psSysData;
-
- PVR_TRACE(("PVRCore_Cleanup"));
-
- SysAcquireData(&psSysData);
-
-#if defined(PVR_LDM_MODULE)
- device_destroy(psPvrClass, MKDEV(AssignedMajorNumber, 0));
- class_destroy(psPvrClass);
-#endif
-
-#if !defined(SUPPORT_DRI_DRM)
- unregister_chrdev((IMG_UINT)AssignedMajorNumber, DRVNAME);
-#endif
-
-#if defined(PVR_LDM_MODULE)
-
-#if defined(PVR_LDM_PCI_MODULE)
- pci_unregister_driver(&powervr_driver);
-#endif
-
-#if defined (PVR_LDM_PLATFORM_MODULE)
-#if defined (MODULE)
- platform_device_unregister(&powervr_device);
-#endif
- platform_driver_unregister(&powervr_driver);
-#endif
-
-#else
-#if defined(PVR_DEBUG_EXT) && defined(PVR_MANUAL_POWER_CONTROL)
- if (gPVRPowerLevel != 0)
- {
- if (PVRSRVSetPowerStateKM(PVRSRV_SYS_POWER_STATE_D0) == PVRSRV_OK)
- {
- gPVRPowerLevel = 0;
- }
- }
-#endif
-
- SysDeinitialise(psSysData);
-#endif
-
- PVRMMapCleanup();
-
- linux_mm_cleanup();
-
- LinuxBridgeDeInit();
-
- PVROSFuncDeInit();
-
- RemoveProcEntries();
-
- PVR_TRACE(("PVRCore_Cleanup: unloading"));
-}
-
-#if !defined(SUPPORT_DRI_DRM)
-module_init(PVRCore_Init);
-module_exit(PVRCore_Cleanup);
-#endif
+++ /dev/null
-/**********************************************************************
- *
- * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful but, except
- * as otherwise stated in writing, 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.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK
- *
- ******************************************************************************/
-
-#include <linux/version.h>
-
-#include <linux/spinlock.h>
-#include <linux/mm.h>
-#include <asm/page.h>
-#include <asm/pgtable.h>
-
-#include "img_defs.h"
-#include "pvr_debug.h"
-#include "mutils.h"
-
-#if defined(SUPPORT_LINUX_X86_PAT)
-#define PAT_LINUX_X86_WC 1
-
-#define PAT_X86_ENTRY_BITS 8
-
-#define PAT_X86_BIT_PWT 1U
-#define PAT_X86_BIT_PCD 2U
-#define PAT_X86_BIT_PAT 4U
-#define PAT_X86_BIT_MASK (PAT_X86_BIT_PAT | PAT_X86_BIT_PCD | PAT_X86_BIT_PWT)
-
-static IMG_BOOL g_write_combining_available = IMG_FALSE;
-
-#define PROT_TO_PAT_INDEX(v, B) ((v & _PAGE_ ## B) ? PAT_X86_BIT_ ## B : 0)
-
-static inline IMG_UINT
-pvr_pat_index(pgprotval_t prot_val)
-{
- IMG_UINT ret = 0;
- pgprotval_t val = prot_val & _PAGE_CACHE_MASK;
-
- ret |= PROT_TO_PAT_INDEX(val, PAT);
- ret |= PROT_TO_PAT_INDEX(val, PCD);
- ret |= PROT_TO_PAT_INDEX(val, PWT);
-
- return ret;
-}
-
-static inline IMG_UINT
-pvr_pat_entry(u64 pat, IMG_UINT index)
-{
- return (IMG_UINT)(pat >> (index * PAT_X86_ENTRY_BITS)) & PAT_X86_BIT_MASK;
-}
-
-static IMG_VOID
-PVRLinuxX86PATProbe(IMG_VOID)
-{
-
- if (cpu_has_pat)
- {
- u64 pat;
- IMG_UINT pat_index;
- IMG_UINT pat_entry;
-
- PVR_TRACE(("%s: PAT available", __FUNCTION__));
-
- rdmsrl(MSR_IA32_CR_PAT, pat);
- PVR_TRACE(("%s: Top 32 bits of PAT: 0x%.8x", __FUNCTION__, (IMG_UINT)(pat >> 32)));
- PVR_TRACE(("%s: Bottom 32 bits of PAT: 0x%.8x", __FUNCTION__, (IMG_UINT)(pat)));
-
- pat_index = pvr_pat_index(_PAGE_CACHE_WC);
- PVR_TRACE(("%s: PAT index for write combining: %u", __FUNCTION__, pat_index));
-
- pat_entry = pvr_pat_entry(pat, pat_index);
- PVR_TRACE(("%s: PAT entry for write combining: 0x%.2x (should be 0x%.2x)", __FUNCTION__, pat_entry, PAT_LINUX_X86_WC));
-
-#if defined(SUPPORT_LINUX_X86_WRITECOMBINE)
- g_write_combining_available = (IMG_BOOL)(pat_entry == PAT_LINUX_X86_WC);
-#endif
- }
-#if defined(PVR_DEBUG_EXT)
-#if defined(SUPPORT_LINUX_X86_WRITECOMBINE)
- if (g_write_combining_available)
- {
- PVR_TRACE(("%s: Write combining available via PAT", __FUNCTION__));
- }
- else
- {
- PVR_TRACE(("%s: Write combining not available", __FUNCTION__));
- }
-#else
- PVR_TRACE(("%s: Write combining disabled in driver build", __FUNCTION__));
-#endif
-#endif
-}
-
-pgprot_t
-pvr_pgprot_writecombine(pgprot_t prot)
-{
-
-
- return (g_write_combining_available) ?
- __pgprot((pgprot_val(prot) & ~_PAGE_CACHE_MASK) | _PAGE_CACHE_WC) : pgprot_noncached(prot);
-}
-#endif
-
-IMG_VOID
-PVRLinuxMUtilsInit(IMG_VOID)
-{
-#if defined(SUPPORT_LINUX_X86_PAT)
- PVRLinuxX86PATProbe();
-#endif
-}
-
+++ /dev/null
-/**********************************************************************
- *
- * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful but, except
- * as otherwise stated in writing, 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.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK
- *
- ******************************************************************************/
-
-#ifndef __IMG_LINUX_MUTILS_H__
-#define __IMG_LINUX_MUTILS_H__
-
-#include <linux/version.h>
-
-#if !(defined(__i386__))
-#if defined(SUPPORT_LINUX_X86_PAT)
-#undef SUPPORT_LINUX_X86_PAT
-#endif
-#endif
-
-#if defined(SUPPORT_LINUX_X86_PAT)
- pgprot_t pvr_pgprot_writecombine(pgprot_t prot);
- #define PGPROT_WC(pv) pvr_pgprot_writecombine(pv)
-#else
- #if defined(__arm__) || defined(__sh__)
- #define PGPROT_WC(pv) pgprot_writecombine(pv)
- #else
- #if defined(__i386__)
- #define PGPROT_WC(pv) pgprot_noncached(pv)
- #else
- #define PGPROT_WC(pv) pgprot_noncached(pv)
- #error Unsupported architecture!
- #endif
- #endif
-#endif
-
-#define PGPROT_UC(pv) pgprot_noncached(pv)
-
-#if defined(__i386__)
- #define IOREMAP(pa, bytes) ioremap_cache(pa, bytes)
-#else
- #if defined(__arm__)
- #define IOREMAP(pa, bytes) ioremap_cached(pa, bytes)
- #else
- #define IOREMAP(pa, bytes) ioremap(pa, bytes)
- #endif
-#endif
-
-#if defined(SUPPORT_LINUX_X86_PAT)
- #if defined(SUPPORT_LINUX_X86_WRITECOMBINE)
- #define IOREMAP_WC(pa, bytes) ioremap_wc(pa, bytes)
- #else
- #define IOREMAP_WC(pa, bytes) ioremap_nocache(pa, bytes)
- #endif
-#else
- #if defined(__arm__)
- #define IOREMAP_WC(pa, bytes) ioremap_wc(pa, bytes)
- #else
- #define IOREMAP_WC(pa, bytes) ioremap_nocache(pa, bytes)
- #endif
-#endif
-
-#define IOREMAP_UC(pa, bytes) ioremap_nocache(pa, bytes)
-
-IMG_VOID PVRLinuxMUtilsInit(IMG_VOID);
-
-#endif
-
+++ /dev/null
-/**********************************************************************
- *
- * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful but, except
- * as otherwise stated in writing, 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.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK
- *
- ******************************************************************************/
-
-#include <linux/version.h>
-#include <asm/io.h>
-#include <asm/page.h>
-#include <asm/system.h>
-#if defined(SUPPORT_CPU_CACHED_BUFFERS)
-#include <asm/cacheflush.h>
-#endif
-#include <linux/mm.h>
-#include <linux/pagemap.h>
-#include <linux/hugetlb.h>
-#include <linux/slab.h>
-#include <linux/vmalloc.h>
-#include <linux/delay.h>
-#include <linux/pci.h>
-
-#include <linux/string.h>
-#include <linux/sched.h>
-#include <linux/interrupt.h>
-#include <asm/hardirq.h>
-#include <linux/timer.h>
-#include <linux/capability.h>
-#include <asm/uaccess.h>
-#include <linux/spinlock.h>
-#if defined(PVR_LINUX_MISR_USING_WORKQUEUE) || \
- defined(PVR_LINUX_MISR_USING_PRIVATE_WORKQUEUE) || \
- defined(PVR_LINUX_TIMERS_USING_WORKQUEUES) || \
- defined(PVR_LINUX_USING_WORKQUEUES)
-#include <linux/workqueue.h>
-#endif
-
-#include "img_types.h"
-#include "services_headers.h"
-#include "mm.h"
-#include "pvrmmap.h"
-#include "mmap.h"
-#include "env_data.h"
-#include "proc.h"
-#include "event.h"
-#include "linkage.h"
-
-#define EVENT_OBJECT_TIMEOUT_MS (100)
-
-#if defined(SUPPORT_CPU_CACHED_BUFFERS) || \
- defined(SUPPORT_CACHEFLUSH_ON_ALLOC)
-
-#if defined(__i386__)
-static void per_cpu_cache_flush(void *arg)
-{
- PVR_UNREFERENCED_PARAMETER(arg);
- wbinvd();
-}
-#endif
-
-#if !defined(SUPPORT_CPU_CACHED_BUFFERS)
-static
-#endif
-IMG_VOID OSFlushCPUCacheKM(IMG_VOID)
-{
-#if defined(__arm__)
- flush_cache_all();
-#elif defined(__i386__)
-
- on_each_cpu(per_cpu_cache_flush, NULL, 1);
-#else
-#error "Implement full CPU cache flush for this CPU!"
-#endif
-}
-
-#endif
-#if defined(SUPPORT_CPU_CACHED_BUFFERS)
-
-IMG_VOID OSFlushCPUCacheRangeKM(IMG_VOID *pvRangeAddrStart,
- IMG_VOID *pvRangeAddrEnd)
-{
- PVR_UNREFERENCED_PARAMETER(pvRangeAddrStart);
- PVR_UNREFERENCED_PARAMETER(pvRangeAddrEnd);
-
-
- OSFlushCPUCacheKM();
-}
-
-#endif
-
-#define HOST_ALLOC_MEM_USING_KMALLOC ((IMG_HANDLE)0)
-#define HOST_ALLOC_MEM_USING_VMALLOC ((IMG_HANDLE)1)
-
-PVRSRV_ERROR OSAllocMem_Impl(IMG_UINT32 ui32Flags, IMG_UINT32 ui32Size, IMG_PVOID *ppvCpuVAddr, IMG_HANDLE *phBlockAlloc)
-{
- PVR_UNREFERENCED_PARAMETER(ui32Flags);
-
- *ppvCpuVAddr = kmalloc(ui32Size, GFP_KERNEL);
-
- if(*ppvCpuVAddr)
- {
- if (phBlockAlloc)
- {
-
- *phBlockAlloc = HOST_ALLOC_MEM_USING_KMALLOC;
- }
- }
- else
- {
- if (!phBlockAlloc)
- {
- return PVRSRV_ERROR_OUT_OF_MEMORY;
- }
-
-
- *ppvCpuVAddr = vmalloc_wrapper(ui32Size, PVRSRV_HAP_CACHED);
- if (!*ppvCpuVAddr)
- {
- return PVRSRV_ERROR_OUT_OF_MEMORY;
- }
-
-
- *phBlockAlloc = HOST_ALLOC_MEM_USING_VMALLOC;
- }
-
- return PVRSRV_OK;
-}
-
-
-PVRSRV_ERROR OSFreeMem_Impl(IMG_UINT32 ui32Flags, IMG_UINT32 ui32Size, IMG_PVOID pvCpuVAddr, IMG_HANDLE hBlockAlloc)
-{
- PVR_UNREFERENCED_PARAMETER(ui32Flags);
- PVR_UNREFERENCED_PARAMETER(ui32Size);
-
- if (hBlockAlloc == HOST_ALLOC_MEM_USING_VMALLOC)
- {
- vfree(pvCpuVAddr);
- }
- else
- {
- kfree(pvCpuVAddr);
- }
-
- return PVRSRV_OK;
-}
-
-
-PVRSRV_ERROR
-OSAllocPages_Impl(IMG_UINT32 ui32AllocFlags,
- IMG_UINT32 ui32Size,
- IMG_UINT32 ui32PageSize,
- IMG_VOID **ppvCpuVAddr,
- IMG_HANDLE *phOSMemHandle)
-{
- LinuxMemArea *psLinuxMemArea;
-
- PVR_UNREFERENCED_PARAMETER(ui32PageSize);
-
-#if 0
-
- if(ui32AllocFlags & PVRSRV_HAP_SINGLE_PROCESS)
- {
- ui32AllocFlags &= ~PVRSRV_HAP_SINGLE_PROCESS;
- ui32AllocFlags |= PVRSRV_HAP_MULTI_PROCESS;
- }
-#endif
-
- switch(ui32AllocFlags & PVRSRV_HAP_MAPTYPE_MASK)
- {
- case PVRSRV_HAP_KERNEL_ONLY:
- {
- psLinuxMemArea = vmalloc_linux_mem_area(ui32Size, ui32AllocFlags);
- if(!psLinuxMemArea)
- {
- return PVRSRV_ERROR_OUT_OF_MEMORY;
- }
- break;
- }
- case PVRSRV_HAP_SINGLE_PROCESS:
- {
-
-
- psLinuxMemArea = alloc_pages_linux_mem_area(ui32Size, ui32AllocFlags);
- if(!psLinuxMemArea)
- {
- return PVRSRV_ERROR_OUT_OF_MEMORY;
- }
- PVRMMapRegisterArea(psLinuxMemArea);
- break;
- }
-
- case PVRSRV_HAP_MULTI_PROCESS:
- {
-
-#if defined(VIVT_CACHE) || defined(__sh__)
-
- ui32AllocFlags &= ~PVRSRV_HAP_CACHED;
-#endif
- psLinuxMemArea = vmalloc_linux_mem_area(ui32Size, ui32AllocFlags);
- if(!psLinuxMemArea)
- {
- return PVRSRV_ERROR_OUT_OF_MEMORY;
- }
- PVRMMapRegisterArea(psLinuxMemArea);
- break;
- }
- default:
- PVR_DPF((PVR_DBG_ERROR, "OSAllocPages: invalid flags 0x%x\n", ui32AllocFlags));
- *ppvCpuVAddr = NULL;
- *phOSMemHandle = (IMG_HANDLE)0;
- return PVRSRV_ERROR_INVALID_PARAMS;
- }
-
-#if defined(SUPPORT_CACHEFLUSH_ON_ALLOC)
-
- if(ui32AllocFlags & (PVRSRV_HAP_WRITECOMBINE | PVRSRV_HAP_UNCACHED))
- {
- OSFlushCPUCacheKM();
- }
-#endif
-
- *ppvCpuVAddr = LinuxMemAreaToCpuVAddr(psLinuxMemArea);
- *phOSMemHandle = psLinuxMemArea;
-
- return PVRSRV_OK;
-}
-
-
-PVRSRV_ERROR
-OSFreePages(IMG_UINT32 ui32AllocFlags, IMG_UINT32 ui32Bytes, IMG_VOID *pvCpuVAddr, IMG_HANDLE hOSMemHandle)
-{
- LinuxMemArea *psLinuxMemArea;
- PVR_UNREFERENCED_PARAMETER(ui32Bytes);
- PVR_UNREFERENCED_PARAMETER(pvCpuVAddr);
-
- psLinuxMemArea = (LinuxMemArea *)hOSMemHandle;
-
- switch(ui32AllocFlags & PVRSRV_HAP_MAPTYPE_MASK)
- {
- case PVRSRV_HAP_KERNEL_ONLY:
- break;
- case PVRSRV_HAP_SINGLE_PROCESS:
- case PVRSRV_HAP_MULTI_PROCESS:
- if(PVRMMapRemoveRegisteredArea(psLinuxMemArea) != PVRSRV_OK)
- {
- PVR_DPF((PVR_DBG_ERROR,
- "OSFreePages(ui32AllocFlags=0x%08X, ui32Bytes=%ld, "
- "pvCpuVAddr=%p, hOSMemHandle=%p) FAILED!",
- ui32AllocFlags, ui32Bytes, pvCpuVAddr, hOSMemHandle));
- return PVRSRV_ERROR_GENERIC;
- }
- break;
- default:
- PVR_DPF((PVR_DBG_ERROR,"%s: invalid flags 0x%x\n",
- __FUNCTION__, ui32AllocFlags));
- return PVRSRV_ERROR_INVALID_PARAMS;
- }
-
- LinuxMemAreaDeepFree(psLinuxMemArea);
-
- return PVRSRV_OK;
-}
-
-
-PVRSRV_ERROR
-OSGetSubMemHandle(IMG_HANDLE hOSMemHandle,
- IMG_UINT32 ui32ByteOffset,
- IMG_UINT32 ui32Bytes,
- IMG_UINT32 ui32Flags,
- IMG_HANDLE *phOSMemHandleRet)
-{
- LinuxMemArea *psParentLinuxMemArea, *psLinuxMemArea;
- PVRSRV_ERROR eError;
-
- psParentLinuxMemArea = (LinuxMemArea *)hOSMemHandle;
-
- psLinuxMemArea = NewSubLinuxMemArea(psParentLinuxMemArea, ui32ByteOffset, ui32Bytes);
- if(!psLinuxMemArea)
- {
- *phOSMemHandleRet = NULL;
- return PVRSRV_ERROR_OUT_OF_MEMORY;
- }
- *phOSMemHandleRet = psLinuxMemArea;
-
-
- if(ui32Flags & PVRSRV_HAP_KERNEL_ONLY)
- {
- return PVRSRV_OK;
- }
-
- eError = PVRMMapRegisterArea(psLinuxMemArea);
- if(eError != PVRSRV_OK)
- {
- goto failed_register_area;
- }
-
- return PVRSRV_OK;
-
-failed_register_area:
- *phOSMemHandleRet = NULL;
- LinuxMemAreaDeepFree(psLinuxMemArea);
- return eError;
-}
-
-PVRSRV_ERROR
-OSReleaseSubMemHandle(IMG_VOID *hOSMemHandle, IMG_UINT32 ui32Flags)
-{
- LinuxMemArea *psLinuxMemArea;
- PVRSRV_ERROR eError;
-
- psLinuxMemArea = (LinuxMemArea *)hOSMemHandle;
- PVR_ASSERT(psLinuxMemArea->eAreaType == LINUX_MEM_AREA_SUB_ALLOC);
-
- if((ui32Flags & PVRSRV_HAP_KERNEL_ONLY) == 0)
- {
- eError = PVRMMapRemoveRegisteredArea(psLinuxMemArea);
- if(eError != PVRSRV_OK)
- {
- return eError;
- }
- }
- LinuxMemAreaDeepFree(psLinuxMemArea);
-
- return PVRSRV_OK;
-}
-
-
-IMG_CPU_PHYADDR
-OSMemHandleToCpuPAddr(IMG_VOID *hOSMemHandle, IMG_UINT32 ui32ByteOffset)
-{
- IMG_CPU_PHYADDR cpu_addr;
- BUG_ON(!hOSMemHandle);
-
- memset(&cpu_addr, 0, sizeof(cpu_addr));
-
- cpu_addr.uiAddr = LinuxMemAreaToCpuPAddr(hOSMemHandle, ui32ByteOffset);
-
- return cpu_addr;
-}
-
-
-
-IMG_VOID OSMemCopy(IMG_VOID *pvDst, IMG_VOID *pvSrc, IMG_UINT32 ui32Size)
-{
-#if defined(USE_UNOPTIMISED_MEMCPY)
- IMG_UINT8 *Src,*Dst;
- IMG_INT i;
-
- Src=(IMG_UINT8 *)pvSrc;
- Dst=(IMG_UINT8 *)pvDst;
- for(i=0;i<ui32Size;i++)
- {
- Dst[i]=Src[i];
- }
-#else
- memcpy(pvDst, pvSrc, ui32Size);
-#endif
-}
-
-
-IMG_VOID OSMemSet(IMG_VOID *pvDest, IMG_UINT8 ui8Value, IMG_UINT32 ui32Size)
-{
-#if defined(USE_UNOPTIMISED_MEMSET)
- IMG_UINT8 *Buff;
- IMG_INT i;
-
- Buff=(IMG_UINT8 *)pvDest;
- for(i=0;i<ui32Size;i++)
- {
- Buff[i]=ui8Value;
- }
-#else
- memset(pvDest, (IMG_INT) ui8Value, (size_t) ui32Size);
-#endif
-}
-
-
-IMG_CHAR *OSStringCopy(IMG_CHAR *pszDest, const IMG_CHAR *pszSrc)
-{
- return (strcpy(pszDest, pszSrc));
-}
-
-IMG_INT32 OSSNPrintf(IMG_CHAR *pStr, IMG_UINT32 ui32Size, const IMG_CHAR *pszFormat, ...)
-{
- va_list argList;
- IMG_INT32 iCount;
-
- va_start(argList, pszFormat);
- iCount = vsnprintf(pStr, (size_t)ui32Size, pszFormat, argList);
- va_end(argList);
-
- return iCount;
-}
-
-IMG_VOID OSBreakResourceLock (PVRSRV_RESOURCE *psResource, IMG_UINT32 ui32ID)
-{
- volatile IMG_UINT32 *pui32Access = (volatile IMG_UINT32 *)&psResource->ui32Lock;
-
- if(*pui32Access)
- {
- if(psResource->ui32ID == ui32ID)
- {
- psResource->ui32ID = 0;
- *pui32Access = 0;
- }
- else
- {
- PVR_DPF((PVR_DBG_MESSAGE,"OSBreakResourceLock: Resource is not locked for this process."));
- }
- }
- else
- {
- PVR_DPF((PVR_DBG_MESSAGE,"OSBreakResourceLock: Resource is not locked"));
- }
-}
-
-
-PVRSRV_ERROR OSCreateResource(PVRSRV_RESOURCE *psResource)
-{
- psResource->ui32ID = 0;
- psResource->ui32Lock = 0;
-
- return PVRSRV_OK;
-}
-
-
-PVRSRV_ERROR OSDestroyResource (PVRSRV_RESOURCE *psResource)
-{
- OSBreakResourceLock (psResource, psResource->ui32ID);
-
- return PVRSRV_OK;
-}
-
-
-PVRSRV_ERROR OSInitEnvData(IMG_PVOID *ppvEnvSpecificData)
-{
- ENV_DATA *psEnvData;
-
-
- if(OSAllocMem(PVRSRV_OS_PAGEABLE_HEAP, sizeof(ENV_DATA), (IMG_VOID **)&psEnvData, IMG_NULL,
- "Environment Data") != PVRSRV_OK)
- {
- return PVRSRV_ERROR_GENERIC;
- }
-
- if(OSAllocMem(PVRSRV_OS_PAGEABLE_HEAP, PVRSRV_MAX_BRIDGE_IN_SIZE + PVRSRV_MAX_BRIDGE_OUT_SIZE,
- &psEnvData->pvBridgeData, IMG_NULL,
- "Bridge Data") != PVRSRV_OK)
- {
- OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP, sizeof(ENV_DATA), psEnvData, IMG_NULL);
-
- return PVRSRV_ERROR_GENERIC;
- }
-
-
-
- psEnvData->bMISRInstalled = IMG_FALSE;
- psEnvData->bLISRInstalled = IMG_FALSE;
-
-
- *ppvEnvSpecificData = psEnvData;
-
- return PVRSRV_OK;
-}
-
-
-PVRSRV_ERROR OSDeInitEnvData(IMG_PVOID pvEnvSpecificData)
-{
- ENV_DATA *psEnvData = (ENV_DATA*)pvEnvSpecificData;
-
- PVR_ASSERT(!psEnvData->bMISRInstalled);
- PVR_ASSERT(!psEnvData->bLISRInstalled);
-
- OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP, PVRSRV_MAX_BRIDGE_IN_SIZE + PVRSRV_MAX_BRIDGE_OUT_SIZE, psEnvData->pvBridgeData, IMG_NULL);
- psEnvData->pvBridgeData = IMG_NULL;
-
- OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP, sizeof(ENV_DATA), pvEnvSpecificData, IMG_NULL);
-
-
- return PVRSRV_OK;
-}
-
-
-
-IMG_VOID OSReleaseThreadQuanta(IMG_VOID)
-{
- schedule();
-}
-
-
-
-IMG_UINT32 OSClockus(IMG_VOID)
-{
- IMG_UINT32 time, j = jiffies;
-
- time = j * (1000000 / HZ);
-
- return time;
-}
-
-
-
-IMG_VOID OSWaitus(IMG_UINT32 ui32Timeus)
-{
- udelay(ui32Timeus);
-}
-
-
-IMG_UINT32 OSGetCurrentProcessIDKM(IMG_VOID)
-{
- if (in_interrupt())
- {
- return KERNEL_ID;
- }
-
- return (IMG_UINT32)task_tgid_nr(current);
-}
-
-
-IMG_UINT32 OSGetPageSize(IMG_VOID)
-{
-#if defined(__sh__)
- IMG_UINT32 ui32ReturnValue = PAGE_SIZE;
-
- return (ui32ReturnValue);
-#else
- return PAGE_SIZE;
-#endif
-}
-
-static irqreturn_t DeviceISRWrapper(int irq, void *dev_id
- )
-{
- PVRSRV_DEVICE_NODE *psDeviceNode;
- IMG_BOOL bStatus = IMG_FALSE;
-
- PVR_UNREFERENCED_PARAMETER(irq);
-
- psDeviceNode = (PVRSRV_DEVICE_NODE*)dev_id;
- if(!psDeviceNode)
- {
- PVR_DPF((PVR_DBG_ERROR, "DeviceISRWrapper: invalid params\n"));
- goto out;
- }
-
- bStatus = PVRSRVDeviceLISR(psDeviceNode);
-
- if (bStatus)
- {
- OSScheduleMISR((IMG_VOID *)psDeviceNode->psSysData);
- }
-
-out:
- return bStatus ? IRQ_HANDLED : IRQ_NONE;
-}
-
-
-
-static irqreturn_t SystemISRWrapper(int irq, void *dev_id)
-{
- SYS_DATA *psSysData;
- IMG_BOOL bStatus = IMG_FALSE;
-
- PVR_UNREFERENCED_PARAMETER(irq);
-
- psSysData = (SYS_DATA *)dev_id;
- if(!psSysData)
- {
- PVR_DPF((PVR_DBG_ERROR, "SystemISRWrapper: invalid params\n"));
- goto out;
- }
-
- bStatus = PVRSRVSystemLISR(psSysData);
-
- if (bStatus)
- {
- OSScheduleMISR((IMG_VOID *)psSysData);
- }
-
-out:
- return bStatus ? IRQ_HANDLED : IRQ_NONE;
-}
-PVRSRV_ERROR OSInstallDeviceLISR(IMG_VOID *pvSysData,
- IMG_UINT32 ui32Irq,
- IMG_CHAR *pszISRName,
- IMG_VOID *pvDeviceNode)
-{
- SYS_DATA *psSysData = (SYS_DATA*)pvSysData;
- ENV_DATA *psEnvData = (ENV_DATA *)psSysData->pvEnvSpecificData;
-
- if (psEnvData->bLISRInstalled)
- {
- PVR_DPF((PVR_DBG_ERROR, "OSInstallDeviceLISR: An ISR has already been installed: IRQ %d cookie %x", psEnvData->ui32IRQ, psEnvData->pvISRCookie));
- return PVRSRV_ERROR_GENERIC;
- }
-
- PVR_TRACE(("Installing device LISR %s on IRQ %d with cookie %x", pszISRName, ui32Irq, pvDeviceNode));
-
- if(request_irq(ui32Irq, DeviceISRWrapper, IRQF_SHARED, pszISRName, pvDeviceNode))
- {
- PVR_DPF((PVR_DBG_ERROR,"OSInstallDeviceLISR: Couldn't install device LISR on IRQ %d", ui32Irq));
-
- return PVRSRV_ERROR_GENERIC;
- }
-
- psEnvData->ui32IRQ = ui32Irq;
- psEnvData->pvISRCookie = pvDeviceNode;
- psEnvData->bLISRInstalled = IMG_TRUE;
-
- return PVRSRV_OK;
-}
-
-PVRSRV_ERROR OSUninstallDeviceLISR(IMG_VOID *pvSysData)
-{
- SYS_DATA *psSysData = (SYS_DATA*)pvSysData;
- ENV_DATA *psEnvData = (ENV_DATA *)psSysData->pvEnvSpecificData;
-
- if (!psEnvData->bLISRInstalled)
- {
- PVR_DPF((PVR_DBG_ERROR, "OSUninstallDeviceLISR: No LISR has been installed"));
- return PVRSRV_ERROR_GENERIC;
- }
-
- PVR_TRACE(("Uninstalling device LISR on IRQ %d with cookie %x", psEnvData->ui32IRQ, psEnvData->pvISRCookie));
-
- free_irq(psEnvData->ui32IRQ, psEnvData->pvISRCookie);
-
- psEnvData->bLISRInstalled = IMG_FALSE;
-
- return PVRSRV_OK;
-}
-
-
-PVRSRV_ERROR OSInstallSystemLISR(IMG_VOID *pvSysData, IMG_UINT32 ui32Irq)
-{
- SYS_DATA *psSysData = (SYS_DATA*)pvSysData;
- ENV_DATA *psEnvData = (ENV_DATA *)psSysData->pvEnvSpecificData;
-
- if (psEnvData->bLISRInstalled)
- {
- PVR_DPF((PVR_DBG_ERROR, "OSInstallSystemLISR: An LISR has already been installed: IRQ %d cookie %x", psEnvData->ui32IRQ, psEnvData->pvISRCookie));
- return PVRSRV_ERROR_GENERIC;
- }
-
- PVR_TRACE(("Installing system LISR on IRQ %d with cookie %x", ui32Irq, pvSysData));
-
- if(request_irq(ui32Irq, SystemISRWrapper, IRQF_SHARED, "PowerVR", pvSysData))
- {
- PVR_DPF((PVR_DBG_ERROR,"OSInstallSystemLISR: Couldn't install system LISR on IRQ %d", ui32Irq));
-
- return PVRSRV_ERROR_GENERIC;
- }
-
- psEnvData->ui32IRQ = ui32Irq;
- psEnvData->pvISRCookie = pvSysData;
- psEnvData->bLISRInstalled = IMG_TRUE;
-
- return PVRSRV_OK;
-}
-
-
-PVRSRV_ERROR OSUninstallSystemLISR(IMG_VOID *pvSysData)
-{
- SYS_DATA *psSysData = (SYS_DATA*)pvSysData;
- ENV_DATA *psEnvData = (ENV_DATA *)psSysData->pvEnvSpecificData;
-
- if (!psEnvData->bLISRInstalled)
- {
- PVR_DPF((PVR_DBG_ERROR, "OSUninstallSystemLISR: No LISR has been installed"));
- return PVRSRV_ERROR_GENERIC;
- }
-
- PVR_TRACE(("Uninstalling system LISR on IRQ %d with cookie %x", psEnvData->ui32IRQ, psEnvData->pvISRCookie));
-
- free_irq(psEnvData->ui32IRQ, psEnvData->pvISRCookie);
-
- psEnvData->bLISRInstalled = IMG_FALSE;
-
- return PVRSRV_OK;
-}
-
-#if defined(PVR_LINUX_MISR_USING_PRIVATE_WORKQUEUE)
-static void MISRWrapper(struct work_struct *data)
-{
- ENV_DATA *psEnvData = container_of(data, ENV_DATA, sMISRWork);
- SYS_DATA *psSysData = (SYS_DATA *)psEnvData->pvMISRData;
-
- PVRSRVMISR(psSysData);
-}
-
-
-PVRSRV_ERROR OSInstallMISR(IMG_VOID *pvSysData)
-{
- SYS_DATA *psSysData = (SYS_DATA*)pvSysData;
- ENV_DATA *psEnvData = (ENV_DATA *)psSysData->pvEnvSpecificData;
-
- if (psEnvData->bMISRInstalled)
- {
- PVR_DPF((PVR_DBG_ERROR, "OSInstallMISR: An MISR has already been installed"));
- return PVRSRV_ERROR_GENERIC;
- }
-
- PVR_TRACE(("Installing MISR with cookie %p", pvSysData));
-
- psEnvData->psWorkQueue = create_singlethread_workqueue("pvr_workqueue");
-
- if (psEnvData->psWorkQueue == IMG_NULL)
- {
- PVR_DPF((PVR_DBG_ERROR, "OSInstallMISR: create_singlethreaded_workqueue failed"));
- return PVRSRV_ERROR_GENERIC;
- }
-
- INIT_WORK(&psEnvData->sMISRWork, MISRWrapper);
-
- psEnvData->pvMISRData = pvSysData;
- psEnvData->bMISRInstalled = IMG_TRUE;
-
- return PVRSRV_OK;
-}
-
-
-PVRSRV_ERROR OSUninstallMISR(IMG_VOID *pvSysData)
-{
- SYS_DATA *psSysData = (SYS_DATA*)pvSysData;
- ENV_DATA *psEnvData = (ENV_DATA *)psSysData->pvEnvSpecificData;
-
- if (!psEnvData->bMISRInstalled)
- {
- PVR_DPF((PVR_DBG_ERROR, "OSUninstallMISR: No MISR has been installed"));
- return PVRSRV_ERROR_GENERIC;
- }
-
- PVR_TRACE(("Uninstalling MISR"));
-
- destroy_workqueue(psEnvData->psWorkQueue);
-
- psEnvData->bMISRInstalled = IMG_FALSE;
-
- return PVRSRV_OK;
-}
-
-
-PVRSRV_ERROR OSScheduleMISR(IMG_VOID *pvSysData)
-{
- SYS_DATA *psSysData = (SYS_DATA*)pvSysData;
- ENV_DATA *psEnvData = (ENV_DATA*)psSysData->pvEnvSpecificData;
-
- if (psEnvData->bMISRInstalled)
- {
- queue_work(psEnvData->psWorkQueue, &psEnvData->sMISRWork);
- }
-
- return PVRSRV_OK;
-}
-#else
-#if defined(PVR_LINUX_MISR_USING_WORKQUEUE)
-static void MISRWrapper(struct work_struct *data)
-{
- ENV_DATA *psEnvData = container_of(data, ENV_DATA, sMISRWork);
- SYS_DATA *psSysData = (SYS_DATA *)psEnvData->pvMISRData;
-
- PVRSRVMISR(psSysData);
-}
-
-
-PVRSRV_ERROR OSInstallMISR(IMG_VOID *pvSysData)
-{
- SYS_DATA *psSysData = (SYS_DATA*)pvSysData;
- ENV_DATA *psEnvData = (ENV_DATA *)psSysData->pvEnvSpecificData;
-
- if (psEnvData->bMISRInstalled)
- {
- PVR_DPF((PVR_DBG_ERROR, "OSInstallMISR: An MISR has already been installed"));
- return PVRSRV_ERROR_GENERIC;
- }
-
- PVR_TRACE(("Installing MISR with cookie %x", pvSysData));
-
- INIT_WORK(&psEnvData->sMISRWork, MISRWrapper);
-
- psEnvData->pvMISRData = pvSysData;
- psEnvData->bMISRInstalled = IMG_TRUE;
-
- return PVRSRV_OK;
-}
-
-
-PVRSRV_ERROR OSUninstallMISR(IMG_VOID *pvSysData)
-{
- SYS_DATA *psSysData = (SYS_DATA*)pvSysData;
- ENV_DATA *psEnvData = (ENV_DATA *)psSysData->pvEnvSpecificData;
-
- if (!psEnvData->bMISRInstalled)
- {
- PVR_DPF((PVR_DBG_ERROR, "OSUninstallMISR: No MISR has been installed"));
- return PVRSRV_ERROR_GENERIC;
- }
-
- PVR_TRACE(("Uninstalling MISR"));
-
- flush_scheduled_work();
-
- psEnvData->bMISRInstalled = IMG_FALSE;
-
- return PVRSRV_OK;
-}
-
-
-PVRSRV_ERROR OSScheduleMISR(IMG_VOID *pvSysData)
-{
- SYS_DATA *psSysData = (SYS_DATA*)pvSysData;
- ENV_DATA *psEnvData = (ENV_DATA*)psSysData->pvEnvSpecificData;
-
- if (psEnvData->bMISRInstalled)
- {
- schedule_work(&psEnvData->sMISRWork);
- }
-
- return PVRSRV_OK;
-}
-
-#else
-
-
-static void MISRWrapper(unsigned long data)
-{
- SYS_DATA *psSysData;
-
- psSysData = (SYS_DATA *)data;
-
- PVRSRVMISR(psSysData);
-}
-
-
-PVRSRV_ERROR OSInstallMISR(IMG_VOID *pvSysData)
-{
- SYS_DATA *psSysData = (SYS_DATA*)pvSysData;
- ENV_DATA *psEnvData = (ENV_DATA *)psSysData->pvEnvSpecificData;
-
- if (psEnvData->bMISRInstalled)
- {
- PVR_DPF((PVR_DBG_ERROR, "OSInstallMISR: An MISR has already been installed"));
- return PVRSRV_ERROR_GENERIC;
- }
-
- PVR_TRACE(("Installing MISR with cookie %x", pvSysData));
-
- tasklet_init(&psEnvData->sMISRTasklet, MISRWrapper, (unsigned long)pvSysData);
-
- psEnvData->bMISRInstalled = IMG_TRUE;
-
- return PVRSRV_OK;
-}
-
-
-PVRSRV_ERROR OSUninstallMISR(IMG_VOID *pvSysData)
-{
- SYS_DATA *psSysData = (SYS_DATA*)pvSysData;
- ENV_DATA *psEnvData = (ENV_DATA *)psSysData->pvEnvSpecificData;
-
- if (!psEnvData->bMISRInstalled)
- {
- PVR_DPF((PVR_DBG_ERROR, "OSUninstallMISR: No MISR has been installed"));
- return PVRSRV_ERROR_GENERIC;
- }
-
- PVR_TRACE(("Uninstalling MISR"));
-
- tasklet_kill(&psEnvData->sMISRTasklet);
-
- psEnvData->bMISRInstalled = IMG_FALSE;
-
- return PVRSRV_OK;
-}
-
-PVRSRV_ERROR OSScheduleMISR(IMG_VOID *pvSysData)
-{
- SYS_DATA *psSysData = (SYS_DATA*)pvSysData;
- ENV_DATA *psEnvData = (ENV_DATA*)psSysData->pvEnvSpecificData;
-
- if (psEnvData->bMISRInstalled)
- {
- tasklet_schedule(&psEnvData->sMISRTasklet);
- }
-
- return PVRSRV_OK;
-}
-
-#endif
-#endif
-
-
-IMG_VOID OSPanic(IMG_VOID)
-{
- BUG();
-}
-
-#define OS_TAS(p) xchg((p), 1)
-PVRSRV_ERROR OSLockResource ( PVRSRV_RESOURCE *psResource,
- IMG_UINT32 ui32ID)
-
-{
- PVRSRV_ERROR eError = PVRSRV_OK;
-
- if(!OS_TAS(&psResource->ui32Lock))
- psResource->ui32ID = ui32ID;
- else
- eError = PVRSRV_ERROR_GENERIC;
-
- return eError;
-}
-
-
-PVRSRV_ERROR OSUnlockResource (PVRSRV_RESOURCE *psResource, IMG_UINT32 ui32ID)
-{
- volatile IMG_UINT32 *pui32Access = (volatile IMG_UINT32 *)&psResource->ui32Lock;
- PVRSRV_ERROR eError = PVRSRV_OK;
-
- if(*pui32Access)
- {
- if(psResource->ui32ID == ui32ID)
- {
- psResource->ui32ID = 0;
- *pui32Access = 0;
- }
- else
- {
- PVR_DPF((PVR_DBG_ERROR,"OSUnlockResource: Resource %p is not locked with expected value.", psResource));
- PVR_DPF((PVR_DBG_MESSAGE,"Should be %x is actually %x", ui32ID, psResource->ui32ID));
- eError = PVRSRV_ERROR_GENERIC;
- }
- }
- else
- {
- PVR_DPF((PVR_DBG_ERROR,"OSUnlockResource: Resource %p is not locked", psResource));
- eError = PVRSRV_ERROR_GENERIC;
- }
-
- return eError;
-}
-
-
-IMG_BOOL OSIsResourceLocked (PVRSRV_RESOURCE *psResource, IMG_UINT32 ui32ID)
-{
- volatile IMG_UINT32 *pui32Access = (volatile IMG_UINT32 *)&psResource->ui32Lock;
-
- return (*(volatile IMG_UINT32 *)pui32Access == 1) && (psResource->ui32ID == ui32ID)
- ? IMG_TRUE
- : IMG_FALSE;
-}
-
-
-IMG_CPU_PHYADDR OSMapLinToCPUPhys(IMG_VOID *pvLinAddr)
-{
- IMG_CPU_PHYADDR CpuPAddr;
-
- CpuPAddr.uiAddr = (IMG_UINTPTR_T)VMallocToPhys(pvLinAddr);
-
- return CpuPAddr;
-}
-
-
-IMG_VOID *
-OSMapPhysToLin(IMG_CPU_PHYADDR BasePAddr,
- IMG_UINT32 ui32Bytes,
- IMG_UINT32 ui32MappingFlags,
- IMG_HANDLE *phOSMemHandle)
-{
- if(phOSMemHandle)
- {
- *phOSMemHandle = (IMG_HANDLE)0;
- }
-
- if(ui32MappingFlags & PVRSRV_HAP_KERNEL_ONLY)
- {
- IMG_VOID *pvIORemapCookie;
- pvIORemapCookie = ioremap_wrapper(BasePAddr.uiAddr, ui32Bytes, ui32MappingFlags);
- if(pvIORemapCookie == IMG_NULL)
- {
- return NULL;
- }
- return pvIORemapCookie;
- }
- else
- {
- PVR_DPF((PVR_DBG_ERROR,
- "OSMapPhysToLin should only be used with PVRSRV_HAP_KERNEL_ONLY "
- " (Use OSReservePhys otherwise)"));
- return NULL;
- }
-}
-
-IMG_BOOL
-OSUnMapPhysToLin(IMG_VOID *pvLinAddr, IMG_UINT32 ui32Bytes, IMG_UINT32 ui32MappingFlags, IMG_HANDLE hPageAlloc)
-{
- PVR_TRACE(("%s: unmapping %d bytes from 0x%08x", __FUNCTION__, ui32Bytes, pvLinAddr));
-
- PVR_UNREFERENCED_PARAMETER(hPageAlloc);
- PVR_UNREFERENCED_PARAMETER(ui32Bytes);
-
- if(ui32MappingFlags & PVRSRV_HAP_KERNEL_ONLY)
- {
- iounmap(pvLinAddr);
- return IMG_TRUE;
- }
- else
- {
- PVR_DPF((PVR_DBG_ERROR,
- "OSUnMapPhysToLin should only be used with PVRSRV_HAP_KERNEL_ONLY "
- " (Use OSUnReservePhys otherwise)"));
- return IMG_FALSE;
- }
-}
-
-static PVRSRV_ERROR
-RegisterExternalMem(IMG_SYS_PHYADDR *pBasePAddr,
- IMG_VOID *pvCPUVAddr,
- IMG_UINT32 ui32Bytes,
- IMG_BOOL bPhysContig,
- IMG_UINT32 ui32MappingFlags,
- IMG_HANDLE *phOSMemHandle)
-{
- LinuxMemArea *psLinuxMemArea;
-
- switch(ui32MappingFlags & PVRSRV_HAP_MAPTYPE_MASK)
- {
- case PVRSRV_HAP_KERNEL_ONLY:
- {
- psLinuxMemArea = NewExternalKVLinuxMemArea(pBasePAddr, pvCPUVAddr, ui32Bytes, bPhysContig, ui32MappingFlags);
-
- if(!psLinuxMemArea)
- {
- return PVRSRV_ERROR_GENERIC;
- }
- break;
- }
- case PVRSRV_HAP_SINGLE_PROCESS:
- {
- psLinuxMemArea = NewExternalKVLinuxMemArea(pBasePAddr, pvCPUVAddr, ui32Bytes, bPhysContig, ui32MappingFlags);
-
- if(!psLinuxMemArea)
- {
- return PVRSRV_ERROR_GENERIC;
- }
- PVRMMapRegisterArea(psLinuxMemArea);
- break;
- }
- case PVRSRV_HAP_MULTI_PROCESS:
- {
-
-#if defined(VIVT_CACHE) || defined(__sh__)
-
- ui32MappingFlags &= ~PVRSRV_HAP_CACHED;
-#endif
- psLinuxMemArea = NewExternalKVLinuxMemArea(pBasePAddr, pvCPUVAddr, ui32Bytes, bPhysContig, ui32MappingFlags);
-
- if(!psLinuxMemArea)
- {
- return PVRSRV_ERROR_GENERIC;
- }
- PVRMMapRegisterArea(psLinuxMemArea);
- break;
- }
- default:
- PVR_DPF((PVR_DBG_ERROR,"OSRegisterMem : invalid flags 0x%x\n", ui32MappingFlags));
- *phOSMemHandle = (IMG_HANDLE)0;
- return PVRSRV_ERROR_GENERIC;
- }
-
- *phOSMemHandle = (IMG_HANDLE)psLinuxMemArea;
-
- return PVRSRV_OK;
-}
-
-
-PVRSRV_ERROR
-OSRegisterMem(IMG_CPU_PHYADDR BasePAddr,
- IMG_VOID *pvCPUVAddr,
- IMG_UINT32 ui32Bytes,
- IMG_UINT32 ui32MappingFlags,
- IMG_HANDLE *phOSMemHandle)
-{
- IMG_SYS_PHYADDR SysPAddr = SysCpuPAddrToSysPAddr(BasePAddr);
-
- return RegisterExternalMem(&SysPAddr, pvCPUVAddr, ui32Bytes, IMG_TRUE, ui32MappingFlags, phOSMemHandle);
-}
-
-
-PVRSRV_ERROR OSRegisterDiscontigMem(IMG_SYS_PHYADDR *pBasePAddr, IMG_VOID *pvCPUVAddr, IMG_UINT32 ui32Bytes, IMG_UINT32 ui32MappingFlags, IMG_HANDLE *phOSMemHandle)
-{
- return RegisterExternalMem(pBasePAddr, pvCPUVAddr, ui32Bytes, IMG_FALSE, ui32MappingFlags, phOSMemHandle);
-}
-
-
-PVRSRV_ERROR
-OSUnRegisterMem (IMG_VOID *pvCpuVAddr,
- IMG_UINT32 ui32Bytes,
- IMG_UINT32 ui32MappingFlags,
- IMG_HANDLE hOSMemHandle)
-{
- LinuxMemArea *psLinuxMemArea = (LinuxMemArea *)hOSMemHandle;
-
- PVR_UNREFERENCED_PARAMETER(pvCpuVAddr);
- PVR_UNREFERENCED_PARAMETER(ui32Bytes);
-
- switch(ui32MappingFlags & PVRSRV_HAP_MAPTYPE_MASK)
- {
- case PVRSRV_HAP_KERNEL_ONLY:
- break;
- case PVRSRV_HAP_SINGLE_PROCESS:
- case PVRSRV_HAP_MULTI_PROCESS:
- {
- if(PVRMMapRemoveRegisteredArea(psLinuxMemArea) != PVRSRV_OK)
- {
- PVR_DPF((PVR_DBG_ERROR, "%s(%p, %d, 0x%08X, %p) FAILED!",
- __FUNCTION__, pvCpuVAddr, ui32Bytes,
- ui32MappingFlags, hOSMemHandle));
- return PVRSRV_ERROR_GENERIC;
- }
- break;
- }
- default:
- {
- PVR_DPF((PVR_DBG_ERROR, "OSUnRegisterMem : invalid flags 0x%x", ui32MappingFlags));
- return PVRSRV_ERROR_INVALID_PARAMS;
- }
- }
-
- LinuxMemAreaDeepFree(psLinuxMemArea);
-
- return PVRSRV_OK;
-}
-
-PVRSRV_ERROR OSUnRegisterDiscontigMem(IMG_VOID *pvCpuVAddr, IMG_UINT32 ui32Bytes, IMG_UINT32 ui32Flags, IMG_HANDLE hOSMemHandle)
-{
- return OSUnRegisterMem(pvCpuVAddr, ui32Bytes, ui32Flags, hOSMemHandle);
-}
-
-PVRSRV_ERROR
-OSReservePhys(IMG_CPU_PHYADDR BasePAddr,
- IMG_UINT32 ui32Bytes,
- IMG_UINT32 ui32MappingFlags,
- IMG_VOID **ppvCpuVAddr,
- IMG_HANDLE *phOSMemHandle)
-{
- LinuxMemArea *psLinuxMemArea;
-
-#if 0
-
- if(ui32MappingFlags & PVRSRV_HAP_SINGLE_PROCESS)
- {
- ui32MappingFlags &= ~PVRSRV_HAP_SINGLE_PROCESS;
- ui32MappingFlags |= PVRSRV_HAP_MULTI_PROCESS;
- }
-#endif
-
- switch(ui32MappingFlags & PVRSRV_HAP_MAPTYPE_MASK)
- {
- case PVRSRV_HAP_KERNEL_ONLY:
- {
-
- psLinuxMemArea = ioremap_linux_mem_area(BasePAddr.uiAddr, ui32Bytes, ui32MappingFlags);
- if(!psLinuxMemArea)
- {
- return PVRSRV_ERROR_GENERIC;
- }
- break;
- }
- case PVRSRV_HAP_SINGLE_PROCESS:
- {
-
- psLinuxMemArea = NewIOLinuxMemArea(BasePAddr.uiAddr, ui32Bytes, ui32MappingFlags);
- if(!psLinuxMemArea)
- {
- return PVRSRV_ERROR_GENERIC;
- }
- PVRMMapRegisterArea(psLinuxMemArea);
- break;
- }
- case PVRSRV_HAP_MULTI_PROCESS:
- {
-
-#if defined(VIVT_CACHE) || defined(__sh__)
-
- ui32MappingFlags &= ~PVRSRV_HAP_CACHED;
-#endif
- psLinuxMemArea = ioremap_linux_mem_area(BasePAddr.uiAddr, ui32Bytes, ui32MappingFlags);
- if(!psLinuxMemArea)
- {
- return PVRSRV_ERROR_GENERIC;
- }
- PVRMMapRegisterArea(psLinuxMemArea);
- break;
- }
- default:
- PVR_DPF((PVR_DBG_ERROR,"OSMapPhysToLin : invalid flags 0x%x\n", ui32MappingFlags));
- *ppvCpuVAddr = NULL;
- *phOSMemHandle = (IMG_HANDLE)0;
- return PVRSRV_ERROR_GENERIC;
- }
-
- *phOSMemHandle = (IMG_HANDLE)psLinuxMemArea;
- *ppvCpuVAddr = LinuxMemAreaToCpuVAddr(psLinuxMemArea);
-
- return PVRSRV_OK;
-}
-
-PVRSRV_ERROR
-OSUnReservePhys(IMG_VOID *pvCpuVAddr,
- IMG_UINT32 ui32Bytes,
- IMG_UINT32 ui32MappingFlags,
- IMG_HANDLE hOSMemHandle)
-{
- LinuxMemArea *psLinuxMemArea;
-
- PVR_UNREFERENCED_PARAMETER(pvCpuVAddr);
- PVR_UNREFERENCED_PARAMETER(ui32Bytes);
-
- psLinuxMemArea = (LinuxMemArea *)hOSMemHandle;
-
- switch(ui32MappingFlags & PVRSRV_HAP_MAPTYPE_MASK)
- {
- case PVRSRV_HAP_KERNEL_ONLY:
- break;
- case PVRSRV_HAP_SINGLE_PROCESS:
- case PVRSRV_HAP_MULTI_PROCESS:
- {
- if(PVRMMapRemoveRegisteredArea(psLinuxMemArea) != PVRSRV_OK)
- {
- PVR_DPF((PVR_DBG_ERROR, "%s(%p, %d, 0x%08X, %p) FAILED!",
- __FUNCTION__, pvCpuVAddr, ui32Bytes,
- ui32MappingFlags, hOSMemHandle));
- return PVRSRV_ERROR_GENERIC;
- }
- break;
- }
- default:
- {
- PVR_DPF((PVR_DBG_ERROR, "OSUnMapPhysToLin : invalid flags 0x%x", ui32MappingFlags));
- return PVRSRV_ERROR_INVALID_PARAMS;
- }
- }
-
- LinuxMemAreaDeepFree(psLinuxMemArea);
-
- return PVRSRV_OK;
-}
-
-
-PVRSRV_ERROR OSBaseAllocContigMemory(IMG_UINT32 ui32Size, IMG_CPU_VIRTADDR *pvLinAddr, IMG_CPU_PHYADDR *psPhysAddr)
-{
-#if !defined(NO_HARDWARE)
- PVR_UNREFERENCED_PARAMETER(ui32Size);
- PVR_UNREFERENCED_PARAMETER(pvLinAddr);
- PVR_UNREFERENCED_PARAMETER(psPhysAddr);
- PVR_DPF((PVR_DBG_ERROR, "%s: Not available", __FUNCTION__));
-
- return PVRSRV_ERROR_OUT_OF_MEMORY;
-#else
- IMG_VOID *pvKernLinAddr;
-
- pvKernLinAddr = kmalloc(ui32Size, GFP_KERNEL);
-
- if (!pvKernLinAddr)
- {
- return PVRSRV_ERROR_OUT_OF_MEMORY;
- }
-
- *pvLinAddr = pvKernLinAddr;
-
- psPhysAddr->uiAddr = virt_to_phys(pvKernLinAddr);
-
- return PVRSRV_OK;
-#endif
-}
-
-
-PVRSRV_ERROR OSBaseFreeContigMemory(IMG_UINT32 ui32Size, IMG_CPU_VIRTADDR pvLinAddr, IMG_CPU_PHYADDR psPhysAddr)
-{
-#if !defined(NO_HARDWARE)
- PVR_UNREFERENCED_PARAMETER(ui32Size);
- PVR_UNREFERENCED_PARAMETER(pvLinAddr);
- PVR_UNREFERENCED_PARAMETER(psPhysAddr.uiAddr);
-
- PVR_DPF((PVR_DBG_WARNING, "%s: Not available", __FUNCTION__));
-#else
- PVR_UNREFERENCED_PARAMETER(ui32Size);
- PVR_UNREFERENCED_PARAMETER(psPhysAddr.uiAddr);
-
- kfree(pvLinAddr);
-#endif
- return PVRSRV_OK;
-}
-
-IMG_UINT32 OSReadHWReg(IMG_PVOID pvLinRegBaseAddr, IMG_UINT32 ui32Offset)
-{
-#if !defined(NO_HARDWARE)
- return (IMG_UINT32) readl((IMG_PBYTE)pvLinRegBaseAddr+ui32Offset);
-#else
- return *(IMG_UINT32 *)((IMG_PBYTE)pvLinRegBaseAddr+ui32Offset);
-#endif
-}
-
-IMG_VOID OSWriteHWReg(IMG_PVOID pvLinRegBaseAddr, IMG_UINT32 ui32Offset, IMG_UINT32 ui32Value)
-{
-#if !defined(NO_HARDWARE)
- writel(ui32Value, (IMG_PBYTE)pvLinRegBaseAddr+ui32Offset);
-#else
- *(IMG_UINT32 *)((IMG_PBYTE)pvLinRegBaseAddr+ui32Offset) = ui32Value;
-#endif
-}
-
-PVRSRV_PCI_DEV_HANDLE OSPCISetDev(IMG_VOID *pvPCICookie, HOST_PCI_INIT_FLAGS eFlags)
-{
- int err;
- IMG_UINT32 i;
- PVR_PCI_DEV *psPVRPCI;
-
- PVR_TRACE(("OSPCISetDev"));
-
- if(OSAllocMem(PVRSRV_OS_PAGEABLE_HEAP, sizeof(*psPVRPCI), (IMG_VOID **)&psPVRPCI, IMG_NULL,
- "PCI Device") != PVRSRV_OK)
- {
- PVR_DPF((PVR_DBG_ERROR, "OSPCISetDev: Couldn't allocate PVR PCI structure"));
- return IMG_NULL;
- }
-
- psPVRPCI->psPCIDev = (struct pci_dev *)pvPCICookie;
- psPVRPCI->ePCIFlags = eFlags;
-
- err = pci_enable_device(psPVRPCI->psPCIDev);
- if (err != 0)
- {
- PVR_DPF((PVR_DBG_ERROR, "OSPCISetDev: Couldn't enable device (%d)", err));
- return IMG_NULL;
- }
-
- if (psPVRPCI->ePCIFlags & HOST_PCI_INIT_FLAG_BUS_MASTER)
- {
- pci_set_master(psPVRPCI->psPCIDev);
- }
-
- if (psPVRPCI->ePCIFlags & HOST_PCI_INIT_FLAG_MSI)
- {
-#if defined(CONFIG_PCI_MSI)
- if (psPVRPCI->psPCIDev->device == PSB_SYS_SGX_DEV_DEVICE_ID_1 ||
- psPVRPCI->psPCIDev->device == PSB_SYS_SGX_DEV_DEVICE_ID_2) // Disable MSI for Menlow
- psPVRPCI->ePCIFlags &= ~HOST_PCI_INIT_FLAG_MSI;
- else if(!psPVRPCI->psPCIDev->msi_enabled)
- /* MSIs enabled at probe() time */
- psPVRPCI->ePCIFlags &= ~HOST_PCI_INIT_FLAG_MSI;
-#else
- PVR_DPF((PVR_DBG_WARNING, "OSPCISetDev: MSI support not enabled in the kernel"));
-#endif
- }
-
-
- for (i = 0; i < DEVICE_COUNT_RESOURCE; i++)
- {
- psPVRPCI->abPCIResourceInUse[i] = IMG_FALSE;
- }
-
- return (PVRSRV_PCI_DEV_HANDLE)psPVRPCI;
-}
-
-PVRSRV_PCI_DEV_HANDLE OSPCIAcquireDev(IMG_UINT16 ui16VendorID, IMG_UINT16 ui16DeviceID, HOST_PCI_INIT_FLAGS eFlags)
-{
- struct pci_dev *psPCIDev;
-
- psPCIDev = pci_get_device(ui16VendorID, ui16DeviceID, NULL);
- if (psPCIDev == NULL)
- {
- PVR_DPF((PVR_DBG_ERROR, "OSPCIAcquireDev: Couldn't acquire device"));
- return IMG_NULL;
- }
-
- return OSPCISetDev((IMG_VOID *)psPCIDev, eFlags);
-}
-
-PVRSRV_ERROR OSPCIIRQ(PVRSRV_PCI_DEV_HANDLE hPVRPCI, IMG_UINT32 *pui32IRQ)
-{
- PVR_PCI_DEV *psPVRPCI = (PVR_PCI_DEV *)hPVRPCI;
-
- *pui32IRQ = psPVRPCI->psPCIDev->irq;
-
- return PVRSRV_OK;
-}
-
-enum HOST_PCI_ADDR_RANGE_FUNC
-{
- HOST_PCI_ADDR_RANGE_FUNC_LEN,
- HOST_PCI_ADDR_RANGE_FUNC_START,
- HOST_PCI_ADDR_RANGE_FUNC_END,
- HOST_PCI_ADDR_RANGE_FUNC_REQUEST,
- HOST_PCI_ADDR_RANGE_FUNC_RELEASE
-};
-
-static IMG_UINT32 OSPCIAddrRangeFunc(enum HOST_PCI_ADDR_RANGE_FUNC eFunc,
- PVRSRV_PCI_DEV_HANDLE hPVRPCI,
- IMG_UINT32 ui32Index)
-{
- PVR_PCI_DEV *psPVRPCI = (PVR_PCI_DEV *)hPVRPCI;
-
- if (ui32Index >= DEVICE_COUNT_RESOURCE)
- {
- PVR_DPF((PVR_DBG_ERROR, "OSPCIAddrRangeFunc: Index out of range"));
- return 0;
-
- }
-
- switch (eFunc)
- {
- case HOST_PCI_ADDR_RANGE_FUNC_LEN:
- return pci_resource_len(psPVRPCI->psPCIDev, ui32Index);
- case HOST_PCI_ADDR_RANGE_FUNC_START:
- return pci_resource_start(psPVRPCI->psPCIDev, ui32Index);
- case HOST_PCI_ADDR_RANGE_FUNC_END:
- return pci_resource_end(psPVRPCI->psPCIDev, ui32Index);
- case HOST_PCI_ADDR_RANGE_FUNC_REQUEST:
- {
- int err;
-
- err = pci_request_region(psPVRPCI->psPCIDev, (IMG_INT)ui32Index, "PowerVR");
- if (err != 0)
- {
- PVR_DPF((PVR_DBG_ERROR, "OSPCIAddrRangeFunc: pci_request_region_failed (%d)", err));
- return 0;
- }
- psPVRPCI->abPCIResourceInUse[ui32Index] = IMG_TRUE;
- return 1;
- }
- case HOST_PCI_ADDR_RANGE_FUNC_RELEASE:
- if (psPVRPCI->abPCIResourceInUse[ui32Index])
- {
- pci_release_region(psPVRPCI->psPCIDev, (IMG_INT)ui32Index);
- psPVRPCI->abPCIResourceInUse[ui32Index] = IMG_FALSE;
- }
- return 1;
- default:
- PVR_DPF((PVR_DBG_ERROR, "OSPCIAddrRangeFunc: Unknown function"));
- break;
- }
-
- return 0;
-}
-
-IMG_UINT32 OSPCIAddrRangeLen(PVRSRV_PCI_DEV_HANDLE hPVRPCI, IMG_UINT32 ui32Index)
-{
- return OSPCIAddrRangeFunc(HOST_PCI_ADDR_RANGE_FUNC_LEN, hPVRPCI, ui32Index);
-}
-
-IMG_UINT32 OSPCIAddrRangeStart(PVRSRV_PCI_DEV_HANDLE hPVRPCI, IMG_UINT32 ui32Index)
-{
- return OSPCIAddrRangeFunc(HOST_PCI_ADDR_RANGE_FUNC_START, hPVRPCI, ui32Index);
-}
-
-IMG_UINT32 OSPCIAddrRangeEnd(PVRSRV_PCI_DEV_HANDLE hPVRPCI, IMG_UINT32 ui32Index)
-{
- return OSPCIAddrRangeFunc(HOST_PCI_ADDR_RANGE_FUNC_END, hPVRPCI, ui32Index);
-}
-
-PVRSRV_ERROR OSPCIRequestAddrRange(PVRSRV_PCI_DEV_HANDLE hPVRPCI,
- IMG_UINT32 ui32Index)
-{
- return OSPCIAddrRangeFunc(HOST_PCI_ADDR_RANGE_FUNC_REQUEST, hPVRPCI, ui32Index) == 0 ? PVRSRV_ERROR_GENERIC : PVRSRV_OK;
-}
-
-PVRSRV_ERROR OSPCIReleaseAddrRange(PVRSRV_PCI_DEV_HANDLE hPVRPCI, IMG_UINT32 ui32Index)
-{
- return OSPCIAddrRangeFunc(HOST_PCI_ADDR_RANGE_FUNC_RELEASE, hPVRPCI, ui32Index) == 0 ? PVRSRV_ERROR_GENERIC : PVRSRV_OK;
-}
-
-PVRSRV_ERROR OSPCIReleaseDev(PVRSRV_PCI_DEV_HANDLE hPVRPCI)
-{
- PVR_PCI_DEV *psPVRPCI = (PVR_PCI_DEV *)hPVRPCI;
- int i;
-
- PVR_TRACE(("OSPCIReleaseDev"));
-
-
- for (i = 0; i < DEVICE_COUNT_RESOURCE; i++)
- {
- if (psPVRPCI->abPCIResourceInUse[i])
- {
- PVR_TRACE(("OSPCIReleaseDev: Releasing Address range %d", i));
- pci_release_region(psPVRPCI->psPCIDev, i);
- psPVRPCI->abPCIResourceInUse[i] = IMG_FALSE;
- }
- }
-
-#if defined(CONFIG_PCI_MSI)
- if (psPVRPCI->ePCIFlags & HOST_PCI_INIT_FLAG_MSI)
- {
- pci_disable_msi(psPVRPCI->psPCIDev);
- }
-#endif
-
- if (psPVRPCI->ePCIFlags & HOST_PCI_INIT_FLAG_BUS_MASTER)
- {
- pci_clear_master(psPVRPCI->psPCIDev);
- }
- pci_disable_device(psPVRPCI->psPCIDev);
-
- OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP, sizeof(*psPVRPCI), (IMG_VOID *)psPVRPCI, IMG_NULL);
-
-
- return PVRSRV_OK;
-}
-
-PVRSRV_ERROR OSPCISuspendDev(PVRSRV_PCI_DEV_HANDLE hPVRPCI)
-{
- PVR_PCI_DEV *psPVRPCI = (PVR_PCI_DEV *)hPVRPCI;
- int i;
- int err;
-
- PVR_TRACE(("OSPCISuspendDev"));
-
-
- for (i = 0; i < DEVICE_COUNT_RESOURCE; i++)
- {
- if (psPVRPCI->abPCIResourceInUse[i])
- {
- pci_release_region(psPVRPCI->psPCIDev, i);
- }
- }
-
- err = pci_save_state(psPVRPCI->psPCIDev);
- if (err != 0)
- {
- PVR_DPF((PVR_DBG_ERROR, "OSPCISuspendDev: pci_save_state_failed (%d)", err));
- return PVRSRV_ERROR_GENERIC;
- }
-
- pci_disable_device(psPVRPCI->psPCIDev);
-
- err = pci_set_power_state(psPVRPCI->psPCIDev, PCI_D3hot);//pci_choose_state(psPVRPCI->psPCIDev, PMSG_SUSPEND));
- switch(err)
- {
- case 0:
- break;
- case -EIO:
- PVR_DPF((PVR_DBG_WARNING, "OSPCISuspendDev: device doesn't support PCI PM"));
- break;
- case -EINVAL:
- PVR_DPF((PVR_DBG_ERROR, "OSPCISuspendDev: can't enter requested power state"));
- break;
- default:
- PVR_DPF((PVR_DBG_ERROR, "OSPCISuspendDev: pci_set_power_state failed (%d)", err));
- break;
- }
-
- return PVRSRV_OK;
-}
-
-PVRSRV_ERROR OSPCIResumeDev(PVRSRV_PCI_DEV_HANDLE hPVRPCI)
-{
- PVR_PCI_DEV *psPVRPCI = (PVR_PCI_DEV *)hPVRPCI;
- int err;
- int i;
-
- PVR_TRACE(("OSPCIResumeDev"));
-
- err = pci_set_power_state(psPVRPCI->psPCIDev, PCI_D0);//pci_choose_state(psPVRPCI->psPCIDev, PMSG_ON));
- switch(err)
- {
- case 0:
- break;
- case -EIO:
- PVR_DPF((PVR_DBG_WARNING, "OSPCIResumeDev: device doesn't support PCI PM"));
- break;
- case -EINVAL:
- PVR_DPF((PVR_DBG_ERROR, "OSPCIResumeDev: can't enter requested power state"));
- return PVRSRV_ERROR_GENERIC;
- default:
- PVR_DPF((PVR_DBG_ERROR, "OSPCIResumeDev: pci_set_power_state failed (%d)", err));
- return PVRSRV_ERROR_GENERIC;
- }
-
- pci_restore_state(psPVRPCI->psPCIDev);
-
- err = pci_enable_device(psPVRPCI->psPCIDev);
- if (err != 0)
- {
- PVR_DPF((PVR_DBG_ERROR, "OSPCIResumeDev: Couldn't enable device (%d)", err));
- return PVRSRV_ERROR_GENERIC;
- }
-
- if (psPVRPCI->ePCIFlags & HOST_PCI_INIT_FLAG_BUS_MASTER)
- pci_set_master(psPVRPCI->psPCIDev);
-
-
- for (i = 0; i < DEVICE_COUNT_RESOURCE; i++)
- {
- if (psPVRPCI->abPCIResourceInUse[i])
- {
- err = pci_request_region(psPVRPCI->psPCIDev, i, "PowerVR");
- if (err != 0)
- {
- PVR_DPF((PVR_DBG_ERROR, "OSPCIResumeDev: pci_request_region_failed (region %d, error %d)", i, err));
- }
- }
-
- }
-
- return PVRSRV_OK;
-}
-
-#define OS_MAX_TIMERS 8
-
-typedef struct TIMER_CALLBACK_DATA_TAG
-{
- IMG_BOOL bInUse;
- PFN_TIMER_FUNC pfnTimerFunc;
- IMG_VOID *pvData;
- struct timer_list sTimer;
- IMG_UINT32 ui32Delay;
- IMG_BOOL bActive;
-#if defined(PVR_LINUX_TIMERS_USING_WORKQUEUES)
- struct work_struct sWork;
-#endif
-}TIMER_CALLBACK_DATA;
-
-#if defined(PVR_LINUX_TIMERS_USING_WORKQUEUES)
-static struct workqueue_struct *psTimerWorkQueue;
-#endif
-
-static TIMER_CALLBACK_DATA sTimers[OS_MAX_TIMERS];
-
-#if defined(PVR_LINUX_TIMERS_USING_WORKQUEUES)
-DEFINE_MUTEX(sTimerStructLock);
-#else
-static DEFINE_SPINLOCK(sTimerStructLock);
-#endif
-
-static void OSTimerCallbackBody(TIMER_CALLBACK_DATA *psTimerCBData)
-{
- if (!psTimerCBData->bActive)
- return;
-
-
- psTimerCBData->pfnTimerFunc(psTimerCBData->pvData);
-
-
- mod_timer(&psTimerCBData->sTimer, psTimerCBData->ui32Delay + jiffies);
-}
-
-
-#if defined(PVR_LINUX_TIMERS_USING_WORKQUEUES)
-static void OSTimerWorkQueueCallBack(struct work_struct *psWork)
-{
- TIMER_CALLBACK_DATA *psTimerCBData = container_of(psWork, TIMER_CALLBACK_DATA, sWork);
-
- OSTimerCallbackBody(psTimerCBData);
-}
-#endif
-
-static IMG_VOID OSTimerCallbackWrapper(IMG_UINT32 ui32Data)
-{
- TIMER_CALLBACK_DATA *psTimerCBData = (TIMER_CALLBACK_DATA*)ui32Data;
-
-#if defined(PVR_LINUX_TIMERS_USING_WORKQUEUES)
- int res;
-
- res = queue_work(psTimerWorkQueue, &psTimerCBData->sWork);
- if (res == 0)
- {
- PVR_DPF((PVR_DBG_WARNING, "OSTimerCallbackWrapper: work already queued"));
- }
-#else
- OSTimerCallbackBody(psTimerCBData);
-#endif
-}
-
-
-IMG_HANDLE OSAddTimer(PFN_TIMER_FUNC pfnTimerFunc, IMG_VOID *pvData, IMG_UINT32 ui32MsTimeout)
-{
- TIMER_CALLBACK_DATA *psTimerCBData;
- IMG_UINT32 ui32i;
-#if !defined(PVR_LINUX_TIMERS_USING_WORKQUEUES)
- unsigned long ulLockFlags;
-#endif
-
-
- if(!pfnTimerFunc)
- {
- PVR_DPF((PVR_DBG_ERROR, "OSAddTimer: passed invalid callback"));
- return IMG_NULL;
- }
-
-
-#if defined(PVR_LINUX_TIMERS_USING_WORKQUEUES)
- mutex_lock(&sTimerStructLock);
-#else
- spin_lock_irqsave(&sTimerStructLock, ulLockFlags);
-#endif
- for (ui32i = 0; ui32i < OS_MAX_TIMERS; ui32i++)
- {
- psTimerCBData = &sTimers[ui32i];
- if (!psTimerCBData->bInUse)
- {
- psTimerCBData->bInUse = IMG_TRUE;
- break;
- }
- }
-#if defined(PVR_LINUX_TIMERS_USING_WORKQUEUES)
- mutex_unlock(&sTimerStructLock);
-#else
- spin_unlock_irqrestore(&sTimerStructLock, ulLockFlags);
-#endif
- if (ui32i >= OS_MAX_TIMERS)
- {
- PVR_DPF((PVR_DBG_ERROR, "OSAddTimer: all timers are in use"));
- return IMG_NULL;
- }
-
- psTimerCBData->pfnTimerFunc = pfnTimerFunc;
- psTimerCBData->pvData = pvData;
- psTimerCBData->bActive = IMG_FALSE;
-
-
-
-
- psTimerCBData->ui32Delay = ((HZ * ui32MsTimeout) < 1000)
- ? 1
- : ((HZ * ui32MsTimeout) / 1000);
-
- init_timer(&psTimerCBData->sTimer);
-
-
- psTimerCBData->sTimer.function = (IMG_VOID *)OSTimerCallbackWrapper;
- psTimerCBData->sTimer.data = (IMG_UINT32)psTimerCBData;
- psTimerCBData->sTimer.expires = psTimerCBData->ui32Delay + jiffies;
-
- return (IMG_HANDLE)(ui32i + 1);
-}
-
-
-static inline TIMER_CALLBACK_DATA *GetTimerStructure(IMG_HANDLE hTimer)
-{
- IMG_UINT32 ui32i = ((IMG_UINT32)hTimer) - 1;
-
- PVR_ASSERT(ui32i < OS_MAX_TIMERS);
-
- return &sTimers[ui32i];
-}
-
-PVRSRV_ERROR OSRemoveTimer (IMG_HANDLE hTimer)
-{
- TIMER_CALLBACK_DATA *psTimerCBData = GetTimerStructure(hTimer);
-
- PVR_ASSERT(psTimerCBData->bInUse);
- PVR_ASSERT(!psTimerCBData->bActive);
-
-
- psTimerCBData->bInUse = IMG_FALSE;
-
- return PVRSRV_OK;
-}
-
-
-PVRSRV_ERROR OSEnableTimer (IMG_HANDLE hTimer)
-{
- TIMER_CALLBACK_DATA *psTimerCBData = GetTimerStructure(hTimer);
-
- PVR_ASSERT(psTimerCBData->bInUse);
- PVR_ASSERT(!psTimerCBData->bActive);
-
-
- psTimerCBData->bActive = IMG_TRUE;
-
-
- psTimerCBData->sTimer.expires = psTimerCBData->ui32Delay + jiffies;
-
-
- add_timer(&psTimerCBData->sTimer);
-
- return PVRSRV_OK;
-}
-
-
-PVRSRV_ERROR OSDisableTimer (IMG_HANDLE hTimer)
-{
- TIMER_CALLBACK_DATA *psTimerCBData = GetTimerStructure(hTimer);
-
- PVR_ASSERT(psTimerCBData->bInUse);
- PVR_ASSERT(psTimerCBData->bActive);
-
-
- psTimerCBData->bActive = IMG_FALSE;
- smp_mb();
-
-#if defined(PVR_LINUX_TIMERS_USING_WORKQUEUES)
- flush_workqueue(psTimerWorkQueue);
-#endif
-
-
- del_timer_sync(&psTimerCBData->sTimer);
-
-#if defined(PVR_LINUX_TIMERS_USING_WORKQUEUES)
-
- flush_workqueue(psTimerWorkQueue);
-#endif
-
- return PVRSRV_OK;
-}
-
-
-PVRSRV_ERROR OSEventObjectCreate(const IMG_CHAR *pszName, PVRSRV_EVENTOBJECT *psEventObject)
-{
-
- PVRSRV_ERROR eError = PVRSRV_OK;
-
- if(psEventObject)
- {
- if(pszName)
- {
-
- strncpy(psEventObject->szName, pszName, EVENTOBJNAME_MAXLENGTH);
- }
- else
- {
-
- static IMG_UINT16 ui16NameIndex = 0;
- snprintf(psEventObject->szName, EVENTOBJNAME_MAXLENGTH, "PVRSRV_EVENTOBJECT_%d", ui16NameIndex++);
- }
-
- if(LinuxEventObjectListCreate(&psEventObject->hOSEventKM) != PVRSRV_OK)
- {
- eError = PVRSRV_ERROR_OUT_OF_MEMORY;
- }
-
- }
- else
- {
- PVR_DPF((PVR_DBG_ERROR, "OSEventObjectCreate: psEventObject is not a valid pointer"));
- eError = PVRSRV_ERROR_GENERIC;
- }
-
- return eError;
-
-}
-
-
-PVRSRV_ERROR OSEventObjectDestroy(PVRSRV_EVENTOBJECT *psEventObject)
-{
- PVRSRV_ERROR eError = PVRSRV_OK;
-
- if(psEventObject)
- {
- if(psEventObject->hOSEventKM)
- {
- LinuxEventObjectListDestroy(psEventObject->hOSEventKM);
- }
- else
- {
- PVR_DPF((PVR_DBG_ERROR, "OSEventObjectDestroy: hOSEventKM is not a valid pointer"));
- eError = PVRSRV_ERROR_INVALID_PARAMS;
- }
- }
- else
- {
- PVR_DPF((PVR_DBG_ERROR, "OSEventObjectDestroy: psEventObject is not a valid pointer"));
- eError = PVRSRV_ERROR_INVALID_PARAMS;
- }
-
- return eError;
-}
-
-PVRSRV_ERROR OSEventObjectWait(IMG_HANDLE hOSEventKM)
-{
- PVRSRV_ERROR eError;
-
- if(hOSEventKM)
- {
- eError = LinuxEventObjectWait(hOSEventKM, EVENT_OBJECT_TIMEOUT_MS);
- }
- else
- {
- PVR_DPF((PVR_DBG_ERROR, "OSEventObjectWait: hOSEventKM is not a valid handle"));
- eError = PVRSRV_ERROR_INVALID_PARAMS;
- }
-
- return eError;
-}
-
-PVRSRV_ERROR OSEventObjectOpen(PVRSRV_EVENTOBJECT *psEventObject,
- IMG_HANDLE *phOSEvent)
-{
- PVRSRV_ERROR eError = PVRSRV_OK;
-
- if(psEventObject)
- {
- if(LinuxEventObjectAdd(psEventObject->hOSEventKM, phOSEvent) != PVRSRV_OK)
- {
- PVR_DPF((PVR_DBG_ERROR, "LinuxEventObjectAdd: failed"));
- eError = PVRSRV_ERROR_INVALID_PARAMS;
- }
-
- }
- else
- {
- PVR_DPF((PVR_DBG_ERROR, "OSEventObjectCreate: psEventObject is not a valid pointer"));
- eError = PVRSRV_ERROR_INVALID_PARAMS;
- }
-
- return eError;
-}
-
-PVRSRV_ERROR OSEventObjectClose(PVRSRV_EVENTOBJECT *psEventObject,
- IMG_HANDLE hOSEventKM)
-{
- PVRSRV_ERROR eError = PVRSRV_OK;
-
- if(psEventObject)
- {
- if(LinuxEventObjectDelete(psEventObject->hOSEventKM, hOSEventKM) != PVRSRV_OK)
- {
- PVR_DPF((PVR_DBG_ERROR, "LinuxEventObjectDelete: failed"));
- eError = PVRSRV_ERROR_INVALID_PARAMS;
- }
-
- }
- else
- {
- PVR_DPF((PVR_DBG_ERROR, "OSEventObjectDestroy: psEventObject is not a valid pointer"));
- eError = PVRSRV_ERROR_INVALID_PARAMS;
- }
-
- return eError;
-
-}
-
-PVRSRV_ERROR OSEventObjectSignal(IMG_HANDLE hOSEventKM)
-{
- PVRSRV_ERROR eError;
-
- if(hOSEventKM)
- {
- eError = LinuxEventObjectSignal(hOSEventKM);
- }
- else
- {
- PVR_DPF((PVR_DBG_ERROR, "OSEventObjectSignal: hOSEventKM is not a valid handle"));
- eError = PVRSRV_ERROR_INVALID_PARAMS;
- }
-
- return eError;
-}
-
-IMG_BOOL OSProcHasPrivSrvInit(IMG_VOID)
-{
- return (capable(CAP_SYS_MODULE) != 0) ? IMG_TRUE : IMG_FALSE;
-}
-
-PVRSRV_ERROR OSCopyToUser(IMG_PVOID pvProcess,
- IMG_VOID *pvDest,
- IMG_VOID *pvSrc,
- IMG_UINT32 ui32Bytes)
-{
- PVR_UNREFERENCED_PARAMETER(pvProcess);
-
- if(copy_to_user(pvDest, pvSrc, ui32Bytes)==0)
- return PVRSRV_OK;
- else
- return PVRSRV_ERROR_GENERIC;
-}
-
-PVRSRV_ERROR OSCopyFromUser( IMG_PVOID pvProcess,
- IMG_VOID *pvDest,
- IMG_VOID *pvSrc,
- IMG_UINT32 ui32Bytes)
-{
- PVR_UNREFERENCED_PARAMETER(pvProcess);
-
- if(copy_from_user(pvDest, pvSrc, ui32Bytes)==0)
- return PVRSRV_OK;
- else
- return PVRSRV_ERROR_GENERIC;
-}
-
-IMG_BOOL OSAccessOK(IMG_VERIFY_TEST eVerification, IMG_VOID *pvUserPtr, IMG_UINT32 ui32Bytes)
-{
- IMG_INT linuxType;
-
- if (eVerification == PVR_VERIFY_READ)
- {
- linuxType = VERIFY_READ;
- }
- else
- {
- PVR_ASSERT(eVerification == PVR_VERIFY_WRITE);
- linuxType = VERIFY_WRITE;
- }
-
- return access_ok(linuxType, pvUserPtr, ui32Bytes);
-}
-
-typedef enum _eWrapMemType_
-{
- WRAP_TYPE_CLEANUP,
- WRAP_TYPE_GET_USER_PAGES,
- WRAP_TYPE_FIND_VMA_PAGES,
- WRAP_TYPE_FIND_VMA_PFN
-} eWrapMemType;
-
-typedef struct _sWrapMemInfo_
-{
- eWrapMemType eType;
- IMG_INT iNumPages;
- struct page **ppsPages;
- IMG_SYS_PHYADDR *psPhysAddr;
- IMG_INT iPageOffset;
- IMG_INT iContiguous;
-#if defined(PVR_DEBUG_EXT)
- IMG_UINT32 ulStartAddr;
- IMG_UINT32 ulBeyondEndAddr;
- struct vm_area_struct *psVMArea;
-#endif
- IMG_BOOL bWrapWorkaround;
-} sWrapMemInfo;
-
-static IMG_VOID CheckPagesContiguous(sWrapMemInfo *psInfo)
-{
- IMG_INT i;
- IMG_UINT32 ui32AddrChk;
-
- BUG_ON(psInfo == IMG_NULL);
-
- psInfo->iContiguous = 1;
-
- for (i = 0, ui32AddrChk = psInfo->psPhysAddr[0].uiAddr;
- i < psInfo->iNumPages;
- i++, ui32AddrChk += PAGE_SIZE)
- {
- if (psInfo->psPhysAddr[i].uiAddr != ui32AddrChk)
- {
- psInfo->iContiguous = 0;
- break;
- }
- }
-}
-
-static struct page *CPUVAddrToPage(struct vm_area_struct *psVMArea, IMG_UINT32 ulCPUVAddr)
-{
- pgd_t *psPGD;
- pud_t *psPUD;
- pmd_t *psPMD;
- pte_t *psPTE;
- struct mm_struct *psMM = psVMArea->vm_mm;
- IMG_UINT32 ulPFN;
- spinlock_t *psPTLock;
- struct page *psPage;
-
- psPGD = pgd_offset(psMM, ulCPUVAddr);
- if (pgd_none(*psPGD) || pgd_bad(*psPGD))
- return NULL;
-
- psPUD = pud_offset(psPGD, ulCPUVAddr);
- if (pud_none(*psPUD) || pud_bad(*psPUD))
- return NULL;
-
- psPMD = pmd_offset(psPUD, ulCPUVAddr);
- if (pmd_none(*psPMD) || pmd_bad(*psPMD))
- return NULL;
-
- psPage = NULL;
-
- psPTE = (pte_t *)pte_offset_map_lock(psMM, psPMD, ulCPUVAddr, &psPTLock);
- if ((pte_none(*psPTE) != 0) || (pte_present(*psPTE) == 0) || (pte_write(*psPTE) == 0))
- goto exit_unlock;
-
- ulPFN = pte_pfn(*psPTE);
- if (!pfn_valid(ulPFN))
- goto exit_unlock;
-
- psPage = pfn_to_page(ulPFN);
-
- get_page(psPage);
-
-exit_unlock:
- pte_unmap_unlock(psPTE, psPTLock);
-
- return psPage;
-}
-PVRSRV_ERROR OSReleasePhysPageAddr(IMG_HANDLE hOSWrapMem)
-{
- sWrapMemInfo *psInfo = (sWrapMemInfo *)hOSWrapMem;
- IMG_INT i;
-
- BUG_ON(psInfo == IMG_NULL);
-
- switch (psInfo->eType)
- {
- case WRAP_TYPE_CLEANUP:
- break;
- case WRAP_TYPE_FIND_VMA_PFN:
- break;
- case WRAP_TYPE_GET_USER_PAGES:
- {
- for (i = 0; i < psInfo->iNumPages; i++)
- {
- struct page *psPage = psInfo->ppsPages[i];
-
-
- if (!PageReserved(psPage));
- {
- SetPageDirty(psPage);
- }
- page_cache_release(psPage);
- }
- break;
- }
- case WRAP_TYPE_FIND_VMA_PAGES:
- {
- for (i = 0; i < psInfo->iNumPages; i++)
- {
- if(psInfo->bWrapWorkaround)
- put_page(psInfo->ppsPages[i]);
- else
- put_page_testzero(psInfo->ppsPages[i]);
- }
- break;
- }
- default:
- {
- PVR_DPF((PVR_DBG_ERROR,
- "OSReleasePhysPageAddr: Unknown wrap type (%d)", psInfo->eType));
- return PVRSRV_ERROR_GENERIC;
- }
- }
-
- if (psInfo->ppsPages != IMG_NULL)
- {
- kfree(psInfo->ppsPages);
- }
-
- if (psInfo->psPhysAddr != IMG_NULL)
- {
- kfree(psInfo->psPhysAddr);
- }
-
- kfree(psInfo);
-
- return PVRSRV_OK;
-}
-
-PVRSRV_ERROR OSAcquirePhysPageAddr(IMG_VOID* pvCPUVAddr,
- IMG_UINT32 ui32Bytes,
- IMG_SYS_PHYADDR *psSysPAddr,
- IMG_HANDLE *phOSWrapMem,
- IMG_BOOL bWrapWorkaround)
-{
- IMG_UINT32 ulStartAddrOrig = (IMG_UINT32) pvCPUVAddr;
- IMG_UINT32 ulAddrRangeOrig = (IMG_UINT32) ui32Bytes;
- IMG_UINT32 ulBeyondEndAddrOrig = ulStartAddrOrig + ulAddrRangeOrig;
- IMG_UINT32 ulStartAddr;
- IMG_UINT32 ulAddrRange;
- IMG_UINT32 ulBeyondEndAddr;
- IMG_UINT32 ulAddr;
- IMG_INT iNumPagesMapped;
- IMG_INT i;
- struct vm_area_struct *psVMArea;
- sWrapMemInfo *psInfo;
-
-
- ulStartAddr = ulStartAddrOrig & PAGE_MASK;
- ulBeyondEndAddr = PAGE_ALIGN(ulBeyondEndAddrOrig);
- ulAddrRange = ulBeyondEndAddr - ulStartAddr;
-
-
- psInfo = kmalloc(sizeof(*psInfo), GFP_KERNEL);
- if (psInfo == NULL)
- {
- PVR_DPF((PVR_DBG_ERROR,
- "OSAcquirePhysPageAddr: Couldn't allocate information structure"));
- return PVRSRV_ERROR_OUT_OF_MEMORY;
- }
- memset(psInfo, 0, sizeof(*psInfo));
- psInfo->bWrapWorkaround = bWrapWorkaround;
-
-#if defined(PVR_DEBUG_EXT)
- psInfo->ulStartAddr = ulStartAddrOrig;
- psInfo->ulBeyondEndAddr = ulBeyondEndAddrOrig;
-#endif
-
- psInfo->iNumPages = (IMG_INT)(ulAddrRange >> PAGE_SHIFT);
- psInfo->iPageOffset = (IMG_INT)(ulStartAddrOrig & ~PAGE_MASK);
-
-
- psInfo->psPhysAddr = kmalloc((size_t)psInfo->iNumPages * sizeof(*psInfo->psPhysAddr), GFP_KERNEL);
- if (psInfo->psPhysAddr == NULL)
- {
- PVR_DPF((PVR_DBG_ERROR,
- "OSAcquirePhysPageAddr: Couldn't allocate page array"));
- goto error_free;
- }
-
-
- psInfo->ppsPages = kmalloc((size_t)psInfo->iNumPages * sizeof(*psInfo->ppsPages), GFP_KERNEL);
- if (psInfo->ppsPages == NULL)
- {
- PVR_DPF((PVR_DBG_ERROR,
- "OSAcquirePhysPageAddr: Couldn't allocate page array"));
- goto error_free;
- }
-
-
- down_read(¤t->mm->mmap_sem);
- iNumPagesMapped = get_user_pages(current, current->mm, ulStartAddr, psInfo->iNumPages, 1, 0, psInfo->ppsPages, NULL);
- up_read(¤t->mm->mmap_sem);
-
- if (iNumPagesMapped >= 0)
- {
-
- if (iNumPagesMapped != psInfo->iNumPages)
- {
- PVR_TRACE(("OSAcquirePhysPageAddr: Couldn't map all the pages needed (wanted: %d, got %d)", psInfo->iNumPages, iNumPagesMapped));
-
-
- for (i = 0; i < iNumPagesMapped; i++)
- {
- page_cache_release(psInfo->ppsPages[i]);
-
- }
- goto error_free;
- }
-
-
- for (i = 0; i < psInfo->iNumPages; i++)
- {
- IMG_CPU_PHYADDR CPUPhysAddr;
-
- CPUPhysAddr.uiAddr = page_to_pfn(psInfo->ppsPages[i]) << PAGE_SHIFT;
- psInfo->psPhysAddr[i] = SysCpuPAddrToSysPAddr(CPUPhysAddr);
- psSysPAddr[i] = psInfo->psPhysAddr[i];
-
- }
-
- psInfo->eType = WRAP_TYPE_GET_USER_PAGES;
-
- goto exit_check;
- }
-
- PVR_DPF((PVR_DBG_MESSAGE, "OSAcquirePhysPageAddr: get_user_pages failed (%d), trying something else", iNumPagesMapped));
-
-
- down_read(¤t->mm->mmap_sem);
-
- psVMArea = find_vma(current->mm, ulStartAddrOrig);
- if (psVMArea == NULL)
- {
- PVR_DPF((PVR_DBG_ERROR,
- "OSAcquirePhysPageAddr: Couldn't find memory region containing start address %lx", ulStartAddrOrig));
-
- goto error_release_mmap_sem;
- }
-#if defined(PVR_DEBUG_EXT)
- psInfo->psVMArea = psVMArea;
-#endif
-
-
- if (ulStartAddrOrig < psVMArea->vm_start)
- {
- PVR_DPF((PVR_DBG_ERROR,
- "OSAcquirePhysPageAddr: Start address %lx is outside of the region returned by find_vma", ulStartAddrOrig));
- goto error_release_mmap_sem;
- }
-
-
- if (ulBeyondEndAddrOrig > psVMArea->vm_end)
- {
- PVR_DPF((PVR_DBG_ERROR,
- "OSAcquirePhysPageAddr: End address %lx is outside of the region returned by find_vma", ulBeyondEndAddrOrig));
- goto error_release_mmap_sem;
- }
-
-
- if ((psVMArea->vm_flags & (VM_IO | VM_RESERVED)) != (VM_IO | VM_RESERVED))
- {
- PVR_DPF((PVR_DBG_ERROR,
- "OSAcquirePhysPageAddr: Memory region does not represent memory mapped I/O (VMA flags: 0x%lx)", psVMArea->vm_flags));
- goto error_release_mmap_sem;
- }
-
-
- if ((psVMArea->vm_flags & (VM_READ | VM_WRITE)) != (VM_READ | VM_WRITE))
- {
- PVR_DPF((PVR_DBG_ERROR,
- "OSAcquirePhysPageAddr: No read/write access to memory region (VMA flags: 0x%lx)", psVMArea->vm_flags));
- goto error_release_mmap_sem;
- }
-
-
- for (ulAddr = ulStartAddrOrig, i = 0; ulAddr < ulBeyondEndAddrOrig; ulAddr += PAGE_SIZE, i++)
- {
- struct page *psPage;
-
- BUG_ON(i >= psInfo->iNumPages);
-
- psPage = CPUVAddrToPage(psVMArea, ulAddr);
- if (psPage == NULL)
- {
- IMG_INT j;
-
- PVR_TRACE(("OSAcquirePhysPageAddr: Couldn't lookup page structure for address 0x%lx, trying something else", ulAddr));
-
-
- for (j = 0; j < i; j++)
- {
- if(psInfo->bWrapWorkaround)
- put_page(psInfo->ppsPages[j]);
- else
- put_page_testzero(psInfo->ppsPages[j]);
- }
- break;
- }
-
- psInfo->ppsPages[i] = psPage;
- }
-
- BUG_ON(i > psInfo->iNumPages);
- if (i == psInfo->iNumPages)
- {
-
- for (i = 0; i < psInfo->iNumPages; i++)
- {
- struct page *psPage = psInfo->ppsPages[i];
- IMG_CPU_PHYADDR CPUPhysAddr;
-
-
- CPUPhysAddr.uiAddr = page_to_pfn(psPage) << PAGE_SHIFT;
-
- psInfo->psPhysAddr[i] = SysCpuPAddrToSysPAddr(CPUPhysAddr);
- psSysPAddr[i] = psInfo->psPhysAddr[i];
- }
-
- psInfo->eType = WRAP_TYPE_FIND_VMA_PAGES;
- }
- else
- {
-#if defined(PVR_SECURE_HANDLES)
-
-
-
- if ((psVMArea->vm_flags & VM_PFNMAP) == 0)
- {
- PVR_DPF((PVR_DBG_WARNING,
- "OSAcquirePhysPageAddr: Region isn't a raw PFN mapping. Giving up."));
- goto error_release_mmap_sem;
- }
-
- for (ulAddr = ulStartAddrOrig, i = 0; ulAddr < ulBeyondEndAddrOrig; ulAddr += PAGE_SIZE, i++)
- {
- IMG_CPU_PHYADDR CPUPhysAddr;
-
- CPUPhysAddr.uiAddr = ((ulAddr - psVMArea->vm_start) + (psVMArea->vm_pgoff << PAGE_SHIFT)) & PAGE_MASK;
-
- psInfo->psPhysAddr[i] = SysCpuPAddrToSysPAddr(CPUPhysAddr);
- psSysPAddr[i] = psInfo->psPhysAddr[i];
- }
- BUG_ON(i != psInfo->iNumPages);
-
- psInfo->eType = WRAP_TYPE_FIND_VMA_PFN;
-
-
- PVR_DPF((PVR_DBG_WARNING,
- "OSAcquirePhysPageAddr: Region can't be locked down"));
-#else
- PVR_DPF((PVR_DBG_WARNING,
- "OSAcquirePhysPageAddr: Raw PFN mappings not supported. Giving up."));
- goto error_release_mmap_sem;
-#endif
- }
-
- up_read(¤t->mm->mmap_sem);
-
-exit_check:
- CheckPagesContiguous(psInfo);
-
-
-
- *phOSWrapMem = (IMG_HANDLE)psInfo;
-
- return PVRSRV_OK;
-
-error_release_mmap_sem:
- up_read(¤t->mm->mmap_sem);
-error_free:
- psInfo->eType = WRAP_TYPE_CLEANUP;
- OSReleasePhysPageAddr((IMG_HANDLE)psInfo);
- return PVRSRV_ERROR_GENERIC;
-}
-
-PVRSRV_ERROR PVROSFuncInit(IMG_VOID)
-{
-#if defined(PVR_LINUX_TIMERS_USING_WORKQUEUES)
- {
- IMG_UINT32 ui32i;
-
- psTimerWorkQueue = create_workqueue("pvr_timer");
- if (psTimerWorkQueue == NULL)
- {
- PVR_DPF((PVR_DBG_ERROR, "%s: couldn't create timer workqueue", __FUNCTION__));
- return PVRSRV_ERROR_GENERIC;
-
- }
-
- for (ui32i = 0; ui32i < OS_MAX_TIMERS; ui32i++)
- {
- TIMER_CALLBACK_DATA *psTimerCBData = &sTimers[ui32i];
-
- INIT_WORK(&psTimerCBData->sWork, OSTimerWorkQueueCallBack);
- }
- }
-#endif
- return PVRSRV_OK;
-}
-
-IMG_VOID PVROSFuncDeInit(IMG_VOID)
-{
-#if defined(PVR_LINUX_TIMERS_USING_WORKQUEUES)
- if (psTimerWorkQueue != NULL)
- {
- destroy_workqueue(psTimerWorkQueue);
- }
-#endif
-}
+++ /dev/null
-/**********************************************************************
- *
- * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful but, except
- * as otherwise stated in writing, 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.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK
- *
- ******************************************************************************/
-
-#include "services_headers.h"
-#include "osperproc.h"
-
-#include "env_perproc.h"
-#include "proc.h"
-
-extern IMG_UINT32 gui32ReleasePID;
-
-PVRSRV_ERROR OSPerProcessPrivateDataInit(IMG_HANDLE *phOsPrivateData)
-{
- PVRSRV_ERROR eError;
- IMG_HANDLE hBlockAlloc;
- PVRSRV_ENV_PER_PROCESS_DATA *psEnvPerProc;
-
- eError = OSAllocMem(PVRSRV_OS_NON_PAGEABLE_HEAP,
- sizeof(PVRSRV_ENV_PER_PROCESS_DATA),
- phOsPrivateData,
- &hBlockAlloc,
- "Environment per Process Data");
-
- if (eError != PVRSRV_OK)
- {
- *phOsPrivateData = IMG_NULL;
-
- PVR_DPF((PVR_DBG_ERROR, "%s: OSAllocMem failed (%d)", __FUNCTION__, eError));
- return eError;
- }
-
- psEnvPerProc = (PVRSRV_ENV_PER_PROCESS_DATA *)*phOsPrivateData;
- OSMemSet(psEnvPerProc, 0, sizeof(*psEnvPerProc));
-
- psEnvPerProc->hBlockAlloc = hBlockAlloc;
-
-
- LinuxMMapPerProcessConnect(psEnvPerProc);
-
-#if defined(SUPPORT_DRI_DRM) && defined(PVR_SECURE_DRM_AUTH_EXPORT)
-
- INIT_LIST_HEAD(&psEnvPerProc->sDRMAuthListHead);
-#endif
-
- return PVRSRV_OK;
-}
-
-PVRSRV_ERROR OSPerProcessPrivateDataDeInit(IMG_HANDLE hOsPrivateData)
-{
- PVRSRV_ERROR eError;
- PVRSRV_ENV_PER_PROCESS_DATA *psEnvPerProc;
-
- if (hOsPrivateData == IMG_NULL)
- {
- return PVRSRV_OK;
- }
-
- psEnvPerProc = (PVRSRV_ENV_PER_PROCESS_DATA *)hOsPrivateData;
-
-
- LinuxMMapPerProcessDisconnect(psEnvPerProc);
-
-
- RemovePerProcessProcDir(psEnvPerProc);
-
- eError = OSFreeMem(PVRSRV_OS_NON_PAGEABLE_HEAP,
- sizeof(PVRSRV_ENV_PER_PROCESS_DATA),
- hOsPrivateData,
- psEnvPerProc->hBlockAlloc);
-
-
- if (eError != PVRSRV_OK)
- {
- PVR_DPF((PVR_DBG_ERROR, "%s: OSFreeMem failed (%d)", __FUNCTION__, eError));
- }
-
- return PVRSRV_OK;
-}
-
-PVRSRV_ERROR OSPerProcessSetHandleOptions(PVRSRV_HANDLE_BASE *psHandleBase)
-{
- return LinuxMMapPerProcessHandleOptions(psHandleBase);
-}
-
-IMG_HANDLE LinuxTerminatingProcessPrivateData(IMG_VOID)
-{
- if(!gui32ReleasePID)
- return NULL;
- return PVRSRVPerProcessPrivateData(gui32ReleasePID);
-}
+++ /dev/null
-/**********************************************************************
- *
- * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful but, except
- * as otherwise stated in writing, 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.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK
- *
- ******************************************************************************/
-
-#if defined (SUPPORT_SGX)
-#if defined (PDUMP)
-
-#include <asm/atomic.h>
-#include <stdarg.h>
-#include "sgxdefs.h"
-#include "services_headers.h"
-
-#include "pvrversion.h"
-#include "pvr_debug.h"
-
-#include "dbgdrvif.h"
-#include "sgxmmu.h"
-#include "mm.h"
-#include "pdump_km.h"
-
-#include <linux/tty.h>
-
-static IMG_BOOL PDumpWriteString2 (IMG_CHAR * pszString, IMG_UINT32 ui32Flags);
-static IMG_BOOL PDumpWriteILock (PDBG_STREAM psStream, IMG_UINT8 *pui8Data, IMG_UINT32 ui32Count, IMG_UINT32 ui32Flags);
-static IMG_VOID DbgSetFrame (PDBG_STREAM psStream, IMG_UINT32 ui32Frame);
-static IMG_UINT32 DbgGetFrame (PDBG_STREAM psStream);
-static IMG_VOID DbgSetMarker (PDBG_STREAM psStream, IMG_UINT32 ui32Marker);
-static IMG_UINT32 DbgWrite (PDBG_STREAM psStream, IMG_UINT8 *pui8Data, IMG_UINT32 ui32BCount, IMG_UINT32 ui32Flags);
-
-#define PDUMP_DATAMASTER_PIXEL (1)
-#define PDUMP_DATAMASTER_EDM (3)
-
-#define MIN(a,b) (a > b ? b : a)
-
-#define MAX_FILE_SIZE 0x40000000
-
-static atomic_t gsPDumpSuspended = ATOMIC_INIT(0);
-
-static PDBGKM_SERVICE_TABLE gpfnDbgDrv = IMG_NULL;
-
-
-
-IMG_CHAR *pszStreamName[PDUMP_NUM_STREAMS] = { "ParamStream2",
- "ScriptStream2",
- "DriverInfoStream"};
-typedef struct PDBG_PDUMP_STATE_TAG
-{
- PDBG_STREAM psStream[PDUMP_NUM_STREAMS];
- IMG_UINT32 ui32ParamFileNum;
-
- IMG_CHAR *pszMsg;
- IMG_CHAR *pszScript;
- IMG_CHAR *pszFile;
-
-} PDBG_PDUMP_STATE;
-
-static PDBG_PDUMP_STATE gsDBGPdumpState = {{IMG_NULL}, 0, IMG_NULL, IMG_NULL, IMG_NULL};
-
-#define SZ_MSG_SIZE_MAX PVRSRV_PDUMP_MAX_COMMENT_SIZE-1
-#define SZ_SCRIPT_SIZE_MAX PVRSRV_PDUMP_MAX_COMMENT_SIZE-1
-#define SZ_FILENAME_SIZE_MAX PVRSRV_PDUMP_MAX_COMMENT_SIZE-1
-
-
-
-
-IMG_VOID DBGDrvGetServiceTable(IMG_VOID **fn_table);
-
-static inline IMG_BOOL PDumpSuspended(IMG_VOID)
-{
- return atomic_read(&gsPDumpSuspended) != 0;
-}
-
-PVRSRV_ERROR PDumpOSGetScriptString(IMG_HANDLE *phScript,
- IMG_UINT32 *pui32MaxLen)
-{
- *phScript = (IMG_HANDLE)gsDBGPdumpState.pszScript;
- *pui32MaxLen = SZ_SCRIPT_SIZE_MAX;
- if ((!*phScript) || PDumpSuspended())
- {
- return PVRSRV_ERROR_GENERIC;
- }
- return PVRSRV_OK;
-}
-
-PVRSRV_ERROR PDumpOSGetMessageString(IMG_HANDLE *phMsg,
- IMG_UINT32 *pui32MaxLen)
-{
- *phMsg = (IMG_HANDLE)gsDBGPdumpState.pszMsg;
- *pui32MaxLen = SZ_MSG_SIZE_MAX;
- if ((!*phMsg) || PDumpSuspended())
- {
- return PVRSRV_ERROR_GENERIC;
- }
- return PVRSRV_OK;
-}
-
-PVRSRV_ERROR PDumpOSGetFilenameString(IMG_CHAR **ppszFile,
- IMG_UINT32 *pui32MaxLen)
-{
- *ppszFile = gsDBGPdumpState.pszFile;
- *pui32MaxLen = SZ_FILENAME_SIZE_MAX;
- if ((!*ppszFile) || PDumpSuspended())
- {
- return PVRSRV_ERROR_GENERIC;
- }
- return PVRSRV_OK;
-}
-
-IMG_BOOL PDumpOSWriteString2(IMG_HANDLE hScript, IMG_UINT32 ui32Flags)
-{
- return PDumpWriteString2(hScript, ui32Flags);
-}
-
-PVRSRV_ERROR PDumpOSBufprintf(IMG_HANDLE hBuf, IMG_UINT32 ui32ScriptSizeMax, IMG_CHAR* pszFormat, ...)
-{
- IMG_CHAR* pszBuf = hBuf;
- IMG_UINT32 n;
- va_list vaArgs;
-
- va_start(vaArgs, pszFormat);
-
- n = vsnprintf(pszBuf, ui32ScriptSizeMax, pszFormat, vaArgs);
-
- va_end(vaArgs);
-
- if (n>=ui32ScriptSizeMax || n==-1)
- {
- PVR_DPF((PVR_DBG_ERROR, "Buffer overflow detected, pdump output may be incomplete."));
-
- return PVRSRV_ERROR_PDUMP_BUF_OVERFLOW;
- }
-
- return PVRSRV_OK;
-}
-
-PVRSRV_ERROR PDumpOSVSprintf(IMG_CHAR *pszComment, IMG_UINT32 ui32ScriptSizeMax, IMG_CHAR* pszFormat, PDUMP_va_list vaArgs)
-{
- IMG_UINT32 n;
-
- n = vsnprintf(pszComment, ui32ScriptSizeMax, pszFormat, vaArgs);
-
- if (n>=ui32ScriptSizeMax || n==-1)
- {
- PVR_DPF((PVR_DBG_ERROR, "Buffer overflow detected, pdump output may be incomplete."));
-
- return PVRSRV_ERROR_PDUMP_BUF_OVERFLOW;
- }
-
- return PVRSRV_OK;
-}
-
-IMG_VOID PDumpOSDebugPrintf(IMG_CHAR* pszFormat, ...)
-{
-
-}
-
-PVRSRV_ERROR PDumpOSSprintf(IMG_CHAR *pszComment, IMG_UINT32 ui32ScriptSizeMax, IMG_CHAR *pszFormat, ...)
-{
- IMG_UINT32 n;
- va_list vaArgs;
-
- va_start(vaArgs, pszFormat);
-
- n = vsnprintf(pszComment, ui32ScriptSizeMax, pszFormat, vaArgs);
-
- va_end(vaArgs);
-
- if (n>=ui32ScriptSizeMax || n==-1)
- {
- PVR_DPF((PVR_DBG_ERROR, "Buffer overflow detected, pdump output may be incomplete."));
-
- return PVRSRV_ERROR_PDUMP_BUF_OVERFLOW;
- }
-
- return PVRSRV_OK;
-}
-
-IMG_UINT32 PDumpOSBuflen(IMG_HANDLE hBuffer, IMG_UINT32 ui32BufferSizeMax)
-{
- IMG_CHAR* pszBuf = hBuffer;
- IMG_UINT32 ui32Count = 0;
-
- while ((pszBuf[ui32Count]!=0) && (ui32Count<ui32BufferSizeMax) )
- {
- ui32Count++;
- }
- return(ui32Count);
-}
-
-IMG_VOID PDumpOSVerifyLineEnding(IMG_HANDLE hBuffer, IMG_UINT32 ui32BufferSizeMax)
-{
- IMG_UINT32 ui32Count = 0;
- IMG_CHAR* pszBuf = hBuffer;
-
-
- ui32Count = PDumpOSBuflen(hBuffer, ui32BufferSizeMax);
-
-
- if ((ui32Count >= 1) && (pszBuf[ui32Count-1] != '\n') && (ui32Count<ui32BufferSizeMax))
- {
- pszBuf[ui32Count] = '\n';
- ui32Count++;
- pszBuf[ui32Count] = '\0';
- }
- if ((ui32Count >= 2) && (pszBuf[ui32Count-2] != '\r') && (ui32Count<ui32BufferSizeMax))
- {
- pszBuf[ui32Count-1] = '\r';
- pszBuf[ui32Count] = '\n';
- ui32Count++;
- pszBuf[ui32Count] = '\0';
- }
-}
-
-IMG_HANDLE PDumpOSGetStream(IMG_UINT32 ePDumpStream)
-{
- return (IMG_HANDLE)gsDBGPdumpState.psStream[ePDumpStream];
-}
-
-IMG_UINT32 PDumpOSGetStreamOffset(IMG_UINT32 ePDumpStream)
-{
- PDBG_STREAM psStream = gsDBGPdumpState.psStream[ePDumpStream];
- return gpfnDbgDrv->pfnGetStreamOffset(psStream);
-}
-
-IMG_UINT32 PDumpOSGetParamFileNum(IMG_VOID)
-{
- return gsDBGPdumpState.ui32ParamFileNum;
-}
-
-IMG_BOOL PDumpOSWriteString(IMG_HANDLE hStream,
- IMG_UINT8 *psui8Data,
- IMG_UINT32 ui32Size,
- IMG_UINT32 ui32Flags)
-{
- PDBG_STREAM psStream = (PDBG_STREAM)hStream;
- return PDumpWriteILock(psStream,
- psui8Data,
- ui32Size,
- ui32Flags);
-}
-
-IMG_VOID PDumpOSCheckForSplitting(IMG_HANDLE hStream, IMG_UINT32 ui32Size, IMG_UINT32 ui32Flags)
-{
-
- PVR_UNREFERENCED_PARAMETER(hStream);
- PVR_UNREFERENCED_PARAMETER(ui32Size);
- PVR_UNREFERENCED_PARAMETER(ui32Size);
-}
-
-IMG_BOOL PDumpOSJTInitialised(IMG_VOID)
-{
- if(gpfnDbgDrv)
- {
- return IMG_TRUE;
- }
- return IMG_FALSE;
-}
-
-inline IMG_BOOL PDumpOSIsSuspended(IMG_VOID)
-{
- return atomic_read(&gsPDumpSuspended) != 0;
-}
-
-IMG_VOID PDumpOSCPUVAddrToDevPAddr(PVRSRV_DEVICE_TYPE eDeviceType,
- IMG_HANDLE hOSMemHandle,
- IMG_UINT32 ui32Offset,
- IMG_UINT8 *pui8LinAddr,
- IMG_UINT32 ui32PageSize,
- IMG_DEV_PHYADDR *psDevPAddr)
-{
- if(hOSMemHandle)
- {
-
- IMG_CPU_PHYADDR sCpuPAddr;
-
- PVR_UNREFERENCED_PARAMETER(pui8LinAddr);
-
- sCpuPAddr = OSMemHandleToCpuPAddr(hOSMemHandle, ui32Offset);
- PVR_ASSERT((sCpuPAddr.uiAddr & (ui32PageSize - 1)) == 0);
-
-
- *psDevPAddr = SysCpuPAddrToDevPAddr(eDeviceType, sCpuPAddr);
- }
- else
- {
- IMG_CPU_PHYADDR sCpuPAddr;
-
- PVR_UNREFERENCED_PARAMETER(ui32Offset);
-
- sCpuPAddr = OSMapLinToCPUPhys(pui8LinAddr);
- *psDevPAddr = SysCpuPAddrToDevPAddr(eDeviceType, sCpuPAddr);
- }
-}
-
-IMG_VOID PDumpOSCPUVAddrToPhysPages(IMG_HANDLE hOSMemHandle,
- IMG_UINT32 ui32Offset,
- IMG_PUINT8 pui8LinAddr,
- IMG_UINT32 *pui32PageOffset)
-{
- if(hOSMemHandle)
- {
-
- IMG_CPU_PHYADDR sCpuPAddr;
-
- PVR_UNREFERENCED_PARAMETER(pui8LinAddr);
-
- sCpuPAddr = OSMemHandleToCpuPAddr(hOSMemHandle, ui32Offset);
- *pui32PageOffset = sCpuPAddr.uiAddr & (HOST_PAGESIZE() -1);
- }
- else
- {
- PVR_UNREFERENCED_PARAMETER(hOSMemHandle);
- PVR_UNREFERENCED_PARAMETER(ui32Offset);
-
- *pui32PageOffset = (IMG_UINT32)pui8LinAddr & (HOST_PAGESIZE() - 1);
- }
-}
-
-
-
-IMG_VOID PDumpInit(IMG_VOID)
-{
- IMG_UINT32 i;
-
-
- if (!gpfnDbgDrv)
- {
- DBGDrvGetServiceTable((IMG_VOID **)&gpfnDbgDrv);
-
-
-
-
- if (gpfnDbgDrv == IMG_NULL)
- {
- return;
- }
-
- if(!gsDBGPdumpState.pszFile)
- {
- if(OSAllocMem(PVRSRV_OS_PAGEABLE_HEAP, SZ_FILENAME_SIZE_MAX, (IMG_PVOID *)&gsDBGPdumpState.pszFile, 0,
- "Filename string") != PVRSRV_OK)
- {
- goto init_failed;
- }
- }
-
- if(!gsDBGPdumpState.pszMsg)
- {
- if(OSAllocMem(PVRSRV_OS_PAGEABLE_HEAP, SZ_MSG_SIZE_MAX, (IMG_PVOID *)&gsDBGPdumpState.pszMsg, 0,
- "Message string") != PVRSRV_OK)
- {
- goto init_failed;
- }
- }
-
- if(!gsDBGPdumpState.pszScript)
- {
- if(OSAllocMem(PVRSRV_OS_PAGEABLE_HEAP, SZ_SCRIPT_SIZE_MAX, (IMG_PVOID *)&gsDBGPdumpState.pszScript, 0,
- "Script string") != PVRSRV_OK)
- {
- goto init_failed;
- }
- }
-
- for(i=0; i < PDUMP_NUM_STREAMS; i++)
- {
- gsDBGPdumpState.psStream[i] = gpfnDbgDrv->pfnCreateStream(pszStreamName[i],
- DEBUG_CAPMODE_FRAMED,
- DEBUG_OUTMODE_STREAMENABLE,
- 0,
- 10);
-
- gpfnDbgDrv->pfnSetCaptureMode(gsDBGPdumpState.psStream[i],DEBUG_CAPMODE_FRAMED,0xFFFFFFFF, 0xFFFFFFFF, 1);
- gpfnDbgDrv->pfnSetFrame(gsDBGPdumpState.psStream[i],0);
- }
-
- PDUMPCOMMENT("Driver Product Name: %s", VS_PRODUCT_NAME);
- PDUMPCOMMENT("Driver Product Version: %s (%s)", PVRVERSION_STRING, PVRVERSION_FILE);
- PDUMPCOMMENT("Start of Init Phase");
- }
-
- return;
-
-init_failed:
-
- if(gsDBGPdumpState.pszFile)
- {
- OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP, SZ_FILENAME_SIZE_MAX, (IMG_PVOID) gsDBGPdumpState.pszFile, 0);
- gsDBGPdumpState.pszFile = IMG_NULL;
- }
-
- if(gsDBGPdumpState.pszScript)
- {
- OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP, SZ_SCRIPT_SIZE_MAX, (IMG_PVOID) gsDBGPdumpState.pszScript, 0);
- gsDBGPdumpState.pszScript = IMG_NULL;
- }
-
- if(gsDBGPdumpState.pszMsg)
- {
- OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP, SZ_MSG_SIZE_MAX, (IMG_PVOID) gsDBGPdumpState.pszMsg, 0);
- gsDBGPdumpState.pszMsg = IMG_NULL;
- }
-
- gpfnDbgDrv = IMG_NULL;
-}
-
-
-IMG_VOID PDumpDeInit(IMG_VOID)
-{
- IMG_UINT32 i;
-
- for(i=0; i < PDUMP_NUM_STREAMS; i++)
- {
- gpfnDbgDrv->pfnDestroyStream(gsDBGPdumpState.psStream[i]);
- }
-
- if(gsDBGPdumpState.pszFile)
- {
- OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP, SZ_FILENAME_SIZE_MAX, (IMG_PVOID) gsDBGPdumpState.pszFile, 0);
- gsDBGPdumpState.pszFile = IMG_NULL;
- }
-
- if(gsDBGPdumpState.pszScript)
- {
- OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP, SZ_SCRIPT_SIZE_MAX, (IMG_PVOID) gsDBGPdumpState.pszScript, 0);
- gsDBGPdumpState.pszScript = IMG_NULL;
- }
-
- if(gsDBGPdumpState.pszMsg)
- {
- OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP, SZ_MSG_SIZE_MAX, (IMG_PVOID) gsDBGPdumpState.pszMsg, 0);
- gsDBGPdumpState.pszMsg = IMG_NULL;
- }
-
- gpfnDbgDrv = IMG_NULL;
-}
-
-PVRSRV_ERROR PDumpStartInitPhaseKM(IMG_VOID)
-{
- IMG_UINT32 i;
-
- if (gpfnDbgDrv)
- {
- PDUMPCOMMENT("Start Init Phase");
- for(i=0; i < PDUMP_NUM_STREAMS; i++)
- {
- gpfnDbgDrv->pfnStartInitPhase(gsDBGPdumpState.psStream[i]);
- }
- }
- return PVRSRV_OK;
-}
-
-PVRSRV_ERROR PDumpStopInitPhaseKM(IMG_VOID)
-{
- IMG_UINT32 i;
-
- if (gpfnDbgDrv)
- {
- PDUMPCOMMENT("Stop Init Phase");
-
- for(i=0; i < PDUMP_NUM_STREAMS; i++)
- {
- gpfnDbgDrv->pfnStopInitPhase(gsDBGPdumpState.psStream[i]);
- }
- }
- return PVRSRV_OK;
-}
-
-IMG_BOOL PDumpIsLastCaptureFrameKM(IMG_VOID)
-{
- return gpfnDbgDrv->pfnIsLastCaptureFrame(gsDBGPdumpState.psStream[PDUMP_STREAM_SCRIPT2]);
-}
-
-
-IMG_BOOL PDumpIsCaptureFrameKM(IMG_VOID)
-{
- if (PDumpSuspended())
- {
- return IMG_FALSE;
- }
- return gpfnDbgDrv->pfnIsCaptureFrame(gsDBGPdumpState.psStream[PDUMP_STREAM_SCRIPT2], IMG_FALSE);
-}
-
-PVRSRV_ERROR PDumpSetFrameKM(IMG_UINT32 ui32Frame)
-{
- IMG_UINT32 ui32Stream;
-
- for (ui32Stream = 0; ui32Stream < PDUMP_NUM_STREAMS; ui32Stream++)
- {
- if (gsDBGPdumpState.psStream[ui32Stream])
- {
- DbgSetFrame(gsDBGPdumpState.psStream[ui32Stream], ui32Frame);
- }
- }
-
- return PVRSRV_OK;
-}
-
-PVRSRV_ERROR PDumpGetFrameKM(IMG_PUINT32 pui32Frame)
-{
- *pui32Frame = DbgGetFrame(gsDBGPdumpState.psStream[PDUMP_STREAM_SCRIPT2]);
-
- return PVRSRV_OK;
-}
-
-
-
-static IMG_BOOL PDumpWriteString2(IMG_CHAR * pszString, IMG_UINT32 ui32Flags)
-{
- return PDumpWriteILock(gsDBGPdumpState.psStream[PDUMP_STREAM_SCRIPT2], (IMG_UINT8 *) pszString, strlen(pszString), ui32Flags);
-}
-
-
-static IMG_BOOL PDumpWriteILock(PDBG_STREAM psStream, IMG_UINT8 *pui8Data, IMG_UINT32 ui32Count, IMG_UINT32 ui32Flags)
-{
- IMG_UINT32 ui32Written = 0;
- IMG_UINT32 ui32Off = 0;
-
- if ((psStream == IMG_NULL) || PDumpSuspended() || ((ui32Flags & PDUMP_FLAGS_NEVER) != 0))
- {
- return IMG_TRUE;
- }
-
-
-
-
- if (psStream == gsDBGPdumpState.psStream[PDUMP_STREAM_PARAM2])
- {
- IMG_UINT32 ui32ParamOutPos = gpfnDbgDrv->pfnGetStreamOffset(gsDBGPdumpState.psStream[PDUMP_STREAM_PARAM2]);
-
- if (ui32ParamOutPos + ui32Count > MAX_FILE_SIZE)
- {
- if ((gsDBGPdumpState.psStream[PDUMP_STREAM_SCRIPT2] && PDumpWriteString2("\r\n-- Splitting pdump output file\r\n\r\n", ui32Flags)))
- {
- DbgSetMarker(gsDBGPdumpState.psStream[PDUMP_STREAM_PARAM2], ui32ParamOutPos);
- gsDBGPdumpState.ui32ParamFileNum++;
- }
- }
- }
-
-
- while (((IMG_UINT32) ui32Count > 0) && (ui32Written != 0xFFFFFFFF))
- {
- ui32Written = DbgWrite(psStream, &pui8Data[ui32Off], ui32Count, ui32Flags);
-
-
-
-
- if (ui32Written == 0)
- {
- OSReleaseThreadQuanta();
- }
-
- if (ui32Written != 0xFFFFFFFF)
- {
- ui32Off += ui32Written;
- ui32Count -= ui32Written;
- }
- }
-
- if (ui32Written == 0xFFFFFFFF)
- {
- return IMG_FALSE;
- }
-
- return IMG_TRUE;
-}
-
-static IMG_VOID DbgSetFrame(PDBG_STREAM psStream, IMG_UINT32 ui32Frame)
-{
- gpfnDbgDrv->pfnSetFrame(psStream, ui32Frame);
-}
-
-
-static IMG_UINT32 DbgGetFrame(PDBG_STREAM psStream)
-{
- return gpfnDbgDrv->pfnGetFrame(psStream);
-}
-
-static IMG_VOID DbgSetMarker(PDBG_STREAM psStream, IMG_UINT32 ui32Marker)
-{
- gpfnDbgDrv->pfnSetMarker(psStream, ui32Marker);
-}
-
-static IMG_UINT32 DbgWrite(PDBG_STREAM psStream, IMG_UINT8 *pui8Data, IMG_UINT32 ui32BCount, IMG_UINT32 ui32Flags)
-{
- IMG_UINT32 ui32BytesWritten;
-
- if ((ui32Flags & PDUMP_FLAGS_CONTINUOUS) != 0)
- {
-
-
- if (((psStream->ui32CapMode & DEBUG_CAPMODE_FRAMED) != 0) &&
- (psStream->ui32Start == 0xFFFFFFFFUL) &&
- (psStream->ui32End == 0xFFFFFFFFUL) &&
- psStream->bInitPhaseComplete)
- {
- ui32BytesWritten = ui32BCount;
- }
- else
- {
- ui32BytesWritten = gpfnDbgDrv->pfnDBGDrivWrite2(psStream, pui8Data, ui32BCount, 1);
- }
- }
- else
- {
- if (ui32Flags & PDUMP_FLAGS_LASTFRAME)
- {
- IMG_UINT32 ui32DbgFlags;
-
- ui32DbgFlags = 0;
- if (ui32Flags & PDUMP_FLAGS_RESETLFBUFFER)
- {
- ui32DbgFlags |= WRITELF_FLAGS_RESETBUF;
- }
-
- ui32BytesWritten = gpfnDbgDrv->pfnWriteLF(psStream, pui8Data, ui32BCount, 1, ui32DbgFlags);
- }
- else
- {
- ui32BytesWritten = gpfnDbgDrv->pfnWriteBINCM(psStream, pui8Data, ui32BCount, 1);
- }
- }
-
- return ui32BytesWritten;
-}
-
-
-IMG_VOID PDumpSuspendKM(IMG_VOID)
-{
- atomic_inc(&gsPDumpSuspended);
-}
-
-IMG_VOID PDumpResumeKM(IMG_VOID)
-{
- atomic_dec(&gsPDumpSuspended);
-}
-
-#endif
-#endif
+++ /dev/null
-/**********************************************************************
- *
- * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful but, except
- * as otherwise stated in writing, 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.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK
- *
- ******************************************************************************/
-
-#ifndef __INCLUDED_PRIVATE_DATA_H_
-#define __INCLUDED_PRIVATE_DATA_H_
-
-#if defined(SUPPORT_DRI_DRM) && defined(PVR_SECURE_DRM_AUTH_EXPORT)
-#include <linux/list.h>
-#include <drm/drmP.h>
-#endif
-
-typedef struct
-{
-
- IMG_UINT32 ui32OpenPID;
-
-#if defined(PVR_SECURE_FD_EXPORT)
-
- IMG_HANDLE hKernelMemInfo;
-#endif
-
-#if defined(SUPPORT_DRI_DRM) && defined(PVR_SECURE_DRM_AUTH_EXPORT)
-
- struct list_head sDRMAuthListItem;
-
- struct drm_file *psDRMFile;
-#endif
-
-#if defined(SUPPORT_MEMINFO_IDS)
-
- IMG_UINT64 ui64Stamp;
-#endif
-
-
- IMG_HANDLE hBlockAlloc;
-
-#if defined(SUPPORT_DRI_DRM_EXT)
- IMG_PVOID pPriv;
-#endif
-}
-PVRSRV_FILE_PRIVATE_DATA;
-
-#endif
-
+++ /dev/null
-/**********************************************************************
- *
- * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful but, except
- * as otherwise stated in writing, 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.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK
- *
- ******************************************************************************/
-
-#include <linux/init.h>
-#include <linux/module.h>
-#include <linux/version.h>
-#include <linux/fs.h>
-#include <linux/proc_fs.h>
-#include <linux/seq_file.h>
-
-#include "services_headers.h"
-
-#include "queue.h"
-#include "resman.h"
-#include "pvrmmap.h"
-#include "pvr_debug.h"
-#include "pvrversion.h"
-#include "proc.h"
-#include "perproc.h"
-#include "env_perproc.h"
-#include "linkage.h"
-
-#include "lists.h"
-DECLARE_LIST_ANY_VA(PVRSRV_DEVICE_NODE);
-
-
-static struct proc_dir_entry * dir;
-
-#ifndef PVR_PROC_USE_SEQ_FILE
-static off_t procDumpSysNodes(IMG_CHAR *buf, size_t size, off_t off);
-static off_t procDumpVersion(IMG_CHAR *buf, size_t size, off_t off);
-#endif
-
-
-static const IMG_CHAR PVRProcDirRoot[] = "pvr";
-
-
-#ifdef PVR_PROC_USE_SEQ_FILE
-
-#define PVR_PROC_SEQ_START_TOKEN (void*)1
-static IMG_INT pvr_proc_open(struct inode *inode,struct file *file);
-static void *pvr_proc_seq_start (struct seq_file *m, loff_t *pos);
-static void pvr_proc_seq_stop (struct seq_file *m, void *v);
-static void *pvr_proc_seq_next (struct seq_file *m, void *v, loff_t *pos);
-static int pvr_proc_seq_show (struct seq_file *m, void *v);
-static ssize_t pvr_proc_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos);
-
-static struct file_operations pvr_proc_operations =
-{
- .open = pvr_proc_open,
- .read = seq_read,
- .write = pvr_proc_write,
- .llseek = seq_lseek,
- .release = seq_release,
-};
-
-static struct seq_operations pvr_proc_seq_operations =
-{
- .start = pvr_proc_seq_start,
- .next = pvr_proc_seq_next,
- .stop = pvr_proc_seq_stop,
- .show = pvr_proc_seq_show,
-};
-
-static struct proc_dir_entry* g_pProcQueue;
-static struct proc_dir_entry* g_pProcVersion;
-static struct proc_dir_entry* g_pProcSysNodes;
-
-#ifdef PVR_DEBUG_EXT
-static struct proc_dir_entry* g_pProcDebugLevel;
-#endif
-
-#ifdef PVR_MANUAL_POWER_CONTROL
-static struct proc_dir_entry* g_pProcPowerLevel;
-#endif
-
-
-static void ProcSeqShowVersion(struct seq_file *sfile,void* el);
-
-static void ProcSeqShowSysNodes(struct seq_file *sfile,void* el);
-static void* ProcSeqOff2ElementSysNodes(struct seq_file * sfile, loff_t off);
-
-#endif
-
-off_t printAppend(IMG_CHAR * buffer, size_t size, off_t off, const IMG_CHAR * format, ...)
-{
- IMG_INT n;
- size_t space = size - (size_t)off;
- va_list ap;
-
- PVR_ASSERT(space >= 0);
-
- va_start (ap, format);
-
- n = vsnprintf (buffer+off, space, format, ap);
-
- va_end (ap);
-
- if (n >= (IMG_INT)space || n < 0)
- {
-
- buffer[size - 1] = 0;
- return (off_t)(size - 1);
- }
- else
- {
- return (off + (off_t)n);
- }
-}
-
-
-#ifdef PVR_PROC_USE_SEQ_FILE
-
-void* ProcSeq1ElementOff2Element(struct seq_file *sfile, loff_t off)
-{
-
- if(!off)
- return (void*)2;
- return NULL;
-}
-
-
-void* ProcSeq1ElementHeaderOff2Element(struct seq_file *sfile, loff_t off)
-{
- if(!off)
- {
- return PVR_PROC_SEQ_START_TOKEN;
- }
-
-
- if(off == 1)
- return (void*)2;
-
- return NULL;
-}
-
-
-static IMG_INT pvr_proc_open(struct inode *inode,struct file *file)
-{
- IMG_INT ret = seq_open(file, &pvr_proc_seq_operations);
-
- struct seq_file *seq = (struct seq_file*)file->private_data;
- struct proc_dir_entry* pvr_proc_entry = PDE(inode);
-
-
- seq->private = pvr_proc_entry->data;
- return ret;
-}
-
-static ssize_t pvr_proc_write(struct file *file, const char __user *buffer,
- size_t count, loff_t *ppos)
-{
- struct inode *inode = file->f_path.dentry->d_inode;
- struct proc_dir_entry * dp;
-
- dp = PDE(inode);
-
- if (!dp->write_proc)
- return -EIO;
-
- return dp->write_proc(file, buffer, count, dp->data);
-}
-
-
-static void *pvr_proc_seq_start (struct seq_file *proc_seq_file, loff_t *pos)
-{
- PVR_PROC_SEQ_HANDLERS *handlers = (PVR_PROC_SEQ_HANDLERS*)proc_seq_file->private;
- if(handlers->startstop != NULL)
- handlers->startstop(proc_seq_file, IMG_TRUE);
- return handlers->off2element(proc_seq_file, *pos);
-}
-
-static void pvr_proc_seq_stop (struct seq_file *proc_seq_file, void *v)
-{
- PVR_PROC_SEQ_HANDLERS *handlers = (PVR_PROC_SEQ_HANDLERS*)proc_seq_file->private;
- if(handlers->startstop != NULL)
- handlers->startstop(proc_seq_file, IMG_FALSE);
-}
-
-static void *pvr_proc_seq_next (struct seq_file *proc_seq_file, void *v, loff_t *pos)
-{
- PVR_PROC_SEQ_HANDLERS *handlers = (PVR_PROC_SEQ_HANDLERS*)proc_seq_file->private;
- (*pos)++;
- if( handlers->next != NULL)
- return handlers->next( proc_seq_file, v, *pos );
- return handlers->off2element(proc_seq_file, *pos);
-}
-
-static int pvr_proc_seq_show (struct seq_file *proc_seq_file, void *v)
-{
- PVR_PROC_SEQ_HANDLERS *handlers = (PVR_PROC_SEQ_HANDLERS*)proc_seq_file->private;
- handlers->show( proc_seq_file,v );
- return 0;
-}
-
-
-
-static struct proc_dir_entry* CreateProcEntryInDirSeq(
- struct proc_dir_entry *pdir,
- const IMG_CHAR * name,
- IMG_VOID* data,
- pvr_next_proc_seq_t next_handler,
- pvr_show_proc_seq_t show_handler,
- pvr_off2element_proc_seq_t off2element_handler,
- pvr_startstop_proc_seq_t startstop_handler,
- write_proc_t whandler
- )
-{
-
- struct proc_dir_entry * file;
- mode_t mode;
-
- if (!dir)
- {
- PVR_DPF((PVR_DBG_ERROR, "CreateProcEntryInDirSeq: cannot make proc entry /proc/%s/%s: no parent", PVRProcDirRoot, name));
- return NULL;
- }
-
- mode = S_IFREG;
-
- if (show_handler)
- {
- mode |= S_IRUGO;
- }
-
- if (whandler)
- {
- mode |= S_IWUSR;
- }
-
- file=create_proc_entry(name, mode, pdir);
-
- if (file)
- {
- PVR_PROC_SEQ_HANDLERS *seq_handlers;
-
- file->proc_fops = &pvr_proc_operations;
- file->write_proc = whandler;
-
-
- file->data = kmalloc(sizeof(PVR_PROC_SEQ_HANDLERS), GFP_KERNEL);
- if(file->data)
- {
- seq_handlers = (PVR_PROC_SEQ_HANDLERS*)file->data;
- seq_handlers->next = next_handler;
- seq_handlers->show = show_handler;
- seq_handlers->off2element = off2element_handler;
- seq_handlers->startstop = startstop_handler;
- seq_handlers->data = data;
-
- return file;
- }
- }
-
- PVR_DPF((PVR_DBG_ERROR, "CreateProcEntryInDirSeq: cannot make proc entry /proc/%s/%s: no memory", PVRProcDirRoot, name));
- return 0;
-}
-
-
-struct proc_dir_entry* CreateProcReadEntrySeq (
- const IMG_CHAR * name,
- IMG_VOID* data,
- pvr_next_proc_seq_t next_handler,
- pvr_show_proc_seq_t show_handler,
- pvr_off2element_proc_seq_t off2element_handler,
- pvr_startstop_proc_seq_t startstop_handler
- )
-{
- return CreateProcEntrySeq(name,
- data,
- next_handler,
- show_handler,
- off2element_handler,
- startstop_handler,
- NULL);
-}
-
-struct proc_dir_entry* CreateProcEntrySeq (
- const IMG_CHAR * name,
- IMG_VOID* data,
- pvr_next_proc_seq_t next_handler,
- pvr_show_proc_seq_t show_handler,
- pvr_off2element_proc_seq_t off2element_handler,
- pvr_startstop_proc_seq_t startstop_handler,
- write_proc_t whandler
- )
-{
- return CreateProcEntryInDirSeq(
- dir,
- name,
- data,
- next_handler,
- show_handler,
- off2element_handler,
- startstop_handler,
- NULL
- );
-}
-
-
-
-struct proc_dir_entry* CreatePerProcessProcEntrySeq (
- const IMG_CHAR * name,
- IMG_VOID* data,
- pvr_next_proc_seq_t next_handler,
- pvr_show_proc_seq_t show_handler,
- pvr_off2element_proc_seq_t off2element_handler,
- pvr_startstop_proc_seq_t startstop_handler,
- write_proc_t whandler
- )
-{
- PVRSRV_ENV_PER_PROCESS_DATA *psPerProc;
- IMG_UINT32 ui32PID;
-
- if (!dir)
- {
- PVR_DPF((PVR_DBG_ERROR, "CreatePerProcessProcEntrySeq: /proc/%s doesn't exist", PVRProcDirRoot));
- return NULL;
- }
-
- ui32PID = OSGetCurrentProcessIDKM();
-
- psPerProc = PVRSRVPerProcessPrivateData(ui32PID);
- if (!psPerProc)
- {
- PVR_DPF((PVR_DBG_ERROR, "CreatePerProcessProcEntrySeq: no per process data"));
-
- return NULL;
- }
-
- if (!psPerProc->psProcDir)
- {
- IMG_CHAR dirname[16];
- IMG_INT ret;
-
- ret = snprintf(dirname, sizeof(dirname), "%lu", ui32PID);
-
- if (ret <=0 || ret >= (IMG_INT)sizeof(dirname))
- {
- PVR_DPF((PVR_DBG_ERROR, "CreatePerProcessProcEntries: couldn't generate per process proc directory name \"%u\"", ui32PID));
- return NULL;
- }
- else
- {
- psPerProc->psProcDir = proc_mkdir(dirname, dir);
- if (!psPerProc->psProcDir)
- {
- PVR_DPF((PVR_DBG_ERROR, "CreatePerProcessProcEntries: couldn't create per process proc directory /proc/%s/%u",
- PVRProcDirRoot, ui32PID));
- return NULL;
- }
- }
- }
-
- return CreateProcEntryInDirSeq(psPerProc->psProcDir, name, data, next_handler,
- show_handler,off2element_handler,startstop_handler,whandler);
-}
-
-
-IMG_VOID RemoveProcEntrySeq( struct proc_dir_entry* proc_entry )
-{
- if (dir)
- {
- void* data = proc_entry->data ;
- PVR_DPF((PVR_DBG_MESSAGE, "Removing /proc/%s/%s", PVRProcDirRoot, proc_entry->name));
-
- remove_proc_entry(proc_entry->name, dir);
- if( data)
- kfree( data );
-
- }
-}
-
-IMG_VOID RemovePerProcessProcEntrySeq(struct proc_dir_entry* proc_entry)
-{
- PVRSRV_ENV_PER_PROCESS_DATA *psPerProc;
-
- psPerProc = LinuxTerminatingProcessPrivateData();
- if (!psPerProc)
- {
- psPerProc = PVRSRVFindPerProcessPrivateData();
- if (!psPerProc)
- {
- PVR_DPF((PVR_DBG_ERROR, "CreatePerProcessProcEntries: can't "
- "remove %s, no per process data", proc_entry->name));
- return;
- }
- }
-
- if (psPerProc->psProcDir)
- {
- void* data = proc_entry->data ;
- PVR_DPF((PVR_DBG_MESSAGE, "Removing proc entry %s from %s", proc_entry->name, psPerProc->psProcDir->name));
-
- remove_proc_entry(proc_entry->name, psPerProc->psProcDir);
- if(data)
- kfree( data );
- }
-}
-
-#endif
-
-static IMG_INT pvr_read_proc(IMG_CHAR *page, IMG_CHAR **start, off_t off,
- IMG_INT count, IMG_INT *eof, IMG_VOID *data)
-{
- pvr_read_proc_t *pprn = (pvr_read_proc_t *)data;
-
- off_t len = pprn (page, (size_t)count, off);
-
- if (len == END_OF_FILE)
- {
- len = 0;
- *eof = 1;
- }
- else if (!len)
- {
- *start = (IMG_CHAR *) 0;
- }
- else
- {
- *start = (IMG_CHAR *) 1;
- }
-
- return len;
-}
-
-
-static IMG_INT CreateProcEntryInDir(struct proc_dir_entry *pdir, const IMG_CHAR * name, read_proc_t rhandler, write_proc_t whandler, IMG_VOID *data)
-{
- struct proc_dir_entry * file;
- mode_t mode;
-
- if (!pdir)
- {
- PVR_DPF((PVR_DBG_ERROR, "CreateProcEntryInDir: parent directory doesn't exist"));
-
- return -ENOMEM;
- }
-
- mode = S_IFREG;
-
- if (rhandler)
- {
- mode |= S_IRUGO;
- }
-
- if (whandler)
- {
- mode |= S_IWUSR;
- }
-
- file = create_proc_entry(name, mode, pdir);
-
- if (file)
- {
- file->read_proc = rhandler;
- file->write_proc = whandler;
- file->data = data;
-
- PVR_DPF((PVR_DBG_MESSAGE, "Created proc entry %s in %s", name, pdir->name));
-
- return 0;
- }
-
- PVR_DPF((PVR_DBG_ERROR, "CreateProcEntry: cannot create proc entry %s in %s", name, pdir->name));
-
- return -ENOMEM;
-}
-
-
-IMG_INT CreateProcEntry(const IMG_CHAR * name, read_proc_t rhandler, write_proc_t whandler, IMG_VOID *data)
-{
- return CreateProcEntryInDir(dir, name, rhandler, whandler, data);
-}
-
-
-IMG_INT CreatePerProcessProcEntry(const IMG_CHAR * name, read_proc_t rhandler, write_proc_t whandler, IMG_VOID *data)
-{
- PVRSRV_ENV_PER_PROCESS_DATA *psPerProc;
- IMG_UINT32 ui32PID;
-
- if (!dir)
- {
- PVR_DPF((PVR_DBG_ERROR, "CreatePerProcessProcEntries: /proc/%s doesn't exist", PVRProcDirRoot));
-
- return -ENOMEM;
- }
-
- ui32PID = OSGetCurrentProcessIDKM();
-
- psPerProc = PVRSRVPerProcessPrivateData(ui32PID);
- if (!psPerProc)
- {
- PVR_DPF((PVR_DBG_ERROR, "CreatePerProcessProcEntries: no per process data"));
-
- return -ENOMEM;
- }
-
- if (!psPerProc->psProcDir)
- {
- IMG_CHAR dirname[16];
- IMG_INT ret;
-
- ret = snprintf(dirname, sizeof(dirname), "%lu", ui32PID);
-
- if (ret <=0 || ret >= (IMG_INT)sizeof(dirname))
- {
- PVR_DPF((PVR_DBG_ERROR, "CreatePerProcessProcEntries: couldn't generate per process proc directory name \"%u\"", ui32PID));
-
- return -ENOMEM;
- }
- else
- {
- psPerProc->psProcDir = proc_mkdir(dirname, dir);
- if (!psPerProc->psProcDir)
- {
- PVR_DPF((PVR_DBG_ERROR, "CreatePerProcessProcEntries: couldn't create per process proc directory /proc/%s/%u", PVRProcDirRoot, ui32PID));
-
- return -ENOMEM;
- }
- }
- }
-
- return CreateProcEntryInDir(psPerProc->psProcDir, name, rhandler, whandler, data);
-}
-
-
-IMG_INT CreateProcReadEntry(const IMG_CHAR * name, pvr_read_proc_t handler)
-{
- struct proc_dir_entry * file;
-
- if (!dir)
- {
- PVR_DPF((PVR_DBG_ERROR, "CreateProcReadEntry: cannot make proc entry /proc/%s/%s: no parent", PVRProcDirRoot, name));
-
- return -ENOMEM;
- }
-
- file = create_proc_read_entry (name, S_IFREG | S_IRUGO, dir, pvr_read_proc, (IMG_VOID *)handler);
-
- if (file)
- return 0;
-
- PVR_DPF((PVR_DBG_ERROR, "CreateProcReadEntry: cannot make proc entry /proc/%s/%s: no memory", PVRProcDirRoot, name));
-
- return -ENOMEM;
-}
-
-
-IMG_INT CreateProcEntries(IMG_VOID)
-{
- dir = proc_mkdir (PVRProcDirRoot, NULL);
-
- if (!dir)
- {
- PVR_DPF((PVR_DBG_ERROR, "CreateProcEntries: cannot make /proc/%s directory", PVRProcDirRoot));
-
- return -ENOMEM;
- }
-
-#ifdef PVR_PROC_USE_SEQ_FILE
- g_pProcQueue = CreateProcReadEntrySeq("queue", NULL, NULL, ProcSeqShowQueue, ProcSeqOff2ElementQueue, NULL);
- g_pProcVersion = CreateProcReadEntrySeq("version", NULL, NULL, ProcSeqShowVersion, ProcSeq1ElementHeaderOff2Element, NULL);
- g_pProcSysNodes = CreateProcReadEntrySeq("nodes", NULL, NULL, ProcSeqShowSysNodes, ProcSeqOff2ElementSysNodes, NULL);
-
- if(!g_pProcQueue || !g_pProcVersion || !g_pProcSysNodes)
-#else
- if (CreateProcReadEntry("queue", QueuePrintQueues) ||
- CreateProcReadEntry("version", procDumpVersion) ||
- CreateProcReadEntry("nodes", procDumpSysNodes))
-#endif
- {
- PVR_DPF((PVR_DBG_ERROR, "CreateProcEntries: couldn't make /proc/%s files", PVRProcDirRoot));
-
- return -ENOMEM;
- }
-
-
-#ifdef PVR_DEBUG_EXT
-
-#ifdef PVR_PROC_USE_SEQ_FILE
- g_pProcDebugLevel = CreateProcEntrySeq("debug_level", NULL, NULL,
- ProcSeqShowDebugLevel,
- ProcSeq1ElementOff2Element, NULL,
- PVRDebugProcSetLevel);
- if(!g_pProcDebugLevel)
-#else
- if (CreateProcEntry ("debug_level", PVRDebugProcGetLevel, PVRDebugProcSetLevel, 0))
-#endif
- {
- PVR_DPF((PVR_DBG_ERROR, "CreateProcEntries: couldn't make /proc/%s/debug_level", PVRProcDirRoot));
-
- return -ENOMEM;
- }
-
-#ifdef PVR_MANUAL_POWER_CONTROL
-#ifdef PVR_PROC_USE_SEQ_FILE
- g_pProcPowerLevel = CreateProcEntrySeq("power_control", NULL, NULL,
- ProcSeqShowPowerLevel,
- ProcSeq1ElementOff2Element, NULL,
- PVRProcSetPowerLevel);
- if(!g_pProcPowerLevel)
-#else
- if (CreateProcEntry("power_control", PVRProcGetPowerLevel, PVRProcSetPowerLevel, 0))
-#endif
- {
- PVR_DPF((PVR_DBG_ERROR, "CreateProcEntries: couldn't make /proc/%s/power_control", PVRProcDirRoot));
-
- return -ENOMEM;
- }
-#endif
-#endif
-
- return 0;
-}
-
-
-IMG_VOID RemoveProcEntry(const IMG_CHAR * name)
-{
- if (dir)
- {
- remove_proc_entry(name, dir);
- PVR_DPF((PVR_DBG_MESSAGE, "Removing /proc/%s/%s", PVRProcDirRoot, name));
- }
-}
-
-
-IMG_VOID RemovePerProcessProcEntry(const IMG_CHAR *name)
-{
- PVRSRV_ENV_PER_PROCESS_DATA *psPerProc;
-
- psPerProc = LinuxTerminatingProcessPrivateData();
- if (!psPerProc)
- {
- psPerProc = PVRSRVFindPerProcessPrivateData();
- if (!psPerProc)
- {
- PVR_DPF((PVR_DBG_ERROR, "CreatePerProcessProcEntries: can't "
- "remove %s, no per process data", name));
- return;
- }
- }
-
- if (psPerProc->psProcDir)
- {
- remove_proc_entry(name, psPerProc->psProcDir);
-
- PVR_DPF((PVR_DBG_MESSAGE, "Removing proc entry %s from %s", name, psPerProc->psProcDir->name));
- }
-}
-
-
-IMG_VOID RemovePerProcessProcDir(PVRSRV_ENV_PER_PROCESS_DATA *psPerProc)
-{
- if (psPerProc->psProcDir)
- {
- while (psPerProc->psProcDir->subdir)
- {
- PVR_DPF((PVR_DBG_WARNING, "Belatedly removing /proc/%s/%s/%s", PVRProcDirRoot, psPerProc->psProcDir->name, psPerProc->psProcDir->subdir->name));
-
- RemoveProcEntry(psPerProc->psProcDir->subdir->name);
- }
- RemoveProcEntry(psPerProc->psProcDir->name);
- }
-}
-
-IMG_VOID RemoveProcEntries(IMG_VOID)
-{
-#ifdef PVR_DEBUG_EXT
-
-#ifdef PVR_PROC_USE_SEQ_FILE
- RemoveProcEntrySeq( g_pProcDebugLevel );
-#else
- RemoveProcEntry("debug_level");
-#endif
-
-#ifdef PVR_MANUAL_POWER_CONTROL
-#ifdef PVR_PROC_USE_SEQ_FILE
- RemoveProcEntrySeq( g_pProcPowerLevel );
-#else
- RemoveProcEntry("power_control");
-#endif
-#endif
-
-#endif
-
-#ifdef PVR_PROC_USE_SEQ_FILE
- RemoveProcEntrySeq(g_pProcQueue);
- RemoveProcEntrySeq(g_pProcVersion);
- RemoveProcEntrySeq(g_pProcSysNodes);
-#else
- RemoveProcEntry("queue");
- RemoveProcEntry("version");
- RemoveProcEntry("nodes");
-#endif
-
- while (dir->subdir)
- {
- PVR_DPF((PVR_DBG_WARNING, "Belatedly removing /proc/%s/%s", PVRProcDirRoot, dir->subdir->name));
-
- RemoveProcEntry(dir->subdir->name);
- }
-
- remove_proc_entry(PVRProcDirRoot, NULL);
-}
-
-
-#ifdef PVR_PROC_USE_SEQ_FILE
-
-static void ProcSeqShowVersion(struct seq_file *sfile,void* el)
-{
- SYS_DATA * psSysData;
- IMG_CHAR *pszSystemVersionString = "None";
-
- if(el == PVR_PROC_SEQ_START_TOKEN)
- {
- seq_printf( sfile,
- "Version %s (%s) %s\n",
- PVRVERSION_STRING,
- PVR_BUILD_TYPE, PVR_BUILD_DIR);
- return;
- }
-
- SysAcquireData(&psSysData);
-
- if(psSysData->pszVersionString)
- {
- pszSystemVersionString = psSysData->pszVersionString;
- }
-
- seq_printf( sfile, "System Version String: %s\n", pszSystemVersionString);
-}
-
-#else
-
-static off_t procDumpVersion(IMG_CHAR *buf, size_t size, off_t off)
-{
- SYS_DATA *psSysData;
-
- if (off == 0)
- {
- return printAppend(buf, size, 0,
- "Version %s (%s) %s\n",
- PVRVERSION_STRING,
- PVR_BUILD_TYPE, PVR_BUILD_DIR);
- }
-
- SysAcquireData(&psSysData)
-
- if (off == 1)
- {
- IMG_CHAR *pszSystemVersionString = "None";
-
- if(psSysData->pszVersionString)
- {
- pszSystemVersionString = psSysData->pszVersionString;
- }
-
- if(strlen(pszSystemVersionString)
- + strlen("System Version String: \n")
- + 1 > size)
- {
- return 0;
- }
- return printAppend(buf, size, 0,
- "System Version String: %s\n",
- pszSystemVersionString);
- }
-
- return END_OF_FILE;
-}
-
-#endif
-
-
-static const IMG_CHAR *deviceTypeToString(PVRSRV_DEVICE_TYPE deviceType)
-{
- switch (deviceType)
- {
- default:
- {
- static IMG_CHAR text[10];
-
- sprintf(text, "?%x", (IMG_UINT)deviceType);
-
- return text;
- }
- }
-}
-
-
-static const IMG_CHAR *deviceClassToString(PVRSRV_DEVICE_CLASS deviceClass)
-{
- switch (deviceClass)
- {
- case PVRSRV_DEVICE_CLASS_3D:
- {
- return "3D";
- }
- case PVRSRV_DEVICE_CLASS_DISPLAY:
- {
- return "display";
- }
- case PVRSRV_DEVICE_CLASS_BUFFER:
- {
- return "buffer";
- }
- default:
- {
- static IMG_CHAR text[10];
-
- sprintf(text, "?%x", (IMG_UINT)deviceClass);
- return text;
- }
- }
-}
-
-IMG_VOID* DecOffPsDev_AnyVaCb(PVRSRV_DEVICE_NODE *psNode, va_list va)
-{
- off_t *pOff = va_arg(va, off_t*);
- if (--(*pOff))
- {
- return IMG_NULL;
- }
- else
- {
- return psNode;
- }
-}
-
-#ifdef PVR_PROC_USE_SEQ_FILE
-
-static void ProcSeqShowSysNodes(struct seq_file *sfile,void* el)
-{
- SYS_DATA * psSysData;
- PVRSRV_DEVICE_NODE *psDevNode = (PVRSRV_DEVICE_NODE*)el;
-
- if(el == PVR_PROC_SEQ_START_TOKEN)
- {
- seq_printf( sfile,
- "Registered nodes\n"
- "Addr Type Class Index Ref pvDev Size Res\n");
- return;
- }
-
- SysAcquireData(&psSysData);
-
- seq_printf( sfile,
- "%p %-8s %-8s %4d %2lu %p %3lu %p\n",
- psDevNode,
- deviceTypeToString(psDevNode->sDevId.eDeviceType),
- deviceClassToString(psDevNode->sDevId.eDeviceClass),
- psDevNode->sDevId.eDeviceClass,
- psDevNode->ui32RefCount,
- psDevNode->pvDevice,
- psDevNode->ui32pvDeviceSize,
- psDevNode->hResManContext);
-
-}
-
-static void* ProcSeqOff2ElementSysNodes(struct seq_file * sfile, loff_t off)
-{
- SYS_DATA *psSysData;
- PVRSRV_DEVICE_NODE *psDevNode;
- if(!off)
- {
- return PVR_PROC_SEQ_START_TOKEN;
- }
-
- SysAcquireData(&psSysData);
-
-
- psDevNode = (PVRSRV_DEVICE_NODE*)
- List_PVRSRV_DEVICE_NODE_Any_va(psSysData->psDeviceNodeList,
- DecOffPsDev_AnyVaCb,
- &off);
-
-
- return (void*)psDevNode;
-}
-
-#else
-
-static
-off_t procDumpSysNodes(IMG_CHAR *buf, size_t size, off_t off)
-{
- SYS_DATA *psSysData;
- PVRSRV_DEVICE_NODE *psDevNode;
- off_t len;
-
-
- if (size < 80)
- {
- return 0;
- }
-
- if (off == 0)
- {
- return printAppend(buf, size, 0,
- "Registered nodes\n"
- "Addr Type Class Index Ref pvDev Size Res\n");
- }
-
- SysAcquireData(&psSysData);
-
-
- psDevNode = (PVRSRV_DEVICE_NODE*)
- List_PVRSRV_DEVICE_NODE_Any_va(psSysData->psDeviceNodeList,
- DecOffPsDev_AnyVaCb,
- &off);
-
- if (!psDevNode)
- {
- return END_OF_FILE;
- }
-
- len = printAppend(buf, size, 0,
- "%p %-8s %-8s %4d %2lu %p %3lu %p\n",
- psDevNode,
- deviceTypeToString(psDevNode->sDevId.eDeviceType),
- deviceClassToString(psDevNode->sDevId.eDeviceClass),
- psDevNode->sDevId.eDeviceClass,
- psDevNode->ui32RefCount,
- psDevNode->pvDevice,
- psDevNode->ui32pvDeviceSize,
- psDevNode->hResManContext);
- return (len);
-}
-
-#endif
-
+++ /dev/null
-/**********************************************************************
- *
- * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful but, except
- * as otherwise stated in writing, 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.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK
- *
- ******************************************************************************/
-
-#ifndef __SERVICES_PROC_H__
-#define __SERVICES_PROC_H__
-
-#include <asm/system.h>
-#include <linux/proc_fs.h>
-#include <linux/seq_file.h>
-
-#define END_OF_FILE (off_t) -1
-
-typedef off_t (pvr_read_proc_t)(IMG_CHAR *, size_t, off_t);
-
-
-#ifdef PVR_PROC_USE_SEQ_FILE
-#define PVR_PROC_SEQ_START_TOKEN (void*)1
-typedef void* (pvr_next_proc_seq_t)(struct seq_file *,void*,loff_t);
-typedef void* (pvr_off2element_proc_seq_t)(struct seq_file *, loff_t);
-typedef void (pvr_show_proc_seq_t)(struct seq_file *,void*);
-typedef void (pvr_startstop_proc_seq_t)(struct seq_file *, IMG_BOOL start);
-
-typedef struct _PVR_PROC_SEQ_HANDLERS_ {
- pvr_next_proc_seq_t *next;
- pvr_show_proc_seq_t *show;
- pvr_off2element_proc_seq_t *off2element;
- pvr_startstop_proc_seq_t *startstop;
- IMG_VOID *data;
-} PVR_PROC_SEQ_HANDLERS;
-
-
-void* ProcSeq1ElementOff2Element(struct seq_file *sfile, loff_t off);
-
-void* ProcSeq1ElementHeaderOff2Element(struct seq_file *sfile, loff_t off);
-
-
-#endif
-
-off_t printAppend(IMG_CHAR * buffer, size_t size, off_t off, const IMG_CHAR * format, ...)
- __attribute__((format(printf, 4, 5)));
-
-IMG_INT CreateProcEntries(IMG_VOID);
-
-IMG_INT CreateProcReadEntry (const IMG_CHAR * name, pvr_read_proc_t handler);
-
-IMG_INT CreateProcEntry(const IMG_CHAR * name, read_proc_t rhandler, write_proc_t whandler, IMG_VOID *data);
-
-IMG_INT CreatePerProcessProcEntry(const IMG_CHAR * name, read_proc_t rhandler, write_proc_t whandler, IMG_VOID *data);
-
-IMG_VOID RemoveProcEntry(const IMG_CHAR * name);
-
-IMG_VOID RemovePerProcessProcEntry(const IMG_CHAR * name);
-
-IMG_VOID RemoveProcEntries(IMG_VOID);
-
-#ifdef PVR_PROC_USE_SEQ_FILE
-struct proc_dir_entry* CreateProcReadEntrySeq (
- const IMG_CHAR* name,
- IMG_VOID* data,
- pvr_next_proc_seq_t next_handler,
- pvr_show_proc_seq_t show_handler,
- pvr_off2element_proc_seq_t off2element_handler,
- pvr_startstop_proc_seq_t startstop_handler
- );
-
-struct proc_dir_entry* CreateProcEntrySeq (
- const IMG_CHAR* name,
- IMG_VOID* data,
- pvr_next_proc_seq_t next_handler,
- pvr_show_proc_seq_t show_handler,
- pvr_off2element_proc_seq_t off2element_handler,
- pvr_startstop_proc_seq_t startstop_handler,
- write_proc_t whandler
- );
-
-struct proc_dir_entry* CreatePerProcessProcEntrySeq (
- const IMG_CHAR* name,
- IMG_VOID* data,
- pvr_next_proc_seq_t next_handler,
- pvr_show_proc_seq_t show_handler,
- pvr_off2element_proc_seq_t off2element_handler,
- pvr_startstop_proc_seq_t startstop_handler,
- write_proc_t whandler
- );
-
-
-IMG_VOID RemoveProcEntrySeq(struct proc_dir_entry* proc_entry);
-IMG_VOID RemovePerProcessProcEntrySeq(struct proc_dir_entry* proc_entry);
-
-#endif
-
-#endif
+++ /dev/null
-/**********************************************************************
- *
- * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful but, except
- * as otherwise stated in writing, 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.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK
- *
- ******************************************************************************/
-
-#include "img_defs.h"
-#include "services.h"
-#include "pvr_bridge.h"
-#include "perproc.h"
-#include "syscommon.h"
-#include "pvr_debug.h"
-#include "proc.h"
-#include "private_data.h"
-#include "linkage.h"
-#include "pvr_bridge_km.h"
-
-#include <linux/mutex.h>
-
-#if defined(SUPPORT_DRI_DRM)
-#include <drm/drmP.h>
-#include "pvr_drm.h"
-#if defined(PVR_SECURE_DRM_AUTH_EXPORT)
-#include "env_perproc.h"
-#endif
-#endif
-
-#if defined(SUPPORT_VGX)
-#include "vgx_bridge.h"
-#endif
-
-#if defined(SUPPORT_SGX)
-#include "sgx_bridge.h"
-#endif
-
-#include "bridged_pvr_bridge.h"
-
-#ifdef MODULE_TEST
-#include "pvr_test_bridge.h"
-#include "kern_test.h"
-#endif
-
-
-#if defined(SUPPORT_DRI_DRM)
-#define PRIVATE_DATA(pFile) ((pFile)->driver_priv)
-#else
-#define PRIVATE_DATA(pFile) ((pFile)->private_data)
-#endif
-
-#if defined(DEBUG_BRIDGE_KM)
-
-#ifdef PVR_PROC_USE_SEQ_FILE
-static struct proc_dir_entry *g_ProcBridgeStats =0;
-static void* ProcSeqNextBridgeStats(struct seq_file *sfile,void* el,loff_t off);
-static void ProcSeqShowBridgeStats(struct seq_file *sfile,void* el);
-static void* ProcSeqOff2ElementBridgeStats(struct seq_file * sfile, loff_t off);
-static void ProcSeqStartstopBridgeStats(struct seq_file *sfile,IMG_BOOL start);
-
-#else
-static off_t printLinuxBridgeStats(IMG_CHAR * buffer, size_t size, off_t off);
-#endif
-
-#endif
-
-extern struct mutex gPVRSRVLock;
-
-#if defined(SUPPORT_MEMINFO_IDS)
-static IMG_UINT64 ui64Stamp;
-#endif
-
-PVRSRV_ERROR
-LinuxBridgeInit(IMG_VOID)
-{
-#if defined(DEBUG_BRIDGE_KM)
- {
- IMG_INT iStatus;
-#ifdef PVR_PROC_USE_SEQ_FILE
- g_ProcBridgeStats = CreateProcReadEntrySeq(
- "bridge_stats",
- NULL,
- ProcSeqNextBridgeStats,
- ProcSeqShowBridgeStats,
- ProcSeqOff2ElementBridgeStats,
- ProcSeqStartstopBridgeStats
- );
- iStatus = !g_ProcBridgeStats ? -1 : 0;
-#else
- iStatus = CreateProcReadEntry("bridge_stats", printLinuxBridgeStats);
-#endif
-
- if(iStatus!=0)
- {
- return PVRSRV_ERROR_OUT_OF_MEMORY;
- }
- }
-#endif
- return CommonBridgeInit();
-}
-
-IMG_VOID
-LinuxBridgeDeInit(IMG_VOID)
-{
-#if defined(DEBUG_BRIDGE_KM)
-#ifdef PVR_PROC_USE_SEQ_FILE
- RemoveProcEntrySeq(g_ProcBridgeStats);
-#else
- RemoveProcEntry("bridge_stats");
-#endif
-#endif
-}
-
-#if defined(DEBUG_BRIDGE_KM)
-
-#ifdef PVR_PROC_USE_SEQ_FILE
-
-static void ProcSeqStartstopBridgeStats(struct seq_file *sfile,IMG_BOOL start)
-{
- if(start)
- {
- mutex_lock(&gPVRSRVLock);
- }
- else
- {
- mutex_unlock(&gPVRSRVLock);
- }
-}
-
-
-static void* ProcSeqOff2ElementBridgeStats(struct seq_file *sfile, loff_t off)
-{
- if(!off)
- {
- return PVR_PROC_SEQ_START_TOKEN;
- }
-
- if(off > BRIDGE_DISPATCH_TABLE_ENTRY_COUNT)
- {
- return (void*)0;
- }
-
-
- return (void*)&g_BridgeDispatchTable[off-1];
-}
-
-static void* ProcSeqNextBridgeStats(struct seq_file *sfile,void* el,loff_t off)
-{
- return ProcSeqOff2ElementBridgeStats(sfile,off);
-}
-
-
-static void ProcSeqShowBridgeStats(struct seq_file *sfile,void* el)
-{
- PVRSRV_BRIDGE_DISPATCH_TABLE_ENTRY *psEntry = ( PVRSRV_BRIDGE_DISPATCH_TABLE_ENTRY*)el;
-
- if(el == PVR_PROC_SEQ_START_TOKEN)
- {
- seq_printf(sfile,
- "Total ioctl call count = %lu\n"
- "Total number of bytes copied via copy_from_user = %lu\n"
- "Total number of bytes copied via copy_to_user = %lu\n"
- "Total number of bytes copied via copy_*_user = %lu\n\n"
- "%-45s | %-40s | %10s | %20s | %10s\n",
- g_BridgeGlobalStats.ui32IOCTLCount,
- g_BridgeGlobalStats.ui32TotalCopyFromUserBytes,
- g_BridgeGlobalStats.ui32TotalCopyToUserBytes,
- g_BridgeGlobalStats.ui32TotalCopyFromUserBytes+g_BridgeGlobalStats.ui32TotalCopyToUserBytes,
- "Bridge Name",
- "Wrapper Function",
- "Call Count",
- "copy_from_user Bytes",
- "copy_to_user Bytes"
- );
- return;
- }
-
- seq_printf(sfile,
- "%-45s %-40s %-10lu %-20lu %-10lu\n",
- psEntry->pszIOCName,
- psEntry->pszFunctionName,
- psEntry->ui32CallCount,
- psEntry->ui32CopyFromUserTotalBytes,
- psEntry->ui32CopyToUserTotalBytes);
-}
-
-#else
-
-static off_t
-printLinuxBridgeStats(IMG_CHAR * buffer, size_t count, off_t off)
-{
- PVRSRV_BRIDGE_DISPATCH_TABLE_ENTRY *psEntry;
- off_t Ret;
-
- mutex_lock(&gPVRSRVLock);
-
- if(!off)
- {
- if(count < 500)
- {
- Ret = 0;
- goto unlock_and_return;
- }
- Ret = printAppend(buffer, count, 0,
- "Total ioctl call count = %lu\n"
- "Total number of bytes copied via copy_from_user = %lu\n"
- "Total number of bytes copied via copy_to_user = %lu\n"
- "Total number of bytes copied via copy_*_user = %lu\n\n"
- "%-45s | %-40s | %10s | %20s | %10s\n",
- g_BridgeGlobalStats.ui32IOCTLCount,
- g_BridgeGlobalStats.ui32TotalCopyFromUserBytes,
- g_BridgeGlobalStats.ui32TotalCopyToUserBytes,
- g_BridgeGlobalStats.ui32TotalCopyFromUserBytes+g_BridgeGlobalStats.ui32TotalCopyToUserBytes,
- "Bridge Name",
- "Wrapper Function",
- "Call Count",
- "copy_from_user Bytes",
- "copy_to_user Bytes"
- );
- goto unlock_and_return;
- }
-
- if(off > BRIDGE_DISPATCH_TABLE_ENTRY_COUNT)
- {
- Ret = END_OF_FILE;
- goto unlock_and_return;
- }
-
- if(count < 300)
- {
- Ret = 0;
- goto unlock_and_return;
- }
-
- psEntry = &g_BridgeDispatchTable[off-1];
- Ret = printAppend(buffer, count, 0,
- "%-45s %-40s %-10lu %-20lu %-10lu\n",
- psEntry->pszIOCName,
- psEntry->pszFunctionName,
- psEntry->ui32CallCount,
- psEntry->ui32CopyFromUserTotalBytes,
- psEntry->ui32CopyToUserTotalBytes);
-
-unlock_and_return:
- mutex_unlock(&gPVRSRVLock);
- return Ret;
-}
-#endif
-#endif
-
-
-
-#if defined(SUPPORT_DRI_DRM)
-IMG_INT
-PVRSRV_BridgeDispatchKM(struct drm_device *dev, IMG_VOID *arg, struct drm_file *pFile)
-#else
-IMG_INT32
-PVRSRV_BridgeDispatchKM(struct file *pFile, IMG_UINT unref__ ioctlCmd, IMG_UINT32 arg)
-#endif
-{
- IMG_UINT32 cmd;
-#if !defined(SUPPORT_DRI_DRM)
- PVRSRV_BRIDGE_PACKAGE *psBridgePackageUM = (PVRSRV_BRIDGE_PACKAGE *)arg;
- PVRSRV_BRIDGE_PACKAGE sBridgePackageKM;
-#endif
- PVRSRV_BRIDGE_PACKAGE *psBridgePackageKM;
- IMG_UINT32 ui32PID = OSGetCurrentProcessIDKM();
- PVRSRV_PER_PROCESS_DATA *psPerProc;
- IMG_INT err = -EFAULT;
-
- mutex_lock(&gPVRSRVLock);
-
-#if defined(SUPPORT_DRI_DRM)
- PVR_UNREFERENCED_PARAMETER(dev);
-
- psBridgePackageKM = (PVRSRV_BRIDGE_PACKAGE *)arg;
- PVR_ASSERT(psBridgePackageKM != IMG_NULL);
-#else
- PVR_UNREFERENCED_PARAMETER(ioctlCmd);
-
- psBridgePackageKM = &sBridgePackageKM;
-
- if(!OSAccessOK(PVR_VERIFY_WRITE,
- psBridgePackageUM,
- sizeof(PVRSRV_BRIDGE_PACKAGE)))
- {
- PVR_DPF((PVR_DBG_ERROR, "%s: Received invalid pointer to function arguments",
- __FUNCTION__));
-
- goto unlock_and_return;
- }
-
-
- if(OSCopyFromUser(IMG_NULL,
- psBridgePackageKM,
- psBridgePackageUM,
- sizeof(PVRSRV_BRIDGE_PACKAGE))
- != PVRSRV_OK)
- {
- goto unlock_and_return;
- }
-#endif
-
- cmd = psBridgePackageKM->ui32BridgeID;
-
-#if defined(MODULE_TEST)
- switch (cmd)
- {
- case PVRSRV_BRIDGE_SERVICES_TEST_MEM1:
- {
- PVRSRV_ERROR eError = MemTest1();
- if (psBridgePackageKM->ui32OutBufferSize == sizeof(PVRSRV_BRIDGE_RETURN))
- {
- PVRSRV_BRIDGE_RETURN* pReturn = (PVRSRV_BRIDGE_RETURN*)psBridgePackageKM->pvParamOut ;
- pReturn->eError = eError;
- }
- }
- err = 0;
- goto unlock_and_return;
- case PVRSRV_BRIDGE_SERVICES_TEST_MEM2:
- {
- PVRSRV_ERROR eError = MemTest2();
- if (psBridgePackageKM->ui32OutBufferSize == sizeof(PVRSRV_BRIDGE_RETURN))
- {
- PVRSRV_BRIDGE_RETURN* pReturn = (PVRSRV_BRIDGE_RETURN*)psBridgePackageKM->pvParamOut ;
- pReturn->eError = eError;
- }
- }
- err = 0;
- goto unlock_and_return;
-
- case PVRSRV_BRIDGE_SERVICES_TEST_RESOURCE:
- {
- PVRSRV_ERROR eError = ResourceTest();
- if (psBridgePackageKM->ui32OutBufferSize == sizeof(PVRSRV_BRIDGE_RETURN))
- {
- PVRSRV_BRIDGE_RETURN* pReturn = (PVRSRV_BRIDGE_RETURN*)psBridgePackageKM->pvParamOut ;
- pReturn->eError = eError;
- }
- }
- err = 0;
- goto unlock_and_return;
-
- case PVRSRV_BRIDGE_SERVICES_TEST_EVENTOBJECT:
- {
- PVRSRV_ERROR eError = EventObjectTest();
- if (psBridgePackageKM->ui32OutBufferSize == sizeof(PVRSRV_BRIDGE_RETURN))
- {
- PVRSRV_BRIDGE_RETURN* pReturn = (PVRSRV_BRIDGE_RETURN*)psBridgePackageKM->pvParamOut ;
- pReturn->eError = eError;
- }
- }
- err = 0;
- goto unlock_and_return;
-
- case PVRSRV_BRIDGE_SERVICES_TEST_MEMMAPPING:
- {
- PVRSRV_ERROR eError = MemMappingTest();
- if (psBridgePackageKM->ui32OutBufferSize == sizeof(PVRSRV_BRIDGE_RETURN))
- {
- PVRSRV_BRIDGE_RETURN* pReturn = (PVRSRV_BRIDGE_RETURN*)psBridgePackageKM->pvParamOut ;
- pReturn->eError = eError;
- }
- }
- err = 0;
- goto unlock_and_return;
-
- case PVRSRV_BRIDGE_SERVICES_TEST_PROCESSID:
- {
- PVRSRV_ERROR eError = ProcessIDTest();
- if (psBridgePackageKM->ui32OutBufferSize == sizeof(PVRSRV_BRIDGE_RETURN))
- {
- PVRSRV_BRIDGE_RETURN* pReturn = (PVRSRV_BRIDGE_RETURN*)psBridgePackageKM->pvParamOut ;
- pReturn->eError = eError;
- }
- }
- err = 0;
- goto unlock_and_return;
-
- case PVRSRV_BRIDGE_SERVICES_TEST_CLOCKUSWAITUS:
- {
- PVRSRV_ERROR eError = ClockusWaitusTest();
- if (psBridgePackageKM->ui32OutBufferSize == sizeof(PVRSRV_BRIDGE_RETURN))
- {
- PVRSRV_BRIDGE_RETURN* pReturn = (PVRSRV_BRIDGE_RETURN*)psBridgePackageKM->pvParamOut ;
- pReturn->eError = eError;
- }
- }
- err = 0;
- goto unlock_and_return;
-
- case PVRSRV_BRIDGE_SERVICES_TEST_TIMER:
- {
- PVRSRV_ERROR eError = TimerTest();
- if (psBridgePackageKM->ui32OutBufferSize == sizeof(PVRSRV_BRIDGE_RETURN))
- {
- PVRSRV_BRIDGE_RETURN* pReturn = (PVRSRV_BRIDGE_RETURN*)psBridgePackageKM->pvParamOut ;
- pReturn->eError = eError;
- }
- }
- err = 0;
- goto unlock_and_return;
-
- case PVRSRV_BRIDGE_SERVICES_TEST_PRIVSRV:
- {
- PVRSRV_ERROR eError = PrivSrvTest();
- if (psBridgePackageKM->ui32OutBufferSize == sizeof(PVRSRV_BRIDGE_RETURN))
- {
- PVRSRV_BRIDGE_RETURN* pReturn = (PVRSRV_BRIDGE_RETURN*)psBridgePackageKM->pvParamOut ;
- pReturn->eError = eError;
- }
- }
- err = 0;
- goto unlock_and_return;
- case PVRSRV_BRIDGE_SERVICES_TEST_COPYDATA:
- {
- IMG_UINT32 ui32PID;
- PVRSRV_PER_PROCESS_DATA *psPerProc;
- PVRSRV_ERROR eError;
-
- ui32PID = OSGetCurrentProcessIDKM();
-
- PVRSRVTrace("PVRSRV_BRIDGE_SERVICES_TEST_COPYDATA %d", ui32PID);
-
- psPerProc = PVRSRVPerProcessData(ui32PID);
-
- eError = CopyDataTest(psBridgePackageKM->pvParamIn, psBridgePackageKM->pvParamOut, psPerProc);
-
- *(PVRSRV_ERROR*)psBridgePackageKM->pvParamOut = eError;
- err = 0;
- goto unlock_and_return;
- }
-
-
- case PVRSRV_BRIDGE_SERVICES_TEST_POWERMGMT:
- {
- PVRSRV_ERROR eError = PowerMgmtTest();
- if (psBridgePackageKM->ui32OutBufferSize == sizeof(PVRSRV_BRIDGE_RETURN))
- {
- PVRSRV_BRIDGE_RETURN* pReturn = (PVRSRV_BRIDGE_RETURN*)psBridgePackageKM->pvParamOut ;
- pReturn->eError = eError;
- }
- }
- err = 0;
- goto unlock_and_return;
-
- }
-#endif
-
- if(cmd != PVRSRV_BRIDGE_CONNECT_SERVICES)
- {
- PVRSRV_ERROR eError;
-
- eError = PVRSRVLookupHandle(KERNEL_HANDLE_BASE,
- (IMG_PVOID *)&psPerProc,
- psBridgePackageKM->hKernelServices,
- PVRSRV_HANDLE_TYPE_PERPROC_DATA);
- if(eError != PVRSRV_OK)
- {
- PVR_DPF((PVR_DBG_ERROR, "%s: Invalid kernel services handle (%d)",
- __FUNCTION__, eError));
- goto unlock_and_return;
- }
-
- if(psPerProc->ui32PID != ui32PID)
- {
- PVR_DPF((PVR_DBG_ERROR, "%s: Process %d tried to access data "
- "belonging to process %d", __FUNCTION__, ui32PID,
- psPerProc->ui32PID));
- goto unlock_and_return;
- }
- }
- else
- {
-
- psPerProc = PVRSRVPerProcessData(ui32PID);
- if(psPerProc == IMG_NULL)
- {
- PVR_DPF((PVR_DBG_ERROR, "PVRSRV_BridgeDispatchKM: "
- "Couldn't create per-process data area"));
- goto unlock_and_return;
- }
- }
-
- psBridgePackageKM->ui32BridgeID = PVRSRV_GET_BRIDGE_ID(psBridgePackageKM->ui32BridgeID);
-
-#if defined(PVR_SECURE_FD_EXPORT)
- switch(cmd)
- {
- case PVRSRV_BRIDGE_EXPORT_DEVICEMEM:
- {
- PVRSRV_FILE_PRIVATE_DATA *psPrivateData = PRIVATE_DATA(pFile);
-
- if(psPrivateData->hKernelMemInfo)
- {
- PVR_DPF((PVR_DBG_ERROR, "%s: Can only export one MemInfo "
- "per file descriptor", __FUNCTION__));
- err = -EINVAL;
- goto unlock_and_return;
- }
- break;
- }
-
- case PVRSRV_BRIDGE_MAP_DEV_MEMORY:
- {
- PVRSRV_BRIDGE_IN_MAP_DEV_MEMORY *psMapDevMemIN =
- (PVRSRV_BRIDGE_IN_MAP_DEV_MEMORY *)psBridgePackageKM->pvParamIn;
- PVRSRV_FILE_PRIVATE_DATA *psPrivateData = PRIVATE_DATA(pFile);
-
- if(!psPrivateData->hKernelMemInfo)
- {
- PVR_DPF((PVR_DBG_ERROR, "%s: File descriptor has no "
- "associated MemInfo handle", __FUNCTION__));
- err = -EINVAL;
- goto unlock_and_return;
- }
-
- psMapDevMemIN->hKernelMemInfo = psPrivateData->hKernelMemInfo;
- break;
- }
-
- default:
- {
- PVRSRV_FILE_PRIVATE_DATA *psPrivateData = PRIVATE_DATA(pFile);
-
- if(psPrivateData->hKernelMemInfo)
- {
- PVR_DPF((PVR_DBG_ERROR, "%s: Import/Export handle tried "
- "to use privileged service", __FUNCTION__));
- goto unlock_and_return;
- }
- break;
- }
- }
-#endif
-#if defined(SUPPORT_DRI_DRM) && defined(PVR_SECURE_DRM_AUTH_EXPORT)
- switch(cmd)
- {
- case PVRSRV_BRIDGE_MAP_DEV_MEMORY:
- case PVRSRV_BRIDGE_MAP_DEVICECLASS_MEMORY:
- {
- PVRSRV_FILE_PRIVATE_DATA *psPrivateData;
- IMG_INT authenticated = pFile->authenticated;
- PVRSRV_ENV_PER_PROCESS_DATA *psEnvPerProc;
-
- if (authenticated)
- {
- break;
- }
-
-
- psEnvPerProc = (PVRSRV_ENV_PER_PROCESS_DATA *)PVRSRVProcessPrivateData(psPerProc);
- if (psEnvPerProc == IMG_NULL)
- {
- PVR_DPF((PVR_DBG_ERROR, "%s: Process private data not allocated", __FUNCTION__));
- err = -EFAULT;
- goto unlock_and_return;
- }
-
- list_for_each_entry(psPrivateData, &psEnvPerProc->sDRMAuthListHead, sDRMAuthListItem)
- {
- struct drm_file *psDRMFile = psPrivateData->psDRMFile;
-
- if (pFile->master == psDRMFile->master)
- {
- authenticated |= psDRMFile->authenticated;
- if (authenticated)
- {
- break;
- }
- }
- }
-
- if (!authenticated)
- {
- PVR_DPF((PVR_DBG_ERROR, "%s: Not authenticated for mapping device or device class memory", __FUNCTION__));
- err = -EPERM;
- goto unlock_and_return;
- }
- break;
- }
- default:
- break;
- }
-#endif
-
- err = BridgedDispatchKM(psPerProc, psBridgePackageKM);
- if(err != PVRSRV_OK)
- goto unlock_and_return;
-
- switch(cmd)
- {
-#if defined(PVR_SECURE_FD_EXPORT)
- case PVRSRV_BRIDGE_EXPORT_DEVICEMEM:
- {
- PVRSRV_BRIDGE_OUT_EXPORTDEVICEMEM *psExportDeviceMemOUT =
- (PVRSRV_BRIDGE_OUT_EXPORTDEVICEMEM *)psBridgePackageKM->pvParamOut;
- PVRSRV_FILE_PRIVATE_DATA *psPrivateData = PRIVATE_DATA(pFile);
-
- psPrivateData->hKernelMemInfo = psExportDeviceMemOUT->hMemInfo;
-#if defined(SUPPORT_MEMINFO_IDS)
- psExportDeviceMemOUT->ui64Stamp = psPrivateData->ui64Stamp = ++ui64Stamp;
-#endif
- break;
- }
-#endif
-
-#if defined(SUPPORT_MEMINFO_IDS)
- case PVRSRV_BRIDGE_MAP_DEV_MEMORY:
- {
- PVRSRV_BRIDGE_OUT_MAP_DEV_MEMORY *psMapDeviceMemoryOUT =
- (PVRSRV_BRIDGE_OUT_MAP_DEV_MEMORY *)psBridgePackageKM->pvParamOut;
- PVRSRV_FILE_PRIVATE_DATA *psPrivateData = PRIVATE_DATA(pFile);
- psMapDeviceMemoryOUT->sDstClientMemInfo.ui64Stamp = psPrivateData->ui64Stamp;
- break;
- }
-
- case PVRSRV_BRIDGE_MAP_DEVICECLASS_MEMORY:
- {
- PVRSRV_BRIDGE_OUT_MAP_DEVICECLASS_MEMORY *psDeviceClassMemoryOUT =
- (PVRSRV_BRIDGE_OUT_MAP_DEVICECLASS_MEMORY *)psBridgePackageKM->pvParamOut;
- psDeviceClassMemoryOUT->sClientMemInfo.ui64Stamp = ++ui64Stamp;
- break;
- }
-#endif
-
- default:
- break;
- }
-
-unlock_and_return:
- mutex_unlock(&gPVRSRVLock);
- return err;
-}
+++ /dev/null
-/**********************************************************************
- *
- * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful but, except
- * as otherwise stated in writing, 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.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK
- *
- ******************************************************************************/
-
-#include <asm/io.h>
-#include <asm/uaccess.h>
-#include <linux/kernel.h>
-#include <linux/hardirq.h>
-#include <linux/module.h>
-#include <linux/spinlock.h>
-#include <linux/tty.h>
-#include <linux/mutex.h>
-#include <stdarg.h>
-#include "img_types.h"
-#include "servicesext.h"
-#include "pvr_debug.h"
-#include "proc.h"
-#include "linkage.h"
-
-#if defined(PVRSRV_NEED_PVR_DPF)
-
-#define PVR_MAX_FILEPATH_LEN 256
-
-static IMG_UINT32 gPVRDebugLevel = DBGPRIV_WARNING;
-
-#endif
-
-#define PVR_MAX_MSG_LEN PVR_MAX_DEBUG_MESSAGE_LEN
-
-static IMG_CHAR gszBufferNonIRQ[PVR_MAX_MSG_LEN + 1];
-
-static IMG_CHAR gszBufferIRQ[PVR_MAX_MSG_LEN + 1];
-
-static struct mutex gsDebugMutexNonIRQ;
-
-static DEFINE_SPINLOCK(gsDebugLockIRQ);
-
-#define USE_SPIN_LOCK (in_interrupt() || !preemptible())
-
-static inline void GetBufferLock(unsigned long *pulLockFlags)
-{
- /* This is broken! */
- if (USE_SPIN_LOCK)
- {
- spin_lock_irqsave(&gsDebugLockIRQ, *pulLockFlags);
- }
- else
- {
- mutex_lock(&gsDebugMutexNonIRQ);
- }
-}
-
-static inline void ReleaseBufferLock(unsigned long ulLockFlags)
-{
- /* and this is even more broken */
- if (USE_SPIN_LOCK)
- {
- spin_unlock_irqrestore(&gsDebugLockIRQ, ulLockFlags);
- }
- else
- {
- mutex_unlock(&gsDebugMutexNonIRQ);
- }
-}
-
-static inline void SelectBuffer(IMG_CHAR **ppszBuf, IMG_UINT32 *pui32BufSiz)
-{
- if (USE_SPIN_LOCK)
- {
- *ppszBuf = gszBufferIRQ;
- *pui32BufSiz = sizeof(gszBufferIRQ);
- }
- else
- {
- *ppszBuf = gszBufferNonIRQ;
- *pui32BufSiz = sizeof(gszBufferNonIRQ);
- }
-}
-
-static IMG_BOOL VBAppend(IMG_CHAR *pszBuf, IMG_UINT32 ui32BufSiz, const IMG_CHAR* pszFormat, va_list VArgs)
-{
- IMG_UINT32 ui32Used;
- IMG_UINT32 ui32Space;
- IMG_INT32 i32Len;
-
- ui32Used = strlen(pszBuf);
- BUG_ON(ui32Used >= ui32BufSiz);
- ui32Space = ui32BufSiz - ui32Used;
-
- i32Len = vsnprintf(&pszBuf[ui32Used], ui32Space, pszFormat, VArgs);
- pszBuf[ui32BufSiz - 1] = 0;
-
-
- return (i32Len < 0 || i32Len >= ui32Space);
-}
-
-IMG_VOID PVRDPFInit(IMG_VOID)
-{
- mutex_init(&gsDebugMutexNonIRQ);
-}
-
-IMG_VOID PVRSRVReleasePrintf(const IMG_CHAR *pszFormat, ...)
-{
- va_list vaArgs;
- unsigned long ulLockFlags = 0;
- IMG_CHAR *pszBuf;
- IMG_UINT32 ui32BufSiz;
-
- SelectBuffer(&pszBuf, &ui32BufSiz);
-
- va_start(vaArgs, pszFormat);
-
- GetBufferLock(&ulLockFlags);
- strncpy (pszBuf, "PVR_K: ", (ui32BufSiz -1));
-
- if (VBAppend(pszBuf, ui32BufSiz, pszFormat, vaArgs))
- {
- printk(KERN_INFO "PVR_K:(Message Truncated): %s\n", pszBuf);
- }
- else
- {
- printk(KERN_INFO "%s\n", pszBuf);
- }
-
- ReleaseBufferLock(ulLockFlags);
- va_end(vaArgs);
-
-}
-
-#if defined(PVRSRV_NEED_PVR_ASSERT)
-
-IMG_VOID PVRSRVDebugAssertFail(const IMG_CHAR* pszFile, IMG_UINT32 uLine)
-{
- PVRSRVDebugPrintf(DBGPRIV_FATAL, pszFile, uLine, "Debug assertion failed!");
- BUG();
-}
-
-#endif
-
-#if defined(PVRSRV_NEED_PVR_TRACE)
-
-IMG_VOID PVRSRVTrace(const IMG_CHAR* pszFormat, ...)
-{
- va_list VArgs;
- unsigned long ulLockFlags = 0;
- IMG_CHAR *pszBuf;
- IMG_UINT32 ui32BufSiz;
-
- SelectBuffer(&pszBuf, &ui32BufSiz);
-
- va_start(VArgs, pszFormat);
-
- GetBufferLock(&ulLockFlags);
-
- strncpy(pszBuf, "PVR: ", (ui32BufSiz -1));
-
- if (VBAppend(pszBuf, ui32BufSiz, pszFormat, VArgs))
- {
- printk(KERN_INFO "PVR_K:(Message Truncated): %s\n", pszBuf);
- }
- else
- {
- printk(KERN_INFO "%s\n", pszBuf);
- }
-
- ReleaseBufferLock(ulLockFlags);
-
- va_end(VArgs);
-}
-
-#endif
-
-#if defined(PVRSRV_NEED_PVR_DPF)
-
-static IMG_BOOL BAppend(IMG_CHAR *pszBuf, IMG_UINT32 ui32BufSiz, const IMG_CHAR *pszFormat, ...)
-{
- va_list VArgs;
- IMG_BOOL bTrunc;
-
- va_start (VArgs, pszFormat);
-
- bTrunc = VBAppend(pszBuf, ui32BufSiz, pszFormat, VArgs);
-
- va_end (VArgs);
-
- return bTrunc;
-}
-
-IMG_VOID PVRSRVDebugPrintf (
- IMG_UINT32 ui32DebugLevel,
- const IMG_CHAR* pszFullFileName,
- IMG_UINT32 ui32Line,
- const IMG_CHAR* pszFormat,
- ...
- )
-{
- IMG_BOOL bTrace, bDebug;
- const IMG_CHAR *pszFileName = pszFullFileName;
- IMG_CHAR *pszLeafName;
-
- bTrace = gPVRDebugLevel & ui32DebugLevel & DBGPRIV_CALLTRACE;
- bDebug = ((gPVRDebugLevel & DBGPRIV_ALLLEVELS) >= ui32DebugLevel);
-
- if (bTrace || bDebug)
- {
- va_list vaArgs;
- unsigned long ulLockFlags = 0;
- IMG_CHAR *pszBuf;
- IMG_UINT32 ui32BufSiz;
-
- SelectBuffer(&pszBuf, &ui32BufSiz);
-
- va_start(vaArgs, pszFormat);
-
- GetBufferLock(&ulLockFlags);
-
-
- if (bDebug)
- {
- switch(ui32DebugLevel)
- {
- case DBGPRIV_FATAL:
- {
- strncpy (pszBuf, "PVR_K:(Fatal): ", (ui32BufSiz -1));
- break;
- }
- case DBGPRIV_ERROR:
- {
- strncpy (pszBuf, "PVR_K:(Error): ", (ui32BufSiz -1));
- break;
- }
- case DBGPRIV_WARNING:
- {
- strncpy (pszBuf, "PVR_K:(Warning): ", (ui32BufSiz -1));
- break;
- }
- case DBGPRIV_MESSAGE:
- {
- strncpy (pszBuf, "PVR_K:(Message): ", (ui32BufSiz -1));
- break;
- }
- case DBGPRIV_VERBOSE:
- {
- strncpy (pszBuf, "PVR_K:(Verbose): ", (ui32BufSiz -1));
- break;
- }
- default:
- {
- strncpy (pszBuf, "PVR_K:(Unknown message level)", (ui32BufSiz -1));
- break;
- }
- }
- }
- else
- {
- strncpy (pszBuf, "PVR_K: ", (ui32BufSiz -1));
- }
-
- if (VBAppend(pszBuf, ui32BufSiz, pszFormat, vaArgs))
- {
- printk(KERN_INFO "PVR_K:(Message Truncated): %s\n", pszBuf);
- }
- else
- {
-
- if (!bTrace)
- {
-#ifdef DEBUG_LOG_PATH_TRUNCATE
-
- static IMG_CHAR szFileNameRewrite[PVR_MAX_FILEPATH_LEN];
-
- IMG_CHAR* pszTruncIter;
- IMG_CHAR* pszTruncBackInter;
-
-
- pszFileName = pszFullFileName + strlen(DEBUG_LOG_PATH_TRUNCATE)+1;
-
-
- strncpy(szFileNameRewrite, pszFileName,PVR_MAX_FILEPATH_LEN);
-
- if(strlen(szFileNameRewrite) == PVR_MAX_FILEPATH_LEN-1) {
- IMG_CHAR szTruncateMassage[] = "FILENAME TRUNCATED";
- strcpy(szFileNameRewrite + (PVR_MAX_FILEPATH_LEN - 1 - strlen(szTruncateMassage)), szTruncateMassage);
- }
-
- pszTruncIter = szFileNameRewrite;
- while(*pszTruncIter++ != 0)
- {
- IMG_CHAR* pszNextStartPoint;
-
- if(
- !( ( *pszTruncIter == '/' && (pszTruncIter-4 >= szFileNameRewrite) ) &&
- ( *(pszTruncIter-1) == '.') &&
- ( *(pszTruncIter-2) == '.') &&
- ( *(pszTruncIter-3) == '/') )
- ) continue;
-
-
- pszTruncBackInter = pszTruncIter - 3;
- while(*(--pszTruncBackInter) != '/')
- {
- if(pszTruncBackInter <= szFileNameRewrite) break;
- }
- pszNextStartPoint = pszTruncBackInter;
-
-
- while(*pszTruncIter != 0)
- {
- *pszTruncBackInter++ = *pszTruncIter++;
- }
- *pszTruncBackInter = 0;
-
-
- pszTruncIter = pszNextStartPoint;
- }
-
- pszFileName = szFileNameRewrite;
-
- if(*pszFileName == '/') pszFileName++;
-#endif
-
-#if !defined(__sh__)
- pszLeafName = (IMG_CHAR *)strrchr (pszFileName, '\\');
-
- if (pszLeafName)
- {
- pszFileName = pszLeafName;
- }
-#endif
-
- if (BAppend(pszBuf, ui32BufSiz, " [%lu, %s]", ui32Line, pszFileName))
- {
- printk(KERN_INFO "PVR_K:(Message Truncated): %s\n", pszBuf);
- }
- else
- {
- printk(KERN_INFO "%s\n", pszBuf);
- }
- }
- else
- {
- printk(KERN_INFO "%s\n", pszBuf);
- }
- }
-
- ReleaseBufferLock(ulLockFlags);
-
- va_end (vaArgs);
- }
-}
-
-#endif
-
-#if defined(PVR_DEBUG_EXT)
-
-IMG_VOID PVRDebugSetLevel(IMG_UINT32 uDebugLevel)
-{
- printk(KERN_INFO "PVR: Setting Debug Level = 0x%x\n",(IMG_UINT)uDebugLevel);
-
- gPVRDebugLevel = uDebugLevel;
-}
-
-IMG_INT PVRDebugProcSetLevel(struct file *file, const IMG_CHAR *buffer, IMG_UINT32 count, IMG_VOID *data)
-{
-#define _PROC_SET_BUFFER_SZ 2
- IMG_CHAR data_buffer[_PROC_SET_BUFFER_SZ];
-
- if (count != _PROC_SET_BUFFER_SZ)
- {
- return -EINVAL;
- }
- else
- {
- if (copy_from_user(data_buffer, buffer, count))
- return -EINVAL;
- if (data_buffer[count - 1] != '\n')
- return -EINVAL;
- PVRDebugSetLevel(data_buffer[0] - '0');
- }
- return (count);
-}
-
-#ifdef PVR_PROC_USE_SEQ_FILE
-void ProcSeqShowDebugLevel(struct seq_file *sfile,void* el)
-{
- seq_printf(sfile, "%lu\n", gPVRDebugLevel);
-}
-
-#else
-IMG_INT PVRDebugProcGetLevel(IMG_CHAR *page, IMG_CHAR **start, off_t off, IMG_INT count, IMG_INT *eof, IMG_VOID *data)
-{
- if (off == 0) {
- *start = (IMG_CHAR *)1;
- return printAppend(page, count, 0, "%lu\n", gPVRDebugLevel);
- }
- *eof = 1;
- return 0;
-}
-#endif
-
-#endif
+++ /dev/null
-/**********************************************************************
- *
- * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful but, except
- * as otherwise stated in writing, 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.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK
- *
- ******************************************************************************/
-
-#if defined(SUPPORT_DRI_DRM)
-
-#include <linux/init.h>
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/version.h>
-#include <linux/fs.h>
-#include <linux/proc_fs.h>
-#include <linux/mutex.h>
-#include <asm/ioctl.h>
-#include <drm/drmP.h>
-#include <drm/drm.h>
-
-#include "img_defs.h"
-#include "services.h"
-#include "kerneldisplay.h"
-#include "kernelbuffer.h"
-#include "syscommon.h"
-#include "pvrmmap.h"
-#include "mm.h"
-#include "mmap.h"
-#include "pvr_debug.h"
-#include "srvkm.h"
-#include "perproc.h"
-#include "handle.h"
-#include "pvr_bridge_km.h"
-#include "pvr_bridge.h"
-#include "proc.h"
-#include "pvrmodule.h"
-#include "pvrversion.h"
-#include "lock.h"
-#include "linkage.h"
-#include "pvr_drm_shared.h"
-#include "pvr_drm.h"
-
-#define MAKENAME_HELPER(x, y) x ## y
-#define MAKENAME(x, y) MAKENAME_HELPER(x, y)
-
-#define PVR_DRM_NAME "pvrsrvkm"
-#define PVR_DRM_DESC "Imagination Technologies PVR DRM"
-
-#define PVR_PCI_IDS \
- {SYS_SGX_DEV_VENDOR_ID, SYS_SGX_DEV_DEVICE_ID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
- {0, 0, 0}
-
-struct pci_dev *gpsPVRLDMDev;
-struct drm_device *gpsPVRDRMDev;
-
-#define PVR_DRM_FILE struct drm_file *
-
-#if !defined(SUPPORT_DRI_DRM_EXT)
-static struct pci_device_id asPciIdList[] = {
- PVR_PCI_IDS
-};
-#endif
-
-IMG_INT PVRSRVDrmLoad(struct drm_device *dev, unsigned long flags)
-{
- IMG_INT iRes;
-
- PVR_TRACE(("PVRSRVDrmLoad"));
-
- gpsPVRDRMDev = dev;
- gpsPVRLDMDev = dev->pdev;
-
-#if defined(PDUMP)
- iRes = dbgdrv_init();
- if (iRes != 0)
- {
- return iRes;
- }
-#endif
-
- iRes = PVRCore_Init();
- if (iRes != 0)
- {
- goto exit_dbgdrv_cleanup;
- }
-
-#if defined(DISPLAY_CONTROLLER)
- iRes = PVR_DRM_MAKENAME(DISPLAY_CONTROLLER, _Init)(dev);
- if (iRes != 0)
- {
- goto exit_pvrcore_cleanup;
- }
-#endif
- return 0;
-
-#if defined(DISPLAY_CONTROLLER)
-exit_pvrcore_cleanup:
- PVRCore_Cleanup();
-#endif
-exit_dbgdrv_cleanup:
-#if defined(PDUMP)
- dbgdrv_cleanup();
-#endif
- return iRes;
-}
-
-IMG_INT PVRSRVDrmUnload(struct drm_device *dev)
-{
- PVR_TRACE(("PVRSRVDrmUnload"));
-
-#if defined(DISPLAY_CONTROLLER)
- PVR_DRM_MAKENAME(DISPLAY_CONTROLLER, _Cleanup)(dev);
-#endif
-
- PVRCore_Cleanup();
-
-#if defined(PDUMP)
- dbgdrv_cleanup();
-#endif
-
- return 0;
-}
-
-IMG_INT PVRSRVDrmOpen(struct drm_device *dev, struct drm_file *file)
-{
- return PVRSRVOpen(dev, file);
-}
-
-IMG_VOID PVRSRVDrmPostClose(struct drm_device *dev, struct drm_file *file)
-{
- PVRSRVRelease(dev, file);
-}
-
-DRI_DRM_STATIC IMG_INT
-PVRDRMIsMaster(struct drm_device *dev, IMG_VOID *arg, struct drm_file *pFile)
-{
- return 0;
-}
-
-#if defined(SUPPORT_DRI_DRM_EXT)
-IMG_INT
-PVRDRM_Dummy_ioctl(struct drm_device *dev, IMG_VOID *arg, struct drm_file *pFile)
-{
- return 0;
-}
-#endif
-
-static IMG_INT
-PVRDRMPCIBusIDField(struct drm_device *dev, IMG_UINT32 *pui32Field, IMG_UINT32 ui32FieldType)
-{
- struct pci_dev *psPCIDev = (struct pci_dev *)dev->pdev;
-
- switch (ui32FieldType)
- {
- case PVR_DRM_PCI_DOMAIN:
- *pui32Field = pci_domain_nr(psPCIDev->bus);
- break;
-
- case PVR_DRM_PCI_BUS:
- *pui32Field = psPCIDev->bus->number;
- break;
-
- case PVR_DRM_PCI_DEV:
- *pui32Field = PCI_SLOT(psPCIDev->devfn);
- break;
-
- case PVR_DRM_PCI_FUNC:
- *pui32Field = PCI_FUNC(psPCIDev->devfn);
- break;
-
- default:
- return -EFAULT;
- }
-
- return 0;
-}
-
-DRI_DRM_STATIC IMG_INT
-PVRDRMUnprivCmd(struct drm_device *dev, IMG_VOID *arg, struct drm_file *pFile)
-{
- IMG_UINT32 *pui32Args = (IMG_UINT32 *)arg;
- IMG_UINT32 ui32Cmd = pui32Args[0];
- IMG_UINT32 ui32Arg1 = pui32Args[1];
- IMG_UINT32 *pui32OutArg = (IMG_UINT32 *)arg;
- IMG_INT ret = 0;
-
- mutex_lock(&gPVRSRVLock);
-
- switch (ui32Cmd)
- {
- case PVR_DRM_UNPRIV_INIT_SUCCESFUL:
- *pui32OutArg = PVRSRVGetInitServerState(PVRSRV_INIT_SERVER_SUCCESSFUL) ? 1 : 0;
- break;
-
- case PVR_DRM_UNPRIV_BUSID_TYPE:
- *pui32OutArg = PVR_DRM_BUS_TYPE_PCI;
- break;
-
- case PVR_DRM_UNPRIV_BUSID_FIELD:
- ret = PVRDRMPCIBusIDField(dev, pui32OutArg, ui32Arg1);
-
- default:
- ret = -EFAULT;
- }
-
- mutex_unlock(&gPVRSRVLock);
-
- return ret;
-}
-
-#if 0
-struct drm_ioctl_desc sPVRDrmIoctls[] = {
- DRM_IOCTL_DEF(PVR_DRM_SRVKM_IOCTL, PVRSRV_BridgeDispatchKM, 0),
- DRM_IOCTL_DEF(PVR_DRM_IS_MASTER_IOCTL, PVRDRMIsMaster, DRM_MASTER),
- DRM_IOCTL_DEF(PVR_DRM_UNPRIV_IOCTL, PVRDRMUnprivCmd, 0),
-#if defined(PDUMP)
- DRM_IOCTL_DEF(PVR_DRM_DBGDRV_IOCTL, dbgdrv_ioctl, 0),
-#endif
-};
-
-static IMG_INT pvr_max_ioctl = DRM_ARRAY_SIZE(sPVRDrmIoctls);
-
-static struct drm_driver sPVRDrmDriver =
-{
- .driver_features = 0,
- .dev_priv_size = sizeof(sPVRDrmBuffer),
- .load = PVRSRVDrmLoad,
- .unload = PVRSRVDrmUnload,
- .open = PVRSRVDrmOpen,
- .postclose = PVRSRVDrmPostClose,
- .suspend = PVRSRVDriverSuspend,
- .resume = PVRSRVDriverResume,
- .get_map_ofs = drm_core_get_map_ofs,
- .get_reg_ofs = drm_core_get_reg_ofs,
- .ioctls = sPVRDrmIoctls,
- .fops =
- {
- .owner = THIS_MODULE,
- .open = drm_open,
- .release = drm_release,
- .ioctl = drm_ioctl,
- .mmap = PVRMMap,
- .poll = drm_poll,
- .fasync = drm_fasync,
- },
- .pci_driver =
- {
- .name = PVR_DRM_NAME,
- .id_table = asPciIdList,
- },
-
- .name = PVR_DRM_NAME,
- .desc = PVR_DRM_DESC,
- .date = PVR_BUILD_DATE,
- .major = PVRVERSION_MAJ,
- .minor = PVRVERSION_MIN,
- .patchlevel = PVRVERSION_BUILD,
-};
-
-static IMG_INT __init PVRSRVDrmInit(IMG_VOID)
-{
- IMG_INT iRes;
- sPVRDrmDriver.num_ioctls = pvr_max_ioctl;
-
-
- PVRDPFInit();
-
- iRes = drm_init(&sPVRDrmDriver);
-
- return iRes;
-}
-
-static IMG_VOID __exit PVRSRVDrmExit(IMG_VOID)
-{
- drm_exit(&sPVRDrmDriver);
-}
-
-module_init(PVRSRVDrmInit);
-module_exit(PVRSRVDrmExit);
-#endif
-#endif
-
-
+++ /dev/null
-/**********************************************************************
- *
- * Copyright(c) 2008 Imagination Technologies Ltd. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful but, except
- * as otherwise stated in writing, 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.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * The full GNU General Public License is included in this distribution in
- * the file called "COPYING".
- *
- * Contact Information:
- * Imagination Technologies Ltd. <gpl-support@imgtec.com>
- * Home Park Estate, Kings Langley, Herts, WD4 8LZ, UK
- *
- ******************************************************************************/
-
-#if !defined(__PVR_DRM_H__)
-#define __PVR_DRM_H__
-
-#include "pvr_drm_shared.h"
-
-#if defined(SUPPORT_DRI_DRM)
-#define PVR_DRM_MAKENAME_HELPER(x, y) x ## y
-#define PVR_DRM_MAKENAME(x, y) PVR_DRM_MAKENAME_HELPER(x, y)
-
-IMG_INT PVRCore_Init(IMG_VOID);
-IMG_VOID PVRCore_Cleanup(IMG_VOID);
-IMG_INT PVRSRVOpen(struct drm_device *dev, struct drm_file *pFile);
-IMG_INT PVRSRVRelease(struct drm_device *dev, struct drm_file *pFile);
-IMG_INT PVRSRVDriverSuspend(struct drm_device *pDevice, pm_message_t state);
-IMG_INT PVRSRVDriverResume(struct drm_device *pDevice);
-
-IMG_INT PVRSRV_BridgeDispatchKM(struct drm_device *dev, IMG_VOID *arg, struct drm_file *pFile);
-
-#if defined(SUPPORT_DRI_DRM_EXT)
-#define DRI_DRM_STATIC
-IMG_INT PVRSRVDrmLoad(struct drm_device *dev, unsigned long flags);
-IMG_INT PVRSRVDrmUnload(struct drm_device *dev);
-IMG_INT PVRSRVDrmOpen(struct drm_device *dev, struct drm_file *file);
-IMG_VOID PVRSRVDrmPostClose(struct drm_device *dev, struct drm_file *file);
-IMG_INT PVRDRMIsMaster(struct drm_device *dev, IMG_VOID *arg, struct drm_file *pFile);
-IMG_INT PVRDRMUnprivCmd(struct drm_device *dev, IMG_VOID *arg, struct drm_file *pFile);
-IMG_INT PVRDRM_Dummy_ioctl(struct drm_device *dev, IMG_VOID *arg, struct drm_file *pFile);
-#else
-#define DRI_DRM_STATIC static
-#endif
-
-#if defined(DISPLAY_CONTROLLER)
-extern int PVR_DRM_MAKENAME(DISPLAY_CONTROLLER, _Init)(struct drm_device *);
-extern void PVR_DRM_MAKENAME(DISPLAY_CONTROLLER, _Cleanup)(struct drm_device *);
-#endif
-
-#if defined(PDUMP)
-int dbgdrv_init(void);
-void dbgdrv_cleanup(void);
-IMG_INT dbgdrv_ioctl(struct drm_device *dev, IMG_VOID *arg, struct drm_file *pFile);
-#endif
-
-#if !defined(SUPPORT_DRI_DRM_EXT)
-#define PVR_DRM_SRVKM_IOCTL _IO(0, PVR_DRM_SRVKM_CMD)
-#define PVR_DRM_IS_MASTER_IOCTL _IO(0, PVR_DRM_IS_MASTER_CMD)
-#define PVR_DRM_UNPRIV_IOCTL _IO(0, PVR_DRM_UNPRIV_CMD)
-#define PVR_DRM_DBGDRV_IOCTL _IO(0, PVR_DRM_DBGDRV_CMD)
-#endif
-
-#endif
-
-#endif
-
-