From patchwork Wed Apr 29 20:19:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 283767 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1828C83007 for ; Wed, 29 Apr 2020 20:38:36 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8D81D206D9 for ; Wed, 29 Apr 2020 20:38:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="mxt4Lsa7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8D81D206D9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=wdc.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:39696 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTtTX-0002nm-Ml for qemu-devel@archiver.kernel.org; Wed, 29 Apr 2020 16:38:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53802) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTtOj-0007sY-2w for qemu-devel@nongnu.org; Wed, 29 Apr 2020 16:37:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jTtO3-00060Z-KU for qemu-devel@nongnu.org; Wed, 29 Apr 2020 16:33:36 -0400 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:7545) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jTtJz-00065g-0R; Wed, 29 Apr 2020 16:28:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1588192122; x=1619728122; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Xc2HQz6O5RjSlw99rYqvdA4/cNZgeA5W0cIUaqMOKPk=; b=mxt4Lsa7vFG1izcTzqB8PdJLwA7FdwzvcNE9Id4KtzU1AAjGRQVhKHFk Ec3ofYHvP4xfVt1ns1efXDikAOira+dnnoDQ71LoTDFtWTH1s24H0tXTs NdQHq54yhNH9Gg7Kwocbl1+K+fM5PnXJ5fsMsWI4TPuVr0xXyUmqHorgG z/tAjPHXQ0XE+7mR77awM99A7Z4zuohON8k+yMRzG/dhWoGTz9fEok4Pt afrqqBR+6L9vaGLGA+fSrC+EmM6QdUAGpe2r2szv6Ru3/ZuwsCOdcZKOW bKzhIsTFZXG2rnzXpMcLGVwozeHJIpO7leib60x8W6SHKWGlX1s/GpIVg A==; IronPort-SDR: sn1OlBLTXEzHxB5o+lRfZjlw9sqOCi632DUimphyfWuZX6+2Ez7oYO5qW5yk6FvP5/HtmtHhwk 7tZiFjyoQXs9QyuV0yQT5v+wzkjII1wGhp0KI7d8ZVNsMs2DH/epmCB6YFyGuoOclop3Hf7+s+ YSwuFFpz0NbDvulZO1hL9PAoaJwcRN6SKGfx2AmOlnCKm2s3MI8QIuwNsH5y9r7Rh0ZwQj0C7q iPCVkvoRyJvI0g3CxnmdqAkl/Bj91a7MBZ7VX/XX/QPqNjsxO7dYgLwTLd24b7vDxo1p+3JDrj AuE= X-IronPort-AV: E=Sophos;i="5.73,333,1583164800"; d="scan'208";a="136507033" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 30 Apr 2020 04:28:38 +0800 IronPort-SDR: toGsanGXqjnwkB5s/kFbSnJuLDjV+ETwDSsycaPkfKQO+dHx/AVfBeWMkMa/sTUkuIZU/UKHZi GP9LQt7k5Lhao1ypr45q7kNjxL3EErpWY= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2020 13:18:42 -0700 IronPort-SDR: p+xBYG0V2x0r7UL7YqejYEwL0XAu726qpR8mw5NITv8vpGPKdV4plyk33ALfgsFtlqbiaV8XR7 QBLBvSrCccbg== WDCIronportException: Internal Received: from usa004631.ad.shared (HELO risc6-mainframe.hgst.com) ([10.86.56.145]) by uls-op-cesaip01.wdc.com with ESMTP; 29 Apr 2020 13:28:38 -0700 From: Alistair Francis To: peter.maydell@linaro.org Subject: [PULL v2 03/14] riscv/sifive_u: Add a serial property to the sifive_u machine Date: Wed, 29 Apr 2020 13:19:55 -0700 Message-Id: <20200429202006.775322-4-alistair.francis@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200429202006.775322-1-alistair.francis@wdc.com> References: <20200429202006.775322-1-alistair.francis@wdc.com> MIME-Version: 1.0 Received-SPF: pass client-ip=216.71.154.42; envelope-from=prvs=381fbd49e=alistair.francis@wdc.com; helo=esa4.hgst.iphmx.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/29 16:28:37 X-ACL-Warn: Detected OS = FreeBSD 9.x or newer [fuzzy] X-Received-From: 216.71.154.42 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alistair Francis , palmerdabbelt@google.com, qemu-riscv@nongnu.org, qemu-devel@nongnu.org, Bin Meng Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Bin Meng At present the board serial number is hard-coded to 1, and passed to OTP model during initialization. Firmware (FSBL, U-Boot) uses the serial number to generate a unique MAC address for the on-chip ethernet controller. When multiple QEMU 'sifive_u' instances are created and connected to the same subnet, they all have the same MAC address hence it creates a unusable network. A new "serial" property is introduced to specify the board serial number. When not given, the default serial number 1 is used. Signed-off-by: Bin Meng Reviewed-by: Palmer Dabbelt Reviewed-by: Alistair Francis Message-Id: <1573916930-19068-1-git-send-email-bmeng.cn@gmail.com> [ Changed by AF: - Use the SoC's serial property to pass the info to the SoC - Fixup commit title - Rebase on file restructuring ] Signed-off-by: Alistair Francis --- hw/riscv/sifive_u.c | 20 ++++++++++++++++++++ include/hw/riscv/sifive_u.h | 1 + 2 files changed, 21 insertions(+) diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c index 6e659e986f..8d0ee8b9c4 100644 --- a/hw/riscv/sifive_u.c +++ b/hw/riscv/sifive_u.c @@ -34,6 +34,7 @@ #include "qemu/log.h" #include "qemu/error-report.h" #include "qapi/error.h" +#include "qapi/visitor.h" #include "hw/boards.h" #include "hw/loader.h" #include "hw/sysbus.h" @@ -326,6 +327,8 @@ static void sifive_u_machine_init(MachineState *machine) object_initialize_child(OBJECT(machine), "soc", &s->soc, sizeof(s->soc), TYPE_RISCV_U_SOC, &error_abort, NULL); + object_property_set_uint(OBJECT(&s->soc), s->serial, "serial", + &error_abort); object_property_set_bool(OBJECT(&s->soc), true, "realized", &error_abort); @@ -417,6 +420,18 @@ static void sifive_u_machine_set_start_in_flash(Object *obj, bool value, Error * s->start_in_flash = value; } +static void sifive_u_machine_get_serial(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + visit_type_uint32(v, name, (uint32_t *)opaque, errp); +} + +static void sifive_u_machine_set_serial(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + visit_type_uint32(v, name, (uint32_t *)opaque, errp); +} + static void sifive_u_machine_instance_init(Object *obj) { SiFiveUState *s = RISCV_U_MACHINE(obj); @@ -428,6 +443,11 @@ static void sifive_u_machine_instance_init(Object *obj) "Set on to tell QEMU's ROM to jump to " "flash. Otherwise QEMU will jump to DRAM", NULL); + + s->serial = OTP_SERIAL; + object_property_add(obj, "serial", "uint32", sifive_u_machine_get_serial, + sifive_u_machine_set_serial, NULL, &s->serial, NULL); + object_property_set_description(obj, "serial", "Board serial number", NULL); } static void sifive_u_machine_class_init(ObjectClass *oc, void *data) diff --git a/include/hw/riscv/sifive_u.h b/include/hw/riscv/sifive_u.h index a2baa1de5f..16c297ec5f 100644 --- a/include/hw/riscv/sifive_u.h +++ b/include/hw/riscv/sifive_u.h @@ -61,6 +61,7 @@ typedef struct SiFiveUState { int fdt_size; bool start_in_flash; + uint32_t serial; } SiFiveUState; enum {