xref: /qemu/include/hw/ppc/spapr.h (revision f03496bc123df4d5a595fd4aa2113786c313e41e)
12a6a4076SMarkus Armbruster #ifndef HW_SPAPR_H
22a6a4076SMarkus Armbruster #define HW_SPAPR_H
39fdf0c29SDavid Gibson 
4ab3dd749SPhilippe Mathieu-Daudé #include "qemu/units.h"
59c17d615SPaolo Bonzini #include "sysemu/dma.h"
628e02042SDavid Gibson #include "hw/boards.h"
731fe14d1SNathan Fontenot #include "hw/ppc/spapr_drc.h"
84a1c9cf0SBharata B Rao #include "hw/mem/pc-dimm.h"
9facdb8b6SMichael Roth #include "hw/ppc/spapr_ovec.h"
1082cffa2eSCédric Le Goater #include "hw/ppc/spapr_irq.h"
11ce2918cbSDavid Gibson #include "hw/ppc/spapr_xive.h"  /* For SpaprXive */
120d8d6a24SThomas Huth #include "hw/ppc/xics.h"        /* For ICSState */
130fb6bd07SMichael Roth #include "hw/ppc/spapr_tpm_proxy.h"
14277f9acfSPaolo Bonzini 
15ce2918cbSDavid Gibson struct SpaprVioBus;
16ce2918cbSDavid Gibson struct SpaprPhbState;
17ce2918cbSDavid Gibson struct SpaprNvram;
180d8d6a24SThomas Huth 
19ce2918cbSDavid Gibson typedef struct SpaprEventLogEntry SpaprEventLogEntry;
20ce2918cbSDavid Gibson typedef struct SpaprEventSource SpaprEventSource;
21ce2918cbSDavid Gibson typedef struct SpaprPendingHpt SpaprPendingHpt;
224040ab72SDavid Gibson 
234be21d56SDavid Gibson #define HPTE64_V_HPTE_DIRTY     0x0000000000000040ULL
241b718907SDavid Gibson #define SPAPR_ENTRY_POINT       0x100
254be21d56SDavid Gibson 
26afd10a0fSBharata B Rao #define SPAPR_TIMEBASE_FREQ     512000000ULL
27afd10a0fSBharata B Rao 
28147ff807SCédric Le Goater #define TYPE_SPAPR_RTC "spapr-rtc"
29147ff807SCédric Le Goater 
30147ff807SCédric Le Goater #define SPAPR_RTC(obj)                                  \
31ce2918cbSDavid Gibson     OBJECT_CHECK(SpaprRtcState, (obj), TYPE_SPAPR_RTC)
32147ff807SCédric Le Goater 
33ce2918cbSDavid Gibson typedef struct SpaprRtcState SpaprRtcState;
34ce2918cbSDavid Gibson struct SpaprRtcState {
35147ff807SCédric Le Goater     /*< private >*/
36147ff807SCédric Le Goater     DeviceState parent_obj;
37147ff807SCédric Le Goater     int64_t ns_offset;
38147ff807SCédric Le Goater };
39147ff807SCédric Le Goater 
40ce2918cbSDavid Gibson typedef struct SpaprDimmState SpaprDimmState;
41ce2918cbSDavid Gibson typedef struct SpaprMachineClass SpaprMachineClass;
4228e02042SDavid Gibson 
4328e02042SDavid Gibson #define TYPE_SPAPR_MACHINE      "spapr-machine"
4428e02042SDavid Gibson #define SPAPR_MACHINE(obj) \
45ce2918cbSDavid Gibson     OBJECT_CHECK(SpaprMachineState, (obj), TYPE_SPAPR_MACHINE)
46183930c0SDavid Gibson #define SPAPR_MACHINE_GET_CLASS(obj) \
47ce2918cbSDavid Gibson     OBJECT_GET_CLASS(SpaprMachineClass, obj, TYPE_SPAPR_MACHINE)
48183930c0SDavid Gibson #define SPAPR_MACHINE_CLASS(klass) \
49ce2918cbSDavid Gibson     OBJECT_CLASS_CHECK(SpaprMachineClass, klass, TYPE_SPAPR_MACHINE)
50183930c0SDavid Gibson 
5130f4b05bSDavid Gibson typedef enum {
5230f4b05bSDavid Gibson     SPAPR_RESIZE_HPT_DEFAULT = 0,
5330f4b05bSDavid Gibson     SPAPR_RESIZE_HPT_DISABLED,
5430f4b05bSDavid Gibson     SPAPR_RESIZE_HPT_ENABLED,
5530f4b05bSDavid Gibson     SPAPR_RESIZE_HPT_REQUIRED,
56ce2918cbSDavid Gibson } SpaprResizeHpt;
5730f4b05bSDavid Gibson 
58183930c0SDavid Gibson /**
5933face6bSDavid Gibson  * Capabilities
6033face6bSDavid Gibson  */
6133face6bSDavid Gibson 
62ee76a09fSDavid Gibson /* Hardware Transactional Memory */
634e5fe368SSuraj Jitindar Singh #define SPAPR_CAP_HTM                   0x00
6429386642SDavid Gibson /* Vector Scalar Extensions */
654e5fe368SSuraj Jitindar Singh #define SPAPR_CAP_VSX                   0x01
662d1fb9bcSDavid Gibson /* Decimal Floating Point */
674e5fe368SSuraj Jitindar Singh #define SPAPR_CAP_DFP                   0x02
688f38eaf8SSuraj Jitindar Singh /* Cache Flush on Privilege Change */
698f38eaf8SSuraj Jitindar Singh #define SPAPR_CAP_CFPC                  0x03
7009114fd8SSuraj Jitindar Singh /* Speculation Barrier Bounds Checking */
7109114fd8SSuraj Jitindar Singh #define SPAPR_CAP_SBBC                  0x04
724be8d4e7SSuraj Jitindar Singh /* Indirect Branch Serialisation */
734be8d4e7SSuraj Jitindar Singh #define SPAPR_CAP_IBS                   0x05
742309832aSDavid Gibson /* HPT Maximum Page Size (encoded as a shift) */
752309832aSDavid Gibson #define SPAPR_CAP_HPT_MAXPAGESIZE       0x06
76b9a477b7SSuraj Jitindar Singh /* Nested KVM-HV */
77b9a477b7SSuraj Jitindar Singh #define SPAPR_CAP_NESTED_KVM_HV         0x07
78c982f5cfSSuraj Jitindar Singh /* Large Decrementer */
79c982f5cfSSuraj Jitindar Singh #define SPAPR_CAP_LARGE_DECREMENTER     0x08
808ff43ee4SSuraj Jitindar Singh /* Count Cache Flush Assist HW Instruction */
818ff43ee4SSuraj Jitindar Singh #define SPAPR_CAP_CCF_ASSIST            0x09
829d953ce4SAravinda Prasad /* FWNMI machine check handling */
839d953ce4SAravinda Prasad #define SPAPR_CAP_FWNMI_MCE             0x0A
844e5fe368SSuraj Jitindar Singh /* Num Caps */
859d953ce4SAravinda Prasad #define SPAPR_CAP_NUM                   (SPAPR_CAP_FWNMI_MCE + 1)
864e5fe368SSuraj Jitindar Singh 
874e5fe368SSuraj Jitindar Singh /*
884e5fe368SSuraj Jitindar Singh  * Capability Values
894e5fe368SSuraj Jitindar Singh  */
904e5fe368SSuraj Jitindar Singh /* Bool Caps */
914e5fe368SSuraj Jitindar Singh #define SPAPR_CAP_OFF                   0x00
924e5fe368SSuraj Jitindar Singh #define SPAPR_CAP_ON                    0x01
93399b2896SSuraj Jitindar Singh 
94c76c0d30SSuraj Jitindar Singh /* Custom Caps */
95399b2896SSuraj Jitindar Singh 
96399b2896SSuraj Jitindar Singh /* Generic */
976898aed7SSuraj Jitindar Singh #define SPAPR_CAP_BROKEN                0x00
986898aed7SSuraj Jitindar Singh #define SPAPR_CAP_WORKAROUND            0x01
996898aed7SSuraj Jitindar Singh #define SPAPR_CAP_FIXED                 0x02
100399b2896SSuraj Jitindar Singh /* SPAPR_CAP_IBS (cap-ibs) */
101c76c0d30SSuraj Jitindar Singh #define SPAPR_CAP_FIXED_IBS             0x02
102c76c0d30SSuraj Jitindar Singh #define SPAPR_CAP_FIXED_CCD             0x03
103399b2896SSuraj Jitindar Singh #define SPAPR_CAP_FIXED_NA              0x10 /* Lets leave a bit of a gap... */
1042d1fb9bcSDavid Gibson 
105ce2918cbSDavid Gibson typedef struct SpaprCapabilities SpaprCapabilities;
106ce2918cbSDavid Gibson struct SpaprCapabilities {
1074e5fe368SSuraj Jitindar Singh     uint8_t caps[SPAPR_CAP_NUM];
10833face6bSDavid Gibson };
10933face6bSDavid Gibson 
11033face6bSDavid Gibson /**
111ce2918cbSDavid Gibson  * SpaprMachineClass:
112183930c0SDavid Gibson  */
113ce2918cbSDavid Gibson struct SpaprMachineClass {
114183930c0SDavid Gibson     /*< private >*/
115183930c0SDavid Gibson     MachineClass parent_class;
116183930c0SDavid Gibson 
117183930c0SDavid Gibson     /*< public >*/
118224245bfSDavid Gibson     bool dr_lmb_enabled;       /* enable dynamic-reconfig/hotplug of LMBs */
119962b6c36SMichael Roth     bool dr_phb_enabled;       /* enable dynamic-reconfig/hotplug of PHBs */
120fea35ca4SAlexey Kardashevskiy     bool update_dt_enabled;    /* enable KVMPPC_H_UPDATE_DT */
12157040d45SThomas Huth     bool use_ohci_by_default;  /* use USB-OHCI instead of XHCI */
12246f7afa3SGreg Kurz     bool pre_2_10_has_unused_icps;
12382cffa2eSCédric Le Goater     bool legacy_irq_allocation;
12454255c1fSDavid Gibson     uint32_t nr_xirqs;
1250a794529SDavid Gibson     bool broken_host_serial_model; /* present real host info to the guest */
1263725ef1aSGreg Kurz     bool pre_4_1_migration; /* don't migrate hpt-max-page-size */
1276c3829a2SAlexey Kardashevskiy     bool linux_pci_probe;
12829cb4187SGreg Kurz     bool smp_threads_vsmt; /* set VSMT to smp_threads by default */
12982cffa2eSCédric Le Goater 
130ce2918cbSDavid Gibson     void (*phb_placement)(SpaprMachineState *spapr, uint32_t index,
131daa23699SDavid Gibson                           uint64_t *buid, hwaddr *pio,
132daa23699SDavid Gibson                           hwaddr *mmio32, hwaddr *mmio64,
133ec132efaSAlexey Kardashevskiy                           unsigned n_dma, uint32_t *liobns, hwaddr *nv2gpa,
134ec132efaSAlexey Kardashevskiy                           hwaddr *nv2atsd, Error **errp);
135ce2918cbSDavid Gibson     SpaprResizeHpt resize_hpt_default;
136ce2918cbSDavid Gibson     SpaprCapabilities default_caps;
137ce2918cbSDavid Gibson     SpaprIrq *irq;
138183930c0SDavid Gibson };
13928e02042SDavid Gibson 
14028e02042SDavid Gibson /**
141ce2918cbSDavid Gibson  * SpaprMachineState:
14228e02042SDavid Gibson  */
143ce2918cbSDavid Gibson struct SpaprMachineState {
14428e02042SDavid Gibson     /*< private >*/
14528e02042SDavid Gibson     MachineState parent_obj;
14628e02042SDavid Gibson 
147ce2918cbSDavid Gibson     struct SpaprVioBus *vio_bus;
148ce2918cbSDavid Gibson     QLIST_HEAD(, SpaprPhbState) phbs;
149ce2918cbSDavid Gibson     struct SpaprNvram *nvram;
150ce2918cbSDavid Gibson     SpaprRtcState rtc;
151a3467baaSDavid Gibson 
152ce2918cbSDavid Gibson     SpaprResizeHpt resize_hpt;
153a3467baaSDavid Gibson     void *htab;
1544be21d56SDavid Gibson     uint32_t htab_shift;
1559861bb3eSSuraj Jitindar Singh     uint64_t patb_entry; /* Process tbl registed in H_REGISTER_PROCESS_TABLE */
156ce2918cbSDavid Gibson     SpaprPendingHpt *pending_hpt; /* in-progress resize */
1570b0b8310SDavid Gibson 
158a8170e5eSAvi Kivity     hwaddr rma_size;
1597f763a5dSDavid Gibson     int vrma_adjust;
160fea35ca4SAlexey Kardashevskiy     uint32_t fdt_size;
161fea35ca4SAlexey Kardashevskiy     uint32_t fdt_initial_size;
162fea35ca4SAlexey Kardashevskiy     void *fdt_blob;
163a19f7fb0SDavid Gibson     long kernel_size;
164a19f7fb0SDavid Gibson     bool kernel_le;
165a19f7fb0SDavid Gibson     uint32_t initrd_base;
166a19f7fb0SDavid Gibson     long initrd_size;
167880ae7deSDavid Gibson     uint64_t rtc_offset; /* Now used only during incoming migration */
16898a8b524SAlexey Kardashevskiy     struct PPCTimebase tb;
1693fc5acdeSAlexander Graf     bool has_graphics;
170fa98fbfcSSam Bobroff     uint32_t vsmt;       /* Virtual SMT mode (KVM's "core stride") */
17174d042e5SDavid Gibson 
17274d042e5SDavid Gibson     Notifier epow_notifier;
173ce2918cbSDavid Gibson     QTAILQ_HEAD(, SpaprEventLogEntry) pending_events;
174ffbb1705SMichael Roth     bool use_hotplug_event_source;
175ce2918cbSDavid Gibson     SpaprEventSource *event_sources;
1764be21d56SDavid Gibson 
1777843c0d6SDavid Gibson     /* ibm,client-architecture-support option negotiation */
1787843c0d6SDavid Gibson     bool cas_reboot;
179daa36379SDavid Gibson     bool cas_pre_isa3_guest;
180ce2918cbSDavid Gibson     SpaprOptionVector *ov5;         /* QEMU-supported option vectors */
181ce2918cbSDavid Gibson     SpaprOptionVector *ov5_cas;     /* negotiated (via CAS) option vectors */
1827843c0d6SDavid Gibson     uint32_t max_compat_pvr;
1837843c0d6SDavid Gibson 
1844be21d56SDavid Gibson     /* Migration state */
1854be21d56SDavid Gibson     int htab_save_index;
1864be21d56SDavid Gibson     bool htab_first_pass;
187e68cb8b4SAlexey Kardashevskiy     int htab_fd;
18846503c2bSMichael Roth 
1890cffce56SDavid Gibson     /* Pending DIMM unplug cache. It is populated when a LMB
1900cffce56SDavid Gibson      * unplug starts. It can be regenerated if a migration
1910cffce56SDavid Gibson      * occurs during the unplug process. */
192ce2918cbSDavid Gibson     QTAILQ_HEAD(, SpaprDimmState) pending_dimm_unplugs;
1930cffce56SDavid Gibson 
1949ac703acSAravinda Prasad     /* State related to "ibm,nmi-register" and "ibm,nmi-interlock" calls */
1959ac703acSAravinda Prasad     target_ulong guest_machine_check_addr;
1969ac703acSAravinda Prasad     /*
1979ac703acSAravinda Prasad      * mc_status is set to -1 if mc is not in progress, else is set to the CPU
1989ac703acSAravinda Prasad      * handling the mc.
1999ac703acSAravinda Prasad      */
2009ac703acSAravinda Prasad     int mc_status;
2019ac703acSAravinda Prasad     QemuCond mc_delivery_cond;
2029ac703acSAravinda Prasad 
20328e02042SDavid Gibson     /*< public >*/
20428e02042SDavid Gibson     char *kvm_type;
20527461d69SPrasad J Pandit     char *host_model;
20627461d69SPrasad J Pandit     char *host_serial;
207852ad27eSCédric Le Goater 
20882cffa2eSCédric Le Goater     int32_t irq_map_nr;
20982cffa2eSCédric Le Goater     unsigned long *irq_map;
210ce2918cbSDavid Gibson     SpaprIrq *irq;
211872ff3deSCédric Le Goater     qemu_irq *qirqs;
21281106dddSDavid Gibson     SpaprInterruptController *active_intc;
21381106dddSDavid Gibson     ICSState *ics;
21481106dddSDavid Gibson     SpaprXive *xive;
21533face6bSDavid Gibson 
2164e5fe368SSuraj Jitindar Singh     bool cmd_line_caps[SPAPR_CAP_NUM];
217ce2918cbSDavid Gibson     SpaprCapabilities def, eff, mig;
218ec132efaSAlexey Kardashevskiy 
219ec132efaSAlexey Kardashevskiy     unsigned gpu_numa_id;
2200fb6bd07SMichael Roth     SpaprTpmProxy *tpm_proxy;
22128e02042SDavid Gibson };
2229fdf0c29SDavid Gibson 
2239fdf0c29SDavid Gibson #define H_SUCCESS         0
2249fdf0c29SDavid Gibson #define H_BUSY            1        /* Hardware busy -- retry later */
2259fdf0c29SDavid Gibson #define H_CLOSED          2        /* Resource closed */
2269fdf0c29SDavid Gibson #define H_NOT_AVAILABLE   3
2279fdf0c29SDavid Gibson #define H_CONSTRAINED     4        /* Resource request constrained to max allowed */
2289fdf0c29SDavid Gibson #define H_PARTIAL         5
2299fdf0c29SDavid Gibson #define H_IN_PROGRESS     14       /* Kind of like busy */
2309fdf0c29SDavid Gibson #define H_PAGE_REGISTERED 15
2319fdf0c29SDavid Gibson #define H_PARTIAL_STORE   16
2329fdf0c29SDavid Gibson #define H_PENDING         17       /* returned from H_POLL_PENDING */
2339fdf0c29SDavid Gibson #define H_CONTINUE        18       /* Returned from H_Join on success */
2349fdf0c29SDavid Gibson #define H_LONG_BUSY_START_RANGE         9900  /* Start of long busy range */
2359fdf0c29SDavid Gibson #define H_LONG_BUSY_ORDER_1_MSEC        9900  /* Long busy, hint that 1msec \
2369fdf0c29SDavid Gibson                                                  is a good time to retry */
2379fdf0c29SDavid Gibson #define H_LONG_BUSY_ORDER_10_MSEC       9901  /* Long busy, hint that 10msec \
2389fdf0c29SDavid Gibson                                                  is a good time to retry */
2399fdf0c29SDavid Gibson #define H_LONG_BUSY_ORDER_100_MSEC      9902  /* Long busy, hint that 100msec \
2409fdf0c29SDavid Gibson                                                  is a good time to retry */
2419fdf0c29SDavid Gibson #define H_LONG_BUSY_ORDER_1_SEC         9903  /* Long busy, hint that 1sec \
2429fdf0c29SDavid Gibson                                                  is a good time to retry */
2439fdf0c29SDavid Gibson #define H_LONG_BUSY_ORDER_10_SEC        9904  /* Long busy, hint that 10sec \
2449fdf0c29SDavid Gibson                                                  is a good time to retry */
2459fdf0c29SDavid Gibson #define H_LONG_BUSY_ORDER_100_SEC       9905  /* Long busy, hint that 100sec \
2469fdf0c29SDavid Gibson                                                  is a good time to retry */
2479fdf0c29SDavid Gibson #define H_LONG_BUSY_END_RANGE           9905  /* End of long busy range */
2489fdf0c29SDavid Gibson #define H_HARDWARE        -1       /* Hardware error */
2499fdf0c29SDavid Gibson #define H_FUNCTION        -2       /* Function not supported */
2509fdf0c29SDavid Gibson #define H_PRIVILEGE       -3       /* Caller not privileged */
2519fdf0c29SDavid Gibson #define H_PARAMETER       -4       /* Parameter invalid, out-of-range or conflicting */
2529fdf0c29SDavid Gibson #define H_BAD_MODE        -5       /* Illegal msr value */
2539fdf0c29SDavid Gibson #define H_PTEG_FULL       -6       /* PTEG is full */
2549fdf0c29SDavid Gibson #define H_NOT_FOUND       -7       /* PTE was not found" */
2559fdf0c29SDavid Gibson #define H_RESERVED_DABR   -8       /* DABR address is reserved by the hypervisor on this processor" */
2569fdf0c29SDavid Gibson #define H_NO_MEM          -9
2579fdf0c29SDavid Gibson #define H_AUTHORITY       -10
2589fdf0c29SDavid Gibson #define H_PERMISSION      -11
2599fdf0c29SDavid Gibson #define H_DROPPED         -12
2609fdf0c29SDavid Gibson #define H_SOURCE_PARM     -13
2619fdf0c29SDavid Gibson #define H_DEST_PARM       -14
2629fdf0c29SDavid Gibson #define H_REMOTE_PARM     -15
2639fdf0c29SDavid Gibson #define H_RESOURCE        -16
2649fdf0c29SDavid Gibson #define H_ADAPTER_PARM    -17
2659fdf0c29SDavid Gibson #define H_RH_PARM         -18
2669fdf0c29SDavid Gibson #define H_RCQ_PARM        -19
2679fdf0c29SDavid Gibson #define H_SCQ_PARM        -20
2689fdf0c29SDavid Gibson #define H_EQ_PARM         -21
2699fdf0c29SDavid Gibson #define H_RT_PARM         -22
2709fdf0c29SDavid Gibson #define H_ST_PARM         -23
2719fdf0c29SDavid Gibson #define H_SIGT_PARM       -24
2729fdf0c29SDavid Gibson #define H_TOKEN_PARM      -25
2739fdf0c29SDavid Gibson #define H_MLENGTH_PARM    -27
2749fdf0c29SDavid Gibson #define H_MEM_PARM        -28
2759fdf0c29SDavid Gibson #define H_MEM_ACCESS_PARM -29
2769fdf0c29SDavid Gibson #define H_ATTR_PARM       -30
2779fdf0c29SDavid Gibson #define H_PORT_PARM       -31
2789fdf0c29SDavid Gibson #define H_MCG_PARM        -32
2799fdf0c29SDavid Gibson #define H_VL_PARM         -33
2809fdf0c29SDavid Gibson #define H_TSIZE_PARM      -34
2819fdf0c29SDavid Gibson #define H_TRACE_PARM      -35
2829fdf0c29SDavid Gibson 
2839fdf0c29SDavid Gibson #define H_MASK_PARM       -37
2849fdf0c29SDavid Gibson #define H_MCG_FULL        -38
2859fdf0c29SDavid Gibson #define H_ALIAS_EXIST     -39
2869fdf0c29SDavid Gibson #define H_P_COUNTER       -40
2879fdf0c29SDavid Gibson #define H_TABLE_FULL      -41
2889fdf0c29SDavid Gibson #define H_ALT_TABLE       -42
2899fdf0c29SDavid Gibson #define H_MR_CONDITION    -43
2909fdf0c29SDavid Gibson #define H_NOT_ENOUGH_RESOURCES -44
2919fdf0c29SDavid Gibson #define H_R_STATE         -45
2929fdf0c29SDavid Gibson #define H_RESCINDEND      -46
29342561bf2SAnton Blanchard #define H_P2              -55
29442561bf2SAnton Blanchard #define H_P3              -56
29542561bf2SAnton Blanchard #define H_P4              -57
29642561bf2SAnton Blanchard #define H_P5              -58
29742561bf2SAnton Blanchard #define H_P6              -59
29842561bf2SAnton Blanchard #define H_P7              -60
29942561bf2SAnton Blanchard #define H_P8              -61
30042561bf2SAnton Blanchard #define H_P9              -62
30142561bf2SAnton Blanchard #define H_UNSUPPORTED_FLAG -256
3029fdf0c29SDavid Gibson #define H_MULTI_THREADS_ACTIVE -9005
3039fdf0c29SDavid Gibson 
3049fdf0c29SDavid Gibson 
3059fdf0c29SDavid Gibson /* Long Busy is a condition that can be returned by the firmware
3069fdf0c29SDavid Gibson  * when a call cannot be completed now, but the identical call
3079fdf0c29SDavid Gibson  * should be retried later.  This prevents calls blocking in the
3089fdf0c29SDavid Gibson  * firmware for long periods of time.  Annoyingly the firmware can return
3099fdf0c29SDavid Gibson  * a range of return codes, hinting at how long we should wait before
3109fdf0c29SDavid Gibson  * retrying.  If you don't care for the hint, the macro below is a good
3119fdf0c29SDavid Gibson  * way to check for the long_busy return codes
3129fdf0c29SDavid Gibson  */
3139fdf0c29SDavid Gibson #define H_IS_LONG_BUSY(x)  ((x >= H_LONG_BUSY_START_RANGE) \
3149fdf0c29SDavid Gibson                             && (x <= H_LONG_BUSY_END_RANGE))
3159fdf0c29SDavid Gibson 
3169fdf0c29SDavid Gibson /* Flags */
3179fdf0c29SDavid Gibson #define H_LARGE_PAGE      (1ULL<<(63-16))
3189fdf0c29SDavid Gibson #define H_EXACT           (1ULL<<(63-24))       /* Use exact PTE or return H_PTEG_FULL */
3199fdf0c29SDavid Gibson #define H_R_XLATE         (1ULL<<(63-25))       /* include a valid logical page num in the pte if the valid bit is set */
3209fdf0c29SDavid Gibson #define H_READ_4          (1ULL<<(63-26))       /* Return 4 PTEs */
3219fdf0c29SDavid Gibson #define H_PAGE_STATE_CHANGE (1ULL<<(63-28))
3229fdf0c29SDavid Gibson #define H_PAGE_UNUSED     ((1ULL<<(63-29)) | (1ULL<<(63-30)))
3239fdf0c29SDavid Gibson #define H_PAGE_SET_UNUSED (H_PAGE_STATE_CHANGE | H_PAGE_UNUSED)
3249fdf0c29SDavid Gibson #define H_PAGE_SET_LOANED (H_PAGE_SET_UNUSED | (1ULL<<(63-31)))
3259fdf0c29SDavid Gibson #define H_PAGE_SET_ACTIVE H_PAGE_STATE_CHANGE
3269fdf0c29SDavid Gibson #define H_AVPN            (1ULL<<(63-32))       /* An avpn is provided as a sanity test */
3279fdf0c29SDavid Gibson #define H_ANDCOND         (1ULL<<(63-33))
3289fdf0c29SDavid Gibson #define H_ICACHE_INVALIDATE (1ULL<<(63-40))     /* icbi, etc.  (ignored for IO pages) */
3299fdf0c29SDavid Gibson #define H_ICACHE_SYNCHRONIZE (1ULL<<(63-41))    /* dcbst, icbi, etc (ignored for IO pages */
3309fdf0c29SDavid Gibson #define H_ZERO_PAGE       (1ULL<<(63-48))       /* zero the page before mapping (ignored for IO pages) */
3319fdf0c29SDavid Gibson #define H_COPY_PAGE       (1ULL<<(63-49))
3329fdf0c29SDavid Gibson #define H_N               (1ULL<<(63-61))
3339fdf0c29SDavid Gibson #define H_PP1             (1ULL<<(63-62))
3349fdf0c29SDavid Gibson #define H_PP2             (1ULL<<(63-63))
3359fdf0c29SDavid Gibson 
336a46622fdSAlexey Kardashevskiy /* Values for 2nd argument to H_SET_MODE */
337a46622fdSAlexey Kardashevskiy #define H_SET_MODE_RESOURCE_SET_CIABR           1
338a46622fdSAlexey Kardashevskiy #define H_SET_MODE_RESOURCE_SET_DAWR            2
339a46622fdSAlexey Kardashevskiy #define H_SET_MODE_RESOURCE_ADDR_TRANS_MODE     3
340a46622fdSAlexey Kardashevskiy #define H_SET_MODE_RESOURCE_LE                  4
341a46622fdSAlexey Kardashevskiy 
342a46622fdSAlexey Kardashevskiy /* Flags for H_SET_MODE_RESOURCE_LE */
34342561bf2SAnton Blanchard #define H_SET_MODE_ENDIAN_BIG    0
34442561bf2SAnton Blanchard #define H_SET_MODE_ENDIAN_LITTLE 1
34542561bf2SAnton Blanchard 
3469fdf0c29SDavid Gibson /* VASI States */
3479fdf0c29SDavid Gibson #define H_VASI_INVALID    0
3489fdf0c29SDavid Gibson #define H_VASI_ENABLED    1
3499fdf0c29SDavid Gibson #define H_VASI_ABORTED    2
3509fdf0c29SDavid Gibson #define H_VASI_SUSPENDING 3
3519fdf0c29SDavid Gibson #define H_VASI_SUSPENDED  4
3529fdf0c29SDavid Gibson #define H_VASI_RESUMED    5
3539fdf0c29SDavid Gibson #define H_VASI_COMPLETED  6
3549fdf0c29SDavid Gibson 
3559fdf0c29SDavid Gibson /* DABRX flags */
3569fdf0c29SDavid Gibson #define H_DABRX_HYPERVISOR (1ULL<<(63-61))
3579fdf0c29SDavid Gibson #define H_DABRX_KERNEL     (1ULL<<(63-62))
3589fdf0c29SDavid Gibson #define H_DABRX_USER       (1ULL<<(63-63))
3599fdf0c29SDavid Gibson 
3608acc2ae5SSuraj Jitindar Singh /* Values for KVM_PPC_GET_CPU_CHAR & H_GET_CPU_CHARACTERISTICS */
3618acc2ae5SSuraj Jitindar Singh #define H_CPU_CHAR_SPEC_BAR_ORI31               PPC_BIT(0)
3628acc2ae5SSuraj Jitindar Singh #define H_CPU_CHAR_BCCTRL_SERIALISED            PPC_BIT(1)
3638acc2ae5SSuraj Jitindar Singh #define H_CPU_CHAR_L1D_FLUSH_ORI30              PPC_BIT(2)
3648acc2ae5SSuraj Jitindar Singh #define H_CPU_CHAR_L1D_FLUSH_TRIG2              PPC_BIT(3)
3658acc2ae5SSuraj Jitindar Singh #define H_CPU_CHAR_L1D_THREAD_PRIV              PPC_BIT(4)
3668acc2ae5SSuraj Jitindar Singh #define H_CPU_CHAR_HON_BRANCH_HINTS             PPC_BIT(5)
3678acc2ae5SSuraj Jitindar Singh #define H_CPU_CHAR_THR_RECONF_TRIG              PPC_BIT(6)
368c76c0d30SSuraj Jitindar Singh #define H_CPU_CHAR_CACHE_COUNT_DIS              PPC_BIT(7)
369399b2896SSuraj Jitindar Singh #define H_CPU_CHAR_BCCTR_FLUSH_ASSIST           PPC_BIT(9)
3708acc2ae5SSuraj Jitindar Singh #define H_CPU_BEHAV_FAVOUR_SECURITY             PPC_BIT(0)
3718acc2ae5SSuraj Jitindar Singh #define H_CPU_BEHAV_L1D_FLUSH_PR                PPC_BIT(1)
3728acc2ae5SSuraj Jitindar Singh #define H_CPU_BEHAV_BNDS_CHK_SPEC_BAR           PPC_BIT(2)
373399b2896SSuraj Jitindar Singh #define H_CPU_BEHAV_FLUSH_COUNT_CACHE           PPC_BIT(5)
3748acc2ae5SSuraj Jitindar Singh 
37566a0a2cbSDong Xu Wang /* Each control block has to be on a 4K boundary */
3769fdf0c29SDavid Gibson #define H_CB_ALIGNMENT     4096
3779fdf0c29SDavid Gibson 
3789fdf0c29SDavid Gibson /* pSeries hypervisor opcodes */
3799fdf0c29SDavid Gibson #define H_REMOVE                0x04
3809fdf0c29SDavid Gibson #define H_ENTER                 0x08
3819fdf0c29SDavid Gibson #define H_READ                  0x0c
3829fdf0c29SDavid Gibson #define H_CLEAR_MOD             0x10
3839fdf0c29SDavid Gibson #define H_CLEAR_REF             0x14
3849fdf0c29SDavid Gibson #define H_PROTECT               0x18
3859fdf0c29SDavid Gibson #define H_GET_TCE               0x1c
3869fdf0c29SDavid Gibson #define H_PUT_TCE               0x20
3879fdf0c29SDavid Gibson #define H_SET_SPRG0             0x24
3889fdf0c29SDavid Gibson #define H_SET_DABR              0x28
3899fdf0c29SDavid Gibson #define H_PAGE_INIT             0x2c
3909fdf0c29SDavid Gibson #define H_SET_ASR               0x30
3919fdf0c29SDavid Gibson #define H_ASR_ON                0x34
3929fdf0c29SDavid Gibson #define H_ASR_OFF               0x38
3939fdf0c29SDavid Gibson #define H_LOGICAL_CI_LOAD       0x3c
3949fdf0c29SDavid Gibson #define H_LOGICAL_CI_STORE      0x40
3959fdf0c29SDavid Gibson #define H_LOGICAL_CACHE_LOAD    0x44
3969fdf0c29SDavid Gibson #define H_LOGICAL_CACHE_STORE   0x48
3979fdf0c29SDavid Gibson #define H_LOGICAL_ICBI          0x4c
3989fdf0c29SDavid Gibson #define H_LOGICAL_DCBF          0x50
3999fdf0c29SDavid Gibson #define H_GET_TERM_CHAR         0x54
4009fdf0c29SDavid Gibson #define H_PUT_TERM_CHAR         0x58
4019fdf0c29SDavid Gibson #define H_REAL_TO_LOGICAL       0x5c
4029fdf0c29SDavid Gibson #define H_HYPERVISOR_DATA       0x60
4039fdf0c29SDavid Gibson #define H_EOI                   0x64
4049fdf0c29SDavid Gibson #define H_CPPR                  0x68
4059fdf0c29SDavid Gibson #define H_IPI                   0x6c
4069fdf0c29SDavid Gibson #define H_IPOLL                 0x70
4079fdf0c29SDavid Gibson #define H_XIRR                  0x74
4089fdf0c29SDavid Gibson #define H_PERFMON               0x7c
4099fdf0c29SDavid Gibson #define H_MIGRATE_DMA           0x78
4109fdf0c29SDavid Gibson #define H_REGISTER_VPA          0xDC
4119fdf0c29SDavid Gibson #define H_CEDE                  0xE0
4129fdf0c29SDavid Gibson #define H_CONFER                0xE4
4139fdf0c29SDavid Gibson #define H_PROD                  0xE8
4149fdf0c29SDavid Gibson #define H_GET_PPP               0xEC
4159fdf0c29SDavid Gibson #define H_SET_PPP               0xF0
4169fdf0c29SDavid Gibson #define H_PURR                  0xF4
4179fdf0c29SDavid Gibson #define H_PIC                   0xF8
4189fdf0c29SDavid Gibson #define H_REG_CRQ               0xFC
4199fdf0c29SDavid Gibson #define H_FREE_CRQ              0x100
4209fdf0c29SDavid Gibson #define H_VIO_SIGNAL            0x104
4219fdf0c29SDavid Gibson #define H_SEND_CRQ              0x108
4229fdf0c29SDavid Gibson #define H_COPY_RDMA             0x110
4239fdf0c29SDavid Gibson #define H_REGISTER_LOGICAL_LAN  0x114
4249fdf0c29SDavid Gibson #define H_FREE_LOGICAL_LAN      0x118
4259fdf0c29SDavid Gibson #define H_ADD_LOGICAL_LAN_BUFFER 0x11C
4269fdf0c29SDavid Gibson #define H_SEND_LOGICAL_LAN      0x120
4279fdf0c29SDavid Gibson #define H_BULK_REMOVE           0x124
4289fdf0c29SDavid Gibson #define H_MULTICAST_CTRL        0x130
4299fdf0c29SDavid Gibson #define H_SET_XDABR             0x134
4309fdf0c29SDavid Gibson #define H_STUFF_TCE             0x138
4319fdf0c29SDavid Gibson #define H_PUT_TCE_INDIRECT      0x13C
4329fdf0c29SDavid Gibson #define H_CHANGE_LOGICAL_LAN_MAC 0x14C
4339fdf0c29SDavid Gibson #define H_VTERM_PARTNER_INFO    0x150
4349fdf0c29SDavid Gibson #define H_REGISTER_VTERM        0x154
4359fdf0c29SDavid Gibson #define H_FREE_VTERM            0x158
4369fdf0c29SDavid Gibson #define H_RESET_EVENTS          0x15C
4379fdf0c29SDavid Gibson #define H_ALLOC_RESOURCE        0x160
4389fdf0c29SDavid Gibson #define H_FREE_RESOURCE         0x164
4399fdf0c29SDavid Gibson #define H_MODIFY_QP             0x168
4409fdf0c29SDavid Gibson #define H_QUERY_QP              0x16C
4419fdf0c29SDavid Gibson #define H_REREGISTER_PMR        0x170
4429fdf0c29SDavid Gibson #define H_REGISTER_SMR          0x174
4439fdf0c29SDavid Gibson #define H_QUERY_MR              0x178
4449fdf0c29SDavid Gibson #define H_QUERY_MW              0x17C
4459fdf0c29SDavid Gibson #define H_QUERY_HCA             0x180
4469fdf0c29SDavid Gibson #define H_QUERY_PORT            0x184
4479fdf0c29SDavid Gibson #define H_MODIFY_PORT           0x188
4489fdf0c29SDavid Gibson #define H_DEFINE_AQP1           0x18C
4499fdf0c29SDavid Gibson #define H_GET_TRACE_BUFFER      0x190
4509fdf0c29SDavid Gibson #define H_DEFINE_AQP0           0x194
4519fdf0c29SDavid Gibson #define H_RESIZE_MR             0x198
4529fdf0c29SDavid Gibson #define H_ATTACH_MCQP           0x19C
4539fdf0c29SDavid Gibson #define H_DETACH_MCQP           0x1A0
4549fdf0c29SDavid Gibson #define H_CREATE_RPT            0x1A4
4559fdf0c29SDavid Gibson #define H_REMOVE_RPT            0x1A8
4569fdf0c29SDavid Gibson #define H_REGISTER_RPAGES       0x1AC
4579fdf0c29SDavid Gibson #define H_DISABLE_AND_GETC      0x1B0
4589fdf0c29SDavid Gibson #define H_ERROR_DATA            0x1B4
4599fdf0c29SDavid Gibson #define H_GET_HCA_INFO          0x1B8
4609fdf0c29SDavid Gibson #define H_GET_PERF_COUNT        0x1BC
4619fdf0c29SDavid Gibson #define H_MANAGE_TRACE          0x1C0
462c59704b2SSuraj Jitindar Singh #define H_GET_CPU_CHARACTERISTICS 0x1C8
4639fdf0c29SDavid Gibson #define H_FREE_LOGICAL_LAN_BUFFER 0x1D4
4649fdf0c29SDavid Gibson #define H_QUERY_INT_STATE       0x1E4
4659fdf0c29SDavid Gibson #define H_POLL_PENDING          0x1D8
4669fdf0c29SDavid Gibson #define H_ILLAN_ATTRIBUTES      0x244
4679fdf0c29SDavid Gibson #define H_MODIFY_HEA_QP         0x250
4689fdf0c29SDavid Gibson #define H_QUERY_HEA_QP          0x254
4699fdf0c29SDavid Gibson #define H_QUERY_HEA             0x258
4709fdf0c29SDavid Gibson #define H_QUERY_HEA_PORT        0x25C
4719fdf0c29SDavid Gibson #define H_MODIFY_HEA_PORT       0x260
4729fdf0c29SDavid Gibson #define H_REG_BCMC              0x264
4739fdf0c29SDavid Gibson #define H_DEREG_BCMC            0x268
4749fdf0c29SDavid Gibson #define H_REGISTER_HEA_RPAGES   0x26C
4759fdf0c29SDavid Gibson #define H_DISABLE_AND_GET_HEA   0x270
4769fdf0c29SDavid Gibson #define H_GET_HEA_INFO          0x274
4779fdf0c29SDavid Gibson #define H_ALLOC_HEA_RESOURCE    0x278
4789fdf0c29SDavid Gibson #define H_ADD_CONN              0x284
4799fdf0c29SDavid Gibson #define H_DEL_CONN              0x288
4809fdf0c29SDavid Gibson #define H_JOIN                  0x298
4819fdf0c29SDavid Gibson #define H_VASI_STATE            0x2A4
4829fdf0c29SDavid Gibson #define H_ENABLE_CRQ            0x2B0
4839fdf0c29SDavid Gibson #define H_GET_EM_PARMS          0x2B8
4849fdf0c29SDavid Gibson #define H_SET_MPP               0x2D0
4859fdf0c29SDavid Gibson #define H_GET_MPP               0x2D4
486c24ba3d0SLaurent Vivier #define H_HOME_NODE_ASSOCIATIVITY 0x2EC
4875d87e4b7SBenjamin Herrenschmidt #define H_XIRR_X                0x2FC
4884d9392beSThomas Huth #define H_RANDOM                0x300
48942561bf2SAnton Blanchard #define H_SET_MODE              0x31C
49030f4b05bSDavid Gibson #define H_RESIZE_HPT_PREPARE    0x36C
49130f4b05bSDavid Gibson #define H_RESIZE_HPT_COMMIT     0x370
492d77a98b0SSuraj Jitindar Singh #define H_CLEAN_SLB             0x374
493d77a98b0SSuraj Jitindar Singh #define H_INVALIDATE_PID        0x378
494d77a98b0SSuraj Jitindar Singh #define H_REGISTER_PROC_TBL     0x37C
4951c7ad77eSNicholas Piggin #define H_SIGNAL_SYS_RESET      0x380
49623bcd5ebSCédric Le Goater 
49723bcd5ebSCédric Le Goater #define H_INT_GET_SOURCE_INFO   0x3A8
49823bcd5ebSCédric Le Goater #define H_INT_SET_SOURCE_CONFIG 0x3AC
49923bcd5ebSCédric Le Goater #define H_INT_GET_SOURCE_CONFIG 0x3B0
50023bcd5ebSCédric Le Goater #define H_INT_GET_QUEUE_INFO    0x3B4
50123bcd5ebSCédric Le Goater #define H_INT_SET_QUEUE_CONFIG  0x3B8
50223bcd5ebSCédric Le Goater #define H_INT_GET_QUEUE_CONFIG  0x3BC
50323bcd5ebSCédric Le Goater #define H_INT_SET_OS_REPORTING_LINE 0x3C0
50423bcd5ebSCédric Le Goater #define H_INT_GET_OS_REPORTING_LINE 0x3C4
50523bcd5ebSCédric Le Goater #define H_INT_ESB               0x3C8
50623bcd5ebSCédric Le Goater #define H_INT_SYNC              0x3CC
50723bcd5ebSCédric Le Goater #define H_INT_RESET             0x3D0
50823bcd5ebSCédric Le Goater 
50923bcd5ebSCédric Le Goater #define MAX_HCALL_OPCODE        H_INT_RESET
5109fdf0c29SDavid Gibson 
51139ac8455SDavid Gibson /* The hcalls above are standardized in PAPR and implemented by pHyp
51239ac8455SDavid Gibson  * as well.
51339ac8455SDavid Gibson  *
51439ac8455SDavid Gibson  * We also need some hcalls which are specific to qemu / KVM-on-POWER.
515498cd995SGreg Kurz  * We put those into the 0xf000-0xfffc range which is reserved by PAPR
516498cd995SGreg Kurz  * for "platform-specific" hcalls.
51739ac8455SDavid Gibson  */
51839ac8455SDavid Gibson #define KVMPPC_HCALL_BASE       0xf000
51939ac8455SDavid Gibson #define KVMPPC_H_RTAS           (KVMPPC_HCALL_BASE + 0x0)
520c73e3771SBenjamin Herrenschmidt #define KVMPPC_H_LOGICAL_MEMOP  (KVMPPC_HCALL_BASE + 0x1)
5212a6593cbSAlexey Kardashevskiy /* Client Architecture support */
5222a6593cbSAlexey Kardashevskiy #define KVMPPC_H_CAS            (KVMPPC_HCALL_BASE + 0x2)
523fea35ca4SAlexey Kardashevskiy #define KVMPPC_H_UPDATE_DT      (KVMPPC_HCALL_BASE + 0x3)
524fea35ca4SAlexey Kardashevskiy #define KVMPPC_HCALL_MAX        KVMPPC_H_UPDATE_DT
52539ac8455SDavid Gibson 
5260fb6bd07SMichael Roth /*
5270fb6bd07SMichael Roth  * The hcall range 0xEF00 to 0xEF80 is reserved for use in facilitating
5280fb6bd07SMichael Roth  * Secure VM mode via an Ultravisor / Protected Execution Facility
5290fb6bd07SMichael Roth  */
5300fb6bd07SMichael Roth #define SVM_HCALL_BASE              0xEF00
5310fb6bd07SMichael Roth #define SVM_H_TPM_COMM              0xEF10
5320fb6bd07SMichael Roth #define SVM_HCALL_MAX               SVM_H_TPM_COMM
5330fb6bd07SMichael Roth 
5340fb6bd07SMichael Roth 
535ce2918cbSDavid Gibson typedef struct SpaprDeviceTreeUpdateHeader {
5362a6593cbSAlexey Kardashevskiy     uint32_t version_id;
537ce2918cbSDavid Gibson } SpaprDeviceTreeUpdateHeader;
5382a6593cbSAlexey Kardashevskiy 
5399fdf0c29SDavid Gibson #define hcall_dprintf(fmt, ...) \
540aaf87c66SThomas Huth     do { \
541aaf87c66SThomas Huth         qemu_log_mask(LOG_GUEST_ERROR, "%s: " fmt, __func__, ## __VA_ARGS__); \
542aaf87c66SThomas Huth     } while (0)
5439fdf0c29SDavid Gibson 
544ce2918cbSDavid Gibson typedef target_ulong (*spapr_hcall_fn)(PowerPCCPU *cpu, SpaprMachineState *sm,
5459fdf0c29SDavid Gibson                                        target_ulong opcode,
5469fdf0c29SDavid Gibson                                        target_ulong *args);
5479fdf0c29SDavid Gibson 
5489fdf0c29SDavid Gibson void spapr_register_hypercall(target_ulong opcode, spapr_hcall_fn fn);
549aa100fa4SAndreas Färber target_ulong spapr_hypercall(PowerPCCPU *cpu, target_ulong opcode,
5509fdf0c29SDavid Gibson                              target_ulong *args);
5519fdf0c29SDavid Gibson 
55203ef074cSNicholas Piggin /* Virtual Processor Area structure constants */
55303ef074cSNicholas Piggin #define VPA_MIN_SIZE           640
55403ef074cSNicholas Piggin #define VPA_SIZE_OFFSET        0x4
55503ef074cSNicholas Piggin #define VPA_SHARED_PROC_OFFSET 0x9
55603ef074cSNicholas Piggin #define VPA_SHARED_PROC_VAL    0x2
55703ef074cSNicholas Piggin #define VPA_DISPATCH_COUNTER   0x100
55803ef074cSNicholas Piggin 
559ee954280SGavin Shan /* ibm,set-eeh-option */
560ee954280SGavin Shan #define RTAS_EEH_DISABLE                 0
561ee954280SGavin Shan #define RTAS_EEH_ENABLE                  1
562ee954280SGavin Shan #define RTAS_EEH_THAW_IO                 2
563ee954280SGavin Shan #define RTAS_EEH_THAW_DMA                3
564ee954280SGavin Shan 
565ee954280SGavin Shan /* ibm,get-config-addr-info2 */
566ee954280SGavin Shan #define RTAS_GET_PE_ADDR                 0
567ee954280SGavin Shan #define RTAS_GET_PE_MODE                 1
568ee954280SGavin Shan #define RTAS_PE_MODE_NONE                0
569ee954280SGavin Shan #define RTAS_PE_MODE_NOT_SHARED          1
570ee954280SGavin Shan #define RTAS_PE_MODE_SHARED              2
571ee954280SGavin Shan 
572ee954280SGavin Shan /* ibm,read-slot-reset-state2 */
573ee954280SGavin Shan #define RTAS_EEH_PE_STATE_NORMAL         0
574ee954280SGavin Shan #define RTAS_EEH_PE_STATE_RESET          1
575ee954280SGavin Shan #define RTAS_EEH_PE_STATE_STOPPED_IO_DMA 2
576ee954280SGavin Shan #define RTAS_EEH_PE_STATE_STOPPED_DMA    4
577ee954280SGavin Shan #define RTAS_EEH_PE_STATE_UNAVAIL        5
578ee954280SGavin Shan #define RTAS_EEH_NOT_SUPPORT             0
579ee954280SGavin Shan #define RTAS_EEH_SUPPORT                 1
580ee954280SGavin Shan #define RTAS_EEH_PE_UNAVAIL_INFO         1000
581ee954280SGavin Shan #define RTAS_EEH_PE_RECOVER_INFO         0
582ee954280SGavin Shan 
583ee954280SGavin Shan /* ibm,set-slot-reset */
584ee954280SGavin Shan #define RTAS_SLOT_RESET_DEACTIVATE       0
585ee954280SGavin Shan #define RTAS_SLOT_RESET_HOT              1
586ee954280SGavin Shan #define RTAS_SLOT_RESET_FUNDAMENTAL      3
587ee954280SGavin Shan 
588ee954280SGavin Shan /* ibm,slot-error-detail */
589ee954280SGavin Shan #define RTAS_SLOT_TEMP_ERR_LOG           1
590ee954280SGavin Shan #define RTAS_SLOT_PERM_ERR_LOG           2
591ee954280SGavin Shan 
592a64d325dSAlexey Kardashevskiy /* RTAS return codes */
593a64d325dSAlexey Kardashevskiy #define RTAS_OUT_SUCCESS                        0
594a64d325dSAlexey Kardashevskiy #define RTAS_OUT_NO_ERRORS_FOUND                1
595a64d325dSAlexey Kardashevskiy #define RTAS_OUT_HW_ERROR                       -1
596a64d325dSAlexey Kardashevskiy #define RTAS_OUT_BUSY                           -2
597a64d325dSAlexey Kardashevskiy #define RTAS_OUT_PARAM_ERROR                    -3
5983ada6b11SAlexey Kardashevskiy #define RTAS_OUT_NOT_SUPPORTED                  -3
5999d1852ceSMichael Roth #define RTAS_OUT_NO_SUCH_INDICATOR              -3
6003ada6b11SAlexey Kardashevskiy #define RTAS_OUT_NOT_AUTHORIZED                 -9002
601c920f7b4SDavid Gibson #define RTAS_OUT_SYSPARM_PARAM_ERROR            -9999
602a64d325dSAlexey Kardashevskiy 
603ae4de14cSAlexey Kardashevskiy /* DDW pagesize mask values from ibm,query-pe-dma-window */
604ae4de14cSAlexey Kardashevskiy #define RTAS_DDW_PGSIZE_4K       0x01
605ae4de14cSAlexey Kardashevskiy #define RTAS_DDW_PGSIZE_64K      0x02
606ae4de14cSAlexey Kardashevskiy #define RTAS_DDW_PGSIZE_16M      0x04
607ae4de14cSAlexey Kardashevskiy #define RTAS_DDW_PGSIZE_32M      0x08
608ae4de14cSAlexey Kardashevskiy #define RTAS_DDW_PGSIZE_64M      0x10
609ae4de14cSAlexey Kardashevskiy #define RTAS_DDW_PGSIZE_128M     0x20
610ae4de14cSAlexey Kardashevskiy #define RTAS_DDW_PGSIZE_256M     0x40
611ae4de14cSAlexey Kardashevskiy #define RTAS_DDW_PGSIZE_16G      0x80
612ae4de14cSAlexey Kardashevskiy 
6133a3b8502SAlexey Kardashevskiy /* RTAS tokens */
6143a3b8502SAlexey Kardashevskiy #define RTAS_TOKEN_BASE      0x2000
6153a3b8502SAlexey Kardashevskiy 
6163a3b8502SAlexey Kardashevskiy #define RTAS_DISPLAY_CHARACTER                  (RTAS_TOKEN_BASE + 0x00)
6173a3b8502SAlexey Kardashevskiy #define RTAS_GET_TIME_OF_DAY                    (RTAS_TOKEN_BASE + 0x01)
6183a3b8502SAlexey Kardashevskiy #define RTAS_SET_TIME_OF_DAY                    (RTAS_TOKEN_BASE + 0x02)
6193a3b8502SAlexey Kardashevskiy #define RTAS_POWER_OFF                          (RTAS_TOKEN_BASE + 0x03)
6203a3b8502SAlexey Kardashevskiy #define RTAS_SYSTEM_REBOOT                      (RTAS_TOKEN_BASE + 0x04)
6213a3b8502SAlexey Kardashevskiy #define RTAS_QUERY_CPU_STOPPED_STATE            (RTAS_TOKEN_BASE + 0x05)
6223a3b8502SAlexey Kardashevskiy #define RTAS_START_CPU                          (RTAS_TOKEN_BASE + 0x06)
6233a3b8502SAlexey Kardashevskiy #define RTAS_STOP_SELF                          (RTAS_TOKEN_BASE + 0x07)
6243a3b8502SAlexey Kardashevskiy #define RTAS_IBM_GET_SYSTEM_PARAMETER           (RTAS_TOKEN_BASE + 0x08)
6253a3b8502SAlexey Kardashevskiy #define RTAS_IBM_SET_SYSTEM_PARAMETER           (RTAS_TOKEN_BASE + 0x09)
6263a3b8502SAlexey Kardashevskiy #define RTAS_IBM_SET_XIVE                       (RTAS_TOKEN_BASE + 0x0A)
6273a3b8502SAlexey Kardashevskiy #define RTAS_IBM_GET_XIVE                       (RTAS_TOKEN_BASE + 0x0B)
6283a3b8502SAlexey Kardashevskiy #define RTAS_IBM_INT_OFF                        (RTAS_TOKEN_BASE + 0x0C)
6293a3b8502SAlexey Kardashevskiy #define RTAS_IBM_INT_ON                         (RTAS_TOKEN_BASE + 0x0D)
6303a3b8502SAlexey Kardashevskiy #define RTAS_CHECK_EXCEPTION                    (RTAS_TOKEN_BASE + 0x0E)
6313a3b8502SAlexey Kardashevskiy #define RTAS_EVENT_SCAN                         (RTAS_TOKEN_BASE + 0x0F)
6323a3b8502SAlexey Kardashevskiy #define RTAS_IBM_SET_TCE_BYPASS                 (RTAS_TOKEN_BASE + 0x10)
6333a3b8502SAlexey Kardashevskiy #define RTAS_QUIESCE                            (RTAS_TOKEN_BASE + 0x11)
6343a3b8502SAlexey Kardashevskiy #define RTAS_NVRAM_FETCH                        (RTAS_TOKEN_BASE + 0x12)
6353a3b8502SAlexey Kardashevskiy #define RTAS_NVRAM_STORE                        (RTAS_TOKEN_BASE + 0x13)
6363a3b8502SAlexey Kardashevskiy #define RTAS_READ_PCI_CONFIG                    (RTAS_TOKEN_BASE + 0x14)
6373a3b8502SAlexey Kardashevskiy #define RTAS_WRITE_PCI_CONFIG                   (RTAS_TOKEN_BASE + 0x15)
6383a3b8502SAlexey Kardashevskiy #define RTAS_IBM_READ_PCI_CONFIG                (RTAS_TOKEN_BASE + 0x16)
6393a3b8502SAlexey Kardashevskiy #define RTAS_IBM_WRITE_PCI_CONFIG               (RTAS_TOKEN_BASE + 0x17)
6403a3b8502SAlexey Kardashevskiy #define RTAS_IBM_QUERY_INTERRUPT_SOURCE_NUMBER  (RTAS_TOKEN_BASE + 0x18)
6413a3b8502SAlexey Kardashevskiy #define RTAS_IBM_CHANGE_MSI                     (RTAS_TOKEN_BASE + 0x19)
6423a3b8502SAlexey Kardashevskiy #define RTAS_SET_INDICATOR                      (RTAS_TOKEN_BASE + 0x1A)
6433a3b8502SAlexey Kardashevskiy #define RTAS_SET_POWER_LEVEL                    (RTAS_TOKEN_BASE + 0x1B)
6443a3b8502SAlexey Kardashevskiy #define RTAS_GET_POWER_LEVEL                    (RTAS_TOKEN_BASE + 0x1C)
6453a3b8502SAlexey Kardashevskiy #define RTAS_GET_SENSOR_STATE                   (RTAS_TOKEN_BASE + 0x1D)
6463a3b8502SAlexey Kardashevskiy #define RTAS_IBM_CONFIGURE_CONNECTOR            (RTAS_TOKEN_BASE + 0x1E)
6473a3b8502SAlexey Kardashevskiy #define RTAS_IBM_OS_TERM                        (RTAS_TOKEN_BASE + 0x1F)
648ee954280SGavin Shan #define RTAS_IBM_SET_EEH_OPTION                 (RTAS_TOKEN_BASE + 0x20)
649ee954280SGavin Shan #define RTAS_IBM_GET_CONFIG_ADDR_INFO2          (RTAS_TOKEN_BASE + 0x21)
650ee954280SGavin Shan #define RTAS_IBM_READ_SLOT_RESET_STATE2         (RTAS_TOKEN_BASE + 0x22)
651ee954280SGavin Shan #define RTAS_IBM_SET_SLOT_RESET                 (RTAS_TOKEN_BASE + 0x23)
652ee954280SGavin Shan #define RTAS_IBM_CONFIGURE_PE                   (RTAS_TOKEN_BASE + 0x24)
653ee954280SGavin Shan #define RTAS_IBM_SLOT_ERROR_DETAIL              (RTAS_TOKEN_BASE + 0x25)
654ae4de14cSAlexey Kardashevskiy #define RTAS_IBM_QUERY_PE_DMA_WINDOW            (RTAS_TOKEN_BASE + 0x26)
655ae4de14cSAlexey Kardashevskiy #define RTAS_IBM_CREATE_PE_DMA_WINDOW           (RTAS_TOKEN_BASE + 0x27)
656ae4de14cSAlexey Kardashevskiy #define RTAS_IBM_REMOVE_PE_DMA_WINDOW           (RTAS_TOKEN_BASE + 0x28)
657ae4de14cSAlexey Kardashevskiy #define RTAS_IBM_RESET_PE_DMA_WINDOW            (RTAS_TOKEN_BASE + 0x29)
65893eac7b8SNicholas Piggin #define RTAS_IBM_SUSPEND_ME                     (RTAS_TOKEN_BASE + 0x2A)
659*f03496bcSAravinda Prasad #define RTAS_IBM_NMI_REGISTER                   (RTAS_TOKEN_BASE + 0x2B)
660*f03496bcSAravinda Prasad #define RTAS_IBM_NMI_INTERLOCK                  (RTAS_TOKEN_BASE + 0x2C)
6613a3b8502SAlexey Kardashevskiy 
662*f03496bcSAravinda Prasad #define RTAS_TOKEN_MAX                          (RTAS_TOKEN_BASE + 0x2D)
6633a3b8502SAlexey Kardashevskiy 
6643052d951SSam bobroff /* RTAS ibm,get-system-parameter token values */
6653b50d897SSam bobroff #define RTAS_SYSPARM_SPLPAR_CHARACTERISTICS      20
6663052d951SSam bobroff #define RTAS_SYSPARM_DIAGNOSTICS_RUN_MODE        42
667b907d7b0SSam bobroff #define RTAS_SYSPARM_UUID                        48
6683052d951SSam bobroff 
6698c8639dfSMike Day /* RTAS indicator/sensor types
6708c8639dfSMike Day  *
6718c8639dfSMike Day  * as defined by PAPR+ 2.7 7.3.5.4, Table 41
6728c8639dfSMike Day  *
6738c8639dfSMike Day  * NOTE: currently only DR-related sensors are implemented here
6748c8639dfSMike Day  */
6758c8639dfSMike Day #define RTAS_SENSOR_TYPE_ISOLATION_STATE        9001
6768c8639dfSMike Day #define RTAS_SENSOR_TYPE_DR                     9002
6778c8639dfSMike Day #define RTAS_SENSOR_TYPE_ALLOCATION_STATE       9003
6788c8639dfSMike Day #define RTAS_SENSOR_TYPE_ENTITY_SENSE RTAS_SENSOR_TYPE_ALLOCATION_STATE
6798c8639dfSMike Day 
6803052d951SSam bobroff /* Possible values for the platform-processor-diagnostics-run-mode parameter
6813052d951SSam bobroff  * of the RTAS ibm,get-system-parameter call.
6823052d951SSam bobroff  */
6833052d951SSam bobroff #define DIAGNOSTICS_RUN_MODE_DISABLED  0
6843052d951SSam bobroff #define DIAGNOSTICS_RUN_MODE_STAGGERED 1
6853052d951SSam bobroff #define DIAGNOSTICS_RUN_MODE_IMMEDIATE 2
6863052d951SSam bobroff #define DIAGNOSTICS_RUN_MODE_PERIODIC  3
6873052d951SSam bobroff 
6884fe822e0SAlexey Kardashevskiy static inline uint64_t ppc64_phys_to_real(uint64_t addr)
6894fe822e0SAlexey Kardashevskiy {
6904fe822e0SAlexey Kardashevskiy     return addr & ~0xF000000000000000ULL;
6914fe822e0SAlexey Kardashevskiy }
6924fe822e0SAlexey Kardashevskiy 
69339ac8455SDavid Gibson static inline uint32_t rtas_ld(target_ulong phys, int n)
69439ac8455SDavid Gibson {
695fdfba1a2SEdgar E. Iglesias     return ldl_be_phys(&address_space_memory, ppc64_phys_to_real(phys + 4*n));
69639ac8455SDavid Gibson }
69739ac8455SDavid Gibson 
698a14aa92bSGavin Shan static inline uint64_t rtas_ldq(target_ulong phys, int n)
699a14aa92bSGavin Shan {
700a14aa92bSGavin Shan     return (uint64_t)rtas_ld(phys, n) << 32 | rtas_ld(phys, n + 1);
701a14aa92bSGavin Shan }
702a14aa92bSGavin Shan 
70339ac8455SDavid Gibson static inline void rtas_st(target_ulong phys, int n, uint32_t val)
70439ac8455SDavid Gibson {
705ab1da857SEdgar E. Iglesias     stl_be_phys(&address_space_memory, ppc64_phys_to_real(phys + 4*n), val);
70639ac8455SDavid Gibson }
70739ac8455SDavid Gibson 
708ce2918cbSDavid Gibson typedef void (*spapr_rtas_fn)(PowerPCCPU *cpu, SpaprMachineState *sm,
709210b580bSAnthony Liguori                               uint32_t token,
71039ac8455SDavid Gibson                               uint32_t nargs, target_ulong args,
71139ac8455SDavid Gibson                               uint32_t nret, target_ulong rets);
7123a3b8502SAlexey Kardashevskiy void spapr_rtas_register(int token, const char *name, spapr_rtas_fn fn);
713ce2918cbSDavid Gibson target_ulong spapr_rtas_call(PowerPCCPU *cpu, SpaprMachineState *sm,
71439ac8455SDavid Gibson                              uint32_t token, uint32_t nargs, target_ulong args,
71539ac8455SDavid Gibson                              uint32_t nret, target_ulong rets);
7163f5dabceSDavid Gibson void spapr_dt_rtas_tokens(void *fdt, int rtas);
717ce2918cbSDavid Gibson void spapr_load_rtas(SpaprMachineState *spapr, void *fdt, hwaddr addr);
71839ac8455SDavid Gibson 
719ad0ebb91SDavid Gibson #define SPAPR_TCE_PAGE_SHIFT   12
720ad0ebb91SDavid Gibson #define SPAPR_TCE_PAGE_SIZE    (1ULL << SPAPR_TCE_PAGE_SHIFT)
721ad0ebb91SDavid Gibson #define SPAPR_TCE_PAGE_MASK    (SPAPR_TCE_PAGE_SIZE - 1)
722ad0ebb91SDavid Gibson 
723ad0ebb91SDavid Gibson #define SPAPR_VIO_BASE_LIOBN    0x00000000
7244290ca49SAlexey Kardashevskiy #define SPAPR_VIO_LIOBN(reg)    (0x00000000 | (reg))
725c8545818SAlexey Kardashevskiy #define SPAPR_PCI_LIOBN(phb_index, window_num) \
726c8545818SAlexey Kardashevskiy     (0x80000000 | ((phb_index) << 8) | (window_num))
727d9d96a3cSAlexey Kardashevskiy #define SPAPR_IS_PCI_LIOBN(liobn)   (!!((liobn) & 0x80000000))
728c8545818SAlexey Kardashevskiy #define SPAPR_PCI_DMA_WINDOW_NUM(liobn) ((liobn) & 0xff)
729ad0ebb91SDavid Gibson 
73074d042e5SDavid Gibson #define RTAS_ERROR_LOG_MAX      2048
73174d042e5SDavid Gibson 
73281fe70e4SAravinda Prasad /* Offset from rtas-base where error log is placed */
73381fe70e4SAravinda Prasad #define RTAS_ERROR_LOG_OFFSET       0x30
73481fe70e4SAravinda Prasad 
73579853e18STyrel Datwyler #define RTAS_EVENT_SCAN_RATE    1
73679853e18STyrel Datwyler 
737bb2d8ab6SGreg Kurz /* This helper should be used to encode interrupt specifiers when the related
738bb2d8ab6SGreg Kurz  * "interrupt-controller" node has its "#interrupt-cells" property set to 2 (ie,
739bb2d8ab6SGreg Kurz  * VIO devices, RTAS event sources and PHBs).
740bb2d8ab6SGreg Kurz  */
7415c7adcf4SGreg Kurz static inline void spapr_dt_irq(uint32_t *intspec, int irq, bool is_lsi)
742bb2d8ab6SGreg Kurz {
743bb2d8ab6SGreg Kurz     intspec[0] = cpu_to_be32(irq);
744bb2d8ab6SGreg Kurz     intspec[1] = is_lsi ? cpu_to_be32(1) : 0;
745bb2d8ab6SGreg Kurz }
746bb2d8ab6SGreg Kurz 
747ce2918cbSDavid Gibson typedef struct SpaprTceTable SpaprTceTable;
74874d042e5SDavid Gibson 
749a83000f5SAnthony Liguori #define TYPE_SPAPR_TCE_TABLE "spapr-tce-table"
750a83000f5SAnthony Liguori #define SPAPR_TCE_TABLE(obj) \
751ce2918cbSDavid Gibson     OBJECT_CHECK(SpaprTceTable, (obj), TYPE_SPAPR_TCE_TABLE)
752a83000f5SAnthony Liguori 
7531221a474SAlexey Kardashevskiy #define TYPE_SPAPR_IOMMU_MEMORY_REGION "spapr-iommu-memory-region"
7541221a474SAlexey Kardashevskiy #define SPAPR_IOMMU_MEMORY_REGION(obj) \
7551221a474SAlexey Kardashevskiy         OBJECT_CHECK(IOMMUMemoryRegion, (obj), TYPE_SPAPR_IOMMU_MEMORY_REGION)
7561221a474SAlexey Kardashevskiy 
757ce2918cbSDavid Gibson struct SpaprTceTable {
758a83000f5SAnthony Liguori     DeviceState parent;
759a83000f5SAnthony Liguori     uint32_t liobn;
760a83000f5SAnthony Liguori     uint32_t nb_table;
7611b8eceeeSAlexey Kardashevskiy     uint64_t bus_offset;
762650f33adSAlexey Kardashevskiy     uint32_t page_shift;
763a83000f5SAnthony Liguori     uint64_t *table;
764a26fdf39SAlexey Kardashevskiy     uint32_t mig_nb_table;
765a26fdf39SAlexey Kardashevskiy     uint64_t *mig_table;
766a83000f5SAnthony Liguori     bool bypass;
7676a81dd17SDavid Gibson     bool need_vfio;
7685f366667SAlexey Kardashevskiy     bool skipping_replay;
769a83000f5SAnthony Liguori     int fd;
7703df9d748SAlexey Kardashevskiy     MemoryRegion root;
7713df9d748SAlexey Kardashevskiy     IOMMUMemoryRegion iommu;
772ce2918cbSDavid Gibson     struct SpaprVioDevice *vdev; /* for @bypass migration compatibility only */
773ce2918cbSDavid Gibson     QLIST_ENTRY(SpaprTceTable) list;
774a83000f5SAnthony Liguori };
775a83000f5SAnthony Liguori 
776ce2918cbSDavid Gibson SpaprTceTable *spapr_tce_find_by_liobn(target_ulong liobn);
77731fe14d1SNathan Fontenot 
778ce2918cbSDavid Gibson struct SpaprEventLogEntry {
779fd38804bSDaniel Henrique Barboza     uint32_t summary;
780fd38804bSDaniel Henrique Barboza     uint32_t extended_length;
781fd38804bSDaniel Henrique Barboza     void *extended_log;
782ce2918cbSDavid Gibson     QTAILQ_ENTRY(SpaprEventLogEntry) next;
78331fe14d1SNathan Fontenot };
78431fe14d1SNathan Fontenot 
7850c21e073SDavid Gibson void *spapr_build_fdt(SpaprMachineState *spapr, bool reset, size_t space);
786ce2918cbSDavid Gibson void spapr_events_init(SpaprMachineState *sm);
787ce2918cbSDavid Gibson void spapr_dt_events(SpaprMachineState *sm, void *fdt);
788ce2918cbSDavid Gibson void close_htab_fd(SpaprMachineState *spapr);
789ce2918cbSDavid Gibson void spapr_setup_hpt_and_vrma(SpaprMachineState *spapr);
790ce2918cbSDavid Gibson void spapr_free_hpt(SpaprMachineState *spapr);
791ce2918cbSDavid Gibson SpaprTceTable *spapr_tce_new_table(DeviceState *owner, uint32_t liobn);
792ce2918cbSDavid Gibson void spapr_tce_table_enable(SpaprTceTable *tcet,
793df7625d4SAlexey Kardashevskiy                             uint32_t page_shift, uint64_t bus_offset,
794df7625d4SAlexey Kardashevskiy                             uint32_t nb_table);
795ce2918cbSDavid Gibson void spapr_tce_table_disable(SpaprTceTable *tcet);
796ce2918cbSDavid Gibson void spapr_tce_set_need_vfio(SpaprTceTable *tcet, bool need_vfio);
797c10325d6SDavid Gibson 
798ce2918cbSDavid Gibson MemoryRegion *spapr_tce_get_iommu(SpaprTceTable *tcet);
799ad0ebb91SDavid Gibson int spapr_dma_dt(void *fdt, int node_off, const char *propname,
8005c4cbcf2SAlexey Kardashevskiy                  uint32_t liobn, uint64_t window, uint32_t size);
8015c4cbcf2SAlexey Kardashevskiy int spapr_tcet_dma_dt(void *fdt, int node_off, const char *propname,
802ce2918cbSDavid Gibson                       SpaprTceTable *tcet);
803eefaccc0SDavid Gibson void spapr_pci_switch_vga(bool big_endian);
804ce2918cbSDavid Gibson void spapr_hotplug_req_add_by_index(SpaprDrc *drc);
805ce2918cbSDavid Gibson void spapr_hotplug_req_remove_by_index(SpaprDrc *drc);
806ce2918cbSDavid Gibson void spapr_hotplug_req_add_by_count(SpaprDrcType drc_type,
8077a36ae7aSBharata B Rao                                        uint32_t count);
808ce2918cbSDavid Gibson void spapr_hotplug_req_remove_by_count(SpaprDrcType drc_type,
8097a36ae7aSBharata B Rao                                           uint32_t count);
810ce2918cbSDavid Gibson void spapr_hotplug_req_add_by_count_indexed(SpaprDrcType drc_type,
811afdbd403SBharata B Rao                                             uint32_t count, uint32_t index);
812ce2918cbSDavid Gibson void spapr_hotplug_req_remove_by_count_indexed(SpaprDrcType drc_type,
813afdbd403SBharata B Rao                                                uint32_t count, uint32_t index);
8140b0b8310SDavid Gibson int spapr_hpt_shift_for_ramsize(uint64_t ramsize);
815ce2918cbSDavid Gibson void spapr_reallocate_hpt(SpaprMachineState *spapr, int shift,
8162772cf6bSDavid Gibson                           Error **errp);
817ce2918cbSDavid Gibson void spapr_clear_pending_events(SpaprMachineState *spapr);
818ce2918cbSDavid Gibson int spapr_max_server_number(SpaprMachineState *spapr);
819a2dd4e83SBenjamin Herrenschmidt void spapr_store_hpte(PowerPCCPU *cpu, hwaddr ptex,
820a2dd4e83SBenjamin Herrenschmidt                       uint64_t pte0, uint64_t pte1);
82181fe70e4SAravinda Prasad void spapr_mce_req_event(PowerPCCPU *cpu, bool recovered);
82228df36a1SDavid Gibson 
82362d38c9bSGreg Kurz /* DRC callbacks. */
82431834723SDaniel Henrique Barboza void spapr_core_release(DeviceState *dev);
825ce2918cbSDavid Gibson int spapr_core_dt_populate(SpaprDrc *drc, SpaprMachineState *spapr,
826345b12b9SGreg Kurz                            void *fdt, int *fdt_start_offset, Error **errp);
82731834723SDaniel Henrique Barboza void spapr_lmb_release(DeviceState *dev);
828ce2918cbSDavid Gibson int spapr_lmb_dt_populate(SpaprDrc *drc, SpaprMachineState *spapr,
82962d38c9bSGreg Kurz                           void *fdt, int *fdt_start_offset, Error **errp);
830bb2bdd81SGreg Kurz void spapr_phb_release(DeviceState *dev);
831ce2918cbSDavid Gibson int spapr_phb_dt_populate(SpaprDrc *drc, SpaprMachineState *spapr,
832bb2bdd81SGreg Kurz                           void *fdt, int *fdt_start_offset, Error **errp);
83331834723SDaniel Henrique Barboza 
834ce2918cbSDavid Gibson void spapr_rtc_read(SpaprRtcState *rtc, struct tm *tm, uint32_t *ns);
835ce2918cbSDavid Gibson int spapr_rtc_import_offset(SpaprRtcState *rtc, int64_t legacy_offset);
83628df36a1SDavid Gibson 
837147ff807SCédric Le Goater #define TYPE_SPAPR_RNG "spapr-rng"
838ad0ebb91SDavid Gibson 
839e075623aSDavid Gibson #define SPAPR_MEMORY_BLOCK_SIZE ((hwaddr)1 << 28) /* 256MB */
840db4ef288SBharata B Rao 
8414a1c9cf0SBharata B Rao /*
8424a1c9cf0SBharata B Rao  * This defines the maximum number of DIMM slots we can have for sPAPR
8434a1c9cf0SBharata B Rao  * guest. This is not defined by sPAPR but we are defining it to 32 slots
8444a1c9cf0SBharata B Rao  * based on default number of slots provided by PowerPC kernel.
8454a1c9cf0SBharata B Rao  */
8464a1c9cf0SBharata B Rao #define SPAPR_MAX_RAM_SLOTS     32
8474a1c9cf0SBharata B Rao 
848ab3dd749SPhilippe Mathieu-Daudé /* 1GB alignment for hotplug memory region */
849ab3dd749SPhilippe Mathieu-Daudé #define SPAPR_DEVICE_MEM_ALIGN (1 * GiB)
8504a1c9cf0SBharata B Rao 
85103d196b7SBharata B Rao /*
85203d196b7SBharata B Rao  * Number of 32 bit words in each LMB list entry in ibm,dynamic-memory
85303d196b7SBharata B Rao  * property under ibm,dynamic-reconfiguration-memory node.
85403d196b7SBharata B Rao  */
85503d196b7SBharata B Rao #define SPAPR_DR_LMB_LIST_ENTRY_SIZE 6
85603d196b7SBharata B Rao 
85703d196b7SBharata B Rao /*
858d0e5a8f2SBharata B Rao  * Defines for flag value in ibm,dynamic-memory property under
859d0e5a8f2SBharata B Rao  * ibm,dynamic-reconfiguration-memory node.
86003d196b7SBharata B Rao  */
86103d196b7SBharata B Rao #define SPAPR_LMB_FLAGS_ASSIGNED 0x00000008
862d0e5a8f2SBharata B Rao #define SPAPR_LMB_FLAGS_DRC_INVALID 0x00000020
863d0e5a8f2SBharata B Rao #define SPAPR_LMB_FLAGS_RESERVED 0x00000080
86403d196b7SBharata B Rao 
8651c7ad77eSNicholas Piggin void spapr_do_system_reset_on_cpu(CPUState *cs, run_on_cpu_data arg);
8661c7ad77eSNicholas Piggin 
8670b0b8310SDavid Gibson #define HTAB_SIZE(spapr)        (1ULL << ((spapr)->htab_shift))
8680b0b8310SDavid Gibson 
86914bb4486SGreg Kurz int spapr_get_vcpu_id(PowerPCCPU *cpu);
870648edb64SGreg Kurz void spapr_set_vcpu_id(PowerPCCPU *cpu, int cpu_index, Error **errp);
8712e886fb3SSam Bobroff PowerPCCPU *spapr_find_cpu(int vcpu_id);
8722e886fb3SSam Bobroff 
8734e5fe368SSuraj Jitindar Singh int spapr_caps_pre_load(void *opaque);
8744e5fe368SSuraj Jitindar Singh int spapr_caps_pre_save(void *opaque);
8754e5fe368SSuraj Jitindar Singh 
87633face6bSDavid Gibson /*
87733face6bSDavid Gibson  * Handling of optional capabilities
87833face6bSDavid Gibson  */
8794e5fe368SSuraj Jitindar Singh extern const VMStateDescription vmstate_spapr_cap_htm;
8804e5fe368SSuraj Jitindar Singh extern const VMStateDescription vmstate_spapr_cap_vsx;
8814e5fe368SSuraj Jitindar Singh extern const VMStateDescription vmstate_spapr_cap_dfp;
8828f38eaf8SSuraj Jitindar Singh extern const VMStateDescription vmstate_spapr_cap_cfpc;
88309114fd8SSuraj Jitindar Singh extern const VMStateDescription vmstate_spapr_cap_sbbc;
8844be8d4e7SSuraj Jitindar Singh extern const VMStateDescription vmstate_spapr_cap_ibs;
88564d4a534SDavid Gibson extern const VMStateDescription vmstate_spapr_cap_hpt_maxpagesize;
886b9a477b7SSuraj Jitindar Singh extern const VMStateDescription vmstate_spapr_cap_nested_kvm_hv;
887c982f5cfSSuraj Jitindar Singh extern const VMStateDescription vmstate_spapr_cap_large_decr;
8888ff43ee4SSuraj Jitindar Singh extern const VMStateDescription vmstate_spapr_cap_ccf_assist;
8899d953ce4SAravinda Prasad extern const VMStateDescription vmstate_spapr_cap_fwnmi;
890be85537dSDavid Gibson 
891ce2918cbSDavid Gibson static inline uint8_t spapr_get_cap(SpaprMachineState *spapr, int cap)
89233face6bSDavid Gibson {
8934e5fe368SSuraj Jitindar Singh     return spapr->eff.caps[cap];
89433face6bSDavid Gibson }
89533face6bSDavid Gibson 
896ce2918cbSDavid Gibson void spapr_caps_init(SpaprMachineState *spapr);
897ce2918cbSDavid Gibson void spapr_caps_apply(SpaprMachineState *spapr);
898ce2918cbSDavid Gibson void spapr_caps_cpu_apply(SpaprMachineState *spapr, PowerPCCPU *cpu);
899ce2918cbSDavid Gibson void spapr_caps_add_properties(SpaprMachineClass *smc, Error **errp);
900ce2918cbSDavid Gibson int spapr_caps_post_migration(SpaprMachineState *spapr);
90133face6bSDavid Gibson 
902ce2918cbSDavid Gibson void spapr_check_pagesize(SpaprMachineState *spapr, hwaddr pagesize,
903123eec65SDavid Gibson                           Error **errp);
904db592b5bSCédric Le Goater /*
905db592b5bSCédric Le Goater  * XIVE definitions
906db592b5bSCédric Le Goater  */
907db592b5bSCédric Le Goater #define SPAPR_OV5_XIVE_LEGACY   0x0
908db592b5bSCédric Le Goater #define SPAPR_OV5_XIVE_EXPLOIT  0x40
909db592b5bSCédric Le Goater #define SPAPR_OV5_XIVE_BOTH     0x80 /* Only to advertise on the platform */
910123eec65SDavid Gibson 
91100fd075eSBenjamin Herrenschmidt void spapr_set_all_lpcrs(target_ulong value, target_ulong mask);
91281fe70e4SAravinda Prasad hwaddr spapr_get_rtas_addr(void);
9132a6a4076SMarkus Armbruster #endif /* HW_SPAPR_H */
914