~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to drivers/dsp/syslink/multicore_ipc/sysmgr.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  sysmgr.c
3
 
 *
4
 
 *  Implementation of System manager.
5
 
 *
6
 
 *  Copyright (C) 2009 Texas Instruments, Inc.
7
 
 *
8
 
 *  This package is free software; you can redistribute it and/or modify
9
 
 *  it under the terms of the GNU General Public License version 2 as
10
 
 *  published by the Free Software Foundation.
11
 
 *
12
 
 *  THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
13
 
 *  IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
14
 
 *  WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
15
 
 *  PURPOSE.
16
 
 */
17
 
 
18
 
 
19
 
/* Standard headers */
20
 
#include <linux/types.h>
21
 
#include <linux/module.h>
22
 
 
23
 
#include <syslink/atomic_linux.h>
24
 
 
25
 
/* Module headers */
26
 
#include <multiproc.h>
27
 
#include <sysmemmgr.h>
28
 
#include <sysmgr.h>
29
 
#include <_sysmgr.h>
30
 
#include <platform.h>
31
 
#include <platform_mem.h>
32
 
 
33
 
#include <gatepeterson.h>
34
 
#include <sharedregion.h>
35
 
#include <listmp.h>
36
 
#include <messageq.h>
37
 
#include <messageq_transportshm.h>
38
 
#include <notify.h>
39
 
/*#include <notify_driver.h>*/
40
 
#include <notify_ducatidriver.h>
41
 
 
42
 
#include <nameserver.h>
43
 
#include <nameserver_remote.h>
44
 
#include <nameserver_remotenotify.h>
45
 
#include <procmgr.h>
46
 
#include <heap.h>
47
 
#include <heapbuf.h>
48
 
 
49
 
/* =============================================================================
50
 
 * Macros
51
 
 * =============================================================================
52
 
 */
53
 
/*!
54
 
 *  @def    BOOTLOADPAGESIZE
55
 
 *  @brief  Error code base for System manager.
56
 
 */
57
 
#define BOOTLOADPAGESIZE                        (0x1000) /* 4K page size */
58
 
 
59
 
/*!
60
 
 *  @def    SYSMGR_ENTRYVALIDITYSTAMP
61
 
 *  @brief  Validity stamp for boot load page entries.
62
 
 */
63
 
#define SYSMGR_ENTRYVALIDITYSTAMP               (0xBABAC0C0)
64
 
 
65
 
/*!
66
 
 *  @def    SYSMGR_ENTRYVALIDSTAMP
67
 
 *  @brief  Validity stamp for boot load page entries.
68
 
 */
69
 
#define SYSMGR_ENTRYVALIDSTAMP                  (0xBABAC0C0)
70
 
 
71
 
/*!
72
 
 *  @def    SYSMGR_SCALABILITYHANDSHAKESTAMP
73
 
 *  @brief  scalability configuration handshake value.
74
 
 */
75
 
#define SYSMGR_SCALABILITYHANDSHAKESTAMP        (0xBEEF0000)
76
 
 
77
 
/*!
78
 
 *  @def    SYSMGR_SETUPHANDSHAKESTAMP
79
 
 *  @brief  Platform configured handshake value.
80
 
 */
81
 
#define SYSMGR_SETUPHANDSHAKESTAMP              (0xBEEF0001)
82
 
 
83
 
/*!
84
 
 *  @def    SYSMGR_DESTROYHANDSHAKESTAMP
85
 
 *  @brief  Destroy handshake value.
86
 
 */
87
 
#define SYSMGR_DESTROYHANDSHAKESTAMP            (0xBEEF0002)
88
 
 
89
 
/*!
90
 
 *  @def    SYSMGR_BOOTLOADPAGESIZE
91
 
 *  @brief  Boot load page size.
92
 
 */
93
 
#define SYSMGR_BOOTLOADPAGESIZE                 (0x00001000)
94
 
 
95
 
/* Macro to make a correct module magic number with ref_count */
96
 
#define SYSMGR_MAKE_MAGICSTAMP(x)               ((SYSMGR_MODULEID << 12) | (x))
97
 
 
98
 
 
99
 
/* =============================================================================
100
 
 * Structures & Enums
101
 
 * =============================================================================
102
 
 */
103
 
/*! @brief structure for System manager boot load page entry */
104
 
struct sysmgr_bootload_page_entry {
105
 
        VOLATILE u32 offset;
106
 
        /* Offset of next entry (-1 if not present) */
107
 
        VOLATILE u32 valid;
108
 
        /* Validity of the entry */
109
 
        VOLATILE u32 size;
110
 
        /* Size of the entry data */
111
 
