| Chris Metcalf | 18aecc2 | 2011-05-04 14:38:26 -0400 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright 2011 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 |  * Atomically access user memory, but use MMU to avoid propagating | 
 | 15 |  * kernel exceptions. | 
 | 16 |  */ | 
 | 17 |  | 
 | 18 | #include <linux/linkage.h> | 
 | 19 | #include <asm/errno.h> | 
 | 20 | #include <asm/futex.h> | 
 | 21 | #include <asm/page.h> | 
 | 22 | #include <asm/processor.h> | 
 | 23 |  | 
 | 24 | /* | 
 | 25 |  * Provide a set of atomic memory operations supporting <asm/futex.h>. | 
 | 26 |  * | 
 | 27 |  * r0: user address to manipulate | 
 | 28 |  * r1: new value to write, or for cmpxchg, old value to compare against | 
 | 29 |  * r2: (cmpxchg only) new value to write | 
 | 30 |  * | 
 | 31 |  * Return __get_user struct, r0 with value, r1 with error. | 
 | 32 |  */ | 
 | 33 | #define FUTEX_OP(name, ...) \ | 
 | 34 | STD_ENTRY(futex_##name)			\ | 
 | 35 | 	__VA_ARGS__;			\ | 
 | 36 | 	{				\ | 
 | 37 | 	 move   r1, zero;		\ | 
 | 38 | 	 jrp    lr			\ | 
 | 39 | 	};				\ | 
 | 40 | 	STD_ENDPROC(futex_##name);	\ | 
 | 41 | 	.pushsection __ex_table,"a";	\ | 
 | 42 | 	.quad 1b, get_user_fault;	\ | 
 | 43 | 	.popsection | 
 | 44 |  | 
 | 45 | 	.pushsection .fixup,"ax" | 
 | 46 | get_user_fault: | 
 | 47 | 	{ movei r1, -EFAULT; jrp lr } | 
 | 48 | 	ENDPROC(get_user_fault) | 
 | 49 | 	.popsection | 
 | 50 |  | 
 | 51 | FUTEX_OP(cmpxchg, mtspr CMPEXCH_VALUE, r1; 1: cmpexch4 r0, r0, r2) | 
 | 52 | FUTEX_OP(set, 1: exch4 r0, r0, r1) | 
 | 53 | FUTEX_OP(add, 1: fetchadd4 r0, r0, r1) | 
 | 54 | FUTEX_OP(or, 1: fetchor4 r0, r0, r1) | 
 | 55 | FUTEX_OP(andn, nor r1, r1, zero; 1: fetchand4 r0, r0, r1) |