1219820Sjeff/*- 2219820Sjeff * Copyright (c) 2010 Isilon Systems, Inc. 3219820Sjeff * Copyright (c) 2010 iX Systems, Inc. 4219820Sjeff * Copyright (c) 2010 Panasas, Inc. 5270710Shselasky * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. 6219820Sjeff * All rights reserved. 7219820Sjeff * 8219820Sjeff * Redistribution and use in source and binary forms, with or without 9219820Sjeff * modification, are permitted provided that the following conditions 10219820Sjeff * are met: 11219820Sjeff * 1. Redistributions of source code must retain the above copyright 12219820Sjeff * notice unmodified, this list of conditions, and the following 13219820Sjeff * disclaimer. 14219820Sjeff * 2. Redistributions in binary form must reproduce the above copyright 15219820Sjeff * notice, this list of conditions and the following disclaimer in the 16219820Sjeff * documentation and/or other materials provided with the distribution. 17219820Sjeff * 18219820Sjeff * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19219820Sjeff * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20219820Sjeff * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21219820Sjeff * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22219820Sjeff * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23219820Sjeff * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24219820Sjeff * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25219820Sjeff * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26219820Sjeff * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27219820Sjeff * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28289644Shselasky * 29289644Shselasky * $FreeBSD: stable/11/sys/compat/linuxkpi/common/include/linux/io-mapping.h 328653 2018-02-01 13:01:44Z hselasky $ 30219820Sjeff */ 31328653Shselasky 32328653Shselasky#ifndef _LINUX_IO_MAPPING_H_ 33219820Sjeff#define _LINUX_IO_MAPPING_H_ 34219820Sjeff 35328653Shselasky#include <sys/types.h> 36328653Shselasky#include <machine/vm.h> 37328653Shselasky 38219820Sjeff#include <linux/types.h> 39219820Sjeff#include <linux/io.h> 40328653Shselasky#include <linux/slab.h> 41219820Sjeff 42328653Shselaskystruct io_mapping { 43328653Shselasky unsigned long base; 44328653Shselasky unsigned long size; 45328653Shselasky void *mem; 46328653Shselasky vm_memattr_t attr; 47328653Shselasky}; 48219820Sjeff 49219820Sjeffstatic inline struct io_mapping * 50328653Shselaskyio_mapping_init_wc(struct io_mapping *mapping, resource_size_t base, 51328653Shselasky unsigned long size) 52328653Shselasky{ 53328653Shselasky 54328653Shselasky mapping->base = base; 55328653Shselasky mapping->size = size; 56328653Shselasky#ifdef VM_MEMATTR_WRITE_COMBINING 57328653Shselasky mapping->mem = ioremap_wc(base, size); 58328653Shselasky mapping->attr = VM_MEMATTR_WRITE_COMBINING; 59328653Shselasky#else 60328653Shselasky mapping->mem = ioremap_nocache(base, size); 61328653Shselasky mapping->attr = VM_MEMATTR_UNCACHEABLE; 62328653Shselasky#endif 63328653Shselasky return (mapping); 64328653Shselasky} 65328653Shselasky 66328653Shselaskystatic inline struct io_mapping * 67219820Sjeffio_mapping_create_wc(resource_size_t base, unsigned long size) 68219820Sjeff{ 69328653Shselasky struct io_mapping *mapping; 70219820Sjeff 71328653Shselasky mapping = kmalloc(sizeof(*mapping), GFP_KERNEL); 72328653Shselasky if (mapping == NULL) 73328653Shselasky return (NULL); 74328653Shselasky return (io_mapping_init_wc(mapping, base, size)); 75219820Sjeff} 76219820Sjeff 77219820Sjeffstatic inline void 78328653Shselaskyio_mapping_fini(struct io_mapping *mapping) 79328653Shselasky{ 80328653Shselasky 81328653Shselasky iounmap(mapping->mem); 82328653Shselasky} 83328653Shselasky 84328653Shselaskystatic inline void 85219820Sjeffio_mapping_free(struct io_mapping *mapping) 86219820Sjeff{ 87219820Sjeff 88328653Shselasky io_mapping_fini(mapping->mem); 89328653Shselasky kfree(mapping); 90219820Sjeff} 91219820Sjeff 92219820Sjeffstatic inline void * 93219820Sjeffio_mapping_map_atomic_wc(struct io_mapping *mapping, unsigned long offset) 94219820Sjeff{ 95219820Sjeff 96328653Shselasky return ((char *)mapping->mem + offset); 97219820Sjeff} 98219820Sjeff 99219820Sjeffstatic inline void 100219820Sjeffio_mapping_unmap_atomic(void *vaddr) 101219820Sjeff{ 102219820Sjeff} 103219820Sjeff 104219820Sjeffstatic inline void * 105328653Shselaskyio_mapping_map_wc(struct io_mapping *mapping, unsigned long offset, 106328653Shselasky unsigned long size) 107219820Sjeff{ 108219820Sjeff 109328653Shselasky return ((char *)mapping->mem + offset); 110219820Sjeff} 111219820Sjeff 112219820Sjeffstatic inline void 113219820Sjeffio_mapping_unmap(void *vaddr) 114219820Sjeff{ 115219820Sjeff} 116219820Sjeff 117328653Shselasky#endif /* _LINUX_IO_MAPPING_H_ */ 118