Liu Yu-B13201 | 2e1ae9c0 | 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> |
Rob Herring | 26a2056 | 2013-09-26 07:40:04 -0500 | [diff] [blame] | 21 | #include <linux/of_fdt.h> |
Liu Yu-B13201 | 2e1ae9c0 | 2012-03-15 10:52:13 +0000 | [diff] [blame] | 22 | #include <asm/epapr_hcalls.h> |
| 23 | #include <asm/cacheflush.h> |
| 24 | #include <asm/code-patching.h> |
Liu Yu-B13201 | 2f979de | 2012-07-03 05:48:53 +0000 | [diff] [blame] | 25 | #include <asm/machdep.h> |
| 26 | |
Stuart Yoder | f9294e9 | 2013-03-22 09:12:13 +0000 | [diff] [blame] | 27 | #if !defined(CONFIG_64BIT) || defined(CONFIG_PPC_BOOK3E_64) |
Liu Yu-B13201 | 2f979de | 2012-07-03 05:48:53 +0000 | [diff] [blame] | 28 | extern void epapr_ev_idle(void); |
| 29 | extern u32 epapr_ev_idle_start[]; |
Stuart Yoder | f9294e9 | 2013-03-22 09:12:13 +0000 | [diff] [blame] | 30 | #endif |
Liu Yu-B13201 | 2e1ae9c0 | 2012-03-15 10:52:13 +0000 | [diff] [blame] | 31 | |
| 32 | bool epapr_paravirt_enabled; |
| 33 | |
Laurentiu TUDOR | 4e21b94 | 2013-07-03 17:13:15 +0300 | [diff] [blame] | 34 | static int __init early_init_dt_scan_epapr(unsigned long node, |
| 35 | const char *uname, |
| 36 | int depth, void *data) |
Liu Yu-B13201 | 2e1ae9c0 | 2012-03-15 10:52:13 +0000 | [diff] [blame] | 37 | { |
Liu Yu-B13201 | 2e1ae9c0 | 2012-03-15 10:52:13 +0000 | [diff] [blame] | 38 | const u32 *insts; |
Laurentiu TUDOR | 4e21b94 | 2013-07-03 17:13:15 +0300 | [diff] [blame] | 39 | unsigned long len; |
| 40 | int i; |
Liu Yu-B13201 | 2e1ae9c0 | 2012-03-15 10:52:13 +0000 | [diff] [blame] | 41 | |
Laurentiu TUDOR | 4e21b94 | 2013-07-03 17:13:15 +0300 | [diff] [blame] | 42 | insts = of_get_flat_dt_prop(node, "hcall-instructions", &len); |
Liu Yu-B13201 | 2e1ae9c0 | 2012-03-15 10:52:13 +0000 | [diff] [blame] | 43 | if (!insts) |
Laurentiu TUDOR | 4e21b94 | 2013-07-03 17:13:15 +0300 | [diff] [blame] | 44 | return 0; |
Liu Yu-B13201 | 2e1ae9c0 | 2012-03-15 10:52:13 +0000 | [diff] [blame] | 45 | |
| 46 | if (len % 4 || len > (4 * 4)) |
Laurentiu TUDOR | 4e21b94 | 2013-07-03 17:13:15 +0300 | [diff] [blame] | 47 | return -1; |
Liu Yu-B13201 | 2e1ae9c0 | 2012-03-15 10:52:13 +0000 | [diff] [blame] | 48 | |
Liu Yu-B13201 | 2f979de | 2012-07-03 05:48:53 +0000 | [diff] [blame] | 49 | for (i = 0; i < (len / 4); i++) { |
Alexander Graf | 235959b | 2014-05-13 16:44:09 +0200 | [diff] [blame^] | 50 | u32 inst = be32_to_cpu(insts[i]); |
| 51 | patch_instruction(epapr_hypercall_start + i, inst); |
Stuart Yoder | f9294e9 | 2013-03-22 09:12:13 +0000 | [diff] [blame] | 52 | #if !defined(CONFIG_64BIT) || defined(CONFIG_PPC_BOOK3E_64) |
Alexander Graf | 235959b | 2014-05-13 16:44:09 +0200 | [diff] [blame^] | 53 | patch_instruction(epapr_ev_idle_start + i, inst); |
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) |
Laurentiu TUDOR | 4e21b94 | 2013-07-03 17:13:15 +0300 | [diff] [blame] | 58 | if (of_get_flat_dt_prop(node, "has-idle", NULL)) |
Liu Yu-B13201 | 2f979de | 2012-07-03 05:48:53 +0000 | [diff] [blame] | 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 | 2e1ae9c0 | 2012-03-15 10:52:13 +0000 | [diff] [blame] | 61 | |
| 62 | epapr_paravirt_enabled = true; |
| 63 | |
Laurentiu TUDOR | 4e21b94 | 2013-07-03 17:13:15 +0300 | [diff] [blame] | 64 | return 1; |
| 65 | } |
| 66 | |
| 67 | int __init epapr_paravirt_early_init(void) |
| 68 | { |
| 69 | of_scan_flat_dt(early_init_dt_scan_epapr, NULL); |
| 70 | |
Liu Yu-B13201 | 2e1ae9c0 | 2012-03-15 10:52:13 +0000 | [diff] [blame] | 71 | return 0; |
| 72 | } |
| 73 | |