15629675aSAdrien Destugues/*
25629675aSAdrien Destugues * Copyright 2014, Pawe�� Dziepak, pdziepak@quarnos.org.
35629675aSAdrien Destugues * Distributed under the terms of the MIT License.
45629675aSAdrien Destugues *
55629675aSAdrien Destugues * Authors:
65629675aSAdrien Destugues *		Alexander von Gluck IV <kallisti5@unixzen.com>
75629675aSAdrien Destugues */
85629675aSAdrien Destugues#ifndef _KERNEL_ARCH_SPARC_ATOMIC_H
95629675aSAdrien Destugues#define _KERNEL_ARCH_SPARC_ATOMIC_H
105629675aSAdrien Destugues
115629675aSAdrien Destugues
125629675aSAdrien Destuguesstatic inline void
135629675aSAdrien Destuguesmemory_read_barrier_inline(void)
145629675aSAdrien Destugues{
155629675aSAdrien Destugues	// TODO
165629675aSAdrien Destugues}
175629675aSAdrien Destugues
185629675aSAdrien Destugues
195629675aSAdrien Destuguesstatic inline void
205629675aSAdrien Destuguesmemory_write_barrier_inline(void)
215629675aSAdrien Destugues{
225629675aSAdrien Destugues	// TODO
235629675aSAdrien Destugues}
245629675aSAdrien Destugues
255629675aSAdrien Destugues
265629675aSAdrien Destuguesstatic inline void
275629675aSAdrien Destuguesmemory_full_barrier_inline(void)
285629675aSAdrien Destugues{
295629675aSAdrien Destugues	// TODO
305629675aSAdrien Destugues}
315629675aSAdrien Destugues
325629675aSAdrien Destugues
335629675aSAdrien Destugues#define memory_read_barrier		memory_read_barrier_inline
345629675aSAdrien Destugues#define memory_write_barrier	memory_write_barrier_inline
355629675aSAdrien Destugues#define memory_full_barrier		memory_full_barrier_inline
365629675aSAdrien Destugues
375629675aSAdrien Destugues
385629675aSAdrien Destuguesstatic inline void
395629675aSAdrien Destuguesatomic_set_inline(int32* value, int32 newValue)
405629675aSAdrien Destugues{
415629675aSAdrien Destugues	memory_write_barrier();
425629675aSAdrien Destugues	*(volatile int32*)value = newValue;
435629675aSAdrien Destugues}
445629675aSAdrien Destugues
455629675aSAdrien Destugues
465629675aSAdrien Destuguesstatic inline int32
475629675aSAdrien Destuguesatomic_get_and_set_inline(int32* value, int32 newValue)
485629675aSAdrien Destugues{
495629675aSAdrien Destugues	// BIG TODO: PowerPC Atomic get and set
505629675aSAdrien Destugues//	asm volatile("xchgl %0, (%1)"
515629675aSAdrien Destugues//		: "+r" (newValue)
525629675aSAdrien Destugues//		: "r" (value)
535629675aSAdrien Destugues//		: "memory");
545629675aSAdrien Destugues	return newValue;
555629675aSAdrien Destugues}
565629675aSAdrien Destugues
575629675aSAdrien Destugues
585629675aSAdrien Destuguesstatic inline int32
595629675aSAdrien Destuguesatomic_test_and_set_inline(int32* value, int32 newValue, int32 testAgainst)
605629675aSAdrien Destugues{
615629675aSAdrien Destugues	// BIG TODO: PowerPC Atomic test and set inline
625629675aSAdrien Destugues//	asm volatile("lock; cmpxchgl %2, (%3)"
635629675aSAdrien Destugues//		: "=a" (newValue)
645629675aSAdrien Destugues//		: "0" (testAgainst), "r" (newValue), "r" (value)
655629675aSAdrien Destugues//		: "memory");
665629675aSAdrien Destugues	return newValue;
675629675aSAdrien Destugues}
685629675aSAdrien Destugues
695629675aSAdrien Destugues
705629675aSAdrien Destuguesstatic inline int32
715629675aSAdrien Destuguesatomic_add_inline(int32* value, int32 newValue)
725629675aSAdrien Destugues{
735629675aSAdrien Destugues	// BIG TODO: PowerPC Atomic add inline
745629675aSAdrien Destugues//	asm volatile("lock; xaddl %0, (%1)"
755629675aSAdrien Destugues//		: "+r" (newValue)
765629675aSAdrien Destugues//		: "r" (value)
775629675aSAdrien Destugues//		: "memory");
785629675aSAdrien Destugues	return newValue;
795629675aSAdrien Destugues}
805629675aSAdrien Destugues
815629675aSAdrien Destugues
825629675aSAdrien Destuguesstatic inline int32
835629675aSAdrien Destuguesatomic_get_inline(int32* value)
845629675aSAdrien Destugues{
855629675aSAdrien Destugues	int32 newValue = *(volatile int32*)value;
865629675aSAdrien Destugues	memory_read_barrier();
875629675aSAdrien Destugues	return newValue;
885629675aSAdrien Destugues}
895629675aSAdrien Destugues
905629675aSAdrien Destugues
915629675aSAdrien Destugues#define atomic_set				atomic_set_inline
925629675aSAdrien Destugues#define atomic_get_and_set		atomic_get_and_set_inline
935629675aSAdrien Destugues#ifndef atomic_test_and_set
945629675aSAdrien Destugues#	define atomic_test_and_set	atomic_test_and_set_inline
955629675aSAdrien Destugues#endif
965629675aSAdrien Destugues#ifndef atomic_add
975629675aSAdrien Destugues#	define atomic_add			atomic_add_inline
985629675aSAdrien Destugues#endif
995629675aSAdrien Destugues#define atomic_get				atomic_get_inline
1005629675aSAdrien Destugues
1015629675aSAdrien Destugues
1025629675aSAdrien Destugues#endif	// _KERNEL_ARCH_PPC_ATOMIC_H
1035629675aSAdrien Destugues
104