Skip to content

Commit c68e5d3

Browse files
committed
sparc32: Implement hard_smp_processor_id() via instruction patching.
This is the last non-trivial user of btfixup. Like sparc64, use a special patch section to resolve the various implementations of how to read the current CPU's ID when we don't have current_thread_info()->cpu necessarily available. Signed-off-by: David S. Miller <davem@davemloft.net> Tested-by: Sam Ravnborg <sam@ravnborg.org>
1 parent 5d83d66 commit c68e5d3

10 files changed

Lines changed: 99 additions & 175 deletions

File tree

‎arch/sparc/include/asm/smp_32.h‎

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,9 @@ void smp_bogo(struct seq_file *);
5959
void smp_info(struct seq_file *);
6060

6161
BTFIXUPDEF_CALL(void, smp_cross_call, smpfunc_t, cpumask_t, unsigned long, unsigned long, unsigned long, unsigned long)
62-
BTFIXUPDEF_CALL(int, __hard_smp_processor_id, void)
6362
BTFIXUPDEF_CALL(void, smp_ipi_resched, int);
6463
BTFIXUPDEF_CALL(void, smp_ipi_single, int);
6564
BTFIXUPDEF_CALL(void, smp_ipi_mask_one, int);
66-
BTFIXUPDEF_BLACKBOX(hard_smp_processor_id)
67-
BTFIXUPDEF_BLACKBOX(load_current)
6865

6966
#define smp_cross_call(func,mask,arg1,arg2,arg3,arg4) BTFIXUP_CALL(smp_cross_call)(func,mask,arg1,arg2,arg3,arg4)
7067

@@ -117,45 +114,7 @@ extern inline int hard_smpleon_processor_id(void)
117114
return cpuid;
118115
}
119116

120-
#ifndef MODULE
121-
static inline int hard_smp_processor_id(void)
122-
{
123-
int cpuid;
124-
125-
/* Black box - sun4m
126-
__asm__ __volatile__("rd %%tbr, %0\n\t"
127-
"srl %0, 12, %0\n\t"
128-
"and %0, 3, %0\n\t" :
129-
"=&r" (cpuid));
130-
- sun4d
131-
__asm__ __volatile__("lda [%g0] ASI_M_VIKING_TMP1, %0\n\t"
132-
"nop; nop" :
133-
"=&r" (cpuid));
134-
- leon
135-
__asm__ __volatile__( "rd %asr17, %0\n\t"
136-
"srl %0, 0x1c, %0\n\t"
137-
"nop\n\t" :
138-
"=&r" (cpuid));
139-
See btfixup.h and btfixupprep.c to understand how a blackbox works.
140-
*/
141-
__asm__ __volatile__("sethi %%hi(___b_hard_smp_processor_id), %0\n\t"
142-
"sethi %%hi(boot_cpu_id), %0\n\t"
143-
"ldub [%0 + %%lo(boot_cpu_id)], %0\n\t" :
144-
"=&r" (cpuid));
145-
return cpuid;
146-
}
147-
#else
148-
static inline int hard_smp_processor_id(void)
149-
{
150-
int cpuid;
151-
152-
__asm__ __volatile__("mov %%o7, %%g1\n\t"
153-
"call ___f___hard_smp_processor_id\n\t"
154-
" nop\n\t"
155-
"mov %%g2, %0\n\t" : "=r"(cpuid) : : "g1", "g2");
156-
return cpuid;
157-
}
158-
#endif
117+
extern int hard_smp_processor_id(void);
159118

160119
#define raw_smp_processor_id() (current_thread_info()->cpu)
161120

‎arch/sparc/include/asm/winmacro.h‎

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -103,37 +103,24 @@
103103
st %scratch, [%cur_reg + TI_W_SAVED];
104104

