Skip to contentSkip to conversation

hw/misc/macio/gpio.c: Add defines for register bits

PATCH Superseded BALATON Zoltan 2 participants 2 messages Feb 23, 2025 – Feb 24, 2025

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/misc/macio/gpio.c: Add defines for register bits

Add named constants for register bit values that should make it easier to understand what these mean.

---
 hw/misc/macio/gpio.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
hw/misc/macio/gpio.c +10 -7
index 4364afc84a..06be5a4f98 100644
@@ -34,6 +34,9 @@
 #include "qemu/module.h"
 #include "trace.h"
 
+#define OUT_DATA   1
+#define IN_DATA    2
+#define OUT_ENABLE 4
 
 void macio_set_gpio(MacIOGPIOState *s, uint32_t gpio, bool state)
 {
@@ -41,14 +44,14 @@ void macio_set_gpio(MacIOGPIOState *s, uint32_t gpio, bool state)
 
     trace_macio_set_gpio(gpio, state);
 
-    if (s->gpio_regs[gpio] & 4) {
+    if (s->gpio_regs[gpio] & OUT_ENABLE) {
         qemu_log_mask(LOG_GUEST_ERROR,
                       "GPIO: Setting GPIO %d while it's an output\n", gpio);
     }
 
-    new_reg = s->gpio_regs[gpio] & ~2;
+    new_reg = s->gpio_regs[gpio] & ~IN_DATA;
     if (state) {
-        new_reg |= 2;
+        new_reg |= IN_DATA;
     }
 
     if (new_reg == s->gpio_regs[gpio]) {
@@ -107,12 +110,12 @@ static void macio_gpio_write(void *opaque, hwaddr addr, uint64_t value,
 
     addr -= 8;
     if (addr < 36) {
-        value &= ~2;
+        value &= ~IN_DATA;
 
-        if (value & 4) {
-            ibit = (value & 1) << 1;
+        if (value & OUT_ENABLE) {
+            ibit = (value & OUT_DATA) << 1;
         } else {
-            ibit = s->gpio_regs[addr] & 2;
+            ibit = s->gpio_regs[addr] & IN_DATA;
         }
 
         s->gpio_regs[addr] = value | ibit;
Signature · 1 line
2.30.9
Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · BALATON Zoltan

Add named constants for register bit values that should make it easier to understand what these mean.

---
  hw/misc/macio/gpio.c | 17 ++++++++++-------
  1 file changed, 10 insertions(+), 7 deletions(-)
hw/misc/macio/gpio.c +0 -0
index 4364afc84a..06be5a4f98 100644

hw/misc/macio/gpio.c line 36

Quoted 3 lines
hw/misc/macio/gpio.c +0 -0
@@ -34,6 +34,9 @@
  #include "qemu/module.h"
  #include "trace.h"
 

Maybe use an enum and add a comment /* Register ... bits */, otherwise:

Quoted 15 lines
hw/misc/macio/gpio.c +4 -1
+#define OUT_DATA   1
+#define IN_DATA    2
+#define OUT_ENABLE 4
 
  void macio_set_gpio(MacIOGPIOState *s, uint32_t gpio, bool state)
  {
@@ -41,14 +44,14 @@ void macio_set_gpio(MacIOGPIOState *s, uint32_t gpio, bool state)
 
      trace_macio_set_gpio(gpio, state);
 
-    if (s->gpio_regs[gpio] & 4) {
+    if (s->gpio_regs[gpio] & OUT_ENABLE) {
          qemu_log_mask(LOG_GUEST_ERROR,
                        "GPIO: Setting GPIO %d while it's an output\n", gpio);
      }