Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

msm7630_surf: Add support for remote spin lock

Use remote spin locks to prevent HLOS & non HLOS processors
to access the ssbi bus concurrently

Change-Id: I6e5722c6f27fd71014fb25ab6ff4f68bddb346bf
  • Loading branch information...
commit e1ecef5af1cbec09a9f11766894a55601d902b07 1 parent 82cebc3
Channagoud Kadabi authored
47 dev/ssbi/ssbi.c
@@ -34,6 +34,9 @@
34 34 #include <reg.h>
35 35 #include <sys/types.h>
36 36 #include <dev/ssbi.h>
  37 +#ifdef TARGET_USES_RSPIN_LOCK
  38 +#include <platform/remote_spinlock.h>
  39 +#endif
37 40
38 41 int i2c_ssbi_poll_for_device_ready(void)
39 42 {
@@ -70,8 +73,17 @@ int i2c_ssbi_read_bytes(unsigned char *buffer, unsigned short length,
70 73 unsigned char *buf = buffer;
71 74 unsigned short len = length;
72 75 unsigned short addr = slave_addr;
73   - unsigned long read_cmd = SSBI_CMD_READ(addr);
74   - unsigned long mode2 = readl(MSM_SSBI_BASE + SSBI2_MODE2);
  76 + unsigned long read_cmd = 0;
  77 + unsigned long mode2 = 0;
  78 +
  79 + /*
  80 + * Use remote spin locks since SSBI2 controller is shared with nonHLOS proc
  81 + */
  82 +#ifdef TARGET_USES_RSPIN_LOCK
  83 + remote_spin_lock(rlock);
  84 +#endif
  85 + read_cmd = SSBI_CMD_READ(addr);
  86 + mode2 = readl(MSM_SSBI_BASE + SSBI2_MODE2);
75 87
76 88 //buf = alloc(len * sizeof(8));
77 89 if (mode2 & SSBI_MODE2_SSBI2_MODE)
@@ -82,7 +94,7 @@ int i2c_ssbi_read_bytes(unsigned char *buffer, unsigned short length,
82 94 ret = i2c_ssbi_poll_for_device_ready();
83 95 if (ret) {
84 96 dprintf (CRITICAL, "Error: device not ready\n");
85   - return ret;
  97 + goto end;
86 98 }
87 99
88 100 writel(read_cmd, MSM_SSBI_BASE + SSBI2_CMD);
@@ -90,13 +102,17 @@ int i2c_ssbi_read_bytes(unsigned char *buffer, unsigned short length,
90 102 ret = i2c_ssbi_poll_for_read_completed();
91 103 if (ret) {
92 104 dprintf (CRITICAL, "Error: read not completed\n");
93   - return ret;
  105 + goto end;
94 106 }
95 107
96 108 *buf++ = readl(MSM_SSBI_BASE + SSBI2_RD) & SSBI_RD_REG_DATA_MASK;
97 109 len--;
98 110 }
99   - return 0;
  111 +end:
  112 +#ifdef TARGET_USES_RSPIN_LOCK
  113 + remote_spin_unlock(rlock);
  114 +#endif
  115 + return ret;
100 116 }
101 117
102 118 int i2c_ssbi_write_bytes(unsigned char *buffer, unsigned short length,
@@ -107,7 +123,15 @@ int i2c_ssbi_write_bytes(unsigned char *buffer, unsigned short length,
107 123 unsigned char *buf = buffer;
108 124 unsigned short len = length;
109 125 unsigned short addr = slave_addr;
110   - unsigned long mode2 = readl(MSM_SSBI_BASE + SSBI2_MODE2);
  126 + unsigned long mode2 = 0;
  127 +
  128 + /*
  129 + * Use remote spin locks since SSBI2 controller is shared with nonHLOS proc
  130 + */
  131 +#ifdef TARGET_USES_RSPIN_LOCK
  132 + remote_spin_lock(rlock);
  133 +#endif
  134 + mode2 = readl(MSM_SSBI_BASE + SSBI2_MODE2);
111 135
112 136 if (mode2 & SSBI_MODE2_SSBI2_MODE)
113 137 writel(SSBI_MODE2_REG_ADDR_15_8(mode2, addr),
@@ -117,19 +141,24 @@ int i2c_ssbi_write_bytes(unsigned char *buffer, unsigned short length,
117 141 ret = i2c_ssbi_poll_for_device_ready();
118 142 if (ret) {
119 143 dprintf (CRITICAL, "Error: device not ready\n");
120   - return ret;
  144 + goto end;
121 145 }
122 146
123 147 writel(SSBI_CMD_WRITE(addr, *buf++), MSM_SSBI_BASE + SSBI2_CMD);
124 148
125 149 while (readl(MSM_SSBI_BASE + SSBI2_STATUS) & SSBI_STATUS_MCHN_BUSY) {
126 150 if (--timeout == 0) {
127   - dprintf(INFO, "In Device ready function:Timeout, status %x\n", readl(MSM_SSBI_BASE + SSBI2_STATUS));
128   - return 1;
  151 + dprintf(INFO, "In Device ready function:Timeout, status %x\n", readl(MSM_SSBI_BASE + SSBI2_STATUS));
  152 + ret = 1;
  153 + goto end;
129 154 }
130 155 }
131 156 len--;
132 157 }
  158 +end:
  159 +#ifdef TARGET_USES_RSPIN_LOCK
  160 + remote_spin_unlock(rlock);
  161 +#endif
133 162 return 0;
134 163 }
135 164
60 platform/msm7x30/include/platform/remote_spinlock.h
... ... @@ -0,0 +1,60 @@
  1 +/* Copyright (c) 2012, Code Aurora Forum. All rights reserved.
  2 + *
  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.
  12 + * * Neither the name of Code Aurora Forum, Inc. nor the names of its
  13 + * 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 +
  30 +#include <sys/types.h>
  31 +
  32 +#define RLOCK_CHUNK_NAME_LENGTH 10
  33 +#define RLOCK_CHUNK_NAME "PMIC_SSBI"
  34 +#define DEK_LOCK_REQUEST 1
  35 +#define DEK_LOCK_YIELD (!DEK_LOCK_REQUEST)
  36 +#define DEK_YIELD_TURN_SELF 0
  37 +
  38 +struct rlock_chunk_header {
  39 + uint32_t size;
  40 + char name[RLOCK_CHUNK_NAME_LENGTH];
  41 + uint32_t lock;
  42 + uint32_t reserved;
  43 + uint32_t type;
  44 + uint32_t version;
  45 +};
  46 +struct dek_spinlock {
  47 + volatile uint8_t self_lock;
  48 + volatile uint8_t other_lock;
  49 + volatile uint8_t next_yield;
  50 + uint8_t pad;
  51 +};
  52 +
  53 +typedef union {
  54 + volatile uint32_t lock;
  55 + struct dek_spinlock dek;
  56 +} raw_remote_spinlock_t;
  57 +
  58 +typedef raw_remote_spinlock_t *remote_spinlock_t;
  59 +
  60 +remote_spinlock_t rlock;
108 platform/msm7x30/remote_spinlock.c
... ... @@ -0,0 +1,108 @@
  1 +/* Copyright (c) 2012, Code Aurora Forum. All rights reserved.
  2 + *
  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.
  12 + * * Neither the name of Code Aurora Forum, Inc. nor the names of its
  13 + * 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 +
  35 +static struct smem *smem = (void *)(MSM_SHARED_BASE);
  36 +
  37 +void *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 +
  56 +int 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 +
  90 +void 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 +}
  104 +void remote_spin_unlock(raw_remote_spinlock_t *lock)
  105 +{
  106 + dmb();
  107 + lock->dek.self_lock = DEK_LOCK_YIELD;
  108 +}
3  platform/msm7x30/rules.mk
@@ -23,7 +23,8 @@ OBJS += \
23 23 $(LOCAL_DIR)/gpio.o \
24 24 $(LOCAL_DIR)/panel.o \
25 25 $(LOCAL_DIR)/panel_sharp_wvga.o \
26   - $(LOCAL_DIR)/acpuclock.o
  26 + $(LOCAL_DIR)/acpuclock.o \
  27 + $(LOCAL_DIR)/remote_spinlock.o
27 28
28 29 ifeq ($(ENABLE_TRUSTZONE),1)
29 30 ifeq ($(ENABLE_ROMLITE_LOCAL_TEST), 1)
2  platform/msm_shared/smem.h
@@ -222,6 +222,8 @@ typedef enum {
222 222
223 223 SMEM_POWER_ON_STATUS_INFO = 403,
224 224
  225 + SMEM_RLOCK_AREA = 404,
  226 +
225 227 SMEM_BOOT_INFO_FOR_APPS = 418,
226 228
227 229 SMEM_FIRST_VALID_TYPE = SMEM_SPINLOCK_ARRAY,
8 target/msm7630_surf/init.c
@@ -41,6 +41,9 @@
41 41 #include <mmc.h>
42 42 #include <platform/iomap.h>
43 43 #include <platform/machtype.h>
  44 +#ifdef TARGET_USES_RSPIN_LOCK
  45 +#include <platform/remote_spinlock.h>
  46 +#endif
44 47 #include <platform.h>
45 48
46 49 #define MSM8255_ID 74
@@ -179,6 +182,11 @@ void target_init(void)
179 182
180 183 dprintf(INFO, "target_init()\n");
181 184
  185 +#ifdef TARGET_USES_RSPIN_LOCK
  186 + if(remote_spinlock_init(&rlock))
  187 + dprintf(SPEW,"Failed to Initialize remote spin locks\n");
  188 +#endif
  189 +
182 190 #if (!ENABLE_NANDWRITE)
183 191 keys_init();
184 192 keypad_init();
3  target/msm7630_surf/rules.mk
@@ -21,6 +21,7 @@ DEFINES += DISPLAY_SPLASH_SCREEN=0
21 21 DEFINES += DISPLAY_TYPE_MDDI=0
22 22 DEFINES += DISPLAY_TYPE_LCDC=0
23 23 DEFINES += MMC_BOOT_ADM=0
  24 +DEFINES += TARGET_USES_RSPIN_LOCK=1
24 25
25 26 MODULES += \
26 27 dev/keys \
@@ -41,4 +42,4 @@ DEFINES += \
41 42 OBJS += \
42 43 $(LOCAL_DIR)/init.o \
43 44 $(LOCAL_DIR)/atags.o \
44   - $(LOCAL_DIR)/keypad.o \
  45 + $(LOCAL_DIR)/keypad.o

0 comments on commit e1ecef5

Please sign in to comment.
Something went wrong with that request. Please try again.