Steve Muckle | 0a9c087 | 2022-02-16 05:58:07 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * Copyright (C) 2018 Cadence Design Systems, Inc. |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining |
| 5 | * a copy of this software and associated documentation files (the |
| 6 | * "Software"), to use this Software with Cadence processor cores only and |
| 7 | * not with any other processors and platforms, subject to |
| 8 | * the following conditions: |
| 9 | * |
| 10 | * The above copyright notice and this permission notice shall be included |
| 11 | * in all copies or substantial portions of the Software. |
| 12 | * |
| 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 14 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 15 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 16 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 17 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 18 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 19 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 20 | |
| 21 | ******************************************************************************/ |
| 22 | |
| 23 | /******************************************************************************* |
| 24 | * xf-proxy.h |
| 25 | * |
| 26 | * Proxy commmand/response messages |
| 27 | * |
| 28 | *******************************************************************************/ |
| 29 | |
| 30 | #ifndef __XF_H |
| 31 | #error "xf-proxy.h mustn't be included directly" |
| 32 | #endif |
| 33 | |
| 34 | /******************************************************************************* |
| 35 | * Types definitions |
| 36 | ******************************************************************************/ |
| 37 | #ifdef XAF_ENABLE_NON_HIKEY |
| 38 | /* ...command/response message */ |
| 39 | typedef struct xf_proxy_message |
| 40 | { |
| 41 | /* ...session ID */ |
| 42 | uint32_t session_id; |
| 43 | |
| 44 | /* ...proxy API command/reponse code */ |
| 45 | uint32_t opcode; |
| 46 | |
| 47 | /* ...length of attached buffer */ |
| 48 | uint32_t length; |
| 49 | |
| 50 | /* ...physical address of message buffer */ |
| 51 | uint64_t address; |
| 52 | uint64_t v_address; |
| 53 | |
| 54 | } __attribute__((__packed__)) xf_proxy_message_t; |
| 55 | #else |
| 56 | /* ...command/response message */ |
| 57 | typedef struct xf_proxy_message |
| 58 | { |
| 59 | /* ...session ID */ |
| 60 | uint32_t session_id; |
| 61 | |
| 62 | /* ...proxy API command/reponse code */ |
| 63 | uint32_t opcode; |
| 64 | |
| 65 | /* ...length of attached buffer */ |
| 66 | uint32_t length; |
| 67 | |
| 68 | /* ...physical address of message buffer */ |
| 69 | uint64_t address; |
| 70 | uint64_t v_address; |
| 71 | |
| 72 | } __attribute__((__packed__)) xf_proxy_message_t; |
| 73 | #endif |
| 74 | /******************************************************************************* |
| 75 | * Ring buffer support |
| 76 | ******************************************************************************/ |
| 77 | |
| 78 | /* ...total length of shared memory queue (for commands and responses) */ |
| 79 | #define XF_PROXY_MESSAGE_QUEUE_LENGTH (1 << 8) |
| 80 | |
| 81 | /* ...index mask */ |
| 82 | #define XF_PROXY_MESSAGE_QUEUE_MASK 0xFF |
| 83 | |
| 84 | /* ...ring-buffer index */ |
| 85 | #define __XF_QUEUE_IDX(idx, counter) \ |
| 86 | (((idx) & XF_PROXY_MESSAGE_QUEUE_MASK) | ((counter) << 16)) |
| 87 | |
| 88 | /* ...retrieve ring-buffer index */ |
| 89 | #define XF_QUEUE_IDX(idx) \ |
| 90 | ((idx) & XF_PROXY_MESSAGE_QUEUE_MASK) |
| 91 | |
| 92 | /* ...increment ring-buffer index */ |
| 93 | #define XF_QUEUE_ADVANCE_IDX(idx) \ |
| 94 | (((idx) + 0x10001) & (0xFFFF0000 | XF_PROXY_MESSAGE_QUEUE_MASK)) |
| 95 | |
| 96 | /* ...test if ring buffer is empty */ |
| 97 | #define XF_QUEUE_EMPTY(read, write) \ |
| 98 | ((read) == (write)) |
| 99 | |
| 100 | /* ...test if ring buffer is full */ |
| 101 | #define XF_QUEUE_FULL(read, write) \ |
| 102 | ((write) == (read) + (XF_PROXY_MESSAGE_QUEUE_LENGTH << 16)) |