Skip to content

Commit b8a9898

Browse files
Graf YangBryan Wu
authored andcommitted
Blackfin arch: SMP supporting patchset: Blackfin CPLB related 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 CPLB related code Signed-off-by: Graf Yang <graf.yang@analog.com> Signed-off-by: Bryan Wu <cooloney@kernel.org>
1 parent 6b3087c commit b8a9898

12 files changed

Lines changed: 275 additions & 219 deletions

File tree

‎arch/blackfin/include/asm/cplb-mpu.h‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
*/
2929
#ifndef __ASM_BFIN_CPLB_MPU_H
3030
#define __ASM_BFIN_CPLB_MPU_H
31+
#include <linux/threads.h>
3132

3233
struct cplb_entry {
3334
unsigned long data, addr;
@@ -39,22 +40,22 @@ struct mem_region {
3940
unsigned long icplb_data;
4041
};
4142

42-
extern struct cplb_entry dcplb_tbl[MAX_CPLBS];
43-
extern struct cplb_entry icplb_tbl[MAX_CPLBS];
43+
extern struct cplb_entry dcplb_tbl[NR_CPUS][MAX_CPLBS];
44+
extern struct cplb_entry icplb_tbl[NR_CPUS][MAX_CPLBS];
4445
extern int first_switched_icplb;
4546
extern int first_mask_dcplb;
4647
extern int first_switched_dcplb;
4748

48-
extern int nr_dcplb_miss, nr_icplb_miss, nr_icplb_supv_miss, nr_dcplb_prot;
49-
extern int nr_cplb_flush;
49+
extern int nr_dcplb_miss[], nr_icplb_miss[], nr_icplb_supv_miss[];
50+
extern int nr_dcplb_prot[], nr_cplb_flush[];
5051

5152
extern int page_mask_order;
5253
extern int page_mask_nelts;
5354

54-
extern unsigned long *current_rwx_mask;
55+
extern unsigned long *current_rwx_mask[NR_CPUS];
5556

56-
extern void flush_switched_cplbs(void);
57-
extern void set_mask_dcplbs(unsigned long *);
57+
extern void flush_switched_cplbs(unsigned int);
58+
extern void set_mask_dcplbs(unsigned long *, unsigned int);
5859

5960
extern void __noreturn panic_cplb_error(int seqstat, struct pt_regs *);
6061

‎arch/blackfin/include/asm/cplb.h‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#ifndef _CPLB_H
3131
#define _CPLB_H
3232

33-
#include <asm/blackfin.h>
3433
#include <mach/anomaly.h>
3534

3635
#define SDRAM_IGENERIC (CPLB_L1_CHBL | CPLB_USER_RD | CPLB_VALID | CPLB_PORTPRIO)
@@ -55,13 +54,24 @@
5554
#endif
5655

5756
#define L1_DMEMORY (CPLB_LOCK | CPLB_COMMON)
57+
58+
#ifdef CONFIG_SMP
59+
#define L2_ATTR (INITIAL_T | I_CPLB | D_CPLB)
60+
#define L2_IMEMORY (CPLB_COMMON | CPLB_LOCK)
61+
#define L2_DMEMORY (CPLB_COMMON | CPLB_LOCK)
62+
63+
#else
5864
#ifdef CONFIG_BFIN_L2_CACHEABLE
5965
#define L2_IMEMORY (SDRAM_IGENERIC)
6066
#define L2_DMEMORY (SDRAM_DGENERIC)
6167
#else
6268
#define L2_IMEMORY (CPLB_COMMON)
6369
#define L2_DMEMORY (CPLB_COMMON)
64-
#endif
70+
#endif /* CONFIG_BFIN_L2_CACHEABLE */
71+
72+
#define L2_ATTR (INITIAL_T | SWITCH_T | I_CPLB | D_CPLB)
73+
#endif /* CONFIG_SMP */
74+
6575
#define SDRAM_DNON_CHBL (CPLB_COMMON)
6676
#define SDRAM_EBIU (CPLB_COMMON)
6777
#define SDRAM_OOPS (CPLB_VALID | ANOMALY_05000158_WORKAROUND | CPLB_LOCK | CPLB_DIRTY)
@@ -71,14 +81,7 @@
7181
#define SIZE_1M 0x00100000 /* 1M */
7282
#define SIZE_4M 0x00400000 /* 4M */
7383

74-
#ifdef CONFIG_MPU
7584
#define MAX_CPLBS 16
76-
#else
77-
#define MAX_CPLBS (16 * 2)
78-
#endif
79-
80-
#define ASYNC_MEMORY_CPLB_COVERAGE ((ASYNC_BANK0_SIZE + ASYNC_BANK1_SIZE + \
81-
ASYNC_BANK2_SIZE + ASYNC_BANK3_SIZE) / SIZE_4M)
8285

