blob: 3a767381b9842fa5f4912d84db1708576d90b3b9 [file] [log] [blame]
Dima Zavina404bce2009-01-26 12:32:22 -08001/*
2 * Copyright (c) 2009, Google Inc.
3 * All rights reserved.
4 *
lijuang7b1b7422017-12-27 17:49:38 +08005 * Copyright (c) 2014-2015, 2017, The Linux Foundation. All rights reserved.
Sundarajan Srinivasan79e5f512014-03-28 16:43:06 -07006 *
Dima Zavina404bce2009-01-26 12:32:22 -08007 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
24 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
27 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31#include <debug.h>
32#include <reg.h>
33#include <sys/types.h>
34#include <platform/iomap.h>
lijuangd1175052015-08-13 16:41:12 +080035#include <board.h>
Dima Zavina404bce2009-01-26 12:32:22 -080036
37#include "smem.h"
38
Sundarajan Srinivasan79e5f512014-03-28 16:43:06 -070039static struct smem *smem;
Dima Zavina404bce2009-01-26 12:32:22 -080040
lijuangd1175052015-08-13 16:41:12 +080041const char *hw_platform[] = {
42 [HW_PLATFORM_UNKNOWN] = "Unknown",
43 [HW_PLATFORM_SURF] = "Surf",
44 [HW_PLATFORM_FFA] = "FFA",
45 [HW_PLATFORM_FLUID] = "Fluid",
46 [HW_PLATFORM_SVLTE] = "SVLTE",
47 [HW_PLATFORM_MTP_MDM] = "MDM_MTP_NO_DISPLAY",
48 [HW_PLATFORM_MTP] = "MTP",
49 [HW_PLATFORM_RCM] = "RCM",
50 [HW_PLATFORM_LIQUID] = "Liquid",
51 [HW_PLATFORM_DRAGON] = "Dragon",
52 [HW_PLATFORM_QRD] = "QRD",
Zhu Bin576c0642016-11-17 18:18:02 +080053 [HW_PLATFORM_IPC] = "IPC",
lijuangd1175052015-08-13 16:41:12 +080054 [HW_PLATFORM_HRD] = "HRD",
55 [HW_PLATFORM_DTV] = "DTV",
56 [HW_PLATFORM_STP] = "STP",
57 [HW_PLATFORM_SBC] = "SBC",
Mayank Grover03b48ed2018-05-17 14:48:29 +053058 [HW_PLATFORM_ATP] = "ATP",
lijuangd1175052015-08-13 16:41:12 +080059};
60
Channagoud Kadabi9e574882014-06-24 16:15:23 -070061/* DYNAMIC SMEM REGION feature enables LK to dynamically
62 * read the SMEM addr info from TCSR register or IMEM location.
63 * The first word read, if indicates a MAGIC number, then
64 * Dynamic SMEM is assumed to be enabled. Read the remaining
65 * SMEM info for SMEM Size and Phy_addr from the other bytes.
66 */
67
68#if DYNAMIC_SMEM
69uint32_t smem_get_base_addr()
70{
71 struct smem_addr_info *smem_info = NULL;
72
73 smem_info = (struct smem_addr_info *) SMEM_TARG_INFO_ADDR;
74 if(smem_info && (smem_info->identifier == SMEM_TARGET_INFO_IDENTIFIER))
75 return smem_info->phy_addr;
76 else
77 return MSM_SHARED_BASE;
78}
79#endif
80
Ajay Dudanic78b36f2010-07-08 19:34:06 -070081/* buf MUST be 4byte aligned, and len MUST be a multiple of 8. */
Dima Zavina404bce2009-01-26 12:32:22 -080082unsigned smem_read_alloc_entry(smem_mem_type_t type, void *buf, int len)
83{
84 struct smem_alloc_info *ainfo;
85 unsigned *dest = buf;
86 unsigned src;
87 unsigned size;
Sundarajan Srinivasan79e5f512014-03-28 16:43:06 -070088 uint32_t smem_addr = 0;
89
Channagoud Kadabi9e574882014-06-24 16:15:23 -070090#if DYNAMIC_SMEM
91 smem_addr = smem_get_base_addr();
92#else
Sundarajan Srinivasan79e5f512014-03-28 16:43:06 -070093 smem_addr = platform_get_smem_base_addr();
Channagoud Kadabi9e574882014-06-24 16:15:23 -070094#endif
Sundarajan Srinivasan79e5f512014-03-28 16:43:06 -070095
96 smem = (struct smem *)smem_addr;
Dima Zavina404bce2009-01-26 12:32:22 -080097
98 if (((len & 0x3) != 0) || (((unsigned)buf & 0x3) != 0))
99 return 1;
100
101 if (type < SMEM_FIRST_VALID_TYPE || type > SMEM_LAST_VALID_TYPE)
102 return 1;
103
104 /* TODO: Use smem spinlocks */
105 ainfo = &smem->alloc_info[type];
106 if (readl(&ainfo->allocated) == 0)
107 return 1;
108
Ajay Dudanic78b36f2010-07-08 19:34:06 -0700109 size = readl(&ainfo->size);
110
Sridhar Parasuramd63ea9c2014-10-22 12:39:11 -0700111 if (size < (unsigned)((len + 7) & ~0x00000007))
Dima Zavina404bce2009-01-26 12:32:22 -0800112 return 1;
113
Sundarajan Srinivasan79e5f512014-03-28 16:43:06 -0700114 src = smem_addr + readl(&ainfo->offset);
Ajay Dudanic78b36f2010-07-08 19:34:06 -0700115 for (; len > 0; src += 4, len -= 4)
Dima Zavina404bce2009-01-26 12:32:22 -0800116 *(dest++) = readl(src);
117
118 return 0;
119}
Chandan Uddaraju1434a602010-03-08 17:13:38 -0800120
Sundarajan Srinivasan28106e32014-07-24 16:39:58 -0700121/* Return a pointer to smem_item with size */
122void* smem_get_alloc_entry(smem_mem_type_t type, uint32_t* size)
123{
124 struct smem_alloc_info *ainfo = NULL;
125 uint32_t smem_addr = 0;
126 uint32_t base_ext = 0;
127 uint32_t offset = 0;
vijay kumar4f4405f2014-08-08 11:49:53 +0530128 void *ret = NULL;
Sundarajan Srinivasan28106e32014-07-24 16:39:58 -0700129
130#if DYNAMIC_SMEM
131 smem_addr = smem_get_base_addr();
132#else
133 smem_addr = platform_get_smem_base_addr();
134#endif
135 smem = (struct smem *)smem_addr;
136
137 if (type < SMEM_FIRST_VALID_TYPE || type > SMEM_LAST_VALID_TYPE)
vijay kumar4f4405f2014-08-08 11:49:53 +0530138 return ret;
Sundarajan Srinivasan28106e32014-07-24 16:39:58 -0700139
140 ainfo = &smem->alloc_info[type];
141 if (readl(&ainfo->allocated) == 0)
vijay kumar4f4405f2014-08-08 11:49:53 +0530142 return ret;
Sundarajan Srinivasan28106e32014-07-24 16:39:58 -0700143
144 *size = readl(&ainfo->size);
145 base_ext = readl(&ainfo->base_ext);
146 offset = readl(&ainfo->offset);
147
148 if(base_ext)
149 {
vijay kumar4f4405f2014-08-08 11:49:53 +0530150 ret = (void*)base_ext + offset;
Sundarajan Srinivasan28106e32014-07-24 16:39:58 -0700151 }
152 else
153 {
154 ret = (void*) smem_addr + offset;
155 }
156
157 return ret;
158}
159
Ajay Dudanib01e5062011-12-03 23:23:42 -0800160unsigned
161smem_read_alloc_entry_offset(smem_mem_type_t type, void *buf, int len,
162 int offset)
Chandan Uddaraju1434a602010-03-08 17:13:38 -0800163{
Ajay Dudanib01e5062011-12-03 23:23:42 -0800164 struct smem_alloc_info *ainfo;
165 unsigned *dest = buf;
166 unsigned src;
167 unsigned size = len;
Sundarajan Srinivasan79e5f512014-03-28 16:43:06 -0700168 uint32_t smem_addr = 0;
169
Channagoud Kadabi9e574882014-06-24 16:15:23 -0700170#if DYNAMIC_SMEM
171 smem_addr = smem_get_base_addr();
172#else
Sundarajan Srinivasan79e5f512014-03-28 16:43:06 -0700173 smem_addr = platform_get_smem_base_addr();
Channagoud Kadabi9e574882014-06-24 16:15:23 -0700174#endif
Sundarajan Srinivasan79e5f512014-03-28 16:43:06 -0700175
176 smem = (struct smem *)smem_addr;
Chandan Uddaraju1434a602010-03-08 17:13:38 -0800177
Ajay Dudanib01e5062011-12-03 23:23:42 -0800178 if (((len & 0x3) != 0) || (((unsigned)buf & 0x3) != 0))
179 return 1;
Chandan Uddaraju1434a602010-03-08 17:13:38 -0800180
Ajay Dudanib01e5062011-12-03 23:23:42 -0800181 if (type < SMEM_FIRST_VALID_TYPE || type > SMEM_LAST_VALID_TYPE)
182 return 1;
Chandan Uddaraju1434a602010-03-08 17:13:38 -0800183
Ajay Dudanib01e5062011-12-03 23:23:42 -0800184 ainfo = &smem->alloc_info[type];
185 if (readl(&ainfo->allocated) == 0)
186 return 1;
Chandan Uddaraju1434a602010-03-08 17:13:38 -0800187
Sundarajan Srinivasan79e5f512014-03-28 16:43:06 -0700188 src = smem_addr + readl(&ainfo->offset) + offset;
Ajay Dudanib01e5062011-12-03 23:23:42 -0800189 for (; size > 0; src += 4, size -= 4)
190 *(dest++) = readl(src);
Chandan Uddaraju1434a602010-03-08 17:13:38 -0800191
Ajay Dudanib01e5062011-12-03 23:23:42 -0800192 return 0;
Chandan Uddaraju1434a602010-03-08 17:13:38 -0800193}
lijuangd1175052015-08-13 16:41:12 +0800194
195size_t smem_get_hw_platform_name(void *buf, uint32 buf_size)
196{
197 uint32 hw_id;
198
199 if (buf == NULL) {
200 dprintf(CRITICAL, "ERROR: buf is NULL\n");
201 return 1;
202 }
203
204 hw_id = board_hardware_id();
lijuang7b1b7422017-12-27 17:49:38 +0800205 if (hw_id >= ARRAY_SIZE(hw_platform) || hw_platform[hw_id] == '\0')
206 return 1;
207
lijuangd1175052015-08-13 16:41:12 +0800208 if (buf_size < strlen(hw_platform[hw_id]) + 1)
209 return 1;
210
211 return snprintf(buf, strlen(hw_platform[hw_id]) + 1,
212 "%s\n", hw_platform[hw_id]);
213}