示例#1
0
/*
 *  ======== 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);
}
示例#2
0
/*
 *  ======== ListMP_sharedMemReq ========
 */
SizeT ListMP_sharedMemReq(const ListMP_Params *params)
{
    SizeT  memReq, minAlign;
    UInt16 regionId;

    if (params->sharedAddr == NULL) {
        regionId = params->regionId;
    }
    else {
        regionId = SharedRegion_getId(params->sharedAddr);
    }
    
    /* Assert that the region is valid */
    Assert_isTrue(regionId != SharedRegion_INVALIDREGIONID,
                  ti_sdo_ipc_Ipc_A_addrNotInSharedRegion);

    minAlign = Memory_getMaxDefaultTypeAlign();
    if (SharedRegion_getCacheLineSize(regionId) > minAlign) {
        minAlign = SharedRegion_getCacheLineSize(regionId);
    }

    memReq = _Ipc_roundup(sizeof(ti_sdo_ipc_ListMP_Attrs), minAlign);
    
    return (memReq);
}
示例#3
0
/*
 *  ======== SemaphoreMP_sharedMemReq ========
 */
SizeT SemaphoreMP_sharedMemReq(const SemaphoreMP_Params *params)
{
    SizeT memReq, minAlign;
    ListMP_Params listMPParams;
    UInt16 regionId;
    
    if (params->sharedAddr == NULL) {
        regionId = params->regionId;
    }
    else {
        regionId = SharedRegion_getId(params->sharedAddr);
    }
    
    Assert_isTrue(regionId != SharedRegion_INVALIDREGIONID, 
            ti_sdo_ipc_Ipc_A_internal);
            
    minAlign = SharedRegion_getCacheLineSize(regionId);
    
    memReq = _Ipc_roundup(sizeof(SemaphoreMP_Attrs), minAlign);
    
    /*
     *  Add size of ListMP Attrs.  No need to init params since it's not used
     *  to create.
     */
    ListMP_Params_init(&listMPParams);
    listMPParams.regionId = regionId;
    memReq += ListMP_sharedMemReq(&listMPParams);
    
    return (memReq);
}
示例#4
0
/*
 *  ======== NotifyDriverShm_sharedMemReq ========
 */
SizeT NotifyDriverShm_sharedMemReq(const NotifyDriverShm_Params *params)
{
    UInt16 regionId;
    SizeT regionCacheSize;
    SizeT minAlign, memReq;
    
    /* Ensure that params is non-NULL */
    Assert_isTrue(params != NULL, ti_sdo_ipc_Ipc_A_internal);
    
    /* 
     *  Determine obj->cacheEnabled using params->cacheEnabled and SharedRegion
     *  cache flag setting, if applicable.
     */
    minAlign = params->cacheLineSize;
    if (minAlign == 0) {
        /* Fix alignment of zero */        
        minAlign = sizeof(Ptr);
    }
    regionId = SharedRegion_getId(params->sharedAddr);
    if (regionId != SharedRegion_INVALIDREGIONID) {
        regionCacheSize = SharedRegion_getCacheLineSize(regionId);
        /* Override minAlign if the region cache line size is smaller */
        if (regionCacheSize < minAlign) {
            minAlign = regionCacheSize;
        }
    }
    
    /* Determine obj->align which will be used to _Ipc_roundup addresses */
    memReq = ((_Ipc_roundup(sizeof(NotifyDriverShm_ProcCtrl), minAlign)) * 2)
           + ((_Ipc_roundup(sizeof(NotifyDriverShm_EventEntry), minAlign) * 2
              * ti_sdo_ipc_Notify_numEvents));

    return (memReq);
}
示例#5
0
/*
 *  ======== TransportShm_sharedMemReq ========
 */
SizeT TransportShm_sharedMemReq(const TransportShm_Params *params)
{
    SizeT memReq, minAlign;
    UInt16 regionId;
    ListMP_Params listMPParams;

    regionId = SharedRegion_getId(params->sharedAddr);

    minAlign = Memory_getMaxDefaultTypeAlign();
    if (SharedRegion_getCacheLineSize(regionId) > minAlign) {
        minAlign = SharedRegion_getCacheLineSize(regionId);
    }

    /* for the Attrs structure */
    memReq = _Ipc_roundup(sizeof(TransportShm_Attrs), minAlign);

    /* for the second Attrs structure */
    memReq += _Ipc_roundup(sizeof(TransportShm_Attrs), minAlign);

    ListMP_Params_init(&listMPParams);
    listMPParams.regionId = regionId;

    /* for localListMP */
    memReq += ListMP_sharedMemReq(&listMPParams);

    /* for remoteListMP */
    memReq += ListMP_sharedMemReq(&listMPParams);

    return(memReq);
}
示例#6
0
/*
 *  ======== ListMP_prev ========
 */
