Skip to content

Commit dbdf20d

Browse files
berndsBryan Wu
authored andcommitted
Blackfin arch: Faster C implementation of no-MPU CPLB handler
This is a mixture ofcMichael McTernan's patch and the existing cplb-mpu code. We ditch the old cplb-nompu implementation, which is a good example of why a good algorithm in a HLL is preferrable to a bad algorithm written in assembly. Rather than try to construct a table of all posible CPLBs and search it, we just create a (smaller) table of memory regions and their attributes. Some of the data structures are now unified for both the mpu and nompu cases. A lot of needless complexity in cplbinit.c is removed. Further optimizations: * compile cplbmgr.c with a lot of -ffixed-reg options, and omit saving these registers on the stack when entering a CPLB exception. * lose cli/nop/nop/sti sequences for some workarounds - these don't * make sense in an exception context Additional code unification should be possible after this. [Mike Frysinger <vapier.adi@gmail.com>: - convert CPP if statements to C if statements - remove redundant statements - use a do...while loop rather than a for loop to get slightly better optimization and to avoid gcc "may be used uninitialized" warnings ... we know that the [id]cplb_nr_bounds variables will never be 0, so this is OK - the no-mpu code was the last user of MAX_MEM_SIZE and with that rewritten, we can punt it - add some BUG_ON() checks to make sure we dont overflow the small cplb_bounds array - add i/d cplb entries for the bootrom because there is functions/data in there we want to access - we do not need a NULL trailing entry as any time we access the bounds arrays, we use the nr_bounds variable ] Signed-off-by: Michael McTernan <mmcternan@airvana.com> Signed-off-by: Mike Frysinger <vapier.adi@gmail.com> Signed-off-by: Bernd Schmidt <bernds_cb1@t-online.de> Signed-off-by: Bryan Wu <cooloney@kernel.org>
1 parent 6651ece commit dbdf20d

19 files changed

Lines changed: 515 additions & 1442 deletions

File tree

‎arch/blackfin/Kconfig‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -524,14 +524,6 @@ config MEM_SDGCTL
524524
default 0x0
525525
endmenu
526526

527-
config MAX_MEM_SIZE
528-
int "Max SDRAM Memory Size in MBytes"
529-
depends on !MPU
530-
default 512
531-
help
532-
This is the max memory size that the kernel will create CPLB
533-
tables for. Your system will not be able to handle any more.
534-
535527
#
536528
# Max & Min Speeds for various Chips
537529
#

‎arch/blackfin/include/asm/context.S‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,3 +357,42 @@
357357
SYSCFG = [sp++];
358358
csync;
359359
.endm
360+
361+
.macro save_context_cplb
362+
[--sp] = (R7:0, P5:0);
363+
[--sp] = fp;
364+
365+
[--sp] = a0.x;
366+
[--sp] = a0.w;
367+
[--sp] = a1.x;
368+
[--sp] = a1.w;
369+
370+
[--sp] = LC0;
371+
[--sp] = LC1;
372+
[--sp] = LT0;
373+
[--sp] = LT1;
374+
[--sp] = LB0;
375+
[--sp] = LB1;
376+
377+
[--sp] = RETS;
378+
.endm
379+
380+
.macro restore_context_cplb
381+
RETS = [sp++];
382+
383+
LB1 = [sp++];
384+
LB0 = [sp++];
385+
LT1 = [sp++];
386+
LT0 = [sp++];
387+
LC1 = [sp++];
388+
LC0 = [sp++];
389+
390+
a1.w = [sp++];
391+
a1.x = [sp++];
392+
a0.w = [sp++];
393+
a0.x = [sp++];
394+
395+
fp = [sp++];
396+
397+
(R7:0, P5:0) = [SP++];
398+
.endm

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

Lines changed: 0 additions & 62 deletions
This file was deleted.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,8 @@
116116
#define CPLB_INOCACHE CPLB_USER_RD | CPLB_VALID
117117
#define CPLB_IDOCACHE CPLB_INOCACHE | CPLB_L1_CHBL
118118

119+
#define FAULT_RW (1 << 16)
120+
#define FAULT_USERSUPV (1 << 17)
121+
#define FAULT_CPLBBITS 0x0000ffff
122+
119123
#endif /* _CPLB_H */

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

Lines changed: 34 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -32,96 +32,56 @@
3232

3333
#include <asm/blackfin.h>
3434
#include <asm/cplb.h>
35+
#include <linux/threads.h>
3536

