kernel: Add missing smp memory barrier calls. Set max cpu to 1

* Set max cpu to 1 for PPC until atomic functions are finished
* We have atomic functions inline in the kernel and assembly
  code in libroot post-scheduler merge... isn't that a lot of
  duplication?
This commit is contained in:
Alexander von Gluck IV
2014-01-19 19:33:21 -06:00
parent cf87df8ba3
commit c9e66bfc9b
3 changed files with 114 additions and 1 deletions
+2
View File
@@ -15,6 +15,8 @@
# include <arch/x86/64/atomic.h>
#elif __INTEL__
# include <arch/x86/32/atomic.h>
#elif __POWERPC__
# include <arch/ppc/arch_atomic.h>
#endif
@@ -0,0 +1,110 @@
/*
* Copyright 2014, Paweł Dziepak, [email protected].
* Distributed under the terms of the MIT License.
*
* Authors:
* Alexander von Gluck IV <[email protected]>
*/
#ifndef _KERNEL_ARCH_PPC_ATOMIC_H
#define _KERNEL_ARCH_PPC_ATOMIC_H
static inline void
memory_read_barrier_inline(void)
{
#ifdef __powerpc64__
asm volatile("lwsync" : : : "memory");
#else
asm volatile("sync" : : : "memory");
#endif
}
static inline void
memory_write_barrier_inline(void)
{
#ifdef __powerpc64__
asm volatile("lwsync" : : : "memory");
#else
asm volatile("eieio" : : : "memory");
#endif
}
static inline void
memory_full_barrier_inline(void)
{
asm volatile("sync" : : : "memory");
}
#define memory_read_barrier memory_read_barrier_inline
#define memory_write_barrier memory_write_barrier_inline
#define memory_full_barrier memory_full_barrier_inline
static inline void
atomic_set_inline(int32* value, int32 newValue)
{
memory_write_barrier();
*(volatile int32*)value = newValue;
}
static inline int32
atomic_get_and_set_inline(int32* value, int32 newValue)
{
// BIG TODO: PowerPC Atomic get and set
// asm volatile("xchgl %0, (%1)"
// : "+r" (newValue)
// : "r" (value)
// : "memory");
return newValue;
}
static inline int32
atomic_test_and_set_inline(int32* value, int32 newValue, int32 testAgainst)
{
// BIG TODO: PowerPC Atomic test and set inline
// asm volatile("lock; cmpxchgl %2, (%3)"
// : "=a" (newValue)
// : "0" (testAgainst), "r" (newValue), "r" (value)
// : "memory");
return newValue;
}
static inline int32
atomic_add_inline(int32* value, int32 newValue)
{
// BIG TODO: PowerPC Atomic add inline
// asm volatile("lock; xaddl %0, (%1)"
// : "+r" (newValue)
// : "r" (value)
// : "memory");
return newValue;
}
static inline int32
atomic_get_inline(int32* value)
{
int32 newValue = *(volatile int32*)value;
memory_read_barrier();
return newValue;
}
#define atomic_set atomic_set_inline
#define atomic_get_and_set atomic_get_and_set_inline
#ifndef atomic_test_and_set
# define atomic_test_and_set atomic_test_and_set_inline
#endif
#ifndef atomic_add
# define atomic_add atomic_add_inline
#endif
#define atomic_get atomic_get_inline
#endif // _KERNEL_ARCH_PPC_ATOMIC_H
@@ -10,7 +10,8 @@
# error This file is included from <boot/kernel_args.h> only
#endif
#define SMP_MAX_CPUS 16
#define SMP_MAX_CPUS 1
// TODO: Until inline kernel atomic code for ppc is fixed
#define MAX_PHYSICAL_MEMORY_RANGE 4
#define MAX_PHYSICAL_ALLOCATED_RANGE 8