Exemplo n.º 1
0
Int32 System_ipcListMPCreate(UInt32 regionId, UInt32 linkId, ListMP_Handle *pOutHndl, ListMP_Handle *pInHndl,
                             GateMP_Handle * pOutHndleGate, GateMP_Handle * pInHndleGate)
{
    Int32 status;
    char  listMPOutName[64];
    char  listMPInName[64];
    ListMP_Params listMPParams;
    GateMP_Params gateMPParams;

    status = System_ipcGetListMPName(linkId, listMPOutName, listMPInName);
    UTILS_assert(status==OSA_SOK);

    GateMP_Params_init(&gateMPParams);
    gateMPParams.regionId = regionId;
    gateMPParams.remoteProtect = GateMP_RemoteProtect_CUSTOM1;
    *pOutHndleGate = GateMP_create(&gateMPParams);
    UTILS_assert(*pOutHndleGate!=NULL);

    ListMP_Params_init(&listMPParams);

    listMPParams.name = listMPOutName;
    listMPParams.regionId = regionId;
    listMPParams.gate     = *pOutHndleGate;

    printf(" %u: SYSTEM: Creating ListMP [%s] in region %d ...\n",
        OSA_getCurTimeInMsec(),
        listMPParams.name,
        listMPParams.regionId
        );

    *pOutHndl = ListMP_create(&listMPParams);

    UTILS_assert(*pOutHndl!=NULL);

    GateMP_Params_init(&gateMPParams);
    gateMPParams.regionId = regionId;
    gateMPParams.remoteProtect = GateMP_RemoteProtect_CUSTOM1;
    *pInHndleGate = GateMP_create(&gateMPParams);
    UTILS_assert(*pInHndleGate!=NULL);

    ListMP_Params_init(&listMPParams);

    listMPParams.name = listMPInName;
    listMPParams.regionId = regionId;
    listMPParams.gate     = *pInHndleGate;

    printf(" %u: SYSTEM: Creating ListMP [%s] in region %d ...\n",
        OSA_getCurTimeInMsec(),
        listMPParams.name,
        listMPParams.regionId
        );

    *pInHndl = ListMP_create(&listMPParams);

    UTILS_assert(*pInHndl!=NULL);

    return status;
}
Exemplo n.º 2
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);
}
Exemplo n.º 3
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);
}
Exemplo n.º 4
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);
}
Exemplo n.º 5
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);
}
Exemplo n.º 6
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);
}