36-
#ifdef CONFIG_MPU
37-
38-
#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);
41-
37+
#ifdef CONFIG_CPLB_SWITCH_TAB_L1
38+
# define PDT_ATTR __attribute__((l1_data))
4239
#else
40+
# define PDT_ATTR
41+
#endif
4342

44-
#define INITIAL_T 0x1
45-
#define SWITCH_T 0x2
46-
#define I_CPLB 0x4
47-
#define D_CPLB 0x8
43+
struct cplb_entry {
44+
unsigned long data, addr;
45+
};
4846

49-
#define ASYNC_MEMORY_CPLB_COVERAGE ((ASYNC_BANK0_SIZE + ASYNC_BANK1_SIZE + \
50-
ASYNC_BANK2_SIZE + ASYNC_BANK3_SIZE) / SIZE_4M)
47+
struct cplb_boundary {
48+
unsigned long eaddr; /* End of this region. */
49+
unsigned long data; /* CPLB data value. */
50+
};
5151

52-
#define CPLB_MEM CONFIG_MAX_MEM_SIZE
52+
extern struct cplb_boundary dcplb_bounds[];
53+
extern struct cplb_boundary icplb_bounds[];
54+
extern int dcplb_nr_bounds, icplb_nr_bounds;
5355

54-
/*
55-
* Number of required data CPLB switchtable entries
56-
* MEMSIZE / 4 (we mostly install 4M page size CPLBs
57-
* approx 16 for smaller 1MB page size CPLBs for allignment purposes
58-
* 1 for L1 Data Memory
59-
* possibly 1 for L2 Data Memory
60-
* 1 for CONFIG_DEBUG_HUNT_FOR_ZERO
61-
* 1 for ASYNC Memory
62-
*/
63-
#define MAX_SWITCH_D_CPLBS (((CPLB_MEM / 4) + 16 + 1 + 1 + 1 \
64-
+ ASYNC_MEMORY_CPLB_COVERAGE) * 2)
56+
extern struct cplb_entry dcplb_tbl[NR_CPUS][MAX_CPLBS];
57+
extern struct cplb_entry icplb_tbl[NR_CPUS][MAX_CPLBS];
58+
extern int first_switched_icplb;
59+
extern int first_switched_dcplb;
6560

66-
/*
67-
* Number of required instruction CPLB switchtable entries
68-
* MEMSIZE / 4 (we mostly install 4M page size CPLBs
69-
* approx 12 for smaller 1MB page size CPLBs for allignment purposes
70-
* 1 for L1 Instruction Memory
71-
* possibly 1 for L2 Instruction Memory
72-
* 1 for CONFIG_DEBUG_HUNT_FOR_ZERO
73-
*/
74-
#define MAX_SWITCH_I_CPLBS (((CPLB_MEM / 4) + 12 + 1 + 1 + 1) * 2)
75-
76-
/* Number of CPLB table entries, used for cplb-nompu. */
77-
#define CPLB_TBL_ENTRIES (16 * 4)
78-
79-
enum {
80-
ZERO_P, L1I_MEM, L1D_MEM, L2_MEM, SDRAM_KERN, SDRAM_RAM_MTD, SDRAM_DMAZ,
81-
RES_MEM, ASYNC_MEM, OCB_ROM
82-
};
61+
extern int nr_dcplb_miss[], nr_icplb_miss[], nr_icplb_supv_miss[];
62+
extern int nr_dcplb_prot[], nr_cplb_flush[];
8363

84-
struct cplb_desc {
85-
u32 start; /* start address */
86-
u32 end; /* end address */
87-
u32 psize; /* prefered size if any otherwise 1MB or 4MB*/
88-
u16 attr;/* attributes */
89-
u16 i_conf;/* I-CPLB DATA */
90-
u16 d_conf;/* D-CPLB DATA */
91-
u16 valid;/* valid */
92-
const s8 name[30];/* name */
93-
};
64+
#ifdef CONFIG_MPU
9465

95-
struct cplb_tab {
96-
u_long *tab;
97-
u16 pos;
98-
u16 size;
99-
};
66+
extern int first_mask_dcplb;
10067

101-
extern u_long icplb_tables[NR_CPUS][CPLB_TBL_ENTRIES+1];
102-
extern u_long dcplb_tables[NR_CPUS][CPLB_TBL_ENTRIES+1];
68+
extern int page_mask_order;
69+
extern int page_mask_nelts;
10370

