summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rw-r--r--firmware/export/kernel.h14
-rw-r--r--firmware/kernel.c51
-rw-r--r--firmware/system.c43
-rw-r--r--firmware/target/arm/system-pp502x.c9
4 files changed, 18 insertions, 99 deletions
diff --git a/firmware/export/kernel.h b/firmware/export/kernel.h
index 982ecf2589..90a21630ed 100644
--- a/firmware/export/kernel.h
+++ b/firmware/export/kernel.h
@@ -159,15 +159,6 @@ struct mutex
159 unsigned char locked; /* locked semaphore */ 159 unsigned char locked; /* locked semaphore */
160}; 160};
161 161
162#if NUM_CORES > 1
163struct spinlock
164{
165 struct thread_entry *thread; /* lock owner */
166 int count; /* lock owner recursion count */
167 struct corelock cl; /* multiprocessor sync */
168};
169#endif
170
171#ifdef HAVE_SEMAPHORE_OBJECTS 162#ifdef HAVE_SEMAPHORE_OBJECTS
172struct semaphore 163struct semaphore
173{ 164{
@@ -284,11 +275,6 @@ extern void mutex_unlock(struct mutex *m);
284static inline void mutex_set_preempt(struct mutex *m, bool preempt) 275static inline void mutex_set_preempt(struct mutex *m, bool preempt)
285 { m->no_preempt = !preempt; } 276 { m->no_preempt = !preempt; }
286#endif 277#endif
287#if NUM_CORES > 1
288extern void spinlock_init(struct spinlock *l);
289extern void spinlock_lock(struct spinlock *l);
290extern void spinlock_unlock(struct spinlock *l);
291#endif
292#ifdef HAVE_SEMAPHORE_OBJECTS 278#ifdef HAVE_SEMAPHORE_OBJECTS
293extern void semaphore_init(struct semaphore *s, int max, int start); 279extern void semaphore_init(struct semaphore *s, int max, int start);
294extern void semaphore_wait(struct semaphore *s); 280extern void semaphore_wait(struct semaphore *s);
diff --git a/firmware/kernel.c b/firmware/kernel.c
index ae8f354261..0c2b87b139 100644
--- a/firmware/kernel.c
+++ b/firmware/kernel.c
@@ -962,57 +962,6 @@ void mutex_unlock(struct mutex *m)
962} 962}
963 963
964/**************************************************************************** 964/****************************************************************************
965 * Simpl-er mutex functions ;)
966 ****************************************************************************/
967#if NUM_CORES > 1
968void spinlock_init(struct spinlock *l)
969{
970 corelock_init(&l->cl);
971 l->thread = NULL;
972 l->count = 0;
973}
974
975void spinlock_lock(struct spinlock *l)
976{
977 const unsigned int core = CURRENT_CORE;
978 struct thread_entry *current = cores[core].running;
979
980 if(l->thread == current)
981 {
982 /* current core already owns it */
983 l->count++;
984 return;
985 }
986
987 /* lock against other processor cores */
988 corelock_lock(&l->cl);
989
990 /* take ownership */
991 l->thread = current;
992}
993
994void spinlock_unlock(struct spinlock *l)
995{
996 /* unlocker not being the owner is an unlocking violation */
997 KERNEL_ASSERT(l->thread == cores[CURRENT_CORE].running,
998 "spinlock_unlock->wrong thread\n");
999
1000 if(l->count > 0)
1001 {
1002 /* this core still owns lock */
1003 l->count--;
1004 return;
1005 }
1006
1007 /* clear owner */
1008 l->thread = NULL;
1009
1010 /* release lock */
1011 corelock_unlock(&l->cl);
1012}
1013#endif /* NUM_CORES > 1 */
1014
1015/****************************************************************************
1016 * Simple semaphore functions ;) 965 * Simple semaphore functions ;)
1017 ****************************************************************************/ 966 ****************************************************************************/
1018#ifdef HAVE_SEMAPHORE_OBJECTS 967#ifdef HAVE_SEMAPHORE_OBJECTS
diff --git a/firmware/system.c b/firmware/system.c
index befc785823..52be7a1a71 100644
--- a/firmware/system.c
+++ b/firmware/system.c
@@ -33,10 +33,10 @@ long cpu_frequency SHAREDBSS_ATTR = CPU_FREQ;
33static int boost_counter SHAREDBSS_ATTR = 0; 33static int boost_counter SHAREDBSS_ATTR = 0;
34static bool cpu_idle SHAREDBSS_ATTR = false; 34static bool cpu_idle SHAREDBSS_ATTR = false;
35#if NUM_CORES > 1 35#if NUM_CORES > 1
36struct spinlock boostctrl_spin SHAREDBSS_ATTR; 36static struct corelock boostctrl_cl SHAREDBSS_ATTR;
37void cpu_boost_init(void) 37void cpu_boost_init(void)
38{ 38{
39 spinlock_init(&boostctrl_spin); 39 corelock_init(&boostctrl_cl);
40} 40}
41#endif 41#endif
42 42
@@ -57,9 +57,7 @@ int cpu_boost_log_getcount(void)
57char * cpu_boost_log_getlog_first(void) 57char * cpu_boost_log_getlog_first(void)
58{ 58{
59 char *first; 59 char *first;
60#if NUM_CORES > 1 60 corelock_lock(&boostctrl_cl);
61 spinlock_lock(&boostctrl_spin);
62#endif
63 61
64 first = NULL; 62 first = NULL;
65 63
@@ -69,10 +67,7 @@ char * cpu_boost_log_getlog_first(void)
69 first = cpu_boost_calls[cpu_boost_first]; 67 first = cpu_boost_calls[cpu_boost_first];
70 } 68 }
71 69
72#if NUM_CORES > 1 70 corelock_unlock(&boostctrl_cl);
73 spinlock_unlock(&boostctrl_spin);
74#endif
75
76 return first; 71 return first;
77} 72}
78 73
@@ -81,9 +76,7 @@ char * cpu_boost_log_getlog_next(void)
81 int message; 76 int message;
82 char *next; 77 char *next;
83 78
84#if NUM_CORES > 1 79 corelock_lock(&boostctrl_cl);
85 spinlock_lock(&boostctrl_spin);
86#endif
87 80
88 message = (cpu_boost_track_message+cpu_boost_first)%MAX_BOOST_LOG; 81 message = (cpu_boost_track_message+cpu_boost_first)%MAX_BOOST_LOG;
89 next = NULL; 82 next = NULL;
@@ -94,18 +87,13 @@ char * cpu_boost_log_getlog_next(void)
94 next = cpu_boost_calls[message]; 87 next = cpu_boost_calls[message];
95 } 88 }
96 89
97#if NUM_CORES > 1 90 corelock_unlock(&boostctrl_cl);
98 spinlock_unlock(&boostctrl_spin);
99#endif
100
101 return next; 91 return next;
102} 92}
103 93
104void cpu_boost_(bool on_off, char* location, int line) 94void cpu_boost_(bool on_off, char* location, int line)
105{ 95{
106#if NUM_CORES > 1 96 corelock_lock(&boostctrl_cl);
107 spinlock_lock(&boostctrl_spin);
108#endif
109 97
110 if (cpu_boost_calls_count == MAX_BOOST_LOG) 98 if (cpu_boost_calls_count == MAX_BOOST_LOG)
111 { 99 {
@@ -124,10 +112,7 @@ void cpu_boost_(bool on_off, char* location, int line)
124#else 112#else
125void cpu_boost(bool on_off) 113void cpu_boost(bool on_off)
126{ 114{
127#if NUM_CORES > 1 115 corelock_lock(&boostctrl_cl);
128 spinlock_lock(&boostctrl_spin);
129#endif
130
131#endif /* CPU_BOOST_LOGGING */ 116#endif /* CPU_BOOST_LOGGING */
132 if(on_off) 117 if(on_off)
133 { 118 {
@@ -153,16 +138,12 @@ void cpu_boost(bool on_off)
153 } 138 }
154 } 139 }
155 140
156#if NUM_CORES > 1 141 corelock_unlock(&boostctrl_cl);
157 spinlock_unlock(&boostctrl_spin);
158#endif
159} 142}
160 143
161void cpu_idle_mode(bool on_off) 144void cpu_idle_mode(bool on_off)
162{ 145{
163#if NUM_CORES > 1 146 corelock_lock(&boostctrl_cl);
164 spinlock_lock(&boostctrl_spin);
165#endif
166 147
167 cpu_idle = on_off; 148 cpu_idle = on_off;
168 149
@@ -176,9 +157,7 @@ void cpu_idle_mode(bool on_off)
176 set_cpu_frequency(CPUFREQ_NORMAL); 157 set_cpu_frequency(CPUFREQ_NORMAL);
177 } 158 }
178 159
179#if NUM_CORES > 1 160 corelock_unlock(&boostctrl_cl);
180 spinlock_unlock(&boostctrl_spin);
181#endif
182} 161}
183#endif /* HAVE_ADJUSTABLE_CPU_FREQ */ 162#endif /* HAVE_ADJUSTABLE_CPU_FREQ */
184 163
diff --git a/firmware/target/arm/system-pp502x.c b/firmware/target/arm/system-pp502x.c
index d4c07f10eb..b1cef7152a 100644
--- a/firmware/target/arm/system-pp502x.c
+++ b/firmware/target/arm/system-pp502x.c
@@ -35,6 +35,10 @@ extern void SERIAL0(void);
35extern void ipod_mini_button_int(void); /* iPod Mini 1st gen only */ 35extern void ipod_mini_button_int(void); /* iPod Mini 1st gen only */
36extern void ipod_4g_button_int(void); /* iPod 4th gen and higher only */ 36extern void ipod_4g_button_int(void); /* iPod 4th gen and higher only */
37 37
38#if defined(HAVE_ADJUSTABLE_CPU_FREQ) && (NUM_CORES > 1)
39static struct corelock cpufreq_cl SHAREDBSS_ATTR;
40#endif
41
38void __attribute__((interrupt("IRQ"))) irq_handler(void) 42void __attribute__((interrupt("IRQ"))) irq_handler(void)
39{ 43{
40 if(CURRENT_CORE == CPU) 44 if(CURRENT_CORE == CPU)
@@ -236,7 +240,7 @@ static void pp_set_cpu_frequency(long frequency)
236#endif 240#endif
237{ 241{
238#if defined(HAVE_ADJUSTABLE_CPU_FREQ) && (NUM_CORES > 1) 242#if defined(HAVE_ADJUSTABLE_CPU_FREQ) && (NUM_CORES > 1)
239 spinlock_lock(&boostctrl_spin); 243 corelock_lock(&cpufreq_cl);
240#endif 244#endif
241 245
242 switch (frequency) 246 switch (frequency)
@@ -347,7 +351,7 @@ static void pp_set_cpu_frequency(long frequency)
347 } 351 }
348 352
349#if defined(HAVE_ADJUSTABLE_CPU_FREQ) && (NUM_CORES > 1) 353#if defined(HAVE_ADJUSTABLE_CPU_FREQ) && (NUM_CORES > 1)
350 spinlock_unlock(&boostctrl_spin); 354 corelock_unlock(&cpufreq_cl);
351#endif 355#endif
352} 356}
353#endif /* !BOOTLOADER || SANSA_E200 || SANSA_C200 */ 357#endif /* !BOOTLOADER || SANSA_E200 || SANSA_C200 */
@@ -475,6 +479,7 @@ void system_init(void)
475 479
476#ifdef HAVE_ADJUSTABLE_CPU_FREQ 480#ifdef HAVE_ADJUSTABLE_CPU_FREQ
477#if NUM_CORES > 1 481#if NUM_CORES > 1
482 corelock_init(&cpufreq_cl);
478 cpu_boost_init(); 483 cpu_boost_init();
479#endif 484#endif
480#else 485#else