xref: /qemu/include/hw/ppc/spapr.h (revision 4be8d4e7d935fc8919d61f53a0f0fb7230052bb3)
12a6a4076SMarkus Armbruster #ifndef HW_SPAPR_H
22a6a4076SMarkus Armbruster #define HW_SPAPR_H
39fdf0c29SDavid Gibson 
49c17d615SPaolo Bonzini #include "sysemu/dma.h"
528e02042SDavid Gibson #include "hw/boards.h"
60d09e41aSPaolo Bonzini #include "hw/ppc/xics.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"
10277f9acfSPaolo Bonzini 
114040ab72SDavid Gibson struct VIOsPAPRBus;
123384f95cSDavid Gibson struct sPAPRPHBState;
13639e8102SDavid Gibson struct sPAPRNVRAM;
1431fe14d1SNathan Fontenot typedef struct sPAPREventLogEntry sPAPREventLogEntry;
15ffbb1705SMichael Roth typedef struct sPAPREventSource sPAPREventSource;
160b0b8310SDavid Gibson typedef struct sPAPRPendingHPT sPAPRPendingHPT;
174040ab72SDavid Gibson 
184be21d56SDavid Gibson #define HPTE64_V_HPTE_DIRTY     0x0000000000000040ULL
191b718907SDavid Gibson #define SPAPR_ENTRY_POINT       0x100
204be21d56SDavid Gibson 
21afd10a0fSBharata B Rao #define SPAPR_TIMEBASE_FREQ     512000000ULL
22afd10a0fSBharata B Rao 
23147ff807SCédric Le Goater #define TYPE_SPAPR_RTC "spapr-rtc"
24147ff807SCédric Le Goater 
25147ff807SCédric Le Goater #define SPAPR_RTC(obj)                                  \
26147ff807SCédric Le Goater     OBJECT_CHECK(sPAPRRTCState, (obj), TYPE_SPAPR_RTC)
27147ff807SCédric Le Goater 
28147ff807SCédric Le Goater typedef struct sPAPRRTCState sPAPRRTCState;
29147ff807SCédric Le Goater struct sPAPRRTCState {
30147ff807SCédric Le Goater     /*< private >*/
31147ff807SCédric Le Goater     DeviceState parent_obj;
32147ff807SCédric Le Goater     int64_t ns_offset;
33147ff807SCédric Le Goater };
34147ff807SCédric Le Goater 
350cffce56SDavid Gibson typedef struct sPAPRDIMMState sPAPRDIMMState;
36183930c0SDavid Gibson typedef struct sPAPRMachineClass sPAPRMachineClass;
3728e02042SDavid Gibson 
3828e02042SDavid Gibson #define TYPE_SPAPR_MACHINE      "spapr-machine"
3928e02042SDavid Gibson #define SPAPR_MACHINE(obj) \
4028e02042SDavid Gibson     OBJECT_CHECK(sPAPRMachineState, (obj), TYPE_SPAPR_MACHINE)
41183930c0SDavid Gibson #define SPAPR_MACHINE_GET_CLASS(obj) \
42183930c0SDavid Gibson     OBJECT_GET_CLASS(sPAPRMachineClass, obj, TYPE_SPAPR_MACHINE)
43183930c0SDavid Gibson #define SPAPR_MACHINE_CLASS(klass) \
44183930c0SDavid Gibson     OBJECT_CLASS_CHECK(sPAPRMachineClass, klass, TYPE_SPAPR_MACHINE)
45183930c0SDavid Gibson 
4630f4b05bSDavid Gibson typedef enum {
4730f4b05bSDavid Gibson     SPAPR_RESIZE_HPT_DEFAULT = 0,
4830f4b05bSDavid Gibson     SPAPR_RESIZE_HPT_DISABLED,
4930f4b05bSDavid Gibson     SPAPR_RESIZE_HPT_ENABLED,
5030f4b05bSDavid Gibson     SPAPR_RESIZE_HPT_REQUIRED,
5130f4b05bSDavid Gibson } sPAPRResizeHPT;
5230f4b05bSDavid Gibson 
53183930c0SDavid Gibson /**
5433face6bSDavid Gibson  * Capabilities
5533face6bSDavid Gibson  */
5633face6bSDavid Gibson 
57ee76a09fSDavid Gibson /* Hardware Transactional Memory */
584e5fe368SSuraj Jitindar Singh #define SPAPR_CAP_HTM                   0x00
5929386642SDavid Gibson /* Vector Scalar Extensions */
604e5fe368SSuraj Jitindar Singh #define SPAPR_CAP_VSX                   0x01
612d1fb9bcSDavid Gibson /* Decimal Floating Point */
624e5fe368SSuraj Jitindar Singh #define SPAPR_CAP_DFP                   0x02
638f38eaf8SSuraj Jitindar Singh /* Cache Flush on Privilege Change */
648f38eaf8SSuraj Jitindar Singh #define SPAPR_CAP_CFPC                  0x03
6509114fd8SSuraj Jitindar Singh /* Speculation Barrier Bounds Checking */
6609114fd8SSuraj Jitindar Singh #define SPAPR_CAP_SBBC                  0x04
67*4be8d4e7SSuraj Jitindar Singh /* Indirect Branch Serialisation */
68*4be8d4e7SSuraj Jitindar Singh #define SPAPR_CAP_IBS                   0x05
694e5fe368SSuraj Jitindar Singh /* Num Caps */
70*4be8d4e7SSuraj Jitindar Singh #define SPAPR_CAP_NUM                   (SPAPR_CAP_IBS + 1)
714e5fe368SSuraj Jitindar Singh 
724e5fe368SSuraj Jitindar Singh /*
734e5fe368SSuraj Jitindar Singh  * Capability Values
744e5fe368SSuraj Jitindar Singh  */
754e5fe368SSuraj Jitindar Singh /* Bool Caps */
764e5fe368SSuraj Jitindar Singh #define SPAPR_CAP_OFF                   0x00
774e5fe368SSuraj Jitindar Singh #define SPAPR_CAP_ON                    0x01
786898aed7SSuraj Jitindar Singh /* Broken | Workaround | Fixed Caps */
796898aed7SSuraj Jitindar Singh #define SPAPR_CAP_BROKEN                0x00
806898aed7SSuraj Jitindar Singh #define SPAPR_CAP_WORKAROUND            0x01
816898aed7SSuraj Jitindar Singh #define SPAPR_CAP_FIXED                 0x02
822d1fb9bcSDavid Gibson 
8333face6bSDavid Gibson typedef struct sPAPRCapabilities sPAPRCapabilities;
8433face6bSDavid Gibson struct sPAPRCapabilities {
854e5fe368SSuraj Jitindar Singh     uint8_t caps[SPAPR_CAP_NUM];
8633face6bSDavid Gibson };
8733face6bSDavid Gibson 
8833face6bSDavid Gibson /**
89183930c0SDavid Gibson  * sPAPRMachineClass:
90183930c0SDavid Gibson  */
91183930c0SDavid Gibson struct sPAPRMachineClass {
92183930c0SDavid Gibson     /*< private >*/
93183930c0SDavid Gibson     MachineClass parent_class;
94183930c0SDavid Gibson 
95183930c0SDavid Gibson     /*< public >*/
96224245bfSDavid Gibson     bool dr_lmb_enabled;       /* enable dynamic-reconfig/hotplug of LMBs */
9757040d45SThomas Huth     bool use_ohci_by_default;  /* use USB-OHCI instead of XHCI */
9846f7afa3SGreg Kurz     bool pre_2_10_has_unused_icps;
996737d9adSDavid Gibson     void (*phb_placement)(sPAPRMachineState *spapr, uint32_t index,
100daa23699SDavid Gibson                           uint64_t *buid, hwaddr *pio,
101daa23699SDavid Gibson                           hwaddr *mmio32, hwaddr *mmio64,
1026737d9adSDavid Gibson                           unsigned n_dma, uint32_t *liobns, Error **errp);
10330f4b05bSDavid Gibson     sPAPRResizeHPT resize_hpt_default;
10433face6bSDavid Gibson     sPAPRCapabilities default_caps;
105183930c0SDavid Gibson };
10628e02042SDavid Gibson 
10728e02042SDavid Gibson /**
10828e02042SDavid Gibson  * sPAPRMachineState:
10928e02042SDavid Gibson  */
11028e02042SDavid Gibson struct sPAPRMachineState {
11128e02042SDavid Gibson     /*< private >*/
11228e02042SDavid Gibson     MachineState parent_obj;
11328e02042SDavid Gibson 
1144040ab72SDavid Gibson     struct VIOsPAPRBus *vio_bus;
1153384f95cSDavid Gibson     QLIST_HEAD(, sPAPRPHBState) phbs;
116639e8102SDavid Gibson     struct sPAPRNVRAM *nvram;
117681bfadeSCédric Le Goater     ICSState *ics;
118147ff807SCédric Le Goater     sPAPRRTCState rtc;
119a3467baaSDavid Gibson 
12030f4b05bSDavid Gibson     sPAPRResizeHPT resize_hpt;
121a3467baaSDavid Gibson     void *htab;
1224be21d56SDavid Gibson     uint32_t htab_shift;
1239861bb3eSSuraj Jitindar Singh     uint64_t patb_entry; /* Process tbl registed in H_REGISTER_PROCESS_TABLE */
1240b0b8310SDavid Gibson     sPAPRPendingHPT *pending_hpt; /* in-progress resize */
1250b0b8310SDavid Gibson 
126a8170e5eSAvi Kivity     hwaddr rma_size;
1277f763a5dSDavid Gibson     int vrma_adjust;
128b7d1f77aSBenjamin Herrenschmidt     ssize_t rtas_size;
129b7d1f77aSBenjamin Herrenschmidt     void *rtas_blob;
130a19f7fb0SDavid Gibson     long kernel_size;
131a19f7fb0SDavid Gibson     bool kernel_le;
132a19f7fb0SDavid Gibson     uint32_t initrd_base;
133a19f7fb0SDavid Gibson     long initrd_size;
134880ae7deSDavid Gibson     uint64_t rtc_offset; /* Now used only during incoming migration */
13598a8b524SAlexey Kardashevskiy     struct PPCTimebase tb;
1363fc5acdeSAlexander Graf     bool has_graphics;
137fa98fbfcSSam Bobroff     uint32_t vsmt;       /* Virtual SMT mode (KVM's "core stride") */
13874d042e5SDavid Gibson 
13974d042e5SDavid Gibson     Notifier epow_notifier;
14031fe14d1SNathan Fontenot     QTAILQ_HEAD(, sPAPREventLogEntry) pending_events;
141ffbb1705SMichael Roth     bool use_hotplug_event_source;
142ffbb1705SMichael Roth     sPAPREventSource *event_sources;
1434be21d56SDavid Gibson 
1447843c0d6SDavid Gibson     /* ibm,client-architecture-support option negotiation */
1457843c0d6SDavid Gibson     bool cas_reboot;
1467843c0d6SDavid Gibson     bool cas_legacy_guest_workaround;
1477843c0d6SDavid Gibson     sPAPROptionVector *ov5;         /* QEMU-supported option vectors */
1487843c0d6SDavid Gibson     sPAPROptionVector *ov5_cas;     /* negotiated (via CAS) option vectors */
1497843c0d6SDavid Gibson     uint32_t max_compat_pvr;
1507843c0d6SDavid Gibson 
1514be21d56SDavid Gibson     /* Migration state */
1524be21d56SDavid Gibson     int htab_save_index;
1534be21d56SDavid Gibson     bool htab_first_pass;
154e68cb8b4SAlexey Kardashevskiy     int htab_fd;
15546503c2bSMichael Roth 
1560cffce56SDavid Gibson     /* Pending DIMM unplug cache. It is populated when a LMB
1570cffce56SDavid Gibson      * unplug starts. It can be regenerated if a migration
1580cffce56SDavid Gibson      * occurs during the unplug process. */
1590cffce56SDavid Gibson     QTAILQ_HEAD(, sPAPRDIMMState) pending_dimm_unplugs;
1600cffce56SDavid Gibson 
16128e02042SDavid Gibson     /*< public >*/
16228e02042SDavid Gibson     char *kvm_type;
1634a1c9cf0SBharata B Rao     MemoryHotplugState hotplug_memory;
164852ad27eSCédric Le Goater 
1655bc8d26dSCédric Le Goater     const char *icp_type;
16633face6bSDavid Gibson 
1674e5fe368SSuraj Jitindar Singh     bool cmd_line_caps[SPAPR_CAP_NUM];
1684e5fe368SSuraj Jitindar Singh     sPAPRCapabilities def, eff, mig;
16928e02042SDavid Gibson };
1709fdf0c29SDavid Gibson 
1719fdf0c29SDavid Gibson #define H_SUCCESS         0
1729fdf0c29SDavid Gibson #define H_BUSY            1        /* Hardware busy -- retry later */
1739fdf0c29SDavid Gibson #define H_CLOSED          2        /* Resource closed */
1749fdf0c29SDavid Gibson #define H_NOT_AVAILABLE   3
1759fdf0c29SDavid Gibson #define H_CONSTRAINED     4        /* Resource request constrained to max allowed */
1769fdf0c29SDavid Gibson #define H_PARTIAL         5
1779fdf0c29SDavid Gibson #define H_IN_PROGRESS     14       /* Kind of like busy */
1789fdf0c29SDavid Gibson #define H_PAGE_REGISTERED 15
1799fdf0c29SDavid Gibson #define H_PARTIAL_STORE   16
1809fdf0c29SDavid Gibson #define H_PENDING         17       /* returned from H_POLL_PENDING */
1819fdf0c29SDavid Gibson #define H_CONTINUE        18       /* Returned from H_Join on success */
1829fdf0c29SDavid Gibson #define H_LONG_BUSY_START_RANGE         9900  /* Start of long busy range */
1839fdf0c29SDavid Gibson #define H_LONG_BUSY_ORDER_1_MSEC        9900  /* Long busy, hint that 1msec \
1849fdf0c29SDavid Gibson                                                  is a good time to retry */
1859fdf0c29SDavid Gibson #define H_LONG_BUSY_ORDER_10_MSEC       9901  /* Long busy, hint that 10msec \
1869fdf0c29SDavid Gibson                                                  is a good time to retry */
1879fdf0c29SDavid Gibson #define H_LONG_BUSY_ORDER_100_MSEC      9902  /* Long busy, hint that 100msec \
1889fdf0c29SDavid Gibson                                                  is a good time to retry */
1899fdf0c29SDavid Gibson #define H_LONG_BUSY_ORDER_1_SEC         9903  /* Long busy, hint that 1sec \
1909fdf0c29SDavid Gibson                                                  is a good time to retry */
1919fdf0c29SDavid Gibson #define H_LONG_BUSY_ORDER_10_SEC        9904  /* Long busy, hint that 10sec \
1929fdf0c29SDavid Gibson                                                  is a good time to retry */
1939fdf0c29SDavid Gibson #define H_LONG_BUSY_ORDER_100_SEC       9905  /* Long busy, hint that 100sec \
1949fdf0c29SDavid Gibson                                                  is a good time to retry */
1959fdf0c29SDavid Gibson #define H_LONG_BUSY_END_RANGE           9905  /* End of long busy range */
1969fdf0c29SDavid Gibson #define H_HARDWARE        -1       /* Hardware error */
1979fdf0c29SDavid Gibson #define H_FUNCTION        -2       /* Function not supported */
1989fdf0c29SDavid Gibson #define H_PRIVILEGE       -3       /* Caller not privileged */
1999fdf0c29SDavid Gibson #define H_PARAMETER       -4       /* Parameter invalid, out-of-range or conflicting */
2009fdf0c29SDavid Gibson #define H_BAD_MODE        -5       /* Illegal msr value */
2019fdf0c29SDavid Gibson #define H_PTEG_FULL       -6       /* PTEG is full */
2029fdf0c29SDavid Gibson #define H_NOT_FOUND       -7       /* PTE was not found" */
2039fdf0c29SDavid Gibson #define H_RESERVED_DABR   -8       /* DABR address is reserved by the hypervisor on this processor" */
2049fdf0c29SDavid Gibson #define H_NO_MEM          -9
2059fdf0c29SDavid Gibson #define H_AUTHORITY       -10
2069fdf0c29SDavid Gibson #define H_PERMISSION      -11
2079fdf0c29SDavid Gibson #define H_DROPPED         -12
2089fdf0c29SDavid Gibson #define H_SOURCE_PARM     -13
2099fdf0c29SDavid Gibson #define H_DEST_PARM       -14
2109fdf0c29SDavid Gibson #define H_REMOTE_PARM     -15
2119fdf0c29SDavid Gibson #define H_RESOURCE        -16
2129fdf0c29SDavid Gibson #define H_ADAPTER_PARM    -17
2139fdf0c29SDavid Gibson #define H_RH_PARM         -18
2149fdf0c29SDavid Gibson #define H_RCQ_PARM        -19
2159fdf0c29SDavid Gibson #define H_SCQ_PARM        -20
2169fdf0c29SDavid Gibson #define H_EQ_PARM         -21
2179fdf0c29SDavid Gibson #define H_RT_PARM         -22
2189fdf0c29SDavid Gibson #define H_ST_PARM         -23
2199fdf0c29SDavid Gibson #define H_SIGT_PARM       -24
2209fdf0c29SDavid Gibson #define H_TOKEN_PARM      -25
2219fdf0c29SDavid Gibson #define H_MLENGTH_PARM    -27
2229fdf0c29SDavid Gibson #define H_MEM_PARM        -28
2239fdf0c29SDavid Gibson #define H_MEM_ACCESS_PARM -29
2249fdf0c29SDavid Gibson #define H_ATTR_PARM       -30
2259fdf0c29SDavid Gibson #define H_PORT_PARM       -31
2269fdf0c29SDavid Gibson #define H_MCG_PARM        -32
2279fdf0c29SDavid Gibson #define H_VL_PARM         -33
2289fdf0c29SDavid Gibson #define H_TSIZE_PARM      -34
2299fdf0c29SDavid Gibson #define H_TRACE_PARM      -35
2309fdf0c29SDavid Gibson 
2319fdf0c29SDavid Gibson #define H_MASK_PARM       -37
2329fdf0c29SDavid Gibson #define H_MCG_FULL        -38
2339fdf0c29SDavid Gibson #define H_ALIAS_EXIST     -39
2349fdf0c29SDavid Gibson #define H_P_COUNTER       -40
2359fdf0c29SDavid Gibson #define H_TABLE_FULL      -41
2369fdf0c29SDavid Gibson #define H_ALT_TABLE       -42
2379fdf0c29SDavid Gibson #define H_MR_CONDITION    -43
2389fdf0c29SDavid Gibson #define H_NOT_ENOUGH_RESOURCES -44
2399fdf0c29SDavid Gibson #define H_R_STATE         -45
2409fdf0c29SDavid Gibson #define H_RESCINDEND      -46
24142561bf2SAnton Blanchard #define H_P2              -55
24242561bf2SAnton Blanchard #define H_P3              -56
24342561bf2SAnton Blanchard #define H_P4              -57
24442561bf2SAnton Blanchard #define H_P5              -58
24542561bf2SAnton Blanchard #define H_P6              -59
24642561bf2SAnton Blanchard #define H_P7              -60
24742561bf2SAnton Blanchard #define H_P8              -61
24842561bf2SAnton Blanchard #define H_P9              -62
24942561bf2SAnton Blanchard #define H_UNSUPPORTED_FLAG -256
2509fdf0c29SDavid Gibson #define H_MULTI_THREADS_ACTIVE -9005
2519fdf0c29SDavid Gibson 
2529fdf0c29SDavid Gibson 
2539fdf0c29SDavid Gibson /* Long Busy is a condition that can be returned by the firmware
2549fdf0c29SDavid Gibson  * when a call cannot be completed now, but the identical call
2559fdf0c29SDavid Gibson  * should be retried later.  This prevents calls blocking in the
2569fdf0c29SDavid Gibson  * firmware for long periods of time.  Annoyingly the firmware can return
2579fdf0c29SDavid Gibson  * a range of return codes, hinting at how long we should wait before
2589fdf0c29SDavid Gibson  * retrying.  If you don't care for the hint, the macro below is a good
2599fdf0c29SDavid Gibson  * way to check for the long_busy return codes
2609fdf0c29SDavid Gibson  */
2619fdf0c29SDavid Gibson #define H_IS_LONG_BUSY(x)  ((x >= H_LONG_BUSY_START_RANGE) \
2629fdf0c29SDavid Gibson                             && (x <= H_LONG_BUSY_END_RANGE))
2639fdf0c29SDavid Gibson 
2649fdf0c29SDavid Gibson /* Flags */
2659fdf0c29SDavid Gibson #define H_LARGE_PAGE      (1ULL<<(63-16))
2669fdf0c29SDavid Gibson #define H_EXACT           (1ULL<<(63-24))       /* Use exact PTE or return H_PTEG_FULL */
2679fdf0c29SDavid Gibson #define H_R_XLATE         (1ULL<<(63-25))       /* include a valid logical page num in the pte if the valid bit is set */
2689fdf0c29SDavid Gibson #define H_READ_4          (1ULL<<(63-26))       /* Return 4 PTEs */
2699fdf0c29SDavid Gibson #define H_PAGE_STATE_CHANGE (1ULL<<(63-28))
2709fdf0c29SDavid Gibson #define H_PAGE_UNUSED     ((1ULL<<(63-29)) | (1ULL<<(63-30)))
2719fdf0c29SDavid Gibson #define H_PAGE_SET_UNUSED (H_PAGE_STATE_CHANGE | H_PAGE_UNUSED)
2729fdf0c29SDavid Gibson #define H_PAGE_SET_LOANED (H_PAGE_SET_UNUSED | (1ULL<<(63-31)))
2739fdf0c29SDavid Gibson #define H_PAGE_SET_ACTIVE H_PAGE_STATE_CHANGE
2749fdf0c29SDavid Gibson #define H_AVPN            (1ULL<<(63-32))       /* An avpn is provided as a sanity test */
2759fdf0c29SDavid Gibson #define H_ANDCOND         (1ULL<<(63-33))
2769fdf0c29SDavid Gibson #define H_ICACHE_INVALIDATE (1ULL<<(63-40))     /* icbi, etc.  (ignored for IO pages) */
2779fdf0c29SDavid Gibson #define H_ICACHE_SYNCHRONIZE (1ULL<<(63-41))    /* dcbst, icbi, etc (ignored for IO pages */
2789fdf0c29SDavid Gibson #define H_ZERO_PAGE       (1ULL<<(63-48))       /* zero the page before mapping (ignored for IO pages) */
2799fdf0c29SDavid Gibson #define H_COPY_PAGE       (1ULL<<(63-49))
2809fdf0c29SDavid Gibson #define H_N               (1ULL<<(63-61))
2819fdf0c29SDavid Gibson #define H_PP1             (1ULL<<(63-62))
2829fdf0c29SDavid Gibson #define H_PP2             (1ULL<<(63-63))
2839fdf0c29SDavid Gibson 
284a46622fdSAlexey Kardashevskiy /* Values for 2nd argument to H_SET_MODE */
285a46622fdSAlexey Kardashevskiy #define H_SET_MODE_RESOURCE_SET_CIABR           1
286a46622fdSAlexey Kardashevskiy #define H_SET_MODE_RESOURCE_SET_DAWR            2
287a46622fdSAlexey Kardashevskiy #define H_SET_MODE_RESOURCE_ADDR_TRANS_MODE     3
288a46622fdSAlexey Kardashevskiy #define H_SET_MODE_RESOURCE_LE                  4
289a46622fdSAlexey Kardashevskiy 
290a46622fdSAlexey Kardashevskiy /* Flags for H_SET_MODE_RESOURCE_LE */
29142561bf2SAnton Blanchard #define H_SET_MODE_ENDIAN_BIG    0
29242561bf2SAnton Blanchard #define H_SET_MODE_ENDIAN_LITTLE 1
29342561bf2SAnton Blanchard 
2949fdf0c29SDavid Gibson /* VASI States */
2959fdf0c29SDavid Gibson #define H_VASI_INVALID    0
2969fdf0c29SDavid Gibson #define H_VASI_ENABLED    1
2979fdf0c29SDavid Gibson #define H_VASI_ABORTED    2
2989fdf0c29SDavid Gibson #define H_VASI_SUSPENDING 3
2999fdf0c29SDavid Gibson #define H_VASI_SUSPENDED  4
3009fdf0c29SDavid Gibson #define H_VASI_RESUMED    5
3019fdf0c29SDavid Gibson #define H_VASI_COMPLETED  6
3029fdf0c29SDavid Gibson 
3039fdf0c29SDavid Gibson /* DABRX flags */
3049fdf0c29SDavid Gibson #define H_DABRX_HYPERVISOR (1ULL<<(63-61))
3059fdf0c29SDavid Gibson #define H_DABRX_KERNEL     (1ULL<<(63-62))
3069fdf0c29SDavid Gibson #define H_DABRX_USER       (1ULL<<(63-63))
3079fdf0c29SDavid Gibson 
3088acc2ae5SSuraj Jitindar Singh /* Values for KVM_PPC_GET_CPU_CHAR & H_GET_CPU_CHARACTERISTICS */
3098acc2ae5SSuraj Jitindar Singh #define H_CPU_CHAR_SPEC_BAR_ORI31               PPC_BIT(0)
3108acc2ae5SSuraj Jitindar Singh #define H_CPU_CHAR_BCCTRL_SERIALISED            PPC_BIT(1)
3118acc2ae5SSuraj Jitindar Singh #define H_CPU_CHAR_L1D_FLUSH_ORI30              PPC_BIT(2)
3128acc2ae5SSuraj Jitindar Singh #define H_CPU_CHAR_L1D_FLUSH_TRIG2              PPC_BIT(3)
3138acc2ae5SSuraj Jitindar Singh #define H_CPU_CHAR_L1D_THREAD_PRIV              PPC_BIT(4)
3148acc2ae5SSuraj Jitindar Singh #define H_CPU_CHAR_HON_BRANCH_HINTS             PPC_BIT(5)
3158acc2ae5SSuraj Jitindar Singh #define H_CPU_CHAR_THR_RECONF_TRIG              PPC_BIT(6)
3168acc2ae5SSuraj Jitindar Singh #define H_CPU_BEHAV_FAVOUR_SECURITY             PPC_BIT(0)
3178acc2ae5SSuraj Jitindar Singh #define H_CPU_BEHAV_L1D_FLUSH_PR                PPC_BIT(1)
3188acc2ae5SSuraj Jitindar Singh #define H_CPU_BEHAV_BNDS_CHK_SPEC_BAR           PPC_BIT(2)
3198acc2ae5SSuraj Jitindar Singh 
32066a0a2cbSDong Xu Wang /* Each control block has to be on a 4K boundary */
3219fdf0c29SDavid Gibson #define H_CB_ALIGNMENT     4096
3229fdf0c29SDavid Gibson 
3239fdf0c29SDavid Gibson /* pSeries hypervisor opcodes */
3249fdf0c29SDavid Gibson #define H_REMOVE                0x04
3259fdf0c29SDavid Gibson #define H_ENTER                 0x08
3269fdf0c29SDavid Gibson #define H_READ                  0x0c
3279fdf0c29SDavid Gibson #define H_CLEAR_MOD             0x10
3289fdf0c29SDavid Gibson #define H_CLEAR_REF             0x14
3299fdf0c29SDavid Gibson #define H_PROTECT               0x18
3309fdf0c29SDavid Gibson #define H_GET_TCE               0x1c
3319fdf0c29SDavid Gibson #define H_PUT_TCE               0x20
3329fdf0c29SDavid Gibson #define H_SET_SPRG0             0x24
3339fdf0c29SDavid Gibson #define H_SET_DABR              0x28
3349fdf0c29SDavid Gibson #define H_PAGE_INIT             0x2c
3359fdf0c29SDavid Gibson #define H_SET_ASR               0x30
3369fdf0c29SDavid Gibson #define H_ASR_ON                0x34
3379fdf0c29SDavid Gibson #define H_ASR_OFF               0x38
3389fdf0c29SDavid Gibson #define H_LOGICAL_CI_LOAD       0x3c
3399fdf0c29SDavid Gibson #define H_LOGICAL_CI_STORE      0x40
3409fdf0c29SDavid Gibson #define H_LOGICAL_CACHE_LOAD    0x44
3419fdf0c29SDavid Gibson #define H_LOGICAL_CACHE_STORE   0x48
3429fdf0c29SDavid Gibson #define H_LOGICAL_ICBI          0x4c
3439fdf0c29SDavid Gibson #define H_LOGICAL_DCBF          0x50
3449fdf0c29SDavid Gibson #define H_GET_TERM_CHAR         0x54
3459fdf0c29SDavid Gibson #define H_PUT_TERM_CHAR         0x58
3469fdf0c29SDavid Gibson #define H_REAL_TO_LOGICAL       0x5c
3479fdf0c29SDavid Gibson #define H_HYPERVISOR_DATA       0x60
3489fdf0c29SDavid Gibson #define H_EOI                   0x64
3499fdf0c29SDavid Gibson #define H_CPPR                  0x68
3509fdf0c29SDavid Gibson #define H_IPI                   0x6c
3519fdf0c29SDavid Gibson #define H_IPOLL                 0x70
3529fdf0c29SDavid Gibson #define H_XIRR                  0x74
3539fdf0c29SDavid Gibson #define H_PERFMON               0x7c
3549fdf0c29SDavid Gibson #define H_MIGRATE_DMA           0x78
3559fdf0c29SDavid Gibson #define H_REGISTER_VPA          0xDC
3569fdf0c29SDavid Gibson #define H_CEDE                  0xE0
3579fdf0c29SDavid Gibson #define H_CONFER                0xE4
3589fdf0c29SDavid Gibson #define H_PROD                  0xE8
3599fdf0c29SDavid Gibson #define H_GET_PPP               0xEC
3609fdf0c29SDavid Gibson #define H_SET_PPP               0xF0
3619fdf0c29SDavid Gibson #define H_PURR                  0xF4
3629fdf0c29SDavid Gibson #define H_PIC                   0xF8
3639fdf0c29SDavid Gibson #define H_REG_CRQ               0xFC
3649fdf0c29SDavid Gibson #define H_FREE_CRQ              0x100
3659fdf0c29SDavid Gibson #define H_VIO_SIGNAL            0x104
3669fdf0c29SDavid Gibson #define H_SEND_CRQ              0x108
3679fdf0c29SDavid Gibson #define H_COPY_RDMA             0x110
3689fdf0c29SDavid Gibson #define H_REGISTER_LOGICAL_LAN  0x114
3699fdf0c29SDavid Gibson #define H_FREE_LOGICAL_LAN      0x118
3709fdf0c29SDavid Gibson #define H_ADD_LOGICAL_LAN_BUFFER 0x11C
3719fdf0c29SDavid Gibson #define H_SEND_LOGICAL_LAN      0x120
3729fdf0c29SDavid Gibson #define H_BULK_REMOVE           0x124
3739fdf0c29SDavid Gibson #define H_MULTICAST_CTRL        0x130
3749fdf0c29SDavid Gibson #define H_SET_XDABR             0x134
3759fdf0c29SDavid Gibson #define H_STUFF_TCE             0x138
3769fdf0c29SDavid Gibson #define H_PUT_TCE_INDIRECT      0x13C
3779fdf0c29SDavid Gibson #define H_CHANGE_LOGICAL_LAN_MAC 0x14C
3789fdf0c29SDavid Gibson #define H_VTERM_PARTNER_INFO    0x150
3799fdf0c29SDavid Gibson #define H_REGISTER_VTERM        0x154
3809fdf0c29SDavid Gibson #define H_FREE_VTERM            0x158
3819fdf0c29SDavid Gibson #define H_RESET_EVENTS          0x15C
3829fdf0c29SDavid Gibson #define H_ALLOC_RESOURCE        0x160
3839fdf0c29SDavid Gibson #define H_FREE_RESOURCE         0x164
3849fdf0c29SDavid Gibson #define H_MODIFY_QP             0x168
3859fdf0c29SDavid Gibson #define H_QUERY_QP              0x16C
3869fdf0c29SDavid Gibson #define H_REREGISTER_PMR        0x170
3879fdf0c29SDavid Gibson #define H_REGISTER_SMR          0x174
3889fdf0c29SDavid Gibson #define H_QUERY_MR              0x178
3899fdf0c29SDavid Gibson #define H_QUERY_MW              0x17C
3909fdf0c29SDavid Gibson #define H_QUERY_HCA             0x180
3919fdf0c29SDavid Gibson #define H_QUERY_PORT            0x184
3929fdf0c29SDavid Gibson #define H_MODIFY_PORT           0x188
3939fdf0c29SDavid Gibson #define H_DEFINE_AQP1           0x18C
3949fdf0c29SDavid Gibson #define H_GET_TRACE_BUFFER      0x190
3959fdf0c29SDavid Gibson #define H_DEFINE_AQP0           0x194
3969fdf0c29SDavid Gibson #define H_RESIZE_MR             0x198
3979fdf0c29SDavid Gibson #define H_ATTACH_MCQP           0x19C
3989fdf0c29SDavid Gibson #define H_DETACH_MCQP           0x1A0
3999fdf0c29SDavid Gibson #define H_CREATE_RPT            0x1A4
4009fdf0c29SDavid Gibson #define H_REMOVE_RPT            0x1A8
4019fdf0c29SDavid Gibson #define H_REGISTER_RPAGES       0x1AC
4029fdf0c29SDavid Gibson #define H_DISABLE_AND_GETC      0x1B0
4039fdf0c29SDavid Gibson #define H_ERROR_DATA            0x1B4
4049fdf0c29SDavid Gibson #define H_GET_HCA_INFO          0x1B8
4059fdf0c29SDavid Gibson #define H_GET_PERF_COUNT        0x1BC
4069fdf0c29SDavid Gibson #define H_MANAGE_TRACE          0x1C0
4079fdf0c29SDavid Gibson #define H_FREE_LOGICAL_LAN_BUFFER 0x1D4
4089fdf0c29SDavid Gibson #define H_QUERY_INT_STATE       0x1E4
4099fdf0c29SDavid Gibson #define H_POLL_PENDING          0x1D8
4109fdf0c29SDavid Gibson #define H_ILLAN_ATTRIBUTES      0x244
4119fdf0c29SDavid Gibson #define H_MODIFY_HEA_QP         0x250
4129fdf0c29SDavid Gibson #define H_QUERY_HEA_QP          0x254
4139fdf0c29SDavid Gibson #define H_QUERY_HEA             0x258
4149fdf0c29SDavid Gibson #define H_QUERY_HEA_PORT        0x25C
4159fdf0c29SDavid Gibson #define H_MODIFY_HEA_PORT       0x260
4169fdf0c29SDavid Gibson #define H_REG_BCMC              0x264
4179fdf0c29SDavid Gibson #define H_DEREG_BCMC            0x268
4189fdf0c29SDavid Gibson #define H_REGISTER_HEA_RPAGES   0x26C
4199fdf0c29SDavid Gibson #define H_DISABLE_AND_GET_HEA   0x270
4209fdf0c29SDavid Gibson #define H_GET_HEA_INFO          0x274
4219fdf0c29SDavid Gibson #define H_ALLOC_HEA_RESOURCE    0x278
4229fdf0c29SDavid Gibson #define H_ADD_CONN              0x284
4239fdf0c29SDavid Gibson #define H_DEL_CONN              0x288
4249fdf0c29SDavid Gibson #define H_JOIN                  0x298
4259fdf0c29SDavid Gibson #define H_VASI_STATE            0x2A4
4269fdf0c29SDavid Gibson #define H_ENABLE_CRQ            0x2B0
4279fdf0c29SDavid Gibson #define H_GET_EM_PARMS          0x2B8
4289fdf0c29SDavid Gibson #define H_SET_MPP               0x2D0
4299fdf0c29SDavid Gibson #define H_GET_MPP               0x2D4
4305d87e4b7SBenjamin Herrenschmidt #define H_XIRR_X                0x2FC
4314d9392beSThomas Huth #define H_RANDOM                0x300
43242561bf2SAnton Blanchard #define H_SET_MODE              0x31C
43330f4b05bSDavid Gibson #define H_RESIZE_HPT_PREPARE    0x36C
43430f4b05bSDavid Gibson #define H_RESIZE_HPT_COMMIT     0x370
435d77a98b0SSuraj Jitindar Singh #define H_CLEAN_SLB             0x374
436d77a98b0SSuraj Jitindar Singh #define H_INVALIDATE_PID        0x378
437d77a98b0SSuraj Jitindar Singh #define H_REGISTER_PROC_TBL     0x37C
4381c7ad77eSNicholas Piggin #define H_SIGNAL_SYS_RESET      0x380
4391c7ad77eSNicholas Piggin #define MAX_HCALL_OPCODE        H_SIGNAL_SYS_RESET
4409fdf0c29SDavid Gibson 
44139ac8455SDavid Gibson /* The hcalls above are standardized in PAPR and implemented by pHyp
44239ac8455SDavid Gibson  * as well.
44339ac8455SDavid Gibson  *
44439ac8455SDavid Gibson  * We also need some hcalls which are specific to qemu / KVM-on-POWER.
445498cd995SGreg Kurz  * We put those into the 0xf000-0xfffc range which is reserved by PAPR
446498cd995SGreg Kurz  * for "platform-specific" hcalls.
44739ac8455SDavid Gibson  */
44839ac8455SDavid Gibson #define KVMPPC_HCALL_BASE       0xf000
44939ac8455SDavid Gibson #define KVMPPC_H_RTAS           (KVMPPC_HCALL_BASE + 0x0)
450c73e3771SBenjamin Herrenschmidt #define KVMPPC_H_LOGICAL_MEMOP  (KVMPPC_HCALL_BASE + 0x1)
4512a6593cbSAlexey Kardashevskiy /* Client Architecture support */
4522a6593cbSAlexey Kardashevskiy #define KVMPPC_H_CAS            (KVMPPC_HCALL_BASE + 0x2)
4532a6593cbSAlexey Kardashevskiy #define KVMPPC_HCALL_MAX        KVMPPC_H_CAS
45439ac8455SDavid Gibson 
4552a6593cbSAlexey Kardashevskiy typedef struct sPAPRDeviceTreeUpdateHeader {
4562a6593cbSAlexey Kardashevskiy     uint32_t version_id;
4572a6593cbSAlexey Kardashevskiy } sPAPRDeviceTreeUpdateHeader;
4582a6593cbSAlexey Kardashevskiy 
4599fdf0c29SDavid Gibson #define hcall_dprintf(fmt, ...) \
460aaf87c66SThomas Huth     do { \
461aaf87c66SThomas Huth         qemu_log_mask(LOG_GUEST_ERROR, "%s: " fmt, __func__, ## __VA_ARGS__); \
462aaf87c66SThomas Huth     } while (0)
4639fdf0c29SDavid Gibson 
46428e02042SDavid Gibson typedef target_ulong (*spapr_hcall_fn)(PowerPCCPU *cpu, sPAPRMachineState *sm,
4659fdf0c29SDavid Gibson                                        target_ulong opcode,
4669fdf0c29SDavid Gibson                                        target_ulong *args);
4679fdf0c29SDavid Gibson 
4689fdf0c29SDavid Gibson void spapr_register_hypercall(target_ulong opcode, spapr_hcall_fn fn);
469aa100fa4SAndreas Färber target_ulong spapr_hypercall(PowerPCCPU *cpu, target_ulong opcode,
4709fdf0c29SDavid Gibson                              target_ulong *args);
4719fdf0c29SDavid Gibson 
472ee954280SGavin Shan /* ibm,set-eeh-option */
473ee954280SGavin Shan #define RTAS_EEH_DISABLE                 0
474ee954280SGavin Shan #define RTAS_EEH_ENABLE                  1
475ee954280SGavin Shan #define RTAS_EEH_THAW_IO                 2
476ee954280SGavin Shan #define RTAS_EEH_THAW_DMA                3
477ee954280SGavin Shan 
478ee954280SGavin Shan /* ibm,get-config-addr-info2 */
479ee954280SGavin Shan #define RTAS_GET_PE_ADDR                 0
480ee954280SGavin Shan #define RTAS_GET_PE_MODE                 1
481ee954280SGavin Shan #define RTAS_PE_MODE_NONE                0
482ee954280SGavin Shan #define RTAS_PE_MODE_NOT_SHARED          1
483ee954280SGavin Shan #define RTAS_PE_MODE_SHARED              2
484ee954280SGavin Shan 
485ee954280SGavin Shan /* ibm,read-slot-reset-state2 */
486ee954280SGavin Shan #define RTAS_EEH_PE_STATE_NORMAL         0
487ee954280SGavin Shan #define RTAS_EEH_PE_STATE_RESET          1
488ee954280SGavin Shan #define RTAS_EEH_PE_STATE_STOPPED_IO_DMA 2
489ee954280SGavin Shan #define RTAS_EEH_PE_STATE_STOPPED_DMA    4
490ee954280SGavin Shan #define RTAS_EEH_PE_STATE_UNAVAIL        5
491ee954280SGavin Shan #define RTAS_EEH_NOT_SUPPORT             0
492ee954280SGavin Shan #define RTAS_EEH_SUPPORT                 1
493ee954280SGavin Shan #define RTAS_EEH_PE_UNAVAIL_INFO         1000
494ee954280SGavin Shan #define RTAS_EEH_PE_RECOVER_INFO         0
495ee954280SGavin Shan 
496ee954280SGavin Shan /* ibm,set-slot-reset */
497ee954280SGavin Shan #define RTAS_SLOT_RESET_DEACTIVATE       0
498ee954280SGavin Shan #define RTAS_SLOT_RESET_HOT              1
499ee954280SGavin Shan #define RTAS_SLOT_RESET_FUNDAMENTAL      3
500ee954280SGavin Shan 
501ee954280SGavin Shan /* ibm,slot-error-detail */
502ee954280SGavin Shan #define RTAS_SLOT_TEMP_ERR_LOG           1
503ee954280SGavin Shan #define RTAS_SLOT_PERM_ERR_LOG           2
504ee954280SGavin Shan 
505a64d325dSAlexey Kardashevskiy /* RTAS return codes */
506a64d325dSAlexey Kardashevskiy #define RTAS_OUT_SUCCESS                        0
507a64d325dSAlexey Kardashevskiy #define RTAS_OUT_NO_ERRORS_FOUND                1
508a64d325dSAlexey Kardashevskiy #define RTAS_OUT_HW_ERROR                       -1
509a64d325dSAlexey Kardashevskiy #define RTAS_OUT_BUSY                           -2
510a64d325dSAlexey Kardashevskiy #define RTAS_OUT_PARAM_ERROR                    -3
5113ada6b11SAlexey Kardashevskiy #define RTAS_OUT_NOT_SUPPORTED                  -3
5129d1852ceSMichael Roth #define RTAS_OUT_NO_SUCH_INDICATOR              -3
5133ada6b11SAlexey Kardashevskiy #define RTAS_OUT_NOT_AUTHORIZED                 -9002
514c920f7b4SDavid Gibson #define RTAS_OUT_SYSPARM_PARAM_ERROR            -9999
515a64d325dSAlexey Kardashevskiy 
516ae4de14cSAlexey Kardashevskiy /* DDW pagesize mask values from ibm,query-pe-dma-window */
517ae4de14cSAlexey Kardashevskiy #define RTAS_DDW_PGSIZE_4K       0x01
518ae4de14cSAlexey Kardashevskiy #define RTAS_DDW_PGSIZE_64K      0x02
519ae4de14cSAlexey Kardashevskiy #define RTAS_DDW_PGSIZE_16M      0x04
520ae4de14cSAlexey Kardashevskiy #define RTAS_DDW_PGSIZE_32M      0x08
521ae4de14cSAlexey Kardashevskiy #define RTAS_DDW_PGSIZE_64M      0x10
522ae4de14cSAlexey Kardashevskiy #define RTAS_DDW_PGSIZE_128M     0x20
523ae4de14cSAlexey Kardashevskiy #define RTAS_DDW_PGSIZE_256M     0x40
524ae4de14cSAlexey Kardashevskiy #define RTAS_DDW_PGSIZE_16G      0x80
525ae4de14cSAlexey Kardashevskiy 
5263a3b8502SAlexey Kardashevskiy /* RTAS tokens */
5273a3b8502SAlexey Kardashevskiy #define RTAS_TOKEN_BASE      0x2000
5283a3b8502SAlexey Kardashevskiy 
5293a3b8502SAlexey Kardashevskiy #define RTAS_DISPLAY_CHARACTER                  (RTAS_TOKEN_BASE + 0x00)
5303a3b8502SAlexey Kardashevskiy #define RTAS_GET_TIME_OF_DAY                    (RTAS_TOKEN_BASE + 0x01)
5313a3b8502SAlexey Kardashevskiy #define RTAS_SET_TIME_OF_DAY                    (RTAS_TOKEN_BASE + 0x02)
5323a3b8502SAlexey Kardashevskiy #define RTAS_POWER_OFF                          (RTAS_TOKEN_BASE + 0x03)
5333a3b8502SAlexey Kardashevskiy #define RTAS_SYSTEM_REBOOT                      (RTAS_TOKEN_BASE + 0x04)
5343a3b8502SAlexey Kardashevskiy #define RTAS_QUERY_CPU_STOPPED_STATE            (RTAS_TOKEN_BASE + 0x05)
5353a3b8502SAlexey Kardashevskiy #define RTAS_START_CPU                          (RTAS_TOKEN_BASE + 0x06)
5363a3b8502SAlexey Kardashevskiy #define RTAS_STOP_SELF                          (RTAS_TOKEN_BASE + 0x07)
5373a3b8502SAlexey Kardashevskiy #define RTAS_IBM_GET_SYSTEM_PARAMETER           (RTAS_TOKEN_BASE + 0x08)
5383a3b8502SAlexey Kardashevskiy #define RTAS_IBM_SET_SYSTEM_PARAMETER           (RTAS_TOKEN_BASE + 0x09)
5393a3b8502SAlexey Kardashevskiy #define RTAS_IBM_SET_XIVE                       (RTAS_TOKEN_BASE + 0x0A)
5403a3b8502SAlexey Kardashevskiy #define RTAS_IBM_GET_XIVE                       (RTAS_TOKEN_BASE + 0x0B)
5413a3b8502SAlexey Kardashevskiy #define RTAS_IBM_INT_OFF                        (RTAS_TOKEN_BASE + 0x0C)
5423a3b8502SAlexey Kardashevskiy #define RTAS_IBM_INT_ON                         (RTAS_TOKEN_BASE + 0x0D)
5433a3b8502SAlexey Kardashevskiy #define RTAS_CHECK_EXCEPTION                    (RTAS_TOKEN_BASE + 0x0E)
5443a3b8502SAlexey Kardashevskiy #define RTAS_EVENT_SCAN                         (RTAS_TOKEN_BASE + 0x0F)
5453a3b8502SAlexey Kardashevskiy #define RTAS_IBM_SET_TCE_BYPASS                 (RTAS_TOKEN_BASE + 0x10)
5463a3b8502SAlexey Kardashevskiy #define RTAS_QUIESCE                            (RTAS_TOKEN_BASE + 0x11)
5473a3b8502SAlexey Kardashevskiy #define RTAS_NVRAM_FETCH                        (RTAS_TOKEN_BASE + 0x12)
5483a3b8502SAlexey Kardashevskiy #define RTAS_NVRAM_STORE                        (RTAS_TOKEN_BASE + 0x13)
5493a3b8502SAlexey Kardashevskiy #define RTAS_READ_PCI_CONFIG                    (RTAS_TOKEN_BASE + 0x14)
5503a3b8502SAlexey Kardashevskiy #define RTAS_WRITE_PCI_CONFIG                   (RTAS_TOKEN_BASE + 0x15)
5513a3b8502SAlexey Kardashevskiy #define RTAS_IBM_READ_PCI_CONFIG                (RTAS_TOKEN_BASE + 0x16)
5523a3b8502SAlexey Kardashevskiy #define RTAS_IBM_WRITE_PCI_CONFIG               (RTAS_TOKEN_BASE + 0x17)
5533a3b8502SAlexey Kardashevskiy #define RTAS_IBM_QUERY_INTERRUPT_SOURCE_NUMBER  (RTAS_TOKEN_BASE + 0x18)
5543a3b8502SAlexey Kardashevskiy #define RTAS_IBM_CHANGE_MSI                     (RTAS_TOKEN_BASE + 0x19)
5553a3b8502SAlexey Kardashevskiy #define RTAS_SET_INDICATOR                      (RTAS_TOKEN_BASE + 0x1A)
5563a3b8502SAlexey Kardashevskiy #define RTAS_SET_POWER_LEVEL                    (RTAS_TOKEN_BASE + 0x1B)
5573a3b8502SAlexey Kardashevskiy #define RTAS_GET_POWER_LEVEL                    (RTAS_TOKEN_BASE + 0x1C)
5583a3b8502SAlexey Kardashevskiy #define RTAS_GET_SENSOR_STATE                   (RTAS_TOKEN_BASE + 0x1D)
5593a3b8502SAlexey Kardashevskiy #define RTAS_IBM_CONFIGURE_CONNECTOR            (RTAS_TOKEN_BASE + 0x1E)
5603a3b8502SAlexey Kardashevskiy #define RTAS_IBM_OS_TERM                        (RTAS_TOKEN_BASE + 0x1F)
561ee954280SGavin Shan #define RTAS_IBM_SET_EEH_OPTION                 (RTAS_TOKEN_BASE + 0x20)
562ee954280SGavin Shan #define RTAS_IBM_GET_CONFIG_ADDR_INFO2          (RTAS_TOKEN_BASE + 0x21)
563ee954280SGavin Shan #define RTAS_IBM_READ_SLOT_RESET_STATE2         (RTAS_TOKEN_BASE + 0x22)
564ee954280SGavin Shan #define RTAS_IBM_SET_SLOT_RESET                 (RTAS_TOKEN_BASE + 0x23)
565ee954280SGavin Shan #define RTAS_IBM_CONFIGURE_PE                   (RTAS_TOKEN_BASE + 0x24)
566ee954280SGavin Shan #define RTAS_IBM_SLOT_ERROR_DETAIL              (RTAS_TOKEN_BASE + 0x25)
567ae4de14cSAlexey Kardashevskiy #define RTAS_IBM_QUERY_PE_DMA_WINDOW            (RTAS_TOKEN_BASE + 0x26)
568ae4de14cSAlexey Kardashevskiy #define RTAS_IBM_CREATE_PE_DMA_WINDOW           (RTAS_TOKEN_BASE + 0x27)
569ae4de14cSAlexey Kardashevskiy #define RTAS_IBM_REMOVE_PE_DMA_WINDOW           (RTAS_TOKEN_BASE + 0x28)
570ae4de14cSAlexey Kardashevskiy #define RTAS_IBM_RESET_PE_DMA_WINDOW            (RTAS_TOKEN_BASE + 0x29)
5713a3b8502SAlexey Kardashevskiy 
572ae4de14cSAlexey Kardashevskiy #define RTAS_TOKEN_MAX                          (RTAS_TOKEN_BASE + 0x2A)
5733a3b8502SAlexey Kardashevskiy 
5743052d951SSam bobroff /* RTAS ibm,get-system-parameter token values */
5753b50d897SSam bobroff #define RTAS_SYSPARM_SPLPAR_CHARACTERISTICS      20
5763052d951SSam bobroff #define RTAS_SYSPARM_DIAGNOSTICS_RUN_MODE        42
577b907d7b0SSam bobroff #define RTAS_SYSPARM_UUID                        48
5783052d951SSam bobroff 
5798c8639dfSMike Day /* RTAS indicator/sensor types
5808c8639dfSMike Day  *
5818c8639dfSMike Day  * as defined by PAPR+ 2.7 7.3.5.4, Table 41
5828c8639dfSMike Day  *
5838c8639dfSMike Day  * NOTE: currently only DR-related sensors are implemented here
5848c8639dfSMike Day  */
5858c8639dfSMike Day #define RTAS_SENSOR_TYPE_ISOLATION_STATE        9001
5868c8639dfSMike Day #define RTAS_SENSOR_TYPE_DR                     9002
5878c8639dfSMike Day #define RTAS_SENSOR_TYPE_ALLOCATION_STATE       9003
5888c8639dfSMike Day #define RTAS_SENSOR_TYPE_ENTITY_SENSE RTAS_SENSOR_TYPE_ALLOCATION_STATE
5898c8639dfSMike Day 
5903052d951SSam bobroff /* Possible values for the platform-processor-diagnostics-run-mode parameter
5913052d951SSam bobroff  * of the RTAS ibm,get-system-parameter call.
5923052d951SSam bobroff  */
5933052d951SSam bobroff #define DIAGNOSTICS_RUN_MODE_DISABLED  0
5943052d951SSam bobroff #define DIAGNOSTICS_RUN_MODE_STAGGERED 1
5953052d951SSam bobroff #define DIAGNOSTICS_RUN_MODE_IMMEDIATE 2
5963052d951SSam bobroff #define DIAGNOSTICS_RUN_MODE_PERIODIC  3
5973052d951SSam bobroff 
5984fe822e0SAlexey Kardashevskiy static inline uint64_t ppc64_phys_to_real(uint64_t addr)
5994fe822e0SAlexey Kardashevskiy {
6004fe822e0SAlexey Kardashevskiy     return addr & ~0xF000000000000000ULL;
6014fe822e0SAlexey Kardashevskiy }
6024fe822e0SAlexey Kardashevskiy 
60339ac8455SDavid Gibson static inline uint32_t rtas_ld(target_ulong phys, int n)
60439ac8455SDavid Gibson {
605fdfba1a2SEdgar E. Iglesias     return ldl_be_phys(&address_space_memory, ppc64_phys_to_real(phys + 4*n));
60639ac8455SDavid Gibson }
60739ac8455SDavid Gibson 
608a14aa92bSGavin Shan static inline uint64_t rtas_ldq(target_ulong phys, int n)
609a14aa92bSGavin Shan {
610a14aa92bSGavin Shan     return (uint64_t)rtas_ld(phys, n) << 32 | rtas_ld(phys, n + 1);
611a14aa92bSGavin Shan }
612a14aa92bSGavin Shan 
61339ac8455SDavid Gibson static inline void rtas_st(target_ulong phys, int n, uint32_t val)
61439ac8455SDavid Gibson {
615ab1da857SEdgar E. Iglesias     stl_be_phys(&address_space_memory, ppc64_phys_to_real(phys + 4*n), val);
61639ac8455SDavid Gibson }
61739ac8455SDavid Gibson 
61828e02042SDavid Gibson typedef void (*spapr_rtas_fn)(PowerPCCPU *cpu, sPAPRMachineState *sm,
619210b580bSAnthony Liguori                               uint32_t token,
62039ac8455SDavid Gibson                               uint32_t nargs, target_ulong args,
62139ac8455SDavid Gibson                               uint32_t nret, target_ulong rets);
6223a3b8502SAlexey Kardashevskiy void spapr_rtas_register(int token, const char *name, spapr_rtas_fn fn);
62328e02042SDavid Gibson target_ulong spapr_rtas_call(PowerPCCPU *cpu, sPAPRMachineState *sm,
62439ac8455SDavid Gibson                              uint32_t token, uint32_t nargs, target_ulong args,
62539ac8455SDavid Gibson                              uint32_t nret, target_ulong rets);
6263f5dabceSDavid Gibson void spapr_dt_rtas_tokens(void *fdt, int rtas);
6272cac78c1SDavid Gibson void spapr_load_rtas(sPAPRMachineState *spapr, void *fdt, hwaddr addr);
62839ac8455SDavid Gibson 
629ad0ebb91SDavid Gibson #define SPAPR_TCE_PAGE_SHIFT   12
630ad0ebb91SDavid Gibson #define SPAPR_TCE_PAGE_SIZE    (1ULL << SPAPR_TCE_PAGE_SHIFT)
631ad0ebb91SDavid Gibson #define SPAPR_TCE_PAGE_MASK    (SPAPR_TCE_PAGE_SIZE - 1)
632ad0ebb91SDavid Gibson 
633ad0ebb91SDavid Gibson #define SPAPR_VIO_BASE_LIOBN    0x00000000
6344290ca49SAlexey Kardashevskiy #define SPAPR_VIO_LIOBN(reg)    (0x00000000 | (reg))
635c8545818SAlexey Kardashevskiy #define SPAPR_PCI_LIOBN(phb_index, window_num) \
636c8545818SAlexey Kardashevskiy     (0x80000000 | ((phb_index) << 8) | (window_num))
637d9d96a3cSAlexey Kardashevskiy #define SPAPR_IS_PCI_LIOBN(liobn)   (!!((liobn) & 0x80000000))
638c8545818SAlexey Kardashevskiy #define SPAPR_PCI_DMA_WINDOW_NUM(liobn) ((liobn) & 0xff)
639ad0ebb91SDavid Gibson 
64074d042e5SDavid Gibson #define RTAS_ERROR_LOG_MAX      2048
64174d042e5SDavid Gibson 
64279853e18STyrel Datwyler #define RTAS_EVENT_SCAN_RATE    1
64379853e18STyrel Datwyler 
644bb2d8ab6SGreg Kurz /* This helper should be used to encode interrupt specifiers when the related
645bb2d8ab6SGreg Kurz  * "interrupt-controller" node has its "#interrupt-cells" property set to 2 (ie,
646bb2d8ab6SGreg Kurz  * VIO devices, RTAS event sources and PHBs).
647bb2d8ab6SGreg Kurz  */
648bb2d8ab6SGreg Kurz static inline void spapr_dt_xics_irq(uint32_t *intspec, int irq, bool is_lsi)
649bb2d8ab6SGreg Kurz {
650bb2d8ab6SGreg Kurz     intspec[0] = cpu_to_be32(irq);
651bb2d8ab6SGreg Kurz     intspec[1] = is_lsi ? cpu_to_be32(1) : 0;
652bb2d8ab6SGreg Kurz }
653bb2d8ab6SGreg Kurz 
6542b7dc949SPaolo Bonzini typedef struct sPAPRTCETable sPAPRTCETable;
65574d042e5SDavid Gibson 
656a83000f5SAnthony Liguori #define TYPE_SPAPR_TCE_TABLE "spapr-tce-table"
657a83000f5SAnthony Liguori #define SPAPR_TCE_TABLE(obj) \
658a83000f5SAnthony Liguori     OBJECT_CHECK(sPAPRTCETable, (obj), TYPE_SPAPR_TCE_TABLE)
659a83000f5SAnthony Liguori 
6601221a474SAlexey Kardashevskiy #define TYPE_SPAPR_IOMMU_MEMORY_REGION "spapr-iommu-memory-region"
6611221a474SAlexey Kardashevskiy #define SPAPR_IOMMU_MEMORY_REGION(obj) \
6621221a474SAlexey Kardashevskiy         OBJECT_CHECK(IOMMUMemoryRegion, (obj), TYPE_SPAPR_IOMMU_MEMORY_REGION)
6631221a474SAlexey Kardashevskiy 
664a83000f5SAnthony Liguori struct sPAPRTCETable {
665a83000f5SAnthony Liguori     DeviceState parent;
666a83000f5SAnthony Liguori     uint32_t liobn;
667a83000f5SAnthony Liguori     uint32_t nb_table;
6681b8eceeeSAlexey Kardashevskiy     uint64_t bus_offset;
669650f33adSAlexey Kardashevskiy     uint32_t page_shift;
670a83000f5SAnthony Liguori     uint64_t *table;
671a26fdf39SAlexey Kardashevskiy     uint32_t mig_nb_table;
672a26fdf39SAlexey Kardashevskiy     uint64_t *mig_table;
673a83000f5SAnthony Liguori     bool bypass;
6746a81dd17SDavid Gibson     bool need_vfio;
675a83000f5SAnthony Liguori     int fd;
6763df9d748SAlexey Kardashevskiy     MemoryRegion root;
6773df9d748SAlexey Kardashevskiy     IOMMUMemoryRegion iommu;
678ee9a569aSAlexey Kardashevskiy     struct VIOsPAPRDevice *vdev; /* for @bypass migration compatibility only */
679a83000f5SAnthony Liguori     QLIST_ENTRY(sPAPRTCETable) list;
680a83000f5SAnthony Liguori };
681a83000f5SAnthony Liguori 
682f9ce8e0aSThomas Huth sPAPRTCETable *spapr_tce_find_by_liobn(target_ulong liobn);
68331fe14d1SNathan Fontenot 
6845341258eSDavid Gibson struct sPAPREventLogEntry {
685fd38804bSDaniel Henrique Barboza     uint32_t summary;
686fd38804bSDaniel Henrique Barboza     uint32_t extended_length;
687fd38804bSDaniel Henrique Barboza     void *extended_log;
68831fe14d1SNathan Fontenot     QTAILQ_ENTRY(sPAPREventLogEntry) next;
68931fe14d1SNathan Fontenot };
69031fe14d1SNathan Fontenot 
69128e02042SDavid Gibson void spapr_events_init(sPAPRMachineState *sm);
692ffbb1705SMichael Roth void spapr_dt_events(sPAPRMachineState *sm, void *fdt);
69328e02042SDavid Gibson int spapr_h_cas_compose_response(sPAPRMachineState *sm,
69403d196b7SBharata B Rao                                  target_ulong addr, target_ulong size,
6956787d27bSMichael Roth                                  sPAPROptionVector *ov5_updates);
696b4db5413SSuraj Jitindar Singh void close_htab_fd(sPAPRMachineState *spapr);
697b4db5413SSuraj Jitindar Singh void spapr_setup_hpt_and_vrma(sPAPRMachineState *spapr);
69806ec79e8SBharata B Rao void spapr_free_hpt(sPAPRMachineState *spapr);
699df7625d4SAlexey Kardashevskiy sPAPRTCETable *spapr_tce_new_table(DeviceState *owner, uint32_t liobn);
700df7625d4SAlexey Kardashevskiy void spapr_tce_table_enable(sPAPRTCETable *tcet,
701df7625d4SAlexey Kardashevskiy                             uint32_t page_shift, uint64_t bus_offset,
702df7625d4SAlexey Kardashevskiy                             uint32_t nb_table);
703a26fdf39SAlexey Kardashevskiy void spapr_tce_table_disable(sPAPRTCETable *tcet);
704c10325d6SDavid Gibson void spapr_tce_set_need_vfio(sPAPRTCETable *tcet, bool need_vfio);
705c10325d6SDavid Gibson 
706a84bb436SPaolo Bonzini MemoryRegion *spapr_tce_get_iommu(sPAPRTCETable *tcet);
707ad0ebb91SDavid Gibson int spapr_dma_dt(void *fdt, int node_off, const char *propname,
7085c4cbcf2SAlexey Kardashevskiy                  uint32_t liobn, uint64_t window, uint32_t size);
7095c4cbcf2SAlexey Kardashevskiy int spapr_tcet_dma_dt(void *fdt, int node_off, const char *propname,
7102b7dc949SPaolo Bonzini                       sPAPRTCETable *tcet);
711eefaccc0SDavid Gibson void spapr_pci_switch_vga(bool big_endian);
7127a36ae7aSBharata B Rao void spapr_hotplug_req_add_by_index(sPAPRDRConnector *drc);
7137a36ae7aSBharata B Rao void spapr_hotplug_req_remove_by_index(sPAPRDRConnector *drc);
7147a36ae7aSBharata B Rao void spapr_hotplug_req_add_by_count(sPAPRDRConnectorType drc_type,
7157a36ae7aSBharata B Rao                                        uint32_t count);
7167a36ae7aSBharata B Rao void spapr_hotplug_req_remove_by_count(sPAPRDRConnectorType drc_type,
7177a36ae7aSBharata B Rao                                           uint32_t count);
718afdbd403SBharata B Rao void spapr_hotplug_req_add_by_count_indexed(sPAPRDRConnectorType drc_type,
719afdbd403SBharata B Rao                                             uint32_t count, uint32_t index);
720afdbd403SBharata B Rao void spapr_hotplug_req_remove_by_count_indexed(sPAPRDRConnectorType drc_type,
721afdbd403SBharata B Rao                                                uint32_t count, uint32_t index);
7220b0b8310SDavid Gibson int spapr_hpt_shift_for_ramsize(uint64_t ramsize);
7232772cf6bSDavid Gibson void spapr_reallocate_hpt(sPAPRMachineState *spapr, int shift,
7242772cf6bSDavid Gibson                           Error **errp);
72556258174SDaniel Henrique Barboza void spapr_clear_pending_events(sPAPRMachineState *spapr);
72628df36a1SDavid Gibson 
72731834723SDaniel Henrique Barboza /* CPU and LMB DRC release callbacks. */
72831834723SDaniel Henrique Barboza void spapr_core_release(DeviceState *dev);
72931834723SDaniel Henrique Barboza void spapr_lmb_release(DeviceState *dev);
73031834723SDaniel Henrique Barboza 
731147ff807SCédric Le Goater void spapr_rtc_read(sPAPRRTCState *rtc, struct tm *tm, uint32_t *ns);
732147ff807SCédric Le Goater int spapr_rtc_import_offset(sPAPRRTCState *rtc, int64_t legacy_offset);
73328df36a1SDavid Gibson 
734147ff807SCédric Le Goater #define TYPE_SPAPR_RNG "spapr-rng"
735ad0ebb91SDavid Gibson 
7364d9392beSThomas Huth int spapr_rng_populate_dt(void *fdt);
7374d9392beSThomas Huth 
738db4ef288SBharata B Rao #define SPAPR_MEMORY_BLOCK_SIZE (1 << 28) /* 256MB */
739db4ef288SBharata B Rao 
7404a1c9cf0SBharata B Rao /*
7414a1c9cf0SBharata B Rao  * This defines the maximum number of DIMM slots we can have for sPAPR
7424a1c9cf0SBharata B Rao  * guest. This is not defined by sPAPR but we are defining it to 32 slots
7434a1c9cf0SBharata B Rao  * based on default number of slots provided by PowerPC kernel.
7444a1c9cf0SBharata B Rao  */
7454a1c9cf0SBharata B Rao #define SPAPR_MAX_RAM_SLOTS     32
7464a1c9cf0SBharata B Rao 
7474a1c9cf0SBharata B Rao /* 1GB alignment for hotplug memory region */
7484a1c9cf0SBharata B Rao #define SPAPR_HOTPLUG_MEM_ALIGN (1ULL << 30)
7494a1c9cf0SBharata B Rao 
75003d196b7SBharata B Rao /*
75103d196b7SBharata B Rao  * Number of 32 bit words in each LMB list entry in ibm,dynamic-memory
75203d196b7SBharata B Rao  * property under ibm,dynamic-reconfiguration-memory node.
75303d196b7SBharata B Rao  */
75403d196b7SBharata B Rao #define SPAPR_DR_LMB_LIST_ENTRY_SIZE 6
75503d196b7SBharata B Rao 
75603d196b7SBharata B Rao /*
757d0e5a8f2SBharata B Rao  * Defines for flag value in ibm,dynamic-memory property under
758d0e5a8f2SBharata B Rao  * ibm,dynamic-reconfiguration-memory node.
75903d196b7SBharata B Rao  */
76003d196b7SBharata B Rao #define SPAPR_LMB_FLAGS_ASSIGNED 0x00000008
761d0e5a8f2SBharata B Rao #define SPAPR_LMB_FLAGS_DRC_INVALID 0x00000020
762d0e5a8f2SBharata B Rao #define SPAPR_LMB_FLAGS_RESERVED 0x00000080
76303d196b7SBharata B Rao 
7641c7ad77eSNicholas Piggin void spapr_do_system_reset_on_cpu(CPUState *cs, run_on_cpu_data arg);
7651c7ad77eSNicholas Piggin 
7660b0b8310SDavid Gibson #define HTAB_SIZE(spapr)        (1ULL << ((spapr)->htab_shift))
7670b0b8310SDavid Gibson 
7682e886fb3SSam Bobroff int spapr_vcpu_id(PowerPCCPU *cpu);
7692e886fb3SSam Bobroff PowerPCCPU *spapr_find_cpu(int vcpu_id);
7702e886fb3SSam Bobroff 
77160c6823bSCédric Le Goater int spapr_irq_alloc(sPAPRMachineState *spapr, int irq_hint, bool lsi,
77260c6823bSCédric Le Goater                     Error **errp);
77360c6823bSCédric Le Goater int spapr_irq_alloc_block(sPAPRMachineState *spapr, int num, bool lsi,
77460c6823bSCédric Le Goater                           bool align, Error **errp);
77560c6823bSCédric Le Goater void spapr_irq_free(sPAPRMachineState *spapr, int irq, int num);
77677183755SCédric Le Goater qemu_irq spapr_qirq(sPAPRMachineState *spapr, int irq);
77760c6823bSCédric Le Goater 
7784e5fe368SSuraj Jitindar Singh 
7794e5fe368SSuraj Jitindar Singh int spapr_caps_pre_load(void *opaque);
7804e5fe368SSuraj Jitindar Singh int spapr_caps_pre_save(void *opaque);
7814e5fe368SSuraj Jitindar Singh 
78233face6bSDavid Gibson /*
78333face6bSDavid Gibson  * Handling of optional capabilities
78433face6bSDavid Gibson  */
7854e5fe368SSuraj Jitindar Singh extern const VMStateDescription vmstate_spapr_cap_htm;
7864e5fe368SSuraj Jitindar Singh extern const VMStateDescription vmstate_spapr_cap_vsx;
7874e5fe368SSuraj Jitindar Singh extern const VMStateDescription vmstate_spapr_cap_dfp;
7888f38eaf8SSuraj Jitindar Singh extern const VMStateDescription vmstate_spapr_cap_cfpc;
78909114fd8SSuraj Jitindar Singh extern const VMStateDescription vmstate_spapr_cap_sbbc;
790*4be8d4e7SSuraj Jitindar Singh extern const VMStateDescription vmstate_spapr_cap_ibs;
791be85537dSDavid Gibson 
7924e5fe368SSuraj Jitindar Singh static inline uint8_t spapr_get_cap(sPAPRMachineState *spapr, int cap)
79333face6bSDavid Gibson {
7944e5fe368SSuraj Jitindar Singh     return spapr->eff.caps[cap];
79533face6bSDavid Gibson }
79633face6bSDavid Gibson 
79733face6bSDavid Gibson void spapr_caps_reset(sPAPRMachineState *spapr);
79833face6bSDavid Gibson void spapr_caps_add_properties(sPAPRMachineClass *smc, Error **errp);
799be85537dSDavid Gibson int spapr_caps_post_migration(sPAPRMachineState *spapr);
80033face6bSDavid Gibson 
8012a6a4076SMarkus Armbruster #endif /* HW_SPAPR_H */
802