From nobody Mon May 13 15:12:46 2024 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1710833698; cv=none; d=zohomail.com; s=zohoarc; b=g40naXPcDbErplOctUEtxi7q8CoqWGXuucASOVNKRySCg00kdLKlIahB8AAjtOMA0f+5bPpZ1yrVI8sNNU/+9i37SOCXEvgVIAgm3jA6h3mWtWHFOJ2xDpSFrNFuWK9Auj/f0yxehNuQkOTw6YAlSeDyMNkVVhQavxddibzz+yA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710833698; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=gw7AqvkdEkFkQaEkj3AAmMlWcj6KLK6J/UQxKNb7WNA=; b=KJ3IiTUmqVHQn34l0cQPXy7H0NYbLRd8qNjX8xpCNBxwLWsFPdSX8ySmi+OQvL1XDI6fwti7nS5OFfFi8f+uldaiSIp0EvPAfcg53nZgdEve/Giq7DgxEie8FEIpqiUGeJt+vOZ/u/NZORkM5Qg2Q1MtDPFjmNMAF0mBBenfR6U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1710833698029865.4690859783298; Tue, 19 Mar 2024 00:34:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rmTz3-0003un-Ah; Tue, 19 Mar 2024 03:34:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rmTyu-0003tY-Ci for qemu-devel@nongnu.org; Tue, 19 Mar 2024 03:33:59 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rmTyr-0000Z6-Pi for qemu-devel@nongnu.org; Tue, 19 Mar 2024 03:33:55 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-390-GrCjKjE-MnyQSfhC_DaTqg-1; Tue, 19 Mar 2024 03:33:47 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 69706101A523; Tue, 19 Mar 2024 07:33:46 +0000 (UTC) Received: from corto.redhat.com (unknown [10.39.192.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id D98D040C6DB3; Tue, 19 Mar 2024 07:33:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710833633; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=gw7AqvkdEkFkQaEkj3AAmMlWcj6KLK6J/UQxKNb7WNA=; b=d9lYns++6tP4p8vH3lIsEaxGFb0IWqI3dFiprM7n6LNbtrKgBXQp1cYnxbL8V24SYOglhF BTB90wPRr2SibX0eurQg40SOjDwA+eKIB6Gpesymi3hORgWIP2JnUWoVbfzmZ9f7WuPVAt lMbwGaJhIkZPOcQx86Z8iu2Bs4tcctw= X-MC-Unique: GrCjKjE-MnyQSfhC_DaTqg-1 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: Alistair Francis , "Edgar E. Iglesias" , Peter Maydell , Kevin Wolf , Hanna Reitz , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Andrew Jeffery , Joel Stanley , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Cc: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Thomas Huth , qemu-arm@nongnu.org, qemu-devel@nongnu.org, qemu-block@nongnu.org Subject: [PATCH] aspeed/smc: Only wire flash devices at reset Date: Tue, 19 Mar 2024 08:33:20 +0100 Message-ID: <20240319073320.315170-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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=170.10.133.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.374, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1710833698601100001 The Aspeed machines have many Static Memory Controllers (SMC), up to 8, which can only drive flash memory devices. Commit 27a2c66c92ec ("aspeed/smc: Wire CS lines at reset") tried to ease the definitions of these devices by allowing flash devices from the command line to be attached to a SSI bus. For that, the wiring of the CS lines of the Aspeed SMC controller was moved at reset. Two assumptions are made though, first that the device has a SSI_GPIO_CS GPIO line, which is not always the case, and second that it is flash device. Correct this problem by ensuring that the devices attached to the bus are the correct flash type. This fixes a QEMU abort when devices without a CS line, such as the max111x, are passed on the command line. While at it, export TYPE_M25P80 used in the Xilinx Versal Virtual machine. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2228 Fixes: 27a2c66c92ec ("aspeed/smc: Wire CS lines at reset") Reported-by: Thomas Huth Signed-off-by: C=C3=A9dric Le Goater Reviewed-by: Thomas Huth Tested-by: Thomas Huth --- include/hw/block/flash.h | 2 ++ hw/arm/xlnx-versal-virt.c | 3 ++- hw/block/m25p80.c | 1 - hw/ssi/aspeed_smc.c | 9 +++++++++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/include/hw/block/flash.h b/include/hw/block/flash.h index de93756cbe8f..2b5ccd92f463 100644 --- a/include/hw/block/flash.h +++ b/include/hw/block/flash.h @@ -78,6 +78,8 @@ extern const VMStateDescription vmstate_ecc_state; =20 /* m25p80.c */ =20 +#define TYPE_M25P80 "m25p80-generic" + BlockBackend *m25p80_get_blk(DeviceState *dev); =20 #endif diff --git a/hw/arm/xlnx-versal-virt.c b/hw/arm/xlnx-versal-virt.c index bfaed1aebfc6..962f98fee2ea 100644 --- a/hw/arm/xlnx-versal-virt.c +++ b/hw/arm/xlnx-versal-virt.c @@ -13,6 +13,7 @@ #include "qemu/error-report.h" #include "qapi/error.h" #include "sysemu/device_tree.h" +#include "hw/block/flash.h" #include "hw/boards.h" #include "hw/sysbus.h" #include "hw/arm/fdt.h" @@ -759,7 +760,7 @@ static void versal_virt_init(MachineState *machine) flash_klass =3D object_class_by_name(s->ospi_model); if (!flash_klass || object_class_is_abstract(flash_klass) || - !object_class_dynamic_cast(flash_klass, "m25p80-generic"))= { + !object_class_dynamic_cast(flash_klass, TYPE_M25P80)) { error_setg(&error_fatal, "'%s' is either abstract or" " not a subtype of m25p80", s->ospi_model); return; diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c index 08a00a6d9b89..8dec134832a1 100644 --- a/hw/block/m25p80.c +++ b/hw/block/m25p80.c @@ -515,7 +515,6 @@ struct M25P80Class { FlashPartInfo *pi; }; =20 -#define TYPE_M25P80 "m25p80-generic" OBJECT_DECLARE_TYPE(Flash, M25P80Class, M25P80) =20 static inline Manufacturer get_man(Flash *s) diff --git a/hw/ssi/aspeed_smc.c b/hw/ssi/aspeed_smc.c index 0dff1d910778..de57e690e124 100644 --- a/hw/ssi/aspeed_smc.c +++ b/hw/ssi/aspeed_smc.c @@ -23,6 +23,7 @@ */ =20 #include "qemu/osdep.h" +#include "hw/block/flash.h" #include "hw/sysbus.h" #include "migration/vmstate.h" #include "qemu/log.h" @@ -711,6 +712,14 @@ static void aspeed_smc_reset(DeviceState *d) for (i =3D 0; i < asc->cs_num_max; i++) { DeviceState *dev =3D ssi_get_cs(s->spi, i); if (dev) { + Object *o =3D OBJECT(dev); + + if (!object_dynamic_cast(o, TYPE_M25P80)) { + warn_report("Aspeed SMC %s.%d : Invalid %s device type", + BUS(s->spi)->name, i, object_get_typename(o)); + continue; + } + qemu_irq cs_line =3D qdev_get_gpio_in_named(dev, SSI_GPIO_CS, = 0); qdev_connect_gpio_out_named(DEVICE(s), "cs", i, cs_line); } --=20 2.44.0