Skip to content

Commit e02db0a

Browse files
committed
microblaze: Handle TLB skip size dynamically
This patch fix the problem with rootfs on JFFS2 with early printk console turned on. The origin version used TLB63 for temporary early printk mapping. The code expect that kernel is not able to use all 64 TLB entries till early printk console is remapped by ioremap. After that temporary mapping on TLB63 is silently lost. This expectation give the opportunity to have early console pretty early. Microblaze systems with JFFS2 rootfs with early printk console turned on used more than 64 TLB entries before kernel can remap early console. Based on that kernel does access to bad area because early printk mapping is rewritten. This patch introduces tlb_skip variable which dynamically stores number of skipped TLB entries from the TLB0. skip_tlb=2 means that TLB0 and TLB1 should be skipped. MICROBLAZE_TLB_SKIP defines how many TLB is skipped at the kernel start. They can be used for user purpose. TLB 63 is used for temporary LMB mapping (MICROBLAZE_LMB_TLB_ID). Also clean TLBLO when kernel starts. For specific kernel sizes kernel can use just one TLB. Detect this case and use the second TLB for general purpose. Change _tlbia function to flush TLB entries from tlb_skip to TLB_SIZE. Export tlb_skip size through debugfs. Signed-off-by: Michal Simek <monstr@monstr.eu>
1 parent 1451d1d commit e02db0a

6 files changed

Lines changed: 83 additions & 22 deletions

File tree

‎arch/microblaze/include/asm/mmu.h‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ typedef struct _SEGREG {
5656

5757
extern void _tlbie(unsigned long va); /* invalidate a TLB entry */
5858
extern void _tlbia(void); /* invalidate all TLB entries */
59+
60+
/*
61+
* tlb_skip size stores actual number skipped TLBs from TLB0 - every directy TLB
62+
* mapping has to increase tlb_skip size.
63+
*/
64+
extern u32 tlb_skip;
5965
# endif /* __ASSEMBLY__ */
6066

6167
/*
@@ -68,7 +74,12 @@ extern void _tlbia(void); /* invalidate all TLB entries */
6874
*/
6975

7076
# define MICROBLAZE_TLB_SIZE 64
71-
# define MICROBLAZE_TLB_SKIP 2
77+
78+
/* For cases when you want to skip some TLB entries */
79+
# define MICROBLAZE_TLB_SKIP 0
80+
81+
/* Use the last TLB for temporary access to LMB */
82+
# define MICROBLAZE_LMB_TLB_ID 63
7283

7384
/*
7485
* TLB entries are defined by a "high" tag portion and a "low" data

‎arch/microblaze/kernel/early_printk.c‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,20 @@ void __init remap_early_printk(void)
175175
base_addr);
176176
base_addr = (u32) ioremap(base_addr, PAGE_SIZE);
177177
printk(KERN_CONT "0x%x\n", base_addr);
178+
179+
/*
180+
* Early console is on the top of skipped TLB entries
181+
* decrease tlb_skip size ensure that hardcoded TLB entry will be
182+
* used by generic algorithm
183+
* FIXME check if early console mapping is on the top by rereading
184+
* TLB entry and compare baseaddr
185+
* mts rtlbx, (tlb_skip - 1)
186+
* nop
187+
* mfs rX, rtlblo
188+
* nop
189+
* cmp rX, orig_base_addr
190+
*/
191+
tlb_skip -= 1;
178192
}
179193

180194
void __init disable_early_printk(void)

‎arch/microblaze/kernel/head.S‎

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ _copy_bram:
149149
_invalidate:
150150
mts rtlbx, r3
151151
mts rtlbhi, r0 /* flush: ensure V is clear */
152+
mts rtlblo, r0
152153
bgtid r3, _invalidate /* loop for all entries */
153154
addik r3, r3, -1
154155
/* sync */
@@ -224,8 +225,14 @@ tlb_end:
224225
andi r4,r4,0xfffffc00 /* Mask off the real page number */
225226
ori r4,r4,(TLB_WR | TLB_EX) /* Set the write and execute bits */
226227

227-
/* TLB0 can be zeroes that's why we not setup it */
228-
beqi r9, jump_over
228+
/*
229+
* TLB0 is always used - check if is not zero (r9 stores TLB0 value)
230+
* if is use TLB1 value and clear it (r10 stores TLB1 value)
231+
*/
232+
bnei r9, tlb0_not_zero
233+
add r9, r10, r0
234+
add r10, r0, r0
235+
tlb0_not_zero:
229236

230237
/* look at the code below */
231238
ori r30, r0, 0x200
@@ -239,18 +246,21 @@ tlb_end:
239246
bneid r29, 1f
240247
addik r30, r30, 0x80
241248
1:
242-
ori r11, r30, 0
243-
244249
andi r3,r3,0xfffffc00 /* Mask off the effective page number */
245250
ori r3,r3,(TLB_VALID)
246-
or r3, r3, r11
251+
or r3, r3, r30
247252

248-
mts rtlbx,r0 /* TLB slow 0 */
253+
/* Load tlb_skip size value which is index to first unused TLB entry */
254+
lwi r11, r0, TOPHYS(tlb_skip)
255+
mts rtlbx,r11 /* TLB slow 0 */
249256

250257
mts rtlblo,r4 /* Load the data portion of the entry */
251258
mts rtlbhi,r3 /* Load the tag portion of the entry */
252259

253-
jump_over:
260+
/* Increase tlb_skip size */
261+
addik r11, r11, 1
262+
swi r11, r0, TOPHYS(tlb_skip)
263+
254264
/* TLB1 can be zeroes that's why we not setup it */
255265
beqi r10, jump_over2
256266

