18d59ecb2SHans Petter Selasky /*- 28d59ecb2SHans Petter Selasky * Copyright (c) 2010 Isilon Systems, Inc. 38d59ecb2SHans Petter Selasky * Copyright (c) 2010 iX Systems, Inc. 48d59ecb2SHans Petter Selasky * Copyright (c) 2010 Panasas, Inc. 58d59ecb2SHans Petter Selasky * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. 68d59ecb2SHans Petter Selasky * All rights reserved. 78d59ecb2SHans Petter Selasky * 88d59ecb2SHans Petter Selasky * Redistribution and use in source and binary forms, with or without 98d59ecb2SHans Petter Selasky * modification, are permitted provided that the following conditions 108d59ecb2SHans Petter Selasky * are met: 118d59ecb2SHans Petter Selasky * 1. Redistributions of source code must retain the above copyright 128d59ecb2SHans Petter Selasky * notice unmodified, this list of conditions, and the following 138d59ecb2SHans Petter Selasky * disclaimer. 148d59ecb2SHans Petter Selasky * 2. Redistributions in binary form must reproduce the above copyright 158d59ecb2SHans Petter Selasky * notice, this list of conditions and the following disclaimer in the 168d59ecb2SHans Petter Selasky * documentation and/or other materials provided with the distribution. 178d59ecb2SHans Petter Selasky * 188d59ecb2SHans Petter Selasky * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 198d59ecb2SHans Petter Selasky * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 208d59ecb2SHans Petter Selasky * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 218d59ecb2SHans Petter Selasky * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 228d59ecb2SHans Petter Selasky * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 238d59ecb2SHans Petter Selasky * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 248d59ecb2SHans Petter Selasky * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 258d59ecb2SHans Petter Selasky * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 268d59ecb2SHans Petter Selasky * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 278d59ecb2SHans Petter Selasky * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 288d59ecb2SHans Petter Selasky * 298d59ecb2SHans Petter Selasky * $FreeBSD$ 308d59ecb2SHans Petter Selasky */ 318d59ecb2SHans Petter Selasky #ifndef _LINUX_DMAPOOL_H_ 328d59ecb2SHans Petter Selasky #define _LINUX_DMAPOOL_H_ 338d59ecb2SHans Petter Selasky 348d59ecb2SHans Petter Selasky #include <linux/types.h> 358d59ecb2SHans Petter Selasky #include <linux/io.h> 368d59ecb2SHans Petter Selasky #include <linux/scatterlist.h> 378d59ecb2SHans Petter Selasky #include <linux/device.h> 388d59ecb2SHans Petter Selasky #include <linux/slab.h> 398d59ecb2SHans Petter Selasky 40*f211d536STycho Nightingale struct dma_pool *linux_dma_pool_create(char *name, struct device *dev, 41*f211d536STycho Nightingale size_t size, size_t align, size_t boundary); 42*f211d536STycho Nightingale void linux_dma_pool_destroy(struct dma_pool *pool); 43*f211d536STycho Nightingale void *linux_dma_pool_alloc(struct dma_pool *pool, gfp_t mem_flags, 44*f211d536STycho Nightingale dma_addr_t *handle); 45*f211d536STycho Nightingale void linux_dma_pool_free(struct dma_pool *pool, void *vaddr, 46*f211d536STycho Nightingale dma_addr_t dma_addr); 47*f211d536STycho Nightingale 488d59ecb2SHans Petter Selasky struct dma_pool { 49*f211d536STycho Nightingale struct pci_dev *pool_pdev; 508d59ecb2SHans Petter Selasky uma_zone_t pool_zone; 51*f211d536STycho Nightingale struct mtx pool_dma_lock; 52*f211d536STycho Nightingale bus_dma_tag_t pool_dmat; 53*f211d536STycho Nightingale size_t pool_entry_size; 54*f211d536STycho Nightingale struct mtx pool_ptree_lock; 55*f211d536STycho Nightingale struct pctrie pool_ptree; 568d59ecb2SHans Petter Selasky }; 578d59ecb2SHans Petter Selasky 588d59ecb2SHans Petter Selasky static inline struct dma_pool * 598d59ecb2SHans Petter Selasky dma_pool_create(char *name, struct device *dev, size_t size, 608d59ecb2SHans Petter Selasky size_t align, size_t boundary) 618d59ecb2SHans Petter Selasky { 628d59ecb2SHans Petter Selasky 63*f211d536STycho Nightingale return (linux_dma_pool_create(name, dev, size, align, boundary)); 648d59ecb2SHans Petter Selasky } 658d59ecb2SHans Petter Selasky 668d59ecb2SHans Petter Selasky static inline void 678d59ecb2SHans Petter Selasky dma_pool_destroy(struct dma_pool *pool) 688d59ecb2SHans Petter Selasky { 69*f211d536STycho Nightingale 70*f211d536STycho Nightingale linux_dma_pool_destroy(pool); 718d59ecb2SHans Petter Selasky } 728d59ecb2SHans Petter Selasky 738d59ecb2SHans Petter Selasky static inline void * 748d59ecb2SHans Petter Selasky dma_pool_alloc(struct dma_pool *pool, gfp_t mem_flags, dma_addr_t *handle) 758d59ecb2SHans Petter Selasky { 768d59ecb2SHans Petter Selasky 77*f211d536STycho Nightingale return (linux_dma_pool_alloc(pool, mem_flags, handle)); 788d59ecb2SHans Petter Selasky } 798d59ecb2SHans Petter Selasky 808ad9551dSHans Petter Selasky static inline void * 818ad9551dSHans Petter Selasky dma_pool_zalloc(struct dma_pool *pool, gfp_t mem_flags, dma_addr_t *handle) 828ad9551dSHans Petter Selasky { 838ad9551dSHans Petter Selasky 848ad9551dSHans Petter Selasky return (dma_pool_alloc(pool, mem_flags | __GFP_ZERO, handle)); 858ad9551dSHans Petter Selasky } 868ad9551dSHans Petter Selasky 878d59ecb2SHans Petter Selasky static inline void 88*f211d536STycho Nightingale dma_pool_free(struct dma_pool *pool, void *vaddr, dma_addr_t dma_addr) 898d59ecb2SHans Petter Selasky { 90*f211d536STycho Nightingale 91*f211d536STycho Nightingale linux_dma_pool_free(pool, vaddr, dma_addr); 928d59ecb2SHans Petter Selasky } 938d59ecb2SHans Petter Selasky 948d59ecb2SHans Petter Selasky 958d59ecb2SHans Petter Selasky #endif /* _LINUX_DMAPOOL_H_ */ 96