1219820Sjeff/* 2219820Sjeff * Copyright (c) 2007 Cisco Systems. All rights reserved. 3219820Sjeff * 4219820Sjeff * This software is available to you under a choice of one of two 5219820Sjeff * licenses. You may choose to be licensed under the terms of the GNU 6219820Sjeff * General Public License (GPL) Version 2, available from the file 7219820Sjeff * COPYING in the main directory of this source tree, or the 8219820Sjeff * OpenIB.org BSD license below: 9219820Sjeff * 10219820Sjeff * Redistribution and use in source and binary forms, with or 11219820Sjeff * without modification, are permitted provided that the following 12219820Sjeff * conditions are met: 13219820Sjeff * 14219820Sjeff * - Redistributions of source code must retain the above 15219820Sjeff * copyright notice, this list of conditions and the following 16219820Sjeff * disclaimer. 17219820Sjeff * 18219820Sjeff * - Redistributions in binary form must reproduce the above 19219820Sjeff * copyright notice, this list of conditions and the following 20219820Sjeff * disclaimer in the documentation and/or other materials 21219820Sjeff * provided with the distribution. 22219820Sjeff * 23219820Sjeff * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 24219820Sjeff * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 25219820Sjeff * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 26219820Sjeff * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 27219820Sjeff * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 28219820Sjeff * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 29219820Sjeff * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30219820Sjeff * SOFTWARE. 31219820Sjeff */ 32219820Sjeff 33219820Sjeff#ifndef IB_UMEM_H 34219820Sjeff#define IB_UMEM_H 35219820Sjeff 36219820Sjeff#include <linux/list.h> 37219820Sjeff#include <linux/scatterlist.h> 38219820Sjeff#include <linux/workqueue.h> 39219820Sjeff#include <linux/dma-attrs.h> 40219820Sjeff 41219820Sjeffstruct ib_ucontext; 42271127Shselaskystruct vm_area_struct; 43219820Sjeff 44219820Sjeffstruct ib_umem { 45219820Sjeff struct ib_ucontext *context; 46219820Sjeff size_t length; 47219820Sjeff int offset; 48219820Sjeff int page_size; 49219820Sjeff int writable; 50219820Sjeff int hugetlb; 51219820Sjeff struct list_head chunk_list; 52219820Sjeff#ifdef __linux__ 53219820Sjeff struct work_struct work; 54219820Sjeff struct mm_struct *mm; 55219820Sjeff#else 56219820Sjeff unsigned long start; 57219820Sjeff#endif 58219820Sjeff unsigned long diff; 59219820Sjeff}; 60219820Sjeff 61255972Salfredstruct ib_cmem { 62255972Salfred 63255972Salfred struct ib_ucontext *context; 64255972Salfred size_t length; 65255972Salfred /* Link list of contiguous blocks being part of that cmem */ 66255972Salfred struct list_head ib_cmem_block; 67255972Salfred 68255972Salfred /* Order of cmem block, 2^ block_order will equal number 69255972Salfred of physical pages per block 70255972Salfred */ 71255972Salfred unsigned long block_order; 72255972Salfred /* Refernce counter for that memory area 73255972Salfred - When value became 0 pages will be returned to the kernel. 74255972Salfred */ 75255972Salfred struct kref refcount; 76255972Salfred}; 77255972Salfred 78255972Salfred 79219820Sjeffstruct ib_umem_chunk { 80219820Sjeff struct list_head list; 81219820Sjeff int nents; 82219820Sjeff int nmap; 83219820Sjeff struct dma_attrs attrs; 84219820Sjeff struct scatterlist page_list[0]; 85219820Sjeff}; 86219820Sjeff 87219820Sjeffstruct ib_umem *ib_umem_get(struct ib_ucontext *context, unsigned long addr, 88219820Sjeff size_t size, int access, int dmasync); 89219820Sjeffvoid ib_umem_release(struct ib_umem *umem); 90219820Sjeffint ib_umem_page_count(struct ib_umem *umem); 91219820Sjeff 92255972Salfredint ib_cmem_map_contiguous_pages_to_vma(struct ib_cmem *ib_cmem, 93255972Salfred struct vm_area_struct *vma); 94255972Salfredstruct ib_cmem *ib_cmem_alloc_contiguous_pages(struct ib_ucontext *context, 95255972Salfred unsigned long total_size, 96255972Salfred unsigned long page_size_order); 97255972Salfredvoid ib_cmem_release_contiguous_pages(struct ib_cmem *cmem); 98255972Salfredint ib_umem_map_to_vma(struct ib_umem *umem, 99255972Salfred struct vm_area_struct *vma); 100255972Salfred 101255972Salfred 102219820Sjeff#endif /* IB_UMEM_H */ 103