qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Joe Komlodi <komlodi@google.com>
To: qemu-devel@nongnu.org
Cc: venture@google.com, komlodi@google.com, peter.maydell@linaro.org
Subject: [PATCH 12/16] hw/i3c/aspeed_i3c: Add controller resets
Date: Fri, 31 Mar 2023 01:01:27 +0000	[thread overview]
Message-ID: <20230331010131.1412571-13-komlodi@google.com> (raw)
In-Reply-To: <20230331010131.1412571-1-komlodi@google.com>

Adds behavior to the device reset register.

Signed-off-by: Joe Komlodi <komlodi@google.com>

Reviewed-by: Patrick Venture <venture@google.com>
Reviewed-by: Stephen Longfield <slongfield@google.com>
---
 hw/i3c/aspeed_i3c.c | 110 +++++++++++++++++++++++++++++++++++++++++---
 hw/i3c/trace-events |   1 +
 2 files changed, 104 insertions(+), 7 deletions(-)

diff --git a/hw/i3c/aspeed_i3c.c b/hw/i3c/aspeed_i3c.c
index 4c0c074012..19d766f074 100644
--- a/hw/i3c/aspeed_i3c.c
+++ b/hw/i3c/aspeed_i3c.c
@@ -938,6 +938,108 @@ static void aspeed_i3c_device_intr_force_w(AspeedI3CDevice *s, uint32_t val)
     aspeed_i3c_device_update_irq(s);
 }
 
