diff mbox series

[080/120] MIPS: PS2: GS: Define gs_xorq_imr()

Message ID c11ccb53a7c064ad002b0742cbea0869e72db165.1567326213.git.noring@nocrew.org (mailing list archive)
State RFC
Headers show
Series Linux for the PlayStation 2 | expand

Commit Message

Fredrik Noring Sept. 1, 2019, 4:19 p.m. UTC
Signed-off-by: Fredrik Noring <noring@nocrew.org>
---
Perhaps this function could have a better name?
---
 arch/mips/include/asm/mach-ps2/gs-registers.h |  8 ++++++++
 drivers/ps2/gs-registers.c                    | 17 +++++++++++++++++
 2 files changed, 25 insertions(+)
diff mbox series

Patch

diff --git a/arch/mips/include/asm/mach-ps2/gs-registers.h b/arch/mips/include/asm/mach-ps2/gs-registers.h
index 596e277a6940..badcb3cce5c2 100644
--- a/arch/mips/include/asm/mach-ps2/gs-registers.h
+++ b/arch/mips/include/asm/mach-ps2/gs-registers.h
@@ -609,4 +609,12 @@  GS_DECLARE_RW_REG(imr,      imr);
 GS_DECLARE_RW_REG(busdir,   busdir);
 GS_DECLARE_RW_REG(siglblid, siglblid);
 
+/**
+ * gs_xorq_imr - exclusive or (XOR) value with the IMR register
+ * @value: value to XOR with the IMR register
+ *
+ * Return: the resulting IMR value
+ */
+u64 gs_xorq_imr(u64 value);
+
 #endif /* __ASM_MACH_PS2_GS_REGISTERS_H */
diff --git a/drivers/ps2/gs-registers.c b/drivers/ps2/gs-registers.c
index 1bd1d072f4cf..8d2bdd26438d 100644
--- a/drivers/ps2/gs-registers.c
+++ b/drivers/ps2/gs-registers.c
@@ -167,6 +167,23 @@  GS_DEFINE_WO_REG(imr,      imr,      GS_IMR);
 GS_DEFINE_WO_REG(busdir,   busdir,   GS_BUSDIR);
 GS_DEFINE_RW_REG(siglblid, siglblid, GS_SIGLBLID);	/* Read-write */
 
+u64 gs_xorq_imr(u64 value)
+{
+	unsigned long flags;
+
+	spin_lock_irqsave(&gs_registers.lock, flags);
+
+	WARN_ON_ONCE(!gs_registers.imr.valid);
+	value = value ^ gs_registers.imr.value;
+	gs_registers.imr.value = value;
+	outq(value, GS_IMR);
+
+	spin_unlock_irqrestore(&gs_registers.lock, flags);
+
+	return value;
+}
+EXPORT_SYMBOL_GPL(gs_xorq_imr);
+
 MODULE_DESCRIPTION("PlayStation 2 privileged Graphics Synthesizer registers");
 MODULE_AUTHOR("Fredrik Noring");
 MODULE_LICENSE("GPL");