Ptr ListMP_prev(ListMP_Handle handle, ListMP_Elem *elem)
{
    ti_sdo_ipc_ListMP_Object *obj = (ti_sdo_ipc_ListMP_Object *)handle;
    ListMP_Elem *retElem;  /* returned elem */
    Bool elemIsCached;

    /* elem == NULL -> start at the head */
    if (elem == NULL) {
        elemIsCached = obj->cacheEnabled;
        elem = (ListMP_Elem *)&(obj->attrs->head);
    }
    else {
        elemIsCached = SharedRegion_isCacheEnabled(SharedRegion_getId(elem));
    }
    
    if (elemIsCached) {
        Cache_inv(elem, sizeof(ListMP_Elem), Cache_Type_ALL, TRUE);
    }

    retElem = SharedRegion_getPtr(elem->prev);

    if (retElem == (ListMP_Elem *)(&(obj->attrs->head))) {
        retElem = NULL;
    }
    
    if (elemIsCached) {
        /* Invalidate because elem pulled into cache && elem != head. */
        Cache_inv(elem, sizeof(ListMP_Elem), Cache_Type_ALL, TRUE);
    }

    return (retElem);
}
示例#7
0
/*
 *  ======== ListMP_remove ========
 */
Int ListMP_remove(ListMP_Handle handle, ListMP_Elem *elem)
{
    ti_sdo_ipc_ListMP_Object *obj = (ti_sdo_ipc_ListMP_Object *)handle;
    UInt key;
    ListMP_Elem *localPrevElem;
    ListMP_Elem *localNextElem;
    Bool localPrevElemIsCached, localNextElemIsCached;

    /* Prevent another thread or processor from modifying the ListMP */
    key = GateMP_enter((GateMP_Handle)obj->gate);

    if (ti_sdo_ipc_SharedRegion_translate == FALSE) {
        localPrevElem = (ListMP_Elem *)(elem->prev);
        localNextElem = (ListMP_Elem *)(elem->next);
    }
    else {
        localPrevElem = SharedRegion_getPtr(elem->prev);
        localNextElem = SharedRegion_getPtr(elem->next);
    }
    
    localPrevElemIsCached = SharedRegion_isCacheEnabled(
            SharedRegion_getId(localPrevElem));
    localNextElemIsCached = SharedRegion_isCacheEnabled(
            SharedRegion_getId(localNextElem));

    if (localPrevElemIsCached) {
        Cache_inv(localPrevElem, sizeof(ListMP_Elem), Cache_Type_ALL, TRUE);
    }
    if (localNextElemIsCached) {
        Cache_inv(localNextElem, sizeof(ListMP_Elem), Cache_Type_ALL, TRUE);
    }
    
    localPrevElem->next = elem->next;
    localNextElem->prev = elem->prev;

    if (localPrevElemIsCached) {
        Cache_wbInv(localPrevElem, sizeof(ListMP_Elem), Cache_Type_ALL, TRUE);
    }
    if (localNextElemIsCached) {
        Cache_wbInv(localNextElem, sizeof(ListMP_Elem), Cache_Type_ALL, TRUE);
    }
    
    GateMP_leave((GateMP_Handle)obj->gate, key);
    
    return (ListMP_S_SUCCESS);
}
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)));

}
示例#9
0
/*
 *  ======== TransportShm_openByAddr ========
 */