105105
#ifdef CONFIG_SMP
106-
/* Results of LOAD_CURRENT() after BTFIXUP for SUN4M, SUN4D & LEON (comments) */
107-
#define LOAD_CURRENT4M(dest_reg, idreg) \
108-
rd %tbr, %idreg; \
109-
sethi %hi(current_set), %dest_reg; \
110-
srl %idreg, 10, %idreg; \
111-
or %dest_reg, %lo(current_set), %dest_reg; \
112-
and %idreg, 0xc, %idreg; \
113-
ld [%idreg + %dest_reg], %dest_reg;
114-
115-
#define LOAD_CURRENT4D(dest_reg, idreg) \
116-
lda [%g0] ASI_M_VIKING_TMP1, %idreg; \
117-
sethi %hi(C_LABEL(current_set)), %dest_reg; \
118-
sll %idreg, 2, %idreg; \
119-
or %dest_reg, %lo(C_LABEL(current_set)), %dest_reg; \
120-
ld [%idreg + %dest_reg], %dest_reg;
121-
122-
#define LOAD_CURRENT_LEON(dest_reg, idreg) \
123-
rd %asr17, %idreg; \
124-
sethi %hi(current_set), %dest_reg; \
125-
srl %idreg, 0x1c, %idreg; \
126-
or %dest_reg, %lo(current_set), %dest_reg; \
127-
sll %idreg, 0x2, %idreg; \
128-
ld [%idreg + %dest_reg], %dest_reg;
129-
130-
/* Blackbox - take care with this... - check smp4m and smp4d before changing this. */
131-
#define LOAD_CURRENT(dest_reg, idreg) \
132-
sethi %hi(___b_load_current), %idreg; \
133-
sethi %hi(current_set), %dest_reg; \
134-
sethi %hi(boot_cpu_id4), %idreg; \
135-
or %dest_reg, %lo(current_set), %dest_reg; \
136-
ldub [%idreg + %lo(boot_cpu_id4)], %idreg; \
106+
#define LOAD_CURRENT(dest_reg, idreg) \
107+
661: rd %tbr, %idreg; \
108+
srl %idreg, 10, %idreg; \
109+
and %idreg, 0xc, %idreg; \
110+
.section .cpuid_patch, "ax"; \
111+
/* Instruction location. */ \
112+
.word 661b; \
113+
/* SUN4D implementation. */ \
114+
lda [%g0] ASI_M_VIKING_TMP1, %idreg; \
115+
sll %idreg, 2, %idreg; \
116+
nop; \
117+
/* LEON implementation. */ \
118+
rd %asr17, %idreg; \
119+
srl %idreg, 0x1c, %idreg; \
120+
sll %idreg, 0x02, %idreg; \
121+
.previous; \
122+
sethi %hi(current_set), %dest_reg; \
123+
or %dest_reg, %lo(current_set), %dest_reg;\
137124
ld [%idreg + %dest_reg], %dest_reg;
138125
#else
139126
#define LOAD_CURRENT(dest_reg, idreg) \

‎arch/sparc/kernel/entry.S‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Copyright (C) 1997 Anton Blanchard (anton@progsoc.uts.edu.au)
88
*/
99

10+
#include <linux/linkage.h>
1011
#include <linux/errno.h>
1112

1213
#include <asm/head.h>
@@ -1347,4 +1348,26 @@ flushw_all:
13471348
ret
13481349
restore
13491350

1351+
#ifdef CONFIG_SMP
1352+
ENTRY(hard_smp_processor_id)
1353+
661: rd %tbr, %g1
1354+
srl %g1, 12, %o0
1355+
and %o0, 3, %o0
1356+
.section .cpuid_patch, "ax"
1357+
/* Instruction location. */
1358+
.word 661b
1359+
/* SUN4D implementation. */
1360+
lda [%g0] ASI_M_VIKING_TMP1, %o0
1361+
nop
1362+
nop
1363+
/* LEON implementation. */
1364+
rd %asr17, %o0
1365+
srl %o0, 0x1c, %o0
1366+
nop
1367+
.previous
1368+
retl
1369+
nop
1370+
ENDPROC(hard_smp_processor_id)
1371+
#endif
1372+
13501373
/* End of entry.S */