        VOLATILE u32 cmd_id;
112
 
        /* Command ID */
113
 
};
114
 
 
115
 
/*! @brief structure containg system manager state object */
116
 
struct sysmgr_boot_load_page {
117
 
        VOLATILE struct sysmgr_bootload_page_entry host_config;
118
 
        /* First entry, host specific configuration in the boot load page */
119
 
        u8 padding1[(BOOTLOADPAGESIZE/2) - \
120
 
                sizeof(struct sysmgr_bootload_page_entry)];
121
 
        /* Padding1 */
122
 
        VOLATILE u32 handshake;
123
 
        /* Handshake variable, wrote by slave to indicate configuration done. */
124
 
        VOLATILE struct sysmgr_bootload_page_entry slave_config;
125
 
        /* First entry, slave specific configuration in the boot load page */
126
 
        u8 padding2[(BOOTLOADPAGESIZE/2) - \
127
 
                        sizeof(struct sysmgr_bootload_page_entry) - \
128
 
                        sizeof(u32)];
129
 
        /* Padding2 */
130
 
};
131
 
 
132
 
/*! @brief structure for System manager module state */
133
 
struct sysmgr_module_object {
134
 
        atomic_t ref_count;
135
 
        /* Reference count */
136
 
        struct sysmgr_config config;
137
 
        /* Overall system configuration */
138
 
        struct sysmgr_boot_load_page *boot_load_page[MULTIPROC_MAXPROCESSORS];
139
 
        /* Boot load page of the slaves */
140
 
        bool platform_mem_init_flag;
141
 
        /* Platform memory manager initialize flag */
142
 
        bool multiproc_init_flag;
143
 
        /* Multiproc Initialize flag */
144
 
        bool gatepeterson_init_flag;
145
 
        /* Gatepeterson Initialize flag */
146
 
        bool sharedregion_init_flag;
147
 
        /* Sharedregion Initialize flag */
148
 
        bool listmp_init_flag;
149
 
        /* Listmp Initialize flag */
150
 
        bool messageq_init_flag;
151
 
        /* Messageq Initialize flag */
152
 
        bool notify_init_flag;
153
 
        /* Notify Initialize flag */
154
 
        bool proc_mgr_init_flag;
155
 
        /* Processor manager Initialize flag */
156
 
        bool heapbuf_init_flag;
157
 
        /* Heapbuf Initialize flag */
158
 
        bool nameserver_init_flag;
159
 
        /* Nameserver_remotenotify Initialize flag */
160
 
        bool listmp_sharedmemory_init_flag;
161
 
        /* Listmp_sharedmemory Initialize flag */
162
 
        bool messageq_transportshm_init_flag;
163
 
        /* Messageq_transportshm Initialize flag */
164
 
        bool notify_ducatidrv_init_flag;
165
 
        /* notify_ducatidrv Initialize flag */
166
 
        bool nameserver_remotenotify_init_flag;
167
 
        /* nameserver_remotenotify Initialize flag */
168
 
        bool platform_init_flag;
169
 
        /* Flag to indicate platform initialization status */
170
 
};
171
 
 
172
 
 
173
 
/* =============================================================================
174
 
 * Globals
175
 
 * =============================================================================
176
 
 */
177
 
/*!
178
 
 *  @var    sysmgr_state
179
 
 *
180
 
 *  @brief  Variable holding state of system manager.
181
 
 */
182
 
static struct sysmgr_module_object sysmgr_state;
183
 
 
184
 
 
185
 
/* =============================================================================
186
 
 * APIS
187
 
 * =============================================================================
188
 
 */
189
 
/*
190
 
 * ======== sysmgr_get_config ========
191
 
 *  Purpose:
192
 
 *  Function to get the default values for configuration.
193
 
 */
194
 
void sysmgr_get_config(struct sysmgr_config *config)
195
 
