1 /** 2 * Copyright (c) 2019, The Linux Foundation. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * * Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * * Redistributions in binary form must reproduce the above 10 * copyright notice, this list of conditions and the following 11 * disclaimer in the documentation and/or other materials provided 12 * with the distribution. 13 * * Neither the name of The Linux Foundation nor the names of its 14 * contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30 #ifndef ADSP_PLS_H 31 #define ADSP_PLS_H 32 33 #include <stdint.h> 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 /** 39 * internal header 40 */ 41 42 /** 43 * adsp process local storage is local storage for the fastrpc hlos 44 * process context. 45 46 * When used from within a fastrpc started thread this will attach 47 * desturctors to the lifetime of the hlos process that is making the 48 * rpc calls. Users can use this to store context for the lifetime of 49 * the calling process on the hlos. 50 */ 51 52 /** 53 * adds a new key to the local storage, overriding 54 * any previous value at the key. Overriding the key 55 * does not cause the destructor to run. 56 * 57 * @param type, type part of the key to be used for lookup, 58 * these should be static addresses, like the address of a function. 59 * @param key, the key to be used for lookup 60 * @param size, the size of the data 61 * @param ctor, constructor that takes a context and memory of size 62 * @param ctx, constructor context passed as the first argument to ctor 63 * @param dtor, destructor to run at pls shutdown 64 * @param ppo, output data 65 * @retval, 0 for success 66 */ 67 int adsp_pls_add(uintptr_t type, uintptr_t key, int size, int (*ctor)(void* ctx, void* data), void* ctx, void (*dtor)(void*), void** ppo); 68 69 /** 70 * Like add, but will only add 1 item, and return the same item on the 71 * next add. If two threads try to call this function at teh same time 72 * they will both receive the same value as a result, but the constructors 73 * may be called twice. 74 * item if its already there, otherwise tries to add. 75 * ctor may be called twice 76 * callers should avoid calling pls_add which will override the singleton 77 */ 78 int adsp_pls_add_lookup(uintptr_t type, uintptr_t key, int size, int (*ctor)(void* ctx, void* data), void* ctx, void (*dtor)(void*), void** ppo); 79 80 /** 81 * finds the last data pointer added for key to the local storage 82 * 83 * @param key, the key to be used for lookup 84 * @param ppo, output data 85 * @retval, 0 for success 86 */ 87 int adsp_pls_lookup(uintptr_t type, uintptr_t key, void** ppo); 88 89 /** 90 * force init/deinit 91 */ 92 int gpls_init(void); 93 void gpls_deinit(void); 94 95 #ifdef __cplusplus 96 } 97 #endif 98 #endif //ADSP_PLS_H 99