1419b0af8Sopenharmony_ci/* 2419b0af8Sopenharmony_ci * Copyright (c) 2012-2022 Huawei Technologies Co., Ltd. 3419b0af8Sopenharmony_ci * Description: get and set static mem info. 4419b0af8Sopenharmony_ci * 5419b0af8Sopenharmony_ci * This software is licensed under the terms of the GNU General Public 6419b0af8Sopenharmony_ci * License version 2, as published by the Free Software Foundation, and 7419b0af8Sopenharmony_ci * may be copied, distributed, and modified under those terms. 8419b0af8Sopenharmony_ci * 9419b0af8Sopenharmony_ci * This program is distributed in the hope that it will be useful, 10419b0af8Sopenharmony_ci * but WITHOUT ANY WARRANTY; without even the implied warranty of 11419b0af8Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12419b0af8Sopenharmony_ci * GNU General Public License for more details. 13419b0af8Sopenharmony_ci */ 14419b0af8Sopenharmony_ci 15419b0af8Sopenharmony_ci#include "declare_static_ion.h" 16419b0af8Sopenharmony_ci#include <linux/of_reserved_mem.h> 17419b0af8Sopenharmony_ci#include <linux/of.h> 18419b0af8Sopenharmony_ci#include "tc_ns_log.h" 19419b0af8Sopenharmony_ci 20419b0af8Sopenharmony_cistatic u64 g_ion_mem_addr; 21419b0af8Sopenharmony_cistatic u64 g_ion_mem_size; 22419b0af8Sopenharmony_ci 23419b0af8Sopenharmony_cistatic int supersonic_reserve_tee_mem(const struct reserved_mem *rmem) 24419b0af8Sopenharmony_ci{ 25419b0af8Sopenharmony_ci if (rmem) { 26419b0af8Sopenharmony_ci g_ion_mem_addr = rmem->base; 27419b0af8Sopenharmony_ci g_ion_mem_size = rmem->size; 28419b0af8Sopenharmony_ci } else { 29419b0af8Sopenharmony_ci tloge("rmem is NULL\n"); 30419b0af8Sopenharmony_ci } 31419b0af8Sopenharmony_ci 32419b0af8Sopenharmony_ci return 0; 33419b0af8Sopenharmony_ci} 34419b0af8Sopenharmony_ci 35419b0af8Sopenharmony_ciRESERVEDMEM_OF_DECLARE(supersonic, "platform-supersonic", 36419b0af8Sopenharmony_ci supersonic_reserve_tee_mem); 37419b0af8Sopenharmony_ci 38419b0af8Sopenharmony_cistatic u64 g_secfacedetect_mem_addr; 39419b0af8Sopenharmony_cistatic u64 g_secfacedetect_mem_size; 40419b0af8Sopenharmony_ci 41419b0af8Sopenharmony_cistatic int secfacedetect_reserve_tee_mem(const struct reserved_mem *rmem) 42419b0af8Sopenharmony_ci{ 43419b0af8Sopenharmony_ci if (rmem) { 44419b0af8Sopenharmony_ci g_secfacedetect_mem_addr = rmem->base; 45419b0af8Sopenharmony_ci g_secfacedetect_mem_size = rmem->size; 46419b0af8Sopenharmony_ci } else { 47419b0af8Sopenharmony_ci tloge("secfacedetect_reserve_tee_mem mem is NULL\n"); 48419b0af8Sopenharmony_ci } 49419b0af8Sopenharmony_ci return 0; 50419b0af8Sopenharmony_ci} 51419b0af8Sopenharmony_ciRESERVEDMEM_OF_DECLARE(secfacedetect, "platform-secfacedetect", 52419b0af8Sopenharmony_ci secfacedetect_reserve_tee_mem); 53419b0af8Sopenharmony_ci 54419b0af8Sopenharmony_cistatic u64 g_pt_addr = 0; 55419b0af8Sopenharmony_cistatic u64 g_pt_size = 0; 56419b0af8Sopenharmony_ci 57419b0af8Sopenharmony_cistatic int reserve_pt_mem(const struct reserved_mem *rmem) 58419b0af8Sopenharmony_ci{ 59419b0af8Sopenharmony_ci if (rmem) { 60419b0af8Sopenharmony_ci g_pt_size = rmem->size; 61419b0af8Sopenharmony_ci g_pt_addr = rmem->base; 62419b0af8Sopenharmony_ci tloge("reserve pt mem is not NULL\n"); 63419b0af8Sopenharmony_ci } else { 64419b0af8Sopenharmony_ci tloge("reserve pt mem is NULL\n"); 65419b0af8Sopenharmony_ci } 66419b0af8Sopenharmony_ci return 0; 67419b0af8Sopenharmony_ci} 68419b0af8Sopenharmony_ci 69419b0af8Sopenharmony_ciRESERVEDMEM_OF_DECLARE(pagetable, "platform-ai-pagetable", 70419b0af8Sopenharmony_ci reserve_pt_mem); 71419b0af8Sopenharmony_ci 72419b0af8Sopenharmony_cistatic u64 g_pp_addr = 0; 73419b0af8Sopenharmony_cistatic u64 g_pp_size = 0; 74419b0af8Sopenharmony_ci 75419b0af8Sopenharmony_cistatic int reserve_pp_mem(const struct reserved_mem *rmem) 76419b0af8Sopenharmony_ci{ 77419b0af8Sopenharmony_ci if (rmem) { 78419b0af8Sopenharmony_ci g_pp_addr = rmem->base; 79419b0af8Sopenharmony_ci g_pp_size = rmem->size; 80419b0af8Sopenharmony_ci } else { 81419b0af8Sopenharmony_ci tloge("reserve pp mem is NULL\n"); 82419b0af8Sopenharmony_ci } 83419b0af8Sopenharmony_ci return 0; 84419b0af8Sopenharmony_ci} 85419b0af8Sopenharmony_ci 86419b0af8Sopenharmony_ciRESERVEDMEM_OF_DECLARE(ai_running, "platform-ai-running", 87419b0af8Sopenharmony_ci reserve_pp_mem); 88419b0af8Sopenharmony_ci 89419b0af8Sopenharmony_cistatic u64 g_voiceid_addr = 0; 90419b0af8Sopenharmony_cistatic u64 g_voiceid_size = 0; 91419b0af8Sopenharmony_cistatic int voiceid_reserve_tee_mem(const struct reserved_mem *rmem) 92419b0af8Sopenharmony_ci{ 93419b0af8Sopenharmony_ci if (rmem) { 94419b0af8Sopenharmony_ci g_voiceid_addr = rmem->base; 95419b0af8Sopenharmony_ci g_voiceid_size = rmem->size; 96419b0af8Sopenharmony_ci } else { 97419b0af8Sopenharmony_ci tloge("voiceid reserve tee mem is NULL\n"); 98419b0af8Sopenharmony_ci } 99419b0af8Sopenharmony_ci return 0; 100419b0af8Sopenharmony_ci} 101419b0af8Sopenharmony_ciRESERVEDMEM_OF_DECLARE(voiceid, "platform-voiceid", 102419b0af8Sopenharmony_ci voiceid_reserve_tee_mem); 103419b0af8Sopenharmony_ci 104419b0af8Sopenharmony_cistatic u64 g_secos_ex_addr; 105419b0af8Sopenharmony_cistatic u64 g_secos_ex_size; 106419b0af8Sopenharmony_cistatic int secos_reserve_tee_mem(const struct reserved_mem *rmem) 107419b0af8Sopenharmony_ci{ 108419b0af8Sopenharmony_ci if (rmem) { 109419b0af8Sopenharmony_ci g_secos_ex_addr = rmem->base; 110419b0af8Sopenharmony_ci g_secos_ex_size = rmem->size; 111419b0af8Sopenharmony_ci } else { 112419b0af8Sopenharmony_ci tloge("secos reserve tee mem is NULL\n"); 113419b0af8Sopenharmony_ci } 114419b0af8Sopenharmony_ci return 0; 115419b0af8Sopenharmony_ci} 116419b0af8Sopenharmony_ciRESERVEDMEM_OF_DECLARE(secos_ex, "platform-secos-ex", 117419b0af8Sopenharmony_ci secos_reserve_tee_mem); 118419b0af8Sopenharmony_ci 119419b0af8Sopenharmony_cistatic u64 g_ion_ex_mem_addr; 120419b0af8Sopenharmony_cistatic u64 g_ion_ex_mem_size; 121419b0af8Sopenharmony_cistatic int supersonic_ex_reserve_tee_mem(const struct reserved_mem *rmem) 122419b0af8Sopenharmony_ci{ 123419b0af8Sopenharmony_ci if (rmem) { 124419b0af8Sopenharmony_ci g_ion_ex_mem_addr = rmem->base; 125419b0af8Sopenharmony_ci g_ion_ex_mem_size = rmem->size; 126419b0af8Sopenharmony_ci } else { 127419b0af8Sopenharmony_ci tloge("rmem is NULL\n"); 128419b0af8Sopenharmony_ci } 129419b0af8Sopenharmony_ci return 0; 130419b0af8Sopenharmony_ci} 131419b0af8Sopenharmony_ciRESERVEDMEM_OF_DECLARE(supersonic_ex, "platform-supersonic-ex", 132419b0af8Sopenharmony_ci supersonic_ex_reserve_tee_mem); 133419b0af8Sopenharmony_ci 134419b0af8Sopenharmony_cistatic void set_mem_tag(struct register_ion_mem_tag *memtag, 135419b0af8Sopenharmony_ci u64 addr, u64 size, uint32_t tag, uint32_t *pos) 136419b0af8Sopenharmony_ci{ 137419b0af8Sopenharmony_ci memtag->memaddr[*pos] = addr; 138419b0af8Sopenharmony_ci memtag->memsize[*pos] = size; 139419b0af8Sopenharmony_ci memtag->memtag[*pos] = tag; 140419b0af8Sopenharmony_ci (*pos)++; 141419b0af8Sopenharmony_ci} 142419b0af8Sopenharmony_ci 143419b0af8Sopenharmony_civoid set_ion_mem_info(struct register_ion_mem_tag *memtag) 144419b0af8Sopenharmony_ci{ 145419b0af8Sopenharmony_ci uint32_t pos = 0; 146419b0af8Sopenharmony_ci if(!memtag) { 147419b0af8Sopenharmony_ci tloge("invalid memtag\n"); 148419b0af8Sopenharmony_ci return; 149419b0af8Sopenharmony_ci } 150419b0af8Sopenharmony_ci 151419b0af8Sopenharmony_ci tlogi("ion mem static reserved for tee face=%d, finger=%d,voiceid=%d," 152419b0af8Sopenharmony_ci "secos=%d,finger-ex=%d, pt_size= %d,pp_size=%d\n", 153419b0af8Sopenharmony_ci (uint32_t)g_secfacedetect_mem_size, (uint32_t)g_ion_mem_size, 154419b0af8Sopenharmony_ci (uint32_t)g_voiceid_size, (uint32_t)g_secos_ex_size, 155419b0af8Sopenharmony_ci (uint32_t)g_ion_ex_mem_size, (uint32_t)g_pt_size, 156419b0af8Sopenharmony_ci (uint32_t)g_pp_size); 157419b0af8Sopenharmony_ci 158419b0af8Sopenharmony_ci if (g_ion_mem_addr != (u64)0 && g_ion_mem_size != (u64)0) 159419b0af8Sopenharmony_ci set_mem_tag(memtag,g_ion_mem_addr, g_ion_mem_size, PP_MEM_TAG, &pos); 160419b0af8Sopenharmony_ci if (g_secfacedetect_mem_addr != (u64)0 && g_secfacedetect_mem_size != (u64)0) 161419b0af8Sopenharmony_ci set_mem_tag(memtag,g_secfacedetect_mem_addr, g_secfacedetect_mem_size, PP_MEM_TAG, &pos); 162419b0af8Sopenharmony_ci if (g_voiceid_addr != (u64)0 && g_voiceid_size != (u64)0) 163419b0af8Sopenharmony_ci set_mem_tag(memtag, g_voiceid_addr, g_voiceid_size, PP_MEM_TAG, &pos); 164419b0af8Sopenharmony_ci if (g_secos_ex_addr != (u64)0 && g_secos_ex_size != (u64)0) 165419b0af8Sopenharmony_ci set_mem_tag(memtag, g_secos_ex_addr, g_secos_ex_size, PP_MEM_TAG, &pos); 166419b0af8Sopenharmony_ci if (g_pt_addr != (u64)0 && g_pt_size != (u64)0) 167419b0af8Sopenharmony_ci set_mem_tag(memtag, g_pt_addr, g_pt_size, PT_MEM_TAG, &pos); 168419b0af8Sopenharmony_ci if (g_pp_addr != (u64)0 && g_pp_size != (u64)0) 169419b0af8Sopenharmony_ci set_mem_tag(memtag, g_pp_addr, g_pp_size, PRI_PP_MEM_TAG, &pos); 170419b0af8Sopenharmony_ci if (g_ion_ex_mem_addr != (u64)0 && g_ion_ex_mem_size != (u64)0) 171419b0af8Sopenharmony_ci set_mem_tag(memtag, g_ion_ex_mem_addr, g_ion_ex_mem_size, PP_MEM_TAG, &pos); 172419b0af8Sopenharmony_ci /* here pos max is 7, memaddr[] has 10 positions, just 3 free */ 173419b0af8Sopenharmony_ci memtag->size = pos; 174419b0af8Sopenharmony_ci return; 175419b0af8Sopenharmony_ci}