1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 2212bebb4SDeepthi Dharwar #ifndef _ASM_POWERPC_PLPAR_WRAPPERS_H 3212bebb4SDeepthi Dharwar #define _ASM_POWERPC_PLPAR_WRAPPERS_H 4212bebb4SDeepthi Dharwar 55017e875SMichael Ellerman #ifdef CONFIG_PPC_PSERIES 65017e875SMichael Ellerman 7212bebb4SDeepthi Dharwar #include <linux/string.h> 8212bebb4SDeepthi Dharwar #include <linux/irqflags.h> 9212bebb4SDeepthi Dharwar 10212bebb4SDeepthi Dharwar #include <asm/hvcall.h> 11212bebb4SDeepthi Dharwar #include <asm/paca.h> 12212bebb4SDeepthi Dharwar #include <asm/page.h> 13212bebb4SDeepthi Dharwar 14212bebb4SDeepthi Dharwar static inline long poll_pending(void) 15212bebb4SDeepthi Dharwar { 16212bebb4SDeepthi Dharwar return plpar_hcall_norets(H_POLL_PENDING); 17212bebb4SDeepthi Dharwar } 18212bebb4SDeepthi Dharwar 19212bebb4SDeepthi Dharwar static inline u8 get_cede_latency_hint(void) 20212bebb4SDeepthi Dharwar { 21212bebb4SDeepthi Dharwar return get_lppaca()->cede_latency_hint; 22212bebb4SDeepthi Dharwar } 23212bebb4SDeepthi Dharwar 24212bebb4SDeepthi Dharwar static inline void set_cede_latency_hint(u8 latency_hint) 25212bebb4SDeepthi Dharwar { 26212bebb4SDeepthi Dharwar get_lppaca()->cede_latency_hint = latency_hint; 27212bebb4SDeepthi Dharwar } 28212bebb4SDeepthi Dharwar 29212bebb4SDeepthi Dharwar static inline long cede_processor(void) 30212bebb4SDeepthi Dharwar { 31212bebb4SDeepthi Dharwar return plpar_hcall_norets(H_CEDE); 32212bebb4SDeepthi Dharwar } 33212bebb4SDeepthi Dharwar 34212bebb4SDeepthi Dharwar static inline long extended_cede_processor(unsigned long latency_hint) 35212bebb4SDeepthi Dharwar { 36212bebb4SDeepthi Dharwar long rc; 37212bebb4SDeepthi Dharwar u8 old_latency_hint = get_cede_latency_hint(); 38212bebb4SDeepthi Dharwar 39212bebb4SDeepthi Dharwar set_cede_latency_hint(latency_hint); 40212bebb4SDeepthi Dharwar 41212bebb4SDeepthi Dharwar rc = cede_processor(); 42*9f4b61b2SNicholas Piggin #ifdef CONFIG_PPC_IRQ_SOFT_MASK_DEBUG 43212bebb4SDeepthi Dharwar /* Ensure that H_CEDE returns with IRQs on */ 44212bebb4SDeepthi Dharwar if (WARN_ON(!(mfmsr() & MSR_EE))) 45212bebb4SDeepthi Dharwar __hard_irq_enable(); 46212bebb4SDeepthi Dharwar #endif 47212bebb4SDeepthi Dharwar 48212bebb4SDeepthi Dharwar set_cede_latency_hint(old_latency_hint); 49212bebb4SDeepthi Dharwar 50212bebb4SDeepthi Dharwar return rc; 51212bebb4SDeepthi Dharwar } 52212bebb4SDeepthi Dharwar 53212bebb4SDeepthi Dharwar static inline long vpa_call(unsigned long flags, unsigned long cpu, 54212bebb4SDeepthi Dharwar unsigned long vpa) 55212bebb4SDeepthi Dharwar { 56212bebb4SDeepthi Dharwar flags = flags << H_VPA_FUNC_SHIFT; 57212bebb4SDeepthi Dharwar 58212bebb4SDeepthi Dharwar return plpar_hcall_norets(H_REGISTER_VPA, flags, cpu, vpa); 59212bebb4SDeepthi Dharwar } 60212bebb4SDeepthi Dharwar 61212bebb4SDeepthi Dharwar static inline long unregister_vpa(unsigned long cpu) 62212bebb4SDeepthi Dharwar { 63212bebb4SDeepthi Dharwar return vpa_call(H_VPA_DEREG_VPA, cpu, 0); 64212bebb4SDeepthi Dharwar } 65212bebb4SDeepthi Dharwar 66212bebb4SDeepthi Dharwar static inline long register_vpa(unsigned long cpu, unsigned long vpa) 67212bebb4SDeepthi Dharwar { 68212bebb4SDeepthi Dharwar return vpa_call(H_VPA_REG_VPA, cpu, vpa); 69212bebb4SDeepthi Dharwar } 70212bebb4SDeepthi Dharwar 71212bebb4SDeepthi Dharwar static inline long unregister_slb_shadow(unsigned long cpu) 72212bebb4SDeepthi Dharwar { 73212bebb4SDeepthi Dharwar return vpa_call(H_VPA_DEREG_SLB, cpu, 0); 74212bebb4SDeepthi Dharwar } 75212bebb4SDeepthi Dharwar 76212bebb4SDeepthi Dharwar static inline long register_slb_shadow(unsigned long cpu, unsigned long vpa) 77212bebb4SDeepthi Dharwar { 78212bebb4SDeepthi Dharwar return vpa_call(H_VPA_REG_SLB, cpu, vpa); 79212bebb4SDeepthi Dharwar } 80212bebb4SDeepthi Dharwar 81212bebb4SDeepthi Dharwar static inline long unregister_dtl(unsigned long cpu) 82212bebb4SDeepthi Dharwar { 83212bebb4SDeepthi Dharwar return vpa_call(H_VPA_DEREG_DTL, cpu, 0); 84212bebb4SDeepthi Dharwar } 85212bebb4SDeepthi Dharwar 86212bebb4SDeepthi Dharwar static inline long register_dtl(unsigned long cpu, unsigned long vpa) 87212bebb4SDeepthi Dharwar { 88212bebb4SDeepthi Dharwar return vpa_call(H_VPA_REG_DTL, cpu, vpa); 89212bebb4SDeepthi Dharwar } 90212bebb4SDeepthi Dharwar 91212bebb4SDeepthi Dharwar extern void vpa_init(int cpu); 92212bebb4SDeepthi Dharwar 93212bebb4SDeepthi Dharwar static inline long plpar_pte_enter(unsigned long flags, 94212bebb4SDeepthi Dharwar unsigned long hpte_group, unsigned long hpte_v, 95212bebb4SDeepthi Dharwar unsigned long hpte_r, unsigned long *slot) 96212bebb4SDeepthi Dharwar { 97212bebb4SDeepthi Dharwar long rc; 98212bebb4SDeepthi Dharwar unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; 99212bebb4SDeepthi Dharwar 100212bebb4SDeepthi Dharwar rc = plpar_hcall(H_ENTER, retbuf, flags, hpte_group, hpte_v, hpte_r); 101212bebb4SDeepthi Dharwar 102212bebb4SDeepthi Dharwar *slot = retbuf[0]; 103212bebb4SDeepthi Dharwar 104212bebb4SDeepthi Dharwar return rc; 105212bebb4SDeepthi Dharwar } 106212bebb4SDeepthi Dharwar 107212bebb4SDeepthi Dharwar static inline long plpar_pte_remove(unsigned long flags, unsigned long ptex, 108212bebb4SDeepthi Dharwar unsigned long avpn, unsigned long *old_pteh_ret, 109212bebb4SDeepthi Dharwar unsigned long *old_ptel_ret) 110212bebb4SDeepthi Dharwar { 111212bebb4SDeepthi Dharwar long rc; 112212bebb4SDeepthi Dharwar unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; 113212bebb4SDeepthi Dharwar 114212bebb4SDeepthi Dharwar rc = plpar_hcall(H_REMOVE, retbuf, flags, ptex, avpn); 115212bebb4SDeepthi Dharwar 116212bebb4SDeepthi Dharwar *old_pteh_ret = retbuf[0]; 117212bebb4SDeepthi Dharwar *old_ptel_ret = retbuf[1]; 118212bebb4SDeepthi Dharwar 119212bebb4SDeepthi Dharwar return rc; 120212bebb4SDeepthi Dharwar } 121212bebb4SDeepthi Dharwar 122212bebb4SDeepthi Dharwar /* plpar_pte_remove_raw can be called in real mode. It calls plpar_hcall_raw */ 123212bebb4SDeepthi Dharwar static inline long plpar_pte_remove_raw(unsigned long flags, unsigned long ptex, 124212bebb4SDeepthi Dharwar unsigned long avpn, unsigned long *old_pteh_ret, 125212bebb4SDeepthi Dharwar unsigned long *old_ptel_ret) 126212bebb4SDeepthi Dharwar { 127212bebb4SDeepthi Dharwar long rc; 128212bebb4SDeepthi Dharwar unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; 129212bebb4SDeepthi Dharwar 130212bebb4SDeepthi Dharwar rc = plpar_hcall_raw(H_REMOVE, retbuf, flags, ptex, avpn); 131212bebb4SDeepthi Dharwar 132212bebb4SDeepthi Dharwar *old_pteh_ret = retbuf[0]; 133212bebb4SDeepthi Dharwar *old_ptel_ret = retbuf[1]; 134212bebb4SDeepthi Dharwar 135212bebb4SDeepthi Dharwar return rc; 136212bebb4SDeepthi Dharwar } 137212bebb4SDeepthi Dharwar 138212bebb4SDeepthi Dharwar static inline long plpar_pte_read(unsigned long flags, unsigned long ptex, 139212bebb4SDeepthi Dharwar unsigned long *old_pteh_ret, unsigned long *old_ptel_ret) 140212bebb4SDeepthi Dharwar { 141212bebb4SDeepthi Dharwar long rc; 142212bebb4SDeepthi Dharwar unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; 143212bebb4SDeepthi Dharwar 144212bebb4SDeepthi Dharwar rc = plpar_hcall(H_READ, retbuf, flags, ptex); 145212bebb4SDeepthi Dharwar 146212bebb4SDeepthi Dharwar *old_pteh_ret = retbuf[0]; 147212bebb4SDeepthi Dharwar *old_ptel_ret = retbuf[1]; 148212bebb4SDeepthi Dharwar 149212bebb4SDeepthi Dharwar return rc; 150212bebb4SDeepthi Dharwar } 151212bebb4SDeepthi Dharwar 152212bebb4SDeepthi Dharwar /* plpar_pte_read_raw can be called in real mode. It calls plpar_hcall_raw */ 153212bebb4SDeepthi Dharwar static inline long plpar_pte_read_raw(unsigned long flags, unsigned long ptex, 154212bebb4SDeepthi Dharwar unsigned long *old_pteh_ret, unsigned long *old_ptel_ret) 155212bebb4SDeepthi Dharwar { 156212bebb4SDeepthi Dharwar long rc; 157212bebb4SDeepthi Dharwar unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; 158212bebb4SDeepthi Dharwar 159212bebb4SDeepthi Dharwar rc = plpar_hcall_raw(H_READ, retbuf, flags, ptex); 160212bebb4SDeepthi Dharwar 161212bebb4SDeepthi Dharwar *old_pteh_ret = retbuf[0]; 162212bebb4SDeepthi Dharwar *old_ptel_ret = retbuf[1]; 163212bebb4SDeepthi Dharwar 164212bebb4SDeepthi Dharwar return rc; 165212bebb4SDeepthi Dharwar } 166212bebb4SDeepthi Dharwar 167212bebb4SDeepthi Dharwar /* 1684ad90c86SAneesh Kumar K.V * ptes must be 8*sizeof(unsigned long) 1694ad90c86SAneesh Kumar K.V */ 1704ad90c86SAneesh Kumar K.V static inline long plpar_pte_read_4(unsigned long flags, unsigned long ptex, 1714ad90c86SAneesh Kumar K.V unsigned long *ptes) 1724ad90c86SAneesh Kumar K.V 1734ad90c86SAneesh Kumar K.V { 1744ad90c86SAneesh Kumar K.V long rc; 1754ad90c86SAneesh Kumar K.V unsigned long retbuf[PLPAR_HCALL9_BUFSIZE]; 1764ad90c86SAneesh Kumar K.V 1774ad90c86SAneesh Kumar K.V rc = plpar_hcall9(H_READ, retbuf, flags | H_READ_4, ptex); 1784ad90c86SAneesh Kumar K.V 1794ad90c86SAneesh Kumar K.V memcpy(ptes, retbuf, 8*sizeof(unsigned long)); 1804ad90c86SAneesh Kumar K.V 1814ad90c86SAneesh Kumar K.V return rc; 1824ad90c86SAneesh Kumar K.V } 1834ad90c86SAneesh Kumar K.V 1844ad90c86SAneesh Kumar K.V /* 185212bebb4SDeepthi Dharwar * plpar_pte_read_4_raw can be called in real mode. 186212bebb4SDeepthi Dharwar * ptes must be 8*sizeof(unsigned long) 187212bebb4SDeepthi Dharwar */ 188212bebb4SDeepthi Dharwar static inline long plpar_pte_read_4_raw(unsigned long flags, unsigned long ptex, 189212bebb4SDeepthi Dharwar unsigned long *ptes) 190212bebb4SDeepthi Dharwar 191212bebb4SDeepthi Dharwar { 192212bebb4SDeepthi Dharwar long rc; 193212bebb4SDeepthi Dharwar unsigned long retbuf[PLPAR_HCALL9_BUFSIZE]; 194212bebb4SDeepthi Dharwar 195212bebb4SDeepthi Dharwar rc = plpar_hcall9_raw(H_READ, retbuf, flags | H_READ_4, ptex); 196212bebb4SDeepthi Dharwar 197212bebb4SDeepthi Dharwar memcpy(ptes, retbuf, 8*sizeof(unsigned long)); 198212bebb4SDeepthi Dharwar 199212bebb4SDeepthi Dharwar return rc; 200212bebb4SDeepthi Dharwar } 201212bebb4SDeepthi Dharwar 202212bebb4SDeepthi Dharwar static inline long plpar_pte_protect(unsigned long flags, unsigned long ptex, 203212bebb4SDeepthi Dharwar unsigned long avpn) 204212bebb4SDeepthi Dharwar { 205212bebb4SDeepthi Dharwar return plpar_hcall_norets(H_PROTECT, flags, ptex, avpn); 206212bebb4SDeepthi Dharwar } 207212bebb4SDeepthi Dharwar 20864b40ffbSDavid Gibson static inline long plpar_resize_hpt_prepare(unsigned long flags, 20964b40ffbSDavid Gibson unsigned long shift) 21064b40ffbSDavid Gibson { 21164b40ffbSDavid Gibson return plpar_hcall_norets(H_RESIZE_HPT_PREPARE, flags, shift); 21264b40ffbSDavid Gibson } 21364b40ffbSDavid Gibson 21464b40ffbSDavid Gibson static inline long plpar_resize_hpt_commit(unsigned long flags, 21564b40ffbSDavid Gibson unsigned long shift) 21664b40ffbSDavid Gibson { 21764b40ffbSDavid Gibson return plpar_hcall_norets(H_RESIZE_HPT_COMMIT, flags, shift); 21864b40ffbSDavid Gibson } 21964b40ffbSDavid Gibson 220212bebb4SDeepthi Dharwar static inline long plpar_tce_get(unsigned long liobn, unsigned long ioba, 221212bebb4SDeepthi Dharwar unsigned long *tce_ret) 222212bebb4SDeepthi Dharwar { 223212bebb4SDeepthi Dharwar long rc; 224212bebb4SDeepthi Dharwar unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; 225212bebb4SDeepthi Dharwar 226212bebb4SDeepthi Dharwar rc = plpar_hcall(H_GET_TCE, retbuf, liobn, ioba); 227212bebb4SDeepthi Dharwar 228212bebb4SDeepthi Dharwar *tce_ret = retbuf[0]; 229212bebb4SDeepthi Dharwar 230212bebb4SDeepthi Dharwar return rc; 231212bebb4SDeepthi Dharwar } 232212bebb4SDeepthi Dharwar 233212bebb4SDeepthi Dharwar static inline long plpar_tce_put(unsigned long liobn, unsigned long ioba, 234212bebb4SDeepthi Dharwar unsigned long tceval) 235212bebb4SDeepthi Dharwar { 236212bebb4SDeepthi Dharwar return plpar_hcall_norets(H_PUT_TCE, liobn, ioba, tceval); 237212bebb4SDeepthi Dharwar } 238212bebb4SDeepthi Dharwar 239212bebb4SDeepthi Dharwar static inline long plpar_tce_put_indirect(unsigned long liobn, 240212bebb4SDeepthi Dharwar unsigned long ioba, unsigned long page, unsigned long count) 241212bebb4SDeepthi Dharwar { 242212bebb4SDeepthi Dharwar return plpar_hcall_norets(H_PUT_TCE_INDIRECT, liobn, ioba, page, count); 243212bebb4SDeepthi Dharwar } 244212bebb4SDeepthi Dharwar 245212bebb4SDeepthi Dharwar static inline long plpar_tce_stuff(unsigned long liobn, unsigned long ioba, 246212bebb4SDeepthi Dharwar unsigned long tceval, unsigned long count) 247212bebb4SDeepthi Dharwar { 248212bebb4SDeepthi Dharwar return plpar_hcall_norets(H_STUFF_TCE, liobn, ioba, tceval, count); 249212bebb4SDeepthi Dharwar } 250212bebb4SDeepthi Dharwar 251212bebb4SDeepthi Dharwar /* Set various resource mode parameters */ 252212bebb4SDeepthi Dharwar static inline long plpar_set_mode(unsigned long mflags, unsigned long resource, 253212bebb4SDeepthi Dharwar unsigned long value1, unsigned long value2) 254212bebb4SDeepthi Dharwar { 255212bebb4SDeepthi Dharwar return plpar_hcall_norets(H_SET_MODE, mflags, resource, value1, value2); 256212bebb4SDeepthi Dharwar } 257212bebb4SDeepthi Dharwar 258212bebb4SDeepthi Dharwar /* 259212bebb4SDeepthi Dharwar * Enable relocation on exceptions on this partition 260212bebb4SDeepthi Dharwar * 261212bebb4SDeepthi Dharwar * Note: this call has a partition wide scope and can take a while to complete. 262212bebb4SDeepthi Dharwar * If it returns H_LONG_BUSY_* it should be retried periodically until it 263212bebb4SDeepthi Dharwar * returns H_SUCCESS. 264212bebb4SDeepthi Dharwar */ 265212bebb4SDeepthi Dharwar static inline long enable_reloc_on_exceptions(void) 266212bebb4SDeepthi Dharwar { 267212bebb4SDeepthi Dharwar /* mflags = 3: Exceptions at 0xC000000000004000 */ 26860666de2SMichael Neuling return plpar_set_mode(3, H_SET_MODE_RESOURCE_ADDR_TRANS_MODE, 0, 0); 269212bebb4SDeepthi Dharwar } 270212bebb4SDeepthi Dharwar 271212bebb4SDeepthi Dharwar /* 272212bebb4SDeepthi Dharwar * Disable relocation on exceptions on this partition 273212bebb4SDeepthi Dharwar * 274212bebb4SDeepthi Dharwar * Note: this call has a partition wide scope and can take a while to complete. 275212bebb4SDeepthi Dharwar * If it returns H_LONG_BUSY_* it should be retried periodically until it 276212bebb4SDeepthi Dharwar * returns H_SUCCESS. 277212bebb4SDeepthi Dharwar */ 278212bebb4SDeepthi Dharwar static inline long disable_reloc_on_exceptions(void) { 27960666de2SMichael Neuling return plpar_set_mode(0, H_SET_MODE_RESOURCE_ADDR_TRANS_MODE, 0, 0); 280212bebb4SDeepthi Dharwar } 281212bebb4SDeepthi Dharwar 282e844b1eeSAnton Blanchard /* 283e844b1eeSAnton Blanchard * Take exceptions in big endian mode on this partition 284e844b1eeSAnton Blanchard * 285e844b1eeSAnton Blanchard * Note: this call has a partition wide scope and can take a while to complete. 286e844b1eeSAnton Blanchard * If it returns H_LONG_BUSY_* it should be retried periodically until it 287e844b1eeSAnton Blanchard * returns H_SUCCESS. 288e844b1eeSAnton Blanchard */ 289e844b1eeSAnton Blanchard static inline long enable_big_endian_exceptions(void) 290e844b1eeSAnton Blanchard { 291e844b1eeSAnton Blanchard /* mflags = 0: big endian exceptions */ 29260666de2SMichael Neuling return plpar_set_mode(0, H_SET_MODE_RESOURCE_LE, 0, 0); 293e844b1eeSAnton Blanchard } 294e844b1eeSAnton Blanchard 295e844b1eeSAnton Blanchard /* 296e844b1eeSAnton Blanchard * Take exceptions in little endian mode on this partition 297e844b1eeSAnton Blanchard * 298e844b1eeSAnton Blanchard * Note: this call has a partition wide scope and can take a while to complete. 299e844b1eeSAnton Blanchard * If it returns H_LONG_BUSY_* it should be retried periodically until it 300e844b1eeSAnton Blanchard * returns H_SUCCESS. 301e844b1eeSAnton Blanchard */ 302e844b1eeSAnton Blanchard static inline long enable_little_endian_exceptions(void) 303e844b1eeSAnton Blanchard { 304e844b1eeSAnton Blanchard /* mflags = 1: little endian exceptions */ 30560666de2SMichael Neuling return plpar_set_mode(1, H_SET_MODE_RESOURCE_LE, 0, 0); 306e844b1eeSAnton Blanchard } 307e844b1eeSAnton Blanchard 3087c09c186SMichael Ellerman static inline long plpar_set_ciabr(unsigned long ciabr) 309212bebb4SDeepthi Dharwar { 31060666de2SMichael Neuling return plpar_set_mode(0, H_SET_MODE_RESOURCE_SET_CIABR, ciabr, 0); 311212bebb4SDeepthi Dharwar } 312212bebb4SDeepthi Dharwar 3137c09c186SMichael Ellerman static inline long plpar_set_watchpoint0(unsigned long dawr0, unsigned long dawrx0) 314212bebb4SDeepthi Dharwar { 31560666de2SMichael Neuling return plpar_set_mode(0, H_SET_MODE_RESOURCE_SET_DAWR, dawr0, dawrx0); 316212bebb4SDeepthi Dharwar } 317212bebb4SDeepthi Dharwar 3187c09c186SMichael Ellerman static inline long plpar_signal_sys_reset(long cpu) 31953ce2996SNicholas Piggin { 32053ce2996SNicholas Piggin return plpar_hcall_norets(H_SIGNAL_SYS_RESET, cpu); 32153ce2996SNicholas Piggin } 32253ce2996SNicholas Piggin 323191eccb1SMichael Neuling static inline long plpar_get_cpu_characteristics(struct h_cpu_char_result *p) 324191eccb1SMichael Neuling { 325191eccb1SMichael Neuling unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; 326191eccb1SMichael Neuling long rc; 327191eccb1SMichael Neuling 328191eccb1SMichael Neuling rc = plpar_hcall(H_GET_CPU_CHARACTERISTICS, retbuf); 329191eccb1SMichael Neuling if (rc == H_SUCCESS) { 330191eccb1SMichael Neuling p->character = retbuf[0]; 331191eccb1SMichael Neuling p->behaviour = retbuf[1]; 332191eccb1SMichael Neuling } 333191eccb1SMichael Neuling 334191eccb1SMichael Neuling return rc; 335191eccb1SMichael Neuling } 336191eccb1SMichael Neuling 337ab83dc79SMichael Ellerman #else /* !CONFIG_PPC_PSERIES */ 338ab83dc79SMichael Ellerman 339ab83dc79SMichael Ellerman static inline long plpar_set_ciabr(unsigned long ciabr) 340ab83dc79SMichael Ellerman { 341ab83dc79SMichael Ellerman return 0; 342ab83dc79SMichael Ellerman } 3435017e875SMichael Ellerman #endif /* CONFIG_PPC_PSERIES */ 3445017e875SMichael Ellerman 345212bebb4SDeepthi Dharwar #endif /* _ASM_POWERPC_PLPAR_WRAPPERS_H */ 346