blob: 59e4ba74975d9cf6be38ffa9312d2cbe6572a829 [file] [log] [blame]
Liu Yu-B132012e1ae9c02012-03-15 10:52:13 +00001/*
2 * ePAPR para-virtualization support.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2, as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 *
17 * Copyright (C) 2012 Freescale Semiconductor, Inc.
18 */
19
20#include <linux/of.h>
Rob Herring26a20562013-09-26 07:40:04 -050021#include <linux/of_fdt.h>
Liu Yu-B132012e1ae9c02012-03-15 10:52:13 +000022#include <asm/epapr_hcalls.h>
23#include <asm/cacheflush.h>
24#include <asm/code-patching.h>
Liu Yu-B132012f979de2012-07-03 05:48:53 +000025#include <asm/machdep.h>
26
Stuart Yoderf9294e92013-03-22 09:12:13 +000027#if !defined(CONFIG_64BIT) || defined(CONFIG_PPC_BOOK3E_64)
Liu Yu-B132012f979de2012-07-03 05:48:53 +000028extern void epapr_ev_idle(void);
29extern u32 epapr_ev_idle_start[];
Stuart Yoderf9294e92013-03-22 09:12:13 +000030#endif
Liu Yu-B132012e1ae9c02012-03-15 10:52:13 +000031
32bool epapr_paravirt_enabled;
Scott Wood8067bd82014-05-15 11:28:26 -050033static bool __maybe_unused epapr_has_idle;
Liu Yu-B132012e1ae9c02012-03-15 10:52:13 +000034
Laurentiu TUDOR4e21b942013-07-03 17:13:15 +030035static int __init early_init_dt_scan_epapr(unsigned long node,
36 const char *uname,
37 int depth, void *data)
Liu Yu-B132012e1ae9c02012-03-15 10:52:13 +000038{
Liu Yu-B132012e1ae9c02012-03-15 10:52:13 +000039 const u32 *insts;
Rob Herring9d0c4df2014-04-01 23:49:03 -050040 int len;
Laurentiu TUDOR4e21b942013-07-03 17:13:15 +030041 int i;
Liu Yu-B132012e1ae9c02012-03-15 10:52:13 +000042
Laurentiu TUDOR4e21b942013-07-03 17:13:15 +030043 insts = of_get_flat_dt_prop(node, "hcall-instructions", &len);
Liu Yu-B132012e1ae9c02012-03-15 10:52:13 +000044 if (!insts)
Laurentiu TUDOR4e21b942013-07-03 17:13:15 +030045 return 0;
Liu Yu-B132012e1ae9c02012-03-15 10:52:13 +000046
47 if (len % 4 || len > (4 * 4))
Laurentiu TUDOR4e21b942013-07-03 17:13:15 +030048 return -1;
Liu Yu-B132012e1ae9c02012-03-15 10:52:13 +000049
Liu Yu-B132012f979de2012-07-03 05:48:53 +000050 for (i = 0; i < (len / 4); i++) {
Alexander Graf235959b2014-05-13 16:44:09 +020051 u32 inst = be32_to_cpu(insts[i]);
52 patch_instruction(epapr_hypercall_start + i, inst);
Stuart Yoderf9294e92013-03-22 09:12:13 +000053#if !defined(CONFIG_64BIT) || defined(CONFIG_PPC_BOOK3E_64)
Alexander Graf235959b2014-05-13 16:44:09 +020054 patch_instruction(epapr_ev_idle_start + i, inst);
Stuart Yoderf9294e92013-03-22 09:12:13 +000055#endif
Liu Yu-B132012f979de2012-07-03 05:48:53 +000056 }
57
Stuart Yoderf9294e92013-03-22 09:12:13 +000058#if !defined(CONFIG_64BIT) || defined(CONFIG_PPC_BOOK3E_64)
Laurentiu TUDOR4e21b942013-07-03 17:13:15 +030059 if (of_get_flat_dt_prop(node, "has-idle", NULL))
Stuart Yoder83e267d2014-04-30 18:34:23 -050060 epapr_has_idle = true;
Stuart Yoderf9294e92013-03-22 09:12:13 +000061#endif
Liu Yu-B132012e1ae9c02012-03-15 10:52:13 +000062
63 epapr_paravirt_enabled = true;
64
Laurentiu TUDOR4e21b942013-07-03 17:13:15 +030065 return 1;
66}
67
68int __init epapr_paravirt_early_init(void)
69{
70 of_scan_flat_dt(early_init_dt_scan_epapr, NULL);
71
Liu Yu-B132012e1ae9c02012-03-15 10:52:13 +000072 return 0;
73}
74
Stuart Yoder83e267d2014-04-30 18:34:23 -050075static int __init epapr_idle_init(void)
76{
Scott Wood440d74d2014-05-12 10:05:19 -050077#if !defined(CONFIG_64BIT) || defined(CONFIG_PPC_BOOK3E_64)
Stuart Yoder83e267d2014-04-30 18:34:23 -050078 if (epapr_has_idle)
79 ppc_md.power_save = epapr_ev_idle;
Scott Wood440d74d2014-05-12 10:05:19 -050080#endif
Stuart Yoder83e267d2014-04-30 18:34:23 -050081
82 return 0;
83}
84
85postcore_initcall(epapr_idle_init);