@@ -266,27 +276,30 @@ jump_over:
266276
bneid r29, 1f
267277
addik r30, r30, 0x80
268278
1:
269-
ori r12, r30, 0
270-
271279
addk r4, r4, r9 /* previous addr + TLB0 size */
272280
addk r3, r3, r9
273281

274282
andi r3,r3,0xfffffc00 /* Mask off the effective page number */
275283
ori r3,r3,(TLB_VALID)
276-
or r3, r3, r12
284+
or r3, r3, r30
277285

278-
ori r6,r0,1 /* TLB slot 1 */
279-
mts rtlbx,r6
286+
lwi r11, r0, TOPHYS(tlb_skip)
287+
mts rtlbx, r11 /* r11 is used from TLB0 */
280288

281289
mts rtlblo,r4 /* Load the data portion of the entry */
282290
mts rtlbhi,r3 /* Load the tag portion of the entry */
283291

292+
/* Increase tlb_skip size */
293+
addik r11, r11, 1
294+
swi r11, r0, TOPHYS(tlb_skip)
295+
284296
jump_over2:
285297
/*
286298
* Load a TLB entry for LMB, since we need access to
287299
* the exception vectors, using a 4k real==virtual mapping.
288300
*/
289-
ori r6,r0,3 /* TLB slot 3 */
301+
/* Use temporary TLB_ID for LMB - clear this temporary mapping later */
302+
ori r6, r0, MICROBLAZE_LMB_TLB_ID
290303
mts rtlbx,r6
291304

292305
ori r4,r0,(TLB_WR | TLB_EX)
@@ -355,8 +368,7 @@ start_here:
355368

356369
/* Load up the kernel context */
357370
kernel_load_context:
358-
# Keep entry 0 and 1 valid. Entry 3 mapped to LMB can go away.
359-
ori r5,r0,3
371+
ori r5, r0, MICROBLAZE_LMB_TLB_ID
360372
mts rtlbx,r5
361373
nop
362374
mts rtlbhi,r0

‎arch/microblaze/kernel/hw_exception_handler.S‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -820,9 +820,15 @@ ex_handler_done:
820820
* Upon exit, we reload everything and RFI.
821821
* A common place to load the TLB.
822822
*/
823+
.section .data
824+
.align 4
825+
.global tlb_skip
826+
tlb_skip:
827+
.long MICROBLAZE_TLB_SKIP
823828
tlb_index:
824829
/* MS: storing last used tlb index */
825-
.long (MICROBLAZE_TLB_SKIP - 1)
830+
.long MICROBLAZE_TLB_SIZE/2
831+
.previous
826832
finish_tlb_load:
827833
/* MS: load the last used TLB index. */
828834
lwi r5, r0, TOPHYS(tlb_index)
@@ -833,7 +839,7 @@ ex_handler_done:
833839
ori r6, r0, 1
834840
cmp r31, r5, r6
835841
blti r31, ex12
836-
addik r5, r6, MICROBLAZE_TLB_SKIP - 1
842+
lwi r5, r0, TOPHYS(tlb_skip)
837843
ex12:
838844
/* MS: save back current TLB index */
839845
swi r5, r0, TOPHYS(tlb_index)

‎arch/microblaze/kernel/misc.S‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@
2929
.type _tlbia, @function
3030
.align 4;
3131
_tlbia:
32-
addik r12, r0, MICROBLAZE_TLB_SIZE - 1 /* flush all entries (63 - 3) */
32+
lwi r12, r0, tlb_skip;
3333
/* isync */
3434
_tlbia_1:
3535
mts rtlbx, r12
3636
nop
3737
mts rtlbhi, r0 /* flush: ensure V is clear */
3838
nop
39-
addik r11, r12, -MICROBLAZE_TLB_SKIP
39+
rsubi r11, r12, MICROBLAZE_TLB_SIZE - 1
4040
bneid r11, _tlbia_1 /* loop for all entries */
41-
addik r12, r12, -1
41+
addik r12, r12, 1
4242
/* sync */
4343
rtsd r15, 8
4444
nop
@@ -75,7 +75,7 @@ early_console_reg_tlb_alloc:
7575
* Load a TLB entry for the UART, so that microblaze_progress() can use
7676
* the UARTs nice and early. We use a 4k real==virtual mapping.
7777
*/
78-
ori r4, r0, 63
78+
lwi r4, r0, tlb_skip
7979
mts rtlbx, r4 /* TLB slot 63 */
8080

8181
or r4,r5,r0
@@ -89,6 +89,11 @@ early_console_reg_tlb_alloc:
8989
nop
9090
mts rtlbhi,r5 /* Load the tag portion of the entry */
9191
nop
92+
93+
lwi r5, r0, tlb_skip
94+
addik r5, r5, 1
95+
swi r5, r0, tlb_skip
96+
9297
rtsd r15, 8
9398
nop
9499

‎arch/microblaze/kernel/setup.c‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,19 @@ static int microblaze_debugfs_init(void)
208208
return of_debugfs_root == NULL;
209209
}
210210
arch_initcall(microblaze_debugfs_init);
211+
212+
static int __init debugfs_tlb(void)
213+
{
214+
struct dentry *d;
215+
216+
if (!of_debugfs_root)
217+
return -ENODEV;
218+
219+
d = debugfs_create_u32("tlb_skip", S_IRUGO, of_debugfs_root, &tlb_skip);
220+
if (!d)
221+
return -ENOMEM;
222+
}
223+
device_initcall(debugfs_tlb);
211224
#endif
212225

213226
static int dflt_bus_notify(struct notifier_block *nb,

0 commit comments

Comments
 (0)