blob: 8c8b8215b1a7039d651af21fd21dfb70aab37de6 [file] [log] [blame]
Eric Holmbergd765e2b2013-01-03 17:05:38 -07001/* Copyright (c) 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/*
15 * Part of this this code is based on the standard ARM spinlock
16 * implementation (asm/spinlock.h) found in the 2.6.29 kernel.
17 */
18
19#ifndef __ASM__ARCH_QC_REMOTE_SPINLOCK_H
20#define __ASM__ARCH_QC_REMOTE_SPINLOCK_H
21
Eric Holmbergf9cfa8e2011-09-23 14:29:11 -060022#include <linux/io.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070023#include <linux/types.h>
24
25/* Remote spinlock definitions. */
26
27struct dek_spinlock {
28 volatile uint8_t self_lock;
29 volatile uint8_t other_lock;
30 volatile uint8_t next_yield;
31 uint8_t pad;
32};
33
34typedef union {
35 volatile uint32_t lock;
36 struct dek_spinlock dek;
37} raw_remote_spinlock_t;
38
39typedef raw_remote_spinlock_t *_remote_spinlock_t;
40
41#define remote_spinlock_id_t const char *
Eric Holmbergd3511d62013-01-02 14:37:09 -070042
Eric Holmbergf9cfa8e2011-09-23 14:29:11 -060043#if defined(CONFIG_MSM_SMD) || defined(CONFIG_MSM_REMOTE_SPINLOCK_SFPB)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070044int _remote_spin_lock_init(remote_spinlock_id_t, _remote_spinlock_t *lock);
Eric Holmbergf9cfa8e2011-09-23 14:29:11 -060045void _remote_spin_release_all(uint32_t pid);
Jeff Hugo416539f2013-01-16 17:24:36 -070046void _remote_spin_lock(_remote_spinlock_t *lock);
47void _remote_spin_unlock(_remote_spinlock_t *lock);
48int _remote_spin_trylock(_remote_spinlock_t *lock);
49int _remote_spin_release(_remote_spinlock_t *lock, uint32_t pid);
50int _remote_spin_owner(_remote_spinlock_t *lock);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070051#else
52static inline
53int _remote_spin_lock_init(remote_spinlock_id_t id, _remote_spinlock_t *lock)
54{
55 return -EINVAL;
56}
Eric Holmbergf9cfa8e2011-09-23 14:29:11 -060057static inline void _remote_spin_release_all(uint32_t pid) {}
Jeff Hugo416539f2013-01-16 17:24:36 -070058static inline void _remote_spin_lock(_remote_spinlock_t *lock) {}
59static inline void _remote_spin_unlock(_remote_spinlock_t *lock) {}
60static inline int _remote_spin_trylock(_remote_spinlock_t *lock)
61{
62 return -ENODEV;
63}
64static inline int _remote_spin_release(_remote_spinlock_t *lock, uint32_t pid)
65{
66 return -ENODEV;
67}
68static inline int _remote_spin_owner(_remote_spinlock_t *lock)
69{
70 return -ENODEV;
71}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070072#endif
73
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070074
75/* Remote mutex definitions. */
76
77typedef struct {
78 _remote_spinlock_t r_spinlock;
79 uint32_t delay_us;
80} _remote_mutex_t;
81
82struct remote_mutex_id {
83 remote_spinlock_id_t r_spinlock_id;
84 uint32_t delay_us;
85};
86
87#ifdef CONFIG_MSM_SMD
88int _remote_mutex_init(struct remote_mutex_id *id, _remote_mutex_t *lock);
89void _remote_mutex_lock(_remote_mutex_t *lock);
90void _remote_mutex_unlock(_remote_mutex_t *lock);
91int _remote_mutex_trylock(_remote_mutex_t *lock);
92#else
93static inline
94int _remote_mutex_init(struct remote_mutex_id *id, _remote_mutex_t *lock)
95{
96 return -EINVAL;
97}
98static inline void _remote_mutex_lock(_remote_mutex_t *lock) {}
99static inline void _remote_mutex_unlock(_remote_mutex_t *lock) {}
100static inline int _remote_mutex_trylock(_remote_mutex_t *lock)
101{
102 return 0;
103}
104#endif
105
106#endif /* __ASM__ARCH_QC_REMOTE_SPINLOCK_H */