xref: /qemu/include/hw/ppc/spapr.h (revision 2a6593cb6a2d72c8c29e14f89413089fa5d38501)
19fdf0c29SDavid Gibson #if !defined(__HW_SPAPR_H__)
29fdf0c29SDavid Gibson #define __HW_SPAPR_H__
39fdf0c29SDavid Gibson 
49c17d615SPaolo Bonzini #include "sysemu/dma.h"
50d09e41aSPaolo Bonzini #include "hw/ppc/xics.h"
6277f9acfSPaolo Bonzini 
74040ab72SDavid Gibson struct VIOsPAPRBus;
83384f95cSDavid Gibson struct sPAPRPHBState;
9639e8102SDavid Gibson struct sPAPRNVRAM;
104040ab72SDavid Gibson 
114be21d56SDavid Gibson #define HPTE64_V_HPTE_DIRTY     0x0000000000000040ULL
124be21d56SDavid Gibson 
139fdf0c29SDavid Gibson typedef struct sPAPREnvironment {
144040ab72SDavid Gibson     struct VIOsPAPRBus *vio_bus;
153384f95cSDavid Gibson     QLIST_HEAD(, sPAPRPHBState) phbs;
16f1c2dc7cSAlexey Kardashevskiy     hwaddr msi_win_addr;
17f1c2dc7cSAlexey Kardashevskiy     MemoryRegion msiwindow;
18639e8102SDavid Gibson     struct sPAPRNVRAM *nvram;
19c04d6cfaSAnthony Liguori     XICSState *icp;
20a3467baaSDavid Gibson 
21a8170e5eSAvi Kivity     hwaddr ram_limit;
22a3467baaSDavid Gibson     void *htab;
234be21d56SDavid Gibson     uint32_t htab_shift;
24a8170e5eSAvi Kivity     hwaddr rma_size;
257f763a5dSDavid Gibson     int vrma_adjust;
26a8170e5eSAvi Kivity     hwaddr fdt_addr, rtas_addr;
27a3467baaSDavid Gibson     long rtas_size;
28a3467baaSDavid Gibson     void *fdt_skel;
29a3467baaSDavid Gibson     target_ulong entry_point;
304be21d56SDavid Gibson     uint32_t next_irq;
314be21d56SDavid Gibson     uint64_t rtc_offset;
3298a8b524SAlexey Kardashevskiy     struct PPCTimebase tb;
333fc5acdeSAlexander Graf     bool has_graphics;
3474d042e5SDavid Gibson 
3574d042e5SDavid Gibson     uint32_t epow_irq;
3674d042e5SDavid Gibson     Notifier epow_notifier;
374be21d56SDavid Gibson 
384be21d56SDavid Gibson     /* Migration state */
394be21d56SDavid Gibson     int htab_save_index;
404be21d56SDavid Gibson     bool htab_first_pass;
41e68cb8b4SAlexey Kardashevskiy     int htab_fd;
429fdf0c29SDavid Gibson } sPAPREnvironment;
439fdf0c29SDavid Gibson 
449fdf0c29SDavid Gibson #define H_SUCCESS         0
459fdf0c29SDavid Gibson #define H_BUSY            1        /* Hardware busy -- retry later */
469fdf0c29SDavid Gibson #define H_CLOSED          2        /* Resource closed */
479fdf0c29SDavid Gibson #define H_NOT_AVAILABLE   3
489fdf0c29SDavid Gibson #define H_CONSTRAINED     4        /* Resource request constrained to max allowed */
499fdf0c29SDavid Gibson #define H_PARTIAL         5
509fdf0c29SDavid Gibson #define H_IN_PROGRESS     14       /* Kind of like busy */
519fdf0c29SDavid Gibson #define H_PAGE_REGISTERED 15
529fdf0c29SDavid Gibson #define H_PARTIAL_STORE   16
539fdf0c29SDavid Gibson #define H_PENDING         17       /* returned from H_POLL_PENDING */
549fdf0c29SDavid Gibson #define H_CONTINUE        18       /* Returned from H_Join on success */
559fdf0c29SDavid Gibson #define H_LONG_BUSY_START_RANGE         9900  /* Start of long busy range */
569fdf0c29SDavid Gibson #define H_LONG_BUSY_ORDER_1_MSEC        9900  /* Long busy, hint that 1msec \
579fdf0c29SDavid Gibson                                                  is a good time to retry */
589fdf0c29SDavid Gibson #define H_LONG_BUSY_ORDER_10_MSEC       9901  /* Long busy, hint that 10msec \
599fdf0c29SDavid Gibson                                                  is a good time to retry */
609fdf0c29SDavid Gibson #define H_LONG_BUSY_ORDER_100_MSEC      9902  /* Long busy, hint that 100msec \
619fdf0c29SDavid Gibson                                                  is a good time to retry */
629fdf0c29SDavid Gibson #define H_LONG_BUSY_ORDER_1_SEC         9903  /* Long busy, hint that 1sec \
639fdf0c29SDavid Gibson                                                  is a good time to retry */
649fdf0c29SDavid Gibson #define H_LONG_BUSY_ORDER_10_SEC        9904  /* Long busy, hint that 10sec \
659fdf0c29SDavid Gibson                                                  is a good time to retry */
669fdf0c29SDavid Gibson #define H_LONG_BUSY_ORDER_100_SEC       9905  /* Long busy, hint that 100sec \
679fdf0c29SDavid Gibson                                                  is a good time to retry */
689fdf0c29SDavid Gibson #define H_LONG_BUSY_END_RANGE           9905  /* End of long busy range */
699fdf0c29SDavid Gibson #define H_HARDWARE        -1       /* Hardware error */
709fdf0c29SDavid Gibson #define H_FUNCTION        -2       /* Function not supported */
719fdf0c29SDavid Gibson #define H_PRIVILEGE       -3       /* Caller not privileged */
729fdf0c29SDavid Gibson #define H_PARAMETER       -4       /* Parameter invalid, out-of-range or conflicting */
739fdf0c29SDavid Gibson #define H_BAD_MODE        -5       /* Illegal msr value */
749fdf0c29SDavid Gibson #define H_PTEG_FULL       -6       /* PTEG is full */
759fdf0c29SDavid Gibson #define H_NOT_FOUND       -7       /* PTE was not found" */
769fdf0c29SDavid Gibson #define H_RESERVED_DABR   -8       /* DABR address is reserved by the hypervisor on this processor" */
779fdf0c29SDavid Gibson #define H_NO_MEM          -9
789fdf0c29SDavid Gibson #define H_AUTHORITY       -10
799fdf0c29SDavid Gibson #define H_PERMISSION      -11
809fdf0c29SDavid Gibson #define H_DROPPED         -12
819fdf0c29SDavid Gibson #define H_SOURCE_PARM     -13
829fdf0c29SDavid Gibson #define H_DEST_PARM       -14
839fdf0c29SDavid Gibson #define H_REMOTE_PARM     -15
849fdf0c29SDavid Gibson #define H_RESOURCE        -16
859fdf0c29SDavid Gibson #define H_ADAPTER_PARM    -17
869fdf0c29SDavid Gibson #define H_RH_PARM         -18
879fdf0c29SDavid Gibson #define H_RCQ_PARM        -19
889fdf0c29SDavid Gibson #define H_SCQ_PARM        -20
899fdf0c29SDavid Gibson #define H_EQ_PARM         -21
909fdf0c29SDavid Gibson #define H_RT_PARM         -22
919fdf0c29SDavid Gibson #define H_ST_PARM         -23
929fdf0c29SDavid Gibson #define H_SIGT_PARM       -24
939fdf0c29SDavid Gibson #define H_TOKEN_PARM      -25
949fdf0c29SDavid Gibson #define H_MLENGTH_PARM    -27
959fdf0c29SDavid Gibson #define H_MEM_PARM        -28
969fdf0c29SDavid Gibson #define H_MEM_ACCESS_PARM -29
979fdf0c29SDavid Gibson #define H_ATTR_PARM       -30
989fdf0c29SDavid Gibson #define H_PORT_PARM       -31
999fdf0c29SDavid Gibson #define H_MCG_PARM        -32
1009fdf0c29SDavid Gibson #define H_VL_PARM         -33
1019fdf0c29SDavid Gibson #define H_TSIZE_PARM      -34
1029fdf0c29SDavid Gibson #define H_TRACE_PARM      -35
1039fdf0c29SDavid Gibson 
1049fdf0c29SDavid Gibson #define H_MASK_PARM       -37
1059fdf0c29SDavid Gibson #define H_MCG_FULL        -38
1069fdf0c29SDavid Gibson #define H_ALIAS_EXIST     -39
1079fdf0c29SDavid Gibson #define H_P_COUNTER       -40
1089fdf0c29SDavid Gibson #define H_TABLE_FULL      -41
1099fdf0c29SDavid Gibson #define H_ALT_TABLE       -42
1109fdf0c29SDavid Gibson #define H_MR_CONDITION    -43
1119fdf0c29SDavid Gibson #define H_NOT_ENOUGH_RESOURCES -44
1129fdf0c29SDavid Gibson #define H_R_STATE         -45
1139fdf0c29SDavid Gibson #define H_RESCINDEND      -46
11442561bf2SAnton Blanchard #define H_P2              -55
11542561bf2SAnton Blanchard #define H_P3              -56
11642561bf2SAnton Blanchard #define H_P4              -57
11742561bf2SAnton Blanchard #define H_P5              -58
11842561bf2SAnton Blanchard #define H_P6              -59
11942561bf2SAnton Blanchard #define H_P7              -60
12042561bf2SAnton Blanchard #define H_P8              -61
12142561bf2SAnton Blanchard #define H_P9              -62
12242561bf2SAnton Blanchard #define H_UNSUPPORTED_FLAG -256
1239fdf0c29SDavid Gibson #define H_MULTI_THREADS_ACTIVE -9005
1249fdf0c29SDavid Gibson 
1259fdf0c29SDavid Gibson 
1269fdf0c29SDavid Gibson /* Long Busy is a condition that can be returned by the firmware
1279fdf0c29SDavid Gibson  * when a call cannot be completed now, but the identical call
1289fdf0c29SDavid Gibson  * should be retried later.  This prevents calls blocking in the
1299fdf0c29SDavid Gibson  * firmware for long periods of time.  Annoyingly the firmware can return
1309fdf0c29SDavid Gibson  * a range of return codes, hinting at how long we should wait before
1319fdf0c29SDavid Gibson  * retrying.  If you don't care for the hint, the macro below is a good
1329fdf0c29SDavid Gibson  * way to check for the long_busy return codes
1339fdf0c29SDavid Gibson  */
1349fdf0c29SDavid Gibson #define H_IS_LONG_BUSY(x)  ((x >= H_LONG_BUSY_START_RANGE) \
1359fdf0c29SDavid Gibson                             && (x <= H_LONG_BUSY_END_RANGE))
1369fdf0c29SDavid Gibson 
1379fdf0c29SDavid Gibson /* Flags */
1389fdf0c29SDavid Gibson #define H_LARGE_PAGE      (1ULL<<(63-16))
1399fdf0c29SDavid Gibson #define H_EXACT           (1ULL<<(63-24))       /* Use exact PTE or return H_PTEG_FULL */
1409fdf0c29SDavid Gibson #define H_R_XLATE         (1ULL<<(63-25))       /* include a valid logical page num in the pte if the valid bit is set */
1419fdf0c29SDavid Gibson #define H_READ_4          (1ULL<<(63-26))       /* Return 4 PTEs */
1429fdf0c29SDavid Gibson #define H_PAGE_STATE_CHANGE (1ULL<<(63-28))
1439fdf0c29SDavid Gibson #define H_PAGE_UNUSED     ((1ULL<<(63-29)) | (1ULL<<(63-30)))
1449fdf0c29SDavid Gibson #define H_PAGE_SET_UNUSED (H_PAGE_STATE_CHANGE | H_PAGE_UNUSED)
1459fdf0c29SDavid Gibson #define H_PAGE_SET_LOANED (H_PAGE_SET_UNUSED | (1ULL<<(63-31)))
1469fdf0c29SDavid Gibson #define H_PAGE_SET_ACTIVE H_PAGE_STATE_CHANGE
1479fdf0c29SDavid Gibson #define H_AVPN            (1ULL<<(63-32))       /* An avpn is provided as a sanity test */
1489fdf0c29SDavid Gibson #define H_ANDCOND         (1ULL<<(63-33))
1499fdf0c29SDavid Gibson #define H_ICACHE_INVALIDATE (1ULL<<(63-40))     /* icbi, etc.  (ignored for IO pages) */
1509fdf0c29SDavid Gibson #define H_ICACHE_SYNCHRONIZE (1ULL<<(63-41))    /* dcbst, icbi, etc (ignored for IO pages */
1519fdf0c29SDavid Gibson #define H_ZERO_PAGE       (1ULL<<(63-48))       /* zero the page before mapping (ignored for IO pages) */
1529fdf0c29SDavid Gibson #define H_COPY_PAGE       (1ULL<<(63-49))
1539fdf0c29SDavid Gibson #define H_N               (1ULL<<(63-61))
1549fdf0c29SDavid Gibson #define H_PP1             (1ULL<<(63-62))
1559fdf0c29SDavid Gibson #define H_PP2             (1ULL<<(63-63))
1569fdf0c29SDavid Gibson 
157a46622fdSAlexey Kardashevskiy /* Values for 2nd argument to H_SET_MODE */
158a46622fdSAlexey Kardashevskiy #define H_SET_MODE_RESOURCE_SET_CIABR           1
159a46622fdSAlexey Kardashevskiy #define H_SET_MODE_RESOURCE_SET_DAWR            2
160a46622fdSAlexey Kardashevskiy #define H_SET_MODE_RESOURCE_ADDR_TRANS_MODE     3
161a46622fdSAlexey Kardashevskiy #define H_SET_MODE_RESOURCE_LE                  4
162a46622fdSAlexey Kardashevskiy 
163a46622fdSAlexey Kardashevskiy /* Flags for H_SET_MODE_RESOURCE_LE */
16442561bf2SAnton Blanchard #define H_SET_MODE_ENDIAN_BIG    0
16542561bf2SAnton Blanchard #define H_SET_MODE_ENDIAN_LITTLE 1
16642561bf2SAnton Blanchard 
1679fdf0c29SDavid Gibson /* VASI States */
1689fdf0c29SDavid Gibson #define H_VASI_INVALID    0
1699fdf0c29SDavid Gibson #define H_VASI_ENABLED    1
1709fdf0c29SDavid Gibson #define H_VASI_ABORTED    2
1719fdf0c29SDavid Gibson #define H_VASI_SUSPENDING 3
1729fdf0c29SDavid Gibson #define H_VASI_SUSPENDED  4
1739fdf0c29SDavid Gibson #define H_VASI_RESUMED    5
1749fdf0c29SDavid Gibson #define H_VASI_COMPLETED  6
1759fdf0c29SDavid Gibson 
1769fdf0c29SDavid Gibson /* DABRX flags */
1779fdf0c29SDavid Gibson #define H_DABRX_HYPERVISOR (1ULL<<(63-61))
1789fdf0c29SDavid Gibson #define H_DABRX_KERNEL     (1ULL<<(63-62))
1799fdf0c29SDavid Gibson #define H_DABRX_USER       (1ULL<<(63-63))
1809fdf0c29SDavid Gibson 
18166a0a2cbSDong Xu Wang /* Each control block has to be on a 4K boundary */
1829fdf0c29SDavid Gibson #define H_CB_ALIGNMENT     4096
1839fdf0c29SDavid Gibson 
1849fdf0c29SDavid Gibson /* pSeries hypervisor opcodes */
1859fdf0c29SDavid Gibson #define H_REMOVE                0x04
1869fdf0c29SDavid Gibson #define H_ENTER                 0x08
1879fdf0c29SDavid Gibson #define H_READ                  0x0c
1889fdf0c29SDavid Gibson #define H_CLEAR_MOD             0x10
1899fdf0c29SDavid Gibson #define H_CLEAR_REF             0x14
1909fdf0c29SDavid Gibson #define H_PROTECT               0x18
1919fdf0c29SDavid Gibson #define H_GET_TCE               0x1c
1929fdf0c29SDavid Gibson #define H_PUT_TCE               0x20
1939fdf0c29SDavid Gibson #define H_SET_SPRG0             0x24
1949fdf0c29SDavid Gibson #define H_SET_DABR              0x28
1959fdf0c29SDavid Gibson #define H_PAGE_INIT             0x2c
1969fdf0c29SDavid Gibson #define H_SET_ASR               0x30
1979fdf0c29SDavid Gibson #define H_ASR_ON                0x34
1989fdf0c29SDavid Gibson #define H_ASR_OFF               0x38
1999fdf0c29SDavid Gibson #define H_LOGICAL_CI_LOAD       0x3c
2009fdf0c29SDavid Gibson #define H_LOGICAL_CI_STORE      0x40
2019fdf0c29SDavid Gibson #define H_LOGICAL_CACHE_LOAD    0x44
2029fdf0c29SDavid Gibson #define H_LOGICAL_CACHE_STORE   0x48
2039fdf0c29SDavid Gibson #define H_LOGICAL_ICBI          0x4c
2049fdf0c29SDavid Gibson #define H_LOGICAL_DCBF          0x50
2059fdf0c29SDavid Gibson #define H_GET_TERM_CHAR         0x54
2069fdf0c29SDavid Gibson #define H_PUT_TERM_CHAR         0x58
2079fdf0c29SDavid Gibson #define H_REAL_TO_LOGICAL       0x5c
2089fdf0c29SDavid Gibson #define H_HYPERVISOR_DATA       0x60
2099fdf0c29SDavid Gibson #define H_EOI                   0x64
2109fdf0c29SDavid Gibson #define H_CPPR                  0x68
2119fdf0c29SDavid Gibson #define H_IPI                   0x6c
2129fdf0c29SDavid Gibson #define H_IPOLL                 0x70
2139fdf0c29SDavid Gibson #define H_XIRR                  0x74
2149fdf0c29SDavid Gibson #define H_PERFMON               0x7c
2159fdf0c29SDavid Gibson #define H_MIGRATE_DMA           0x78
2169fdf0c29SDavid Gibson #define H_REGISTER_VPA          0xDC
2179fdf0c29SDavid Gibson #define H_CEDE                  0xE0
2189fdf0c29SDavid Gibson #define H_CONFER                0xE4
2199fdf0c29SDavid Gibson #define H_PROD                  0xE8
2209fdf0c29SDavid Gibson #define H_GET_PPP               0xEC
2219fdf0c29SDavid Gibson #define H_SET_PPP               0xF0
2229fdf0c29SDavid Gibson #define H_PURR                  0xF4
2239fdf0c29SDavid Gibson #define H_PIC                   0xF8
2249fdf0c29SDavid Gibson #define H_REG_CRQ               0xFC
2259fdf0c29SDavid Gibson #define H_FREE_CRQ              0x100
2269fdf0c29SDavid Gibson #define H_VIO_SIGNAL            0x104
2279fdf0c29SDavid Gibson #define H_SEND_CRQ              0x108
2289fdf0c29SDavid Gibson #define H_COPY_RDMA             0x110
2299fdf0c29SDavid Gibson #define H_REGISTER_LOGICAL_LAN  0x114
2309fdf0c29SDavid Gibson #define H_FREE_LOGICAL_LAN      0x118
2319fdf0c29SDavid Gibson #define H_ADD_LOGICAL_LAN_BUFFER 0x11C
2329fdf0c29SDavid Gibson #define H_SEND_LOGICAL_LAN      0x120
2339fdf0c29SDavid Gibson #define H_BULK_REMOVE           0x124
2349fdf0c29SDavid Gibson #define H_MULTICAST_CTRL        0x130
2359fdf0c29SDavid Gibson #define H_SET_XDABR             0x134
2369fdf0c29SDavid Gibson #define H_STUFF_TCE             0x138
2379fdf0c29SDavid Gibson #define H_PUT_TCE_INDIRECT      0x13C
2389fdf0c29SDavid Gibson #define H_CHANGE_LOGICAL_LAN_MAC 0x14C
2399fdf0c29SDavid Gibson #define H_VTERM_PARTNER_INFO    0x150
2409fdf0c29SDavid Gibson #define H_REGISTER_VTERM        0x154
2419fdf0c29SDavid Gibson #define H_FREE_VTERM            0x158
2429fdf0c29SDavid Gibson #define H_RESET_EVENTS          0x15C
2439fdf0c29SDavid Gibson #define H_ALLOC_RESOURCE        0x160
2449fdf0c29SDavid Gibson #define H_FREE_RESOURCE         0x164
2459fdf0c29SDavid Gibson #define H_MODIFY_QP             0x168
2469fdf0c29SDavid Gibson #define H_QUERY_QP              0x16C
2479fdf0c29SDavid Gibson #define H_REREGISTER_PMR        0x170
2489fdf0c29SDavid Gibson #define H_REGISTER_SMR          0x174
2499fdf0c29SDavid Gibson #define H_QUERY_MR              0x178
2509fdf0c29SDavid Gibson #define H_QUERY_MW              0x17C
2519fdf0c29SDavid Gibson #define H_QUERY_HCA             0x180
2529fdf0c29SDavid Gibson #define H_QUERY_PORT            0x184
2539fdf0c29SDavid Gibson #define H_MODIFY_PORT           0x188
2549fdf0c29SDavid Gibson #define H_DEFINE_AQP1           0x18C
2559fdf0c29SDavid Gibson #define H_GET_TRACE_BUFFER      0x190
2569fdf0c29SDavid Gibson #define H_DEFINE_AQP0           0x194
2579fdf0c29SDavid Gibson #define H_RESIZE_MR             0x198
2589fdf0c29SDavid Gibson #define H_ATTACH_MCQP           0x19C
2599fdf0c29SDavid Gibson #define H_DETACH_MCQP           0x1A0
2609fdf0c29SDavid Gibson #define H_CREATE_RPT            0x1A4
2619fdf0c29SDavid Gibson #define H_REMOVE_RPT            0x1A8
2629fdf0c29SDavid Gibson #define H_REGISTER_RPAGES       0x1AC
2639fdf0c29SDavid Gibson #define H_DISABLE_AND_GETC      0x1B0
2649fdf0c29SDavid Gibson #define H_ERROR_DATA            0x1B4
2659fdf0c29SDavid Gibson #define H_GET_HCA_INFO          0x1B8
2669fdf0c29SDavid Gibson #define H_GET_PERF_COUNT        0x1BC
2679fdf0c29SDavid Gibson #define H_MANAGE_TRACE          0x1C0
2689fdf0c29SDavid Gibson #define H_FREE_LOGICAL_LAN_BUFFER 0x1D4
2699fdf0c29SDavid Gibson #define H_QUERY_INT_STATE       0x1E4
2709fdf0c29SDavid Gibson #define H_POLL_PENDING          0x1D8
2719fdf0c29SDavid Gibson #define H_ILLAN_ATTRIBUTES      0x244
2729fdf0c29SDavid Gibson #define H_MODIFY_HEA_QP         0x250
2739fdf0c29SDavid Gibson #define H_QUERY_HEA_QP          0x254
2749fdf0c29SDavid Gibson #define H_QUERY_HEA             0x258
2759fdf0c29SDavid Gibson #define H_QUERY_HEA_PORT        0x25C
2769fdf0c29SDavid Gibson #define H_MODIFY_HEA_PORT       0x260
2779fdf0c29SDavid Gibson #define H_REG_BCMC              0x264
2789fdf0c29SDavid Gibson #define H_DEREG_BCMC            0x268
2799fdf0c29SDavid Gibson #define H_REGISTER_HEA_RPAGES   0x26C
2809fdf0c29SDavid Gibson #define H_DISABLE_AND_GET_HEA   0x270
2819fdf0c29SDavid Gibson #define H_GET_HEA_INFO          0x274
2829fdf0c29SDavid Gibson #define H_ALLOC_HEA_RESOURCE    0x278
2839fdf0c29SDavid Gibson #define H_ADD_CONN              0x284
2849fdf0c29SDavid Gibson #define H_DEL_CONN              0x288
2859fdf0c29SDavid Gibson #define H_JOIN                  0x298
2869fdf0c29SDavid Gibson #define H_VASI_STATE            0x2A4
2879fdf0c29SDavid Gibson #define H_ENABLE_CRQ            0x2B0
2889fdf0c29SDavid Gibson #define H_GET_EM_PARMS          0x2B8
2899fdf0c29SDavid Gibson #define H_SET_MPP               0x2D0
2909fdf0c29SDavid Gibson #define H_GET_MPP               0x2D4
2915d87e4b7SBenjamin Herrenschmidt #define H_XIRR_X                0x2FC
29242561bf2SAnton Blanchard #define H_SET_MODE              0x31C
29342561bf2SAnton Blanchard #define MAX_HCALL_OPCODE        H_SET_MODE
2949fdf0c29SDavid Gibson 
29539ac8455SDavid Gibson /* The hcalls above are standardized in PAPR and implemented by pHyp
29639ac8455SDavid Gibson  * as well.
29739ac8455SDavid Gibson  *
29839ac8455SDavid Gibson  * We also need some hcalls which are specific to qemu / KVM-on-POWER.
29939ac8455SDavid Gibson  * So far we just need one for H_RTAS, but in future we'll need more
30039ac8455SDavid Gibson  * for extensions like virtio.  We put those into the 0xf000-0xfffc
30139ac8455SDavid Gibson  * range which is reserved by PAPR for "platform-specific" hcalls.
30239ac8455SDavid Gibson  */
30339ac8455SDavid Gibson #define KVMPPC_HCALL_BASE       0xf000
30439ac8455SDavid Gibson #define KVMPPC_H_RTAS           (KVMPPC_HCALL_BASE + 0x0)
305c73e3771SBenjamin Herrenschmidt #define KVMPPC_H_LOGICAL_MEMOP  (KVMPPC_HCALL_BASE + 0x1)
306*2a6593cbSAlexey Kardashevskiy /* Client Architecture support */
307*2a6593cbSAlexey Kardashevskiy #define KVMPPC_H_CAS            (KVMPPC_HCALL_BASE + 0x2)
308*2a6593cbSAlexey Kardashevskiy #define KVMPPC_HCALL_MAX        KVMPPC_H_CAS
30939ac8455SDavid Gibson 
3109fdf0c29SDavid Gibson extern sPAPREnvironment *spapr;
3119fdf0c29SDavid Gibson 
312*2a6593cbSAlexey Kardashevskiy typedef struct sPAPRDeviceTreeUpdateHeader {
313*2a6593cbSAlexey Kardashevskiy     uint32_t version_id;
314*2a6593cbSAlexey Kardashevskiy } sPAPRDeviceTreeUpdateHeader;
315*2a6593cbSAlexey Kardashevskiy 
3169fdf0c29SDavid Gibson /*#define DEBUG_SPAPR_HCALLS*/
3179fdf0c29SDavid Gibson 
3189fdf0c29SDavid Gibson #ifdef DEBUG_SPAPR_HCALLS
3199fdf0c29SDavid Gibson #define hcall_dprintf(fmt, ...) \
320d9599c92SDavid Gibson     do { fprintf(stderr, "%s: " fmt, __func__, ## __VA_ARGS__); } while (0)
3219fdf0c29SDavid Gibson #else
3229fdf0c29SDavid Gibson #define hcall_dprintf(fmt, ...) \
3239fdf0c29SDavid Gibson     do { } while (0)
3249fdf0c29SDavid Gibson #endif
3259fdf0c29SDavid Gibson 
326b13ce26dSAndreas Färber typedef target_ulong (*spapr_hcall_fn)(PowerPCCPU *cpu, sPAPREnvironment *spapr,
3279fdf0c29SDavid Gibson                                        target_ulong opcode,
3289fdf0c29SDavid Gibson                                        target_ulong *args);
3299fdf0c29SDavid Gibson 
3309fdf0c29SDavid Gibson void spapr_register_hypercall(target_ulong opcode, spapr_hcall_fn fn);
331aa100fa4SAndreas Färber target_ulong spapr_hypercall(PowerPCCPU *cpu, target_ulong opcode,
3329fdf0c29SDavid Gibson                              target_ulong *args);
3339fdf0c29SDavid Gibson 
334ff9d2afaSDavid Gibson int spapr_allocate_irq(int hint, bool lsi);
335f1c2dc7cSAlexey Kardashevskiy int spapr_allocate_irq_block(int num, bool lsi, bool msi);
336d07fee7eSDavid Gibson 
337a307d594SAlexey Kardashevskiy static inline int spapr_allocate_msi(int hint)
338d07fee7eSDavid Gibson {
339ff9d2afaSDavid Gibson     return spapr_allocate_irq(hint, false);
340d07fee7eSDavid Gibson }
341d07fee7eSDavid Gibson 
342a307d594SAlexey Kardashevskiy static inline int spapr_allocate_lsi(int hint)
343d07fee7eSDavid Gibson {
344ff9d2afaSDavid Gibson     return spapr_allocate_irq(hint, true);
345d07fee7eSDavid Gibson }
346277f9acfSPaolo Bonzini 
347a64d325dSAlexey Kardashevskiy /* RTAS return codes */
348a64d325dSAlexey Kardashevskiy #define RTAS_OUT_SUCCESS            0
349a64d325dSAlexey Kardashevskiy #define RTAS_OUT_NO_ERRORS_FOUND    1
350a64d325dSAlexey Kardashevskiy #define RTAS_OUT_HW_ERROR           -1
351a64d325dSAlexey Kardashevskiy #define RTAS_OUT_BUSY               -2
352a64d325dSAlexey Kardashevskiy #define RTAS_OUT_PARAM_ERROR        -3
3533ada6b11SAlexey Kardashevskiy #define RTAS_OUT_NOT_SUPPORTED      -3
3543ada6b11SAlexey Kardashevskiy #define RTAS_OUT_NOT_AUTHORIZED     -9002
355a64d325dSAlexey Kardashevskiy 
3564fe822e0SAlexey Kardashevskiy static inline uint64_t ppc64_phys_to_real(uint64_t addr)
3574fe822e0SAlexey Kardashevskiy {
3584fe822e0SAlexey Kardashevskiy     return addr & ~0xF000000000000000ULL;
3594fe822e0SAlexey Kardashevskiy }
3604fe822e0SAlexey Kardashevskiy 
36139ac8455SDavid Gibson static inline uint32_t rtas_ld(target_ulong phys, int n)
36239ac8455SDavid Gibson {
363fdfba1a2SEdgar E. Iglesias     return ldl_be_phys(&address_space_memory, ppc64_phys_to_real(phys + 4*n));
36439ac8455SDavid Gibson }
36539ac8455SDavid Gibson 
36639ac8455SDavid Gibson static inline void rtas_st(target_ulong phys, int n, uint32_t val)
36739ac8455SDavid Gibson {
368ab1da857SEdgar E. Iglesias     stl_be_phys(&address_space_memory, ppc64_phys_to_real(phys + 4*n), val);
36939ac8455SDavid Gibson }
37039ac8455SDavid Gibson 
371210b580bSAnthony Liguori typedef void (*spapr_rtas_fn)(PowerPCCPU *cpu, sPAPREnvironment *spapr,
372210b580bSAnthony Liguori                               uint32_t token,
37339ac8455SDavid Gibson                               uint32_t nargs, target_ulong args,
37439ac8455SDavid Gibson                               uint32_t nret, target_ulong rets);
3754aac82c3SMichael Ellerman int spapr_rtas_register(const char *name, spapr_rtas_fn fn);
376210b580bSAnthony Liguori target_ulong spapr_rtas_call(PowerPCCPU *cpu, sPAPREnvironment *spapr,
37739ac8455SDavid Gibson                              uint32_t token, uint32_t nargs, target_ulong args,
37839ac8455SDavid Gibson                              uint32_t nret, target_ulong rets);
379a8170e5eSAvi Kivity int spapr_rtas_device_tree_setup(void *fdt, hwaddr rtas_addr,
380a8170e5eSAvi Kivity                                  hwaddr rtas_size);
38139ac8455SDavid Gibson 
382ad0ebb91SDavid Gibson #define SPAPR_TCE_PAGE_SHIFT   12
383ad0ebb91SDavid Gibson #define SPAPR_TCE_PAGE_SIZE    (1ULL << SPAPR_TCE_PAGE_SHIFT)
384ad0ebb91SDavid Gibson #define SPAPR_TCE_PAGE_MASK    (SPAPR_TCE_PAGE_SIZE - 1)
385ad0ebb91SDavid Gibson 
386ad0ebb91SDavid Gibson #define SPAPR_VIO_BASE_LIOBN    0x00000000
387edded454SDavid Gibson #define SPAPR_PCI_BASE_LIOBN    0x80000000
388ad0ebb91SDavid Gibson 
38974d042e5SDavid Gibson #define RTAS_ERROR_LOG_MAX      2048
39074d042e5SDavid Gibson 
3912b7dc949SPaolo Bonzini typedef struct sPAPRTCETable sPAPRTCETable;
39274d042e5SDavid Gibson 
393a83000f5SAnthony Liguori #define TYPE_SPAPR_TCE_TABLE "spapr-tce-table"
394a83000f5SAnthony Liguori #define SPAPR_TCE_TABLE(obj) \
395a83000f5SAnthony Liguori     OBJECT_CHECK(sPAPRTCETable, (obj), TYPE_SPAPR_TCE_TABLE)
396a83000f5SAnthony Liguori 
397a83000f5SAnthony Liguori struct sPAPRTCETable {
398a83000f5SAnthony Liguori     DeviceState parent;
399a83000f5SAnthony Liguori     uint32_t liobn;
400a83000f5SAnthony Liguori     uint32_t window_size;
401a83000f5SAnthony Liguori     uint32_t nb_table;
402a83000f5SAnthony Liguori     uint64_t *table;
403a83000f5SAnthony Liguori     bool bypass;
404a83000f5SAnthony Liguori     int fd;
405a83000f5SAnthony Liguori     MemoryRegion iommu;
406a83000f5SAnthony Liguori     QLIST_ENTRY(sPAPRTCETable) list;
407a83000f5SAnthony Liguori };
408a83000f5SAnthony Liguori 
40974d042e5SDavid Gibson void spapr_events_init(sPAPREnvironment *spapr);
41074d042e5SDavid Gibson void spapr_events_fdt_skel(void *fdt, uint32_t epow_irq);
411*2a6593cbSAlexey Kardashevskiy int spapr_h_cas_compose_response(target_ulong addr, target_ulong size);
41284af6d9fSPaolo Bonzini sPAPRTCETable *spapr_tce_new_table(DeviceState *owner, uint32_t liobn,
41384af6d9fSPaolo Bonzini                                    size_t window_size);
414a84bb436SPaolo Bonzini MemoryRegion *spapr_tce_get_iommu(sPAPRTCETable *tcet);
4152b7dc949SPaolo Bonzini void spapr_tce_set_bypass(sPAPRTCETable *tcet, bool bypass);
416ad0ebb91SDavid Gibson int spapr_dma_dt(void *fdt, int node_off, const char *propname,
4175c4cbcf2SAlexey Kardashevskiy                  uint32_t liobn, uint64_t window, uint32_t size);
4185c4cbcf2SAlexey Kardashevskiy int spapr_tcet_dma_dt(void *fdt, int node_off, const char *propname,
4192b7dc949SPaolo Bonzini                       sPAPRTCETable *tcet);
420ad0ebb91SDavid Gibson 
4219fdf0c29SDavid Gibson #endif /* !defined (__HW_SPAPR_H__) */
422