1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ESE_SG_H_ 18 #define ESE_SG_H_ 1 19 20 #include "../../../libese-sysdeps/include/ese/sysdeps.h" 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 26 /* Scatter-Gather Buffer */ 27 struct EseSgBuffer { 28 union { 29 uint8_t *base; 30 const uint8_t *c_base; 31 }; 32 uint32_t len; 33 }; 34 35 #define ese_sg_set(ese_sg_ptr, buf, len) \ 36 (ese_sg_ptr)->base = buf; \ 37 (ese_sg_ptr)->len = len 38 39 /* Computes the total length/size of the buffer on each call. */ 40 uint32_t ese_sg_length(const struct EseSgBuffer *bufs, uint32_t cnt); 41 uint32_t ese_sg_to_buf(const struct EseSgBuffer *src, uint32_t src_cnt, uint32_t start_at, uint32_t length, uint8_t *dst); 42 uint32_t ese_sg_from_buf(struct EseSgBuffer *dst, uint32_t dst_cnt, uint32_t start_at, uint32_t length, const uint8_t *src); 43 44 #ifdef __cplusplus 45 } /* extern "C" */ 46 #endif 47 48 #endif /* ESE_SG_H_ */ 49