{
196
 
        s32 status = 0;
197
 
 
198
 
        if (WARN_ON(config == NULL)) {
199
 
                status = -EINVAL;
200
 
                pr_err("sysmgr_get_config [0x%x] : Argument of type"
201
 
                                " (sysmgr_get_config *) passed is null!",
202
 
                                status);
203
 
                return;
204
 
        }
205
 
 
206
 
        /* Get the gatepeterson default config */
207
 
        multiproc_get_config(&config->multiproc_cfg);
208
 
 
209
 
        /* Get the gatepeterson default config */
210
 
        gatepeterson_get_config(&config->gatepeterson_cfg);
211
 
 
212
 
        /* Get the sharedregion default config */
213
 
        sharedregion_get_config(&config->sharedregion_cfg);
214
 
 
215
 
        /* Get the messageq default config */
216
 
        messageq_get_config(&config->messageq_cfg);
217
 
 
218
 
        /* Get the notify default config */
219
 
        notify_get_config(&config->notify_cfg);
220
 
 
221
 
        /* Get the proc_mgr default config */
222
 
        proc_mgr_get_config(&config->proc_mgr_cfg);
223
 
 
224
 
        /* Get the heapbuf default config */
225
 
        heapbuf_get_config(&config->heapbuf_cfg);
226
 
 
227
 
        /* Get the listmp_sharedmemory default config */
228
 
        listmp_sharedmemory_get_config(&config->listmp_sharedmemory_cfg);
229
 
 
230
 
        /* Get the messageq_transportshm default config */
231
 
        messageq_transportshm_get_config(&config->messageq_transportshm_cfg);
232
 
 
233
 
        /* Get the notify_ducati driver default config */
234
 
        notify_ducatidrv_getconfig(&config->notify_ducatidrv_cfg);
235
 
 
236
 
        /* Get the nameserver_remotenotify default config */
237
 
        nameserver_remotenotify_get_config(
238
 
                &config->nameserver_remotenotify_cfg);
239
 
}
240
 
EXPORT_SYMBOL(sysmgr_get_config);
241
 
 
242
 
/*
243
 
 * ======== sysmgr_get_object_config ========
244
 
 *  Purpose:
245
 
 *  Function to get the SysMgr Object configuration from Slave.
246
 
 */
247
 
u32 sysmgr_get_object_config(u16 proc_id, void *config, u32 cmd_id, u32 size)
248
 
{
249
 
        struct sysmgr_bootload_page_entry *entry = NULL;
250
 
        u32 offset = 0;
251
 
        u32 ret = 0;
252
 
        struct sysmgr_boot_load_page *blp = NULL;
253
 
 
254
 
        if ((proc_id < 0) || (proc_id >= MULTIPROC_MAXPROCESSORS)) {
255
 
                ret = 0;
256
 
                goto exit;
257
 
        }
258
 
 
259
 
        blp = (struct sysmgr_boot_load_page *)
260
 
                        sysmgr_state.boot_load_page[proc_id];
261
 
 
262
 
        entry = (struct sysmgr_bootload_page_entry *) &blp->slave_config;
263
 
        while (entry->valid == SYSMGR_ENTRYVALIDSTAMP) {
264
 
                if (entry->cmd_id == cmd_id) {
265
 
                        if (size == entry->size) {
266
 
                                memcpy(config, (void *)((u32)entry + \
267
 
                                sizeof(struct sysmgr_bootload_page_entry)),
268
 
                                size);
269
 
                                ret = size;
270
 
                                break;
271
 
                        }
272
 
                }
273
 
                if (entry->offset != -1) {
274
 
                        offset += entry->offset;
275
 
                        entry = (struct sysmgr_bootload_page_entry *)
276
 
                                ((u32) &blp->slave_config + entry->offset);
277
 
                } else {
278
 
                        break;
279
 
                }
280
 
        }
281
 
 
282
 
exit:
283
 
        /* return number of bytes wrote to the boot load page */
284
 
        return ret;
285
 
}
286
 
 
287
 
 
288
 
/*
289
 
 * ======== sysmgr_put_object_config ========
290
 
 *  Purpose:
291
 
 *  Function to put the SysMgr Object configuration to Slave.
292
 
 */
293
 
u32 sysmgr_put_object_config(u16 proc_id, void *config, u32 cmd_id, u32 size)
294
 
