/*!
******************************************************************************

 @Function                PALLOC_AttachToConnection

******************************************************************************/
IMG_RESULT PALLOC_AttachToConnection(
    IMG_UINT32           ui32ConnId,
    IMG_UINT32 __user *  pui32AttachId
)
{
    IMG_HANDLE  hDevHandle;
    IMG_UINT32  ui32Result;
    IMG_HANDLE  hConnHandle;
    IMG_UINT32  ui32AttachId;

    LOG_EVENT(PALLOC, PALLOC_ATTACH, (LOG_FLAG_START), 0, 0);

    /* Get the connection handle from it's ID...*/
    ui32Result = DMANKM_GetConnHandleFromId(ui32ConnId, &hConnHandle);
    IMG_ASSERT(ui32Result == IMG_SUCCESS);
    if (ui32Result != IMG_SUCCESS)
    {
        return ui32Result;
    }

    /* Get the device handle from the connection...*/
    hDevHandle = DMANKM_GetDevHandleFromConn(hConnHandle);

    /* Lock the device...*/
    DMANKM_LockDeviceContext(hDevHandle);

    /* Call on to the kernel function...*/
    ui32Result = DMANKM_AttachComponent(hConnHandle, "PALLOCBRG", palloc_fnCompAttach, IMG_NULL, &ui32AttachId);
    IMG_ASSERT(ui32Result == IMG_SUCCESS);

    /* Unlock the device...*/
    DMANKM_UnlockDeviceContext(hDevHandle);

    SYSOSKM_CopyToUser(pui32AttachId, &ui32AttachId, sizeof(ui32AttachId));
    LOG_EVENT(PALLOC, PALLOC_ATTACH, (LOG_FLAG_END), 0, 0);

    /* Return ui32Result...*/
    return ui32Result;
}
IMG_VOID MEMMGR_dispatch(SYSBRG_sPacket *psPacket)
{
	MEMMGR_sCmdMsg sCommandMsg;
	MEMMGR_sRespMsg sResponseMsg;

	if(SYSOSKM_CopyFromUser(&sCommandMsg, psPacket->pvCmdData, sizeof(sCommandMsg)))
		IMG_ASSERT(!"failed to copy from user");

	switch (sCommandMsg.eFuncId)
	{
	
      case WriteMemRefToMemRef_ID:
      
#if 0
#ifdef CONFIG_COMPAT      
      printk("bridge %d %s %s\n", is_compat_task(), __FUNCTION__, "WriteMemRefToMemRef");
#else
      printk("bridge %s %s\n", __FUNCTION__, "WriteMemRefToMemRef");
#endif
#endif
      		WriteMemRefToMemRef(
      
	  sCommandMsg.sCmd.sWriteMemRefToMemRefCmd.hDeviceMem,
	  sCommandMsg.sCmd.sWriteMemRefToMemRefCmd.ui32Offset,
	  sCommandMsg.sCmd.sWriteMemRefToMemRefCmd.ui32ManglerFuncIdExt,
	  sCommandMsg.sCmd.sWriteMemRefToMemRefCmd.hRefDeviceMem,
	  sCommandMsg.sCmd.sWriteMemRefToMemRefCmd.ui32RefOffset
      );
      break;
      
    
      case TOPAZKM_MMUMAllocateHeapDeviceMemory_ID:
      
#if 0
#ifdef CONFIG_COMPAT      
      printk("bridge %d %s %s\n", is_compat_task(), __FUNCTION__, "TOPAZKM_MMUMAllocateHeapDeviceMemory");
#else
      printk("bridge %s %s\n", __FUNCTION__, "TOPAZKM_MMUMAllocateHeapDeviceMemory");
#endif
#endif
      
	sResponseMsg.sResp.sTOPAZKM_MMUMAllocateHeapDeviceMemoryResp.xTOPAZKM_MMUMAllocateHeapDeviceMemoryResp =
      		TOPAZKM_MMUMAllocateHeapDeviceMemory(
      
	  sCommandMsg.sCmd.sTOPAZKM_MMUMAllocateHeapDeviceMemoryCmd.ui32Size,
	  sCommandMsg.sCmd.sTOPAZKM_MMUMAllocateHeapDeviceMemoryCmd.ui32Alignment,
	  sCommandMsg.sCmd.sTOPAZKM_MMUMAllocateHeapDeviceMemoryCmd.ui32Heap,
	  sCommandMsg.sCmd.sTOPAZKM_MMUMAllocateHeapDeviceMemoryCmd.bSaveRestore,
	  sCommandMsg.sCmd.sTOPAZKM_MMUMAllocateHeapDeviceMemoryCmd.ppMemInfo,
	  sCommandMsg.sCmd.sTOPAZKM_MMUMAllocateHeapDeviceMemoryCmd.tileSensetive
      );
      break;
      
    
      case TOPAZKM_StreamMMUMAllocateHeapDeviceMemory_ID:
      
#if 0
#ifdef CONFIG_COMPAT      
      printk("bridge %d %s %s\n", is_compat_task(), __FUNCTION__, "TOPAZKM_StreamMMUMAllocateHeapDeviceMemory");
#else
      printk("bridge %s %s\n", __FUNCTION__, "TOPAZKM_StreamMMUMAllocateHeapDeviceMemory");
#endif
#endif
      
	sResponseMsg.sResp.sTOPAZKM_StreamMMUMAllocateHeapDeviceMemoryResp.xTOPAZKM_StreamMMUMAllocateHeapDeviceMemoryResp =
      		TOPAZKM_StreamMMUMAllocateHeapDeviceMemory(
      
	  sCommandMsg.sCmd.sTOPAZKM_StreamMMUMAllocateHeapDeviceMemoryCmd.ui32StreamId,
	  sCommandMsg.sCmd.sTOPAZKM_StreamMMUMAllocateHeapDeviceMemoryCmd.ui32Size,
	  sCommandMsg.sCmd.sTOPAZKM_StreamMMUMAllocateHeapDeviceMemoryCmd.ui32Alignment,
	  sCommandMsg.sCmd.sTOPAZKM_StreamMMUMAllocateHeapDeviceMemoryCmd.ui32Heap,
	  sCommandMsg.sCmd.sTOPAZKM_StreamMMUMAllocateHeapDeviceMemoryCmd.bSaveRestore,
	  sCommandMsg.sCmd.sTOPAZKM_StreamMMUMAllocateHeapDeviceMemoryCmd.ppMemInfo,
	  sCommandMsg.sCmd.sTOPAZKM_StreamMMUMAllocateHeapDeviceMemoryCmd.tileSensetive
      );
      break;
      
    
      case TOPAZKM_MMUMFreeDeviceMemory_ID:
      
#if 0
#ifdef CONFIG_COMPAT      
      printk("bridge %d %s %s\n", is_compat_task(), __FUNCTION__, "TOPAZKM_MMUMFreeDeviceMemory");
#else
      printk("bridge %s %s\n", __FUNCTION__, "TOPAZKM_MMUMFreeDeviceMemory");
#endif
#endif
      
	sResponseMsg.sResp.sTOPAZKM_MMUMFreeDeviceMemoryResp.xTOPAZKM_MMUMFreeDeviceMemoryResp =
      		TOPAZKM_MMUMFreeDeviceMemory(
      
	  sCommandMsg.sCmd.sTOPAZKM_MMUMFreeDeviceMemoryCmd.pMemInfo
      );
      break;
      
    
      case TOPAZKM_MMUFlushMMUTableCache_ID:
      
#if 0
#ifdef CONFIG_COMPAT      
      printk("bridge %d %s %s\n", is_compat_task(), __FUNCTION__, "TOPAZKM_MMUFlushMMUTableCache");
#else
      printk("bridge %s %s\n", __FUNCTION__, "TOPAZKM_MMUFlushMMUTableCache");
#endif
#endif
      
	sResponseMsg.sResp.sTOPAZKM_MMUFlushMMUTableCacheResp.xTOPAZKM_MMUFlushMMUTableCacheResp =
      		TOPAZKM_MMUFlushMMUTableCache(
      
      );
      break;
      
    
      case TOPAZKM_MapExternal_ID:
      
#if 0
#ifdef CONFIG_COMPAT      
      printk("bridge %d %s %s\n", is_compat_task(), __FUNCTION__, "TOPAZKM_MapExternal");
#else
      printk("bridge %s %s\n", __FUNCTION__, "TOPAZKM_MapExternal");
#endif
#endif
      
	sResponseMsg.sResp.sTOPAZKM_MapExternalResp.xTOPAZKM_MapExternalResp =
      		TOPAZKM_MapExternal(
      
	  sCommandMsg.sCmd.sTOPAZKM_MapExternalCmd.ui32BufLen,
	  sCommandMsg.sCmd.sTOPAZKM_MapExternalCmd.ui32PallocId,
	  sCommandMsg.sCmd.sTOPAZKM_MapExternalCmd.ui32Heap,
	  sCommandMsg.sCmd.sTOPAZKM_MapExternalCmd.ui32Alignment,
	  sCommandMsg.sCmd.sTOPAZKM_MapExternalCmd.memInfo
      );
      break;
      
    
      case TOPAZKM_UnMapExternal_ID:
      
#if 0
#ifdef CONFIG_COMPAT      
      printk("bridge %d %s %s\n", is_compat_task(), __FUNCTION__, "TOPAZKM_UnMapExternal");
#else
      printk("bridge %s %s\n", __FUNCTION__, "TOPAZKM_UnMapExternal");
#endif
#endif
      
	sResponseMsg.sResp.sTOPAZKM_UnMapExternalResp.xTOPAZKM_UnMapExternalResp =
      		TOPAZKM_UnMapExternal(
      
	  sCommandMsg.sCmd.sTOPAZKM_UnMapExternalCmd.memInfo
      );
      break;
      
    
      case TOPAZKM_MMCopyTiledBuffer_ID:
      
#if 0
#ifdef CONFIG_COMPAT      
      printk("bridge %d %s %s\n", is_compat_task(), __FUNCTION__, "TOPAZKM_MMCopyTiledBuffer");
#else
      printk("bridge %s %s\n", __FUNCTION__, "TOPAZKM_MMCopyTiledBuffer");
#endif
#endif
      
	sResponseMsg.sResp.sTOPAZKM_MMCopyTiledBufferResp.xTOPAZKM_MMCopyTiledBufferResp =
      		TOPAZKM_MMCopyTiledBuffer(
      
	  sCommandMsg.sCmd.sTOPAZKM_MMCopyTiledBufferCmd.pMemoryInfo,
	  sCommandMsg.sCmd.sTOPAZKM_MMCopyTiledBufferCmd.pcBuffer,
	  sCommandMsg.sCmd.sTOPAZKM_MMCopyTiledBufferCmd.ui32Size,
	  sCommandMsg.sCmd.sTOPAZKM_MMCopyTiledBufferCmd.ui32Offset,
	  sCommandMsg.sCmd.sTOPAZKM_MMCopyTiledBufferCmd.bToMemory
      );
      break;
      
    
	}
	if(SYSOSKM_CopyToUser(psPacket->pvRespData, &sResponseMsg, sizeof(sResponseMsg)))
		IMG_ASSERT(!"failed to copy to user");
}
IMG_VOID DBGOPTBRG_dispatch(SYSBRG_sPacket *psPacket)
{
	DBGOPTBRG_sCmdMsg sCommandMsg;
	DBGOPTBRG_sRespMsg sResponseMsg;

	if(SYSOSKM_CopyFromUser(&sCommandMsg, psPacket->pvCmdData, sizeof(sCommandMsg)))
		IMG_ASSERT(!"failed to copy from user");

	switch (sCommandMsg.eFuncId)
	{
	
      case DBGOPTBRG_Initialise_ID:
      
#if 0
#ifdef CONFIG_COMPAT      
      printk("bridge %d %s %s\n", is_compat_task(), __FUNCTION__, "DBGOPTBRG_Initialise");
#else
      printk("bridge %s %s\n", __FUNCTION__, "DBGOPTBRG_Initialise");
#endif
#endif
      
	sResponseMsg.sResp.sDBGOPTBRG_InitialiseResp.xDBGOPTBRG_InitialiseResp =
      		DBGOPTBRG_Initialise(
      
      );
      break;
      
    
      case DBGOPTBRG_Deinitialise_ID:
      
#if 0
#ifdef CONFIG_COMPAT      
      printk("bridge %d %s %s\n", is_compat_task(), __FUNCTION__, "DBGOPTBRG_Deinitialise");
#else
      printk("bridge %s %s\n", __FUNCTION__, "DBGOPTBRG_Deinitialise");
#endif
#endif
      		DBGOPTBRG_Deinitialise(
      
      );
      break;
      
    
      case DBGOPTBRG_Set_ID:
      
#if 0
#ifdef CONFIG_COMPAT      
      printk("bridge %d %s %s\n", is_compat_task(), __FUNCTION__, "DBGOPTBRG_Set");
#else
      printk("bridge %s %s\n", __FUNCTION__, "DBGOPTBRG_Set");
#endif
#endif
      
	sResponseMsg.sResp.sDBGOPTBRG_SetResp.xDBGOPTBRG_SetResp =
      		DBGOPTBRG_Set(
      
	  sCommandMsg.sCmd.sDBGOPTBRG_SetCmd.sStrName,
	  sCommandMsg.sCmd.sDBGOPTBRG_SetCmd.eType,
	  sCommandMsg.sCmd.sDBGOPTBRG_SetCmd.sVal
      );
      break;
      
    
      case DBGOPTBRG_Get_ID:
      
#if 0
#ifdef CONFIG_COMPAT      
      printk("bridge %d %s %s\n", is_compat_task(), __FUNCTION__, "DBGOPTBRG_Get");
#else
      printk("bridge %s %s\n", __FUNCTION__, "DBGOPTBRG_Get");
#endif
#endif
      
	sResponseMsg.sResp.sDBGOPTBRG_GetResp.xDBGOPTBRG_GetResp =
      		DBGOPTBRG_Get(
      
	  sCommandMsg.sCmd.sDBGOPTBRG_GetCmd.sStrName,
	  sCommandMsg.sCmd.sDBGOPTBRG_GetCmd.peType,
	  sCommandMsg.sCmd.sDBGOPTBRG_GetCmd.psVal
      );
      break;
      
    
      case DBGOPTBRG_Clear_ID:
      
#if 0
#ifdef CONFIG_COMPAT      
      printk("bridge %d %s %s\n", is_compat_task(), __FUNCTION__, "DBGOPTBRG_Clear");
#else
      printk("bridge %s %s\n", __FUNCTION__, "DBGOPTBRG_Clear");
#endif
#endif
      		DBGOPTBRG_Clear(
      
	  sCommandMsg.sCmd.sDBGOPTBRG_ClearCmd.sStrName
      );
      break;
      
    
      case DBGOPTBRG_SetWithKey_ID:
      
#if 0
#ifdef CONFIG_COMPAT      
      printk("bridge %d %s %s\n", is_compat_task(), __FUNCTION__, "DBGOPTBRG_SetWithKey");
#else
      printk("bridge %s %s\n", __FUNCTION__, "DBGOPTBRG_SetWithKey");
#endif
#endif
      
	sResponseMsg.sResp.sDBGOPTBRG_SetWithKeyResp.xDBGOPTBRG_SetWithKeyResp =
      		DBGOPTBRG_SetWithKey(
      
	  sCommandMsg.sCmd.sDBGOPTBRG_SetWithKeyCmd.i32Key,
	  sCommandMsg.sCmd.sDBGOPTBRG_SetWithKeyCmd.sStrName,
	  sCommandMsg.sCmd.sDBGOPTBRG_SetWithKeyCmd.eType,
	  sCommandMsg.sCmd.sDBGOPTBRG_SetWithKeyCmd.sVal
      );
      break;
      
    
      case DBGOPTBRG_GetWithKey_ID:
      
#if 0
#ifdef CONFIG_COMPAT      
      printk("bridge %d %s %s\n", is_compat_task(), __FUNCTION__, "DBGOPTBRG_GetWithKey");
#else
      printk("bridge %s %s\n", __FUNCTION__, "DBGOPTBRG_GetWithKey");
#endif
#endif
      
	sResponseMsg.sResp.sDBGOPTBRG_GetWithKeyResp.xDBGOPTBRG_GetWithKeyResp =
      		DBGOPTBRG_GetWithKey(
      
	  sCommandMsg.sCmd.sDBGOPTBRG_GetWithKeyCmd.i32Key,
	  sCommandMsg.sCmd.sDBGOPTBRG_GetWithKeyCmd.sStrName,
	  sCommandMsg.sCmd.sDBGOPTBRG_GetWithKeyCmd.peType,
	  sCommandMsg.sCmd.sDBGOPTBRG_GetWithKeyCmd.psVal
      );
      break;
      
    
      case DBGOPTBRG_ClearWithKey_ID:
      
#if 0
#ifdef CONFIG_COMPAT      
      printk("bridge %d %s %s\n", is_compat_task(), __FUNCTION__, "DBGOPTBRG_ClearWithKey");
#else
      printk("bridge %s %s\n", __FUNCTION__, "DBGOPTBRG_ClearWithKey");
#endif
#endif
      		DBGOPTBRG_ClearWithKey(
      
	  sCommandMsg.sCmd.sDBGOPTBRG_ClearWithKeyCmd.i32Key,
	  sCommandMsg.sCmd.sDBGOPTBRG_ClearWithKeyCmd.sStrName
      );
      break;
      
    
      case DBGOPTBRG_ClearAll_ID:
      
#if 0
#ifdef CONFIG_COMPAT      
      printk("bridge %d %s %s\n", is_compat_task(), __FUNCTION__, "DBGOPTBRG_ClearAll");
#else
      printk("bridge %s %s\n", __FUNCTION__, "DBGOPTBRG_ClearAll");
#endif
#endif
      		DBGOPTBRG_ClearAll(
      
      );
      break;
      
    
	}
	if(SYSOSKM_CopyToUser(psPacket->pvRespData, &sResponseMsg, sizeof(sResponseMsg)))
		IMG_ASSERT(!"failed to copy to user");
}
/*!
******************************************************************************

 @Function              PALLOC_Import1

******************************************************************************/
IMG_RESULT PALLOC_Import1(
    IMG_UINT32                ui32AttachId,
    SYS_eMemAttrib            eMemAttrib,
    int                       buff_fd,
    PALLOC_sUmAlloc __user *  psUmAlloc
)
{
    IMG_HANDLE               hDevHandle;
    IMG_UINT32               ui32Result;
    PALLOC_sKmAlloc *        psKmAlloc;
    IMG_HANDLE               hAttachHandle;
    PALLOC_sAttachContext *  psAttachContext;
    IMG_UINT32               ui32PageNo;
    IMG_UINT32               ui32PageIdx;
    IMG_UINT64               ui64CpuPAddr;
    PALLOC_sUmAlloc          sUmAllocCp;
    IMG_UINT64 *             paui64DevAddrs;
    SYSDEVU_sInfo *          psSysDev;
    SYS_eMemPool             eMemPool;
    IMG_PVOID                pvCpuKmAddr;

    LOG_EVENT(PALLOC, PALLOC_IMPORT, LOG_FLAG_START | LOG_FLAG_QUAL_ARG1 | LOG_FLAG_QUAL_ARG2,
              ui32AttachId, buff_fd);

    DEBUG_REPORT(REPORT_MODULE_PALLOC, "PALLOC_Import1 fd %d", buff_fd);

    if (SYSOSKM_CopyFromUser(&sUmAllocCp, psUmAlloc, sizeof sUmAllocCp) != IMG_SUCCESS)
    {
        return IMG_ERROR_FATAL;
    }

    IMG_ASSERT(sUmAllocCp.bMappingOnly);

    /* Get the attachment handle from its ID... */
    ui32Result = DMANKM_GetAttachHandleFromId(ui32AttachId, &hAttachHandle);
    IMG_ASSERT(ui32Result == IMG_SUCCESS);
    if (ui32Result != IMG_SUCCESS)
    {
        return ui32Result;
    }

    /* Get access to the attachment specific data...*/
    psAttachContext = DMANKM_GetCompAttachmentData(hAttachHandle);

    /* Get access to the device handle...*/
    hDevHandle = DMANKM_GetDevHandleFromAttach(hAttachHandle);

    /* Lock the device...*/
    DMANKM_LockDeviceContext(hDevHandle);

    psSysDev = SYSDEVU_GetDeviceById(SYSDEVKM_GetDeviceID(psAttachContext->hSysDevHandle));
    IMG_ASSERT(psSysDev != IMG_NULL); // I
    if (psSysDev == IMG_NULL)
    {
        ui32Result = IMG_ERROR_DEVICE_NOT_FOUND;
        goto error_get_dev_by_id;
    }

    eMemPool = (eMemAttrib & SYS_MEMATTRIB_SECURE) ? psSysDev->secureMemPool : psSysDev->sMemPool;

    /* Allocate allocation info...*/
    psKmAlloc = IMG_MALLOC(sizeof *psKmAlloc);
    IMG_ASSERT(psKmAlloc != IMG_NULL);
    if (psKmAlloc == IMG_NULL)
    {
        ui32Result = IMG_ERROR_OUT_OF_MEMORY;
        goto error_alloc_info;
    }
    IMG_MEMSET(psKmAlloc, 0, sizeof *psKmAlloc);

    /* Save device handle etc... */
    psKmAlloc->hDevHandle = hDevHandle;
    psKmAlloc->sAllocInfo.ui32Size = sUmAllocCp.ui32Size;
    psKmAlloc->sAllocInfo.bIsContiguous = IMG_FALSE;

    /* Get the device id...*/
    ui32Result = DMANKM_GetDeviceId(hDevHandle, &sUmAllocCp.ui32DeviceId);
    IMG_ASSERT(ui32Result == IMG_SUCCESS);
    if (ui32Result != IMG_SUCCESS)
    {
        goto error_get_dev_id;
    }

    psKmAlloc->sAllocInfo.bMappingOnly = IMG_TRUE;

    /* Calculate the size of the allocation in pages */
    ui32PageNo = (sUmAllocCp.ui32Size + SYS_MMU_PAGE_SIZE - 1)/SYS_MMU_PAGE_SIZE;

    psKmAlloc->sAllocInfo.psSysPAddr = IMG_BIGORSMALL_ALLOC(sizeof(IMG_SYS_PHYADDR) * ui32PageNo);
    IMG_ASSERT(psKmAlloc->sAllocInfo.psSysPAddr);
    if (IMG_NULL == psKmAlloc->sAllocInfo.psSysPAddr)
    {
        ui32Result = IMG_ERROR_OUT_OF_MEMORY;
        goto error_page_array;
    }
    paui64DevAddrs = IMG_BIGORSMALL_ALLOC((sizeof *paui64DevAddrs) * ui32PageNo);
    IMG_ASSERT(paui64DevAddrs);
    if (IMG_NULL == paui64DevAddrs)
    {
        ui32Result = IMG_ERROR_OUT_OF_MEMORY;
        goto error_addr_array;
    }

    if(buff_fd >= 0)
    {
        pvCpuKmAddr = NULL;
        /* ION buffer */
#if defined ANDROID_ION_BUFFERS
        psKmAlloc->eBufType = PALLOC_BUFTYPE_ANDROIDNATIVE;
    #if defined CONFIG_X86
        ui32Result = palloc_GetIONPages(eMemPool, buff_fd, sUmAllocCp.ui32Size,
                                        psKmAlloc->sAllocInfo.psSysPAddr,
                                        &pvCpuKmAddr,
                                        &psKmAlloc->hBufHandle);
    #else // if CONFIG_X86
        ui32Result = palloc_GetIONPages(eMemPool, buff_fd, sUmAllocCp.ui32Size,
                                        psKmAlloc->sAllocInfo.psSysPAddr,
                                        NULL,
                                        &psKmAlloc->hBufHandle);
    #endif // if CONFIG_X86
        if (ui32Result != IMG_SUCCESS)
        {
            IMG_ASSERT(!"palloc_GetIONPages");
            goto error_get_pages;
        }
#else   // if ANDROID_ION_BUFFERS
        IMG_ASSERT(!"NOT ANDROID: ION not supported");
        goto error_get_pages;
#endif  // if ANDROID_ION_BUFFERS
    }
    else
    {
        /* User space allocated buffer */
        IMG_VOID __user *  pvUmBuff = ( IMG_VOID __user * ) sUmAllocCp.pvCpuUmAddr;
        IMG_ASSERT(pvUmBuff);
        psKmAlloc->hBufHandle = (IMG_HANDLE)(sUmAllocCp.pvCpuUmAddr);
        psKmAlloc->eBufType = PALLOC_BUFTYPE_USERALLOC;
        /* Assign and lock physical addresses to the user space buffer.
           The mapping of the first page in the kernel is also returned */
        ui32Result = SYSOSKM_CpuUmAddrToCpuPAddrArray(pvUmBuff, psKmAlloc->sAllocInfo.psSysPAddr,
                                                      ui32PageNo, &pvCpuKmAddr);
        IMG_ASSERT(ui32Result == IMG_SUCCESS);
        if (ui32Result != IMG_SUCCESS)
        {
            goto error_get_pages;
        }
    }

    /* Import pages */
    ui32Result = SYSMEMU_ImportExternalPages(eMemPool, sUmAllocCp.ui32Size, eMemAttrib,
                                             &psKmAlloc->hPagesHandle, pvCpuKmAddr,
                                             psKmAlloc->sAllocInfo.psSysPAddr);
    IMG_ASSERT(ui32Result == IMG_SUCCESS);
    if (ui32Result != IMG_SUCCESS)
    {
        goto error_import_pages;
    }

    // Access from user space is not needed for the moment. Can be changed.
    sUmAllocCp.lOffset = 0;
#if PALLOC_EXPOSE_KM_HANDLE
    sUmAllocCp.hKmAllocHandle = psKmAlloc->hPagesHandle;
#endif /* PALLOC_EXPOSE_KM_HANDLE */

    for (ui32PageIdx = 0; ui32PageIdx < ui32PageNo; ++ui32PageIdx)
    {
        ui64CpuPAddr = psKmAlloc->sAllocInfo.psSysPAddr[ui32PageIdx];
        paui64DevAddrs[ui32PageIdx] =
            SYSDEVKM_CpuPAddrToDevPAddr(psAttachContext->hSysDevHandle, ui64CpuPAddr);
    }

    /* Register this with the resource manager */
    ui32Result = RMAN_RegisterResource(psAttachContext->hResBHandle, PALLOC_RES_TYPE_1,
                                       palloc_fnFree, psKmAlloc, IMG_NULL, &sUmAllocCp.ui32AllocId);
    IMG_ASSERT(ui32Result == IMG_SUCCESS);
    if (ui32Result != IMG_SUCCESS)
    {
        goto error_resource_register;
    }

    LOG_EVENT(PALLOC, PALLOC_IMPORTID, LOG_FLAG_END | LOG_FLAG_QUAL_ARG1 | LOG_FLAG_QUAL_ARG2,
              ui32AttachId, sUmAllocCp.ui32AllocId);

    /* Unlock the device...*/
    DMANKM_UnlockDeviceContext(hDevHandle);

    /* Copy to user changed PALLOC_sUmAlloc, including physical device addresses */
    if (SYSOSKM_CopyToUser(psUmAlloc, &sUmAllocCp, sizeof sUmAllocCp))
    {
        ui32Result = IMG_ERROR_FATAL;
        goto error_copy_to_user;
    }
    if (SYSOSKM_CopyToUser(psUmAlloc->aui64DevPAddr, paui64DevAddrs,
                           (sizeof *paui64DevAddrs) * ui32PageNo))
    {
        ui32Result = IMG_ERROR_FATAL;
        goto error_copy_to_user;
    }
    /* Free the address array */
    IMG_BIGORSMALL_FREE((sizeof *paui64DevAddrs) * ui32PageNo, paui64DevAddrs);

    LOG_EVENT(PALLOC, PALLOC_IMPORT, LOG_FLAG_END | LOG_FLAG_QUAL_ARG1 | LOG_FLAG_QUAL_ARG2,
              ui32AttachId, buff_fd);

    /* Return. */
    return IMG_SUCCESS;

    /* Error handling. */
error_copy_to_user:
    /* Free everything. */
    PALLOC_Free1(sUmAllocCp.ui32AllocId);
    goto error_return;

error_resource_register:
    SYSMEMU_FreePages(psKmAlloc->hPagesHandle);
error_import_pages:
    if (buff_fd >= 0)
    {
#ifdef ANDROID_ION_BUFFERS
        palloc_ReleaseIONBuf(psKmAlloc->hBufHandle, NULL);
#endif /* ANDROID_ION_BUFFERS */
    }
    else
    {
        SYSOSKM_ReleaseCpuPAddrArray(pvCpuKmAddr, psKmAlloc->hBufHandle,
                                     psKmAlloc->sAllocInfo.psSysPAddr, ui32PageNo);
    }
error_get_pages:
    IMG_BIGORSMALL_FREE((sizeof *paui64DevAddrs) * ui32PageNo, paui64DevAddrs);
error_addr_array:
    IMG_BIGORSMALL_FREE(sizeof(IMG_SYS_PHYADDR) * ui32PageNo, psKmAlloc->sAllocInfo.psSysPAddr);
error_page_array:
error_get_dev_id:
    IMG_FREE(psKmAlloc);
error_alloc_info:
error_get_dev_by_id:
    /* Unlock the device. */
    DMANKM_UnlockDeviceContext(hDevHandle);

error_return:
    return ui32Result;
}
/*!
******************************************************************************

 @Function                PALLOC_Alloc1

******************************************************************************/
IMG_RESULT PALLOC_Alloc1(
    IMG_UINT32                ui32AttachId,
    SYS_eMemAttrib            eMemAttrib,
    PALLOC_sUmAlloc __user *  psUmAlloc
)
{
    IMG_HANDLE               hDevHandle;
    IMG_UINT32               ui32Result;
    PALLOC_sKmAlloc *        psKmAlloc;
    IMG_HANDLE               hAttachHandle;
    PALLOC_sAttachContext *  psAttachContext;
    IMG_UINT32               ui32PageNo;
    PALLOC_sUmAlloc          sUmAllocCp;
    IMG_UINT32               ui32PageIdx;
    IMG_UINT64 *             pui64Phys;
    SYSMEMU_sPages *         psSysMem;
    SYS_eMemPool             eMemPool;
    SYSDEVU_sInfo *          psSysDev;
    /* the following code assumes that IMG_SYS_PHYADDR and IMG_UINT64 are the same size */

#ifndef SYSBRG_BRIDGING
    IMG_VOID *               pvKmAddr;
#endif

    if (SYSOSKM_CopyFromUser(&sUmAllocCp, psUmAlloc, sizeof(sUmAllocCp)) != IMG_SUCCESS)
    {
        return IMG_ERROR_FATAL;
    }

    LOG_EVENT(PALLOC, PALLOC_ALLOC, (LOG_FLAG_START | LOG_FLAG_QUAL_ARG1 |LOG_FLAG_QUAL_ARG2), ui32AttachId, sUmAllocCp.ui32Size);

    IMG_ASSERT(!sUmAllocCp.bMappingOnly);

    /* Get the attachment handle from its ID...*/
    ui32Result = DMANKM_GetAttachHandleFromId(ui32AttachId, &hAttachHandle);
    IMG_ASSERT(ui32Result == IMG_SUCCESS);
    if (ui32Result != IMG_SUCCESS)
    {
        return ui32Result;
    }

    /* Get access to the attachment specific data...*/
    psAttachContext = DMANKM_GetCompAttachmentData(hAttachHandle);

    /* Get access to the device handle...*/
    hDevHandle = DMANKM_GetDevHandleFromAttach(hAttachHandle);

    /* Lock the device...*/
    DMANKM_LockDeviceContext(hDevHandle);

    psSysDev = SYSDEVU_GetDeviceById(SYSDEVKM_GetDeviceID(psAttachContext->hSysDevHandle));
    IMG_ASSERT(psSysDev != IMG_NULL); // I
    if (psSysDev == IMG_NULL)
    {
        return IMG_ERROR_DEVICE_NOT_FOUND;
    }

    eMemPool = (eMemAttrib & SYS_MEMATTRIB_SECURE) ? psSysDev->secureMemPool : psSysDev->sMemPool;

    /* Allocate allocation info...*/
    psKmAlloc = IMG_MALLOC(sizeof(*psKmAlloc));
    IMG_ASSERT(psKmAlloc != IMG_NULL);
    if (psKmAlloc == IMG_NULL)
    {
        ui32Result = IMG_ERROR_OUT_OF_MEMORY;
        goto error_alloc_info;
    }
    IMG_MEMSET(psKmAlloc, 0, sizeof(*psKmAlloc));

    /* Save device handle etc...*/
    psKmAlloc->hDevHandle          = hDevHandle;
    psKmAlloc->sAllocInfo.ui32Size = sUmAllocCp.ui32Size;
    psKmAlloc->hBufHandle          = NULL;
    psKmAlloc->eBufType            = PALLOC_BUFTYPE_PALLOCATED;

    /* Allocate pages...*/
    ui32Result = SYSMEMU_AllocatePages(sUmAllocCp.ui32Size, eMemAttrib, eMemPool,
                                       &psKmAlloc->hPagesHandle, &pui64Phys);
    IMG_ASSERT(ui32Result == IMG_SUCCESS);
    if (ui32Result != IMG_SUCCESS)
    {
        goto error_alloc_pages;
    }

#ifndef SYSBRG_BRIDGING
    SYSMEMU_GetCpuKmAddr(&pvKmAddr, psKmAlloc->hPagesHandle);
    IMG_ASSERT(pvKmAddr != IMG_NULL);
    if(pvKmAddr == IMG_NULL)
    {
        ui32Result = IMG_ERROR_FATAL;
        goto error_cpu_km_addr;
    }
#endif

    /* Return addresses...*/
    psSysMem = psKmAlloc->hPagesHandle;


#ifdef PALLOC_EXPOSE_KM_HANDLE
    sUmAllocCp.hKmAllocHandle = psKmAlloc->hPagesHandle;
#endif

    /* Check if contiguous...*/
    psKmAlloc->sAllocInfo.bIsContiguous = SYSMEMKM_IsContiguous(psKmAlloc->hPagesHandle);

    /* Get the device id...*/
    ui32Result = DMANKM_GetDeviceId(hDevHandle, &sUmAllocCp.ui32DeviceId);
    IMG_ASSERT(ui32Result == IMG_SUCCESS);
    if (ui32Result != IMG_SUCCESS)
    {
        goto error_get_dev_id;
    }

    sUmAllocCp.lOffset = 0;
    if (psSysMem->hRegHandle)
    {
        // Determine the offset to memory if it has been made mappable in UM.
        sUmAllocCp.lOffset = (long)pui64Phys[0];
    }

    /* Calculate the size of the allocation in pages...*/
    ui32PageNo = (sUmAllocCp.ui32Size + SYS_MMU_PAGE_SIZE - 1)/SYS_MMU_PAGE_SIZE;
    psKmAlloc->sAllocInfo.psSysPAddr = IMG_BIGORSMALL_ALLOC(sizeof(IMG_SYS_PHYADDR) * ui32PageNo);
    IMG_ASSERT(psKmAlloc->sAllocInfo.psSysPAddr);
    if (IMG_NULL == psKmAlloc->sAllocInfo.psSysPAddr)
    {
        ui32Result = IMG_ERROR_OUT_OF_MEMORY;
        goto error_page_array;
    }
    IMG_MEMSET(psKmAlloc->sAllocInfo.psSysPAddr, 0, sizeof(IMG_SYS_PHYADDR) * ui32PageNo);

    for (ui32PageIdx = 0; ui32PageIdx < ui32PageNo; ++ui32PageIdx)
    {
        psKmAlloc->sAllocInfo.psSysPAddr[ui32PageIdx] = pui64Phys[ui32PageIdx];
    }

    /* Register this with the resource manager...*/
    ui32Result = RMAN_RegisterResource(psAttachContext->hResBHandle, PALLOC_RES_TYPE_1,
                                       palloc_fnFree, psKmAlloc, IMG_NULL, &sUmAllocCp.ui32AllocId);
    IMG_ASSERT(ui32Result == IMG_SUCCESS);
    if (ui32Result != IMG_SUCCESS)
    {
        goto error_resource_register;
    }

    LOG_EVENT(PALLOC, PALLOC_ALLOCID, (LOG_FLAG_END | LOG_FLAG_QUAL_ARG1 |LOG_FLAG_QUAL_ARG2),
              ui32AttachId, sUmAllocCp.ui32AllocId);

    /* Unlock the device...*/
    DMANKM_UnlockDeviceContext(hDevHandle);

    /* Copy to user changed PALLOC_sUmAlloc, including physical device addresses */
    if (SYSOSKM_CopyToUser(psUmAlloc, &sUmAllocCp, sizeof(sUmAllocCp)))
    {
        ui32Result = IMG_ERROR_FATAL;
        goto error_copy_to_user;
    }
    if (SYSOSKM_CopyToUser(psUmAlloc->aui64DevPAddr, psKmAlloc->sAllocInfo.psSysPAddr,
                           sizeof(psKmAlloc->sAllocInfo.psSysPAddr[0]) * ui32PageNo))
    {
        ui32Result = IMG_ERROR_FATAL;
        goto error_copy_to_user;
    }

    LOG_EVENT(PALLOC, PALLOC_ALLOC, (LOG_FLAG_END | LOG_FLAG_QUAL_ARG1 |LOG_FLAG_QUAL_ARG2),
              ui32AttachId, sUmAllocCp.ui32Size);

    /* Return. */
    return IMG_SUCCESS;

    /* Error handling. */
error_copy_to_user:
    /* Free everything. */
    PALLOC_Free1(sUmAllocCp.ui32AllocId);
    goto error_return;

error_resource_register:
    IMG_BIGORSMALL_FREE(sizeof(IMG_SYS_PHYADDR) * ui32PageNo,
                        psKmAlloc->sAllocInfo.psSysPAddr);
error_page_array:
error_get_dev_id:
#ifndef SYSBRG_BRIDGING
error_cpu_km_addr:
#endif /* SYSBRG_BRIDGING */
    SYSMEMU_FreePages(psKmAlloc->hPagesHandle);
error_alloc_pages:
    IMG_FREE(psKmAlloc);
error_alloc_info:
    /* Unlock the device. */
    DMANKM_UnlockDeviceContext(hDevHandle);

error_return:
    return ui32Result;
}
IMG_VOID DMAN_dispatch(SYSBRG_sPacket __user *psPacket)
{
	SYSBRG_sPacket sPacket;
	DMAN_sCmdMsg sCommandMsg;
	DMAN_sRespMsg sResponseMsg;

	if(SYSOSKM_CopyFromUser(&sPacket, psPacket, sizeof(sPacket)))
		IMG_ASSERT(!"failed to copy from user");
	if(SYSOSKM_CopyFromUser(&sCommandMsg, sPacket.pvCmdData, sizeof(sCommandMsg)))
		IMG_ASSERT(!"failed to copy from user");

	switch (sCommandMsg.eFuncId)
	{
	
      case DMAN_Initialise_ID:
      
      
	sResponseMsg.sResp.sDMAN_InitialiseResp.xDMAN_InitialiseResp =
      		DMAN_Initialise(
      
      );
      break;
      
    
      case DMAN_Deinitialise_ID:
      
      
	sResponseMsg.sResp.sDMAN_DeinitialiseResp.xDMAN_DeinitialiseResp =
      		DMAN_Deinitialise(
      
      );
      break;
      
    
      case DMAN_CloseDevice_ID:
      
      
	sResponseMsg.sResp.sDMAN_CloseDeviceResp.xDMAN_CloseDeviceResp =
      		DMAN_CloseDevice(
      
	  sCommandMsg.sCmd.sDMAN_CloseDeviceCmd.ui32ConnId
      );
      break;
      
    
      case DMAN_GetDeviceId_ID:
      
      
		#ifdef WIN32
		if(!SYSBRGKM_CheckParams((IMG_VOID __user *)&sCommandMsg.sCmd.sDMAN_GetDeviceIdCmd.pui32DeviceId, sizeof((SYSBRG_sPacket *)&sCommandMsg.sCmd.sDMAN_GetDeviceIdCmd.pui32DeviceId)))
		    IMG_ASSERT(IMG_FALSE);
		#else
        // not required to check pointer access under linux, as SYSOSKM_Copy{To,From}User has to be used
		#endif
	      
	sResponseMsg.sResp.sDMAN_GetDeviceIdResp.xDMAN_GetDeviceIdResp =
      		DMAN_GetDeviceId(
      
	  sCommandMsg.sCmd.sDMAN_GetDeviceIdCmd.ui32ConnId,
	  sCommandMsg.sCmd.sDMAN_GetDeviceIdCmd.pui32DeviceId
      );
      break;
      
    
      case DMAN_GetKmBuildFlags_ID:
      
      
		#ifdef WIN32
		if(!SYSBRGKM_CheckParams((IMG_VOID __user *)&sCommandMsg.sCmd.sDMAN_GetKmBuildFlagsCmd.pui32KmBuildFlags, sizeof((SYSBRG_sPacket *)&sCommandMsg.sCmd.sDMAN_GetKmBuildFlagsCmd.pui32KmBuildFlags)))
		    IMG_ASSERT(IMG_FALSE);
		#else
        // not required to check pointer access under linux, as SYSOSKM_Copy{To,From}User has to be used
		#endif
	      
	sResponseMsg.sResp.sDMAN_GetKmBuildFlagsResp.xDMAN_GetKmBuildFlagsResp =
      		DMAN_GetKmBuildFlags(
      
	  sCommandMsg.sCmd.sDMAN_GetKmBuildFlagsCmd.pui32KmBuildFlags
      );
      break;
      
    
      case DMAN_OpenDevice1_ID:
      
      
		if(!SYSBRGKM_CheckParams((IMG_VOID __user *)&sCommandMsg.sCmd.sDMAN_OpenDevice1Cmd.pszDevName, sCommandMsg.sCmd.sDMAN_OpenDevice1Cmd.ui32DevNameSize))
		    IMG_ASSERT(IMG_FALSE);
	      
		#ifdef WIN32
		if(!SYSBRGKM_CheckParams((IMG_VOID __user *)&sCommandMsg.sCmd.sDMAN_OpenDevice1Cmd.pui32ConnId, sizeof((SYSBRG_sPacket *)&sCommandMsg.sCmd.sDMAN_OpenDevice1Cmd.pui32ConnId)))
		    IMG_ASSERT(IMG_FALSE);
		#else
        // not required to check pointer access under linux, as SYSOSKM_Copy{To,From}User has to be used
		#endif
	      
	sResponseMsg.sResp.sDMAN_OpenDevice1Resp.xDMAN_OpenDevice1Resp =
      		DMAN_OpenDevice1(
      
	  sCommandMsg.sCmd.sDMAN_OpenDevice1Cmd.pszDevName,
	  sCommandMsg.sCmd.sDMAN_OpenDevice1Cmd.ui32DevNameSize,
	  sCommandMsg.sCmd.sDMAN_OpenDevice1Cmd.eOpenMode,
	  sCommandMsg.sCmd.sDMAN_OpenDevice1Cmd.pui32ConnId
      );
      break;
      
    
	}
	if(SYSOSKM_CopyToUser(sPacket.pvRespData, &sResponseMsg, sizeof(sResponseMsg)))
		IMG_ASSERT(!"failed to copy to user");
}
IMG_VOID HOSTUTILS_dispatch(SYSBRG_sPacket *psPacket)
{
	HOSTUTILS_sCmdMsg sCommandMsg;
	HOSTUTILS_sRespMsg sResponseMsg;

	if(SYSOSKM_CopyFromUser(&sCommandMsg, psPacket->pvCmdData, sizeof(sCommandMsg)))
		IMG_ASSERT(!"failed to copy from user");

	switch (sCommandMsg.eFuncId)
	{
	
      case COMMKM_Initialize_ID:
      
#if 0
#ifdef CONFIG_COMPAT      
      printk("bridge %d %s %s\n", is_compat_task(), __FUNCTION__, "COMMKM_Initialize");
#else
      printk("bridge %s %s\n", __FUNCTION__, "COMMKM_Initialize");
#endif
#endif
      
	sResponseMsg.sResp.sCOMMKM_InitializeResp.xCOMMKM_InitializeResp =
      		COMMKM_Initialize(
      
	  sCommandMsg.sCmd.sCOMMKM_InitializeCmd.ui32ConnId,
	  sCommandMsg.sCmd.sCOMMKM_InitializeCmd.apsWBDataInfo,
	  sCommandMsg.sCmd.sCOMMKM_InitializeCmd.pui32NumPipes,
	  sCommandMsg.sCmd.sCOMMKM_InitializeCmd.ui32MmuFlags,
	  sCommandMsg.sCmd.sCOMMKM_InitializeCmd.ui32MMUTileStride
      );
      break;
      
    
      case COMMKM_OpenSocket_ID:
      
#if 0
#ifdef CONFIG_COMPAT      
      printk("bridge %d %s %s\n", is_compat_task(), __FUNCTION__, "COMMKM_OpenSocket");
#else
      printk("bridge %s %s\n", __FUNCTION__, "COMMKM_OpenSocket");
#endif
#endif
      
	sResponseMsg.sResp.sCOMMKM_OpenSocketResp.xCOMMKM_OpenSocketResp =
      		COMMKM_OpenSocket(
      
	  sCommandMsg.sCmd.sCOMMKM_OpenSocketCmd.ui32ConnId,
	  sCommandMsg.sCmd.sCOMMKM_OpenSocketCmd.ui32SockId,
	  sCommandMsg.sCmd.sCOMMKM_OpenSocketCmd.eCodec
      );
      break;
      
    
      case COMMKM_SetupSocket_ID:
      
#if 0
#ifdef CONFIG_COMPAT      
      printk("bridge %d %s %s\n", is_compat_task(), __FUNCTION__, "COMMKM_SetupSocket");
#else
      printk("bridge %s %s\n", __FUNCTION__, "COMMKM_SetupSocket");
#endif
#endif
      
	sResponseMsg.sResp.sCOMMKM_SetupSocketResp.xCOMMKM_SetupSocketResp =
      		COMMKM_SetupSocket(
      
	  sCommandMsg.sCmd.sCOMMKM_SetupSocketCmd.ui32SockId,
	  sCommandMsg.sCmd.sCOMMKM_SetupSocketCmd.psBiasTables,
	  sCommandMsg.sCmd.sCOMMKM_SetupSocketCmd.ui16FrameHeight,
	  sCommandMsg.sCmd.sCOMMKM_SetupSocketCmd.ui16Width,
	  sCommandMsg.sCmd.sCOMMKM_SetupSocketCmd.bDoSerializedComm,
	  sCommandMsg.sCmd.sCOMMKM_SetupSocketCmd.ui8CtxtNum,
	  sCommandMsg.sCmd.sCOMMKM_SetupSocketCmd.usedSocket
      );
      break;
      
    
      case COMMKM_CloseSocket_ID:
      
#if 0
#ifdef CONFIG_COMPAT      
      printk("bridge %d %s %s\n", is_compat_task(), __FUNCTION__, "COMMKM_CloseSocket");
#else
      printk("bridge %s %s\n", __FUNCTION__, "COMMKM_CloseSocket");
#endif
#endif
      
	sResponseMsg.sResp.sCOMMKM_CloseSocketResp.xCOMMKM_CloseSocketResp =
      		COMMKM_CloseSocket(
      
	  sCommandMsg.sCmd.sCOMMKM_CloseSocketCmd.ui32SockId
      );
      break;
      
    
      case COMMKM_Send_ID:
      
#if 0
#ifdef CONFIG_COMPAT      
      printk("bridge %d %s %s\n", is_compat_task(), __FUNCTION__, "COMMKM_Send");
#else
      printk("bridge %s %s\n", __FUNCTION__, "COMMKM_Send");
#endif
#endif
      
	sResponseMsg.sResp.sCOMMKM_SendResp.xCOMMKM_SendResp =
      		COMMKM_Send(
      
	  sCommandMsg.sCmd.sCOMMKM_SendCmd.ui32SockId,
	  sCommandMsg.sCmd.sCOMMKM_SendCmd.msg_eCmdId,
	  sCommandMsg.sCmd.sCOMMKM_SendCmd.msg_ui32Data,
	  sCommandMsg.sCmd.sCOMMKM_SendCmd.msg_pCommandDataBuf,
	  sCommandMsg.sCmd.sCOMMKM_SendCmd.pui32WritebackVal
      );
      break;
      
    
      case COMMKM_Recv_ID:
      
#if 0
#ifdef CONFIG_COMPAT      
      printk("bridge %d %s %s\n", is_compat_task(), __FUNCTION__, "COMMKM_Recv");
#else
      printk("bridge %s %s\n", __FUNCTION__, "COMMKM_Recv");
#endif
#endif
      
	sResponseMsg.sResp.sCOMMKM_RecvResp.xCOMMKM_RecvResp =
      		COMMKM_Recv(
      
	  sCommandMsg.sCmd.sCOMMKM_RecvCmd.ui32SockId,
	  sCommandMsg.sCmd.sCOMMKM_RecvCmd.pMsg,
	  sCommandMsg.sCmd.sCOMMKM_RecvCmd.bBlocking
      );
      break;
      
    
      case COMMKM_LoadBias_ID:
      
#if 0
#ifdef CONFIG_COMPAT      
      printk("bridge %d %s %s\n", is_compat_task(), __FUNCTION__, "COMMKM_LoadBias");
#else
      printk("bridge %s %s\n", __FUNCTION__, "COMMKM_LoadBias");
#endif
#endif
      
	sResponseMsg.sResp.sCOMMKM_LoadBiasResp.xCOMMKM_LoadBiasResp =
      		COMMKM_LoadBias(
      
	  sCommandMsg.sCmd.sCOMMKM_LoadBiasCmd.psBiasTables,
	  sCommandMsg.sCmd.sCOMMKM_LoadBiasCmd.eStandard
      );
      break;
      
    
      case COMMKM_GetFwConfigInt_ID:
      
#if 0
#ifdef CONFIG_COMPAT      
      printk("bridge %d %s %s\n", is_compat_task(), __FUNCTION__, "COMMKM_GetFwConfigInt");
#else
      printk("bridge %s %s\n", __FUNCTION__, "COMMKM_GetFwConfigInt");
#endif
#endif
      
	sResponseMsg.sResp.sCOMMKM_GetFwConfigIntResp.xCOMMKM_GetFwConfigIntResp =
      		COMMKM_GetFwConfigInt(
      
	  sCommandMsg.sCmd.sCOMMKM_GetFwConfigIntCmd.ui32ConnId,
	  sCommandMsg.sCmd.sCOMMKM_GetFwConfigIntCmd.name,
	  sCommandMsg.sCmd.sCOMMKM_GetFwConfigIntCmd.szNameSize
      );
      break;
      
    
      case COMM_GetPipeUsage_ID:
      
#if 0
#ifdef CONFIG_COMPAT      
      printk("bridge %d %s %s\n", is_compat_task(), __FUNCTION__, "COMM_GetPipeUsage");
#else
      printk("bridge %s %s\n", __FUNCTION__, "COMM_GetPipeUsage");
#endif
#endif
      
	sResponseMsg.sResp.sCOMM_GetPipeUsageResp.xCOMM_GetPipeUsageResp =
      		COMM_GetPipeUsage(
      
	  sCommandMsg.sCmd.sCOMM_GetPipeUsageCmd.ui8Pipe
      );
      break;
      
    
      case COMM_SetPipeUsage_ID:
      
#if 0
#ifdef CONFIG_COMPAT      
      printk("bridge %d %s %s\n", is_compat_task(), __FUNCTION__, "COMM_SetPipeUsage");
#else
      printk("bridge %s %s\n", __FUNCTION__, "COMM_SetPipeUsage");
#endif
#endif
      		COMM_SetPipeUsage(
      
	  sCommandMsg.sCmd.sCOMM_SetPipeUsageCmd.ui8Pipe,
	  sCommandMsg.sCmd.sCOMM_SetPipeUsageCmd.ui8Val
      );
      break;
      
    
      case COMMKM_IsIdle_ID:
      
#if 0
#ifdef CONFIG_COMPAT      
      printk("bridge %d %s %s\n", is_compat_task(), __FUNCTION__, "COMMKM_IsIdle");
#else
      printk("bridge %s %s\n", __FUNCTION__, "COMMKM_IsIdle");
#endif
#endif
      
	sResponseMsg.sResp.sCOMMKM_IsIdleResp.xCOMMKM_IsIdleResp =
      		COMMKM_IsIdle(
      
	  sCommandMsg.sCmd.sCOMMKM_IsIdleCmd.ui32SockId
      );
      break;
      
    
      case TOPAZKM_IsIdle_ID:
      
#if 0
#ifdef CONFIG_COMPAT      
      printk("bridge %d %s %s\n", is_compat_task(), __FUNCTION__, "TOPAZKM_IsIdle");
#else
      printk("bridge %s %s\n", __FUNCTION__, "TOPAZKM_IsIdle");
#endif
#endif
      
	sResponseMsg.sResp.sTOPAZKM_IsIdleResp.xTOPAZKM_IsIdleResp =
      		TOPAZKM_IsIdle(
      
	  sCommandMsg.sCmd.sTOPAZKM_IsIdleCmd.ui32SockId
      );
      break;
      
    
      case TOPAZKM_Suspend_ID:
      
#if 0
#ifdef CONFIG_COMPAT      
      printk("bridge %d %s %s\n", is_compat_task(), __FUNCTION__, "TOPAZKM_Suspend");
#else
      printk("bridge %s %s\n", __FUNCTION__, "TOPAZKM_Suspend");
#endif
#endif
      		TOPAZKM_Suspend(
      
	  sCommandMsg.sCmd.sTOPAZKM_SuspendCmd.ui32ConnId
      );
      break;
      
    
      case TOPAZKM_Resume_ID:
      
#if 0
#ifdef CONFIG_COMPAT      
      printk("bridge %d %s %s\n", is_compat_task(), __FUNCTION__, "TOPAZKM_Resume");
#else
      printk("bridge %s %s\n", __FUNCTION__, "TOPAZKM_Resume");
#endif
#endif
      		TOPAZKM_Resume(
      
	  sCommandMsg.sCmd.sTOPAZKM_ResumeCmd.ui32ConnId
      );
      break;
      
    
      case TOPAZKM_GetCoreDes1_ID:
      
#if 0
#ifdef CONFIG_COMPAT      
      printk("bridge %d %s %s\n", is_compat_task(), __FUNCTION__, "TOPAZKM_GetCoreDes1");
#else
      printk("bridge %s %s\n", __FUNCTION__, "TOPAZKM_GetCoreDes1");
#endif
#endif
      
	sResponseMsg.sResp.sTOPAZKM_GetCoreDes1Resp.xTOPAZKM_GetCoreDes1Resp =
      		TOPAZKM_GetCoreDes1(
      
      );
      break;
      
    
      case TOPAZKM_GetCoreRev_ID:
      
#if 0
#ifdef CONFIG_COMPAT      
      printk("bridge %d %s %s\n", is_compat_task(), __FUNCTION__, "TOPAZKM_GetCoreRev");
#else
      printk("bridge %s %s\n", __FUNCTION__, "TOPAZKM_GetCoreRev");
#endif
#endif
      
	sResponseMsg.sResp.sTOPAZKM_GetCoreRevResp.xTOPAZKM_GetCoreRevResp =
      		TOPAZKM_GetCoreRev(
      
      );
      break;
      
    
      case TOPAZKM_GetNumPipes_ID:
      
#if 0
#ifdef CONFIG_COMPAT      
      printk("bridge %d %s %s\n", is_compat_task(), __FUNCTION__, "TOPAZKM_GetNumPipes");
#else
      printk("bridge %s %s\n", __FUNCTION__, "TOPAZKM_GetNumPipes");
#endif
#endif
      
	sResponseMsg.sResp.sTOPAZKM_GetNumPipesResp.xTOPAZKM_GetNumPipesResp =
      		TOPAZKM_GetNumPipes(
      
      );
      break;
      
    
	}
	if(SYSOSKM_CopyToUser(psPacket->pvRespData, &sResponseMsg, sizeof(sResponseMsg)))
		IMG_ASSERT(!"failed to copy to user");
}