| 1 | /* |
|---|
| 2 | * This program is free software; you can redistribute it and/or modify |
|---|
| 3 | * it under the terms of the GNU General Public License as published by |
|---|
| 4 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 5 | * (at your option) any later version. |
|---|
| 6 | * |
|---|
| 7 | * This program is distributed in the hope that it will be useful, |
|---|
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 10 | * GNU General Public License for more details. |
|---|
| 11 | * |
|---|
| 12 | * You should have received a copy of the GNU General Public License |
|---|
| 13 | * along with this program; if not, write to the Free Software |
|---|
| 14 | * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|---|
| 15 | * |
|---|
| 16 | * Copyright (C) IBM Corp. 2005 |
|---|
| 17 | * |
|---|
| 18 | * Authors: Jimi Xenidis <jimix@watson.ibm.com> |
|---|
| 19 | */ |
|---|
| 20 | |
|---|
| 21 | #include <xen/config.h> |
|---|
| 22 | #include <xen/types.h> |
|---|
| 23 | #include <xen/sched.h> |
|---|
| 24 | #include <xen/init.h> |
|---|
| 25 | #include <public/xen.h> |
|---|
| 26 | #include <asm/current.h> |
|---|
| 27 | #include <asm/papr.h> |
|---|
| 28 | #include <asm/hcalls.h> |
|---|
| 29 | |
|---|
| 30 | #define DABR_BT (1UL << 2) |
|---|
| 31 | #define DABR_DW (1UL << 1) |
|---|
| 32 | #define DABR_DR (1UL << 0) |
|---|
| 33 | |
|---|
| 34 | #define DABRX_BT (1UL << 3) |
|---|
| 35 | #define DABRX_HYP (1UL << 2) |
|---|
| 36 | #define DABRX_PNH (1UL << 1) |
|---|
| 37 | #define DABRX_PRO (1UL << 0) |
|---|
| 38 | |
|---|
| 39 | static inline int has_dabrx(void) { return 1; } |
|---|
| 40 | |
|---|
| 41 | static void h_set_dabr(struct cpu_user_regs *regs) |
|---|
| 42 | { |
|---|
| 43 | ulong dabr = regs->gprs[4]; |
|---|
| 44 | |
|---|
| 45 | if (!has_dabrx()) { |
|---|
| 46 | if (!(dabr & DABR_BT)) { |
|---|
| 47 | regs->gprs[3] = H_Parameter; |
|---|
| 48 | return; |
|---|
| 49 | } |
|---|
| 50 | } else { |
|---|
| 51 | asm volatile("mtspr %0,%1" : : "I" (SPRN_DABRX), "r" (2) : "memory"); |
|---|
| 52 | } |
|---|
| 53 | asm volatile("mtspr %0,%1" : : "I" (SPRN_DABR), "r" (dabr) : "memory"); |
|---|
| 54 | regs->gprs[3] = H_Success; |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | static void h_set_xdabr(struct cpu_user_regs *regs) |
|---|
| 58 | { |
|---|
| 59 | ulong dabr = regs->gprs[4]; |
|---|
| 60 | ulong dabrx = regs->gprs[5]; |
|---|
| 61 | |
|---|
| 62 | if (!has_dabrx()) { |
|---|
| 63 | regs->gprs[3] = H_Function; |
|---|
| 64 | return; |
|---|
| 65 | } |
|---|
| 66 | /* make sure reserved bits are 0 */ |
|---|
| 67 | if ((dabrx & ~((DABRX_BT << 1) - 1)) != 0) { |
|---|
| 68 | regs->gprs[3] = H_Parameter; |
|---|
| 69 | return; |
|---|
| 70 | } |
|---|
| 71 | if ((dabrx & DABRX_HYP) || dabrx == 0) { |
|---|
| 72 | regs->gprs[3] = H_Parameter; |
|---|
| 73 | return; |
|---|
| 74 | } |
|---|
| 75 | asm volatile("mtspr %0,%1; mtspr %2,%3" |
|---|
| 76 | : /* output */ : |
|---|
| 77 | "I" (SPRN_DABR), "r" (dabr), |
|---|
| 78 | "I" (SPRN_DABRX), "r" (dabrx) : "memory"); |
|---|
| 79 | |
|---|
| 80 | regs->gprs[3] = H_Success; |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | __init_papr_hcall(H_SET_DABR, h_set_dabr); |
|---|
| 84 | __init_papr_hcall(H_SET_XDABR, h_set_xdabr); |
|---|