{
295
 
        struct sysmgr_bootload_page_entry *entry = NULL;
296
 
        struct sysmgr_bootload_page_entry *prev = NULL;
297
 
        u32 offset = 0;
298
 
        struct sysmgr_boot_load_page *blp = NULL;
299
 
 
300
 
        if ((proc_id < 0) || (proc_id >= MULTIPROC_MAXPROCESSORS)) {
301
 
                size = 0;
302
 
                goto exit;
303
 
        }
304
 
 
305
 
        /* Get the boot load page pointer */
306
 
        blp = sysmgr_state.boot_load_page[proc_id];
307
 
 
308
 
        /* Put the entry at the end of list */
309
 
        entry = (struct sysmgr_bootload_page_entry *) &blp->host_config;
310
 
        while (entry->valid == SYSMGR_ENTRYVALIDSTAMP) {
311
 
                prev  = entry;
312
 
                if (entry->offset != -1) {
313
 
                        offset += entry->offset;
314
 
                        entry = (struct sysmgr_bootload_page_entry *)
315
 
                                ((u32) &blp->host_config + entry->offset);
316
 
                } else {
317
 
                        break;
318
 
                }
319
 
        }
320
 
 
321
 
        /* First entry has prev set to NULL */
322
 
        if (prev == NULL) {
323
 
                entry->offset = -1;
324
 
                entry->cmd_id  = cmd_id;
325
 
                entry->size   = size;
326
 
                memcpy((void *)((u32)entry + \
327
 
                        sizeof(struct sysmgr_bootload_page_entry)),
328
 
                        config, size);
329
 
                entry->valid  = SYSMGR_ENTRYVALIDSTAMP;
330
 
        } else {
331
 
                entry = (struct sysmgr_bootload_page_entry *)((u32)entry + \
332
 
                                sizeof(struct sysmgr_bootload_page_entry) + \
333
 
                                entry->size);
334
 
                entry->offset = -1;
335
 
                entry->cmd_id = cmd_id;
336
 
                entry->size = size;
337
 
                memcpy((void *)((u32)entry + \
338
 
                        sizeof(struct sysmgr_bootload_page_entry)),
339
 
                        config, size);
340
 
                entry->valid = SYSMGR_ENTRYVALIDSTAMP;
341
 
 
342
 
                /* Attach the new created entry */
343
 
                prev->offset = ((u32) entry - (u32) &blp->host_config);
344
 
        }
345
 
 
346
 
exit:
347
 
        /* return number of bytes wrote to the boot load page */
348
 
        return size;
349
 
}
350
 
 
351
 
 
352
 
/*
353
 
 * ======== sysmgr_setup ========
354
 
 *  Purpose:
355
 
 *  Function to setup the System.
356
 
 */
357
 
s32 sysmgr_setup(const struct sysmgr_config *cfg)
358
 
