epapr_paravirt.c 2.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/*
 * ePAPR para-virtualization support.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License, version 2, as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 * Copyright (C) 2012 Freescale Semiconductor, Inc.
 */

#include <linux/of.h>
R
Rob Herring 已提交
21
#include <linux/of_fdt.h>
22 23 24
#include <asm/epapr_hcalls.h>
#include <asm/cacheflush.h>
#include <asm/code-patching.h>
25 26
#include <asm/machdep.h>

27
#if !defined(CONFIG_64BIT) || defined(CONFIG_PPC_BOOK3E_64)
28 29
extern void epapr_ev_idle(void);
extern u32 epapr_ev_idle_start[];
30
#endif
31 32

bool epapr_paravirt_enabled;
33
static bool __maybe_unused epapr_has_idle;
34

35 36 37
static int __init early_init_dt_scan_epapr(unsigned long node,
					   const char *uname,
					   int depth, void *data)
38 39
{
	const u32 *insts;
40 41
	unsigned long len;
	int i;
42

43
	insts = of_get_flat_dt_prop(node, "hcall-instructions", &len);
44
	if (!insts)
45
		return 0;
46 47

	if (len % 4 || len > (4 * 4))
48
		return -1;
49

50
	for (i = 0; i < (len / 4); i++) {
51 52
		u32 inst = be32_to_cpu(insts[i]);
		patch_instruction(epapr_hypercall_start + i, inst);
53
#if !defined(CONFIG_64BIT) || defined(CONFIG_PPC_BOOK3E_64)
54
		patch_instruction(epapr_ev_idle_start + i, inst);
55
#endif
56 57
	}

58
#if !defined(CONFIG_64BIT) || defined(CONFIG_PPC_BOOK3E_64)
59
	if (of_get_flat_dt_prop(node, "has-idle", NULL))
60
		epapr_has_idle = true;
61
#endif
62 63 64

	epapr_paravirt_enabled = true;

65 66 67 68 69 70 71
	return 1;
}

int __init epapr_paravirt_early_init(void)
{
	of_scan_flat_dt(early_init_dt_scan_epapr, NULL);

72 73 74
	return 0;
}

75 76
static int __init epapr_idle_init(void)
{
77
#if !defined(CONFIG_64BIT) || defined(CONFIG_PPC_BOOK3E_64)
78 79
	if (epapr_has_idle)
		ppc_md.power_save = epapr_ev_idle;
80
#endif
81 82 83 84 85

	return 0;
}

postcore_initcall(epapr_idle_init);