104-
/* Till here we are discussing about the static memory management model.
105-
* However, the operating envoronments commonly define more CPLB
106-
* descriptors to cover the entire addressable memory than will fit into
107-
* the available on-chip 16 CPLB MMRs. When this happens, the below table
108-
* will be used which will hold all the potentially required CPLB descriptors
109-
*
110-
* This is how Page descriptor Table is implemented in uClinux/Blackfin.
111-
*/
71+
extern unsigned long *current_rwx_mask[NR_CPUS];
11272

113-
extern u_long ipdt_tables[NR_CPUS][MAX_SWITCH_I_CPLBS+1];
114-
extern u_long dpdt_tables[NR_CPUS][MAX_SWITCH_D_CPLBS+1];
115-
#ifdef CONFIG_CPLB_INFO
116-
extern u_long ipdt_swapcount_tables[NR_CPUS][MAX_SWITCH_I_CPLBS];
117-
extern u_long dpdt_swapcount_tables[NR_CPUS][MAX_SWITCH_D_CPLBS];
118-
#endif
119-
extern void bfin_icache_init(u_long icplbs[]);
120-
extern void bfin_dcache_init(u_long dcplbs[]);
73+
extern void flush_switched_cplbs(unsigned int);
74+
extern void set_mask_dcplbs(unsigned long *, unsigned int);
75+
76+
extern void __noreturn panic_cplb_error(int seqstat, struct pt_regs *);
12177

12278
#endif /* CONFIG_MPU */
12379

80+
extern void bfin_icache_init(struct cplb_entry *icplb_tbl);
81+
extern void bfin_dcache_init(struct cplb_entry *icplb_tbl);
82+
12483
#if defined(CONFIG_BFIN_DCACHE) || defined(CONFIG_BFIN_ICACHE)
84+
extern void generate_cplb_tables_all(void);
12585
extern void generate_cplb_tables_cpu(unsigned int cpu);
12686
#endif
12787
#endif

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@
5353
/* This one pushes RETI without using CLI. Interrupts are enabled. */
5454
#define SAVE_CONTEXT_SYSCALL save_context_syscall
5555
#define SAVE_CONTEXT save_context_with_interrupts
56+
#define SAVE_CONTEXT_CPLB save_context_cplb
5657

5758
#define RESTORE_ALL_SYS restore_context_no_interrupts
5859
#define RESTORE_CONTEXT restore_context_with_interrupts
60+
#define RESTORE_CONTEXT_CPLB restore_context_cplb
5961

6062
#endif /* __ASSEMBLY__ */
6163
#endif /* __BFIN_ENTRY_H */

‎arch/blackfin/kernel/cplb-mpu/Makefile‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,8 @@
33
#
44

55
obj-y := cplbinit.o cacheinit.o cplbmgr.o
6+
7+
CFLAGS_cplbmgr.o := -ffixed-I0 -ffixed-I1 -ffixed-I2 -ffixed-I3 \
8+
-ffixed-L0 -ffixed-L1 -ffixed-L2 -ffixed-L3 \
9+
-ffixed-M0 -ffixed-M1 -ffixed-M2 -ffixed-M3 \
10+
-ffixed-B0 -ffixed-B1 -ffixed-B2 -ffixed-B3

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,7 @@ void __init generate_cplb_tables_cpu(unsigned int cpu)
107107
while (i_i < MAX_CPLBS)
108108
icplb_tbl[cpu][i_i++].data = 0;
109109
}
110+
111+
void generate_cplb_tables_all(void)
112+
{
113+
}

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

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

28-
#define FAULT_RW (1 << 16)
29-
#define FAULT_USERSUPV (1 << 17)
28+
/*
29+
* WARNING
30+
*
31+
* This file is compiled with certain -ffixed-reg options. We have to
32+
* make sure not to call any functions here that could clobber these
33+
* registers.
34+
*/
3035

3136
int page_mask_nelts;
3237
int page_mask_order;

‎arch/blackfin/kernel/cplb-nompu/Makefile‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,9 @@
22
# arch/blackfin/kernel/cplb-nompu/Makefile
33
#
44

5-
obj-y := cplbinit.o cacheinit.o cplbhdlr.o cplbmgr.o
5+
obj-y := cplbinit.o cacheinit.o cplbmgr.o
6+
7+
CFLAGS_cplbmgr.o := -ffixed-I0 -ffixed-I1 -ffixed-I2 -ffixed-I3 \
8+
-ffixed-L0 -ffixed-L1 -ffixed-L2 -ffixed-L3 \
9+
-ffixed-M0 -ffixed-M1 -ffixed-M2 -ffixed-M3 \
10+
-ffixed-B0 -ffixed-B1 -ffixed-B2 -ffixed-B3

0 commit comments

Comments
 (0)