Int TransportShm_openByAddr(Ptr sharedAddr,
                      TransportShm_Handle *handlePtr,
                      Error_Block *eb)
{
    TransportShm_Params params;
    TransportShm_Attrs *attrs;
    Int status;
    UInt16 id;

    if (sharedAddr == NULL) {
        return (MessageQ_E_FAIL);
    }

    TransportShm_Params_init(&params);

    /* Tell Instance_init() that we're opening */
    params.openFlag = TRUE;

    attrs = (TransportShm_Attrs *)sharedAddr;
    id = SharedRegion_getId(sharedAddr);

    /* Assert that the region is valid */
    Assert_isTrue(id != SharedRegion_INVALIDREGIONID,
            ti_sdo_ipc_Ipc_A_addrNotInSharedRegion);

    /* invalidate the attrs before using it */
    if (SharedRegion_isCacheEnabled(id)) {
        Cache_inv(attrs, sizeof(TransportShm_Attrs), Cache_Type_ALL, TRUE);
    }

    /* set params field */
    params.sharedAddr    = sharedAddr;
    params.priority      = attrs->priority;

    if (attrs->flag != TransportShm_UP) {
        /* make sure transport is up */
        *handlePtr = NULL;
        status = MessageQ_E_NOTFOUND;
    }
    else {
        /* Create the object */
        *handlePtr = TransportShm_create(attrs->creatorProcId, &params, eb);
        if (*handlePtr == NULL) {
            status = MessageQ_E_FAIL;
        }
        else {
            status = MessageQ_S_SUCCESS;
        }
    }

    return (status);
}
示例#10
0
/*
 *  ======== 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);
    }
}
示例#11
0
/*
 *  ======== ListMP_openByAddr ========
 */
Int ListMP_openByAddr(Ptr sharedAddr, ListMP_Handle *handlePtr)
{
    ti_sdo_ipc_ListMP_Params params;
    ti_sdo_ipc_ListMP_Attrs *attrs;
    Error_Block eb;
    Int status;
    UInt16 id;
    
    Error_init(&eb);
    
    ti_sdo_ipc_ListMP_Params_init(&params);
    
    /* Tell Instance_init() that we're opening */
    params.openFlag = TRUE;
    
    attrs = (ti_sdo_ipc_ListMP_Attrs *)sharedAddr;
    params.sharedAddr = sharedAddr;
    id = SharedRegion_getId(sharedAddr);
    
    if (SharedRegion_isCacheEnabled(id)) {
        Cache_inv(attrs, sizeof(ti_sdo_ipc_ListMP_Attrs), Cache_Type_ALL, TRUE);
    }
    
    if (attrs->status != ti_sdo_ipc_ListMP_CREATED) {
        *handlePtr = NULL;
        status = ListMP_E_NOTFOUND;
    }
    else {
        /* Create the object */
        *handlePtr = (ListMP_Handle)ti_sdo_ipc_ListMP_create(&params, &eb);
        if (*handlePtr == NULL) {
            status = ListMP_E_FAIL;
        }
        else {
            status = ListMP_S_SUCCESS;
        }
    }

    if (SharedRegion_isCacheEnabled(id)) {
        Cache_inv(attrs, sizeof(ti_sdo_ipc_ListMP_Attrs), Cache_Type_ALL, TRUE);
    }

    return (status);
}
示例#12
0
/* 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);
}
示例#13
0
/*
 *  ======== TransportShm_put ========
 *  Assuming MessageQ_put is making sure that the arguments are ok
 */
Bool TransportShm_put(TransportShm_Object *obj, Ptr msg)
{
    Int32 status;
    Bool retval = TRUE;
    IArg key;
    UInt16 id = SharedRegion_getId(msg);

    /* This transport only deals with messages allocated from SR's */
    Assert_isTrue(id != SharedRegion_INVALIDREGIONID,
            ti_sdo_ipc_SharedRegion_A_regionInvalid);

    /* writeback invalidate the message */
    if (SharedRegion_isCacheEnabled(id)) {
        Cache_wbInv(msg, ((MessageQ_Msg)(msg))->msgSize, Cache_Type_ALL,
            TRUE);
    }

    /* make sure ListMP_put and sendEvent are done before remote executes */
    key = GateMP_enter((GateMP_Handle)obj->gate);

    /* Put the message on the remoteList */
    ListMP_putTail((ListMP_Handle)obj->remoteList, (ListMP_Elem *)msg);

    /* Notify the remote processor */
    status = Notify_sendEvent(obj->remoteProcId, 0, TransportShm_notifyEventId,
        0, FALSE);

    /* check the status of the sendEvent */
    if (status < 0) {
        /* remove the message from the List and return 'FALSE' */
        ListMP_remove((ListMP_Handle)obj->remoteList, (ListMP_Elem *)msg);
        retval = FALSE;
    }

    /* leave the gate */
    GateMP_leave((GateMP_Handle)obj->gate, key);

    return (retval);
}
示例#14
0
/**
 * 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)));

}
示例#15
0
/*
 *  ======== SemaphoreMP_openByAddr ========
 */
