/* * ======== ListMP_putTail ======== */ Int ListMP_putTail(ListMP_Handle handle, ListMP_Elem *elem) { ti_sdo_ipc_ListMP_Object *obj = (ti_sdo_ipc_ListMP_Object *)handle; UInt key; UInt16 id; ListMP_Elem *localPrevElem; SharedRegion_SRPtr sharedElem; SharedRegion_SRPtr sharedHead; Bool localPrevElemIsCached; /* prevent another thread or processor from modifying the ListMP */ key = GateMP_enter((GateMP_Handle)obj->gate); id = SharedRegion_getId(elem); if (ti_sdo_ipc_SharedRegion_translate == FALSE) { sharedElem = (SharedRegion_SRPtr)elem; sharedHead = (SharedRegion_SRPtr)&(obj->attrs->head); localPrevElem = (ListMP_Elem *)obj->attrs->head.prev; } else { sharedElem = SharedRegion_getSRPtr(elem, id); sharedHead = SharedRegion_getSRPtr(&(obj->attrs->head), obj->regionId); localPrevElem = SharedRegion_getPtr(obj->attrs->head.prev); } /* Assert that pointer is not NULL */ Assert_isTrue(localPrevElem != NULL, ti_sdo_ipc_Ipc_A_nullPointer); localPrevElemIsCached = SharedRegion_isCacheEnabled( SharedRegion_getId(localPrevElem)); if (localPrevElemIsCached) { Cache_inv(localPrevElem, sizeof(ListMP_Elem), Cache_Type_ALL, TRUE); } /* add the new elem into the list */ elem->next = sharedHead; elem->prev = obj->attrs->head.prev; localPrevElem->next = sharedElem; obj->attrs->head.prev = sharedElem; if (localPrevElemIsCached) { /* Write-back because localPrevElem->next changed */ Cache_wbInv(localPrevElem, sizeof(ListMP_Elem), Cache_Type_ALL, TRUE); } if (obj->cacheEnabled) { /* Write-back because obj->attrs->head.prev changed */ Cache_wbInv(&(obj->attrs->head), sizeof(ListMP_Elem), Cache_Type_ALL, TRUE); } if (SharedRegion_isCacheEnabled(id)) { /* Write-back because elem->next & elem->prev changed */ Cache_wbInv(elem, sizeof(ListMP_Elem), Cache_Type_ALL, TRUE); } GateMP_leave((GateMP_Handle)obj->gate, key); return (ListMP_S_SUCCESS); }
Int32 Vsys_allocBuf(UInt32 srRegId, UInt32 bufSize, UInt32 bufAlign, Vsys_AllocBufInfo *bufInfo) { IHeap_Handle heapHndl; heapHndl = SharedRegion_getHeap(srRegId); OSA_assert(heapHndl != NULL); bufInfo->virtAddr = NULL; bufInfo->physAddr = NULL; bufInfo->srPtr = 0; bufInfo->virtAddr = Memory_alloc(heapHndl, bufSize, bufAlign, NULL); if(bufInfo->virtAddr==NULL) return -1; bufInfo->physAddr = Memory_translate (bufInfo->virtAddr, Memory_XltFlags_Virt2Phys); if(bufInfo->physAddr==NULL) return -1; bufInfo->srPtr = SharedRegion_getSRPtr(bufInfo->virtAddr,srRegId); return 0; }
int syslink_frameq_open(resmgr_context_t *ctp, io_devctl_t *msg, syslink_ocb_t *ocb) { FrameQDrv_CmdArgs *cargs = (FrameQDrv_CmdArgs *) (_DEVCTL_DATA (msg->i)); FrameQDrv_CmdArgs *out = (FrameQDrv_CmdArgs *) (_DEVCTL_DATA (msg->o)); Ptr openParams = NULL; UInt16 index; FrameQ_Handle handle; Ptr mgrshMem; Ptr gateShMem; openParams = (Ptr)(cargs+1); /* Convert the shared control address to virtual format */ ((FrameQ_OpenParams *)openParams)-> commonOpenParams.sharedAddr = SharedRegion_getPtr ((SharedRegion_SRPtr) ((FrameQ_OpenParams *)openParams)->commonOpenParams.sharedAddr); if (cargs->args.open.nameLen > 0) ((FrameQ_OpenParams *)openParams)->commonOpenParams.name = (String)(((FrameQ_ShMem_OpenParams*)openParams) + 1); out->apiStatus = FrameQ_open (openParams,&handle); GT_assert (curTrace, (out->apiStatus >= 0)); out->args.open.handle = handle; if (cargs->args.open.handle != NULL) { mgrshMem = _FrameQ_getCliNotifyMgrShAddr(cargs->args.open.handle); index = SharedRegion_getId(mgrshMem); out->args.open.cliNotifyMgrSharedMem = SharedRegion_getSRPtr(mgrshMem, index); gateShMem = _FrameQ_getCliNotifyMgrGateShAddr(cargs->args.open.handle); index = SharedRegion_getId(gateShMem); out->args.open.cliGateSharedMem = SharedRegion_getSRPtr(gateShMem, index); } return (_RESMGR_PTR (ctp, &msg->o, sizeof (msg->o) + sizeof(FrameQDrv_CmdArgs))); }
/* * ======== ti_sdo_ipc_ListMP_elemClear ======== */ Void ti_sdo_ipc_ListMP_elemClear(ti_sdo_ipc_ListMP_Elem *elem) { SharedRegion_SRPtr sharedElem; UInt16 id; id = SharedRegion_getId(elem); sharedElem = SharedRegion_getSRPtr(elem, id); elem->next = elem->prev = sharedElem; if (SharedRegion_isCacheEnabled(id)) { Cache_wbInv(elem, sizeof(ListMP_Elem), Cache_Type_ALL, TRUE); } }
/* Function to allocate memory from the SyslinkMemMgr.Calls sharedregion API to do * address translations */ Ptr SyslinkMemMgr_SharedMemory_translate(SyslinkMemMgr_SharedMemory_Object *obj, Ptr srcAddr, SyslinkMemMgr_AddrType srcAddrType, SyslinkMemMgr_AddrType desAddrType) { Ptr dstAddr = NULL; Int32 index; if (obj != NULL) { if (srcAddrType == desAddrType) { /* Return NULL if both addr types are same */ dstAddr = srcAddr; } else { switch (srcAddrType) { case SyslinkMemMgr_AddrType_Virtual: if (desAddrType == SyslinkMemMgr_AddrType_Portable) { index = SharedRegion_getId((Ptr)srcAddr); dstAddr = (Ptr)SharedRegion_getSRPtr((Ptr)srcAddr, index); if (dstAddr == (Ptr)ti_sdo_ipc_SharedRegion_INVALIDSRPTR) { dstAddr = NULL; } } break; case SyslinkMemMgr_AddrType_Portable: if (desAddrType == SyslinkMemMgr_AddrType_Virtual) { dstAddr = SharedRegion_getPtr( (SharedRegion_SRPtr)srcAddr); } break; default: dstAddr = NULL; break; } } } return (dstAddr); }
/** * Handler for heapbufmp alloc API. * * \param ctp Thread's associated context information. * \param msg The actual devctl() message. * \param ocb OCB associated with client's session. * * \return POSIX errno value. * * \retval EOK Success. * \retval ENOTSUP Unsupported devctl(). */ int syslink_heapbufmp_alloc(resmgr_context_t *ctp, io_devctl_t *msg, syslink_ocb_t *ocb) { HeapBufMPDrv_CmdArgs * cargs = (HeapBufMPDrv_CmdArgs *) (_DEVCTL_DATA (msg->i)); HeapBufMPDrv_CmdArgs * out = (HeapBufMPDrv_CmdArgs *) (_DEVCTL_DATA (msg->o)); Char * block; SharedRegion_SRPtr blockSrPtr = SharedRegion_INVALIDSRPTR; UInt16 index = SharedRegion_INVALIDREGIONID; block = HeapBufMP_alloc (cargs->args.alloc.handle, cargs->args.alloc.size, cargs->args.alloc.align); if (block != NULL) { index = SharedRegion_getId (block); blockSrPtr = SharedRegion_getSRPtr (block, index); } out->args.alloc.blockSrPtr = blockSrPtr; out->apiStatus = HeapBufMP_S_SUCCESS; return (_RESMGR_PTR (ctp, &msg->o, sizeof (msg->o) + sizeof(HeapBufMPDrv_CmdArgs))); }
/** * Handler for messageq get API. * * \param ctp Thread's associated context information. * \param msg The actual devctl() message. * \param ocb OCB associated with client's session. * * \return POSIX errno value. * * \retval EOK Success. * \retval ENOTSUP Unsupported devctl(). */ int syslink_messageq_get(resmgr_context_t *ctp, io_devctl_t *msg, syslink_ocb_t *ocb) { MessageQDrv_CmdArgs * cargs = (MessageQDrv_CmdArgs *) (_DEVCTL_DATA (msg->i)); MessageQDrv_CmdArgs * out = (MessageQDrv_CmdArgs *) (_DEVCTL_DATA (msg->o)); MessageQ_Msg lmsg = NULL; SharedRegion_SRPtr msgSrPtr = SharedRegion_INVALIDSRPTR; UInt16 index; out->apiStatus = MessageQ_get (cargs->args.get.handle, &lmsg, cargs->args.get.timeout); if (out->apiStatus >= 0) { index = SharedRegion_getId (lmsg); msgSrPtr = SharedRegion_getSRPtr (lmsg, index); } out->args.get.msgSrPtr = msgSrPtr; return (_RESMGR_PTR (ctp, &msg->o, sizeof (msg->o) + sizeof(MessageQDrv_CmdArgs))); }
/* * ======== ListMP_empty ======== */ Bool ListMP_empty(ListMP_Handle handle) { ti_sdo_ipc_ListMP_Object *obj = (ti_sdo_ipc_ListMP_Object *)handle; Bool flag = FALSE; IArg key; SharedRegion_SRPtr sharedHead; /* prevent another thread or processor from modifying the ListMP */ key = GateMP_enter((GateMP_Handle)obj->gate); if (ti_sdo_ipc_SharedRegion_translate == FALSE) { /* get the SRPtr for the head */ sharedHead = (SharedRegion_SRPtr)&(obj->attrs->head); } else { /* get the SRPtr for the head */ sharedHead = SharedRegion_getSRPtr(&(obj->attrs->head), obj->regionId); } /* if 'next' is ourself, then the ListMP must be empty */ if (obj->attrs->head.next == sharedHead) { flag = TRUE; } if (obj->cacheEnabled) { /* invalidate the head to make sure we are not getting stale data */ Cache_inv(&(obj->attrs->head), sizeof(ListMP_Elem), Cache_Type_ALL, TRUE); } /* leave the gate */ GateMP_leave((GateMP_Handle)obj->gate, key); return (flag); }
/** * Handler for messageq alloc API. * * \param ctp Thread's associated context information. * \param msg The actual devctl() message. * \param ocb OCB associated with client's session. * * \return POSIX errno value. * * \retval EOK Success. * \retval ENOTSUP Unsupported devctl(). */ int syslink_messageq_alloc(resmgr_context_t *ctp, io_devctl_t *msg, syslink_ocb_t *ocb) { MessageQDrv_CmdArgs * cargs = (MessageQDrv_CmdArgs *) (_DEVCTL_DATA (msg->i)); MessageQDrv_CmdArgs * out = (MessageQDrv_CmdArgs *) (_DEVCTL_DATA (msg->o)); MessageQ_Msg lmsg; SharedRegion_SRPtr msgSrPtr = SharedRegion_INVALIDSRPTR; UInt16 index; lmsg = MessageQ_alloc (cargs->args.alloc.heapId, cargs->args.alloc.size); if (lmsg != NULL) { index = SharedRegion_getId (lmsg); msgSrPtr = SharedRegion_getSRPtr (lmsg, index); cargs->apiStatus = MessageQ_S_SUCCESS; } else { cargs->apiStatus = MessageQ_E_FAIL; } out->args.alloc.msgSrPtr = msgSrPtr; return (_RESMGR_PTR (ctp, &msg->o, sizeof (msg->o) + sizeof(MessageQDrv_CmdArgs))); }
/* * ======== Ipc_attach ======== */ Int Ipc_attach(UInt16 remoteProcId) { Int i; Ptr sharedAddr; SizeT memReq; volatile ti_sdo_ipc_Ipc_Reserved *slave; ti_sdo_ipc_Ipc_ProcEntry *ipc; Error_Block eb; SharedRegion_Entry entry; SizeT reservedSize = ti_sdo_ipc_Ipc_reservedSizePerProc(); Bool cacheEnabled = SharedRegion_isCacheEnabled(0); UInt16 clusterId = ti_sdo_utils_MultiProc_getClusterId(remoteProcId); Int status; UInt hwiKey; /* Assert remoteProcId is in our cluster and isn't our own */ Assert_isTrue(clusterId < ti_sdo_utils_MultiProc_numProcsInCluster, ti_sdo_utils_MultiProc_A_invalidMultiProcId); Assert_isTrue(remoteProcId != MultiProc_self(), ti_sdo_ipc_Ipc_A_invArgument); /* Check whether Ipc_start has been called. If not, fail. */ if (Ipc_module->ipcSharedAddr == NULL) { return (Ipc_E_FAIL); } /* for checking and incrementing attached below */ hwiKey = Hwi_disable(); /* Make sure its not already attached */ if (Ipc_module->procEntry[clusterId].attached) { Ipc_module->procEntry[clusterId].attached++; /* restore interrupts and return */ Hwi_restore(hwiKey); return (Ipc_S_ALREADYSETUP); } /* restore interrupts */ Hwi_restore(hwiKey); /* get region 0 information */ SharedRegion_getEntry(0, &entry); /* Make sure we've attached to owner of SR0 if we're not owner */ if ((MultiProc_self() != entry.ownerProcId) && (remoteProcId != entry.ownerProcId) && !(Ipc_module->procEntry[ti_sdo_utils_MultiProc_getClusterId( entry.ownerProcId)].attached)) { return (Ipc_E_FAIL); } /* Init error block */ Error_init(&eb); /* determine the slave's slot */ slave = Ipc_getSlaveAddr(remoteProcId, Ipc_module->ipcSharedAddr); if (cacheEnabled) { Cache_inv((Ptr)slave, reservedSize, Cache_Type_ALL, TRUE); } /* Synchronize the processors. */ status = Ipc_procSyncStart(remoteProcId, Ipc_module->ipcSharedAddr); if (status < 0) { return (status); } /* must be called before SharedRegion_attach */ status = ti_sdo_ipc_GateMP_attach(remoteProcId, Ipc_module->gateMPSharedAddr); if (status < 0) { return (status); } /* retrieves the SharedRegion Heap handles */ status = ti_sdo_ipc_SharedRegion_attach(remoteProcId); if (status < 0) { return (status); } /* get the attach parameters associated with remoteProcId */ ipc = &(Ipc_module->procEntry[clusterId]); /* attach Notify if not yet attached and specified to set internal setup */ if (!(Notify_intLineRegistered(remoteProcId, 0)) && (ipc->entry.setupNotify)) { /* call Notify_attach */ memReq = Notify_sharedMemReq(remoteProcId, Ipc_module->ipcSharedAddr); if (memReq != 0) { if (MultiProc_self() < remoteProcId) { /* * calloc required here due to race condition. Its possible * that the slave, who creates the instance, tries a sendEvent * before the master has created its instance because the * state of memory was enabled from a previous run. */ sharedAddr = Memory_calloc(SharedRegion_getHeap(0), memReq, SharedRegion_getCacheLineSize(0), &eb); /* make sure alloc did not fail */ if (sharedAddr == NULL) { return (Ipc_E_MEMORY); } /* if cache enabled, wbInv the calloc above */ if (cacheEnabled) { Cache_wbInv(sharedAddr, memReq, Cache_Type_ALL, TRUE); } /* set the notify SRPtr */ slave->notifySRPtr = SharedRegion_getSRPtr(sharedAddr, 0); } else { /* get the notify SRPtr */ sharedAddr = SharedRegion_getPtr(slave->notifySRPtr); } } else { sharedAddr = NULL; slave->notifySRPtr = 0; } /* call attach to remote processor */ status = Notify_attach(remoteProcId, sharedAddr); if (status < 0) { if (MultiProc_self() < remoteProcId && sharedAddr != NULL) { /* free the memory back to SharedRegion 0 heap */ Memory_free(SharedRegion_getHeap(0), sharedAddr, memReq); } return (Ipc_E_FAIL); } } /* Must come after GateMP_start because depends on default GateMP */ if (!(ti_sdo_utils_NameServer_isRegistered(remoteProcId)) && (ipc->entry.setupNotify)) { memReq = ti_sdo_utils_NameServer_SetupProxy_sharedMemReq( Ipc_module->ipcSharedAddr); if (memReq != 0) { if (MultiProc_self() < remoteProcId) { sharedAddr = Memory_alloc(SharedRegion_getHeap(0), memReq, SharedRegion_getCacheLineSize(0), &eb); /* make sure alloc did not fail */ if (sharedAddr == NULL) { return (Ipc_E_MEMORY); } /* set the NSRN SRPtr */ slave->nsrnSRPtr = SharedRegion_getSRPtr(sharedAddr, 0); } else { /* get the NSRN SRPtr */ sharedAddr = SharedRegion_getPtr(slave->nsrnSRPtr); } } else { sharedAddr = NULL; slave->nsrnSRPtr = 0; } /* call attach to remote processor */ status = ti_sdo_utils_NameServer_SetupProxy_attach(remoteProcId, sharedAddr); if (status < 0) { if (MultiProc_self() < remoteProcId && sharedAddr != NULL) { /* free the memory back to SharedRegion 0 heap */ Memory_free(SharedRegion_getHeap(0), sharedAddr, memReq); } return (Ipc_E_FAIL); } } /* Must come after GateMP_start because depends on default GateMP */ if (!(ti_sdo_ipc_MessageQ_SetupTransportProxy_isRegistered(remoteProcId)) && (ipc->entry.setupMessageQ)) { memReq = ti_sdo_ipc_MessageQ_SetupTransportProxy_sharedMemReq( Ipc_module->ipcSharedAddr); if (memReq != 0) { if (MultiProc_self() < remoteProcId) { sharedAddr = Memory_alloc(SharedRegion_getHeap(0), memReq, SharedRegion_getCacheLineSize(0), &eb); /* make sure alloc did not fail */ if (sharedAddr == NULL) { return (Ipc_E_MEMORY); } /* set the transport SRPtr */ slave->transportSRPtr = SharedRegion_getSRPtr(sharedAddr, 0); } else { /* get the transport SRPtr */ sharedAddr = SharedRegion_getPtr(slave->transportSRPtr); } } else { sharedAddr = NULL; slave->transportSRPtr = 0; } /* call attach to remote processor */ status = ti_sdo_ipc_MessageQ_SetupTransportProxy_attach(remoteProcId, sharedAddr); if (status < 0) { if (MultiProc_self() < remoteProcId && sharedAddr != NULL) { /* free the memory back to SharedRegion 0 heap */ Memory_free(SharedRegion_getHeap(0), sharedAddr, memReq); } return (Ipc_E_FAIL); } } /* writeback invalidate slave's shared memory if cache enabled */ if (cacheEnabled) { if (MultiProc_self() < remoteProcId) { Cache_wbInv((Ptr)slave, reservedSize, Cache_Type_ALL, TRUE); } } /* Call user attach fxns */ for (i = 0; i < ti_sdo_ipc_Ipc_numUserFxns; i++) { if (ti_sdo_ipc_Ipc_userFxns[i].userFxn.attach) { status = ti_sdo_ipc_Ipc_userFxns[i].userFxn.attach( ti_sdo_ipc_Ipc_userFxns[i].arg, remoteProcId); if (status < 0) { return (status); } } } /* Finish the processor synchronization */ status = ti_sdo_ipc_Ipc_procSyncFinish(remoteProcId, Ipc_module->ipcSharedAddr); if (status < 0) { return (status); } /* for atomically incrementing attached */ hwiKey = Hwi_disable(); /* now attached to remote processor */ Ipc_module->procEntry[clusterId].attached++; /* restore interrupts */ Hwi_restore(hwiKey); return (status); }
/* * ======== Ipc_writeConfig ======== */ Int Ipc_writeConfig(UInt16 remoteProcId, UInt32 tag, Ptr cfg, SizeT size) { Int status = Ipc_S_SUCCESS; UInt16 clusterId = ti_sdo_utils_MultiProc_getClusterId(remoteProcId); SharedRegion_SRPtr curSRPtr, *prevSRPtr; ti_sdo_ipc_Ipc_ConfigEntry *entry; Error_Block eb; Bool cacheEnabled = SharedRegion_isCacheEnabled(0); /* Assert that the remoteProc in our cluster */ Assert_isTrue(clusterId < ti_sdo_utils_MultiProc_numProcsInCluster, ti_sdo_utils_MultiProc_A_invalidMultiProcId); Error_init(&eb); if (cfg == NULL) { status = Ipc_E_FAIL; /* get head of local config list and set prevSRPtr to it */ prevSRPtr = (Ipc_module->procEntry[clusterId].localConfigList); /* * When cfg is NULL, the last memory allocated from a previous * Ipc_writeConfig call with the same remoteProcId, tag, and size * is freed. */ curSRPtr = *prevSRPtr; /* loop through list of config entries until matching entry is found */ while (curSRPtr != ti_sdo_ipc_SharedRegion_INVALIDSRPTR) { /* convert Ptr associated with curSRPtr */ entry = (ti_sdo_ipc_Ipc_ConfigEntry *) (SharedRegion_getPtr(curSRPtr)); /* make sure entry matches remoteProcId, tag, and size */ if ((entry->remoteProcId == remoteProcId) && (entry->tag == tag) && (entry->size == size)) { /* Update the 'prev' next ptr */ *prevSRPtr = (SharedRegion_SRPtr)entry->next; /* writeback the 'prev' ptr */ if (cacheEnabled) { Cache_wb(prevSRPtr, sizeof(ti_sdo_ipc_Ipc_ConfigEntry), Cache_Type_ALL, FALSE); } /* free entry's memory back to shared heap */ Memory_free(SharedRegion_getHeap(0), entry, size + sizeof(ti_sdo_ipc_Ipc_ConfigEntry)); /* set the status to success */ status = Ipc_S_SUCCESS; break; } /* set the 'prev' to the 'cur' SRPtr */ prevSRPtr = (SharedRegion_SRPtr *)(&entry->next); /* point to next config entry */ curSRPtr = (SharedRegion_SRPtr)entry->next; } /* return that status */ return (status); } /* Allocate memory from the shared heap (System Heap) */ entry = Memory_alloc(SharedRegion_getHeap(0), size + sizeof(ti_sdo_ipc_Ipc_ConfigEntry), SharedRegion_getCacheLineSize(0), &eb); if (entry == NULL) { return (Ipc_E_FAIL); } /* set the entry */ entry->remoteProcId = remoteProcId; entry->localProcId = MultiProc_self(); entry->tag = tag; entry->size = size; memcpy((Ptr)((UInt32)entry + sizeof(ti_sdo_ipc_Ipc_ConfigEntry)), cfg, size); /* point the entry's next to the first entry in the list */ entry->next = *Ipc_module->procEntry[clusterId].localConfigList; /* first write-back the entry if cache is enabled */ if (cacheEnabled) { Cache_wb(entry, size + sizeof(ti_sdo_ipc_Ipc_ConfigEntry), Cache_Type_ALL, FALSE); } /* set the entry as the new first in the list */ *Ipc_module->procEntry[clusterId].localConfigList = SharedRegion_getSRPtr(entry, 0); /* write-back the config list */ if (cacheEnabled) { Cache_wb(Ipc_module->procEntry[clusterId].localConfigList, SharedRegion_getCacheLineSize(0), Cache_Type_ALL, FALSE); } return (status); }
/* * ======== syslink_frameq_create ======== */ int syslink_frameq_create( resmgr_context_t * ctp, io_devctl_t * msg, syslink_ocb_t * ocb) { FrameQDrv_CmdArgs * cargs; Ptr params = NULL; FrameQ_ShMem_Params * shMemParams; Ptr mgrshMem; Ptr gateShMem; String name = NULL; UInt16 index; SharedRegion_SRPtr srptr; Ptr gateAttrs; Int status; status = 0; cargs = (FrameQDrv_CmdArgs *)(_DEVCTL_DATA(msg->i)); params = (Ptr)(cargs+1); if (cargs->args.create.nameLen > 0) { name = ((FrameQ_Params*)params)->commonCreateParams.name = (String)((FrameQ_ShMem_Params*)params+1); } if (cargs->args.create.interfaceType == FrameQ_INTERFACE_SHAREDMEM) { shMemParams = (FrameQ_ShMem_Params*)params; shMemParams->sharedAddr = SharedRegion_getPtr((SharedRegion_SRPtr)shMemParams->sharedAddr); if ((SharedRegion_SRPtr)shMemParams->frameQBufMgrSharedAddr == SharedRegion_INVALIDSRPTR) { shMemParams->frameQBufMgrSharedAddr = NULL; } else { shMemParams->frameQBufMgrSharedAddr = SharedRegion_getPtr((SharedRegion_SRPtr) shMemParams->frameQBufMgrSharedAddr); } /* Copy FrameQ BufMgr Name */ if (cargs->args.create.nameLen > 0) { if (cargs->args.create.fQBMnameLen > 0) { shMemParams->frameQBufMgrName = (String)(name + cargs->args.create.nameLen); } } else if (cargs->args.create.fQBMnameLen > 0) { shMemParams->frameQBufMgrName = (String)((FrameQ_ShMem_Params*)params+1); } /* open the gate instance to get a handle */ srptr = (SharedRegion_SRPtr)shMemParams->gate; if (srptr != SharedRegion_INVALIDSRPTR) { gateAttrs = SharedRegion_getPtr(srptr); status = GateMP_openByAddr(gateAttrs, &shMemParams->gate); } else { shMemParams->gate = NULL; } } /* Call FrameQ_create with the updated params */ if (status >= 0) { cargs->args.create.handle = FrameQ_create(params); } else { cargs->args.create.handle = NULL; } if (cargs->args.create.handle != NULL) { /* Get the required info to be able to create ClientNotify * Mgr instane at user space */ mgrshMem = _FrameQ_getCliNotifyMgrShAddr(cargs->args.create.handle); index = SharedRegion_getId(mgrshMem); cargs->args.create.cliNotifyMgrSharedMem = SharedRegion_getSRPtr(mgrshMem, index); gateShMem=_FrameQ_getCliNotifyMgrGateShAddr(cargs->args.create.handle); index = SharedRegion_getId(gateShMem); cargs->args.create.cliGateSharedMem = SharedRegion_getSRPtr(gateShMem, index); } /* clear the return message, setup return values */ memset(&msg->o, 0, sizeof(msg->o)); msg->o.nbytes = sizeof(FrameQDrv_CmdArgs); return(_RESMGR_PTR(ctp, &msg->o, sizeof(msg->o) + msg->o.nbytes)); }
/* * ======== ti_sdo_ipc_ListMP_Instance_init ======== */ Int ti_sdo_ipc_ListMP_Instance_init(ti_sdo_ipc_ListMP_Object *obj, const ti_sdo_ipc_ListMP_Params *params, Error_Block *eb) { SharedRegion_SRPtr sharedShmBase; Ptr localAddr; Int status; ListMP_Params sparams; IHeap_Handle regionHeap; if (params->openFlag == TRUE) { /* Open by sharedAddr */ obj->objType = ti_sdo_ipc_Ipc_ObjType_OPENDYNAMIC; obj->attrs = (ti_sdo_ipc_ListMP_Attrs *)params->sharedAddr; obj->regionId = SharedRegion_getId(&(obj->attrs->head)); obj->cacheEnabled = SharedRegion_isCacheEnabled(obj->regionId); obj->cacheLineSize = SharedRegion_getCacheLineSize(obj->regionId); /* get the local address of the SRPtr */ localAddr = SharedRegion_getPtr(obj->attrs->gateMPAddr); status = GateMP_openByAddr(localAddr, (GateMP_Handle *)&(obj->gate)); if (status != GateMP_S_SUCCESS) { Error_raise(eb, ti_sdo_ipc_Ipc_E_internal, 0, 0); return (1); } return (0); } /* init the gate */ if (params->gate != NULL) { obj->gate = params->gate; } else { obj->gate = (ti_sdo_ipc_GateMP_Handle)GateMP_getDefaultRemote(); } if (params->sharedAddr == NULL) { /* Creating using a shared region ID */ obj->objType = ti_sdo_ipc_Ipc_ObjType_CREATEDYNAMIC_REGION; obj->regionId = params->regionId; obj->cacheEnabled = SharedRegion_isCacheEnabled(obj->regionId); obj->cacheLineSize = SharedRegion_getCacheLineSize(obj->regionId); /* Need to allocate from the heap */ ListMP_Params_init(&sparams); sparams.regionId = params->regionId; obj->allocSize = ListMP_sharedMemReq(&sparams); regionHeap = SharedRegion_getHeap(obj->regionId); Assert_isTrue(regionHeap != NULL, ti_sdo_ipc_SharedRegion_A_noHeap); /* The region heap will take care of the alignment */ obj->attrs = Memory_alloc(regionHeap, obj->allocSize, 0, eb); if (obj->attrs == NULL) { return (2); } } else { /* Creating using sharedAddr */ obj->regionId = SharedRegion_getId(params->sharedAddr); /* Assert that the buffer is in a valid shared region */ Assert_isTrue(obj->regionId != SharedRegion_INVALIDREGIONID, ti_sdo_ipc_Ipc_A_addrNotInSharedRegion); /* set object's cacheEnabled, objType, and attrs */ obj->cacheEnabled = SharedRegion_isCacheEnabled(obj->regionId); obj->cacheLineSize = SharedRegion_getCacheLineSize(obj->regionId); obj->objType = ti_sdo_ipc_Ipc_ObjType_CREATEDYNAMIC; obj->attrs = (ti_sdo_ipc_ListMP_Attrs *)params->sharedAddr; /* Assert that sharedAddr is cache aligned */ Assert_isTrue((obj->cacheLineSize == 0) || ((UInt32)params->sharedAddr % obj->cacheLineSize == 0), ti_sdo_ipc_Ipc_A_addrNotCacheAligned); } /* init the head (to be empty) */ ListMP_elemClear(&(obj->attrs->head)); /* store the GateMP sharedAddr in the Attrs */ obj->attrs->gateMPAddr = ti_sdo_ipc_GateMP_getSharedAddr(obj->gate); /* last thing, set the status */ obj->attrs->status = ti_sdo_ipc_ListMP_CREATED; if (obj->cacheEnabled) { Cache_wbInv(obj->attrs, sizeof(ti_sdo_ipc_ListMP_Attrs), Cache_Type_ALL, TRUE); } /* add to NameServer if name not NULL */ if (params->name != NULL) { sharedShmBase = SharedRegion_getSRPtr(obj->attrs, obj->regionId); obj->nsKey = NameServer_addUInt32( (NameServer_Handle)ListMP_module->nameServer, params->name, (UInt32)sharedShmBase); if (obj->nsKey == NULL) { Error_raise(eb, ti_sdo_ipc_Ipc_E_nameFailed, params->name, 0); return (3); } } return (0); }
/* * ======== ListMP_insert ======== */ Int ListMP_insert(ListMP_Handle handle, ListMP_Elem *newElem, ListMP_Elem *curElem) { ti_sdo_ipc_ListMP_Object *obj = (ti_sdo_ipc_ListMP_Object *)handle; UInt key; Int id; ListMP_Elem *localPrevElem; SharedRegion_SRPtr sharedNewElem; SharedRegion_SRPtr sharedCurElem; Bool curElemIsCached, localPrevElemIsCached; /* prevent another thread or processor from modifying the ListMP */ key = GateMP_enter((GateMP_Handle)obj->gate); if (ti_sdo_ipc_SharedRegion_translate == FALSE) { sharedNewElem = (SharedRegion_SRPtr)newElem; sharedCurElem = (SharedRegion_SRPtr)curElem; localPrevElem = (ListMP_Elem *)(curElem->prev); } else { /* get SRPtr for newElem */ id = SharedRegion_getId(newElem); sharedNewElem = SharedRegion_getSRPtr(newElem, id); /* get SRPtr for curElem */ id = SharedRegion_getId(curElem); sharedCurElem = SharedRegion_getSRPtr(curElem, id); } curElemIsCached = SharedRegion_isCacheEnabled(SharedRegion_getId(curElem)); if (curElemIsCached) { Cache_inv(curElem, sizeof(ListMP_Elem), Cache_Type_ALL, TRUE); } /* get Ptr for curElem->prev */ localPrevElem = SharedRegion_getPtr(curElem->prev); localPrevElemIsCached = SharedRegion_isCacheEnabled( SharedRegion_getId(localPrevElem)); if (localPrevElemIsCached) { Cache_inv(localPrevElem, sizeof(ListMP_Elem), Cache_Type_ALL, TRUE); } newElem->next = sharedCurElem; newElem->prev = curElem->prev; localPrevElem->next = sharedNewElem; curElem->prev = sharedNewElem; if (localPrevElemIsCached) { Cache_wbInv(localPrevElem, sizeof(ListMP_Elem), Cache_Type_ALL, TRUE); } /* * The next two Cache_wbInv needs to be done because curElem * and newElem are passed in and maybe already in the cache */ if (curElemIsCached) { /* writeback invalidate current elem structure */ Cache_wbInv(curElem, sizeof(ListMP_Elem), Cache_Type_ALL, TRUE); } if (SharedRegion_isCacheEnabled(SharedRegion_getId(newElem))) { /* writeback invalidate new elem structure */ Cache_wbInv(newElem, sizeof(ListMP_Elem), Cache_Type_ALL, TRUE); } GateMP_leave((GateMP_Handle)obj->gate, key); return (ListMP_S_SUCCESS); }
/* * ======== SemaphoreMP_Instance_init ======== */ Int SemaphoreMP_Instance_init(SemaphoreMP_Object *obj, Int count, const SemaphoreMP_Params *params, Error_Block *eb) { Ptr localAddr; Int status; IHeap_Handle regionHeap; ListMP_Params listMPParams; SharedRegion_SRPtr sharedShmBase; if (params->openFlag) { /* Open by sharedAddr */ obj->objType = ti_sdo_ipc_Ipc_ObjType_OPENDYNAMIC; obj->attrs = (SemaphoreMP_Attrs *)params->sharedAddr; obj->regionId = SharedRegion_getId(obj->attrs); obj->cacheEnabled = SharedRegion_isCacheEnabled(obj->regionId); obj->mode = (SemaphoreMP_Mode)obj->attrs->mode; regionHeap = SharedRegion_getHeap(obj->regionId); Assert_isTrue(regionHeap != NULL, ti_sdo_ipc_SharedRegion_A_noHeap); /* get the local address of the SRPtr */ localAddr = SharedRegion_getPtr(obj->attrs->gateMPAddr); status = GateMP_openByAddr(localAddr, (GateMP_Handle *)&(obj->gate)); if (status < 0) { return (1); } /* Open the ListMP */ localAddr = (Ptr)_Ipc_roundup( (UInt32)obj->attrs + sizeof(SemaphoreMP_Attrs), SharedRegion_getCacheLineSize(obj->regionId)); status = ListMP_openByAddr(localAddr, (ListMP_Handle *)&(obj->pendQ)); if (status < 0) { /* obj->freeList set to NULL */ return (4); } return (0); } /* init the gate */ if (params->gate != NULL) { obj->gate = params->gate; } else { obj->gate = (ti_sdo_ipc_GateMP_Handle)GateMP_getDefaultRemote(); } obj->mode = params->mode; if (params->sharedAddr == NULL) { /* Creating using a shared region ID */ obj->objType = ti_sdo_ipc_Ipc_ObjType_CREATEDYNAMIC_REGION; obj->regionId = params->regionId; obj->cacheEnabled = SharedRegion_isCacheEnabled(obj->regionId); /* Need to allocate from the heap */ obj->allocSize = SemaphoreMP_sharedMemReq(params); regionHeap = SharedRegion_getHeap(obj->regionId); Assert_isTrue(regionHeap != NULL, ti_sdo_ipc_SharedRegion_A_noHeap); /* The region heap will take care of the alignment */ obj->attrs = Memory_alloc(regionHeap, obj->allocSize, 0, eb); if (obj->attrs == NULL) { return (2); } } else { /* Creating using sharedAddr */ obj->regionId = SharedRegion_getId(params->sharedAddr); /* Assert that the buffer is in a valid shared region */ Assert_isTrue(obj->regionId != SharedRegion_INVALIDREGIONID, ti_sdo_ipc_Ipc_A_addrNotInSharedRegion); /* Assert that sharedAddr is cache aligned */ Assert_isTrue(((UInt32)params->sharedAddr % SharedRegion_getCacheLineSize(obj->regionId) == 0), ti_sdo_ipc_Ipc_A_addrNotCacheAligned); /* set object's cacheEnabled, objType, and attrs */ obj->cacheEnabled = SharedRegion_isCacheEnabled(obj->regionId); obj->objType = ti_sdo_ipc_Ipc_ObjType_CREATEDYNAMIC; obj->attrs = (SemaphoreMP_Attrs *)params->sharedAddr; } /* Store the GateMP sharedAddr in the SemaphoreMP Attrs */ obj->attrs->gateMPAddr = ti_sdo_ipc_GateMP_getSharedAddr(obj->gate); obj->attrs->mode = (Bits16)obj->mode; obj->attrs->count = count; /* Create the freeList */ ListMP_Params_init(&listMPParams); listMPParams.sharedAddr = (Ptr)_Ipc_roundup((UInt32)obj->attrs + sizeof(SemaphoreMP_Attrs), SharedRegion_getCacheLineSize(obj->regionId)); listMPParams.gate = (GateMP_Handle)obj->gate; obj->pendQ = (ti_sdo_ipc_ListMP_Handle)ListMP_create(&listMPParams); if (obj->pendQ == NULL) { return (3); } /* Last thing, set the status */ obj->attrs->status = SemaphoreMP_CREATED; if (obj->cacheEnabled) { Cache_wbInv(obj->attrs, sizeof(SemaphoreMP_Attrs), Cache_Type_ALL, TRUE); } /* Add entry to NameServer */ if (params->name != NULL) { /* We will store a shared pointer in the NameServer */ sharedShmBase = SharedRegion_getSRPtr(obj->attrs, obj->regionId); obj->nsKey = NameServer_addUInt32((NameServer_Handle) SemaphoreMP_module->nameServer, params->name, (UInt32)sharedShmBase); if (obj->nsKey == NULL) { /* NameServer_addUInt32 failed */ return (4); } } return (0); }