From nobody Mon Feb 9 08:34:04 2026 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=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 165647394352136.92490808679156; Tue, 28 Jun 2022 20:39:03 -0700 (PDT) Received: from localhost ([::1]:38412 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o6OXc-00023D-Tp for importer@patchew.org; Tue, 28 Jun 2022 23:39:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45744) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o6OVL-0007RG-ID; Tue, 28 Jun 2022 23:36:39 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]:36593) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o6OVK-0006dY-1v; Tue, 28 Jun 2022 23:36:39 -0400 Received: by mail-pl1-x630.google.com with SMTP id m2so12879319plx.3; Tue, 28 Jun 2022 20:36:37 -0700 (PDT) Received: from localhost (fwdproxy-prn-008.fbsv.net. [2a03:2880:ff:8::face:b00c]) by smtp.gmail.com with ESMTPSA id j12-20020a170902690c00b0016909be39e5sm10155813plk.177.2022.06.28.20.36.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jun 2022 20:36:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tzL49z7f9q1RDvOIK4hpBj6ivrpxB/a+VyPlYZdu6RA=; b=Xcir9ZfGotLBQnpB98OqnxLQZF18EEoq+mCIx3ghudRFrYG3mHSTBX+t9mCxA3t+tc OsuJl0VWWIDkRAAwomH+B1uL0ph5tiF/JOj7Pm4dMVGoYuqcxBWHln9Mx0rOE+moq7Sg wPHD1/C0xHlhyRJFxrLwAiKYWykIzvnjCYU2xBaU8DopY2JubDfsNC0awfdBrPnCUUPk DrBWPRfu3GKBLx/nSattyOqAjGxQN6+vYYH36F+g5nhsxwLxOh0TwNR/PUs2kDVtIL+y oOl/l8YNyQZekuNRa164HX88nRGT5Yo0+Ple5Pr/Mu0m+4mxYkEvRV2h3oDJLTea1HJ0 UyTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tzL49z7f9q1RDvOIK4hpBj6ivrpxB/a+VyPlYZdu6RA=; b=vtqJl4uyA33hcdmTWIh/0cfOhglfGkZsGHwV+a5J6o0lJnnILwp/vh7pVtLpDyUJjg W1cqQvwV1VtmiHdjcTmDh5Z1xjg4fz9GLcM1fj4DEK2feS1PaJ33zKxhlS47XEJ/AEAf sUIH10YfY7bbTaMebncLcZ57aVKTJVhNWCUNvAVN4qeSDQXLg4kIrJrhNLR/9FBKpnp1 5AXsbhFx1KRgHgM9yNz00QQ15/jGAUJUBCG26qZ0E2rSmaoPj8xZqpAv+tXHO55KBNQQ DoF5RR9PmPX30aWdhN4AN40zwDtQLcAWlhH8y4cSX2djJqcL1ZTBg1GVXdltO1WG4dhf K1KQ== X-Gm-Message-State: AJIora9dGulBW9edYmRlaJvDtreblNIlm+IIn9jWNaFlKAbiGiSveGFe DmY2ZTkCgNKRTglLBiBsVBc= X-Google-Smtp-Source: AGRyM1t515/naIwTk0/6JId7zoZdRhFDOLBhzfxJ1iEwpRKeLRh2Ba/IDCEz4bLymS53OOPmU8a71w== X-Received: by 2002:a17:90b:4a42:b0:1ec:adee:e298 with SMTP id lb2-20020a17090b4a4200b001ecadeee298mr3456564pjb.161.1656473796399; Tue, 28 Jun 2022 20:36:36 -0700 (PDT) From: Peter Delevoryas X-Google-Original-From: Peter Delevoryas To: Cc: clg@kaod.org, peter.maydell@linaro.org, andrew@aj.id.au, joel@jms.id.au, cminyard@mvista.com, titusr@google.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, zhdaniel@fb.com, pdel@fb.com Subject: [PATCH v2 01/13] hw/i2c/aspeed: Fix R_I2CD_FUN_CTRL reference Date: Tue, 28 Jun 2022 20:36:22 -0700 Message-Id: <20220629033634.3850922-2-pdel@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220629033634.3850922-1-pdel@fb.com> References: <20220629033634.3850922-1-pdel@fb.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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::630; envelope-from=peterdelevoryas@gmail.com; helo=mail-pl1-x630.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1656473946200100001 Content-Type: text/plain; charset="utf-8" Very minor, doesn't effect functionality, but this is supposed to be R_I2CC_FUN_CTRL (new-mode, not old-mode). Fixes: ba2cccd64e9 ("aspeed: i2c: Add new mode support") Signed-off-by: Peter Delevoryas Reviewed-by: C=C3=A9dric Le Goater --- hw/i2c/aspeed_i2c.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/i2c/aspeed_i2c.c b/hw/i2c/aspeed_i2c.c index 37ae1f2e04..ff33571954 100644 --- a/hw/i2c/aspeed_i2c.c +++ b/hw/i2c/aspeed_i2c.c @@ -552,7 +552,7 @@ static void aspeed_i2c_bus_new_write(AspeedI2CBus *bus,= hwaddr offset, __func__); break; } - bus->regs[R_I2CD_FUN_CTRL] =3D value & 0x007dc3ff; + bus->regs[R_I2CC_FUN_CTRL] =3D value & 0x007dc3ff; break; case A_I2CC_AC_TIMING: bus->regs[R_I2CC_AC_TIMING] =3D value & 0x1ffff0ff; --=20 2.30.2 From nobody Mon Feb 9 08:34:04 2026 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=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1656473960987147.7121045744425; Tue, 28 Jun 2022 20:39:20 -0700 (PDT) Received: from localhost ([::1]:39494 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o6OXv-0002tX-D6 for importer@patchew.org; Tue, 28 Jun 2022 23:39:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45768) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o6OVN-0007SI-14; Tue, 28 Jun 2022 23:36:41 -0400 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]:42621) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o6OVL-0006gt-AF; Tue, 28 Jun 2022 23:36:40 -0400 Received: by mail-pg1-x532.google.com with SMTP id d129so14050499pgc.9; Tue, 28 Jun 2022 20:36:38 -0700 (PDT) Received: from localhost (fwdproxy-prn-021.fbsv.net. [2a03:2880:ff:15::face:b00c]) by smtp.gmail.com with ESMTPSA id a13-20020a63e40d000000b0040d48cf046csm10083686pgi.55.2022.06.28.20.36.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jun 2022 20:36:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bxxCeDZQXcCNEHkjubN8AwS0BfANRLIXqhbPQWkeSQg=; b=cJfeKB9XaCHOfpI5LYPAXhJ7G+7lkXZXLOoq/QoY9rzcPy+UnPZt9HRdsv80JWJWGC VlnurHDPXx6JY5+iS/Zo8Cl4IEZmKrmP6Mlg+xfh6gadDHNJDpDV305r+81nZiGjtG9G mBdqMmijK/t3UbNvrme9aBcwEta88hjiTRo3Jj2DfM1jhW9qhI/2hck6RcKudf0En1Pn UHcHn7EcgKJfWlnH7jNpj7DHb1DB+qiYtgcCC7+R36rvLTDRlI5psMT0CLAr6qr1msc0 av1hpjoyROkdTtGZ+JSg/LvSnL0spe0bqgCB0Pry6vwwrQ4hbH1KGJiYnDI1J9wc3ysu x/Nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bxxCeDZQXcCNEHkjubN8AwS0BfANRLIXqhbPQWkeSQg=; b=s6jx9l8LgisqSBm4BybYgXopS+t6e5SzT57atre80xTUkC1y66jKZTAd1Ird+QaPYE 2FQhFFuIKt7EPSxIMTwOnqsZCJk4rDx9YMtaIAblhM4kD7Ga3NDNZTyS01AraxiqMEe7 ultHoWHzwWrEHcdkcvpOENqqFmTy2FSatz6eb7t9uXVESItVn02F38Nf9NtmXFOunu5M elwJSmD18Bourbvsh+cs3aEBmM5lBw/01aMlRLFLObBN6x/qvY2NiUnO3jgpvgDzqesy a++Nf+TtBPjVXrX59/IxnJMKXZ1CpeNUBn/LBLX+bziHhHQ9j0RYJnEZ/dAG4ohT2m06 ZvTA== X-Gm-Message-State: AJIora8EzhfswJm0aHZdyJzzSNvDKlcJJIBSvb92wRJudaVrPk/1JbzY UkpuqHlaUoLxkOLihyFqSC8= X-Google-Smtp-Source: AGRyM1tnCWjzBKl2YjVmPZZoT1P0hPpOFfhrMG7zU3mM4Eh3seFHFbnQqf5TXewhj0z9bFfIKZ5biw== X-Received: by 2002:a63:82c3:0:b0:40d:3b63:a806 with SMTP id w186-20020a6382c3000000b0040d3b63a806mr1157852pgd.75.1656473797499; Tue, 28 Jun 2022 20:36:37 -0700 (PDT) From: Peter Delevoryas X-Google-Original-From: Peter Delevoryas To: Cc: clg@kaod.org, peter.maydell@linaro.org, andrew@aj.id.au, joel@jms.id.au, cminyard@mvista.com, titusr@google.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, zhdaniel@fb.com, pdel@fb.com Subject: [PATCH v2 02/13] hw/i2c/aspeed: Fix DMA len write-enable bit handling Date: Tue, 28 Jun 2022 20:36:23 -0700 Message-Id: <20220629033634.3850922-3-pdel@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220629033634.3850922-1-pdel@fb.com> References: <20220629033634.3850922-1-pdel@fb.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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::532; envelope-from=peterdelevoryas@gmail.com; helo=mail-pg1-x532.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1656473962113100001 Content-Type: text/plain; charset="utf-8" I noticed i2c rx transfers were getting shortened to "1" on Zephyr. It seems to be because the Zephyr i2c driver sets the RX DMA len with the RX field write-enable bit set (bit 31) to avoid a read-modify-write. [1] /* 0x1C : I2CM Master DMA Transfer Length Register */ I think we should be checking the write-enable bits on the incoming value, not checking the register array. I'm not sure we're even writing the write-enable bits to the register array, actually. [1] https://github.com/AspeedTech-BMC/zephyr/blob/db3dbcc9c52e67a47180890ac= 938ed380b33f91c/drivers/i2c/i2c_aspeed.c#L145-L148 Fixes: ba2cccd64e90f34 ("aspeed: i2c: Add new mode support") Signed-off-by: Peter Delevoryas Reviewed-by: C=C3=A9dric Le Goater --- hw/i2c/aspeed_i2c.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/i2c/aspeed_i2c.c b/hw/i2c/aspeed_i2c.c index ff33571954..cbaa7c96fc 100644 --- a/hw/i2c/aspeed_i2c.c +++ b/hw/i2c/aspeed_i2c.c @@ -644,18 +644,18 @@ static void aspeed_i2c_bus_new_write(AspeedI2CBus *bu= s, hwaddr offset, RX_BUF_LEN) + 1; break; case A_I2CM_DMA_LEN: - w1t =3D ARRAY_FIELD_EX32(bus->regs, I2CM_DMA_LEN, RX_BUF_LEN_W1T) = || - ARRAY_FIELD_EX32(bus->regs, I2CM_DMA_LEN, TX_BUF_LEN_W1= T); + w1t =3D FIELD_EX32(value, I2CM_DMA_LEN, RX_BUF_LEN_W1T) || + FIELD_EX32(value, I2CM_DMA_LEN, TX_BUF_LEN_W1T); /* If none of the w1t bits are set, just write to the reg as norma= l. */ if (!w1t) { bus->regs[R_I2CM_DMA_LEN] =3D value; break; } - if (ARRAY_FIELD_EX32(bus->regs, I2CM_DMA_LEN, RX_BUF_LEN_W1T)) { + if (FIELD_EX32(value, I2CM_DMA_LEN, RX_BUF_LEN_W1T)) { ARRAY_FIELD_DP32(bus->regs, I2CM_DMA_LEN, RX_BUF_LEN, FIELD_EX32(value, I2CM_DMA_LEN, RX_BUF_LEN)); } - if (ARRAY_FIELD_EX32(bus->regs, I2CM_DMA_LEN, TX_BUF_LEN_W1T)) { + if (FIELD_EX32(value, I2CM_DMA_LEN, TX_BUF_LEN_W1T)) { ARRAY_FIELD_DP32(bus->regs, I2CM_DMA_LEN, TX_BUF_LEN, FIELD_EX32(value, I2CM_DMA_LEN, TX_BUF_LEN)); } --=20 2.30.2 From nobody Mon Feb 9 08:34:04 2026 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=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1656473949434787.7781121205933; Tue, 28 Jun 2022 20:39:09 -0700 (PDT) Received: from localhost ([::1]:38730 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o6OXj-0002J4-Me for importer@patchew.org; Tue, 28 Jun 2022 23:39:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45772) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o6OVN-0007Sp-GU; Tue, 28 Jun 2022 23:36:41 -0400 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]:47006) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o6OVM-0006gx-0l; Tue, 28 Jun 2022 23:36:41 -0400 Received: by mail-pl1-x62d.google.com with SMTP id q18so12832528pld.13; Tue, 28 Jun 2022 20:36:39 -0700 (PDT) Received: from localhost (fwdproxy-prn-002.fbsv.net. [2a03:2880:ff:2::face:b00c]) by smtp.gmail.com with ESMTPSA id j18-20020a63e752000000b0040aeb7e9358sm9880203pgk.90.2022.06.28.20.36.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jun 2022 20:36:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6h+oD3INdlvLAYbbdQxBhdr6X4GdD4XpIa63iOUDJvU=; b=JMWObqJ3SanHu9O97jKpug8ylHeS09eRuH8CXE3oitlbPLx503eYeGZqNm7e8ni/55 LizpKVqDck7twv5b7asazwb4SFu1L/V5SQUyLB0qVONDzqXhaUl8cEyF3SRpOns0v69y unv10w7BqTWN9eH+P6RQqXRvktbtdzKrt3h7TPJj75X57HmiU283qBrAtT2nboisrbbA nRw5wQioTV6CrQInKyhHwfJRsIUdV+e4/bXSgAOm6MyfSocxoeHX9yGbIhcLXHwupXbm U45ixB20CXxfsIoIswV+s0TfcMODtdWKQCFJ4gr7J7sp7VGZc9z0hlB+bj5xS59ZCvfV 1GSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6h+oD3INdlvLAYbbdQxBhdr6X4GdD4XpIa63iOUDJvU=; b=3sZDavkloYLSPNmFwwLpmVImtOgHWE5eTK64vLeUIbFqaEM1HwP/sGN+s8Bpc6KflA fnp0YQNN199HUFGoPGuYLZl1ijVnSCyHJVlKwbDT4dBxx6BmxOKQYjHQB88u9l6v6Lz+ E4m4Y0rmdbhCaj0EyjK/XAzQPhzkAokIo0liZ1VYG14fXEj79PzZvTh61SEPZaDYbaCD 75wHC9H14oAAGoe3H/iRgKepRyux6xiy3Z1ynMijmtJrzo6sIDM73d70x7ZkbvHSgWMX W1nP0vwb1vG1Jv6iWp3GMGEnK3MgyQR9Qdq6ulCXRzhgnNvtZ+1vv93o+rZVn+sw0A7O 2cPw== X-Gm-Message-State: AJIora8eomcXTImVmI1nPqUYzYzahBL+y0usW/YxkSLkVwhtPkzyMwkb iQlOokSyh+8JNd955PbwcKE= X-Google-Smtp-Source: AGRyM1vPFGj04pv7plYfxSYK+w7o3J+9KFHbuyeG0RdNKYhilZUNdI35Ht73jOCImIi5yuGfE4cMlg== X-Received: by 2002:a17:902:ce85:b0:16a:4637:c4da with SMTP id f5-20020a170902ce8500b0016a4637c4damr8475143plg.82.1656473798389; Tue, 28 Jun 2022 20:36:38 -0700 (PDT) From: Peter Delevoryas X-Google-Original-From: Peter Delevoryas To: Cc: clg@kaod.org, peter.maydell@linaro.org, andrew@aj.id.au, joel@jms.id.au, cminyard@mvista.com, titusr@google.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, zhdaniel@fb.com, pdel@fb.com Subject: [PATCH v2 03/13] hw/i2c/aspeed: Fix MASTER_EN missing error message Date: Tue, 28 Jun 2022 20:36:24 -0700 Message-Id: <20220629033634.3850922-4-pdel@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220629033634.3850922-1-pdel@fb.com> References: <20220629033634.3850922-1-pdel@fb.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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::62d; envelope-from=peterdelevoryas@gmail.com; helo=mail-pl1-x62d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1656473951594100001 Content-Type: text/plain; charset="utf-8" aspeed_i2c_bus_is_master is checking if master mode is enabled in the I2C bus controller's function-control register, not that slave mode is enabled or something. The error here is that the guest is trying to trigger an I2C master mode command while master mode is not enabled. Fixes: ba2cccd64e90f342 ("aspeed: i2c: Add new mode support") Signed-off-by: Peter Delevoryas Reviewed-by: C=C3=A9dric Le Goater --- hw/i2c/aspeed_i2c.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/i2c/aspeed_i2c.c b/hw/i2c/aspeed_i2c.c index cbaa7c96fc..c153a1a942 100644 --- a/hw/i2c/aspeed_i2c.c +++ b/hw/i2c/aspeed_i2c.c @@ -601,7 +601,7 @@ static void aspeed_i2c_bus_new_write(AspeedI2CBus *bus,= hwaddr offset, } =20 if (!aspeed_i2c_bus_is_master(bus)) { - qemu_log_mask(LOG_UNIMP, "%s: slave mode not implemented\n", + qemu_log_mask(LOG_GUEST_ERROR, "%s: Master mode is not enabled= \n", __func__); break; } @@ -744,7 +744,7 @@ static void aspeed_i2c_bus_old_write(AspeedI2CBus *bus,= hwaddr offset, } =20 if (!aspeed_i2c_bus_is_master(bus)) { - qemu_log_mask(LOG_UNIMP, "%s: slave mode not implemented\n", + qemu_log_mask(LOG_GUEST_ERROR, "%s: Master mode is not enabled= \n", __func__); break; } --=20 2.30.2 From nobody Mon Feb 9 08:34:04 2026 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=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1656474512127603.9015147399865; Tue, 28 Jun 2022 20:48:32 -0700 (PDT) Received: from localhost ([::1]:57748 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o6Ogp-0007ri-01 for importer@patchew.org; Tue, 28 Jun 2022 23:48:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45798) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o6OVO-0007Vy-PC; Tue, 28 Jun 2022 23:36:42 -0400 Received: from mail-pg1-x534.google.com ([2607:f8b0:4864:20::534]:42623) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o6OVM-0006j9-UH; Tue, 28 Jun 2022 23:36:42 -0400 Received: by mail-pg1-x534.google.com with SMTP id d129so14050547pgc.9; Tue, 28 Jun 2022 20:36:40 -0700 (PDT) Received: from localhost (fwdproxy-prn-016.fbsv.net. [2a03:2880:ff:10::face:b00c]) by smtp.gmail.com with ESMTPSA id jh2-20020a170903328200b00161478027f5sm10078575plb.150.2022.06.28.20.36.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jun 2022 20:36:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=m6HnsM1GE9zfNQZdSDDG8Va3eAhnVI4VwKPZDbWjHfo=; b=okSNJfgi77udcW2noC+G7jxdCoE7hPF7faV+1AP6u2bcWxr5jSEc0G+UoAMT/2BnlR fLTeph3QPc5BTq/7fVnPw6Ua04ZSGR8dzgv1I+PIoJMTkS3D9O7/2WaYUhisxa5x9D82 1NVT264+UZf60BAlHxq7jwL+NfIR4c9NMLiAFUWOWhWTZ7BOhX53Bvnl2sWO6VrrbPtq mapnQTqIDBUEshqqY9Vv+CcI2YL8x0o3/c8UPNHOdlKbgo/LofXFHEsqqKh9o8zUgFem RIapzxGgZ2BwPeTtYT9Kbg3kHe5fh6L6CZkujI9Sxf3clJB+hkvkL23TITqaisHjuYRF ArGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=m6HnsM1GE9zfNQZdSDDG8Va3eAhnVI4VwKPZDbWjHfo=; b=CcccgOZQzctZxK2bhkiKld0mLinlzmS9m8rMGh8ZZMrr3gaCoqqP3BHe1+HbscuTEf YxFKumvhH9fVoOstxP+J5oom5Uhx74q9AIP6DNFtXmmwQ16xNthBIun350O3NyeMU1JZ Pjz29hWxxCklrxESt2nE2OsPTBlFI96gPpvwmqYQviqerXhCU5sTS/83HqlZxYvzWQ8R IMJA6I0GLsmLhaYshSYUbJQvPEUejVLY+QqHjA8cdmcdAl23Y+K8ckSq261XthQXwye8 PmK6UzYD0KB85Z2mOh2pSoFZORW7z+sfsX89id2u4jq7jhEC1DLaEIrsMFuYl+sWJURv u9Zw== X-Gm-Message-State: AJIora/enymyMe2L4rAViZ757XciWj3NIKAXa1aK7oLl4sbQTFIlA+CA Js95q3gbrgc6/kuW2RZjiFg= X-Google-Smtp-Source: AGRyM1tTcpvUxtAZS5BxVZaJo8CR4issRXFAV81Sro1m53bFJE6lJ2JrB9XYHQ1ttq9NQNLPkP1nSQ== X-Received: by 2002:a63:140e:0:b0:408:a923:1a81 with SMTP id u14-20020a63140e000000b00408a9231a81mr1187974pgl.358.1656473799279; Tue, 28 Jun 2022 20:36:39 -0700 (PDT) From: Peter Delevoryas X-Google-Original-From: Peter Delevoryas To: Cc: clg@kaod.org, peter.maydell@linaro.org, andrew@aj.id.au, joel@jms.id.au, cminyard@mvista.com, titusr@google.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, zhdaniel@fb.com, pdel@fb.com Subject: [PATCH v2 04/13] hw/i2c: support multiple masters Date: Tue, 28 Jun 2022 20:36:25 -0700 Message-Id: <20220629033634.3850922-5-pdel@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220629033634.3850922-1-pdel@fb.com> References: <20220629033634.3850922-1-pdel@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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::534; envelope-from=peterdelevoryas@gmail.com; helo=mail-pg1-x534.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1656474514207100001 From: Klaus Jensen Allow slaves to master the bus by registering a bottom halve. If the bus is busy, the bottom half is queued up. When a slave has succesfully mastered the bus, the bottom half is scheduled. Signed-off-by: Klaus Jensen [ clg : - fixed typos in commit log ] Message-Id: <20220601210831.67259-4-its@irrelevant.dk> Signed-off-by: C=C3=A9dric Le Goater --- hw/i2c/core.c | 34 +++++++++++++++++++++++++++++++++- include/hw/i2c/i2c.h | 14 ++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/hw/i2c/core.c b/hw/i2c/core.c index d0cb2d32fa..145dce6078 100644 --- a/hw/i2c/core.c +++ b/hw/i2c/core.c @@ -13,6 +13,7 @@ #include "migration/vmstate.h" #include "qapi/error.h" #include "qemu/module.h" +#include "qemu/main-loop.h" #include "trace.h" =20 #define I2C_BROADCAST 0x00 @@ -62,6 +63,7 @@ I2CBus *i2c_init_bus(DeviceState *parent, const char *nam= e) =20 bus =3D I2C_BUS(qbus_new(TYPE_I2C_BUS, parent, name)); QLIST_INIT(&bus->current_devs); + QSIMPLEQ_INIT(&bus->pending_masters); vmstate_register(NULL, VMSTATE_INSTANCE_ID_ANY, &vmstate_i2c_bus, bus); return bus; } @@ -74,7 +76,7 @@ void i2c_slave_set_address(I2CSlave *dev, uint8_t address) /* Return nonzero if bus is busy. */ int i2c_bus_busy(I2CBus *bus) { - return !QLIST_EMPTY(&bus->current_devs); + return !QLIST_EMPTY(&bus->current_devs) || bus->bh; } =20 bool i2c_scan_bus(I2CBus *bus, uint8_t address, bool broadcast, @@ -180,6 +182,26 @@ int i2c_start_transfer(I2CBus *bus, uint8_t address, b= ool is_recv) : I2C_START_SEND); } =20 +void i2c_bus_master(I2CBus *bus, QEMUBH *bh) +{ + if (i2c_bus_busy(bus)) { + I2CPendingMaster *node =3D g_new(struct I2CPendingMaster, 1); + node->bh =3D bh; + + QSIMPLEQ_INSERT_TAIL(&bus->pending_masters, node, entry); + + return; + } + + bus->bh =3D bh; + qemu_bh_schedule(bus->bh); +} + +void i2c_bus_release(I2CBus *bus) +{ + bus->bh =3D NULL; +} + int i2c_start_recv(I2CBus *bus, uint8_t address) { return i2c_do_start_transfer(bus, address, I2C_START_RECV); @@ -206,6 +228,16 @@ void i2c_end_transfer(I2CBus *bus) g_free(node); } bus->broadcast =3D false; + + if (!QSIMPLEQ_EMPTY(&bus->pending_masters)) { + I2CPendingMaster *node =3D QSIMPLEQ_FIRST(&bus->pending_masters); + bus->bh =3D node->bh; + + QSIMPLEQ_REMOVE_HEAD(&bus->pending_masters, entry); + g_free(node); + + qemu_bh_schedule(bus->bh); + } } =20 int i2c_send(I2CBus *bus, uint8_t data) diff --git a/include/hw/i2c/i2c.h b/include/hw/i2c/i2c.h index 5ca3b708c0..be8bb8b78a 100644 --- a/include/hw/i2c/i2c.h +++ b/include/hw/i2c/i2c.h @@ -69,13 +69,25 @@ struct I2CNode { QLIST_ENTRY(I2CNode) next; }; =20 +typedef struct I2CPendingMaster I2CPendingMaster; + +struct I2CPendingMaster { + QEMUBH *bh; + QSIMPLEQ_ENTRY(I2CPendingMaster) entry; +}; + typedef QLIST_HEAD(I2CNodeList, I2CNode) I2CNodeList; +typedef QSIMPLEQ_HEAD(I2CPendingMasters, I2CPendingMaster) I2CPendingMaste= rs; =20 struct I2CBus { BusState qbus; I2CNodeList current_devs; + I2CPendingMasters pending_masters; uint8_t saved_address; bool broadcast; + + /* Set from slave currently mastering the bus. */ + QEMUBH *bh; }; =20 I2CBus *i2c_init_bus(DeviceState *parent, const char *name); @@ -117,6 +129,8 @@ int i2c_start_send(I2CBus *bus, uint8_t address); =20 void i2c_end_transfer(I2CBus *bus); void i2c_nack(I2CBus *bus); +void i2c_bus_master(I2CBus *bus, QEMUBH *bh); +void i2c_bus_release(I2CBus *bus); int i2c_send(I2CBus *bus, uint8_t data); uint8_t i2c_recv(I2CBus *bus); bool i2c_scan_bus(I2CBus *bus, uint8_t address, bool broadcast, --=20 2.30.2 From nobody Mon Feb 9 08:34:04 2026 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=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1656474217598178.18088196751057; Tue, 28 Jun 2022 20:43:37 -0700 (PDT) Received: from localhost ([::1]:48258 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o6Oc4-00018q-JG for importer@patchew.org; Tue, 28 Jun 2022 23:43:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45818) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o6OVP-0007Za-QS; Tue, 28 Jun 2022 23:36:43 -0400 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]:43970) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o6OVN-0006na-R8; Tue, 28 Jun 2022 23:36:43 -0400 Received: by mail-pl1-x62c.google.com with SMTP id r1so12855363plo.10; Tue, 28 Jun 2022 20:36:41 -0700 (PDT) Received: from localhost (fwdproxy-prn-017.fbsv.net. [2a03:2880:ff:11::face:b00c]) by smtp.gmail.com with ESMTPSA id h15-20020a170902680f00b00161e50e2245sm10029592plk.178.2022.06.28.20.36.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jun 2022 20:36:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/tiUOgVtzpiwLKug/bkj+5+Wfrcbxl9syNls8Ol46q4=; b=fFCPYTDCfnQVDeZvYxuwhbOzOdBCLphx+XCl/anQQD7jkiOBmFoTdPWd8ljNItSLPA qVOCFUhy1a+sTLXktgxxWcusa+A4nru3s3QWfLUQLkdOcnN+HOIHq32qAlGYWCuDDGke /P2axmNRlI+EU4HehpMaSnH8I/UHzMQ+HuKXiJDlU89D/98aCDLtZVrIDuoRtQRT751w blA9QfGS3SSt2acE27cJTQ4bHC9gxWaSVXho1FGAfqn0gycqw7NXk1eH38r8qEFuBeRY Nmqper7NvDZAU8c18VSMEHlfz72FMRR2RKKHos6U72X86lA0/9qucTnec/Q4UaF8akqU tgvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/tiUOgVtzpiwLKug/bkj+5+Wfrcbxl9syNls8Ol46q4=; b=41YsncZw8hoGlO+jbzgMB6b6vGiCZ6U/RgJo7+WPM/74g6oGlNUZi/Dm+IwPM0DA7T I2Vyzc8vrKawILgcq9IonWV1oZB76AK2oB0Q7zwHg/ac6XetJgX4INmRpjSfJJ8mdOU4 nxmW46V3Be1mPmIwZkGUFL5NYz++VR9/9BnRlL4Vx1HW2w1WnLbcqTA6qRMxmhC4Tj25 ZCAFV0ldgreNJFbs8h7rc1xSp7xA6BmH0YLJngPOmb1iNdyVoR3WTvBoTDEQP6fAy6DA ds/pqLLk3GfIk7bFV4mp2apJyp88KyepONZBe3ZqdbNcnZLAhrq+Fd39AnRjDmXS3qP9 BCzA== X-Gm-Message-State: AJIora+WfcoQUTOhBNeP3BbtrrwUeJ48AGnKyHu1U7bjij/a2eEijoDv 6iJisPVK/KIi1R41BtDl1qo= X-Google-Smtp-Source: AGRyM1sBxOKsucy/2D8li1KRr4Y4G1jsU22BR+KrOe9TnjWo0CXaR6jggGV3at6e0Hp59SRBvBGG+A== X-Received: by 2002:a17:903:22c9:b0:16a:749b:16d6 with SMTP id y9-20020a17090322c900b0016a749b16d6mr7029887plg.32.1656473800142; Tue, 28 Jun 2022 20:36:40 -0700 (PDT) From: Peter Delevoryas X-Google-Original-From: Peter Delevoryas To: Cc: clg@kaod.org, peter.maydell@linaro.org, andrew@aj.id.au, joel@jms.id.au, cminyard@mvista.com, titusr@google.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, zhdaniel@fb.com, pdel@fb.com Subject: [PATCH v2 05/13] hw/i2c: add asynchronous send Date: Tue, 28 Jun 2022 20:36:26 -0700 Message-Id: <20220629033634.3850922-6-pdel@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220629033634.3850922-1-pdel@fb.com> References: <20220629033634.3850922-1-pdel@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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::62c; envelope-from=peterdelevoryas@gmail.com; helo=mail-pl1-x62c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1656474218651100001 From: Klaus Jensen Add an asynchronous version of i2c_send() that requires the slave to explicitly acknowledge on the bus with i2c_ack(). The current master must use the new i2c_start_send_async() to indicate that it wants to do an asynchronous transfer. This allows the i2c core to check if the target slave supports this or not. This approach relies on adding a new enum i2c_event member, which is why a bunch of other devices needs changes in their event handling switches. Signed-off-by: Klaus Jensen Message-Id: <20220601210831.67259-5-its@irrelevant.dk> Signed-off-by: C=C3=A9dric Le Goater --- hw/arm/pxa2xx.c | 2 ++ hw/display/sii9022.c | 2 ++ hw/display/ssd0303.c | 2 ++ hw/i2c/core.c | 36 +++++++++++++++++++++++++++++++++++- hw/i2c/smbus_slave.c | 4 ++++ hw/i2c/trace-events | 2 ++ hw/nvram/eeprom_at24c.c | 2 ++ hw/sensor/lsm303dlhc_mag.c | 2 ++ include/hw/i2c/i2c.h | 16 ++++++++++++++++ 9 files changed, 67 insertions(+), 1 deletion(-) diff --git a/hw/arm/pxa2xx.c b/hw/arm/pxa2xx.c index f4f687df68..93dda83d7a 100644 --- a/hw/arm/pxa2xx.c +++ b/hw/arm/pxa2xx.c @@ -1305,6 +1305,8 @@ static int pxa2xx_i2c_event(I2CSlave *i2c, enum i2c_e= vent event) case I2C_NACK: s->status |=3D 1 << 1; /* set ACKNAK */ break; + default: + return -1; } pxa2xx_i2c_update(s); =20 diff --git a/hw/display/sii9022.c b/hw/display/sii9022.c index b591a58789..664fd4046d 100644 --- a/hw/display/sii9022.c +++ b/hw/display/sii9022.c @@ -76,6 +76,8 @@ static int sii9022_event(I2CSlave *i2c, enum i2c_event ev= ent) break; case I2C_NACK: break; + default: + return -1; } =20 return 0; diff --git a/hw/display/ssd0303.c b/hw/display/ssd0303.c index aeae22da9c..d67b0ad7b5 100644 --- a/hw/display/ssd0303.c +++ b/hw/display/ssd0303.c @@ -196,6 +196,8 @@ static int ssd0303_event(I2CSlave *i2c, enum i2c_event = event) case I2C_NACK: /* Nothing to do. */ break; + default: + return -1; } =20 return 0; diff --git a/hw/i2c/core.c b/hw/i2c/core.c index 145dce6078..d4ba8146bf 100644 --- a/hw/i2c/core.c +++ b/hw/i2c/core.c @@ -161,7 +161,8 @@ static int i2c_do_start_transfer(I2CBus *bus, uint8_t a= ddress, start condition. */ =20 if (sc->event) { - trace_i2c_event("start", s->address); + trace_i2c_event(event =3D=3D I2C_START_SEND ? "start" : "start= _async", + s->address); rv =3D sc->event(s, event); if (rv && !bus->broadcast) { if (bus_scanned) { @@ -212,6 +213,11 @@ int i2c_start_send(I2CBus *bus, uint8_t address) return i2c_do_start_transfer(bus, address, I2C_START_SEND); } =20 +int i2c_start_send_async(I2CBus *bus, uint8_t address) +{ + return i2c_do_start_transfer(bus, address, I2C_START_SEND_ASYNC); +} + void i2c_end_transfer(I2CBus *bus) { I2CSlaveClass *sc; @@ -261,6 +267,23 @@ int i2c_send(I2CBus *bus, uint8_t data) return ret ? -1 : 0; } =20 +int i2c_send_async(I2CBus *bus, uint8_t data) +{ + I2CNode *node =3D QLIST_FIRST(&bus->current_devs); + I2CSlave *slave =3D node->elt; + I2CSlaveClass *sc =3D I2C_SLAVE_GET_CLASS(slave); + + if (!sc->send_async) { + return -1; + } + + trace_i2c_send_async(slave->address, data); + + sc->send_async(slave, data); + + return 0; +} + uint8_t i2c_recv(I2CBus *bus) { uint8_t data =3D 0xff; @@ -297,6 +320,17 @@ void i2c_nack(I2CBus *bus) } } =20 +void i2c_ack(I2CBus *bus) +{ + if (!bus->bh) { + return; + } + + trace_i2c_ack(); + + qemu_bh_schedule(bus->bh); +} + static int i2c_slave_post_load(void *opaque, int version_id) { I2CSlave *dev =3D opaque; diff --git a/hw/i2c/smbus_slave.c b/hw/i2c/smbus_slave.c index 5d10e27664..feb3ec6333 100644 --- a/hw/i2c/smbus_slave.c +++ b/hw/i2c/smbus_slave.c @@ -143,6 +143,10 @@ static int smbus_i2c_event(I2CSlave *s, enum i2c_event= event) dev->mode =3D SMBUS_CONFUSED; break; } + break; + + default: + return -1; } =20 return 0; diff --git a/hw/i2c/trace-events b/hw/i2c/trace-events index 209275ed2d..af181d43ee 100644 --- a/hw/i2c/trace-events +++ b/hw/i2c/trace-events @@ -4,7 +4,9 @@ =20 i2c_event(const char *event, uint8_t address) "%s(addr:0x%02x)" i2c_send(uint8_t address, uint8_t data) "send(addr:0x%02x) data:0x%02x" +i2c_send_async(uint8_t address, uint8_t data) "send_async(addr:0x%02x) dat= a:0x%02x" i2c_recv(uint8_t address, uint8_t data) "recv(addr:0x%02x) data:0x%02x" +i2c_ack(void) "" =20 # aspeed_i2c.c =20 diff --git a/hw/nvram/eeprom_at24c.c b/hw/nvram/eeprom_at24c.c index 01a3093600..d695f6ae89 100644 --- a/hw/nvram/eeprom_at24c.c +++ b/hw/nvram/eeprom_at24c.c @@ -75,6 +75,8 @@ int at24c_eeprom_event(I2CSlave *s, enum i2c_event event) break; case I2C_NACK: break; + default: + return -1; } return 0; } diff --git a/hw/sensor/lsm303dlhc_mag.c b/hw/sensor/lsm303dlhc_mag.c index 4c98ddbf20..bb8d48b2fd 100644 --- a/hw/sensor/lsm303dlhc_mag.c +++ b/hw/sensor/lsm303dlhc_mag.c @@ -427,6 +427,8 @@ static int lsm303dlhc_mag_event(I2CSlave *i2c, enum i2c= _event event) break; case I2C_NACK: break; + default: + return -1; } =20 s->len =3D 0; diff --git a/include/hw/i2c/i2c.h b/include/hw/i2c/i2c.h index be8bb8b78a..9b9581d230 100644 --- a/include/hw/i2c/i2c.h +++ b/include/hw/i2c/i2c.h @@ -12,6 +12,7 @@ enum i2c_event { I2C_START_RECV, I2C_START_SEND, + I2C_START_SEND_ASYNC, I2C_FINISH, I2C_NACK /* Masker NACKed a receive byte. */ }; @@ -28,6 +29,9 @@ struct I2CSlaveClass { /* Master to slave. Returns non-zero for a NAK, 0 for success. */ int (*send)(I2CSlave *s, uint8_t data); =20 + /* Master to slave (asynchronous). Receiving slave must call i2c_ack()= . */ + void (*send_async)(I2CSlave *s, uint8_t data); + /* * Slave to master. This cannot fail, the device should always * return something here. @@ -127,11 +131,23 @@ int i2c_start_recv(I2CBus *bus, uint8_t address); */ int i2c_start_send(I2CBus *bus, uint8_t address); =20 +/** + * i2c_start_send_async: start an asynchronous 'send' transfer on an I2C b= us. + * + * @bus: #I2CBus to be used + * @address: address of the slave + * + * Return: 0 on success, -1 on error + */ +int i2c_start_send_async(I2CBus *bus, uint8_t address); + void i2c_end_transfer(I2CBus *bus); void i2c_nack(I2CBus *bus); +void i2c_ack(I2CBus *bus); void i2c_bus_master(I2CBus *bus, QEMUBH *bh); void i2c_bus_release(I2CBus *bus); int i2c_send(I2CBus *bus, uint8_t data); +int i2c_send_async(I2CBus *bus, uint8_t data); uint8_t i2c_recv(I2CBus *bus); bool i2c_scan_bus(I2CBus *bus, uint8_t address, bool broadcast, I2CNodeList *current_devs); --=20 2.30.2 From nobody Mon Feb 9 08:34:04 2026 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=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1656473969059263.03921424223813; Tue, 28 Jun 2022 20:39:29 -0700 (PDT) Received: from localhost ([::1]:40246 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o6OY4-0003ai-0d for importer@patchew.org; Tue, 28 Jun 2022 23:39:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45824) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o6OVQ-0007bo-H8; Tue, 28 Jun 2022 23:36:44 -0400 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]:52001) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o6OVO-0006nz-Jm; Tue, 28 Jun 2022 23:36:44 -0400 Received: by mail-pj1-x1030.google.com with SMTP id l2so13233418pjf.1; Tue, 28 Jun 2022 20:36:41 -0700 (PDT) Received: from localhost (fwdproxy-prn-008.fbsv.net. [2a03:2880:ff:8::face:b00c]) by smtp.gmail.com with ESMTPSA id h13-20020a62b40d000000b00522d32a6a38sm10128831pfn.121.2022.06.28.20.36.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jun 2022 20:36:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NXvhEiMTm4gtnwtl8PNzi7kh9fQPpkM3x9AxlrD9smk=; b=e0k3qOQcJwpJmDuL3zrJAexjwPLgS6E9FhcmEyCM9KgVzI7udlfqKVgM9jykY46bh3 aH7PoxHluJorRqpI+AOgq2dXpAyj6UJ82HYtnxovqy1H2+xtQdCQNaUgvN47DeXAkQ/F z+3ggbJLkqcPrDCaRoc5D/7lTL7KsYvSG88dai/lXOw7l5d07zUsuXWV/oqabOzGOtmX 5LKmvg5pIMjzSIE3MTTk6LVDYDfDTbylUEhmla8cyGsrgeOK0O4u65f7V2xI1dSLb/Fj ZuNtcMrY+EWe85kBvkFJvj3X+IQ8a9Z/f8G+HRJJw6+IPfcv/UJvAXf3yOKgVsq+0BcG J9NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NXvhEiMTm4gtnwtl8PNzi7kh9fQPpkM3x9AxlrD9smk=; b=vr6dXy5rSUiP9vkmXUHMhy5uLNi3+EDpJNdYfjOm3VhZZ1R2/ZGJhj3uTGxPVdn/gD jHKqf4+jWO0YCh3qAkn45IZHItFBtIaDBhJ6qKBHkH0FSowX2lZg3U1Ehbrz48454l4S HbruaT3GqFBpg6niEPdlh2NaASoofCoLKTIcbUFpi1Vanwa6JsxRYPCtkhh2V7u1Xwiy 5ze7TyrP2TB8yZUj+3FOWQIaR5L35k0IujLzb88xrA8W9s+kRUaCQR0x/rfq9ydhJuOU PvETKwtkNR5uTgPC405pB3u/rAnQttf24OG297dy8w5Xnw7BjpgfaV1HvmZZynmP+PdO i9XA== X-Gm-Message-State: AJIora9mJRTFQ+BtaPk3TPdZ6uHEPaRzMIrzVe35/xUF3gPJRr8VPV0x iZkRgNUJeRLbz62wW572MtQ= X-Google-Smtp-Source: AGRyM1uQblr7UrMgKBmh2zCbfC32WGIVHV5LkZJPqhHiTUByfcHSRPQEL15F0KrPOXy7/cJyzFLBRQ== X-Received: by 2002:a17:903:40c9:b0:16a:2d26:5553 with SMTP id t9-20020a17090340c900b0016a2d265553mr8105522pld.31.1656473800944; Tue, 28 Jun 2022 20:36:40 -0700 (PDT) From: Peter Delevoryas X-Google-Original-From: Peter Delevoryas To: Cc: clg@kaod.org, peter.maydell@linaro.org, andrew@aj.id.au, joel@jms.id.au, cminyard@mvista.com, titusr@google.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, zhdaniel@fb.com, pdel@fb.com Subject: [PATCH v2 06/13] hw/i2c/aspeed: add slave device in old register mode Date: Tue, 28 Jun 2022 20:36:27 -0700 Message-Id: <20220629033634.3850922-7-pdel@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220629033634.3850922-1-pdel@fb.com> References: <20220629033634.3850922-1-pdel@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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::1030; envelope-from=peterdelevoryas@gmail.com; helo=mail-pj1-x1030.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1656473971134100001 From: Klaus Jensen Add slave mode functionality for the Aspeed I2C controller in old register mode. This is implemented by realizing an I2C slave device owned by the I2C controller and attached to its own bus. The I2C slave device only implements asynchronous sends on the bus, so slaves not supporting that will not be able to communicate with it. Signed-off-by: Klaus Jensen [ clg: checkpatch fixes ] Message-Id: <20220601210831.67259-6-its@irrelevant.dk> Signed-off-by: C=C3=A9dric Le Goater --- hw/i2c/aspeed_i2c.c | 89 +++++++++++++++++++++++++++++++++---- include/hw/i2c/aspeed_i2c.h | 8 ++++ 2 files changed, 88 insertions(+), 9 deletions(-) diff --git a/hw/i2c/aspeed_i2c.c b/hw/i2c/aspeed_i2c.c index c153a1a942..8a8514586f 100644 --- a/hw/i2c/aspeed_i2c.c +++ b/hw/i2c/aspeed_i2c.c @@ -696,9 +696,7 @@ static void aspeed_i2c_bus_old_write(AspeedI2CBus *bus,= hwaddr offset, switch (offset) { case A_I2CD_FUN_CTRL: if (SHARED_FIELD_EX32(value, SLAVE_EN)) { - qemu_log_mask(LOG_UNIMP, "%s: slave mode not implemented\n", - __func__); - break; + i2c_slave_set_address(bus->slave, bus->regs[R_I2CD_DEV_ADDR]); } bus->regs[R_I2CD_FUN_CTRL] =3D value & 0x0071C3FF; break; @@ -719,12 +717,15 @@ static void aspeed_i2c_bus_old_write(AspeedI2CBus *bu= s, hwaddr offset, bus->controller->intr_status &=3D ~(1 << bus->id); qemu_irq_lower(aic->bus_get_irq(bus)); } - if (handle_rx && (SHARED_ARRAY_FIELD_EX32(bus->regs, R_I2CD_CMD, - M_RX_CMD) || - SHARED_ARRAY_FIELD_EX32(bus->regs, R_I2CD_CMD, - M_S_RX_CMD_LAST))) { - aspeed_i2c_handle_rx_cmd(bus); - aspeed_i2c_bus_raise_interrupt(bus); + if (handle_rx) { + if (SHARED_ARRAY_FIELD_EX32(bus->regs, R_I2CD_CMD, M_RX_CMD) || + SHARED_ARRAY_FIELD_EX32(bus->regs, R_I2CD_CMD, + M_S_RX_CMD_LAST)) { + aspeed_i2c_handle_rx_cmd(bus); + aspeed_i2c_bus_raise_interrupt(bus); + } else if (aspeed_i2c_get_state(bus) =3D=3D I2CD_STXD) { + i2c_ack(bus->bus); + } } break; case A_I2CD_DEV_ADDR: @@ -1036,6 +1037,73 @@ static const TypeInfo aspeed_i2c_info =3D { .abstract =3D true, }; =20 +static int aspeed_i2c_bus_slave_event(I2CSlave *slave, enum i2c_event even= t) +{ + BusState *qbus =3D qdev_get_parent_bus(DEVICE(slave)); + AspeedI2CBus *bus =3D ASPEED_I2C_BUS(qbus->parent); + uint32_t reg_intr_sts =3D aspeed_i2c_bus_intr_sts_offset(bus); + uint32_t reg_byte_buf =3D aspeed_i2c_bus_byte_buf_offset(bus); + uint32_t value; + + switch (event) { + case I2C_START_SEND_ASYNC: + value =3D SHARED_ARRAY_FIELD_EX32(bus->regs, reg_byte_buf, TX_BUF); + SHARED_ARRAY_FIELD_DP32(bus->regs, reg_byte_buf, RX_BUF, value << = 1); + + ARRAY_FIELD_DP32(bus->regs, I2CD_INTR_STS, SLAVE_ADDR_RX_MATCH, 1); + SHARED_ARRAY_FIELD_DP32(bus->regs, reg_intr_sts, RX_DONE, 1); + + aspeed_i2c_set_state(bus, I2CD_STXD); + + break; + + case I2C_FINISH: + SHARED_ARRAY_FIELD_DP32(bus->regs, reg_intr_sts, NORMAL_STOP, 1); + + aspeed_i2c_set_state(bus, I2CD_IDLE); + + break; + + default: + return -1; + } + + aspeed_i2c_bus_raise_interrupt(bus); + + return 0; +} + +static void aspeed_i2c_bus_slave_send_async(I2CSlave *slave, uint8_t data) +{ + BusState *qbus =3D qdev_get_parent_bus(DEVICE(slave)); + AspeedI2CBus *bus =3D ASPEED_I2C_BUS(qbus->parent); + uint32_t reg_intr_sts =3D aspeed_i2c_bus_intr_sts_offset(bus); + uint32_t reg_byte_buf =3D aspeed_i2c_bus_byte_buf_offset(bus); + + SHARED_ARRAY_FIELD_DP32(bus->regs, reg_byte_buf, RX_BUF, data); + SHARED_ARRAY_FIELD_DP32(bus->regs, reg_intr_sts, RX_DONE, 1); + + aspeed_i2c_bus_raise_interrupt(bus); +} + +static void aspeed_i2c_bus_slave_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + I2CSlaveClass *sc =3D I2C_SLAVE_CLASS(klass); + + dc->desc =3D "Aspeed I2C Bus Slave"; + + sc->event =3D aspeed_i2c_bus_slave_event; + sc->send_async =3D aspeed_i2c_bus_slave_send_async; +} + +static const TypeInfo aspeed_i2c_bus_slave_info =3D { + .name =3D TYPE_ASPEED_I2C_BUS_SLAVE, + .parent =3D TYPE_I2C_SLAVE, + .instance_size =3D sizeof(AspeedI2CBusSlave), + .class_init =3D aspeed_i2c_bus_slave_class_init, +}; + static void aspeed_i2c_bus_reset(DeviceState *dev) { AspeedI2CBus *s =3D ASPEED_I2C_BUS(dev); @@ -1060,6 +1128,8 @@ static void aspeed_i2c_bus_realize(DeviceState *dev, = Error **errp) sysbus_init_irq(SYS_BUS_DEVICE(dev), &s->irq); =20 s->bus =3D i2c_init_bus(dev, name); + s->slave =3D i2c_slave_create_simple(s->bus, TYPE_ASPEED_I2C_BUS_SLAVE, + 0xff); =20 memory_region_init_io(&s->mr, OBJECT(s), &aspeed_i2c_bus_ops, s, name, aic->reg_size); @@ -1219,6 +1289,7 @@ static const TypeInfo aspeed_1030_i2c_info =3D { static void aspeed_i2c_register_types(void) { type_register_static(&aspeed_i2c_bus_info); + type_register_static(&aspeed_i2c_bus_slave_info); type_register_static(&aspeed_i2c_info); type_register_static(&aspeed_2400_i2c_info); type_register_static(&aspeed_2500_i2c_info); diff --git a/include/hw/i2c/aspeed_i2c.h b/include/hw/i2c/aspeed_i2c.h index 1398befc10..ba148b2f6d 100644 --- a/include/hw/i2c/aspeed_i2c.h +++ b/include/hw/i2c/aspeed_i2c.h @@ -223,6 +223,9 @@ struct AspeedI2CBus { =20 struct AspeedI2CState *controller; =20 + /* slave mode */ + I2CSlave *slave; + MemoryRegion mr; =20 I2CBus *bus; @@ -249,6 +252,11 @@ struct AspeedI2CState { AddressSpace dram_as; }; =20 +#define TYPE_ASPEED_I2C_BUS_SLAVE "aspeed.i2c.slave" +OBJECT_DECLARE_SIMPLE_TYPE(AspeedI2CBusSlave, ASPEED_I2C_BUS_SLAVE) +struct AspeedI2CBusSlave { + I2CSlave i2c; +}; =20 struct AspeedI2CClass { SysBusDeviceClass parent_class; --=20 2.30.2 From nobody Mon Feb 9 08:34:04 2026 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=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1656474476816343.0049813359228; Tue, 28 Jun 2022 20:47:56 -0700 (PDT) Received: from localhost ([::1]:56956 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o6OgF-0007JT-Ka for importer@patchew.org; Tue, 28 Jun 2022 23:47:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45852) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o6OVR-0007fw-MN; Tue, 28 Jun 2022 23:36:45 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]:33759) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o6OVP-0006dT-19; Tue, 28 Jun 2022 23:36:45 -0400 Received: by mail-pl1-x633.google.com with SMTP id n10so12915380plp.0; Tue, 28 Jun 2022 20:36:42 -0700 (PDT) Received: from localhost (fwdproxy-prn-003.fbsv.net. [2a03:2880:ff:3::face:b00c]) by smtp.gmail.com with ESMTPSA id 8-20020aa79208000000b0050dc76281e0sm5913463pfo.186.2022.06.28.20.36.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jun 2022 20:36:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vb4Z8dCYcKJsQU+4wQnj8TmeB5G+rHH0WmkyQB2Y6Fc=; b=m4cD9T6dvMXGnHjHeuaGHJnxvRDVIzjims9IGkF4F0e1tBFhXrsie9rdhYpDoFd9LK 7An3ZDw/nV/gArLhukkxf+JlDGTmIZRgtc5Ib6OsvA/juOfcNyBWW8X2rStgFBzdH5al vpUFuhDgsPk3YG3MdSNVI6Tt/wV2QUhcUbiDNOmF3HSCpPwSNu0SFBJr8jGnuCuP65xF 2AY/Y/t6sDRWeBht6RM9By8Lky/Z99QEAMDjOJ7LTloXfonGlvPVETpotLocjKuXHFUw 83UVcH2UBth7l1FoFzsXlUu0A5VIXf+k/gqIc5dgn38MCWNhJhvniz24ER1J/FVhT+te kp/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vb4Z8dCYcKJsQU+4wQnj8TmeB5G+rHH0WmkyQB2Y6Fc=; b=1u+8X2BQylins7Dll+fJx/LdP/v9CSzVcscytjx1AnaDfA5GQ/8U1ZEQR89Oo0JKLs lQ3qeTHQ0pP4mQ4KlU0UTebRMwShf4B0FxXae+DyHlrwf+0EOchnZBAmHML2K0EjrVEn /swRYLzZrW+qNyn5X1MFlDGESlXr5PtvLv8ZbknPPXlHphp9I3TaqMstFJcU/ib1GV7C Yts638AYeIMESYrd8xvo8JbMVcJrdiic49dmXaeaT0mBOgqcGM0Sbl1TUSADVebykYF1 EQalJsdtpKFLlLSCcxnIQi+XTj9DA5T5yTsOjaKL6/zQwQKZPx2Roz78jbiWnanqjCSU UybA== X-Gm-Message-State: AJIora+FJzRy4wboSL+2sjouCj6RH/OrBZJLXxoyK/r9X7UzS4/2Mz/O TGJDzCrZEg17aCNi1F+VIx8= X-Google-Smtp-Source: AGRyM1tWQoOXcGieoMa5MFTGV1ZsWNM92yyDT4lzaJxitBw6c7UqBRzzAgTzTgGFO21XOVz3hchvzw== X-Received: by 2002:a17:90b:3b81:b0:1ed:3655:d0c8 with SMTP id pc1-20020a17090b3b8100b001ed3655d0c8mr3454520pjb.56.1656473801882; Tue, 28 Jun 2022 20:36:41 -0700 (PDT) From: Peter Delevoryas X-Google-Original-From: Peter Delevoryas To: Cc: clg@kaod.org, peter.maydell@linaro.org, andrew@aj.id.au, joel@jms.id.au, cminyard@mvista.com, titusr@google.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, zhdaniel@fb.com, pdel@fb.com Subject: [PATCH v2 07/13] hw/i2c/aspeed: Add new-registers DMA slave mode RX support Date: Tue, 28 Jun 2022 20:36:28 -0700 Message-Id: <20220629033634.3850922-8-pdel@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220629033634.3850922-1-pdel@fb.com> References: <20220629033634.3850922-1-pdel@fb.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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::633; envelope-from=peterdelevoryas@gmail.com; helo=mail-pl1-x633.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1656474478096100001 Content-Type: text/plain; charset="utf-8" This commit adds support for DMA RX in slave mode while using the new register set in the AST2600 and AST1030. This patch also pretty much assumes packet mode is enabled, I'm not sure if this will work in DMA step mode. This is particularly useful for testing IPMB exchanges between Zephyr and external devices, which requires multi-master I2C support and DMA in the new register mode, because the Zephyr drivers from Aspeed use DMA in the new mode by default. The Zephyr drivers are also using packet mode. The typical sequence of events for receiving data in DMA slave + packet mode is that the Zephyr firmware will configure the slave address register with an address to receive on and configure the bus's function control register to enable master mode and slave mode simultaneously at startup, before any transfers are initiated. RX DMA is enabled in the slave mode command register, and the slave RX DMA buffer address and slave RX DMA buffer length are set. TX DMA is not covered in this patch. When the Aspeed I2C controller receives data from some other I2C master, it will reset the I2CS_DMA_LEN RX_LEN value to zero, then buffer incoming data in the RX DMA buffer while incrementing the I2CC_DMA_ADDR address counter and decrementing the I2CC_DMA_LEN counter. It will also update the I2CS_DMA_LEN RX_LEN value along the way. Once all the data has been received, the bus controller will raise an interrupt indicating a packet command was completed, the slave address matched, a normal stop condition was seen, and the transfer was an RX operation. If the master sent a NACK instead of a normal stop condition, or the transfer timed out, then a slightly different set of interrupt status values would be set. Those conditions are not handled in this commit. The Zephyr firmware then collects data from the RX DMA buffer and clears the status register by writing the PKT_MODE_EN bit to the status register. In packet mode, clearing the packet mode interrupt enable bit also clears most of the other interrupt bits automatically (except for a few bits above it). Note: if the master transmit or receive functions were in use simultaneously with the slave mode receive functionality, then the master mode functions may have raised the interrupt line for the bus before the DMA slave transfer is complete. It's important to have the slave's interrupt status register clear throughout the receive operation, and if the slave attempts to raise the interrupt before the master interrupt status is cleared, then it needs to re-raise the interrupt once the master interrupt status is cleared. (And vice-versa). That's why in this commit, when the master interrupt status is cleared and the interrupt line is lowered, we call the slave interrupt _raise_ function, to see if the interrupt was pending. (And again, vice-versa). Signed-off-by: Peter Delevoryas --- hw/i2c/aspeed_i2c.c | 133 ++++++++++++++++++++++++++++++++---- include/hw/i2c/aspeed_i2c.h | 3 + 2 files changed, 124 insertions(+), 12 deletions(-) diff --git a/hw/i2c/aspeed_i2c.c b/hw/i2c/aspeed_i2c.c index 8a8514586f..fc8b6b62cf 100644 --- a/hw/i2c/aspeed_i2c.c +++ b/hw/i2c/aspeed_i2c.c @@ -78,6 +78,18 @@ static inline void aspeed_i2c_bus_raise_interrupt(Aspeed= I2CBus *bus) } } =20 +static inline void aspeed_i2c_bus_raise_slave_interrupt(AspeedI2CBus *bus) +{ + AspeedI2CClass *aic =3D ASPEED_I2C_GET_CLASS(bus->controller); + + if (!bus->regs[R_I2CS_INTR_STS]) { + return; + } + + bus->controller->intr_status |=3D 1 << bus->id; + qemu_irq_raise(aic->bus_get_irq(bus)); +} + static uint64_t aspeed_i2c_bus_old_read(AspeedI2CBus *bus, hwaddr offset, unsigned size) { @@ -140,8 +152,17 @@ static uint64_t aspeed_i2c_bus_new_read(AspeedI2CBus *= bus, hwaddr offset, case A_I2CM_DMA_LEN_STS: case A_I2CC_DMA_ADDR: case A_I2CC_DMA_LEN: + + case A_I2CS_DEV_ADDR: + case A_I2CS_DMA_RX_ADDR: + case A_I2CS_DMA_LEN: + case A_I2CS_CMD: + case A_I2CS_INTR_CTRL: + case A_I2CS_DMA_LEN_STS: /* Value is already set, don't do anything. */ break; + case A_I2CS_INTR_STS: + break; case A_I2CM_CMD: value =3D SHARED_FIELD_DP32(value, BUS_BUSY_STS, i2c_bus_busy(bus-= >bus)); break; @@ -547,12 +568,7 @@ static void aspeed_i2c_bus_new_write(AspeedI2CBus *bus= , hwaddr offset, =20 switch (offset) { case A_I2CC_FUN_CTRL: - if (SHARED_FIELD_EX32(value, SLAVE_EN)) { - qemu_log_mask(LOG_UNIMP, "%s: slave mode not implemented\n", - __func__); - break; - } - bus->regs[R_I2CC_FUN_CTRL] =3D value & 0x007dc3ff; + bus->regs[R_I2CC_FUN_CTRL] =3D value; break; case A_I2CC_AC_TIMING: bus->regs[R_I2CC_AC_TIMING] =3D value & 0x1ffff0ff; @@ -580,6 +596,7 @@ static void aspeed_i2c_bus_new_write(AspeedI2CBus *bus,= hwaddr offset, bus->controller->intr_status &=3D ~(1 << bus->id); qemu_irq_lower(aic->bus_get_irq(bus)); } + aspeed_i2c_bus_raise_slave_interrupt(bus); break; } bus->regs[R_I2CM_INTR_STS] &=3D ~(value & 0xf007f07f); @@ -668,15 +685,53 @@ static void aspeed_i2c_bus_new_write(AspeedI2CBus *bu= s, hwaddr offset, case A_I2CC_DMA_LEN: /* RO */ break; - case A_I2CS_DMA_LEN_STS: - case A_I2CS_DMA_TX_ADDR: - case A_I2CS_DMA_RX_ADDR: case A_I2CS_DEV_ADDR: + bus->regs[R_I2CS_DEV_ADDR] =3D value; + break; + case A_I2CS_DMA_RX_ADDR: + bus->regs[R_I2CS_DMA_RX_ADDR] =3D value; + break; + case A_I2CS_DMA_LEN: + assert(FIELD_EX32(value, I2CS_DMA_LEN, TX_BUF_LEN) =3D=3D 0); + if (FIELD_EX32(value, I2CS_DMA_LEN, RX_BUF_LEN_W1T)) { + ARRAY_FIELD_DP32(bus->regs, I2CS_DMA_LEN, RX_BUF_LEN, + FIELD_EX32(value, I2CS_DMA_LEN, RX_BUF_LEN)); + } else { + bus->regs[R_I2CS_DMA_LEN] =3D value; + } + break; + case A_I2CS_CMD: + if (FIELD_EX32(value, I2CS_CMD, W1_CTRL)) { + bus->regs[R_I2CS_CMD] |=3D value; + } else { + bus->regs[R_I2CS_CMD] =3D value; + } + i2c_slave_set_address(bus->slave, bus->regs[R_I2CS_DEV_ADDR]); + break; case A_I2CS_INTR_CTRL: + bus->regs[R_I2CS_INTR_CTRL] =3D value; + break; + case A_I2CS_INTR_STS: - case A_I2CS_CMD: - case A_I2CS_DMA_LEN: - qemu_log_mask(LOG_UNIMP, "%s: Slave mode is not implemented\n", + if (ARRAY_FIELD_EX32(bus->regs, I2CS_INTR_CTRL, PKT_CMD_DONE)) { + if (ARRAY_FIELD_EX32(bus->regs, I2CS_INTR_STS, PKT_CMD_DONE) && + FIELD_EX32(value, I2CS_INTR_STS, PKT_CMD_DONE)) { + bus->regs[R_I2CS_INTR_STS] &=3D 0xfffc0000; + } + } else { + bus->regs[R_I2CS_INTR_STS] &=3D ~value; + } + if (!bus->regs[R_I2CS_INTR_STS]) { + bus->controller->intr_status &=3D ~(1 << bus->id); + qemu_irq_lower(aic->bus_get_irq(bus)); + } + aspeed_i2c_bus_raise_interrupt(bus); + break; + case A_I2CS_DMA_LEN_STS: + bus->regs[R_I2CS_DMA_LEN_STS] =3D 0; + break; + case A_I2CS_DMA_TX_ADDR: + qemu_log_mask(LOG_UNIMP, "%s: Slave mode DMA TX is not implemented= \n", __func__); break; default: @@ -1037,6 +1092,39 @@ static const TypeInfo aspeed_i2c_info =3D { .abstract =3D true, }; =20 +static int aspeed_i2c_bus_new_slave_event(AspeedI2CBus *bus, + enum i2c_event event) +{ + switch (event) { + case I2C_START_SEND_ASYNC: + if (!SHARED_ARRAY_FIELD_EX32(bus->regs, R_I2CS_CMD, RX_DMA_EN)) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: Slave mode RX DMA is not enabled\n", __func= __); + return -1; + } + ARRAY_FIELD_DP32(bus->regs, I2CS_DMA_LEN_STS, RX_LEN, 0); + bus->regs[R_I2CC_DMA_ADDR] =3D + ARRAY_FIELD_EX32(bus->regs, I2CS_DMA_RX_ADDR, ADDR); + bus->regs[R_I2CC_DMA_LEN] =3D + ARRAY_FIELD_EX32(bus->regs, I2CS_DMA_LEN, RX_BUF_LEN) + 1; + i2c_ack(bus->bus); + break; + case I2C_FINISH: + ARRAY_FIELD_DP32(bus->regs, I2CS_INTR_STS, PKT_CMD_DONE, 1); + ARRAY_FIELD_DP32(bus->regs, I2CS_INTR_STS, SLAVE_ADDR_RX_MATCH, 1); + SHARED_ARRAY_FIELD_DP32(bus->regs, R_I2CS_INTR_STS, NORMAL_STOP, 1= ); + SHARED_ARRAY_FIELD_DP32(bus->regs, R_I2CS_INTR_STS, RX_DONE, 1); + aspeed_i2c_bus_raise_slave_interrupt(bus); + break; + default: + qemu_log_mask(LOG_UNIMP, "%s: i2c event %d unimplemented\n", + __func__, event); + return -1; + } + + return 0; +} + static int aspeed_i2c_bus_slave_event(I2CSlave *slave, enum i2c_event even= t) { BusState *qbus =3D qdev_get_parent_bus(DEVICE(slave)); @@ -1045,6 +1133,10 @@ static int aspeed_i2c_bus_slave_event(I2CSlave *slav= e, enum i2c_event event) uint32_t reg_byte_buf =3D aspeed_i2c_bus_byte_buf_offset(bus); uint32_t value; =20 + if (aspeed_i2c_is_new_mode(bus->controller)) { + return aspeed_i2c_bus_new_slave_event(bus, event); + } + switch (event) { case I2C_START_SEND_ASYNC: value =3D SHARED_ARRAY_FIELD_EX32(bus->regs, reg_byte_buf, TX_BUF); @@ -1073,6 +1165,19 @@ static int aspeed_i2c_bus_slave_event(I2CSlave *slav= e, enum i2c_event event) return 0; } =20 +static void aspeed_i2c_bus_new_slave_send_async(AspeedI2CBus *bus, uint8_t= data) +{ + assert(address_space_write(&bus->controller->dram_as, + bus->regs[R_I2CC_DMA_ADDR], + MEMTXATTRS_UNSPECIFIED, &data, 1) =3D=3D ME= MTX_OK); + + bus->regs[R_I2CC_DMA_ADDR]++; + bus->regs[R_I2CC_DMA_LEN]--; + ARRAY_FIELD_DP32(bus->regs, I2CS_DMA_LEN_STS, RX_LEN, + ARRAY_FIELD_EX32(bus->regs, I2CS_DMA_LEN_STS, RX_LEN)= + 1); + i2c_ack(bus->bus); +} + static void aspeed_i2c_bus_slave_send_async(I2CSlave *slave, uint8_t data) { BusState *qbus =3D qdev_get_parent_bus(DEVICE(slave)); @@ -1080,6 +1185,10 @@ static void aspeed_i2c_bus_slave_send_async(I2CSlave= *slave, uint8_t data) uint32_t reg_intr_sts =3D aspeed_i2c_bus_intr_sts_offset(bus); uint32_t reg_byte_buf =3D aspeed_i2c_bus_byte_buf_offset(bus); =20 + if (aspeed_i2c_is_new_mode(bus->controller)) { + return aspeed_i2c_bus_new_slave_send_async(bus, data); + } + SHARED_ARRAY_FIELD_DP32(bus->regs, reg_byte_buf, RX_BUF, data); SHARED_ARRAY_FIELD_DP32(bus->regs, reg_intr_sts, RX_DONE, 1); =20 diff --git a/include/hw/i2c/aspeed_i2c.h b/include/hw/i2c/aspeed_i2c.h index ba148b2f6d..300a89b343 100644 --- a/include/hw/i2c/aspeed_i2c.h +++ b/include/hw/i2c/aspeed_i2c.h @@ -174,6 +174,8 @@ REG32(I2CM_DMA_LEN, 0x1c) FIELD(I2CM_DMA_LEN, TX_BUF_LEN_W1T, 15, 1) FIELD(I2CM_DMA_LEN, TX_BUF_LEN, 0, 11) REG32(I2CS_INTR_CTRL, 0x20) + FIELD(I2CS_INTR_CTRL, PKT_CMD_FAIL, 17, 1) + FIELD(I2CS_INTR_CTRL, PKT_CMD_DONE, 16, 1) REG32(I2CS_INTR_STS, 0x24) /* 31:29 shared with I2CD_INTR_STS[31:29] */ FIELD(I2CS_INTR_STS, SLAVE_PARKING_STS, 24, 2) @@ -184,6 +186,7 @@ REG32(I2CS_INTR_STS, 0x24) FIELD(I2CS_INTR_STS, PKT_CMD_FAIL, 17, 1) FIELD(I2CS_INTR_STS, PKT_CMD_DONE, 16, 1) /* 14:0 shared with I2CD_INTR_STS[14:0] */ + FIELD(I2CS_INTR_STS, SLAVE_ADDR_RX_MATCH, 7, 1) REG32(I2CS_CMD, 0x28) FIELD(I2CS_CMD, W1_CTRL, 31, 1) FIELD(I2CS_CMD, PKT_MODE_ACTIVE_ADDR, 17, 2) --=20 2.30.2 From nobody Mon Feb 9 08:34:04 2026 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=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1656474245432498.4124601955216; Tue, 28 Jun 2022 20:44:05 -0700 (PDT) Received: from localhost ([::1]:49694 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o6OcW-0002Br-B1 for importer@patchew.org; Tue, 28 Jun 2022 23:44:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45856) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o6OVR-0007gP-PB; Tue, 28 Jun 2022 23:36:45 -0400 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]:50806) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o6OVQ-0006oR-8R; Tue, 28 Jun 2022 23:36:45 -0400 Received: by mail-pj1-x1030.google.com with SMTP id go6so14472565pjb.0; Tue, 28 Jun 2022 20:36:43 -0700 (PDT) Received: from localhost (fwdproxy-prn-119.fbsv.net. [2a03:2880:ff:77::face:b00c]) by smtp.gmail.com with ESMTPSA id w20-20020a1709029a9400b0015e8d4eb231sm10098269plp.123.2022.06.28.20.36.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jun 2022 20:36:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=iAfcxedpA0fkKQ95aKfI39jiWma1JkWWL+ACHMzG7Ls=; b=PF1cTARNTNViX4k0IpSOUVov9hrMqZiQbYcweT2xPH390bKbLjp4OCmfvgaNjONLPk lOcvqKA4xUQ2EYbd0X0UJP8CBLFA5gNCRYeRwdCigndHBd5iQXXZ2ZM/C85jpfeRrKem PBsQcrhLJSb+Fs3qcTpWeN36kTSbOySWIRYnBhyGQZlIVjAlBdKBJIKdTuR1rYYFaB9S 5B/vYA95jCheG9X3TkhEiBrHDBNhHOy9IpoOsvHz3tfI5RZ8853AFniMYoeL/0KhRTB+ 1Xa9he5DBj5pBV9HMZc28enPWSq5up4WXCsnTPW2ZWf9qcj/16tpvnDHKeGdYCHPvwXz 8fGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=iAfcxedpA0fkKQ95aKfI39jiWma1JkWWL+ACHMzG7Ls=; b=PsHathOHgoqgg4D9a4V76iuLQtd6ExFS/Hv4atRcFwXiAfzkhxJRo1V809OtRLCXKl +HPQih4ZjsUJYVivN4ygz8cA7zOQhYWX6ipqxsIrw9rnVAxZRIBDplt5KOgcUfIHk79H XwF7gY9y1JEC8dLpbKGcmUKOJyiWweQHMg6mjqfc2r5dg9bCOfbd/9dtWtTFOXtl2MoR e/8EPEYohBcdjDl324PZg9RT7hM3UbJcfV348sqfiHds2mnu/PuTA+7Bv5gOgMxkTXdA sjJCVFxpwsy1p/Jx5JWLJpwtaXqIwfu8MaMUQi35T7N3vmqqOH1AJ9MdkvIQlOpcl63s I4tw== X-Gm-Message-State: AJIora93WNZce4Ph3UJvdEAIq7guwQhnu1ea0K390LoqzXKXIiVpQwa0 xGEYY+e8bwqz8uh24tudxBw= X-Google-Smtp-Source: AGRyM1sFM4j38p/nnyNh9sn5EfEFpo2z1a3cNAM6L8cxOt7lHJ+inXKtuqcKQN0j1sWLAwK9IwMjzA== X-Received: by 2002:a17:90a:3e07:b0:1ed:492d:2792 with SMTP id j7-20020a17090a3e0700b001ed492d2792mr3456533pjc.57.1656473802657; Tue, 28 Jun 2022 20:36:42 -0700 (PDT) From: Peter Delevoryas X-Google-Original-From: Peter Delevoryas To: Cc: clg@kaod.org, peter.maydell@linaro.org, andrew@aj.id.au, joel@jms.id.au, cminyard@mvista.com, titusr@google.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, zhdaniel@fb.com, pdel@fb.com Subject: [PATCH v2 08/13] hw/i2c/pmbus: Reset out buf after switching pages Date: Tue, 28 Jun 2022 20:36:29 -0700 Message-Id: <20220629033634.3850922-9-pdel@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220629033634.3850922-1-pdel@fb.com> References: <20220629033634.3850922-1-pdel@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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::1030; envelope-from=peterdelevoryas@gmail.com; helo=mail-pj1-x1030.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1656474246710100001 When a pmbus device switches pages, it should clears its output buffer so that the next transaction doesn't emit data from the previous page. Fixes: 3746d5c15e70570b ("hw/i2c: add support for PMBus=E2=80=9D) Signed-off-by: Peter Delevoryas Reviewed-by: C=C3=A9dric Le Goater --- hw/i2c/pmbus_device.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/i2c/pmbus_device.c b/hw/i2c/pmbus_device.c index 62885fa6a1..efddc36fd9 100644 --- a/hw/i2c/pmbus_device.c +++ b/hw/i2c/pmbus_device.c @@ -1088,6 +1088,7 @@ static int pmbus_write_data(SMBusDevice *smd, uint8_t= *buf, uint8_t len) =20 if (pmdev->code =3D=3D PMBUS_PAGE) { pmdev->page =3D pmbus_receive8(pmdev); + pmdev->out_buf_len =3D 0; return 0; } =20 --=20 2.30.2 From nobody Mon Feb 9 08:34:04 2026 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=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1656474513319414.1554060044708; Tue, 28 Jun 2022 20:48:33 -0700 (PDT) Received: from localhost ([::1]:57812 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o6Ogq-0007uJ-7p for importer@patchew.org; Tue, 28 Jun 2022 23:48:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45868) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o6OVS-0007jK-HO; Tue, 28 Jun 2022 23:36:46 -0400 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]:43970) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o6OVQ-0006na-NY; Tue, 28 Jun 2022 23:36:46 -0400 Received: by mail-pl1-x62c.google.com with SMTP id r1so12855363plo.10; Tue, 28 Jun 2022 20:36:43 -0700 (PDT) Received: from localhost (fwdproxy-prn-008.fbsv.net. [2a03:2880:ff:8::face:b00c]) by smtp.gmail.com with ESMTPSA id bf7-20020a170902b90700b00165105518f6sm10081261plb.287.2022.06.28.20.36.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jun 2022 20:36:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3q1s4ScM99S1u0cq6BdjiWyx+aQVAgBUoJiRzkTlxxA=; b=RLTZf3LBfDlUxcvInSRaxt6fCMETPUQ9eFsxaKM1k3wL4kT1cqmikUJapn9tYgmuUr +U5rYnmYR3+fLkRixUOVQvJJCSBx/ZS8cjqrT8iew42xZn0DO6uC4uD5oCTw009HCKTs taoIIwudhN+phLsBuorcYra+3W7265TnvWW12vBCDDzobhEtHChEKe/9rmREYdRXv9a9 lXaoUnXlIUOap0T+8jxBFz2LKd6ZNpLJwt31rZ1EhQlo8pghTtv+toxby+eqCXBatUY0 FMzXX+tx5AGbj0neLhOrSw3tfY7XZXGkouHvOlKN7UpvRRocs0qP4+AkvhJLd8gfq9qI qYVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3q1s4ScM99S1u0cq6BdjiWyx+aQVAgBUoJiRzkTlxxA=; b=zTAnlyYcxfflwmgboHpwtJKBDNbcjE6Or5KctugYU+FcYYudK3a26nvD1adYu2MN5R OT5zIbyBJIwMB9eI13a9G4DHxOIl54/G0PR2UH/mo/6XLAPQsHWGmKWnlf7KATtC/8sX N5pSLquLywnP8ZfIBwqaRhkO3LqTKw/Lk634A6AWOnoTwfZMuAs6rXQWJFU/qytjGEbr G7/GrMdqJUDhT7Uja0gysMNH/Agnh2Qb9m9rF0ihlE3jgSsXdN50XLDJS/W9FR23DjAO +28pMrSQPwL0oRoeVvDrgydolkkmMEWt/GwkViECCtPEUAmNDePV2phCC8Ye5BlwRat7 GUiQ== X-Gm-Message-State: AJIora9x4S9Zl2eO4r2MndBjuhxoH/Zwv14cfI4hRy8r79XPkGo1l6fC TTuBbHwOB6R6uoqIwGah03A= X-Google-Smtp-Source: AGRyM1t7ePVnVBRS00C8aF10IMen9cZqmxJoGRUeI1Niru/2qQ29oZWlJAMvJ8r9Sq2dZ5eH/IW0kw== X-Received: by 2002:a17:903:124f:b0:16b:8167:e34e with SMTP id u15-20020a170903124f00b0016b8167e34emr8220677plh.52.1656473803585; Tue, 28 Jun 2022 20:36:43 -0700 (PDT) From: Peter Delevoryas X-Google-Original-From: Peter Delevoryas To: Cc: clg@kaod.org, peter.maydell@linaro.org, andrew@aj.id.au, joel@jms.id.au, cminyard@mvista.com, titusr@google.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, zhdaniel@fb.com, pdel@fb.com Subject: [PATCH v2 09/13] hw/i2c/pmbus: Add read-only IC_DEVICE_ID support Date: Tue, 28 Jun 2022 20:36:30 -0700 Message-Id: <20220629033634.3850922-10-pdel@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220629033634.3850922-1-pdel@fb.com> References: <20220629033634.3850922-1-pdel@fb.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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::62c; envelope-from=peterdelevoryas@gmail.com; helo=mail-pl1-x62c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1656474514232100002 Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Delevoryas --- hw/i2c/pmbus_device.c | 5 +++++ hw/sensor/isl_pmbus_vr.c | 31 +++++++++++++++++++++++++++++++ include/hw/i2c/pmbus_device.h | 1 + include/hw/sensor/isl_pmbus_vr.h | 1 + 4 files changed, 38 insertions(+) diff --git a/hw/i2c/pmbus_device.c b/hw/i2c/pmbus_device.c index efddc36fd9..82131fff85 100644 --- a/hw/i2c/pmbus_device.c +++ b/hw/i2c/pmbus_device.c @@ -984,6 +984,11 @@ static uint8_t pmbus_receive_byte(SMBusDevice *smd) } break; =20 + case PMBUS_IC_DEVICE_ID: + pmbus_send(pmdev, pmdev->pages[index].ic_device_id, + sizeof(pmdev->pages[index].ic_device_id)); + break; + case PMBUS_CLEAR_FAULTS: /* Send Byte */ case PMBUS_PAGE_PLUS_WRITE: /* Block Write-only */ case PMBUS_STORE_DEFAULT_ALL: /* Send Byte */ diff --git a/hw/sensor/isl_pmbus_vr.c b/hw/sensor/isl_pmbus_vr.c index e11e028884..b12c46ab6d 100644 --- a/hw/sensor/isl_pmbus_vr.c +++ b/hw/sensor/isl_pmbus_vr.c @@ -218,6 +218,28 @@ static void isl_pmbus_vr_class_init(ObjectClass *klass= , void *data, k->device_num_pages =3D pages; } =20 +static void isl69259_init(Object *obj) +{ + static const uint8_t ic_device_id[] =3D {0x04, 0x00, 0x81, 0xD2, 0x49}; + PMBusDevice *pmdev =3D PMBUS_DEVICE(obj); + int i; + + raa22xx_init(obj); + for (i =3D 0; i < pmdev->num_pages; i++) { + memcpy(pmdev->pages[i].ic_device_id, ic_device_id, + sizeof(ic_device_id)); + } +} + +static void isl69259_class_init(ObjectClass *klass, void *data) +{ + ResettableClass *rc =3D RESETTABLE_CLASS(klass); + DeviceClass *dc =3D DEVICE_CLASS(klass); + dc->desc =3D "Renesas ISL69259 Digital Multiphase Voltage Regulator"; + rc->phases.exit =3D isl_pmbus_vr_exit_reset; + isl_pmbus_vr_class_init(klass, data, 2); +} + static void isl69260_class_init(ObjectClass *klass, void *data) { ResettableClass *rc =3D RESETTABLE_CLASS(klass); @@ -245,6 +267,14 @@ static void raa229004_class_init(ObjectClass *klass, v= oid *data) isl_pmbus_vr_class_init(klass, data, 2); } =20 +static const TypeInfo isl69259_info =3D { + .name =3D TYPE_ISL69259, + .parent =3D TYPE_PMBUS_DEVICE, + .instance_size =3D sizeof(ISLState), + .instance_init =3D isl69259_init, + .class_init =3D isl69259_class_init, +}; + static const TypeInfo isl69260_info =3D { .name =3D TYPE_ISL69260, .parent =3D TYPE_PMBUS_DEVICE, @@ -271,6 +301,7 @@ static const TypeInfo raa228000_info =3D { =20 static void isl_pmbus_vr_register_types(void) { + type_register_static(&isl69259_info); type_register_static(&isl69260_info); type_register_static(&raa228000_info); type_register_static(&raa229004_info); diff --git a/include/hw/i2c/pmbus_device.h b/include/hw/i2c/pmbus_device.h index 0f4d6b3fad..aed7809841 100644 --- a/include/hw/i2c/pmbus_device.h +++ b/include/hw/i2c/pmbus_device.h @@ -407,6 +407,7 @@ typedef struct PMBusPage { uint16_t mfr_max_temp_1; /* R/W word */ uint16_t mfr_max_temp_2; /* R/W word */ uint16_t mfr_max_temp_3; /* R/W word */ + uint8_t ic_device_id[16]; /* Read-Only block-read */ } PMBusPage; =20 /* State */ diff --git a/include/hw/sensor/isl_pmbus_vr.h b/include/hw/sensor/isl_pmbus= _vr.h index 3e47ff7e48..d501b3bc82 100644 --- a/include/hw/sensor/isl_pmbus_vr.h +++ b/include/hw/sensor/isl_pmbus_vr.h @@ -12,6 +12,7 @@ #include "hw/i2c/pmbus_device.h" #include "qom/object.h" =20 +#define TYPE_ISL69259 "isl69259" #define TYPE_ISL69260 "isl69260" #define TYPE_RAA228000 "raa228000" #define TYPE_RAA229004 "raa229004" --=20 2.30.2 From nobody Mon Feb 9 08:34:04 2026 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=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1656474772936131.13300576514473; Tue, 28 Jun 2022 20:52:52 -0700 (PDT) Received: from localhost ([::1]:37254 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o6Ol1-0004pI-SX for importer@patchew.org; Tue, 28 Jun 2022 23:52:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45894) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o6OVU-0007oE-Qq; Tue, 28 Jun 2022 23:36:48 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]:41560) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o6OVS-0006qe-4z; Tue, 28 Jun 2022 23:36:48 -0400 Received: by mail-pf1-x42d.google.com with SMTP id i64so13829532pfc.8; Tue, 28 Jun 2022 20:36:45 -0700 (PDT) Received: from localhost (fwdproxy-prn-117.fbsv.net. [2a03:2880:ff:75::face:b00c]) by smtp.gmail.com with ESMTPSA id v10-20020a63f84a000000b003fd9b8b865dsm10127580pgj.0.2022.06.28.20.36.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jun 2022 20:36:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8Ze+hlbYJ35OCG5NEYf07MrKqfhpAc9F4NzS2kxZipw=; b=mYAxaS69ggdHx/5VKPCTSlNUASMNPUd7Hzrpt17c2aI8O8OqwWNQFblCPO7S5Ya5Xk 1EqCDK5uy7aZ3kd2Gge+EsPv0TQypXSWgPIEianLBpSA3RwGmG5kHdyQMTV616QN5ijF r0thi5sMW0WxaAtzdvmswZW6/L3cXzd61aEV2GIq3+DoepNHV3A/iv/Oi3ZbdLBGfEIy 607OofoDADdOqlo22hqbNgtQ0GP4gJ6LDNfSh+55wP8Z6kY1Lwt/wBeKhKziIRtAXdLj VPSKWUSKCLqs/2nfHz0uSnbIGRiwZ6wKp+tvrfDBYMoReShRTrZiC+OzgPCP0iPhSMQl ZJmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8Ze+hlbYJ35OCG5NEYf07MrKqfhpAc9F4NzS2kxZipw=; b=jTZSN8xtFsYj//EsPxeCiYACZcUN2G45QuUyCb6OvdNO0CVM+/Gbu0jqohiN+mnym2 oZ5Ezhs+BnmExKAb9MN1UR1zZQXIgX0RVvfp7pDmjhMez+cPLsJErDjniT8vWQWs2U6C i/+erSQpNu67RxMrWINAEfrQopd3nI3NoX8paumfw3sL1GXraCZy59BVi1sdfJflpo51 altEnqZA3k0fYKCHpZ8Ho3KPvaucmn8i24vOAREhQrfgRefmHa6g1phx9XXVvU0monzy JLIbKkJ0JwoY88f/2vzmGn974WnpMqhzkycCzCutwqK7pHFL53IFCy2dgwfoatF3Qykq v8mg== X-Gm-Message-State: AJIora8V9rlTruCe3M7a3Jbf5yonnChaLCiIIzv8H1dJDbjBQdW/TTzj DkN44GkWuyREHdhR5aGuyh0= X-Google-Smtp-Source: AGRyM1vUFiHMtnXpq0x9Q/ys4v7dZK08XJ743+iQ6vaznl86fpLdCL+3Kh9eRdEa5C0bbtwkxdal0A== X-Received: by 2002:a63:89c6:0:b0:40d:316b:6626 with SMTP id v189-20020a6389c6000000b0040d316b6626mr1117080pgd.569.1656473804405; Tue, 28 Jun 2022 20:36:44 -0700 (PDT) From: Peter Delevoryas X-Google-Original-From: Peter Delevoryas To: Cc: clg@kaod.org, peter.maydell@linaro.org, andrew@aj.id.au, joel@jms.id.au, cminyard@mvista.com, titusr@google.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, zhdaniel@fb.com, pdel@fb.com Subject: [PATCH v2 10/13] hw/misc/aspeed: Add PECI controller Date: Tue, 28 Jun 2022 20:36:31 -0700 Message-Id: <20220629033634.3850922-11-pdel@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220629033634.3850922-1-pdel@fb.com> References: <20220629033634.3850922-1-pdel@fb.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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::42d; envelope-from=peterdelevoryas@gmail.com; helo=mail-pf1-x42d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1656474773885100001 Content-Type: text/plain; charset="utf-8" This introduces a really basic PECI controller that responses to commands by always setting the response code to success and then raising an interrupt to indicate the command is done. This helps avoid getting hit with constant errors if the driver continuously attempts to send a command and keeps timing out. The AST2400 and AST2500 only included registers up to 0x5C, not 0xFC. They supported PECI 1.1, 2.0, and 3.0. The AST2600 and AST1030 support PECI 4.0, which includes more read/write buffer registers from 0x80 to 0xFC to support 64-byte mode. This patch doesn't attempt to handle that, or to create a different version of the controller for the different generations, since it's only implementing functionality that is common to all generations. The basic sequence of events is that the firmware will read and write to various registers and then trigger a command by setting the FIRE bit in the command register (similar to the I2C controller). Then the firmware waits for an interrupt from the PECI controller, expecting the interrupt status register to be filled in with info on what happened. If the command was transmitted and received successfully, then response codes from the host CPU will be found in the data buffer registers. Signed-off-by: Peter Delevoryas --- hw/arm/aspeed_ast10x0.c | 12 +++ hw/arm/aspeed_ast2600.c | 12 +++ hw/arm/aspeed_soc.c | 13 ++++ hw/misc/aspeed_peci.c | 136 ++++++++++++++++++++++++++++++++++ hw/misc/meson.build | 3 +- hw/misc/trace-events | 4 + include/hw/arm/aspeed_soc.h | 3 + include/hw/misc/aspeed_peci.h | 47 ++++++++++++ 8 files changed, 229 insertions(+), 1 deletion(-) create mode 100644 hw/misc/aspeed_peci.c create mode 100644 include/hw/misc/aspeed_peci.h diff --git a/hw/arm/aspeed_ast10x0.c b/hw/arm/aspeed_ast10x0.c index 5df480a21f..56e8de3d89 100644 --- a/hw/arm/aspeed_ast10x0.c +++ b/hw/arm/aspeed_ast10x0.c @@ -47,6 +47,7 @@ static const hwaddr aspeed_soc_ast1030_memmap[] =3D { [ASPEED_DEV_UART13] =3D 0x7E790700, [ASPEED_DEV_WDT] =3D 0x7E785000, [ASPEED_DEV_LPC] =3D 0x7E789000, + [ASPEED_DEV_PECI] =3D 0x7E78B000, [ASPEED_DEV_I2C] =3D 0x7E7B0000, }; =20 @@ -75,6 +76,7 @@ static const int aspeed_soc_ast1030_irqmap[] =3D { [ASPEED_DEV_TIMER8] =3D 23, [ASPEED_DEV_WDT] =3D 24, [ASPEED_DEV_LPC] =3D 35, + [ASPEED_DEV_PECI] =3D 38, [ASPEED_DEV_FMC] =3D 39, [ASPEED_DEV_PWM] =3D 44, [ASPEED_DEV_ADC] =3D 46, @@ -133,6 +135,8 @@ static void aspeed_soc_ast1030_init(Object *obj) =20 object_initialize_child(obj, "lpc", &s->lpc, TYPE_ASPEED_LPC); =20 + object_initialize_child(obj, "peci", &s->peci, TYPE_ASPEED_PECI); + object_initialize_child(obj, "sbc", &s->sbc, TYPE_ASPEED_SBC); =20 for (i =3D 0; i < sc->wdts_num; i++) { @@ -206,6 +210,14 @@ static void aspeed_soc_ast1030_realize(DeviceState *de= v_soc, Error **errp) sysbus_connect_irq(SYS_BUS_DEVICE(&s->i2c.busses[i]), 0, irq); } =20 + /* PECI */ + if (!sysbus_realize(SYS_BUS_DEVICE(&s->peci), errp)) { + return; + } + sysbus_mmio_map(SYS_BUS_DEVICE(&s->peci), 0, sc->memmap[ASPEED_DEV_PEC= I]); + sysbus_connect_irq(SYS_BUS_DEVICE(&s->peci), 0, + aspeed_soc_get_irq(s, ASPEED_DEV_PECI)); + /* LPC */ if (!sysbus_realize(SYS_BUS_DEVICE(&s->lpc), errp)) { return; diff --git a/hw/arm/aspeed_ast2600.c b/hw/arm/aspeed_ast2600.c index b0a4199b69..85178fabea 100644 --- a/hw/arm/aspeed_ast2600.c +++ b/hw/arm/aspeed_ast2600.c @@ -59,6 +59,7 @@ static const hwaddr aspeed_soc_ast2600_memmap[] =3D { [ASPEED_DEV_LPC] =3D 0x1E789000, [ASPEED_DEV_IBT] =3D 0x1E789140, [ASPEED_DEV_I2C] =3D 0x1E78A000, + [ASPEED_DEV_PECI] =3D 0x1E78B000, [ASPEED_DEV_UART1] =3D 0x1E783000, [ASPEED_DEV_UART2] =3D 0x1E78D000, [ASPEED_DEV_UART3] =3D 0x1E78E000, @@ -122,6 +123,7 @@ static const int aspeed_soc_ast2600_irqmap[] =3D { [ASPEED_DEV_LPC] =3D 35, [ASPEED_DEV_IBT] =3D 143, [ASPEED_DEV_I2C] =3D 110, /* 110 -> 125 */ + [ASPEED_DEV_PECI] =3D 38, [ASPEED_DEV_ETH1] =3D 2, [ASPEED_DEV_ETH2] =3D 3, [ASPEED_DEV_HACE] =3D 4, @@ -180,6 +182,8 @@ static void aspeed_soc_ast2600_init(Object *obj) snprintf(typename, sizeof(typename), "aspeed.i2c-%s", socname); object_initialize_child(obj, "i2c", &s->i2c, typename); =20 + object_initialize_child(obj, "peci", &s->peci, TYPE_ASPEED_PECI); + snprintf(typename, sizeof(typename), "aspeed.fmc-%s", socname); object_initialize_child(obj, "fmc", &s->fmc, typename); =20 @@ -388,6 +392,14 @@ static void aspeed_soc_ast2600_realize(DeviceState *de= v, Error **errp) sysbus_connect_irq(SYS_BUS_DEVICE(&s->i2c.busses[i]), 0, irq); } =20 + /* PECI */ + if (!sysbus_realize(SYS_BUS_DEVICE(&s->peci), errp)) { + return; + } + sysbus_mmio_map(SYS_BUS_DEVICE(&s->peci), 0, sc->memmap[ASPEED_DEV_PEC= I]); + sysbus_connect_irq(SYS_BUS_DEVICE(&s->peci), 0, + aspeed_soc_get_irq(s, ASPEED_DEV_PECI)); + /* FMC, The number of CS is set at the board level */ object_property_set_link(OBJECT(&s->fmc), "dram", OBJECT(s->dram_mr), &error_abort); diff --git a/hw/arm/aspeed_soc.c b/hw/arm/aspeed_soc.c index 30574d4276..cb78d9945c 100644 --- a/hw/arm/aspeed_soc.c +++ b/hw/arm/aspeed_soc.c @@ -45,6 +45,7 @@ static const hwaddr aspeed_soc_ast2400_memmap[] =3D { [ASPEED_DEV_LPC] =3D 0x1E789000, [ASPEED_DEV_IBT] =3D 0x1E789140, [ASPEED_DEV_I2C] =3D 0x1E78A000, + [ASPEED_DEV_PECI] =3D 0x1E78B000, [ASPEED_DEV_ETH1] =3D 0x1E660000, [ASPEED_DEV_ETH2] =3D 0x1E680000, [ASPEED_DEV_UART1] =3D 0x1E783000, @@ -80,6 +81,7 @@ static const hwaddr aspeed_soc_ast2500_memmap[] =3D { [ASPEED_DEV_LPC] =3D 0x1E789000, [ASPEED_DEV_IBT] =3D 0x1E789140, [ASPEED_DEV_I2C] =3D 0x1E78A000, + [ASPEED_DEV_PECI] =3D 0x1E78B000, [ASPEED_DEV_ETH1] =3D 0x1E660000, [ASPEED_DEV_ETH2] =3D 0x1E680000, [ASPEED_DEV_UART1] =3D 0x1E783000, @@ -118,6 +120,7 @@ static const int aspeed_soc_ast2400_irqmap[] =3D { [ASPEED_DEV_PWM] =3D 28, [ASPEED_DEV_LPC] =3D 8, [ASPEED_DEV_I2C] =3D 12, + [ASPEED_DEV_PECI] =3D 15, [ASPEED_DEV_ETH1] =3D 2, [ASPEED_DEV_ETH2] =3D 3, [ASPEED_DEV_XDMA] =3D 6, @@ -174,6 +177,8 @@ static void aspeed_soc_init(Object *obj) snprintf(typename, sizeof(typename), "aspeed.i2c-%s", socname); object_initialize_child(obj, "i2c", &s->i2c, typename); =20 + object_initialize_child(obj, "peci", &s->peci, TYPE_ASPEED_PECI); + snprintf(typename, sizeof(typename), "aspeed.fmc-%s", socname); object_initialize_child(obj, "fmc", &s->fmc, typename); =20 @@ -316,6 +321,14 @@ static void aspeed_soc_realize(DeviceState *dev, Error= **errp) sysbus_connect_irq(SYS_BUS_DEVICE(&s->i2c), 0, aspeed_soc_get_irq(s, ASPEED_DEV_I2C)); =20 + /* PECI */ + if (!sysbus_realize(SYS_BUS_DEVICE(&s->peci), errp)) { + return; + } + sysbus_mmio_map(SYS_BUS_DEVICE(&s->peci), 0, sc->memmap[ASPEED_DEV_PEC= I]); + sysbus_connect_irq(SYS_BUS_DEVICE(&s->peci), 0, + aspeed_soc_get_irq(s, ASPEED_DEV_PECI)); + /* FMC, The number of CS is set at the board level */ object_property_set_link(OBJECT(&s->fmc), "dram", OBJECT(s->dram_mr), &error_abort); diff --git a/hw/misc/aspeed_peci.c b/hw/misc/aspeed_peci.c new file mode 100644 index 0000000000..91637e29b2 --- /dev/null +++ b/hw/misc/aspeed_peci.c @@ -0,0 +1,136 @@ +/* + * Aspeed PECI Controller + * + * Copyright (c) Meta Platforms, Inc. and affiliates. (http://www.meta.com) + * + * This code is licensed under the GPL version 2 or later. See the COPYING + * file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "hw/irq.h" +#include "hw/misc/aspeed_peci.h" +#include "trace.h" + +static void aspeed_peci_raise_interrupt(AspeedPECIState *s, uint32_t statu= s) +{ + s->regs[R_PECI_INT_STS] =3D s->regs[R_PECI_INT_CTRL] & status; + if (!s->regs[R_PECI_INT_STS]) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: Interrupts disabled: ctrl 0x%08x sts 0x%08x\n", + __func__, s->regs[R_PECI_INT_CTRL], status); + return; + } + qemu_irq_raise(s->irq); +} + +static uint64_t aspeed_peci_read(void *opaque, hwaddr offset, unsigned siz= e) +{ + AspeedPECIState *s =3D ASPEED_PECI(opaque); + uint64_t data; + + if (offset >=3D ASPEED_PECI_NR_REGS << 2) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: Out-of-bounds read at offset 0x%" HWADDR_PRIx "= \n", + __func__, offset); + return 0; + } + data =3D s->regs[offset / sizeof(s->regs[0])]; + + trace_aspeed_peci_read(offset, data); + return data; +} + +static void aspeed_peci_write(void *opaque, hwaddr offset, uint64_t data, + unsigned size) +{ + AspeedPECIState *s =3D ASPEED_PECI(opaque); + + trace_aspeed_peci_write(offset, data); + + if (offset >=3D ASPEED_PECI_NR_REGS << 2) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: Out-of-bounds write at offset 0x%" HWADDR_PRIx = "\n", + __func__, offset); + return; + } + + switch (offset) { + case A_PECI_INT_STS: + s->regs[R_PECI_INT_STS] &=3D ~data; + if (!s->regs[R_PECI_INT_STS]) { + qemu_irq_lower(s->irq); + } + break; + case A_PECI_CMD: + /* + * Only the FIRE bit is writable. Once the command is complete, it + * should be cleared. Since we complete the command immediately, t= he + * value is not stored in the register array. + */ + if (!FIELD_EX32(data, PECI_CMD, FIRE)) { + break; + } + if (s->regs[R_PECI_INT_STS]) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: Interrupt status must be " + "cleared before firing another command: 0x%08x\n= ", + __func__, s->regs[R_PECI_INT_STS]); + break; + } + s->regs[R_PECI_RD_DATA0] =3D ASPEED_PECI_CC_RSP_SUCCESS; + s->regs[R_PECI_WR_DATA0] =3D ASPEED_PECI_CC_RSP_SUCCESS; + aspeed_peci_raise_interrupt(s, + FIELD_DP32(0, PECI_INT_STS, CMD_DONE, = 1)); + qemu_irq_raise(s->irq); + break; + default: + s->regs[offset / sizeof(s->regs[0])] =3D data; + break; + } +} + +static const MemoryRegionOps aspeed_peci_ops =3D { + .read =3D aspeed_peci_read, + .write =3D aspeed_peci_write, + .endianness =3D DEVICE_LITTLE_ENDIAN, +}; + +static void aspeed_peci_realize(DeviceState *dev, Error **errp) +{ + AspeedPECIState *s =3D ASPEED_PECI(dev); + SysBusDevice *sbd =3D SYS_BUS_DEVICE(dev); + + memory_region_init_io(&s->mmio, OBJECT(s), &aspeed_peci_ops, s, + TYPE_ASPEED_PECI, 0x1000); + sysbus_init_mmio(sbd, &s->mmio); + sysbus_init_irq(sbd, &s->irq); +} + +static void aspeed_peci_reset(DeviceState *dev) +{ + AspeedPECIState *s =3D ASPEED_PECI(dev); + + memset(s->regs, 0, sizeof(s->regs)); +} + +static void aspeed_peci_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + dc->realize =3D aspeed_peci_realize; + dc->reset =3D aspeed_peci_reset; + dc->desc =3D "Aspeed PECI Controller"; +} + +static const TypeInfo aspeed_peci_types[] =3D { + { + .name =3D TYPE_ASPEED_PECI, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(AspeedPECIState), + .class_init =3D aspeed_peci_class_init, + .abstract =3D false, + }, +}; + +DEFINE_TYPES(aspeed_peci_types); diff --git a/hw/misc/meson.build b/hw/misc/meson.build index 132b7b7344..95268eddc0 100644 --- a/hw/misc/meson.build +++ b/hw/misc/meson.build @@ -116,7 +116,8 @@ softmmu_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: file= s( 'aspeed_scu.c', 'aspeed_sbc.c', 'aspeed_sdmc.c', - 'aspeed_xdma.c')) + 'aspeed_xdma.c', + 'aspeed_peci.c')) =20 softmmu_ss.add(when: 'CONFIG_MSF2', if_true: files('msf2-sysreg.c')) softmmu_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('nrf51_rng.c')) diff --git a/hw/misc/trace-events b/hw/misc/trace-events index c5e37b0154..af0b9c5dbf 100644 --- a/hw/misc/trace-events +++ b/hw/misc/trace-events @@ -209,6 +209,10 @@ aspeed_i3c_device_write(uint32_t deviceid, uint64_t of= fset, uint64_t data) "I3C 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 =20 +# aspeed_peci.c +aspeed_peci_read(uint64_t offset, uint64_t data) "offset 0x%" PRIx64 " dat= a 0x%" PRIx64 +aspeed_peci_write(uint64_t offset, uint64_t data) "offset 0x%" PRIx64 " da= ta 0x%" PRIx64 + # bcm2835_property.c bcm2835_mbox_property(uint32_t tag, uint32_t bufsize, size_t resplen) "mbo= x property tag:0x%08x in_sz:%u out_sz:%zu" =20 diff --git a/include/hw/arm/aspeed_soc.h b/include/hw/arm/aspeed_soc.h index 02a5a9ffcb..f72a8db50b 100644 --- a/include/hw/arm/aspeed_soc.h +++ b/include/hw/arm/aspeed_soc.h @@ -34,6 +34,7 @@ #include "hw/usb/hcd-ehci.h" #include "qom/object.h" #include "hw/misc/aspeed_lpc.h" +#include "hw/misc/aspeed_peci.h" =20 #define ASPEED_SPIS_NUM 2 #define ASPEED_EHCIS_NUM 2 @@ -73,6 +74,7 @@ struct AspeedSoCState { AspeedSDHCIState sdhci; AspeedSDHCIState emmc; AspeedLPCState lpc; + AspeedPECIState peci; uint32_t uart_default; Clock *sysclk; }; @@ -145,6 +147,7 @@ enum { ASPEED_DEV_LPC, ASPEED_DEV_IBT, ASPEED_DEV_I2C, + ASPEED_DEV_PECI, ASPEED_DEV_ETH1, ASPEED_DEV_ETH2, ASPEED_DEV_ETH3, diff --git a/include/hw/misc/aspeed_peci.h b/include/hw/misc/aspeed_peci.h new file mode 100644 index 0000000000..8746f93ad7 --- /dev/null +++ b/include/hw/misc/aspeed_peci.h @@ -0,0 +1,47 @@ +/* + * Aspeed PECI Controller + * + * Copyright (c) Meta Platforms, Inc. and affiliates. (http://www.meta.com) + * + * This code is licensed under the GPL version 2 or later. See the COPYING + * file in the top-level directory. + */ + +#ifndef ASPEED_PECI_H +#define ASPEED_PECI_H + +#include "hw/sysbus.h" +#include "hw/registerfields.h" + +#define ASPEED_PECI_NR_REGS ((0xFC + 4) >> 2) +#define ASPEED_PECI_CC_RSP_SUCCESS (0x40U) + +#define TYPE_ASPEED_PECI "aspeed.peci" +OBJECT_DECLARE_SIMPLE_TYPE(AspeedPECIState, ASPEED_PECI); + +/* Command Register */ +REG32(PECI_CMD, 0x08) + FIELD(PECI_CMD, FIRE, 0, 1) + +/* Interrupt Control Register */ +REG32(PECI_INT_CTRL, 0x18) + +/* Interrupt Status Register */ +REG32(PECI_INT_STS, 0x1C) + FIELD(PECI_INT_STS, CMD_DONE, 0, 1) + +/* Rx/Tx Data Buffer Registers */ +REG32(PECI_WR_DATA0, 0x20) +REG32(PECI_RD_DATA0, 0x30) + +struct AspeedPECIState { + /* */ + SysBusDevice parent; + + MemoryRegion mmio; + qemu_irq irq; + + uint32_t regs[ASPEED_PECI_NR_REGS]; +}; + +#endif --=20 2.30.2 From nobody Mon Feb 9 08:34:04 2026 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=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1656474668250194.78802077311786; Tue, 28 Jun 2022 20:51:08 -0700 (PDT) Received: from localhost ([::1]:34768 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o6OjK-00031F-QC for importer@patchew.org; Tue, 28 Jun 2022 23:51:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45906) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o6OVV-0007t5-Kh; Tue, 28 Jun 2022 23:36:49 -0400 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]:44930) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o6OVT-0006sb-Ju; Tue, 28 Jun 2022 23:36:49 -0400 Received: by mail-pf1-x434.google.com with SMTP id 65so13803578pfw.11; Tue, 28 Jun 2022 20:36:46 -0700 (PDT) Received: from localhost (fwdproxy-prn-019.fbsv.net. [2a03:2880:ff:13::face:b00c]) by smtp.gmail.com with ESMTPSA id t16-20020aa79390000000b0052521fd273fsm10217347pfe.218.2022.06.28.20.36.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jun 2022 20:36:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ORuh6V682i3Tt38y6TVhgXBFwXWiboHy9vQ1EQI2xMg=; b=b0HP8aE16JLDd4d6imHEstX3rs+X4ICC0Vlm9io91SEzmoUVLsXddiSDGNvyzsVuFX bfb7eZfjqWLgledvA8WvMMSbJdAyXa3qEQqzYbJBePPyztqs9yIccUfBUSJBRuZEftWw 9/KdFgsQSRlQNKDe+PRBX8JyKTu/w1Glbj8b/v4CYY910BVge0GPZvUoYofycXxX+3gU BDwbQoITesUrEJe8CAPqo8I5YkFxv7SBbPNNhvyYHUmfOXqOVWyu3k848JMEfYe7M3y/ p+coZBV6IoQXY1P9lUBPwEtSIHReSKSUVXn1pfFkfyUKW6pi37XI5hjhDAwNKrscuiru Txhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ORuh6V682i3Tt38y6TVhgXBFwXWiboHy9vQ1EQI2xMg=; b=PPiqRGf9wElwu3MxhduDRNjr4svSoiw8bTCu1yI7aJz08aFuxJlJ4BtSr2C/0Alj0/ tRQ+NT0Z7xZDHllkIsKExahWEeFEkgZ3WMgi/+e8X9XL7WFApkDn0FmO3469s3tM1LSa y9eM/Wcgp+TBSfZ6XZagRLTiLIej/ZoojBguYW48SzeisHzK8/5J8gULs31lx8gUwdvZ IVm0FCjPSlnOqo1nMtfo/kH3IkZlef/4M3ULQuam/7TrcILQonl+IajO4u4i39kavdhg Rty4R58n0RLdcWyCUps3kgjiZjJBUKTaXlZ1BdKqcw1b7x34XqA5TQ9O1p16OPEkYdOd bZHg== X-Gm-Message-State: AJIora/cwWpWXy88zDVhH7t3M3dN7IwK5tNHeY/xUvce4nRdZjN9wtgA elFFoGRTZqlGzCKPiqcC0/8= X-Google-Smtp-Source: AGRyM1tovU2A1neyrphv1XHKhOvbpeZ0tMSY4HDzGWyFQDAtUGBnS44du60bD8E5Xrtl5hHVEuiRMA== X-Received: by 2002:a63:cf18:0:b0:40d:5506:df97 with SMTP id j24-20020a63cf18000000b0040d5506df97mr1142894pgg.43.1656473805412; Tue, 28 Jun 2022 20:36:45 -0700 (PDT) From: Peter Delevoryas X-Google-Original-From: Peter Delevoryas To: Cc: clg@kaod.org, peter.maydell@linaro.org, andrew@aj.id.au, joel@jms.id.au, cminyard@mvista.com, titusr@google.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, zhdaniel@fb.com, pdel@fb.com Subject: [PATCH v2 11/13] hw/misc/aspeed: Add fby35-sb-cpld Date: Tue, 28 Jun 2022 20:36:32 -0700 Message-Id: <20220629033634.3850922-12-pdel@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220629033634.3850922-1-pdel@fb.com> References: <20220629033634.3850922-1-pdel@fb.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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::434; envelope-from=peterdelevoryas@gmail.com; helo=mail-pf1-x434.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1656474669025100001 Content-Type: text/plain; charset="utf-8" fby35 machines have 1 BMC on a baseboard and 2-4 server boards with BIC's. There are also CPLD's on each of the boards, one type of CPLD on the baseboard and another type on each of the server boards. This commit adds an implementation of some of the logic performed by the server board CPLD, which is connected to the server board BIC. fby35 machines have 1 baseboard with a BMC (AST2600) and 4 server boards with bridge interconnects (BIC's, AST1030's). Each server board has a CPLD on it which provides FRU information and some synchronization functionality with the BMC. The baseboard also has one CPLD, but it does other stuff. This commit just adds some of the FRU functionality to allow the BIC to startup without any errors. Signed-off-by: Peter Delevoryas --- MAINTAINERS | 1 + hw/misc/fby35_sb_cpld.c | 128 ++++++++++++++++++++++++++++++++++++++++ hw/misc/meson.build | 3 +- 3 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 hw/misc/fby35_sb_cpld.c diff --git a/MAINTAINERS b/MAINTAINERS index 05cf84b58c..3ffd473db1 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1067,6 +1067,7 @@ F: hw/net/ftgmac100.c F: include/hw/net/ftgmac100.h F: docs/system/arm/aspeed.rst F: tests/qtest/*aspeed* +F: hw/misc/fby35_sb_cpld.c =20 NRF51 M: Joel Stanley diff --git a/hw/misc/fby35_sb_cpld.c b/hw/misc/fby35_sb_cpld.c new file mode 100644 index 0000000000..f170a6c781 --- /dev/null +++ b/hw/misc/fby35_sb_cpld.c @@ -0,0 +1,128 @@ +/* + * fby35 Server Board CPLD + * + * Copyright (c) Meta Platforms, Inc. and affiliates. (http://www.meta.com) + * + * This code is licensed under the GPL version 2 or later. See the COPYING + * file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "hw/i2c/i2c.h" +#include "hw/registerfields.h" + +#define BOARD_ID_CLASS1 0b0000 +#define BOARD_ID_CLASS2 0b0001 + +#define TYPE_FBY35_SB_CPLD "fby35-sb-cpld" +OBJECT_DECLARE_SIMPLE_TYPE(Fby35SbCpldState, FBY35_SB_CPLD); + +REG8(CLASS_TYPE, 0x5); + FIELD(CLASS_TYPE, RESERVED, 0, 2); + FIELD(CLASS_TYPE, 1OU_EXPANSION_NOT_PRESENT, 2, 1); + FIELD(CLASS_TYPE, 2OU_EXPANSION_NOT_PRESENT, 3, 1); + FIELD(CLASS_TYPE, BOARD_ID, 4, 4); +REG8(BOARD_REVISION, 0x8); + FIELD(BOARD_REVISION, VALUE, 0, 4); + FIELD(BOARD_REVISION, RESERVED, 4, 4); + +struct Fby35SbCpldState { + I2CSlave parent_obj; + + uint8_t target_reg; + uint32_t regs[10]; +}; + +static void fby35_sb_cpld_realize(DeviceState *dev, Error **errp) +{ + Fby35SbCpldState *s =3D FBY35_SB_CPLD(dev); + + memset(s->regs, 0, sizeof(s->regs)); + s->target_reg =3D 0; + + ARRAY_FIELD_DP32(s->regs, CLASS_TYPE, BOARD_ID, 0b0000); + ARRAY_FIELD_DP32(s->regs, CLASS_TYPE, 1OU_EXPANSION_NOT_PRESENT, 1); + ARRAY_FIELD_DP32(s->regs, CLASS_TYPE, 2OU_EXPANSION_NOT_PRESENT, 1); + ARRAY_FIELD_DP32(s->regs, BOARD_REVISION, VALUE, 0x1); +} + +static int fby35_sb_cpld_i2c_event(I2CSlave *i2c, enum i2c_event event) +{ + Fby35SbCpldState *s =3D FBY35_SB_CPLD(i2c); + + switch (event) { + case I2C_START_RECV: + break; + case I2C_START_SEND: + s->target_reg =3D 0; + break; + case I2C_START_SEND_ASYNC: + case I2C_FINISH: + case I2C_NACK: + break; + } + + return 0; +} + +static uint8_t fby35_sb_cpld_i2c_recv(I2CSlave *i2c) +{ + Fby35SbCpldState *s =3D FBY35_SB_CPLD(i2c); + + switch (s->target_reg) { + case R_CLASS_TYPE: + case R_BOARD_REVISION: + return s->regs[s->target_reg]; + default: + qemu_log_mask(LOG_UNIMP, "%s: Register read unimplemented: 0x%02x\= n", + __func__, s->target_reg); + return 0xff; + } +} + +static int fby35_sb_cpld_i2c_send(I2CSlave *i2c, uint8_t data) +{ + Fby35SbCpldState *s =3D FBY35_SB_CPLD(i2c); + + if (s->target_reg =3D=3D 0) { + s->target_reg =3D data; + return 0; + } + + switch (s->target_reg) { + case R_CLASS_TYPE: + case R_BOARD_REVISION: + s->regs[s->target_reg] =3D data; + break; + default: + qemu_log_mask(LOG_UNIMP, + "%s: Register write unimplemented: 0x%02x 0x%02x\n", + __func__, s->target_reg, data); + break; + } + + return 0; +} + +static void fby35_sb_cpld_class_init(ObjectClass *oc, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(oc); + I2CSlaveClass *i2c =3D I2C_SLAVE_CLASS(oc); + + dc->realize =3D fby35_sb_cpld_realize; + i2c->event =3D fby35_sb_cpld_i2c_event; + i2c->recv =3D fby35_sb_cpld_i2c_recv; + i2c->send =3D fby35_sb_cpld_i2c_send; +} + +static const TypeInfo types[] =3D { + { + .name =3D TYPE_FBY35_SB_CPLD, + .parent =3D TYPE_I2C_SLAVE, + .instance_size =3D sizeof(Fby35SbCpldState), + .class_init =3D fby35_sb_cpld_class_init, + }, +}; + +DEFINE_TYPES(types); diff --git a/hw/misc/meson.build b/hw/misc/meson.build index 95268eddc0..948e25c440 100644 --- a/hw/misc/meson.build +++ b/hw/misc/meson.build @@ -117,7 +117,8 @@ softmmu_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: file= s( 'aspeed_sbc.c', 'aspeed_sdmc.c', 'aspeed_xdma.c', - 'aspeed_peci.c')) + 'aspeed_peci.c', + 'fby35_sb_cpld.c')) =20 softmmu_ss.add(when: 'CONFIG_MSF2', if_true: files('msf2-sysreg.c')) softmmu_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('nrf51_rng.c')) --=20 2.30.2 From nobody Mon Feb 9 08:34:04 2026 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=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16564748196498.077573678924637; Tue, 28 Jun 2022 20:53:39 -0700 (PDT) Received: from localhost ([::1]:38914 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o6Olm-0005yC-EH for importer@patchew.org; Tue, 28 Jun 2022 23:53:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45930) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o6OVW-0007xG-Og; Tue, 28 Jun 2022 23:36:50 -0400 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]:50806) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o6OVU-0006oR-G3; Tue, 28 Jun 2022 23:36:50 -0400 Received: by mail-pj1-x1030.google.com with SMTP id go6so14472565pjb.0; Tue, 28 Jun 2022 20:36:46 -0700 (PDT) Received: from localhost (fwdproxy-prn-012.fbsv.net. [2a03:2880:ff:c::face:b00c]) by smtp.gmail.com with ESMTPSA id h5-20020a170902f7c500b00163bfaf0b17sm6774673plw.233.2022.06.28.20.36.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jun 2022 20:36:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SzQWwnUtME47hns+L0n+YQNwQXFOjidePehK/A5S+y4=; b=nb6kKEeO2Z7RtR+nTKvVFvGj2OFiKtwG9R9+JLzG4tE0CFG5Z27OSFtRkQ/vCYrzZX Cg7FuVfBLu7hhUvMyX1lA/4HpUOCLyB/GS/7C1pFQoSUInGlLnMZ16/6rxMuKrUDJmvY eg3h9yWlwODcBLZ+DOv+ARc3+WoA2owvmmUuICnwbSfqwJNx0rZBTXNt+bTvFgUjuCe1 9bJLft1GnUUwVIyqbvVIqb5kQKENQx0cVF+SWOAiuwaHXxc+L52VsYIXADtujzU+jHBe TiNnQP3acqQF8fGM7rC/i7TVVBhfsHcI/Jrs3jxEeXySfFT/NM47Z8QgOgK5K6Xxzl2T wLlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SzQWwnUtME47hns+L0n+YQNwQXFOjidePehK/A5S+y4=; b=nwj5ZpCi6APNyF9F6Wj3t15RUcyN+7Vfnaxk2d+gf9zJVKnpM4+6Ln12O0Xahh+Q+h XuhxgiSk2cpm/aVy3Ea4LAOpJscSbtwBD+MR4xjYw4BaXUqPos3EIVm7vZzYl1Fueu9s sja3Qtv3xpI4JxbhpAdwyGjYozfA/JXIOvimklta911H/NxSQ1oqDHJObU2g75i/gK7q trsTSB0O89/CQzYgN+iTYgxBFT7IXLQkWcYPYkBrFZ4H/IpOID0szI2VP4rMvOxZxPEm RvtSGfquw/qlrM5T9FhQt2r90OEhKfOg8hsVJGn0EosU/3vQOsNfefRAhhYcIAgz6dsJ y3aw== X-Gm-Message-State: AJIora8f5BwCTJcGj59iDFjmE/CRF+/MUBu5q8ru09GY7hbDkgAtLaJB W24T0gNOQzUFyAsshg7Yzs6e4eSvQC8Pww== X-Google-Smtp-Source: AGRyM1uVxpx51DiHh9q0K/Nnql0Jn5lLvVM99HL/APrrOMpqiHDNBOgFQSX+cZCAzQjRmzlz7XR4wQ== X-Received: by 2002:a17:903:22c7:b0:16a:7114:feb4 with SMTP id y7-20020a17090322c700b0016a7114feb4mr7010122plg.22.1656473806400; Tue, 28 Jun 2022 20:36:46 -0700 (PDT) From: Peter Delevoryas X-Google-Original-From: Peter Delevoryas To: Cc: clg@kaod.org, peter.maydell@linaro.org, andrew@aj.id.au, joel@jms.id.au, cminyard@mvista.com, titusr@google.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, zhdaniel@fb.com, pdel@fb.com Subject: [PATCH v2 12/13] hw/misc/aspeed: Add intel-me Date: Tue, 28 Jun 2022 20:36:33 -0700 Message-Id: <20220629033634.3850922-13-pdel@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220629033634.3850922-1-pdel@fb.com> References: <20220629033634.3850922-1-pdel@fb.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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::1030; envelope-from=peterdelevoryas@gmail.com; helo=mail-pj1-x1030.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1656474820076100001 Content-Type: text/plain; charset="utf-8" The Intel Management Engine is an IPMI endpoint that responds to various IPMI commands. In this commit, I've added some very basic functionality that will respond back with a respond code of zero (success), while also setting an appropriate response NetFN (request NetFN + 1), a matching command ID and sequence number, and the 2 standard checksums. Other data is not provided, but the model here could be extended to respond to more kinds of requests. Signed-off-by: Peter Delevoryas --- MAINTAINERS | 1 + hw/misc/intel_me.c | 162 +++++++++++++++++++++++++++++++++++++++++++ hw/misc/meson.build | 3 +- hw/misc/trace-events | 8 +++ 4 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 hw/misc/intel_me.c diff --git a/MAINTAINERS b/MAINTAINERS index 3ffd473db1..3220644bb5 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -1068,6 +1068,7 @@ F: include/hw/net/ftgmac100.h F: docs/system/arm/aspeed.rst F: tests/qtest/*aspeed* F: hw/misc/fby35_sb_cpld.c +F: hw/misc/intel_me.c =20 NRF51 M: Joel Stanley diff --git a/hw/misc/intel_me.c b/hw/misc/intel_me.c new file mode 100644 index 0000000000..933ae45101 --- /dev/null +++ b/hw/misc/intel_me.c @@ -0,0 +1,162 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. (http://www.meta.com) + * + * This code is licensed under the GPL version 2 or later. See the COPYING + * file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "qemu/main-loop.h" +#include "hw/i2c/i2c.h" +#include "trace.h" + +#define TYPE_INTEL_ME "intel-me" +OBJECT_DECLARE_SIMPLE_TYPE(IntelMEState, INTEL_ME); + +struct IntelMEState { + I2CSlave parent_obj; + + I2CBus *bus; + QEMUBH *bh; + int rx_len; + int tx_len; + int tx_pos; + uint8_t rx_buf[512]; + uint8_t tx_buf[512]; +}; + +static void intel_me_bh(void *opaque) +{ + IntelMEState *s =3D opaque; + I2CSlave *i2c =3D I2C_SLAVE(s); + uint8_t target_addr; + + assert(s->bus->bh =3D=3D s->bh); + + switch (s->tx_pos) { + case 0: + target_addr =3D s->tx_buf[s->tx_pos++]; + trace_intel_me_tx_start(i2c->address, target_addr); + if (i2c_start_send_async(s->bus, target_addr) !=3D 0) { + break; + } + return; + default: + if (s->tx_pos >=3D s->tx_len) { + break; + } + trace_intel_me_tx_data(i2c->address, s->tx_buf[s->tx_pos]); + if (i2c_send_async(s->bus, s->tx_buf[s->tx_pos++]) !=3D 0) { + break; + } + return; + } + + trace_intel_me_tx_end(i2c->address); + i2c_end_transfer(s->bus); + i2c_bus_release(s->bus); + s->tx_len =3D 0; + s->tx_pos =3D 0; + memset(s->tx_buf, 0, sizeof(s->tx_buf)); +} + +static void intel_me_realize(DeviceState *dev, Error **errp) +{ + IntelMEState *s =3D INTEL_ME(dev); + + s->bus =3D I2C_BUS(qdev_get_parent_bus(dev)); + s->bh =3D qemu_bh_new(intel_me_bh, s); + s->rx_len =3D 0; + s->tx_len =3D 0; + s->tx_pos =3D 0; + memset(s->rx_buf, 0, sizeof(s->rx_buf)); + memset(s->tx_buf, 0, sizeof(s->tx_buf)); +} + +static uint8_t checksum(const uint8_t *ptr, int len) +{ + int sum =3D 0; + + for (int i =3D 0; i < len; i++) { + sum +=3D ptr[i]; + } + + return 256 - sum; +} + +static int intel_me_i2c_event(I2CSlave *i2c, enum i2c_event event) +{ + IntelMEState *s =3D INTEL_ME(i2c); + + switch (event) { + case I2C_START_RECV: + break; + case I2C_START_SEND: + trace_intel_me_rx_start(i2c->address); + s->rx_len =3D 0; + memset(s->rx_buf, 0, sizeof(s->rx_buf)); + break; + case I2C_START_SEND_ASYNC: + break; + case I2C_FINISH: + trace_intel_me_rx_end(i2c->address); + s->tx_len =3D 10; + s->tx_pos =3D 0; + s->tx_buf[0] =3D s->rx_buf[2]; + s->tx_buf[1] =3D ((s->rx_buf[0] >> 2) + 1) << 2; + s->tx_buf[2] =3D checksum(s->tx_buf, 2); + s->tx_buf[3] =3D i2c->address; + s->tx_buf[4] =3D (s->rx_buf[3] >> 2) << 2; + s->tx_buf[5] =3D s->rx_buf[4]; + s->tx_buf[6] =3D 0x00; + s->tx_buf[7] =3D 0x55; + s->tx_buf[8] =3D 0x00; + s->tx_buf[9] =3D checksum(s->tx_buf, s->tx_len - 1); + s->tx_buf[0] >>=3D 1; + i2c_bus_master(s->bus, s->bh); + break; + case I2C_NACK: + break; + } + + return 0; +} + +static uint8_t intel_me_i2c_recv(I2CSlave *i2c) +{ + return 0xff; +} + +static int intel_me_i2c_send(I2CSlave *i2c, uint8_t data) +{ + IntelMEState *s =3D INTEL_ME(i2c); + + trace_intel_me_rx_data(i2c->address, data); + + assert(s->rx_len < sizeof(s->rx_buf)); + s->rx_buf[s->rx_len++] =3D data; + + return 0; +} + +static void intel_me_class_init(ObjectClass *oc, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(oc); + I2CSlaveClass *i2c =3D I2C_SLAVE_CLASS(oc); + + dc->realize =3D intel_me_realize; + i2c->event =3D intel_me_i2c_event; + i2c->recv =3D intel_me_i2c_recv; + i2c->send =3D intel_me_i2c_send; +} + +static const TypeInfo types[] =3D { + { + .name =3D TYPE_INTEL_ME, + .parent =3D TYPE_I2C_SLAVE, + .instance_size =3D sizeof(IntelMEState), + .class_init =3D intel_me_class_init, + }, +}; + +DEFINE_TYPES(types); diff --git a/hw/misc/meson.build b/hw/misc/meson.build index 948e25c440..165b9dce6d 100644 --- a/hw/misc/meson.build +++ b/hw/misc/meson.build @@ -118,7 +118,8 @@ softmmu_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: file= s( 'aspeed_sdmc.c', 'aspeed_xdma.c', 'aspeed_peci.c', - 'fby35_sb_cpld.c')) + 'fby35_sb_cpld.c', + 'intel_me.c')) =20 softmmu_ss.add(when: 'CONFIG_MSF2', if_true: files('msf2-sysreg.c')) softmmu_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('nrf51_rng.c')) diff --git a/hw/misc/trace-events b/hw/misc/trace-events index af0b9c5dbf..089668ff6c 100644 --- a/hw/misc/trace-events +++ b/hw/misc/trace-events @@ -272,3 +272,11 @@ virt_ctrl_instance_init(void *dev) "ctrl: %p" lasi_chip_mem_valid(uint64_t addr, uint32_t val) "access to addr 0x%"PRIx6= 4" is %d" lasi_chip_read(uint64_t addr, uint32_t val) "addr 0x%"PRIx64" val 0x%08x" lasi_chip_write(uint64_t addr, uint32_t val) "addr 0x%"PRIx64" val 0x%08x" + +# intel_me.c +intel_me_rx_start(uint8_t addr) "addr 0x%02x" +intel_me_rx_data(uint8_t addr, uint8_t data) "addr 0x%02x data 0x%02x" +intel_me_rx_end(uint8_t addr) "addr 0x%02x" +intel_me_tx_start(uint8_t addr, uint8_t target_addr) "addr 0x%02x target_a= ddr 0x%02x" +intel_me_tx_data(uint8_t addr, uint8_t data) "addr 0x%02x data 0x%02x" +intel_me_tx_end(uint8_t addr) "addr 0x%02x" --=20 2.30.2 From nobody Mon Feb 9 08:34:04 2026 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=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1656475005487481.88991881166385; Tue, 28 Jun 2022 20:56:45 -0700 (PDT) Received: from localhost ([::1]:43130 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o6Oom-0000Va-Bv for importer@patchew.org; Tue, 28 Jun 2022 23:56:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45932) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o6OVW-0007xW-RF; Tue, 28 Jun 2022 23:36:50 -0400 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]:40520) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o6OVU-0006ss-R7; Tue, 28 Jun 2022 23:36:50 -0400 Received: by mail-pg1-x52c.google.com with SMTP id 9so14058691pgd.7; Tue, 28 Jun 2022 20:36:48 -0700 (PDT) Received: from localhost (fwdproxy-prn-006.fbsv.net. [2a03:2880:ff:6::face:b00c]) by smtp.gmail.com with ESMTPSA id c13-20020a170902c1cd00b0016a276aada7sm10136635plc.20.2022.06.28.20.36.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jun 2022 20:36:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mQ7p58dP8yL7VZt2P5gdrVm9FaK+5XRismhrco1SEZY=; b=JAGO6l5OulxoENGAfU9Xfvs8kV1yVXVfRHerk3BGfNrNehuwlx7QJriuxy9ZGgx3ga m+4+Y2fH+1O89uPfXrRsrWY7lFrA6wM8s2XbfPi9c+BIPovNwbElC/KnFUC7+dfK1nX3 oMSDdIDlZHSoh4eBbvXsiyv0VpfwkqQ/EqK9LxA907owk0TJ7T2hBg9wKnyDoc+z3AN8 5R3aGyzbY6VybGy9VpgZL0k9/ejEmnKPSZJnnFYwSFfXD+Nqf4/wuClLo+6yAn6Qrivq o0MA9QSOEwp4KeGTzEeMjCG9vmTtIIpnHeW580mIm1zjrzOGHqVzdiI3t/RAmtyqDwKJ 6iPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mQ7p58dP8yL7VZt2P5gdrVm9FaK+5XRismhrco1SEZY=; b=KfZtuBiRZ4yi47BTYb3pAtonjKB/6JI6Sv7Whda4otKIJry6mCQK5HiOTHmUcmDjYr KFRfDS7UCAU6qgxOe2A3iOkSfcJs3yCZgHVHd1upNYpsfSxxCsAtY7GN52ZhdiNUvb7Y f0BSfkJmNyuZqP4PvPm8cUcwk0FOGqGGCLsm9ToAjeHgFlbwHy3gZNwWtdxyv6scnqYM GiMowf968sh1DgnFszOCOiReyADaCwCJHtpxB6w4Wy25Bpj55gD6zJgJ6AcoNHEoSa9g 9O5N3q3K3bLMJrrAPKxN4JQtG9hSl7Brn7HT5sR1RxfAxqCKauw5/Vg3rNfRy/yfL/mE Ywmw== X-Gm-Message-State: AJIora/cnZ46Dw6l+vhqZCD/O8LcELaaEnwGvGLqr1jX/dMlo+sjKB8j IlZ7f/An/k+ezN+uYQrTCC0= X-Google-Smtp-Source: AGRyM1vduUI32CLI0oiQZduq+ljdy2NIZ4FHY0BBf7xuY18YnnZNHZ2VACVYHtT9KDHs+GUZ3aV4mw== X-Received: by 2002:a63:6d0d:0:b0:40c:f2dc:222f with SMTP id i13-20020a636d0d000000b0040cf2dc222fmr1170668pgc.414.1656473807171; Tue, 28 Jun 2022 20:36:47 -0700 (PDT) From: Peter Delevoryas X-Google-Original-From: Peter Delevoryas To: Cc: clg@kaod.org, peter.maydell@linaro.org, andrew@aj.id.au, joel@jms.id.au, cminyard@mvista.com, titusr@google.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, zhdaniel@fb.com, pdel@fb.com Subject: [PATCH v2 13/13] hw/arm/aspeed: Add oby35-cl machine Date: Tue, 28 Jun 2022 20:36:34 -0700 Message-Id: <20220629033634.3850922-14-pdel@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220629033634.3850922-1-pdel@fb.com> References: <20220629033634.3850922-1-pdel@fb.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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::52c; envelope-from=peterdelevoryas@gmail.com; helo=mail-pg1-x52c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1656475006889100001 Content-Type: text/plain; charset="utf-8" The fby35 machine includes 4 server boards, each of which has a "bridge interconnect" (BIC). This chip abstracts the pinout for the server board into a single endpoint that the baseboard management controller (BMC) can talk to using IPMB. The codename for this board is oby35-cl, which means "OpenBIC Yosemite3.5 CraterLake". There is also a variant of the BIC called "OpenBIC Yosemite3.5 Baseboard", which is an image built to run from the baseboard as a replacement for the BMC, that's not included here, but that's why the "-cl" suffix is included. A test image can be built from https://github.com/facebook/openbic using the instructions in the README.md to build the meta-facebook/yv35-cl recipe, or retrieved from my Github: wget https://github.com/peterdelevoryas/OpenBIC/releases/download/oby35= -cl-2022.17.01/Y35BCL.elf And you can run this machine with the following command: qemu-system-arm -machine oby35-cl -nographic -kernel Y35BCL.elf It should produce output like the following: [00:00:00.008,000] usb_dc_aspeed: select ep[0x81] as IN endpoint [00:00:00.009,000] usb_dc_aspeed: select ep[0x82] as IN endpoint [00:00:00.009,000] usb_dc_aspeed: pre-selected ep[0x1] as IN endp= oint [00:00:00.009,000] usb_dc_aspeed: pre-selected ep[0x2] as IN endp= oint [00:00:00.009,000] usb_dc_aspeed: select ep[0x3] as OUT endpoint *** Booting Zephyr OS build v00.01.05 *** Hello, welcome to yv35 craterlake 2022.25.1 BIC class type(class-1), 1ou present status(0), 2ou present status(0), = board revision(0x1) [init_drive_type] sensor 0x14 post sensor read failed! [init_drive_type] sensor 0x30 post sensor read failed! [init_drive_type] sensor 0x39 post sensor read failed! ipmi_init [set_DC_status] gpio number(15) status(0) [set_post_status] gpio number(1) status(1) uart:~$ [00:00:00.249,000] kcs_aspeed: KCS3: addr=3D0xca2, idr=3D= 0x2c, odr=3D0x38, str=3D0x44 [00:00:00.255,000] spi_nor_multi_dev: [1216][spi1_cs0]SFDP magic = 00000000 invalid [00:00:00.255,000] spi_nor_multi_dev: [1456]SFDP read failed: -22 [00:00:00.249,000] kcs_aspeed: KCS3: addr=3D0xca2, idr=3D0x2c, od= r=3D0x38, str=3D0x44 [00:00:00.255,000] spi_nor_multi_dev: [1216][spi1_cs0]SFDP magic = 00000000 invalid [00:00:00.255,000] spi_nor_multi_dev: [1456]SFDP read failed: -22 uart:~$ BIC Ready Signed-off-by: Peter Delevoryas --- hw/arm/aspeed.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c index a06f7c1b62..75971ef2ca 100644 --- a/hw/arm/aspeed.c +++ b/hw/arm/aspeed.c @@ -1429,6 +1429,50 @@ static void aspeed_minibmc_machine_ast1030_evb_class= _init(ObjectClass *oc, amc->macs_mask =3D 0; } =20 +static void oby35_cl_i2c_init(AspeedMachineState *bmc) +{ + AspeedSoCState *soc =3D &bmc->soc; + I2CBus *i2c[14]; + I2CBus *ssd[8]; + int i; + + for (i =3D 0; i < 14; i++) { + i2c[i] =3D aspeed_i2c_get_bus(&soc->i2c, i); + } + get_pca9548_channels(i2c[1], 0x71, ssd); + + i2c_slave_create_simple(i2c[0], "fby35-sb-cpld", 0x21); + i2c_slave_create_simple(i2c[1], "tmp105", 0x48); + i2c_slave_create_simple(i2c[1], "tmp105", 0x49); + i2c_slave_create_simple(i2c[1], "tmp105", 0x4a); + i2c_slave_create_simple(i2c[1], "adm1272", 0x40); + i2c_slave_create_simple(i2c[1], "tmp421", 0x4c); + i2c_slave_create_simple(i2c[2], "intel-me", 0x16); + i2c_slave_create_simple(i2c[4], "isl69259", 0x76); + i2c_slave_create_simple(i2c[4], "isl69259", 0x62); + i2c_slave_create_simple(i2c[4], "isl69259", 0x60); + + for (int i =3D 0; i < 8; i++) { + i2c_slave_create_simple(ssd[i], "tmp105", 0x6a); + } + + /* + * FIXME: This should actually be the BMC, but both the ME and the BMC + * are IPMB endpoints, and the current ME implementation is generic + * enough to respond normally to some things. + */ + i2c_slave_create_simple(i2c[6], "intel-me", 0x10); +} + +static void aspeed_machine_oby35_cl_class_init(ObjectClass *oc, void *data) +{ + MachineClass *mc =3D MACHINE_CLASS(oc); + AspeedMachineClass *amc =3D ASPEED_MACHINE_CLASS(oc); + + mc->desc =3D "Meta Platforms fby35 CraterLake BIC (Cortex-M4)"; + amc->i2c_init =3D oby35_cl_i2c_init; +} + static const TypeInfo aspeed_machine_types[] =3D { { .name =3D MACHINE_TYPE_NAME("palmetto-bmc"), @@ -1494,6 +1538,10 @@ static const TypeInfo aspeed_machine_types[] =3D { .name =3D MACHINE_TYPE_NAME("ast1030-evb"), .parent =3D TYPE_ASPEED_MACHINE, .class_init =3D aspeed_minibmc_machine_ast1030_evb_class_init, + }, { + .name =3D MACHINE_TYPE_NAME("oby35-cl"), + .parent =3D MACHINE_TYPE_NAME("ast1030-evb"), + .class_init =3D aspeed_machine_oby35_cl_class_init, }, { .name =3D TYPE_ASPEED_MACHINE, .parent =3D TYPE_MACHINE, --=20 2.30.2