{
359
 
        s32 status = 0;
360
 
        struct sysmgr_config *config = NULL;
361
 
 
362
 
        /* This sets the ref_count variable is not initialized, upper 16 bits is
363
 
         * written with module Id to ensure correctness of ref_count variable.
364
 
         */
365
 
        atomic_cmpmask_and_set(&sysmgr_state.ref_count,
366
 
                                SYSMGR_MAKE_MAGICSTAMP(0),
367
 
                                SYSMGR_MAKE_MAGICSTAMP(0));
368
 
 
369
 
        if (atomic_inc_return(&sysmgr_state.ref_count)
370
 
                        != SYSMGR_MAKE_MAGICSTAMP(1)) {
371
 
                status = 1;
372
 
                goto exit;
373
 
        }
374
 
 
375
 
        if (cfg == NULL) {
376
 
                sysmgr_get_config(&sysmgr_state.config);
377
 
                config = &sysmgr_state.config;
378
 
        } else {
379
 
                memcpy((void *) (&sysmgr_state.config), (void *) cfg,
380
 
                                sizeof(struct sysmgr_config));
381
 
                config = (struct sysmgr_config *) cfg;
382
 
        }
383
 
 
384
 
        /* Initialize PlatformMem */
385
 
        status = platform_mem_setup();
386
 
        if (status < 0) {
387
 
                pr_err("sysmgr_setup : platform_mem_setup "
388
 
                        "failed [0x%x]\n", status);
389
 
        } else {
390
 
                pr_err("platform_mem_setup : status [0x%x]\n" ,
391
 
                        status);
392
 
                sysmgr_state.platform_mem_init_flag = true;
393
 
        }
394
 
 
395
 
        /* Override the platform specific configuration */
396
 
        platform_override_config(config);
397
 
 
398
 
        status = multiproc_setup(&(config->multiproc_cfg));
399
 
        if (status < 0) {
400
 
                pr_err("sysmgr_setup : multiproc_setup "
401
 
                        "failed [0x%x]\n", status);
402
 
        } else {
403
 
                pr_err("sysmgr_setup : status [0x%x]\n" , status);
404
 
                sysmgr_state.multiproc_init_flag = true;
405
 
        }
406
 
 
407
 
        /* Initialize ProcMgr */
408
 
        if (status >= 0) {
409
 
                status = proc_mgr_setup(&(config->proc_mgr_cfg));
410
 
                if (status < 0) {
411
 
                        pr_err("sysmgr_setup : proc_mgr_setup "
412
 
                                "failed [0x%x]\n", status);
413
 
                } else {
414
 
                        pr_err("proc_mgr_setup : status [0x%x]\n" ,
415
 
                                status);
416
 
                        sysmgr_state.proc_mgr_init_flag = true;
417
 
                }
418
 
        }
419
 
 
420
 
        /* Initialize SharedRegion */
421
 
        if (status >= 0) {
422
 
                status = sharedregion_setup(&config->sharedregion_cfg);
423
 
                if (status < 0) {
424
 
                        pr_err("sysmgr_setup : sharedregion_setup "
425
 
                                "failed [0x%x]\n", status);
426
 
                } else {
427
 
                        pr_err("sharedregion_setup : status [0x%x]\n" ,
428
 
                                status);
429
 
                        sysmgr_state.sharedregion_init_flag = true;
430
 
                }
431
 
        }
432
 
 
433
 
        /* Initialize Notify */
434
 
        if (status >= 0) {
435
 
                status = notify_setup(&config->notify_cfg);
436
 
                if (status < 0) {
437
 
                        pr_err("sysmgr_setup : notify_setup "
438
 
                                "failed [0x%x]\n", status);
439
 
                } else {
440
 
                        pr_err("notify_setup : status [0x%x]\n" ,
441
 
                                status);
442
 
                        sysmgr_state.notify_init_flag = true;
443
 
                }
444
 
        }
445
 
 
446
 
        /* Initialize NameServer */
447
 
        if (status >= 0) {
448
 
                status = nameserver_setup();
449
 
                if (status < 0) {
450
 
                        pr_err("sysmgr_setup : nameserver_setup "
451
 
                                "failed [0x%x]\n", status);
452
 
                } else {
453
 
                        pr_err("nameserver_setup : status [0x%x]\n" ,
454
 
                                status);
455
 
                        sysmgr_state.nameserver_init_flag = true;
456
 
                }
457
 
        }
458
 
 
459
 
        /* Initialize GatePeterson */
460
 
        if (status >= 0) {
461
 
                status = gatepeterson_setup(&config->gatepeterson_cfg);
462
 
                if (status < 0) {
463
 
                        pr_err("sysmgr_setup : gatepeterson_setup "
464
 
                                "failed [0x%x]\n", status);
465
 
                } else {
466
 
                        pr_err("gatepeterson_setup : status [0x%x]\n" ,
467
 
                                status);
468
 
                        sysmgr_state.gatepeterson_init_flag = true;
469
 
                }
470
 
        }
471
 
 
472
 
        /* Intialize MessageQ */
473
 
        if (status >= 0) {
474
 
                status = messageq_setup(&config->messageq_cfg);
475
 
                if (status < 0) {
476
 
                        pr_err("sysmgr_setup : messageq_setup "
477
 
                                "failed [0x%x]\n", status);
478
 
                } else {
479
 
                        pr_err("messageq_setup : status [0x%x]\n" ,
480
 
                                status);
481
 
                        sysmgr_state.messageq_init_flag = true;
482
 
                }
483
 
        }
484
 
 
485
 
        /* Intialize HeapBuf */
486
 
        if (status >= 0) {
487
 
                status = heapbuf_setup(&config->heapbuf_cfg);
488
 
                if (status < 0) {
489
 
                        pr_err("sysmgr_setup : heapbuf_setup "
490
 
                                "failed [0x%x]\n", status);
491
 
                } else {
492
 
                        pr_err("heapbuf_setup : status [0x%x]\n" ,
493
 
                                status);
494
 
                        sysmgr_state.heapbuf_init_flag = true;
495
 
                }
496
 
        }
497
 
 
498
 
        /* Initialize ListMPSharedMemory */
499
 
        if (status >= 0) {
500
 
                status = listmp_sharedmemory_setup(
501
 
                                &config->listmp_sharedmemory_cfg);
502
 
                if (status < 0) {
503
 
                        pr_err("sysmgr_setup : "
504
 
                                "listmp_sharedmemory_setup failed [0x%x]\n",
505
 
                                status);
506
 
                } else {
507
 
                        pr_err("listmp_sharedmemory_setup : "
508
 
                                "status [0x%x]\n" , status);
509
 
                        sysmgr_state.listmp_sharedmemory_init_flag = true;
510
 
                }
511
 
        }
512
 
 
513
 
        /* Initialize MessageQTransportShm */
514
 
        if (status >= 0) {
515
 
                status = messageq_transportshm_setup(
516
 
                                 &config->messageq_transportshm_cfg);
517
 
                if (status < 0) {
518
 
                        pr_err("sysmgr_setup : "
519
 
                                "messageq_transportshm_setup failed [0x%x]\n",
520
 
                                status);
521
 
                } else {
522
 
                        pr_err("messageq_transportshm_setup : "
523
 
                                "status [0x%x]\n", status);
524
 
                        sysmgr_state.messageq_transportshm_init_flag = true;
525
 
                }
526
 
        }
527
 
 
528
 
        /* Initialize Notify DucatiDriver */
529
 
        if (status >= 0) {
530
 
                status = notify_ducatidrv_setup(&config->notify_ducatidrv_cfg);
531
 
                if (status < 0) {
532
 
                        pr_err("sysmgr_setup : "
533
 
                                "notify_ducatidrv_setup failed [0x%x]\n",
534
 
                                status);
535
 
                } else {
536
 
                        pr_err("notify_ducatidrv_setup : "
537
 
                                "status [0x%x]\n" , status);
538
 
                        sysmgr_state.notify_ducatidrv_init_flag = true;
539
 
                }
540
 
        }
541
 
 
542
 
        /* Initialize NameServerRemoteNotify */
543
 
        if (status >= 0) {
544
 
                status = nameserver_remotenotify_setup(
545
 
                                 &config->nameserver_remotenotify_cfg);
546
 
                if (status < 0) {
547
 
                        pr_err("sysmgr_setup : "
548
 
                                "nameserver_remotenotify_setup failed [0x%x]\n",
549
 
                                status);
550
 
                } else {
551
 
                        pr_err("nameserver_remotenotify_setup : "
552
 
                                "status [0x%x]\n" , status);
553
 
                        sysmgr_state.nameserver_remotenotify_init_flag = true;
554
 
                }
555
 
        }
556
 
 
557
 
        if (status >= 0) {
558
 
                /* Call platform setup function */
559
 
                status = platform_setup(config);
560
 
                if (status < 0) {
561
 
                        pr_err("sysmgr_setup : platform_setup "
562
 
                                "failed [0x%x]\n", status);
563
 
                } else {
564
 
                        pr_err("platform_setup : status [0x%x]\n" ,
565
 
                                status);
566
 
                        sysmgr_state.platform_init_flag = true;
567
 
                }
568
 
        }
569
 
 
570
 
exit:
571
 
        if (status < 0)
572
 
                atomic_set(&sysmgr_state.ref_count, SYSMGR_MAKE_MAGICSTAMP(0));
573
 
 
574
 
        return status;
575
 
}
576
 
