// SPDX-License-Identifier: GPL-2.0 /* * Driver for FPGA Accelerated Function Unit (AFU) DMA Region Management * * Copyright (C) 2017-2018 Intel Corporation, Inc. * * Authors: * Wu Hao <[email protected]> * Xiao Guangrong <[email protected]> */ #include <linux/dma-mapping.h> #include <linux/sched/signal.h> #include <linux/uaccess.h> #include <linux/mm.h> #include "dfl-afu.h" void afu_dma_region_init(struct dfl_feature_platform_data *pdata) { … } /** * afu_dma_pin_pages - pin pages of given dma memory region * @pdata: feature device platform data * @region: dma memory region to be pinned * * Pin all the pages of given dfl_afu_dma_region. * Return 0 for success or negative error code. */ static int afu_dma_pin_pages(struct dfl_feature_platform_data *pdata, struct dfl_afu_dma_region *region) { … } /** * afu_dma_unpin_pages - unpin pages of given dma memory region * @pdata: feature device platform data * @region: dma memory region to be unpinned * * Unpin all the pages of given dfl_afu_dma_region. * Return 0 for success or negative error code. */ static void afu_dma_unpin_pages(struct dfl_feature_platform_data *pdata, struct dfl_afu_dma_region *region) { … } /** * afu_dma_check_continuous_pages - check if pages are continuous * @region: dma memory region * * Return true if pages of given dma memory region have continuous physical * address, otherwise return false. */ static bool afu_dma_check_continuous_pages(struct dfl_afu_dma_region *region) { … } /** * dma_region_check_iova - check if memory area is fully contained in the region * @region: dma memory region * @iova: address of the dma memory area * @size: size of the dma memory area * * Compare the dma memory area defined by @iova and @size with given dma region. * Return true if memory area is fully contained in the region, otherwise false. */ static bool dma_region_check_iova(struct dfl_afu_dma_region *region, u64 iova, u64 size) { … } /** * afu_dma_region_add - add given dma region to rbtree * @pdata: feature device platform data * @region: dma region to be added * * Return 0 for success, -EEXIST if dma region has already been added. * * Needs to be called with pdata->lock heold. */ static int afu_dma_region_add(struct dfl_feature_platform_data *pdata, struct dfl_afu_dma_region *region) { … } /** * afu_dma_region_remove - remove given dma region from rbtree * @pdata: feature device platform data * @region: dma region to be removed * * Needs to be called with pdata->lock heold. */ static void afu_dma_region_remove(struct dfl_feature_platform_data *pdata, struct dfl_afu_dma_region *region) { … } /** * afu_dma_region_destroy - destroy all regions in rbtree * @pdata: feature device platform data * * Needs to be called with pdata->lock heold. */ void afu_dma_region_destroy(struct dfl_feature_platform_data *pdata) { … } /** * afu_dma_region_find - find the dma region from rbtree based on iova and size * @pdata: feature device platform data * @iova: address of the dma memory area * @size: size of the dma memory area * * It finds the dma region from the rbtree based on @iova and @size: * - if @size == 0, it finds the dma region which starts from @iova * - otherwise, it finds the dma region which fully contains * [@iova, @iova+size) * If nothing is matched returns NULL. * * Needs to be called with pdata->lock held. */ struct dfl_afu_dma_region * afu_dma_region_find(struct dfl_feature_platform_data *pdata, u64 iova, u64 size) { … } /** * afu_dma_region_find_iova - find the dma region from rbtree by iova * @pdata: feature device platform data * @iova: address of the dma region * * Needs to be called with pdata->lock held. */ static struct dfl_afu_dma_region * afu_dma_region_find_iova(struct dfl_feature_platform_data *pdata, u64 iova) { … } /** * afu_dma_map_region - map memory region for dma * @pdata: feature device platform data * @user_addr: address of the memory region * @length: size of the memory region * @iova: pointer of iova address * * Map memory region defined by @user_addr and @length, and return dma address * of the memory region via @iova. * Return 0 for success, otherwise error code. */ int afu_dma_map_region(struct dfl_feature_platform_data *pdata, u64 user_addr, u64 length, u64 *iova) { … } /** * afu_dma_unmap_region - unmap dma memory region * @pdata: feature device platform data * @iova: dma address of the region * * Unmap dma memory region based on @iova. * Return 0 for success, otherwise error code. */ int afu_dma_unmap_region(struct dfl_feature_platform_data *pdata, u64 iova) { … }