Skip to content

Commit

Permalink
parisc: Refactor alternative code to accept multiple conditions
Browse files Browse the repository at this point in the history
Allow the alternative loop to accept multiple conditions when replacing
existing code, e.g.
	ALTERNATIVE(ALT_COND_NO_SMP | ALT_COND_RUN_ON_QEMU, INSN_NOP)

Signed-off-by: Helge Deller <deller@gmx.de>
  • Loading branch information
Helge Deller committed Apr 5, 2020
1 parent fbdc8f0 commit 2a3778e
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions arch/parisc/kernel/alternative.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
struct alt_instr *entry;
int index = 0, applied = 0;
int num_cpus = num_online_cpus();
u32 cond_check;

cond_check = ALT_COND_ALWAYS |
((num_cpus == 1) ? ALT_COND_NO_SMP : 0) |
((cache_info.dc_size == 0) ? ALT_COND_NO_DCACHE : 0) |
((cache_info.ic_size == 0) ? ALT_COND_NO_ICACHE : 0) |
(running_on_qemu ? ALT_COND_RUN_ON_QEMU : 0) |
((split_tlb == 0) ? ALT_COND_NO_SPLIT_TLB : 0) |
/*
* If the PDC_MODEL capabilities has Non-coherent IO-PDIR bit
* set (bit #61, big endian), we have to flush and sync every
* time IO-PDIR is changed in Ike/Astro.
*/
(((boot_cpu_data.cpu_type > pcxw_) &&
((boot_cpu_data.pdc.capabilities & PDC_MODEL_IOPDIR_FDC) == 0))
? ALT_COND_NO_IOC_FDC : 0);

for (entry = start; entry < end; entry++, index++) {

Expand All @@ -38,29 +54,14 @@ void __init_or_module apply_alternatives(struct alt_instr *start,

WARN_ON(!cond);

if (cond != ALT_COND_ALWAYS && no_alternatives)
if ((cond & ALT_COND_ALWAYS) == 0 && no_alternatives)
continue;

pr_debug("Check %d: Cond 0x%x, Replace %02d instructions @ 0x%px with 0x%08x\n",
index, cond, len, from, replacement);

if ((cond & ALT_COND_NO_SMP) && (num_cpus != 1))
continue;
if ((cond & ALT_COND_NO_DCACHE) && (cache_info.dc_size != 0))
continue;
if ((cond & ALT_COND_NO_ICACHE) && (cache_info.ic_size != 0))
continue;
if ((cond & ALT_COND_RUN_ON_QEMU) && !running_on_qemu)
continue;

/*
* If the PDC_MODEL capabilities has Non-coherent IO-PDIR bit
* set (bit #61, big endian), we have to flush and sync every
* time IO-PDIR is changed in Ike/Astro.
*/
if ((cond & ALT_COND_NO_IOC_FDC) &&
((boot_cpu_data.cpu_type <= pcxw_) ||
(boot_cpu_data.pdc.capabilities & PDC_MODEL_IOPDIR_FDC)))
/* Bounce out if none of the conditions are true. */
if ((cond & cond_check) == 0)
continue;

/* Want to replace pdtlb by a pdtlb,l instruction? */
Expand Down

0 comments on commit 2a3778e

Please sign in to comment.