Int SemaphoreMP_openByAddr(Ptr sharedAddr,
                           SemaphoreMP_Handle *handlePtr)
{
    SemaphoreMP_Params params;
    SemaphoreMP_Attrs *attrs;
    Int status;
    Error_Block eb;

    Error_init(&eb);

    SemaphoreMP_Params_init(&params);

    /* Tell Instance_init() that we're opening */
    params.openFlag = TRUE;

    params.sharedAddr = sharedAddr;
    attrs = (SemaphoreMP_Attrs *)sharedAddr;

    if (SharedRegion_isCacheEnabled(SharedRegion_getId(sharedAddr))) {
        Cache_inv(attrs, sizeof(SemaphoreMP_Attrs), Cache_Type_ALL, TRUE);
    }

    if (attrs->status != SemaphoreMP_CREATED) {
        *handlePtr = NULL;
        status = -1; //SemaphoreMP_E_NOTFOUND;
    }
    else {
        *handlePtr = SemaphoreMP_create(0, &params, &eb);
        if (*handlePtr == NULL) {
            status = -1; //SemaphoreMP_E_FAIL;
        }
        else {
            status = 0; //SemaphoreMP_S_SUCCESS;
        }
    }

    return (status);
}
示例#16
0
/**
 * 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)));

}
示例#17
0
static Int32 IpcFramesInLink_getFrameBuf(IpcFramesInLink_Obj * pObj,
                                     SystemIpcFrames_ListElem * pListElem,
                                     FVID2_Frame ** pFrameBufPtr)
{
    FVID2_Frame *freeFrameBuf;
    Int status;


    UTILS_assert(pListElem != NULL);
    /* No cache ops done since pListElem is allocated from non-cached memory */
    UTILS_assert(SharedRegion_isCacheEnabled(SharedRegion_getId(pListElem)) ==
                 FALSE);
    status = Utils_queGet(&pObj->freeFrameQue,
                          (Ptr *)&freeFrameBuf,1,BIOS_NO_WAIT);
    UTILS_assert(status == FVID2_SOK);

    IpcFramesInLink_copyFrameInfo(pObj,
                                  &pListElem->frameBuf,
                                  freeFrameBuf,
                                  pListElem->srBufPtr);
    *pFrameBufPtr = freeFrameBuf;
    return IPC_FRAMES_IN_LINK_S_SUCCESS;
}
示例#18
0
/**
 * 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)));
}
示例#19
0
/*
 *  ======== NotifyDriverShm_Instance_init ========
 */
