Skip to content

Commit d381d7c

Browse files
ozbenhmpe
authored andcommitted
powerpc: Consolidate variants of real-mode MMIOs
We have all sort of variants of MMIO accessors for the real mode instructions. This creates a clean set of accessors based on Linux normal naming conventions, replacing all occurrences of the old ones in the tree. I have purposefully removed the "out/in" variants in favor of only including __raw variants. Any code using these is already pretty much hand tuned to operate in a very specific environment. I've fixed up the 2 users (only one of them actually needed a barrier in the first place). Signed-off-by: Benjamin Herrenschmidt <[email protected]> Signed-off-by: Michael Ellerman <[email protected]>
1 parent f50d6bd commit d381d7c

File tree

7 files changed

+68
-69
lines changed

7 files changed

+68
-69
lines changed

arch/powerpc/include/asm/io.h

Lines changed: 51 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -192,24 +192,8 @@ DEF_MMIO_OUT_D(out_le32, 32, stw);
192192

193193
#endif /* __BIG_ENDIAN */
194194

195-
/*
196-
* Cache inhibitied accessors for use in real mode, you don't want to use these
197-
* unless you know what you're doing.
198-
*
199-
* NB. These use the cpu byte ordering.
200-
*/
201-
DEF_MMIO_OUT_X(out_rm8, 8, stbcix);
202-
DEF_MMIO_OUT_X(out_rm16, 16, sthcix);
203-
DEF_MMIO_OUT_X(out_rm32, 32, stwcix);
204-
DEF_MMIO_IN_X(in_rm8, 8, lbzcix);
205-
DEF_MMIO_IN_X(in_rm16, 16, lhzcix);
206-
DEF_MMIO_IN_X(in_rm32, 32, lwzcix);
207-
208195
#ifdef __powerpc64__
209196

210-
DEF_MMIO_OUT_X(out_rm64, 64, stdcix);
211-
DEF_MMIO_IN_X(in_rm64, 64, ldcix);
212-
213197
#ifdef __BIG_ENDIAN__
214198
DEF_MMIO_OUT_D(out_be64, 64, std);
215199
DEF_MMIO_IN_D(in_be64, 64, ld);
@@ -242,35 +226,6 @@ static inline void out_be64(volatile u64 __iomem *addr, u64 val)
242226
#endif
243227
#endif /* __powerpc64__ */
244228

245-
246-
/*
247-
* Simple Cache inhibited accessors
248-
* Unlike the DEF_MMIO_* macros, these don't include any h/w memory
249-
* barriers, callers need to manage memory barriers on their own.
250-
* These can only be used in hypervisor real mode.
251-
*/
252-
253-
static inline u32 _lwzcix(unsigned long addr)
254-
{
255-
u32 ret;
256-
257-
__asm__ __volatile__("lwzcix %0,0, %1"
258-
: "=r" (ret) : "r" (addr) : "memory");
259-
return ret;
260-
}
261-
262-
static inline void _stbcix(u64 addr, u8 val)
263-
{
264-
__asm__ __volatile__("stbcix %0,0,%1"
265-
: : "r" (val), "r" (addr) : "memory");
266-
}
267-
268-
static inline void _stwcix(u64 addr, u32 val)
269-
{
270-
__asm__ __volatile__("stwcix %0,0,%1"
271-
: : "r" (val), "r" (addr) : "memory");
272-
}
273-
274229
/*
275230
* Low level IO stream instructions are defined out of line for now
276231
*/
@@ -417,15 +372,64 @@ static inline void __raw_writeq(unsigned long v, volatile void __iomem *addr)
417372
}
418373

419374
/*
420-
* Real mode version of the above. stdcix is only supposed to be used
421-
* in hypervisor real mode as per the architecture spec.
375+
* Real mode versions of the above. Those instructions are only supposed
376+
* to be used in hypervisor real mode as per the architecture spec.
422377
*/
378+
static inline void __raw_rm_writeb(u8 val, volatile void __iomem *paddr)
379+
{
380+
__asm__ __volatile__("stbcix %0,0,%1"
381+
: : "r" (val), "r" (paddr) : "memory");
382+
}
383+
384+
static inline void __raw_rm_writew(u16 val, volatile void __iomem *paddr)
385+
{
386+
__asm__ __volatile__("sthcix %0,0,%1"
387+
: : "r" (val), "r" (paddr) : "memory");
388+
}
389+
390+
static inline void __raw_rm_writel(u32 val, volatile void __iomem *paddr)
391+
{
392+
__asm__ __volatile__("stwcix %0,0,%1"
393+
: : "r" (val), "r" (paddr) : "memory");
394+
}
395+
423396
static inline void __raw_rm_writeq(u64 val, volatile void __iomem *paddr)
424397
{
425398
__asm__ __volatile__("stdcix %0,0,%1"
426399
: : "r" (val), "r" (paddr) : "memory");
427400
}
428401

