From nobody Thu May 2 23:00:56 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 ARC-Seal: i=1; a=rsa-sha256; t=1667745665; cv=none; d=zohomail.com; s=zohoarc; b=Ps1s+eBPOVJNFMqKLs9zjBT2DWcYDrCVDdhRjgPAGq3lPYpqM1IZjNiAla3TLIAHU5TAM9C+OFGh285NekgoiVYZ6u6mw0ouemtgTatjUifzvY16/4K5E6ZRAE7iQMKWSNlqqGPSg02L39+O2XnSDTdRM6LKHmCuxc3sBqCmW+g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667745665; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=0fB0udMZsQvg+8bmyp7ro9M87xUAvgONQV5uxUWqipI=; b=mbafMox1o6o9+TalvAjaSHBu5GyZDcD7TXHyRtHzHa7eIyuzSQi0XwBx+f0qnNzHrhegjD4peiTOdcUTL0ExPw45qbGg0IeSxtauJvL28IumUjRl99Mt1gL8cWfAHJX9jA9X0ZFNVY1GBcBBFn1yfxp1Qx8Np58kkOUAtBTRcgE= 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1667745665399479.7964921881679; Sun, 6 Nov 2022 06:41:05 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1orgo2-0004FL-JT; Sun, 06 Nov 2022 09:39:26 -0500 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 1orgo0-0004Eh-Ul for qemu-devel@nongnu.org; Sun, 06 Nov 2022 09:39:25 -0500 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1orgnz-0001oc-4L for qemu-devel@nongnu.org; Sun, 06 Nov 2022 09:39:24 -0500 Received: by mail-pj1-x1033.google.com with SMTP id c15-20020a17090a1d0f00b0021365864446so8219599pjd.4 for ; Sun, 06 Nov 2022 06:39:22 -0800 (PST) Received: from localhost.localdomain ([49.206.12.236]) by smtp.gmail.com with ESMTPSA id j17-20020a170902da9100b001811a197797sm3209279plx.194.2022.11.06.06.39.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Nov 2022 06:39:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=0fB0udMZsQvg+8bmyp7ro9M87xUAvgONQV5uxUWqipI=; b=ggDIFH98FXDYmmiwkLS0iwWF9t7b7GVvHrlwecxRF2F053snlg9f9BM67ed2qr++J8 6p52T30J7KJwpqNkobym2Re7QqKcq6sapzH5fkgm4S7ISlnEwVbzyTfIgnJPACn38bEo QHOrqdf0YZSHaj8nm7iVRVf/8wiOZh+VOBZ568aC9ywLwFmPHyFjl5s9oriXjrlVWetr CEWM1YQAUyi2sTjZVHUlrdyGcYhIM8GSpyOL6U3SnmoXg6PIGruQeN5nw5MYQPeAWxuV zwg7PBV8rm9eeau4DzANqNGDyu0rxppsPRAtbcvI+UBPAAtnbALgRl+EgAno+fyaVmne kGRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=0fB0udMZsQvg+8bmyp7ro9M87xUAvgONQV5uxUWqipI=; b=XUbFhVuxpNVNDMub6INNiubgwsOHXotxwtQJj5hqAllC5Cqt/k0EUGhjUPo9BpwFEd DBNuvV43WhewIw4oDsEmveCs+HusX8HIZJoespmfA1XWzqs0ZEyLKWTqXskvBH+ndbeB YcdRYpFbnRlYkMEdxe+ofqBwimF4HIETpgXc/WQQEogv5dNE1+Y1YwbJz3sWdI+KbwJf JMZLJ2uqx3fzLcH+Yv1K/XtiRoHK2ATWnbHlxiMNYXbg23CDSv5wjQlVgWxowNy8CiBa iUrJh0JzaF4HzyjcSEWvEoLwZQJx7w3OIAsKJiZQJtA9/FyqzXhF6BOWf0vSJa/UheYk AYUQ== X-Gm-Message-State: ACrzQf0qdiAOlBJJeFDFsZ3CU1RJcK/xj/QlhTnI6Sj4jzd+Ooq3SP40 GRHQYujqPRnVPlNa9GfKPAvQsw== X-Google-Smtp-Source: AMsMyM6V8hLxqW4YpWe4tjoHcKpzTHKqP74L/YQAUFEn42140SN0bgY9R4Hc2Pt8Vs86BMEhLmuFsg== X-Received: by 2002:a17:90b:19ca:b0:212:d2c4:83ac with SMTP id nm10-20020a17090b19ca00b00212d2c483acmr63709269pjb.166.1667745560751; Sun, 06 Nov 2022 06:39:20 -0800 (PST) From: Sunil V L To: Palmer Dabbelt , Alistair Francis , Bin Meng , Gerd Hoffmann Cc: qemu-riscv@nongnu.org, qemu-devel@nongnu.org, Sunil V L Subject: [PATCH] hw/riscv: virt: Remove size restriction for pflash Date: Sun, 6 Nov 2022 20:09:00 +0530 Message-Id: <20221106143900.2229449-1-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.38.0 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::1033; envelope-from=sunilvl@ventanamicro.com; helo=mail-pj1-x1033.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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @ventanamicro.com) X-ZM-MESSAGEID: 1667745666287100001 Content-Type: text/plain; charset="utf-8" The pflash implementation currently assumes fixed size of the backend storage. Due to this, the backend storage file needs to be exactly of size 32M. Otherwise, there will be an error like below. "device requires 33554432 bytes, block backend provides 3145728 bytes" Fix this issue by using the actual size of the backing store. Signed-off-by: Sunil V L Reviewed-by: Andrew Jones --- hw/riscv/virt.c | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c index a5bc7353b4..aad175fa31 100644 --- a/hw/riscv/virt.c +++ b/hw/riscv/virt.c @@ -49,6 +49,7 @@ #include "hw/pci/pci.h" #include "hw/pci-host/gpex.h" #include "hw/display/ramfb.h" +#include "sysemu/block-backend.h" =20 /* * The virt machine physical address space used by some of the devices @@ -144,10 +145,17 @@ static void virt_flash_map1(PFlashCFI01 *flash, MemoryRegion *sysmem) { DeviceState *dev =3D DEVICE(flash); + BlockBackend *blk; + hwaddr real_size; =20 - assert(QEMU_IS_ALIGNED(size, VIRT_FLASH_SECTOR_SIZE)); - assert(size / VIRT_FLASH_SECTOR_SIZE <=3D UINT32_MAX); - qdev_prop_set_uint32(dev, "num-blocks", size / VIRT_FLASH_SECTOR_SIZE); + blk =3D pflash_cfi01_get_blk(flash); + + real_size =3D blk ? blk_getlength(blk): size; + + assert(real_size); + assert(QEMU_IS_ALIGNED(real_size, VIRT_FLASH_SECTOR_SIZE)); + assert(real_size / VIRT_FLASH_SECTOR_SIZE <=3D UINT32_MAX); + qdev_prop_set_uint32(dev, "num-blocks", real_size / VIRT_FLASH_SECTOR_= SIZE); sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); =20 memory_region_add_subregion(sysmem, base, @@ -971,15 +979,24 @@ static void create_fdt_flash(RISCVVirtState *s, const= MemMapEntry *memmap) { char *name; MachineState *mc =3D MACHINE(s); - hwaddr flashsize =3D virt_memmap[VIRT_FLASH].size / 2; - hwaddr flashbase =3D virt_memmap[VIRT_FLASH].base; + MemoryRegion *flash_mem; + hwaddr flashsize[2]; + hwaddr flashbase[2]; + + flash_mem =3D pflash_cfi01_get_memory(s->flash[0]); + flashbase[0] =3D flash_mem->addr; + flashsize[0] =3D flash_mem->size; + + flash_mem =3D pflash_cfi01_get_memory(s->flash[1]); + flashbase[1] =3D flash_mem->addr; + flashsize[1] =3D flash_mem->size; =20 - name =3D g_strdup_printf("/flash@%" PRIx64, flashbase); + name =3D g_strdup_printf("/flash@%" PRIx64, flashbase[0]); qemu_fdt_add_subnode(mc->fdt, name); qemu_fdt_setprop_string(mc->fdt, name, "compatible", "cfi-flash"); qemu_fdt_setprop_sized_cells(mc->fdt, name, "reg", - 2, flashbase, 2, flashsize, - 2, flashbase + flashsize, 2, flashsize); + 2, flashbase[0], 2, flashsize[0], + 2, flashbase[1], 2, flashsize[1]); qemu_fdt_setprop_cell(mc->fdt, name, "bank-width", 4); g_free(name); } --=20 2.38.0