1 /* 2 * Copyright (C) 2018 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 #pragma once 18 19 /* Trusty-specific APIs for memory management */ 20 21 #include <stdint.h> 22 #include <uapi/mm.h> 23 24 /* Don't use convenience macros here, it will polute the namespace. */ 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 29 /* Trusty specific. */ 30 int prepare_dma(void* uaddr, 31 uint32_t size, 32 uint32_t flags, 33 struct dma_pmem* pmem); 34 int finish_dma(void* uaddr, uint32_t size, uint32_t flags); 35 36 /* Utility Functions */ 37 38 /** 39 * prepare_input_output_dma() - helper utility for using the prepare_dma 40 * syscall. prepare_dma can only be called once with an address. If the same 41 * buffer is being used for input and output, we should only call prepare_dma 42 * once. This utility will handle address checking, making the prepare_dma 43 * sycall, and filling in the appropriate dma_pmem. 44 * 45 * @input pointer to input buffer 46 * @input_len length of input buffer 47 * @output pointer to output buffer 48 * @output_len length of output buffer 49 * @input_pmem pointer to input dma descriptor 50 * @output_pmem pointer to output dma descriptor 51 * 52 * Returns : LK error code 53 */ 54 int prepare_input_output_dma(void* input, 55 uint32_t input_len, 56 void* output, 57 uint32_t output_len, 58 struct dma_pmem* input_pmem, 59 struct dma_pmem* output_pmem); 60 61 /** 62 * finish_input_output_dma() - helper utility for using the finish_dma 63 * syscalls. Depending on the input/output address, only one prepare_dma might 64 * have been called. This utility handles calling finish_dma with the correct 65 * flags and number of times. 66 * 67 * @input pointer to input buffer 68 * @input_len length of input buffer 69 * @output pointer to output buffer 70 * @output_len length of output buffer 71 * 72 * Returns : LK error code 73 */ 74 int finish_input_output_dma(void* input, 75 uint32_t input_len, 76 void* output, 77 uint32_t output_len); 78 79 #ifdef __cplusplus 80 } 81 #endif 82