402+
static inline u8 __raw_rm_readb(volatile void __iomem *paddr)
403+
{
404+
u8 ret;
405+
__asm__ __volatile__("lbzcix %0,0, %1"
406+
: "=r" (ret) : "r" (paddr) : "memory");
407+
return ret;
408+
}
409+
410+
static inline u16 __raw_rm_readw(volatile void __iomem *paddr)
411+
{
412+
u16 ret;
413+
__asm__ __volatile__("lhzcix %0,0, %1"
414+
: "=r" (ret) : "r" (paddr) : "memory");
415+
return ret;
416+
}
417+
418+
static inline u32 __raw_rm_readl(volatile void __iomem *paddr)
419+
{
420+
u32 ret;
421+
__asm__ __volatile__("lwzcix %0,0, %1"
422+
: "=r" (ret) : "r" (paddr) : "memory");
423+
return ret;
424+
}
425+
426+
static inline u64 __raw_rm_readq(volatile void __iomem *paddr)
427+
{
428+
u64 ret;
429+
__asm__ __volatile__("ldcix %0,0, %1"
430+
: "=r" (ret) : "r" (paddr) : "memory");
431+
return ret;
432+
}
429433
#endif /* __powerpc64__ */
430434

431435
/*

arch/powerpc/include/asm/kvm_book3s_asm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ struct kvmppc_host_state {
110110
u8 ptid;
111111
struct kvm_vcpu *kvm_vcpu;
112112
struct kvmppc_vcore *kvm_vcore;
113-
unsigned long xics_phys;
113+
void __iomem *xics_phys;
114114
u32 saved_xirr;
115115
u64 dabr;
116116
u64 host_mmcr[7]; /* MMCR 0,1,A, SIAR, SDAR, MMCR2, SIER */

arch/powerpc/include/asm/kvm_ppc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ struct openpic;
409409
extern void kvm_cma_reserve(void) __init;
410410
static inline void kvmppc_set_xics_phys(int cpu, unsigned long addr)
411411
{
412-
paca[cpu].kvm_hstate.xics_phys = addr;
412+
paca[cpu].kvm_hstate.xics_phys = (void __iomem *)addr;
413413
}
414414

415415
static inline u32 kvmppc_get_xics_latch(void)

arch/powerpc/kvm/book3s_hv_builtin.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -194,20 +194,14 @@ long kvmppc_h_random(struct kvm_vcpu *vcpu)
194194
return H_HARDWARE;
195195
}
196196

197-
static inline void rm_writeb(unsigned long paddr, u8 val)
198-
{
199-
__asm__ __volatile__("stbcix %0,0,%1"
200-
: : "r" (val), "r" (paddr) : "memory");
201-
}
202-
203197
/*
204198
* Send an interrupt or message to another CPU.
205199
* The caller needs to include any barrier needed to order writes
206200
* to memory vs. the IPI/message.
207201
*/
208202
void kvmhv_rm_send_ipi(int cpu)
209203
{
210-
unsigned long xics_phys;
204+
void __iomem *xics_phys;
211205
unsigned long msg = PPC_DBELL_TYPE(PPC_DBELL_SERVER);
212206

213207
/* On POWER9 we can use msgsnd for any destination cpu. */
@@ -232,7 +226,7 @@ void kvmhv_rm_send_ipi(int cpu)
232226
/* Else poke the target with an IPI */
233227
xics_phys = paca[cpu].kvm_hstate.xics_phys;
234228
if (xics_phys)
235-
rm_writeb(xics_phys + XICS_MFRR, IPI_PRIORITY);
229+
__raw_rm_writeb(IPI_PRIORITY, xics_phys + XICS_MFRR);
236230
else
237231
opal_int_set_mfrr(get_hard_smp_processor_id(cpu), IPI_PRIORITY);
238232
}
@@ -405,7 +399,7 @@ long kvmppc_read_intr(void)
405399

