blob: f547abd3ad381b3c2af07ecfacc85dff88a4e0e4 [file] [log] [blame]
Duy Truongf3ac7b32013-02-13 01:07:28 -08001/* Copyright (c) 2012, The Linux Foundation. All rights reserved.
Channagoud Kadabie1ecef52012-02-04 15:54:34 +05302 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
Duy Truongf3ac7b32013-02-13 01:07:28 -080012 * * Neither the name of The Linux Foundation nor the names of its
Channagoud Kadabie1ecef52012-02-04 15:54:34 +053013 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 */
29#include <platform/iomap.h>
30#include <platform/remote_spinlock.h>
31#include <debug.h>
32#include <smem.h>
33#include <reg.h>
34
35static struct smem *smem = (void *)(MSM_SHARED_BASE);
36
37void *smem_rlock_get_entry(unsigned id, unsigned *size)
38{
39 struct smem_alloc_info *ainfo;
40 void *ret = 0;
41 unsigned long flags = 0;
42
43 ainfo = &smem->alloc_info[id];
44
45 if (readl(&ainfo->allocated) == 0) {
46 dprintf(SPEW,"Shared memory is not allocated\n");
47 return ret;
48 }
49 /* Read the DAL area */
50 *size = readl(&ainfo->size);
51 ret = (void *) (MSM_SHARED_BASE + readl(&ainfo->offset));
52
53 return ret;
54}
55
56int remote_spinlock_init(remote_spinlock_t *lock)
57{
58 struct rlock_chunk_header *cur_header;
59 void *rlock_smem_start, *rlock_smem_end;
60 uint32_t rlock_smem_size = 0;
61 int smem_status = 0;
62
63 rlock_smem_start = smem_rlock_get_entry(SMEM_RLOCK_AREA, &rlock_smem_size);
64
65 if (!rlock_smem_start) {
66 dprintf(CRITICAL,"Failed to get smem entry for remote spin lock\n");
67 return 1;
68 }
69
70 rlock_smem_end = rlock_smem_start + rlock_smem_size;
71
72 cur_header = (struct rlock_chunk_header *)
73 (((uint32_t)rlock_smem_start + (4095)) & ~4095);
74 *lock = NULL;
75 /* Find the lock from the list */
76 while (cur_header->size != 0
77 && ((uint32_t)(cur_header + 1) < (uint32_t)rlock_smem_end)) {
78 /* If we found the lock, get the address */
79 if (!strncmp(cur_header->name, RLOCK_CHUNK_NAME,
80 RLOCK_CHUNK_NAME_LENGTH)) {
81 *lock = (remote_spinlock_t)&cur_header->lock;
82 return 0;
83 }
84 cur_header = (void *)cur_header + cur_header->size;
85 }
86 dprintf(CRITICAL,"%s: remote lock not found: %s\n",RLOCK_CHUNK_NAME,__FILE__);
87 return 1;
88}
89
90void remote_spin_lock(raw_remote_spinlock_t *lock)
91{
92 lock->dek.self_lock = DEK_LOCK_REQUEST;
93
94 /* check if the lock is available*/
95 while(lock->dek.other_lock) {
96 if(lock->dek.next_yield == DEK_YIELD_TURN_SELF)
97 while (lock->dek.other_lock);
98 lock->dek.self_lock = DEK_LOCK_REQUEST;
99 }
100 /* We acquired the lock */
101 lock->dek.next_yield = DEK_YIELD_TURN_SELF;
102 dmb();
103}
104void remote_spin_unlock(raw_remote_spinlock_t *lock)
105{
106 dmb();
107 lock->dek.self_lock = DEK_LOCK_YIELD;
108}