qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hw/misc/macio/gpio.c: Add defines for register bits
@ 2025-02-23  0:14 BALATON Zoltan
  2025-02-24  9:23 ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 2+ messages in thread
From: BALATON Zoltan @ 2025-02-23  0:14 UTC (permalink / raw)
  To: qemu-devel, qemu-ppc; +Cc: Mark Cave-Ayland

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

Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
---
 hw/misc/macio/gpio.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/hw/misc/macio/gpio.c b/hw/misc/macio/gpio.c
index 4364afc84a..06be5a4f98 100644
--- a/hw/misc/macio/gpio.c
+++ b/hw/misc/macio/gpio.c
@@ -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;
-- 
2.30.9



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] hw/misc/macio/gpio.c: Add defines for register bits
  2025-02-23  0:14 [PATCH] hw/misc/macio/gpio.c: Add defines for register bits BALATON Zoltan
@ 2025-02-24  9:23 ` Philippe Mathieu-Daudé
  0 siblings, 0 replies; 2+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-02-24  9:23 UTC (permalink / raw)
  To: BALATON Zoltan, qemu-devel, qemu-ppc; +Cc: Mark Cave-Ayland

On 23/2/25 01:14, BALATON Zoltan wrote:
> Add named constants for register bit values that should make it easier
> to understand what these mean.
> 
> Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
> ---
>   hw/misc/macio/gpio.c | 17 ++++++++++-------
>   1 file changed, 10 insertions(+), 7 deletions(-)
> 
> diff --git a/hw/misc/macio/gpio.c b/hw/misc/macio/gpio.c
> index 4364afc84a..06be5a4f98 100644
> --- a/hw/misc/macio/gpio.c
> +++ b/hw/misc/macio/gpio.c
> @@ -34,6 +34,9 @@
>   #include "qemu/module.h"
>   #include "trace.h"
>   

Maybe use an enum and add a comment /* Register ... bits */, otherwise:
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>

> +#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);
>       }


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-02-24  9:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-23  0:14 [PATCH] hw/misc/macio/gpio.c: Add defines for register bits BALATON Zoltan
2025-02-24  9:23 ` Philippe Mathieu-Daudé

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).