406400
static long kvmppc_read_one_intr(bool *again)
407401
{
408-
unsigned long xics_phys;
402+
void __iomem *xics_phys;
409403
u32 h_xirr;
410404
__be32 xirr;
411405
u32 xisr;
@@ -423,7 +417,7 @@ static long kvmppc_read_one_intr(bool *again)
423417
if (!xics_phys)
424418
rc = opal_int_get_xirr(&xirr, false);
425419
else
426-
xirr = _lwzcix(xics_phys + XICS_XIRR);
420+
xirr = __raw_rm_readl(xics_phys + XICS_XIRR);
427421
if (rc < 0)
428422
return 1;
429423

@@ -453,8 +447,8 @@ static long kvmppc_read_one_intr(bool *again)
453447
if (xisr == XICS_IPI) {
454448
rc = 0;
455449
if (xics_phys) {
456-
_stbcix(xics_phys + XICS_MFRR, 0xff);
457-
_stwcix(xics_phys + XICS_XIRR, xirr);
450+
__raw_rm_writeb(0xff, xics_phys + XICS_MFRR);
451+
__raw_rm_writel(xirr, xics_phys + XICS_XIRR);
458452
} else {
459453
opal_int_set_mfrr(hard_smp_processor_id(), 0xff);
460454
rc = opal_int_eoi(h_xirr);
@@ -479,7 +473,8 @@ static long kvmppc_read_one_intr(bool *again)
479473
* we need to resend that IPI, bummer
480474
*/
481475
if (xics_phys)
482-
_stbcix(xics_phys + XICS_MFRR, IPI_PRIORITY);
476+
__raw_rm_writeb(IPI_PRIORITY,
477+
xics_phys + XICS_MFRR);
483478
else
484479
opal_int_set_mfrr(hard_smp_processor_id(),
485480
IPI_PRIORITY);

arch/powerpc/kvm/book3s_hv_rm_xics.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ unsigned long eoi_rc;
766766

767767
static void icp_eoi(struct irq_chip *c, u32 hwirq, __be32 xirr, bool *again)
768768
{
769-
unsigned long xics_phys;
769+
void __iomem *xics_phys;
770770
int64_t rc;
771771

772772
rc = pnv_opal_pci_msi_eoi(c, hwirq);
@@ -779,7 +779,7 @@ static void icp_eoi(struct irq_chip *c, u32 hwirq, __be32 xirr, bool *again)
779779
/* EOI it */
780780
xics_phys = local_paca->kvm_hstate.xics_phys;
781781
if (xics_phys) {
782-
_stwcix(xics_phys + XICS_XIRR, xirr);
782+
__raw_rm_writel(xirr, xics_phys + XICS_XIRR);
783783
} else {
784784
rc = opal_int_eoi(be32_to_cpu(xirr));
785785
*again = rc > 0;

arch/powerpc/platforms/powernv/rng.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ int powernv_get_random_real_mode(unsigned long *v)
6262

6363
rng = raw_cpu_read(powernv_rng);
6464

65-
*v = rng_whiten(rng, in_rm64(rng->regs_real));
65+
*v = rng_whiten(rng, __raw_rm_readq(rng->regs_real));
6666

6767
return 1;
6868
}

arch/powerpc/sysdev/xics/icp-native.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,15 @@ void icp_native_cause_ipi_rm(int cpu)
168168
* Need the physical address of the XICS to be
169169
* previously saved in kvm_hstate in the paca.
170170
*/
171-
unsigned long xics_phys;
171+
void __iomem *xics_phys;
172172

173173
/*
174174
* Just like the cause_ipi functions, it is required to
175-
* include a full barrier (out8 includes a sync) before
176-
* causing the IPI.
175+
* include a full barrier before causing the IPI.
177176
*/
178177
xics_phys = paca[cpu].kvm_hstate.xics_phys;
179-
out_rm8((u8 *)(xics_phys + XICS_MFRR), IPI_PRIORITY);
178+
mb();
179+
__raw_rm_writeb(IPI_PRIORITY, xics_phys + XICS_MFRR);
180180
}
181181
#endif
182182

0 commit comments

Comments
 (0)