Int NotifyDriverShm_Instance_init(NotifyDriverShm_Object *obj,
                                  const NotifyDriverShm_Params *params,
                                  Error_Block *eb)
{
    UInt16 regionId;
    SizeT regionCacheSize, minAlign, procCtrlSize;
    
   /*
    * Check whether remote proc ID has been set and isn't the same as the
    * local proc ID
    */
    Assert_isTrue ((params->remoteProcId != MultiProc_INVALIDID) &&
                   (params->remoteProcId != MultiProc_self()),
                   ti_sdo_ipc_Ipc_A_invParam);
                   
    /* 
     *  Determine obj->cacheEnabled using params->cacheEnabled and SharedRegion
     *  cache flag setting, if applicable.
     */
    obj->cacheEnabled = params->cacheEnabled;
    minAlign = params->cacheLineSize;
    if (minAlign == 0) {
        /* Fix alignment of zero */
        minAlign = sizeof(Ptr);
    }
    regionId = SharedRegion_getId(params->sharedAddr);
    if (regionId != SharedRegion_INVALIDREGIONID) {
        /* 
         *  Override the user cacheEnabled setting if the region 
         *  cacheEnabled is FALSE.
         */
        if (!SharedRegion_isCacheEnabled(regionId)) {
            obj->cacheEnabled = FALSE;
        }
        
        regionCacheSize = SharedRegion_getCacheLineSize(regionId);
        
        /* 
         *  Override the user cache line size setting if the region 
         *  cache line size is smaller.
         */
        if (regionCacheSize < minAlign) {
            minAlign = regionCacheSize;
        }
    }
    
    /* Check if shared memory base addr is aligned to cache line boundary.*/
    Assert_isTrue ((UInt32)params->sharedAddr % minAlign == 0, 
        ti_sdo_ipc_Ipc_A_addrNotCacheAligned);
    
    obj->remoteProcId           = params->remoteProcId;

    /* 
     *  Store all interrupt information so it may be used (if neccessary) by
     *  the IInterrupt delegates
     */
    obj->intInfo.remoteIntId    = params->remoteIntId;
    obj->intInfo.localIntId     = params->localIntId;
    obj->intInfo.intVectorId    = params->intVectorId;

    obj->nesting            = 0;

    if (params->remoteProcId > MultiProc_self()) {
        obj->selfId  = 0;
        obj->otherId = 1;
    }
    else {
        obj->selfId  = 1;
        obj->otherId = 0;
    }
    
    /* Initialize pointers to shared memory regions */
    procCtrlSize = _Ipc_roundup(sizeof(NotifyDriverShm_ProcCtrl), minAlign);

    /* 
     *  Save the eventEntrySize in obj since we will need it at runtime to 
     *  index the event charts
     */
    obj->eventEntrySize = _Ipc_roundup(sizeof(NotifyDriverShm_EventEntry), 
        minAlign);
    
    obj->selfProcCtrl = (NotifyDriverShm_ProcCtrl *)
        ((UInt32)params->sharedAddr + (obj->selfId * procCtrlSize));
    obj->otherProcCtrl = (NotifyDriverShm_ProcCtrl *)
        ((UInt32)params->sharedAddr + (obj->otherId * procCtrlSize));
    obj->selfEventChart  = (NotifyDriverShm_EventEntry *)
        ((UInt32)params->sharedAddr
         + (2 * procCtrlSize)
         + (obj->eventEntrySize * ti_sdo_ipc_Notify_numEvents * obj->selfId));
    obj->otherEventChart  = (NotifyDriverShm_EventEntry *)
         ((UInt32)params->sharedAddr
         + (2 * procCtrlSize)
         + (obj->eventEntrySize * ti_sdo_ipc_Notify_numEvents * obj->otherId));

    /* Allocate memory for regChart and init to (UInt32)-1 (unregistered) */
    obj->regChart = Memory_valloc(
            NotifyDriverShm_Object_heap(),
            (sizeof(UInt32) * ti_sdo_ipc_Notify_numEvents),
            NULL,
            ~0,
            eb);
    if (obj->regChart == NULL) { 
        return (1);
    }

    /* Enable all events initially.*/
    obj->selfProcCtrl->eventEnableMask = 0xFFFFFFFF;
    
    /* Write back our own ProcCtrl */
    if (obj->cacheEnabled) {
        Cache_wbInv(obj->selfProcCtrl, sizeof(NotifyDriverShm_ProcCtrl),
            Cache_Type_ALL, TRUE);
    }

    /* Register the incoming interrupt */
    NotifyDriverShm_InterruptProxy_intRegister(obj->remoteProcId, 
        &(obj->intInfo), (Fxn)NotifyDriverShm_isr, (UArg)obj);

    return (0);
}
/*!
 *  @brief      Function to perform device specific setup for Notify module.
 *              This function creates the Notify drivers.
 *
 *  @param[in]  sharedAddr Shared address base.
 *
 *  @sa         NotifySetupOmapl1xx_detach
 */