8386
#define CPLB_ENABLE_ICACHE_P 0
8487
#define CPLB_ENABLE_DCACHE_P 1

‎arch/blackfin/include/asm/cplbinit.h‎

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
#ifdef CONFIG_MPU
3737

3838
#include <asm/cplb-mpu.h>
39+
extern void bfin_icache_init(struct cplb_entry *icplb_tbl);
40+
extern void bfin_dcache_init(struct cplb_entry *icplb_tbl);
3941

4042
#else
4143

@@ -46,8 +48,40 @@
4648

4749
#define IN_KERNEL 1
4850

49-
enum
50-
{ZERO_P, L1I_MEM, L1D_MEM, SDRAM_KERN , SDRAM_RAM_MTD, SDRAM_DMAZ, RES_MEM, ASYNC_MEM, L2_MEM};
51+
#define ASYNC_MEMORY_CPLB_COVERAGE ((ASYNC_BANK0_SIZE + ASYNC_BANK1_SIZE + \
52+
ASYNC_BANK2_SIZE + ASYNC_BANK3_SIZE) / SIZE_4M)
53+
54+
#define CPLB_MEM CONFIG_MAX_MEM_SIZE
55+
56+
/*
57+
* Number of required data CPLB switchtable entries
58+
* MEMSIZE / 4 (we mostly install 4M page size CPLBs
59+
* approx 16 for smaller 1MB page size CPLBs for allignment purposes
60+
* 1 for L1 Data Memory
61+
* possibly 1 for L2 Data Memory
62+
* 1 for CONFIG_DEBUG_HUNT_FOR_ZERO
63+
* 1 for ASYNC Memory
64+
*/
65+
#define MAX_SWITCH_D_CPLBS (((CPLB_MEM / 4) + 16 + 1 + 1 + 1 \
66+
+ ASYNC_MEMORY_CPLB_COVERAGE) * 2)
67+
68+
/*
69+
* Number of required instruction CPLB switchtable entries
70+
* MEMSIZE / 4 (we mostly install 4M page size CPLBs
71+
* approx 12 for smaller 1MB page size CPLBs for allignment purposes
72+
* 1 for L1 Instruction Memory
73+
* possibly 1 for L2 Instruction Memory
74+
* 1 for CONFIG_DEBUG_HUNT_FOR_ZERO
75+
*/
76+
#define MAX_SWITCH_I_CPLBS (((CPLB_MEM / 4) + 12 + 1 + 1 + 1) * 2)
77+
78+
/* Number of CPLB table entries, used for cplb-nompu. */
79+
#define CPLB_TBL_ENTRIES (16 * 4)
80+
81+
enum {
82+
ZERO_P, L1I_MEM, L1D_MEM, L2_MEM, SDRAM_KERN, SDRAM_RAM_MTD, SDRAM_DMAZ,
83+
RES_MEM, ASYNC_MEM, OCB_ROM
84+
};
5185

