xref: /qemu/include/hw/ppc/spapr.h (revision 2cac78c12ade9a87b6251f8d854c2e43a30f41bf)
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"
9277f9acfSPaolo Bonzini 
104040ab72SDavid Gibson struct VIOsPAPRBus;
113384f95cSDavid Gibson struct sPAPRPHBState;
12639e8102SDavid Gibson struct sPAPRNVRAM;
1346503c2bSMichael Roth typedef struct sPAPRConfigureConnectorState sPAPRConfigureConnectorState;
1431fe14d1SNathan Fontenot typedef struct sPAPREventLogEntry sPAPREventLogEntry;
154040ab72SDavid Gibson 
164be21d56SDavid Gibson #define HPTE64_V_HPTE_DIRTY     0x0000000000000040ULL
171b718907SDavid Gibson #define SPAPR_ENTRY_POINT       0x100
184be21d56SDavid Gibson 
19afd10a0fSBharata B Rao #define SPAPR_TIMEBASE_FREQ     512000000ULL
20afd10a0fSBharata B Rao 
21183930c0SDavid Gibson typedef struct sPAPRMachineClass sPAPRMachineClass;
2228e02042SDavid Gibson typedef struct sPAPRMachineState sPAPRMachineState;
2328e02042SDavid Gibson 
2428e02042SDavid Gibson #define TYPE_SPAPR_MACHINE      "spapr-machine"
2528e02042SDavid Gibson #define SPAPR_MACHINE(obj) \
2628e02042SDavid Gibson     OBJECT_CHECK(sPAPRMachineState, (obj), TYPE_SPAPR_MACHINE)
27183930c0SDavid Gibson #define SPAPR_MACHINE_GET_CLASS(obj) \
28183930c0SDavid Gibson     OBJECT_GET_CLASS(sPAPRMachineClass, obj, TYPE_SPAPR_MACHINE)
29183930c0SDavid Gibson #define SPAPR_MACHINE_CLASS(klass) \
30183930c0SDavid Gibson     OBJECT_CLASS_CHECK(sPAPRMachineClass, klass, TYPE_SPAPR_MACHINE)
31183930c0SDavid Gibson 
32183930c0SDavid Gibson /**
33183930c0SDavid Gibson  * sPAPRMachineClass:
34183930c0SDavid Gibson  */
35183930c0SDavid Gibson struct sPAPRMachineClass {
36183930c0SDavid Gibson     /*< private >*/
37183930c0SDavid Gibson     MachineClass parent_class;
38183930c0SDavid Gibson 
39183930c0SDavid Gibson     /*< public >*/
40224245bfSDavid Gibson     bool dr_lmb_enabled;       /* enable dynamic-reconfig/hotplug of LMBs */
4157040d45SThomas Huth     bool use_ohci_by_default;  /* use USB-OHCI instead of XHCI */
423daa4a9fSThomas Huth     const char *tcg_default_cpu; /* which (TCG) CPU to simulate by default */
436737d9adSDavid Gibson     void (*phb_placement)(sPAPRMachineState *spapr, uint32_t index,
44daa23699SDavid Gibson                           uint64_t *buid, hwaddr *pio,
45daa23699SDavid Gibson                           hwaddr *mmio32, hwaddr *mmio64,
466737d9adSDavid Gibson                           unsigned n_dma, uint32_t *liobns, Error **errp);
47183930c0SDavid Gibson };
4828e02042SDavid Gibson 
4928e02042SDavid Gibson /**
5028e02042SDavid Gibson  * sPAPRMachineState:
5128e02042SDavid Gibson  */
5228e02042SDavid Gibson struct sPAPRMachineState {
5328e02042SDavid Gibson     /*< private >*/
5428e02042SDavid Gibson     MachineState parent_obj;
5528e02042SDavid Gibson 
564040ab72SDavid Gibson     struct VIOsPAPRBus *vio_bus;
573384f95cSDavid Gibson     QLIST_HEAD(, sPAPRPHBState) phbs;
58639e8102SDavid Gibson     struct sPAPRNVRAM *nvram;
5927f24582SBenjamin Herrenschmidt     XICSState *xics;
6028df36a1SDavid Gibson     DeviceState *rtc;
61a3467baaSDavid Gibson 
62a3467baaSDavid Gibson     void *htab;
634be21d56SDavid Gibson     uint32_t htab_shift;
64a8170e5eSAvi Kivity     hwaddr rma_size;
657f763a5dSDavid Gibson     int vrma_adjust;
66b7d1f77aSBenjamin Herrenschmidt     ssize_t rtas_size;
67b7d1f77aSBenjamin Herrenschmidt     void *rtas_blob;
68a19f7fb0SDavid Gibson     long kernel_size;
69a19f7fb0SDavid Gibson     bool kernel_le;
70a19f7fb0SDavid Gibson     uint32_t initrd_base;
71a19f7fb0SDavid Gibson     long initrd_size;
72a3467baaSDavid Gibson     void *fdt_skel;
73880ae7deSDavid Gibson     uint64_t rtc_offset; /* Now used only during incoming migration */
7498a8b524SAlexey Kardashevskiy     struct PPCTimebase tb;
753fc5acdeSAlexander Graf     bool has_graphics;
7674d042e5SDavid Gibson 
7731fe14d1SNathan Fontenot     uint32_t check_exception_irq;
7874d042e5SDavid Gibson     Notifier epow_notifier;
7931fe14d1SNathan Fontenot     QTAILQ_HEAD(, sPAPREventLogEntry) pending_events;
804be21d56SDavid Gibson 
814be21d56SDavid Gibson     /* Migration state */
824be21d56SDavid Gibson     int htab_save_index;
834be21d56SDavid Gibson     bool htab_first_pass;
84e68cb8b4SAlexey Kardashevskiy     int htab_fd;
8546503c2bSMichael Roth 
8646503c2bSMichael Roth     /* RTAS state */
8746503c2bSMichael Roth     QTAILQ_HEAD(, sPAPRConfigureConnectorState) ccs_list;
8828e02042SDavid Gibson 
8928e02042SDavid Gibson     /*< public >*/
9028e02042SDavid Gibson     char *kvm_type;
914a1c9cf0SBharata B Rao     MemoryHotplugState hotplug_memory;
9294a94e4cSBharata B Rao     Object **cores;
9328e02042SDavid Gibson };
949fdf0c29SDavid Gibson 
959fdf0c29SDavid Gibson #define H_SUCCESS         0
969fdf0c29SDavid Gibson #define H_BUSY            1        /* Hardware busy -- retry later */
979fdf0c29SDavid Gibson #define H_CLOSED          2        /* Resource closed */
989fdf0c29SDavid Gibson #define H_NOT_AVAILABLE   3
999fdf0c29SDavid Gibson #define H_CONSTRAINED     4        /* Resource request constrained to max allowed */
1009fdf0c29SDavid Gibson #define H_PARTIAL         5
1019fdf0c29SDavid Gibson #define H_IN_PROGRESS     14       /* Kind of like busy */
1029fdf0c29SDavid Gibson #define H_PAGE_REGISTERED 15
1039fdf0c29SDavid Gibson #define H_PARTIAL_STORE   16
1049fdf0c29SDavid Gibson #define H_PENDING         17       /* returned from H_POLL_PENDING */
1059fdf0c29SDavid Gibson #define H_CONTINUE        18       /* Returned from H_Join on success */
1069fdf0c29SDavid Gibson #define H_LONG_BUSY_START_RANGE         9900  /* Start of long busy range */
1079fdf0c29SDavid Gibson #define H_LONG_BUSY_ORDER_1_MSEC        9900  /* Long busy, hint that 1msec \
1089fdf0c29SDavid Gibson                                                  is a good time to retry */
1099fdf0c29SDavid Gibson #define H_LONG_BUSY_ORDER_10_MSEC       9901  /* Long busy, hint that 10msec \
1109fdf0c29SDavid Gibson                                                  is a good time to retry */
1119fdf0c29SDavid Gibson #define H_LONG_BUSY_ORDER_100_MSEC      9902  /* Long busy, hint that 100msec \
1129fdf0c29SDavid Gibson                                                  is a good time to retry */
1139fdf0c29SDavid Gibson #define H_LONG_BUSY_ORDER_1_SEC         9903  /* Long busy, hint that 1sec \
1149fdf0c29SDavid Gibson                                                  is a good time to retry */
1159fdf0c29SDavid Gibson #define H_LONG_BUSY_ORDER_10_SEC        9904  /* Long busy, hint that 10sec \
1169fdf0c29SDavid Gibson                                                  is a good time to retry */
1179fdf0c29SDavid Gibson #define H_LONG_BUSY_ORDER_100_SEC       9905  /* Long busy, hint that 100sec \
1189fdf0c29SDavid Gibson                                                  is a good time to retry */
1199fdf0c29SDavid Gibson #define H_LONG_BUSY_END_RANGE           9905  /* End of long busy range */
1209fdf0c29SDavid Gibson #define H_HARDWARE        -1       /* Hardware error */
1219fdf0c29SDavid Gibson #define H_FUNCTION        -2       /* Function not supported */
1229fdf0c29SDavid Gibson #define H_PRIVILEGE       -3       /* Caller not privileged */
1239fdf0c29SDavid Gibson #define H_PARAMETER       -4       /* Parameter invalid, out-of-range or conflicting */
1249fdf0c29SDavid Gibson #define H_BAD_MODE        -5       /* Illegal msr value */
1259fdf0c29SDavid Gibson #define H_PTEG_FULL       -6       /* PTEG is full */
1269fdf0c29SDavid Gibson #define H_NOT_FOUND       -7       /* PTE was not found" */
1279fdf0c29SDavid Gibson #define H_RESERVED_DABR   -8       /* DABR address is reserved by the hypervisor on this processor" */
1289fdf0c29SDavid Gibson #define H_NO_MEM          -9
1299fdf0c29SDavid Gibson #define H_AUTHORITY       -10
1309fdf0c29SDavid Gibson #define H_PERMISSION      -11
1319fdf0c29SDavid Gibson #define H_DROPPED         -12
1329fdf0c29SDavid Gibson #define H_SOURCE_PARM     -13
1339fdf0c29SDavid Gibson #define H_DEST_PARM       -14
1349fdf0c29SDavid Gibson #define H_REMOTE_PARM     -15
1359fdf0c29SDavid Gibson #define H_RESOURCE        -16
1369fdf0c29SDavid Gibson #define H_ADAPTER_PARM    -17
1379fdf0c29SDavid Gibson #define H_RH_PARM         -18
1389fdf0c29SDavid Gibson #define H_RCQ_PARM        -19
1399fdf0c29SDavid Gibson #define H_SCQ_PARM        -20
1409fdf0c29SDavid Gibson #define H_EQ_PARM         -21
1419fdf0c29SDavid Gibson #define H_RT_PARM         -22
1429fdf0c29SDavid Gibson #define H_ST_PARM         -23
1439fdf0c29SDavid Gibson #define H_SIGT_PARM       -24
1449fdf0c29SDavid Gibson #define H_TOKEN_PARM      -25
1459fdf0c29SDavid Gibson #define H_MLENGTH_PARM    -27
1469fdf0c29SDavid Gibson #define H_MEM_PARM        -28
1479fdf0c29SDavid Gibson #define H_MEM_ACCESS_PARM -29
1489fdf0c29SDavid Gibson #define H_ATTR_PARM       -30
1499fdf0c29SDavid Gibson #define H_PORT_PARM       -31
1509fdf0c29SDavid Gibson #define H_MCG_PARM        -32
1519fdf0c29SDavid Gibson #define H_VL_PARM         -33
1529fdf0c29SDavid Gibson #define H_TSIZE_PARM      -34
1539fdf0c29SDavid Gibson #define H_TRACE_PARM      -35
1549fdf0c29SDavid Gibson 
1559fdf0c29SDavid Gibson #define H_MASK_PARM       -37
1569fdf0c29SDavid Gibson #define H_MCG_FULL        -38
1579fdf0c29SDavid Gibson #define H_ALIAS_EXIST     -39
1589fdf0c29SDavid Gibson #define H_P_COUNTER       -40
1599fdf0c29SDavid Gibson #define H_TABLE_FULL      -41
1609fdf0c29SDavid Gibson #define H_ALT_TABLE       -42
1619fdf0c29SDavid Gibson #define H_MR_CONDITION    -43
1629fdf0c29SDavid Gibson #define H_NOT_ENOUGH_RESOURCES -44
1639fdf0c29SDavid Gibson #define H_R_STATE         -45
1649fdf0c29SDavid Gibson #define H_RESCINDEND      -46
16542561bf2SAnton Blanchard #define H_P2              -55
16642561bf2SAnton Blanchard #define H_P3              -56
16742561bf2SAnton Blanchard #define H_P4              -57
16842561bf2SAnton Blanchard #define H_P5              -58
16942561bf2SAnton Blanchard #define H_P6              -59
17042561bf2SAnton Blanchard #define H_P7              -60
17142561bf2SAnton Blanchard #define H_P8              -61
17242561bf2SAnton Blanchard #define H_P9              -62
17342561bf2SAnton Blanchard #define H_UNSUPPORTED_FLAG -256
1749fdf0c29SDavid Gibson #define H_MULTI_THREADS_ACTIVE -9005
1759fdf0c29SDavid Gibson 
1769fdf0c29SDavid Gibson 
1779fdf0c29SDavid Gibson /* Long Busy is a condition that can be returned by the firmware
1789fdf0c29SDavid Gibson  * when a call cannot be completed now, but the identical call
1799fdf0c29SDavid Gibson  * should be retried later.  This prevents calls blocking in the
1809fdf0c29SDavid Gibson  * firmware for long periods of time.  Annoyingly the firmware can return
1819fdf0c29SDavid Gibson  * a range of return codes, hinting at how long we should wait before
1829fdf0c29SDavid Gibson  * retrying.  If you don't care for the hint, the macro below is a good
1839fdf0c29SDavid Gibson  * way to check for the long_busy return codes
1849fdf0c29SDavid Gibson  */
1859fdf0c29SDavid Gibson #define H_IS_LONG_BUSY(x)  ((x >= H_LONG_BUSY_START_RANGE) \
1869fdf0c29SDavid Gibson                             && (x <= H_LONG_BUSY_END_RANGE))
1879fdf0c29SDavid Gibson 
1889fdf0c29SDavid Gibson /* Flags */
1899fdf0c29SDavid Gibson #define H_LARGE_PAGE      (1ULL<<(63-16))
1909fdf0c29SDavid Gibson #define H_EXACT           (1ULL<<(63-24))       /* Use exact PTE or return H_PTEG_FULL */
1919fdf0c29SDavid Gibson #define H_R_XLATE         (1ULL<<(63-25))       /* include a valid logical page num in the pte if the valid bit is set */
1929fdf0c29SDavid Gibson #define H_READ_4          (1ULL<<(63-26))       /* Return 4 PTEs */
1939fdf0c29SDavid Gibson #define H_PAGE_STATE_CHANGE (1ULL<<(63-28))
1949fdf0c29SDavid Gibson #define H_PAGE_UNUSED     ((1ULL<<(63-29)) | (1ULL<<(63-30)))
1959fdf0c29SDavid Gibson #define H_PAGE_SET_UNUSED (H_PAGE_STATE_CHANGE | H_PAGE_UNUSED)
1969fdf0c29SDavid Gibson #define H_PAGE_SET_LOANED (H_PAGE_SET_UNUSED | (1ULL<<(63-31)))
1979fdf0c29SDavid Gibson #define H_PAGE_SET_ACTIVE H_PAGE_STATE_CHANGE
1989fdf0c29SDavid Gibson #define H_AVPN            (1ULL<<(63-32))       /* An avpn is provided as a sanity test */
1999fdf0c29SDavid Gibson #define H_ANDCOND         (1ULL<<(63-33))
2009fdf0c29SDavid Gibson #define H_ICACHE_INVALIDATE (1ULL<<(63-40))     /* icbi, etc.  (ignored for IO pages) */
2019fdf0c29SDavid Gibson #define H_ICACHE_SYNCHRONIZE (1ULL<<(63-41))    /* dcbst, icbi, etc (ignored for IO pages */
2029fdf0c29SDavid Gibson #define H_ZERO_PAGE       (1ULL<<(63-48))       /* zero the page before mapping (ignored for IO pages) */
2039fdf0c29SDavid Gibson #define H_COPY_PAGE       (1ULL<<(63-49))
2049fdf0c29SDavid Gibson #define H_N               (1ULL<<(63-61))
2059fdf0c29SDavid Gibson #define H_PP1             (1ULL<<(63-62))
2069fdf0c29SDavid Gibson #define H_PP2             (1ULL<<(63-63))
2079fdf0c29SDavid Gibson 
208a46622fdSAlexey Kardashevskiy /* Values for 2nd argument to H_SET_MODE */
209a46622fdSAlexey Kardashevskiy #define H_SET_MODE_RESOURCE_SET_CIABR           1
210a46622fdSAlexey Kardashevskiy #define H_SET_MODE_RESOURCE_SET_DAWR            2
211a46622fdSAlexey Kardashevskiy #define H_SET_MODE_RESOURCE_ADDR_TRANS_MODE     3
212a46622fdSAlexey Kardashevskiy #define H_SET_MODE_RESOURCE_LE                  4
213a46622fdSAlexey Kardashevskiy 
214a46622fdSAlexey Kardashevskiy /* Flags for H_SET_MODE_RESOURCE_LE */
21542561bf2SAnton Blanchard #define H_SET_MODE_ENDIAN_BIG    0
21642561bf2SAnton Blanchard #define H_SET_MODE_ENDIAN_LITTLE 1
21742561bf2SAnton Blanchard 
2189fdf0c29SDavid Gibson /* VASI States */
2199fdf0c29SDavid Gibson #define H_VASI_INVALID    0
2209fdf0c29SDavid Gibson #define H_VASI_ENABLED    1
2219fdf0c29SDavid Gibson #define H_VASI_ABORTED    2
2229fdf0c29SDavid Gibson #define H_VASI_SUSPENDING 3
2239fdf0c29SDavid Gibson #define H_VASI_SUSPENDED  4
2249fdf0c29SDavid Gibson #define H_VASI_RESUMED    5
2259fdf0c29SDavid Gibson #define H_VASI_COMPLETED  6
2269fdf0c29SDavid Gibson 
2279fdf0c29SDavid Gibson /* DABRX flags */
2289fdf0c29SDavid Gibson #define H_DABRX_HYPERVISOR (1ULL<<(63-61))
2299fdf0c29SDavid Gibson #define H_DABRX_KERNEL     (1ULL<<(63-62))
2309fdf0c29SDavid Gibson #define H_DABRX_USER       (1ULL<<(63-63))
2319fdf0c29SDavid Gibson 
23266a0a2cbSDong Xu Wang /* Each control block has to be on a 4K boundary */
2339fdf0c29SDavid Gibson #define H_CB_ALIGNMENT     4096
2349fdf0c29SDavid Gibson 
2359fdf0c29SDavid Gibson /* pSeries hypervisor opcodes */
2369fdf0c29SDavid Gibson #define H_REMOVE                0x04
2379fdf0c29SDavid Gibson #define H_ENTER                 0x08
2389fdf0c29SDavid Gibson #define H_READ                  0x0c
2399fdf0c29SDavid Gibson #define H_CLEAR_MOD             0x10
2409fdf0c29SDavid Gibson #define H_CLEAR_REF             0x14
2419fdf0c29SDavid Gibson #define H_PROTECT               0x18
2429fdf0c29SDavid Gibson #define H_GET_TCE               0x1c
2439fdf0c29SDavid Gibson #define H_PUT_TCE               0x20
2449fdf0c29SDavid Gibson #define H_SET_SPRG0             0x24
2459fdf0c29SDavid Gibson #define H_SET_DABR              0x28
2469fdf0c29SDavid Gibson #define H_PAGE_INIT             0x2c
2479fdf0c29SDavid Gibson #define H_SET_ASR               0x30
2489fdf0c29SDavid Gibson #define H_ASR_ON                0x34
2499fdf0c29SDavid Gibson #define H_ASR_OFF               0x38
2509fdf0c29SDavid Gibson #define H_LOGICAL_CI_LOAD       0x3c
2519fdf0c29SDavid Gibson #define H_LOGICAL_CI_STORE      0x40
2529fdf0c29SDavid Gibson #define H_LOGICAL_CACHE_LOAD    0x44
2539fdf0c29SDavid Gibson #define H_LOGICAL_CACHE_STORE   0x48
2549fdf0c29SDavid Gibson #define H_LOGICAL_ICBI          0x4c
2559fdf0c29SDavid Gibson #define H_LOGICAL_DCBF          0x50
2569fdf0c29SDavid Gibson #define H_GET_TERM_CHAR         0x54
2579fdf0c29SDavid Gibson #define H_PUT_TERM_CHAR         0x58
2589fdf0c29SDavid Gibson #define H_REAL_TO_LOGICAL       0x5c
2599fdf0c29SDavid Gibson #define H_HYPERVISOR_DATA       0x60
2609fdf0c29SDavid Gibson #define H_EOI                   0x64
2619fdf0c29SDavid Gibson #define H_CPPR                  0x68
2629fdf0c29SDavid Gibson #define H_IPI                   0x6c
2639fdf0c29SDavid Gibson #define H_IPOLL                 0x70
2649fdf0c29SDavid Gibson #define H_XIRR                  0x74
2659fdf0c29SDavid Gibson #define H_PERFMON               0x7c
2669fdf0c29SDavid Gibson #define H_MIGRATE_DMA           0x78
2679fdf0c29SDavid Gibson #define H_REGISTER_VPA          0xDC
2689fdf0c29SDavid Gibson #define H_CEDE                  0xE0
2699fdf0c29SDavid Gibson #define H_CONFER                0xE4
2709fdf0c29SDavid Gibson #define H_PROD                  0xE8
2719fdf0c29SDavid Gibson #define H_GET_PPP               0xEC
2729fdf0c29SDavid Gibson #define H_SET_PPP               0xF0
2739fdf0c29SDavid Gibson #define H_PURR                  0xF4
2749fdf0c29SDavid Gibson #define H_PIC                   0xF8
2759fdf0c29SDavid Gibson #define H_REG_CRQ               0xFC
2769fdf0c29SDavid Gibson #define H_FREE_CRQ              0x100
2779fdf0c29SDavid Gibson #define H_VIO_SIGNAL            0x104
2789fdf0c29SDavid Gibson #define H_SEND_CRQ              0x108
2799fdf0c29SDavid Gibson #define H_COPY_RDMA             0x110
2809fdf0c29SDavid Gibson #define H_REGISTER_LOGICAL_LAN  0x114
2819fdf0c29SDavid Gibson #define H_FREE_LOGICAL_LAN      0x118
2829fdf0c29SDavid Gibson #define H_ADD_LOGICAL_LAN_BUFFER 0x11C
2839fdf0c29SDavid Gibson #define H_SEND_LOGICAL_LAN      0x120
2849fdf0c29SDavid Gibson #define H_BULK_REMOVE           0x124
2859fdf0c29SDavid Gibson #define H_MULTICAST_CTRL        0x130
2869fdf0c29SDavid Gibson #define H_SET_XDABR             0x134
2879fdf0c29SDavid Gibson #define H_STUFF_TCE             0x138
2889fdf0c29SDavid Gibson #define H_PUT_TCE_INDIRECT      0x13C
2899fdf0c29SDavid Gibson #define H_CHANGE_LOGICAL_LAN_MAC 0x14C
2909fdf0c29SDavid Gibson #define H_VTERM_PARTNER_INFO    0x150
2919fdf0c29SDavid Gibson #define H_REGISTER_VTERM        0x154
2929fdf0c29SDavid Gibson #define H_FREE_VTERM            0x158
2939fdf0c29SDavid Gibson #define H_RESET_EVENTS          0x15C
2949fdf0c29SDavid Gibson #define H_ALLOC_RESOURCE        0x160
2959fdf0c29SDavid Gibson #define H_FREE_RESOURCE         0x164
2969fdf0c29SDavid Gibson #define H_MODIFY_QP             0x168
2979fdf0c29SDavid Gibson #define H_QUERY_QP              0x16C
2989fdf0c29SDavid Gibson #define H_REREGISTER_PMR        0x170
2999fdf0c29SDavid Gibson #define H_REGISTER_SMR          0x174
3009fdf0c29SDavid Gibson #define H_QUERY_MR              0x178
3019fdf0c29SDavid Gibson #define H_QUERY_MW              0x17C
3029fdf0c29SDavid Gibson #define H_QUERY_HCA             0x180
3039fdf0c29SDavid Gibson #define H_QUERY_PORT            0x184
3049fdf0c29SDavid Gibson #define H_MODIFY_PORT           0x188
3059fdf0c29SDavid Gibson #define H_DEFINE_AQP1           0x18C
3069fdf0c29SDavid Gibson #define H_GET_TRACE_BUFFER      0x190
3079fdf0c29SDavid Gibson #define H_DEFINE_AQP0           0x194
3089fdf0c29SDavid Gibson #define H_RESIZE_MR             0x198
3099fdf0c29SDavid Gibson #define H_ATTACH_MCQP           0x19C
3109fdf0c29SDavid Gibson #define H_DETACH_MCQP           0x1A0
3119fdf0c29SDavid Gibson #define H_CREATE_RPT            0x1A4
3129fdf0c29SDavid Gibson #define H_REMOVE_RPT            0x1A8
3139fdf0c29SDavid Gibson #define H_REGISTER_RPAGES       0x1AC
3149fdf0c29SDavid Gibson #define H_DISABLE_AND_GETC      0x1B0
3159fdf0c29SDavid Gibson #define H_ERROR_DATA            0x1B4
3169fdf0c29SDavid Gibson #define H_GET_HCA_INFO          0x1B8
3179fdf0c29SDavid Gibson #define H_GET_PERF_COUNT        0x1BC
3189fdf0c29SDavid Gibson #define H_MANAGE_TRACE          0x1C0
3199fdf0c29SDavid Gibson #define H_FREE_LOGICAL_LAN_BUFFER 0x1D4
3209fdf0c29SDavid Gibson #define H_QUERY_INT_STATE       0x1E4
3219fdf0c29SDavid Gibson #define H_POLL_PENDING          0x1D8
3229fdf0c29SDavid Gibson #define H_ILLAN_ATTRIBUTES      0x244
3239fdf0c29SDavid Gibson #define H_MODIFY_HEA_QP         0x250
3249fdf0c29SDavid Gibson #define H_QUERY_HEA_QP          0x254
3259fdf0c29SDavid Gibson #define H_QUERY_HEA             0x258
3269fdf0c29SDavid Gibson #define H_QUERY_HEA_PORT        0x25C
3279fdf0c29SDavid Gibson #define H_MODIFY_HEA_PORT       0x260
3289fdf0c29SDavid Gibson #define H_REG_BCMC              0x264
3299fdf0c29SDavid Gibson #define H_DEREG_BCMC            0x268
3309fdf0c29SDavid Gibson #define H_REGISTER_HEA_RPAGES   0x26C
3319fdf0c29SDavid Gibson #define H_DISABLE_AND_GET_HEA   0x270
3329fdf0c29SDavid Gibson #define H_GET_HEA_INFO          0x274
3339fdf0c29SDavid Gibson #define H_ALLOC_HEA_RESOURCE    0x278
3349fdf0c29SDavid Gibson #define H_ADD_CONN              0x284
3359fdf0c29SDavid Gibson #define H_DEL_CONN              0x288
3369fdf0c29SDavid Gibson #define H_JOIN                  0x298
3379fdf0c29SDavid Gibson #define H_VASI_STATE            0x2A4
3389fdf0c29SDavid Gibson #define H_ENABLE_CRQ            0x2B0
3399fdf0c29SDavid Gibson #define H_GET_EM_PARMS          0x2B8
3409fdf0c29SDavid Gibson #define H_SET_MPP               0x2D0
3419fdf0c29SDavid Gibson #define H_GET_MPP               0x2D4
3425d87e4b7SBenjamin Herrenschmidt #define H_XIRR_X                0x2FC
3434d9392beSThomas Huth #define H_RANDOM                0x300
34442561bf2SAnton Blanchard #define H_SET_MODE              0x31C
34542561bf2SAnton Blanchard #define MAX_HCALL_OPCODE        H_SET_MODE
3469fdf0c29SDavid Gibson 
34739ac8455SDavid Gibson /* The hcalls above are standardized in PAPR and implemented by pHyp
34839ac8455SDavid Gibson  * as well.
34939ac8455SDavid Gibson  *
35039ac8455SDavid Gibson  * We also need some hcalls which are specific to qemu / KVM-on-POWER.
35139ac8455SDavid Gibson  * So far we just need one for H_RTAS, but in future we'll need more
35239ac8455SDavid Gibson  * for extensions like virtio.  We put those into the 0xf000-0xfffc
35339ac8455SDavid Gibson  * range which is reserved by PAPR for "platform-specific" hcalls.
35439ac8455SDavid Gibson  */
35539ac8455SDavid Gibson #define KVMPPC_HCALL_BASE       0xf000
35639ac8455SDavid Gibson #define KVMPPC_H_RTAS           (KVMPPC_HCALL_BASE + 0x0)
357c73e3771SBenjamin Herrenschmidt #define KVMPPC_H_LOGICAL_MEMOP  (KVMPPC_HCALL_BASE + 0x1)
3582a6593cbSAlexey Kardashevskiy /* Client Architecture support */
3592a6593cbSAlexey Kardashevskiy #define KVMPPC_H_CAS            (KVMPPC_HCALL_BASE + 0x2)
3602a6593cbSAlexey Kardashevskiy #define KVMPPC_HCALL_MAX        KVMPPC_H_CAS
36139ac8455SDavid Gibson 
3622a6593cbSAlexey Kardashevskiy typedef struct sPAPRDeviceTreeUpdateHeader {
3632a6593cbSAlexey Kardashevskiy     uint32_t version_id;
3642a6593cbSAlexey Kardashevskiy } sPAPRDeviceTreeUpdateHeader;
3652a6593cbSAlexey Kardashevskiy 
3669fdf0c29SDavid Gibson #define hcall_dprintf(fmt, ...) \
367aaf87c66SThomas Huth     do { \
368aaf87c66SThomas Huth         qemu_log_mask(LOG_GUEST_ERROR, "%s: " fmt, __func__, ## __VA_ARGS__); \
369aaf87c66SThomas Huth     } while (0)
3709fdf0c29SDavid Gibson 
37128e02042SDavid Gibson typedef target_ulong (*spapr_hcall_fn)(PowerPCCPU *cpu, sPAPRMachineState *sm,
3729fdf0c29SDavid Gibson                                        target_ulong opcode,
3739fdf0c29SDavid Gibson                                        target_ulong *args);
3749fdf0c29SDavid Gibson 
3759fdf0c29SDavid Gibson void spapr_register_hypercall(target_ulong opcode, spapr_hcall_fn fn);
376aa100fa4SAndreas Färber target_ulong spapr_hypercall(PowerPCCPU *cpu, target_ulong opcode,
3779fdf0c29SDavid Gibson                              target_ulong *args);
3789fdf0c29SDavid Gibson 
379ee954280SGavin Shan /* ibm,set-eeh-option */
380ee954280SGavin Shan #define RTAS_EEH_DISABLE                 0
381ee954280SGavin Shan #define RTAS_EEH_ENABLE                  1
382ee954280SGavin Shan #define RTAS_EEH_THAW_IO                 2
383ee954280SGavin Shan #define RTAS_EEH_THAW_DMA                3
384ee954280SGavin Shan 
385ee954280SGavin Shan /* ibm,get-config-addr-info2 */
386ee954280SGavin Shan #define RTAS_GET_PE_ADDR                 0
387ee954280SGavin Shan #define RTAS_GET_PE_MODE                 1
388ee954280SGavin Shan #define RTAS_PE_MODE_NONE                0
389ee954280SGavin Shan #define RTAS_PE_MODE_NOT_SHARED          1
390ee954280SGavin Shan #define RTAS_PE_MODE_SHARED              2
391ee954280SGavin Shan 
392ee954280SGavin Shan /* ibm,read-slot-reset-state2 */
393ee954280SGavin Shan #define RTAS_EEH_PE_STATE_NORMAL         0
394ee954280SGavin Shan #define RTAS_EEH_PE_STATE_RESET          1
395ee954280SGavin Shan #define RTAS_EEH_PE_STATE_STOPPED_IO_DMA 2
396ee954280SGavin Shan #define RTAS_EEH_PE_STATE_STOPPED_DMA    4
397ee954280SGavin Shan #define RTAS_EEH_PE_STATE_UNAVAIL        5
398ee954280SGavin Shan #define RTAS_EEH_NOT_SUPPORT             0
399ee954280SGavin Shan #define RTAS_EEH_SUPPORT                 1
400ee954280SGavin Shan #define RTAS_EEH_PE_UNAVAIL_INFO         1000
401ee954280SGavin Shan #define RTAS_EEH_PE_RECOVER_INFO         0
402ee954280SGavin Shan 
403ee954280SGavin Shan /* ibm,set-slot-reset */
404ee954280SGavin Shan #define RTAS_SLOT_RESET_DEACTIVATE       0
405ee954280SGavin Shan #define RTAS_SLOT_RESET_HOT              1
406ee954280SGavin Shan #define RTAS_SLOT_RESET_FUNDAMENTAL      3
407ee954280SGavin Shan 
408ee954280SGavin Shan /* ibm,slot-error-detail */
409ee954280SGavin Shan #define RTAS_SLOT_TEMP_ERR_LOG           1
410ee954280SGavin Shan #define RTAS_SLOT_PERM_ERR_LOG           2
411ee954280SGavin Shan 
412a64d325dSAlexey Kardashevskiy /* RTAS return codes */
413a64d325dSAlexey Kardashevskiy #define RTAS_OUT_SUCCESS                        0
414a64d325dSAlexey Kardashevskiy #define RTAS_OUT_NO_ERRORS_FOUND                1
415a64d325dSAlexey Kardashevskiy #define RTAS_OUT_HW_ERROR                       -1
416a64d325dSAlexey Kardashevskiy #define RTAS_OUT_BUSY                           -2
417a64d325dSAlexey Kardashevskiy #define RTAS_OUT_PARAM_ERROR                    -3
4183ada6b11SAlexey Kardashevskiy #define RTAS_OUT_NOT_SUPPORTED                  -3
4199d1852ceSMichael Roth #define RTAS_OUT_NO_SUCH_INDICATOR              -3
4203ada6b11SAlexey Kardashevskiy #define RTAS_OUT_NOT_AUTHORIZED                 -9002
421c920f7b4SDavid Gibson #define RTAS_OUT_SYSPARM_PARAM_ERROR            -9999
422a64d325dSAlexey Kardashevskiy 
423ae4de14cSAlexey Kardashevskiy /* DDW pagesize mask values from ibm,query-pe-dma-window */
424ae4de14cSAlexey Kardashevskiy #define RTAS_DDW_PGSIZE_4K       0x01
425ae4de14cSAlexey Kardashevskiy #define RTAS_DDW_PGSIZE_64K      0x02
426ae4de14cSAlexey Kardashevskiy #define RTAS_DDW_PGSIZE_16M      0x04
427ae4de14cSAlexey Kardashevskiy #define RTAS_DDW_PGSIZE_32M      0x08
428ae4de14cSAlexey Kardashevskiy #define RTAS_DDW_PGSIZE_64M      0x10
429ae4de14cSAlexey Kardashevskiy #define RTAS_DDW_PGSIZE_128M     0x20
430ae4de14cSAlexey Kardashevskiy #define RTAS_DDW_PGSIZE_256M     0x40
431ae4de14cSAlexey Kardashevskiy #define RTAS_DDW_PGSIZE_16G      0x80
432ae4de14cSAlexey Kardashevskiy 
4333a3b8502SAlexey Kardashevskiy /* RTAS tokens */
4343a3b8502SAlexey Kardashevskiy #define RTAS_TOKEN_BASE      0x2000
4353a3b8502SAlexey Kardashevskiy 
4363a3b8502SAlexey Kardashevskiy #define RTAS_DISPLAY_CHARACTER                  (RTAS_TOKEN_BASE + 0x00)
4373a3b8502SAlexey Kardashevskiy #define RTAS_GET_TIME_OF_DAY                    (RTAS_TOKEN_BASE + 0x01)
4383a3b8502SAlexey Kardashevskiy #define RTAS_SET_TIME_OF_DAY                    (RTAS_TOKEN_BASE + 0x02)
4393a3b8502SAlexey Kardashevskiy #define RTAS_POWER_OFF                          (RTAS_TOKEN_BASE + 0x03)
4403a3b8502SAlexey Kardashevskiy #define RTAS_SYSTEM_REBOOT                      (RTAS_TOKEN_BASE + 0x04)
4413a3b8502SAlexey Kardashevskiy #define RTAS_QUERY_CPU_STOPPED_STATE            (RTAS_TOKEN_BASE + 0x05)
4423a3b8502SAlexey Kardashevskiy #define RTAS_START_CPU                          (RTAS_TOKEN_BASE + 0x06)
4433a3b8502SAlexey Kardashevskiy #define RTAS_STOP_SELF                          (RTAS_TOKEN_BASE + 0x07)
4443a3b8502SAlexey Kardashevskiy #define RTAS_IBM_GET_SYSTEM_PARAMETER           (RTAS_TOKEN_BASE + 0x08)
4453a3b8502SAlexey Kardashevskiy #define RTAS_IBM_SET_SYSTEM_PARAMETER           (RTAS_TOKEN_BASE + 0x09)
4463a3b8502SAlexey Kardashevskiy #define RTAS_IBM_SET_XIVE                       (RTAS_TOKEN_BASE + 0x0A)
4473a3b8502SAlexey Kardashevskiy #define RTAS_IBM_GET_XIVE                       (RTAS_TOKEN_BASE + 0x0B)
4483a3b8502SAlexey Kardashevskiy #define RTAS_IBM_INT_OFF                        (RTAS_TOKEN_BASE + 0x0C)
4493a3b8502SAlexey Kardashevskiy #define RTAS_IBM_INT_ON                         (RTAS_TOKEN_BASE + 0x0D)
4503a3b8502SAlexey Kardashevskiy #define RTAS_CHECK_EXCEPTION                    (RTAS_TOKEN_BASE + 0x0E)
4513a3b8502SAlexey Kardashevskiy #define RTAS_EVENT_SCAN                         (RTAS_TOKEN_BASE + 0x0F)
4523a3b8502SAlexey Kardashevskiy #define RTAS_IBM_SET_TCE_BYPASS                 (RTAS_TOKEN_BASE + 0x10)
4533a3b8502SAlexey Kardashevskiy #define RTAS_QUIESCE                            (RTAS_TOKEN_BASE + 0x11)
4543a3b8502SAlexey Kardashevskiy #define RTAS_NVRAM_FETCH                        (RTAS_TOKEN_BASE + 0x12)
4553a3b8502SAlexey Kardashevskiy #define RTAS_NVRAM_STORE                        (RTAS_TOKEN_BASE + 0x13)
4563a3b8502SAlexey Kardashevskiy #define RTAS_READ_PCI_CONFIG                    (RTAS_TOKEN_BASE + 0x14)
4573a3b8502SAlexey Kardashevskiy #define RTAS_WRITE_PCI_CONFIG                   (RTAS_TOKEN_BASE + 0x15)
4583a3b8502SAlexey Kardashevskiy #define RTAS_IBM_READ_PCI_CONFIG                (RTAS_TOKEN_BASE + 0x16)
4593a3b8502SAlexey Kardashevskiy #define RTAS_IBM_WRITE_PCI_CONFIG               (RTAS_TOKEN_BASE + 0x17)
4603a3b8502SAlexey Kardashevskiy #define RTAS_IBM_QUERY_INTERRUPT_SOURCE_NUMBER  (RTAS_TOKEN_BASE + 0x18)
4613a3b8502SAlexey Kardashevskiy #define RTAS_IBM_CHANGE_MSI                     (RTAS_TOKEN_BASE + 0x19)
4623a3b8502SAlexey Kardashevskiy #define RTAS_SET_INDICATOR                      (RTAS_TOKEN_BASE + 0x1A)
4633a3b8502SAlexey Kardashevskiy #define RTAS_SET_POWER_LEVEL                    (RTAS_TOKEN_BASE + 0x1B)
4643a3b8502SAlexey Kardashevskiy #define RTAS_GET_POWER_LEVEL                    (RTAS_TOKEN_BASE + 0x1C)
4653a3b8502SAlexey Kardashevskiy #define RTAS_GET_SENSOR_STATE                   (RTAS_TOKEN_BASE + 0x1D)
4663a3b8502SAlexey Kardashevskiy #define RTAS_IBM_CONFIGURE_CONNECTOR            (RTAS_TOKEN_BASE + 0x1E)
4673a3b8502SAlexey Kardashevskiy #define RTAS_IBM_OS_TERM                        (RTAS_TOKEN_BASE + 0x1F)
468ee954280SGavin Shan #define RTAS_IBM_SET_EEH_OPTION                 (RTAS_TOKEN_BASE + 0x20)
469ee954280SGavin Shan #define RTAS_IBM_GET_CONFIG_ADDR_INFO2          (RTAS_TOKEN_BASE + 0x21)
470ee954280SGavin Shan #define RTAS_IBM_READ_SLOT_RESET_STATE2         (RTAS_TOKEN_BASE + 0x22)
471ee954280SGavin Shan #define RTAS_IBM_SET_SLOT_RESET                 (RTAS_TOKEN_BASE + 0x23)
472ee954280SGavin Shan #define RTAS_IBM_CONFIGURE_PE                   (RTAS_TOKEN_BASE + 0x24)
473ee954280SGavin Shan #define RTAS_IBM_SLOT_ERROR_DETAIL              (RTAS_TOKEN_BASE + 0x25)
474ae4de14cSAlexey Kardashevskiy #define RTAS_IBM_QUERY_PE_DMA_WINDOW            (RTAS_TOKEN_BASE + 0x26)
475ae4de14cSAlexey Kardashevskiy #define RTAS_IBM_CREATE_PE_DMA_WINDOW           (RTAS_TOKEN_BASE + 0x27)
476ae4de14cSAlexey Kardashevskiy #define RTAS_IBM_REMOVE_PE_DMA_WINDOW           (RTAS_TOKEN_BASE + 0x28)
477ae4de14cSAlexey Kardashevskiy #define RTAS_IBM_RESET_PE_DMA_WINDOW            (RTAS_TOKEN_BASE + 0x29)
4783a3b8502SAlexey Kardashevskiy 
479ae4de14cSAlexey Kardashevskiy #define RTAS_TOKEN_MAX                          (RTAS_TOKEN_BASE + 0x2A)
4803a3b8502SAlexey Kardashevskiy 
4813052d951SSam bobroff /* RTAS ibm,get-system-parameter token values */
4823b50d897SSam bobroff #define RTAS_SYSPARM_SPLPAR_CHARACTERISTICS      20
4833052d951SSam bobroff #define RTAS_SYSPARM_DIAGNOSTICS_RUN_MODE        42
484b907d7b0SSam bobroff #define RTAS_SYSPARM_UUID                        48
4853052d951SSam bobroff 
4868c8639dfSMike Day /* RTAS indicator/sensor types
4878c8639dfSMike Day  *
4888c8639dfSMike Day  * as defined by PAPR+ 2.7 7.3.5.4, Table 41
4898c8639dfSMike Day  *
4908c8639dfSMike Day  * NOTE: currently only DR-related sensors are implemented here
4918c8639dfSMike Day  */
4928c8639dfSMike Day #define RTAS_SENSOR_TYPE_ISOLATION_STATE        9001
4938c8639dfSMike Day #define RTAS_SENSOR_TYPE_DR                     9002
4948c8639dfSMike Day #define RTAS_SENSOR_TYPE_ALLOCATION_STATE       9003
4958c8639dfSMike Day #define RTAS_SENSOR_TYPE_ENTITY_SENSE RTAS_SENSOR_TYPE_ALLOCATION_STATE
4968c8639dfSMike Day 
4973052d951SSam bobroff /* Possible values for the platform-processor-diagnostics-run-mode parameter
4983052d951SSam bobroff  * of the RTAS ibm,get-system-parameter call.
4993052d951SSam bobroff  */
5003052d951SSam bobroff #define DIAGNOSTICS_RUN_MODE_DISABLED  0
5013052d951SSam bobroff #define DIAGNOSTICS_RUN_MODE_STAGGERED 1
5023052d951SSam bobroff #define DIAGNOSTICS_RUN_MODE_IMMEDIATE 2
5033052d951SSam bobroff #define DIAGNOSTICS_RUN_MODE_PERIODIC  3
5043052d951SSam bobroff 
5054fe822e0SAlexey Kardashevskiy static inline uint64_t ppc64_phys_to_real(uint64_t addr)
5064fe822e0SAlexey Kardashevskiy {
5074fe822e0SAlexey Kardashevskiy     return addr & ~0xF000000000000000ULL;
5084fe822e0SAlexey Kardashevskiy }
5094fe822e0SAlexey Kardashevskiy 
51039ac8455SDavid Gibson static inline uint32_t rtas_ld(target_ulong phys, int n)
51139ac8455SDavid Gibson {
512fdfba1a2SEdgar E. Iglesias     return ldl_be_phys(&address_space_memory, ppc64_phys_to_real(phys + 4*n));
51339ac8455SDavid Gibson }
51439ac8455SDavid Gibson 
515a14aa92bSGavin Shan static inline uint64_t rtas_ldq(target_ulong phys, int n)
516a14aa92bSGavin Shan {
517a14aa92bSGavin Shan     return (uint64_t)rtas_ld(phys, n) << 32 | rtas_ld(phys, n + 1);
518a14aa92bSGavin Shan }
519a14aa92bSGavin Shan 
52039ac8455SDavid Gibson static inline void rtas_st(target_ulong phys, int n, uint32_t val)
52139ac8455SDavid Gibson {
522ab1da857SEdgar E. Iglesias     stl_be_phys(&address_space_memory, ppc64_phys_to_real(phys + 4*n), val);
52339ac8455SDavid Gibson }
52439ac8455SDavid Gibson 
52528e02042SDavid Gibson typedef void (*spapr_rtas_fn)(PowerPCCPU *cpu, sPAPRMachineState *sm,
526210b580bSAnthony Liguori                               uint32_t token,
52739ac8455SDavid Gibson                               uint32_t nargs, target_ulong args,
52839ac8455SDavid Gibson                               uint32_t nret, target_ulong rets);
5293a3b8502SAlexey Kardashevskiy void spapr_rtas_register(int token, const char *name, spapr_rtas_fn fn);
53028e02042SDavid Gibson target_ulong spapr_rtas_call(PowerPCCPU *cpu, sPAPRMachineState *sm,
53139ac8455SDavid Gibson                              uint32_t token, uint32_t nargs, target_ulong args,
53239ac8455SDavid Gibson                              uint32_t nret, target_ulong rets);
533a8170e5eSAvi Kivity int spapr_rtas_device_tree_setup(void *fdt, hwaddr rtas_addr,
534a8170e5eSAvi Kivity                                  hwaddr rtas_size);
535*2cac78c1SDavid Gibson void spapr_load_rtas(sPAPRMachineState *spapr, void *fdt, hwaddr addr);
53639ac8455SDavid Gibson 
537ad0ebb91SDavid Gibson #define SPAPR_TCE_PAGE_SHIFT   12
538ad0ebb91SDavid Gibson #define SPAPR_TCE_PAGE_SIZE    (1ULL << SPAPR_TCE_PAGE_SHIFT)
539ad0ebb91SDavid Gibson #define SPAPR_TCE_PAGE_MASK    (SPAPR_TCE_PAGE_SIZE - 1)
540ad0ebb91SDavid Gibson 
541ad0ebb91SDavid Gibson #define SPAPR_VIO_BASE_LIOBN    0x00000000
5424290ca49SAlexey Kardashevskiy #define SPAPR_VIO_LIOBN(reg)    (0x00000000 | (reg))
543c8545818SAlexey Kardashevskiy #define SPAPR_PCI_LIOBN(phb_index, window_num) \
544c8545818SAlexey Kardashevskiy     (0x80000000 | ((phb_index) << 8) | (window_num))
545d9d96a3cSAlexey Kardashevskiy #define SPAPR_IS_PCI_LIOBN(liobn)   (!!((liobn) & 0x80000000))
546c8545818SAlexey Kardashevskiy #define SPAPR_PCI_DMA_WINDOW_NUM(liobn) ((liobn) & 0xff)
547ad0ebb91SDavid Gibson 
54874d042e5SDavid Gibson #define RTAS_ERROR_LOG_MAX      2048
54974d042e5SDavid Gibson 
55079853e18STyrel Datwyler #define RTAS_EVENT_SCAN_RATE    1
55179853e18STyrel Datwyler 
5522b7dc949SPaolo Bonzini typedef struct sPAPRTCETable sPAPRTCETable;
55374d042e5SDavid Gibson 
554a83000f5SAnthony Liguori #define TYPE_SPAPR_TCE_TABLE "spapr-tce-table"
555a83000f5SAnthony Liguori #define SPAPR_TCE_TABLE(obj) \
556a83000f5SAnthony Liguori     OBJECT_CHECK(sPAPRTCETable, (obj), TYPE_SPAPR_TCE_TABLE)
557a83000f5SAnthony Liguori 
558a83000f5SAnthony Liguori struct sPAPRTCETable {
559a83000f5SAnthony Liguori     DeviceState parent;
560a83000f5SAnthony Liguori     uint32_t liobn;
561a83000f5SAnthony Liguori     uint32_t nb_table;
5621b8eceeeSAlexey Kardashevskiy     uint64_t bus_offset;
563650f33adSAlexey Kardashevskiy     uint32_t page_shift;
564a83000f5SAnthony Liguori     uint64_t *table;
565a26fdf39SAlexey Kardashevskiy     uint32_t mig_nb_table;
566a26fdf39SAlexey Kardashevskiy     uint64_t *mig_table;
567a83000f5SAnthony Liguori     bool bypass;
5686a81dd17SDavid Gibson     bool need_vfio;
569a83000f5SAnthony Liguori     int fd;
570b4b6eb77SAlexey Kardashevskiy     MemoryRegion root, iommu;
571ee9a569aSAlexey Kardashevskiy     struct VIOsPAPRDevice *vdev; /* for @bypass migration compatibility only */
572a83000f5SAnthony Liguori     QLIST_ENTRY(sPAPRTCETable) list;
573a83000f5SAnthony Liguori };
574a83000f5SAnthony Liguori 
575f9ce8e0aSThomas Huth sPAPRTCETable *spapr_tce_find_by_liobn(target_ulong liobn);
57631fe14d1SNathan Fontenot 
57731fe14d1SNathan Fontenot struct sPAPREventLogEntry {
57831fe14d1SNathan Fontenot     int log_type;
57979853e18STyrel Datwyler     bool exception;
58031fe14d1SNathan Fontenot     void *data;
58131fe14d1SNathan Fontenot     QTAILQ_ENTRY(sPAPREventLogEntry) next;
58231fe14d1SNathan Fontenot };
58331fe14d1SNathan Fontenot 
58428e02042SDavid Gibson void spapr_events_init(sPAPRMachineState *sm);
58574d042e5SDavid Gibson void spapr_events_fdt_skel(void *fdt, uint32_t epow_irq);
58628e02042SDavid Gibson int spapr_h_cas_compose_response(sPAPRMachineState *sm,
58703d196b7SBharata B Rao                                  target_ulong addr, target_ulong size,
58803d196b7SBharata B Rao                                  bool cpu_update, bool memory_update);
589df7625d4SAlexey Kardashevskiy sPAPRTCETable *spapr_tce_new_table(DeviceState *owner, uint32_t liobn);
590df7625d4SAlexey Kardashevskiy void spapr_tce_table_enable(sPAPRTCETable *tcet,
591df7625d4SAlexey Kardashevskiy                             uint32_t page_shift, uint64_t bus_offset,
592df7625d4SAlexey Kardashevskiy                             uint32_t nb_table);
593a26fdf39SAlexey Kardashevskiy void spapr_tce_table_disable(sPAPRTCETable *tcet);
594c10325d6SDavid Gibson void spapr_tce_set_need_vfio(sPAPRTCETable *tcet, bool need_vfio);
595c10325d6SDavid Gibson 
596a84bb436SPaolo Bonzini MemoryRegion *spapr_tce_get_iommu(sPAPRTCETable *tcet);
597ad0ebb91SDavid Gibson int spapr_dma_dt(void *fdt, int node_off, const char *propname,
5985c4cbcf2SAlexey Kardashevskiy                  uint32_t liobn, uint64_t window, uint32_t size);
5995c4cbcf2SAlexey Kardashevskiy int spapr_tcet_dma_dt(void *fdt, int node_off, const char *propname,
6002b7dc949SPaolo Bonzini                       sPAPRTCETable *tcet);
601eefaccc0SDavid Gibson void spapr_pci_switch_vga(bool big_endian);
6027a36ae7aSBharata B Rao void spapr_hotplug_req_add_by_index(sPAPRDRConnector *drc);
6037a36ae7aSBharata B Rao void spapr_hotplug_req_remove_by_index(sPAPRDRConnector *drc);
6047a36ae7aSBharata B Rao void spapr_hotplug_req_add_by_count(sPAPRDRConnectorType drc_type,
6057a36ae7aSBharata B Rao                                        uint32_t count);
6067a36ae7aSBharata B Rao void spapr_hotplug_req_remove_by_count(sPAPRDRConnectorType drc_type,
6077a36ae7aSBharata B Rao                                           uint32_t count);
6083b542549SBharata B Rao void spapr_cpu_init(sPAPRMachineState *spapr, PowerPCCPU *cpu, Error **errp);
609af81cf32SBharata B Rao void *spapr_populate_hotplug_cpu_dt(CPUState *cs, int *fdt_offset,
610af81cf32SBharata B Rao                                     sPAPRMachineState *spapr);
61128df36a1SDavid Gibson 
61246503c2bSMichael Roth /* rtas-configure-connector state */
61346503c2bSMichael Roth struct sPAPRConfigureConnectorState {
61446503c2bSMichael Roth     uint32_t drc_index;
61546503c2bSMichael Roth     int fdt_offset;
61646503c2bSMichael Roth     int fdt_depth;
61746503c2bSMichael Roth     QTAILQ_ENTRY(sPAPRConfigureConnectorState) next;
61846503c2bSMichael Roth };
61946503c2bSMichael Roth 
62046503c2bSMichael Roth void spapr_ccs_reset_hook(void *opaque);
62146503c2bSMichael Roth 
62228df36a1SDavid Gibson #define TYPE_SPAPR_RTC "spapr-rtc"
6234d9392beSThomas Huth #define TYPE_SPAPR_RNG "spapr-rng"
62428df36a1SDavid Gibson 
62528df36a1SDavid Gibson void spapr_rtc_read(DeviceState *dev, struct tm *tm, uint32_t *ns);
626880ae7deSDavid Gibson int spapr_rtc_import_offset(DeviceState *dev, int64_t legacy_offset);
627ad0ebb91SDavid Gibson 
6284d9392beSThomas Huth int spapr_rng_populate_dt(void *fdt);
6294d9392beSThomas Huth 
630db4ef288SBharata B Rao #define SPAPR_MEMORY_BLOCK_SIZE (1 << 28) /* 256MB */
631db4ef288SBharata B Rao 
6324a1c9cf0SBharata B Rao /*
6334a1c9cf0SBharata B Rao  * This defines the maximum number of DIMM slots we can have for sPAPR
6344a1c9cf0SBharata B Rao  * guest. This is not defined by sPAPR but we are defining it to 32 slots
6354a1c9cf0SBharata B Rao  * based on default number of slots provided by PowerPC kernel.
6364a1c9cf0SBharata B Rao  */
6374a1c9cf0SBharata B Rao #define SPAPR_MAX_RAM_SLOTS     32
6384a1c9cf0SBharata B Rao 
6394a1c9cf0SBharata B Rao /* 1GB alignment for hotplug memory region */
6404a1c9cf0SBharata B Rao #define SPAPR_HOTPLUG_MEM_ALIGN (1ULL << 30)
6414a1c9cf0SBharata B Rao 
64203d196b7SBharata B Rao /*
64303d196b7SBharata B Rao  * Number of 32 bit words in each LMB list entry in ibm,dynamic-memory
64403d196b7SBharata B Rao  * property under ibm,dynamic-reconfiguration-memory node.
64503d196b7SBharata B Rao  */
64603d196b7SBharata B Rao #define SPAPR_DR_LMB_LIST_ENTRY_SIZE 6
64703d196b7SBharata B Rao 
64803d196b7SBharata B Rao /*
649d0e5a8f2SBharata B Rao  * Defines for flag value in ibm,dynamic-memory property under
650d0e5a8f2SBharata B Rao  * ibm,dynamic-reconfiguration-memory node.
65103d196b7SBharata B Rao  */
65203d196b7SBharata B Rao #define SPAPR_LMB_FLAGS_ASSIGNED 0x00000008
653d0e5a8f2SBharata B Rao #define SPAPR_LMB_FLAGS_DRC_INVALID 0x00000020
654d0e5a8f2SBharata B Rao #define SPAPR_LMB_FLAGS_RESERVED 0x00000080
65503d196b7SBharata B Rao 
6562a6a4076SMarkus Armbruster #endif /* HW_SPAPR_H */
657