aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/lib/feature-fixups.c
blob: f6fd5d2ff10deb14d2e9741c30c2eda40f338af8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
 *  Copyright (C) 2001 Ben. Herrenschmidt (benh@kernel.crashing.org)
 *
 *  Modifications for ppc64:
 *      Copyright (C) 2003 Dave Engebretsen <engebret@us.ibm.com>
 *
 *  Copyright 2008 Michael Ellerman, IBM Corporation.
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version
 *  2 of the License, or (at your option) any later version.
 */

#include <linux/kernel.h>
#include <asm/cputable.h>
#include <asm/code-patching.h>


struct fixup_entry {
	unsigned long	mask;
	unsigned long	value;
	long		start_off;
	long		end_off;
};

static void patch_feature_section(unsigned long value, struct fixup_entry *fcur)
{
	unsigned int *pstart, *pend, *p;

	if ((value & fcur->mask) == fcur->value)
		return;

	pstart = ((unsigned int *)fcur) + (fcur->start_off / 4);
	pend = ((unsigned int *)fcur) + (fcur->end_off / 4);

	for (p = pstart; p < pend; p++) {
		*p = PPC_NOP_INSTR;
		asm volatile ("dcbst 0, %0" : : "r" (p));
	}
	asm volatile ("sync" : : : "memory");
	for (p = pstart; p < pend; p++)
		asm volatile ("icbi 0,%0" : : "r" (p));
	asm volatile ("sync; isync" : : : "memory");
}

void do_feature_fixups(unsigned long value, void *fixup_start, void *fixup_end)
{
	struct fixup_entry *fcur, *fend;

	fcur = fixup_start;
	fend = fixup_end;

	for (; fcur < fend; fcur++)
		patch_feature_section(value, fcur);
}