1219820Sjeff/*- 2219820Sjeff * Copyright (c) 2010 Isilon Systems, Inc. 3219820Sjeff * Copyright (c) 2010 iX Systems, Inc. 4219820Sjeff * Copyright (c) 2010 Panasas, Inc. 5271127Shselasky * 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. 28219820Sjeff */ 29219820Sjeff 30219820Sjeff#ifndef _LINUX_IO_H_ 31219820Sjeff#define _LINUX_IO_H_ 32219820Sjeff 33219820Sjeff#include <machine/vm.h> 34282513Shselasky#include <sys/endian.h> 35219820Sjeff 36219820Sjeffstatic inline uint32_t 37219820Sjeff__raw_readl(const volatile void *addr) 38219820Sjeff{ 39219820Sjeff return *(const volatile uint32_t *)addr; 40219820Sjeff} 41219820Sjeff 42219820Sjeffstatic inline void 43219820Sjeff__raw_writel(uint32_t b, volatile void *addr) 44219820Sjeff{ 45219820Sjeff *(volatile uint32_t *)addr = b; 46219820Sjeff} 47219820Sjeff 48219820Sjeffstatic inline uint64_t 49219820Sjeff__raw_readq(const volatile void *addr) 50219820Sjeff{ 51219820Sjeff return *(const volatile uint64_t *)addr; 52219820Sjeff} 53219820Sjeff 54219820Sjeffstatic inline void 55219820Sjeff__raw_writeq(uint64_t b, volatile void *addr) 56219820Sjeff{ 57219820Sjeff *(volatile uint64_t *)addr = b; 58219820Sjeff} 59219820Sjeff 60219820Sjeff/* 61219820Sjeff * XXX This is all x86 specific. It should be bus space access. 62219820Sjeff */ 63219820Sjeff#define mmiowb() 64219820Sjeff 65219820Sjeff#undef writel 66219820Sjeffstatic inline void 67219820Sjeffwritel(uint32_t b, void *addr) 68219820Sjeff{ 69219820Sjeff *(volatile uint32_t *)addr = b; 70219820Sjeff} 71219820Sjeff 72219820Sjeff#undef writeq 73219820Sjeffstatic inline void 74219820Sjeffwriteq(uint64_t b, void *addr) 75219820Sjeff{ 76219820Sjeff *(volatile uint64_t *)addr = b; 77219820Sjeff} 78219820Sjeff 79219820Sjeff#undef writeb 80219820Sjeffstatic inline void 81219820Sjeffwriteb(uint8_t b, void *addr) 82219820Sjeff{ 83219820Sjeff *(volatile uint8_t *)addr = b; 84219820Sjeff} 85219820Sjeff 86219820Sjeff#undef writew 87219820Sjeffstatic inline void 88219820Sjeffwritew(uint16_t b, void *addr) 89219820Sjeff{ 90219820Sjeff *(volatile uint16_t *)addr = b; 91219820Sjeff} 92219820Sjeff 93282513Shselasky#undef ioread32be 94282513Shselaskystatic inline uint32_t 95282513Shselaskyioread32be(const volatile void *addr) 96282513Shselasky{ 97282513Shselasky return be32toh(*(const volatile uint32_t *)addr); 98282513Shselasky} 99282513Shselasky 100282513Shselasky#undef iowrite32be 101282513Shselaskystatic inline void 102282513Shselaskyiowrite32be(uint32_t v, volatile void *addr) 103282513Shselasky{ 104282513Shselasky *(volatile uint32_t *)addr = htobe32(v); 105282513Shselasky} 106282513Shselasky 107219820Sjeffvoid *_ioremap_attr(vm_paddr_t phys_addr, unsigned long size, int attr); 108219820Sjeff#define ioremap_nocache(addr, size) \ 109233547Sjhb _ioremap_attr((addr), (size), VM_MEMATTR_UNCACHEABLE) 110219820Sjeff#define ioremap_wc(addr, size) \ 111219820Sjeff _ioremap_attr((addr), (size), VM_MEMATTR_WRITE_COMBINING) 112219820Sjeff#define ioremap ioremap_nocache 113219820Sjeffvoid iounmap(void *addr); 114219820Sjeff 115219820Sjeff#define memset_io(a, b, c) memset((a), (b), (c)) 116219820Sjeff#define memcpy_fromio(a, b, c) memcpy((a), (b), (c)) 117219820Sjeff#define memcpy_toio(a, b, c) memcpy((a), (b), (c)) 118219820Sjeff 119219820Sjeffstatic inline void 120219820Sjeff__iowrite64_copy(void *to, void *from, size_t count) 121219820Sjeff{ 122219820Sjeff#ifdef __LP64__ 123219820Sjeff uint64_t *src; 124219820Sjeff uint64_t *dst; 125219820Sjeff int i; 126219820Sjeff 127219820Sjeff for (i = 0, src = from, dst = to; i < count; i++, src++, dst++) 128219820Sjeff __raw_writeq(*src, dst); 129219820Sjeff#else 130219820Sjeff uint32_t *src; 131219820Sjeff uint32_t *dst; 132219820Sjeff int i; 133219820Sjeff 134219820Sjeff count *= 2; 135219820Sjeff for (i = 0, src = from, dst = to; i < count; i++, src++, dst++) 136219820Sjeff __raw_writel(*src, dst); 137219820Sjeff#endif 138219820Sjeff} 139219820Sjeff 140219820Sjeff 141219820Sjeff#endif /* _LINUX_IO_H_ */ 142