Catalin Marinas | fc47897 | 2012-03-05 11:49:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Based on arch/arm/kernel/io.c |
| 3 | * |
| 4 | * Copyright (C) 2012 ARM Ltd. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | #include <linux/export.h> |
| 20 | #include <linux/types.h> |
| 21 | #include <linux/io.h> |
| 22 | |
| 23 | /* |
| 24 | * Copy data from IO memory space to "real" memory space. |
| 25 | */ |
| 26 | void __memcpy_fromio(void *to, const volatile void __iomem *from, size_t count) |
| 27 | { |
Mark Salyzyn | a93e312 | 2017-10-24 07:47:14 -0700 | [diff] [blame] | 28 | while (count && !IS_ALIGNED((unsigned long)from, 8)) { |
Joonwoo Park | 70ddb63 | 2014-10-21 01:59:03 +0100 | [diff] [blame] | 29 | *(u8 *)to = __raw_readb(from); |
Catalin Marinas | fc47897 | 2012-03-05 11:49:29 +0000 | [diff] [blame] | 30 | from++; |
Joonwoo Park | 70ddb63 | 2014-10-21 01:59:03 +0100 | [diff] [blame] | 31 | to++; |
| 32 | count--; |
| 33 | } |
| 34 | |
| 35 | while (count >= 8) { |
| 36 | *(u64 *)to = __raw_readq(from); |
| 37 | from += 8; |
| 38 | to += 8; |
| 39 | count -= 8; |
| 40 | } |
| 41 | |
| 42 | while (count) { |
| 43 | *(u8 *)to = __raw_readb(from); |
| 44 | from++; |
| 45 | to++; |
| 46 | count--; |
Catalin Marinas | fc47897 | 2012-03-05 11:49:29 +0000 | [diff] [blame] | 47 | } |
| 48 | } |
| 49 | EXPORT_SYMBOL(__memcpy_fromio); |
| 50 | |
| 51 | /* |
| 52 | * Copy data from "real" memory space to IO memory space. |
| 53 | */ |
| 54 | void __memcpy_toio(volatile void __iomem *to, const void *from, size_t count) |
| 55 | { |
Mark Salyzyn | a93e312 | 2017-10-24 07:47:14 -0700 | [diff] [blame] | 56 | while (count && !IS_ALIGNED((unsigned long)to, 8)) { |
| 57 | __raw_writeb(*(u8 *)from, to); |
Joonwoo Park | 70ddb63 | 2014-10-21 01:59:03 +0100 | [diff] [blame] | 58 | from++; |
Catalin Marinas | fc47897 | 2012-03-05 11:49:29 +0000 | [diff] [blame] | 59 | to++; |
Joonwoo Park | 70ddb63 | 2014-10-21 01:59:03 +0100 | [diff] [blame] | 60 | count--; |
| 61 | } |
| 62 | |
| 63 | while (count >= 8) { |
Mark Salyzyn | a93e312 | 2017-10-24 07:47:14 -0700 | [diff] [blame] | 64 | __raw_writeq(*(u64 *)from, to); |
Joonwoo Park | 70ddb63 | 2014-10-21 01:59:03 +0100 | [diff] [blame] | 65 | from += 8; |
| 66 | to += 8; |
| 67 | count -= 8; |
| 68 | } |
| 69 | |
| 70 | while (count) { |
Mark Salyzyn | a93e312 | 2017-10-24 07:47:14 -0700 | [diff] [blame] | 71 | __raw_writeb(*(u8 *)from, to); |
Joonwoo Park | 70ddb63 | 2014-10-21 01:59:03 +0100 | [diff] [blame] | 72 | from++; |
| 73 | to++; |
| 74 | count--; |
Catalin Marinas | fc47897 | 2012-03-05 11:49:29 +0000 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | EXPORT_SYMBOL(__memcpy_toio); |
| 78 | |
| 79 | /* |
| 80 | * "memset" on IO memory space. |
| 81 | */ |
| 82 | void __memset_io(volatile void __iomem *dst, int c, size_t count) |
| 83 | { |
Joonwoo Park | 70ddb63 | 2014-10-21 01:59:03 +0100 | [diff] [blame] | 84 | u64 qc = (u8)c; |
| 85 | |
| 86 | qc |= qc << 8; |
| 87 | qc |= qc << 16; |
| 88 | qc |= qc << 32; |
| 89 | |
| 90 | while (count && !IS_ALIGNED((unsigned long)dst, 8)) { |
| 91 | __raw_writeb(c, dst); |
Catalin Marinas | fc47897 | 2012-03-05 11:49:29 +0000 | [diff] [blame] | 92 | dst++; |
Joonwoo Park | 70ddb63 | 2014-10-21 01:59:03 +0100 | [diff] [blame] | 93 | count--; |
| 94 | } |
| 95 | |
| 96 | while (count >= 8) { |
| 97 | __raw_writeq(qc, dst); |
| 98 | dst += 8; |
| 99 | count -= 8; |
| 100 | } |
| 101 | |
| 102 | while (count) { |
| 103 | __raw_writeb(c, dst); |
| 104 | dst++; |
| 105 | count--; |
Catalin Marinas | fc47897 | 2012-03-05 11:49:29 +0000 | [diff] [blame] | 106 | } |
| 107 | } |
| 108 | EXPORT_SYMBOL(__memset_io); |