Path: blob/main/sys/compat/linuxkpi/common/include/linux/dmapool.h
39604 views
/*-1* Copyright (c) 2010 Isilon Systems, Inc.2* Copyright (c) 2010 iX Systems, Inc.3* Copyright (c) 2010 Panasas, Inc.4* Copyright (c) 2013, 2014 Mellanox Technologies, Ltd.5* All rights reserved.6*7* Redistribution and use in source and binary forms, with or without8* modification, are permitted provided that the following conditions9* are met:10* 1. Redistributions of source code must retain the above copyright11* notice unmodified, this list of conditions, and the following12* disclaimer.13* 2. Redistributions in binary form must reproduce the above copyright14* notice, this list of conditions and the following disclaimer in the15* documentation and/or other materials provided with the distribution.16*17* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR18* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES19* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.20* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,21* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT22* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,23* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY24* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT25* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF26* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.27*/28#ifndef _LINUXKPI_LINUX_DMAPOOL_H_29#define _LINUXKPI_LINUX_DMAPOOL_H_3031#include <linux/types.h>32#include <linux/io.h>33#include <linux/scatterlist.h>34#include <linux/device.h>35#include <linux/slab.h>3637struct dma_pool;38struct dma_pool *linux_dma_pool_create(char *name, struct device *dev,39size_t size, size_t align, size_t boundary);40void linux_dma_pool_destroy(struct dma_pool *pool);41void lkpi_dmam_pool_destroy(struct device *, void *);42void *linux_dma_pool_alloc(struct dma_pool *pool, gfp_t mem_flags,43dma_addr_t *handle);44void linux_dma_pool_free(struct dma_pool *pool, void *vaddr,45dma_addr_t dma_addr);4647static inline struct dma_pool *48dma_pool_create(char *name, struct device *dev, size_t size,49size_t align, size_t boundary)50{5152return (linux_dma_pool_create(name, dev, size, align, boundary));53}5455static inline struct dma_pool *56dmam_pool_create(/* const */ char *name, struct device *dev, size_t size,57size_t align, size_t boundary)58{59struct dma_pool **pp;6061pp = devres_alloc(lkpi_dmam_pool_destroy, sizeof(*pp), GFP_KERNEL);62if (pp == NULL)63return (NULL);64*pp = linux_dma_pool_create(name, dev, size, align, boundary);65if (*pp == NULL) {66devres_free(pp);67return (NULL);68}6970devres_add(dev, pp);71return (*pp);72}7374static inline void75dma_pool_destroy(struct dma_pool *pool)76{7778linux_dma_pool_destroy(pool);79}8081static inline void *82dma_pool_alloc(struct dma_pool *pool, gfp_t mem_flags, dma_addr_t *handle)83{8485return (linux_dma_pool_alloc(pool, mem_flags, handle));86}8788static inline void *89dma_pool_zalloc(struct dma_pool *pool, gfp_t mem_flags, dma_addr_t *handle)90{9192return (dma_pool_alloc(pool, mem_flags | __GFP_ZERO, handle));93}9495static inline void96dma_pool_free(struct dma_pool *pool, void *vaddr, dma_addr_t dma_addr)97{9899linux_dma_pool_free(pool, vaddr, dma_addr);100}101102#endif /* _LINUXKPI_LINUX_DMAPOOL_H_ */103104105