Int
NotifySetupOmapl1xx_attach (UInt16 procId, Ptr sharedAddr)
{
    Int32                  status    = Notify_S_SUCCESS ;
    NotifyDriverShm_Params notifyShmParams;

    GT_1trace (curTrace, GT_ENTER, "NotifySetupOmapl1xx_attach", sharedAddr);

    GT_assert (curTrace, (sharedAddr != NULL));

#if !defined(SYSLINK_BUILD_OPTIMIZE)
    if (sharedAddr == NULL) {
        /*! @retval  Notify_E_INVALIDARG Invalid NULL sharedAddr argument
                                         provided. */
        status = Notify_E_INVALIDARG;
        GT_setFailureReason (curTrace,
                             GT_4CLASS,
                             "NotifySetupOmapl1xx_attach",
                             status,
                             "Invalid NULL sharedAddr provided.");
    }
    else {
#endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
        /*
         *  Setup the notify driver to the DSP (Line 0)
         */
        NotifyDriverShm_Params_init (&notifyShmParams);
        notifyShmParams.cacheEnabled   = SharedRegion_isCacheEnabled(
            SharedRegion_getId((Ptr)sharedAddr));
        notifyShmParams.localIntId     = NotifySetup_armRecvIntId0;
        notifyShmParams.remoteIntId    = NotifySetup_dspRecvIntId0;
        notifyShmParams.remoteProcId   = procId;
        notifyShmParams.lineId         = 0u;
        notifyShmParams.sharedAddr     = sharedAddr;

        NotifySetup_dspDriverHandle0 = NotifyDriverShm_create(&notifyShmParams);
#if !defined(SYSLINK_BUILD_OPTIMIZE)
        if (NotifySetup_dspDriverHandle0 == NULL) {
            /*! @retval  Notify_E_FAIL NotifyDriverShm_create failed for line
                                       0 */
            status = Notify_E_FAIL;
            GT_setFailureReason (curTrace,
                                 GT_4CLASS,
                                 "NotifySetupOmapl1xx_attach",
                                 status,
                                 "NotifyDriverShm_create failed for line 0");
        }
        else {
#endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
            NotifySetup_notifyHandle0 = Notify_create (
                                                   NotifySetup_dspDriverHandle0,
                                                   procId,
                                                   0u,
                                                   NULL);

#if !defined(SYSLINK_BUILD_OPTIMIZE)
            if (NotifySetup_notifyHandle0 == NULL) {
                /*! @retval  Notify_E_FAIL Notify_create failed for line 0 */
                status = Notify_E_FAIL;
                GT_setFailureReason (curTrace,
                                     GT_4CLASS,
                                     "NotifySetupOmapl1xx_attach",
                                     status,
                                     "Notify_create failed for line 0");
            }
        }

        if (status >= 0) {
#endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
            if (NotifySetup_useSecondLine) {
                /*
                 *  Setup the notify driver to the DSP (Line 1)
                 */
                NotifyDriverShm_Params_init (&notifyShmParams);
                notifyShmParams.localIntId     = NotifySetup_armRecvIntId1;
                notifyShmParams.remoteIntId    = NotifySetup_dspRecvIntId1;
                notifyShmParams.remoteProcId   = procId;
                notifyShmParams.lineId         = 1u;
                notifyShmParams.sharedAddr     = sharedAddr;/* To allow sharedegion
                                                             * Calculations
                                                             */
                notifyShmParams.sharedAddr     = (Ptr)((UInt32) sharedAddr +
                              NotifyDriverShm_sharedMemReq (&notifyShmParams));
                NotifySetup_dspDriverHandle1 = NotifyDriverShm_create (
                                                            &notifyShmParams);
#if !defined(SYSLINK_BUILD_OPTIMIZE)
                if (NotifySetup_dspDriverHandle1 == NULL) {
                    /*! @retval  Notify_E_FAIL NotifyDriverShm_create failed
                                               for line 1*/
                    status = Notify_E_FAIL;
                    GT_setFailureReason (curTrace,
                                 GT_4CLASS,
                                 "NotifySetupOmapl1xx_attach",
                                 status,
                                 "NotifyDriverShm_create failed for line 1");
                }
                else {
#endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
                    NotifySetup_notifyHandle1 = Notify_create (
                                                  NotifySetup_dspDriverHandle1,
                                                  procId,
                                                  1u,
                                                  NULL);
#if !defined(SYSLINK_BUILD_OPTIMIZE)
                    if (NotifySetup_notifyHandle0 == NULL) {
                        /*! @retval  Notify_E_FAIL Notify_create failed for
                                                 line 1*/
                        status = Notify_E_FAIL;
                        GT_setFailureReason (curTrace,
                                         GT_4CLASS,
                                         "NotifySetupOmapl1xx_attach",
                                         status,
                                         "Notify_create failed for line 1");
                    }
                }
#endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */
            }
#if !defined(SYSLINK_BUILD_OPTIMIZE)
        }
    }
#endif /* if !defined(SYSLINK_BUILD_OPTIMIZE) */

    GT_1trace (curTrace, GT_LEAVE, "NotifySetupOmapl1xx_attach", status);

    /*! @retval Notify_S_SUCCESS Operation successful */
    return (status);
}
示例#21
0
/*
 *  ======== 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));
}
示例#22
0
/*
 *  ======== 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);
}
示例#23
0
/*
 *  ======== 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);
}
示例#24
0
/*
 *  ======== TransportShm_Instance_init ========
 */
