diff mbox

[1/2] xscom: Add xscom_write_mask() function

Message ID 1501820120-22627-1-git-send-email-alistair@popple.id.au
State Accepted
Headers show

Commit Message

Alistair Popple Aug. 4, 2017, 4:15 a.m. UTC
It is common for xscom registers to only contain specific bit fields that
need to be modified without altering the rest of the register. This adds a
convenience function to perform xscom read-modify-write operations under a
mask.

Signed-off-by: Alistair Popple <alistair@popple.id.au>
---
 hw/xscom.c      | 15 +++++++++++++++
 include/xscom.h |  2 +-
 2 files changed, 16 insertions(+), 1 deletion(-)

Comments

Stewart Smith Aug. 4, 2017, 7:58 a.m. UTC | #1
Alistair Popple <alistair@popple.id.au> writes:
> It is common for xscom registers to only contain specific bit fields that
> need to be modified without altering the rest of the register. This adds a
> convenience function to perform xscom read-modify-write operations under a
> mask.
>
> Signed-off-by: Alistair Popple <alistair@popple.id.au>

Thanks, series merged to master as of 07937c792d3e028cf2eef68b5957813a5fddcbb9
diff mbox

Patch

diff --git a/hw/xscom.c b/hw/xscom.c
index a739b3c..ea3c3fb 100644
--- a/hw/xscom.c
+++ b/hw/xscom.c
@@ -577,6 +577,21 @@  int _xscom_write(uint32_t partid, uint64_t pcb_addr, uint64_t val, bool take_loc
 }
 opal_call(OPAL_XSCOM_WRITE, xscom_write, 3);
 
+/*
+ * Perform a xscom read-modify-write.
+ */
+int xscom_write_mask(uint32_t partid, uint64_t pcb_addr, uint64_t val, uint64_t mask)
+{
+	int rc;
+	uint64_t old_val;
+
+	rc = xscom_read(partid, pcb_addr, &old_val);
+	if (rc)
+		return rc;
+	val = (old_val & ~mask) | (val & mask);
+	return xscom_write(partid, pcb_addr, val);
+}
+
 int xscom_readme(uint64_t pcb_addr, uint64_t *val)
 {
 	return xscom_read(this_cpu()->chip_id, pcb_addr, val);
diff --git a/include/xscom.h b/include/xscom.h
index 743a47b..5a5d0b9 100644
--- a/include/xscom.h
+++ b/include/xscom.h
@@ -230,7 +230,7 @@  static inline int xscom_read(uint32_t partid, uint64_t pcb_addr, uint64_t *val)
 static inline int xscom_write(uint32_t partid, uint64_t pcb_addr, uint64_t val) {
 	return _xscom_write(partid, pcb_addr, val, true);
 }
-
+extern int xscom_write_mask(uint32_t partid, uint64_t pcb_addr, uint64_t val, uint64_t mask);
 
 /* This chip SCOM access */
 extern int xscom_readme(uint64_t pcb_addr, uint64_t *val);