‎arch/sparc/kernel/kernel.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ extern unsigned int patchme_maybe_smp_msg[];
8080
extern void floppy_hardint(void);
8181

8282
/* trampoline_32.S */
83-
extern int __smp4m_processor_id(void);
84-
extern int __smp4d_processor_id(void);
8583
extern unsigned long sun4m_cpu_startup;
8684
extern unsigned long sun4d_cpu_startup;
8785

‎arch/sparc/kernel/leon_smp.c‎

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static inline unsigned long do_swap(volatile unsigned long *ptr,
7373

7474
void __cpuinit leon_callin(void)
7575
{
76-
int cpuid = hard_smpleon_processor_id();
76+
int cpuid = hard_smp_processor_id();
7777

7878
local_ops->cache_all();
7979
local_ops->tlb_all();
@@ -491,39 +491,12 @@ void leon_cross_call_irq(void)
491491
ccall_info.processors_out[i] = 1;
492492
}
493493

494-
void __init leon_blackbox_id(unsigned *addr)
495-
{
496-
int rd = *addr & 0x3e000000;
497-
int rs1 = rd >> 11;
498-
499-
/* patch places where ___b_hard_smp_processor_id appears */
500-
addr[0] = 0x81444000 | rd; /* rd %asr17, reg */
501-
addr[1] = 0x8130201c | rd | rs1; /* srl reg, 0x1c, reg */
502-
addr[2] = 0x01000000; /* nop */
503-
}
504-
505-
void __init leon_blackbox_current(unsigned *addr)
506-
{
507-
int rd = *addr & 0x3e000000;
508-
int rs1 = rd >> 11;
509-
510-
/* patch LOAD_CURRENT macro where ___b_load_current appears */
511-
addr[0] = 0x81444000 | rd; /* rd %asr17, reg */
512-
addr[2] = 0x8130201c | rd | rs1; /* srl reg, 0x1c, reg */
513-
addr[4] = 0x81282002 | rd | rs1; /* sll reg, 0x2, reg */
514-
515-
}
516-
517494
void __init leon_init_smp(void)
518495
{
519496
/* Patch ipi15 trap table */
520497
t_nmi[1] = t_nmi[1] + (linux_trap_ipi15_leon - linux_trap_ipi15_sun4m);
521498

522-
BTFIXUPSET_BLACKBOX(hard_smp_processor_id, leon_blackbox_id);
523-
BTFIXUPSET_BLACKBOX(load_current, leon_blackbox_current);
524499
BTFIXUPSET_CALL(smp_cross_call, leon_cross_call, BTFIXUPCALL_NORM);
525-
BTFIXUPSET_CALL(__hard_smp_processor_id, __leon_processor_id,
526-
BTFIXUPCALL_NORM);
527500
BTFIXUPSET_CALL(smp_ipi_resched, leon_ipi_resched, BTFIXUPCALL_NORM);
528501
BTFIXUPSET_CALL(smp_ipi_single, leon_ipi_single, BTFIXUPCALL_NORM);
529502
BTFIXUPSET_CALL(smp_ipi_mask_one, leon_ipi_mask_one, BTFIXUPCALL_NORM);

‎arch/sparc/kernel/setup_32.c‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,52 @@ extern int root_mountflags;
192192

193193
char reboot_command[COMMAND_LINE_SIZE];
194194

195+
struct cpuid_patch_entry {
196+
unsigned int addr;
197+
unsigned int sun4d[3];
198+
unsigned int leon[3];
199+
};
200+
extern struct cpuid_patch_entry __cpuid_patch, __cpuid_patch_end;
201+
202+
static void __init per_cpu_patch(void)
203+
{
204+
struct cpuid_patch_entry *p;
205+
206+
if (sparc_cpu_model == sun4m) {
207+
/* Nothing to do, this is what the unpatched code
208+
* targets.
209+
*/
210+
return;
211+
}
212+
213+
p = &__cpuid_patch;
214+
while (p < &__cpuid_patch_end) {
215+
unsigned long addr = p->addr;
216+
unsigned int *insns;
217+
218+
switch (sparc_cpu_model) {
219+
case sun4d:
220+
insns = &p->sun4d[0];
221+
break;
222+
223+
case sparc_leon:
224+
insns = &p->leon[0];
225+
break;
226+
default:
227+
prom_printf("Unknown cpu type, halting.\n");
228+
prom_halt();
229+
}
230+
*(unsigned int *) (addr + 0) = insns[0];
231+
*(unsigned int *) (addr + 4) = insns[1];
232+
*(unsigned int *) (addr + 8) = insns[2];
233+
}
234+
#ifdef CONFIG_SMP
235+
local_ops->cache_all();
236+
#else
237+
sparc32_cachetlb_ops->cache_all();
238+
#endif
239+
}
240+
195241
enum sparc_cpu sparc_cpu_model;
196242
EXPORT_SYMBOL(sparc_cpu_model);
197243

@@ -295,6 +341,11 @@ void __init setup_arch(char **cmdline_p)
295341

296342
paging_init();
297343

344+
/* Now that we have the cache ops hooked up, we can patch
345+
* instructions.
346+
*/
347+
per_cpu_patch();
348+
298349
smp_setup_cpu_possible_map();
299350
}
300351

‎arch/sparc/kernel/sparc_ksyms_32.c‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,5 @@ EXPORT_SYMBOL(__ndelay);
2828
EXPORT_SYMBOL(__ret_efault);
2929
EXPORT_SYMBOL(empty_zero_page);
3030

31-
/* Defined using magic */
32-
#ifdef CONFIG_SMP
33-
EXPORT_SYMBOL(BTFIXUP_CALL(__hard_smp_processor_id));
34-
#endif
35-
3631
/* Exporting a symbol from /init/main.c */
3732
EXPORT_SYMBOL(saved_command_line);

‎arch/sparc/kernel/sun4d_smp.c‎

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ static inline void show_leds(int cpuid)
5252

5353
void __cpuinit smp4d_callin(void)
5454
{
55-
int cpuid = hard_smp4d_processor_id();
55+
int cpuid = hard_smp_processor_id();
5656
unsigned long flags;
5757

5858
/* Show we are alive */
@@ -354,7 +354,7 @@ static void smp4d_cross_call(smpfunc_t func, cpumask_t mask, unsigned long arg1,
354354
/* Running cross calls. */
355355
void smp4d_cross_call_irq(void)
356356
{
357-
int i = hard_smp4d_processor_id();
357+
int i = hard_smp_processor_id();
358358

359359
ccall_info.processors_in[i] = 1;
360360
ccall_info.func(ccall_info.arg1, ccall_info.arg2, ccall_info.arg3,
@@ -365,7 +365,7 @@ void smp4d_cross_call_irq(void)
365365
void smp4d_percpu_timer_interrupt(struct pt_regs *regs)
366366
{
367367
struct pt_regs *old_regs;
368-
int cpu = hard_smp4d_processor_id();
368+
int cpu = hard_smp_processor_id();
369369
struct clock_event_device *ce;
370370
static int cpu_tick[NR_CPUS];
371371
static char led_mask[] = { 0xe, 0xd, 0xb, 0x7, 0xb, 0xd };
@@ -391,24 +391,6 @@ void smp4d_percpu_timer_interrupt(struct pt_regs *regs)
391391
set_irq_regs(old_regs);
392392
}
393393

394-
void __init smp4d_blackbox_id(unsigned *addr)
395-
{
396-
int rd = *addr & 0x3e000000;
397-
398-
addr[0] = 0xc0800800 | rd; /* lda [%g0] ASI_M_VIKING_TMP1, reg */
399-
addr[1] = 0x01000000; /* nop */
400-
addr[2] = 0x01000000; /* nop */
401-
}
402-
403-
void __init smp4d_blackbox_current(unsigned *addr)
404-
{
405-
int rd = *addr & 0x3e000000;
406-
407-
addr[0] = 0xc0800800 | rd; /* lda [%g0] ASI_M_VIKING_TMP1, reg */
408-
addr[2] = 0x81282002 | rd | (rd >> 11); /* sll reg, 2, reg */
409-
addr[4] = 0x01000000; /* nop */
410-
}
411-
412394
void __init sun4d_init_smp(void)
413395
{
414396
int i;
@@ -417,10 +399,7 @@ void __init sun4d_init_smp(void)
417399
t_nmi[1] = t_nmi[1] + (linux_trap_ipi15_sun4d - linux_trap_ipi15_sun4m);
418400

419401
/* And set btfixup... */
420-
BTFIXUPSET_BLACKBOX(hard_smp_processor_id, smp4d_blackbox_id);
421-
BTFIXUPSET_BLACKBOX(load_current, smp4d_blackbox_current);
422402
BTFIXUPSET_CALL(smp_cross_call, smp4d_cross_call, BTFIXUPCALL_NORM);
423-
BTFIXUPSET_CALL(__hard_smp_processor_id, __smp4d_processor_id, BTFIXUPCALL_NORM);
424403
BTFIXUPSET_CALL(smp_ipi_resched, smp4d_ipi_resched, BTFIXUPCALL_NORM);
425404
BTFIXUPSET_CALL(smp_ipi_single, smp4d_ipi_single, BTFIXUPCALL_NORM);
426405
BTFIXUPSET_CALL(smp_ipi_mask_one, smp4d_ipi_mask_one, BTFIXUPCALL_NORM);

‎arch/sparc/kernel/sun4m_smp.c‎

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -281,32 +281,9 @@ void smp4m_percpu_timer_interrupt(struct pt_regs *regs)
281281
set_irq_regs(old_regs);
282282
}
283283

284-
static void __init smp4m_blackbox_id(unsigned *addr)
285-
{
286-
int rd = *addr & 0x3e000000;
287-
int rs1 = rd >> 11;
288-
289-
addr[0] = 0x81580000 | rd; /* rd %tbr, reg */
290-
addr[1] = 0x8130200c | rd | rs1; /* srl reg, 0xc, reg */
291-
addr[2] = 0x80082003 | rd | rs1; /* and reg, 3, reg */
292-
}
293-
294-
static void __init smp4m_blackbox_current(unsigned *addr)
295-
{
296-
int rd = *addr & 0x3e000000;
297-
int rs1 = rd >> 11;
298-
299-
addr[0] = 0x81580000 | rd; /* rd %tbr, reg */
300-
addr[2] = 0x8130200a | rd | rs1; /* srl reg, 0xa, reg */
301-
addr[4] = 0x8008200c | rd | rs1; /* and reg, 0xc, reg */
302-
}
303-
304284
void __init sun4m_init_smp(void)
305285
{
306-
BTFIXUPSET_BLACKBOX(hard_smp_processor_id, smp4m_blackbox_id);
307-
BTFIXUPSET_BLACKBOX(load_current, smp4m_blackbox_current);
308286
BTFIXUPSET_CALL(smp_cross_call, smp4m_cross_call, BTFIXUPCALL_NORM);
309-
BTFIXUPSET_CALL(__hard_smp_processor_id, __smp4m_processor_id, BTFIXUPCALL_NORM);
310287
BTFIXUPSET_CALL(smp_ipi_resched, smp4m_ipi_resched, BTFIXUPCALL_NORM);
311288
BTFIXUPSET_CALL(smp_ipi_single, smp4m_ipi_single, BTFIXUPCALL_NORM);
312289
BTFIXUPSET_CALL(smp_ipi_mask_one, smp4m_ipi_mask_one, BTFIXUPCALL_NORM);

0 commit comments

Comments
 (0)