Eric Holmberg | d765e2b | 2013-01-03 17:05:38 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2009, 2011, 2013 The Linux Foundation. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2 | * |
| 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 Holmberg | f9cfa8e | 2011-09-23 14:29:11 -0600 | [diff] [blame] | 22 | #include <linux/io.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 23 | #include <linux/types.h> |
| 24 | |
| 25 | /* Remote spinlock definitions. */ |
| 26 | |
| 27 | struct 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 | |
| 34 | typedef union { |
| 35 | volatile uint32_t lock; |
| 36 | struct dek_spinlock dek; |
| 37 | } raw_remote_spinlock_t; |
| 38 | |
| 39 | typedef raw_remote_spinlock_t *_remote_spinlock_t; |
| 40 | |
| 41 | #define remote_spinlock_id_t const char * |
Eric Holmberg | d3511d6 | 2013-01-02 14:37:09 -0700 | [diff] [blame] | 42 | |
Eric Holmberg | f9cfa8e | 2011-09-23 14:29:11 -0600 | [diff] [blame] | 43 | #if defined(CONFIG_MSM_SMD) || defined(CONFIG_MSM_REMOTE_SPINLOCK_SFPB) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 44 | int _remote_spin_lock_init(remote_spinlock_id_t, _remote_spinlock_t *lock); |
Eric Holmberg | f9cfa8e | 2011-09-23 14:29:11 -0600 | [diff] [blame] | 45 | void _remote_spin_release_all(uint32_t pid); |
Jeff Hugo | 416539f | 2013-01-16 17:24:36 -0700 | [diff] [blame] | 46 | void _remote_spin_lock(_remote_spinlock_t *lock); |
| 47 | void _remote_spin_unlock(_remote_spinlock_t *lock); |
| 48 | int _remote_spin_trylock(_remote_spinlock_t *lock); |
| 49 | int _remote_spin_release(_remote_spinlock_t *lock, uint32_t pid); |
| 50 | int _remote_spin_owner(_remote_spinlock_t *lock); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 51 | #else |
| 52 | static inline |
| 53 | int _remote_spin_lock_init(remote_spinlock_id_t id, _remote_spinlock_t *lock) |
| 54 | { |
| 55 | return -EINVAL; |
| 56 | } |
Eric Holmberg | f9cfa8e | 2011-09-23 14:29:11 -0600 | [diff] [blame] | 57 | static inline void _remote_spin_release_all(uint32_t pid) {} |
Jeff Hugo | 416539f | 2013-01-16 17:24:36 -0700 | [diff] [blame] | 58 | static inline void _remote_spin_lock(_remote_spinlock_t *lock) {} |
| 59 | static inline void _remote_spin_unlock(_remote_spinlock_t *lock) {} |
| 60 | static inline int _remote_spin_trylock(_remote_spinlock_t *lock) |
| 61 | { |
| 62 | return -ENODEV; |
| 63 | } |
| 64 | static inline int _remote_spin_release(_remote_spinlock_t *lock, uint32_t pid) |
| 65 | { |
| 66 | return -ENODEV; |
| 67 | } |
| 68 | static inline int _remote_spin_owner(_remote_spinlock_t *lock) |
| 69 | { |
| 70 | return -ENODEV; |
| 71 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 72 | #endif |
| 73 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 74 | |
| 75 | /* Remote mutex definitions. */ |
| 76 | |
| 77 | typedef struct { |
| 78 | _remote_spinlock_t r_spinlock; |
| 79 | uint32_t delay_us; |
| 80 | } _remote_mutex_t; |
| 81 | |
| 82 | struct remote_mutex_id { |
| 83 | remote_spinlock_id_t r_spinlock_id; |
| 84 | uint32_t delay_us; |
| 85 | }; |
| 86 | |
| 87 | #ifdef CONFIG_MSM_SMD |
| 88 | int _remote_mutex_init(struct remote_mutex_id *id, _remote_mutex_t *lock); |
| 89 | void _remote_mutex_lock(_remote_mutex_t *lock); |
| 90 | void _remote_mutex_unlock(_remote_mutex_t *lock); |
| 91 | int _remote_mutex_trylock(_remote_mutex_t *lock); |
| 92 | #else |
| 93 | static inline |
| 94 | int _remote_mutex_init(struct remote_mutex_id *id, _remote_mutex_t *lock) |
| 95 | { |
| 96 | return -EINVAL; |
| 97 | } |
| 98 | static inline void _remote_mutex_lock(_remote_mutex_t *lock) {} |
| 99 | static inline void _remote_mutex_unlock(_remote_mutex_t *lock) {} |
| 100 | static 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 */ |