blob: 27789c9d3595ee7ca70b61e3982890b4de790bbe [file] [log] [blame]
Jeff Hugo416539f2013-01-16 17:24:36 -07001/* Copyright (c) 2008-2009, 2011-2013 The Linux Foundation. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 */
13
14#include <linux/err.h>
15#include <linux/kernel.h>
16#include <linux/string.h>
17#include <linux/delay.h>
Jeff Hugo83e28f52012-12-12 15:16:37 -070018#include <linux/module.h>
19#include <linux/platform_device.h>
20#include <linux/of.h>
21#include <linux/of_address.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070022
23#include <asm/system.h>
24
Eric Holmbergf9cfa8e2011-09-23 14:29:11 -060025#include <mach/msm_iomap.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070026#include <mach/remote_spinlock.h>
27#include <mach/dal.h>
28#include "smd_private.h"
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070029
Eric Holmbergf9cfa8e2011-09-23 14:29:11 -060030
Jeff Hugo416539f2013-01-16 17:24:36 -070031#define SPINLOCK_PID_APPS 1
32
33#define AUTO_MODE -1
34#define DEKKERS_MODE 1
35#define SWP_MODE 2
36#define LDREX_MODE 3
37#define SFPB_MODE 4
38
39#if defined(CONFIG_MSM_REMOTE_SPINLOCK_DEKKERS) ||\
40 defined(CONFIG_MSM_REMOTE_SPINLOCK_SWP) ||\
41 defined(CONFIG_MSM_REMOTE_SPINLOCK_LDREX) ||\
42 defined(CONFIG_MSM_REMOTE_SPINLOCK_SFPB)
43
44#ifdef CONFIG_MSM_REMOTE_SPINLOCK_DEKKERS
45/*
46 * Use Dekker's algorithm when LDREX/STREX and SWP are unavailable for
47 * shared memory
48 */
49#define CURRENT_MODE_INIT DEKKERS_MODE;
50#endif
51
52#ifdef CONFIG_MSM_REMOTE_SPINLOCK_SWP
53/* Use SWP-based locks when LDREX/STREX are unavailable for shared memory. */
54#define CURRENT_MODE_INIT SWP_MODE;
55#endif
56
57#ifdef CONFIG_MSM_REMOTE_SPINLOCK_LDREX
58/* Use LDREX/STREX for shared memory locking, when available */
59#define CURRENT_MODE_INIT LDREX_MODE;
60#endif
61
62#ifdef CONFIG_MSM_REMOTE_SPINLOCK_SFPB
63/* Use SFPB Hardware Mutex Registers */
64#define CURRENT_MODE_INIT SFPB_MODE;
65#endif
66
67#else
68/* Use DT info to configure with a fallback to LDREX if DT is missing */
69#define CURRENT_MODE_INIT AUTO_MODE;
70#endif
71
72static int current_mode = CURRENT_MODE_INIT;
73
74static int is_hw_lock_type;
75static DEFINE_MUTEX(ops_init_lock);
76
77struct spinlock_ops {
78 void (*lock)(raw_remote_spinlock_t *lock);
79 void (*unlock)(raw_remote_spinlock_t *lock);
80 int (*trylock)(raw_remote_spinlock_t *lock);
81 int (*release)(raw_remote_spinlock_t *lock, uint32_t pid);
82 int (*owner)(raw_remote_spinlock_t *lock);
83};
84
85static struct spinlock_ops current_ops;
86
87static int remote_spinlock_init_address(int id, _remote_spinlock_t *lock);
88
89/* dekkers implementation --------------------------------------------------- */
90#define DEK_LOCK_REQUEST 1
91#define DEK_LOCK_YIELD (!DEK_LOCK_REQUEST)
92#define DEK_YIELD_TURN_SELF 0
93static void __raw_remote_dek_spin_lock(raw_remote_spinlock_t *lock)
94{
95 lock->dek.self_lock = DEK_LOCK_REQUEST;
96
97 while (lock->dek.other_lock) {
98
99 if (lock->dek.next_yield == DEK_YIELD_TURN_SELF)
100 lock->dek.self_lock = DEK_LOCK_YIELD;
101
102 while (lock->dek.other_lock)
103 ;
104
105 lock->dek.self_lock = DEK_LOCK_REQUEST;
106 }
107 lock->dek.next_yield = DEK_YIELD_TURN_SELF;
108
109 smp_mb();
110}
111
112static int __raw_remote_dek_spin_trylock(raw_remote_spinlock_t *lock)
113{
114 lock->dek.self_lock = DEK_LOCK_REQUEST;
115
116 if (lock->dek.other_lock) {
117 lock->dek.self_lock = DEK_LOCK_YIELD;
118 return 0;
119 }
120
121 lock->dek.next_yield = DEK_YIELD_TURN_SELF;
122
123 smp_mb();
124 return 1;
125}
126
127static void __raw_remote_dek_spin_unlock(raw_remote_spinlock_t *lock)
128{
129 smp_mb();
130
131 lock->dek.self_lock = DEK_LOCK_YIELD;
132}
133
134static int __raw_remote_dek_spin_release(raw_remote_spinlock_t *lock,
135 uint32_t pid)
136{
137 return -EPERM;
138}
139
140static int __raw_remote_dek_spin_owner(raw_remote_spinlock_t *lock)
141{
142 return -EPERM;
143}
144/* end dekkers implementation ----------------------------------------------- */
145
146/* swp implementation ------------------------------------------------------- */
147static void __raw_remote_swp_spin_lock(raw_remote_spinlock_t *lock)
148{
149 unsigned long tmp;
150
151 __asm__ __volatile__(
152"1: swp %0, %2, [%1]\n"
153" teq %0, #0\n"
154" bne 1b"
155 : "=&r" (tmp)
156 : "r" (&lock->lock), "r" (1)
157 : "cc");
158
159 smp_mb();
160}
161
162static int __raw_remote_swp_spin_trylock(raw_remote_spinlock_t *lock)
163{
164 unsigned long tmp;
165
166 __asm__ __volatile__(
167" swp %0, %2, [%1]\n"
168 : "=&r" (tmp)
169 : "r" (&lock->lock), "r" (1)
170 : "cc");
171
172 if (tmp == 0) {
173 smp_mb();
174 return 1;
175 }
176 return 0;
177}
178
179static void __raw_remote_swp_spin_unlock(raw_remote_spinlock_t *lock)
180{
181 int lock_owner;
182
183 smp_mb();
184 lock_owner = readl_relaxed(&lock->lock);
185 if (lock_owner != SPINLOCK_PID_APPS) {
186 pr_err("%s: spinlock not owned by Apps (actual owner is %d)\n",
187 __func__, lock_owner);
188 }
189
190 __asm__ __volatile__(
191" str %1, [%0]"
192 :
193 : "r" (&lock->lock), "r" (0)
194 : "cc");
195}
196/* end swp implementation --------------------------------------------------- */
197
198/* ldrex implementation ----------------------------------------------------- */
199static void __raw_remote_ex_spin_lock(raw_remote_spinlock_t *lock)
200{
201 unsigned long tmp;
202
203 __asm__ __volatile__(
204"1: ldrex %0, [%1]\n"
205" teq %0, #0\n"
206" strexeq %0, %2, [%1]\n"
207" teqeq %0, #0\n"
208" bne 1b"
209 : "=&r" (tmp)
210 : "r" (&lock->lock), "r" (SPINLOCK_PID_APPS)
211 : "cc");
212
213 smp_mb();
214}
215
216static int __raw_remote_ex_spin_trylock(raw_remote_spinlock_t *lock)
217{
218 unsigned long tmp;
219
220 __asm__ __volatile__(
221" ldrex %0, [%1]\n"
222" teq %0, #0\n"
223" strexeq %0, %2, [%1]\n"
224 : "=&r" (tmp)
225 : "r" (&lock->lock), "r" (SPINLOCK_PID_APPS)
226 : "cc");
227
228 if (tmp == 0) {
229 smp_mb();
230 return 1;
231 }
232 return 0;
233}
234
235static void __raw_remote_ex_spin_unlock(raw_remote_spinlock_t *lock)
236{
237 int lock_owner;
238
239 smp_mb();
240 lock_owner = readl_relaxed(&lock->lock);
241 if (lock_owner != SPINLOCK_PID_APPS) {
242 pr_err("%s: spinlock not owned by Apps (actual owner is %d)\n",
243 __func__, lock_owner);
244 }
245
246 __asm__ __volatile__(
247" str %1, [%0]\n"
248 :
249 : "r" (&lock->lock), "r" (0)
250 : "cc");
251}
252/* end ldrex implementation ------------------------------------------------- */
253
254/* sfpb implementation ------------------------------------------------------ */
Eric Holmbergf9cfa8e2011-09-23 14:29:11 -0600255#define SFPB_SPINLOCK_COUNT 8
256#define MSM_SFPB_MUTEX_REG_BASE 0x01200600
257#define MSM_SFPB_MUTEX_REG_SIZE (33 * 4)
Jeff Hugo83e28f52012-12-12 15:16:37 -0700258#define SFPB_SPINLOCK_OFFSET 4
259#define SFPB_SPINLOCK_SIZE 4
260
261static uint32_t lock_count;
262static phys_addr_t reg_base;
263static uint32_t reg_size;
264static uint32_t lock_offset; /* offset into the hardware block before lock 0 */
265static uint32_t lock_size;
Eric Holmbergf9cfa8e2011-09-23 14:29:11 -0600266
267static void *hw_mutex_reg_base;
268static DEFINE_MUTEX(hw_map_init_lock);
269
Jeff Hugo83e28f52012-12-12 15:16:37 -0700270static char *compatible_string = "qcom,ipc-spinlock";
271
272static int init_hw_mutex(struct device_node *node)
273{
274 struct resource r;
275 int rc;
276
277 rc = of_address_to_resource(node, 0, &r);
278 if (rc)
279 BUG();
280
281 rc = of_property_read_u32(node, "qcom,num-locks", &lock_count);
282 if (rc)
283 BUG();
284
285 reg_base = r.start;
286 reg_size = (uint32_t)(resource_size(&r));
287 lock_offset = 0;
288 lock_size = reg_size / lock_count;
289
290 return 0;
291}
292
293static void find_and_init_hw_mutex(void)
294{
295 struct device_node *node;
296
297 node = of_find_compatible_node(NULL, NULL, compatible_string);
298 if (node) {
299 init_hw_mutex(node);
300 } else {
301 lock_count = SFPB_SPINLOCK_COUNT;
302 reg_base = MSM_SFPB_MUTEX_REG_BASE;
303 reg_size = MSM_SFPB_MUTEX_REG_SIZE;
304 lock_offset = SFPB_SPINLOCK_OFFSET;
305 lock_size = SFPB_SPINLOCK_SIZE;
306 }
307 hw_mutex_reg_base = ioremap(reg_base, reg_size);
308 BUG_ON(hw_mutex_reg_base == NULL);
309}
310
Jeff Hugo416539f2013-01-16 17:24:36 -0700311static int remote_spinlock_init_address_hw(int id, _remote_spinlock_t *lock)
Eric Holmbergf9cfa8e2011-09-23 14:29:11 -0600312{
Jeff Hugo83e28f52012-12-12 15:16:37 -0700313 /*
314 * Optimistic locking. Init only needs to be done once by the first
315 * caller. After that, serializing inits between different callers
316 * is unnecessary. The second check after the lock ensures init
317 * wasn't previously completed by someone else before the lock could
318 * be grabbed.
319 */
Eric Holmbergf9cfa8e2011-09-23 14:29:11 -0600320 if (!hw_mutex_reg_base) {
321 mutex_lock(&hw_map_init_lock);
322 if (!hw_mutex_reg_base)
Jeff Hugo83e28f52012-12-12 15:16:37 -0700323 find_and_init_hw_mutex();
Eric Holmbergf9cfa8e2011-09-23 14:29:11 -0600324 mutex_unlock(&hw_map_init_lock);
Eric Holmbergf9cfa8e2011-09-23 14:29:11 -0600325 }
326
Jeff Hugo83e28f52012-12-12 15:16:37 -0700327 if (id >= lock_count)
328 return -EINVAL;
329
330 *lock = hw_mutex_reg_base + lock_offset + id * lock_size;
Eric Holmbergf9cfa8e2011-09-23 14:29:11 -0600331 return 0;
332}
333
Jeff Hugo416539f2013-01-16 17:24:36 -0700334static void __raw_remote_sfpb_spin_lock(raw_remote_spinlock_t *lock)
Eric Holmbergf9cfa8e2011-09-23 14:29:11 -0600335{
Jeff Hugo416539f2013-01-16 17:24:36 -0700336 do {
337 writel_relaxed(SPINLOCK_PID_APPS, lock);
338 smp_mb();
339 } while (readl_relaxed(lock) != SPINLOCK_PID_APPS);
Eric Holmbergf9cfa8e2011-09-23 14:29:11 -0600340}
341
Jeff Hugo416539f2013-01-16 17:24:36 -0700342static int __raw_remote_sfpb_spin_trylock(raw_remote_spinlock_t *lock)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700343{
Jeff Hugod36eae62013-03-04 16:56:40 -0700344 writel_relaxed(SPINLOCK_PID_APPS, lock);
345 smp_mb();
346 return readl_relaxed(lock) == SPINLOCK_PID_APPS;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700347}
348
Jeff Hugo416539f2013-01-16 17:24:36 -0700349static void __raw_remote_sfpb_spin_unlock(raw_remote_spinlock_t *lock)
Eric Holmbergf9cfa8e2011-09-23 14:29:11 -0600350{
Jeff Hugo416539f2013-01-16 17:24:36 -0700351 int lock_owner;
352
353 lock_owner = readl_relaxed(lock);
354 if (lock_owner != SPINLOCK_PID_APPS) {
355 pr_err("%s: spinlock not owned by Apps (actual owner is %d)\n",
356 __func__, lock_owner);
357 }
358
359 writel_relaxed(0, lock);
360 smp_mb();
361}
362/* end sfpb implementation -------------------------------------------------- */
363
364/* common spinlock API ------------------------------------------------------ */
365/**
366 * Release spinlock if it is owned by @pid.
367 *
368 * This is only to be used for situations where the processor owning
369 * the spinlock has crashed and the spinlock must be released.
370 *
371 * @lock: lock structure
372 * @pid: processor ID of processor to release
373 */
374static int __raw_remote_gen_spin_release(raw_remote_spinlock_t *lock,
375 uint32_t pid)
376{
377 int ret = 1;
378
379 if (readl_relaxed(&lock->lock) == pid) {
380 writel_relaxed(0, &lock->lock);
381 wmb();
382 ret = 0;
383 }
384 return ret;
Eric Holmbergf9cfa8e2011-09-23 14:29:11 -0600385}
386
Jeff Hugo416539f2013-01-16 17:24:36 -0700387/**
388 * Return owner of the spinlock.
389 *
390 * @lock: pointer to lock structure
391 * @returns: >= 0 owned PID; < 0 for error case
392 *
393 * Used for testing. PID's are assumed to be 31 bits or less.
394 */
395static int __raw_remote_gen_spin_owner(raw_remote_spinlock_t *lock)
396{
397 rmb();
398 return readl_relaxed(&lock->lock);
399}
400
401
402static void initialize_ops(void)
403{
404 struct device_node *node;
405
406 switch (current_mode) {
407 case DEKKERS_MODE:
408 current_ops.lock = __raw_remote_dek_spin_lock;
409 current_ops.unlock = __raw_remote_dek_spin_unlock;
410 current_ops.trylock = __raw_remote_dek_spin_trylock;
411 current_ops.release = __raw_remote_dek_spin_release;
412 current_ops.owner = __raw_remote_dek_spin_owner;
413 is_hw_lock_type = 0;
414 break;
415 case SWP_MODE:
416 current_ops.lock = __raw_remote_swp_spin_lock;
417 current_ops.unlock = __raw_remote_swp_spin_unlock;
418 current_ops.trylock = __raw_remote_swp_spin_trylock;
419 current_ops.release = __raw_remote_gen_spin_release;
420 current_ops.owner = __raw_remote_gen_spin_owner;
421 is_hw_lock_type = 0;
422 break;
423 case LDREX_MODE:
424 current_ops.lock = __raw_remote_ex_spin_lock;
425 current_ops.unlock = __raw_remote_ex_spin_unlock;
426 current_ops.trylock = __raw_remote_ex_spin_trylock;
427 current_ops.release = __raw_remote_gen_spin_release;
428 current_ops.owner = __raw_remote_gen_spin_owner;
429 is_hw_lock_type = 0;
430 break;
431 case SFPB_MODE:
432 current_ops.lock = __raw_remote_sfpb_spin_lock;
433 current_ops.unlock = __raw_remote_sfpb_spin_unlock;
434 current_ops.trylock = __raw_remote_sfpb_spin_trylock;
435 current_ops.release = __raw_remote_gen_spin_release;
436 current_ops.owner = __raw_remote_gen_spin_owner;
437 is_hw_lock_type = 1;
438 break;
439 case AUTO_MODE:
440 node = of_find_compatible_node(NULL, NULL, compatible_string);
441 if (node) {
442 current_ops.lock = __raw_remote_sfpb_spin_lock;
443 current_ops.unlock = __raw_remote_sfpb_spin_unlock;
444 current_ops.trylock = __raw_remote_sfpb_spin_trylock;
445 current_ops.release = __raw_remote_gen_spin_release;
446 current_ops.owner = __raw_remote_gen_spin_owner;
447 is_hw_lock_type = 1;
448 } else {
449 current_ops.lock = __raw_remote_ex_spin_lock;
450 current_ops.unlock = __raw_remote_ex_spin_unlock;
451 current_ops.trylock = __raw_remote_ex_spin_trylock;
452 current_ops.release = __raw_remote_gen_spin_release;
453 current_ops.owner = __raw_remote_gen_spin_owner;
454 is_hw_lock_type = 0;
455 pr_warn("Falling back to LDREX remote spinlock implementation");
456 }
457 break;
458 default:
459 BUG();
460 break;
461 }
462}
Eric Holmbergf9cfa8e2011-09-23 14:29:11 -0600463
464/**
465 * Release all spinlocks owned by @pid.
466 *
467 * This is only to be used for situations where the processor owning
468 * spinlocks has crashed and the spinlocks must be released.
469 *
470 * @pid - processor ID of processor to release
471 */
472static void remote_spin_release_all_locks(uint32_t pid, int count)
473{
474 int n;
475 _remote_spinlock_t lock;
476
477 for (n = 0; n < count; ++n) {
478 if (remote_spinlock_init_address(n, &lock) == 0)
479 _remote_spin_release(&lock, pid);
480 }
481}
482
Jeff Hugo416539f2013-01-16 17:24:36 -0700483void _remote_spin_release_all(uint32_t pid)
484{
485 remote_spin_release_all_locks(pid, lock_count);
486}
487
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700488static int
489remote_spinlock_dal_init(const char *chunk_name, _remote_spinlock_t *lock)
490{
491 void *dal_smem_start, *dal_smem_end;
492 uint32_t dal_smem_size;
493 struct dal_chunk_header *cur_header;
494
495 if (!chunk_name)
496 return -EINVAL;
497
498 dal_smem_start = smem_get_entry(SMEM_DAL_AREA, &dal_smem_size);
499 if (!dal_smem_start)
500 return -ENXIO;
501
502 dal_smem_end = dal_smem_start + dal_smem_size;
503
504 /* Find first chunk header */
505 cur_header = (struct dal_chunk_header *)
506 (((uint32_t)dal_smem_start + (4095)) & ~4095);
507 *lock = NULL;
508 while (cur_header->size != 0
509 && ((uint32_t)(cur_header + 1) < (uint32_t)dal_smem_end)) {
510
511 /* Check if chunk name matches */
512 if (!strncmp(cur_header->name, chunk_name,
513 DAL_CHUNK_NAME_LENGTH)) {
514 *lock = (_remote_spinlock_t)&cur_header->lock;
515 return 0;
516 }
517 cur_header = (void *)cur_header + cur_header->size;
518 }
519
520 pr_err("%s: DAL remote lock \"%s\" not found.\n", __func__,
521 chunk_name);
522 return -EINVAL;
523}
524
Jeff Hugo416539f2013-01-16 17:24:36 -0700525#define SMEM_SPINLOCK_COUNT 8
526#define SMEM_SPINLOCK_ARRAY_SIZE (SMEM_SPINLOCK_COUNT * sizeof(uint32_t))
527
528static int remote_spinlock_init_address_smem(int id, _remote_spinlock_t *lock)
529{
530 _remote_spinlock_t spinlock_start;
531
532 if (id >= SMEM_SPINLOCK_COUNT)
533 return -EINVAL;
534
535 spinlock_start = smem_alloc(SMEM_SPINLOCK_ARRAY,
536 SMEM_SPINLOCK_ARRAY_SIZE);
537 if (spinlock_start == NULL)
538 return -ENXIO;
539
540 *lock = spinlock_start + id;
541
542 lock_count = SMEM_SPINLOCK_COUNT;
543
544 return 0;
545}
546
547static int remote_spinlock_init_address(int id, _remote_spinlock_t *lock)
548{
549 if (is_hw_lock_type)
550 return remote_spinlock_init_address_hw(id, lock);
551 else
552 return remote_spinlock_init_address_smem(id, lock);
553}
554
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700555int _remote_spin_lock_init(remote_spinlock_id_t id, _remote_spinlock_t *lock)
556{
557 BUG_ON(id == NULL);
558
Jeff Hugo416539f2013-01-16 17:24:36 -0700559 /*
560 * Optimistic locking. Init only needs to be done once by the first
561 * caller. After that, serializing inits between different callers
562 * is unnecessary. The second check after the lock ensures init
563 * wasn't previously completed by someone else before the lock could
564 * be grabbed.
565 */
566 if (!current_ops.lock) {
567 mutex_lock(&ops_init_lock);
568 if (!current_ops.lock)
569 initialize_ops();
570 mutex_unlock(&ops_init_lock);
571 }
572
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700573 if (id[0] == 'D' && id[1] == ':') {
574 /* DAL chunk name starts after "D:" */
575 return remote_spinlock_dal_init(&id[2], lock);
576 } else if (id[0] == 'S' && id[1] == ':') {
Eric Holmbergf9cfa8e2011-09-23 14:29:11 -0600577 /* Single-digit lock ID follows "S:" */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700578 BUG_ON(id[3] != '\0');
Eric Holmbergf9cfa8e2011-09-23 14:29:11 -0600579
580 return remote_spinlock_init_address((((uint8_t)id[2])-'0'),
Jeff Hugo416539f2013-01-16 17:24:36 -0700581 lock);
Eric Holmbergf9cfa8e2011-09-23 14:29:11 -0600582 } else {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700583 return -EINVAL;
Eric Holmbergf9cfa8e2011-09-23 14:29:11 -0600584 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700585}
586
Jeff Hugo416539f2013-01-16 17:24:36 -0700587/*
588 * lock comes in as a pointer to a pointer to the lock location, so it must
589 * be dereferenced and casted to the right type for the actual lock
590 * implementation functions
591 */
592void _remote_spin_lock(_remote_spinlock_t *lock)
593{
594 if (unlikely(!current_ops.lock))
595 BUG();
596 current_ops.lock((raw_remote_spinlock_t *)(*lock));
597}
598EXPORT_SYMBOL(_remote_spin_lock);
599
600void _remote_spin_unlock(_remote_spinlock_t *lock)
601{
602 if (unlikely(!current_ops.unlock))
603 BUG();
604 current_ops.unlock((raw_remote_spinlock_t *)(*lock));
605}
606EXPORT_SYMBOL(_remote_spin_unlock);
607
608int _remote_spin_trylock(_remote_spinlock_t *lock)
609{
610 if (unlikely(!current_ops.trylock))
611 BUG();
612 return current_ops.trylock((raw_remote_spinlock_t *)(*lock));
613}
614EXPORT_SYMBOL(_remote_spin_trylock);
615
616int _remote_spin_release(_remote_spinlock_t *lock, uint32_t pid)
617{
618 if (unlikely(!current_ops.release))
619 BUG();
620 return current_ops.release((raw_remote_spinlock_t *)(*lock), pid);
621}
622EXPORT_SYMBOL(_remote_spin_release);
623
624int _remote_spin_owner(_remote_spinlock_t *lock)
625{
626 if (unlikely(!current_ops.owner))
627 BUG();
628 return current_ops.owner((raw_remote_spinlock_t *)(*lock));
629}
630EXPORT_SYMBOL(_remote_spin_owner);
631/* end common spinlock API -------------------------------------------------- */
632
633/* remote mutex implementation ---------------------------------------------- */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700634int _remote_mutex_init(struct remote_mutex_id *id, _remote_mutex_t *lock)
635{
636 BUG_ON(id == NULL);
637
638 lock->delay_us = id->delay_us;
639 return _remote_spin_lock_init(id->r_spinlock_id, &(lock->r_spinlock));
640}
641EXPORT_SYMBOL(_remote_mutex_init);
642
643void _remote_mutex_lock(_remote_mutex_t *lock)
644{
645 while (!_remote_spin_trylock(&(lock->r_spinlock))) {
646 if (lock->delay_us >= 1000)
647 msleep(lock->delay_us/1000);
648 else
649 udelay(lock->delay_us);
650 }
651}
652EXPORT_SYMBOL(_remote_mutex_lock);
653
654void _remote_mutex_unlock(_remote_mutex_t *lock)
655{
656 _remote_spin_unlock(&(lock->r_spinlock));
657}
658EXPORT_SYMBOL(_remote_mutex_unlock);
659
660int _remote_mutex_trylock(_remote_mutex_t *lock)
661{
662 return _remote_spin_trylock(&(lock->r_spinlock));
663}
664EXPORT_SYMBOL(_remote_mutex_trylock);
Jeff Hugo416539f2013-01-16 17:24:36 -0700665/* end remote mutex implementation ------------------------------------------ */