+static void aspeed_i3c_device_cmd_queue_reset(AspeedI3CDevice *s)
+{
+    fifo32_reset(&s->cmd_queue);
+
+    ARRAY_FIELD_DP32(s->regs, QUEUE_STATUS_LEVEL, CMD_QUEUE_EMPTY_LOC,
+                     fifo32_num_free(&s->cmd_queue));
+    uint8_t empty_threshold = ARRAY_FIELD_EX32(s->regs, QUEUE_THLD_CTRL,
+                                               CMD_BUF_EMPTY_THLD);
+    if (fifo32_num_free(&s->cmd_queue) >= empty_threshold) {
+        ARRAY_FIELD_DP32(s->regs, INTR_STATUS, CMD_QUEUE_RDY, 1);
+        aspeed_i3c_device_update_irq(s);
+    };
+}
+
+static void aspeed_i3c_device_resp_queue_reset(AspeedI3CDevice *s)
+{
+    fifo32_reset(&s->resp_queue);
+
+    ARRAY_FIELD_DP32(s->regs, QUEUE_STATUS_LEVEL, RESP_BUF_BLR,
+                     fifo32_num_used(&s->resp_queue));
+    /*
+     * This interrupt will always be cleared because the threshold is a minimum
+     * of 1 and the queue size is 0.
+     */
+    ARRAY_FIELD_DP32(s->regs, INTR_STATUS, RESP_RDY, 0);
+    aspeed_i3c_device_update_irq(s);
+}
+
+static void aspeed_i3c_device_ibi_queue_reset(AspeedI3CDevice *s)
+{
+    fifo32_reset(&s->ibi_queue);
+
+    ARRAY_FIELD_DP32(s->regs, QUEUE_STATUS_LEVEL, IBI_BUF_BLR,
+                     fifo32_num_used(&s->resp_queue));
+    /*
+     * This interrupt will always be cleared because the threshold is a minimum
+     * of 1 and the queue size is 0.
+     */
+    ARRAY_FIELD_DP32(s->regs, INTR_STATUS, IBI_THLD, 0);
+    aspeed_i3c_device_update_irq(s);
+}
+
+static void aspeed_i3c_device_tx_queue_reset(AspeedI3CDevice *s)
+{
+    fifo32_reset(&s->tx_queue);
+
+    ARRAY_FIELD_DP32(s->regs, DATA_BUFFER_STATUS_LEVEL, TX_BUF_EMPTY_LOC,
+                     fifo32_num_free(&s->tx_queue));
+    /* TX buf is empty, so this interrupt will always be set. */
+    ARRAY_FIELD_DP32(s->regs, INTR_STATUS, TX_THLD, 1);
+    aspeed_i3c_device_update_irq(s);
+}
+
+static void aspeed_i3c_device_rx_queue_reset(AspeedI3CDevice *s)
+{
+    fifo32_reset(&s->rx_queue);
+
+    ARRAY_FIELD_DP32(s->regs, DATA_BUFFER_STATUS_LEVEL, RX_BUF_BLR,
+                     fifo32_num_used(&s->resp_queue));
+    /*
+     * This interrupt will always be cleared because the threshold is a minimum
+     * of 1 and the queue size is 0.
+     */
+    ARRAY_FIELD_DP32(s->regs, INTR_STATUS, RX_THLD, 0);
+    aspeed_i3c_device_update_irq(s);
+}
+
+static void aspeed_i3c_device_reset(DeviceState *dev)
+{
+    AspeedI3CDevice *s = ASPEED_I3C_DEVICE(dev);
+    trace_aspeed_i3c_device_reset(s->id);
+
+    memcpy(s->regs, ast2600_i3c_device_resets, sizeof(s->regs));
+    aspeed_i3c_device_cmd_queue_reset(s);
+    aspeed_i3c_device_resp_queue_reset(s);
+    aspeed_i3c_device_ibi_queue_reset(s);
+    aspeed_i3c_device_tx_queue_reset(s);
+    aspeed_i3c_device_rx_queue_reset(s);
+}
+
+static void aspeed_i3c_device_reset_ctrl_w(AspeedI3CDevice *s, uint32_t val)
+{
+    if (FIELD_EX32(val, RESET_CTRL, CORE_RESET)) {
+        aspeed_i3c_device_reset(DEVICE(s));
+    }
+    if (FIELD_EX32(val, RESET_CTRL, CMD_QUEUE_RESET)) {
+        aspeed_i3c_device_cmd_queue_reset(s);
+    }
+    if (FIELD_EX32(val, RESET_CTRL, RESP_QUEUE_RESET)) {
+        aspeed_i3c_device_resp_queue_reset(s);
+    }
+    if (FIELD_EX32(val, RESET_CTRL, TX_BUF_RESET)) {
+        aspeed_i3c_device_tx_queue_reset(s);
+    }
+    if (FIELD_EX32(val, RESET_CTRL, RX_BUF_RESET)) {
+        aspeed_i3c_device_rx_queue_reset(s);
+    }
+    if (FIELD_EX32(val, RESET_CTRL, IBI_QUEUE_RESET)) {
+        aspeed_i3c_device_ibi_queue_reset(s);
+    }
+}
+
 static uint32_t aspeed_i3c_device_pop_rx(AspeedI3CDevice *s)
 {
     if (fifo32_is_empty(&s->rx_queue)) {
@@ -1693,6 +1795,7 @@ static void aspeed_i3c_device_write(void *opaque, hwaddr offset,
         aspeed_i3c_device_cmd_queue_port_w(s, val32);
         break;
     case R_RESET_CTRL:
+        aspeed_i3c_device_reset_ctrl_w(s, val32);
         break;
     case R_INTR_STATUS:
         aspeed_i3c_device_intr_status_w(s, val32);
@@ -1728,13 +1831,6 @@ static const MemoryRegionOps aspeed_i3c_device_ops = {
     .endianness = DEVICE_LITTLE_ENDIAN,
 };
 
-static void aspeed_i3c_device_reset(DeviceState *dev)
-{
-    AspeedI3CDevice *s = ASPEED_I3C_DEVICE(dev);
-
-    memcpy(s->regs, ast2600_i3c_device_resets, sizeof(s->regs));
-}
-
 static void aspeed_i3c_device_realize(DeviceState *dev, Error **errp)
 {
     AspeedI3CDevice *s = ASPEED_I3C_DEVICE(dev);
diff --git a/hw/i3c/trace-events b/hw/i3c/trace-events
index 7a202b28c9..71e3059f8d 100644
--- a/hw/i3c/trace-events
+++ b/hw/i3c/trace-events
@@ -9,6 +9,7 @@ aspeed_i3c_device_send(uint32_t deviceid, uint32_t num_bytes) "I3C Dev[%u] send
 aspeed_i3c_device_recv_data(uint32_t deviceid, uint32_t num_bytes) "I3C Dev[%u] recv %" PRId32 " bytes from bus"
 aspeed_i3c_device_ibi_recv(uint32_t deviceid, uint8_t ibi_byte) "I3C Dev[%u] recv IBI byte 0x%" PRIx8
 aspeed_i3c_device_ibi_handle(uint32_t deviceid, uint8_t addr, bool rnw) "I3C Dev[%u] handle IBI from address 0x%" PRIx8 " RnW=%d"
+aspeed_i3c_device_reset(uint32_t deviceid) "I3C Dev[%u] reset"
 aspeed_i3c_device_pop_rx(uint32_t deviceid, uint32_t data) "I3C Dev[%u] pop 0x%" PRIx32 " from RX FIFO"
 aspeed_i3c_device_resp_queue_push(uint32_t deviceid, uint32_t data) "I3C Dev[%u] push 0x%" PRIx32 " to response queue"
 aspeed_i3c_device_push_tx(uint32_t deviceid, uint32_t data) "I3C Dev[%u] push 0x%" PRIx32 " to TX FIFO"
-- 
2.40.0.348.gf938b09366-goog



  parent reply	other threads:[~2023-03-31  1:05 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-31  1:01 [PATCH 00/16] i3c: aspeed: Add I3C support Joe Komlodi
2023-03-31  1:01 ` [PATCH 01/16] hw/misc/aspeed_i3c: Move to i3c directory Joe Komlodi
2023-03-31  1:01 ` [PATCH 02/16] hw/i3c: Add bus support Joe Komlodi
2023-03-31  1:01 ` [PATCH 03/16] hw/i3c/aspeed_i3c: Add more register fields Joe Komlodi
2023-03-31  1:01 ` [PATCH 04/16] hw/i3c/aspeed_i3c: Add more reset values Joe Komlodi
2023-03-31  1:01 ` [PATCH 05/16] hw/i3c/aspeed_i3c: Add register RO field masks Joe Komlodi
2023-03-31  1:01 ` [PATCH 06/16] hw/i3c/aspeed_i3c: Treat more registers as read-as-zero Joe Komlodi
2023-03-31  1:01 ` [PATCH 07/16] hw/i3c/aspeed_i3c: Use 32 bits on MMIO writes Joe Komlodi
2023-03-31  1:01 ` [PATCH 08/16] hw/i3c/aspeed_i3c: Add IRQ MMIO behavior Joe Komlodi
2023-03-31  1:01 ` [PATCH 09/16] hw/i3c/aspeed_i3c: Add data TX and RX Joe Komlodi
2023-04-03  8:45   ` Jeremy Kerr
2023-03-31  1:01 ` [PATCH 10/16] hw/i3c/aspeed_i3c: Add IBI handling Joe Komlodi
2023-04-03  3:08   ` Jeremy Kerr
2023-04-11  9:16   ` Jeremy Kerr
2023-04-12 23:13     ` Joe Komlodi
2023-03-31  1:01 ` [PATCH 11/16] hw/i3c/aspeed_i3c: Add ctrl MMIO handling Joe Komlodi
2023-03-31  1:01 ` Joe Komlodi [this message]
2023-03-31  1:01 ` [PATCH 13/16] hw/i3c: Add Mock target Joe Komlodi
2023-03-31  1:01 ` [PATCH 14/16] hw/i3c: remote_i3c: Add model Joe Komlodi
2023-04-03  6:13   ` Jeremy Kerr
2023-04-05  2:04     ` Joe Komlodi
2023-04-05  2:44       ` Jeremy Kerr
2023-03-31  1:01 ` [PATCH 15/16] qtest: remote_i3c: Add remote I3C qtest Joe Komlodi
2023-03-31  1:01 ` [PATCH 16/16] hw/i3c: Add hotplug support Joe Komlodi
2023-04-01 17:28 ` [PATCH 00/16] i3c: aspeed: Add I3C support Ben Dooks
2023-04-02  7:33   ` Cédric Le Goater
2023-04-02  8:11     ` Jeremy Kerr
2023-04-05  1:55       ` Joe Komlodi
2023-04-05  2:06         ` Jeremy Kerr
2023-04-05  2:30           ` Joel Stanley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230331010131.1412571-13-komlodi@google.com \
    --to=komlodi@google.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=venture@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).