Liu Yu-B13201 | 2e1ae9c | 2012-03-15 10:52:13 +0000 | [diff] [blame] | 1 | /* |
| 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> |
| 21 | #include <asm/epapr_hcalls.h> |
| 22 | #include <asm/cacheflush.h> |
| 23 | #include <asm/code-patching.h> |
Liu Yu-B13201 | 2f979de | 2012-07-03 05:48:53 +0000 | [diff] [blame] | 24 | #include <asm/machdep.h> |
| 25 | |
Stuart Yoder | f9294e9 | 2013-03-22 09:12:13 +0000 | [diff] [blame] | 26 | #if !defined(CONFIG_64BIT) || defined(CONFIG_PPC_BOOK3E_64) |
Liu Yu-B13201 | 2f979de | 2012-07-03 05:48:53 +0000 | [diff] [blame] | 27 | extern void epapr_ev_idle(void); |
| 28 | extern u32 epapr_ev_idle_start[]; |
Stuart Yoder | f9294e9 | 2013-03-22 09:12:13 +0000 | [diff] [blame] | 29 | #endif |
Liu Yu-B13201 | 2e1ae9c | 2012-03-15 10:52:13 +0000 | [diff] [blame] | 30 | |
| 31 | bool epapr_paravirt_enabled; |
| 32 | |
| 33 | static int __init epapr_paravirt_init(void) |
| 34 | { |
| 35 | struct device_node *hyper_node; |
| 36 | const u32 *insts; |
| 37 | int len, i; |
| 38 | |
| 39 | hyper_node = of_find_node_by_path("/hypervisor"); |
| 40 | if (!hyper_node) |
| 41 | return -ENODEV; |
| 42 | |
| 43 | insts = of_get_property(hyper_node, "hcall-instructions", &len); |
| 44 | if (!insts) |
| 45 | return -ENODEV; |
| 46 | |
| 47 | if (len % 4 || len > (4 * 4)) |
| 48 | return -ENODEV; |
| 49 | |
Liu Yu-B13201 | 2f979de | 2012-07-03 05:48:53 +0000 | [diff] [blame] | 50 | for (i = 0; i < (len / 4); i++) { |
Liu Yu-B13201 | 2e1ae9c | 2012-03-15 10:52:13 +0000 | [diff] [blame] | 51 | patch_instruction(epapr_hypercall_start + i, insts[i]); |
Stuart Yoder | f9294e9 | 2013-03-22 09:12:13 +0000 | [diff] [blame] | 52 | #if !defined(CONFIG_64BIT) || defined(CONFIG_PPC_BOOK3E_64) |
Liu Yu-B13201 | 2f979de | 2012-07-03 05:48:53 +0000 | [diff] [blame] | 53 | patch_instruction(epapr_ev_idle_start + i, insts[i]); |
Stuart Yoder | f9294e9 | 2013-03-22 09:12:13 +0000 | [diff] [blame] | 54 | #endif |
Liu Yu-B13201 | 2f979de | 2012-07-03 05:48:53 +0000 | [diff] [blame] | 55 | } |
| 56 | |
Stuart Yoder | f9294e9 | 2013-03-22 09:12:13 +0000 | [diff] [blame] | 57 | #if !defined(CONFIG_64BIT) || defined(CONFIG_PPC_BOOK3E_64) |
Liu Yu-B13201 | 2f979de | 2012-07-03 05:48:53 +0000 | [diff] [blame] | 58 | if (of_get_property(hyper_node, "has-idle", NULL)) |
| 59 | ppc_md.power_save = epapr_ev_idle; |
Stuart Yoder | f9294e9 | 2013-03-22 09:12:13 +0000 | [diff] [blame] | 60 | #endif |
Liu Yu-B13201 | 2e1ae9c | 2012-03-15 10:52:13 +0000 | [diff] [blame] | 61 | |
| 62 | epapr_paravirt_enabled = true; |
| 63 | |
| 64 | return 0; |
| 65 | } |
| 66 | |
| 67 | early_initcall(epapr_paravirt_init); |