Int TransportShm_Instance_init(TransportShm_Object *obj,
        UInt16 procId, const TransportShm_Params *params,
        Error_Block *eb)
{
    Int            localIndex;
    Int            remoteIndex;
    Int            status;
    Bool           flag;
    UInt32         minAlign;
    ListMP_Params  listMPParams[2];
    Swi_Handle     swiHandle;
    Swi_Params     swiParams;
    Ptr            localAddr;

    swiHandle = TransportShm_Instance_State_swiObj(obj);

    /*
     *  Determine who gets the '0' slot in shared memory and who gets
     *  the '1' slot. The '0' slot is given to the lower MultiProc id.
     */
    if (MultiProc_self() < procId) {
        localIndex  = 0;
        remoteIndex = 1;
    }
    else {
        localIndex  = 1;
        remoteIndex = 0;
    }

    if (params->openFlag) {
        /* Open by sharedAddr */
        obj->objType = ti_sdo_ipc_Ipc_ObjType_OPENDYNAMIC;
        obj->self = (TransportShm_Attrs *)params->sharedAddr;
        obj->regionId = SharedRegion_getId(params->sharedAddr);
        obj->cacheEnabled = SharedRegion_isCacheEnabled(obj->regionId);

        localAddr = SharedRegion_getPtr(obj->self->gateMPAddr);
        status = GateMP_openByAddr(localAddr, (GateMP_Handle *)&obj->gate);
        if (status < 0) {
            Error_raise(eb, ti_sdo_ipc_Ipc_E_internal, 0, 0);
            return(1);
        }
    }
    else {
        /* init the gate for ListMP create below */
        if (params->gate != NULL) {
            obj->gate = params->gate;
        }
        else {
            obj->gate = (ti_sdo_ipc_GateMP_Handle)GateMP_getDefaultRemote();
        }

        /* 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, type, self */
        obj->cacheEnabled = SharedRegion_isCacheEnabled(obj->regionId);
        obj->objType = ti_sdo_ipc_Ipc_ObjType_CREATEDYNAMIC;
        obj->self = (TransportShm_Attrs *)params->sharedAddr;
    }

    /* determine the minimum alignment to align to */
    minAlign = Memory_getMaxDefaultTypeAlign();
    if (SharedRegion_getCacheLineSize(obj->regionId) > minAlign) {
        minAlign = SharedRegion_getCacheLineSize(obj->regionId);
    }

    /*
     *  Carve up the shared memory.
     *  If cache is enabled, these need to be on separate cache lines.
     *  This is done with minAlign and _Ipc_roundup function.
     */
    obj->other = (TransportShm_Attrs *)((UInt32)(obj->self) +
        (_Ipc_roundup(sizeof(TransportShm_Attrs), minAlign)));

    ListMP_Params_init(&(listMPParams[0]));
    listMPParams[0].gate = (GateMP_Handle)obj->gate;
    listMPParams[0].sharedAddr = (UInt32 *)((UInt32)(obj->other) +
        (_Ipc_roundup(sizeof(TransportShm_Attrs), minAlign)));

    ListMP_Params_init(&listMPParams[1]);
    listMPParams[1].gate = (GateMP_Handle)obj->gate;
    listMPParams[1].sharedAddr = (UInt32 *)((UInt32)(listMPParams[0].sharedAddr)
        + ListMP_sharedMemReq(&listMPParams[0]));

    obj->priority      = params->priority;
    obj->remoteProcId  = procId;

    Swi_Params_init(&swiParams);
    swiParams.arg0 = (UArg)obj;
    Swi_construct(Swi_struct(swiHandle),
                 (Swi_FuncPtr)TransportShm_swiFxn,
                 &swiParams, eb);

    if (params->openFlag == FALSE) {
        obj->localList = (ti_sdo_ipc_ListMP_Handle)
                ListMP_create(&(listMPParams[localIndex]));
        if (obj->localList == NULL) {
            Error_raise(eb, ti_sdo_ipc_Ipc_E_internal, 0, 0);
            return (2);
        }

        obj->remoteList = (ti_sdo_ipc_ListMP_Handle)
                ListMP_create(&(listMPParams[remoteIndex]));
        if (obj->localList == NULL) {
            Error_raise(eb, ti_sdo_ipc_Ipc_E_internal, 0, 0);
            return (2);
        }
    }
    else {
        /* Open the local ListMP instance */
        status = ListMP_openByAddr(listMPParams[localIndex].sharedAddr,
                                   (ListMP_Handle *)&(obj->localList));

        if (status < 0) {
            Error_raise(eb, ti_sdo_ipc_Ipc_E_internal, 0, 0);
            return (2);
        }

        /* Open the remote ListMP instance */
        status = ListMP_openByAddr(listMPParams[remoteIndex].sharedAddr,
                                   (ListMP_Handle *)&(obj->remoteList));

        if (status < 0) {
            Error_raise(eb, ti_sdo_ipc_Ipc_E_internal, 0, 0);
            return (2);
        }
    }

    /* register the event with Notify */
    status = Notify_registerEventSingle(
                 procId,    /* remoteProcId */
                 0,         /* lineId */
                 TransportShm_notifyEventId,
                 (Notify_FnNotifyCbck)TransportShm_notifyFxn,
                 (UArg)swiHandle);
    if (status < 0) {
        Error_raise(eb, ti_sdo_ipc_Ipc_E_internal, 0, 0);
        return (3);
    }

    /* Register the transport with MessageQ */
    flag = ti_sdo_ipc_MessageQ_registerTransport(
            TransportShm_Handle_upCast(obj), procId, params->priority);
    if (flag == FALSE) {
        Error_raise(eb, ti_sdo_ipc_Ipc_E_internal, 0, 0);
        return (4);
    }

    if (params->openFlag == FALSE) {
        obj->self->creatorProcId = MultiProc_self();
        obj->self->notifyEventId = TransportShm_notifyEventId;
        obj->self->priority = obj->priority;

        /* Store the GateMP sharedAddr in the Attrs */
        obj->self->gateMPAddr = ti_sdo_ipc_GateMP_getSharedAddr(obj->gate);
        obj->self->flag = TransportShm_UP;

        if (obj->cacheEnabled) {
            Cache_wbInv(obj->self, sizeof(TransportShm_Attrs),
                     Cache_Type_ALL, TRUE);
        }
    }
    else {
        obj->other->flag = TransportShm_UP;
        if (obj->cacheEnabled) {
            Cache_wbInv(&(obj->other->flag), minAlign, Cache_Type_ALL, TRUE);
        }
    }

    obj->status = TransportShm_UP;

    return (0);
}
示例#25
0
/*
 *  ======== ListMP_getTail ========
 */