5286
struct cplb_desc {
5387
u32 start; /* start address */
@@ -66,8 +100,8 @@ struct cplb_tab {
66100
u16 size;
67101
};
68102

69-
extern u_long icplb_table[];
70-
extern u_long dcplb_table[];
103+
extern u_long icplb_tables[NR_CPUS][CPLB_TBL_ENTRIES+1];
104+
extern u_long dcplb_tables[NR_CPUS][CPLB_TBL_ENTRIES+1];
71105

72106
/* Till here we are discussing about the static memory management model.
73107
* However, the operating envoronments commonly define more CPLB
@@ -78,15 +112,18 @@ extern u_long dcplb_table[];
78112
* This is how Page descriptor Table is implemented in uClinux/Blackfin.
79113
*/
80114

81-
extern u_long ipdt_table[];
82-
extern u_long dpdt_table[];
115+
extern u_long ipdt_tables[NR_CPUS][MAX_SWITCH_I_CPLBS+1];
116+
extern u_long dpdt_tables[NR_CPUS][MAX_SWITCH_D_CPLBS+1];
83117
#ifdef CONFIG_CPLB_INFO
84-
extern u_long ipdt_swapcount_table[];
85-
extern u_long dpdt_swapcount_table[];
118+
extern u_long ipdt_swapcount_tables[NR_CPUS][MAX_SWITCH_I_CPLBS];
119+
extern u_long dpdt_swapcount_tables[NR_CPUS][MAX_SWITCH_D_CPLBS];
86120
#endif
121+
extern void bfin_icache_init(u_long icplbs[]);
122+
extern void bfin_dcache_init(u_long dcplbs[]);
87123

88124
#endif /* CONFIG_MPU */
89125

90-
extern void generate_cplb_tables(void);
91-
126+
#if defined(CONFIG_BFIN_DCACHE) || defined(CONFIG_BFIN_ICACHE)
127+
extern void generate_cplb_tables_cpu(unsigned int cpu);
128+
#endif
92129
#endif

‎arch/blackfin/include/asm/mmu_context.h‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
#include <asm/pgalloc.h>
3838
#include <asm/cplbinit.h>
3939

40+
/* Note: L1 stacks are CPU-private things, so we bluntly disable this
41+
feature in SMP mode, and use the per-CPU scratch SRAM bank only to
42+
store the PDA instead. */
43+
4044
extern void *current_l1_stack_save;
4145
extern int nr_l1stack_tasks;
4246
extern void *l1_stack_base;
@@ -88,12 +92,15 @@ activate_l1stack(struct mm_struct *mm, unsigned long sp_base)
8892
static inline void switch_mm(struct mm_struct *prev_mm, struct mm_struct *next_mm,
8993
struct task_struct *tsk)
9094
{
95+
#ifdef CONFIG_MPU
96+
unsigned int cpu = smp_processor_id();
97+
#endif
9198
if (prev_mm == next_mm)
9299
return;
93100
#ifdef CONFIG_MPU
94-
if (prev_mm->context.page_rwx_mask == current_rwx_mask) {
95-
flush_switched_cplbs();
96-
set_mask_dcplbs(next_mm->context.page_rwx_mask);
101+
if (prev_mm->context.page_rwx_mask == current_rwx_mask[cpu]) {
102+
flush_switched_cplbs(cpu);
103+
set_mask_dcplbs(next_mm->context.page_rwx_mask, cpu);
97104
}
98105
#endif
99106

@@ -138,9 +145,10 @@ static inline void protect_page(struct mm_struct *mm, unsigned long addr,
138145

139146
static inline void update_protections(struct mm_struct *mm)
140147
{
141-
if (mm->context.page_rwx_mask == current_rwx_mask) {
142-
flush_switched_cplbs();
143-
set_mask_dcplbs(mm->context.page_rwx_mask);
148+
unsigned int cpu = smp_processor_id();
149+
if (mm->context.page_rwx_mask == current_rwx_mask[cpu]) {
150+
flush_switched_cplbs(cpu);
151+
set_mask_dcplbs(mm->context.page_rwx_mask, cpu);
144152
}
145153
}
146154
#endif
@@ -165,6 +173,9 @@ init_new_context(struct task_struct *tsk, struct mm_struct *mm)
165173
static inline void destroy_context(struct mm_struct *mm)
166174
{
167175
struct sram_list_struct *tmp;
176+
#ifdef CONFIG_MPU
177+
unsigned int cpu = smp_processor_id();
178+
#endif
168179

169180
#ifdef CONFIG_APP_STACK_L1
170181
if (current_l1_stack_save == mm->context.l1_stack_save)
@@ -179,8 +190,8 @@ static inline void destroy_context(struct mm_struct *mm)
179190
kfree(tmp);
180191
}
181192
#ifdef CONFIG_MPU
182-
if (current_rwx_mask == mm->context.page_rwx_mask)
183-
current_rwx_mask = NULL;
193+
if (current_rwx_mask[cpu] == mm->context.page_rwx_mask)
194+
current_rwx_mask[cpu] = NULL;
184195
free_pages((unsigned long)mm->context.page_rwx_mask, page_mask_order);
185196
#endif
186197
}

‎arch/blackfin/kernel/cplb-mpu/cacheinit.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <asm/cplbinit.h>
2626

2727
#if defined(CONFIG_BFIN_ICACHE)
28-
void __init bfin_icache_init(void)
28+
void __cpuinit bfin_icache_init(struct cplb_entry *icplb_tbl)
2929
{
3030
unsigned long ctrl;
3131
int i;
@@ -43,7 +43,7 @@ void __init bfin_icache_init(void)
4343
#endif
4444

4545
#if defined(CONFIG_BFIN_DCACHE)
46-
void __init bfin_dcache_init(void)
46+
void __cpuinit bfin_dcache_init(struct cplb_entry *dcplb_tbl)
4747
{
4848
unsigned long ctrl;
4949
int i;

‎arch/blackfin/kernel/cplb-mpu/cplbinfo.c‎

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,32 +66,32 @@ static char *cplb_print_entry(char *buf, struct cplb_entry *tbl, int switched)
6666
return buf;
6767
}
6868

69-
int cplbinfo_proc_output(char *buf)
69+
int cplbinfo_proc_output(char *buf, void *data)
7070
{
7171
char *p;
72+
unsigned int cpu = (unsigned int)data;;
7273

7374
p = buf;
7475

75-
p += sprintf(p, "------------------ CPLB Information ------------------\n\n");
76-
76+
p += sprintf(p, "------------- CPLB Information on CPU%u --------------\n\n", cpu);
7777
if (bfin_read_IMEM_CONTROL() & ENICPLB) {
7878
p += sprintf(p, "Instruction CPLB entry:\n");
79-
p = cplb_print_entry(p, icplb_tbl, first_switched_icplb);
79+
p = cplb_print_entry(p, icplb_tbl[cpu], first_switched_icplb);
8080
} else
8181
p += sprintf(p, "Instruction CPLB is disabled.\n\n");
8282

8383
if (1 || bfin_read_DMEM_CONTROL() & ENDCPLB) {
8484
p += sprintf(p, "Data CPLB entry:\n");
85-
p = cplb_print_entry(p, dcplb_tbl, first_switched_dcplb);
85+
p = cplb_print_entry(p, dcplb_tbl[cpu], first_switched_dcplb);
8686
} else
8787
p += sprintf(p, "Data CPLB is disabled.\n");
8888

8989
p += sprintf(p, "ICPLB miss: %d\nICPLB supervisor miss: %d\n",
90-
nr_icplb_miss, nr_icplb_supv_miss);
90+
nr_icplb_miss[cpu], nr_icplb_supv_miss[cpu]);
9191
p += sprintf(p, "DCPLB miss: %d\nDCPLB protection fault:%d\n",
92-
nr_dcplb_miss, nr_dcplb_prot);
92+
nr_dcplb_miss[cpu], nr_dcplb_prot[cpu]);
9393
p += sprintf(p, "CPLB flushes: %d\n",
94-
nr_cplb_flush);
94+
nr_cplb_flush[cpu]);
9595

9696
return p - buf;
9797
}
@@ -101,7 +101,7 @@ static int cplbinfo_read_proc(char *page, char **start, off_t off,
101101
{
102102
int len;
103103

104-
len = cplbinfo_proc_output(page);
104+
len = cplbinfo_proc_output(page, data);
105105
if (len <= off + count)
106106
*eof = 1;
107107
*start = page + off;
@@ -115,20 +115,33 @@ static int cplbinfo_read_proc(char *page, char **start, off_t off,
115115

116116
static int __init cplbinfo_init(void)
117117
{
118-
struct proc_dir_entry *entry;
118+
struct proc_dir_entry *parent, *entry;
119+
unsigned int cpu;
120+
unsigned char str[10];
121+
122+
parent = proc_mkdir("cplbinfo", NULL);
119123

120-
entry = create_proc_entry("cplbinfo", 0, NULL);
121-
if (!entry)
122-
return -ENOMEM;
124+
for_each_online_cpu(cpu) {
125+
sprintf(str, "cpu%u", cpu);
126+
entry = create_proc_entry(str, 0, parent);
127+
if (!entry)
128+
return -ENOMEM;
123129

124-
entry->read_proc = cplbinfo_read_proc;
125-
entry->data = NULL;
130+
entry->read_proc = cplbinfo_read_proc;
131+
entry->data = (void *)cpu;
132+
}
126133

127134
return 0;
128135
}
129136

130137
static void __exit cplbinfo_exit(void)
131138
{
139+
unsigned int cpu;
140+
unsigned char str[20];
141+
for_each_online_cpu(cpu) {
142+
sprintf(str, "cplbinfo/cpu%u", cpu);
143+
remove_proc_entry(str, NULL);
144+
}
132145
remove_proc_entry("cplbinfo", NULL);
133146
}
134147

0 commit comments

Comments
 (0)