EXPORT_SYMBOL(sysmgr_setup);
577
 
 
578
 
/*
579
 
 * ======== sysmgr_setup ========
580
 
 *  Purpose:
581
 
 *  Function to finalize the System.
582
 
 */
583
 
s32 sysmgr_destroy(void)
584
 
{
585
 
        s32 status = 0;
586
 
 
587
 
        if (atomic_cmpmask_and_lt(&(sysmgr_state.ref_count),
588
 
                                SYSMGR_MAKE_MAGICSTAMP(0),
589
 
                                SYSMGR_MAKE_MAGICSTAMP(1)) != false) {
590
 
                /*! @retval SYSMGR_E_INVALIDSTATE Module was not initialized */
591
 
                status = SYSMGR_E_INVALIDSTATE;
592
 
                goto exit;
593
 
        }
594
 
 
595
 
        if (atomic_dec_return(&sysmgr_state.ref_count)
596
 
                        != SYSMGR_MAKE_MAGICSTAMP(0)) {
597
 
                status = 1;
598
 
                goto exit;
599
 
        }
600
 
 
601
 
        /* Finalize Platform module*/
602
 
        if (sysmgr_state.platform_init_flag == true) {
603
 
                status = platform_destroy();
604
 
                if (status < 0) {
605
 
                        pr_err("sysmgr_destroy : platform_destroy "
606
 
                                "failed [0x%x]\n", status);
607
 
                } else {
608
 
                        sysmgr_state.platform_init_flag = false;
609
 
                }
610
 
        }
611
 
 
612
 
        /* Finalize NameServerRemoteNotify module */
613
 
        if (sysmgr_state.nameserver_remotenotify_init_flag == true) {
614
 
                status = nameserver_remotenotify_destroy();
615
 
                if (status < 0) {
616
 
                        pr_err("sysmgr_destroy : "
617
 
                                "nameserver_remotenotify_destroy "
618
 
                                "failed [0x%x]\n", status);
619
 
                } else {
620
 
                        sysmgr_state.nameserver_remotenotify_init_flag \
621
 
                                = false;
622
 
                }
623
 
        }
624
 
 
625
 
        /* Finalize Notify Ducati Driver module */
626
 
        if (sysmgr_state.notify_ducatidrv_init_flag == true) {
627
 
                status = notify_ducatidrv_destroy();
628
 
                if (status < 0) {
629
 
                        pr_err("sysmgr_destroy : "
630
 
                                "notify_ducatidrv_destroy failed [0x%x]\n",
631
 
                                status);
632
 
                } else {
633
 
                        sysmgr_state.notify_ducatidrv_init_flag = false;
634
 
                }
635
 
        }
636
 
 
637
 
        /* Finalize MessageQTransportShm module */
638
 
        if (sysmgr_state.messageq_transportshm_init_flag == true) {
639
 
                status = messageq_transportshm_destroy();
640
 
                if (status < 0) {
641
 
                        pr_err("sysmgr_destroy : "
642
 
                                "messageq_transportshm_destroy failed [0x%x]\n",
643
 
                                status);
644
 
                } else {
645
 
                        sysmgr_state.messageq_transportshm_init_flag = \
646
 
                                false;
647
 
                }
648
 
        }
649
 
 
650
 
        /* Finalize ListMPSharedMemory module */
651
 
        if (sysmgr_state.listmp_sharedmemory_init_flag == true) {
652
 
                status = listmp_sharedmemory_destroy();
653
 
                if (status < 0) {
654
 
                        pr_err("sysmgr_destroy : "
655
 
                                "listmp_sharedmemory_destroy failed [0x%x]\n",
656
 
                                status);
657
 
                } else {
658
 
                        sysmgr_state.listmp_sharedmemory_init_flag = \
659
 
                                false;
660
 
                }
661
 
        }
662
 
 
663
 
        /* Finalize HeapBuf module */
664
 
        if (sysmgr_state.heapbuf_init_flag == true) {
665
 
                status = heapbuf_destroy();
666
 
                if (status < 0) {
667
 
                        pr_err("sysmgr_destroy : heapbuf_destroy "
668
 
                                "failed [0x%x]\n", status);
669
 
                } else {
670
 
                        sysmgr_state.heapbuf_init_flag = false;
671
 
                }
672
 
        }
673
 
 
674
 
        /* Finalize MessageQ module */
675
 
        if (sysmgr_state.messageq_init_flag == true) {
676
 
                status = messageq_destroy();
677
 
                if (status < 0) {
678
 
                        pr_err("sysmgr_destroy : messageq_destroy "
679
 
                                "failed [0x%x]\n", status);
680
 
                } else {
681
 
                        sysmgr_state.messageq_init_flag = false;
682
 
                }
683
 
        }
684
 
 
685
 
        /* Finalize GatePeterson module */
686
 
        if (sysmgr_state.gatepeterson_init_flag == true) {
687
 
                status = gatepeterson_destroy();
688
 
                if (status < 0) {
689
 
                        pr_err("sysmgr_destroy : "
690
 
                                "gatepeterson_destroy failed [0x%x]\n", status);
691
 
                } else {
692
 
                        sysmgr_state.gatepeterson_init_flag = false;
693
 
                }
694
 
        }
695
 
 
696
 
        /* Finalize NameServer module */
697
 
        if (sysmgr_state.nameserver_init_flag == true) {
698
 
                status = nameserver_destroy();
699
 
                if (status < 0) {
700
 
                        pr_err("sysmgr_destroy : nameserver_destroy "
701
 
                                "failed [0x%x]\n", status);
702
 
                } else {
703
 
                        sysmgr_state.nameserver_init_flag = false;
704
 
                }
705
 
        }
706
 
 
707
 
        /* Finalize Notify module */
708
 
        if (sysmgr_state.notify_init_flag == true) {
709
 
                status = notify_destroy();
710
 
                if (status < 0) {
711
 
                        pr_err("sysmgr_destroy : sysmgr_destroy "
712
 
                                "failed [0x%x]\n", status);
713
 
                } else {
714
 
                        sysmgr_state.notify_init_flag = false;
715
 
                }
716
 
        }
717
 
 
718
 
        /* Finalize SharedRegion module */
719
 
        if (sysmgr_state.sharedregion_init_flag == true) {
720
 
                status = sharedregion_destroy();
721
 
                if (status < 0) {
722
 
                        pr_err("sysmgr_destroy : "
723
 
                                "sharedregion_destroy failed [0x%x]\n", status);
724
 
                } else {
725
 
                        sysmgr_state.sharedregion_init_flag = false;
726
 
                }
727
 
        }
728
 
 
729
 
        /* Finalize ProcMgr module */
730
 
        if (sysmgr_state.proc_mgr_init_flag == true) {
731
 
                status = proc_mgr_destroy();
732
 
                if (status < 0) {
733
 
                        pr_err("sysmgr_destroy : proc_mgr_destroy "
734
 
                                "failed [0x%x]\n", status);
735
 
                } else {
736
 
                        sysmgr_state.proc_mgr_init_flag = false;
737
 
                }
738
 
        }
739
 
 
740
 
        /* Finalize MultiProc module */
741
 
        if (sysmgr_state.multiproc_init_flag == true) {
742
 
                status = multiproc_destroy();
743
 
                if (status < 0) {
744
 
                        pr_err("sysmgr_destroy : multiproc_destroy "
745
 
                                "failed [0x%x]\n", status);
746
 
                } else {
747
 
                        sysmgr_state.proc_mgr_init_flag = false;
748
 
                }
749
 
        }
750
 
 
751
 
        /* Finalize PlatformMem module */
752
 
        if (sysmgr_state.platform_mem_init_flag == true) {
753
 
                status = platform_mem_destroy();
754
 
                if (status < 0) {
755
 
                        pr_err("sysmgr_destroy : platform_mem_destroy "
756
 
                                "failed [0x%x]\n", status);
757
 
                } else {
758
 
                        sysmgr_state.platform_mem_init_flag = false;
759
 
                }
760
 
        }
761
 
 
762
 
        atomic_set(&sysmgr_state.ref_count, SYSMGR_MAKE_MAGICSTAMP(0));
763
 
 
764
 
exit:
765
 
        if (status < 0) {
766
 
                pr_err("sysmgr_destroy : failed with "
767
 
                        "status = [0x%x]\n", status);
768
 
        }
769
 
        return status;
770
 
}
771
 
