1 /*
2 * SPAPR definitions and declarations
3 *
4 * Borrowed heavily from QEMU's spapr.h,
5 * Copyright (c) 2010 David Gibson, IBM Corporation.
6 *
7 * Modifications by Matt Evans <matt@ozlabs.org>, IBM Corporation.
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License version 2 as published
11 * by the Free Software Foundation.
12 */
13
14 #if !defined(__HW_SPAPR_H__)
15 #define __HW_SPAPR_H__
16
17 #include <inttypes.h>
18 #include <linux/byteorder.h>
19
20 #include "kvm/kvm.h"
21 #include "kvm/kvm-cpu.h"
22
23 typedef unsigned long target_ulong;
24 typedef uintptr_t target_phys_addr_t;
25
26 #define H_SUCCESS 0
27 #define H_HARDWARE -1 /* Hardware error */
28 #define H_FUNCTION -2 /* Function not supported */
29 #define H_PARAMETER -4 /* Parameter invalid, out-of-range or conflicting */
30 #define H_P2 -55
31 #define H_SET_DABR 0x28
32 #define H_LOGICAL_CI_LOAD 0x3c
33 #define H_LOGICAL_CI_STORE 0x40
34 #define H_LOGICAL_CACHE_LOAD 0x44
35 #define H_LOGICAL_CACHE_STORE 0x48
36 #define H_LOGICAL_ICBI 0x4c
37 #define H_LOGICAL_DCBF 0x50
38 #define H_GET_TERM_CHAR 0x54
39 #define H_PUT_TERM_CHAR 0x58
40 #define H_CPPR 0x68
41 #define H_EOI 0x64
42 #define H_IPI 0x6c
43 #define H_XIRR 0x74
44 #define H_SET_MODE 0x31C
45 #define MAX_HCALL_OPCODE H_SET_MODE
46
47 /* Values for 2nd argument to H_SET_MODE */
48 #define H_SET_MODE_RESOURCE_SET_CIABR 1
49 #define H_SET_MODE_RESOURCE_SET_DAWR 2
50 #define H_SET_MODE_RESOURCE_ADDR_TRANS_MODE 3
51 #define H_SET_MODE_RESOURCE_LE 4
52
53 /* Flags for H_SET_MODE_RESOURCE_LE */
54 #define H_SET_MODE_ENDIAN_BIG 0
55 #define H_SET_MODE_ENDIAN_LITTLE 1
56
57 /*
58 * The hcalls above are standardized in PAPR and implemented by pHyp
59 * as well.
60 *
61 * We also need some hcalls which are specific to qemu / KVM-on-POWER.
62 * So far we just need one for H_RTAS, but in future we'll need more
63 * for extensions like virtio. We put those into the 0xf000-0xfffc
64 * range which is reserved by PAPR for "platform-specific" hcalls.
65 */
66 #define KVMPPC_HCALL_BASE 0xf000
67 #define KVMPPC_H_RTAS (KVMPPC_HCALL_BASE + 0x0)
68 #define KVMPPC_HCALL_MAX KVMPPC_H_RTAS
69
70 #define DEBUG_SPAPR_HCALLS
71
72 #ifdef DEBUG_SPAPR_HCALLS
73 #define hcall_dprintf(fmt, ...) \
74 do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)
75 #else
76 #define hcall_dprintf(fmt, ...) \
77 do { } while (0)
78 #endif
79
80 typedef target_ulong (*spapr_hcall_fn)(struct kvm_cpu *vcpu,
81 target_ulong opcode,
82 target_ulong *args);
83
84 void hypercall_init(void);
85 void register_core_rtas(void);
86
87 void spapr_register_hypercall(target_ulong opcode, spapr_hcall_fn fn);
88 target_ulong spapr_hypercall(struct kvm_cpu *vcpu, target_ulong opcode,
89 target_ulong *args);
90
91 int spapr_rtas_fdt_setup(struct kvm *kvm, void *fdt);
92
rtas_ld(struct kvm * kvm,target_ulong phys,int n)93 static inline uint32_t rtas_ld(struct kvm *kvm, target_ulong phys, int n)
94 {
95 return cpu_to_be32(*((uint32_t *)guest_flat_to_host(kvm, phys + 4*n)));
96 }
97
rtas_st(struct kvm * kvm,target_ulong phys,int n,uint32_t val)98 static inline void rtas_st(struct kvm *kvm, target_ulong phys, int n, uint32_t val)
99 {
100 *((uint32_t *)guest_flat_to_host(kvm, phys + 4*n)) = cpu_to_be32(val);
101 }
102
103 typedef void (*spapr_rtas_fn)(struct kvm_cpu *vcpu, uint32_t token,
104 uint32_t nargs, target_ulong args,
105 uint32_t nret, target_ulong rets);
106 void spapr_rtas_register(const char *name, spapr_rtas_fn fn);
107 target_ulong spapr_rtas_call(struct kvm_cpu *vcpu,
108 uint32_t token, uint32_t nargs, target_ulong args,
109 uint32_t nret, target_ulong rets);
110
111 #define SPAPR_PCI_BUID 0x800000020000001ULL
112 #define SPAPR_PCI_MEM_WIN_ADDR (KVM_MMIO_START + 0xA0000000)
113 #define SPAPR_PCI_MEM_WIN_SIZE 0x20000000
114 #define SPAPR_PCI_IO_WIN_ADDR (SPAPR_PCI_MEM_WIN_ADDR + SPAPR_PCI_MEM_WIN_SIZE)
115 #define SPAPR_PCI_IO_WIN_SIZE 0x2000000
116
117 #define SPAPR_PCI_WIN_START SPAPR_PCI_MEM_WIN_ADDR
118 #define SPAPR_PCI_WIN_END (SPAPR_PCI_IO_WIN_ADDR + SPAPR_PCI_IO_WIN_SIZE)
119
120 #endif /* !defined (__HW_SPAPR_H__) */
121