1*be76823fSMatt Evans /* 2*be76823fSMatt Evans * SPAPR definitions and declarations 3*be76823fSMatt Evans * 4*be76823fSMatt Evans * Borrowed heavily from QEMU's spapr.h, 5*be76823fSMatt Evans * Copyright (c) 2010 David Gibson, IBM Corporation. 6*be76823fSMatt Evans * 7*be76823fSMatt Evans * Modifications by Matt Evans <matt@ozlabs.org>, IBM Corporation. 8*be76823fSMatt Evans * 9*be76823fSMatt Evans * This program is free software; you can redistribute it and/or modify it 10*be76823fSMatt Evans * under the terms of the GNU General Public License version 2 as published 11*be76823fSMatt Evans * by the Free Software Foundation. 12*be76823fSMatt Evans */ 13*be76823fSMatt Evans 14*be76823fSMatt Evans #if !defined(__HW_SPAPR_H__) 15*be76823fSMatt Evans #define __HW_SPAPR_H__ 16*be76823fSMatt Evans 17*be76823fSMatt Evans #include <inttypes.h> 18*be76823fSMatt Evans 19*be76823fSMatt Evans /* We need some of the H_ hcall defs, but they're __KERNEL__ only. */ 20*be76823fSMatt Evans #define __KERNEL__ 21*be76823fSMatt Evans #include <asm/hvcall.h> 22*be76823fSMatt Evans #undef __KERNEL__ 23*be76823fSMatt Evans 24*be76823fSMatt Evans #include "kvm/kvm.h" 25*be76823fSMatt Evans #include "kvm/kvm-cpu.h" 26*be76823fSMatt Evans 27*be76823fSMatt Evans typedef unsigned long target_ulong; 28*be76823fSMatt Evans typedef uintptr_t target_phys_addr_t; 29*be76823fSMatt Evans 30*be76823fSMatt Evans /* 31*be76823fSMatt Evans * The hcalls above are standardized in PAPR and implemented by pHyp 32*be76823fSMatt Evans * as well. 33*be76823fSMatt Evans * 34*be76823fSMatt Evans * We also need some hcalls which are specific to qemu / KVM-on-POWER. 35*be76823fSMatt Evans * So far we just need one for H_RTAS, but in future we'll need more 36*be76823fSMatt Evans * for extensions like virtio. We put those into the 0xf000-0xfffc 37*be76823fSMatt Evans * range which is reserved by PAPR for "platform-specific" hcalls. 38*be76823fSMatt Evans */ 39*be76823fSMatt Evans #define KVMPPC_HCALL_BASE 0xf000 40*be76823fSMatt Evans #define KVMPPC_H_RTAS (KVMPPC_HCALL_BASE + 0x0) 41*be76823fSMatt Evans #define KVMPPC_HCALL_MAX KVMPPC_H_RTAS 42*be76823fSMatt Evans 43*be76823fSMatt Evans #define DEBUG_SPAPR_HCALLS 44*be76823fSMatt Evans 45*be76823fSMatt Evans #ifdef DEBUG_SPAPR_HCALLS 46*be76823fSMatt Evans #define hcall_dprintf(fmt, ...) \ 47*be76823fSMatt Evans do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0) 48*be76823fSMatt Evans #else 49*be76823fSMatt Evans #define hcall_dprintf(fmt, ...) \ 50*be76823fSMatt Evans do { } while (0) 51*be76823fSMatt Evans #endif 52*be76823fSMatt Evans 53*be76823fSMatt Evans typedef target_ulong (*spapr_hcall_fn)(struct kvm_cpu *vcpu, 54*be76823fSMatt Evans target_ulong opcode, 55*be76823fSMatt Evans target_ulong *args); 56*be76823fSMatt Evans 57*be76823fSMatt Evans void hypercall_init(void); 58*be76823fSMatt Evans void register_core_rtas(void); 59*be76823fSMatt Evans 60*be76823fSMatt Evans void spapr_register_hypercall(target_ulong opcode, spapr_hcall_fn fn); 61*be76823fSMatt Evans target_ulong spapr_hypercall(struct kvm_cpu *vcpu, target_ulong opcode, 62*be76823fSMatt Evans target_ulong *args); 63*be76823fSMatt Evans 64*be76823fSMatt Evans int spapr_rtas_fdt_setup(struct kvm *kvm, void *fdt); 65*be76823fSMatt Evans 66*be76823fSMatt Evans static inline uint32_t rtas_ld(struct kvm *kvm, target_ulong phys, int n) 67*be76823fSMatt Evans { 68*be76823fSMatt Evans return *((uint32_t *)guest_flat_to_host(kvm, phys + 4*n)); 69*be76823fSMatt Evans } 70*be76823fSMatt Evans 71*be76823fSMatt Evans static inline void rtas_st(struct kvm *kvm, target_ulong phys, int n, uint32_t val) 72*be76823fSMatt Evans { 73*be76823fSMatt Evans *((uint32_t *)guest_flat_to_host(kvm, phys + 4*n)) = val; 74*be76823fSMatt Evans } 75*be76823fSMatt Evans 76*be76823fSMatt Evans typedef void (*spapr_rtas_fn)(struct kvm_cpu *vcpu, uint32_t token, 77*be76823fSMatt Evans uint32_t nargs, target_ulong args, 78*be76823fSMatt Evans uint32_t nret, target_ulong rets); 79*be76823fSMatt Evans void spapr_rtas_register(const char *name, spapr_rtas_fn fn); 80*be76823fSMatt Evans target_ulong spapr_rtas_call(struct kvm_cpu *vcpu, 81*be76823fSMatt Evans uint32_t token, uint32_t nargs, target_ulong args, 82*be76823fSMatt Evans uint32_t nret, target_ulong rets); 83*be76823fSMatt Evans 84*be76823fSMatt Evans #endif /* !defined (__HW_SPAPR_H__) */ 85