EXPORT_SYMBOL(sysmgr_destroy);
772
 
 
773
 
/*
774
 
 * ======== sysmgr_set_boot_load_page ========
775
 
 *  Purpose:
776
 
 *  Function to set the boot load page address for a slave.
777
 
 */
778
 
void sysmgr_set_boot_load_page(u16 proc_id, u32 boot_load_page)
779
 
{
780
 
        struct sysmgr_boot_load_page *temp = \
781
 
                (struct sysmgr_boot_load_page *) boot_load_page;
782
 
 
783
 
        if ((proc_id < 0) || (proc_id >= MULTIPROC_MAXPROCESSORS)) {
784
 
                pr_err(
785
 
                "sysmgr_set_boot_load_page failed: Invalid proc_id passed\n");
786
 
                return;
787
 
        }
788
 
 
789
 
        /* Initialize the host config area */
790
 
        sysmgr_state.boot_load_page[proc_id] = temp;
791
 
        temp->host_config.offset = -1;
792
 
        temp->host_config.valid = 0;
793
 
        temp->handshake = 0;
794
 
}
795
 
 
796
 
 
797
 
/*
798
 
 * ======== sysmgr_wait_for_scalability_info ========
799
 
 *  Purpose:
800
 
 *  Function to wait for scalability handshake value.
801
 
 */
