Skip to content

Commit 8f65873

Browse files
Graf YangBryan Wu
authored andcommitted
Blackfin arch: SMP supporting patchset: Blackfin kernel and memory management code
Blackfin dual core BF561 processor can support SMP like features. https://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:smp-like In this patch, we provide SMP extend to Blackfin kernel and memory management code Singed-off-by: Graf Yang <graf.yang@analog.com> Signed-off-by: Mike Frysinger <vapier.adi@gmail.com> Signed-off-by: Bryan Wu <cooloney@kernel.org>
1 parent b8a9898 commit 8f65873

14 files changed

Lines changed: 580 additions & 309 deletions

File tree

‎arch/blackfin/kernel/asm-offsets.c‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ int main(void)
5656
/* offsets into the thread struct */
5757
DEFINE(THREAD_KSP, offsetof(struct thread_struct, ksp));
5858
DEFINE(THREAD_USP, offsetof(struct thread_struct, usp));
59+
DEFINE(THREAD_SR, offsetof(struct thread_struct, seqstat));
60+
DEFINE(PT_SR, offsetof(struct thread_struct, seqstat));
61+
DEFINE(THREAD_ESP0, offsetof(struct thread_struct, esp0));
5962
DEFINE(THREAD_PC, offsetof(struct thread_struct, pc));
6063
DEFINE(KERNEL_STACK_SIZE, THREAD_SIZE);
6164

@@ -128,5 +131,31 @@ int main(void)
128131
DEFINE(SIGSEGV, SIGSEGV);
129132
DEFINE(SIGTRAP, SIGTRAP);
130133

134+
/* PDA management (in L1 scratchpad) */
135+
DEFINE(PDA_SYSCFG, offsetof(struct blackfin_pda, syscfg));
136+
#ifdef CONFIG_SMP
137+
DEFINE(PDA_IRQFLAGS, offsetof(struct blackfin_pda, imask));
138+
#endif
139+
DEFINE(PDA_IPDT, offsetof(struct blackfin_pda, ipdt));
140+
DEFINE(PDA_IPDT_SWAPCOUNT, offsetof(struct blackfin_pda, ipdt_swapcount));
141+
DEFINE(PDA_DPDT, offsetof(struct blackfin_pda, dpdt));
142+
DEFINE(PDA_DPDT_SWAPCOUNT, offsetof(struct blackfin_pda, dpdt_swapcount));
143+
DEFINE(PDA_EXIPTR, offsetof(struct blackfin_pda, ex_iptr));
144+
DEFINE(PDA_EXOPTR, offsetof(struct blackfin_pda, ex_optr));
145+
DEFINE(PDA_EXBUF, offsetof(struct blackfin_pda, ex_buf));
146+
DEFINE(PDA_EXIMASK, offsetof(struct blackfin_pda, ex_imask));
147+
DEFINE(PDA_EXSTACK, offsetof(struct blackfin_pda, ex_stack));
148+
#ifdef ANOMALY_05000261
149+
DEFINE(PDA_LFRETX, offsetof(struct blackfin_pda, last_cplb_fault_retx));
150+
#endif
151+
DEFINE(PDA_DCPLB, offsetof(struct blackfin_pda, dcplb_fault_addr));
152+
DEFINE(PDA_ICPLB, offsetof(struct blackfin_pda, icplb_fault_addr));
153+
DEFINE(PDA_RETX, offsetof(struct blackfin_pda, retx));
154+
DEFINE(PDA_SEQSTAT, offsetof(struct blackfin_pda, seqstat));
155+
#ifdef CONFIG_SMP
156+
/* Inter-core lock (in L2 SRAM) */
157+
DEFINE(SIZEOF_CORELOCK, sizeof(struct corelock_slot));
158+
#endif
159+
131160
return 0;
132161
}