Ptr ListMP_getTail(ListMP_Handle handle)
{
    ti_sdo_ipc_ListMP_Object *obj = (ti_sdo_ipc_ListMP_Object *)handle;
    ListMP_Elem *elem;
    ListMP_Elem *localHeadPrev;
    ListMP_Elem *localPrev;
    Bool localPrevIsCached;
    UInt key;

    /* prevent another thread or processor from modifying the ListMP */
    key = GateMP_enter((GateMP_Handle)obj->gate);

    if (ti_sdo_ipc_SharedRegion_translate == FALSE) {
        localHeadPrev = (ListMP_Elem *)obj->attrs->head.prev;
    }
    else {
        localHeadPrev = SharedRegion_getPtr(obj->attrs->head.prev);
    }

    /* Assert that pointer is not NULL */
    Assert_isTrue(localHeadPrev != NULL, ti_sdo_ipc_Ipc_A_nullPointer);

    /* See if the ListMP was empty */
    if (localHeadPrev == (ListMP_Elem *)(&(obj->attrs->head))) {
        /* Empty, return NULL */
        elem = NULL;
    }
    else {
        if (SharedRegion_isCacheEnabled(SharedRegion_getId(localHeadPrev))) {
            /* invalidate elem */
            Cache_inv(localHeadPrev, sizeof(ListMP_Elem), Cache_Type_ALL, TRUE);
        }

        if (ti_sdo_ipc_SharedRegion_translate == FALSE) {
            localPrev = (ListMP_Elem *)localHeadPrev->prev;
        }
        else {
            localPrev = SharedRegion_getPtr(localHeadPrev->prev);
        }

        /* Assert that pointer is not NULL */
        Assert_isTrue(localPrev != NULL, ti_sdo_ipc_Ipc_A_nullPointer);

        /* Elem to return */
        elem = localHeadPrev;
        localPrevIsCached = SharedRegion_isCacheEnabled(
                SharedRegion_getId(localPrev));
        if (localPrevIsCached) {
            Cache_inv(localPrev, sizeof(ListMP_Elem), Cache_Type_ALL, TRUE);
        }
        
        /* Fix the head of the list prev pointer */
        obj->attrs->head.prev = elem->prev;

        /* Fix the next pointer of the new last elem on the list */
        localPrev->next = localHeadPrev->next;
        if (localPrevIsCached) {
            Cache_wbInv(localPrev, sizeof(ListMP_Elem), Cache_Type_ALL, TRUE);
        }
    }

    if (obj->cacheEnabled) {
        Cache_wbInv(&(obj->attrs->head), sizeof(ListMP_Elem),
                    Cache_Type_ALL, TRUE);
    }

    GateMP_leave((GateMP_Handle)obj->gate, key);

    return (elem);
}
示例#26
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);
}