Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2010 Tilera Corporation. All Rights Reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation, version 2. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, but |
| 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or |
| 11 | * NON INFRINGEMENT. See the GNU General Public License for |
| 12 | * more details. |
| 13 | */ |
| 14 | |
| 15 | #include <linux/linkage.h> |
| 16 | #include <asm/errno.h> |
| 17 | #include <asm/cache.h> |
| 18 | #include <arch/chip.h> |
| 19 | |
| 20 | /* Access user memory, but use MMU to avoid propagating kernel exceptions. */ |
| 21 | |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 22 | /* |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 23 | * clear_user_asm takes the user target address in r0 and the |
| 24 | * number of bytes to zero in r1. |
| 25 | * It returns the number of uncopiable bytes (hopefully zero) in r0. |
| 26 | * Note that we don't use a separate .fixup section here since we fall |
| 27 | * through into the "fixup" code as the last straight-line bundle anyway. |
| 28 | */ |
| 29 | STD_ENTRY(clear_user_asm) |
| 30 | { bz r1, 2f; or r2, r0, r1 } |
| 31 | andi r2, r2, 3 |
| 32 | bzt r2, .Lclear_aligned_user_asm |
| 33 | 1: { sb r0, zero; addi r0, r0, 1; addi r1, r1, -1 } |
| 34 | bnzt r1, 1b |
| 35 | 2: { move r0, r1; jrp lr } |
| 36 | .pushsection __ex_table,"a" |
Chris Metcalf | d4d9eab | 2013-08-09 15:38:43 -0400 | [diff] [blame] | 37 | .align 4 |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 38 | .word 1b, 2b |
| 39 | .popsection |
| 40 | |
| 41 | .Lclear_aligned_user_asm: |
| 42 | 1: { sw r0, zero; addi r0, r0, 4; addi r1, r1, -4 } |
| 43 | bnzt r1, 1b |
| 44 | 2: { move r0, r1; jrp lr } |
| 45 | STD_ENDPROC(clear_user_asm) |
| 46 | .pushsection __ex_table,"a" |
Chris Metcalf | d4d9eab | 2013-08-09 15:38:43 -0400 | [diff] [blame] | 47 | .align 4 |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 48 | .word 1b, 2b |
| 49 | .popsection |
| 50 | |
| 51 | /* |
| 52 | * flush_user_asm takes the user target address in r0 and the |
| 53 | * number of bytes to flush in r1. |
| 54 | * It returns the number of unflushable bytes (hopefully zero) in r0. |
| 55 | */ |
| 56 | STD_ENTRY(flush_user_asm) |
| 57 | bz r1, 2f |
| 58 | { movei r2, L2_CACHE_BYTES; add r1, r0, r1 } |
| 59 | { sub r2, zero, r2; addi r1, r1, L2_CACHE_BYTES-1 } |
| 60 | { and r0, r0, r2; and r1, r1, r2 } |
| 61 | { sub r1, r1, r0 } |
| 62 | 1: { flush r0; addi r1, r1, -CHIP_FLUSH_STRIDE() } |
| 63 | { addi r0, r0, CHIP_FLUSH_STRIDE(); bnzt r1, 1b } |
| 64 | 2: { move r0, r1; jrp lr } |
| 65 | STD_ENDPROC(flush_user_asm) |
| 66 | .pushsection __ex_table,"a" |
Chris Metcalf | d4d9eab | 2013-08-09 15:38:43 -0400 | [diff] [blame] | 67 | .align 4 |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 68 | .word 1b, 2b |
| 69 | .popsection |
| 70 | |
| 71 | /* |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 72 | * finv_user_asm takes the user target address in r0 and the |
| 73 | * number of bytes to flush-invalidate in r1. |
| 74 | * It returns the number of not finv'able bytes (hopefully zero) in r0. |
| 75 | */ |
| 76 | STD_ENTRY(finv_user_asm) |
| 77 | bz r1, 2f |
| 78 | { movei r2, L2_CACHE_BYTES; add r1, r0, r1 } |
| 79 | { sub r2, zero, r2; addi r1, r1, L2_CACHE_BYTES-1 } |
| 80 | { and r0, r0, r2; and r1, r1, r2 } |
| 81 | { sub r1, r1, r0 } |
| 82 | 1: { finv r0; addi r1, r1, -CHIP_FINV_STRIDE() } |
| 83 | { addi r0, r0, CHIP_FINV_STRIDE(); bnzt r1, 1b } |
| 84 | 2: { move r0, r1; jrp lr } |
| 85 | STD_ENDPROC(finv_user_asm) |
| 86 | .pushsection __ex_table,"a" |
Chris Metcalf | d4d9eab | 2013-08-09 15:38:43 -0400 | [diff] [blame] | 87 | .align 4 |
Chris Metcalf | 867e359 | 2010-05-28 23:09:12 -0400 | [diff] [blame] | 88 | .word 1b, 2b |
| 89 | .popsection |