‎arch/blackfin/kernel/bfin_ksyms.c‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,37 @@ EXPORT_SYMBOL(insw_8);
6868
EXPORT_SYMBOL(outsl);
6969
EXPORT_SYMBOL(insl);
7070
EXPORT_SYMBOL(insl_16);
71+
72+
#ifdef CONFIG_SMP
73+
EXPORT_SYMBOL(__raw_atomic_update_asm);
74+
EXPORT_SYMBOL(__raw_atomic_clear_asm);
75+
EXPORT_SYMBOL(__raw_atomic_set_asm);
76+
EXPORT_SYMBOL(__raw_atomic_xor_asm);
77+
EXPORT_SYMBOL(__raw_atomic_test_asm);
78+
EXPORT_SYMBOL(__raw_xchg_1_asm);
79+
EXPORT_SYMBOL(__raw_xchg_2_asm);
80+
EXPORT_SYMBOL(__raw_xchg_4_asm);
81+
EXPORT_SYMBOL(__raw_cmpxchg_1_asm);
82+
EXPORT_SYMBOL(__raw_cmpxchg_2_asm);
83+
EXPORT_SYMBOL(__raw_cmpxchg_4_asm);
84+
EXPORT_SYMBOL(__raw_spin_is_locked_asm);
85+
EXPORT_SYMBOL(__raw_spin_lock_asm);
86+
EXPORT_SYMBOL(__raw_spin_trylock_asm);
87+
EXPORT_SYMBOL(__raw_spin_unlock_asm);
88+
EXPORT_SYMBOL(__raw_read_lock_asm);
89+
EXPORT_SYMBOL(__raw_read_trylock_asm);
90+
EXPORT_SYMBOL(__raw_read_unlock_asm);
91+
EXPORT_SYMBOL(__raw_write_lock_asm);
92+
EXPORT_SYMBOL(__raw_write_trylock_asm);
93+
EXPORT_SYMBOL(__raw_write_unlock_asm);
94+
EXPORT_SYMBOL(__raw_bit_set_asm);
95+
EXPORT_SYMBOL(__raw_bit_clear_asm);
96+
EXPORT_SYMBOL(__raw_bit_toggle_asm);
97+
EXPORT_SYMBOL(__raw_bit_test_asm);
98+
EXPORT_SYMBOL(__raw_bit_test_set_asm);
99+
EXPORT_SYMBOL(__raw_bit_test_clear_asm);
100+
EXPORT_SYMBOL(__raw_bit_test_toggle_asm);
101+
EXPORT_SYMBOL(__raw_uncached_fetch_asm);
102+
EXPORT_SYMBOL(__raw_smp_mark_barrier_asm);
103+
EXPORT_SYMBOL(__raw_smp_check_barrier_asm);
104+
#endif

‎arch/blackfin/kernel/entry.S‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <linux/linkage.h>
3131
#include <asm/thread_info.h>
3232
#include <asm/errno.h>
33+
#include <asm/blackfin.h>
3334
#include <asm/asm-offsets.h>
3435

3536
#include <asm/context.S>

‎arch/blackfin/kernel/irqchip.c‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#include <linux/irq.h>
3737
#include <asm/trace.h>
3838

39-
static unsigned long irq_err_count;
39+
static atomic_t irq_err_count;
4040
static spinlock_t irq_controller_lock;
4141

4242
/*
@@ -48,7 +48,7 @@ void dummy_mask_unmask_irq(unsigned int irq)
4848

4949
void ack_bad_irq(unsigned int irq)
5050
{
51-
irq_err_count += 1;
51+
atomic_inc(&irq_err_count);
5252
printk(KERN_ERR "IRQ: spurious interrupt %d\n", irq);
5353
}
5454
EXPORT_SYMBOL(ack_bad_irq);
@@ -72,27 +72,28 @@ static struct irq_desc bad_irq_desc = {
7272

7373
int show_interrupts(struct seq_file *p, void *v)
7474
{
75-
int i = *(loff_t *) v;
75+
int i = *(loff_t *) v, j;
7676
struct irqaction *action;
7777
unsigned long flags;
7878

7979
if (i < NR_IRQS) {
8080
spin_lock_irqsave(&irq_desc[i].lock, flags);
8181
action = irq_desc[i].action;
8282
if (!action)
83-
goto unlock;
84-
85-
seq_printf(p, "%3d: %10u ", i, kstat_irqs(i));
83+
goto skip;
84+
seq_printf(p, "%3d: ", i);
85+
for_each_online_cpu(j)
86+
seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
87+
seq_printf(p, " %8s", irq_desc[i].chip->name);
8688
seq_printf(p, " %s", action->name);
8789
for (action = action->next; action; action = action->next)
88-
seq_printf(p, ", %s", action->name);
90+
seq_printf(p, " %s", action->name);
8991

9092
seq_putc(p, '\n');
91-
unlock:
93+
skip:
9294
spin_unlock_irqrestore(&irq_desc[i].lock, flags);
93-
} else if (i == NR_IRQS) {
94-
seq_printf(p, "Err: %10lu\n", irq_err_count);
95-
}
95+
} else if (i == NR_IRQS)
96+
seq_printf(p, "Err: %10u\n", atomic_read(&irq_err_count));
9697
return 0;
9798
}
9899

@@ -101,7 +102,6 @@ int show_interrupts(struct seq_file *p, void *v)
101102
* come via this function. Instead, they should provide their
102103
* own 'handler'
103104
*/
104-
105105
#ifdef CONFIG_DO_IRQ_L1
106106
__attribute__((l1_text))
107107
#endif