802
 
void sysmgr_wait_for_scalability_info(u16 proc_id)
803
 
{
804
 
        VOLATILE struct sysmgr_boot_load_page *temp = NULL;
805
 
 
806
 
        if ((proc_id < 0) || (proc_id >= MULTIPROC_MAXPROCESSORS)) {
807
 
                pr_err("sysmgr_wait_for_scalability_info failed: "
808
 
                        "Invalid proc_id passed\n");
809
 
                return;
810
 
        }
811
 
        temp = sysmgr_state.boot_load_page[proc_id];
812
 
 
813
 
        pr_err("sysmgr_wait_for_scalability_info: BF while temp->handshake:%x\n",
814
 
                temp->handshake);
815
 
        while (temp->handshake != SYSMGR_SCALABILITYHANDSHAKESTAMP)
816
 
                ;
817
 
        pr_err("sysmgr_wait_for_scalability_info:AF while temp->handshake:%x\n",
818
 
                temp->handshake);
819
 
 
820
 
        /* Reset the handshake value for reverse synchronization */
821
 
        temp->handshake = 0;
822
 
}
823
 
 
824
 
 
825
 
/*
826
 
 * ======== sysmgr_wait_for_slave_setup ========
827
 
 *  Purpose:
828
 
 *  Function to wait for slave to complete setup.
829
 
 */
830
 
void sysmgr_wait_for_slave_setup(u16 proc_id)
831
 
{
832
 
        VOLATILE struct sysmgr_boot_load_page *temp = NULL;
833
 
 
834
 
        if ((proc_id < 0) || (proc_id >= MULTIPROC_MAXPROCESSORS)) {
835
 
                pr_err("sysmgr_wait_for_slave_setup failed: "
836
 
                        "Invalid proc_id passed\n");
837
 
                return;
838
 
        }
839
 
        temp = sysmgr_state.boot_load_page[proc_id];
840
 
 
841
 
        while (temp->handshake != SYSMGR_SETUPHANDSHAKESTAMP)
842
 
                ;
843
 
 
844
 
        /* Reset the handshake value for reverse synchronization */
845
 
        temp->handshake = 0;
846
 
}