summaryrefslogtreecommitdiff
path: root/drivers/staging/nmf-cm/cm/engine/configuration/src/configuration.c
blob: f092c7061b42632760f6a3204fc98f3e03b324e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
 * Copyright (C) ST-Ericsson SA 2010
 * Author: Jean-Philippe FASSINO <jean-philippe.fassino@stericsson.com> for ST-Ericsson.
 * License terms: GNU General Public License (GPL) version 2.
 */
#include <cm/engine/configuration/inc/configuration.h>
#include <cm/engine/component/inc/initializer.h>
#include <cm/engine/os_adaptation_layer/inc/os_adaptation_layer.h>
#include <cm/engine/dsp/inc/dsp.h>
#include <cm/engine/memory/inc/memory.h>
#include <cm/engine/executive_engine_mgt/inc/executive_engine_mgt.h>
#include <cm/engine/semaphores/inc/semaphores.h>
#include <cm/engine/communication/inc/communication.h>
#include <cm/engine/utils/inc/string.h>
#include <cm/engine/repository_mgt/inc/repository_mgt.h>
#include <inc/nmf-limits.h>
#include <cm/engine/trace/inc/trace.h>
#include <cm/engine/memory/inc/domain.h>

#include <cm/engine/trace/inc/trace.h>
#include <cm/engine/utils/inc/convert.h>

#include <cm/engine/power_mgt/inc/power.h>

t_sint32 cmIntensiveCheckState = 0;
t_sint32 cm_debug_level = 1;
t_sint32 cm_error_break = 0;
t_bool cmUlpEnable = FALSE;


#define MAX_EE_NAME_LENGTH      32
typedef struct {
    char eeName[MAX_EE_NAME_LENGTH];
    t_nmf_executive_engine_id executiveEngineId;
    t_uint32 EEmemoryCount;
} t_cfg_mpc_desc;

static t_cfg_mpc_desc        cfgMpcDescArray[NB_CORE_IDS];

PUBLIC t_cm_error cm_CFG_ConfigureMediaProcessorCore(
        t_nmf_core_id coreId,
        t_nmf_executive_engine_id executiveEngineId,
        t_nmf_semaphore_type_id semaphoreTypeId,
        t_uint8 nbYramBanks,
        const t_cm_system_address *mediaProcessorMappingBaseAddr,
        const t_cm_domain_id eeDomain,
        t_dsp_allocator_desc *sdramCodeAllocDesc,
        t_dsp_allocator_desc *sdramDataAllocDesc)
{
    /* Process requested configuration (save it) */
    cfgMpcDescArray[coreId].EEmemoryCount = 0;
    cfgMpcDescArray[coreId].executiveEngineId = executiveEngineId;
    /* Build Executive Engine Name */
    switch(executiveEngineId)
    {
        case SYNCHRONOUS_EXECUTIVE_ENGINE:
            cm_StringCopy(cfgMpcDescArray[coreId].eeName, "synchronous_", MAX_EE_NAME_LENGTH);
            break;
        case HYBRID_EXECUTIVE_ENGINE:
            cm_StringCopy(cfgMpcDescArray[coreId].eeName, "hybrid_", MAX_EE_NAME_LENGTH);
            break;
    }

    switch(semaphoreTypeId)
    {
        case LOCAL_SEMAPHORES:
            cm_StringConcatenate(cfgMpcDescArray[coreId].eeName, "lsem", MAX_EE_NAME_LENGTH);
            break;
        case SYSTEM_SEMAPHORES:
            cm_StringConcatenate(cfgMpcDescArray[coreId].eeName, "hsem", MAX_EE_NAME_LENGTH);
            break;
    }

    cm_SEM_InitMpc(coreId, semaphoreTypeId);

    return cm_DSP_Add(coreId, nbYramBanks, mediaProcessorMappingBaseAddr, eeDomain, sdramCodeAllocDesc, sdramDataAllocDesc);
}

// TODO JPF: Move in dsp.c
PUBLIC t_cm_error cm_CFG_AddMpcSdramSegment(const t_nmf_memory_segment *pDesc, const char* memoryname, t_dsp_allocator_desc **allocDesc)
{
    t_dsp_allocator_desc *desc;
    if ( (pDesc == NULL) ||
            ((pDesc->systemAddr.logical & CM_MM_ALIGN_64BYTES) != 0) )
        return CM_INVALID_PARAMETER;

    //TODO, juraj, the right place and way to do this?
    desc = (t_dsp_allocator_desc*)OSAL_Alloc(sizeof (t_dsp_allocator_desc));
    if (desc == 0)
        return CM_NO_MORE_MEMORY;

    desc->allocDesc = cm_MM_CreateAllocator(pDesc->size, 0, memoryname);
    if (desc->allocDesc == 0) {
    	OSAL_Free(desc);
    	return CM_NO_MORE_MEMORY;
    }
    desc->baseAddress = pDesc->systemAddr;
    desc->referenceCounter = 0;

    *allocDesc = desc;

    return CM_OK;
}

PUBLIC t_cm_error cm_CFG_CheckMpcStatus(t_nmf_core_id coreId)
{
    t_cm_error error;

    if (cm_DSP_GetState(coreId)->state == MPC_STATE_BOOTABLE)
    {
        /* Allocate coms fifo for a given MPC */
        if ((error = cm_COM_AllocateMpc(coreId)) != CM_OK)
            return error;

        /* Launch EE */
        if ((error = cm_EEM_Init(coreId,
                                 cfgMpcDescArray[coreId].eeName,
                                 cfgMpcDescArray[coreId].executiveEngineId)) != CM_OK)
        {
            cm_COM_FreeMpc(coreId);
            return error;
        }

        /* Initialize coms fifo for a given MPC */
        cm_COM_InitMpc(coreId);

        /* Initialisation of the dedicated communication channel for component initialization */
        if((error = cm_COMP_INIT_Init(coreId)) != CM_OK)
        {
            cm_EEM_Close(coreId);
            cm_COM_FreeMpc(coreId);
            return error;
        }

        cfgMpcDescArray[coreId].EEmemoryCount = cm_PWR_GetMPCMemoryCount(coreId);

        if(cmUlpEnable)
        {
            // We have finish boot, allow MMDSP to go in auto idle
            cm_EEM_AllowSleep(coreId);
        }
    }

    if (cm_DSP_GetState(coreId)->state != MPC_STATE_BOOTED)
        return CM_MPC_NOT_INITIALIZED;

    return CM_OK;
}

void cm_CFG_ReleaseMpc(t_nmf_core_id coreId)
{
    t_uint32 memoryCount = cm_PWR_GetMPCMemoryCount(coreId);

    // If No more memory and no more component (to avoid switch off in case of component using no memory)
    if(
            cm_PWR_GetMode() == NORMAL_PWR_MODE &&
            memoryCount != 0 /* Just to see if there is something */ &&
            memoryCount == cfgMpcDescArray[coreId].EEmemoryCount &&
            cm_isComponentOnCoreId(coreId) == FALSE)
    {
        LOG_INTERNAL(1, "\n##### Shutdown %s #####\n", cm_getDspName(coreId), 0, 0, 0, 0, 0);

        (void)cm_EEM_ForceWakeup(coreId);

        /* remove ee from load map here */
        cm_COMP_INIT_Close(coreId);
        cm_EEM_Close(coreId);
        cm_COM_FreeMpc(coreId);

        cfgMpcDescArray[coreId].EEmemoryCount = 0; // For debug purpose
    }
}