From nobody Sat Nov 15 16:09:06 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1749773238; cv=none; d=zohomail.com; s=zohoarc; b=XorACCsCasM2OQXZ2HmQ+QMP0dl5SAsalBjs0U4xuBeUH4fNZOkAoLF0EDYpN8XvVquMYL7sTmqZDti8n9sslQwhdkZf35OVfE3VT/wvPye3JY2CFEsXj5sfhhKv9RWEcEnwCDMXptaGOKL4EWru/T1BfbUKXvVHT3eRbWm5cYQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749773238; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=d0QgfeILdUyMD1NSsyF9wqtByo57i/HsEw7CLoZHHwQ=; b=ZDLVnFUK6y8tFjbJdXQ5bAOcCX6u6g+REbx3wRY2prB06YWW9oAoQKhqpyjXHO2gIk/Ub0OvCTei5HY0wPBb7uvLVUmw22e0UL1xkzd9YCIdpqKcW+IuOF11sBXTJwgzKhfJhW/b50yrigCV1f9rqW0oFPYjg12VsFtjPOBjeic= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749773238280186.06104697571504; Thu, 12 Jun 2025 17:07:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPru7-0005lm-Tb; Thu, 12 Jun 2025 20:04:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3_WpLaAcKCkow0yx0pus00sxq.o0y2qy6-pq7qxz0zsz6.03s@flex--komlodi.bounces.google.com>) id 1uPru6-0005kz-A0 for qemu-devel@nongnu.org; Thu, 12 Jun 2025 20:04:18 -0400 Received: from mail-pg1-x549.google.com ([2607:f8b0:4864:20::549]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3_WpLaAcKCkow0yx0pus00sxq.o0y2qy6-pq7qxz0zsz6.03s@flex--komlodi.bounces.google.com>) id 1uPru4-0000WN-0x for qemu-devel@nongnu.org; Thu, 12 Jun 2025 20:04:18 -0400 Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-b2f103f6074so945371a12.3 for ; Thu, 12 Jun 2025 17:04:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1749773054; x=1750377854; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=d0QgfeILdUyMD1NSsyF9wqtByo57i/HsEw7CLoZHHwQ=; b=TWyNMfq/1D69OsTULtleaNAwWsYolubi5a914+SG7TjW4wh9edEf+nnkPLWknk3nzs tIWKUYOIKXGqWaE5nO+Ef8c58hFaIEqBk2olpxU67jjxLUwwfzfFC9FmlLpZOBXH1CNQ MMs4pFbSuN695SFvAHqEnzfsMwbEgtCur4p+qZk+EnTt2+rkW6wczhSlpH9s9I6rDAJq h4Afod+4t/+NE9oS0TH3pg6dpgbeFBtolgeSbdjFl67Qt+PpCp8g/7Ef8oiMRi5Nhplu GclNFWIWrq/hAV0oWQgKnv4YDZIg8hw7XGSsj4x1PY/JwKd3oxT4ckUGl4w8bqsWeGgd YB+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749773054; x=1750377854; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=d0QgfeILdUyMD1NSsyF9wqtByo57i/HsEw7CLoZHHwQ=; b=XPnpRsAqdO2e7sTQYOp9MEIMWDl4gJj6ujHEWf8XH27B8vXWe3Hr0dZ0PcSuvEiYiM P1cmXv3kTKFuk5LywN1DH9HZjy93Cr82g4s2FUaPCQPeSVzrJOm35FIspupzwIIk8qlo 2sT5IFrla7kT0tdXJwsAVJ2vQ5UcLhBDz/dfvCoxs/cA9rEYIDu5iJwqqLKLhfFFmAIW ijPGA/cm07lnpRmJl5fqKzcnpn/0zrPdaEpJdG7b0g9BUdtKyBOfEN3AA4Ah9jTlTDfA PufBH7Q1Q+ExTXeF0Sd8tdzTGneKpoSQa47KjVJElyAdDbiVwYZb5DpTF6EYo1AxuR3f JlhQ== X-Gm-Message-State: AOJu0YwFHmaMo9mqKm/eO8gYG7wMIwyTnOxH8VkekvglCcslaiOtUGgJ aqz409TH52vLdLgQav2LFTj2O9zhJvElQLMzcfJ+YX6NmchIp/0VdmjTyjaPA6T5ebMUEUwENno b+oaJ2PNTbUEdxOW2/h2Y910u+K2oCcAHf/tjQnUE+bSoy+tlhddEDF1MV9kNNt77RFIEe1WGYf iG74hv+wieLo2WH6QrhoQGaNv5HFa/BRVYM/r4jJZT X-Google-Smtp-Source: AGHT+IFkwbndRCus8AHEk0L4obEO+w7S4ETJu7WgtZ9eKEPgvmWf6hXEo3DwX2varqNhaoEwWKe9HsVNcJSR X-Received: from pgbfy15.prod.google.com ([2002:a05:6a02:2a8f:b0:b2e:c15e:3eb7]) (user=komlodi job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:394a:b0:21c:fa68:c33a with SMTP id adf61e73a8af0-21facc8e6f5mr1222482637.23.1749773053909; Thu, 12 Jun 2025 17:04:13 -0700 (PDT) Date: Fri, 13 Jun 2025 00:03:53 +0000 In-Reply-To: <20250613000411.1516521-1-komlodi@google.com> Mime-Version: 1.0 References: <20250613000411.1516521-1-komlodi@google.com> X-Mailer: git-send-email 2.50.0.rc1.591.g9c95f17f64-goog Message-ID: <20250613000411.1516521-2-komlodi@google.com> Subject: [PATCH 01/19] hw/misc/aspeed_i3c: Move to i3c directory From: Joe Komlodi To: qemu-devel@nongnu.org Cc: venture@google.com, komlodi@google.com, clg@kaod.org, peter.maydell@linaro.org, steven_lee@aspeedtech.com, leetroy@gmail.com, jamin_lin@aspeedtech.com, andrew@codeconstruct.com.au, joel@jms.id.au, qemu-arm@nongnu.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::549; envelope-from=3_WpLaAcKCkow0yx0pus00sxq.o0y2qy6-pq7qxz0zsz6.03s@flex--komlodi.bounces.google.com; helo=mail-pg1-x549.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1749773238988116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Moves the Aspeed I3C model and traces into hw/i3c and creates I3C build files. Signed-off-by: Joe Komlodi Reviewed-by: Patrick Venture Reviewed-by: Titus Rwantare Reviewed-by: C=C3=A9dric Le Goater --- hw/Kconfig | 1 + hw/arm/Kconfig | 1 + hw/i3c/Kconfig | 2 ++ hw/{misc =3D> i3c}/aspeed_i3c.c | 2 +- hw/i3c/meson.build | 3 +++ hw/i3c/trace-events | 7 +++++++ hw/i3c/trace.h | 2 ++ hw/meson.build | 1 + hw/misc/meson.build | 1 - hw/misc/trace-events | 6 ------ include/hw/arm/aspeed_soc.h | 2 +- include/hw/{misc =3D> i3c}/aspeed_i3c.h | 0 meson.build | 1 + 13 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 hw/i3c/Kconfig rename hw/{misc =3D> i3c}/aspeed_i3c.c (99%) create mode 100644 hw/i3c/meson.build create mode 100644 hw/i3c/trace-events create mode 100644 hw/i3c/trace.h rename include/hw/{misc =3D> i3c}/aspeed_i3c.h (100%) diff --git a/hw/Kconfig b/hw/Kconfig index 9a86a6a28a..61b8b2a142 100644 --- a/hw/Kconfig +++ b/hw/Kconfig @@ -13,6 +13,7 @@ source fsi/Kconfig source gpio/Kconfig source hyperv/Kconfig source i2c/Kconfig +source i3c/Kconfig source ide/Kconfig source input/Kconfig source intc/Kconfig diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig index f543d944c3..427d0f0271 100644 --- a/hw/arm/Kconfig +++ b/hw/arm/Kconfig @@ -530,6 +530,7 @@ config ASPEED_SOC select DS1338 select FTGMAC100 select I2C + select I3C select DPS310 select PCA9552 select SERIAL_MM diff --git a/hw/i3c/Kconfig b/hw/i3c/Kconfig new file mode 100644 index 0000000000..e07fe445c6 --- /dev/null +++ b/hw/i3c/Kconfig @@ -0,0 +1,2 @@ +config I3C + bool diff --git a/hw/misc/aspeed_i3c.c b/hw/i3c/aspeed_i3c.c similarity index 99% rename from hw/misc/aspeed_i3c.c rename to hw/i3c/aspeed_i3c.c index 3bef1c84dd..e56822f928 100644 --- a/hw/misc/aspeed_i3c.c +++ b/hw/i3c/aspeed_i3c.c @@ -10,7 +10,7 @@ #include "qemu/osdep.h" #include "qemu/log.h" #include "qemu/error-report.h" -#include "hw/misc/aspeed_i3c.h" +#include "hw/i3c/aspeed_i3c.h" #include "hw/registerfields.h" #include "hw/qdev-properties.h" #include "qapi/error.h" diff --git a/hw/i3c/meson.build b/hw/i3c/meson.build new file mode 100644 index 0000000000..ebf20325cb --- /dev/null +++ b/hw/i3c/meson.build @@ -0,0 +1,3 @@ +i3c_ss =3D ss.source_set() +i3c_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_i3c.c')) +system_ss.add_all(when: 'CONFIG_I3C', if_true: i3c_ss) diff --git a/hw/i3c/trace-events b/hw/i3c/trace-events new file mode 100644 index 0000000000..3ead84eb45 --- /dev/null +++ b/hw/i3c/trace-events @@ -0,0 +1,7 @@ +# See docs/devel/tracing.rst for syntax documentation. + +# aspeed_i3c.c +aspeed_i3c_read(uint64_t offset, uint64_t data) "I3C read: offset 0x%" PRI= x64 " data 0x%" PRIx64 +aspeed_i3c_write(uint64_t offset, uint64_t data) "I3C write: offset 0x%" P= RIx64 " data 0x%" PRIx64 +aspeed_i3c_device_read(uint32_t deviceid, uint64_t offset, uint64_t data) = "I3C Dev[%u] read: offset 0x%" PRIx64 " data 0x%" PRIx64 +aspeed_i3c_device_write(uint32_t deviceid, uint64_t offset, uint64_t data)= "I3C Dev[%u] write: offset 0x%" PRIx64 " data 0x%" PRIx64 diff --git a/hw/i3c/trace.h b/hw/i3c/trace.h new file mode 100644 index 0000000000..1e0c4eadf0 --- /dev/null +++ b/hw/i3c/trace.h @@ -0,0 +1,2 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#include "trace/trace-hw_i3c.h" diff --git a/hw/meson.build b/hw/meson.build index b91f761fe0..31786f03d0 100644 --- a/hw/meson.build +++ b/hw/meson.build @@ -12,6 +12,7 @@ subdir('dma') subdir('gpio') subdir('hyperv') subdir('i2c') +subdir('i3c') subdir('ide') subdir('input') subdir('intc') diff --git a/hw/misc/meson.build b/hw/misc/meson.build index 6d47de482c..4a41716625 100644 --- a/hw/misc/meson.build +++ b/hw/misc/meson.build @@ -130,7 +130,6 @@ system_ss.add(when: 'CONFIG_PVPANIC_MMIO', if_true: fil= es('pvpanic-mmio.c')) system_ss.add(when: 'CONFIG_AUX', if_true: files('auxbus.c')) system_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files( 'aspeed_hace.c', - 'aspeed_i3c.c', 'aspeed_lpc.c', 'aspeed_scu.c', 'aspeed_sbc.c', diff --git a/hw/misc/trace-events b/hw/misc/trace-events index e3f64c0ff6..f70459b3b7 100644 --- a/hw/misc/trace-events +++ b/hw/misc/trace-events @@ -287,12 +287,6 @@ armsse_mhu_write(uint64_t offset, uint64_t data, unsig= ned size) "SSE-200 MHU wri # aspeed_xdma.c aspeed_xdma_write(uint64_t offset, uint64_t data) "XDMA write: offset 0x%"= PRIx64 " data 0x%" PRIx64 =20 -# aspeed_i3c.c -aspeed_i3c_read(uint64_t offset, uint64_t data) "I3C read: offset 0x%" PRI= x64 " data 0x%" PRIx64 -aspeed_i3c_write(uint64_t offset, uint64_t data) "I3C write: offset 0x%" P= RIx64 " data 0x%" PRIx64 -aspeed_i3c_device_read(uint32_t deviceid, uint64_t offset, uint64_t data) = "I3C Dev[%u] read: offset 0x%" PRIx64 " data 0x%" PRIx64 -aspeed_i3c_device_write(uint32_t deviceid, uint64_t offset, uint64_t data)= "I3C Dev[%u] write: offset 0x%" PRIx64 " data 0x%" PRIx64 - # aspeed_sdmc.c aspeed_sdmc_write(uint64_t reg, uint64_t data) "reg @0x%" PRIx64 " data: 0= x%" PRIx64 aspeed_sdmc_read(uint64_t reg, uint64_t data) "reg @0x%" PRIx64 " data: 0x= %" PRIx64 diff --git a/include/hw/arm/aspeed_soc.h b/include/hw/arm/aspeed_soc.h index 217ef0eafd..07265f26cf 100644 --- a/include/hw/arm/aspeed_soc.h +++ b/include/hw/arm/aspeed_soc.h @@ -23,7 +23,7 @@ #include "hw/timer/aspeed_timer.h" #include "hw/rtc/aspeed_rtc.h" #include "hw/i2c/aspeed_i2c.h" -#include "hw/misc/aspeed_i3c.h" +#include "hw/i3c/aspeed_i3c.h" #include "hw/ssi/aspeed_smc.h" #include "hw/misc/aspeed_hace.h" #include "hw/misc/aspeed_sbc.h" diff --git a/include/hw/misc/aspeed_i3c.h b/include/hw/i3c/aspeed_i3c.h similarity index 100% rename from include/hw/misc/aspeed_i3c.h rename to include/hw/i3c/aspeed_i3c.h diff --git a/meson.build b/meson.build index 34729c2a3d..186effb84f 100644 --- a/meson.build +++ b/meson.build @@ -3651,6 +3651,7 @@ if have_system 'hw/fsi', 'hw/hyperv', 'hw/i2c', + 'hw/i3c', 'hw/i386', 'hw/i386/xen', 'hw/i386/kvm', --=20 2.50.0.rc1.591.g9c95f17f64-goog From nobody Sat Nov 15 16:09:06 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1749773173; cv=none; d=zohomail.com; s=zohoarc; b=HZGVKzo1pjpXVvmPioahQob0sRudllPKCNv+0oVje5fVHDlqCO95jM0nWOtYM8M5enjLPwnoJqpivvZTJF8S83f1vLeSlH3uKkCK+hZx7NzBJlvJ6qbysvf4sdt4I/TnJnMlVzHZJk42N04WeiqCwwZVRLUGB/vsq1rUIo+9ydk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749773173; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=PIg7sL/WCpdczVnw7x/YjYUgS2IwjNMgdqFMSAfzWxE=; b=fldK1Q67OMzt3ey8RGteCIRZ/8VSXhdnLdNPoEiqRdVptKQZlXtHW9mGLaUY6fug/9szVWUsmsKw36EQpxlXQlwcJsNgvDUrt3AzvEcndcRwwxmWw1pQQXHCJJsYcMYx8vS0WzMWMkld5lhtKFu4jN+mtuNITv+p18+9VoycP9c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749773173701650.4426617247963; Thu, 12 Jun 2025 17:06:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPruA-0005mx-49; Thu, 12 Jun 2025 20:04:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3_2pLaAcKCkwy20z2rwu22uzs.q204s08-rs9sz121u18.25u@flex--komlodi.bounces.google.com>) id 1uPru8-0005lp-I8 for qemu-devel@nongnu.org; Thu, 12 Jun 2025 20:04:20 -0400 Received: from mail-pl1-x64a.google.com ([2607:f8b0:4864:20::64a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3_2pLaAcKCkwy20z2rwu22uzs.q204s08-rs9sz121u18.25u@flex--komlodi.bounces.google.com>) id 1uPru5-0000Wc-0d for qemu-devel@nongnu.org; Thu, 12 Jun 2025 20:04:20 -0400 Received: by mail-pl1-x64a.google.com with SMTP id d9443c01a7336-235f6b829cfso12653715ad.2 for ; Thu, 12 Jun 2025 17:04:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1749773055; x=1750377855; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=PIg7sL/WCpdczVnw7x/YjYUgS2IwjNMgdqFMSAfzWxE=; b=xAbeY0Ofl9SdfI9sPELCdlvcoMzO4eENNgEUz5LE8IbsKtcfl9OHV04foB6dZww+lE rhg77Nv85n7sz7psRw8fLLkltLXhJbCrZ5Bk7gMCkdyY5B/7VgbP5EPIRXZBTL5lexK+ iRL1RYaVXGW1JskutkJVXSi6JweWIzd0kkO3rZxUyguMCRCceyntMYnA//XHYbAm+J78 ZzDJBowC2/SuMFE1i3/9XG/iGxJFlOVq9CZuLkdv04SHB+xRDtbv9xP6//d866ZFDd77 cQLLzmVBoZhIpJDSAoM8XQoAEa2F5ycgNF2JkDMAD1u9TES9X1PNe+GS+hW5yM4VXK/g iiDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749773055; x=1750377855; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=PIg7sL/WCpdczVnw7x/YjYUgS2IwjNMgdqFMSAfzWxE=; b=Si3PE6+TshSDVb64PASoVf7HIfnjF//odOtm7FpCVFwq97wXyoFjxVDL+c9dgwyaaw JsRKa9zek9lnp1MfYKEuWZS7SYsSu3Beg/cGiW9Tpth70V35YPdDgomJmrEK8lR3Conu EFj/P8kcl5Cty2hyPa7ESOxaDNXuZAfLKvj2DzQ9iuMqSIDmySya/eY074SNmLG1eL3i FSvUzaW+EkGT/Aj1rINbihQrwwCvxZTGn8kuO9EeP7dzzOvEozVXhuUsVIlyBZbhPadC /Awv7dXxi/v+he0tdaeTkpSs4ZcIZ14ip3NbqNG8Xmv7H8A2KMCnyDo63D/8BS44JBg7 fpfw== X-Gm-Message-State: AOJu0YwI7pjo+VzKxbE6C6QVl6TUlnTL5ypt+NpDzFOcijvFviu/bBST G61qQXGEzvV+mCRkIyYS569SI2lMmdBuqGQS0idobfjH8hLnjcpzNV1Vz3UUcn0oxkVpSCI8DC/ FNkEe+XssyTSvq2gByffRnO9wklnSCsYFDrbZTVcZ7XfvvAZ5D4ISydGB6pF0zZ+lwaE6rJ6l9g tVE1QYpTCDc2KCp6Of3Bdza+Oo7ZrMkS651zOjgrwv X-Google-Smtp-Source: AGHT+IEmfoAAJdKE1zVCsJwM5L5eQMSYsPJZ+1L1QpOTzRQUQ7jKlyoQiAJmX6QITeRn0Z2hNN+MqNZIPjmY X-Received: from pgar23.prod.google.com ([2002:a05:6a02:2e97:b0:b2c:4a89:4b36]) (user=komlodi job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:ce82:b0:235:eca0:12d4 with SMTP id d9443c01a7336-2365de39ccdmr14360075ad.53.1749773055414; Thu, 12 Jun 2025 17:04:15 -0700 (PDT) Date: Fri, 13 Jun 2025 00:03:54 +0000 In-Reply-To: <20250613000411.1516521-1-komlodi@google.com> Mime-Version: 1.0 References: <20250613000411.1516521-1-komlodi@google.com> X-Mailer: git-send-email 2.50.0.rc1.591.g9c95f17f64-goog Message-ID: <20250613000411.1516521-3-komlodi@google.com> Subject: [PATCH 02/19] hw/i3c: Add bus support From: Joe Komlodi To: qemu-devel@nongnu.org Cc: venture@google.com, komlodi@google.com, clg@kaod.org, peter.maydell@linaro.org, steven_lee@aspeedtech.com, leetroy@gmail.com, jamin_lin@aspeedtech.com, andrew@codeconstruct.com.au, joel@jms.id.au, qemu-arm@nongnu.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::64a; envelope-from=3_2pLaAcKCkwy20z2rwu22uzs.q204s08-rs9sz121u18.25u@flex--komlodi.bounces.google.com; helo=mail-pl1-x64a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1749773174092116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Adds an I3C bus and a target class. The bus supports: - I3C data transmission and reception - CCCs (including ENTDAA) - IBIs - legacy I2C transactions General usage of the bus is similar to I2C. Users are expected to initialize a bus via i3c_init_bus, and use the bus returned from the init function to do transactions on the bus. In order to handle IBIs, the controller provides callbacks to handle receiving an IBI from a target, receiving (optional) additional IBI bytes from a target, and handling when a target is done with its IBI. Similarly, target creation is done via i3c_target_create_simple and users use the provided I3CTarget to handle transactions. The target has functions provided that it can use to invoke an IBI and send additional bytes. Along with the send, recv, and event callbacks that are expected of an I3C target, which are similar to I2C, there is a separate callback for CCC handling. This is to help encapsulate CCC handling and keep it separate from target-specific read/write functionality. To avoid repition for required CCCs among I3C targets, there is some class-level CCC handling added. The CCC is then passed to the target in case it needs to handle it in some way. Signed-off-by: Joe Komlodi Reviewed-by: Patrick Venture Reviewed-by: Titus Rwantare --- hw/i3c/core.c | 652 +++++++++++++++++++++++++++++++++++++++++++ hw/i3c/meson.build | 1 + hw/i3c/trace-events | 16 ++ include/hw/i3c/i3c.h | 277 ++++++++++++++++++ 4 files changed, 946 insertions(+) create mode 100644 hw/i3c/core.c create mode 100644 include/hw/i3c/i3c.h diff --git a/hw/i3c/core.c b/hw/i3c/core.c new file mode 100644 index 0000000000..117d9da7ac --- /dev/null +++ b/hw/i3c/core.c @@ -0,0 +1,652 @@ +/* + * QEMU I3C bus interface. + * + * Copyright 2025 Google LLC + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "qapi/error.h" +#include "trace.h" +#include "hw/i3c/i3c.h" +#include "hw/qdev-properties.h" + +/* + * In test mode (enabled by ENTTM CCC) we're supposed to send a random PID + * during ENTDAA, so we'll just send "QEMU". + */ +#define TEST_MODE_PROVISIONED_ID 0x0000554d4551ULL + +static const Property i3c_props[] =3D { + DEFINE_PROP_UINT8("static-address", struct I3CTarget, static_address, = 0), + DEFINE_PROP_UINT8("dcr", struct I3CTarget, dcr, 0), + DEFINE_PROP_UINT8("bcr", struct I3CTarget, bcr, 0), + DEFINE_PROP_UINT64("pid", struct I3CTarget, pid, 0), +}; + +static const TypeInfo i3c_bus_info =3D { + .name =3D TYPE_I3C_BUS, + .parent =3D TYPE_BUS, + .instance_size =3D sizeof(I3CBus), + .class_size =3D sizeof(I3CBusClass), +}; + +I3CBus *i3c_init_bus(DeviceState *parent, const char *name) +{ + return i3c_init_bus_type(TYPE_I3C_BUS, parent, name); +} + +I3CBus *i3c_init_bus_type(const char *type, DeviceState *parent, + const char *name) +{ + I3CBus *bus; + + bus =3D I3C_BUS(qbus_new(type, parent, name)); + QLIST_INIT(&bus->current_devs); + bus->broadcast =3D false; + bus->in_entdaa =3D false; + bus->in_ccc =3D false; + + /* I2C init. */ + g_autofree gchar *i2c_bus_name =3D g_strdup_printf("%s-legacy-i2c", na= me); + bus->i2c_bus =3D i2c_init_bus(parent, i2c_bus_name); + + return bus; +} + +bool i3c_bus_busy(I3CBus *bus) +{ + return !QLIST_EMPTY(&bus->current_devs); +} + +static bool i3c_target_match(I3CTarget *candidate, uint8_t address, + bool is_recv, bool broadcast, bool in_entdaa) +{ + /* Once a target has a dynamic address, it only responds to that. */ + uint8_t targ_addr =3D candidate->address ? candidate->address : + candidate->static_address; + + if (in_entdaa) { + if (address !=3D I3C_BROADCAST) { + g_autofree char *path =3D + object_get_canonical_path(OBJECT(candidate)); + qemu_log_mask(LOG_GUEST_ERROR, "%s: I3C Address 0x%.2x sent du= ring " + "ENTDAA instead of a broadcast address\n", + path, address); + return false; + } + + /* + * Targets should only ACK ENTDAA broadcasts if they have no dynam= ic + * address. + */ + return candidate->address =3D=3D 0; + } + + /* Return if our addresses match, or if it's a broadcast. */ + return targ_addr =3D=3D address || broadcast; +} + +bool i3c_target_match_and_add(I3CBus *bus, I3CTarget *target, uint8_t addr= ess, + enum I3CEvent event) +{ + I3CTargetClass *tc =3D I3C_TARGET_GET_CLASS(target); + bool matched =3D tc->target_match(target, address, event =3D=3D I3C_ST= ART_RECV, + bus->broadcast, bus->in_entdaa); + + if (matched) { + I3CNode *node =3D g_new(struct I3CNode, 1); + node->target =3D target; + QLIST_INSERT_HEAD(&bus->current_devs, node, next); + } + return matched; +} + +bool i3c_scan_bus(I3CBus *bus, uint8_t address, enum I3CEvent event) +{ + BusChild *child; + I3CNode *node, *next; + + /* Clear out any devices from a previous (re-)START. */ + QLIST_FOREACH_SAFE(node, &bus->current_devs, next, next) { + QLIST_REMOVE(node, next); + g_free(node); + } + + QTAILQ_FOREACH(child, &bus->qbus.children, sibling) { + DeviceState *qdev =3D child->child; + I3CTarget *target =3D I3C_TARGET(qdev); + + if (i3c_target_match_and_add(bus, target, address, event)) { + return true; + } + } + + /* No one on the bus could respond. */ + return false; +} + +/* Class-level event handling, since we do some CCCs at the class level. */ +static int i3c_target_event(I3CTarget *t, enum I3CEvent event) +{ + I3CTargetClass *tc =3D I3C_TARGET_GET_CLASS(t); + trace_i3c_target_event(t->address, event); + + if (event =3D=3D I3C_STOP) { + t->curr_ccc =3D 0; + t->ccc_byte_offset =3D 0; + t->in_ccc =3D false; + } + return tc->event(t, event); +} + +/* + * Sends a START or repeated START and the address for an I3C transaction. + * + * This function returns 0 if a device on the bus was able to respond to t= he + * address, and non-zero otherwise. + * A non-zero return represents a NACK. + */ +static int i3c_do_start_transfer(I3CBus *bus, uint8_t address, + enum I3CEvent event) +{ + I3CTargetClass *tc; + I3CNode *node; + + if (address =3D=3D I3C_BROADCAST) { + bus->broadcast =3D true; + /* If we're not in ENTDAA, a broadcast is the start of a new CCC. = */ + if (!bus->in_entdaa) { + bus->in_ccc =3D false; + } + } else { + bus->broadcast =3D false; + } + + /* No one responded to the address, NACK it. */ + if (!i3c_scan_bus(bus, address, event)) { + return -1; + } + + QLIST_FOREACH(node, &bus->current_devs, next) { + I3CTarget *t =3D node->target; + + tc =3D I3C_TARGET_GET_CLASS(t); + if (tc->event) { + int rv =3D i3c_target_event(t, event); + if (rv && !bus->broadcast) { + return rv; + } + } + } + + return 0; +} + +int i3c_start_transfer(I3CBus *bus, uint8_t address, bool is_recv) +{ + trace_i3c_start_transfer(address, is_recv); + return i3c_do_start_transfer(bus, address, is_recv + ? I3C_START_RECV + : I3C_START_SEND); +} + +int i3c_start_recv(I3CBus *bus, uint8_t address) +{ + trace_i3c_start_transfer(address, true); + return i3c_do_start_transfer(bus, address, I3C_START_RECV); +} + +int i3c_start_send(I3CBus *bus, uint8_t address) +{ + trace_i3c_start_transfer(address, false); + return i3c_do_start_transfer(bus, address, I3C_START_SEND); +} + +void i3c_end_transfer(I3CBus *bus) +{ + I3CTargetClass *tc; + I3CNode *node, *next; + + trace_i3c_end_transfer(); + + /* + * If we're in ENTDAA, we need to notify all devices when ENTDAA is do= ne. + * This is because everyone initially participates due to the broadcas= t, + * but gradually drops out as they get assigned addresses. + * Since the current_devs list only stores who's currently participati= ng, + * and not everyone who previously participated, we send the STOP to a= ll + * children. + */ + if (bus->in_entdaa) { + BusChild *child; + + QTAILQ_FOREACH(child, &bus->qbus.children, sibling) { + DeviceState *qdev =3D child->child; + I3CTarget *t =3D I3C_TARGET(qdev); + tc =3D I3C_TARGET_GET_CLASS(t); + if (tc->event) { + i3c_target_event(t, I3C_STOP); + } + } + } else { + QLIST_FOREACH_SAFE(node, &bus->current_devs, next, next) { + I3CTarget *t =3D node->target; + tc =3D I3C_TARGET_GET_CLASS(t); + if (tc->event) { + i3c_target_event(t, I3C_STOP); + } + QLIST_REMOVE(node, next); + g_free(node); + } + } + bus->broadcast =3D false; + bus->in_entdaa =3D false; + bus->in_ccc =3D false; +} + +/* + * Any CCCs that are universal across all I3C devices should be handled he= re. + * Once they're handled, we pass the CCC up to the I3C target to do anythi= ng + * else it may want with the bytes. + */ +static int i3c_target_handle_ccc_write(I3CTarget *t, const uint8_t *data, + uint32_t num_to_send, uint32_t *num= _sent) +{ + I3CTargetClass *tc =3D I3C_TARGET_GET_CLASS(t); + *num_sent =3D 0; + + /* Is this the start of a new CCC? */ + if (!t->in_ccc) { + t->curr_ccc =3D *data; + t->in_ccc =3D true; + *num_sent =3D 1; + trace_i3c_target_handle_ccc(t->address, t->curr_ccc); + } + + switch (t->curr_ccc) { + case I3C_CCC_ENTDAA: + /* + * This is the last byte of ENTDAA, the controller is assigning us= an + * address. + */ + if (t->ccc_byte_offset =3D=3D 8) { + t->address =3D *data; + t->in_ccc =3D false; + t->curr_ccc =3D 0; + t->ccc_byte_offset =3D 0; + *num_sent =3D 1; + } + break; + case I3C_CCCD_SETDASA: + t->address =3D t->static_address; + break; + case I3C_CCC_SETAASA: + t->address =3D t->static_address; + break; + case I3C_CCC_RSTDAA: + t->address =3D 0; + break; + case I3C_CCCD_SETNEWDA: + /* If this isn't the CCC byte, it's our new address. */ + if (*num_sent =3D=3D 0) { + t->address =3D *data; + *num_sent =3D 1; + } + break; + case I3C_CCC_ENTTM: + /* + * If there are still more to look at, the next byte is the test m= ode + * byte. + */ + if (*num_sent !=3D num_to_send) { + /* Enter test mode if the byte is non-zero. Otherwise exit. */ + t->in_test_mode =3D !!data[*num_sent]; + ++*num_sent; + } + break; + /* Ignore other CCCs it's better to handle on a device-by-device basis= . */ + default: + break; + } + return tc->handle_ccc_write(t, data, num_to_send, num_sent); +} + +int i3c_send_byte(I3CBus *bus, uint8_t data) +{ + /* + * Ignored, the caller can determine how many were sent based on if th= is was + * ACKed/NACKed. + */ + uint32_t num_sent; + return i3c_send(bus, &data, 1, &num_sent); +} + +int i3c_send(I3CBus *bus, const uint8_t *data, uint32_t num_to_send, + uint32_t *num_sent) +{ + I3CTargetClass *tc; + I3CTarget *t; + I3CNode *node; + int ret =3D 0; + + /* If this message is a broadcast and no CCC has been found, grab it. = */ + if (bus->broadcast && !bus->in_ccc) { + bus->ccc =3D *data; + bus->in_ccc =3D true; + /* + * We need to keep track if we're currently in ENTDAA. + * On any other CCC, the CCC is over on a RESTART or STOP, but ENT= DAA + * is only over on a STOP. + */ + if (bus->ccc =3D=3D I3C_CCC_ENTDAA) { + bus->in_entdaa =3D true; + } + } + + QLIST_FOREACH(node, &bus->current_devs, next) { + t =3D node->target; + tc =3D I3C_TARGET_GET_CLASS(t); + if (bus->in_ccc) { + if (!tc->handle_ccc_write) { + ret =3D -1; + continue; + } + ret =3D i3c_target_handle_ccc_write(t, data, num_to_send, num_= sent); + /* Targets should only NACK on a direct CCC. */ + if (ret && !CCC_IS_DIRECT(bus->ccc)) { + ret =3D 0; + } + } else { + if (tc->send) { + ret =3D ret || tc->send(t, data, num_to_send, num_sent); + } else { + ret =3D -1; + } + } + } + + trace_i3c_send(*num_sent, num_to_send, ret =3D=3D 0); + + return ret ? -1 : 0; +} + +static int i3c_target_handle_ccc_read(I3CTarget *t, uint8_t *data, + uint32_t num_to_read, uint32_t *num_= read) +{ + I3CTargetClass *tc =3D I3C_TARGET_GET_CLASS(t); + uint8_t read_count =3D 0; + uint64_t pid; + + switch (t->curr_ccc) { + case I3C_CCC_ENTDAA: + if (t->in_test_mode) { + pid =3D TEST_MODE_PROVISIONED_ID; + } else { + pid =3D t->pid; + } + /* Return the 6-byte PID, followed by BCR then DCR. */ + while (t->ccc_byte_offset < 6) { + if (read_count >=3D num_to_read) { + break; + } + data[read_count] =3D (pid >> (t->ccc_byte_offset * 8)) & 0xff; + t->ccc_byte_offset++; + read_count++; + } + if (read_count < num_to_read) { + data[read_count] =3D t->bcr; + t->ccc_byte_offset++; + read_count++; + } + if (read_count < num_to_read) { + data[read_count] =3D t->dcr; + t->ccc_byte_offset++; + read_count++; + } + *num_read =3D read_count; + break; + case I3C_CCCD_GETPID: + while (t->ccc_byte_offset < 6) { + if (read_count >=3D num_to_read) { + break; + } + data[read_count] =3D (t->pid >> (t->ccc_byte_offset * 8)) & 0x= ff; + t->ccc_byte_offset++; + read_count++; + } + *num_read =3D read_count; + break; + case I3C_CCCD_GETBCR: + *data =3D t->bcr; + *num_read =3D 1; + break; + case I3C_CCCD_GETDCR: + *data =3D t->dcr; + *num_read =3D 1; + break; + default: + /* Unhandled on the I3CTarget class level. */ + break; + } + + return tc->handle_ccc_read(t, data, num_to_read, num_read); +} + +int i3c_recv_byte(I3CBus *bus, uint8_t *data) +{ + /* + * Ignored, the caller can determine how many bytes were read based o= n if + * this is ACKed/NACKed. + */ + uint32_t num_read; + return i3c_recv(bus, data, 1, &num_read); +} + +int i3c_recv(I3CBus *bus, uint8_t *data, uint32_t num_to_read, + uint32_t *num_read) +{ + int ret =3D 0; + I3CTargetClass *tc; + I3CTarget *t; + + *data =3D 0xff; + if (!QLIST_EMPTY(&bus->current_devs)) { + tc =3D I3C_TARGET_GET_CLASS(QLIST_FIRST(&bus->current_devs)->targe= t); + t =3D QLIST_FIRST(&bus->current_devs)->target; + if (bus->in_ccc) { + if (!tc->handle_ccc_read) { + return -1; + } + ret =3D i3c_target_handle_ccc_read(t, data, num_to_read, num_r= ead); + } else { + if (tc->recv) { + /* + * Targets cannot NACK on a direct transfer, so the data + * is returned directly. + */ + *num_read =3D tc->recv(t, data, num_to_read); + } + } + } + + trace_i3c_recv(*num_read, num_to_read, ret =3D=3D 0); + + return ret; +} + +void i3c_nack(I3CBus *bus) +{ + I3CTargetClass *tc; + I3CNode *node; + + if (QLIST_EMPTY(&bus->current_devs)) { + return; + } + + QLIST_FOREACH(node, &bus->current_devs, next) { + tc =3D I3C_TARGET_GET_CLASS(node->target); + if (tc->event) { + i3c_target_event(node->target, I3C_NACK); + } + } +} + +int i3c_target_send_ibi(I3CTarget *t, uint8_t addr, bool is_recv) +{ + I3CBus *bus =3D I3C_BUS(t->qdev.parent_bus); + I3CBusClass *bc =3D I3C_BUS_GET_CLASS(bus); + trace_i3c_target_send_ibi(addr, is_recv); + return bc->ibi_handle(bus, addr, is_recv); +} + +int i3c_target_send_ibi_bytes(I3CTarget *t, uint8_t data) +{ + I3CBus *bus =3D I3C_BUS(t->qdev.parent_bus); + I3CBusClass *bc =3D I3C_BUS_GET_CLASS(bus); + trace_i3c_target_send_ibi_bytes(data); + return bc->ibi_recv(bus, data); +} + +int i3c_target_ibi_finish(I3CTarget *t, uint8_t data) +{ + I3CBus *bus =3D I3C_BUS(t->qdev.parent_bus); + I3CBusClass *bc =3D I3C_BUS_GET_CLASS(bus); + trace_i3c_target_ibi_finish(); + return bc->ibi_finish(bus); +} + +static bool i3c_addr_is_rsvd(uint8_t addr) +{ + const bool is_rsvd[255] =3D { + [0x00] =3D true, + [0x01] =3D true, + [0x02] =3D true, + [0x3e] =3D true, + [0x5e] =3D true, + [0x6e] =3D true, + [0x76] =3D true, + [0x7a] =3D true, + [0x7c] =3D true, + [0x7e] =3D true, + [0x7f] =3D true, + }; + + return is_rsvd[addr]; +} + +I3CTarget *i3c_target_new(const char *name, uint8_t addr, uint8_t dcr, + uint8_t bcr, uint64_t pid) +{ + DeviceState *dev; + + dev =3D qdev_new(name); + qdev_prop_set_uint8(dev, "static-address", addr); + qdev_prop_set_uint8(dev, "dcr", dcr); + qdev_prop_set_uint8(dev, "bcr", bcr); + qdev_prop_set_uint64(dev, "pid", pid); + + if (i3c_addr_is_rsvd(addr)) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(dev)); + qemu_log_mask(LOG_GUEST_ERROR, "%s: I3C target created with reserv= ed " + "address 0x%.2x\n", path, addr); + } + return I3C_TARGET(dev); +} + +bool i3c_target_realize_and_unref(I3CTarget *dev, I3CBus *bus, Error **err= p) +{ + return qdev_realize_and_unref(&dev->qdev, &bus->qbus, errp); +} + +I3CTarget *i3c_target_create_simple(I3CBus *bus, const char *name, uint8_t= addr, + uint8_t dcr, uint8_t bcr, uint64_t pid) +{ + I3CTarget *dev =3D i3c_target_new(name, addr, dcr, bcr, pid); + dev->address =3D 0; + i3c_target_realize_and_unref(dev, bus, &error_abort); + + return dev; +} + +/* Legacy I2C functions. */ +void legacy_i2c_nack(I3CBus *bus) +{ + trace_legacy_i2c_nack(); + i2c_nack(bus->i2c_bus); +} + +uint8_t legacy_i2c_recv(I3CBus *bus) +{ + uint8_t byte =3D i2c_recv(bus->i2c_bus); + trace_legacy_i2c_recv(byte); + return byte; +} + +int legacy_i2c_send(I3CBus *bus, uint8_t data) +{ + trace_legacy_i2c_send(data); + return i2c_send(bus->i2c_bus, data); +} + +int legacy_i2c_start_transfer(I3CBus *bus, uint8_t address, bool is_recv) +{ + trace_legacy_i2c_start_transfer(address, is_recv); + return i2c_start_transfer(bus->i2c_bus, address, is_recv); +} + +int legacy_i2c_start_recv(I3CBus *bus, uint8_t address) +{ + trace_legacy_i2c_start_transfer(address, true); + return i2c_start_transfer(bus->i2c_bus, address, /*is_recv=3D*/true); +} + +int legacy_i2c_start_send(I3CBus *bus, uint8_t address) +{ + trace_legacy_i2c_start_transfer(address, false); + return i2c_start_transfer(bus->i2c_bus, address, /*is_recv=3D*/false); +} + +void legacy_i2c_end_transfer(I3CBus *bus) +{ + trace_legacy_i2c_end_transfer(); + i2c_end_transfer(bus->i2c_bus); +} + +I2CSlave *legacy_i2c_device_create_simple(I3CBus *bus, const char *name, + uint8_t addr) +{ + I2CSlave *dev =3D i2c_slave_new(name, addr); + + i2c_slave_realize_and_unref(dev, bus->i2c_bus, &error_abort); + return dev; +} + +static void i3c_target_class_init(ObjectClass *klass, const void *data) +{ + DeviceClass *k =3D DEVICE_CLASS(klass); + I3CTargetClass *sc =3D I3C_TARGET_CLASS(klass); + set_bit(DEVICE_CATEGORY_MISC, k->categories); + k->bus_type =3D TYPE_I3C_BUS; + device_class_set_props(k, i3c_props); + sc->target_match =3D i3c_target_match; +} + +static const TypeInfo i3c_target_type_info =3D { + .name =3D TYPE_I3C_TARGET, + .parent =3D TYPE_DEVICE, + .instance_size =3D sizeof(I3CTarget), + .abstract =3D true, + .class_size =3D sizeof(I3CTargetClass), + .class_init =3D i3c_target_class_init, +}; + +static void i3c_register_types(void) +{ + type_register_static(&i3c_bus_info); + type_register_static(&i3c_target_type_info); +} + +type_init(i3c_register_types) diff --git a/hw/i3c/meson.build b/hw/i3c/meson.build index ebf20325cb..fb127613fe 100644 --- a/hw/i3c/meson.build +++ b/hw/i3c/meson.build @@ -1,3 +1,4 @@ i3c_ss =3D ss.source_set() +i3c_ss.add(when: 'CONFIG_I3C', if_true: files('core.c')) i3c_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_i3c.c')) system_ss.add_all(when: 'CONFIG_I3C', if_true: i3c_ss) diff --git a/hw/i3c/trace-events b/hw/i3c/trace-events index 3ead84eb45..cdf7cb07f6 100644 --- a/hw/i3c/trace-events +++ b/hw/i3c/trace-events @@ -5,3 +5,19 @@ aspeed_i3c_read(uint64_t offset, uint64_t data) "I3C read:= offset 0x%" PRIx64 " aspeed_i3c_write(uint64_t offset, uint64_t data) "I3C write: offset 0x%" P= RIx64 " data 0x%" PRIx64 aspeed_i3c_device_read(uint32_t deviceid, uint64_t offset, uint64_t data) = "I3C Dev[%u] read: offset 0x%" PRIx64 " data 0x%" PRIx64 aspeed_i3c_device_write(uint32_t deviceid, uint64_t offset, uint64_t data)= "I3C Dev[%u] write: offset 0x%" PRIx64 " data 0x%" PRIx64 + +# core.c +i3c_target_event(uint8_t address, uint8_t event) "I3C target 0x%" PRIx8 " = event 0x%" PRIx8 +i3c_target_handle_ccc(uint8_t address, uint8_t ccc) "I3C target 0x%" PRIx8= " handling CCC 0x%" PRIx8 +i3c_target_send_ibi(uint8_t address, bool is_recv) "I3C target IBI address= 0x%" PRIx8 " RnW=3D%d" +i3c_target_send_ibi_bytes(uint8_t byte) "I3C target IBI byte 0x%" PRIx8 +i3c_target_ibi_finish(void) "I3C target IBI finish" +i3c_start_transfer(uint8_t address, bool is_recv) "I3C START with address = 0x%" PRIx8 " is_recv=3D%d" +i3c_end_transfer(void) "I3C transfer done" +i3c_send(uint32_t num_sent, uint32_t num_to_send, bool ack) "I3C send %" P= RId32 "/%" PRId32 " bytes, ack=3D%d" +i3c_recv(uint32_t num_read, uint32_t num_to_read, bool ack) "I3C recv %" P= RId32 "/%" PRId32 " bytes, ack=3D%d" +legacy_i2c_nack(void) "Legacy I2C NACK" +legacy_i2c_recv(uint8_t byte) "Legacy I2C recv 0x%" PRIx8 +legacy_i2c_send(uint8_t byte) "Legacy I2C send 0x%" PRIx8 +legacy_i2c_start_transfer(uint8_t address, bool is_recv) "Legacy I2C START= with address 0x%" PRIx8 " is_recv=3D%d" +legacy_i2c_end_transfer(void) "Legacy I2C STOP" diff --git a/include/hw/i3c/i3c.h b/include/hw/i3c/i3c.h new file mode 100644 index 0000000000..cd54223845 --- /dev/null +++ b/include/hw/i3c/i3c.h @@ -0,0 +1,277 @@ +/* + * QEMU I3C bus interface. + * + * Copyright 2025 Google LLC + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef QEMU_INCLUDE_HW_I3C_I3C_H_ +#define QEMU_INCLUDE_HW_I3C_I3C_H_ + +#include "hw/qdev-core.h" +#include "qom/object.h" +#include "hw/i2c/i2c.h" + +#define TYPE_I3C_TARGET "i3c-target" +OBJECT_DECLARE_TYPE(I3CTarget, I3CTargetClass, I3C_TARGET) + +typedef enum I3CEvent { + I3C_START_RECV, + I3C_START_SEND, + I3C_STOP, + I3C_NACK, +} I3CEvent; + +typedef enum I3CCCC { + /* Broadcast CCCs */ + I3C_CCC_ENEC =3D 0x00, + I3C_CCC_DISEC =3D 0x01, + I3C_CCC_ENTAS0 =3D 0x02, + I3C_CCC_ENTAS1 =3D 0x03, + I3C_CCC_ENTAS2 =3D 0x04, + I3C_CCC_ENTAS3 =3D 0x05, + I3C_CCC_RSTDAA =3D 0x06, + I3C_CCC_ENTDAA =3D 0x07, + I3C_CCC_DEFTGTS =3D 0x08, + I3C_CCC_SETMWL =3D 0x09, + I3C_CCC_SETMRL =3D 0x0a, + I3C_CCC_ENTTM =3D 0x0b, + I3C_CCC_SETBUSCON =3D 0x0c, + I3C_CCC_ENDXFER =3D 0x12, + I3C_CCC_ENTHDR0 =3D 0x20, + I3C_CCC_ENTHDR1 =3D 0x21, + I3C_CCC_ENTHDR2 =3D 0x22, + I3C_CCC_ENTHDR3 =3D 0x23, + I3C_CCC_ENTHDR4 =3D 0x24, + I3C_CCC_ENTHDR5 =3D 0x25, + I3C_CCC_ENTHDR6 =3D 0x26, + I3C_CCC_ENTHDR7 =3D 0x27, + I3C_CCC_SETXTIME =3D 0x28, + I3C_CCC_SETAASA =3D 0x29, + I3C_CCC_RSTACT =3D 0x2a, + I3C_CCC_DEFGRPA =3D 0x2b, + I3C_CCC_RSTGRPA =3D 0x2c, + I3C_CCC_MLANE =3D 0x2d, + /* Direct CCCs */ + I3C_CCCD_ENEC =3D 0x80, + I3C_CCCD_DISEC =3D 0x81, + I3C_CCCD_ENTAS0 =3D 0x82, + I3C_CCCD_ENTAS1 =3D 0x83, + I3C_CCCD_ENTAS2 =3D 0x84, + I3C_CCCD_ENTAS3 =3D 0x85, + I3C_CCCD_SETDASA =3D 0x87, + I3C_CCCD_SETNEWDA =3D 0x88, + I3C_CCCD_SETMWL =3D 0x89, + I3C_CCCD_SETMRL =3D 0x8a, + I3C_CCCD_GETMWL =3D 0x8b, + I3C_CCCD_GETMRL =3D 0x8c, + I3C_CCCD_GETPID =3D 0x8d, + I3C_CCCD_GETBCR =3D 0x8e, + I3C_CCCD_GETDCR =3D 0x8f, + I3C_CCCD_GETSTATUS =3D 0x90, + I3C_CCCD_GETACCCR =3D 0x91, + I3C_CCCD_ENDXFER =3D 0x92, + I3C_CCCD_SETBRGTGT =3D 0x93, + I3C_CCCD_GETMXDS =3D 0x94, + I3C_CCCD_GETCAPS =3D 0x95, + I3C_CCCD_SETROUTE =3D 0x96, + I3C_CCCD_SETXTIME =3D 0x98, + I3C_CCCD_GETXTIME =3D 0x99, + I3C_CCCD_RSTACT =3D 0x9a, + I3C_CCCD_SETGRPA =3D 0x9b, + I3C_CCCD_RSTGRPA =3D 0x9c, + I3C_CCCD_MLANE =3D 0x9d, +} I3CCCC; + +#define CCC_IS_DIRECT(_ccc) (_ccc & 0x80) + +#define I3C_BROADCAST 0x7e +#define I3C_HJ_ADDR 0x02 +#define I3C_ENTDAA_SIZE 8 + +struct I3CTargetClass { + DeviceClass parent; + + /* + * Controller to target. Returns 0 for success, non-zero for NAK or ot= her + * error. + */ + int (*send)(I3CTarget *s, const uint8_t *data, uint32_t num_to_send, + uint32_t *num_sent); + /* + * Target to controller. I3C targets are able to terminate reads early= , so + * this returns the number of bytes read from the target. + */ + uint32_t (*recv)(I3CTarget *s, uint8_t *data, uint32_t num_to_read); + /* Notify the target of a bus state change. */ + int (*event)(I3CTarget *s, enum I3CEvent event); + /* + * Handle a read CCC transmitted from a controller. + * CCCs are I3C commands that I3C targets support. + * The target can NACK the CCC if it does not support it. + */ + int (*handle_ccc_read)(I3CTarget *s, uint8_t *data, uint32_t num_to_re= ad, + uint32_t *num_read); + /* + * Handle a write CCC transmitted from a controller. + * CCCs are I3C commands that I3C targets support. + * The target can NACK the CCC if it does not support it. + */ + int (*handle_ccc_write)(I3CTarget *s, const uint8_t *data, + uint32_t num_to_send, uint32_t *num_sent); + + /* + * Matches and adds the candidate if the address matches the candidate= 's + * address. + * Returns true if the address matched, or if this was a broadcast, and + * updates the device list. Otherwise returns false. + */ + bool (*target_match)(I3CTarget *candidate, uint8_t address, bool is_re= ad, + bool broadcast, bool in_entdaa); +}; + +struct I3CTarget { + DeviceState qdev; + + uint8_t address; + uint8_t static_address; + uint8_t dcr; + uint8_t bcr; + uint64_t pid; + + /* CCC State tracking. */ + I3CCCC curr_ccc; + uint8_t ccc_byte_offset; + bool in_ccc; + bool in_test_mode; +}; + +struct I3CNode { + I3CTarget *target; + QLIST_ENTRY(I3CNode) next; +}; + +typedef struct I3CNode I3CNode; + +typedef QLIST_HEAD(I3CNodeList, I3CNode) I3CNodeList; + +#define TYPE_I3C_BUS "i3c-bus" +OBJECT_DECLARE_TYPE(I3CBus, I3CBusClass, I3C_BUS) + +struct I3CBus { + BusState qbus; + + /* Legacy I2C. */ + I2CBus *i2c_bus; + + I3CNodeList current_devs; + bool broadcast; + uint8_t ccc; + bool in_ccc; + bool in_entdaa; + uint8_t saved_address; +}; + +struct I3CBusClass { + DeviceClass parent; + + /* Handle an incoming IBI request from a target */ + int (*ibi_handle) (I3CBus *bus, uint8_t addr, bool is_recv); + /* Receive data from an IBI request */ + int (*ibi_recv) (I3CBus *bus, uint8_t data); + /* Do anything that needs to be done, since the IBI is finished. */ + int (*ibi_finish) (I3CBus *bus); +}; + +I3CBus *i3c_init_bus(DeviceState *parent, const char *name); +I3CBus *i3c_init_bus_type(const char *type, DeviceState *parent, + const char *name); +void i3c_set_target_address(I3CTarget *dev, uint8_t address); +bool i3c_bus_busy(I3CBus *bus); + +/* + * Start a transfer on an I3C bus. + * If is_recv is known at compile-time (i.e. a device will always be sendi= ng or + * will always be receiving at a certain point), prefer to use i3c_start_r= ecv or + * i3c_start_send instead. + * + * Returns 0 on success, non-zero on an error. + */ +int i3c_start_transfer(I3CBus *bus, uint8_t address, bool is_recv); + +/* + * Start a receive transfer on an I3C bus. + * + * Returns 0 on success, non-zero on an error + */ +int i3c_start_recv(I3CBus *bus, uint8_t address); + +/* + * Start a send transfer on an I3C bus. + * + * Returns 0 on success, non-zero on an error + */ +int i3c_start_send(I3CBus *bus, uint8_t address); + +void i3c_end_transfer(I3CBus *bus); +void i3c_nack(I3CBus *bus); +int i3c_send_byte(I3CBus *bus, uint8_t data); +int i3c_send(I3CBus *bus, const uint8_t *data, uint32_t num_to_send, + uint32_t *num_sent); +/* + * I3C receives can only NACK on a CCC. The target should NACK a CCC it do= es not + * support. + */ +int i3c_recv_byte(I3CBus *bus, uint8_t *data); +int i3c_recv(I3CBus *bus, uint8_t *data, uint32_t num_to_read, + uint32_t *num_read); +bool i3c_scan_bus(I3CBus *bus, uint8_t address, enum I3CEvent event); +int i3c_do_entdaa(I3CBus *bus, uint8_t address, uint64_t *pid, uint8_t *bc= r, + uint8_t *dcr); +int i3c_start_device_transfer(I3CTarget *dev, int send_length); +bool i3c_target_match_and_add(I3CBus *bus, I3CTarget *target, uint8_t addr= ess, + enum I3CEvent event); +int i3c_target_send_ibi(I3CTarget *t, uint8_t addr, bool is_recv); +int i3c_target_send_ibi_bytes(I3CTarget *t, uint8_t data); +int i3c_target_ibi_finish(I3CTarget *t, uint8_t data); + +/* + * Legacy I2C functions. + * + * These are wrapper for I2C functions that take in an I3C bus instead of = an I2C + * bus. Internally they use the I2C bus (and devices attached to it) that'= s a + * part of the I3C bus + */ +void legacy_i2c_nack(I3CBus *bus); +uint8_t legacy_i2c_recv(I3CBus *bus); +int legacy_i2c_send(I3CBus *bus, uint8_t data); +int legacy_i2c_start_transfer(I3CBus *bus, uint8_t address, bool is_recv); +int legacy_i2c_start_recv(I3CBus *bus, uint8_t address); +int legacy_i2c_start_send(I3CBus *bus, uint8_t address); +void legacy_i2c_end_transfer(I3CBus *bus); +I2CSlave *legacy_i2c_device_create_simple(I3CBus *bus, const char *name, + uint8_t addr); + +/** + * Create an I3C Target. + * + * The target returned from this function still needs to be realized. + */ +I3CTarget *i3c_target_new(const char *name, uint8_t addr, uint8_t dcr, + uint8_t bcr, uint64_t pid); + +/** + * Create and realize an I3C target. + * + * Create the target, initialize it, put it on the specified I3C bus, and + * realize it. + */ +I3CTarget *i3c_target_create_simple(I3CBus *bus, const char *name, + uint8_t addr, uint8_t dcr, uint8_t bcr, + uint64_t pid); + +/* Realize and drop the reference count on an I3C target. */ +bool i3c_target_realize_and_unref(I3CTarget *dev, I3CBus *bus, Error **err= p); + +#endif /* QEMU_INCLUDE_HW_I3C_I3C_H_ */ --=20 2.50.0.rc1.591.g9c95f17f64-goog From nobody Sat Nov 15 16:09:06 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1749773097; cv=none; d=zohomail.com; s=zohoarc; b=VJR2iLtgGFamc5pyLX6HkNDpyQrpO50hxV0MWofdQNyX8bk/ZhkRniFfpYVwsSsfSkbo1Wycoq3cw0qZh+pfKIgE1XdOEOhn4kCCUb52MpGYC7hbnPKCGCOZljsadBfOJTrmjM8HoD2TT28dSOciY6TN3GaqWrai6kCfSWQEZwg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749773097; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=rlKLlPaZ/qjCDaZme7JPe4na4UPbi/S79jkvjPexJpU=; b=Kdua1O1Z71kAHKD0il1Vw14gXMjumMqAzgec1Gg3t3HGFbTZuOGkM5whX+sEMJc/Gi0S70jNdsDFHbAEYv+LdaxUUdPiFtPKLVuzxcJSOI4DZjUUMfVhsS1lL8x6Ane33uMVReP+W7iZyr9W7GiYoiSmUVFf/umyescON9hbfiQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749773097504521.8120992708452; Thu, 12 Jun 2025 17:04:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPruB-0005nl-LH; Thu, 12 Jun 2025 20:04:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3AGtLaAcKCk0z3103sxv33v0t.r315t19-stAt0232v29.36v@flex--komlodi.bounces.google.com>) id 1uPru9-0005md-Ja for qemu-devel@nongnu.org; Thu, 12 Jun 2025 20:04:21 -0400 Received: from mail-pf1-x44a.google.com ([2607:f8b0:4864:20::44a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3AGtLaAcKCk0z3103sxv33v0t.r315t19-stAt0232v29.36v@flex--komlodi.bounces.google.com>) id 1uPru6-0000Wu-ND for qemu-devel@nongnu.org; Thu, 12 Jun 2025 20:04:21 -0400 Received: by mail-pf1-x44a.google.com with SMTP id d2e1a72fcca58-747d394f45fso1343906b3a.2 for ; Thu, 12 Jun 2025 17:04:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1749773057; x=1750377857; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=rlKLlPaZ/qjCDaZme7JPe4na4UPbi/S79jkvjPexJpU=; b=jFKhybts4p+lkAyt/hRlc52F/fo6eUdw+Yfpk324NH3XHAPNHOQLR3RXCswtj56eDN /GMGNJk4eHS0gr/U2+/IQ/DvA5K4ka84x0Y+dUQQ2IgaMOGOd4PsNlBaBIdTr/whBBNq QKcW/hyzo59/uzOPRELca/owYw2KL99ddM0HDmfvgUUIyr9TUj6IcGs1pXtazORX+b4V zxnpLn7WInNn4j4bk7seF6SYBDCJumLSB1jg33KgbVsrMVeuBLRIQ+lwp1Y80+vUvdlQ d2gKBsVrEzYYOCnEfpBglWzxakyYcqmBRRCag7Sd1c49fubfHz+fzONnifqZ7Sa0/pFu yJhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749773057; x=1750377857; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=rlKLlPaZ/qjCDaZme7JPe4na4UPbi/S79jkvjPexJpU=; b=YoUJvVOEG3dF2jN7BHXaJOo96X0omNmruNBcSi1VCzWpT3aOSLvZdJOw3rKT+MH7MV gqZuH/tsr3AuocybR6cg8WMj4WK+SVrQONkc0z+NjFiXWN6VWgGIUA0Khsiphw13zIlO kK1135jojLwTnOTWlY6rjvU8eOHIMNFtztW698BNq0napip4ieeFWsWkVto8u9kukyww KXXoddopWSD/HgHWmCyWYNnYh/Bty6cLkUytV4O7MXVan8EeyBXcn7VRNVaQ9ikKdbtn arjoOpgVuJ/OEfTGNnKDUUavFfP1nKwPyAlU/U4wyfmw9M+qK3E9tALomBJY8Fcl9DKU WJ+g== X-Gm-Message-State: AOJu0Ywdl3ZfqIZjCwWmDmW140kYlASgBcvKxHl08n4/RRJ/Q209nENy c0kBgmdQzS97u1cIzK319k3l/IqWr8F+5LCek0ksSo82A503sAFdH3MRlhZ9hsDYkJ9vE5uYl+b DkkQVsrUA4kFqIbyparWS2IQc83OL8WSFTFREBNB8QEXOeOq8/CqGKKtth8WbWNWNXRbDQT/7ON 3S01Urz8QbxSPhUjVClIBPuov5n96pXRIuX7yr24r+ X-Google-Smtp-Source: AGHT+IG6akEqGlNM8qsP7MZTZas9c60HPxg5e6upy7QQEHMJbGLhCImjYT8+m30GdpsgxYtDz8rNbPPE8oHp X-Received: from pgbfy9.prod.google.com ([2002:a05:6a02:2a89:b0:b2c:374b:9e48]) (user=komlodi job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:700d:b0:1f5:769a:a4be with SMTP id adf61e73a8af0-21fad0bb9b6mr1359209637.36.1749773056758; Thu, 12 Jun 2025 17:04:16 -0700 (PDT) Date: Fri, 13 Jun 2025 00:03:55 +0000 In-Reply-To: <20250613000411.1516521-1-komlodi@google.com> Mime-Version: 1.0 References: <20250613000411.1516521-1-komlodi@google.com> X-Mailer: git-send-email 2.50.0.rc1.591.g9c95f17f64-goog Message-ID: <20250613000411.1516521-4-komlodi@google.com> Subject: [PATCH 03/19] hw/i3c: Split DesignWare I3C out of Aspeed I3C From: Joe Komlodi To: qemu-devel@nongnu.org Cc: venture@google.com, komlodi@google.com, clg@kaod.org, peter.maydell@linaro.org, steven_lee@aspeedtech.com, leetroy@gmail.com, jamin_lin@aspeedtech.com, andrew@codeconstruct.com.au, joel@jms.id.au, qemu-arm@nongnu.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::44a; envelope-from=3AGtLaAcKCk0z3103sxv33v0t.r315t19-stAt0232v29.36v@flex--komlodi.bounces.google.com; helo=mail-pf1-x44a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1749773101480116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The Aspeed I3C IP block is technically an Aspeed IP block that manages 6 DW I3C controllers. To help reflect this better and to make it easier for other SoCs to use the DW I3C model, we'll split out the DW portion from the Aspeed portion. Signed-off-by: Joe Komlodi --- hw/arm/Kconfig | 1 + hw/i3c/Kconfig | 3 + hw/i3c/aspeed_i3c.c | 183 +------------------------------- hw/i3c/dw-i3c.c | 204 ++++++++++++++++++++++++++++++++++++ hw/i3c/meson.build | 1 + hw/i3c/trace-events | 6 +- include/hw/i3c/aspeed_i3c.h | 19 +--- include/hw/i3c/dw-i3c.h | 35 +++++++ 8 files changed, 254 insertions(+), 198 deletions(-) create mode 100644 hw/i3c/dw-i3c.c create mode 100644 include/hw/i3c/dw-i3c.h diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig index 427d0f0271..53d62cd08d 100644 --- a/hw/arm/Kconfig +++ b/hw/arm/Kconfig @@ -531,6 +531,7 @@ config ASPEED_SOC select FTGMAC100 select I2C select I3C + select DW_I3C select DPS310 select PCA9552 select SERIAL_MM diff --git a/hw/i3c/Kconfig b/hw/i3c/Kconfig index e07fe445c6..ecec77d6fc 100644 --- a/hw/i3c/Kconfig +++ b/hw/i3c/Kconfig @@ -1,2 +1,5 @@ config I3C bool + +config DW_I3C + bool diff --git a/hw/i3c/aspeed_i3c.c b/hw/i3c/aspeed_i3c.c index e56822f928..cb0332828c 100644 --- a/hw/i3c/aspeed_i3c.c +++ b/hw/i3c/aspeed_i3c.c @@ -2,6 +2,7 @@ * ASPEED I3C Controller * * Copyright (C) 2021 ASPEED Technology Inc. + * Copyright (C) 2025 Google, LLC. * * This code is licensed under the GPL version 2 or later. See * the COPYING file in the top-level directory. @@ -43,162 +44,6 @@ REG32(I3C6_REG1, 0x64) FIELD(I3C6_REG1, I2C_MODE, 0, 1) FIELD(I3C6_REG1, SA_EN, 15, 1) =20 -/* I3C Device Registers */ -REG32(DEVICE_CTRL, 0x00) -REG32(DEVICE_ADDR, 0x04) -REG32(HW_CAPABILITY, 0x08) -REG32(COMMAND_QUEUE_PORT, 0x0c) -REG32(RESPONSE_QUEUE_PORT, 0x10) -REG32(RX_TX_DATA_PORT, 0x14) -REG32(IBI_QUEUE_STATUS, 0x18) -REG32(IBI_QUEUE_DATA, 0x18) -REG32(QUEUE_THLD_CTRL, 0x1c) -REG32(DATA_BUFFER_THLD_CTRL, 0x20) -REG32(IBI_QUEUE_CTRL, 0x24) -REG32(IBI_MR_REQ_REJECT, 0x2c) -REG32(IBI_SIR_REQ_REJECT, 0x30) -REG32(RESET_CTRL, 0x34) -REG32(SLV_EVENT_CTRL, 0x38) -REG32(INTR_STATUS, 0x3c) -REG32(INTR_STATUS_EN, 0x40) -REG32(INTR_SIGNAL_EN, 0x44) -REG32(INTR_FORCE, 0x48) -REG32(QUEUE_STATUS_LEVEL, 0x4c) -REG32(DATA_BUFFER_STATUS_LEVEL, 0x50) -REG32(PRESENT_STATE, 0x54) -REG32(CCC_DEVICE_STATUS, 0x58) -REG32(DEVICE_ADDR_TABLE_POINTER, 0x5c) - FIELD(DEVICE_ADDR_TABLE_POINTER, DEPTH, 16, 16) - FIELD(DEVICE_ADDR_TABLE_POINTER, ADDR, 0, 16) -REG32(DEV_CHAR_TABLE_POINTER, 0x60) -REG32(VENDOR_SPECIFIC_REG_POINTER, 0x6c) -REG32(SLV_MIPI_PID_VALUE, 0x70) -REG32(SLV_PID_VALUE, 0x74) -REG32(SLV_CHAR_CTRL, 0x78) -REG32(SLV_MAX_LEN, 0x7c) -REG32(MAX_READ_TURNAROUND, 0x80) -REG32(MAX_DATA_SPEED, 0x84) -REG32(SLV_DEBUG_STATUS, 0x88) -REG32(SLV_INTR_REQ, 0x8c) -REG32(DEVICE_CTRL_EXTENDED, 0xb0) -REG32(SCL_I3C_OD_TIMING, 0xb4) -REG32(SCL_I3C_PP_TIMING, 0xb8) -REG32(SCL_I2C_FM_TIMING, 0xbc) -REG32(SCL_I2C_FMP_TIMING, 0xc0) -REG32(SCL_EXT_LCNT_TIMING, 0xc8) -REG32(SCL_EXT_TERMN_LCNT_TIMING, 0xcc) -REG32(BUS_FREE_TIMING, 0xd4) -REG32(BUS_IDLE_TIMING, 0xd8) -REG32(I3C_VER_ID, 0xe0) -REG32(I3C_VER_TYPE, 0xe4) -REG32(EXTENDED_CAPABILITY, 0xe8) -REG32(SLAVE_CONFIG, 0xec) - -static const uint32_t ast2600_i3c_device_resets[ASPEED_I3C_DEVICE_NR_REGS]= =3D { - [R_HW_CAPABILITY] =3D 0x000e00bf, - [R_QUEUE_THLD_CTRL] =3D 0x01000101, - [R_I3C_VER_ID] =3D 0x3130302a, - [R_I3C_VER_TYPE] =3D 0x6c633033, - [R_DEVICE_ADDR_TABLE_POINTER] =3D 0x00080280, - [R_DEV_CHAR_TABLE_POINTER] =3D 0x00020200, - [A_VENDOR_SPECIFIC_REG_POINTER] =3D 0x000000b0, - [R_SLV_MAX_LEN] =3D 0x00ff00ff, -}; - -static uint64_t aspeed_i3c_device_read(void *opaque, hwaddr offset, - unsigned size) -{ - AspeedI3CDevice *s =3D ASPEED_I3C_DEVICE(opaque); - uint32_t addr =3D offset >> 2; - uint64_t value; - - switch (addr) { - case R_COMMAND_QUEUE_PORT: - value =3D 0; - break; - default: - value =3D s->regs[addr]; - break; - } - - trace_aspeed_i3c_device_read(s->id, offset, value); - - return value; -} - -static void aspeed_i3c_device_write(void *opaque, hwaddr offset, - uint64_t value, unsigned size) -{ - AspeedI3CDevice *s =3D ASPEED_I3C_DEVICE(opaque); - uint32_t addr =3D offset >> 2; - - trace_aspeed_i3c_device_write(s->id, offset, value); - - switch (addr) { - case R_HW_CAPABILITY: - case R_RESPONSE_QUEUE_PORT: - case R_IBI_QUEUE_DATA: - case R_QUEUE_STATUS_LEVEL: - case R_PRESENT_STATE: - case R_CCC_DEVICE_STATUS: - case R_DEVICE_ADDR_TABLE_POINTER: - case R_VENDOR_SPECIFIC_REG_POINTER: - case R_SLV_CHAR_CTRL: - case R_SLV_MAX_LEN: - case R_MAX_READ_TURNAROUND: - case R_I3C_VER_ID: - case R_I3C_VER_TYPE: - case R_EXTENDED_CAPABILITY: - qemu_log_mask(LOG_GUEST_ERROR, - "%s: write to readonly register[0x%02" HWADDR_PRIx - "] =3D 0x%08" PRIx64 "\n", - __func__, offset, value); - break; - case R_RX_TX_DATA_PORT: - break; - case R_RESET_CTRL: - break; - default: - s->regs[addr] =3D value; - break; - } -} - -static const VMStateDescription aspeed_i3c_device_vmstate =3D { - .name =3D TYPE_ASPEED_I3C, - .version_id =3D 1, - .minimum_version_id =3D 1, - .fields =3D (const VMStateField[]){ - VMSTATE_UINT32_ARRAY(regs, AspeedI3CDevice, ASPEED_I3C_DEVICE_NR_R= EGS), - VMSTATE_END_OF_LIST(), - } -}; - -static const MemoryRegionOps aspeed_i3c_device_ops =3D { - .read =3D aspeed_i3c_device_read, - .write =3D aspeed_i3c_device_write, - .endianness =3D DEVICE_LITTLE_ENDIAN, -}; - -static void aspeed_i3c_device_reset(DeviceState *dev) -{ - AspeedI3CDevice *s =3D 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 =3D ASPEED_I3C_DEVICE(dev); - g_autofree char *name =3D g_strdup_printf(TYPE_ASPEED_I3C_DEVICE ".%d", - s->id); - - sysbus_init_irq(SYS_BUS_DEVICE(dev), &s->irq); - - memory_region_init_io(&s->mr, OBJECT(s), &aspeed_i3c_device_ops, - s, name, ASPEED_I3C_DEVICE_NR_REGS << 2); -} - static uint64_t aspeed_i3c_read(void *opaque, hwaddr addr, unsigned int si= ze) { AspeedI3CState *s =3D ASPEED_I3C(opaque); @@ -275,7 +120,7 @@ static void aspeed_i3c_instance_init(Object *obj) =20 for (i =3D 0; i < ASPEED_I3C_NR_DEVICES; ++i) { object_initialize_child(obj, "device[*]", &s->devices[i], - TYPE_ASPEED_I3C_DEVICE); + TYPE_DW_I3C); } } =20 @@ -323,27 +168,6 @@ static void aspeed_i3c_realize(DeviceState *dev, Error= **errp) =20 } =20 -static const Property aspeed_i3c_device_properties[] =3D { - DEFINE_PROP_UINT8("device-id", AspeedI3CDevice, id, 0), -}; - -static void aspeed_i3c_device_class_init(ObjectClass *klass, const void *d= ata) -{ - DeviceClass *dc =3D DEVICE_CLASS(klass); - - dc->desc =3D "Aspeed I3C Device"; - dc->realize =3D aspeed_i3c_device_realize; - device_class_set_legacy_reset(dc, aspeed_i3c_device_reset); - device_class_set_props(dc, aspeed_i3c_device_properties); -} - -static const TypeInfo aspeed_i3c_device_info =3D { - .name =3D TYPE_ASPEED_I3C_DEVICE, - .parent =3D TYPE_SYS_BUS_DEVICE, - .instance_size =3D sizeof(AspeedI3CDevice), - .class_init =3D aspeed_i3c_device_class_init, -}; - static const VMStateDescription vmstate_aspeed_i3c =3D { .name =3D TYPE_ASPEED_I3C, .version_id =3D 1, @@ -351,7 +175,7 @@ static const VMStateDescription vmstate_aspeed_i3c =3D { .fields =3D (const VMStateField[]) { VMSTATE_UINT32_ARRAY(regs, AspeedI3CState, ASPEED_I3C_NR_REGS), VMSTATE_STRUCT_ARRAY(devices, AspeedI3CState, ASPEED_I3C_NR_DEVICE= S, 1, - aspeed_i3c_device_vmstate, AspeedI3CDevice), + vmstate_dw_i3c, DWI3C), VMSTATE_END_OF_LIST(), } }; @@ -376,7 +200,6 @@ static const TypeInfo aspeed_i3c_info =3D { =20 static void aspeed_i3c_register_types(void) { - type_register_static(&aspeed_i3c_device_info); type_register_static(&aspeed_i3c_info); } =20 diff --git a/hw/i3c/dw-i3c.c b/hw/i3c/dw-i3c.c new file mode 100644 index 0000000000..4b1a3f3f07 --- /dev/null +++ b/hw/i3c/dw-i3c.c @@ -0,0 +1,204 @@ +/* + * DesignWare I3C Controller + * + * Copyright (C) 2021 ASPEED Technology Inc. + * Copyright (C) 2025 Google, LLC + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "qemu/error-report.h" +#include "hw/i3c/i3c.h" +#include "hw/i3c/dw-i3c.h" +#include "hw/registerfields.h" +#include "hw/qdev-properties.h" +#include "qapi/error.h" +#include "migration/vmstate.h" +#include "trace.h" + +REG32(DEVICE_CTRL, 0x00) +REG32(DEVICE_ADDR, 0x04) +REG32(HW_CAPABILITY, 0x08) +REG32(COMMAND_QUEUE_PORT, 0x0c) +REG32(RESPONSE_QUEUE_PORT, 0x10) +REG32(RX_TX_DATA_PORT, 0x14) +REG32(IBI_QUEUE_STATUS, 0x18) +REG32(IBI_QUEUE_DATA, 0x18) +REG32(QUEUE_THLD_CTRL, 0x1c) +REG32(DATA_BUFFER_THLD_CTRL, 0x20) +REG32(IBI_QUEUE_CTRL, 0x24) +REG32(IBI_MR_REQ_REJECT, 0x2c) +REG32(IBI_SIR_REQ_REJECT, 0x30) +REG32(RESET_CTRL, 0x34) +REG32(SLV_EVENT_CTRL, 0x38) +REG32(INTR_STATUS, 0x3c) +REG32(INTR_STATUS_EN, 0x40) +REG32(INTR_SIGNAL_EN, 0x44) +REG32(INTR_FORCE, 0x48) +REG32(QUEUE_STATUS_LEVEL, 0x4c) +REG32(DATA_BUFFER_STATUS_LEVEL, 0x50) +REG32(PRESENT_STATE, 0x54) +REG32(CCC_DEVICE_STATUS, 0x58) +REG32(DEVICE_ADDR_TABLE_POINTER, 0x5c) + FIELD(DEVICE_ADDR_TABLE_POINTER, DEPTH, 16, 16) + FIELD(DEVICE_ADDR_TABLE_POINTER, ADDR, 0, 16) +REG32(DEV_CHAR_TABLE_POINTER, 0x60) +REG32(VENDOR_SPECIFIC_REG_POINTER, 0x6c) +REG32(SLV_MIPI_PID_VALUE, 0x70) +REG32(SLV_PID_VALUE, 0x74) +REG32(SLV_CHAR_CTRL, 0x78) +REG32(SLV_MAX_LEN, 0x7c) +REG32(MAX_READ_TURNAROUND, 0x80) +REG32(MAX_DATA_SPEED, 0x84) +REG32(SLV_DEBUG_STATUS, 0x88) +REG32(SLV_INTR_REQ, 0x8c) +REG32(DEVICE_CTRL_EXTENDED, 0xb0) +REG32(SCL_I3C_OD_TIMING, 0xb4) +REG32(SCL_I3C_PP_TIMING, 0xb8) +REG32(SCL_I2C_FM_TIMING, 0xbc) +REG32(SCL_I2C_FMP_TIMING, 0xc0) +REG32(SCL_EXT_LCNT_TIMING, 0xc8) +REG32(SCL_EXT_TERMN_LCNT_TIMING, 0xcc) +REG32(BUS_FREE_TIMING, 0xd4) +REG32(BUS_IDLE_TIMING, 0xd8) +REG32(I3C_VER_ID, 0xe0) +REG32(I3C_VER_TYPE, 0xe4) +REG32(EXTENDED_CAPABILITY, 0xe8) +REG32(SLAVE_CONFIG, 0xec) + +static const uint32_t dw_i3c_resets[DW_I3C_NR_REGS] =3D { + [R_HW_CAPABILITY] =3D 0x000e00bf, + [R_QUEUE_THLD_CTRL] =3D 0x01000101, + [R_I3C_VER_ID] =3D 0x3130302a, + [R_I3C_VER_TYPE] =3D 0x6c633033, + [R_DEVICE_ADDR_TABLE_POINTER] =3D 0x00080280, + [R_DEV_CHAR_TABLE_POINTER] =3D 0x00020200, + [A_VENDOR_SPECIFIC_REG_POINTER] =3D 0x000000b0, + [R_SLV_MAX_LEN] =3D 0x00ff00ff, +}; + +static uint64_t dw_i3c_read(void *opaque, hwaddr offset, unsigned size) +{ + DWI3C *s =3D DW_I3C(opaque); + uint32_t addr =3D offset >> 2; + uint64_t value; + + switch (addr) { + case R_COMMAND_QUEUE_PORT: + value =3D 0; + break; + default: + value =3D s->regs[addr]; + break; + } + + trace_dw_i3c_read(s->id, offset, value); + + return value; +} + +static void dw_i3c_write(void *opaque, hwaddr offset, uint64_t value, + unsigned size) +{ + DWI3C *s =3D DW_I3C(opaque); + uint32_t addr =3D offset >> 2; + + trace_dw_i3c_write(s->id, offset, value); + + switch (addr) { + case R_HW_CAPABILITY: + case R_RESPONSE_QUEUE_PORT: + case R_IBI_QUEUE_DATA: + case R_QUEUE_STATUS_LEVEL: + case R_PRESENT_STATE: + case R_CCC_DEVICE_STATUS: + case R_DEVICE_ADDR_TABLE_POINTER: + case R_VENDOR_SPECIFIC_REG_POINTER: + case R_SLV_CHAR_CTRL: + case R_SLV_MAX_LEN: + case R_MAX_READ_TURNAROUND: + case R_I3C_VER_ID: + case R_I3C_VER_TYPE: + case R_EXTENDED_CAPABILITY: + qemu_log_mask(LOG_GUEST_ERROR, + "%s: write to readonly register[0x%02" HWADDR_PRIx + "] =3D 0x%08" PRIx64 "\n", + __func__, offset, value); + break; + case R_RX_TX_DATA_PORT: + break; + case R_RESET_CTRL: + break; + default: + s->regs[addr] =3D value; + break; + } +} + +const VMStateDescription vmstate_dw_i3c =3D { + .name =3D TYPE_DW_I3C, + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (VMStateField[]){ + VMSTATE_UINT32_ARRAY(regs, DWI3C, DW_I3C_NR_REGS), + VMSTATE_END_OF_LIST(), + } +}; + +static const MemoryRegionOps dw_i3c_ops =3D { + .read =3D dw_i3c_read, + .write =3D dw_i3c_write, + .endianness =3D DEVICE_LITTLE_ENDIAN, +}; + +static void dw_i3c_reset_enter(Object *obj, ResetType type) +{ + DWI3C *s =3D DW_I3C(obj); + + memcpy(s->regs, dw_i3c_resets, sizeof(s->regs)); +} + +static void dw_i3c_realize(DeviceState *dev, Error **errp) +{ + DWI3C *s =3D DW_I3C(dev); + g_autofree char *name =3D g_strdup_printf(TYPE_DW_I3C ".%d", s->id); + + sysbus_init_irq(SYS_BUS_DEVICE(dev), &s->irq); + + memory_region_init_io(&s->mr, OBJECT(s), &dw_i3c_ops, s, name, + DW_I3C_NR_REGS << 2); + sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->mr); +} + +static const Property dw_i3c_properties[] =3D { + DEFINE_PROP_UINT8("device-id", DWI3C, id, 0), +}; + +static void dw_i3c_class_init(ObjectClass *klass, const void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + ResettableClass *rc =3D RESETTABLE_CLASS(klass); + + rc->phases.enter =3D dw_i3c_reset_enter; + + dc->desc =3D "DesignWare I3C Controller"; + dc->realize =3D dw_i3c_realize; + dc->vmsd =3D &vmstate_dw_i3c; + device_class_set_props(dc, dw_i3c_properties); +} + +static const TypeInfo dw_i3c_info =3D { + .name =3D TYPE_DW_I3C, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(DWI3C), + .class_init =3D dw_i3c_class_init, +}; + +static void dw_i3c_register_types(void) +{ + type_register_static(&dw_i3c_info); +} + +type_init(dw_i3c_register_types); diff --git a/hw/i3c/meson.build b/hw/i3c/meson.build index fb127613fe..83d75e7d5c 100644 --- a/hw/i3c/meson.build +++ b/hw/i3c/meson.build @@ -1,4 +1,5 @@ i3c_ss =3D ss.source_set() i3c_ss.add(when: 'CONFIG_I3C', if_true: files('core.c')) i3c_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_i3c.c')) +i3c_ss.add(when: 'CONFIG_DW_I3C', if_true: files('dw-i3c.c')) system_ss.add_all(when: 'CONFIG_I3C', if_true: i3c_ss) diff --git a/hw/i3c/trace-events b/hw/i3c/trace-events index cdf7cb07f6..2d944387db 100644 --- a/hw/i3c/trace-events +++ b/hw/i3c/trace-events @@ -3,8 +3,10 @@ # aspeed_i3c.c aspeed_i3c_read(uint64_t offset, uint64_t data) "I3C read: offset 0x%" PRI= x64 " data 0x%" PRIx64 aspeed_i3c_write(uint64_t offset, uint64_t data) "I3C write: offset 0x%" P= RIx64 " data 0x%" PRIx64 -aspeed_i3c_device_read(uint32_t deviceid, uint64_t offset, uint64_t data) = "I3C Dev[%u] read: offset 0x%" PRIx64 " data 0x%" PRIx64 -aspeed_i3c_device_write(uint32_t deviceid, uint64_t offset, uint64_t data)= "I3C Dev[%u] write: offset 0x%" PRIx64 " data 0x%" PRIx64 + +# dw-i3c,c +dw_i3c_read(uint32_t deviceid, uint64_t offset, uint64_t data) "I3C Dev[%u= ] read: offset 0x%" PRIx64 " data 0x%" PRIx64 +dw_i3c_write(uint32_t deviceid, uint64_t offset, uint64_t data) "I3C Dev[%= u] write: offset 0x%" PRIx64 " data 0x%" PRIx64 =20 # core.c i3c_target_event(uint8_t address, uint8_t event) "I3C target 0x%" PRIx8 " = event 0x%" PRIx8 diff --git a/include/hw/i3c/aspeed_i3c.h b/include/hw/i3c/aspeed_i3c.h index 39679dfa1a..793ee111cb 100644 --- a/include/hw/i3c/aspeed_i3c.h +++ b/include/hw/i3c/aspeed_i3c.h @@ -10,29 +10,15 @@ #ifndef ASPEED_I3C_H #define ASPEED_I3C_H =20 +#include "hw/i3c/dw-i3c.h" #include "hw/sysbus.h" =20 #define TYPE_ASPEED_I3C "aspeed.i3c" -#define TYPE_ASPEED_I3C_DEVICE "aspeed.i3c.device" OBJECT_DECLARE_TYPE(AspeedI3CState, AspeedI3CClass, ASPEED_I3C) =20 #define ASPEED_I3C_NR_REGS (0x70 >> 2) -#define ASPEED_I3C_DEVICE_NR_REGS (0x300 >> 2) #define ASPEED_I3C_NR_DEVICES 6 =20 -OBJECT_DECLARE_SIMPLE_TYPE(AspeedI3CDevice, ASPEED_I3C_DEVICE) -typedef struct AspeedI3CDevice { - /* */ - SysBusDevice parent; - - /* */ - MemoryRegion mr; - qemu_irq irq; - - uint8_t id; - uint32_t regs[ASPEED_I3C_DEVICE_NR_REGS]; -} AspeedI3CDevice; - typedef struct AspeedI3CState { /* */ SysBusDevice parent; @@ -43,6 +29,7 @@ typedef struct AspeedI3CState { qemu_irq irq; =20 uint32_t regs[ASPEED_I3C_NR_REGS]; - AspeedI3CDevice devices[ASPEED_I3C_NR_DEVICES]; + DWI3C devices[ASPEED_I3C_NR_DEVICES]; + uint8_t id; } AspeedI3CState; #endif /* ASPEED_I3C_H */ diff --git a/include/hw/i3c/dw-i3c.h b/include/hw/i3c/dw-i3c.h new file mode 100644 index 0000000000..214f5ffed2 --- /dev/null +++ b/include/hw/i3c/dw-i3c.h @@ -0,0 +1,35 @@ +/* + * DesignWare I3C Controller + * + * Copyright (C) 2021 ASPEED Technology Inc. + * Copyright (C) 2025 Google, LLC. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef DW_I3C_H +#define DW_I3C_H + +#include "hw/sysbus.h" + +#define TYPE_DW_I3C "dw.i3c" +OBJECT_DECLARE_SIMPLE_TYPE(DWI3C, DW_I3C) + +#define DW_I3C_NR_REGS (0x300 >> 2) + +typedef struct DWI3C { + /* */ + SysBusDevice parent; + + /* */ + MemoryRegion mr; + qemu_irq irq; + + uint8_t id; + uint32_t regs[DW_I3C_NR_REGS]; +} DWI3C; + +/* Extern for other controllers that use DesignWare I3C. */ +extern const VMStateDescription vmstate_dw_i3c; + +#endif /* DW_I3C_H */ --=20 2.50.0.rc1.591.g9c95f17f64-goog From nobody Sat Nov 15 16:09:06 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1749773127; cv=none; d=zohomail.com; s=zohoarc; b=O1JoqaQ2/ATodPCaVLxXmH9to26V9rJ4UanYKK0Swqui11vZUM5VzvEMZCodxdwd1lBI6ddhxNEjQDhNQecb9b5cl3nQCJyrT016Z/DjBGH6gu1omWbLuZDkxcp4upBdo3AzZ8kzzx0KDcLenKCppL3ZAZIuW+hWGOywt72ftLk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749773127; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=yV4kGwbpp1m9FhU4yzA1jnn6GM9g9YaJoL8u1HuZLk4=; b=F9kosot0v6eLqTTNXEpKL/h9pRdflwJKpjaCvuT4trl34L0xx0euZkrfHLK/nq+gkCPuQCXVLylVysrRvZOjJcpnkhVAUj1jlOEomymbTKUGlhMCuqUbBzGYjUliyG+u1b1NjFDthe6hTDhbHynhDPLneYbf1PwgkEZudU134pc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749773127944642.0028447297067; Thu, 12 Jun 2025 17:05:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPruD-0005pB-Dr; Thu, 12 Jun 2025 20:04:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3AmtLaAcKCk815325uzx55x2v.t537v3B-uvCv2454x4B.58x@flex--komlodi.bounces.google.com>) id 1uPruA-0005n1-D3 for qemu-devel@nongnu.org; Thu, 12 Jun 2025 20:04:22 -0400 Received: from mail-pl1-x64a.google.com ([2607:f8b0:4864:20::64a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3AmtLaAcKCk815325uzx55x2v.t537v3B-uvCv2454x4B.58x@flex--komlodi.bounces.google.com>) id 1uPru7-0000XN-Qa for qemu-devel@nongnu.org; Thu, 12 Jun 2025 20:04:22 -0400 Received: by mail-pl1-x64a.google.com with SMTP id d9443c01a7336-2358de17665so13421045ad.3 for ; Thu, 12 Jun 2025 17:04:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1749773058; x=1750377858; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=yV4kGwbpp1m9FhU4yzA1jnn6GM9g9YaJoL8u1HuZLk4=; b=2RbQc45IgQTor61EZMPrnidJHE4LfByPrS5Xns6GGNU1ioRcWoq8d65tmPvGVASAIH BER6G3D/BQ+bgtdrUUiK1HqpRQt6McJ20nvKARJagA4iibIyBUps3+5J2sYlbNm01Ru8 tb38mOLls7Nz/r3yzm4A5quJVg//wxv3Yf3UxWGl1+CgEQOUxzWZU+ktWs99LI2d030v lS5M2bFp+UmcC3fXCH9Zj0tIc8KdYybOVC9OEdvydvHCqEREg8WGynSdvA6doO0AAyDH Lc79vLkOBiUthQ6AD0etS0+XlpY/DA7ASBKMGubqxZbCFVpWP+k2xHT3NwvuKvv0qx8g cPAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749773058; x=1750377858; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=yV4kGwbpp1m9FhU4yzA1jnn6GM9g9YaJoL8u1HuZLk4=; b=LcPvrnM0jesOpQtQkV2NgBL911oNdox756kGc0yuS27Mh3TvxZ0EUehPsheefMyRvj 0AwosAlhamoGqViwA8SgycMPKBxzF/lfc/3+kyLIpfdlWCEHI+5nIVYf8dc768nmQ3Ct z34BQGjTPPVWnLKe0oYeojUXA9vYh7ncH2mAYDzWYW56qXrZYcsCn0zcvK0Baxlswiic tme1ODeXItSjGwpXEgPzGrNwbn3ywzbs4jar1xREDnwMdgflP7r5JifhMnrCV52an8AP KIe14AP6krVppQotXMhxvs19XvLzs95IlsmJXCgt0H0NnzJq7KsjCzY3Iv4kA3fJ0ixs yiqA== X-Gm-Message-State: AOJu0YyyVDvQTugwMqYkIB4GfLbM5dwJqNIkVmszW/2kpvA4qVSzeY4Q f/3/F77jnS9z/aM67lS+iGYOuwCFVtnybOu2edquzOj2aS7BQLcGwGtTmY3T3ijMM0keMDp31YY 7xRd3eQC7jpblySiKoxQmGIPlE2VGmm/Wiy+5dXrSGL2/XngMYxFnMlWpjmTrhGV0bXX8AX45cE ZXwHIN7WmRc7niQKAkuNI5YqkLxEwZmB+liXjgMQWo X-Google-Smtp-Source: AGHT+IEItkmlqA0nh1bG1USlq32Zt0fVXVjxOFcC3qqim18euF/XBFRjLkEEWdkTrdMxTUkzZ/cMfsMRYUg0 X-Received: from pgg12.prod.google.com ([2002:a05:6a02:4d8c:b0:b1f:dd75:de2a]) (user=komlodi job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:3205:b0:234:b131:15a with SMTP id d9443c01a7336-2365d8880f8mr14744295ad.4.1749773058144; Thu, 12 Jun 2025 17:04:18 -0700 (PDT) Date: Fri, 13 Jun 2025 00:03:56 +0000 In-Reply-To: <20250613000411.1516521-1-komlodi@google.com> Mime-Version: 1.0 References: <20250613000411.1516521-1-komlodi@google.com> X-Mailer: git-send-email 2.50.0.rc1.591.g9c95f17f64-goog Message-ID: <20250613000411.1516521-5-komlodi@google.com> Subject: [PATCH 04/19] hw/i3c/dw-i3c: Add more register fields From: Joe Komlodi To: qemu-devel@nongnu.org Cc: venture@google.com, komlodi@google.com, clg@kaod.org, peter.maydell@linaro.org, steven_lee@aspeedtech.com, leetroy@gmail.com, jamin_lin@aspeedtech.com, andrew@codeconstruct.com.au, joel@jms.id.au, qemu-arm@nongnu.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::64a; envelope-from=3AmtLaAcKCk815325uzx55x2v.t537v3B-uvCv2454x4B.58x@flex--komlodi.bounces.google.com; helo=mail-pl1-x64a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UPPERCASE_75_100=0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1749773130153116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Adds the rest of the Designware register fields. Signed-off-by: Joe Komlodi Reviewed-by: Patrick Venture --- hw/i3c/dw-i3c.c | 216 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 216 insertions(+) diff --git a/hw/i3c/dw-i3c.c b/hw/i3c/dw-i3c.c index 4b1a3f3f07..b252903ea4 100644 --- a/hw/i3c/dw-i3c.c +++ b/hw/i3c/dw-i3c.c @@ -19,54 +19,270 @@ #include "trace.h" =20 REG32(DEVICE_CTRL, 0x00) + FIELD(DEVICE_CTRL, I3C_BROADCAST_ADDR_INC, 0, 1) + FIELD(DEVICE_CTRL, I2C_SLAVE_PRESENT, 7, 1) + FIELD(DEVICE_CTRL, HOT_JOIN_ACK_NACK_CTRL, 8, 1) + FIELD(DEVICE_CTRL, IDLE_CNT_MULTIPLIER, 24, 2) + FIELD(DEVICE_CTRL, SLV_ADAPT_TO_I2C_I3C_MODE, 27, 1) + FIELD(DEVICE_CTRL, DMA_HANDSHAKE_EN, 28, 1) + FIELD(DEVICE_CTRL, I3C_ABORT, 29, 1) + FIELD(DEVICE_CTRL, I3C_RESUME, 30, 1) + FIELD(DEVICE_CTRL, I3C_EN, 31, 1) REG32(DEVICE_ADDR, 0x04) + FIELD(DEVICE_ADDR, STATIC_ADDR, 0, 7) + FIELD(DEVICE_ADDR, STATIC_ADDR_VALID, 15, 1) + FIELD(DEVICE_ADDR, DYNAMIC_ADDR, 16, 7) + FIELD(DEVICE_ADDR, DYNAMIC_ADDR_VALID, 15, 1) REG32(HW_CAPABILITY, 0x08) + FIELD(HW_CAPABILITY, DEVICE_ROLE_CONFIG, 0, 2) + FIELD(HW_CAPABILITY, HDR_DDR, 3, 1) + FIELD(HW_CAPABILITY, HDR_TS, 4, 1) REG32(COMMAND_QUEUE_PORT, 0x0c) + FIELD(COMMAND_QUEUE_PORT, CMD_ATTR, 0, 3) + /* Transfer command structure */ + FIELD(COMMAND_QUEUE_PORT, TID, 3, 4) + FIELD(COMMAND_QUEUE_PORT, CMD, 7, 8) + FIELD(COMMAND_QUEUE_PORT, CP, 15, 1) + FIELD(COMMAND_QUEUE_PORT, DEV_INDEX, 16, 5) + FIELD(COMMAND_QUEUE_PORT, SPEED, 21, 3) + FIELD(COMMAND_QUEUE_PORT, ROC, 26, 1) + FIELD(COMMAND_QUEUE_PORT, SDAP, 27, 1) + FIELD(COMMAND_QUEUE_PORT, RNW, 28, 1) + FIELD(COMMAND_QUEUE_PORT, TOC, 30, 1) + FIELD(COMMAND_QUEUE_PORT, PEC, 31, 1) + /* Transfer argument data structure */ + FIELD(COMMAND_QUEUE_PORT, DB, 8, 8) + FIELD(COMMAND_QUEUE_PORT, DL, 16, 16) + /* Short data argument data structure */ + FIELD(COMMAND_QUEUE_PORT, BYTE_STRB, 3, 3) + FIELD(COMMAND_QUEUE_PORT, BYTE0, 8, 8) + FIELD(COMMAND_QUEUE_PORT, BYTE1, 16, 8) + FIELD(COMMAND_QUEUE_PORT, BYTE2, 24, 8) + /* Address assignment command structure */ + /* + * bits 3..21 and 26..31 are the same as the transfer command structur= e, or + * marked as reserved. + */ + FIELD(COMMAND_QUEUE_PORT, DEV_COUNT, 21, 3) REG32(RESPONSE_QUEUE_PORT, 0x10) + FIELD(RESPONSE_QUEUE_PORT, DL, 0, 16) + FIELD(RESPONSE_QUEUE_PORT, CCCT, 16, 8) + FIELD(RESPONSE_QUEUE_PORT, TID, 24, 4) + FIELD(RESPONSE_QUEUE_PORT, ERR_STATUS, 28, 4) REG32(RX_TX_DATA_PORT, 0x14) REG32(IBI_QUEUE_STATUS, 0x18) + FIELD(IBI_QUEUE_STATUS, IBI_DATA_LEN, 0, 8) + FIELD(IBI_QUEUE_STATUS, IBI_ID, 8, 8) + FIELD(IBI_QUEUE_STATUS, LAST_STATUS, 24, 1) + FIELD(IBI_QUEUE_STATUS, ERROR, 30, 1) + FIELD(IBI_QUEUE_STATUS, IBI_STATUS, 31, 1) REG32(IBI_QUEUE_DATA, 0x18) REG32(QUEUE_THLD_CTRL, 0x1c) + FIELD(QUEUE_THLD_CTRL, CMD_BUF_EMPTY_THLD, 0, 8); + FIELD(QUEUE_THLD_CTRL, RESP_BUF_THLD, 8, 8); + FIELD(QUEUE_THLD_CTRL, IBI_DATA_THLD, 16, 8); + FIELD(QUEUE_THLD_CTRL, IBI_STATUS_THLD, 24, 8); REG32(DATA_BUFFER_THLD_CTRL, 0x20) + FIELD(DATA_BUFFER_THLD_CTRL, TX_BUF_THLD, 0, 3) + FIELD(DATA_BUFFER_THLD_CTRL, RX_BUF_THLD, 10, 3) + FIELD(DATA_BUFFER_THLD_CTRL, TX_START_THLD, 16, 3) + FIELD(DATA_BUFFER_THLD_CTRL, RX_START_THLD, 24, 3) REG32(IBI_QUEUE_CTRL, 0x24) + FIELD(IBI_QUEUE_CTRL, NOTIFY_REJECTED_HOT_JOIN, 0, 1) + FIELD(IBI_QUEUE_CTRL, NOTIFY_REJECTED_MASTER_REQ, 1, 1) + FIELD(IBI_QUEUE_CTRL, NOTIFY_REJECTED_SLAVE_IRQ, 3, 1) REG32(IBI_MR_REQ_REJECT, 0x2c) REG32(IBI_SIR_REQ_REJECT, 0x30) REG32(RESET_CTRL, 0x34) + FIELD(RESET_CTRL, CORE_RESET, 0, 1) + FIELD(RESET_CTRL, CMD_QUEUE_RESET, 1, 1) + FIELD(RESET_CTRL, RESP_QUEUE_RESET, 2, 1) + FIELD(RESET_CTRL, TX_BUF_RESET, 3, 1) + FIELD(RESET_CTRL, RX_BUF_RESET, 4, 1) + FIELD(RESET_CTRL, IBI_QUEUE_RESET, 5, 1) REG32(SLV_EVENT_CTRL, 0x38) + FIELD(SLV_EVENT_CTRL, SLV_INTERRUPT, 0, 1) + FIELD(SLV_EVENT_CTRL, MASTER_INTERRUPT, 1, 1) + FIELD(SLV_EVENT_CTRL, HOT_JOIN_INTERRUPT, 3, 1) + FIELD(SLV_EVENT_CTRL, ACTIVITY_STATE, 4, 2) + FIELD(SLV_EVENT_CTRL, MRL_UPDATED, 6, 1) + FIELD(SLV_EVENT_CTRL, MWL_UPDATED, 7, 1) REG32(INTR_STATUS, 0x3c) + FIELD(INTR_STATUS, TX_THLD, 0, 1) + FIELD(INTR_STATUS, RX_THLD, 1, 1) + FIELD(INTR_STATUS, IBI_THLD, 2, 1) + FIELD(INTR_STATUS, CMD_QUEUE_RDY, 3, 1) + FIELD(INTR_STATUS, RESP_RDY, 4, 1) + FIELD(INTR_STATUS, TRANSFER_ABORT, 5, 1) + FIELD(INTR_STATUS, CCC_UPDATED, 6, 1) + FIELD(INTR_STATUS, DYN_ADDR_ASSGN, 8, 1) + FIELD(INTR_STATUS, TRANSFER_ERR, 9, 1) + FIELD(INTR_STATUS, DEFSLV, 10, 1) + FIELD(INTR_STATUS, READ_REQ_RECV, 11, 1) + FIELD(INTR_STATUS, IBI_UPDATED, 12, 1) + FIELD(INTR_STATUS, BUSOWNER_UPDATED, 13, 1) REG32(INTR_STATUS_EN, 0x40) + FIELD(INTR_STATUS_EN, TX_THLD, 0, 1) + FIELD(INTR_STATUS_EN, RX_THLD, 1, 1) + FIELD(INTR_STATUS_EN, IBI_THLD, 2, 1) + FIELD(INTR_STATUS_EN, CMD_QUEUE_RDY, 3, 1) + FIELD(INTR_STATUS_EN, RESP_RDY, 4, 1) + FIELD(INTR_STATUS_EN, TRANSFER_ABORT, 5, 1) + FIELD(INTR_STATUS_EN, CCC_UPDATED, 6, 1) + FIELD(INTR_STATUS_EN, DYN_ADDR_ASSGN, 8, 1) + FIELD(INTR_STATUS_EN, TRANSFER_ERR, 9, 1) + FIELD(INTR_STATUS_EN, DEFSLV, 10, 1) + FIELD(INTR_STATUS_EN, READ_REQ_RECV, 11, 1) + FIELD(INTR_STATUS_EN, IBI_UPDATED, 12, 1) + FIELD(INTR_STATUS_EN, BUSOWNER_UPDATED, 13, 1) REG32(INTR_SIGNAL_EN, 0x44) + FIELD(INTR_SIGNAL_EN, TX_THLD, 0, 1) + FIELD(INTR_SIGNAL_EN, RX_THLD, 1, 1) + FIELD(INTR_SIGNAL_EN, IBI_THLD, 2, 1) + FIELD(INTR_SIGNAL_EN, CMD_QUEUE_RDY, 3, 1) + FIELD(INTR_SIGNAL_EN, RESP_RDY, 4, 1) + FIELD(INTR_SIGNAL_EN, TRANSFER_ABORT, 5, 1) + FIELD(INTR_SIGNAL_EN, CCC_UPDATED, 6, 1) + FIELD(INTR_SIGNAL_EN, DYN_ADDR_ASSGN, 8, 1) + FIELD(INTR_SIGNAL_EN, TRANSFER_ERR, 9, 1) + FIELD(INTR_SIGNAL_EN, DEFSLV, 10, 1) + FIELD(INTR_SIGNAL_EN, READ_REQ_RECV, 11, 1) + FIELD(INTR_SIGNAL_EN, IBI_UPDATED, 12, 1) + FIELD(INTR_SIGNAL_EN, BUSOWNER_UPDATED, 13, 1) REG32(INTR_FORCE, 0x48) + FIELD(INTR_FORCE, TX_THLD, 0, 1) + FIELD(INTR_FORCE, RX_THLD, 1, 1) + FIELD(INTR_FORCE, IBI_THLD, 2, 1) + FIELD(INTR_FORCE, CMD_QUEUE_RDY, 3, 1) + FIELD(INTR_FORCE, RESP_RDY, 4, 1) + FIELD(INTR_FORCE, TRANSFER_ABORT, 5, 1) + FIELD(INTR_FORCE, CCC_UPDATED, 6, 1) + FIELD(INTR_FORCE, DYN_ADDR_ASSGN, 8, 1) + FIELD(INTR_FORCE, TRANSFER_ERR, 9, 1) + FIELD(INTR_FORCE, DEFSLV, 10, 1) + FIELD(INTR_FORCE, READ_REQ_RECV, 11, 1) + FIELD(INTR_FORCE, IBI_UPDATED, 12, 1) + FIELD(INTR_FORCE, BUSOWNER_UPDATED, 13, 1) REG32(QUEUE_STATUS_LEVEL, 0x4c) + FIELD(QUEUE_STATUS_LEVEL, CMD_QUEUE_EMPTY_LOC, 0, 8) + FIELD(QUEUE_STATUS_LEVEL, RESP_BUF_BLR, 8, 8) + FIELD(QUEUE_STATUS_LEVEL, IBI_BUF_BLR, 16, 8) + FIELD(QUEUE_STATUS_LEVEL, IBI_STATUS_CNT, 24, 5) REG32(DATA_BUFFER_STATUS_LEVEL, 0x50) + FIELD(DATA_BUFFER_STATUS_LEVEL, TX_BUF_EMPTY_LOC, 0, 8) + FIELD(DATA_BUFFER_STATUS_LEVEL, RX_BUF_BLR, 16, 8) REG32(PRESENT_STATE, 0x54) + FIELD(PRESENT_STATE, SCL_LINE_SIGNAL_LEVEL, 0, 1) + FIELD(PRESENT_STATE, SDA_LINE_SIGNAL_LEVEL, 1, 1) + FIELD(PRESENT_STATE, CURRENT_MASTER, 2, 1) + FIELD(PRESENT_STATE, CM_TFR_STATUS, 8, 6) + FIELD(PRESENT_STATE, CM_TFR_ST_STATUS, 16, 6) + FIELD(PRESENT_STATE, CMD_TID, 24, 4) REG32(CCC_DEVICE_STATUS, 0x58) + FIELD(CCC_DEVICE_STATUS, PENDING_INTR, 0, 4) + FIELD(CCC_DEVICE_STATUS, PROTOCOL_ERR, 4, 2) + FIELD(CCC_DEVICE_STATUS, ACTIVITY_MODE, 6, 2) + FIELD(CCC_DEVICE_STATUS, UNDER_ERR, 8, 1) + FIELD(CCC_DEVICE_STATUS, SLV_BUSY, 9, 1) + FIELD(CCC_DEVICE_STATUS, OVERFLOW_ERR, 10, 1) + FIELD(CCC_DEVICE_STATUS, DATA_NOT_READY, 11, 1) + FIELD(CCC_DEVICE_STATUS, BUFFER_NOT_AVAIL, 12, 1) REG32(DEVICE_ADDR_TABLE_POINTER, 0x5c) FIELD(DEVICE_ADDR_TABLE_POINTER, DEPTH, 16, 16) FIELD(DEVICE_ADDR_TABLE_POINTER, ADDR, 0, 16) REG32(DEV_CHAR_TABLE_POINTER, 0x60) + FIELD(DEV_CHAR_TABLE_POINTER, P_DEV_CHAR_TABLE_START_ADDR, 0, 12) + FIELD(DEV_CHAR_TABLE_POINTER, DEV_CHAR_TABLE_DEPTH, 12, 7) + FIELD(DEV_CHAR_TABLE_POINTER, PRESENT_DEV_CHAR_TABLE_INDEX, 19, 3) REG32(VENDOR_SPECIFIC_REG_POINTER, 0x6c) + FIELD(VENDOR_SPECIFIC_REG_POINTER, P_VENDOR_REG_START_ADDR, 0, 16) REG32(SLV_MIPI_PID_VALUE, 0x70) REG32(SLV_PID_VALUE, 0x74) + FIELD(SLV_PID_VALUE, SLV_PID_DCR, 0, 12) + FIELD(SLV_PID_VALUE, SLV_INST_ID, 12, 4) + FIELD(SLV_PID_VALUE, SLV_PART_ID, 16, 16) REG32(SLV_CHAR_CTRL, 0x78) + FIELD(SLV_CHAR_CTRL, BCR, 0, 8) + FIELD(SLV_CHAR_CTRL, DCR, 8, 8) + FIELD(SLV_CHAR_CTRL, HDR_CAP, 16, 8) REG32(SLV_MAX_LEN, 0x7c) + FIELD(SLV_MAX_LEN, MWL, 0, 16) + FIELD(SLV_MAX_LEN, MRL, 16, 16) REG32(MAX_READ_TURNAROUND, 0x80) REG32(MAX_DATA_SPEED, 0x84) REG32(SLV_DEBUG_STATUS, 0x88) REG32(SLV_INTR_REQ, 0x8c) + FIELD(SLV_INTR_REQ, SIR, 0, 1) + FIELD(SLV_INTR_REQ, SIR_CTRL, 1, 2) + FIELD(SLV_INTR_REQ, MIR, 3, 1) + FIELD(SLV_INTR_REQ, TS, 4, 1) + FIELD(SLV_INTR_REQ, IBI_STS, 8, 2) + FIELD(SLV_INTR_REQ, MDB, 8, 8) + FIELD(SLV_INTR_REQ, SIR_DATA_LEN, 16, 8) +REG32(SLV_TSX_SYMBL_TIMING, 0x90) + FIELD(SLV_TSX_SYMBL_TIMING, SLV_TSX_SYMBL_CNT, 0, 6) +REG32(SLV_SIR_DATA, 0x94) + FIELD(SLV_SIR_DATA, SIR_DATA_BYTE0, 0, 8) + FIELD(SLV_SIR_DATA, SIR_DATA_BYTE1, 8, 8) + FIELD(SLV_SIR_DATA, SIR_DATA_BYTE2, 16, 8) + FIELD(SLV_SIR_DATA, SIR_DATA_BYTE3, 24, 8) +REG32(SLV_IBI_RESP, 0x98) + FIELD(SLV_IBI_RESP, IBI_STS, 0, 2) + FIELD(SLV_IBI_RESP, SIR_RESP_DATA_LEN, 8, 16) REG32(DEVICE_CTRL_EXTENDED, 0xb0) + FIELD(DEVICE_CTRL_EXTENDED, MODE, 0, 2) + FIELD(DEVICE_CTRL_EXTENDED, REQMST_ACK_CTRL, 3, 1) REG32(SCL_I3C_OD_TIMING, 0xb4) + FIELD(SCL_I3C_OD_TIMING, I3C_OD_LCNT, 0, 8) + FIELD(SCL_I3C_OD_TIMING, I3C_OD_HCNT, 16, 8) REG32(SCL_I3C_PP_TIMING, 0xb8) + FIELD(SCL_I3C_PP_TIMING, I3C_PP_LCNT, 0, 8) + FIELD(SCL_I3C_PP_TIMING, I3C_PP_HCNT, 16, 8) REG32(SCL_I2C_FM_TIMING, 0xbc) REG32(SCL_I2C_FMP_TIMING, 0xc0) + FIELD(SCL_I2C_FMP_TIMING, I2C_FMP_LCNT, 0, 16) + FIELD(SCL_I2C_FMP_TIMING, I2C_FMP_HCNT, 16, 8) REG32(SCL_EXT_LCNT_TIMING, 0xc8) REG32(SCL_EXT_TERMN_LCNT_TIMING, 0xcc) REG32(BUS_FREE_TIMING, 0xd4) REG32(BUS_IDLE_TIMING, 0xd8) + FIELD(BUS_IDLE_TIMING, BUS_IDLE_TIME, 0, 20) REG32(I3C_VER_ID, 0xe0) REG32(I3C_VER_TYPE, 0xe4) REG32(EXTENDED_CAPABILITY, 0xe8) + FIELD(EXTENDED_CAPABILITY, APP_IF_MODE, 0, 2) + FIELD(EXTENDED_CAPABILITY, APP_IF_DATA_WIDTH, 2, 2) + FIELD(EXTENDED_CAPABILITY, OPERATION_MODE, 4, 2) + FIELD(EXTENDED_CAPABILITY, CLK_PERIOD, 8, 6) REG32(SLAVE_CONFIG, 0xec) + FIELD(SLAVE_CONFIG, DMA_EN, 0, 1) + FIELD(SLAVE_CONFIG, HJ_CAP, 0, 1) + FIELD(SLAVE_CONFIG, CLK_PERIOD, 2, 14) +/* Device characteristic table fields */ +REG32(DEVICE_CHARACTERISTIC_TABLE_LOC1, 0x200) +REG32(DEVICE_CHARACTERISTIC_TABLE_LOC_SECONDARY, 0x200) + FIELD(DEVICE_CHARACTERISTIC_TABLE_LOC_SECONDARY, DYNAMIC_ADDR, 0, 8) + FIELD(DEVICE_CHARACTERISTIC_TABLE_LOC_SECONDARY, DCR, 8, 8) + FIELD(DEVICE_CHARACTERISTIC_TABLE_LOC_SECONDARY, BCR, 16, 8) + FIELD(DEVICE_CHARACTERISTIC_TABLE_LOC_SECONDARY, STATIC_ADDR, 24, 8) +REG32(DEVICE_CHARACTERISTIC_TABLE_LOC2, 0x204) + FIELD(DEVICE_CHARACTERISTIC_TABLE_LOC2, MSB_PID, 0, 16) +REG32(DEVICE_CHARACTERISTIC_TABLE_LOC3, 0x208) + FIELD(DEVICE_CHARACTERISTIC_TABLE_LOC3, DCR, 0, 8) + FIELD(DEVICE_CHARACTERISTIC_TABLE_LOC3, BCR, 8, 8) +REG32(DEVICE_CHARACTERISTIC_TABLE_LOC4, 0x20c) + FIELD(DEVICE_CHARACTERISTIC_TABLE_LOC4, DEV_DYNAMIC_ADDR, 0, 8) +/* Dev addr table fields */ +REG32(DEVICE_ADDR_TABLE_LOC1, 0x280) + FIELD(DEVICE_ADDR_TABLE_LOC1, DEV_STATIC_ADDR, 0, 7) + FIELD(DEVICE_ADDR_TABLE_LOC1, IBI_PEC_EN, 11, 1) + FIELD(DEVICE_ADDR_TABLE_LOC1, IBI_WITH_DATA, 12, 1) + FIELD(DEVICE_ADDR_TABLE_LOC1, SIR_REJECT, 13, 1) + FIELD(DEVICE_ADDR_TABLE_LOC1, MR_REJECT, 14, 1) + FIELD(DEVICE_ADDR_TABLE_LOC1, DEV_DYNAMIC_ADDR, 16, 8) + FIELD(DEVICE_ADDR_TABLE_LOC1, IBI_ADDR_MASK, 24, 2) + FIELD(DEVICE_ADDR_TABLE_LOC1, DEV_NACK_RETRY_CNT, 29, 2) + FIELD(DEVICE_ADDR_TABLE_LOC1, LEGACY_I2C_DEVICE, 31, 1) =20 static const uint32_t dw_i3c_resets[DW_I3C_NR_REGS] =3D { [R_HW_CAPABILITY] =3D 0x000e00bf, --=20 2.50.0.rc1.591.g9c95f17f64-goog From nobody Sat Nov 15 16:09:06 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1749773249; cv=none; d=zohomail.com; s=zohoarc; b=e6o3lyqayqxOOdMqeiQb2j6rgNWAifJmaq9wizy0fjvtWbKYUlAJOw6AL8jsYoKcq/ZZrr7ZkTkTXAVsp3kQXNt6iCVOO+OhfnCDah3/gbGgLrqpd7eU0N68sCNddi91o8v4NMXoBg4KuykjZVeG1ahe5FHTvU9Ae+ZUA6nansA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749773249; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=tPtGaQ6vCtmF19bKh+Rkwj9EooYkX69QK4ltOQGJ2bM=; b=flIGt4LsUc8o3EuqLaW2C35N2Ogy8oZhxUUj55gc7wZHbK4975hXI0Wj9HmQKc9S0kvHBURqfqGHsoZkbJEXOsHTpJbseH3+8ml0AThj9wB7ICil31pjvrzF30Z0YsdEwd1shdKhOWaDlJvbMHvMW2n+hwhsAWD0ViID/znP4gQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 174977324902665.30429883538784; Thu, 12 Jun 2025 17:07:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPruE-0005pL-VV; Thu, 12 Jun 2025 20:04:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3A2tLaAcKClA26436v0y66y3w.u648w4C-vwDw3565y5C.69y@flex--komlodi.bounces.google.com>) id 1uPruB-0005nm-It for qemu-devel@nongnu.org; Thu, 12 Jun 2025 20:04:23 -0400 Received: from mail-pg1-x54a.google.com ([2607:f8b0:4864:20::54a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3A2tLaAcKClA26436v0y66y3w.u648w4C-vwDw3565y5C.69y@flex--komlodi.bounces.google.com>) id 1uPru9-0000Xc-Pl for qemu-devel@nongnu.org; Thu, 12 Jun 2025 20:04:23 -0400 Received: by mail-pg1-x54a.google.com with SMTP id 41be03b00d2f7-af59547f55bso928302a12.0 for ; Thu, 12 Jun 2025 17:04:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1749773060; x=1750377860; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=tPtGaQ6vCtmF19bKh+Rkwj9EooYkX69QK4ltOQGJ2bM=; b=jyKoxpcuV5ZlR+dJ0mSSFxDw1N5UUhDmcRsJWyQXiTBjqZDNHzrFkHCizdowVgOOME CQAvcOFXt3LpeVnSvBjCCJXjQstRvy2+JQhNW0GzUh4LIbU21IKJyy584ijwr57R+rPF 58dxrgMf2kupiBKQST9GLA/muZRG6y9oLIjamW/bxqgoZ+jfIbfiqjQLrqP33/5mj2JY kfNU/UzL3d1LSH13XDTxz3tK7ZP4cMtI4RE22fFt4Dy4HGPXj/LFcK1KJo12aXXcQbac YWE+Th8aMs+Zthb5iOG8S1vqvM1lbSunTxOJE5sedcEWKvQ/ZHmLJLLYIERtDeAbHKKq PBmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749773060; x=1750377860; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=tPtGaQ6vCtmF19bKh+Rkwj9EooYkX69QK4ltOQGJ2bM=; b=gYrSF+iK/Nii3YCXYXpMjr8EpoRyB8PpdGoZf+Rq7DMUkny8NTxX5esVFYJly3IiPd lP+GI0w7jTy40zipPCBwK/dcIBI/aIdXOYnUzrEzSY7ngkbkhijsra5pDivqQsHqVbkh A8aqSfxTJpfrjFETCC0/xhBKm1bOSgxSpRhgYZufEGasE8ui4hF3SOCyJPkGANbJeDRL PuNtEWrpiXaxXPnXsbUfPPzU0yA5X3el2oq9HsRdhJPtpcELjGDYR+xccgb8bGHEE++W /Bgpp+Zgr6zLSUon+R3ZAG+51vE99EJsFNeXln8zc5uuB8aQj5MFzWpdDgmtuuZL5J2J /l0Q== X-Gm-Message-State: AOJu0YzdL74LummLXodtDygn/BxjiQIe+RuNRjoLpv61hLYi2GraVy5y WZWsSj3bJ7Hc8wzATP7KgyrhVD4n40n5RWpXDd9t/4gwbQ4qr+4mtsEYpDxPztYD8tKh5lhJrar IgX9ZGcB55ZM68nshjhEreFICm1bB0LuXYhzoQLN2JOfyqncrBjiKb1CR6w42QZDTzytzRAjTHk hXKE3HxX++8fJb1DU3CZPwMg8N3vzOt2aeMqWfXznm X-Google-Smtp-Source: AGHT+IE+wKtidJQQHaeAv26xb51vHC11aupnISz/rbqHPp8ZlgD6ID3Yf9t5RGWbCHWE8prPxAbGShLFDUqn X-Received: from pgbdi9.prod.google.com ([2002:a05:6a02:c09:b0:b2c:3afe:6ece]) (user=komlodi job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:914f:b0:1f3:41d5:65f6 with SMTP id adf61e73a8af0-21faced23acmr1337373637.32.1749773059627; Thu, 12 Jun 2025 17:04:19 -0700 (PDT) Date: Fri, 13 Jun 2025 00:03:57 +0000 In-Reply-To: <20250613000411.1516521-1-komlodi@google.com> Mime-Version: 1.0 References: <20250613000411.1516521-1-komlodi@google.com> X-Mailer: git-send-email 2.50.0.rc1.591.g9c95f17f64-goog Message-ID: <20250613000411.1516521-6-komlodi@google.com> Subject: [PATCH 05/19] hw/i3c/aspeed_i3c: Add more register fields From: Joe Komlodi To: qemu-devel@nongnu.org Cc: venture@google.com, komlodi@google.com, clg@kaod.org, peter.maydell@linaro.org, steven_lee@aspeedtech.com, leetroy@gmail.com, jamin_lin@aspeedtech.com, andrew@codeconstruct.com.au, joel@jms.id.au, qemu-arm@nongnu.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::54a; envelope-from=3A2tLaAcKClA26436v0y66y3w.u648w4C-vwDw3565y5C.69y@flex--komlodi.bounces.google.com; helo=mail-pg1-x54a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, UPPERCASE_50_75=0.008, USER_IN_DEF_DKIM_WL=-7.5 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1749773250776116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Adds the rest of the Aspeed I3C controller register fields. Signed-off-by: Joe Komlodi Reviewed-by: Patrick Venture --- hw/i3c/aspeed_i3c.c | 54 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/hw/i3c/aspeed_i3c.c b/hw/i3c/aspeed_i3c.c index cb0332828c..7a16dfec53 100644 --- a/hw/i3c/aspeed_i3c.c +++ b/hw/i3c/aspeed_i3c.c @@ -21,28 +21,58 @@ /* I3C Controller Registers */ REG32(I3C1_REG0, 0x10) REG32(I3C1_REG1, 0x14) - FIELD(I3C1_REG1, I2C_MODE, 0, 1) - FIELD(I3C1_REG1, SA_EN, 15, 1) + FIELD(I3C1_REG1, I2C_MODE, 0, 1) + FIELD(I3C1_REG1, SLV_TEST_MODE, 1, 1) + FIELD(I3C1_REG1, ACT_MODE, 2, 2) + FIELD(I3C1_REG1, PENDING_INT, 4, 4) + FIELD(I3C1_REG1, SA, 8, 7) + FIELD(I3C1_REG1, SA_EN, 15, 1) + FIELD(I3C1_REG1, INST_ID, 16, 4) REG32(I3C2_REG0, 0x20) REG32(I3C2_REG1, 0x24) - FIELD(I3C2_REG1, I2C_MODE, 0, 1) - FIELD(I3C2_REG1, SA_EN, 15, 1) + FIELD(I3C2_REG1, I2C_MODE, 0, 1) + FIELD(I3C2_REG1, SLV_TEST_MODE, 1, 1) + FIELD(I3C2_REG1, ACT_MODE, 2, 2) + FIELD(I3C2_REG1, PENDING_INT, 4, 4) + FIELD(I3C2_REG1, SA, 8, 7) + FIELD(I3C2_REG1, SA_EN, 15, 1) + FIELD(I3C2_REG1, INST_ID, 16, 4) REG32(I3C3_REG0, 0x30) REG32(I3C3_REG1, 0x34) - FIELD(I3C3_REG1, I2C_MODE, 0, 1) - FIELD(I3C3_REG1, SA_EN, 15, 1) + FIELD(I3C3_REG1, I2C_MODE, 0, 1) + FIELD(I3C3_REG1, SLV_TEST_MODE, 1, 1) + FIELD(I3C3_REG1, ACT_MODE, 2, 2) + FIELD(I3C3_REG1, PENDING_INT, 4, 4) + FIELD(I3C3_REG1, SA, 8, 7) + FIELD(I3C3_REG1, SA_EN, 15, 1) + FIELD(I3C3_REG1, INST_ID, 16, 4) REG32(I3C4_REG0, 0x40) REG32(I3C4_REG1, 0x44) - FIELD(I3C4_REG1, I2C_MODE, 0, 1) - FIELD(I3C4_REG1, SA_EN, 15, 1) + FIELD(I3C4_REG1, I2C_MODE, 0, 1) + FIELD(I3C4_REG1, SLV_TEST_MODE, 1, 1) + FIELD(I3C4_REG1, ACT_MODE, 2, 2) + FIELD(I3C4_REG1, PENDING_INT, 4, 4) + FIELD(I3C4_REG1, SA, 8, 7) + FIELD(I3C4_REG1, SA_EN, 15, 1) + FIELD(I3C4_REG1, INST_ID, 16, 4) REG32(I3C5_REG0, 0x50) REG32(I3C5_REG1, 0x54) - FIELD(I3C5_REG1, I2C_MODE, 0, 1) - FIELD(I3C5_REG1, SA_EN, 15, 1) + FIELD(I3C5_REG1, I2C_MODE, 0, 1) + FIELD(I3C5_REG1, SLV_TEST_MODE, 1, 1) + FIELD(I3C5_REG1, ACT_MODE, 2, 2) + FIELD(I3C5_REG1, PENDING_INT, 4, 4) + FIELD(I3C5_REG1, SA, 8, 7) + FIELD(I3C5_REG1, SA_EN, 15, 1) + FIELD(I3C5_REG1, INST_ID, 16, 4) REG32(I3C6_REG0, 0x60) REG32(I3C6_REG1, 0x64) - FIELD(I3C6_REG1, I2C_MODE, 0, 1) - FIELD(I3C6_REG1, SA_EN, 15, 1) + FIELD(I3C6_REG1, I2C_MODE, 0, 1) + FIELD(I3C6_REG1, SLV_TEST_MODE, 1, 1) + FIELD(I3C6_REG1, ACT_MODE, 2, 2) + FIELD(I3C6_REG1, PENDING_INT, 4, 4) + FIELD(I3C6_REG1, SA, 8, 7) + FIELD(I3C6_REG1, SA_EN, 15, 1) + FIELD(I3C6_REG1, INST_ID, 16, 4) =20 static uint64_t aspeed_i3c_read(void *opaque, hwaddr addr, unsigned int si= ze) { --=20 2.50.0.rc1.591.g9c95f17f64-goog From nobody Sat Nov 15 16:09:06 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1749773290; cv=none; d=zohomail.com; s=zohoarc; b=j6pwLYUpIEybNqJZelBc4ZGlXedwKiHVQsbQ2tXGk5PzfDXiPdcGHjc5P+WAFHlnblR9tp4D5JGCcPALfhK9ag541G3pBC/eqW+/JTClDcaiFOjxklLaqzkRSHWUESICxP8i/ijI9MCX2UBMWuiIWY6LeAmxSAMR/gLeE8/kRWs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749773290; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=+3D32wRripWDGh37R/51W0a4xFipOjv3ijoy2qH+SOM=; b=mg73fjtp5rj0MXB9yB+7oE5vakr2dTgPRlgYQ+xqYooB3/klWBtAvzvvzEBCpaqSyxZRl1FUxK64xbAeW0isazMy7Izqaqqye/iiaOcCNLQJ3fTzs/2Su6qXQLlQqsNNr1NThUHNF8xwWCJsYgDVLJC32qLN3IiTEnDrXnG9YKE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749773290204921.1722976923298; Thu, 12 Jun 2025 17:08:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPruL-0005rQ-HM; Thu, 12 Jun 2025 20:04:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3BGtLaAcKClE37547w1z77z4x.v759x5D-wxEx4676z6D.7Az@flex--komlodi.bounces.google.com>) id 1uPruC-0005oO-6H for qemu-devel@nongnu.org; Thu, 12 Jun 2025 20:04:24 -0400 Received: from mail-pg1-x549.google.com ([2607:f8b0:4864:20::549]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3BGtLaAcKClE37547w1z77z4x.v759x5D-wxEx4676z6D.7Az@flex--komlodi.bounces.google.com>) id 1uPruA-0000Y5-NG for qemu-devel@nongnu.org; Thu, 12 Jun 2025 20:04:23 -0400 Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-b0e0c573531so835849a12.3 for ; Thu, 12 Jun 2025 17:04:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1749773061; x=1750377861; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=+3D32wRripWDGh37R/51W0a4xFipOjv3ijoy2qH+SOM=; b=U9+wVJUn3EXHBhrOR7Qsxnmy9VL3KdOa8UCfJB0Btl16YxtcT9n4keRXA2BQ7ImlDQ WI84BvyvpQmw3ywtsmyvYDRLzxCiMMiTLWJp+7FCqobSJ26XkZ+VzgSFN7JqzV5e2wZw S1qFqmufdFpoKy8EgJpDxq/IYE934yILnlJLSx7OOfYVFwhmFpy1udfZoABr30RGaB9g l/l9Rlb0UX1fM9IJlWb17WsU3R9i2sLI7I1kvC8fBeyk0uEZ7qDh3Y0wAP/WOQa+Pxie sz2eKEVrA4saEEdmu+VcA3ApRWCs++cirKF6gHWDwz6tuyfnd2M5N0vlsHU8qh5Vz3t8 56FA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749773061; x=1750377861; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+3D32wRripWDGh37R/51W0a4xFipOjv3ijoy2qH+SOM=; b=Jli0sNhV2Pct2f2M32GYqQi+/BSrJKLDlqGHrAi/cMH9RuzqWGMGgIz439S/jhJbZf Jj/XwNm4QV/dsH5FIOO2NPReG2EmDP+zzJbY72aHViyA6kcjO18FAYcvPwNDrEe2YJ2v rd3b6PH5FrWAFIF7EEbRQ0GX8alE7845EiYnTwQwHWwG75hdQVy8/Jcb/JKbGukf4Ew1 4EJirCSathGqOz5A9I0IqlU6JYUzCDubv8oD2UP2UFCCO4AUy6EclLqpHVSuphc0Mm0A GCfe1lfNnzLh591nNzlqksKNJHdepwI1U+nsKVq/qXFTie4u5DaraqwPMLqe2WTznGVD f5cQ== X-Gm-Message-State: AOJu0YzfHJYXYVOu64wrsXjHbzVa8T2rc2tNWlBFJiRdeyllS2x5oiM6 lo3qfJDhMYdLFkhTdpoME4JkRYgQoAJABPocqmzn6nZyi47xU5NUHIDFfWhbF0/mS+eZApSxNyL caDz/QcpMPGqCnEgfimNahKYgmjd1AZbtdbbq2RNjtinsYeeBetUXYB/hqLvqmcQm6cnMM8/pMq OWIYdAEyi3iAXkV1QAMslYK7kLKrIvK/uc8eZkRYIp X-Google-Smtp-Source: AGHT+IGlnPTM7QeaeaCrToaS2aQ3n7oiYYosCaPN87vXCa/zLMwd/RA/f7cLTESWfAxQGgPJ+kzH8HdYvxnC X-Received: from pgah7.prod.google.com ([2002:a05:6a02:4e87:b0:b2e:b684:1f9e]) (user=komlodi job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:6a25:b0:218:96ad:720d with SMTP id adf61e73a8af0-21facbba984mr1179219637.1.1749773060836; Thu, 12 Jun 2025 17:04:20 -0700 (PDT) Date: Fri, 13 Jun 2025 00:03:58 +0000 In-Reply-To: <20250613000411.1516521-1-komlodi@google.com> Mime-Version: 1.0 References: <20250613000411.1516521-1-komlodi@google.com> X-Mailer: git-send-email 2.50.0.rc1.591.g9c95f17f64-goog Message-ID: <20250613000411.1516521-7-komlodi@google.com> Subject: [PATCH 06/19] hw/i3c/dw-i3c: Add more reset values From: Joe Komlodi To: qemu-devel@nongnu.org Cc: venture@google.com, komlodi@google.com, clg@kaod.org, peter.maydell@linaro.org, steven_lee@aspeedtech.com, leetroy@gmail.com, jamin_lin@aspeedtech.com, andrew@codeconstruct.com.au, joel@jms.id.au, qemu-arm@nongnu.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::549; envelope-from=3BGtLaAcKClE37547w1z77z4x.v759x5D-wxEx4676z6D.7Az@flex--komlodi.bounces.google.com; helo=mail-pg1-x549.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1749773291150116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Adds reset values for the new registers added. Signed-off-by: Joe Komlodi Reviewed-by: Patrick Venture --- hw/i3c/dw-i3c.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/hw/i3c/dw-i3c.c b/hw/i3c/dw-i3c.c index b252903ea4..845fbd5efd 100644 --- a/hw/i3c/dw-i3c.c +++ b/hw/i3c/dw-i3c.c @@ -285,14 +285,32 @@ REG32(DEVICE_ADDR_TABLE_LOC1, 0x280) FIELD(DEVICE_ADDR_TABLE_LOC1, LEGACY_I2C_DEVICE, 31, 1) =20 static const uint32_t dw_i3c_resets[DW_I3C_NR_REGS] =3D { - [R_HW_CAPABILITY] =3D 0x000e00bf, + /* Target mode is not supported, don't advertise it for now. */ + [R_HW_CAPABILITY] =3D 0x000e00b9, [R_QUEUE_THLD_CTRL] =3D 0x01000101, + [R_DATA_BUFFER_THLD_CTRL] =3D 0x01010100, + [R_SLV_EVENT_CTRL] =3D 0x0000000b, + [R_QUEUE_STATUS_LEVEL] =3D 0x00000002, + [R_DATA_BUFFER_STATUS_LEVEL] =3D 0x00000010, + [R_PRESENT_STATE] =3D 0x00000003, [R_I3C_VER_ID] =3D 0x3130302a, [R_I3C_VER_TYPE] =3D 0x6c633033, [R_DEVICE_ADDR_TABLE_POINTER] =3D 0x00080280, [R_DEV_CHAR_TABLE_POINTER] =3D 0x00020200, + [R_SLV_CHAR_CTRL] =3D 0x00010000, [A_VENDOR_SPECIFIC_REG_POINTER] =3D 0x000000b0, [R_SLV_MAX_LEN] =3D 0x00ff00ff, + [R_SLV_TSX_SYMBL_TIMING] =3D 0x0000003f, + [R_SCL_I3C_OD_TIMING] =3D 0x000a0010, + [R_SCL_I3C_PP_TIMING] =3D 0x000a000a, + [R_SCL_I2C_FM_TIMING] =3D 0x00100010, + [R_SCL_I2C_FMP_TIMING] =3D 0x00100010, + [R_SCL_EXT_LCNT_TIMING] =3D 0x20202020, + [R_SCL_EXT_TERMN_LCNT_TIMING] =3D 0x00300000, + [R_BUS_FREE_TIMING] =3D 0x00200020, + [R_BUS_IDLE_TIMING] =3D 0x00000020, + [R_EXTENDED_CAPABILITY] =3D 0x00000239, + [R_SLAVE_CONFIG] =3D 0x00000023, }; =20 static uint64_t dw_i3c_read(void *opaque, hwaddr offset, unsigned size) --=20 2.50.0.rc1.591.g9c95f17f64-goog From nobody Sat Nov 15 16:09:06 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1749773391; cv=none; d=zohomail.com; s=zohoarc; b=nJ7sDC9T+EePDpf0LxNz6RQg+VB52FM1SgWjrTbI5uMkXcu7yePIpaff7AjYBuloyJ4tuRlFjVSLqOvDy2gBb1flqnNgIMWtQ8Fk1J0zXw/EBK8fzrYbvrFhh8TjnvVYONh6HedAnzCh94Vq7akK5P30Sf6c3+k6IU+MmL//8mQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749773391; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=NO1C/XYn0cNc0jJwYcW3jpPIHQxOkwpZejg8rpn/AhI=; b=mNfqMseRV1lIS6tSdE+JBWgcObSEAuyz3GdHHjfXpH1dUfEW1t/hNidWKIp9xMdCcNKwkYDPGzeewRck4bZ57ebkxMi/PCZJG/2EujyNlhHG9Iw7UtU6nGOOyl19WoEDiG2b7Nol2FwujeCexHbJByBdX6Zq1hMFNQdqZFiFLf0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749773391255985.4908619673322; Thu, 12 Jun 2025 17:09:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPrv3-0006FL-R5; Thu, 12 Jun 2025 20:05:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3BmtLaAcKClM59769y319916z.x97Bz7F-yzGz689818F.9C1@flex--komlodi.bounces.google.com>) id 1uPruD-0005pE-MR for qemu-devel@nongnu.org; Thu, 12 Jun 2025 20:04:26 -0400 Received: from mail-pl1-x64a.google.com ([2607:f8b0:4864:20::64a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3BmtLaAcKClM59769y319916z.x97Bz7F-yzGz689818F.9C1@flex--komlodi.bounces.google.com>) id 1uPruC-0000Yb-4e for qemu-devel@nongnu.org; Thu, 12 Jun 2025 20:04:25 -0400 Received: by mail-pl1-x64a.google.com with SMTP id d9443c01a7336-23507382e64so13721565ad.2 for ; Thu, 12 Jun 2025 17:04:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1749773062; x=1750377862; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=NO1C/XYn0cNc0jJwYcW3jpPIHQxOkwpZejg8rpn/AhI=; b=QeUuvCsdXl92znA3t7UbNu+WKqdMnW3G7IFNz9wAPzSnWTLh2d+eJxSu8s5niz0gsO K/X/UbhohwmjpFOBryPHzff4Td2+gWhWX5TtonmzBMB2Q9G1EDEnyKlrqZSEYd2TWu/j iMRn0eoQ0FAHCzZoKejcXqeNeutFqNC76RefV0T46bMlPqW9eGFLaFJqGP4CC2/g5tT/ FxZD1ZrnZL26N1Mv8HDndDdKufM6EYwtL6616Pli1JR2tKv2/Fywl+/v3YrUuAbgwO6A ajpwSKS3qBOfiLd7VvnSQBFL71Rb8klnWxY2FCZgUMxlGShX2Vmcn5LuGk7MUSC9Wt9R pfZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749773062; x=1750377862; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=NO1C/XYn0cNc0jJwYcW3jpPIHQxOkwpZejg8rpn/AhI=; b=Odva11nslluDDRkfGHpTlHZDDO119G71ClQuxfz/Pg0c2JlH68LGYFUXg/zdcBAtlb z0E0823bYCys816DBj6jY7j7lzOqEtcN73TnwmDILHh03oYgOpyMtrMnPZinmtFg1ISV yxD7X95O8I3AlTAt5MFCOgTW0q810bFSyJHUfklndM6TnSccDXyQRy2vTuklBa7M54t+ cJWDx9/5jVMIrKvsFO7TfW+5GXlxv8xU6ViCtI8td6HP4wPr6wiksh5z1ytZ6LHnG8ov OGLFrp2SkLKGMl4fO/tC+4KlaYbvAYgXqaZxZQBsZvl4kffRJNcH7KCLnDw518NT4GBI wcTg== X-Gm-Message-State: AOJu0Yz6bxRJh8bBW8lki7yBgu8Kmo8AIcE/+Emh5jVCxmBYPjseErZk 46VT9NF6XOitmX+39aH0WqjPTCp8El/mUfIP0n8Ccj3KTwZiaro4c8DI4u8YzYGQrQTE5XYD2iQ gVzJbY8MSU9oTeEfBGTYwLXcJJEPV1swXVZwO7lp1lsYUlFF65WVIFeBnyMO/cjzX0mQ/WIKV54 mcxcj4a2QJoYOBpWhVo4hV6sjMvZ7XcRmo09P7YE16 X-Google-Smtp-Source: AGHT+IF9eJQlQuSnGUux3PbemsptH8BHWBlQK73JP4lTFI29QphP1Bx+UKQyMnvHcdm+jIpaXg+9fua7Py1l X-Received: from pgac10.prod.google.com ([2002:a05:6a02:294a:b0:b2c:3a2e:ac7]) (user=komlodi job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:4b2b:b0:235:f45f:ed41 with SMTP id d9443c01a7336-2365d89f25fmr13389855ad.19.1749773062018; Thu, 12 Jun 2025 17:04:22 -0700 (PDT) Date: Fri, 13 Jun 2025 00:03:59 +0000 In-Reply-To: <20250613000411.1516521-1-komlodi@google.com> Mime-Version: 1.0 References: <20250613000411.1516521-1-komlodi@google.com> X-Mailer: git-send-email 2.50.0.rc1.591.g9c95f17f64-goog Message-ID: <20250613000411.1516521-8-komlodi@google.com> Subject: [PATCH 07/19] hw/i3c/aspeed_i3c: Add register RO field masks From: Joe Komlodi To: qemu-devel@nongnu.org Cc: venture@google.com, komlodi@google.com, clg@kaod.org, peter.maydell@linaro.org, steven_lee@aspeedtech.com, leetroy@gmail.com, jamin_lin@aspeedtech.com, andrew@codeconstruct.com.au, joel@jms.id.au, qemu-arm@nongnu.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::64a; envelope-from=3BmtLaAcKClM59769y319916z.x97Bz7F-yzGz689818F.9C1@flex--komlodi.bounces.google.com; helo=mail-pl1-x64a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1749773392220116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Adds read-only register masks for the Aspeed I3C controller registers. Signed-off-by: Joe Komlodi Reviewed-by: Patrick Venture --- hw/i3c/aspeed_i3c.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/hw/i3c/aspeed_i3c.c b/hw/i3c/aspeed_i3c.c index 7a16dfec53..1ad25e5a00 100644 --- a/hw/i3c/aspeed_i3c.c +++ b/hw/i3c/aspeed_i3c.c @@ -74,6 +74,21 @@ REG32(I3C6_REG1, 0x64) FIELD(I3C6_REG1, SA_EN, 15, 1) FIELD(I3C6_REG1, INST_ID, 16, 4) =20 +static const uint32_t ast2600_i3c_controller_ro[ASPEED_I3C_NR_REGS] =3D { + [R_I3C1_REG0] =3D 0xfc000000, + [R_I3C1_REG1] =3D 0xfff00000, + [R_I3C2_REG0] =3D 0xfc000000, + [R_I3C2_REG1] =3D 0xfff00000, + [R_I3C3_REG0] =3D 0xfc000000, + [R_I3C3_REG1] =3D 0xfff00000, + [R_I3C4_REG0] =3D 0xfc000000, + [R_I3C4_REG1] =3D 0xfff00000, + [R_I3C5_REG0] =3D 0xfc000000, + [R_I3C5_REG1] =3D 0xfff00000, + [R_I3C6_REG0] =3D 0xfc000000, + [R_I3C6_REG1] =3D 0xfff00000, +}; + static uint64_t aspeed_i3c_read(void *opaque, hwaddr addr, unsigned int si= ze) { AspeedI3CState *s =3D ASPEED_I3C(opaque); @@ -97,6 +112,7 @@ static void aspeed_i3c_write(void *opaque, =20 addr >>=3D 2; =20 + data &=3D ~ast2600_i3c_controller_ro[addr]; /* I3C controller register */ switch (addr) { case R_I3C1_REG1: --=20 2.50.0.rc1.591.g9c95f17f64-goog From nobody Sat Nov 15 16:09:06 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1749773097; cv=none; d=zohomail.com; s=zohoarc; b=U5oEUgegt04GXdIfZOvkeNEuh2Xe2wBTzL9ek59mAt6Y2eHnmR9rcQEA/txsVSkVHE3xwlYhrcVBz8rvci3Lygh2lsdKQaGeGRaIvBQixEQwaJEncPhPvOfINeSgSpA6t4A2/oNB/HSvUDQ+szS8nmR3GuLoK2CccwbXgpctvTo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749773097; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=p8GFuynGr1nk+VpIO+5MvKgGfqQz5tqawVbKnQiXbx4=; b=jIDX4wQtas51THjauyK9S0vUDIHGvSHTgkTUHryFJlvsNj95lFnlbQQGwwethnpin6bul/cRA8uLwCN/pNSZM06AAerN95NK9GRbqB8pKB2ZUwH+A6ulDjiZ+9oISBYvOUATZmjsf3eR+Nfgm5vAbVyhpAovZSZUspnJhNMW+Wc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749773097141787.9294621134709; Thu, 12 Jun 2025 17:04:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPruK-0005qy-9x; Thu, 12 Jun 2025 20:04:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3B2tLaAcKClQ6A87Az42AA270.yA8C08G-z0H079A929G.AD2@flex--komlodi.bounces.google.com>) id 1uPruF-0005q2-PO for qemu-devel@nongnu.org; Thu, 12 Jun 2025 20:04:27 -0400 Received: from mail-pg1-x549.google.com ([2607:f8b0:4864:20::549]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3B2tLaAcKClQ6A87Az42AA270.yA8C08G-z0H079A929G.AD2@flex--komlodi.bounces.google.com>) id 1uPruD-0000ZA-PG for qemu-devel@nongnu.org; Thu, 12 Jun 2025 20:04:27 -0400 Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-b00e4358a34so921001a12.0 for ; Thu, 12 Jun 2025 17:04:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1749773064; x=1750377864; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=p8GFuynGr1nk+VpIO+5MvKgGfqQz5tqawVbKnQiXbx4=; b=z8id1q9TSumCNdFNNRtbKIKvvlWNKDeYR/6zI/KE/q7qOM5KAcgQjhy05pYffiigR4 F7B5PGh5S9Ryan9FSfidb5DdSXwP11nEH0KFlfFBCUq721Iig7AGrhBu1E7d0ASpjUI7 uyZSoXs9kergOaeOgkDZDukaLy1ssnKDF17pn5hnLD0ZHT7X4SNDDH2G+3vtIA79qjB7 WAVOFMJ2BMEo/qDk48s1oiEMXs6BdZFu/IGwN9akKo2ac6LQ9F5jgkHwjR8hmkgeKEeE yHM62cZCk4xAFdVvcSTa8DGllvPD8cr4GgZ45O0wRvJ7oZ+B21PWUfRLOcnl2jkPBxdd FNnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749773064; x=1750377864; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=p8GFuynGr1nk+VpIO+5MvKgGfqQz5tqawVbKnQiXbx4=; b=AZK1iNe5H7bM2d3bqLUzHYNra9DBsBgYeB22hqP2ZfgqtMkR9F+lS3pzVViPsR7oWu 2uW9Pe3beT1kor8lcTvttYGQdGQzC4dC9PGshmrtEEXeXe0lLNR0yg5U4L/brDnLiDMW BNPWXmPUJkbRf721FkGDT0xqS3q3StBKOq/+AUmMcTyXahd99UiyVQjFPq1D7w7uoErb Cw4UfNEH3aas7nWOo6055FYP/9nH4YuTqRdOkxFMqIaMfWBbqymdDxmrl/Y9fusOHLXg n5zUf7RkRcAeE8bLBvobnMDFJcoACdj+bcJWxGB5jlUOE9VZKXtCjEflZKPgpbcC71OP tuJg== X-Gm-Message-State: AOJu0YxIs1Gz661brh+KqyjHQuRAOT/L/O6luAk9pJiQjVbLe9JASNwB cU/4f8RXLG1eJ/sjzGl/a0DB5WgAJN6OKgd2w6mtfr1o8yqBsHxh5SXlpZCZ7ExEx5e4i6tFhUI l1AEM0EFrGTr+aBd8wZdM8wEY7TexyznPrDQeOXsx4OG1L6RlR2ZWrceR7LdvGMOS3ZMqW/k9wa Ly7jVkfSSg4yY783wr509VkPTRhtMbo2f8cjxXo00M X-Google-Smtp-Source: AGHT+IHkf788GgVLS7iXbgwTAE5UzkS0H2haTTYF+o0yJk64nWaDSM0TC0ZIyzG8EqOobxTF5pJgiqEOevc4 X-Received: from pgbcw6.prod.google.com ([2002:a05:6a02:4286:b0:af9:8f44:d7ec]) (user=komlodi job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:431d:b0:21f:5aa1:3124 with SMTP id adf61e73a8af0-21fac92fc14mr1289955637.13.1749773063550; Thu, 12 Jun 2025 17:04:23 -0700 (PDT) Date: Fri, 13 Jun 2025 00:04:00 +0000 In-Reply-To: <20250613000411.1516521-1-komlodi@google.com> Mime-Version: 1.0 References: <20250613000411.1516521-1-komlodi@google.com> X-Mailer: git-send-email 2.50.0.rc1.591.g9c95f17f64-goog Message-ID: <20250613000411.1516521-9-komlodi@google.com> Subject: [PATCH 08/19] hw/i3c/dw-i3c: Add register RO field masks From: Joe Komlodi To: qemu-devel@nongnu.org Cc: venture@google.com, komlodi@google.com, clg@kaod.org, peter.maydell@linaro.org, steven_lee@aspeedtech.com, leetroy@gmail.com, jamin_lin@aspeedtech.com, andrew@codeconstruct.com.au, joel@jms.id.au, qemu-arm@nongnu.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::549; envelope-from=3B2tLaAcKClQ6A87Az42AA270.yA8C08G-z0H079A929G.AD2@flex--komlodi.bounces.google.com; helo=mail-pg1-x549.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1749773101534116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Adds read-only register masks for the DwC I3C controller. Signed-off-by: Joe Komlodi Reviewed-by: Patrick Venture --- hw/i3c/dw-i3c.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/hw/i3c/dw-i3c.c b/hw/i3c/dw-i3c.c index 845fbd5efd..4f40f999f4 100644 --- a/hw/i3c/dw-i3c.c +++ b/hw/i3c/dw-i3c.c @@ -313,6 +313,45 @@ static const uint32_t dw_i3c_resets[DW_I3C_NR_REGS] = =3D { [R_SLAVE_CONFIG] =3D 0x00000023, }; =20 +static const uint32_t dw_i3c_ro[DW_I3C_NR_REGS] =3D { + [R_DEVICE_CTRL] =3D 0x04fffe00, + [R_DEVICE_ADDR] =3D 0x7f807f80, + [R_HW_CAPABILITY] =3D 0xffffffff, + [R_IBI_QUEUE_STATUS] =3D 0xffffffff, + [R_DATA_BUFFER_THLD_CTRL] =3D 0xf8f8f8f8, + [R_IBI_QUEUE_CTRL] =3D 0xfffffff0, + [R_RESET_CTRL] =3D 0xffffffc0, + [R_SLV_EVENT_CTRL] =3D 0xffffff3f, + [R_INTR_STATUS] =3D 0xffff809f, + [R_INTR_STATUS_EN] =3D 0xffff8080, + [R_INTR_SIGNAL_EN] =3D 0xffff8080, + [R_INTR_FORCE] =3D 0xffff8000, + [R_QUEUE_STATUS_LEVEL] =3D 0xffffffff, + [R_DATA_BUFFER_STATUS_LEVEL] =3D 0xffffffff, + [R_PRESENT_STATE] =3D 0xffffffff, + [R_CCC_DEVICE_STATUS] =3D 0xffffffff, + [R_I3C_VER_ID] =3D 0xffffffff, + [R_I3C_VER_TYPE] =3D 0xffffffff, + [R_DEVICE_ADDR_TABLE_POINTER] =3D 0xffffffff, + [R_DEV_CHAR_TABLE_POINTER] =3D 0xffcbffff, + [R_SLV_PID_VALUE] =3D 0xffff0fff, + [R_SLV_CHAR_CTRL] =3D 0xffffffff, + [A_VENDOR_SPECIFIC_REG_POINTER] =3D 0xffffffff, + [R_SLV_MAX_LEN] =3D 0xffffffff, + [R_MAX_READ_TURNAROUND] =3D 0xffffffff, + [R_MAX_DATA_SPEED] =3D 0xffffffff, + [R_SLV_INTR_REQ] =3D 0xfffffff0, + [R_SLV_TSX_SYMBL_TIMING] =3D 0xffffffc0, + [R_DEVICE_CTRL_EXTENDED] =3D 0xfffffff8, + [R_SCL_I3C_OD_TIMING] =3D 0xff00ff00, + [R_SCL_I3C_PP_TIMING] =3D 0xff00ff00, + [R_SCL_I2C_FMP_TIMING] =3D 0xff000000, + [R_SCL_EXT_TERMN_LCNT_TIMING] =3D 0x0000fff0, + [R_BUS_IDLE_TIMING] =3D 0xfff00000, + [R_EXTENDED_CAPABILITY] =3D 0xffffffff, + [R_SLAVE_CONFIG] =3D 0xffffffff, +}; + static uint64_t dw_i3c_read(void *opaque, hwaddr offset, unsigned size) { DWI3C *s =3D DW_I3C(opaque); @@ -341,6 +380,7 @@ static void dw_i3c_write(void *opaque, hwaddr offset, u= int64_t value, =20 trace_dw_i3c_write(s->id, offset, value); =20 + value &=3D ~dw_i3c_ro[addr]; switch (addr) { case R_HW_CAPABILITY: case R_RESPONSE_QUEUE_PORT: --=20 2.50.0.rc1.591.g9c95f17f64-goog From nobody Sat Nov 15 16:09:06 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1749773274; cv=none; d=zohomail.com; s=zohoarc; b=MBLKh/6fLnJIPVQdR+UVdLMjoAs33ny317ippFOYR+stkN0kF8UhhtSHFsEJP/6nX8JflRSfi9ijLJoZsgK7hnVDdkmxbwM2U+kZeHpfu2fFEsKwTeGmXGxJowhplG+rcDICfaVj3yRuR87EUYw0PJGPEUnfE1uCBsmD0X/xsU4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749773274; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=qzeXApkoHKyQHwiWeTNus/brrOxPdJq1kjayormL0Vs=; b=JPGyxjg2xM7TlCexliHlmSgMy55lTHdyibdzTKwT/b4GwGHkWzg7WAnsl51vKK0rXEpe2xg5KOyNkVoXac53m+vkn9Vug7/+APC+AGVxDtJDs5BH2DtJXfncHJO70UBk9MebJz1Y7DL8CyNRSDN3u7JAfumBhbBOA6kx7b0TDis= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749773274084788.9596534511497; Thu, 12 Jun 2025 17:07:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPrux-00060b-5m; Thu, 12 Jun 2025 20:05:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3CWtLaAcKClY8CA9C164CC492.0CAE2AI-12J29BCB4BI.CF4@flex--komlodi.bounces.google.com>) id 1uPruH-0005qi-AJ for qemu-devel@nongnu.org; Thu, 12 Jun 2025 20:04:29 -0400 Received: from mail-pl1-x649.google.com ([2607:f8b0:4864:20::649]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3CWtLaAcKClY8CA9C164CC492.0CAE2AI-12J29BCB4BI.CF4@flex--komlodi.bounces.google.com>) id 1uPruF-0000Zd-Nl for qemu-devel@nongnu.org; Thu, 12 Jun 2025 20:04:28 -0400 Received: by mail-pl1-x649.google.com with SMTP id d9443c01a7336-235e1d66fa6so14388205ad.0 for ; Thu, 12 Jun 2025 17:04:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1749773065; x=1750377865; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=qzeXApkoHKyQHwiWeTNus/brrOxPdJq1kjayormL0Vs=; b=U6HMRmO5/2Q5kFg8xS3AKQE63dUheuOX6DAITITb/HZn7q/wp/8N9Wdpd8xOG1Thoj 9d8Fry/dsnjSQmxHhP9piVGAwRFMylWppCEsNN5Be9muWd1PmnPkemtg6UnE6vjNJgQC EuoavtADB61I44GCcZUgyDWHs9yyvPtXf/nqyHcyx8qHA1x5MnCRCtNu5pJXM1TbrBgW +G/6O6WBgtA7WC0txHKf2J/sy1NnIMvvRxAaWa3Tn5k5P6eQPIEp9mUxTFO1lTvTu3+e 3AQZ8jbLO66JQDvJMVzGjISJ/cCpLI5MZIFlEuvd9h55SQ1QbumLO05vKB6hU+8moEJs JOXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749773065; x=1750377865; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=qzeXApkoHKyQHwiWeTNus/brrOxPdJq1kjayormL0Vs=; b=Tna3q5YkJNhBEGPKG2sl2AHPbwx8wiltuEeuPE9w9pnBbdTFhxqY1RpbkQLunevu6U zLVjEoF2rCfwwQ1XVdLrqqh8VDfiR9FUIs5+dIrdCXML2ASiduc3T5rcTltq6tgGmq+R AqFz/UEsJimBIVmyY6JLSIm0BYOOWB9DZ7iUbTmbP1zW6aJJ/j5V6vEczHDWzVUlqmXd fOmEg+skWFOuc6YXlvqYr4Yb9xREFZI1wuklOTygw/YTE/JsZBd0dpYhdPL5J7o+5KC9 /fUo26TeWT2j50LuNnaR22/1WfHzjj5+X+eemZDTBHcrdwjgm2rz6ylH8/HcLE+tl0hv lBqA== X-Gm-Message-State: AOJu0YzUyxyrv4xbUJgGRehx/yPXU7E6JEQdxHl2ZkrAmiAWU7bPc+VX sMeiI7odmIpEKrcrVcMQgeflKKN6SLdmAkwC1UdNekgS9EQhQ3w9+z3Zy75WL6m/IcyQzmx4DVW VA5LneL6Ez19ZbJXKyOdFvsHSiD/njPoDCtrLG2MsWlLv8bLnV7X1zrI847lWPyJgg6SKk9CLWn HnObak4UrQxn4LhgJXBVhV9WK3537V4G0W8HpbDtwL X-Google-Smtp-Source: AGHT+IGLKDmLbZW/qGezSxYha2G+BZmAVQInMd45qP0gEERp59ero1+jqvHP6nwox2JBl1Byld/1jiqT+PWI X-Received: from pgbda8.prod.google.com ([2002:a05:6a02:2388:b0:b2c:4d7e:b626]) (user=komlodi job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:f684:b0:234:aa5b:e7b1 with SMTP id d9443c01a7336-2365d8ad4aamr11086965ad.18.1749773065089; Thu, 12 Jun 2025 17:04:25 -0700 (PDT) Date: Fri, 13 Jun 2025 00:04:01 +0000 In-Reply-To: <20250613000411.1516521-1-komlodi@google.com> Mime-Version: 1.0 References: <20250613000411.1516521-1-komlodi@google.com> X-Mailer: git-send-email 2.50.0.rc1.591.g9c95f17f64-goog Message-ID: <20250613000411.1516521-10-komlodi@google.com> Subject: [PATCH 09/19] hw/i3c/dw-i3c: Treat more registers as read-as-zero From: Joe Komlodi To: qemu-devel@nongnu.org Cc: venture@google.com, komlodi@google.com, clg@kaod.org, peter.maydell@linaro.org, steven_lee@aspeedtech.com, leetroy@gmail.com, jamin_lin@aspeedtech.com, andrew@codeconstruct.com.au, joel@jms.id.au, qemu-arm@nongnu.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::649; envelope-from=3CWtLaAcKClY8CA9C164CC492.0CAE2AI-12J29BCB4BI.CF4@flex--komlodi.bounces.google.com; helo=mail-pl1-x649.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1749773275082116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" RESET_CTRL and INTR_FORCE are write-only. Signed-off-by: Joe Komlodi Reviewed-by: Patrick Venture --- hw/i3c/dw-i3c.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/i3c/dw-i3c.c b/hw/i3c/dw-i3c.c index 4f40f999f4..bf51c00935 100644 --- a/hw/i3c/dw-i3c.c +++ b/hw/i3c/dw-i3c.c @@ -359,7 +359,10 @@ static uint64_t dw_i3c_read(void *opaque, hwaddr offse= t, unsigned size) uint64_t value; =20 switch (addr) { + /* RAZ */ case R_COMMAND_QUEUE_PORT: + case R_RESET_CTRL: + case R_INTR_FORCE: value =3D 0; break; default: --=20 2.50.0.rc1.591.g9c95f17f64-goog From nobody Sat Nov 15 16:09:06 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1749773197; cv=none; d=zohomail.com; s=zohoarc; b=mnN0lsx5E8vFh7ftx+9PLEI+yzoRskZFC5iQorFYVY2Kr+M3NOb7Jjivk1cYXr5SEzZ3rdc7XsHyrCzkF1kpN3lgdNPD1b/qop6VZ/IPjQ4TeNHDTEVy/1QTtlz/91H1ZUIWiyjR2yf/P8TQoDp+zqdGTsc92BqWwDKDGTL6VOI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749773197; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=bGxi0+b2ieHBb3xRNVEv/9JKjepFFVub1/UswMe9fwo=; b=iT5f9dAoZ4fd8zi1BA0/8Df3P68mSlqZic344pjNXFqgvFfUKoGJFMImM4Y5keeOlW9ETNZEmM+D4OuI9I/4KQaIoF5rdtz1SE+1Hhf7lG+etRW4SAuDfDuBwL2QEKJJophDk4v11WMGjB5x/eB7I1jbT0ZBwka8RNcIAx/jALQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749773197173479.3490239991195; Thu, 12 Jun 2025 17:06:37 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPrvJ-0006SR-Ho; Thu, 12 Jun 2025 20:05:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3CmtLaAcKClc9DBAD275DD5A3.1DBF3BJ-23K3ACDC5CJ.DG5@flex--komlodi.bounces.google.com>) id 1uPruI-0005rB-Ax for qemu-devel@nongnu.org; Thu, 12 Jun 2025 20:04:31 -0400 Received: from mail-pl1-x64a.google.com ([2607:f8b0:4864:20::64a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3CmtLaAcKClc9DBAD275DD5A3.1DBF3BJ-23K3ACDC5CJ.DG5@flex--komlodi.bounces.google.com>) id 1uPruG-0000a3-L2 for qemu-devel@nongnu.org; Thu, 12 Jun 2025 20:04:30 -0400 Received: by mail-pl1-x64a.google.com with SMTP id d9443c01a7336-2365ab89b52so5026945ad.2 for ; Thu, 12 Jun 2025 17:04:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1749773066; x=1750377866; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=bGxi0+b2ieHBb3xRNVEv/9JKjepFFVub1/UswMe9fwo=; b=3gjmOgRqwpEeQ4+ZUxnKZCXqdUCux0gW/uF15+pzQ2sZRZKloX/9Em65LU2yfijvTO +1yxpop18yOQHvq6/xQkNpNhiBjngrGGNhDPtpd8aO5mCfvP8tPcVUQmTt/R0VAlCWc4 wGJQ9fwPYTMr/VXnlbjEV8u+cEYJD2Uar0ZDN7QMUPxSggTgOuhA60DFTE/3kOzYmM2q BIN/stQPRHNAn+3kmrKXlx8I+HgTd99hxafjMJvDGWI9GjczIltNA+JXA/yEfwU6Fj0R NvZfL7lOT8Zt1eZi6zbM72SRqCGxPrpySaAvOajY6EvbKn2+uXvuEkwYg6HQIsunOvPa 9Dhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749773066; x=1750377866; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=bGxi0+b2ieHBb3xRNVEv/9JKjepFFVub1/UswMe9fwo=; b=Fe3/yzSLAfI8OLbfb27g4Vbrtc+8JqY+zc4g6mg2J6GOCuZVidHQiLzzu821gQdxhu Dv70i+45d2WGnePnbLn2Inm2M7pIdeY5ZbIjBCPacjkrQASthfJpQPkz3TkVzoygZjV8 0Ld1p4XNTiq/ddnfjcUWGeriAgMgtWWzz0qhSbcdg/8RAFETc2z8rVfn9zQWA0LeO0OI 7AKhaStSkN8rLyUfEUnv0MelrjSA7yLeRstzVDh044LYWucb9PvJTTiCKcmPk4bMToAu v/T3qDu0+Kc2Cwxq8pBpaoLLSz9yiQQ25guyxabbp/wea11gDxgGEyEp+IuCaqxsMPDT 9mIA== X-Gm-Message-State: AOJu0Yxv+4CDoWbMMioERQin5EYk9hg/4sP79YOzAMr0NAaai/2CzS6/ wpTiUS8FGlsVzuKe4WQIOx7FIv/McWXNDqFtWjbWOCl0X2T23oG6e4JAWzZPas9+koo2c0UH1Ll goIbEI+I2ppw42LXWprx4o/wolOwmyE2cql8gEz+TMm7JCm0b/duI+XmOa54AppS7/kpRwlRN3G DaXN/gPs7HoU2hCUCuSGWPbUZDPn4O0m8stt0D9Had X-Google-Smtp-Source: AGHT+IFirUvxD2IX451LrPoZsi4qEBbNUbqzhApW0pieIbOQgAAFEoX1n+cFSAlycEtF4voIhDobGxe5YWPU X-Received: from pgb23.prod.google.com ([2002:a05:6a02:3417:b0:b2c:4d40:79b9]) (user=komlodi job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:f689:b0:235:ea0d:ae21 with SMTP id d9443c01a7336-2365dc09ad7mr14535485ad.35.1749773066491; Thu, 12 Jun 2025 17:04:26 -0700 (PDT) Date: Fri, 13 Jun 2025 00:04:02 +0000 In-Reply-To: <20250613000411.1516521-1-komlodi@google.com> Mime-Version: 1.0 References: <20250613000411.1516521-1-komlodi@google.com> X-Mailer: git-send-email 2.50.0.rc1.591.g9c95f17f64-goog Message-ID: <20250613000411.1516521-11-komlodi@google.com> Subject: [PATCH 10/19] hw/i3c/dw-i3c: Use 32 bits on MMIO writes From: Joe Komlodi To: qemu-devel@nongnu.org Cc: venture@google.com, komlodi@google.com, clg@kaod.org, peter.maydell@linaro.org, steven_lee@aspeedtech.com, leetroy@gmail.com, jamin_lin@aspeedtech.com, andrew@codeconstruct.com.au, joel@jms.id.au, qemu-arm@nongnu.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::64a; envelope-from=3CmtLaAcKClc9DBAD275DD5A3.1DBF3BJ-23K3ACDC5CJ.DG5@flex--komlodi.bounces.google.com; helo=mail-pl1-x64a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1749773198272116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The registers are only 32 bits wide, so we should cast the 64-bit value passed in to only be 32 bits wide. Signed-off-by: Joe Komlodi Reviewed-by: Patrick Venture Reviewed-by: Titus Rwantare --- hw/i3c/dw-i3c.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hw/i3c/dw-i3c.c b/hw/i3c/dw-i3c.c index bf51c00935..ecd79aba8c 100644 --- a/hw/i3c/dw-i3c.c +++ b/hw/i3c/dw-i3c.c @@ -380,10 +380,11 @@ static void dw_i3c_write(void *opaque, hwaddr offset,= uint64_t value, { DWI3C *s =3D DW_I3C(opaque); uint32_t addr =3D offset >> 2; + uint32_t val32 =3D (uint32_t)value; =20 trace_dw_i3c_write(s->id, offset, value); =20 - value &=3D ~dw_i3c_ro[addr]; + val32 &=3D ~dw_i3c_ro[addr]; switch (addr) { case R_HW_CAPABILITY: case R_RESPONSE_QUEUE_PORT: @@ -409,7 +410,7 @@ static void dw_i3c_write(void *opaque, hwaddr offset, u= int64_t value, case R_RESET_CTRL: break; default: - s->regs[addr] =3D value; + s->regs[addr] =3D val32; break; } } --=20 2.50.0.rc1.591.g9c95f17f64-goog From nobody Sat Nov 15 16:09:06 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1749773223; cv=none; d=zohomail.com; s=zohoarc; b=jM8IPiAVTvyN2af67CehvlV4dzaqeBwyNGQ+EL8mJZtQ6cNAa4fjJbOVHaxmyWkFJv74PI1miJYJM21sz9nrE2sRK21Di4YS6HZx0w6SwT5kzo3wMQ+2bPijkD5ZXKGThXciw6fL6xC+phTkIvCOotntNQTfe6UtW6og6brxR6g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749773223; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=IFNo7OhYkVhWHM6SQDIAUQfEPwpaNIWcaew9uihGsFg=; b=EAQ094sGXVnI8iXnMI0t3SLVaIS+Gv6eQQVN9gU0L6ocE5GEjWBPzJQeysS0LuFvqUX8LGO2RQl7wx98laO9tpuMh38M4Mr5RyxezsV9o0jyONL/lPvArb6UpTsTHQp45OsweMKDmDIi+Vadn8YVvRsWuK7inHgODbllIuE+1T4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749773223050126.89300663766812; Thu, 12 Jun 2025 17:07:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPrwB-00074P-Og; Thu, 12 Jun 2025 20:06:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3C2tLaAcKClgAECBE386EE6B4.2ECG4CK-34L4BDED6DK.EH6@flex--komlodi.bounces.google.com>) id 1uPruL-0005rd-AE for qemu-devel@nongnu.org; Thu, 12 Jun 2025 20:04:33 -0400 Received: from mail-pg1-x54a.google.com ([2607:f8b0:4864:20::54a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3C2tLaAcKClgAECBE386EE6B4.2ECG4CK-34L4BDED6DK.EH6@flex--komlodi.bounces.google.com>) id 1uPruI-0000aN-FN for qemu-devel@nongnu.org; Thu, 12 Jun 2025 20:04:32 -0400 Received: by mail-pg1-x54a.google.com with SMTP id 41be03b00d2f7-b26e73d375aso1444108a12.2 for ; Thu, 12 Jun 2025 17:04:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1749773068; x=1750377868; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=IFNo7OhYkVhWHM6SQDIAUQfEPwpaNIWcaew9uihGsFg=; b=xYzK8/eRnulGq8Vq4ieSqByHu+l2ILJYN4o7sMHTU7o40s9CfRyutMvh4CvmwSHjbE twqWoIHbMNsvFFMPVaKYdTVqY6Fr3Yer8pn72dGogV48W80+lCzFwxZNxtZYDmXlJNzU /S0NltdyQi3+9tck/Yl3SRqaGhdeRpJ+hxkR75FlMZxBh1abziQ+v3QBqugtPCbS5J3e 2pJ4Z7wNGBhNqt+dCdCfpcRNjD0jqQ1XbY8Zl8y9TmsB0B6FOhO8iKXT+eHesc6ZHRx7 SxSroErzWQ20l/HkPot6fAqJ1nJDje0lhFZoe+ZXKG9gsfTP2QEQ1qaWNBkatdUi4InX xuyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749773068; x=1750377868; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=IFNo7OhYkVhWHM6SQDIAUQfEPwpaNIWcaew9uihGsFg=; b=Nn6s/GHP8lB5Tq6Y/+Y7qTFvOCObq5pxk6Wmj22UYQO7FHajuYl18fDjonZcgPs3x6 Yd9DBadieqsnWnaGnAhc/auU4djgxC9YHEB0b38L8LIfF1w5AGREV2Yw6JMdB/fF+xYp oIXAO80euQ/AW0cpiU6U73R3Z2Eyfr+Ist9u6m00uj0RUhuHckDSssae5H78Mfd42/TN h3UjIK9eXUV6bunwK7NlzeTYhGqhXkfl7PjRVm6NOTEngpaGxo41Lt99M1YHaB2YRb6k 5qYl5/wxAhC8bQoUO7mmjPP/dja3b0IlGfL1vGGwmtkl4OE8OTuGLDNUkpkw/Lya9QGP J2/g== X-Gm-Message-State: AOJu0Yx/PPXL8bxSKRtsrnWWgxR5lieQAM4AyJaXB+rUm7c6w57JG3ql zb/nHWCxwEzq/QkELHEO3SAyVxpUmv+2+/V352aSO3C+JM3RfIewT58cWO6TcG480KNLhzstbVK s6CWIwN4D/HftftiPrOcE0q4m4eC8Tv2rus98oAyQ5S51VGtJPovj/ISyTXxkOJmmFdIYJS7Qx6 Kd6/AU2HHkx6XYbi61o5rTpMLWLq2YsgnaVwoTGunF X-Google-Smtp-Source: AGHT+IEoz+VmcVEpV6XfckGFBq9gJ+0WJ/H0fJ8JLXUKl/XSuEpQmGHbDJxSCtjPcapQdpVit1pneTX/4VkX X-Received: from pgbda8.prod.google.com ([2002:a05:6a02:2388:b0:b2c:4d7e:b626]) (user=komlodi job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:3994:b0:20b:a75e:fa32 with SMTP id adf61e73a8af0-21facf126aamr1382432637.40.1749773067968; Thu, 12 Jun 2025 17:04:27 -0700 (PDT) Date: Fri, 13 Jun 2025 00:04:03 +0000 In-Reply-To: <20250613000411.1516521-1-komlodi@google.com> Mime-Version: 1.0 References: <20250613000411.1516521-1-komlodi@google.com> X-Mailer: git-send-email 2.50.0.rc1.591.g9c95f17f64-goog Message-ID: <20250613000411.1516521-12-komlodi@google.com> Subject: [PATCH 11/19] hw/i3c/dw-i3c: Add IRQ MMIO behavior From: Joe Komlodi To: qemu-devel@nongnu.org Cc: venture@google.com, komlodi@google.com, clg@kaod.org, peter.maydell@linaro.org, steven_lee@aspeedtech.com, leetroy@gmail.com, jamin_lin@aspeedtech.com, andrew@codeconstruct.com.au, joel@jms.id.au, qemu-arm@nongnu.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::54a; envelope-from=3C2tLaAcKClgAECBE386EE6B4.2ECG4CK-34L4BDED6DK.EH6@flex--komlodi.bounces.google.com; helo=mail-pg1-x54a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1749773224665116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Signed-off-by: Joe Komlodi Reviewed-by: Patrick Venture Reviewed-by: Hao Wu --- hw/i3c/dw-i3c.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/hw/i3c/dw-i3c.c b/hw/i3c/dw-i3c.c index ecd79aba8c..c58e12964c 100644 --- a/hw/i3c/dw-i3c.c +++ b/hw/i3c/dw-i3c.c @@ -17,6 +17,7 @@ #include "qapi/error.h" #include "migration/vmstate.h" #include "trace.h" +#include "hw/irq.h" =20 REG32(DEVICE_CTRL, 0x00) FIELD(DEVICE_CTRL, I3C_BROADCAST_ADDR_INC, 0, 1) @@ -352,6 +353,46 @@ static const uint32_t dw_i3c_ro[DW_I3C_NR_REGS] =3D { [R_SLAVE_CONFIG] =3D 0xffffffff, }; =20 +static void dw_i3c_update_irq(DWI3C *s) +{ + bool level =3D !!(s->regs[R_INTR_SIGNAL_EN] & s->regs[R_INTR_STATUS]); + qemu_set_irq(s->irq, level); +} + +static uint32_t dw_i3c_intr_status_r(DWI3C *s) +{ + /* Only return the status whose corresponding EN bits are set. */ + return s->regs[R_INTR_STATUS] & s->regs[R_INTR_STATUS_EN]; +} + +static void dw_i3c_intr_status_w(DWI3C *s, uint32_t val) +{ + /* INTR_STATUS[13:5] is w1c, other bits are RO. */ + val &=3D 0x3fe0; + s->regs[R_INTR_STATUS] &=3D ~val; + + dw_i3c_update_irq(s); +} + +static void dw_i3c_intr_status_en_w(DWI3C *s, uint32_t val) +{ + s->regs[R_INTR_STATUS_EN] =3D val; + dw_i3c_update_irq(s); +} + +static void dw_i3c_intr_signal_en_w(DWI3C *s, uint32_t val) +{ + s->regs[R_INTR_SIGNAL_EN] =3D val; + dw_i3c_update_irq(s); +} + +static void dw_i3c_intr_force_w(DWI3C *s, uint32_t val) +{ + /* INTR_FORCE is WO, just set the corresponding INTR_STATUS bits. */ + s->regs[R_INTR_STATUS] =3D val; + dw_i3c_update_irq(s); +} + static uint64_t dw_i3c_read(void *opaque, hwaddr offset, unsigned size) { DWI3C *s =3D DW_I3C(opaque); @@ -365,6 +406,9 @@ static uint64_t dw_i3c_read(void *opaque, hwaddr offset= , unsigned size) case R_INTR_FORCE: value =3D 0; break; + case R_INTR_STATUS: + value =3D dw_i3c_intr_status_r(s); + break; default: value =3D s->regs[addr]; break; @@ -409,6 +453,18 @@ static void dw_i3c_write(void *opaque, hwaddr offset, = uint64_t value, break; case R_RESET_CTRL: break; + case R_INTR_STATUS: + dw_i3c_intr_status_w(s, val32); + break; + case R_INTR_STATUS_EN: + dw_i3c_intr_status_en_w(s, val32); + break; + case R_INTR_SIGNAL_EN: + dw_i3c_intr_signal_en_w(s, val32); + break; + case R_INTR_FORCE: + dw_i3c_intr_force_w(s, val32); + break; default: s->regs[addr] =3D val32; break; --=20 2.50.0.rc1.591.g9c95f17f64-goog From nobody Sat Nov 15 16:09:06 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1749773381; cv=none; d=zohomail.com; s=zohoarc; b=kq5iBZ9IOcjrvGLNootutdZATPMw8u0oRGLoIkKTr3lFR8y3XwHDBYfgMU3Zsth0XO9J9cMe1fQKATQMSR/tJ2z87eh43SITxaS7QQoFzAp/ug8+NQRtS+zOAUA2LN8WQJCJi2++U62CWUu7NfvdPsbrWk3Ss9UdzKzIrXWopkM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749773381; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=yLPe5ak+2daSUQYBIKud169Th5/ffkfuG/3PwAWFPbc=; b=FZSxqVaQq2k5VcDVyNiwEschpAXcy42pm31WFH65C+n536J6tYPP9KgADB3dVo2Op1hPJn5Ea6UMC1f0o4XBcpKFldpVXhaaWZ6tM3C7jBhtJhIsMCBXuy1xo4rnM1jSzbOT7uDSqHpSJuAHxkpMPJYnPxZogF/tgRbDYOWTSFw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749773381609398.60578149503624; Thu, 12 Jun 2025 17:09:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPrxG-0000ox-3p; Thu, 12 Jun 2025 20:07:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3DWtLaAcKCloCGEDG5A8GG8D6.4GEI6EM-56N6DFGF8FM.GJ8@flex--komlodi.bounces.google.com>) id 1uPruU-0005sv-AB for qemu-devel@nongnu.org; Thu, 12 Jun 2025 20:04:47 -0400 Received: from mail-pl1-x649.google.com ([2607:f8b0:4864:20::649]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3DWtLaAcKCloCGEDG5A8GG8D6.4GEI6EM-56N6DFGF8FM.GJ8@flex--komlodi.bounces.google.com>) id 1uPruK-0000ak-1H for qemu-devel@nongnu.org; Thu, 12 Jun 2025 20:04:36 -0400 Received: by mail-pl1-x649.google.com with SMTP id d9443c01a7336-234dbbc4899so21122015ad.2 for ; Thu, 12 Jun 2025 17:04:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1749773069; x=1750377869; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=yLPe5ak+2daSUQYBIKud169Th5/ffkfuG/3PwAWFPbc=; b=h29xjjy67H4GrlH4R788g9MZ4l5LOdH03+7em7Z9OtvkCFMSNPCQrvbQK/R9lNDrAU cqrITRIHs50EA9Hzmifulz7qxo4Hp14E+S6yurAf60RxG3mCSxP9ZDBmywxgLA6cynDX m/qupuXmY3Omff8Y0A9mM2lKqmIqDAk9UOwOAwzqdtgwXeJZhyvzY0bOXH7xa0KARyeB om2eyfCgIZ5UpLkEz/LSztx2n5xhs4fsrdtSMI2NUedYFC5wdK5ZZ5n6Ej/wP0nKhkpD xfRZdICvze//9lllgCAXhvS8zQBPQ2pMv/dLN0fy/X0DVkkSrw3hiarsvLYk+RWWmFVB 78gQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749773069; x=1750377869; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=yLPe5ak+2daSUQYBIKud169Th5/ffkfuG/3PwAWFPbc=; b=sMhjowxJtANs6rDp+YAF4bN3fPZiGPl53ZQ6ANThof1AdFeZ8ETHWmmMlsKW05SNO2 rlcFoVA1iTUhesVcy3EY03lKoeejR+uAElLu4UDvX+Hiss2n9dyD1N2HkObsZ/ZoQBIg 0ZHJ3FbDG8kd0Aen/oapnrOL+V4YxjJgI2EvdVz3xes2aixy3e8WOuMQ7Suz4fp2xQ6l brM/tMu0rrN0ptFouHTmLq+6X5gwsIvOunCPELLdCUPWjXEqsqO6KbvBKoeQOIk76reJ Dnj0UqCPcpgMeASqZ9XsjHCaTiJje4zYB17E2fDLg8u4wBXLxg5IlkT1U5mWL77fw4UC h5Iw== X-Gm-Message-State: AOJu0YwcYTO/jd0RTIz0WEpHKcG4cJTn6fMotUtQVHK2JY0zBsL9RL1w N/K1Ufq8wiQADTJ92b9ymBwvxUp7IlZFfxvuqmIbgT65seqpC5NRaXv+veqCEkmKNQsLnGOd8iu uhx+zpucftlV7hLYy3iLVPVjbYXJX9DcST3OqUPSMgusgQLxKIPvxhXdZ+4Apr7mhXH1KoXd8BI L15uGl/9utg7gbrXWMw5ZRdOgqoGSfNIQTRO1QbNlW X-Google-Smtp-Source: AGHT+IEDGoBBh5Q4NKvODKXbx27HRrFr74xQ8hunpagtfKiBk/Sde98JxcUqBif9zFpLZmZcOFa8hxP2BEFf X-Received: from pgbfm22.prod.google.com ([2002:a05:6a02:4996:b0:b29:82be:c692]) (user=komlodi job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:fc44:b0:234:c549:da14 with SMTP id d9443c01a7336-2365dc0d163mr13433885ad.29.1749773069459; Thu, 12 Jun 2025 17:04:29 -0700 (PDT) Date: Fri, 13 Jun 2025 00:04:04 +0000 In-Reply-To: <20250613000411.1516521-1-komlodi@google.com> Mime-Version: 1.0 References: <20250613000411.1516521-1-komlodi@google.com> X-Mailer: git-send-email 2.50.0.rc1.591.g9c95f17f64-goog Message-ID: <20250613000411.1516521-13-komlodi@google.com> Subject: [PATCH 12/19] hw/i3c/dw-i3c: Add data TX and RX From: Joe Komlodi To: qemu-devel@nongnu.org Cc: venture@google.com, komlodi@google.com, clg@kaod.org, peter.maydell@linaro.org, steven_lee@aspeedtech.com, leetroy@gmail.com, jamin_lin@aspeedtech.com, andrew@codeconstruct.com.au, joel@jms.id.au, qemu-arm@nongnu.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::649; envelope-from=3DWtLaAcKCloCGEDG5A8GG8D6.4GEI6EM-56N6DFGF8FM.GJ8@flex--komlodi.bounces.google.com; helo=mail-pl1-x649.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1749773382304116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This adds data and CCC transmission, reception, and the associated queues required for data transmission and reception to happen. The I3C controller transmits data by the user writing into a command queue. When the queue has a command and an argument in it, the controller starts executing the command. The controller can execute 1 of 3 ways: 1. A larger data transfer that involves using the TX and RX queues. This is the most common way the controller does transactions. 2. A small data transfer that involves sending a couple bytes passed into the command queue argument. 3. An address assignment command. This is how the controller does ENTDAA. When ENTDAA succeeds in assigning an address to a target, it updates the controller's char table with the target's PID, BCR, and DCR. The controller determines what addresses to send by looking at the index in the device address table specified by the argument in the command queue. ENTDAA also uses these addresses to assign to targets on the bus. When the controller is done executing a command, it puts a response in the response queue indicating how command execution went. In order for the user to send and receive data to/from the controller, the user reads/writes to a bidirectional TX/RX port. Signed-off-by: Joe Komlodi Reviewed-by: Stephen Longfield Reviewed-by: Patrick Venture --- hw/i3c/dw-i3c.c | 882 +++++++++++++++++++++++++++++++++++- hw/i3c/trace-events | 10 + include/hw/i3c/aspeed_i3c.h | 1 + include/hw/i3c/dw-i3c.h | 143 +++++- 4 files changed, 1030 insertions(+), 6 deletions(-) diff --git a/hw/i3c/dw-i3c.c b/hw/i3c/dw-i3c.c index c58e12964c..2c3e1a5760 100644 --- a/hw/i3c/dw-i3c.c +++ b/hw/i3c/dw-i3c.c @@ -353,12 +353,179 @@ static const uint32_t dw_i3c_ro[DW_I3C_NR_REGS] =3D { [R_SLAVE_CONFIG] =3D 0xffffffff, }; =20 +static inline bool dw_i3c_has_hdr_ts(DWI3C *s) +{ + return ARRAY_FIELD_EX32(s->regs, HW_CAPABILITY, HDR_TS); +} + +static inline bool dw_i3c_has_hdr_ddr(DWI3C *s) +{ + return ARRAY_FIELD_EX32(s->regs, HW_CAPABILITY, HDR_DDR); +} + +static inline bool dw_i3c_can_transmit(DWI3C *s) +{ + /* + * We can only transmit if we're enabled and the resume bit is cleared. + * The resume bit is set on a transaction error, and software must cle= ar it. + */ + return ARRAY_FIELD_EX32(s->regs, DEVICE_CTRL, I3C_EN) && + !ARRAY_FIELD_EX32(s->regs, DEVICE_CTRL, I3C_RESUME); +} + +static inline uint8_t dw_i3c_fifo_threshold_from_reg(uint8_t regval) +{ + return regval =3D regval ? (2 << regval) : 1; +} + static void dw_i3c_update_irq(DWI3C *s) { bool level =3D !!(s->regs[R_INTR_SIGNAL_EN] & s->regs[R_INTR_STATUS]); qemu_set_irq(s->irq, level); } =20 +static void dw_i3c_end_transfer(DWI3C *s, bool is_i2c) +{ + if (is_i2c) { + legacy_i2c_end_transfer(s->bus); + } else { + i3c_end_transfer(s->bus); + } +} + +static int dw_i3c_send_start(DWI3C *s, uint8_t addr, bool is_recv, bool is= _i2c) +{ + int ret; + + if (is_i2c) { + ret =3D legacy_i2c_start_transfer(s->bus, addr, is_recv); + } else { + ret =3D i3c_start_transfer(s->bus, addr, is_recv); + } + if (ret) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); + qemu_log_mask(LOG_GUEST_ERROR, "%s: NACKed on TX with addr 0x%.2x\= n", + path, addr); + ARRAY_FIELD_DP32(s->regs, PRESENT_STATE, CM_TFR_ST_STATUS, + DW_I3C_TRANSFER_STATE_HALT); + ARRAY_FIELD_DP32(s->regs, PRESENT_STATE, CM_TFR_STATUS, + DW_I3C_TRANSFER_STATUS_HALT); + ARRAY_FIELD_DP32(s->regs, INTR_STATUS, TRANSFER_ERR, 1); + ARRAY_FIELD_DP32(s->regs, DEVICE_CTRL, I3C_RESUME, 1); + } + + return ret; +} + +static int dw_i3c_send(DWI3C *s, const uint8_t *data, uint32_t num_to_send, + uint32_t *num_sent, bool is_i2c) +{ + int ret; + uint32_t i; + + *num_sent =3D 0; + if (is_i2c) { + /* Legacy I2C must be byte-by-byte. */ + for (i =3D 0; i < num_to_send; i++) { + ret =3D legacy_i2c_send(s->bus, data[i]); + if (ret) { + break; + } + (*num_sent)++; + } + } else { + ret =3D i3c_send(s->bus, data, num_to_send, num_sent); + } + if (ret) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); + qemu_log_mask(LOG_GUEST_ERROR, "%s: NACKed sending byte 0x%.2x\n", + path, data[*num_sent]); + ARRAY_FIELD_DP32(s->regs, PRESENT_STATE, CM_TFR_ST_STATUS, + DW_I3C_TRANSFER_STATE_HALT); + ARRAY_FIELD_DP32(s->regs, PRESENT_STATE, CM_TFR_STATUS, + DW_I3C_TRANSFER_STATUS_HALT); + ARRAY_FIELD_DP32(s->regs, INTR_STATUS, TRANSFER_ERR, 1); + ARRAY_FIELD_DP32(s->regs, DEVICE_CTRL, I3C_RESUME, 1); + } + + trace_dw_i3c_send(s->cfg.id, *num_sent); + + return ret; +} + +static int dw_i3c_send_byte(DWI3C *s, uint8_t byte, bool is_i2c) +{ + /* + * Ignored, the caller will know if we sent 0 or 1 bytes depending on = if + * we were ACKed/NACKed. + */ + uint32_t num_sent; + return dw_i3c_send(s, &byte, 1, &num_sent, is_i2c); +} + +static int dw_i3c_recv_data(DWI3C *s, bool is_i2c, uint8_t *data, + uint16_t num_to_read, uint32_t *num_read) +{ + int ret; + + if (is_i2c) { + for (uint16_t i =3D 0; i < num_to_read; i++) { + data[i] =3D legacy_i2c_recv(s->bus); + } + /* I2C devices can neither NACK a read, nor end transfers early. */ + *num_read =3D num_to_read; + trace_dw_i3c_recv_data(s->cfg.id, *num_read); + return 0; + } + /* I3C devices can NACK if the controller sends an unsupported CCC. */ + ret =3D i3c_recv(s->bus, data, num_to_read, num_read); + if (ret) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: NACKed receiving byte\n", + object_get_canonical_path(OBJECT(s))); + ARRAY_FIELD_DP32(s->regs, PRESENT_STATE, CM_TFR_ST_STATUS, + DW_I3C_TRANSFER_STATE_HALT); + ARRAY_FIELD_DP32(s->regs, PRESENT_STATE, CM_TFR_STATUS, + DW_I3C_TRANSFER_STATUS_HALT); + ARRAY_FIELD_DP32(s->regs, INTR_STATUS, TRANSFER_ERR, 1); + ARRAY_FIELD_DP32(s->regs, DEVICE_CTRL, I3C_RESUME, 1); + } + + trace_dw_i3c_recv_data(s->cfg.id, *num_read); + + return ret; +} + +static inline bool dw_i3c_target_is_i2c(DWI3C *s, uint16_t offset) +{ + /* / sizeof(uint32_t) because we're indexing into our 32-bit reg array= . */ + uint16_t dev_index =3D (ARRAY_FIELD_EX32(s->regs, DEVICE_ADDR_TABLE_PO= INTER, + ADDR) / sizeof(uint32_t)) + offs= et; + return FIELD_EX32(s->regs[dev_index], DEVICE_ADDR_TABLE_LOC1, + LEGACY_I2C_DEVICE); +} + +static uint8_t dw_i3c_target_addr(DWI3C *s, uint16_t offset) +{ + if (offset > s->cfg.num_addressable_devices) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); + qemu_log_mask(LOG_GUEST_ERROR, "%s: Device addr table offset %d ou= t of " + "bounds\n", path, offset); + /* If we're out of bounds, return an address of 0. */ + return 0; + } + + /* / sizeof(uint32_t) because we're indexing into our 32-bit reg array= . */ + uint16_t dev_index =3D (ARRAY_FIELD_EX32(s->regs, DEVICE_ADDR_TABLE_PO= INTER, + ADDR) / sizeof(uint32_t)) + offs= et; + /* I2C devices use a static address. */ + if (dw_i3c_target_is_i2c(s, offset)) { + return FIELD_EX32(s->regs[dev_index], DEVICE_ADDR_TABLE_LOC1, + DEV_STATIC_ADDR); + } + return FIELD_EX32(s->regs[dev_index], DEVICE_ADDR_TABLE_LOC1, + DEV_DYNAMIC_ADDR); +} + static uint32_t dw_i3c_intr_status_r(DWI3C *s) { /* Only return the status whose corresponding EN bits are set. */ @@ -393,6 +560,56 @@ static void dw_i3c_intr_force_w(DWI3C *s, uint32_t val) dw_i3c_update_irq(s); } =20 +static uint32_t dw_i3c_pop_rx(DWI3C *s) +{ + if (fifo32_is_empty(&s->rx_queue)) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); + qemu_log_mask(LOG_GUEST_ERROR, "%s: Tried to read RX FIFO when emp= ty\n", + path); + return 0; + } + + uint32_t val =3D fifo32_pop(&s->rx_queue); + ARRAY_FIELD_DP32(s->regs, DATA_BUFFER_STATUS_LEVEL, RX_BUF_BLR, + fifo32_num_used(&s->rx_queue)); + + /* Threshold is 2^RX_BUF_THLD. */ + uint8_t threshold =3D ARRAY_FIELD_EX32(s->regs, DATA_BUFFER_THLD_CTRL, + RX_BUF_THLD); + threshold =3D dw_i3c_fifo_threshold_from_reg(threshold); + if (fifo32_num_used(&s->rx_queue) < threshold) { + ARRAY_FIELD_DP32(s->regs, INTR_STATUS, RX_THLD, 0); + dw_i3c_update_irq(s); + } + + trace_dw_i3c_pop_rx(s->cfg.id, val); + return val; +} + +static uint32_t dw_i3c_resp_queue_port_r(DWI3C *s) +{ + if (fifo32_is_empty(&s->resp_queue)) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); + qemu_log_mask(LOG_GUEST_ERROR, "%s: Tried to read response FIFO wh= en " + "empty\n", path); + return 0; + } + + uint32_t val =3D fifo32_pop(&s->resp_queue); + ARRAY_FIELD_DP32(s->regs, QUEUE_STATUS_LEVEL, RESP_BUF_BLR, + fifo32_num_used(&s->resp_queue)); + + /* Threshold is the register value + 1. */ + uint8_t threshold =3D ARRAY_FIELD_EX32(s->regs, QUEUE_THLD_CTRL, + RESP_BUF_THLD) + 1; + if (fifo32_num_used(&s->resp_queue) < threshold) { + ARRAY_FIELD_DP32(s->regs, INTR_STATUS, RESP_RDY, 0); + dw_i3c_update_irq(s); + } + + return val; +} + static uint64_t dw_i3c_read(void *opaque, hwaddr offset, unsigned size) { DWI3C *s =3D DW_I3C(opaque); @@ -409,16 +626,635 @@ static uint64_t dw_i3c_read(void *opaque, hwaddr off= set, unsigned size) case R_INTR_STATUS: value =3D dw_i3c_intr_status_r(s); break; + case R_RX_TX_DATA_PORT: + value =3D dw_i3c_pop_rx(s); + break; + case R_RESPONSE_QUEUE_PORT: + value =3D dw_i3c_resp_queue_port_r(s); + break; default: value =3D s->regs[addr]; break; } =20 - trace_dw_i3c_read(s->id, offset, value); + trace_dw_i3c_read(s->cfg.id, offset, value); =20 return value; } =20 +static void dw_i3c_resp_queue_push(DWI3C *s, uint8_t err, uint8_t tid, + uint8_t ccc_type, uint16_t data_len) +{ + uint32_t val =3D 0; + val =3D FIELD_DP32(val, RESPONSE_QUEUE_PORT, ERR_STATUS, err); + val =3D FIELD_DP32(val, RESPONSE_QUEUE_PORT, TID, tid); + val =3D FIELD_DP32(val, RESPONSE_QUEUE_PORT, CCCT, ccc_type); + val =3D FIELD_DP32(val, RESPONSE_QUEUE_PORT, DL, data_len); + if (!fifo32_is_full(&s->resp_queue)) { + trace_dw_i3c_resp_queue_push(s->cfg.id, val); + fifo32_push(&s->resp_queue, val); + } + + ARRAY_FIELD_DP32(s->regs, QUEUE_STATUS_LEVEL, RESP_BUF_BLR, + fifo32_num_used(&s->resp_queue)); + /* Threshold is the register value + 1. */ + uint8_t threshold =3D ARRAY_FIELD_EX32(s->regs, QUEUE_THLD_CTRL, + RESP_BUF_THLD) + 1; + if (fifo32_num_used(&s->resp_queue) >=3D threshold) { + ARRAY_FIELD_DP32(s->regs, INTR_STATUS, RESP_RDY, 1); + dw_i3c_update_irq(s); + } +} + +static void dw_i3c_push_tx(DWI3C *s, uint32_t val) +{ + if (fifo32_is_full(&s->tx_queue)) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: Tried to push to TX FIFO when " + "full\n", object_get_canonical_path(OBJECT(s))); + return; + } + + trace_dw_i3c_push_tx(s->cfg.id, val); + fifo32_push(&s->tx_queue, val); + ARRAY_FIELD_DP32(s->regs, DATA_BUFFER_STATUS_LEVEL, TX_BUF_EMPTY_LOC, + fifo32_num_free(&s->tx_queue)); + + /* Threshold is 2^TX_BUF_THLD. */ + uint8_t empty_threshold =3D ARRAY_FIELD_EX32(s->regs, DATA_BUFFER_THLD= _CTRL, + TX_BUF_THLD); + empty_threshold =3D + dw_i3c_fifo_threshold_from_reg(empty_threshold); + if (fifo32_num_free(&s->tx_queue) < empty_threshold) { + ARRAY_FIELD_DP32(s->regs, INTR_STATUS, TX_THLD, 0); + dw_i3c_update_irq(s); + } +} + +static uint32_t dw_i3c_pop_tx(DWI3C *s) +{ + if (fifo32_is_empty(&s->tx_queue)) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); + qemu_log_mask(LOG_GUEST_ERROR, "%s: Tried to pop from TX FIFO when= " + "empty\n", path); + return 0; + } + + uint32_t val =3D fifo32_pop(&s->tx_queue); + trace_dw_i3c_pop_tx(s->cfg.id, val); + ARRAY_FIELD_DP32(s->regs, DATA_BUFFER_STATUS_LEVEL, TX_BUF_EMPTY_LOC, + fifo32_num_free(&s->tx_queue)); + + /* Threshold is 2^TX_BUF_THLD. */ + uint8_t empty_threshold =3D ARRAY_FIELD_EX32(s->regs, DATA_BUFFER_THLD= _CTRL, + TX_BUF_THLD); + empty_threshold =3D + dw_i3c_fifo_threshold_from_reg(empty_threshold); + if (fifo32_num_free(&s->tx_queue) >=3D empty_threshold) { + ARRAY_FIELD_DP32(s->regs, INTR_STATUS, TX_THLD, 1); + dw_i3c_update_irq(s); + } + return val; +} + +static void dw_i3c_push_rx(DWI3C *s, uint32_t val) +{ + if (fifo32_is_full(&s->rx_queue)) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); + qemu_log_mask(LOG_GUEST_ERROR, "%s: Tried to push to RX FIFO when " + "full\n", path); + return; + } + trace_dw_i3c_push_rx(s->cfg.id, val); + fifo32_push(&s->rx_queue, val); + + ARRAY_FIELD_DP32(s->regs, DATA_BUFFER_STATUS_LEVEL, RX_BUF_BLR, + fifo32_num_used(&s->rx_queue)); + /* Threshold is 2^RX_BUF_THLD. */ + uint8_t threshold =3D ARRAY_FIELD_EX32(s->regs, DATA_BUFFER_THLD_CTRL, + RX_BUF_THLD); + threshold =3D dw_i3c_fifo_threshold_from_reg(threshold); + if (fifo32_num_used(&s->rx_queue) >=3D threshold) { + ARRAY_FIELD_DP32(s->regs, INTR_STATUS, RX_THLD, 1); + dw_i3c_update_irq(s); + } +} + +static void dw_i3c_short_transfer(DWI3C *s, DWI3CTransferCmd cmd, + DWI3CShortArg arg) +{ + uint8_t err =3D DW_I3C_RESP_QUEUE_ERR_NONE; + uint8_t addr =3D dw_i3c_target_addr(s, cmd.dev_index); + bool is_i2c =3D dw_i3c_target_is_i2c(s, cmd.dev_index); + uint8_t data[4]; /* Max we can send on a short transfer is 4 bytes. */ + uint8_t len =3D 0; + uint32_t bytes_sent; /* Ignored on short transfers. */ + + /* Can't do reads on a short transfer. */ + if (cmd.rnw) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); + qemu_log_mask(LOG_GUEST_ERROR, "%s: Cannot do a read on a short " + "transfer\n", path); + return; + } + + if (dw_i3c_send_start(s, addr, /*is_recv=3D*/false, is_i2c)) { + err =3D DW_I3C_RESP_QUEUE_ERR_I2C_NACK; + goto transfer_done; + } + + /* Are we sending a command? */ + if (cmd.cp) { + data[len] =3D cmd.cmd; + len++; + /* + * byte0 is the defining byte for a command, and is only sent if a + * command is present and if the command has a defining byte prese= nt. + * (byte_strb & 0x01) is always treated as set by the controller, = and is + * ignored. + */ + if (cmd.dbp) { + data[len] +=3D arg.byte0; + len++; + } + } + + /* Send the bytes passed in the argument. */ + if (arg.byte_strb & 0x02) { + data[len] =3D arg.byte1; + len++; + } + if (arg.byte_strb & 0x04) { + data[len] =3D arg.byte2; + len++; + } + + if (dw_i3c_send(s, data, len, &bytes_sent, is_i2c)) { + err =3D DW_I3C_RESP_QUEUE_ERR_I2C_NACK; + } else { + /* Only go to an idle state on a successful transfer. */ + ARRAY_FIELD_DP32(s->regs, PRESENT_STATE, CM_TFR_ST_STATUS, + DW_I3C_TRANSFER_STATE_IDLE); + } + +transfer_done: + if (cmd.toc) { + dw_i3c_end_transfer(s, is_i2c); + } + if (cmd.roc) { + /* + * ccc_type is always 0 in controller mode, data_len is 0 in short + * transfers. + */ + dw_i3c_resp_queue_push(s, err, cmd.tid, /*ccc_type=3D*/0, + /*data_len=3D*/0); + } +} + +/* Returns number of bytes transmitted. */ +static uint16_t dw_i3c_tx(DWI3C *s, uint16_t num, bool is_i2c) +{ + uint16_t bytes_sent =3D 0; + union { + uint8_t b[sizeof(uint32_t)]; + uint32_t val; + } val32; + + while (bytes_sent < num) { + val32.val =3D dw_i3c_pop_tx(s); + for (uint8_t i =3D 0; i < sizeof(val32.val); i++) { + if (dw_i3c_send_byte(s, val32.b[i], is_i2c)) { + return bytes_sent; + } + bytes_sent++; + + /* We're not sending the full 32-bits, break early. */ + if (bytes_sent >=3D num) { + break; + } + } + } + + return bytes_sent; +} + +/* Returns number of bytes received. */ +static uint16_t dw_i3c_rx(DWI3C *s, uint16_t num, bool is_i2c) +{ + /* + * Allocate a temporary buffer to read data from the target. + * Zero it and word-align it as well in case we're reading unaligned d= ata. + */ + g_autofree uint8_t *data =3D g_new0(uint8_t, num + (4 - (num & 0x03))); + uint32_t *data32 =3D (uint32_t *)data; + /* + * 32-bits since the I3C API wants a 32-bit number, even though the + * controller can only do 16-bit transfers. + */ + uint32_t num_read =3D 0; + + /* Can NACK if the target receives an unsupported CCC. */ + if (dw_i3c_recv_data(s, is_i2c, data, num, &num_read)) { + return 0; + } + + for (uint16_t i =3D 0; i < num_read / 4; i++) { + dw_i3c_push_rx(s, *data32); + data32++; + } + /* + * If we're pushing data that isn't 32-bit aligned, push what's left. + * It's software's responsibility to know what bits are valid in the p= artial + * data. + */ + if (num_read & 0x03) { + dw_i3c_push_rx(s, *data32); + } + + return num_read; +} + +static int dw_i3c_transfer_ccc(DWI3C *s, DWI3CTransferCmd cmd, + DWI3CTransferArg arg) +{ + /* CCC start is always a write. CCCs cannot be done on I2C devices. */ + if (dw_i3c_send_start(s, I3C_BROADCAST, /*is_recv=3D*/false, + /*is_i2c=3D*/false)) { + return DW_I3C_RESP_QUEUE_ERR_BROADCAST_NACK; + } + trace_dw_i3c_transfer_ccc(s->cfg.id, cmd.cmd); + if (dw_i3c_send_byte(s, cmd.cmd, /*is_i2c=3D*/false)) { + return DW_I3C_RESP_QUEUE_ERR_I2C_NACK; + } + + /* On a direct CCC, we do a restart and then send the target's address= . */ + if (CCC_IS_DIRECT(cmd.cmd)) { + bool is_recv =3D cmd.rnw; + uint8_t addr =3D dw_i3c_target_addr(s, cmd.dev_index); + if (dw_i3c_send_start(s, addr, is_recv, /*is_i2c=3D*/false)) { + return DW_I3C_RESP_QUEUE_ERR_BROADCAST_NACK; + } + } + + return DW_I3C_RESP_QUEUE_ERR_NONE; +} + +static void dw_i3c_transfer(DWI3C *s, DWI3CTransferCmd cmd, + DWI3CTransferArg arg) +{ + bool is_recv =3D cmd.rnw; + uint8_t err =3D DW_I3C_RESP_QUEUE_ERR_NONE; + uint8_t addr =3D dw_i3c_target_addr(s, cmd.dev_index); + bool is_i2c =3D dw_i3c_target_is_i2c(s, cmd.dev_index); + uint16_t bytes_transferred =3D 0; + + if (cmd.cp) { + /* We're sending a CCC. */ + err =3D dw_i3c_transfer_ccc(s, cmd, arg); + if (err !=3D DW_I3C_RESP_QUEUE_ERR_NONE) { + goto transfer_done; + } + } else { + if (ARRAY_FIELD_EX32(s->regs, DEVICE_CTRL, I3C_BROADCAST_ADDR_INC)= && + is_i2c =3D=3D false) { + if (dw_i3c_send_start(s, I3C_BROADCAST, + /*is_recv=3D*/false, is_i2c))= { + err =3D DW_I3C_RESP_QUEUE_ERR_I2C_NACK; + goto transfer_done; + } + } + /* Otherwise we're doing a private transfer. */ + if (dw_i3c_send_start(s, addr, is_recv, is_i2c)) { + err =3D DW_I3C_RESP_QUEUE_ERR_I2C_NACK; + goto transfer_done; + } + } + + if (is_recv) { + bytes_transferred =3D dw_i3c_rx(s, arg.data_len, is_i2c); + } else { + bytes_transferred =3D dw_i3c_tx(s, arg.data_len, is_i2c); + } + + ARRAY_FIELD_DP32(s->regs, PRESENT_STATE, CM_TFR_ST_STATUS, + DW_I3C_TRANSFER_STATE_IDLE); + +transfer_done: + if (cmd.toc) { + dw_i3c_end_transfer(s, is_i2c); + } + if (cmd.roc) { + /* + * data_len is the number of bytes that still need to be TX'd, or = the + * number of bytes RX'd. + */ + uint16_t data_len =3D is_recv ? bytes_transferred : arg.data_len - + bytes_transferre= d; + /* CCCT is always 0 in controller mode. */ + dw_i3c_resp_queue_push(s, err, cmd.tid, /*ccc_type=3D*/0, + data_len); + } + + dw_i3c_update_irq(s); +} + +static void dw_i3c_transfer_cmd(DWI3C *s, DWI3CTransferCmd cmd, + DWI3CCmdQueueData arg) +{ + uint8_t arg_attr =3D FIELD_EX32(arg.word, COMMAND_QUEUE_PORT, CMD_ATTR= ); + + ARRAY_FIELD_DP32(s->regs, PRESENT_STATE, CMD_TID, cmd.tid); + + /* User is trying to do HDR transfers, see if we can do them. */ + if (cmd.speed =3D=3D 0x06 && !dw_i3c_has_hdr_ddr(s)) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); + qemu_log_mask(LOG_GUEST_ERROR, "%s: HDR DDR is not supported\n", p= ath); + ARRAY_FIELD_DP32(s->regs, PRESENT_STATE, CM_TFR_ST_STATUS, + DW_I3C_TRANSFER_STATE_HALT); + return; + } + if (cmd.speed =3D=3D 0x05 && !dw_i3c_has_hdr_ts(s)) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); + qemu_log_mask(LOG_GUEST_ERROR, "%s: HDR TS is not supported\n", pa= th); + ARRAY_FIELD_DP32(s->regs, PRESENT_STATE, CM_TFR_ST_STATUS, + DW_I3C_TRANSFER_STATE_HALT); + return; + } + + if (arg_attr =3D=3D DW_I3C_CMD_ATTR_TRANSFER_ARG) { + dw_i3c_transfer(s, cmd, arg.transfer_arg); + } else if (arg_attr =3D=3D DW_I3C_CMD_ATTR_SHORT_DATA_ARG) { + dw_i3c_short_transfer(s, cmd, arg.short_arg); + } else { + g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); + qemu_log_mask(LOG_GUEST_ERROR, "%s: Unknown command queue cmd_attr= 0x%x" + "\n", path, arg_attr); + ARRAY_FIELD_DP32(s->regs, PRESENT_STATE, CM_TFR_ST_STATUS, + DW_I3C_TRANSFER_STATE_HALT); + } +} + +static void dw_i3c_update_char_table(DWI3C *s, uint8_t offset, uint64_t pi= d, + uint8_t bcr, uint8_t dcr, uint8_t add= r) +{ + if (offset > s->cfg.num_addressable_devices) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); + qemu_log_mask(LOG_GUEST_ERROR, "%s: Device char table offset %d ou= t of " + "bounds\n", path, offset); + /* If we're out of bounds, do nothing. */ + return; + } + + /* + * Each device offset is 128 bits apart in the table, since each devic= e gets + * 4 * 32-bits of entries in the table. + * / sizeof(uint32_t) because we're indexing into our 32-bit reg array. + */ + uint16_t dev_index =3D (ARRAY_FIELD_EX32(s->regs, DEV_CHAR_TABLE_POINT= ER, + P_DEV_CHAR_TABLE_START_ADDR) / + sizeof(uint32_t)) + + (offset * sizeof(uint32_t)); + s->regs[dev_index] =3D pid & 0xffffffff; + pid >>=3D 32; + s->regs[dev_index + 1] =3D FIELD_DP32(s->regs[dev_index + 1], + DEVICE_CHARACTERISTIC_TABLE_LOC2, + MSB_PID, pid); + s->regs[dev_index + 2] =3D FIELD_DP32(s->regs[dev_index + 2], + DEVICE_CHARACTERISTIC_TABLE_LOC3, = DCR, + dcr); + s->regs[dev_index + 2] =3D FIELD_DP32(s->regs[dev_index + 2], + DEVICE_CHARACTERISTIC_TABLE_LOC3, = BCR, + bcr); + s->regs[dev_index + 3] =3D FIELD_DP32(s->regs[dev_index + 3], + DEVICE_CHARACTERISTIC_TABLE_LOC4, + DEV_DYNAMIC_ADDR, addr); + + /* Increment PRESENT_DEV_CHAR_TABLE_INDEX. */ + uint8_t idx =3D ARRAY_FIELD_EX32(s->regs, DEV_CHAR_TABLE_POINTER, + PRESENT_DEV_CHAR_TABLE_INDEX); + /* Increment and rollover. */ + idx++; + if (idx >=3D ARRAY_FIELD_EX32(s->regs, DEV_CHAR_TABLE_POINTER, + DEV_CHAR_TABLE_DEPTH) / 4) { + idx =3D 0; + } + ARRAY_FIELD_DP32(s->regs, DEV_CHAR_TABLE_POINTER, + PRESENT_DEV_CHAR_TABLE_INDEX, idx); +} + +static void dw_i3c_addr_assign_cmd(DWI3C *s, DWI3CAddrAssignCmd cmd) +{ + uint8_t i =3D 0; + uint8_t err =3D DW_I3C_RESP_QUEUE_ERR_NONE; + + /* Tell everyone to ENTDAA. If these error, no one is on the bus. */ + if (dw_i3c_send_start(s, I3C_BROADCAST, /*is_recv=3D*/false, + /*is_i2c=3D*/false)) { + err =3D DW_I3C_RESP_QUEUE_ERR_BROADCAST_NACK; + goto transfer_done; + } + if (dw_i3c_send_byte(s, cmd.cmd, /*is_i2c=3D*/false)) { + err =3D DW_I3C_RESP_QUEUE_ERR_BROADCAST_NACK; + goto transfer_done; + } + + /* Go through each device in the table and assign it an address. */ + for (i =3D 0; i < cmd.dev_count; i++) { + uint8_t addr =3D dw_i3c_target_addr(s, cmd.dev_index + i); + union { + uint64_t pid:48; + uint8_t bcr; + uint8_t dcr; + uint32_t w[2]; + uint8_t b[8]; + } target_info; + + /* If this fails, there was no one left to ENTDAA. */ + if (dw_i3c_send_start(s, I3C_BROADCAST, /*is_recv=3D*/false, + /*is_i2c=3D*/false)) { + err =3D DW_I3C_RESP_QUEUE_ERR_BROADCAST_NACK; + break; + } + + /* + * In ENTDAA, we read 8 bytes from the target, which will be the + * target's PID, BCR, and DCR. After that, we send it the dynamic + * address. + * Don't bother checking the number of bytes received, it must sen= d 8 + * bytes during ENTDAA. + */ + uint32_t num_read; + if (dw_i3c_recv_data(s, /*is_i2c=3D*/false, target_info.b, + I3C_ENTDAA_SIZE, &num_read)) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); + qemu_log_mask(LOG_GUEST_ERROR, "%s: Target NACKed ENTDAA CCC\n= ", + path); + err =3D DW_I3C_RESP_QUEUE_ERR_DAA_NACK; + goto transfer_done; + } + if (dw_i3c_send_byte(s, addr, /*is_i2c=3D*/false)) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); + qemu_log_mask(LOG_GUEST_ERROR, "%s: Target NACKed addr 0x%.2x " + "during ENTDAA\n", path, addr); + err =3D DW_I3C_RESP_QUEUE_ERR_DAA_NACK; + break; + } + dw_i3c_update_char_table(s, cmd.dev_index + i, + target_info.pid, target_info.b= cr, + target_info.dcr, addr); + + /* Push the PID, BCR, and DCR to the RX queue. */ + dw_i3c_push_rx(s, target_info.w[0]); + dw_i3c_push_rx(s, target_info.w[1]); + } + +transfer_done: + /* Do we send a STOP? */ + if (cmd.toc) { + dw_i3c_end_transfer(s, /*is_i2c=3D*/false); + } + /* + * For addr assign commands, the length field is the number of devices + * left to assign. CCCT is always 0 in controller mode. + */ + if (cmd.roc) { + dw_i3c_resp_queue_push(s, err, cmd.tid, /*ccc_type=3D*/0, + cmd.dev_count - i); + } +} + +static uint32_t dw_i3c_cmd_queue_pop(DWI3C *s) +{ + if (fifo32_is_empty(&s->cmd_queue)) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); + qemu_log_mask(LOG_GUEST_ERROR, "%s: Tried to dequeue command queue= " + "when it was empty\n", path); + return 0; + } + uint32_t val =3D fifo32_pop(&s->cmd_queue); + + uint8_t empty_threshold =3D ARRAY_FIELD_EX32(s->regs, QUEUE_THLD_CTRL, + CMD_BUF_EMPTY_THLD); + uint8_t cmd_queue_empty_loc =3D ARRAY_FIELD_EX32(s->regs, + QUEUE_STATUS_LEVEL, + CMD_QUEUE_EMPTY_LOC); + cmd_queue_empty_loc++; + ARRAY_FIELD_DP32(s->regs, QUEUE_STATUS_LEVEL, CMD_QUEUE_EMPTY_LOC, + cmd_queue_empty_loc); + if (cmd_queue_empty_loc >=3D empty_threshold) { + ARRAY_FIELD_DP32(s->regs, INTR_STATUS, CMD_QUEUE_RDY, 1); + dw_i3c_update_irq(s); + } + + return val; +} + +static void dw_i3c_cmd_queue_execute(DWI3C *s) +{ + ARRAY_FIELD_DP32(s->regs, PRESENT_STATE, CM_TFR_ST_STATUS, + DW_I3C_TRANSFER_STATE_IDLE); + if (!dw_i3c_can_transmit(s)) { + return; + } + + /* + * We only start executing when a command is passed into the FIFO. + * We expect there to be a multiple of 2 items in the queue. The first= item + * should be an argument to a command, and the command should be the s= econd + * item. + */ + if (fifo32_num_used(&s->cmd_queue) & 1) { + return; + } + + while (!fifo32_is_empty(&s->cmd_queue)) { + DWI3CCmdQueueData arg; + arg.word =3D dw_i3c_cmd_queue_pop(s); + DWI3CCmdQueueData cmd; + cmd.word =3D dw_i3c_cmd_queue_pop(s); + trace_dw_i3c_cmd_queue_execute(s->cfg.id, cmd.word, arg.word); + + uint8_t cmd_attr =3D FIELD_EX32(cmd.word, COMMAND_QUEUE_PORT, CMD_= ATTR); + switch (cmd_attr) { + case DW_I3C_CMD_ATTR_TRANSFER_CMD: + dw_i3c_transfer_cmd(s, cmd.transfer_cmd, arg); + break; + case DW_I3C_CMD_ATTR_ADDR_ASSIGN_CMD: + /* Arg is discarded for addr assign commands. */ + dw_i3c_addr_assign_cmd(s, cmd.addr_assign_cmd); + break; + case DW_I3C_CMD_ATTR_TRANSFER_ARG: + case DW_I3C_CMD_ATTR_SHORT_DATA_ARG: + { + g_autofree char *path =3D object_get_canonical_path(OBJECT= (s)); + qemu_log_mask(LOG_GUEST_ERROR, "%s: Command queue received= " + "argument packet when it expected a command " + "packet\n", path); + } + break; + default: + /* + * The caller's check before queueing an item should prevent t= his + * from happening. + */ + g_assert_not_reached(); + break; + } + } +} + +static void dw_i3c_cmd_queue_push(DWI3C *s, uint32_t val) +{ + if (fifo32_is_full(&s->cmd_queue)) { + g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); + qemu_log_mask(LOG_GUEST_ERROR, "%s: Command queue received packet = when " + "already full\n", path); + return; + } + trace_dw_i3c_cmd_queue_push(s->cfg.id, val); + fifo32_push(&s->cmd_queue, val); + + uint8_t empty_threshold =3D ARRAY_FIELD_EX32(s->regs, QUEUE_THLD_CTRL, + CMD_BUF_EMPTY_THLD); + uint8_t cmd_queue_empty_loc =3D ARRAY_FIELD_EX32(s->regs, + QUEUE_STATUS_LEVEL, + CMD_QUEUE_EMPTY_LOC); + if (cmd_queue_empty_loc) { + cmd_queue_empty_loc--; + ARRAY_FIELD_DP32(s->regs, QUEUE_STATUS_LEVEL, CMD_QUEUE_EMPTY_LOC, + cmd_queue_empty_loc); + } + if (cmd_queue_empty_loc < empty_threshold) { + ARRAY_FIELD_DP32(s->regs, INTR_STATUS, CMD_QUEUE_RDY, 0); + dw_i3c_update_irq(s); + } +} + +static void dw_i3c_cmd_queue_port_w(DWI3C *s, uint32_t val) +{ + uint8_t cmd_attr =3D FIELD_EX32(val, COMMAND_QUEUE_PORT, CMD_ATTR); + + switch (cmd_attr) { + /* If a command is received we can start executing it. */ + case DW_I3C_CMD_ATTR_TRANSFER_CMD: + case DW_I3C_CMD_ATTR_ADDR_ASSIGN_CMD: + dw_i3c_cmd_queue_push(s, val); + dw_i3c_cmd_queue_execute(s); + break; + /* If we get an argument just push it. */ + case DW_I3C_CMD_ATTR_TRANSFER_ARG: + case DW_I3C_CMD_ATTR_SHORT_DATA_ARG: + dw_i3c_cmd_queue_push(s, val); + break; + default: + { + g_autofree char *path =3D object_get_canonical_path(OBJECT(s)); + qemu_log_mask(LOG_GUEST_ERROR, "%s: Command queue received pac= ket " + "with unknown cmd attr 0x%x\n", path, cmd_attr); + } + break; + } +} + static void dw_i3c_write(void *opaque, hwaddr offset, uint64_t value, unsigned size) { @@ -426,7 +1262,7 @@ static void dw_i3c_write(void *opaque, hwaddr offset, = uint64_t value, uint32_t addr =3D offset >> 2; uint32_t val32 =3D (uint32_t)value; =20 - trace_dw_i3c_write(s->id, offset, value); + trace_dw_i3c_write(s->cfg.id, offset, value); =20 val32 &=3D ~dw_i3c_ro[addr]; switch (addr) { @@ -450,6 +1286,10 @@ static void dw_i3c_write(void *opaque, hwaddr offset,= uint64_t value, __func__, offset, value); break; case R_RX_TX_DATA_PORT: + dw_i3c_push_tx(s, val32); + break; + case R_COMMAND_QUEUE_PORT: + dw_i3c_cmd_queue_port_w(s, val32); break; case R_RESET_CTRL: break; @@ -492,22 +1332,56 @@ static void dw_i3c_reset_enter(Object *obj, ResetTyp= e type) DWI3C *s =3D DW_I3C(obj); =20 memcpy(s->regs, dw_i3c_resets, sizeof(s->regs)); + /* + * The user config for these may differ from our resets array, set them + * manually. + */ + ARRAY_FIELD_DP32(s->regs, DEVICE_ADDR_TABLE_POINTER, ADDR, + s->cfg.dev_addr_table_pointer); + ARRAY_FIELD_DP32(s->regs, DEVICE_ADDR_TABLE_POINTER, DEPTH, + s->cfg.dev_addr_table_depth); + ARRAY_FIELD_DP32(s->regs, DEV_CHAR_TABLE_POINTER, + P_DEV_CHAR_TABLE_START_ADDR, + s->cfg.dev_char_table_pointer); + ARRAY_FIELD_DP32(s->regs, DEV_CHAR_TABLE_POINTER, DEV_CHAR_TABLE_DEPTH, + s->cfg.dev_char_table_depth); } =20 static void dw_i3c_realize(DeviceState *dev, Error **errp) { DWI3C *s =3D DW_I3C(dev); - g_autofree char *name =3D g_strdup_printf(TYPE_DW_I3C ".%d", s->id); + g_autofree char *name =3D g_strdup_printf(TYPE_DW_I3C ".%d", s->cfg.id= ); =20 sysbus_init_irq(SYS_BUS_DEVICE(dev), &s->irq); =20 memory_region_init_io(&s->mr, OBJECT(s), &dw_i3c_ops, s, name, DW_I3C_NR_REGS << 2); sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->mr); + + fifo32_create(&s->cmd_queue, s->cfg.cmd_resp_queue_capacity_bytes); + fifo32_create(&s->resp_queue, s->cfg.cmd_resp_queue_capacity_bytes); + fifo32_create(&s->tx_queue, s->cfg.tx_rx_queue_capacity_bytes); + fifo32_create(&s->rx_queue, s->cfg.tx_rx_queue_capacity_bytes); + + s->bus =3D i3c_init_bus(DEVICE(s), name); } =20 static const Property dw_i3c_properties[] =3D { - DEFINE_PROP_UINT8("device-id", DWI3C, id, 0), + DEFINE_PROP_UINT8("device-id", DWI3C, cfg.id, 0), + DEFINE_PROP_UINT8("command-response-queue-capacity-bytes", DWI3C, + cfg.cmd_resp_queue_capacity_bytes, 0x10), + DEFINE_PROP_UINT16("tx-rx-queue-capacity-bytes", DWI3C, + cfg.tx_rx_queue_capacity_bytes, 0x40), + DEFINE_PROP_UINT8("num-addressable-devices", DWI3C, + cfg.num_addressable_devices, 8), + DEFINE_PROP_UINT16("dev-addr-table-pointer", DWI3C, + cfg.dev_addr_table_pointer, 0x280), + DEFINE_PROP_UINT16("dev-addr-table-depth", DWI3C, + cfg.dev_addr_table_depth, 0x08), + DEFINE_PROP_UINT16("dev-char-table-pointer", DWI3C, + cfg.dev_char_table_pointer, 0x200), + DEFINE_PROP_UINT16("dev-char-table-depth", DWI3C, + cfg.dev_char_table_depth, 0x20), }; =20 static void dw_i3c_class_init(ObjectClass *klass, const void *data) diff --git a/hw/i3c/trace-events b/hw/i3c/trace-events index 2d944387db..044ff06a01 100644 --- a/hw/i3c/trace-events +++ b/hw/i3c/trace-events @@ -7,6 +7,16 @@ aspeed_i3c_write(uint64_t offset, uint64_t data) "I3C writ= e: offset 0x%" PRIx64 # dw-i3c,c dw_i3c_read(uint32_t deviceid, uint64_t offset, uint64_t data) "I3C Dev[%u= ] read: offset 0x%" PRIx64 " data 0x%" PRIx64 dw_i3c_write(uint32_t deviceid, uint64_t offset, uint64_t data) "I3C Dev[%= u] write: offset 0x%" PRIx64 " data 0x%" PRIx64 +dw_i3c_send(uint32_t deviceid, uint32_t num_bytes) "I3C Dev[%u] send %" PR= Id32 " bytes to bus" +dw_i3c_recv_data(uint32_t deviceid, uint32_t num_bytes) "I3C Dev[%u] recv = %" PRId32 " bytes from bus" +dw_i3c_pop_rx(uint32_t deviceid, uint32_t data) "I3C Dev[%u] pop 0x%" PRIx= 32 " from RX FIFO" +dw_i3c_resp_queue_push(uint32_t deviceid, uint32_t data) "I3C Dev[%u] push= 0x%" PRIx32 " to response queue" +dw_i3c_push_tx(uint32_t deviceid, uint32_t data) "I3C Dev[%u] push 0x%" PR= Ix32 " to TX FIFO" +dw_i3c_pop_tx(uint32_t deviceid, uint32_t data) "I3C Dev[%u] pop 0x%" PRIx= 32 " from TX FIFO" +dw_i3c_push_rx(uint32_t deviceid, uint32_t data) "I3C Dev[%u] push 0x%" PR= Ix32 " to RX FIFO" +dw_i3c_transfer_ccc(uint32_t deviceid, uint8_t ccc) "I3C Dev[%u] transfer = CCC 0x%" PRIx8 +dw_i3c_cmd_queue_execute(uint32_t deviceid, uint32_t cmd, uint32_t arg) "I= 3C Dev[%u] execute command 0x%" PRIx32 " arg 0x%" PRIx32 +dw_i3c_cmd_queue_push(uint32_t deviceid, uint32_t data) "I3C Dev[%u] push = 0x%" PRIx32 " to cmd queue" =20 # core.c i3c_target_event(uint8_t address, uint8_t event) "I3C target 0x%" PRIx8 " = event 0x%" PRIx8 diff --git a/include/hw/i3c/aspeed_i3c.h b/include/hw/i3c/aspeed_i3c.h index 793ee111cb..9833292ec0 100644 --- a/include/hw/i3c/aspeed_i3c.h +++ b/include/hw/i3c/aspeed_i3c.h @@ -2,6 +2,7 @@ * ASPEED I3C Controller * * Copyright (C) 2021 ASPEED Technology Inc. + * Copyright (C) 2023 Google, LLC * * This code is licensed under the GPL version 2 or later. See * the COPYING file in the top-level directory. diff --git a/include/hw/i3c/dw-i3c.h b/include/hw/i3c/dw-i3c.h index 214f5ffed2..3de2e46b09 100644 --- a/include/hw/i3c/dw-i3c.h +++ b/include/hw/i3c/dw-i3c.h @@ -10,12 +10,136 @@ #ifndef DW_I3C_H #define DW_I3C_H =20 +#include "qemu/fifo32.h" +#include "hw/i3c/i3c.h" #include "hw/sysbus.h" =20 #define TYPE_DW_I3C "dw.i3c" OBJECT_DECLARE_SIMPLE_TYPE(DWI3C, DW_I3C) =20 -#define DW_I3C_NR_REGS (0x300 >> 2) +/* + * Sufficiently large enough to handle configurations with large device ad= dress + * tables. + */ +#define DW_I3C_NR_REGS (0x1000 >> 2) + +/* From datasheet. */ +#define DW_I3C_CMD_ATTR_TRANSFER_CMD 0 +#define DW_I3C_CMD_ATTR_TRANSFER_ARG 1 +#define DW_I3C_CMD_ATTR_SHORT_DATA_ARG 2 +#define DW_I3C_CMD_ATTR_ADDR_ASSIGN_CMD 3 + +/* Enum values from datasheet. */ +typedef enum DWI3CRespQueueErr { + DW_I3C_RESP_QUEUE_ERR_NONE =3D 0, + DW_I3C_RESP_QUEUE_ERR_CRC =3D 1, + DW_I3C_RESP_QUEUE_ERR_PARITY =3D 2, + DW_I3C_RESP_QUEUE_ERR_FRAME =3D 3, + DW_I3C_RESP_QUEUE_ERR_BROADCAST_NACK =3D 4, + DW_I3C_RESP_QUEUE_ERR_DAA_NACK =3D 5, + DW_I3C_RESP_QUEUE_ERR_OVERFLOW =3D 6, + DW_I3C_RESP_QUEUE_ERR_ABORTED =3D 8, + DW_I3C_RESP_QUEUE_ERR_I2C_NACK =3D 9, +} DWI3CRespQueueErr; + +typedef enum DWI3CTransferState { + DW_I3C_TRANSFER_STATE_IDLE =3D 0x00, + DW_I3C_TRANSFER_STATE_START =3D 0x01, + DW_I3C_TRANSFER_STATE_RESTART =3D 0x02, + DW_I3C_TRANSFER_STATE_STOP =3D 0x03, + DW_I3C_TRANSFER_STATE_START_HOLD =3D 0x04, + DW_I3C_TRANSFER_STATE_BROADCAST_W =3D 0x05, + DW_I3C_TRANSFER_STATE_BROADCAST_R =3D 0x06, + DW_I3C_TRANSFER_STATE_DAA =3D 0x07, + DW_I3C_TRANSFER_STATE_DAA_GEN =3D 0x08, + DW_I3C_TRANSFER_STATE_CCC_BYTE =3D 0x0b, + DW_I3C_TRANSFER_STATE_HDR_CMD =3D 0x0c, + DW_I3C_TRANSFER_STATE_WRITE =3D 0x0d, + DW_I3C_TRANSFER_STATE_READ =3D 0x0e, + DW_I3C_TRANSFER_STATE_IBI_READ =3D 0x0f, + DW_I3C_TRANSFER_STATE_IBI_DIS =3D 0x10, + DW_I3C_TRANSFER_STATE_HDR_DDR_CRC =3D 0x11, + DW_I3C_TRANSFER_STATE_CLK_STRETCH =3D 0x12, + DW_I3C_TRANSFER_STATE_HALT =3D 0x13, +} DWI3CTransferState; + +typedef enum DWI3CTransferStatus { + DW_I3C_TRANSFER_STATUS_IDLE =3D 0x00, + DW_I3C_TRANSFER_STATUS_BROACAST_CCC =3D 0x01, + DW_I3C_TRANSFER_STATUS_DIRECT_CCC_W =3D 0x02, + DW_I3C_TRANSFER_STATUS_DIRECT_CCC_R =3D 0x03, + DW_I3C_TRANSFER_STATUS_ENTDAA =3D 0x04, + DW_I3C_TRANSFER_STATUS_SETDASA =3D 0x05, + DW_I3C_TRANSFER_STATUS_I3C_SDR_W =3D 0x06, + DW_I3C_TRANSFER_STATUS_I3C_SDR_R =3D 0x07, + DW_I3C_TRANSFER_STATUS_I2C_SDR_W =3D 0x08, + DW_I3C_TRANSFER_STATUS_I2C_SDR_R =3D 0x09, + DW_I3C_TRANSFER_STATUS_HDR_TS_W =3D 0x0a, + DW_I3C_TRANSFER_STATUS_HDR_TS_R =3D 0x0b, + DW_I3C_TRANSFER_STATUS_HDR_DDR_W =3D 0x0c, + DW_I3C_TRANSFER_STATUS_HDR_DDR_R =3D 0x0d, + DW_I3C_TRANSFER_STATUS_IBI =3D 0x0e, + DW_I3C_TRANSFER_STATUS_HALT =3D 0x0f, +} DWI3CTransferStatus; + +/* + * Transfer commands and arguments are 32-bit wide values that the user pa= sses + * into the command queue. We interpret each 32-bit word based on the cmd_= attr + * field. + */ +typedef struct DWI3CTransferCmd { + uint8_t cmd_attr:3; + uint8_t tid:4; /* Transaction ID */ + uint16_t cmd:8; + uint8_t cp:1; /* Command present */ + uint8_t dev_index:5; + uint8_t speed:3; + uint8_t resv0:1; + uint8_t dbp:1; /* Defining byte present */ + uint8_t roc:1; /* Response on completion */ + uint8_t sdap:1; /* Short data argument present */ + uint8_t rnw:1; /* Read not write */ + uint8_t resv1:1; + uint8_t toc:1; /* Termination (I3C STOP) on completion */ + uint8_t pec:1; /* Parity error check enabled */ +} DWI3CTransferCmd; + +typedef struct DWI3CTransferArg { + uint8_t cmd_attr:3; + uint8_t resv:5; + uint8_t db; /* Defining byte */ + uint16_t data_len; +} DWI3CTransferArg; + +typedef struct DWI3CShortArg { + uint8_t cmd_attr:3; + uint8_t byte_strb:3; + uint8_t resv:2; + uint8_t byte0; + uint8_t byte1; + uint8_t byte2; +} DWI3CShortArg; + +typedef struct DWI3CAddrAssignCmd { + uint8_t cmd_attr:3; + uint8_t tid:4; /* Transaction ID */ + uint16_t cmd:8; + uint8_t resv0:1; + uint8_t dev_index:5; + uint16_t dev_count:5; + uint8_t roc:1; /* Response on completion */ + uint8_t resv1:3; + uint8_t toc:1; /* Termination (I3C STOP) on completion */ + uint8_t resv2:1; +} DWI3CAddrAssignCmd; + +typedef union DWI3CCmdQueueData { + uint32_t word; + DWI3CTransferCmd transfer_cmd; + DWI3CTransferArg transfer_arg; + DWI3CShortArg short_arg; + DWI3CAddrAssignCmd addr_assign_cmd; +} DWI3CCmdQueueData; =20 typedef struct DWI3C { /* */ @@ -24,8 +148,23 @@ typedef struct DWI3C { /* */ MemoryRegion mr; qemu_irq irq; + I3CBus *bus; + + Fifo32 cmd_queue; + Fifo32 resp_queue; + Fifo32 tx_queue; + Fifo32 rx_queue; =20 - uint8_t id; + struct { + uint8_t id; + uint8_t cmd_resp_queue_capacity_bytes; + uint16_t tx_rx_queue_capacity_bytes; + uint8_t num_addressable_devices; + uint16_t dev_addr_table_pointer; + uint16_t dev_addr_table_depth; + uint16_t dev_char_table_pointer; + uint16_t dev_char_table_depth; + } cfg; uint32_t regs[DW_I3C_NR_REGS]; } DWI3C; =20 --=20 2.50.0.rc1.591.g9c95f17f64-goog From nobody Sat Nov 15 16:09:06 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1749773278; cv=none; d=zohomail.com; s=zohoarc; b=PJ8dj6kBWkM+w/klqSiAOrTuGuptYi8JZbJMTd1ERVL4Z/5chOY6qwvH3kiHYBcub/DRPo5o6uqKWgYKwQEmmBPlMZmdMsCxBgtvy2Mi8mgeLCJt0t+Dwhv/qXkmrTCruLPNphu1pGmbOl7NsBjMhvis6EXH4x96zLvFeTUUIcs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749773278; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=8C3VgK1ZX7GYEarJgog+aC0MW3DwCChIc2JJrdXQp18=; b=lIRChi67KQ3IF7v/P5+TOcUIag6pk7VXhz3tnfSOeonUNhs53U++0noeub481LacHFf4WQwCJTo7tjUfztnotg33Q+0o3MGPBcrc62CiltkzLnguSKckm+9Zz/jupCmUHp3xrM0O8PNr54JLTdu9p0kp4tHt4xUIz76RgPTWFTQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 174977327878165.33837529002153; Thu, 12 Jun 2025 17:07:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPrwh-0007w1-Sx; Thu, 12 Jun 2025 20:06:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3DmtLaAcKClsDHFEH6B9HH9E7.5HFJ7FN-67O7EGHG9GN.HK9@flex--komlodi.bounces.google.com>) id 1uPruV-0005t2-Sk for qemu-devel@nongnu.org; Thu, 12 Jun 2025 20:04:47 -0400 Received: from mail-pf1-x449.google.com ([2607:f8b0:4864:20::449]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3DmtLaAcKClsDHFEH6B9HH9E7.5HFJ7FN-67O7EGHG9GN.HK9@flex--komlodi.bounces.google.com>) id 1uPruL-0000b4-Vy for qemu-devel@nongnu.org; Thu, 12 Jun 2025 20:04:37 -0400 Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-74858256d38so1091829b3a.2 for ; Thu, 12 Jun 2025 17:04:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1749773071; x=1750377871; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=8C3VgK1ZX7GYEarJgog+aC0MW3DwCChIc2JJrdXQp18=; b=Nj5bczcgpjSicspgrEG9V5nYxiWUVAzl8VGTHPT7QxTabt2n8tt1Bxp3+oJzTYQqNW Sta2h0ywI4kOMWYPbjHozqtXf5Gp1gLfPmN6QBfw7LDK4me7gWXM6GxK259KA8PTyrlL 25OnQg8KsoYWacXYB1V8nQN4s74V/J5Yq9vircagXsF7NjJtfRHDupVJtU6YuAX375Ct tkh+iS7o6AShtJuv0eBSKm1fbgQgu3oqXl9tftZzATDjEvAM9oRqGpkx9VBOd5m6zy21 wg9oKOS6YDO7bhZL/PsJ6SwoKISbVwJcO3rZGXy1u64a0Lr2U9+ucOoF06b+PWO/awJe tx7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749773071; x=1750377871; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=8C3VgK1ZX7GYEarJgog+aC0MW3DwCChIc2JJrdXQp18=; b=hnwbOcjQnlAPYBBhUHP+0lak6glSO4q0bSWsJodz3Pt2zD7/VdXt+RCyXa4RLUeUYA CMonh2BqXE33gAKJ3WxrUUYz6eCAQ1l2xfsWU87eKPTUhd7hmy1dQq4L/mXHf/3H8JnJ lEbGQZZyfFF0NLR+RQ0RTJnEGT57J33Ml1At+N0oekBnaohrKC46l9qM6C05Se/AursD TQ4l+Ayr0ADPkBnLQoFW9y6z2waLjEVukAyiTYGPOjpx3CCZvRF+uCy5hoHczPRFTrlT AGR6R6bMRLRkan0cg4oPGhIJ/RPM9u9PaGdBZfB8jawMpFeK0dM44Le8Y68c4Mhkr/Zu M5hg== X-Gm-Message-State: AOJu0YzXQ7SaBZ0k+eWD/2gWocuIh3tnCKUBfSG2m1u6YU+Pp+wRne41 duzTTOM3wIaUHXc+JWGbaeMaW9bIG4buNsQBxN/OY/+mAT/b479nvxzIYj+JIhUfuaZ1llRpaHk pDtmhoVXcZfnp+bCf4jx9y+Wu+iDmxJfJ8EfPMd/bSbJODaBIR6hxjsib41aLR7YVRe8ZjqjRM8 9U1ScrGNBQfkzJNyuCyRVxc/jRTvFlgwBCJYCJCW4J X-Google-Smtp-Source: AGHT+IGyIoqd3mQVLLIRstlT1lE8jxebq2Nhc8fWbty+Z0d0pJUuIQ45bVWGyIsyP+Wei9bD1AFmR3g5G9KH X-Received: from pgbcw6.prod.google.com ([2002:a05:6a02:4286:b0:af9:8f44:d7ec]) (user=komlodi job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:4312:b0:1ee:a914:1d67 with SMTP id adf61e73a8af0-21fac851b5cmr1298105637.2.1749773070888; Thu, 12 Jun 2025 17:04:30 -0700 (PDT) Date: Fri, 13 Jun 2025 00:04:05 +0000 In-Reply-To: <20250613000411.1516521-1-komlodi@google.com> Mime-Version: 1.0 References: <20250613000411.1516521-1-komlodi@google.com> X-Mailer: git-send-email 2.50.0.rc1.591.g9c95f17f64-goog Message-ID: <20250613000411.1516521-14-komlodi@google.com> Subject: [PATCH 13/19] hw/i3c/dw-i3c: Add IBI handling From: Joe Komlodi To: qemu-devel@nongnu.org Cc: venture@google.com, komlodi@google.com, clg@kaod.org, peter.maydell@linaro.org, steven_lee@aspeedtech.com, leetroy@gmail.com, jamin_lin@aspeedtech.com, andrew@codeconstruct.com.au, joel@jms.id.au, qemu-arm@nongnu.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::449; envelope-from=3DmtLaAcKClsDHFEH6B9HH9E7.5HFJ7FN-67O7EGHG9GN.HK9@flex--komlodi.bounces.google.com; helo=mail-pf1-x449.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1749773281443116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Adds handling for different IBI events that the controller can receive. This includes: - Handling a hot-join from a target - Handling a secondary controller on the bus requesting to be the primary bus controller - Handling an interrupt request from a target. When receiving an IBI, the controller sets an interrupt to notify software about what happened. When the IBI is finished being serviced, the controller pushes the result of the IBI and any data received from the target into the IBI queue. Signed-off-by: Joe Komlodi Reviewed-by: Patrick Venture Reviewed-by: Stephen Longfield --- hw/i3c/dw-i3c.c | 317 ++++++++++++++++++++++++++++++++++++++++ hw/i3c/trace-events | 2 + include/hw/i3c/dw-i3c.h | 27 ++++ 3 files changed, 346 insertions(+) diff --git a/hw/i3c/dw-i3c.c b/hw/i3c/dw-i3c.c index 2c3e1a5760..c5af331ac4 100644 --- a/hw/i3c/dw-i3c.c +++ b/hw/i3c/dw-i3c.c @@ -19,6 +19,14 @@ #include "trace.h" #include "hw/irq.h" =20 +/* + * Disable event command values. sent along with a DISEC CCC to disable ce= rtain + * events on targets. + */ +#define DISEC_HJ 0x08 +#define DISEC_CR 0x02 +#define DISEC_INT 0x01 + REG32(DEVICE_CTRL, 0x00) FIELD(DEVICE_CTRL, I3C_BROADCAST_ADDR_INC, 0, 1) FIELD(DEVICE_CTRL, I2C_SLAVE_PRESENT, 7, 1) @@ -373,6 +381,23 @@ static inline bool dw_i3c_can_transmit(DWI3C *s) !ARRAY_FIELD_EX32(s->regs, DEVICE_CTRL, I3C_RESUME); } =20 +static inline uint8_t dw_i3c_ibi_slice_size(DWI3C *s) +{ + uint8_t ibi_slice_size =3D ARRAY_FIELD_EX32(s->regs, QUEUE_THLD_CTRL, + IBI_DATA_THLD); + /* The minimum supported slice size is 4 bytes. */ + if (ibi_slice_size =3D=3D 0) { + ibi_slice_size =3D 1; + } + ibi_slice_size *=3D sizeof(uint32_t); + /* maximum supported size is 63 bytes. */ + if (ibi_slice_size >=3D 64) { + ibi_slice_size =3D 63; + } + + return ibi_slice_size; +} + static inline uint8_t dw_i3c_fifo_threshold_from_reg(uint8_t regval) { return regval =3D regval ? (2 << regval) : 1; @@ -526,6 +551,266 @@ static uint8_t dw_i3c_target_addr(DWI3C *s, uint16_t = offset) DEV_DYNAMIC_ADDR); } =20 +static int dw_i3c_addr_table_index_from_addr(DWI3C *s, uint8_t addr) +{ + uint8_t table_size =3D ARRAY_FIELD_EX32(s->regs, DEVICE_ADDR_TABLE_POI= NTER, + DEPTH); + for (uint8_t i =3D 0; i < table_size; i++) { + if (dw_i3c_target_addr(s, i) =3D=3D addr) { + return i; + } + } + return -1; +} + +static void dw_i3c_send_disec(DWI3C *s) +{ + uint8_t ccc =3D I3C_CCC_DISEC; + if (s->ibi_data.send_direct_disec) { + ccc =3D I3C_CCCD_DISEC; + } + + dw_i3c_send_start(s, I3C_BROADCAST, /*is_recv=3D*/false, + /*is_i2c=3D*/false); + dw_i3c_send_byte(s, ccc, /*is_i2c=3D*/false); + if (s->ibi_data.send_direct_disec) { + dw_i3c_send_start(s, s->ibi_data.disec_addr, + /*is_recv=3D*/false, /*is_i2c=3D*/fal= se); + } + dw_i3c_send_byte(s, s->ibi_data.disec_byte, /*is_i2c=3D*/false); +} + +static int dw_i3c_handle_hj(DWI3C *s) +{ + if (ARRAY_FIELD_EX32(s->regs, IBI_QUEUE_CTRL, NOTIFY_REJECTED_HOT_JOIN= )) { + s->ibi_data.notify_ibi_nack =3D true; + } + + bool nack_and_disable =3D ARRAY_FIELD_EX32(s->regs, DEVICE_CTRL, + HOT_JOIN_ACK_NACK_CTRL); + if (nack_and_disable) { + s->ibi_data.ibi_queue_status =3D FIELD_DP32(s->ibi_data.ibi_queue_= status, + IBI_QUEUE_STATUS, + IBI_STATUS, 1); + s->ibi_data.ibi_nacked =3D true; + s->ibi_data.disec_byte =3D DISEC_HJ; + return -1; + } + return 0; +} + +static int dw_i3c_handle_ctlr_req(DWI3C *s, uint8_t addr) +{ + if (ARRAY_FIELD_EX32(s->regs, IBI_QUEUE_CTRL, NOTIFY_REJECTED_MASTER_R= EQ)) { + s->ibi_data.notify_ibi_nack =3D true; + } + + int table_offset =3D dw_i3c_addr_table_index_from_addr(s, addr); + /* Doesn't exist in the table, NACK it, don't DISEC. */ + if (table_offset < 0) { + return -1; + } + + /* / sizeof(uint32_t) because we're indexing into our 32-bit reg array= . */ + table_offset +=3D (ARRAY_FIELD_EX32(s->regs, DEVICE_ADDR_TABLE_POINTER, + ADDR) / sizeof(uint32_t)); + if (FIELD_EX32(s->regs[table_offset], DEVICE_ADDR_TABLE_LOC1, MR_REJEC= T)) { + s->ibi_data.ibi_queue_status =3D FIELD_DP32(s->ibi_data.ibi_queue_= status, + IBI_QUEUE_STATUS, + IBI_STATUS, 1); + s->ibi_data.ibi_nacked =3D true; + s->ibi_data.disec_addr =3D addr; + /* Tell the requester to disable controller role requests. */ + s->ibi_data.disec_byte =3D DISEC_CR; + s->ibi_data.send_direct_disec =3D true; + return -1; + } + return 0; +} + +static int dw_i3c_handle_targ_irq(DWI3C *s, uint8_t addr) +{ + if (ARRAY_FIELD_EX32(s->regs, IBI_QUEUE_CTRL, NOTIFY_REJECTED_SLAVE_IR= Q)) { + s->ibi_data.notify_ibi_nack =3D true; + } + + int table_offset =3D dw_i3c_addr_table_index_from_addr(s, addr); + /* Doesn't exist in the table, NACK it, don't DISEC. */ + if (table_offset < 0) { + return -1; + } + + /* / sizeof(uint32_t) because we're indexing into our 32-bit reg array= . */ + table_offset +=3D (ARRAY_FIELD_EX32(s->regs, DEVICE_ADDR_TABLE_POINTER, + ADDR) / sizeof(uint32_t)); + if (FIELD_EX32(s->regs[table_offset], DEVICE_ADDR_TABLE_LOC1, SIR_REJE= CT)) { + s->ibi_data.ibi_queue_status =3D FIELD_DP32(s->ibi_data.ibi_queue_= status, + IBI_QUEUE_STATUS, + IBI_STATUS, 1); + s->ibi_data.ibi_nacked =3D true; + s->ibi_data.disec_addr =3D addr; + /* Tell the requester to disable interrupts. */ + s->ibi_data.disec_byte =3D DISEC_INT; + s->ibi_data.send_direct_disec =3D true; + return -1; + } + return 0; +} + +static int dw_i3c_ibi_handle(I3CBus *bus, uint8_t addr, bool is_recv) +{ + DWI3C *s =3D DW_I3C(bus->qbus.parent); + + trace_dw_i3c_ibi_handle(s->cfg.id, addr, is_recv); + s->ibi_data.ibi_queue_status =3D FIELD_DP32(s->ibi_data.ibi_queue_stat= us, + IBI_QUEUE_STATUS, IBI_ID, + (addr << 1) | is_recv); + /* Is this a hot join request? */ + if (addr =3D=3D I3C_HJ_ADDR) { + return dw_i3c_handle_hj(s); + } + /* Is secondary controller requesting access? */ + if (!is_recv) { + return dw_i3c_handle_ctlr_req(s, addr); + } + /* Is this a target IRQ? */ + if (is_recv) { + return dw_i3c_handle_targ_irq(s, addr); + } + + /* At this point the IBI should have been ACKed or NACKed. */ + g_assert_not_reached(); + return -1; +} + +static int dw_i3c_ibi_recv(I3CBus *bus, uint8_t data) +{ + DWI3C *s =3D DW_I3C(bus->qbus.parent); + if (fifo8_is_full(&s->ibi_data.ibi_intermediate_queue)) { + return -1; + } + + fifo8_push(&s->ibi_data.ibi_intermediate_queue, data); + trace_dw_i3c_ibi_recv(s->cfg.id, data); + return 0; +} + +static void dw_i3c_ibi_queue_push(DWI3C *s) +{ + /* Stored value is in 32-bit chunks, convert it to byte chunks. */ + uint8_t ibi_slice_size =3D dw_i3c_ibi_slice_size(s); + uint8_t num_slices =3D (fifo8_num_used(&s->ibi_data.ibi_intermediate_q= ueue) / + ibi_slice_size) + + ((fifo8_num_used(&s->ibi_data.ibi_intermediate_qu= eue) % + ibi_slice_size) ? 1 : 0); + uint8_t ibi_status_count =3D num_slices; + union { + uint8_t b[sizeof(uint32_t)]; + uint32_t val32; + } ibi_data =3D { + .val32 =3D 0 + }; + + /* The report was suppressed, do nothing. */ + if (s->ibi_data.ibi_nacked && !s->ibi_data.notify_ibi_nack) { + ARRAY_FIELD_DP32(s->regs, PRESENT_STATE, CM_TFR_ST_STATUS, + DW_I3C_TRANSFER_STATE_IDLE); + ARRAY_FIELD_DP32(s->regs, PRESENT_STATE, CM_TFR_STATUS, + DW_I3C_TRANSFER_STATUS_IDLE); + return; + } + + /* If we don't have any slices to push, just push the status. */ + if (num_slices =3D=3D 0) { + s->ibi_data.ibi_queue_status =3D + FIELD_DP32(s->ibi_data.ibi_queue_status, IBI_QUEUE_STATUS, + LAST_STATUS, 1); + fifo32_push(&s->ibi_queue, s->ibi_data.ibi_queue_status); + ibi_status_count =3D 1; + } + + for (uint8_t i =3D 0; i < num_slices; i++) { + /* If this is the last slice, set LAST_STATUS. */ + if (fifo8_num_used(&s->ibi_data.ibi_intermediate_queue) < + ibi_slice_size) { + s->ibi_data.ibi_queue_status =3D + FIELD_DP32(s->ibi_data.ibi_queue_status, IBI_QUEUE_STATUS, + IBI_DATA_LEN, + fifo8_num_used(&s->ibi_data.ibi_intermediate_qu= eue)); + s->ibi_data.ibi_queue_status =3D + FIELD_DP32(s->ibi_data.ibi_queue_status, IBI_QUEUE_STATUS, + LAST_STATUS, 1); + } else { + s->ibi_data.ibi_queue_status =3D + FIELD_DP32(s->ibi_data.ibi_queue_status, IBI_QUEUE_STATUS, + IBI_DATA_LEN, ibi_slice_size); + } + + /* Push the IBI status header. */ + fifo32_push(&s->ibi_queue, s->ibi_data.ibi_queue_status); + /* Move each IBI byte into a 32-bit word and push it into the queu= e. */ + for (uint8_t j =3D 0; j < ibi_slice_size; ++j) { + if (fifo8_is_empty(&s->ibi_data.ibi_intermediate_queue)) { + break; + } + + ibi_data.b[j & 3] =3D fifo8_pop(&s->ibi_data.ibi_intermediate_= queue); + /* We have 32-bits, push it to the IBI FIFO. */ + if ((j & 0x03) =3D=3D 0x03) { + fifo32_push(&s->ibi_queue, ibi_data.val32); + ibi_data.val32 =3D 0; + } + } + /* If the data isn't 32-bit aligned, push the leftover bytes. */ + if (ibi_slice_size & 0x03) { + fifo32_push(&s->ibi_queue, ibi_data.val32); + } + + /* Clear out the data length for the next iteration. */ + s->ibi_data.ibi_queue_status =3D FIELD_DP32(s->ibi_data.ibi_queue_= status, + IBI_QUEUE_STATUS, IBI_DATA_LEN, 0= ); + } + + ARRAY_FIELD_DP32(s->regs, QUEUE_STATUS_LEVEL, IBI_BUF_BLR, + fifo32_num_used(&s->ibi_queue)); + ARRAY_FIELD_DP32(s->regs, QUEUE_STATUS_LEVEL, IBI_STATUS_CNT, + ibi_status_count); + /* Threshold is the register value + 1. */ + uint8_t threshold =3D ARRAY_FIELD_EX32(s->regs, QUEUE_THLD_CTRL, + IBI_STATUS_THLD) + 1; + if (fifo32_num_used(&s->ibi_queue) >=3D threshold) { + ARRAY_FIELD_DP32(s->regs, INTR_STATUS, IBI_THLD, 1); + dw_i3c_update_irq(s); + } + + /* State update. */ + ARRAY_FIELD_DP32(s->regs, PRESENT_STATE, CM_TFR_ST_STATUS, + DW_I3C_TRANSFER_STATE_IDLE); + ARRAY_FIELD_DP32(s->regs, PRESENT_STATE, CM_TFR_STATUS, + DW_I3C_TRANSFER_STATUS_IDLE); +} + +static int dw_i3c_ibi_finish(I3CBus *bus) +{ + DWI3C *s =3D DW_I3C(bus->qbus.parent); + bool nack_and_disable_hj =3D ARRAY_FIELD_EX32(s->regs, DEVICE_CTRL, + HOT_JOIN_ACK_NACK_CTRL); + if (nack_and_disable_hj || s->ibi_data.send_direct_disec) { + dw_i3c_send_disec(s); + } + dw_i3c_ibi_queue_push(s); + + /* Clear out the intermediate values. */ + s->ibi_data.ibi_queue_status =3D 0; + s->ibi_data.disec_addr =3D 0; + s->ibi_data.disec_byte =3D 0; + s->ibi_data.send_direct_disec =3D false; + s->ibi_data.notify_ibi_nack =3D false; + s->ibi_data.ibi_nacked =3D false; + + return 0; +} + static uint32_t dw_i3c_intr_status_r(DWI3C *s) { /* Only return the status whose corresponding EN bits are set. */ @@ -586,6 +871,25 @@ static uint32_t dw_i3c_pop_rx(DWI3C *s) return val; } =20 +static uint32_t dw_i3c_ibi_queue_r(DWI3C *s) +{ + if (fifo32_is_empty(&s->ibi_queue)) { + return 0; + } + + uint32_t val =3D fifo32_pop(&s->ibi_queue); + ARRAY_FIELD_DP32(s->regs, QUEUE_STATUS_LEVEL, IBI_BUF_BLR, + fifo32_num_used(&s->ibi_queue)); + /* Threshold is the register value + 1. */ + uint8_t threshold =3D ARRAY_FIELD_EX32(s->regs, QUEUE_THLD_CTRL, + IBI_STATUS_THLD) + 1; + if (fifo32_num_used(&s->ibi_queue) < threshold) { + ARRAY_FIELD_DP32(s->regs, INTR_STATUS, IBI_THLD, 0); + dw_i3c_update_irq(s); + } + return val; +} + static uint32_t dw_i3c_resp_queue_port_r(DWI3C *s) { if (fifo32_is_empty(&s->resp_queue)) { @@ -623,6 +927,9 @@ static uint64_t dw_i3c_read(void *opaque, hwaddr offset= , unsigned size) case R_INTR_FORCE: value =3D 0; break; + case R_IBI_QUEUE_DATA: + value =3D dw_i3c_ibi_queue_r(s); + break; case R_INTR_STATUS: value =3D dw_i3c_intr_status_r(s); break; @@ -1362,8 +1669,16 @@ static void dw_i3c_realize(DeviceState *dev, Error *= *errp) fifo32_create(&s->resp_queue, s->cfg.cmd_resp_queue_capacity_bytes); fifo32_create(&s->tx_queue, s->cfg.tx_rx_queue_capacity_bytes); fifo32_create(&s->rx_queue, s->cfg.tx_rx_queue_capacity_bytes); + fifo32_create(&s->ibi_queue, s->cfg.ibi_queue_capacity_bytes); + /* Arbitrarily large enough to not be an issue. */ + fifo8_create(&s->ibi_data.ibi_intermediate_queue, + s->cfg.ibi_queue_capacity_bytes * 8); =20 s->bus =3D i3c_init_bus(DEVICE(s), name); + I3CBusClass *bc =3D I3C_BUS_GET_CLASS(s->bus); + bc->ibi_handle =3D dw_i3c_ibi_handle; + bc->ibi_recv =3D dw_i3c_ibi_recv; + bc->ibi_finish =3D dw_i3c_ibi_finish; } =20 static const Property dw_i3c_properties[] =3D { @@ -1372,6 +1687,8 @@ static const Property dw_i3c_properties[] =3D { cfg.cmd_resp_queue_capacity_bytes, 0x10), DEFINE_PROP_UINT16("tx-rx-queue-capacity-bytes", DWI3C, cfg.tx_rx_queue_capacity_bytes, 0x40), + DEFINE_PROP_UINT8("ibi-queue-capacity-bytes", DWI3C, + cfg.ibi_queue_capacity_bytes, 0x10), DEFINE_PROP_UINT8("num-addressable-devices", DWI3C, cfg.num_addressable_devices, 8), DEFINE_PROP_UINT16("dev-addr-table-pointer", DWI3C, diff --git a/hw/i3c/trace-events b/hw/i3c/trace-events index 044ff06a01..a262fcce39 100644 --- a/hw/i3c/trace-events +++ b/hw/i3c/trace-events @@ -9,6 +9,8 @@ dw_i3c_read(uint32_t deviceid, uint64_t offset, uint64_t da= ta) "I3C Dev[%u] read dw_i3c_write(uint32_t deviceid, uint64_t offset, uint64_t data) "I3C Dev[%= u] write: offset 0x%" PRIx64 " data 0x%" PRIx64 dw_i3c_send(uint32_t deviceid, uint32_t num_bytes) "I3C Dev[%u] send %" PR= Id32 " bytes to bus" dw_i3c_recv_data(uint32_t deviceid, uint32_t num_bytes) "I3C Dev[%u] recv = %" PRId32 " bytes from bus" +dw_i3c_ibi_recv(uint32_t deviceid, uint8_t ibi_byte) "I3C Dev[%u] recv IBI= byte 0x%" PRIx8 +dw_i3c_ibi_handle(uint32_t deviceid, uint8_t addr, bool rnw) "I3C Dev[%u] = handle IBI from address 0x%" PRIx8 " RnW=3D%d" dw_i3c_pop_rx(uint32_t deviceid, uint32_t data) "I3C Dev[%u] pop 0x%" PRIx= 32 " from RX FIFO" dw_i3c_resp_queue_push(uint32_t deviceid, uint32_t data) "I3C Dev[%u] push= 0x%" PRIx32 " to response queue" dw_i3c_push_tx(uint32_t deviceid, uint32_t data) "I3C Dev[%u] push 0x%" PR= Ix32 " to TX FIFO" diff --git a/include/hw/i3c/dw-i3c.h b/include/hw/i3c/dw-i3c.h index 3de2e46b09..a2cb375aa2 100644 --- a/include/hw/i3c/dw-i3c.h +++ b/include/hw/i3c/dw-i3c.h @@ -141,6 +141,28 @@ typedef union DWI3CCmdQueueData { DWI3CAddrAssignCmd addr_assign_cmd; } DWI3CCmdQueueData; =20 +/* + * When we receive an IBI with data, we need to store it temporarily until + * the target is finished sending data. Then we can set the IBI queue stat= us + * appropriately. + */ +typedef struct DWI3CIBIData { + /* Do we notify the user that an IBI was NACKed? */ + bool notify_ibi_nack; + /* Intermediate storage of IBI_QUEUE_STATUS. */ + uint32_t ibi_queue_status; + /* Temporary buffer to store IBI data from the target. */ + Fifo8 ibi_intermediate_queue; + /* The address we should send a CCC_DISEC to. */ + uint8_t disec_addr; + /* The byte we should send along with the CCC_DISEC. */ + uint8_t disec_byte; + /* Should we send a direct DISEC CCC? (As opposed to global). */ + bool send_direct_disec; + /* Was this IBI NACKed? */ + bool ibi_nacked; +} DWI3CIBIData; + typedef struct DWI3C { /* */ SysBusDevice parent; @@ -154,11 +176,16 @@ typedef struct DWI3C { Fifo32 resp_queue; Fifo32 tx_queue; Fifo32 rx_queue; + Fifo32 ibi_queue; + + /* Temporary storage for IBI data. */ + DWI3CIBIData ibi_data; =20 struct { uint8_t id; uint8_t cmd_resp_queue_capacity_bytes; uint16_t tx_rx_queue_capacity_bytes; + uint8_t ibi_queue_capacity_bytes; uint8_t num_addressable_devices; uint16_t dev_addr_table_pointer; uint16_t dev_addr_table_depth; --=20 2.50.0.rc1.591.g9c95f17f64-goog From nobody Sat Nov 15 16:09:06 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1749773353; cv=none; d=zohomail.com; s=zohoarc; b=d8CRYgnmXhtHekp/NVmcaDYPzyOFxjbEvqcbHrU443Vjc0S4QX7ZBOFNo/NnK9cOBFs4TuA0/mEK9ma5N+0Kswei2hwKgvkt7erFCUZpUomYCiU51nxLuGlYJCRK2UMOMel76nu/gJpO2PPBuVFDoMOPwGGzHSYN5Y9/rgd97Kc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749773353; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=OIZH2xkbqf0VU2m6tXJnpYTNb7RaFWBkaYVW+cq3n6g=; b=icpgqqqXDF60GQAnorqA2eDvJphMvBmBrc1GsNVIrcNxKT+4ptFq/6SGcibQ0fQpCIgJOBvPmViKzBa2OpZMZraZt6g4Zy5VBQDrwJK6pQiKutOm/0egnVVsyvYoyS6qr7YPrYnQ4dGD5+LXUGXtblF/loKC8b60+Y99rdPefTY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749773353650442.38320169187875; Thu, 12 Jun 2025 17:09:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPrwg-0007qo-RU; Thu, 12 Jun 2025 20:06:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3EGtLaAcKCl0FJHGJ8DBJJBG9.7JHL9HP-89Q9GIJIBIP.JMB@flex--komlodi.bounces.google.com>) id 1uPruU-0005sy-FR for qemu-devel@nongnu.org; Thu, 12 Jun 2025 20:04:47 -0400 Received: from mail-pl1-x649.google.com ([2607:f8b0:4864:20::649]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3EGtLaAcKCl0FJHGJ8DBJJBG9.7JHL9HP-89Q9GIJIBIP.JMB@flex--komlodi.bounces.google.com>) id 1uPruM-0000bH-Av for qemu-devel@nongnu.org; Thu, 12 Jun 2025 20:04:36 -0400 Received: by mail-pl1-x649.google.com with SMTP id d9443c01a7336-235e3f93687so18896045ad.2 for ; Thu, 12 Jun 2025 17:04:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1749773072; x=1750377872; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=OIZH2xkbqf0VU2m6tXJnpYTNb7RaFWBkaYVW+cq3n6g=; b=dnxTVhVntuJWK4JAjyE85IQnDZEheEM52MWq6HCHqtT5oGTzV+YnAp3x1zn41P1crR idptzk+YaPi2j1kJwvLm4+45lkJCIHUhd9xlGjFVK4qjwSlhgMQyS5i/7svDKUhj3oJj jXUPgLk/3k/Fo9e6F4BqnUnrcNRdcz8TjJlz2eGPcEWDXgteR8sAoUErl/tHcCKOql07 Lwj5e8JZxEbzw+TAUPRJCQDfUiyIcDJlcaWmhhbx+OcEb7V4UUqSxc8+B9ceIg8i1Jfo /xmOVAOFBMh+a27uc+wvoVugFjv8pTrfQ8qt/ljuA2bARIFHYdusVXR60lOvN92wucSb gkEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749773072; x=1750377872; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=OIZH2xkbqf0VU2m6tXJnpYTNb7RaFWBkaYVW+cq3n6g=; b=TCBefP1QAWoKcAjyJjytlhQ7p1vicoAFqdHgwXXHqLNx0tdIKu/JDypfnrzr3QAqJT dJa+8t5V73UYlrcIVPt+3C1EUqad3C3aFqX5oCvxUq8fE9YKO3oiHTgEGbGOsOaLqVTH o6ZYypjn964R3EAKRV6U3ajYVpw48H0IKq8wlH278EjUWhk7FSBhUF43RAH3W4Paoksk tzEJPnER3jJCR+YUQsw6Q2GjfSA+oHo1I9kQRU7JggrD6BldtIG4nZH3owuc9reyLrD2 q0CRhBRh7UcolFeo/Mo9UN0A3ns/K+0lz4qnIggpWbsR6PpX7dEFzrzinVntrLaMz5Kl YrrQ== X-Gm-Message-State: AOJu0YyzbCzA+U6H4bhoV3Ns9qAEPeA0NsccQ+zn64drfTUV3n40YwB3 /OCcQLAH4VSa06qUzaXrmD/THcFU6YxWSlCiBIzuFghQFNocPMQ8TucLGWHBOi08DgAklkxAwa3 nx20fJnTLHCknakUI6my6O7JxNoEQtRyfeqye2SSh81LQ6fiZ0EY+WaV+BWvrjZhutp2q/kcr1R Do/P3Cw8hK1WY05VqAopTKkNjDPo8To0WLRkKasNMO X-Google-Smtp-Source: AGHT+IEP1W9AelPzz3ZYsYe3gktWUdq580jYTbGroEtbfPQaUTVZGezYF+TuAf0CxnnchkAj23SD6RuUZ5ak X-Received: from pge22.prod.google.com ([2002:a05:6a02:2d16:b0:b2f:795e:379a]) (user=komlodi job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:be03:b0:235:27b6:a891 with SMTP id d9443c01a7336-2365da079a2mr10352165ad.28.1749773072319; Thu, 12 Jun 2025 17:04:32 -0700 (PDT) Date: Fri, 13 Jun 2025 00:04:06 +0000 In-Reply-To: <20250613000411.1516521-1-komlodi@google.com> Mime-Version: 1.0 References: <20250613000411.1516521-1-komlodi@google.com> X-Mailer: git-send-email 2.50.0.rc1.591.g9c95f17f64-goog Message-ID: <20250613000411.1516521-15-komlodi@google.com> Subject: [PATCH 14/19] hw/i3c/dw-i3c: Add ctrl MMIO handling From: Joe Komlodi To: qemu-devel@nongnu.org Cc: venture@google.com, komlodi@google.com, clg@kaod.org, peter.maydell@linaro.org, steven_lee@aspeedtech.com, leetroy@gmail.com, jamin_lin@aspeedtech.com, andrew@codeconstruct.com.au, joel@jms.id.au, qemu-arm@nongnu.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::649; envelope-from=3EGtLaAcKCl0FJHGJ8DBJJBG9.7JHL9HP-89Q9GIJIBIP.JMB@flex--komlodi.bounces.google.com; helo=mail-pl1-x649.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1749773355783116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Adds functionality to the CTRL register. Signed-off-by: Joe Komlodi Reviewed-by: Titus Rwantare Reviewed-by: Patrick Venture --- hw/i3c/dw-i3c.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/hw/i3c/dw-i3c.c b/hw/i3c/dw-i3c.c index c5af331ac4..61845c909f 100644 --- a/hw/i3c/dw-i3c.c +++ b/hw/i3c/dw-i3c.c @@ -361,6 +361,8 @@ static const uint32_t dw_i3c_ro[DW_I3C_NR_REGS] =3D { [R_SLAVE_CONFIG] =3D 0xffffffff, }; =20 +static void dw_i3c_cmd_queue_execute(DWI3C *s); + static inline bool dw_i3c_has_hdr_ts(DWI3C *s) { return ARRAY_FIELD_EX32(s->regs, HW_CAPABILITY, HDR_TS); @@ -520,6 +522,36 @@ static int dw_i3c_recv_data(DWI3C *s, bool is_i2c, uin= t8_t *data, return ret; } =20 +static void dw_i3c_ctrl_w(DWI3C *s, uint32_t val) +{ + /* + * If the user is setting I3C_RESUME, the controller was halted. + * Try and resume execution and leave the bit cleared. + */ + if (FIELD_EX32(val, DEVICE_CTRL, I3C_RESUME)) { + dw_i3c_cmd_queue_execute(s); + val =3D FIELD_DP32(val, DEVICE_CTRL, I3C_RESUME, 0); + } + /* + * I3C_ABORT being set sends an I3C STOP. It's cleared when the STOP is + * sent. + */ + if (FIELD_EX32(val, DEVICE_CTRL, I3C_ABORT)) { + dw_i3c_end_transfer(s, /*is_i2c=3D*/true); + dw_i3c_end_transfer(s, /*is_i2c=3D*/false); + val =3D FIELD_DP32(val, DEVICE_CTRL, I3C_ABORT, 0); + ARRAY_FIELD_DP32(s->regs, INTR_STATUS, TRANSFER_ABORT, 1); + dw_i3c_update_irq(s); + } + /* Update present state. */ + ARRAY_FIELD_DP32(s->regs, PRESENT_STATE, CM_TFR_ST_STATUS, + DW_I3C_TRANSFER_STATE_IDLE); + ARRAY_FIELD_DP32(s->regs, PRESENT_STATE, CM_TFR_STATUS, + DW_I3C_TRANSFER_STATUS_IDLE); + + s->regs[R_DEVICE_CTRL] =3D val; +} + static inline bool dw_i3c_target_is_i2c(DWI3C *s, uint16_t offset) { /* / sizeof(uint32_t) because we're indexing into our 32-bit reg array= . */ @@ -1592,6 +1624,9 @@ static void dw_i3c_write(void *opaque, hwaddr offset,= uint64_t value, "] =3D 0x%08" PRIx64 "\n", __func__, offset, value); break; + case R_DEVICE_CTRL: + dw_i3c_ctrl_w(s, val32); + break; case R_RX_TX_DATA_PORT: dw_i3c_push_tx(s, val32); break; --=20 2.50.0.rc1.591.g9c95f17f64-goog From nobody Sat Nov 15 16:09:06 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1749773272; cv=none; d=zohomail.com; s=zohoarc; b=i1ZExNqIbYEJai66c66p9pIjYOvELJgWptdFzxjGCUMEMWaWQaxYHsVWUrlGKDem/sBmjsYlDkK7sIkErgsD1bPjj9jvaDzaCm43ikrHiaitSTPYuhxVnSCYryRQN/LBxxclQ9vXDcHF+hGjiQhdU6MCXfskJIol9hX93zqNa7o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749773272; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=DyCoNnGqjybs2atj+VUDFeC2YSxcleyR8BFixP1/Qu4=; b=iPpxTWxzBk0uugqRGWxphJ9agqYCW75fxkRRS2NbMoHt2Tc0QUYLem7ugSIOtNPXy4VW+s4MnW+L6VokL3Bx2xqNOOrFlHUl21WShI5VjXHiZLBDLgcIvU/r/ZkDS1apWIZy7eSgIzsDjQqBsGJOjajYHvUteEKnwmFrWuZYS2U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749773272387759.7976313264594; Thu, 12 Jun 2025 17:07:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPrxM-0001RX-8O; Thu, 12 Jun 2025 20:07:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3EWtLaAcKCl4GKIHK9ECKKCHA.8KIMAIQ-9ARAHJKJCJQ.KNC@flex--komlodi.bounces.google.com>) id 1uPruV-0005t3-UD for qemu-devel@nongnu.org; Thu, 12 Jun 2025 20:04:47 -0400 Received: from mail-pg1-x549.google.com ([2607:f8b0:4864:20::549]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3EWtLaAcKCl4GKIHK9ECKKCHA.8KIMAIQ-9ARAHJKJCJQ.KNC@flex--komlodi.bounces.google.com>) id 1uPruN-0000bZ-I2 for qemu-devel@nongnu.org; Thu, 12 Jun 2025 20:04:40 -0400 Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-6c8f99fef10so1618108a12.3 for ; Thu, 12 Jun 2025 17:04:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1749773074; x=1750377874; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=DyCoNnGqjybs2atj+VUDFeC2YSxcleyR8BFixP1/Qu4=; b=J5PXfWF6Q0DbIIaNhIFwgx5tIcL4ct37bRm5ZYcMkKpuB3nBe8xKHO6I0z9hJbV5lb vmnUbikXq0a5x+S0QbI9YNP9MaBNwsiM+e3QUhFM2Uhdvgs6YlRLcG81o3VCYNeUS+7z CBW0se16UlSOApA1FXlbhXp5A4hXgr1e741+eKKf6CYWWZ6UftqUBrPKquuy9DyP3KY/ 8YTRF3MhzkH+tjtanFIr4dPMSGTobH2qvDYFvhN+rjUV9c8+rSAAyjsndr85zK+PyubF +uHrySZBhVWY4ihgwpQcZJarwLmRnPD80D3M1Yp7OisEgynIQjM/DT1+FtUY9MpUp5Ho YBDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749773074; x=1750377874; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=DyCoNnGqjybs2atj+VUDFeC2YSxcleyR8BFixP1/Qu4=; b=hnPzDkv08zWcwKlcN2daV8rV9F9Nj0dZMmSq1F8QNsPyFjA/jAiZKf87gMajGqCPHN dbgdB5s+J7aj6uAWKox5c6EjJhpUyg76dnxMCW552DzO0H5Cm5n9KB+dBskgIvbimb8g JKDIwmlzGR7jfWrzKMEOtPRnGPaSQUT/bpSqxgKUhlxEY/8L8zLlNWkPYeM4IpU0RzZZ U/TG8toHrMDciXouFg7crT7Tq7qTQV7sy9ztXfS6flMi0mF6WOxgAQaxu0pSf+c2hL5N Th6+XLBfBsGq/ew8eyQRNYPUNrwV48OLQR65O35er7mMVdOjlR2v33mOzIM3ItTQYsQI QtjQ== X-Gm-Message-State: AOJu0Yys5mxEY5NTtm12T4qdNfZqDdh9Ttw1XmrdtA7FaU5nSjiM1/rp 311T3tN0ql5UjvN+FrBXH8Mp1xkU/e5caMPlfQEk9XsbWK3jrdJuY3tgR1isBjGutMBkscVBu5z XZ5Z2lPJI9I5TVAnzCPHgxcNcH+ZHNoP1WO9iyoa5tceXucUFftVNYlOYX9kLrzCu6MG3gazBJR Jp0kyDXhfmg8PYMCCckbRGWFGOcd8pSWHmmKrRi7bv X-Google-Smtp-Source: AGHT+IEQNf3jfeqf9R3//A0o866O8OSG6b08lWEizaGS9QyaXLbndrVufc6kDUvYwo5Qco4ejdRPIzyI8PTv X-Received: from pgbda7.prod.google.com ([2002:a05:6a02:2387:b0:b2c:4fcd:fe1b]) (user=komlodi job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:9148:b0:21f:512c:ba2c with SMTP id adf61e73a8af0-21facec450emr1402302637.34.1749773073827; Thu, 12 Jun 2025 17:04:33 -0700 (PDT) Date: Fri, 13 Jun 2025 00:04:07 +0000 In-Reply-To: <20250613000411.1516521-1-komlodi@google.com> Mime-Version: 1.0 References: <20250613000411.1516521-1-komlodi@google.com> X-Mailer: git-send-email 2.50.0.rc1.591.g9c95f17f64-goog Message-ID: <20250613000411.1516521-16-komlodi@google.com> Subject: [PATCH 15/19] hw/i3c/dw-i3c: Add controller resets From: Joe Komlodi To: qemu-devel@nongnu.org Cc: venture@google.com, komlodi@google.com, clg@kaod.org, peter.maydell@linaro.org, steven_lee@aspeedtech.com, leetroy@gmail.com, jamin_lin@aspeedtech.com, andrew@codeconstruct.com.au, joel@jms.id.au, qemu-arm@nongnu.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::549; envelope-from=3EWtLaAcKCl4GKIHK9ECKKCHA.8KIMAIQ-9ARAHJKJCJQ.KNC@flex--komlodi.bounces.google.com; helo=mail-pg1-x549.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1749773275022116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Adds behavior to the device reset register. Signed-off-by: Joe Komlodi Reviewed-by: Patrick Venture Reviewed-by: Stephen Longfield --- hw/i3c/dw-i3c.c | 117 ++++++++++++++++++++++++++++++++++++++++++++ hw/i3c/trace-events | 1 + 2 files changed, 118 insertions(+) diff --git a/hw/i3c/dw-i3c.c b/hw/i3c/dw-i3c.c index 61845c909f..fff3a3591f 100644 --- a/hw/i3c/dw-i3c.c +++ b/hw/i3c/dw-i3c.c @@ -877,6 +877,122 @@ static void dw_i3c_intr_force_w(DWI3C *s, uint32_t va= l) dw_i3c_update_irq(s); } =20 +static void dw_i3c_cmd_queue_reset(DWI3C *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 =3D ARRAY_FIELD_EX32(s->regs, QUEUE_THLD_CTRL, + CMD_BUF_EMPTY_THLD); + if (fifo32_num_free(&s->cmd_queue) >=3D empty_threshold) { + ARRAY_FIELD_DP32(s->regs, INTR_STATUS, CMD_QUEUE_RDY, 1); + dw_i3c_update_irq(s); + }; +} + +static void dw_i3c_resp_queue_reset(DWI3C *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 mi= nimum + * of 1 and the queue size is 0. + */ + ARRAY_FIELD_DP32(s->regs, INTR_STATUS, RESP_RDY, 0); + dw_i3c_update_irq(s); +} + +static void dw_i3c_ibi_queue_reset(DWI3C *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 mi= nimum + * of 1 and the queue size is 0. + */ + ARRAY_FIELD_DP32(s->regs, INTR_STATUS, IBI_THLD, 0); + dw_i3c_update_irq(s); +} + +static void dw_i3c_tx_queue_reset(DWI3C *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); + dw_i3c_update_irq(s); +} + +static void dw_i3c_rx_queue_reset(DWI3C *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 mi= nimum + * of 1 and the queue size is 0. + */ + ARRAY_FIELD_DP32(s->regs, INTR_STATUS, RX_THLD, 0); + dw_i3c_update_irq(s); +} + +static void dw_i3c_reset(DeviceState *dev) +{ + DWI3C *s =3D DW_I3C(dev); + trace_dw_i3c_reset(s->cfg.id); + + memcpy(s->regs, dw_i3c_resets, sizeof(s->regs)); + /* + * The user config for these may differ from our resets array, set them + * manually. + */ + ARRAY_FIELD_DP32(s->regs, DEVICE_ADDR_TABLE_POINTER, ADDR, + s->cfg.dev_addr_table_pointer); + ARRAY_FIELD_DP32(s->regs, DEVICE_ADDR_TABLE_POINTER, DEPTH, + s->cfg.dev_addr_table_depth); + ARRAY_FIELD_DP32(s->regs, DEV_CHAR_TABLE_POINTER, + P_DEV_CHAR_TABLE_START_ADDR, + s->cfg.dev_char_table_pointer); + ARRAY_FIELD_DP32(s->regs, DEV_CHAR_TABLE_POINTER, DEV_CHAR_TABLE_DEPTH, + s->cfg.dev_char_table_depth); + + dw_i3c_cmd_queue_reset(s); + dw_i3c_resp_queue_reset(s); + dw_i3c_ibi_queue_reset(s); + dw_i3c_tx_queue_reset(s); + dw_i3c_rx_queue_reset(s); +} + +static void dw_i3c_reset_ctrl_w(DWI3C *s, uint32_t val) +{ + if (FIELD_EX32(val, RESET_CTRL, CORE_RESET)) { + dw_i3c_reset(DEVICE(s)); + } + if (FIELD_EX32(val, RESET_CTRL, CMD_QUEUE_RESET)) { + dw_i3c_cmd_queue_reset(s); + } + if (FIELD_EX32(val, RESET_CTRL, RESP_QUEUE_RESET)) { + dw_i3c_resp_queue_reset(s); + } + if (FIELD_EX32(val, RESET_CTRL, TX_BUF_RESET)) { + dw_i3c_tx_queue_reset(s); + } + if (FIELD_EX32(val, RESET_CTRL, RX_BUF_RESET)) { + dw_i3c_rx_queue_reset(s); + } + if (FIELD_EX32(val, RESET_CTRL, IBI_QUEUE_RESET)) { + dw_i3c_ibi_queue_reset(s); + } +} + static uint32_t dw_i3c_pop_rx(DWI3C *s) { if (fifo32_is_empty(&s->rx_queue)) { @@ -1634,6 +1750,7 @@ static void dw_i3c_write(void *opaque, hwaddr offset,= uint64_t value, dw_i3c_cmd_queue_port_w(s, val32); break; case R_RESET_CTRL: + dw_i3c_reset_ctrl_w(s, val32); break; case R_INTR_STATUS: dw_i3c_intr_status_w(s, val32); diff --git a/hw/i3c/trace-events b/hw/i3c/trace-events index a262fcce39..39f33d9a50 100644 --- a/hw/i3c/trace-events +++ b/hw/i3c/trace-events @@ -11,6 +11,7 @@ dw_i3c_send(uint32_t deviceid, uint32_t num_bytes) "I3C D= ev[%u] send %" PRId32 " dw_i3c_recv_data(uint32_t deviceid, uint32_t num_bytes) "I3C Dev[%u] recv = %" PRId32 " bytes from bus" dw_i3c_ibi_recv(uint32_t deviceid, uint8_t ibi_byte) "I3C Dev[%u] recv IBI= byte 0x%" PRIx8 dw_i3c_ibi_handle(uint32_t deviceid, uint8_t addr, bool rnw) "I3C Dev[%u] = handle IBI from address 0x%" PRIx8 " RnW=3D%d" +dw_i3c_reset(uint32_t deviceid) "I3C Dev[%u] reset" dw_i3c_pop_rx(uint32_t deviceid, uint32_t data) "I3C Dev[%u] pop 0x%" PRIx= 32 " from RX FIFO" dw_i3c_resp_queue_push(uint32_t deviceid, uint32_t data) "I3C Dev[%u] push= 0x%" PRIx32 " to response queue" dw_i3c_push_tx(uint32_t deviceid, uint32_t data) "I3C Dev[%u] push 0x%" PR= Ix32 " to TX FIFO" --=20 2.50.0.rc1.591.g9c95f17f64-goog From nobody Sat Nov 15 16:09:06 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1749773391; cv=none; d=zohomail.com; s=zohoarc; b=iQQF3oRv9FQHiipeSiH7oPES4Xxo6m2To2WFmAYuIiK5DG/glnyabpIJwGzyHu3RIyWVnrlhORfP779qiHo51/NgIU8z56aKn9cdhDmVNbWvcmFm8ZvT35JxRiUSjflkc5acsDfUFqfIemdk0oyjQ1uhMyX+mrb/MoFFQJQuHGQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749773391; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=pN6ktvXR5IcGeRx1cB4+P3xO5YRnqgnQGID5P3shDMc=; b=Si7Ngh1V1XW+xpiMflPRijSEUai4FeffsGWNAr+UTDszfPvAy3L9W9y/ZUA9dfE9Lb/ku7E+QA3w1wbZeGf5c/pq60mDXrmPyJX4biza4VVQnnSOwMm7kpEuzmm655B8sFOdIKBfqsRnQw+qISAnRDnGDuMYf58bSlDJe6ruuvs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749773391285499.2252290447508; Thu, 12 Jun 2025 17:09:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPrxJ-00016l-92; Thu, 12 Jun 2025 20:07:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3E2tLaAcKCmAIMKJMBGEMMEJC.AMKOCKS-BCTCJLMLELS.MPE@flex--komlodi.bounces.google.com>) id 1uPrud-0005tU-7e for qemu-devel@nongnu.org; Thu, 12 Jun 2025 20:04:55 -0400 Received: from mail-pg1-x549.google.com ([2607:f8b0:4864:20::549]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3E2tLaAcKCmAIMKJMBGEMMEJC.AMKOCKS-BCTCJLMLELS.MPE@flex--komlodi.bounces.google.com>) id 1uPruZ-0000bl-Cs for qemu-devel@nongnu.org; Thu, 12 Jun 2025 20:04:50 -0400 Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-b26e73d375aso1444230a12.2 for ; Thu, 12 Jun 2025 17:04:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1749773075; x=1750377875; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=pN6ktvXR5IcGeRx1cB4+P3xO5YRnqgnQGID5P3shDMc=; b=Wf5dAC8H5WjOjLP93XhN+dXmA8WPzwWgZWssReTjF0rbutcJ+pW3xClVeCHEYZy4R9 HtNK3rWxO9gDC/kxKoi6dQOvoznGC35JVkDxz9IVkqA4/yKgRujStIQPoVNbLUK6VieL oo5KAkhjnv8MwdzkSemrD4JtJ1A6qjXRxbx4Ep4y/97VVYDvevUCTKIa0xqyXNps7Bpr 9jaRSz919knoPh7SHKAf66SqU0ue9c4LVxoNo52lSsMJ6vo02GaF6xN1IrF7prZk8sWz f/9TT94zF6JQXaM4fpPY2pW12Kwru9xvz7bwSNcfPvY65U9NvLr14745oivOeqSoYHqJ cDyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749773075; x=1750377875; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=pN6ktvXR5IcGeRx1cB4+P3xO5YRnqgnQGID5P3shDMc=; b=ZZ2c7HqAKtb78lV40ZHyo30yCBgKlB+bi92ZWg1Qi+7Y3QBCZUN7tYzpxQuYgvKwjB tLtC2j3Fs96Y9JSq7c4QOMOT4/dfbjODumoHrDDtVhFow9347uYsPRh127qlTw6Ldk4s VXjv/QsXv4qgHUE5YNr+NiULMPB9Pw/RRGUb8upKgD2pXtfX2oCIQz4Wrfp3oUS4wTjS FJQagDHMHg+fNWBm57Z84eTC7nwF1C709AiiA40D7TjPqp5wvzktw2ectJH8ph0rpO0T +5XCUIBQW8ORjCjYpcraWxdD6Y8Zivgz4wb8lYX38PVHPMebr2k9WMVwEnwPfkoIT3hN waRQ== X-Gm-Message-State: AOJu0YzL4U6mx/RQMA/f/U3QeWXpkE2gHpQXASmNi1mbXjP4XJw6ZR6L I8zzHe0UJ6RGtXO3EzedU5OtKtF9zgcfR/qpYmri8ZRBcj9976KVz76W0Ma8bOL4vRqDBh8mvh9 2knLukNj/yM+yqlBMA6rGO950CbA6wkfKw1KYQJE/9ea7p2K5VQl7QyJioAdpKovckoNKZRJuni lnA0xn9KEFvZgEj8o4ab79fVjqTsKM4lGMVBvUzleo X-Google-Smtp-Source: AGHT+IFPONQP5DnSBqEEPxsAL2xmsePbPa1IuwYoWdmX218MRAG8eaFUT9eZo7aMFmZfmFZMhF43sl40WevP X-Received: from pgac23.prod.google.com ([2002:a05:6a02:2957:b0:b2e:b47d:8dc]) (user=komlodi job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:244b:b0:21f:4f34:6b1 with SMTP id adf61e73a8af0-21facb2719dmr1204032637.14.1749773075301; Thu, 12 Jun 2025 17:04:35 -0700 (PDT) Date: Fri, 13 Jun 2025 00:04:08 +0000 In-Reply-To: <20250613000411.1516521-1-komlodi@google.com> Mime-Version: 1.0 References: <20250613000411.1516521-1-komlodi@google.com> X-Mailer: git-send-email 2.50.0.rc1.591.g9c95f17f64-goog Message-ID: <20250613000411.1516521-17-komlodi@google.com> Subject: [PATCH 16/19] hw/i3c/aspeed: Add I3C bus get function From: Joe Komlodi To: qemu-devel@nongnu.org Cc: venture@google.com, komlodi@google.com, clg@kaod.org, peter.maydell@linaro.org, steven_lee@aspeedtech.com, leetroy@gmail.com, jamin_lin@aspeedtech.com, andrew@codeconstruct.com.au, joel@jms.id.au, qemu-arm@nongnu.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::549; envelope-from=3E2tLaAcKCmAIMKJMBGEMMEJC.AMKOCKS-BCTCJLMLELS.MPE@flex--komlodi.bounces.google.com; helo=mail-pg1-x549.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1749773392227116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" To retrieve the I3C bus object normally, the order is Aspeed I3C -> DW I3C[n] -> bus object, so make a nice wrapper for people to use. Signed-off-by: Joe Komlodi --- hw/i3c/aspeed_i3c.c | 9 +++++++++ include/hw/i3c/aspeed_i3c.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/hw/i3c/aspeed_i3c.c b/hw/i3c/aspeed_i3c.c index 1ad25e5a00..af1ff5bc12 100644 --- a/hw/i3c/aspeed_i3c.c +++ b/hw/i3c/aspeed_i3c.c @@ -153,6 +153,15 @@ static const MemoryRegionOps aspeed_i3c_ops =3D { } }; =20 +I3CBus *aspeed_i3c_get_bus(AspeedI3CState *s, uint8_t bus_num) +{ + if (bus_num < ARRAY_SIZE(s->devices)) { + return s->devices[bus_num].bus; + } + /* Developer error, fail fast. */ + g_assert_not_reached(); +} + static void aspeed_i3c_reset(DeviceState *dev) { AspeedI3CState *s =3D ASPEED_I3C(dev); diff --git a/include/hw/i3c/aspeed_i3c.h b/include/hw/i3c/aspeed_i3c.h index 9833292ec0..b3e4d1055c 100644 --- a/include/hw/i3c/aspeed_i3c.h +++ b/include/hw/i3c/aspeed_i3c.h @@ -34,3 +34,5 @@ typedef struct AspeedI3CState { uint8_t id; } AspeedI3CState; #endif /* ASPEED_I3C_H */ + +I3CBus *aspeed_i3c_get_bus(AspeedI3CState *s, uint8_t bus_num); --=20 2.50.0.rc1.591.g9c95f17f64-goog From nobody Sat Nov 15 16:09:06 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1749773263; cv=none; d=zohomail.com; s=zohoarc; b=iV4qa+Lv8HjHW/yrgvah/1pAC0Yr4LVbAGmejNoEK/NXtYS4eVzxw8we2KRUQfQvgiEVWaNoZaVDKY/xOEg2PBeTp6gXUUJYvQ1TVO+cIbNsloNatvaZeP/wQDvENQhP2iRGidjVWgLpcyitbL83Dfz/EXz5j3gYJXau5nyzMvg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749773263; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ttW1DzP9OWCZDqGp3U/516oCn+UzVifCZfp2E4TJHHs=; b=UzxZKKe5iVW1zvxX7sR5RXy62zCnciMGkAVVm67hUWAxmzeNMFnGU5HtXUdzdf2/bCcigR9kNj86KM20+G9fL2UhCpx1renWRDdy2RIjSQ2x6eIR3u6MpTARPlRkoiRpMf7UJOVSeLq2+geIWt3fXiNlhTIakkMBonRPKUJEkus= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749773263493232.44601560135288; Thu, 12 Jun 2025 17:07:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPrx9-0000Lf-BP; Thu, 12 Jun 2025 20:07:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3FGtLaAcKCmEJNLKNCHFNNFKD.BNLPDLT-CDUDKMNMFMT.NQF@flex--komlodi.bounces.google.com>) id 1uPrue-0005tn-Na for qemu-devel@nongnu.org; Thu, 12 Jun 2025 20:04:57 -0400 Received: from mail-pg1-x549.google.com ([2607:f8b0:4864:20::549]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3FGtLaAcKCmEJNLKNCHFNNFKD.BNLPDLT-CDUDKMNMFMT.NQF@flex--komlodi.bounces.google.com>) id 1uPruZ-0000bw-Cy for qemu-devel@nongnu.org; Thu, 12 Jun 2025 20:04:51 -0400 Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-b2fb347b3e4so960992a12.3 for ; Thu, 12 Jun 2025 17:04:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1749773076; x=1750377876; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ttW1DzP9OWCZDqGp3U/516oCn+UzVifCZfp2E4TJHHs=; b=eRDGnIR+neOtP6qwYvkO2OCwKD4LVso+57j1GZ+TcPXRpoElG+/oAfV+PLZsMiDSzI f/Y7c2rL2tUwxkrQCkqWkoP51bHlO3y4e6NGLHxyIO0CtQ4nbTQTXD9mZoMfVHDXxiyu y1XG+sQl2P7kzDUpK/XPELcRTdjnmByUkoyrRhIC1LouuryrY6K0gATzQK38BG8Tk9sF WaLXJyAgpeCEGO4m9ldmal6L/DY3KmWg+7EBwSqvW62O7QrV9XEBEOm2NbWOdIYEPn8S hNxjjfJlPHcHCwZQW3OeRbr+StA1kJfkEGEMuCCGUP9DE58Hupzhvd4t45Z+5ADQ/c0A cCpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749773076; x=1750377876; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ttW1DzP9OWCZDqGp3U/516oCn+UzVifCZfp2E4TJHHs=; b=cPx0CXEbwU/t6x8JHx0VV3duv3sQq7JqGPzyCqXgW1zsKtCYeLk/SZjYyAB6sQjjtt GRCiAFF4mKv26c+kZxkZrTkcHvuyOcaFeNUzIPsM3ZmB2UR9BCby3PO6uOz0q4yJtr02 iX6a+UMHwK75Fi3nQhjKfVeC5AyckKXrH1f2y7Di2cI377JxQaletG67XWzVPWLs0sG3 7QzZmKhi12T8KoFMzzH/hWIlJb0Vwyh20/ptltVJREPm/7OlTzlCQ5ZGfAZXbuStcKiC rmkYYY7VsQIfzL8t2JlRABI+ItyYAMgRlWifMjfwlb6xFKu+V8o6Vps1580VZ+ohyrtn gHQA== X-Gm-Message-State: AOJu0Yyj0sKUVuu2oNATDJ2Rz2W4GdY3RljQfAnqJ32Y9Rb0o1IqGnVr KqvUOnwqN6d1FuhtK5gdz2hMW81nNznf0LJSroVy7+16KIGiBKoG9YMrG3GRBm3DVU2ouua7Gts K6Ex2nsTUgfuUYqfie9SYyH+ByV5f4pQsbkJBcNyT0hzYcWzUbl6lckfQUnvXAvP8W17+lSZSMr ZHJ44v6DpO/b/o3B7x1j+upoaEA4gINc6SrnsqdzLb X-Google-Smtp-Source: AGHT+IG0pd5RCDR1yMfUW0BRksQbgS6AyIZULYdzSLWTHDQqW+vCTMldFlC84gm/amJMxZV5STuBolq4rbeV X-Received: from pgbbo5.prod.google.com ([2002:a05:6a02:385:b0:b2f:63c8:753d]) (user=komlodi job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:3942:b0:1f5:a3e8:64dd with SMTP id adf61e73a8af0-21fab5f2209mr1638430637.0.1749773076458; Thu, 12 Jun 2025 17:04:36 -0700 (PDT) Date: Fri, 13 Jun 2025 00:04:09 +0000 In-Reply-To: <20250613000411.1516521-1-komlodi@google.com> Mime-Version: 1.0 References: <20250613000411.1516521-1-komlodi@google.com> X-Mailer: git-send-email 2.50.0.rc1.591.g9c95f17f64-goog Message-ID: <20250613000411.1516521-18-komlodi@google.com> Subject: [PATCH 17/19] hw/i3c: Add Mock target From: Joe Komlodi To: qemu-devel@nongnu.org Cc: venture@google.com, komlodi@google.com, clg@kaod.org, peter.maydell@linaro.org, steven_lee@aspeedtech.com, leetroy@gmail.com, jamin_lin@aspeedtech.com, andrew@codeconstruct.com.au, joel@jms.id.au, qemu-arm@nongnu.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::549; envelope-from=3FGtLaAcKCmEJNLKNCHFNNFKD.BNLPDLT-CDUDKMNMFMT.NQF@flex--komlodi.bounces.google.com; helo=mail-pg1-x549.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1749773264834116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Adds a simple i3c device to be used for testing in lieu of a real device. The mock target supports the following features: - A buffer that users can read and write to. - CCC support for commonly used CCCs when probing devices on an I3C bus. - IBI sending upon receiving a user-defined byte. Signed-off-by: Joe Komlodi Reviewed-by: Titus Rwantare Reviewed-by: Patrick Venture --- hw/i3c/Kconfig | 10 + hw/i3c/meson.build | 1 + hw/i3c/mock-i3c-target.c | 311 +++++++++++++++++++++++++++++++ hw/i3c/trace-events | 9 + include/hw/i3c/mock-i3c-target.h | 52 ++++++ 5 files changed, 383 insertions(+) create mode 100644 hw/i3c/mock-i3c-target.c create mode 100644 include/hw/i3c/mock-i3c-target.h diff --git a/hw/i3c/Kconfig b/hw/i3c/Kconfig index ecec77d6fc..d5c6d4049b 100644 --- a/hw/i3c/Kconfig +++ b/hw/i3c/Kconfig @@ -3,3 +3,13 @@ config I3C =20 config DW_I3C bool + +config I3C_DEVICES + # Device group for i3c devices which can reasonably be user-plugged to= any + # board's i3c bus. + bool + +config MOCK_I3C_TARGET + bool + select I3C + default y if I3C_DEVICES diff --git a/hw/i3c/meson.build b/hw/i3c/meson.build index 83d75e7d5c..e614b18712 100644 --- a/hw/i3c/meson.build +++ b/hw/i3c/meson.build @@ -2,4 +2,5 @@ i3c_ss =3D ss.source_set() i3c_ss.add(when: 'CONFIG_I3C', if_true: files('core.c')) i3c_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_i3c.c')) i3c_ss.add(when: 'CONFIG_DW_I3C', if_true: files('dw-i3c.c')) +i3c_ss.add(when: 'CONFIG_MOCK_I3C_TARGET', if_true: files('mock-i3c-target= .c')) system_ss.add_all(when: 'CONFIG_I3C', if_true: i3c_ss) diff --git a/hw/i3c/mock-i3c-target.c b/hw/i3c/mock-i3c-target.c new file mode 100644 index 0000000000..8d42776ece --- /dev/null +++ b/hw/i3c/mock-i3c-target.c @@ -0,0 +1,311 @@ +/* + * Mock I3C Device + * + * Copyright (c) 2025 Google LLC + * + * The mock I3C device can be thought of as a simple EEPROM. It has a buff= er, + * and the pointer in the buffer is reset to 0 on an I3C STOP. + * To write to the buffer, issue a private write and send data. + * To read from the buffer, issue a private read. + * + * The mock target also supports sending target interrupt IBIs. + * To issue an IBI, set the 'ibi-magic-num' property to a non-zero number,= and + * send that number in a private transaction. The mock target will issue a= n IBI + * after 1 second. + * + * It also supports a handful of CCCs that are typically used when probing= I3C + * devices. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "trace.h" +#include "hw/i3c/i3c.h" +#include "hw/i3c/mock-i3c-target.h" +#include "hw/irq.h" +#include "hw/qdev-properties.h" +#include "qapi/error.h" +#include "qemu/module.h" + +#ifndef MOCK_I3C_TARGET_DEBUG +#define MOCK_I3C_TARGET_DEBUG 0 +#endif + +#define DB_PRINTF(...) do { \ + if (MOCK_I3C_TARGET_DEBUG) { \ + qemu_log("%s: ", __func__); \ + qemu_log(__VA_ARGS__); \ + } \ + } while (0) + +#define IBI_DELAY_NS (1 * 1000 * 1000) + +static uint32_t mock_i3c_target_rx(I3CTarget *i3c, uint8_t *data, + uint32_t num_to_read) +{ + MockI3cTargetState *s =3D MOCK_I3C_TARGET(i3c); + uint32_t i; + + /* Bounds check. */ + if (s->p_buf =3D=3D s->cfg.buf_size) { + return 0; + } + + for (i =3D 0; i < num_to_read; i++) { + data[i] =3D s->buf[s->p_buf]; + trace_mock_i3c_target_rx(data[i]); + s->p_buf++; + if (s->p_buf =3D=3D s->cfg.buf_size) { + break; + } + } + + /* Return the number of bytes we're sending to the controller. */ + return i; +} + +static void mock_i3c_target_ibi_timer_start(MockI3cTargetState *s) +{ + int64_t now =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + timer_mod(&s->qtimer, now + IBI_DELAY_NS); +} + +static int mock_i3c_target_tx(I3CTarget *i3c, const uint8_t *data, + uint32_t num_to_send, uint32_t *num_sent) +{ + MockI3cTargetState *s =3D MOCK_I3C_TARGET(i3c); + int ret; + uint32_t to_write; + + if (s->cfg.ibi_magic && num_to_send =3D=3D 1 && s->cfg.ibi_magic =3D= =3D *data) { + mock_i3c_target_ibi_timer_start(s); + return 0; + } + + /* Bounds check. */ + if (num_to_send + s->p_buf > s->cfg.buf_size) { + to_write =3D s->cfg.buf_size - s->p_buf; + ret =3D -1; + } else { + to_write =3D num_to_send; + ret =3D 0; + } + for (uint32_t i =3D 0; i < to_write; i++) { + trace_mock_i3c_target_tx(data[i]); + s->buf[s->p_buf] =3D data[i]; + s->p_buf++; + } + return ret; +} + +static int mock_i3c_target_event(I3CTarget *i3c, enum I3CEvent event) +{ + MockI3cTargetState *s =3D MOCK_I3C_TARGET(i3c); + + trace_mock_i3c_target_event(event); + if (event =3D=3D I3C_STOP) { + s->in_ccc =3D false; + s->curr_ccc =3D 0; + s->ccc_byte_offset =3D 0; + s->p_buf =3D 0; + } + + return 0; +} + +static int mock_i3c_target_handle_ccc_read(I3CTarget *i3c, uint8_t *data, + uint32_t num_to_read, + uint32_t *num_read) +{ + MockI3cTargetState *s =3D MOCK_I3C_TARGET(i3c); + + switch (s->curr_ccc) { + case I3C_CCCD_GETMXDS: + /* Default data rate for I3C. */ + while (s->ccc_byte_offset < num_to_read) { + if (s->ccc_byte_offset >=3D 2) { + break; + } + data[s->ccc_byte_offset] =3D 0; + *num_read =3D s->ccc_byte_offset; + s->ccc_byte_offset++; + } + break; + case I3C_CCCD_GETCAPS: + /* Support I3C version 1.1.x, no other features. */ + while (s->ccc_byte_offset < num_to_read) { + if (s->ccc_byte_offset >=3D 2) { + break; + } + if (s->ccc_byte_offset =3D=3D 0) { + data[s->ccc_byte_offset] =3D 0; + } else { + data[s->ccc_byte_offset] =3D 0x01; + } + *num_read =3D s->ccc_byte_offset; + s->ccc_byte_offset++; + } + break; + case I3C_CCCD_GETMWL: + case I3C_CCCD_GETMRL: + /* MWL/MRL is MSB first. */ + while (s->ccc_byte_offset < num_to_read) { + if (s->ccc_byte_offset >=3D 2) { + break; + } + data[s->ccc_byte_offset] =3D (s->cfg.buf_size & + (0xff00 >> (s->ccc_byte_offset * 8= ))) >> + (8 - (s->ccc_byte_offset * 8)); + s->ccc_byte_offset++; + *num_read =3D num_to_read; + } + break; + case I3C_CCC_ENTDAA: + case I3C_CCCD_GETPID: + case I3C_CCCD_GETBCR: + case I3C_CCCD_GETDCR: + /* Nothing to do. */ + break; + default: + qemu_log_mask(LOG_GUEST_ERROR, "Unhandled CCC 0x%.2x\n", s->curr_c= cc); + return -1; + } + + trace_mock_i3c_target_handle_ccc_read(*num_read, num_to_read); + return 0; +} + +static int mock_i3c_target_handle_ccc_write(I3CTarget *i3c, const uint8_t = *data, + uint32_t num_to_send, + uint32_t *num_sent) +{ + MockI3cTargetState *s =3D MOCK_I3C_TARGET(i3c); + + if (!s->curr_ccc) { + s->in_ccc =3D true; + s->curr_ccc =3D *data; + trace_mock_i3c_target_new_ccc(s->curr_ccc); + } + + *num_sent =3D 1; + switch (s->curr_ccc) { + case I3C_CCC_ENEC: + case I3C_CCCD_ENEC: + s->can_ibi =3D true; + break; + case I3C_CCC_DISEC: + case I3C_CCCD_DISEC: + s->can_ibi =3D false; + break; + case I3C_CCC_ENTDAA: + case I3C_CCC_SETAASA: + case I3C_CCC_RSTDAA: + case I3C_CCCD_SETDASA: + case I3C_CCCD_GETPID: + case I3C_CCCD_GETBCR: + case I3C_CCCD_GETDCR: + case I3C_CCCD_GETMWL: + case I3C_CCCD_GETMRL: + case I3C_CCCD_GETMXDS: + case I3C_CCCD_GETCAPS: + /* Nothing to do. */ + break; + default: + qemu_log_mask(LOG_GUEST_ERROR, "Unhandled CCC 0x%.2x\n", s->curr_c= cc); + return -1; + } + + trace_mock_i3c_target_handle_ccc_write(*num_sent, num_to_send); + return 0; +} + +static void mock_i3c_target_do_ibi(MockI3cTargetState *s) +{ + if (!s->can_ibi) { + DB_PRINTF("IBIs disabled by controller"); + return; + } + + trace_mock_i3c_target_do_ibi(s->i3c.address, true); + int nack =3D i3c_target_send_ibi(&s->i3c, s->i3c.address, /*is_recv=3D= */true); + /* Getting NACKed isn't necessarily an error, just print it out. */ + if (nack) { + DB_PRINTF("NACKed from controller when sending target interrupt.\n= "); + } + nack =3D i3c_target_ibi_finish(&s->i3c, 0x00); + if (nack) { + DB_PRINTF("NACKed from controller when finishing target interrupt.= \n"); + } +} + +static void mock_i3c_target_timer_elapsed(void *opaque) +{ + MockI3cTargetState *s =3D MOCK_I3C_TARGET(opaque); + timer_del(&s->qtimer); + mock_i3c_target_do_ibi(s); +} + +static void mock_i3c_target_reset(I3CTarget *i3c) +{ + MockI3cTargetState *s =3D MOCK_I3C_TARGET(i3c); + s->can_ibi =3D false; +} + +static void mock_i3c_target_realize(DeviceState *dev, Error **errp) +{ + MockI3cTargetState *s =3D MOCK_I3C_TARGET(dev); + s->buf =3D g_new0(uint8_t, s->cfg.buf_size); + mock_i3c_target_reset(&s->i3c); +} + +static void mock_i3c_target_init(Object *obj) +{ + MockI3cTargetState *s =3D MOCK_I3C_TARGET(obj); + s->can_ibi =3D false; + + /* For IBIs. */ + timer_init_ns(&s->qtimer, QEMU_CLOCK_VIRTUAL, mock_i3c_target_timer_el= apsed, + s); +} + +static const Property remote_i3c_props[] =3D { + /* The size of the internal buffer. */ + DEFINE_PROP_UINT32("buf-size", MockI3cTargetState, cfg.buf_size, 0x100= ), + /* + * If the mock target receives this number, it will issue an IBI after + * 1 second. Disabled if the IBI magic number is 0. + */ + DEFINE_PROP_UINT8("ibi-magic-num", MockI3cTargetState, cfg.ibi_magic, = 0x00), +}; + +static void mock_i3c_target_class_init(ObjectClass *klass, const void *dat= a) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + I3CTargetClass *k =3D I3C_TARGET_CLASS(klass); + + dc->realize =3D mock_i3c_target_realize; + k->event =3D mock_i3c_target_event; + k->recv =3D mock_i3c_target_rx; + k->send =3D mock_i3c_target_tx; + k->handle_ccc_read =3D mock_i3c_target_handle_ccc_read; + k->handle_ccc_write =3D mock_i3c_target_handle_ccc_write; + + device_class_set_props(dc, remote_i3c_props); +} + +static const TypeInfo mock_i3c_target_info =3D { + .name =3D TYPE_MOCK_I3C_TARGET, + .parent =3D TYPE_I3C_TARGET, + .instance_size =3D sizeof(MockI3cTargetState), + .instance_init =3D mock_i3c_target_init, + .class_init =3D mock_i3c_target_class_init, +}; + +static void mock_i3c_target_register_types(void) +{ + type_register_static(&mock_i3c_target_info); +} + +type_init(mock_i3c_target_register_types) diff --git a/hw/i3c/trace-events b/hw/i3c/trace-events index 39f33d9a50..3d6dd4f7dd 100644 --- a/hw/i3c/trace-events +++ b/hw/i3c/trace-events @@ -36,3 +36,12 @@ legacy_i2c_recv(uint8_t byte) "Legacy I2C recv 0x%" PRIx8 legacy_i2c_send(uint8_t byte) "Legacy I2C send 0x%" PRIx8 legacy_i2c_start_transfer(uint8_t address, bool is_recv) "Legacy I2C START= with address 0x%" PRIx8 " is_recv=3D%d" legacy_i2c_end_transfer(void) "Legacy I2C STOP" + +# mock-target.c +mock_i3c_target_rx(uint8_t byte) "I3C mock target read 0x%" PRIx8 +mock_i3c_target_tx(uint8_t byte) "I3C mock target write 0x%" PRIx8 +mock_i3c_target_event(uint8_t event) "I3C mock target event 0x%" PRIx8 +mock_i3c_target_handle_ccc_read(uint32_t num_read, uint32_t num_to_read) "= I3C mock target read %" PRId32 "/%" PRId32 " bytes" +mock_i3c_target_new_ccc(uint8_t ccc) "I3C mock target handle CCC 0x%" PRIx8 +mock_i3c_target_handle_ccc_write(uint32_t num_sent, uint32_t num_to_send) = "I3C mock target send %" PRId32 "/%" PRId32 " bytes" +mock_i3c_target_do_ibi(uint8_t address, bool is_recv) "I3C mock target IBI= with address 0x%" PRIx8 " RnW=3D%d" diff --git a/include/hw/i3c/mock-i3c-target.h b/include/hw/i3c/mock-i3c-tar= get.h new file mode 100644 index 0000000000..7ac55a3179 --- /dev/null +++ b/include/hw/i3c/mock-i3c-target.h @@ -0,0 +1,52 @@ +#ifndef MOCK_I3C_TARGET_H_ +#define MOCK_I3C_TARGET_H_ + +/* + * Mock I3C Device + * + * Copyright (c) 2025 Google LLC + * + * The mock I3C device can be thought of as a simple EEPROM. It has a buff= er, + * and the pointer in the buffer is reset to 0 on an I3C STOP. + * To write to the buffer, issue a private write and send data. + * To read from the buffer, issue a private read. + * + * The mock target also supports sending target interrupt IBIs. + * To issue an IBI, set the 'ibi-magic-num' property to a non-zero number,= and + * send that number in a private transaction. The mock target will issue a= n IBI + * after 1 second. + * + * It also supports a handful of CCCs that are typically used when probing= I3C + * devices. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qemu/timer.h" +#include "hw/i3c/i3c.h" + +#define TYPE_MOCK_I3C_TARGET "mock-i3c-target" +OBJECT_DECLARE_SIMPLE_TYPE(MockI3cTargetState, MOCK_I3C_TARGET) + +struct MockI3cTargetState { + I3CTarget i3c; + + /* General device state */ + bool can_ibi; + QEMUTimer qtimer; + size_t p_buf; + uint8_t *buf; + + /* For Handing CCCs. */ + bool in_ccc; + I3CCCC curr_ccc; + uint8_t ccc_byte_offset; + + struct { + uint32_t buf_size; + uint8_t ibi_magic; + } cfg; +}; + +#endif --=20 2.50.0.rc1.591.g9c95f17f64-goog From nobody Sat Nov 15 16:09:06 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1749773309; cv=none; d=zohomail.com; s=zohoarc; b=n+zUng2MjBurHBFomHBeEeDJzyLRpFEDg58OLW5JLbbTUkJa9j3rjhEdAxFMD2aQtd+HeBB4UDoBdCsW/BBpthiEQq7KDH0LIaXAiPLKu+l5VtRmpneM3DOgOilB9IgYSb9pZjlfmQBQQlvNlgKV+HpAhOCXdt9FDJ5MQ+8AT+o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749773309; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=3dMmftlsYq0W3pEEdzMB8bc0OSbplvg01s3pXlWG/po=; b=VIO/DOnp/QXewnVN6WCWnzPN1Ez/7LSvtw0mQ3t3Yac0CDSXB+TsjQ1HIOpcIPtAYU8O93k0C9J6CP1YebkXum2iftZa16386fklAkO/R7WMC/NWxj0ohMCSE4R2OPrNd2O3KZbd7FDdfLntAdJpnFPpeIE4kM8bpEWLfjxBPBM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749773309193367.0598840283543; Thu, 12 Jun 2025 17:08:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPrwx-0008Rc-Lv; Thu, 12 Jun 2025 20:07:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3FWtLaAcKCmIKOMLODIGOOGLE.COMQEMU-DEVELNONGNU.ORG@flex--komlodi.bounces.google.com>) id 1uPrub-0005tQ-Oo for qemu-devel@nongnu.org; Thu, 12 Jun 2025 20:04:55 -0400 Received: from mail-pf1-x449.google.com ([2607:f8b0:4864:20::449]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3FWtLaAcKCmIKOMLODIGOOGLE.COMQEMU-DEVELNONGNU.ORG@flex--komlodi.bounces.google.com>) id 1uPruV-0000c6-J7 for qemu-devel@nongnu.org; Thu, 12 Jun 2025 20:04:47 -0400 Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-742c03c0272so1733348b3a.1 for ; Thu, 12 Jun 2025 17:04:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1749773078; x=1750377878; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=3dMmftlsYq0W3pEEdzMB8bc0OSbplvg01s3pXlWG/po=; b=Tl8Kk/rnyoEYS8H/Xa8TqCUeJt5/LR6Y7NV5jI+ikkg1sQvYEeqz2O0q+UyziazF8X y+zEvLgS0K1GKi38EL3IavD5l4WxvG+JFyHB1G+z2081ldEeTTcJaTeVwBPhDoc3uebP HOjTt8mN9GosDglc8bETYmDUu3XSkiRxOKXKoZ3Urfu6J2alxKmTyyzZDVtS/unUpJVe 9jm84K4igJZ4toZQ50msIMYwgC6HMukT7tX7pbDh8c24bIIrlwymdE2iswZeG0ruEupR fgtVQFEXK1fPMVNRcbrkDubIzmXDvuic7xKQcR52i2onX4R9b/XfVLLKYmzsE4ygOb+c it7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749773078; x=1750377878; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=3dMmftlsYq0W3pEEdzMB8bc0OSbplvg01s3pXlWG/po=; b=Jyao/hie5YU9PqUCiHEYIaMsaGrbgd33bzKkWc2Xv/uz3eIhhIgMm71L4JQW1u+HTb Hj5h8jrZRF77VaeJA+iqkD3nxv2YmiyijLUnlAMFThWm0d5DhN+uYUeeN+SUav6jh++u AMEaoA7mMZRF6BXgX7FglOcJUnZ4JgBFyYS/nFMDmAJkINEbAjbs/6sruvghtprfOnob +b+w45191dZEJt0x3iFeQfvD6Hc0GcphNXxZ51BTJfK6Z8LcGgLdr2eF+V0L58Eq8Rhl tGCu5WXJPBNSWg4aknrPESDivqBddBHFwVcYYZAx/Ai0DeTr0PxWGCZtkUbVzGlYdfgA 6WIg== X-Gm-Message-State: AOJu0YwNqyswznLaZbkTdUty8Vf4LRltPjLhzmuyqlOheBkMYJwc1UkD qTVZoI9jNn72v7/YqeyLwGmbbc6A4L7dEh+2ZM/l4IJaMBcBGL+BBpIg9gIRbERb8AVsjYvrIt3 buMvui3MR9m1FrvBNWAhfUeD4HNpNSHnu8lTf3BIzlmFfZUDvbNVXlm8NOLHZo+wmSXJ7tqaT0e EgvJYVqlwhV2wyA4BF6lyiXLULtxNpNSRUwyVrQnQX X-Google-Smtp-Source: AGHT+IFxP4kScfo/Q+nLp6caWjyHqPRwwREtqqxFR1/6/5XujpNYyvJHUa59u4jlTa2G1cQGPLys28z8V/9b X-Received: from pgct19.prod.google.com ([2002:a05:6a02:5293:b0:b2c:2139:ff4]) (user=komlodi job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:6e01:b0:21f:5598:4c2c with SMTP id adf61e73a8af0-21facb9ed49mr1243456637.13.1749773077886; Thu, 12 Jun 2025 17:04:37 -0700 (PDT) Date: Fri, 13 Jun 2025 00:04:10 +0000 In-Reply-To: <20250613000411.1516521-1-komlodi@google.com> Mime-Version: 1.0 References: <20250613000411.1516521-1-komlodi@google.com> X-Mailer: git-send-email 2.50.0.rc1.591.g9c95f17f64-goog Message-ID: <20250613000411.1516521-19-komlodi@google.com> Subject: [PATCH 18/19] hw/arm/aspeed: Build with I3C_DEVICES From: Joe Komlodi To: qemu-devel@nongnu.org Cc: venture@google.com, komlodi@google.com, clg@kaod.org, peter.maydell@linaro.org, steven_lee@aspeedtech.com, leetroy@gmail.com, jamin_lin@aspeedtech.com, andrew@codeconstruct.com.au, joel@jms.id.au, qemu-arm@nongnu.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::449; envelope-from=3FWtLaAcKCmIKOMLODIGOOGLE.COMQEMU-DEVELNONGNU.ORG@flex--komlodi.bounces.google.com; helo=mail-pf1-x449.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1749773311363116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Allows us to attach the mock I3C target Signed-off-by: Joe Komlodi --- hw/arm/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig index 53d62cd08d..940418b46b 100644 --- a/hw/arm/Kconfig +++ b/hw/arm/Kconfig @@ -532,6 +532,7 @@ config ASPEED_SOC select I2C select I3C select DW_I3C + select I3C_DEVICES select DPS310 select PCA9552 select SERIAL_MM --=20 2.50.0.rc1.591.g9c95f17f64-goog From nobody Sat Nov 15 16:09:06 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1749773273; cv=none; d=zohomail.com; s=zohoarc; b=QsCMKIQzfI4jUtTo1r96bzPQsBnzAfkM5gJJC1OPchC4SrpoLY9mvvyQqlbjE3+2hdj+nKWCDOWSKxcs32pMuFaxYvV7l3JAwC8mihAOw/qYqi0Ias+50AwrW+QAexYug9dUZYxH4c5f/gldmPMG4Gp7ty5oTOJzu/062vW4MvQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749773273; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=xIhdIBQOkbJNaFfY3EaNA90ZGsHrJPHBaTmly0mQe8g=; b=bq3T/WiB0XsF50PbMv1yE2R5uUCDG/bNwxd5ACNVnSc31h2PzUPtYyVmgEqcL7+C7NfjfzSz6/hY6+5dQp0xdpdKUnPC4bwnxkEpj01KSXiRVG1utD7Ci0fIjXgtw5LOz8a21BWTWwZQL8QD+qHFS31HS547E2IG5TEyo8pfqhI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1749773273783723.2507675231576; Thu, 12 Jun 2025 17:07:53 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uPrxG-0000uM-Px; Thu, 12 Jun 2025 20:07:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3F2tLaAcKCmQMQONQFKIQQING.EQOSGOW-FGXGNPQPIPW.QTI@flex--komlodi.bounces.google.com>) id 1uPruk-0005zM-EK for qemu-devel@nongnu.org; Thu, 12 Jun 2025 20:05:01 -0400 Received: from mail-pf1-x44a.google.com ([2607:f8b0:4864:20::44a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3F2tLaAcKCmQMQONQFKIQQING.EQOSGOW-FGXGNPQPIPW.QTI@flex--komlodi.bounces.google.com>) id 1uPruc-0000cK-VS for qemu-devel@nongnu.org; Thu, 12 Jun 2025 20:04:53 -0400 Received: by mail-pf1-x44a.google.com with SMTP id d2e1a72fcca58-7395d07a3dcso1107232b3a.3 for ; Thu, 12 Jun 2025 17:04:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1749773079; x=1750377879; darn=nongnu.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=xIhdIBQOkbJNaFfY3EaNA90ZGsHrJPHBaTmly0mQe8g=; b=t08rQEbmo2wXvXlfPmd1/G7LWpabJ6a3VeaYHHWI5UQFdU27Sht9e1cfrNRgJtETd4 48nT6y+cfsFgPzOaAAd7HEXLLQw7d1BQj32CyeI3OA6PTKI9K27OyXhrJeDbVTIX6GNY OwM9a3mSZ5e6eBBqmt1iGf5wVq405FhYJ3Wd5sa87DZMYUTOLkM+ZM7cvM1cqO6VISBW 9vu3brmwCgV+WEtrCs8k3Szak+3XzSYAQUqsISb9VL+hXZ84npmpx16H4am6tk+13co/ VeVGZFmgHdn8KoDn3K4oSLRe6jL9bKdeq0HVl9AMKa1TIfemNHkJhBI8jTTRIMw+VaTu j3LA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749773079; x=1750377879; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xIhdIBQOkbJNaFfY3EaNA90ZGsHrJPHBaTmly0mQe8g=; b=hOIHVKlu9lLdl5vgpMNTsgej/CANP1lgQZKKt5Nh+MS62gd4g25O+GFcnR3l07E1g+ 2D4xscHXg6sJTnlOeSSskbK6RZPVW9P6UN7cbRjNDNaP+mJ5jg4jq7crmQ6F+a8l0HC4 hdINVe7KGWPl0qca6Ojhlp4eiMxIzvO1OGKIEJXBtsFt5vVq0aP6ICyQ9kX+qc7eAk4s G8ZQzAiuR6WtqInnFWwwdVykX5DFjHGx0IOVRVwz1mbZlYUisSJY27ucuiTMo+7+wAXY WpYFdVtWPXw7NlREEs6RM+mb4KhRr+wILwcBKsvfWd9nlM2nx3LI6SVoeLHtAzKyxzdw YvNA== X-Gm-Message-State: AOJu0Yzj1HcVN8u0ID7maxHuegnJdpo8fnYta3kmFjkOOg62laHjvP4F u4JAkf2smUgm/2QTsBO/vF+vsK76VuqD0cft7iDnnCTsqBQdylQaBx0KBCBoBupFBi1uOraCagz oUvAxHO2Vgzz72Q8zdDwS5hDQv0/3Qp1CF4xQxtLPOOJ5S+pv46kwkWHDDzrZsVmzHPUnegfVrL D+klSOpnpSkzJUNbBbfdYGPrO8DgQgueExPrzhH+jo X-Google-Smtp-Source: AGHT+IH038V/B9s0KvHcWg+rpEm/kj61OdzkGzP0C4XwRkFM5/ENXAjszxpXeNh7mCqUytjV9pntCumWNRDx X-Received: from pgbdm4.prod.google.com ([2002:a05:6a02:d84:b0:b2f:56fa:ef1d]) (user=komlodi job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:4312:b0:1ee:a914:1d67 with SMTP id adf61e73a8af0-21fac851b5cmr1298718637.2.1749773079320; Thu, 12 Jun 2025 17:04:39 -0700 (PDT) Date: Fri, 13 Jun 2025 00:04:11 +0000 In-Reply-To: <20250613000411.1516521-1-komlodi@google.com> Mime-Version: 1.0 References: <20250613000411.1516521-1-komlodi@google.com> X-Mailer: git-send-email 2.50.0.rc1.591.g9c95f17f64-goog Message-ID: <20250613000411.1516521-20-komlodi@google.com> Subject: [PATCH 19/19] hw/i3c: Add hotplug support From: Joe Komlodi To: qemu-devel@nongnu.org Cc: venture@google.com, komlodi@google.com, clg@kaod.org, peter.maydell@linaro.org, steven_lee@aspeedtech.com, leetroy@gmail.com, jamin_lin@aspeedtech.com, andrew@codeconstruct.com.au, joel@jms.id.au, qemu-arm@nongnu.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::44a; envelope-from=3F2tLaAcKCmQMQONQFKIQQING.EQOSGOW-FGXGNPQPIPW.QTI@flex--komlodi.bounces.google.com; helo=mail-pf1-x44a.google.com X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @google.com) X-ZM-MESSAGEID: 1749773275078116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This adds support for hotplugging in I3C. Conceptually this can be thought of as an I3C target being physically socketed onto a board. It is then the target's responsibility to go through the hot-join and DAA process so it can participate on the bus. Signed-off-by: Joe Komlodi Reviewed-by: Patrick Venture --- hw/i3c/core.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/hw/i3c/core.c b/hw/i3c/core.c index 117d9da7ac..1b62ee7a43 100644 --- a/hw/i3c/core.c +++ b/hw/i3c/core.c @@ -11,6 +11,7 @@ #include "qapi/error.h" #include "trace.h" #include "hw/i3c/i3c.h" +#include "hw/hotplug.h" #include "hw/qdev-properties.h" =20 /* @@ -26,11 +27,27 @@ static const Property i3c_props[] =3D { DEFINE_PROP_UINT64("pid", struct I3CTarget, pid, 0), }; =20 +static void i3c_realize(BusState *bus, Error **errp) +{ + qbus_set_bus_hotplug_handler(bus); +} + +static void i3c_class_init(ObjectClass *klass, const void *data) +{ + BusClass *k =3D BUS_CLASS(klass); + k->realize =3D i3c_realize; +} + static const TypeInfo i3c_bus_info =3D { .name =3D TYPE_I3C_BUS, .parent =3D TYPE_BUS, .instance_size =3D sizeof(I3CBus), .class_size =3D sizeof(I3CBusClass), + .class_init =3D i3c_class_init, + .interfaces =3D (InterfaceInfo[]) { + { TYPE_HOTPLUG_HANDLER }, + { } + } }; =20 I3CBus *i3c_init_bus(DeviceState *parent, const char *name) --=20 2.50.0.rc1.591.g9c95f17f64-goog