‎arch/blackfin/kernel/kgdb.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,12 +363,12 @@ void kgdb_passive_cpu_callback(void *info)
363363

364364
void kgdb_roundup_cpus(unsigned long flags)
365365
{
366-
smp_call_function(kgdb_passive_cpu_callback, NULL, 0, 0);
366+
smp_call_function(kgdb_passive_cpu_callback, NULL, 0);
367367
}
368368

369369
void kgdb_roundup_cpu(int cpu, unsigned long flags)
370370
{
371-
smp_call_function_single(cpu, kgdb_passive_cpu_callback, NULL, 0, 0);
371+
smp_call_function_single(cpu, kgdb_passive_cpu_callback, NULL, 0);
372372
}
373373
#endif
374374

‎arch/blackfin/kernel/module.c‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,13 @@ apply_relocate_add(Elf_Shdr * sechdrs, const char *strtab,
343343
pr_debug("location is %x, value is %x type is %d \n",
344344
(unsigned int) location32, value,
345345
ELF32_R_TYPE(rel[i].r_info));
346-
346+
#ifdef CONFIG_SMP
347+
if ((unsigned long)location16 >= COREB_L1_DATA_A_START) {
348+
printk(KERN_ERR "module %s: cannot relocate in L1: %u (SMP kernel)",
349+
mod->name, ELF32_R_TYPE(rel[i].r_info));
350+
return -ENOEXEC;
351+
}
352+
#endif
347353
switch (ELF32_R_TYPE(rel[i].r_info)) {
348354

349355
case R_pcrel24:
@@ -436,6 +442,7 @@ module_finalize(const Elf_Ehdr * hdr,
436442
{
437443
unsigned int i, strindex = 0, symindex = 0;
438444
char *secstrings;
445+
long err = 0;
439446

440447
secstrings = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
441448

@@ -460,8 +467,10 @@ module_finalize(const Elf_Ehdr * hdr,
460467
(strcmp(".rela.l1.text", secstrings + sechdrs[i].sh_name) == 0) ||
461468
((strcmp(".rela.text", secstrings + sechdrs[i].sh_name) == 0) &&
462469
(hdr->e_flags & (EF_BFIN_CODE_IN_L1|EF_BFIN_CODE_IN_L2))))) {
463-
apply_relocate_add((Elf_Shdr *) sechdrs, strtab,
470+
err = apply_relocate_add((Elf_Shdr *) sechdrs, strtab,
464471
symindex, i, mod);
472+
if (err < 0)
473+
return -ENOEXEC;
465474
}
466475
}
467476
return 0;

‎arch/blackfin/kernel/process.c‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,13 @@ asmlinkage int bfin_clone(struct pt_regs *regs)
171171
unsigned long clone_flags;
172172
unsigned long newsp;
173173

174+
#ifdef __ARCH_SYNC_CORE_DCACHE
175+
if (current->rt.nr_cpus_allowed == num_possible_cpus()) {
176+
current->cpus_allowed = cpumask_of_cpu(smp_processor_id());
177+
current->rt.nr_cpus_allowed = 1;
178+
}
179+
#endif
180+
174181
/* syscall2 puts clone_flags in r0 and usp in r1 */
175182
clone_flags = regs->r0;
176183
newsp = regs->r1;
@@ -338,22 +345,22 @@ int _access_ok(unsigned long addr, unsigned long size)
338345
if (addr >= (unsigned long)__init_begin &&
339346
addr + size <= (unsigned long)__init_end)
340347
return 1;
341-
if (addr >= L1_SCRATCH_START
342-
&& addr + size <= L1_SCRATCH_START + L1_SCRATCH_LENGTH)
348+
if (addr >= get_l1_scratch_start()
349+
&& addr + size <= get_l1_scratch_start() + L1_SCRATCH_LENGTH)
343350
return 1;
344351
#if L1_CODE_LENGTH != 0
345-
if (addr >= L1_CODE_START + (_etext_l1 - _stext_l1)
346-
&& addr + size <= L1_CODE_START + L1_CODE_LENGTH)
352+
if (addr >= get_l1_code_start() + (_etext_l1 - _stext_l1)
353+
&& addr + size <= get_l1_code_start() + L1_CODE_LENGTH)
347354
return 1;
348355
#endif
349356
#if L1_DATA_A_LENGTH != 0
350-
if (addr >= L1_DATA_A_START + (_ebss_l1 - _sdata_l1)
351-
&& addr + size <= L1_DATA_A_START + L1_DATA_A_LENGTH)
357+
if (addr >= get_l1_data_a_start() + (_ebss_l1 - _sdata_l1)
358+
&& addr + size <= get_l1_data_a_start() + L1_DATA_A_LENGTH)
352359
return 1;
353360
#endif
354361
#if L1_DATA_B_LENGTH != 0
355-
if (addr >= L1_DATA_B_START + (_ebss_b_l1 - _sdata_b_l1)
356-
&& addr + size <= L1_DATA_B_START + L1_DATA_B_LENGTH)
362+
if (addr >= get_l1_data_b_start() + (_ebss_b_l1 - _sdata_b_l1)
363+
&& addr + size <= get_l1_data_b_start() + L1_DATA_B_LENGTH)
357364
return 1;
358365
#endif
359366
#if L2_LENGTH != 0

‎arch/blackfin/kernel/ptrace.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,8 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
220220
break;
221221
pr_debug("ptrace: user address is valid\n");
222222

223-
if (L1_CODE_LENGTH != 0 && addr >= L1_CODE_START
224-
&& addr + sizeof(tmp) <= L1_CODE_START + L1_CODE_LENGTH) {
223+
if (L1_CODE_LENGTH != 0 && addr >= get_l1_code_start()
224+
&& addr + sizeof(tmp) <= get_l1_code_start() + L1_CODE_LENGTH) {
225225
safe_dma_memcpy (&tmp, (const void *)(addr), sizeof(tmp));
226226
copied = sizeof(tmp);
227227

@@ -300,8 +300,8 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
300300
break;
301301
pr_debug("ptrace: user address is valid\n");
302302

303-
if (L1_CODE_LENGTH != 0 && addr >= L1_CODE_START
304-
&& addr + sizeof(data) <= L1_CODE_START + L1_CODE_LENGTH) {
303+
if (L1_CODE_LENGTH != 0 && addr >= get_l1_code_start()
304+
&& addr + sizeof(data) <= get_l1_code_start() + L1_CODE_LENGTH) {
305305
safe_dma_memcpy ((void *)(addr), &data, sizeof(data));
306306
copied = sizeof(data);
307307

‎arch/blackfin/kernel/reboot.c‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* the core reset.
2222
*/
2323
__attribute__((l1_text))
24-
static void bfin_reset(void)
24+
static void _bfin_reset(void)
2525
{
2626
/* Wait for completion of "system" events such as cache line
2727
* line fills so that we avoid infinite stalls later on as
@@ -66,6 +66,18 @@ static void bfin_reset(void)
6666
}
6767
}
6868

69+
static void bfin_reset(void)
70+
{
71+
if (ANOMALY_05000353 || ANOMALY_05000386)
72+
_bfin_reset();
73+
else
74+
/* the bootrom checks to see how it was reset and will
75+
* automatically perform a software reset for us when
76+
* it starts executing boot
77+
*/
78+
asm("raise 1;");
79+
}
80+
6981
__attribute__((weak))
7082
void native_machine_restart(char *cmd)
7183
{
@@ -75,14 +87,10 @@ void machine_restart(char *cmd)
7587
{
7688
native_machine_restart(cmd);
7789
local_irq_disable();
78-
if (ANOMALY_05000353 || ANOMALY_05000386)
79-
bfin_reset();
90+
if (smp_processor_id())
91+
smp_call_function((void *)bfin_reset, 0, 1);
8092
else
81-
/* the bootrom checks to see how it was reset and will
82-
* automatically perform a software reset for us when
83-
* it starts executing boot
84-
*/
85-
asm("raise 1;");
93+
bfin_reset();
8694
}
8795

8896
__attribute__((weak))

0 commit comments

Comments
 (0)