From nobody Sun May 19 05:51:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=1598314712; cv=none; d=zohomail.com; s=zohoarc; b=WPdXFKCkiVXIi9apFwNFm6WVBuZBLGGeqEfszI8/kscpNMSX/y5O2c/88zOG2hY8B/7SDSNSRLme0Vfzv4t+E07enPJSyrRcWPJZ2m1lpjQFfCBAa1xinAsK5mg7Wi4R+jlcBZBWML9L/HwSIFJgsNLUXkbl6tJmmaeyki0im9U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598314712; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=K4419BP+6vI7tyG+lJ5WOiKHB0WZfwY2gV6M8yysefs=; b=DL5uktzMhBiSQ9vZA+uOMlS75AskitaaQE8Xtf2AiTWEwtb48dFKAYCvz8hiE3b+o2Yd33tNekackDC/Mmx6jS51CMfacvv8ujSe6MI6waI3Q6XHovj8KZR1R2ZmtP55zR1WSi3U7g0OeSmQbxfNiTsGzb7z5B63TIs4Sd9Eyu4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1598314712807251.89399254434704; Mon, 24 Aug 2020 17:18:32 -0700 (PDT) Received: from localhost ([::1]:55700 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kAMfX-0005Zw-FB for importer@patchew.org; Mon, 24 Aug 2020 20:18:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45100) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3k1hEXwsKClY5G86BB2AC2B4CC492.0CAE2AI-12J29BCB4BI.CF4@flex--hskinnemoen.bounces.google.com>) id 1kAMeX-0003lx-7r for qemu-devel@nongnu.org; Mon, 24 Aug 2020 20:17:29 -0400 Received: from mail-pf1-x44a.google.com ([2607:f8b0:4864:20::44a]:42107) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3k1hEXwsKClY5G86BB2AC2B4CC492.0CAE2AI-12J29BCB4BI.CF4@flex--hskinnemoen.bounces.google.com>) id 1kAMeU-00066T-4A for qemu-devel@nongnu.org; Mon, 24 Aug 2020 20:17:28 -0400 Received: by mail-pf1-x44a.google.com with SMTP id b142so7152150pfb.9 for ; Mon, 24 Aug 2020 17:17:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc:content-transfer-encoding; bh=K4419BP+6vI7tyG+lJ5WOiKHB0WZfwY2gV6M8yysefs=; b=k6rmbR4Uw3IRUMsOyoLDzJ/QJ32LYpe4Lps7XT7gNWHfsRDQ4hXd7MBPZegAD2VODs ZwLBEs2JqdXzJju+nSY93rqrjdF29ehXAr1U0RUy+SZ/RsAWYBg4yK43alf1x2HBnieD f6gXh0zazg5gVnu6XaqflBbDzxw42dy+0UPJOc665IRsQ91fEcVncLeimGXeL9DrlvmE OU4b7nxxEKG9+8hTh58U6hZTN7aORL25DdfyYSph7rGXudNQ4nPYZN/VIwm0r9LqbLRv vrKbSspwXOknWVLFpvD7m2dfQywXyoEpdn1fSrF3C/YEDgXmY/sCcOfTBNFONyDkZKBD kECA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=K4419BP+6vI7tyG+lJ5WOiKHB0WZfwY2gV6M8yysefs=; b=B/e0rmosEVwhiutqOtP1+IYGJSz6MEMJ6j8G5ZEx8ifAmWmi3CHLm66uu+NdGcUCfz oGRaHVUaQ5P32ZaqtADZ1EiraeHx3+6mtkVuR+/p8Ufm4woeCOp4QsZ6kqumhkortdJQ 1NON040MObqpEzp9IhqNgPY1ZD5nCwfUZ8e9nJRAIhqn2+CuAVMe4mKcfq1kBoChHMZB Ww9KBUDAxg4FA9U3u5t/vh22zQMJfHyC+boGPquGfv3I3B3l8JGTi9LXo1GZfPhDEqAi 4MPhY+1A8lcbOvr2nlECft1rYFPC/B3e1jj6CJKmKiGK2X+jHnb3emTpAYH84KTRis29 g8Nw== X-Gm-Message-State: AOAM531GbgTXDgWnURORsQHHLf1ekrBqqZ8VUkZs03NTzNi1CM49qAr6 E4k0th72/3RskdHOGmJMsw9VbfZTtE1Cx0fJVA== X-Google-Smtp-Source: ABdhPJyw4E8kL3lCCFRDN3pSLO8AL0+xhLrjWGnM2PYkApn7bYpQvmTs+2G/CYb3ViZUW9ozhQ3k4/1wz7exHi2V1Q== X-Received: from skybert.c.googlers.com ([fda3:e722:ac3:10:24:72f4:c0a8:3107]) (user=hskinnemoen job=sendgmr) by 2002:a17:90a:8c8f:: with SMTP id b15mr1428358pjo.84.1598314643795; Mon, 24 Aug 2020 17:17:23 -0700 (PDT) Date: Mon, 24 Aug 2020 17:16:58 -0700 In-Reply-To: <20200825001711.1340443-1-hskinnemoen@google.com> Message-Id: <20200825001711.1340443-2-hskinnemoen@google.com> Mime-Version: 1.0 References: <20200825001711.1340443-1-hskinnemoen@google.com> X-Mailer: git-send-email 2.28.0.297.g1956fa8f8d-goog Subject: [PATCH v8 01/14] hw/misc: Add NPCM7xx System Global Control Registers device model To: peter.maydell@linaro.org, f4bug@amsat.org Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, Avi.Fishman@nuvoton.com, kfting@nuvoton.com, Havard Skinnemoen , Joel Stanley , "=?UTF-8?q?C=C3=A9dric=20Le=20Goater?=" 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::44a; envelope-from=3k1hEXwsKClY5G86BB2AC2B4CC492.0CAE2AI-12J29BCB4BI.CF4@flex--hskinnemoen.bounces.google.com; helo=mail-pf1-x44a.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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" Reply-to: Havard Skinnemoen From: Havard Skinnemoen via X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Implement a device model for the System Global Control Registers in the NPCM730 and NPCM750 BMC SoCs. This is primarily used to enable SMP boot (the boot ROM spins reading the SCRPAD register) and DDR memory initialization; other registers are best effort for now. The reset values of the MDLR and PWRON registers are determined by the SoC variant (730 vs 750) and board straps respectively. Reviewed-by: Joel Stanley Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Havard Skinnemoen Tested-by: Alexander Bulekov Tested-by: Philippe Mathieu-Daud=C3=A9 --- include/hw/misc/npcm7xx_gcr.h | 43 ++++++ hw/misc/npcm7xx_gcr.c | 269 ++++++++++++++++++++++++++++++++++ MAINTAINERS | 8 + hw/arm/Kconfig | 3 + hw/misc/meson.build | 3 + hw/misc/trace-events | 4 + 6 files changed, 330 insertions(+) create mode 100644 include/hw/misc/npcm7xx_gcr.h create mode 100644 hw/misc/npcm7xx_gcr.c diff --git a/include/hw/misc/npcm7xx_gcr.h b/include/hw/misc/npcm7xx_gcr.h new file mode 100644 index 0000000000..13109d9d32 --- /dev/null +++ b/include/hw/misc/npcm7xx_gcr.h @@ -0,0 +1,43 @@ +/* + * Nuvoton NPCM7xx System Global Control Registers. + * + * Copyright 2020 Google LLC + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WIT= HOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ +#ifndef NPCM7XX_GCR_H +#define NPCM7XX_GCR_H + +#include "exec/memory.h" +#include "hw/sysbus.h" + +/* + * Number of registers in our device state structure. Don't change this wi= thout + * incrementing the version_id in the vmstate. + */ +#define NPCM7XX_GCR_NR_REGS (0x148 / sizeof(uint32_t)) + +typedef struct NPCM7xxGCRState { + SysBusDevice parent; + + MemoryRegion iomem; + + uint32_t regs[NPCM7XX_GCR_NR_REGS]; + + uint32_t reset_pwron; + uint32_t reset_mdlr; + uint32_t reset_intcr3; +} NPCM7xxGCRState; + +#define TYPE_NPCM7XX_GCR "npcm7xx-gcr" +#define NPCM7XX_GCR(obj) OBJECT_CHECK(NPCM7xxGCRState, (obj), TYPE_NPCM7XX= _GCR) + +#endif /* NPCM7XX_GCR_H */ diff --git a/hw/misc/npcm7xx_gcr.c b/hw/misc/npcm7xx_gcr.c new file mode 100644 index 0000000000..745f690809 --- /dev/null +++ b/hw/misc/npcm7xx_gcr.c @@ -0,0 +1,269 @@ +/* + * Nuvoton NPCM7xx System Global Control Registers. + * + * Copyright 2020 Google LLC + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WIT= HOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#include "qemu/osdep.h" + +#include "hw/misc/npcm7xx_gcr.h" +#include "hw/qdev-properties.h" +#include "migration/vmstate.h" +#include "qapi/error.h" +#include "qemu/cutils.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qemu/units.h" + +#include "trace.h" + +#define NPCM7XX_GCR_MIN_DRAM_SIZE (128 * MiB) +#define NPCM7XX_GCR_MAX_DRAM_SIZE (2 * GiB) + +enum NPCM7xxGCRRegisters { + NPCM7XX_GCR_PDID, + NPCM7XX_GCR_PWRON, + NPCM7XX_GCR_MFSEL1 =3D 0x0c / sizeof(uint32_t), + NPCM7XX_GCR_MFSEL2, + NPCM7XX_GCR_MISCPE, + NPCM7XX_GCR_SPSWC =3D 0x038 / sizeof(uint32_t), + NPCM7XX_GCR_INTCR, + NPCM7XX_GCR_INTSR, + NPCM7XX_GCR_HIFCR =3D 0x050 / sizeof(uint32_t), + NPCM7XX_GCR_INTCR2 =3D 0x060 / sizeof(uint32_t), + NPCM7XX_GCR_MFSEL3, + NPCM7XX_GCR_SRCNT, + NPCM7XX_GCR_RESSR, + NPCM7XX_GCR_RLOCKR1, + NPCM7XX_GCR_FLOCKR1, + NPCM7XX_GCR_DSCNT, + NPCM7XX_GCR_MDLR, + NPCM7XX_GCR_SCRPAD3, + NPCM7XX_GCR_SCRPAD2, + NPCM7XX_GCR_DAVCLVLR =3D 0x098 / sizeof(uint32_t), + NPCM7XX_GCR_INTCR3, + NPCM7XX_GCR_VSINTR =3D 0x0ac / sizeof(uint32_t), + NPCM7XX_GCR_MFSEL4, + NPCM7XX_GCR_CPBPNTR =3D 0x0c4 / sizeof(uint32_t), + NPCM7XX_GCR_CPCTL =3D 0x0d0 / sizeof(uint32_t), + NPCM7XX_GCR_CP2BST, + NPCM7XX_GCR_B2CPNT, + NPCM7XX_GCR_CPPCTL, + NPCM7XX_GCR_I2CSEGSEL, + NPCM7XX_GCR_I2CSEGCTL, + NPCM7XX_GCR_VSRCR, + NPCM7XX_GCR_MLOCKR, + NPCM7XX_GCR_SCRPAD =3D 0x013c / sizeof(uint32_t), + NPCM7XX_GCR_USB1PHYCTL, + NPCM7XX_GCR_USB2PHYCTL, + NPCM7XX_GCR_REGS_END, +}; + +static const uint32_t cold_reset_values[NPCM7XX_GCR_NR_REGS] =3D { + [NPCM7XX_GCR_PDID] =3D 0x04a92750, /* Poleg A1 */ + [NPCM7XX_GCR_MISCPE] =3D 0x0000ffff, + [NPCM7XX_GCR_SPSWC] =3D 0x00000003, + [NPCM7XX_GCR_INTCR] =3D 0x0000035e, + [NPCM7XX_GCR_HIFCR] =3D 0x0000004e, + [NPCM7XX_GCR_INTCR2] =3D (1U << 19), /* DDR initialized */ + [NPCM7XX_GCR_RESSR] =3D 0x80000000, + [NPCM7XX_GCR_DSCNT] =3D 0x000000c0, + [NPCM7XX_GCR_DAVCLVLR] =3D 0x5a00f3cf, + [NPCM7XX_GCR_SCRPAD] =3D 0x00000008, + [NPCM7XX_GCR_USB1PHYCTL] =3D 0x034730e4, + [NPCM7XX_GCR_USB2PHYCTL] =3D 0x034730e4, +}; + +static uint64_t npcm7xx_gcr_read(void *opaque, hwaddr offset, unsigned siz= e) +{ + uint32_t reg =3D offset / sizeof(uint32_t); + NPCM7xxGCRState *s =3D opaque; + + if (reg >=3D NPCM7XX_GCR_NR_REGS) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: offset 0x%04" HWADDR_PRIx " out of range\n", + __func__, offset); + return 0; + } + + trace_npcm7xx_gcr_read(offset, s->regs[reg]); + + return s->regs[reg]; +} + +static void npcm7xx_gcr_write(void *opaque, hwaddr offset, + uint64_t v, unsigned size) +{ + uint32_t reg =3D offset / sizeof(uint32_t); + NPCM7xxGCRState *s =3D opaque; + uint32_t value =3D v; + + trace_npcm7xx_gcr_write(offset, value); + + if (reg >=3D NPCM7XX_GCR_NR_REGS) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: offset 0x%04" HWADDR_PRIx " out of range\n", + __func__, offset); + return; + } + + switch (reg) { + case NPCM7XX_GCR_PDID: + case NPCM7XX_GCR_PWRON: + case NPCM7XX_GCR_INTSR: + qemu_log_mask(LOG_GUEST_ERROR, + "%s: register @ 0x%04" HWADDR_PRIx " is read-only\n", + __func__, offset); + return; + + case NPCM7XX_GCR_RESSR: + case NPCM7XX_GCR_CP2BST: + /* Write 1 to clear */ + value =3D s->regs[reg] & ~value; + break; + + case NPCM7XX_GCR_RLOCKR1: + case NPCM7XX_GCR_MDLR: + /* Write 1 to set */ + value |=3D s->regs[reg]; + break; + }; + + s->regs[reg] =3D value; +} + +static const struct MemoryRegionOps npcm7xx_gcr_ops =3D { + .read =3D npcm7xx_gcr_read, + .write =3D npcm7xx_gcr_write, + .endianness =3D DEVICE_LITTLE_ENDIAN, + .valid =3D { + .min_access_size =3D 4, + .max_access_size =3D 4, + .unaligned =3D false, + }, +}; + +static void npcm7xx_gcr_enter_reset(Object *obj, ResetType type) +{ + NPCM7xxGCRState *s =3D NPCM7XX_GCR(obj); + + QEMU_BUILD_BUG_ON(sizeof(s->regs) !=3D sizeof(cold_reset_values)); + + switch (type) { + case RESET_TYPE_COLD: + memcpy(s->regs, cold_reset_values, sizeof(s->regs)); + s->regs[NPCM7XX_GCR_PWRON] =3D s->reset_pwron; + s->regs[NPCM7XX_GCR_MDLR] =3D s->reset_mdlr; + s->regs[NPCM7XX_GCR_INTCR3] =3D s->reset_intcr3; + break; + } +} + +static void npcm7xx_gcr_realize(DeviceState *dev, Error **errp) +{ + ERRP_GUARD(); + NPCM7xxGCRState *s =3D NPCM7XX_GCR(dev); + uint64_t dram_size; + Object *obj; + + obj =3D object_property_get_link(OBJECT(dev), "dram-mr", errp); + if (!obj) { + error_prepend(errp, "%s: required dram-mr link not found: ", __fun= c__); + return; + } + dram_size =3D memory_region_size(MEMORY_REGION(obj)); + if (!is_power_of_2(dram_size) || + dram_size < NPCM7XX_GCR_MIN_DRAM_SIZE || + dram_size > NPCM7XX_GCR_MAX_DRAM_SIZE) { + g_autofree char *sz =3D size_to_str(dram_size); + g_autofree char *min_sz =3D size_to_str(NPCM7XX_GCR_MIN_DRAM_SIZE); + g_autofree char *max_sz =3D size_to_str(NPCM7XX_GCR_MAX_DRAM_SIZE); + error_setg(errp, "%s: unsupported DRAM size %s", __func__, sz); + error_append_hint(errp, + "DRAM size must be a power of two between %s and= %s," + " inclusive.\n", min_sz, max_sz); + return; + } + + /* Power-on reset value */ + s->reset_intcr3 =3D 0x00001002; + + /* + * The GMMAP (Graphics Memory Map) field is used by u-boot to detect t= he + * DRAM size, and is normally initialized by the boot block as part of= DRAM + * training. However, since we don't have a complete emulation of the + * memory controller and try to make it look like it has already been + * initialized, the boot block will skip this initialization, and we n= eed + * to make sure this field is set correctly up front. + * + * WARNING: some versions of u-boot only looks at bits 8 and 9, so 2 G= iB of + * DRAM will be interpreted as 128 MiB. + * + * https://github.com/Nuvoton-Israel/u-boot/blob/2aef993bd2aafeb5408db= aad0f3ce099ee40c4aa/board/nuvoton/poleg/poleg.c#L244 + */ + s->reset_intcr3 |=3D ctz64(dram_size / NPCM7XX_GCR_MIN_DRAM_SIZE) << 8; +} + +static void npcm7xx_gcr_init(Object *obj) +{ + NPCM7xxGCRState *s =3D NPCM7XX_GCR(obj); + + memory_region_init_io(&s->iomem, obj, &npcm7xx_gcr_ops, s, + TYPE_NPCM7XX_GCR, 4 * KiB); + sysbus_init_mmio(&s->parent, &s->iomem); +} + +static const VMStateDescription vmstate_npcm7xx_gcr =3D { + .name =3D "npcm7xx-gcr", + .version_id =3D 0, + .minimum_version_id =3D 0, + .fields =3D (VMStateField[]) { + VMSTATE_UINT32_ARRAY(regs, NPCM7xxGCRState, NPCM7XX_GCR_NR_REGS), + VMSTATE_END_OF_LIST(), + }, +}; + +static Property npcm7xx_gcr_properties[] =3D { + DEFINE_PROP_UINT32("disabled-modules", NPCM7xxGCRState, reset_mdlr, 0), + DEFINE_PROP_UINT32("power-on-straps", NPCM7xxGCRState, reset_pwron, 0), + DEFINE_PROP_END_OF_LIST(), +}; + +static void npcm7xx_gcr_class_init(ObjectClass *klass, void *data) +{ + ResettableClass *rc =3D RESETTABLE_CLASS(klass); + DeviceClass *dc =3D DEVICE_CLASS(klass); + + QEMU_BUILD_BUG_ON(NPCM7XX_GCR_REGS_END > NPCM7XX_GCR_NR_REGS); + + dc->desc =3D "NPCM7xx System Global Control Registers"; + dc->realize =3D npcm7xx_gcr_realize; + dc->vmsd =3D &vmstate_npcm7xx_gcr; + rc->phases.enter =3D npcm7xx_gcr_enter_reset; + + device_class_set_props(dc, npcm7xx_gcr_properties); +} + +static const TypeInfo npcm7xx_gcr_info =3D { + .name =3D TYPE_NPCM7XX_GCR, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(NPCM7xxGCRState), + .instance_init =3D npcm7xx_gcr_init, + .class_init =3D npcm7xx_gcr_class_init, +}; + +static void npcm7xx_gcr_register_type(void) +{ + type_register_static(&npcm7xx_gcr_info); +} +type_init(npcm7xx_gcr_register_type); diff --git a/MAINTAINERS b/MAINTAINERS index 5a22c8be42..3f72250630 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -749,6 +749,14 @@ S: Odd Fixes F: hw/arm/musicpal.c F: docs/system/arm/musicpal.rst =20 +Nuvoton NPCM7xx +M: Havard Skinnemoen +M: Tyrone Ting +L: qemu-arm@nongnu.org +S: Supported +F: hw/*/npcm7xx* +F: include/hw/*/npcm7xx* + nSeries M: Andrzej Zaborowski M: Peter Maydell diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig index bc3a423940..4aec9c63f8 100644 --- a/hw/arm/Kconfig +++ b/hw/arm/Kconfig @@ -355,6 +355,9 @@ config XLNX_VERSAL select VIRTIO_MMIO select UNIMP =20 +config NPCM7XX + bool + config FSL_IMX25 bool select IMX diff --git a/hw/misc/meson.build b/hw/misc/meson.build index 84fed0494d..99ffb9f9e8 100644 --- a/hw/misc/meson.build +++ b/hw/misc/meson.build @@ -50,6 +50,9 @@ softmmu_ss.add(when: 'CONFIG_IMX', if_true: files( )) softmmu_ss.add(when: 'CONFIG_MILKYMIST', if_true: files('milkymist-hpdmc.c= ', 'milkymist-pfpu.c')) softmmu_ss.add(when: 'CONFIG_MAINSTONE', if_true: files('mst_fpga.c')) +softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files( + 'npcm7xx_gcr.c', +)) softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files( 'omap_clk.c', 'omap_gpmc.c', diff --git a/hw/misc/trace-events b/hw/misc/trace-events index 066752aa90..dbf90db8ed 100644 --- a/hw/misc/trace-events +++ b/hw/misc/trace-events @@ -111,6 +111,10 @@ mos6522_set_sr_int(void) "set sr_int" mos6522_write(uint64_t addr, uint64_t val) "reg=3D0x%"PRIx64 " val=3D0x%"P= RIx64 mos6522_read(uint64_t addr, unsigned val) "reg=3D0x%"PRIx64 " val=3D0x%x" =20 +# npcm7xx_gcr.c +npcm7xx_gcr_read(uint64_t offset, uint32_t value) " offset: 0x%04" PRIx64 = " value: 0x%08" PRIx32 +npcm7xx_gcr_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 = " value: 0x%08" PRIx32 + # stm32f4xx_syscfg stm32f4xx_syscfg_set_irq(int gpio, int line, int level) "Interupt: GPIO: %= d, Line: %d; Level: %d" stm32f4xx_pulse_exti(int irq) "Pulse EXTI: %d" --=20 2.28.0.297.g1956fa8f8d-goog From nobody Sun May 19 05:51:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=1598314809; cv=none; d=zohomail.com; s=zohoarc; b=iRt71vnp4Dpd451C/EDmv/l2cigOAuAxEr40nPnA5ojxfssaZkJAXiUxkSPiTXL+RGUQ5QBsV2xTUe5C2DOr29dbWXWUKsOOH0dmt0hHjSWwJOz3wAS/KKljLtqh2VfIvq6U6FDBS0w7nmBtc/s1z1p21Hi4MwIfym7vxLkgBF4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598314809; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=m/ayDG00qMRIUpleuYo4aKp7Q1JphS2n6/ujInOccCs=; b=JUE5hHR1G+y0qsV1lDf4MyzmviLr/bZHdXH19AvT+knu466jVXm7CvgxcloVEvvYGmrtGAXpPP1ZGrV/VvqFm4TI7veIfsKlB7cfNcg+Wx7UHjguix2b2/l+vwi4xsg0ThDY1PdEcizAcqicvtt+OATrg3+QFUqD+H0axSTMYTo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1598314809729344.1347001578587; Mon, 24 Aug 2020 17:20:09 -0700 (PDT) Received: from localhost ([::1]:35884 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kAMh6-0000X3-BC for importer@patchew.org; Mon, 24 Aug 2020 20:20:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45130) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3llhEXwsKClk8JB9EE5DF5E7FF7C5.3FDH5DL-45M5CEFE7EL.FI7@flex--hskinnemoen.bounces.google.com>) id 1kAMeZ-0003qQ-6V for qemu-devel@nongnu.org; Mon, 24 Aug 2020 20:17:31 -0400 Received: from mail-pg1-x54a.google.com ([2607:f8b0:4864:20::54a]:37950) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3llhEXwsKClk8JB9EE5DF5E7FF7C5.3FDH5DL-45M5CEFE7EL.FI7@flex--hskinnemoen.bounces.google.com>) id 1kAMeW-00066f-Ql for qemu-devel@nongnu.org; Mon, 24 Aug 2020 20:17:30 -0400 Received: by mail-pg1-x54a.google.com with SMTP id 78so1429160pgf.5 for ; Mon, 24 Aug 2020 17:17:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc:content-transfer-encoding; bh=m/ayDG00qMRIUpleuYo4aKp7Q1JphS2n6/ujInOccCs=; b=R/P2v5Q9O7jwD4krZnLhn1MXF2KRh3jYd0eHuU+msIBtTDr27ocXdnIx39GWTOq5XP Ze+Z2QyPx7AzpMj7ygG/Yz/X2CzIGyr8NlpVZetKMqfjqZGNIYmPBJG3ShpiLgDczFmf e7HqTDeoBb2MLmHxbGZb6LBVadKWCOT4T0bFCSi4xjHocHh24RlVRWNFZl8BH8bkyF8N rK1D7mC96b6R96C8637M2TPcGOWT5f6v3qCoYnlMZhM3fpKV2wvhkE12xzMbmxywDc6C 6QjAJJqOp6rtpFVzl8tYzubQ7+hbiPKiRjAgwv4rBlnZ70VSDmQ97fsBwSzGHruOyjkw X7Rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=m/ayDG00qMRIUpleuYo4aKp7Q1JphS2n6/ujInOccCs=; b=tmIUK+ZzNEYzLoFvlGJIyFQ4gd+ZDvwGwOcyqxfI81qtiMl+H+tS9za5AoqKWKguRO JXpTiAvvpLmFK6ZqtYlj9fR65fVlb6VA/0d1JxW6cznBEgnFnfb7aI+WlN7/IXFTSr0B i4Hkp5BHtHx7MGgpa0L/3bQSzyYx0Kw+SVGdWrxKARy+tgKXltb97rcqZft1/XeK/hzS 6zWkdaOZG4cpSo8GRd1DIxujt6ljC5etZk2cW6zTiuIn7ZcGjWSa/N5mdc0c6IrlYXY4 9cR+FEuSXCH+R4U40Aa0yRg/f0dojc0JrS48QgmZt0WgyFo4FCaHoq4KDkhd5ystajCH cyEw== X-Gm-Message-State: AOAM530oJ2yCerCaGrjhVI6XHuzhGy64lNgusfi1dGKWwYevYutnOzg4 NybcueOEO9okPCBFxLfVg1tgH6Lu83oQaRpa4w== X-Google-Smtp-Source: ABdhPJzt4nIx+iM7SVj6mliAA0zC1GBGufIJtGAlUN8h/VVgRn7awzzgUqIvhvYxnVSfJc6GriysdR+D+bURGlZkSg== X-Received: from skybert.c.googlers.com ([fda3:e722:ac3:10:24:72f4:c0a8:3107]) (user=hskinnemoen job=sendgmr) by 2002:a17:90a:5b:: with SMTP id 27mr1326455pjb.188.1598314646036; Mon, 24 Aug 2020 17:17:26 -0700 (PDT) Date: Mon, 24 Aug 2020 17:16:59 -0700 In-Reply-To: <20200825001711.1340443-1-hskinnemoen@google.com> Message-Id: <20200825001711.1340443-3-hskinnemoen@google.com> Mime-Version: 1.0 References: <20200825001711.1340443-1-hskinnemoen@google.com> X-Mailer: git-send-email 2.28.0.297.g1956fa8f8d-goog Subject: [PATCH v8 02/14] hw/misc: Add NPCM7xx Clock Controller device model To: peter.maydell@linaro.org, f4bug@amsat.org Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, Avi.Fishman@nuvoton.com, kfting@nuvoton.com, Havard Skinnemoen , Joel Stanley , "=?UTF-8?q?C=C3=A9dric=20Le=20Goater?=" 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::54a; envelope-from=3llhEXwsKClk8JB9EE5DF5E7FF7C5.3FDH5DL-45M5CEFE7EL.FI7@flex--hskinnemoen.bounces.google.com; helo=mail-pg1-x54a.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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" Reply-to: Havard Skinnemoen From: Havard Skinnemoen via X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Enough functionality to boot the Linux kernel has been implemented. This includes: - Correct power-on reset values so the various clock rates can be accurately calculated. - Clock enables stick around when written. In addition, a best effort attempt to implement SECCNT and CNTR25M was made even though I don't think the kernel needs them. Reviewed-by: Tyrone Ting Reviewed-by: Joel Stanley Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: Havard Skinnemoen Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Alexander Bulekov Tested-by: Philippe Mathieu-Daud=C3=A9 --- include/hw/misc/npcm7xx_clk.h | 48 ++++++ hw/misc/npcm7xx_clk.c | 266 ++++++++++++++++++++++++++++++++++ hw/misc/meson.build | 1 + hw/misc/trace-events | 4 + 4 files changed, 319 insertions(+) create mode 100644 include/hw/misc/npcm7xx_clk.h create mode 100644 hw/misc/npcm7xx_clk.c diff --git a/include/hw/misc/npcm7xx_clk.h b/include/hw/misc/npcm7xx_clk.h new file mode 100644 index 0000000000..cdcc9e8534 --- /dev/null +++ b/include/hw/misc/npcm7xx_clk.h @@ -0,0 +1,48 @@ +/* + * Nuvoton NPCM7xx Clock Control Registers. + * + * Copyright 2020 Google LLC + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WIT= HOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ +#ifndef NPCM7XX_CLK_H +#define NPCM7XX_CLK_H + +#include "exec/memory.h" +#include "hw/sysbus.h" + +/* + * The reference clock frequency for the timer modules, and the SECCNT and + * CNTR25M registers in this module, is always 25 MHz. + */ +#define NPCM7XX_TIMER_REF_HZ (25000000) + +/* + * Number of registers in our device state structure. Don't change this wi= thout + * incrementing the version_id in the vmstate. + */ +#define NPCM7XX_CLK_NR_REGS (0x70 / sizeof(uint32_t)) + +typedef struct NPCM7xxCLKState { + SysBusDevice parent; + + MemoryRegion iomem; + + uint32_t regs[NPCM7XX_CLK_NR_REGS]; + + /* Time reference for SECCNT and CNTR25M, initialized by power on rese= t */ + int64_t ref_ns; +} NPCM7xxCLKState; + +#define TYPE_NPCM7XX_CLK "npcm7xx-clk" +#define NPCM7XX_CLK(obj) OBJECT_CHECK(NPCM7xxCLKState, (obj), TYPE_NPCM7XX= _CLK) + +#endif /* NPCM7XX_CLK_H */ diff --git a/hw/misc/npcm7xx_clk.c b/hw/misc/npcm7xx_clk.c new file mode 100644 index 0000000000..21ab4200d1 --- /dev/null +++ b/hw/misc/npcm7xx_clk.c @@ -0,0 +1,266 @@ +/* + * Nuvoton NPCM7xx Clock Control Registers. + * + * Copyright 2020 Google LLC + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WIT= HOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#include "qemu/osdep.h" + +#include "hw/misc/npcm7xx_clk.h" +#include "migration/vmstate.h" +#include "qemu/error-report.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qemu/timer.h" +#include "qemu/units.h" +#include "trace.h" + +#define PLLCON_LOKI BIT(31) +#define PLLCON_LOKS BIT(30) +#define PLLCON_PWDEN BIT(12) + +enum NPCM7xxCLKRegisters { + NPCM7XX_CLK_CLKEN1, + NPCM7XX_CLK_CLKSEL, + NPCM7XX_CLK_CLKDIV1, + NPCM7XX_CLK_PLLCON0, + NPCM7XX_CLK_PLLCON1, + NPCM7XX_CLK_SWRSTR, + NPCM7XX_CLK_IPSRST1 =3D 0x20 / sizeof(uint32_t), + NPCM7XX_CLK_IPSRST2, + NPCM7XX_CLK_CLKEN2, + NPCM7XX_CLK_CLKDIV2, + NPCM7XX_CLK_CLKEN3, + NPCM7XX_CLK_IPSRST3, + NPCM7XX_CLK_WD0RCR, + NPCM7XX_CLK_WD1RCR, + NPCM7XX_CLK_WD2RCR, + NPCM7XX_CLK_SWRSTC1, + NPCM7XX_CLK_SWRSTC2, + NPCM7XX_CLK_SWRSTC3, + NPCM7XX_CLK_SWRSTC4, + NPCM7XX_CLK_PLLCON2, + NPCM7XX_CLK_CLKDIV3, + NPCM7XX_CLK_CORSTC, + NPCM7XX_CLK_PLLCONG, + NPCM7XX_CLK_AHBCKFI, + NPCM7XX_CLK_SECCNT, + NPCM7XX_CLK_CNTR25M, + NPCM7XX_CLK_REGS_END, +}; + +/* + * These reset values were taken from version 0.91 of the NPCM750R data sh= eet. + * + * All are loaded on power-up reset. CLKENx and SWRSTR should also be load= ed on + * core domain reset, but this reset type is not yet supported by QEMU. + */ +static const uint32_t cold_reset_values[NPCM7XX_CLK_NR_REGS] =3D { + [NPCM7XX_CLK_CLKEN1] =3D 0xffffffff, + [NPCM7XX_CLK_CLKSEL] =3D 0x004aaaaa, + [NPCM7XX_CLK_CLKDIV1] =3D 0x5413f855, + [NPCM7XX_CLK_PLLCON0] =3D 0x00222101 | PLLCON_LOKI, + [NPCM7XX_CLK_PLLCON1] =3D 0x00202101 | PLLCON_LOKI, + [NPCM7XX_CLK_IPSRST1] =3D 0x00001000, + [NPCM7XX_CLK_IPSRST2] =3D 0x80000000, + [NPCM7XX_CLK_CLKEN2] =3D 0xffffffff, + [NPCM7XX_CLK_CLKDIV2] =3D 0xaa4f8f9f, + [NPCM7XX_CLK_CLKEN3] =3D 0xffffffff, + [NPCM7XX_CLK_IPSRST3] =3D 0x03000000, + [NPCM7XX_CLK_WD0RCR] =3D 0xffffffff, + [NPCM7XX_CLK_WD1RCR] =3D 0xffffffff, + [NPCM7XX_CLK_WD2RCR] =3D 0xffffffff, + [NPCM7XX_CLK_SWRSTC1] =3D 0x00000003, + [NPCM7XX_CLK_PLLCON2] =3D 0x00c02105 | PLLCON_LOKI, + [NPCM7XX_CLK_CORSTC] =3D 0x04000003, + [NPCM7XX_CLK_PLLCONG] =3D 0x01228606 | PLLCON_LOKI, + [NPCM7XX_CLK_AHBCKFI] =3D 0x000000c8, +}; + +static uint64_t npcm7xx_clk_read(void *opaque, hwaddr offset, unsigned siz= e) +{ + uint32_t reg =3D offset / sizeof(uint32_t); + NPCM7xxCLKState *s =3D opaque; + int64_t now_ns; + uint32_t value =3D 0; + + if (reg >=3D NPCM7XX_CLK_NR_REGS) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: offset 0x%04" HWADDR_PRIx " out of range\n", + __func__, offset); + return 0; + } + + switch (reg) { + case NPCM7XX_CLK_SWRSTR: + qemu_log_mask(LOG_GUEST_ERROR, + "%s: register @ 0x%04" HWADDR_PRIx " is write-only\n= ", + __func__, offset); + break; + + case NPCM7XX_CLK_SECCNT: + now_ns =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + value =3D (now_ns - s->ref_ns) / NANOSECONDS_PER_SECOND; + break; + + case NPCM7XX_CLK_CNTR25M: + now_ns =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + /* + * This register counts 25 MHz cycles, updating every 640 ns. It r= olls + * over to zero every second. + * + * The 4 LSBs are always zero: (1e9 / 640) << 4 =3D 25000000. + */ + value =3D (((now_ns - s->ref_ns) / 640) << 4) % NPCM7XX_TIMER_REF_= HZ; + break; + + default: + value =3D s->regs[reg]; + break; + }; + + trace_npcm7xx_clk_read(offset, value); + + return value; +} + +static void npcm7xx_clk_write(void *opaque, hwaddr offset, + uint64_t v, unsigned size) +{ + uint32_t reg =3D offset / sizeof(uint32_t); + NPCM7xxCLKState *s =3D opaque; + uint32_t value =3D v; + + trace_npcm7xx_clk_write(offset, value); + + if (reg >=3D NPCM7XX_CLK_NR_REGS) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: offset 0x%04" HWADDR_PRIx " out of range\n", + __func__, offset); + return; + } + + switch (reg) { + case NPCM7XX_CLK_SWRSTR: + qemu_log_mask(LOG_UNIMP, "%s: SW reset not implemented: 0x%02x\n", + __func__, value); + value =3D 0; + break; + + case NPCM7XX_CLK_PLLCON0: + case NPCM7XX_CLK_PLLCON1: + case NPCM7XX_CLK_PLLCON2: + case NPCM7XX_CLK_PLLCONG: + if (value & PLLCON_PWDEN) { + /* Power down -- clear lock and indicate loss of lock */ + value &=3D ~PLLCON_LOKI; + value |=3D PLLCON_LOKS; + } else { + /* Normal mode -- assume always locked */ + value |=3D PLLCON_LOKI; + /* Keep LOKS unchanged unless cleared by writing 1 */ + if (value & PLLCON_LOKS) { + value &=3D ~PLLCON_LOKS; + } else { + value |=3D (value & PLLCON_LOKS); + } + } + break; + + case NPCM7XX_CLK_CNTR25M: + qemu_log_mask(LOG_GUEST_ERROR, + "%s: register @ 0x%04" HWADDR_PRIx " is read-only\n", + __func__, offset); + return; + } + + s->regs[reg] =3D value; +} + +static const struct MemoryRegionOps npcm7xx_clk_ops =3D { + .read =3D npcm7xx_clk_read, + .write =3D npcm7xx_clk_write, + .endianness =3D DEVICE_LITTLE_ENDIAN, + .valid =3D { + .min_access_size =3D 4, + .max_access_size =3D 4, + .unaligned =3D false, + }, +}; + +static void npcm7xx_clk_enter_reset(Object *obj, ResetType type) +{ + NPCM7xxCLKState *s =3D NPCM7XX_CLK(obj); + + QEMU_BUILD_BUG_ON(sizeof(s->regs) !=3D sizeof(cold_reset_values)); + + switch (type) { + case RESET_TYPE_COLD: + memcpy(s->regs, cold_reset_values, sizeof(cold_reset_values)); + s->ref_ns =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + return; + } + + /* + * A small number of registers need to be reset on a core domain reset, + * but no such reset type exists yet. + */ + qemu_log_mask(LOG_UNIMP, "%s: reset type %d not implemented.", + __func__, type); +} + +static void npcm7xx_clk_init(Object *obj) +{ + NPCM7xxCLKState *s =3D NPCM7XX_CLK(obj); + + memory_region_init_io(&s->iomem, obj, &npcm7xx_clk_ops, s, + TYPE_NPCM7XX_CLK, 4 * KiB); + sysbus_init_mmio(&s->parent, &s->iomem); +} + +static const VMStateDescription vmstate_npcm7xx_clk =3D { + .name =3D "npcm7xx-clk", + .version_id =3D 0, + .minimum_version_id =3D 0, + .fields =3D (VMStateField[]) { + VMSTATE_UINT32_ARRAY(regs, NPCM7xxCLKState, NPCM7XX_CLK_NR_REGS), + VMSTATE_INT64(ref_ns, NPCM7xxCLKState), + VMSTATE_END_OF_LIST(), + }, +}; + +static void npcm7xx_clk_class_init(ObjectClass *klass, void *data) +{ + ResettableClass *rc =3D RESETTABLE_CLASS(klass); + DeviceClass *dc =3D DEVICE_CLASS(klass); + + QEMU_BUILD_BUG_ON(NPCM7XX_CLK_REGS_END > NPCM7XX_CLK_NR_REGS); + + dc->desc =3D "NPCM7xx Clock Control Registers"; + dc->vmsd =3D &vmstate_npcm7xx_clk; + rc->phases.enter =3D npcm7xx_clk_enter_reset; +} + +static const TypeInfo npcm7xx_clk_info =3D { + .name =3D TYPE_NPCM7XX_CLK, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(NPCM7xxCLKState), + .instance_init =3D npcm7xx_clk_init, + .class_init =3D npcm7xx_clk_class_init, +}; + +static void npcm7xx_clk_register_type(void) +{ + type_register_static(&npcm7xx_clk_info); +} +type_init(npcm7xx_clk_register_type); diff --git a/hw/misc/meson.build b/hw/misc/meson.build index 99ffb9f9e8..531cc31dcc 100644 --- a/hw/misc/meson.build +++ b/hw/misc/meson.build @@ -51,6 +51,7 @@ softmmu_ss.add(when: 'CONFIG_IMX', if_true: files( softmmu_ss.add(when: 'CONFIG_MILKYMIST', if_true: files('milkymist-hpdmc.c= ', 'milkymist-pfpu.c')) softmmu_ss.add(when: 'CONFIG_MAINSTONE', if_true: files('mst_fpga.c')) softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files( + 'npcm7xx_clk.c', 'npcm7xx_gcr.c', )) softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files( diff --git a/hw/misc/trace-events b/hw/misc/trace-events index dbf90db8ed..a010699b4f 100644 --- a/hw/misc/trace-events +++ b/hw/misc/trace-events @@ -111,6 +111,10 @@ mos6522_set_sr_int(void) "set sr_int" mos6522_write(uint64_t addr, uint64_t val) "reg=3D0x%"PRIx64 " val=3D0x%"P= RIx64 mos6522_read(uint64_t addr, unsigned val) "reg=3D0x%"PRIx64 " val=3D0x%x" =20 +# npcm7xx_clk.c +npcm7xx_clk_read(uint64_t offset, uint32_t value) " offset: 0x%04" PRIx64 = " value: 0x%08" PRIx32 +npcm7xx_clk_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 = " value: 0x%08" PRIx32 + # npcm7xx_gcr.c npcm7xx_gcr_read(uint64_t offset, uint32_t value) " offset: 0x%04" PRIx64 = " value: 0x%08" PRIx32 npcm7xx_gcr_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 = " value: 0x%08" PRIx32 --=20 2.28.0.297.g1956fa8f8d-goog From nobody Sun May 19 05:51:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=1598314721; cv=none; d=zohomail.com; s=zohoarc; b=WFdULGOEAoGmAdTfK9ZWXNi5OftrM5LdmJi70Q+06O+amLGgnT5S77ZKYJqljigucPeYq2P08q5tUAnI4ixFkXJqvVogpZ1b873vQfPmlB4b6s7AWSSjGr+iyYhp7UomCvMKpUGKSI0ga2S/iNGrS9/KL3jF4Tz7Iu9/zWfX1BA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598314721; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=KRVXVQIRHgTzvCW8n19vtxcYvRV4Hq2WTqRLXenSd4U=; b=aAm/oo3khGpKHV3RMVU5m9XR+H0whiIXLSsSaCSW031RBrP4CXR13oYd6yQGHT5Fe1aEE/ukG+YYa7HKZS8k3FyyZzeKFckXWj4DusfglwUtB+tcNUxewQ++R9LNbztEt8+GmxHHR+pPVFXHLix4MCFuXo1u8yzZSNG+hz/YeDU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 159831472181624.291557754425753; Mon, 24 Aug 2020 17:18:41 -0700 (PDT) Received: from localhost ([::1]:56624 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kAMfg-0005wp-Eg for importer@patchew.org; Mon, 24 Aug 2020 20:18:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45162) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3mFhEXwsKClsALDBGG7FH7G9HH9E7.5HFJ7FN-67O7EGHG9GN.HK9@flex--hskinnemoen.bounces.google.com>) id 1kAMea-0003vB-QT for qemu-devel@nongnu.org; Mon, 24 Aug 2020 20:17:32 -0400 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]:39017) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3mFhEXwsKClsALDBGG7FH7G9HH9E7.5HFJ7FN-67O7EGHG9GN.HK9@flex--hskinnemoen.bounces.google.com>) id 1kAMeX-00066x-IV for qemu-devel@nongnu.org; Mon, 24 Aug 2020 20:17:32 -0400 Received: by mail-yb1-xb49.google.com with SMTP id e196so12691796ybh.6 for ; Mon, 24 Aug 2020 17:17:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc:content-transfer-encoding; bh=KRVXVQIRHgTzvCW8n19vtxcYvRV4Hq2WTqRLXenSd4U=; b=CNelWPCFnVpLjwve0AtHyp5HhVNhQs8zILjnzVS0ocabg/VSqGpMknJi182n1myIe0 CuiVbrRwsyQbUr8hwa+qKJ7OgCOyxlktjnrc7leMVc2hufTNYdTqypxtXcv9NYKBwDhG ik9UPrMl64uclZKn2e9IZj9GDib/6W4P13sdmZzj+f+27Q7Ujec3//CdbRd/jE6EUvy5 /f/IxpKMv5bYcPr00gpnHTibOmsTZPEyXfSGYeUSr5cu1YfeT4amGIjIVGAdmCtE6Div WXg/HP0IWk9QkwSXYIryZyK1Ts3GSwIrJQKGxSTNXWtZgtFggwIIw+aF+nelM7JNqMBO c6Gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=KRVXVQIRHgTzvCW8n19vtxcYvRV4Hq2WTqRLXenSd4U=; b=gOIZB1qjmDeTN24FMN3MQMA6JUO7TO3xZdTiv5P2l7/uakFa85AljhAw0+zCrJgIIa wne4i7ooZXTb1882qcInQEfal4ry3WUySdP/n0N6k2/HvRgLyOkkIipdGfPMBUCct9Jw XALfk9ve2NDUd+0Q/JOdKRMW+HcwDvjCX60hwmTPXklUyES8TZD7V21Xmiq+3x8vvHlD 5n/Wjs7RkAn8K8xZP0R7clgWkYNQ9OME8Xswbt+7fmy8xXZglghDeyTI1y8t+UjxwyCv EnVeIJKlT9G5/HuEYGkvMA69Adv0ystleta2yQ/LwueTD2s8mII00fo136atiLTJdnG/ 2qeg== X-Gm-Message-State: AOAM5308XzhmAsFlvdZfqLNdnQvQWb7Im8v4lvdGIkN9N6cLPKEho2YV EaqucXVnTQGP4U4DRo2O22lBxDXLhqAJcelWIw== X-Google-Smtp-Source: ABdhPJxtj9yR+pszC+qFNVfrIB+CRCTrp+y15z/S6/U1MMMwij9p3Y3px2gOYaJhV4SH9exhGFRIZHdTzZFFiEjftA== X-Received: from skybert.c.googlers.com ([fda3:e722:ac3:10:24:72f4:c0a8:3107]) (user=hskinnemoen job=sendgmr) by 2002:a25:7310:: with SMTP id o16mr11493234ybc.415.1598314648051; Mon, 24 Aug 2020 17:17:28 -0700 (PDT) Date: Mon, 24 Aug 2020 17:17:00 -0700 In-Reply-To: <20200825001711.1340443-1-hskinnemoen@google.com> Message-Id: <20200825001711.1340443-4-hskinnemoen@google.com> Mime-Version: 1.0 References: <20200825001711.1340443-1-hskinnemoen@google.com> X-Mailer: git-send-email 2.28.0.297.g1956fa8f8d-goog Subject: [PATCH v8 03/14] hw/timer: Add NPCM7xx Timer device model To: peter.maydell@linaro.org, f4bug@amsat.org Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, Avi.Fishman@nuvoton.com, kfting@nuvoton.com, Havard Skinnemoen , Joel Stanley 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::b49; envelope-from=3mFhEXwsKClsALDBGG7FH7G9HH9E7.5HFJ7FN-67O7EGHG9GN.HK9@flex--hskinnemoen.bounces.google.com; helo=mail-yb1-xb49.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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" Reply-to: Havard Skinnemoen From: Havard Skinnemoen via X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The NPCM730 and NPCM750 SoCs have three timer modules each holding five timers and some shared registers (e.g. interrupt status). Each timer runs at 25 MHz divided by a prescaler, and counts down from a configurable initial value to zero. When zero is reached, the interrupt flag for the timer is set, and the timer is disabled (one-shot mode) or reloaded from its initial value (periodic mode). This implementation is sufficient to boot a Linux kernel configured for NPCM750. Note that the kernel does not seem to actually turn on the interrupts. Reviewed-by: Tyrone Ting Reviewed-by: Joel Stanley Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Havard Skinnemoen Tested-by: Alexander Bulekov Tested-by: Philippe Mathieu-Daud=C3=A9 --- include/hw/timer/npcm7xx_timer.h | 78 +++++ hw/timer/npcm7xx_timer.c | 509 +++++++++++++++++++++++++++++++ hw/timer/meson.build | 1 + hw/timer/trace-events | 5 + 4 files changed, 593 insertions(+) create mode 100644 include/hw/timer/npcm7xx_timer.h create mode 100644 hw/timer/npcm7xx_timer.c diff --git a/include/hw/timer/npcm7xx_timer.h b/include/hw/timer/npcm7xx_ti= mer.h new file mode 100644 index 0000000000..878a365a79 --- /dev/null +++ b/include/hw/timer/npcm7xx_timer.h @@ -0,0 +1,78 @@ +/* + * Nuvoton NPCM7xx Timer Controller + * + * Copyright 2020 Google LLC + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WIT= HOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ +#ifndef NPCM7XX_TIMER_H +#define NPCM7XX_TIMER_H + +#include "exec/memory.h" +#include "hw/sysbus.h" +#include "qemu/timer.h" + +/* Each Timer Module (TIM) instance holds five 25 MHz timers. */ +#define NPCM7XX_TIMERS_PER_CTRL (5) + +/* + * Number of registers in our device state structure. Don't change this wi= thout + * incrementing the version_id in the vmstate. + */ +#define NPCM7XX_TIMER_NR_REGS (0x54 / sizeof(uint32_t)) + +typedef struct NPCM7xxTimerCtrlState NPCM7xxTimerCtrlState; + +/** + * struct NPCM7xxTimer - Individual timer state. + * @irq: GIC interrupt line to fire on expiration (if enabled). + * @qtimer: QEMU timer that notifies us on expiration. + * @expires_ns: Absolute virtual expiration time. + * @remaining_ns: Remaining time until expiration if timer is paused. + * @tcsr: The Timer Control and Status Register. + * @ticr: The Timer Initial Count Register. + */ +typedef struct NPCM7xxTimer { + NPCM7xxTimerCtrlState *ctrl; + + qemu_irq irq; + QEMUTimer qtimer; + int64_t expires_ns; + int64_t remaining_ns; + + uint32_t tcsr; + uint32_t ticr; +} NPCM7xxTimer; + +/** + * struct NPCM7xxTimerCtrlState - Timer Module device state. + * @parent: System bus device. + * @iomem: Memory region through which registers are accessed. + * @tisr: The Timer Interrupt Status Register. + * @wtcr: The Watchdog Timer Control Register. + * @timer: The five individual timers managed by this module. + */ +struct NPCM7xxTimerCtrlState { + SysBusDevice parent; + + MemoryRegion iomem; + + uint32_t tisr; + uint32_t wtcr; + + NPCM7xxTimer timer[NPCM7XX_TIMERS_PER_CTRL]; +}; + +#define TYPE_NPCM7XX_TIMER "npcm7xx-timer" +#define NPCM7XX_TIMER(obj) \ + OBJECT_CHECK(NPCM7xxTimerCtrlState, (obj), TYPE_NPCM7XX_TIMER) + +#endif /* NPCM7XX_TIMER_H */ diff --git a/hw/timer/npcm7xx_timer.c b/hw/timer/npcm7xx_timer.c new file mode 100644 index 0000000000..ad5ebd9878 --- /dev/null +++ b/hw/timer/npcm7xx_timer.c @@ -0,0 +1,509 @@ +/* + * Nuvoton NPCM7xx Timer Controller + * + * Copyright 2020 Google LLC + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WIT= HOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#include "qemu/osdep.h" + +#include "hw/irq.h" +#include "hw/misc/npcm7xx_clk.h" +#include "hw/timer/npcm7xx_timer.h" +#include "migration/vmstate.h" +#include "qemu/bitops.h" +#include "qemu/error-report.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qemu/timer.h" +#include "qemu/units.h" +#include "trace.h" + +/* 32-bit register indices. */ +enum NPCM7xxTimerRegisters { + NPCM7XX_TIMER_TCSR0, + NPCM7XX_TIMER_TCSR1, + NPCM7XX_TIMER_TICR0, + NPCM7XX_TIMER_TICR1, + NPCM7XX_TIMER_TDR0, + NPCM7XX_TIMER_TDR1, + NPCM7XX_TIMER_TISR, + NPCM7XX_TIMER_WTCR, + NPCM7XX_TIMER_TCSR2, + NPCM7XX_TIMER_TCSR3, + NPCM7XX_TIMER_TICR2, + NPCM7XX_TIMER_TICR3, + NPCM7XX_TIMER_TDR2, + NPCM7XX_TIMER_TDR3, + NPCM7XX_TIMER_TCSR4 =3D 0x0040 / sizeof(uint32_t), + NPCM7XX_TIMER_TICR4 =3D 0x0048 / sizeof(uint32_t), + NPCM7XX_TIMER_TDR4 =3D 0x0050 / sizeof(uint32_t), + NPCM7XX_TIMER_REGS_END, +}; + +/* Register field definitions. */ +#define NPCM7XX_TCSR_CEN BIT(30) +#define NPCM7XX_TCSR_IE BIT(29) +#define NPCM7XX_TCSR_PERIODIC BIT(27) +#define NPCM7XX_TCSR_CRST BIT(26) +#define NPCM7XX_TCSR_CACT BIT(25) +#define NPCM7XX_TCSR_RSVD 0x21ffff00 +#define NPCM7XX_TCSR_PRESCALE_START 0 +#define NPCM7XX_TCSR_PRESCALE_LEN 8 + +/* + * Returns the index of timer in the tc->timer array. This can be used to + * locate the registers that belong to this timer. + */ +static int npcm7xx_timer_index(NPCM7xxTimerCtrlState *tc, NPCM7xxTimer *ti= mer) +{ + int index =3D timer - tc->timer; + + g_assert(index >=3D 0 && index < NPCM7XX_TIMERS_PER_CTRL); + + return index; +} + +/* Return the value by which to divide the reference clock rate. */ +static uint32_t npcm7xx_timer_prescaler(const NPCM7xxTimer *t) +{ + return extract32(t->tcsr, NPCM7XX_TCSR_PRESCALE_START, + NPCM7XX_TCSR_PRESCALE_LEN) + 1; +} + +/* Convert a timer cycle count to a time interval in nanoseconds. */ +static int64_t npcm7xx_timer_count_to_ns(NPCM7xxTimer *t, uint32_t count) +{ + int64_t ns =3D count; + + ns *=3D NANOSECONDS_PER_SECOND / NPCM7XX_TIMER_REF_HZ; + ns *=3D npcm7xx_timer_prescaler(t); + + return ns; +} + +/* Convert a time interval in nanoseconds to a timer cycle count. */ +static uint32_t npcm7xx_timer_ns_to_count(NPCM7xxTimer *t, int64_t ns) +{ + int64_t count; + + count =3D ns / (NANOSECONDS_PER_SECOND / NPCM7XX_TIMER_REF_HZ); + count /=3D npcm7xx_timer_prescaler(t); + + return count; +} + +/* + * Raise the interrupt line if there's a pending interrupt and interrupts = are + * enabled for this timer. If not, lower it. + */ +static void npcm7xx_timer_check_interrupt(NPCM7xxTimer *t) +{ + NPCM7xxTimerCtrlState *tc =3D t->ctrl; + int index =3D npcm7xx_timer_index(tc, t); + bool pending =3D (t->tcsr & NPCM7XX_TCSR_IE) && (tc->tisr & BIT(index)= ); + + qemu_set_irq(t->irq, pending); + trace_npcm7xx_timer_irq(DEVICE(tc)->canonical_path, index, pending); +} + +/* Start or resume the timer. */ +static void npcm7xx_timer_start(NPCM7xxTimer *t) +{ + int64_t now; + + now =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + t->expires_ns =3D now + t->remaining_ns; + timer_mod(&t->qtimer, t->expires_ns); +} + +/* + * Called when the counter reaches zero. Sets the interrupt flag, and eith= er + * restarts or disables the timer. + */ +static void npcm7xx_timer_reached_zero(NPCM7xxTimer *t) +{ + NPCM7xxTimerCtrlState *tc =3D t->ctrl; + int index =3D npcm7xx_timer_index(tc, t); + + tc->tisr |=3D BIT(index); + + if (t->tcsr & NPCM7XX_TCSR_PERIODIC) { + t->remaining_ns =3D npcm7xx_timer_count_to_ns(t, t->ticr); + if (t->tcsr & NPCM7XX_TCSR_CEN) { + npcm7xx_timer_start(t); + } + } else { + t->tcsr &=3D ~(NPCM7XX_TCSR_CEN | NPCM7XX_TCSR_CACT); + } + + npcm7xx_timer_check_interrupt(t); +} + +/* Stop counting. Record the time remaining so we can continue later. */ +static void npcm7xx_timer_pause(NPCM7xxTimer *t) +{ + int64_t now; + + timer_del(&t->qtimer); + now =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + t->remaining_ns =3D t->expires_ns - now; + g_assert(t->remaining_ns > 0); +} + +/* + * Restart the timer from its initial value. If the timer was enabled and = stays + * enabled, adjust the QEMU timer according to the new count. If the timer= is + * transitioning from disabled to enabled, the caller is expected to start= the + * timer later. + */ +static void npcm7xx_timer_restart(NPCM7xxTimer *t, uint32_t old_tcsr) +{ + t->remaining_ns =3D npcm7xx_timer_count_to_ns(t, t->ticr); + + if (old_tcsr & t->tcsr & NPCM7XX_TCSR_CEN) { + npcm7xx_timer_start(t); + } +} + +/* Register read and write handlers */ + +static void npcm7xx_timer_write_tcsr(NPCM7xxTimer *t, uint32_t new_tcsr) +{ + uint32_t old_tcsr =3D t->tcsr; + + if (new_tcsr & NPCM7XX_TCSR_RSVD) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: reserved bits in 0x%08x ignore= d\n", + __func__, new_tcsr); + new_tcsr &=3D ~NPCM7XX_TCSR_RSVD; + } + if (new_tcsr & NPCM7XX_TCSR_CACT) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: read-only bits in 0x%08x ignor= ed\n", + __func__, new_tcsr); + new_tcsr &=3D ~NPCM7XX_TCSR_CACT; + } + + t->tcsr =3D (t->tcsr & NPCM7XX_TCSR_CACT) | new_tcsr; + + if ((old_tcsr ^ new_tcsr) & NPCM7XX_TCSR_IE) { + npcm7xx_timer_check_interrupt(t); + } + if (new_tcsr & NPCM7XX_TCSR_CRST) { + npcm7xx_timer_restart(t, old_tcsr); + t->tcsr &=3D ~NPCM7XX_TCSR_CRST; + } + if ((old_tcsr ^ new_tcsr) & NPCM7XX_TCSR_CEN) { + if (new_tcsr & NPCM7XX_TCSR_CEN) { + npcm7xx_timer_start(t); + } else { + npcm7xx_timer_pause(t); + } + } +} + +static void npcm7xx_timer_write_ticr(NPCM7xxTimer *t, uint32_t new_ticr) +{ + t->ticr =3D new_ticr; + + npcm7xx_timer_restart(t, t->tcsr); +} + +static uint32_t npcm7xx_timer_read_tdr(NPCM7xxTimer *t) +{ + if (t->tcsr & NPCM7XX_TCSR_CEN) { + int64_t now =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + + return npcm7xx_timer_ns_to_count(t, t->expires_ns - now); + } + + return npcm7xx_timer_ns_to_count(t, t->remaining_ns); +} + +static hwaddr npcm7xx_tcsr_index(hwaddr reg) +{ + switch (reg) { + case NPCM7XX_TIMER_TCSR0: + return 0; + case NPCM7XX_TIMER_TCSR1: + return 1; + case NPCM7XX_TIMER_TCSR2: + return 2; + case NPCM7XX_TIMER_TCSR3: + return 3; + case NPCM7XX_TIMER_TCSR4: + return 4; + default: + g_assert_not_reached(); + } +} + +static hwaddr npcm7xx_ticr_index(hwaddr reg) +{ + switch (reg) { + case NPCM7XX_TIMER_TICR0: + return 0; + case NPCM7XX_TIMER_TICR1: + return 1; + case NPCM7XX_TIMER_TICR2: + return 2; + case NPCM7XX_TIMER_TICR3: + return 3; + case NPCM7XX_TIMER_TICR4: + return 4; + default: + g_assert_not_reached(); + } +} + +static hwaddr npcm7xx_tdr_index(hwaddr reg) +{ + switch (reg) { + case NPCM7XX_TIMER_TDR0: + return 0; + case NPCM7XX_TIMER_TDR1: + return 1; + case NPCM7XX_TIMER_TDR2: + return 2; + case NPCM7XX_TIMER_TDR3: + return 3; + case NPCM7XX_TIMER_TDR4: + return 4; + default: + g_assert_not_reached(); + } +} + +static uint64_t npcm7xx_timer_read(void *opaque, hwaddr offset, unsigned s= ize) +{ + NPCM7xxTimerCtrlState *s =3D opaque; + uint64_t value =3D 0; + hwaddr reg; + + reg =3D offset / sizeof(uint32_t); + switch (reg) { + case NPCM7XX_TIMER_TCSR0: + case NPCM7XX_TIMER_TCSR1: + case NPCM7XX_TIMER_TCSR2: + case NPCM7XX_TIMER_TCSR3: + case NPCM7XX_TIMER_TCSR4: + value =3D s->timer[npcm7xx_tcsr_index(reg)].tcsr; + break; + + case NPCM7XX_TIMER_TICR0: + case NPCM7XX_TIMER_TICR1: + case NPCM7XX_TIMER_TICR2: + case NPCM7XX_TIMER_TICR3: + case NPCM7XX_TIMER_TICR4: + value =3D s->timer[npcm7xx_ticr_index(reg)].ticr; + break; + + case NPCM7XX_TIMER_TDR0: + case NPCM7XX_TIMER_TDR1: + case NPCM7XX_TIMER_TDR2: + case NPCM7XX_TIMER_TDR3: + case NPCM7XX_TIMER_TDR4: + value =3D npcm7xx_timer_read_tdr(&s->timer[npcm7xx_tdr_index(reg)]= ); + break; + + case NPCM7XX_TIMER_TISR: + value =3D s->tisr; + break; + + case NPCM7XX_TIMER_WTCR: + value =3D s->wtcr; + break; + + default: + qemu_log_mask(LOG_GUEST_ERROR, + "%s: invalid offset 0x%04" HWADDR_PRIx "\n", + __func__, offset); + break; + } + + trace_npcm7xx_timer_read(DEVICE(s)->canonical_path, offset, value); + + return value; +} + +static void npcm7xx_timer_write(void *opaque, hwaddr offset, + uint64_t v, unsigned size) +{ + uint32_t reg =3D offset / sizeof(uint32_t); + NPCM7xxTimerCtrlState *s =3D opaque; + uint32_t value =3D v; + + trace_npcm7xx_timer_write(DEVICE(s)->canonical_path, offset, value); + + switch (reg) { + case NPCM7XX_TIMER_TCSR0: + case NPCM7XX_TIMER_TCSR1: + case NPCM7XX_TIMER_TCSR2: + case NPCM7XX_TIMER_TCSR3: + case NPCM7XX_TIMER_TCSR4: + npcm7xx_timer_write_tcsr(&s->timer[npcm7xx_tcsr_index(reg)], value= ); + return; + + case NPCM7XX_TIMER_TICR0: + case NPCM7XX_TIMER_TICR1: + case NPCM7XX_TIMER_TICR2: + case NPCM7XX_TIMER_TICR3: + case NPCM7XX_TIMER_TICR4: + npcm7xx_timer_write_ticr(&s->timer[npcm7xx_ticr_index(reg)], value= ); + return; + + case NPCM7XX_TIMER_TDR0: + case NPCM7XX_TIMER_TDR1: + case NPCM7XX_TIMER_TDR2: + case NPCM7XX_TIMER_TDR3: + case NPCM7XX_TIMER_TDR4: + qemu_log_mask(LOG_GUEST_ERROR, + "%s: register @ 0x%04" HWADDR_PRIx " is read-only\n", + __func__, offset); + return; + + case NPCM7XX_TIMER_TISR: + s->tisr &=3D ~value; + return; + + case NPCM7XX_TIMER_WTCR: + qemu_log_mask(LOG_UNIMP, "%s: WTCR write not implemented: 0x%08x\n= ", + __func__, value); + return; + } + + qemu_log_mask(LOG_GUEST_ERROR, + "%s: invalid offset 0x%04" HWADDR_PRIx "\n", + __func__, offset); +} + +static const struct MemoryRegionOps npcm7xx_timer_ops =3D { + .read =3D npcm7xx_timer_read, + .write =3D npcm7xx_timer_write, + .endianness =3D DEVICE_LITTLE_ENDIAN, + .valid =3D { + .min_access_size =3D 4, + .max_access_size =3D 4, + .unaligned =3D false, + }, +}; + +/* Called when the QEMU timer expires. */ +static void npcm7xx_timer_expired(void *opaque) +{ + NPCM7xxTimer *t =3D opaque; + + if (t->tcsr & NPCM7XX_TCSR_CEN) { + npcm7xx_timer_reached_zero(t); + } +} + +static void npcm7xx_timer_enter_reset(Object *obj, ResetType type) +{ + NPCM7xxTimerCtrlState *s =3D NPCM7XX_TIMER(obj); + int i; + + for (i =3D 0; i < NPCM7XX_TIMERS_PER_CTRL; i++) { + NPCM7xxTimer *t =3D &s->timer[i]; + + timer_del(&t->qtimer); + t->expires_ns =3D 0; + t->remaining_ns =3D 0; + t->tcsr =3D 0x00000005; + t->ticr =3D 0x00000000; + } + + s->tisr =3D 0x00000000; + s->wtcr =3D 0x00000400; +} + +static void npcm7xx_timer_hold_reset(Object *obj) +{ + NPCM7xxTimerCtrlState *s =3D NPCM7XX_TIMER(obj); + int i; + + for (i =3D 0; i < NPCM7XX_TIMERS_PER_CTRL; i++) { + qemu_irq_lower(s->timer[i].irq); + } +} + +static void npcm7xx_timer_realize(DeviceState *dev, Error **errp) +{ + NPCM7xxTimerCtrlState *s =3D NPCM7XX_TIMER(dev); + SysBusDevice *sbd =3D &s->parent; + int i; + + for (i =3D 0; i < NPCM7XX_TIMERS_PER_CTRL; i++) { + NPCM7xxTimer *t =3D &s->timer[i]; + t->ctrl =3D s; + timer_init_ns(&t->qtimer, QEMU_CLOCK_VIRTUAL, npcm7xx_timer_expire= d, t); + sysbus_init_irq(sbd, &t->irq); + } + + memory_region_init_io(&s->iomem, OBJECT(s), &npcm7xx_timer_ops, s, + TYPE_NPCM7XX_TIMER, 4 * KiB); + sysbus_init_mmio(sbd, &s->iomem); +} + +static const VMStateDescription vmstate_npcm7xx_timer =3D { + .name =3D "npcm7xx-timer", + .version_id =3D 0, + .minimum_version_id =3D 0, + .fields =3D (VMStateField[]) { + VMSTATE_TIMER(qtimer, NPCM7xxTimer), + VMSTATE_INT64(expires_ns, NPCM7xxTimer), + VMSTATE_INT64(remaining_ns, NPCM7xxTimer), + VMSTATE_UINT32(tcsr, NPCM7xxTimer), + VMSTATE_UINT32(ticr, NPCM7xxTimer), + VMSTATE_END_OF_LIST(), + }, +}; + +static const VMStateDescription vmstate_npcm7xx_timer_ctrl =3D { + .name =3D "npcm7xx-timer-ctrl", + .version_id =3D 0, + .minimum_version_id =3D 0, + .fields =3D (VMStateField[]) { + VMSTATE_UINT32(tisr, NPCM7xxTimerCtrlState), + VMSTATE_UINT32(wtcr, NPCM7xxTimerCtrlState), + VMSTATE_STRUCT_ARRAY(timer, NPCM7xxTimerCtrlState, + NPCM7XX_TIMERS_PER_CTRL, 0, vmstate_npcm7xx_t= imer, + NPCM7xxTimer), + VMSTATE_END_OF_LIST(), + }, +}; + +static void npcm7xx_timer_class_init(ObjectClass *klass, void *data) +{ + ResettableClass *rc =3D RESETTABLE_CLASS(klass); + DeviceClass *dc =3D DEVICE_CLASS(klass); + + QEMU_BUILD_BUG_ON(NPCM7XX_TIMER_REGS_END > NPCM7XX_TIMER_NR_REGS); + + dc->desc =3D "NPCM7xx Timer Controller"; + dc->realize =3D npcm7xx_timer_realize; + dc->vmsd =3D &vmstate_npcm7xx_timer_ctrl; + rc->phases.enter =3D npcm7xx_timer_enter_reset; + rc->phases.hold =3D npcm7xx_timer_hold_reset; +} + +static const TypeInfo npcm7xx_timer_info =3D { + .name =3D TYPE_NPCM7XX_TIMER, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(NPCM7xxTimerCtrlState), + .class_init =3D npcm7xx_timer_class_init, +}; + +static void npcm7xx_timer_register_type(void) +{ + type_register_static(&npcm7xx_timer_info); +} +type_init(npcm7xx_timer_register_type); diff --git a/hw/timer/meson.build b/hw/timer/meson.build index 9f0a267c83..be343f68fe 100644 --- a/hw/timer/meson.build +++ b/hw/timer/meson.build @@ -23,6 +23,7 @@ softmmu_ss.add(when: 'CONFIG_LM32', if_true: files('lm32_= timer.c')) softmmu_ss.add(when: 'CONFIG_MILKYMIST', if_true: files('milkymist-sysctl.= c')) softmmu_ss.add(when: 'CONFIG_MIPS_CPS', if_true: files('mips_gictimer.c')) softmmu_ss.add(when: 'CONFIG_MSF2', if_true: files('mss-timer.c')) +softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_timer.c')) softmmu_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('nrf51_timer.c')) softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files('omap_gptimer.c')) softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files('omap_synctimer.c')) diff --git a/hw/timer/trace-events b/hw/timer/trace-events index 447b7c405b..ee66d8c84f 100644 --- a/hw/timer/trace-events +++ b/hw/timer/trace-events @@ -66,6 +66,11 @@ cmsdk_apb_dualtimer_read(uint64_t offset, uint64_t data,= unsigned size) "CMSDK A cmsdk_apb_dualtimer_write(uint64_t offset, uint64_t data, unsigned size) "= CMSDK APB dualtimer write: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u" cmsdk_apb_dualtimer_reset(void) "CMSDK APB dualtimer: reset" =20 +# npcm7xx_timer.c +npcm7xx_timer_read(const char *id, uint64_t offset, uint64_t value) " %s o= ffset: 0x%04" PRIx64 " value 0x%08" PRIx64 +npcm7xx_timer_write(const char *id, uint64_t offset, uint64_t value) "%s o= ffset: 0x%04" PRIx64 " value 0x%08" PRIx64 +npcm7xx_timer_irq(const char *id, int timer, int state) "%s timer %d state= %d" + # nrf51_timer.c nrf51_timer_read(uint8_t timer_id, uint64_t addr, uint32_t value, unsigned= size) "timer %u read addr 0x%" PRIx64 " data 0x%" PRIx32 " size %u" nrf51_timer_write(uint8_t timer_id, uint64_t addr, uint32_t value, unsigne= d size) "timer %u write addr 0x%" PRIx64 " data 0x%" PRIx32 " size %u" --=20 2.28.0.297.g1956fa8f8d-goog From nobody Sun May 19 05:51:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=1598314931; cv=none; d=zohomail.com; s=zohoarc; b=Dwczj9rMCxbqVTFQSfTQzUy+SaNDiiWzY3i9oqFI2TM1rmeabaI7j/mJwDkUfxUxe7e3uEnTTf3NICDxybqeiDSxPVuz75Ck2C70wWluF95biPida3Hbq0qfVRMGxEyQaOBA1zpYnlKK8RQPGDh6EVOIvo1aVwZn72+PAacaV10= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598314931; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=tXkgiwTbsbo2dG1AmnAh+6XnAGkL86RtqOGlQim3KOk=; b=YinjN2KbcZFSelVuWPwCywQbQyBwpbo3J9Xbnxu67rooDPLgioUxXDC9fHlNmYbJR5x8fRX7HX0XArXOJBxnkEBtuA58guwfgL89WtyJ262BxauGT/A+y6B0mQ7EnTETVGDj65HT0ZdJgfmHKZn2JdsNrHdxxUuBFB9h7Sm2pNI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 159831493197712.672164000897851; Mon, 24 Aug 2020 17:22:11 -0700 (PDT) Received: from localhost ([::1]:44874 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kAMj4-0004Kj-Lb for importer@patchew.org; Mon, 24 Aug 2020 20:22:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45198) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3mVhEXwsKClwBMECHH8GI8HAIIAF8.6IGK8GO-78P8FHIHAHO.ILA@flex--hskinnemoen.bounces.google.com>) id 1kAMec-00040E-I9 for qemu-devel@nongnu.org; Mon, 24 Aug 2020 20:17:34 -0400 Received: from mail-pj1-x104a.google.com ([2607:f8b0:4864:20::104a]:59668) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3mVhEXwsKClwBMECHH8GI8HAIIAF8.6IGK8GO-78P8FHIHAHO.ILA@flex--hskinnemoen.bounces.google.com>) id 1kAMeZ-00067I-F1 for qemu-devel@nongnu.org; Mon, 24 Aug 2020 20:17:34 -0400 Received: by mail-pj1-x104a.google.com with SMTP id lx6so420610pjb.9 for ; Mon, 24 Aug 2020 17:17:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc:content-transfer-encoding; bh=tXkgiwTbsbo2dG1AmnAh+6XnAGkL86RtqOGlQim3KOk=; b=l9H0YgcjZCXq2ECZCw/qMJYaiqvuEt2nGKJVigBDq71danRnTybymxmhfb2KWQZyv0 iep7zaLF5bbk+1HEY4g7GjQfQPOG/rJTMoiVyiz8J++UCoG/o0JCg2d9+3ZidZ/eXsiL qWGTX3Npml8RkTeMz/XHsJLj6Br2I67DsWIghbr9/K0I23vAL7s3PhznJdWjSg1oMd34 lREqVlcGWraQgbqOjko2W21umWqekcUp6H1eCfm7P4ZLhvBacuWEWuuJV+EsW3LAjLyd a/ORCBKdEQeocpD/6vB6zYtypkGNBxj8m6vzXnHhLJ2QWq8IM0czmFPATrIvi4dm5LW+ dkkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=tXkgiwTbsbo2dG1AmnAh+6XnAGkL86RtqOGlQim3KOk=; b=bkeAYDz8GIQMPViS4E2LxliQ0QN5PhNANfqHM4gE8xuHWyeoBVyC6A64Ps52XX6p/s gHHfLJy76tsF2EgVo5IJmt1Mg6AkbLSXWB6Gb1MGUh4BUGACxsGeD59Kpe0XsnZeZ4hW qMEixEpYrbIpTwTE2+wH66P/Ha9imSrWHyVp+5w+pr7BXJNt6P5ENNJNbI0TFCzyC1Ja uBfSAbxgX0RMtr765oBWAn4hB16PgRmpEavJkmIqAFkZe9KnlwsrZrsdqIc/Lv7zIHc6 QR496akB9/fbCHGm7NbmHdGYizZDY4tQ63iOpou4AW2K+/LKew9BxCLo2jPWXzM1IJe0 o3+g== X-Gm-Message-State: AOAM533fmMMRQDZtVrVhhoeZ4tgAWwN4v22nqMxX0jPO+HQj9B+/+WPR bys4g9IyfK6+DLrjirvGV/VZcPlNStm5eTk/yw== X-Google-Smtp-Source: ABdhPJyJP1YTqiQPSDOMxlu6mXMIAtkBhjMCXdPixlM/j25riYqBIGfZrXIJ8wGOD45TxP5w4kjaYlJu8jOIzIuoSA== X-Received: from skybert.c.googlers.com ([fda3:e722:ac3:10:24:72f4:c0a8:3107]) (user=hskinnemoen job=sendgmr) by 2002:a17:90a:cc03:: with SMTP id b3mr1387859pju.189.1598314649629; Mon, 24 Aug 2020 17:17:29 -0700 (PDT) Date: Mon, 24 Aug 2020 17:17:01 -0700 In-Reply-To: <20200825001711.1340443-1-hskinnemoen@google.com> Message-Id: <20200825001711.1340443-5-hskinnemoen@google.com> Mime-Version: 1.0 References: <20200825001711.1340443-1-hskinnemoen@google.com> X-Mailer: git-send-email 2.28.0.297.g1956fa8f8d-goog Subject: [PATCH v8 04/14] hw/arm: Add NPCM730 and NPCM750 SoC models To: peter.maydell@linaro.org, f4bug@amsat.org Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, Avi.Fishman@nuvoton.com, kfting@nuvoton.com, Havard Skinnemoen , Joel Stanley 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::104a; envelope-from=3mVhEXwsKClwBMECHH8GI8HAIIAF8.6IGK8GO-78P8FHIHAHO.ILA@flex--hskinnemoen.bounces.google.com; helo=mail-pj1-x104a.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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" Reply-to: Havard Skinnemoen From: Havard Skinnemoen via X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The Nuvoton NPCM7xx SoC family are used to implement Baseboard Management Controllers in servers. While the family includes four SoCs, this patch implements limited support for two of them: NPCM730 (targeted for Data Center applications) and NPCM750 (targeted for Enterprise applications). This patch includes little more than the bare minimum needed to boot a Linux kernel built with NPCM7xx support in direct-kernel mode: - Two Cortex-A9 CPU cores with built-in periperhals. - Global Configuration Registers. - Clock Management. - 3 Timer Modules with 5 timers each. - 4 serial ports. The chips themselves have a lot more features, some of which will be added to the model at a later stage. Reviewed-by: Tyrone Ting Reviewed-by: Joel Stanley Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Havard Skinnemoen Tested-by: Alexander Bulekov Tested-by: Philippe Mathieu-Daud=C3=A9 --- include/hw/arm/npcm7xx.h | 85 ++++++++ hw/arm/npcm7xx.c | 407 +++++++++++++++++++++++++++++++++++++++ hw/arm/Kconfig | 5 + hw/arm/meson.build | 1 + 4 files changed, 498 insertions(+) create mode 100644 include/hw/arm/npcm7xx.h create mode 100644 hw/arm/npcm7xx.c diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h new file mode 100644 index 0000000000..e68d9c79e6 --- /dev/null +++ b/include/hw/arm/npcm7xx.h @@ -0,0 +1,85 @@ +/* + * Nuvoton NPCM7xx SoC family. + * + * Copyright 2020 Google LLC + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WIT= HOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ +#ifndef NPCM7XX_H +#define NPCM7XX_H + +#include "hw/boards.h" +#include "hw/cpu/a9mpcore.h" +#include "hw/misc/npcm7xx_clk.h" +#include "hw/misc/npcm7xx_gcr.h" +#include "hw/timer/npcm7xx_timer.h" +#include "target/arm/cpu.h" + +#define NPCM7XX_MAX_NUM_CPUS (2) + +/* The first half of the address space is reserved for DDR4 DRAM. */ +#define NPCM7XX_DRAM_BA (0x00000000) +#define NPCM7XX_DRAM_SZ (2 * GiB) + +/* Magic addresses for setting up direct kernel booting and SMP boot stubs= . */ +#define NPCM7XX_LOADER_START (0x00000000) /* Start of SDRAM */ +#define NPCM7XX_SMP_LOADER_START (0xffff0000) /* Boot ROM */ +#define NPCM7XX_SMP_BOOTREG_ADDR (0xf080013c) /* GCR.SCRPAD */ +#define NPCM7XX_GIC_CPU_IF_ADDR (0xf03fe100) /* GIC within A9 */ + +typedef struct NPCM7xxState { + DeviceState parent; + + ARMCPU cpu[NPCM7XX_MAX_NUM_CPUS]; + A9MPPrivState a9mpcore; + + MemoryRegion sram; + MemoryRegion irom; + MemoryRegion ram3; + MemoryRegion *dram; + + NPCM7xxGCRState gcr; + NPCM7xxCLKState clk; + NPCM7xxTimerCtrlState tim[3]; +} NPCM7xxState; + +#define TYPE_NPCM7XX "npcm7xx" +#define NPCM7XX(obj) OBJECT_CHECK(NPCM7xxState, (obj), TYPE_NPCM7XX) + +#define TYPE_NPCM730 "npcm730" +#define TYPE_NPCM750 "npcm750" + +typedef struct NPCM7xxClass { + DeviceClass parent; + + /* Bitmask of modules that are permanently disabled on this chip. */ + uint32_t disabled_modules; + /* Number of CPU cores enabled in this SoC class (may be 1 or 2). */ + uint32_t num_cpus; +} NPCM7xxClass; + +#define NPCM7XX_CLASS(klass) \ + OBJECT_CLASS_CHECK(NPCM7xxClass, (klass), TYPE_NPCM7XX) +#define NPCM7XX_GET_CLASS(obj) \ + OBJECT_GET_CLASS(NPCM7xxClass, (obj), TYPE_NPCM7XX) + +/** + * npcm7xx_load_kernel - Loads memory with everything needed to boot + * @machine - The machine containing the SoC to be booted. + * @soc - The SoC containing the CPU to be booted. + * + * This will set up the ARM boot info structure for the specific NPCM7xx + * derivative and call arm_load_kernel() to set up loading of the kernel, = etc. + * into memory, if requested by the user. + */ +void npcm7xx_load_kernel(MachineState *machine, NPCM7xxState *soc); + +#endif /* NPCM7XX_H */ diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c new file mode 100644 index 0000000000..9669ac5fa0 --- /dev/null +++ b/hw/arm/npcm7xx.c @@ -0,0 +1,407 @@ +/* + * Nuvoton NPCM7xx SoC family. + * + * Copyright 2020 Google LLC + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WIT= HOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#include "qemu/osdep.h" + +#include "exec/address-spaces.h" +#include "hw/arm/boot.h" +#include "hw/arm/npcm7xx.h" +#include "hw/char/serial.h" +#include "hw/loader.h" +#include "hw/misc/unimp.h" +#include "hw/qdev-properties.h" +#include "qapi/error.h" +#include "qemu/units.h" +#include "sysemu/sysemu.h" + +/* + * This covers the whole MMIO space. We'll use this to catch any MMIO acce= sses + * that aren't handled by any device. + */ +#define NPCM7XX_MMIO_BA (0x80000000) +#define NPCM7XX_MMIO_SZ (0x7ffd0000) + +/* Core system modules. */ +#define NPCM7XX_L2C_BA (0xf03fc000) +#define NPCM7XX_CPUP_BA (0xf03fe000) +#define NPCM7XX_GCR_BA (0xf0800000) +#define NPCM7XX_CLK_BA (0xf0801000) + +/* Internal AHB SRAM */ +#define NPCM7XX_RAM3_BA (0xc0008000) +#define NPCM7XX_RAM3_SZ (4 * KiB) + +/* Memory blocks at the end of the address space */ +#define NPCM7XX_RAM2_BA (0xfffd0000) +#define NPCM7XX_RAM2_SZ (128 * KiB) +#define NPCM7XX_ROM_BA (0xffff0000) +#define NPCM7XX_ROM_SZ (64 * KiB) + +/* + * Interrupt lines going into the GIC. This does not include internal Cort= ex-A9 + * interrupts. + */ +enum NPCM7xxInterrupt { + NPCM7XX_UART0_IRQ =3D 2, + NPCM7XX_UART1_IRQ, + NPCM7XX_UART2_IRQ, + NPCM7XX_UART3_IRQ, + NPCM7XX_TIMER0_IRQ =3D 32, /* Timer Module 0 */ + NPCM7XX_TIMER1_IRQ, + NPCM7XX_TIMER2_IRQ, + NPCM7XX_TIMER3_IRQ, + NPCM7XX_TIMER4_IRQ, + NPCM7XX_TIMER5_IRQ, /* Timer Module 1 */ + NPCM7XX_TIMER6_IRQ, + NPCM7XX_TIMER7_IRQ, + NPCM7XX_TIMER8_IRQ, + NPCM7XX_TIMER9_IRQ, + NPCM7XX_TIMER10_IRQ, /* Timer Module 2 */ + NPCM7XX_TIMER11_IRQ, + NPCM7XX_TIMER12_IRQ, + NPCM7XX_TIMER13_IRQ, + NPCM7XX_TIMER14_IRQ, +}; + +/* Total number of GIC interrupts, including internal Cortex-A9 interrupts= . */ +#define NPCM7XX_NUM_IRQ (160) + +/* Register base address for each Timer Module */ +static const hwaddr npcm7xx_tim_addr[] =3D { + 0xf0008000, + 0xf0009000, + 0xf000a000, +}; + +/* Register base address for each 16550 UART */ +static const hwaddr npcm7xx_uart_addr[] =3D { + 0xf0001000, + 0xf0002000, + 0xf0003000, + 0xf0004000, +}; + +static void npcm7xx_write_secondary_boot(ARMCPU *cpu, + const struct arm_boot_info *info) +{ + /* + * The default smpboot stub halts the secondary CPU with a 'wfi' + * instruction, but the arch/arm/mach-npcm/platsmp.c in the Linux kern= el + * does not send an IPI to wake it up, so the second CPU fails to boot= . So + * we need to provide our own smpboot stub that can not use 'wfi', it = has + * to spin the secondary CPU until the first CPU writes to the SCRPAD = reg. + */ + uint32_t smpboot[] =3D { + 0xe59f2018, /* ldr r2, bootreg_addr */ + 0xe3a00000, /* mov r0, #0 */ + 0xe5820000, /* str r0, [r2] */ + 0xe320f002, /* wfe */ + 0xe5921000, /* ldr r1, [r2] */ + 0xe1110001, /* tst r1, r1 */ + 0x0afffffb, /* beq */ + 0xe12fff11, /* bx r1 */ + NPCM7XX_SMP_BOOTREG_ADDR, + }; + int i; + + for (i =3D 0; i < ARRAY_SIZE(smpboot); i++) { + smpboot[i] =3D tswap32(smpboot[i]); + } + + rom_add_blob_fixed("smpboot", smpboot, sizeof(smpboot), + NPCM7XX_SMP_LOADER_START); +} + +static struct arm_boot_info npcm7xx_binfo =3D { + .loader_start =3D NPCM7XX_LOADER_START, + .smp_loader_start =3D NPCM7XX_SMP_LOADER_START, + .smp_bootreg_addr =3D NPCM7XX_SMP_BOOTREG_ADDR, + .gic_cpu_if_addr =3D NPCM7XX_GIC_CPU_IF_ADDR, + .write_secondary_boot =3D npcm7xx_write_secondary_boot, + .board_id =3D -1, +}; + +void npcm7xx_load_kernel(MachineState *machine, NPCM7xxState *soc) +{ + NPCM7xxClass *sc =3D NPCM7XX_GET_CLASS(soc); + + npcm7xx_binfo.ram_size =3D machine->ram_size; + npcm7xx_binfo.nb_cpus =3D sc->num_cpus; + + arm_load_kernel(&soc->cpu[0], machine, &npcm7xx_binfo); +} + +static qemu_irq npcm7xx_irq(NPCM7xxState *s, int n) +{ + return qdev_get_gpio_in(DEVICE(&s->a9mpcore), n); +} + +static void npcm7xx_init(Object *obj) +{ + NPCM7xxState *s =3D NPCM7XX(obj); + int i; + + for (i =3D 0; i < NPCM7XX_MAX_NUM_CPUS; i++) { + object_initialize_child(obj, "cpu[*]", &s->cpu[i], + ARM_CPU_TYPE_NAME("cortex-a9")); + } + + object_initialize_child(obj, "a9mpcore", &s->a9mpcore, TYPE_A9MPCORE_P= RIV); + object_initialize_child(obj, "gcr", &s->gcr, TYPE_NPCM7XX_GCR); + object_property_add_alias(obj, "power-on-straps", OBJECT(&s->gcr), + "power-on-straps"); + object_initialize_child(obj, "clk", &s->clk, TYPE_NPCM7XX_CLK); + + for (i =3D 0; i < ARRAY_SIZE(s->tim); i++) { + object_initialize_child(obj, "tim[*]", &s->tim[i], TYPE_NPCM7XX_TI= MER); + } +} + +static void npcm7xx_realize(DeviceState *dev, Error **errp) +{ + NPCM7xxState *s =3D NPCM7XX(dev); + NPCM7xxClass *nc =3D NPCM7XX_GET_CLASS(s); + int i; + + if (memory_region_size(s->dram) > NPCM7XX_DRAM_SZ) { + error_setg(errp, "%s: NPCM7xx cannot address more than %" PRIu64 + " MiB of DRAM", __func__, NPCM7XX_DRAM_SZ / MiB); + return; + } + + /* CPUs */ + for (i =3D 0; i < nc->num_cpus; i++) { + object_property_set_int(OBJECT(&s->cpu[i]), "mp-affinity", + arm_cpu_mp_affinity(i, NPCM7XX_MAX_NUM_CPU= S), + &error_abort); + object_property_set_int(OBJECT(&s->cpu[i]), "reset-cbar", + NPCM7XX_GIC_CPU_IF_ADDR, &error_abort); + object_property_set_bool(OBJECT(&s->cpu[i]), "reset-hivecs", true, + &error_abort); + + /* Disable security extensions. */ + object_property_set_bool(OBJECT(&s->cpu[i]), "has_el3", false, + &error_abort); + + if (!qdev_realize(DEVICE(&s->cpu[i]), NULL, errp)) { + return; + } + } + + /* A9MPCORE peripherals. Can only fail if we pass bad parameters here.= */ + object_property_set_int(OBJECT(&s->a9mpcore), "num-cpu", nc->num_cpus, + &error_abort); + object_property_set_int(OBJECT(&s->a9mpcore), "num-irq", NPCM7XX_NUM_I= RQ, + &error_abort); + sysbus_realize(SYS_BUS_DEVICE(&s->a9mpcore), &error_abort); + sysbus_mmio_map(SYS_BUS_DEVICE(&s->a9mpcore), 0, NPCM7XX_CPUP_BA); + + for (i =3D 0; i < nc->num_cpus; i++) { + sysbus_connect_irq(SYS_BUS_DEVICE(&s->a9mpcore), i, + qdev_get_gpio_in(DEVICE(&s->cpu[i]), ARM_CPU_IR= Q)); + sysbus_connect_irq(SYS_BUS_DEVICE(&s->a9mpcore), i + nc->num_cpus, + qdev_get_gpio_in(DEVICE(&s->cpu[i]), ARM_CPU_FI= Q)); + } + + /* L2 cache controller */ + sysbus_create_simple("l2x0", NPCM7XX_L2C_BA, NULL); + + /* System Global Control Registers (GCR). Can fail due to user input. = */ + object_property_set_int(OBJECT(&s->gcr), "disabled-modules", + nc->disabled_modules, &error_abort); + object_property_add_const_link(OBJECT(&s->gcr), "dram-mr", OBJECT(s->d= ram)); + if (!sysbus_realize(SYS_BUS_DEVICE(&s->gcr), errp)) { + return; + } + sysbus_mmio_map(SYS_BUS_DEVICE(&s->gcr), 0, NPCM7XX_GCR_BA); + + /* Clock Control Registers (CLK). Cannot fail. */ + sysbus_realize(SYS_BUS_DEVICE(&s->clk), &error_abort); + sysbus_mmio_map(SYS_BUS_DEVICE(&s->clk), 0, NPCM7XX_CLK_BA); + + /* Timer Modules (TIM). Cannot fail. */ + QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_tim_addr) !=3D ARRAY_SIZE(s->tim)= ); + for (i =3D 0; i < ARRAY_SIZE(s->tim); i++) { + SysBusDevice *sbd =3D SYS_BUS_DEVICE(&s->tim[i]); + int first_irq; + int j; + + sysbus_realize(sbd, &error_abort); + sysbus_mmio_map(sbd, 0, npcm7xx_tim_addr[i]); + + first_irq =3D NPCM7XX_TIMER0_IRQ + i * NPCM7XX_TIMERS_PER_CTRL; + for (j =3D 0; j < NPCM7XX_TIMERS_PER_CTRL; j++) { + qemu_irq irq =3D npcm7xx_irq(s, first_irq + j); + sysbus_connect_irq(sbd, j, irq); + } + } + + /* UART0..3 (16550 compatible) */ + for (i =3D 0; i < ARRAY_SIZE(npcm7xx_uart_addr); i++) { + serial_mm_init(get_system_memory(), npcm7xx_uart_addr[i], 2, + npcm7xx_irq(s, NPCM7XX_UART0_IRQ + i), 115200, + serial_hd(i), DEVICE_LITTLE_ENDIAN); + } + + /* RAM2 (SRAM) */ + memory_region_init_ram(&s->sram, OBJECT(dev), "ram2", + NPCM7XX_RAM2_SZ, &error_abort); + memory_region_add_subregion(get_system_memory(), NPCM7XX_RAM2_BA, &s->= sram); + + /* RAM3 (SRAM) */ + memory_region_init_ram(&s->ram3, OBJECT(dev), "ram3", + NPCM7XX_RAM3_SZ, &error_abort); + memory_region_add_subregion(get_system_memory(), NPCM7XX_RAM3_BA, &s->= ram3); + + /* Internal ROM */ + memory_region_init_rom(&s->irom, OBJECT(dev), "irom", NPCM7XX_ROM_SZ, + &error_abort); + memory_region_add_subregion(get_system_memory(), NPCM7XX_ROM_BA, &s->i= rom); + + create_unimplemented_device("npcm7xx.shm", 0xc0001000, 4 * = KiB); + create_unimplemented_device("npcm7xx.vdmx", 0xe0800000, 4 * = KiB); + create_unimplemented_device("npcm7xx.pcierc", 0xe1000000, 64 * = KiB); + create_unimplemented_device("npcm7xx.kcs", 0xf0007000, 4 * = KiB); + create_unimplemented_device("npcm7xx.rng", 0xf000b000, 4 * = KiB); + create_unimplemented_device("npcm7xx.adc", 0xf000c000, 4 * = KiB); + create_unimplemented_device("npcm7xx.gfxi", 0xf000e000, 4 * = KiB); + create_unimplemented_device("npcm7xx.gpio[0]", 0xf0010000, 4 * = KiB); + create_unimplemented_device("npcm7xx.gpio[1]", 0xf0011000, 4 * = KiB); + create_unimplemented_device("npcm7xx.gpio[2]", 0xf0012000, 4 * = KiB); + create_unimplemented_device("npcm7xx.gpio[3]", 0xf0013000, 4 * = KiB); + create_unimplemented_device("npcm7xx.gpio[4]", 0xf0014000, 4 * = KiB); + create_unimplemented_device("npcm7xx.gpio[5]", 0xf0015000, 4 * = KiB); + create_unimplemented_device("npcm7xx.gpio[6]", 0xf0016000, 4 * = KiB); + create_unimplemented_device("npcm7xx.gpio[7]", 0xf0017000, 4 * = KiB); + create_unimplemented_device("npcm7xx.smbus[0]", 0xf0080000, 4 * = KiB); + create_unimplemented_device("npcm7xx.smbus[1]", 0xf0081000, 4 * = KiB); + create_unimplemented_device("npcm7xx.smbus[2]", 0xf0082000, 4 * = KiB); + create_unimplemented_device("npcm7xx.smbus[3]", 0xf0083000, 4 * = KiB); + create_unimplemented_device("npcm7xx.smbus[4]", 0xf0084000, 4 * = KiB); + create_unimplemented_device("npcm7xx.smbus[5]", 0xf0085000, 4 * = KiB); + create_unimplemented_device("npcm7xx.smbus[6]", 0xf0086000, 4 * = KiB); + create_unimplemented_device("npcm7xx.smbus[7]", 0xf0087000, 4 * = KiB); + create_unimplemented_device("npcm7xx.smbus[8]", 0xf0088000, 4 * = KiB); + create_unimplemented_device("npcm7xx.smbus[9]", 0xf0089000, 4 * = KiB); + create_unimplemented_device("npcm7xx.smbus[10]", 0xf008a000, 4 * = KiB); + create_unimplemented_device("npcm7xx.smbus[11]", 0xf008b000, 4 * = KiB); + create_unimplemented_device("npcm7xx.smbus[12]", 0xf008c000, 4 * = KiB); + create_unimplemented_device("npcm7xx.smbus[13]", 0xf008d000, 4 * = KiB); + create_unimplemented_device("npcm7xx.smbus[14]", 0xf008e000, 4 * = KiB); + create_unimplemented_device("npcm7xx.smbus[15]", 0xf008f000, 4 * = KiB); + create_unimplemented_device("npcm7xx.espi", 0xf009f000, 4 * = KiB); + create_unimplemented_device("npcm7xx.peci", 0xf0100000, 4 * = KiB); + create_unimplemented_device("npcm7xx.siox[1]", 0xf0101000, 4 * = KiB); + create_unimplemented_device("npcm7xx.siox[2]", 0xf0102000, 4 * = KiB); + create_unimplemented_device("npcm7xx.pwm[0]", 0xf0103000, 4 * = KiB); + create_unimplemented_device("npcm7xx.pwm[1]", 0xf0104000, 4 * = KiB); + create_unimplemented_device("npcm7xx.mft[0]", 0xf0180000, 4 * = KiB); + create_unimplemented_device("npcm7xx.mft[1]", 0xf0181000, 4 * = KiB); + create_unimplemented_device("npcm7xx.mft[2]", 0xf0182000, 4 * = KiB); + create_unimplemented_device("npcm7xx.mft[3]", 0xf0183000, 4 * = KiB); + create_unimplemented_device("npcm7xx.mft[4]", 0xf0184000, 4 * = KiB); + create_unimplemented_device("npcm7xx.mft[5]", 0xf0185000, 4 * = KiB); + create_unimplemented_device("npcm7xx.mft[6]", 0xf0186000, 4 * = KiB); + create_unimplemented_device("npcm7xx.mft[7]", 0xf0187000, 4 * = KiB); + create_unimplemented_device("npcm7xx.pspi1", 0xf0200000, 4 * = KiB); + create_unimplemented_device("npcm7xx.pspi2", 0xf0201000, 4 * = KiB); + create_unimplemented_device("npcm7xx.ahbpci", 0xf0400000, 1 * = MiB); + create_unimplemented_device("npcm7xx.mcphy", 0xf05f0000, 64 * = KiB); + create_unimplemented_device("npcm7xx.gmac1", 0xf0802000, 8 * = KiB); + create_unimplemented_device("npcm7xx.gmac2", 0xf0804000, 8 * = KiB); + create_unimplemented_device("npcm7xx.ehci", 0xf0806000, 4 * = KiB); + create_unimplemented_device("npcm7xx.ohci", 0xf0807000, 4 * = KiB); + create_unimplemented_device("npcm7xx.vcd", 0xf0810000, 64 * = KiB); + create_unimplemented_device("npcm7xx.ece", 0xf0820000, 8 * = KiB); + create_unimplemented_device("npcm7xx.vdma", 0xf0822000, 8 * = KiB); + create_unimplemented_device("npcm7xx.emc1", 0xf0825000, 4 * = KiB); + create_unimplemented_device("npcm7xx.emc2", 0xf0826000, 4 * = KiB); + create_unimplemented_device("npcm7xx.usbd[0]", 0xf0830000, 4 * = KiB); + create_unimplemented_device("npcm7xx.usbd[1]", 0xf0831000, 4 * = KiB); + create_unimplemented_device("npcm7xx.usbd[2]", 0xf0832000, 4 * = KiB); + create_unimplemented_device("npcm7xx.usbd[3]", 0xf0833000, 4 * = KiB); + create_unimplemented_device("npcm7xx.usbd[4]", 0xf0834000, 4 * = KiB); + create_unimplemented_device("npcm7xx.usbd[5]", 0xf0835000, 4 * = KiB); + create_unimplemented_device("npcm7xx.usbd[6]", 0xf0836000, 4 * = KiB); + create_unimplemented_device("npcm7xx.usbd[7]", 0xf0837000, 4 * = KiB); + create_unimplemented_device("npcm7xx.usbd[8]", 0xf0838000, 4 * = KiB); + create_unimplemented_device("npcm7xx.usbd[9]", 0xf0839000, 4 * = KiB); + create_unimplemented_device("npcm7xx.sd", 0xf0840000, 8 * = KiB); + create_unimplemented_device("npcm7xx.mmc", 0xf0842000, 8 * = KiB); + create_unimplemented_device("npcm7xx.pcimbx", 0xf0848000, 512 * = KiB); + create_unimplemented_device("npcm7xx.aes", 0xf0858000, 4 * = KiB); + create_unimplemented_device("npcm7xx.des", 0xf0859000, 4 * = KiB); + create_unimplemented_device("npcm7xx.sha", 0xf085a000, 4 * = KiB); + create_unimplemented_device("npcm7xx.secacc", 0xf085b000, 4 * = KiB); + create_unimplemented_device("npcm7xx.spixcs0", 0xf8000000, 16 * = MiB); + create_unimplemented_device("npcm7xx.spixcs1", 0xf9000000, 16 * = MiB); + create_unimplemented_device("npcm7xx.spix", 0xfb001000, 4 * = KiB); +} + +static Property npcm7xx_properties[] =3D { + DEFINE_PROP_LINK("dram-mr", NPCM7xxState, dram, TYPE_MEMORY_REGION, + MemoryRegion *), + DEFINE_PROP_END_OF_LIST(), +}; + +static void npcm7xx_class_init(ObjectClass *oc, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(oc); + + dc->realize =3D npcm7xx_realize; + dc->user_creatable =3D false; + device_class_set_props(dc, npcm7xx_properties); +} + +static void npcm730_class_init(ObjectClass *oc, void *data) +{ + NPCM7xxClass *nc =3D NPCM7XX_CLASS(oc); + + /* NPCM730 is optimized for data center use, so no graphics, etc. */ + nc->disabled_modules =3D 0x00300395; + nc->num_cpus =3D 2; +} + +static void npcm750_class_init(ObjectClass *oc, void *data) +{ + NPCM7xxClass *nc =3D NPCM7XX_CLASS(oc); + + /* NPCM750 has 2 cores and a full set of peripherals */ + nc->disabled_modules =3D 0x00000000; + nc->num_cpus =3D 2; +} + +static const TypeInfo npcm7xx_soc_types[] =3D { + { + .name =3D TYPE_NPCM7XX, + .parent =3D TYPE_DEVICE, + .instance_size =3D sizeof(NPCM7xxState), + .instance_init =3D npcm7xx_init, + .class_size =3D sizeof(NPCM7xxClass), + .class_init =3D npcm7xx_class_init, + .abstract =3D true, + }, { + .name =3D TYPE_NPCM730, + .parent =3D TYPE_NPCM7XX, + .class_init =3D npcm730_class_init, + }, { + .name =3D TYPE_NPCM750, + .parent =3D TYPE_NPCM7XX, + .class_init =3D npcm750_class_init, + }, +}; + +DEFINE_TYPES(npcm7xx_soc_types); diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig index 4aec9c63f8..cd74642034 100644 --- a/hw/arm/Kconfig +++ b/hw/arm/Kconfig @@ -357,6 +357,11 @@ config XLNX_VERSAL =20 config NPCM7XX bool + select A9MPCORE + select ARM_GIC + select PL310 # cache controller + select SERIAL + select UNIMP =20 config FSL_IMX25 bool diff --git a/hw/arm/meson.build b/hw/arm/meson.build index 1ae5e17eeb..b777a6ae39 100644 --- a/hw/arm/meson.build +++ b/hw/arm/meson.build @@ -13,6 +13,7 @@ arm_ss.add(when: 'CONFIG_MICROBIT', if_true: files('micro= bit.c')) arm_ss.add(when: 'CONFIG_MUSICPAL', if_true: files('musicpal.c')) arm_ss.add(when: 'CONFIG_NETDUINO2', if_true: files('netduino2.c')) arm_ss.add(when: 'CONFIG_NETDUINOPLUS2', if_true: files('netduinoplus2.c')) +arm_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx.c')) arm_ss.add(when: 'CONFIG_NSERIES', if_true: files('nseries.c')) arm_ss.add(when: 'CONFIG_SX1', if_true: files('omap_sx1.c')) arm_ss.add(when: 'CONFIG_CHEETAH', if_true: files('palm.c')) --=20 2.28.0.297.g1956fa8f8d-goog From nobody Sun May 19 05:51:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=1598314831; cv=none; d=zohomail.com; s=zohoarc; b=IowG6MW4eqRfpup1QNn+zNqlLlqYcAe+q0wOo61oeF2DyLMwxEn3sJpUGrO1jOLiG0GZLUXaIGYlZoy28J6Vh8yOLpZHcOJHSYLO28NhE+NQ7h76eQSEU4/q7u/TNizAyNV4DvwBISNZUGHi3AZ7TbNsKSm7bvq0PzqMoUY3sxE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598314831; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=PXi/bfcS56Gam/LYIPtMRq9bICGHWInBx1mGRvZqa8s=; b=V9sqXEvWUtMUp8dy2c8Xwe7ZcPi5Zk6r6ZHoNHVDl6oNAsBl/6UCv+bGh0zf49a49kRlEL0fxYhyzb1rWmF0jIvbV3rtSwC9DTxrkIxZuVTwFf9P2GLOL695awLNtRawKBpgyQSp5/vNenm5zH/RqwY/117bd6pt4/6TYz965bM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1598314831706441.86639205088; Mon, 24 Aug 2020 17:20:31 -0700 (PDT) Received: from localhost ([::1]:38036 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kAMhS-0001O8-C7 for importer@patchew.org; Mon, 24 Aug 2020 20:20:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45220) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3m1hEXwsKCl4DOGEJJAIKAJCKKCHA.8KIMAIQ-9ARAHJKJCJQ.KNC@flex--hskinnemoen.bounces.google.com>) id 1kAMed-00044J-Qs for qemu-devel@nongnu.org; Mon, 24 Aug 2020 20:17:35 -0400 Received: from mail-pg1-x549.google.com ([2607:f8b0:4864:20::549]:40967) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3m1hEXwsKCl4DOGEJJAIKAJCKKCHA.8KIMAIQ-9ARAHJKJCJQ.KNC@flex--hskinnemoen.bounces.google.com>) id 1kAMeb-00067a-EV for qemu-devel@nongnu.org; Mon, 24 Aug 2020 20:17:35 -0400 Received: by mail-pg1-x549.google.com with SMTP id k26so194016pgf.8 for ; Mon, 24 Aug 2020 17:17:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc:content-transfer-encoding; bh=PXi/bfcS56Gam/LYIPtMRq9bICGHWInBx1mGRvZqa8s=; b=hCgqXyktRhYu6qZMrCa+G/f1hSpfNiBdnsuL3BdLBewAy1y/oGOkBUFG2prlBYMDfJ awYl3BkB1PzbUXd7PZDV5dPQTxPOi/76Uwpp+UssDI5hCP7jyB1sq+c6ldXCTkWKX6Dk 85Acyyv4hGnjWSf+kZNa9s8uNUyhT0dqx3wFCwtyMRIyvRQe4T0N6MfKtP4OxUrB8vij LFSqtqVcEujvMpxcVtVjZ/iBrwoUOVZLlC4NB0ZTTiz3EsykGECp+dwMnhQ5Cn87G3ja hdsmGy0K8jYpxQb9giYs5MK8X7Cfb9s+g+bby06XsgF6MAUjEynT4twF7eVPAZxJAVcE chLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=PXi/bfcS56Gam/LYIPtMRq9bICGHWInBx1mGRvZqa8s=; b=nk2wrPYKBML2QmBpplcIOphj4vjwMgyGUOJ/tb5R3Dds/kKaXgSM+1t4n9fKfj17FR v6zOpe384WcKD/Xe3qp/keTxXxSCnGhkDJAptdxQJpzAnMQeTlYF2vJofw0sAljFMAJw FXeEQDGvodTIy4YXCCfdqOLqBloAfXF8JY581rJwL/h8HdhD/RCOJCmPzeLjd1WBV57a pgv7oid9vTI/oD2q05Gy906wsvoQWg38xs+RtoLgInxENamU9ZI+Zmo5PbQML/OinPVh E9b55g88uFpw2qrOU3EwPTZm8c4n0ZzurKlYwQLPEh/0s7+7K/PBgw9pvhcQcakwhMsR 7Yuw== X-Gm-Message-State: AOAM532bQPyNwGa7FDk2LmTORrCobVXR8CyH12IPD411u9yrI6HKPHpT ZAYgJcAY8Jkiy4ED3lH8BgtHEhWAOkjLcU5+vA== X-Google-Smtp-Source: ABdhPJxMvvgLNXgMCTbUg3o42rcf1evBIZlVu61cNNlXavtIcYsGZCkQS2Xz/834hptI5XXoFLQ9HB3KQVTQcmSk7g== X-Received: from skybert.c.googlers.com ([fda3:e722:ac3:10:24:72f4:c0a8:3107]) (user=hskinnemoen job=sendgmr) by 2002:aa7:81c1:: with SMTP id c1mr5767973pfn.203.1598314651308; Mon, 24 Aug 2020 17:17:31 -0700 (PDT) Date: Mon, 24 Aug 2020 17:17:02 -0700 In-Reply-To: <20200825001711.1340443-1-hskinnemoen@google.com> Message-Id: <20200825001711.1340443-6-hskinnemoen@google.com> Mime-Version: 1.0 References: <20200825001711.1340443-1-hskinnemoen@google.com> X-Mailer: git-send-email 2.28.0.297.g1956fa8f8d-goog Subject: [PATCH v8 05/14] hw/arm: Add two NPCM7xx-based machines To: peter.maydell@linaro.org, f4bug@amsat.org Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, Avi.Fishman@nuvoton.com, kfting@nuvoton.com, Havard Skinnemoen , Joel Stanley , "=?UTF-8?q?C=C3=A9dric=20Le=20Goater?=" 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::549; envelope-from=3m1hEXwsKCl4DOGEJJAIKAJCKKCHA.8KIMAIQ-9ARAHJKJCJQ.KNC@flex--hskinnemoen.bounces.google.com; helo=mail-pg1-x549.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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" Reply-to: Havard Skinnemoen From: Havard Skinnemoen via X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This adds two new machines, both supported by OpenBMC: - npcm750-evb: Nuvoton NPCM750 Evaluation Board. - quanta-gsj: A board with a NPCM730 chip. They rely on the NPCM7xx SoC device to do the heavy lifting. They are almost completely identical at the moment, apart from the SoC type, which currently only changes the reset contents of one register (GCR.MDLR), but they might grow apart a bit more as more functionality is added. Both machines can boot the Linux kernel into /bin/sh. Reviewed-by: Tyrone Ting Reviewed-by: Joel Stanley Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Havard Skinnemoen Tested-by: Alexander Bulekov Tested-by: Philippe Mathieu-Daud=C3=A9 --- default-configs/arm-softmmu.mak | 1 + include/hw/arm/npcm7xx.h | 19 +++++ hw/arm/npcm7xx_boards.c | 144 ++++++++++++++++++++++++++++++++ hw/arm/meson.build | 2 +- 4 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 hw/arm/npcm7xx_boards.c diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.= mak index 8fc09a4a51..9a94ebd0be 100644 --- a/default-configs/arm-softmmu.mak +++ b/default-configs/arm-softmmu.mak @@ -27,6 +27,7 @@ CONFIG_GUMSTIX=3Dy CONFIG_SPITZ=3Dy CONFIG_TOSA=3Dy CONFIG_Z2=3Dy +CONFIG_NPCM7XX=3Dy CONFIG_COLLIE=3Dy CONFIG_ASPEED_SOC=3Dy CONFIG_NETDUINO2=3Dy diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h index e68d9c79e6..ba7495869d 100644 --- a/include/hw/arm/npcm7xx.h +++ b/include/hw/arm/npcm7xx.h @@ -35,6 +35,25 @@ #define NPCM7XX_SMP_BOOTREG_ADDR (0xf080013c) /* GCR.SCRPAD */ #define NPCM7XX_GIC_CPU_IF_ADDR (0xf03fe100) /* GIC within A9 */ =20 +typedef struct NPCM7xxMachine { + MachineState parent; +} NPCM7xxMachine; + +#define TYPE_NPCM7XX_MACHINE MACHINE_TYPE_NAME("npcm7xx") +#define NPCM7XX_MACHINE(obj) \ + OBJECT_CHECK(NPCM7xxMachine, (obj), TYPE_NPCM7XX_MACHINE) + +typedef struct NPCM7xxMachineClass { + MachineClass parent; + + const char *soc_type; +} NPCM7xxMachineClass; + +#define NPCM7XX_MACHINE_CLASS(klass) \ + OBJECT_CLASS_CHECK(NPCM7xxMachineClass, (klass), TYPE_NPCM7XX_MACHINE) +#define NPCM7XX_MACHINE_GET_CLASS(obj) \ + OBJECT_GET_CLASS(NPCM7xxMachineClass, (obj), TYPE_NPCM7XX_MACHINE) + typedef struct NPCM7xxState { DeviceState parent; =20 diff --git a/hw/arm/npcm7xx_boards.c b/hw/arm/npcm7xx_boards.c new file mode 100644 index 0000000000..0b9dce2b35 --- /dev/null +++ b/hw/arm/npcm7xx_boards.c @@ -0,0 +1,144 @@ +/* + * Machine definitions for boards featuring an NPCM7xx SoC. + * + * Copyright 2020 Google LLC + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WIT= HOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#include "qemu/osdep.h" + +#include "hw/arm/npcm7xx.h" +#include "hw/core/cpu.h" +#include "qapi/error.h" +#include "qemu/units.h" + +#define NPCM750_EVB_POWER_ON_STRAPS 0x00001ff7 +#define QUANTA_GSJ_POWER_ON_STRAPS 0x00001fff + +static void npcm7xx_connect_dram(NPCM7xxState *soc, MemoryRegion *dram) +{ + memory_region_add_subregion(get_system_memory(), NPCM7XX_DRAM_BA, dram= ); + + object_property_set_link(OBJECT(soc), "dram-mr", OBJECT(dram), + &error_abort); +} + +static NPCM7xxState *npcm7xx_create_soc(MachineState *machine, + uint32_t hw_straps) +{ + NPCM7xxMachineClass *nmc =3D NPCM7XX_MACHINE_GET_CLASS(machine); + MachineClass *mc =3D &nmc->parent; + Object *obj; + + if (strcmp(machine->cpu_type, mc->default_cpu_type) !=3D 0) { + error_report("This board can only be used with %s", + mc->default_cpu_type); + exit(1); + } + + obj =3D object_new_with_props(nmc->soc_type, OBJECT(machine), "soc", + &error_abort, NULL); + object_property_set_uint(obj, "power-on-straps", hw_straps, &error_abo= rt); + + return NPCM7XX(obj); +} + +static void npcm750_evb_init(MachineState *machine) +{ + NPCM7xxState *soc; + + soc =3D npcm7xx_create_soc(machine, NPCM750_EVB_POWER_ON_STRAPS); + npcm7xx_connect_dram(soc, machine->ram); + qdev_realize(DEVICE(soc), NULL, &error_fatal); + + npcm7xx_load_kernel(machine, soc); +} + +static void quanta_gsj_init(MachineState *machine) +{ + NPCM7xxState *soc; + + soc =3D npcm7xx_create_soc(machine, QUANTA_GSJ_POWER_ON_STRAPS); + npcm7xx_connect_dram(soc, machine->ram); + qdev_realize(DEVICE(soc), NULL, &error_fatal); + + npcm7xx_load_kernel(machine, soc); +} + +static void npcm7xx_set_soc_type(NPCM7xxMachineClass *nmc, const char *typ= e) +{ + NPCM7xxClass *sc =3D NPCM7XX_CLASS(object_class_by_name(type)); + MachineClass *mc =3D MACHINE_CLASS(nmc); + + nmc->soc_type =3D type; + mc->default_cpus =3D mc->min_cpus =3D mc->max_cpus =3D sc->num_cpus; +} + +static void npcm7xx_machine_class_init(ObjectClass *oc, void *data) +{ + MachineClass *mc =3D MACHINE_CLASS(oc); + + mc->no_floppy =3D 1; + mc->no_cdrom =3D 1; + mc->no_parallel =3D 1; + mc->default_ram_id =3D "ram"; + mc->default_cpu_type =3D ARM_CPU_TYPE_NAME("cortex-a9"); +} + +/* + * Schematics: + * https://github.com/Nuvoton-Israel/nuvoton-info/blob/master/npcm7xx-pole= g/evaluation-board/board_deliverables/NPCM750x_EB_ver.A1.1_COMPLETE.pdf + */ +static void npcm750_evb_machine_class_init(ObjectClass *oc, void *data) +{ + NPCM7xxMachineClass *nmc =3D NPCM7XX_MACHINE_CLASS(oc); + MachineClass *mc =3D MACHINE_CLASS(oc); + + npcm7xx_set_soc_type(nmc, TYPE_NPCM750); + + mc->desc =3D "Nuvoton NPCM750 Evaluation Board (Cortex A9)"; + mc->init =3D npcm750_evb_init; + mc->default_ram_size =3D 512 * MiB; +}; + +static void gsj_machine_class_init(ObjectClass *oc, void *data) +{ + NPCM7xxMachineClass *nmc =3D NPCM7XX_MACHINE_CLASS(oc); + MachineClass *mc =3D MACHINE_CLASS(oc); + + npcm7xx_set_soc_type(nmc, TYPE_NPCM730); + + mc->desc =3D "Quanta GSJ (Cortex A9)"; + mc->init =3D quanta_gsj_init; + mc->default_ram_size =3D 512 * MiB; +}; + +static const TypeInfo npcm7xx_machine_types[] =3D { + { + .name =3D TYPE_NPCM7XX_MACHINE, + .parent =3D TYPE_MACHINE, + .instance_size =3D sizeof(NPCM7xxMachine), + .class_size =3D sizeof(NPCM7xxMachineClass), + .class_init =3D npcm7xx_machine_class_init, + .abstract =3D true, + }, { + .name =3D MACHINE_TYPE_NAME("npcm750-evb"), + .parent =3D TYPE_NPCM7XX_MACHINE, + .class_init =3D npcm750_evb_machine_class_init, + }, { + .name =3D MACHINE_TYPE_NAME("quanta-gsj"), + .parent =3D TYPE_NPCM7XX_MACHINE, + .class_init =3D gsj_machine_class_init, + }, +}; + +DEFINE_TYPES(npcm7xx_machine_types) diff --git a/hw/arm/meson.build b/hw/arm/meson.build index b777a6ae39..aa045d924a 100644 --- a/hw/arm/meson.build +++ b/hw/arm/meson.build @@ -13,7 +13,7 @@ arm_ss.add(when: 'CONFIG_MICROBIT', if_true: files('micro= bit.c')) arm_ss.add(when: 'CONFIG_MUSICPAL', if_true: files('musicpal.c')) arm_ss.add(when: 'CONFIG_NETDUINO2', if_true: files('netduino2.c')) arm_ss.add(when: 'CONFIG_NETDUINOPLUS2', if_true: files('netduinoplus2.c')) -arm_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx.c')) +arm_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx.c', 'npcm7xx_bo= ards.c')) arm_ss.add(when: 'CONFIG_NSERIES', if_true: files('nseries.c')) arm_ss.add(when: 'CONFIG_SX1', if_true: files('omap_sx1.c')) arm_ss.add(when: 'CONFIG_CHEETAH', if_true: files('palm.c')) --=20 2.28.0.297.g1956fa8f8d-goog From nobody Sun May 19 05:51:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=1598315044; cv=none; d=zohomail.com; s=zohoarc; b=n0eDIjtEVlC3/vQXvX9p2myTTrMOkEZ+H74ueQth3wBtVKr5DMeNSGvFmcQOkkdp7Z0SYFOHGdEfFPlfST0lL7ay+L/yRMlk/owCeYIl/FuYQUh0ZSSX8sMc+ehb7JC2ysyCC0cL6SzQ97Ii1+X+lpwaugieyxh5hyj+Pi72Cng= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598315044; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=uYevUGfZIkhvqGlY6GhgrWEQ7RdmB99+oEnNEV3tBGs=; b=byx3KgPXlb7SBS27tVh4LS6vWTq5dacdXv62ZamQ3AV88SawH4bZ+KSCfGEkLZYnI09sl9xOWMTD0ZYR3SNX6LGbfGn47ZejGuPDpZcMjrR7H4mgwhawi83sySCFz7wP+jKzE3M7Vfcsy5PqY69gnhK6kf6coKHCfio76rEd5oI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1598315044263461.0112120480943; Mon, 24 Aug 2020 17:24:04 -0700 (PDT) Received: from localhost ([::1]:52292 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kAMks-0007Hk-CL for importer@patchew.org; Mon, 24 Aug 2020 20:24:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45268) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3nVhEXwsKCmAFQIGLLCKMCLEMMEJC.AMKOCKS-BCTCJLMLELS.MPE@flex--hskinnemoen.bounces.google.com>) id 1kAMef-00049q-ME for qemu-devel@nongnu.org; Mon, 24 Aug 2020 20:17:37 -0400 Received: from mail-pf1-x449.google.com ([2607:f8b0:4864:20::449]:50142) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3nVhEXwsKCmAFQIGLLCKMCLEMMEJC.AMKOCKS-BCTCJLMLELS.MPE@flex--hskinnemoen.bounces.google.com>) id 1kAMed-00067x-Ma for qemu-devel@nongnu.org; Mon, 24 Aug 2020 20:17:37 -0400 Received: by mail-pf1-x449.google.com with SMTP id b189so2794082pfa.16 for ; Mon, 24 Aug 2020 17:17:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=uYevUGfZIkhvqGlY6GhgrWEQ7RdmB99+oEnNEV3tBGs=; b=rTFujelO8n3UIY+fUEawiRZWIni7QZwK/68yUCs56OA02Ge16a0PWpDtVpM+gdt/Xy vxFQAMZNKmIyz0RzHj8AJsk47zhuTPZxgP15Rq54jp4sZpj1xUXpkgdYghhe7kNPlQ7o zhpD777cTeDpKMIgFU+MixeiHDTExLzHU4IjXlA7u+LANgQlndc61VovXP0V1g4q0Zqo gYSKVutTrsjaFGhbwhfK2RAipXxFPZry9v73SkbrKWpLg42gzr+GgcMxCD/l1yaq7SgE RYJ5cnMMHFiT9AyFdcDHIJ0j8UYvTye4ymnMU8GkI2SraUCqFGucFwVP5izAfqXCMg7+ 9EfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=uYevUGfZIkhvqGlY6GhgrWEQ7RdmB99+oEnNEV3tBGs=; b=aj8hEiIwzp7S9X5VRFo69vUPDT2I4by0pc6UhNMStTAJpzqoGiGzWkeEZNp+prBgBl JRWAGXd3d7YAVQE5siOw7Zlus+0e0D+/2oMGgF3X5e1n7S2AWufkfQCvqObTXApVcNKi NG2IKPV4Pi9cVu7aHDx0RHUxFhxqXGdYScv14hgAqOKZCpiKL5DqxMauiJRaoSlnOqhJ ASMJCSr7dDvBYU86Tkz6wny3DkPCr1I3eDd94h0sWtDhhZziY4PiaCoZlk9z9yb1Zbrv /W77jy1D39uOYx8MImZ3VeV1UxSqdZqbmC7xxnd90yMd4htU6xG4tZKwXwRADHeMvw+w dEWw== X-Gm-Message-State: AOAM532XTtWw29XIocEzsrGNNEai2rw4mhiicd5grqEHeR1INMPJmPI2 bmr0tXzvgL3prAWnxS2sRdjGRJa6eq3D0iy4Zw== X-Google-Smtp-Source: ABdhPJw/PYp83jZjxZfJ3FNnuKF5SAp3AawKv4/q/UG0YbAt9ixPoIiS2uTSEBR/Q2aG3F42gnouWNfycBaOxFzTVg== X-Received: from skybert.c.googlers.com ([fda3:e722:ac3:10:24:72f4:c0a8:3107]) (user=hskinnemoen job=sendgmr) by 2002:a17:902:d905:: with SMTP id c5mr5493386plz.34.1598314653278; Mon, 24 Aug 2020 17:17:33 -0700 (PDT) Date: Mon, 24 Aug 2020 17:17:03 -0700 In-Reply-To: <20200825001711.1340443-1-hskinnemoen@google.com> Message-Id: <20200825001711.1340443-7-hskinnemoen@google.com> Mime-Version: 1.0 References: <20200825001711.1340443-1-hskinnemoen@google.com> X-Mailer: git-send-email 2.28.0.297.g1956fa8f8d-goog Subject: [PATCH v8 06/14] roms: Add virtual Boot ROM for NPCM7xx SoCs To: peter.maydell@linaro.org, f4bug@amsat.org Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, Avi.Fishman@nuvoton.com, kfting@nuvoton.com, Havard Skinnemoen Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::449; envelope-from=3nVhEXwsKCmAFQIGLLCKMCLEMMEJC.AMKOCKS-BCTCJLMLELS.MPE@flex--hskinnemoen.bounces.google.com; helo=mail-pf1-x449.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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" Reply-to: Havard Skinnemoen From: Havard Skinnemoen via X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This is a minimalistic boot ROM written specifically for use with QEMU. It supports loading the second-stage loader from SPI flash into RAM, SMP boot, and not much else. Signed-off-by: Havard Skinnemoen Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Alexander Bulekov Tested-by: Philippe Mathieu-Daud=C3=A9 --- Makefile | 1 + .gitmodules | 3 +++ MAINTAINERS | 2 ++ pc-bios/README | 6 ++++++ pc-bios/npcm7xx_bootrom.bin | Bin 0 -> 768 bytes roms/Makefile | 7 +++++++ roms/vbootrom | 1 + 7 files changed, 20 insertions(+) create mode 100644 pc-bios/npcm7xx_bootrom.bin create mode 160000 roms/vbootrom diff --git a/Makefile b/Makefile index 81794d5c34..08e9af3793 100644 --- a/Makefile +++ b/Makefile @@ -246,6 +246,7 @@ s390-ccw.img s390-netboot.img \ slof.bin skiboot.lid \ palcode-clipper \ u-boot.e500 u-boot-sam460-20100605.bin \ +npcm7xx_bootrom.bin \ qemu_vga.ndrv \ edk2-licenses.txt \ hppa-firmware.img \ diff --git a/.gitmodules b/.gitmodules index ce979398a8..9ffb9f3f4f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -61,3 +61,6 @@ [submodule "meson"] path =3D meson url =3D https://github.com/mesonbuild/meson/ +[submodule "roms/vbootrom"] + path =3D roms/vbootrom + url =3D https://github.com/google/vbootrom.git diff --git a/MAINTAINERS b/MAINTAINERS index 3f72250630..d71afedc20 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -756,6 +756,8 @@ L: qemu-arm@nongnu.org S: Supported F: hw/*/npcm7xx* F: include/hw/*/npcm7xx* +F: pc-bios/npcm7xx_bootrom.bin +F: roms/vbootrom =20 nSeries M: Andrzej Zaborowski diff --git a/pc-bios/README b/pc-bios/README index fa8b58b797..4d6297fca7 100644 --- a/pc-bios/README +++ b/pc-bios/README @@ -71,3 +71,9 @@ ("Simplified BSD License" or "FreeBSD License", SPDX: BSD-2-Clause). Ope= nSBI source code also contains code reused from other projects desribed here: https://github.com/riscv/opensbi/blob/master/ThirdPartyNotices.md. + +- npcm7xx_bootrom.bin is a simplified, free (Apache 2.0) boot ROM for Nuvo= ton + NPCM7xx BMC devices. It currently implements the bare minimum to load, p= arse, + initialize and run boot images stored in SPI flash, but may grow more + features over time as needed. The source code is available at: + https://github.com/google/vbootrom diff --git a/pc-bios/npcm7xx_bootrom.bin b/pc-bios/npcm7xx_bootrom.bin new file mode 100644 index 0000000000000000000000000000000000000000..38f89d1b97b0c2e133af2a9fbed= 0521be132065b GIT binary patch literal 768 zcmd5)JxClu6n-9S05p1#kf90Sj5Z(jG8}+)IZIp~iXK=3DT&)dL`%d-q*8aR#mq{7 z9`=3D6;Dr(H0ACe72R5x?!)^86Qj-X%{+!K9iZNA@*wkBAV&iZ(l^I9?!Gz=3DS2I_*1d zr+tTQDHjvyzKnw(hu00yX`u!FvC;DilBe_YlkeSUVHA-crNk+k jtiF_MudA Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1598314948287432.6862502907262; Mon, 24 Aug 2020 17:22:28 -0700 (PDT) Received: from localhost ([::1]:45636 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kAMjL-0004dO-2f for importer@patchew.org; Mon, 24 Aug 2020 20:22:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45270) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3nlhEXwsKCmEGRJHMMDLNDMFNNFKD.BNLPDLT-CDUDKMNMFMT.NQF@flex--hskinnemoen.bounces.google.com>) id 1kAMef-0004AY-UT for qemu-devel@nongnu.org; Mon, 24 Aug 2020 20:17:37 -0400 Received: from mail-qt1-x849.google.com ([2607:f8b0:4864:20::849]:56760) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3nlhEXwsKCmEGRJHMMDLNDMFNNFKD.BNLPDLT-CDUDKMNMFMT.NQF@flex--hskinnemoen.bounces.google.com>) id 1kAMee-00068B-4F for qemu-devel@nongnu.org; Mon, 24 Aug 2020 20:17:37 -0400 Received: by mail-qt1-x849.google.com with SMTP id d24so8118706qtg.23 for ; Mon, 24 Aug 2020 17:17:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc:content-transfer-encoding; bh=6BgkETAcTJ1Tm8Ekvmcx0mODyms04MyIwr14Jstxmpw=; b=rJvFlbz1MKK0e6w97fF74oGphSjk5uDVMdaN73C4E0YLsQihc5EbVHb3pVx7Bl/GYL QUh5D2VYpU3VjD2HB6EqApjN126oZJTlpA4ib3+tU3V4IZUXAokNjbmNBU02aheh0K/l slINJmutbPwzRJzMuEL5pEK5qLn9y06feya9kdcf6AC9cU3e+F2b4HNH0BXvrnR2IDvh FMGp8vCtaopX8q7u/CLWe/rMxySckIRuXEJIfUGpYIXO92QWprxVF9DGjcAC9DkaMXLQ veqMlaNKxrQGx29FwGYNlaE7iHlLKhkzoG2w7iy/Fn7RN5vqdcPFMHI3jvROTk9cbHr9 hPzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=6BgkETAcTJ1Tm8Ekvmcx0mODyms04MyIwr14Jstxmpw=; b=cKScYBsUSU8efZ7scyFCk8FSmtYuOoPfhmV/Hdf9g+7Ib76gmOybGkI3ajIeka6eb/ PELg94ed2TRwRygAyvOOLtm53qZ7/Nm3yLuKC9vDTsWAKY6kgTJ3HlSThFkLkFw25Ev4 1O7yYmRFKNt1lQjmoJ8eSJ4Jn4P3sxFEAPHTkPnrftvH5dDXARd37025dwCmdQSZBVJS 9Y7bHLlSg0txbuUJ22C2BWVNMrIrDpeVMKSk+Mli3kcKN+s1d1hkgZkHq1/wiiD8IeTw nmtwExz1Tn96A9uu5XgCivoGCHbf6JZlkdVbaMoHEWV1ZKF8GU3P3bX9mAbAa31erxYc E3bQ== X-Gm-Message-State: AOAM532sf4PdOJQvvHVS2pk18DmA+B9uuyDGXyIzTD+nacZMJcA4sPVe URdVcxluHrA9qQRDQHYjOa7AIVtprmIUP8MoEg== X-Google-Smtp-Source: ABdhPJw9SCvg2+05LgnpO11Buz0X2MQ7jNORQkNYR4JQBCOCq8OHI+RnKVnftGiAWJMknX0efrJAvjOgt1NWBuIp0w== X-Received: from skybert.c.googlers.com ([fda3:e722:ac3:10:24:72f4:c0a8:3107]) (user=hskinnemoen job=sendgmr) by 2002:a0c:ff06:: with SMTP id w6mr7437735qvt.61.1598314654879; Mon, 24 Aug 2020 17:17:34 -0700 (PDT) Date: Mon, 24 Aug 2020 17:17:04 -0700 In-Reply-To: <20200825001711.1340443-1-hskinnemoen@google.com> Message-Id: <20200825001711.1340443-8-hskinnemoen@google.com> Mime-Version: 1.0 References: <20200825001711.1340443-1-hskinnemoen@google.com> X-Mailer: git-send-email 2.28.0.297.g1956fa8f8d-goog Subject: [PATCH v8 07/14] hw/arm: Load -bios image as a boot ROM for npcm7xx To: peter.maydell@linaro.org, f4bug@amsat.org Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, Avi.Fishman@nuvoton.com, kfting@nuvoton.com, Havard Skinnemoen , "=?UTF-8?q?C=C3=A9dric=20Le=20Goater?=" 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::849; envelope-from=3nlhEXwsKCmEGRJHMMDLNDMFNNFKD.BNLPDLT-CDUDKMNMFMT.NQF@flex--hskinnemoen.bounces.google.com; helo=mail-qt1-x849.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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" Reply-to: Havard Skinnemoen From: Havard Skinnemoen via X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" If a -bios option is specified on the command line, load the image into the internal ROM memory region, which contains the first instructions run by the CPU after reset. If -bios is not specified, the vbootrom included with qemu is loaded by default. Reviewed-by: Tyrone Ting Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: Havard Skinnemoen Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Alexander Bulekov Tested-by: Philippe Mathieu-Daud=C3=A9 --- hw/arm/npcm7xx_boards.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/hw/arm/npcm7xx_boards.c b/hw/arm/npcm7xx_boards.c index 0b9dce2b35..b67e45e913 100644 --- a/hw/arm/npcm7xx_boards.c +++ b/hw/arm/npcm7xx_boards.c @@ -18,12 +18,43 @@ =20 #include "hw/arm/npcm7xx.h" #include "hw/core/cpu.h" +#include "hw/loader.h" #include "qapi/error.h" +#include "qemu-common.h" #include "qemu/units.h" +#include "sysemu/sysemu.h" =20 #define NPCM750_EVB_POWER_ON_STRAPS 0x00001ff7 #define QUANTA_GSJ_POWER_ON_STRAPS 0x00001fff =20 +static const char npcm7xx_default_bootrom[] =3D "npcm7xx_bootrom.bin"; + +static void npcm7xx_load_bootrom(MachineState *machine, NPCM7xxState *soc) +{ + g_autofree char *filename =3D NULL; + int ret; + + if (machine->kernel_filename) { + /* Don't load the bootrom if user requested direct kernel boot. */ + return; + } + + if (!bios_name) { + bios_name =3D npcm7xx_default_bootrom; + } + + filename =3D qemu_find_file(QEMU_FILE_TYPE_BIOS, bios_name); + if (!filename) { + error_report("Could not find ROM image '%s'", bios_name); + exit(1); + } + ret =3D load_image_mr(filename, &soc->irom); + if (ret < 0) { + error_report("Failed to load ROM image '%s'", filename); + exit(1); + } +} + static void npcm7xx_connect_dram(NPCM7xxState *soc, MemoryRegion *dram) { memory_region_add_subregion(get_system_memory(), NPCM7XX_DRAM_BA, dram= ); @@ -60,6 +91,7 @@ static void npcm750_evb_init(MachineState *machine) npcm7xx_connect_dram(soc, machine->ram); qdev_realize(DEVICE(soc), NULL, &error_fatal); =20 + npcm7xx_load_bootrom(machine, soc); npcm7xx_load_kernel(machine, soc); } =20 @@ -71,6 +103,7 @@ static void quanta_gsj_init(MachineState *machine) npcm7xx_connect_dram(soc, machine->ram); qdev_realize(DEVICE(soc), NULL, &error_fatal); =20 + npcm7xx_load_bootrom(machine, soc); npcm7xx_load_kernel(machine, soc); } =20 --=20 2.28.0.297.g1956fa8f8d-goog From nobody Sun May 19 05:51:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=1598315150; cv=none; d=zohomail.com; s=zohoarc; b=KwdAh+77Nv3CrhIBzVXuJsJSF0KFn/J+wAqooSF3aqVn8hsfzkqCqRQsVUfUgPghN/nyedT/8oo2GPqup0vzOMTkrcNuZISXpVXZiBtcv3/3hwwCpgwyuMUvpPB9G7H5DsDkWm/odnYsdBG9WLpI8WjBbHAy6dfIfmE6DNzp5G4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598315150; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=JwDpihp6kqw1uHhFvwp2iyjEqrKtOZu5n+Jr4qeAE2o=; b=lToKklSJJeKwBC1kFouKSGJpiSgl2tUF4HD2lf+XWLDXV9lMFpIefv80PKUC3DHLMUkaSIcTxORKXbrpETquMY3JWHW1gXmksbV5EeQgGW9gv+dS4DAeX7OaA3pdnVcR1G/P0IlJP8D91iyh+XWHvFDsa7osl1jLGhFhSfh1XpE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1598315150835706.938614142424; Mon, 24 Aug 2020 17:25:50 -0700 (PDT) Received: from localhost ([::1]:60298 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kAMmb-00027h-Go for importer@patchew.org; Mon, 24 Aug 2020 20:25:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45306) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3oFhEXwsKCmMITLJOOFNPFOHPPHMF.DPNRFNV-EFWFMOPOHOV.PSH@flex--hskinnemoen.bounces.google.com>) id 1kAMej-0004KO-Ab for qemu-devel@nongnu.org; Mon, 24 Aug 2020 20:17:41 -0400 Received: from mail-pf1-x449.google.com ([2607:f8b0:4864:20::449]:43133) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3oFhEXwsKCmMITLJOOFNPFOHPPHMF.DPNRFNV-EFWFMOPOHOV.PSH@flex--hskinnemoen.bounces.google.com>) id 1kAMeg-00068V-Du for qemu-devel@nongnu.org; Mon, 24 Aug 2020 20:17:41 -0400 Received: by mail-pf1-x449.google.com with SMTP id a73so7141654pfa.10 for ; Mon, 24 Aug 2020 17:17:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc:content-transfer-encoding; bh=JwDpihp6kqw1uHhFvwp2iyjEqrKtOZu5n+Jr4qeAE2o=; b=fEKH+tfnTZ41qowJuI/Kx5GCzupce7TgUpfTh37JdDoApAoDwy59Z2EaUlAet3880V 8WkiDR7dMw6Wt1HGQaGkCWRCsBuE/CN1ykGuOCTIGR4WH7KLqxptiDHukMhawTuS4YA7 eVlgfaJMrRhiolV6q/T+H8vcWDfKk4OF+luQ5K+B+080icwCA07YzcuKS4BAm6BpVuVD gG38uueKXTQseSlaGBdan/C+FuKD+P2e0iwiC+1V6N26RU+tj9UTkMty1cmupZGGS6PQ l8mq6MIafVm1adTGP+AVUQFMnm7XYzlUGjXvan92SgsUnxwgZPO08znCgdbC4onNeqbE doDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=JwDpihp6kqw1uHhFvwp2iyjEqrKtOZu5n+Jr4qeAE2o=; b=oKPz22tTQd+Ktq/gxyGDtM7mb/kxKSTQqu7q2VaB9Ny9CFPb4Rm50RPiK63mjLJnbE opq3+err7iO5ACkL0TwIxBvnms5yya/yjhKWCQ2cRZL7KUMI46qHyrUWtVK+JFaL+3Fn cM0h7psPdGFxVyjR0y5uodGrIKEnbKEwWWUQi5TYpvD6wkUWrFuuLs9ZH+9L1sMsswwa C6oIP4VSiHCSoHI/Eigrk7xYI4N8//bthbwSNP2WFI5XpST//IYahf204AArsGUtTBrx HI80oYjLrs4hq5Zn7T6H2H5OppwefobJ78uJJu6HCKgLmhECeiJY/p2A5Ayc78/hfl5P hxXA== X-Gm-Message-State: AOAM531sMy6fOD9pf+SS2y7fgqxXu5IVNxKGiGq9DEATDRZFRiqCjmju GUYr2jfa9lXVplfhB+uHkU7dfRMh6LOQW61e3g== X-Google-Smtp-Source: ABdhPJy3aDP/K0z+UTFXSU5ywBchEFYiralbap6ZrYe+nVuGjSAPlW0lp87K+JkpfrzDU619ZFuWcEKsZ8djxDLbyg== X-Received: from skybert.c.googlers.com ([fda3:e722:ac3:10:24:72f4:c0a8:3107]) (user=hskinnemoen job=sendgmr) by 2002:a17:902:ab96:: with SMTP id f22mr5555454plr.292.1598314656618; Mon, 24 Aug 2020 17:17:36 -0700 (PDT) Date: Mon, 24 Aug 2020 17:17:05 -0700 In-Reply-To: <20200825001711.1340443-1-hskinnemoen@google.com> Message-Id: <20200825001711.1340443-9-hskinnemoen@google.com> Mime-Version: 1.0 References: <20200825001711.1340443-1-hskinnemoen@google.com> X-Mailer: git-send-email 2.28.0.297.g1956fa8f8d-goog Subject: [PATCH v8 08/14] hw/nvram: NPCM7xx OTP device model To: peter.maydell@linaro.org, f4bug@amsat.org Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, Avi.Fishman@nuvoton.com, kfting@nuvoton.com, Havard Skinnemoen , Avi Fishman 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::449; envelope-from=3oFhEXwsKCmMITLJOOFNPFOHPPHMF.DPNRFNV-EFWFMOPOHOV.PSH@flex--hskinnemoen.bounces.google.com; helo=mail-pf1-x449.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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" Reply-to: Havard Skinnemoen From: Havard Skinnemoen via X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This supports reading and writing OTP fuses and keys. Only fuse reading has been tested. Protection is not implemented. Reviewed-by: Avi Fishman Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Havard Skinnemoen Tested-by: Alexander Bulekov Tested-by: Philippe Mathieu-Daud=C3=A9 --- include/hw/arm/npcm7xx.h | 3 + include/hw/nvram/npcm7xx_otp.h | 79 ++++++ hw/arm/npcm7xx.c | 29 +++ hw/nvram/npcm7xx_otp.c | 439 +++++++++++++++++++++++++++++++++ hw/nvram/meson.build | 1 + 5 files changed, 551 insertions(+) create mode 100644 include/hw/nvram/npcm7xx_otp.h create mode 100644 hw/nvram/npcm7xx_otp.c diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h index ba7495869d..5816a07a72 100644 --- a/include/hw/arm/npcm7xx.h +++ b/include/hw/arm/npcm7xx.h @@ -20,6 +20,7 @@ #include "hw/cpu/a9mpcore.h" #include "hw/misc/npcm7xx_clk.h" #include "hw/misc/npcm7xx_gcr.h" +#include "hw/nvram/npcm7xx_otp.h" #include "hw/timer/npcm7xx_timer.h" #include "target/arm/cpu.h" =20 @@ -68,6 +69,8 @@ typedef struct NPCM7xxState { NPCM7xxGCRState gcr; NPCM7xxCLKState clk; NPCM7xxTimerCtrlState tim[3]; + NPCM7xxOTPState key_storage; + NPCM7xxOTPState fuse_array; } NPCM7xxState; =20 #define TYPE_NPCM7XX "npcm7xx" diff --git a/include/hw/nvram/npcm7xx_otp.h b/include/hw/nvram/npcm7xx_otp.h new file mode 100644 index 0000000000..156bbd151a --- /dev/null +++ b/include/hw/nvram/npcm7xx_otp.h @@ -0,0 +1,79 @@ +/* + * Nuvoton NPCM7xx OTP (Fuse Array) Interface + * + * Copyright 2020 Google LLC + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WIT= HOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ +#ifndef NPCM7XX_OTP_H +#define NPCM7XX_OTP_H + +#include "exec/memory.h" +#include "hw/sysbus.h" + +/* Each OTP module holds 8192 bits of one-time programmable storage */ +#define NPCM7XX_OTP_ARRAY_BITS (8192) +#define NPCM7XX_OTP_ARRAY_BYTES (NPCM7XX_OTP_ARRAY_BITS / BITS_PER_BYTE) + +/* Fuse array offsets */ +#define NPCM7XX_FUSE_FUSTRAP (0) +#define NPCM7XX_FUSE_CP_FUSTRAP (12) +#define NPCM7XX_FUSE_DAC_CALIB (16) +#define NPCM7XX_FUSE_ADC_CALIB (24) +#define NPCM7XX_FUSE_DERIVATIVE (64) +#define NPCM7XX_FUSE_TEST_SIG (72) +#define NPCM7XX_FUSE_DIE_LOCATION (74) +#define NPCM7XX_FUSE_GP1 (80) +#define NPCM7XX_FUSE_GP2 (128) + +/* + * Number of registers in our device state structure. Don't change this wi= thout + * incrementing the version_id in the vmstate. + */ +#define NPCM7XX_OTP_NR_REGS (0x18 / sizeof(uint32_t)) + +/** + * struct NPCM7xxOTPState - Device state for one OTP module. + * @parent: System bus device. + * @mmio: Memory region through which registers are accessed. + * @regs: Register contents. + * @array: OTP storage array. + */ +typedef struct NPCM7xxOTPState { + SysBusDevice parent; + + MemoryRegion mmio; + uint32_t regs[NPCM7XX_OTP_NR_REGS]; + uint8_t array[NPCM7XX_OTP_ARRAY_BYTES]; +} NPCM7xxOTPState; + +#define TYPE_NPCM7XX_OTP "npcm7xx-otp" +#define NPCM7XX_OTP(obj) OBJECT_CHECK(NPCM7xxOTPState, (obj), TYPE_NPCM7XX= _OTP) + +#define TYPE_NPCM7XX_KEY_STORAGE "npcm7xx-key-storage" +#define TYPE_NPCM7XX_FUSE_ARRAY "npcm7xx-fuse-array" + +typedef struct NPCM7xxOTPClass NPCM7xxOTPClass; + +/** + * npcm7xx_otp_array_write - ECC encode and write data to OTP array. + * @s: OTP module. + * @data: Data to be encoded and written. + * @offset: Offset of first byte to be written in the OTP array. + * @len: Number of bytes before ECC encoding. + * + * Each nibble of data is encoded into a byte, so the number of bytes writ= ten + * to the array will be @len * 2. + */ +extern void npcm7xx_otp_array_write(NPCM7xxOTPState *s, const void *data, + unsigned int offset, unsigned int len); + +#endif /* NPCM7XX_OTP_H */ diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c index 9669ac5fa0..9166002598 100644 --- a/hw/arm/npcm7xx.c +++ b/hw/arm/npcm7xx.c @@ -34,6 +34,10 @@ #define NPCM7XX_MMIO_BA (0x80000000) #define NPCM7XX_MMIO_SZ (0x7ffd0000) =20 +/* OTP key storage and fuse strap array */ +#define NPCM7XX_OTP1_BA (0xf0189000) +#define NPCM7XX_OTP2_BA (0xf018a000) + /* Core system modules. */ #define NPCM7XX_L2C_BA (0xf03fc000) #define NPCM7XX_CPUP_BA (0xf03fe000) @@ -144,6 +148,20 @@ void npcm7xx_load_kernel(MachineState *machine, NPCM7x= xState *soc) arm_load_kernel(&soc->cpu[0], machine, &npcm7xx_binfo); } =20 +static void npcm7xx_init_fuses(NPCM7xxState *s) +{ + NPCM7xxClass *nc =3D NPCM7XX_GET_CLASS(s); + uint32_t value; + + /* + * The initial mask of disabled modules indicates the chip derivative = (e.g. + * NPCM750 or NPCM730). + */ + value =3D tswap32(nc->disabled_modules); + npcm7xx_otp_array_write(&s->fuse_array, &value, NPCM7XX_FUSE_DERIVATIV= E, + sizeof(value)); +} + static qemu_irq npcm7xx_irq(NPCM7xxState *s, int n) { return qdev_get_gpio_in(DEVICE(&s->a9mpcore), n); @@ -164,6 +182,10 @@ static void npcm7xx_init(Object *obj) object_property_add_alias(obj, "power-on-straps", OBJECT(&s->gcr), "power-on-straps"); object_initialize_child(obj, "clk", &s->clk, TYPE_NPCM7XX_CLK); + object_initialize_child(obj, "otp1", &s->key_storage, + TYPE_NPCM7XX_KEY_STORAGE); + object_initialize_child(obj, "otp2", &s->fuse_array, + TYPE_NPCM7XX_FUSE_ARRAY); =20 for (i =3D 0; i < ARRAY_SIZE(s->tim); i++) { object_initialize_child(obj, "tim[*]", &s->tim[i], TYPE_NPCM7XX_TI= MER); @@ -232,6 +254,13 @@ static void npcm7xx_realize(DeviceState *dev, Error **= errp) sysbus_realize(SYS_BUS_DEVICE(&s->clk), &error_abort); sysbus_mmio_map(SYS_BUS_DEVICE(&s->clk), 0, NPCM7XX_CLK_BA); =20 + /* OTP key storage and fuse strap array. Cannot fail. */ + sysbus_realize(SYS_BUS_DEVICE(&s->key_storage), &error_abort); + sysbus_mmio_map(SYS_BUS_DEVICE(&s->key_storage), 0, NPCM7XX_OTP1_BA); + sysbus_realize(SYS_BUS_DEVICE(&s->fuse_array), &error_abort); + sysbus_mmio_map(SYS_BUS_DEVICE(&s->fuse_array), 0, NPCM7XX_OTP2_BA); + npcm7xx_init_fuses(s); + /* Timer Modules (TIM). Cannot fail. */ QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_tim_addr) !=3D ARRAY_SIZE(s->tim)= ); for (i =3D 0; i < ARRAY_SIZE(s->tim); i++) { diff --git a/hw/nvram/npcm7xx_otp.c b/hw/nvram/npcm7xx_otp.c new file mode 100644 index 0000000000..ba4188ada8 --- /dev/null +++ b/hw/nvram/npcm7xx_otp.c @@ -0,0 +1,439 @@ +/* + * Nuvoton NPCM7xx OTP (Fuse Array) Interface + * + * Copyright 2020 Google LLC + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WIT= HOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#include "qemu/osdep.h" + +#include "hw/nvram/npcm7xx_otp.h" +#include "migration/vmstate.h" +#include "qapi/error.h" +#include "qemu/bitops.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qemu/units.h" + +/* Each module has 4 KiB of register space. Only a fraction of it is used.= */ +#define NPCM7XX_OTP_REGS_SIZE (4 * KiB) + +/* 32-bit register indices. */ +typedef enum NPCM7xxOTPRegister { + NPCM7XX_OTP_FST, + NPCM7XX_OTP_FADDR, + NPCM7XX_OTP_FDATA, + NPCM7XX_OTP_FCFG, + /* Offset 0x10 is FKEYIND in OTP1, FUSTRAP in OTP2 */ + NPCM7XX_OTP_FKEYIND =3D 0x0010 / sizeof(uint32_t), + NPCM7XX_OTP_FUSTRAP =3D 0x0010 / sizeof(uint32_t), + NPCM7XX_OTP_FCTL, + NPCM7XX_OTP_REGS_END, +} NPCM7xxOTPRegister; + +/* Register field definitions. */ +#define FST_RIEN BIT(2) +#define FST_RDST BIT(1) +#define FST_RDY BIT(0) +#define FST_RO_MASK (FST_RDST | FST_RDY) + +#define FADDR_BYTEADDR(rv) extract32((rv), 0, 10) +#define FADDR_BITPOS(rv) extract32((rv), 10, 3) + +#define FDATA_CLEAR 0x00000001 + +#define FCFG_FDIS BIT(31) +#define FCFG_FCFGLK_MASK 0x00ff0000 + +#define FCTL_PROG_CMD1 0x00000001 +#define FCTL_PROG_CMD2 0xbf79e5d0 +#define FCTL_READ_CMD 0x00000002 + +/** + * struct NPCM7xxOTPClass - OTP module class. + * @parent: System bus device class. + * @mmio_ops: MMIO register operations for this type of module. + * + * The two OTP modules (key-storage and fuse-array) have slightly different + * behavior, so we give them different MMIO register operations. + */ +struct NPCM7xxOTPClass { + SysBusDeviceClass parent; + + const MemoryRegionOps *mmio_ops; +}; + +#define NPCM7XX_OTP_CLASS(klass) \ + OBJECT_CLASS_CHECK(NPCM7xxOTPClass, (klass), TYPE_NPCM7XX_OTP) +#define NPCM7XX_OTP_GET_CLASS(obj) \ + OBJECT_GET_CLASS(NPCM7xxOTPClass, (obj), TYPE_NPCM7XX_OTP) + +static uint8_t ecc_encode_nibble(uint8_t n) +{ + uint8_t result =3D n; + + result |=3D (((n >> 0) & 1) ^ ((n >> 1) & 1)) << 4; + result |=3D (((n >> 2) & 1) ^ ((n >> 3) & 1)) << 5; + result |=3D (((n >> 0) & 1) ^ ((n >> 2) & 1)) << 6; + result |=3D (((n >> 1) & 1) ^ ((n >> 3) & 1)) << 7; + + return result; +} + +void npcm7xx_otp_array_write(NPCM7xxOTPState *s, const void *data, + unsigned int offset, unsigned int len) +{ + const uint8_t *src =3D data; + uint8_t *dst =3D &s->array[offset]; + + while (len-- > 0) { + uint8_t c =3D *src++; + + *dst++ =3D ecc_encode_nibble(extract8(c, 0, 4)); + *dst++ =3D ecc_encode_nibble(extract8(c, 4, 4)); + } +} + +/* Common register read handler for both OTP classes. */ +static uint64_t npcm7xx_otp_read(NPCM7xxOTPState *s, NPCM7xxOTPRegister re= g) +{ + uint32_t value =3D 0; + + switch (reg) { + case NPCM7XX_OTP_FST: + case NPCM7XX_OTP_FADDR: + case NPCM7XX_OTP_FDATA: + case NPCM7XX_OTP_FCFG: + value =3D s->regs[reg]; + break; + + case NPCM7XX_OTP_FCTL: + qemu_log_mask(LOG_GUEST_ERROR, + "%s: read from write-only FCTL register\n", + DEVICE(s)->canonical_path); + break; + + default: + qemu_log_mask(LOG_GUEST_ERROR, "%s: read from invalid offset 0x%zx= \n", + DEVICE(s)->canonical_path, reg * sizeof(uint32_t)); + break; + } + + return value; +} + +/* Read a byte from the OTP array into the data register. */ +static void npcm7xx_otp_read_array(NPCM7xxOTPState *s) +{ + uint32_t faddr =3D s->regs[NPCM7XX_OTP_FADDR]; + + s->regs[NPCM7XX_OTP_FDATA] =3D s->array[FADDR_BYTEADDR(faddr)]; + s->regs[NPCM7XX_OTP_FST] |=3D FST_RDST | FST_RDY; +} + +/* Program a byte from the data register into the OTP array. */ +static void npcm7xx_otp_program_array(NPCM7xxOTPState *s) +{ + uint32_t faddr =3D s->regs[NPCM7XX_OTP_FADDR]; + + /* Bits can only go 0->1, never 1->0. */ + s->array[FADDR_BYTEADDR(faddr)] |=3D (1U << FADDR_BITPOS(faddr)); + s->regs[NPCM7XX_OTP_FST] |=3D FST_RDST | FST_RDY; +} + +/* Compute the next value of the FCFG register. */ +static uint32_t npcm7xx_otp_compute_fcfg(uint32_t cur_value, uint32_t new_= value) +{ + uint32_t lock_mask; + uint32_t value; + + /* + * FCFGLK holds sticky bits 16..23, indicating which bits in FPRGLK (8= ..15) + * and FRDLK (0..7) that are read-only. + */ + lock_mask =3D (cur_value & FCFG_FCFGLK_MASK) >> 8; + lock_mask |=3D lock_mask >> 8; + /* FDIS and FCFGLK bits are sticky (write 1 to set; can't clear). */ + value =3D cur_value & (FCFG_FDIS | FCFG_FCFGLK_MASK); + /* Preserve read-only bits in FPRGLK and FRDLK */ + value |=3D cur_value & lock_mask; + /* Set all bits that aren't read-only. */ + value |=3D new_value & ~lock_mask; + + return value; +} + +/* Common register write handler for both OTP classes. */ +static void npcm7xx_otp_write(NPCM7xxOTPState *s, NPCM7xxOTPRegister reg, + uint32_t value) +{ + switch (reg) { + case NPCM7XX_OTP_FST: + /* RDST is cleared by writing 1 to it. */ + if (value & FST_RDST) { + s->regs[NPCM7XX_OTP_FST] &=3D ~FST_RDST; + } + /* Preserve read-only and write-one-to-clear bits */ + value &=3D ~FST_RO_MASK; + value |=3D s->regs[NPCM7XX_OTP_FST] & FST_RO_MASK; + break; + + case NPCM7XX_OTP_FADDR: + break; + + case NPCM7XX_OTP_FDATA: + /* + * This register is cleared by writing a magic value to it; no oth= er + * values can be written. + */ + if (value =3D=3D FDATA_CLEAR) { + value =3D 0; + } else { + value =3D s->regs[NPCM7XX_OTP_FDATA]; + } + break; + + case NPCM7XX_OTP_FCFG: + value =3D npcm7xx_otp_compute_fcfg(s->regs[NPCM7XX_OTP_FCFG], valu= e); + break; + + case NPCM7XX_OTP_FCTL: + switch (value) { + case FCTL_READ_CMD: + npcm7xx_otp_read_array(s); + break; + + case FCTL_PROG_CMD1: + /* + * Programming requires writing two separate magic values to t= his + * register; this is the first one. Just store it so it can be + * verified later when the second magic value is received. + */ + break; + + case FCTL_PROG_CMD2: + /* + * Only initiate programming if we received the first half of = the + * command immediately before this one. + */ + if (s->regs[NPCM7XX_OTP_FCTL] =3D=3D FCTL_PROG_CMD1) { + npcm7xx_otp_program_array(s); + } + break; + + default: + qemu_log_mask(LOG_GUEST_ERROR, + "%s: unrecognized FCNTL value 0x%" PRIx32 "\n", + DEVICE(s)->canonical_path, value); + break; + } + if (value !=3D FCTL_PROG_CMD1) { + value =3D 0; + } + break; + + default: + qemu_log_mask(LOG_GUEST_ERROR, "%s: write to invalid offset 0x%zx\= n", + DEVICE(s)->canonical_path, reg * sizeof(uint32_t)); + return; + } + + s->regs[reg] =3D value; +} + +/* Register read handler specific to the fuse array OTP module. */ +static uint64_t npcm7xx_fuse_array_read(void *opaque, hwaddr addr, + unsigned int size) +{ + NPCM7xxOTPRegister reg =3D addr / sizeof(uint32_t); + NPCM7xxOTPState *s =3D opaque; + uint32_t value; + + /* + * Only the Fuse Strap register needs special handling; all other regi= sters + * work the same way for both kinds of OTP modules. + */ + if (reg !=3D NPCM7XX_OTP_FUSTRAP) { + value =3D npcm7xx_otp_read(s, reg); + } else { + /* FUSTRAP is stored as three copies in the OTP array. */ + uint32_t fustrap[3]; + + memcpy(fustrap, &s->array[0], sizeof(fustrap)); + + /* Determine value by a majority vote on each bit. */ + value =3D (fustrap[0] & fustrap[1]) | (fustrap[0] & fustrap[2]) | + (fustrap[1] & fustrap[2]); + } + + return value; +} + +/* Register write handler specific to the fuse array OTP module. */ +static void npcm7xx_fuse_array_write(void *opaque, hwaddr addr, uint64_t v, + unsigned int size) +{ + NPCM7xxOTPRegister reg =3D addr / sizeof(uint32_t); + NPCM7xxOTPState *s =3D opaque; + + /* + * The Fuse Strap register is read-only. Other registers are handled by + * common code. + */ + if (reg !=3D NPCM7XX_OTP_FUSTRAP) { + npcm7xx_otp_write(s, reg, v); + } +} + +static const MemoryRegionOps npcm7xx_fuse_array_ops =3D { + .read =3D npcm7xx_fuse_array_read, + .write =3D npcm7xx_fuse_array_write, + .endianness =3D DEVICE_LITTLE_ENDIAN, + .valid =3D { + .min_access_size =3D 4, + .max_access_size =3D 4, + .unaligned =3D false, + }, +}; + +/* Register read handler specific to the key storage OTP module. */ +static uint64_t npcm7xx_key_storage_read(void *opaque, hwaddr addr, + unsigned int size) +{ + NPCM7xxOTPRegister reg =3D addr / sizeof(uint32_t); + NPCM7xxOTPState *s =3D opaque; + + /* + * Only the Fuse Key Index register needs special handling; all other + * registers work the same way for both kinds of OTP modules. + */ + if (reg !=3D NPCM7XX_OTP_FKEYIND) { + return npcm7xx_otp_read(s, reg); + } + + qemu_log_mask(LOG_UNIMP, "%s: FKEYIND is not implemented\n", __func__); + + return s->regs[NPCM7XX_OTP_FKEYIND]; +} + +/* Register write handler specific to the key storage OTP module. */ +static void npcm7xx_key_storage_write(void *opaque, hwaddr addr, uint64_t = v, + unsigned int size) +{ + NPCM7xxOTPRegister reg =3D addr / sizeof(uint32_t); + NPCM7xxOTPState *s =3D opaque; + + /* + * Only the Fuse Key Index register needs special handling; all other + * registers work the same way for both kinds of OTP modules. + */ + if (reg !=3D NPCM7XX_OTP_FKEYIND) { + npcm7xx_otp_write(s, reg, v); + return; + } + + qemu_log_mask(LOG_UNIMP, "%s: FKEYIND is not implemented\n", __func__); + + s->regs[NPCM7XX_OTP_FKEYIND] =3D v; +} + +static const MemoryRegionOps npcm7xx_key_storage_ops =3D { + .read =3D npcm7xx_key_storage_read, + .write =3D npcm7xx_key_storage_write, + .endianness =3D DEVICE_LITTLE_ENDIAN, + .valid =3D { + .min_access_size =3D 4, + .max_access_size =3D 4, + .unaligned =3D false, + }, +}; + +static void npcm7xx_otp_enter_reset(Object *obj, ResetType type) +{ + NPCM7xxOTPState *s =3D NPCM7XX_OTP(obj); + + memset(s->regs, 0, sizeof(s->regs)); + + s->regs[NPCM7XX_OTP_FST] =3D 0x00000001; + s->regs[NPCM7XX_OTP_FCFG] =3D 0x20000000; +} + +static void npcm7xx_otp_realize(DeviceState *dev, Error **errp) +{ + NPCM7xxOTPClass *oc =3D NPCM7XX_OTP_GET_CLASS(dev); + NPCM7xxOTPState *s =3D NPCM7XX_OTP(dev); + SysBusDevice *sbd =3D &s->parent; + + memset(s->array, 0, sizeof(s->array)); + + memory_region_init_io(&s->mmio, OBJECT(s), oc->mmio_ops, s, "regs", + NPCM7XX_OTP_REGS_SIZE); + sysbus_init_mmio(sbd, &s->mmio); +} + +static const VMStateDescription vmstate_npcm7xx_otp =3D { + .name =3D "npcm7xx-otp", + .version_id =3D 0, + .minimum_version_id =3D 0, + .fields =3D (VMStateField[]) { + VMSTATE_UINT32_ARRAY(regs, NPCM7xxOTPState, NPCM7XX_OTP_NR_REGS), + VMSTATE_UINT8_ARRAY(array, NPCM7xxOTPState, NPCM7XX_OTP_ARRAY_BYTE= S), + VMSTATE_END_OF_LIST(), + }, +}; + +static void npcm7xx_otp_class_init(ObjectClass *klass, void *data) +{ + ResettableClass *rc =3D RESETTABLE_CLASS(klass); + DeviceClass *dc =3D DEVICE_CLASS(klass); + + QEMU_BUILD_BUG_ON(NPCM7XX_OTP_REGS_END > NPCM7XX_OTP_NR_REGS); + + dc->realize =3D npcm7xx_otp_realize; + dc->vmsd =3D &vmstate_npcm7xx_otp; + rc->phases.enter =3D npcm7xx_otp_enter_reset; +} + +static void npcm7xx_key_storage_class_init(ObjectClass *klass, void *data) +{ + NPCM7xxOTPClass *oc =3D NPCM7XX_OTP_CLASS(klass); + + oc->mmio_ops =3D &npcm7xx_key_storage_ops; +} + +static void npcm7xx_fuse_array_class_init(ObjectClass *klass, void *data) +{ + NPCM7xxOTPClass *oc =3D NPCM7XX_OTP_CLASS(klass); + + oc->mmio_ops =3D &npcm7xx_fuse_array_ops; +} + +static const TypeInfo npcm7xx_otp_types[] =3D { + { + .name =3D TYPE_NPCM7XX_OTP, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(NPCM7xxOTPState), + .class_init =3D npcm7xx_otp_class_init, + .abstract =3D true, + }, + { + .name =3D TYPE_NPCM7XX_KEY_STORAGE, + .parent =3D TYPE_NPCM7XX_OTP, + .class_init =3D npcm7xx_key_storage_class_init, + }, + { + .name =3D TYPE_NPCM7XX_FUSE_ARRAY, + .parent =3D TYPE_NPCM7XX_OTP, + .class_init =3D npcm7xx_fuse_array_class_init, + }, +}; +DEFINE_TYPES(npcm7xx_otp_types); diff --git a/hw/nvram/meson.build b/hw/nvram/meson.build index ba214558ac..1f2ed013b2 100644 --- a/hw/nvram/meson.build +++ b/hw/nvram/meson.build @@ -4,6 +4,7 @@ softmmu_ss.add(when: 'CONFIG_DS1225Y', if_true: files('ds12= 25y.c')) softmmu_ss.add(when: 'CONFIG_NMC93XX_EEPROM', if_true: files('eeprom93xx.c= ')) softmmu_ss.add(when: 'CONFIG_AT24C', if_true: files('eeprom_at24c.c')) softmmu_ss.add(when: 'CONFIG_MAC_NVRAM', if_true: files('mac_nvram.c')) +softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_otp.c')) softmmu_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('nrf51_nvm.c')) =20 specific_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr_nvram.c')) --=20 2.28.0.297.g1956fa8f8d-goog From nobody Sun May 19 05:51:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=1598314848; cv=none; d=zohomail.com; s=zohoarc; b=AO5MQyaFIdkqdQSbty2kjp/6MQuDcD0YBgnkb/kPx6H1OhSn2EYWZyLpIIl5/IkT3n/BZSeVOu1ZepnOBrnAitzkRZsyG/gXw4iqeGoISkcTIu8l4Q6hahFn475uAOseQZG7NCkZ1lhcGIGrzj9X+96MeUHLv6uwO+6w+rXs2QA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598314848; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=EjZpIuq+eVTSZ1GsEJOqpPj5iZwCnZXTRJVF6pR0tIM=; b=N0CrnB0WYSAOUiw3Ou1ONKVgJggPrno1GoWriP2BMjvfHTJHFfFWmRUexO2Mp99ETnm9u493xuK+ctWSu3YGntXGo3xp/sOWUjRsuNu+6oZYYkon9m3cnpWVmDt0u1KzlSizI+sfDj0UWn9A+d8/vcwR5/JiDpJPhTbh+Kyy8WU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1598314848304667.0486363759638; Mon, 24 Aug 2020 17:20:48 -0700 (PDT) Received: from localhost ([::1]:38860 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kAMhi-0001iL-Vj for importer@patchew.org; Mon, 24 Aug 2020 20:20:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45334) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3olhEXwsKCmUKVNLQQHPRHQJRRJOH.FRPTHPX-GHYHOQRQJQX.RUJ@flex--hskinnemoen.bounces.google.com>) id 1kAMel-0004PE-6b for qemu-devel@nongnu.org; Mon, 24 Aug 2020 20:17:44 -0400 Received: from mail-pg1-x549.google.com ([2607:f8b0:4864:20::549]:44295) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3olhEXwsKCmUKVNLQQHPRHQJRRJOH.FRPTHPX-GHYHOQRQJQX.RUJ@flex--hskinnemoen.bounces.google.com>) id 1kAMei-00068q-4h for qemu-devel@nongnu.org; Mon, 24 Aug 2020 20:17:42 -0400 Received: by mail-pg1-x549.google.com with SMTP id 130so6390113pga.11 for ; Mon, 24 Aug 2020 17:17:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc:content-transfer-encoding; bh=EjZpIuq+eVTSZ1GsEJOqpPj5iZwCnZXTRJVF6pR0tIM=; b=l3xl0wwEINXdhet4BFyHtkdecAb/TJZrtYNoZtvy07CtiXy6WHDMvTqNfb1VQJqw2t bDlxjvD82e1dzYN1oJFmJD7EQErqsx6IW+HwP0yZ8473YnKwfE0JAsj5jZhI9TguoaM/ bYtVXjsk4+NZUWHriBrPYkc+zNVNZKs79is7fX/cTQeT7MmTEn8U64bUmxGtGT8wZ8Qg lWziRN7VGqB8SWTSNMZmjJRanV+AJH/QZ3ONnZt48Ex42YZqINHJr1KVk46wxRvP+MLu QZaqJHs1BQFixmxiHvniD46Zdty6urxwldnzAOgCSxnvevCyOnnSdzG9iJat5swdP3y5 YHGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=EjZpIuq+eVTSZ1GsEJOqpPj5iZwCnZXTRJVF6pR0tIM=; b=YKZLBVX7WpysR5iAnt2rs9cqw6Exz8q2s18lAuod+bEIhmKxjgP0X7GkLVknKmUldV srS9fxCnHJ8DFxaKxodhKEoKWQ+LWLr2X7dBC9sMiqItljSGwdfpv5oBg1dl24RCzry8 hdcY6c2DSSVLV0MkMYnA10mqxUc27vw/J7LiijWhirKqao0z7P6amzOGFr+JKhMgMr0m 4yW0zIYBaUiwsYv1bF5NKBSDvRDey1hO9mEaxw7c3lnrOruhZk9AhIf+oRp0HCY1VrL2 oLTnP+NUqGSVdRKPHyvmg/+9xGomkgujQjw2v8QoLAw3TuQEvjaBu+SpGlMOGUwwcWig Py9A== X-Gm-Message-State: AOAM531csFIkfkl4wFbk6sMRXKRsvVPkrSgq2R02aJlYbR771gPRpw0x uwS6RicaNwdl8enwOnOdezl2mAlKUpU2YgJfZg== X-Google-Smtp-Source: ABdhPJz9orohdTYyuMwWORjpdxAnGiC1rAZsY4uMT1vLYM1PT1qHiRJ5iuso/HqGXubegTCsOXDXdAhe82+TPPuZZQ== X-Received: from skybert.c.googlers.com ([fda3:e722:ac3:10:24:72f4:c0a8:3107]) (user=hskinnemoen job=sendgmr) by 2002:a63:d907:: with SMTP id r7mr4914299pgg.160.1598314658166; Mon, 24 Aug 2020 17:17:38 -0700 (PDT) Date: Mon, 24 Aug 2020 17:17:06 -0700 In-Reply-To: <20200825001711.1340443-1-hskinnemoen@google.com> Message-Id: <20200825001711.1340443-10-hskinnemoen@google.com> Mime-Version: 1.0 References: <20200825001711.1340443-1-hskinnemoen@google.com> X-Mailer: git-send-email 2.28.0.297.g1956fa8f8d-goog Subject: [PATCH v8 09/14] hw/mem: Stubbed out NPCM7xx Memory Controller model To: peter.maydell@linaro.org, f4bug@amsat.org Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, Avi.Fishman@nuvoton.com, kfting@nuvoton.com, Havard Skinnemoen , "=?UTF-8?q?C=C3=A9dric=20Le=20Goater?=" 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::549; envelope-from=3olhEXwsKCmUKVNLQQHPRHQJRRJOH.FRPTHPX-GHYHOQRQJQX.RUJ@flex--hskinnemoen.bounces.google.com; helo=mail-pg1-x549.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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" Reply-to: Havard Skinnemoen From: Havard Skinnemoen via X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This just implements the bare minimum to cause the boot block to skip memory initialization. Reviewed-by: Tyrone Ting Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Havard Skinnemoen Tested-by: Alexander Bulekov Tested-by: Philippe Mathieu-Daud=C3=A9 --- include/hw/arm/npcm7xx.h | 2 + include/hw/mem/npcm7xx_mc.h | 36 ++++++++++++++++ hw/arm/npcm7xx.c | 6 +++ hw/mem/npcm7xx_mc.c | 84 +++++++++++++++++++++++++++++++++++++ hw/mem/meson.build | 1 + 5 files changed, 129 insertions(+) create mode 100644 include/hw/mem/npcm7xx_mc.h create mode 100644 hw/mem/npcm7xx_mc.c diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h index 5816a07a72..9fa84a0702 100644 --- a/include/hw/arm/npcm7xx.h +++ b/include/hw/arm/npcm7xx.h @@ -18,6 +18,7 @@ =20 #include "hw/boards.h" #include "hw/cpu/a9mpcore.h" +#include "hw/mem/npcm7xx_mc.h" #include "hw/misc/npcm7xx_clk.h" #include "hw/misc/npcm7xx_gcr.h" #include "hw/nvram/npcm7xx_otp.h" @@ -71,6 +72,7 @@ typedef struct NPCM7xxState { NPCM7xxTimerCtrlState tim[3]; NPCM7xxOTPState key_storage; NPCM7xxOTPState fuse_array; + NPCM7xxMCState mc; } NPCM7xxState; =20 #define TYPE_NPCM7XX "npcm7xx" diff --git a/include/hw/mem/npcm7xx_mc.h b/include/hw/mem/npcm7xx_mc.h new file mode 100644 index 0000000000..7ed38be243 --- /dev/null +++ b/include/hw/mem/npcm7xx_mc.h @@ -0,0 +1,36 @@ +/* + * Nuvoton NPCM7xx Memory Controller stub + * + * Copyright 2020 Google LLC + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WIT= HOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ +#ifndef NPCM7XX_MC_H +#define NPCM7XX_MC_H + +#include "exec/memory.h" +#include "hw/sysbus.h" + +/** + * struct NPCM7xxMCState - Device state for the memory controller. + * @parent: System bus device. + * @mmio: Memory region through which registers are accessed. + */ +typedef struct NPCM7xxMCState { + SysBusDevice parent; + + MemoryRegion mmio; +} NPCM7xxMCState; + +#define TYPE_NPCM7XX_MC "npcm7xx-mc" +#define NPCM7XX_MC(obj) OBJECT_CHECK(NPCM7xxMCState, (obj), TYPE_NPCM7XX_M= C) + +#endif /* NPCM7XX_MC_H */ diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c index 9166002598..6bb1693833 100644 --- a/hw/arm/npcm7xx.c +++ b/hw/arm/npcm7xx.c @@ -43,6 +43,7 @@ #define NPCM7XX_CPUP_BA (0xf03fe000) #define NPCM7XX_GCR_BA (0xf0800000) #define NPCM7XX_CLK_BA (0xf0801000) +#define NPCM7XX_MC_BA (0xf0824000) =20 /* Internal AHB SRAM */ #define NPCM7XX_RAM3_BA (0xc0008000) @@ -186,6 +187,7 @@ static void npcm7xx_init(Object *obj) TYPE_NPCM7XX_KEY_STORAGE); object_initialize_child(obj, "otp2", &s->fuse_array, TYPE_NPCM7XX_FUSE_ARRAY); + object_initialize_child(obj, "mc", &s->mc, TYPE_NPCM7XX_MC); =20 for (i =3D 0; i < ARRAY_SIZE(s->tim); i++) { object_initialize_child(obj, "tim[*]", &s->tim[i], TYPE_NPCM7XX_TI= MER); @@ -261,6 +263,10 @@ static void npcm7xx_realize(DeviceState *dev, Error **= errp) sysbus_mmio_map(SYS_BUS_DEVICE(&s->fuse_array), 0, NPCM7XX_OTP2_BA); npcm7xx_init_fuses(s); =20 + /* Fake Memory Controller (MC). Cannot fail. */ + sysbus_realize(SYS_BUS_DEVICE(&s->mc), &error_abort); + sysbus_mmio_map(SYS_BUS_DEVICE(&s->mc), 0, NPCM7XX_MC_BA); + /* Timer Modules (TIM). Cannot fail. */ QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_tim_addr) !=3D ARRAY_SIZE(s->tim)= ); for (i =3D 0; i < ARRAY_SIZE(s->tim); i++) { diff --git a/hw/mem/npcm7xx_mc.c b/hw/mem/npcm7xx_mc.c new file mode 100644 index 0000000000..0435d06ab4 --- /dev/null +++ b/hw/mem/npcm7xx_mc.c @@ -0,0 +1,84 @@ +/* + * Nuvoton NPCM7xx Memory Controller stub + * + * Copyright 2020 Google LLC + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WIT= HOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#include "qemu/osdep.h" + +#include "hw/mem/npcm7xx_mc.h" +#include "qapi/error.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qemu/units.h" + +#define NPCM7XX_MC_REGS_SIZE (4 * KiB) + +static uint64_t npcm7xx_mc_read(void *opaque, hwaddr addr, unsigned int si= ze) +{ + /* + * If bits 8..11 @ offset 0 are not zero, the boot block thinks the me= mory + * controller has already been initialized and will skip DDR training. + */ + if (addr =3D=3D 0) { + return 0x100; + } + + qemu_log_mask(LOG_UNIMP, "%s: mostly unimplemented\n", __func__); + + return 0; +} + +static void npcm7xx_mc_write(void *opaque, hwaddr addr, uint64_t v, + unsigned int size) +{ + qemu_log_mask(LOG_UNIMP, "%s: mostly unimplemented\n", __func__); +} + +static const MemoryRegionOps npcm7xx_mc_ops =3D { + .read =3D npcm7xx_mc_read, + .write =3D npcm7xx_mc_write, + .endianness =3D DEVICE_LITTLE_ENDIAN, + .valid =3D { + .min_access_size =3D 4, + .max_access_size =3D 4, + .unaligned =3D false, + }, +}; + +static void npcm7xx_mc_realize(DeviceState *dev, Error **errp) +{ + NPCM7xxMCState *s =3D NPCM7XX_MC(dev); + + memory_region_init_io(&s->mmio, OBJECT(s), &npcm7xx_mc_ops, s, "regs", + NPCM7XX_MC_REGS_SIZE); + sysbus_init_mmio(&s->parent, &s->mmio); +} + +static void npcm7xx_mc_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + dc->desc =3D "NPCM7xx Memory Controller stub"; + dc->realize =3D npcm7xx_mc_realize; +} + +static const TypeInfo npcm7xx_mc_types[] =3D { + { + .name =3D TYPE_NPCM7XX_MC, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(NPCM7xxMCState), + .class_init =3D npcm7xx_mc_class_init, + }, +}; +DEFINE_TYPES(npcm7xx_mc_types); diff --git a/hw/mem/meson.build b/hw/mem/meson.build index ba424622bb..0d22f2b572 100644 --- a/hw/mem/meson.build +++ b/hw/mem/meson.build @@ -1,6 +1,7 @@ mem_ss =3D ss.source_set() mem_ss.add(files('memory-device.c')) mem_ss.add(when: 'CONFIG_DIMM', if_true: files('pc-dimm.c')) +mem_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_mc.c')) mem_ss.add(when: 'CONFIG_NVDIMM', if_true: files('nvdimm.c')) =20 softmmu_ss.add_all(when: 'CONFIG_MEM_DEVICE', if_true: mem_ss) --=20 2.28.0.297.g1956fa8f8d-goog From nobody Sun May 19 05:51:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=1598314828; cv=none; d=zohomail.com; s=zohoarc; b=ZbQQRvs71WbpyAf7P2KNA+icJ3sQ1cKTM4XNjXrpoR/XDZ2C038UybVms6ZCl3MIpfM5oMKDlg9ut9pk0C4kHSkrCTe9a9eoBpbTdr0NR0aN7W6LvKByk7duxqzTobAfNA0pvZbvPiU4Zo4kFdX/QFngDJ9B5Shprz44OTGT7dU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598314828; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=c1MZF2ezr3ddIvAR3zY02pisuLxj7we9YNIhvsAAxTo=; b=GxQ5xtQQ7r8uNclN6i+BOyvFqXwkK7fVhXDvFPVUVJnuzb5eKCeALrp/DEaK06JNnsqQf+cDNHTYGEkfOmiPdegsjaHs27oWigV3xjPpYaSnbA+TuXaxR1KKE4MqNR04z5eelFtE3FLMk9eox31kpH5st/zBCa8x/8c12349zdw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1598314828829160.74416787941618; Mon, 24 Aug 2020 17:20:28 -0700 (PDT) Received: from localhost ([::1]:37648 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kAMhO-0001Eh-RE for importer@patchew.org; Mon, 24 Aug 2020 20:20:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45358) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3pFhEXwsKCmcMXPNSSJRTJSLTTLQJ.HTRVJRZ-IJaJQSTSLSZ.TWL@flex--hskinnemoen.bounces.google.com>) id 1kAMen-0004Qt-82 for qemu-devel@nongnu.org; Mon, 24 Aug 2020 20:17:46 -0400 Received: from mail-pg1-x54a.google.com ([2607:f8b0:4864:20::54a]:42020) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3pFhEXwsKCmcMXPNSSJRTJSLTTLQJ.HTRVJRZ-IJaJQSTSLSZ.TWL@flex--hskinnemoen.bounces.google.com>) id 1kAMek-000692-2K for qemu-devel@nongnu.org; Mon, 24 Aug 2020 20:17:44 -0400 Received: by mail-pg1-x54a.google.com with SMTP id c3so6422902pgq.9 for ; Mon, 24 Aug 2020 17:17:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc:content-transfer-encoding; bh=c1MZF2ezr3ddIvAR3zY02pisuLxj7we9YNIhvsAAxTo=; b=au7K1lCf2h7YZ7QSZVLHoVFNyZL9oquTT+Uut1ltAC/pYGAtw2RSZaeiAXOl07V+C3 kgSzQ+uZsIcJdVzf0Wrw1eBmSAo9S6u2ZlYjcLLLC3/eI3aPxNLZj71TAlUNO39utK2u b10zFzaIAakGEhyZKOUoSm6Y7LdA1DqcuLJSqunBSeqACmr6xd7DfX+wOuQMynakdsju 31UnZQxBFMcbmJ+R4bHZlTIr12VGpsickt8fBWJplxqUwMyhlTyw7/f5x/DM14xxFpgI QN+7RoLcusv/GeU2QKuVlkWfGC7hl5cotCZm4AV8CUIOSCp1S3Np5sJ8YEmKvJ2zFE1H kIMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=c1MZF2ezr3ddIvAR3zY02pisuLxj7we9YNIhvsAAxTo=; b=WIgAld2Lw+bl950gydwrAGbwwyoXjKnjD8QJyKeInaAwh+/ex7zG5/xZX31DsKz2uF hlCjWEBoKKWJH+FoqnMbsbl6Jp1ayePasZzj0LwvQPKoY+ewBpDSQvqUFaH0fPNgduHb BKO+/yXxTErUwIjYYSqNutiNInIJYrdIA700m7lUagsjuOy4LvYnsiGQG4N40Gp2zCni vPj3mYr7EiVybl2DEbDSIlLkkparVaDzirXMCP6E9vX0laJetWKsSpa8k9zr2R4rGNE6 BwpGFpbWyU2/pSYIBGQrugTg2r7clhxJB6+t9dZtKA36y/PYe+grm+zEOsTLzda/bHg7 FYeg== X-Gm-Message-State: AOAM5324wBmnWsCthM3J44/246mp/SDnjsPOWxeSAsvljbDUaOHJUiRX MgqZChoFXEQJJPSaQeokpwSpWStN+gC7K4avuw== X-Google-Smtp-Source: ABdhPJy3tD+YEoPNOnWglSXxLlCZHw5D5L+ka2/cbeS4LTH/d7GdO5BFiGQFqCftVbJnUI/k1JiIuzAawLdiy8n5EA== X-Received: from skybert.c.googlers.com ([fda3:e722:ac3:10:24:72f4:c0a8:3107]) (user=hskinnemoen job=sendgmr) by 2002:a17:902:ee02:: with SMTP id z2mr5492140plb.291.1598314660153; Mon, 24 Aug 2020 17:17:40 -0700 (PDT) Date: Mon, 24 Aug 2020 17:17:07 -0700 In-Reply-To: <20200825001711.1340443-1-hskinnemoen@google.com> Message-Id: <20200825001711.1340443-11-hskinnemoen@google.com> Mime-Version: 1.0 References: <20200825001711.1340443-1-hskinnemoen@google.com> X-Mailer: git-send-email 2.28.0.297.g1956fa8f8d-goog Subject: [PATCH v8 10/14] hw/ssi: NPCM7xx Flash Interface Unit device model To: peter.maydell@linaro.org, f4bug@amsat.org Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, Avi.Fishman@nuvoton.com, kfting@nuvoton.com, Havard Skinnemoen , "=?UTF-8?q?C=C3=A9dric=20Le=20Goater?=" 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::54a; envelope-from=3pFhEXwsKCmcMXPNSSJRTJSLTTLQJ.HTRVJRZ-IJaJQSTSLSZ.TWL@flex--hskinnemoen.bounces.google.com; helo=mail-pg1-x54a.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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" Reply-to: Havard Skinnemoen From: Havard Skinnemoen via X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This implements a device model for the NPCM7xx SPI flash controller. Direct reads and writes, and user-mode transactions have been tested in various modes. Protection features are not implemented yet. All the FIU instances are available in the SoC's address space, regardless of whether or not they're connected to actual flash chips. Reviewed-by: Tyrone Ting Reviewed-by: C=C3=A9dric Le Goater Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Havard Skinnemoen Tested-by: Alexander Bulekov Tested-by: Philippe Mathieu-Daud=C3=A9 --- include/hw/arm/npcm7xx.h | 2 + include/hw/ssi/npcm7xx_fiu.h | 73 +++++ hw/arm/npcm7xx.c | 58 ++++ hw/ssi/npcm7xx_fiu.c | 572 +++++++++++++++++++++++++++++++++++ hw/arm/Kconfig | 1 + hw/ssi/meson.build | 1 + hw/ssi/trace-events | 11 + 7 files changed, 718 insertions(+) create mode 100644 include/hw/ssi/npcm7xx_fiu.h create mode 100644 hw/ssi/npcm7xx_fiu.c diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h index 9fa84a0702..78d0d78c52 100644 --- a/include/hw/arm/npcm7xx.h +++ b/include/hw/arm/npcm7xx.h @@ -23,6 +23,7 @@ #include "hw/misc/npcm7xx_gcr.h" #include "hw/nvram/npcm7xx_otp.h" #include "hw/timer/npcm7xx_timer.h" +#include "hw/ssi/npcm7xx_fiu.h" #include "target/arm/cpu.h" =20 #define NPCM7XX_MAX_NUM_CPUS (2) @@ -73,6 +74,7 @@ typedef struct NPCM7xxState { NPCM7xxOTPState key_storage; NPCM7xxOTPState fuse_array; NPCM7xxMCState mc; + NPCM7xxFIUState fiu[2]; } NPCM7xxState; =20 #define TYPE_NPCM7XX "npcm7xx" diff --git a/include/hw/ssi/npcm7xx_fiu.h b/include/hw/ssi/npcm7xx_fiu.h new file mode 100644 index 0000000000..a3a1704289 --- /dev/null +++ b/include/hw/ssi/npcm7xx_fiu.h @@ -0,0 +1,73 @@ +/* + * Nuvoton NPCM7xx Flash Interface Unit (FIU) + * + * Copyright 2020 Google LLC + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WIT= HOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ +#ifndef NPCM7XX_FIU_H +#define NPCM7XX_FIU_H + +#include "hw/ssi/ssi.h" +#include "hw/sysbus.h" + +/* + * Number of registers in our device state structure. Don't change this wi= thout + * incrementing the version_id in the vmstate. + */ +#define NPCM7XX_FIU_NR_REGS (0x7c / sizeof(uint32_t)) + +typedef struct NPCM7xxFIUState NPCM7xxFIUState; + +/** + * struct NPCM7xxFIUFlash - Per-chipselect flash controller state. + * @direct_access: Memory region for direct flash access. + * @fiu: Pointer to flash controller shared state. + */ +typedef struct NPCM7xxFIUFlash { + MemoryRegion direct_access; + NPCM7xxFIUState *fiu; +} NPCM7xxFIUFlash; + +/** + * NPCM7xxFIUState - Device state for one Flash Interface Unit. + * @parent: System bus device. + * @mmio: Memory region for register access. + * @cs_count: Number of flash chips that may be connected to this module. + * @active_cs: Currently active chip select, or -1 if no chip is selected. + * @cs_lines: GPIO lines that may be wired to flash chips. + * @flash: Array of @cs_count per-flash-chip state objects. + * @spi: The SPI bus mastered by this controller. + * @regs: Register contents. + * + * Each FIU has a shared bank of registers, and controls up to four chip + * selects. Each chip select has a dedicated memory region which may be us= ed to + * read and write the flash connected to that chip select as if it were me= mory. + */ +struct NPCM7xxFIUState { + SysBusDevice parent; + + MemoryRegion mmio; + + int32_t cs_count; + int32_t active_cs; + qemu_irq *cs_lines; + NPCM7xxFIUFlash *flash; + + SSIBus *spi; + + uint32_t regs[NPCM7XX_FIU_NR_REGS]; +}; + +#define TYPE_NPCM7XX_FIU "npcm7xx-fiu" +#define NPCM7XX_FIU(obj) OBJECT_CHECK(NPCM7xxFIUState, (obj), TYPE_NPCM7XX= _FIU) + +#endif /* NPCM7XX_FIU_H */ diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c index 6bb1693833..7884b2b03d 100644 --- a/hw/arm/npcm7xx.c +++ b/hw/arm/npcm7xx.c @@ -99,6 +99,39 @@ static const hwaddr npcm7xx_uart_addr[] =3D { 0xf0004000, }; =20 +/* Direct memory-mapped access to SPI0 CS0-1. */ +static const hwaddr npcm7xx_fiu0_flash_addr[] =3D { + 0x80000000, /* CS0 */ + 0x88000000, /* CS1 */ +}; + +/* Direct memory-mapped access to SPI3 CS0-3. */ +static const hwaddr npcm7xx_fiu3_flash_addr[] =3D { + 0xa0000000, /* CS0 */ + 0xa8000000, /* CS1 */ + 0xb0000000, /* CS2 */ + 0xb8000000, /* CS3 */ +}; + +static const struct { + const char *name; + hwaddr regs_addr; + int cs_count; + const hwaddr *flash_addr; +} npcm7xx_fiu[] =3D { + { + .name =3D "fiu0", + .regs_addr =3D 0xfb000000, + .cs_count =3D ARRAY_SIZE(npcm7xx_fiu0_flash_addr), + .flash_addr =3D npcm7xx_fiu0_flash_addr, + }, { + .name =3D "fiu3", + .regs_addr =3D 0xc0000000, + .cs_count =3D ARRAY_SIZE(npcm7xx_fiu3_flash_addr), + .flash_addr =3D npcm7xx_fiu3_flash_addr, + }, +}; + static void npcm7xx_write_secondary_boot(ARMCPU *cpu, const struct arm_boot_info *info) { @@ -192,6 +225,12 @@ static void npcm7xx_init(Object *obj) for (i =3D 0; i < ARRAY_SIZE(s->tim); i++) { object_initialize_child(obj, "tim[*]", &s->tim[i], TYPE_NPCM7XX_TI= MER); } + + QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_fiu) !=3D ARRAY_SIZE(s->fiu)); + for (i =3D 0; i < ARRAY_SIZE(s->fiu); i++) { + object_initialize_child(obj, npcm7xx_fiu[i].name, &s->fiu[i], + TYPE_NPCM7XX_FIU); + } } =20 static void npcm7xx_realize(DeviceState *dev, Error **errp) @@ -291,6 +330,25 @@ static void npcm7xx_realize(DeviceState *dev, Error **= errp) serial_hd(i), DEVICE_LITTLE_ENDIAN); } =20 + /* + * Flash Interface Unit (FIU). Can fail if incorrect number of chip se= lects + * specified, but this is a programming error. + */ + QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_fiu) !=3D ARRAY_SIZE(s->fiu)); + for (i =3D 0; i < ARRAY_SIZE(s->fiu); i++) { + SysBusDevice *sbd =3D SYS_BUS_DEVICE(&s->fiu[i]); + int j; + + object_property_set_int(OBJECT(sbd), "cs-count", + npcm7xx_fiu[i].cs_count, &error_abort); + sysbus_realize(sbd, &error_abort); + + sysbus_mmio_map(sbd, 0, npcm7xx_fiu[i].regs_addr); + for (j =3D 0; j < npcm7xx_fiu[i].cs_count; j++) { + sysbus_mmio_map(sbd, j + 1, npcm7xx_fiu[i].flash_addr[j]); + } + } + /* RAM2 (SRAM) */ memory_region_init_ram(&s->sram, OBJECT(dev), "ram2", NPCM7XX_RAM2_SZ, &error_abort); diff --git a/hw/ssi/npcm7xx_fiu.c b/hw/ssi/npcm7xx_fiu.c new file mode 100644 index 0000000000..104e8f2b96 --- /dev/null +++ b/hw/ssi/npcm7xx_fiu.c @@ -0,0 +1,572 @@ +/* + * Nuvoton NPCM7xx Flash Interface Unit (FIU) + * + * Copyright 2020 Google LLC + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WIT= HOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * for more details. + */ + +#include "qemu/osdep.h" + +#include "hw/irq.h" +#include "hw/qdev-properties.h" +#include "hw/ssi/npcm7xx_fiu.h" +#include "migration/vmstate.h" +#include "qapi/error.h" +#include "qemu/error-report.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qemu/units.h" + +#include "trace.h" + +/* Up to 128 MiB of flash may be accessed directly as memory. */ +#define NPCM7XX_FIU_FLASH_WINDOW_SIZE (128 * MiB) + +/* Each module has 4 KiB of register space. Only a fraction of it is used.= */ +#define NPCM7XX_FIU_CTRL_REGS_SIZE (4 * KiB) + +/* 32-bit FIU register indices. */ +enum NPCM7xxFIURegister { + NPCM7XX_FIU_DRD_CFG, + NPCM7XX_FIU_DWR_CFG, + NPCM7XX_FIU_UMA_CFG, + NPCM7XX_FIU_UMA_CTS, + NPCM7XX_FIU_UMA_CMD, + NPCM7XX_FIU_UMA_ADDR, + NPCM7XX_FIU_PRT_CFG, + NPCM7XX_FIU_UMA_DW0 =3D 0x0020 / sizeof(uint32_t), + NPCM7XX_FIU_UMA_DW1, + NPCM7XX_FIU_UMA_DW2, + NPCM7XX_FIU_UMA_DW3, + NPCM7XX_FIU_UMA_DR0, + NPCM7XX_FIU_UMA_DR1, + NPCM7XX_FIU_UMA_DR2, + NPCM7XX_FIU_UMA_DR3, + NPCM7XX_FIU_PRT_CMD0, + NPCM7XX_FIU_PRT_CMD1, + NPCM7XX_FIU_PRT_CMD2, + NPCM7XX_FIU_PRT_CMD3, + NPCM7XX_FIU_PRT_CMD4, + NPCM7XX_FIU_PRT_CMD5, + NPCM7XX_FIU_PRT_CMD6, + NPCM7XX_FIU_PRT_CMD7, + NPCM7XX_FIU_PRT_CMD8, + NPCM7XX_FIU_PRT_CMD9, + NPCM7XX_FIU_CFG =3D 0x78 / sizeof(uint32_t), + NPCM7XX_FIU_REGS_END, +}; + +/* FIU_{DRD,DWR,UMA,PTR}_CFG cannot be written when this bit is set. */ +#define NPCM7XX_FIU_CFG_LCK BIT(31) + +/* Direct Read configuration register fields. */ +#define FIU_DRD_CFG_ADDSIZ(rv) extract32(rv, 16, 2) +#define FIU_ADDSIZ_3BYTES 0 +#define FIU_ADDSIZ_4BYTES 1 +#define FIU_DRD_CFG_DBW(rv) extract32(rv, 12, 2) +#define FIU_DRD_CFG_ACCTYPE(rv) extract32(rv, 8, 2) +#define FIU_DRD_CFG_RDCMD(rv) extract32(rv, 0, 8) + +/* Direct Write configuration register fields. */ +#define FIU_DWR_CFG_ADDSIZ(rv) extract32(rv, 16, 2) +#define FIU_DWR_CFG_WRCMD(rv) extract32(rv, 0, 8) + +/* User-Mode Access register fields. */ + +/* Command Mode Lock and the bits protected by it. */ +#define FIU_UMA_CFG_CMMLCK BIT(30) +#define FIU_UMA_CFG_CMMLCK_MASK 0x00000403 + +#define FIU_UMA_CFG_RDATSIZ(rv) extract32(rv, 24, 5) +#define FIU_UMA_CFG_DBSIZ(rv) extract32(rv, 21, 3) +#define FIU_UMA_CFG_WDATSIZ(rv) extract32(rv, 16, 5) +#define FIU_UMA_CFG_ADDSIZ(rv) extract32(rv, 11, 3) +#define FIU_UMA_CFG_CMDSIZ(rv) extract32(rv, 10, 1) +#define FIU_UMA_CFG_DBPCK(rv) extract32(rv, 6, 2) + +#define FIU_UMA_CTS_RDYIE BIT(25) +#define FIU_UMA_CTS_RDYST BIT(24) +#define FIU_UMA_CTS_SW_CS BIT(16) +#define FIU_UMA_CTS_DEV_NUM(rv) extract32(rv, 8, 2) +#define FIU_UMA_CTS_EXEC_DONE BIT(0) + +/* + * Returns the index of flash in the fiu->flash array. This corresponds to= the + * chip select ID of the flash. + */ +static int npcm7xx_fiu_cs_index(NPCM7xxFIUState *fiu, NPCM7xxFIUFlash *fla= sh) +{ + int index =3D flash - fiu->flash; + + g_assert(index >=3D 0 && index < fiu->cs_count); + + return index; +} + +/* Assert the chip select specified in the UMA Control/Status Register. */ +static void npcm7xx_fiu_select(NPCM7xxFIUState *s, int cs_id) +{ + trace_npcm7xx_fiu_select(DEVICE(s)->canonical_path, cs_id); + + if (cs_id < s->cs_count) { + qemu_irq_lower(s->cs_lines[cs_id]); + } else { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: UMA to CS%d; this module has only %d chip selec= ts", + DEVICE(s)->canonical_path, cs_id, s->cs_count); + cs_id =3D -1; + } + + s->active_cs =3D cs_id; +} + +/* Deassert the currently active chip select. */ +static void npcm7xx_fiu_deselect(NPCM7xxFIUState *s) +{ + if (s->active_cs < 0) { + return; + } + + trace_npcm7xx_fiu_deselect(DEVICE(s)->canonical_path, s->active_cs); + + qemu_irq_raise(s->cs_lines[s->active_cs]); + s->active_cs =3D -1; +} + +/* Direct flash memory read handler. */ +static uint64_t npcm7xx_fiu_flash_read(void *opaque, hwaddr addr, + unsigned int size) +{ + NPCM7xxFIUFlash *f =3D opaque; + NPCM7xxFIUState *fiu =3D f->fiu; + uint64_t value =3D 0; + uint32_t drd_cfg; + int dummy_cycles; + int i; + + if (fiu->active_cs !=3D -1) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: direct flash read with CS%d already active", + DEVICE(fiu)->canonical_path, fiu->active_cs); + } + + npcm7xx_fiu_select(fiu, npcm7xx_fiu_cs_index(fiu, f)); + + drd_cfg =3D fiu->regs[NPCM7XX_FIU_DRD_CFG]; + ssi_transfer(fiu->spi, FIU_DRD_CFG_RDCMD(drd_cfg)); + + switch (FIU_DRD_CFG_ADDSIZ(drd_cfg)) { + case FIU_ADDSIZ_4BYTES: + ssi_transfer(fiu->spi, extract32(addr, 24, 8)); + /* fall through */ + case FIU_ADDSIZ_3BYTES: + ssi_transfer(fiu->spi, extract32(addr, 16, 8)); + ssi_transfer(fiu->spi, extract32(addr, 8, 8)); + ssi_transfer(fiu->spi, extract32(addr, 0, 8)); + break; + + default: + qemu_log_mask(LOG_GUEST_ERROR, "%s: bad address size %d\n", + DEVICE(fiu)->canonical_path, FIU_DRD_CFG_ADDSIZ(drd_= cfg)); + break; + } + + /* Flash chip model expects one transfer per dummy bit, not byte */ + dummy_cycles =3D + (FIU_DRD_CFG_DBW(drd_cfg) * 8) >> FIU_DRD_CFG_ACCTYPE(drd_cfg); + for (i =3D 0; i < dummy_cycles; i++) { + ssi_transfer(fiu->spi, 0); + } + + for (i =3D 0; i < size; i++) { + value =3D deposit64(value, 8 * i, 8, ssi_transfer(fiu->spi, 0)); + } + + trace_npcm7xx_fiu_flash_read(DEVICE(fiu)->canonical_path, fiu->active_= cs, + addr, size, value); + + npcm7xx_fiu_deselect(fiu); + + return value; +} + +/* Direct flash memory write handler. */ +static void npcm7xx_fiu_flash_write(void *opaque, hwaddr addr, uint64_t v, + unsigned int size) +{ + NPCM7xxFIUFlash *f =3D opaque; + NPCM7xxFIUState *fiu =3D f->fiu; + uint32_t dwr_cfg; + int cs_id; + int i; + + if (fiu->active_cs !=3D -1) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: direct flash write with CS%d already active", + DEVICE(fiu)->canonical_path, fiu->active_cs); + } + + cs_id =3D npcm7xx_fiu_cs_index(fiu, f); + trace_npcm7xx_fiu_flash_write(DEVICE(fiu)->canonical_path, cs_id, addr, + size, v); + npcm7xx_fiu_select(fiu, cs_id); + + dwr_cfg =3D fiu->regs[NPCM7XX_FIU_DWR_CFG]; + ssi_transfer(fiu->spi, FIU_DWR_CFG_WRCMD(dwr_cfg)); + + switch (FIU_DWR_CFG_ADDSIZ(dwr_cfg)) { + case FIU_ADDSIZ_4BYTES: + ssi_transfer(fiu->spi, extract32(addr, 24, 8)); + /* fall through */ + case FIU_ADDSIZ_3BYTES: + ssi_transfer(fiu->spi, extract32(addr, 16, 8)); + ssi_transfer(fiu->spi, extract32(addr, 8, 8)); + ssi_transfer(fiu->spi, extract32(addr, 0, 8)); + break; + + default: + qemu_log_mask(LOG_GUEST_ERROR, "%s: bad address size %d\n", + DEVICE(fiu)->canonical_path, FIU_DWR_CFG_ADDSIZ(dwr_= cfg)); + break; + } + + for (i =3D 0; i < size; i++) { + ssi_transfer(fiu->spi, extract64(v, i * 8, 8)); + } + + npcm7xx_fiu_deselect(fiu); +} + +static const MemoryRegionOps npcm7xx_fiu_flash_ops =3D { + .read =3D npcm7xx_fiu_flash_read, + .write =3D npcm7xx_fiu_flash_write, + .endianness =3D DEVICE_LITTLE_ENDIAN, + .valid =3D { + .min_access_size =3D 1, + .max_access_size =3D 8, + .unaligned =3D true, + }, +}; + +/* Control register read handler. */ +static uint64_t npcm7xx_fiu_ctrl_read(void *opaque, hwaddr addr, + unsigned int size) +{ + hwaddr reg =3D addr / sizeof(uint32_t); + NPCM7xxFIUState *s =3D opaque; + uint32_t value; + + if (reg < NPCM7XX_FIU_NR_REGS) { + value =3D s->regs[reg]; + } else { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: read from invalid offset 0x%" PRIx64 "\n", + DEVICE(s)->canonical_path, addr); + value =3D 0; + } + + trace_npcm7xx_fiu_ctrl_read(DEVICE(s)->canonical_path, addr, value); + + return value; +} + +/* Send the specified number of address bytes from the UMA address registe= r. */ +static void send_address(SSIBus *spi, unsigned int addsiz, uint32_t addr) +{ + switch (addsiz) { + case 4: + ssi_transfer(spi, extract32(addr, 24, 8)); + /* fall through */ + case 3: + ssi_transfer(spi, extract32(addr, 16, 8)); + /* fall through */ + case 2: + ssi_transfer(spi, extract32(addr, 8, 8)); + /* fall through */ + case 1: + ssi_transfer(spi, extract32(addr, 0, 8)); + /* fall through */ + case 0: + break; + } +} + +/* Send the number of dummy bits specified in the UMA config register. */ +static void send_dummy_bits(SSIBus *spi, uint32_t uma_cfg, uint32_t uma_cm= d) +{ + unsigned int bits_per_clock =3D 1U << FIU_UMA_CFG_DBPCK(uma_cfg); + unsigned int i; + + for (i =3D 0; i < FIU_UMA_CFG_DBSIZ(uma_cfg); i++) { + /* Use bytes 0 and 1 first, then keep repeating byte 2 */ + unsigned int field =3D (i < 2) ? ((i + 1) * 8) : 24; + unsigned int j; + + for (j =3D 0; j < 8; j +=3D bits_per_clock) { + ssi_transfer(spi, extract32(uma_cmd, field + j, bits_per_clock= )); + } + } +} + +/* Perform a User-Mode Access transaction. */ +static void npcm7xx_fiu_uma_transaction(NPCM7xxFIUState *s) +{ + uint32_t uma_cts =3D s->regs[NPCM7XX_FIU_UMA_CTS]; + uint32_t uma_cfg; + unsigned int i; + + /* SW_CS means the CS is already forced low, so don't touch it. */ + if (uma_cts & FIU_UMA_CTS_SW_CS) { + int cs_id =3D FIU_UMA_CTS_DEV_NUM(s->regs[NPCM7XX_FIU_UMA_CTS]); + npcm7xx_fiu_select(s, cs_id); + } + + /* Send command, if present. */ + uma_cfg =3D s->regs[NPCM7XX_FIU_UMA_CFG]; + if (FIU_UMA_CFG_CMDSIZ(uma_cfg) > 0) { + ssi_transfer(s->spi, extract32(s->regs[NPCM7XX_FIU_UMA_CMD], 0, 8)= ); + } + + /* Send address, if present. */ + send_address(s->spi, FIU_UMA_CFG_ADDSIZ(uma_cfg), + s->regs[NPCM7XX_FIU_UMA_ADDR]); + + /* Write data, if present. */ + for (i =3D 0; i < FIU_UMA_CFG_WDATSIZ(uma_cfg); i++) { + unsigned int reg =3D + (i < 16) ? (NPCM7XX_FIU_UMA_DW0 + i / 4) : NPCM7XX_FIU_UMA_DW3; + unsigned int field =3D (i % 4) * 8; + + ssi_transfer(s->spi, extract32(s->regs[reg], field, 8)); + } + + /* Send dummy bits, if present. */ + send_dummy_bits(s->spi, uma_cfg, s->regs[NPCM7XX_FIU_UMA_CMD]); + + /* Read data, if present. */ + for (i =3D 0; i < FIU_UMA_CFG_RDATSIZ(uma_cfg); i++) { + unsigned int reg =3D NPCM7XX_FIU_UMA_DR0 + i / 4; + unsigned int field =3D (i % 4) * 8; + uint8_t c; + + c =3D ssi_transfer(s->spi, 0); + if (reg <=3D NPCM7XX_FIU_UMA_DR3) { + s->regs[reg] =3D deposit32(s->regs[reg], field, 8, c); + } + } + + /* Again, don't touch CS if the user is forcing it low. */ + if (uma_cts & FIU_UMA_CTS_SW_CS) { + npcm7xx_fiu_deselect(s); + } + + /* RDYST means a command has completed since it was cleared. */ + s->regs[NPCM7XX_FIU_UMA_CTS] |=3D FIU_UMA_CTS_RDYST; + /* EXEC_DONE means Execute Command / Not Done, so clear it here. */ + s->regs[NPCM7XX_FIU_UMA_CTS] &=3D ~FIU_UMA_CTS_EXEC_DONE; +} + +/* Control register write handler. */ +static void npcm7xx_fiu_ctrl_write(void *opaque, hwaddr addr, uint64_t v, + unsigned int size) +{ + hwaddr reg =3D addr / sizeof(uint32_t); + NPCM7xxFIUState *s =3D opaque; + uint32_t value =3D v; + + trace_npcm7xx_fiu_ctrl_write(DEVICE(s)->canonical_path, addr, value); + + switch (reg) { + case NPCM7XX_FIU_UMA_CFG: + if (s->regs[reg] & FIU_UMA_CFG_CMMLCK) { + value &=3D ~FIU_UMA_CFG_CMMLCK_MASK; + value |=3D (s->regs[reg] & FIU_UMA_CFG_CMMLCK_MASK); + } + /* fall through */ + case NPCM7XX_FIU_DRD_CFG: + case NPCM7XX_FIU_DWR_CFG: + if (s->regs[reg] & NPCM7XX_FIU_CFG_LCK) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: write to locked register @ 0x%" PRIx64 "\n", + DEVICE(s)->canonical_path, addr); + return; + } + s->regs[reg] =3D value; + break; + + case NPCM7XX_FIU_UMA_CTS: + if (value & FIU_UMA_CTS_RDYST) { + value &=3D ~FIU_UMA_CTS_RDYST; + } else { + value |=3D s->regs[reg] & FIU_UMA_CTS_RDYST; + } + if ((s->regs[reg] ^ value) & FIU_UMA_CTS_SW_CS) { + if (value & FIU_UMA_CTS_SW_CS) { + /* + * Don't drop CS if there's a transfer in progress, or we'= re + * about to start one. + */ + if (!((value | s->regs[reg]) & FIU_UMA_CTS_EXEC_DONE)) { + npcm7xx_fiu_deselect(s); + } + } else { + int cs_id =3D FIU_UMA_CTS_DEV_NUM(s->regs[NPCM7XX_FIU_UMA_= CTS]); + npcm7xx_fiu_select(s, cs_id); + } + } + s->regs[reg] =3D value | (s->regs[reg] & FIU_UMA_CTS_EXEC_DONE); + if (value & FIU_UMA_CTS_EXEC_DONE) { + npcm7xx_fiu_uma_transaction(s); + } + break; + + case NPCM7XX_FIU_UMA_DR0 ... NPCM7XX_FIU_UMA_DR3: + qemu_log_mask(LOG_GUEST_ERROR, + "%s: write to read-only register @ 0x%" PRIx64 "\n", + DEVICE(s)->canonical_path, addr); + return; + + case NPCM7XX_FIU_PRT_CFG: + case NPCM7XX_FIU_PRT_CMD0 ... NPCM7XX_FIU_PRT_CMD9: + qemu_log_mask(LOG_UNIMP, "%s: PRT is not implemented\n", __func__); + break; + + case NPCM7XX_FIU_UMA_CMD: + case NPCM7XX_FIU_UMA_ADDR: + case NPCM7XX_FIU_UMA_DW0 ... NPCM7XX_FIU_UMA_DW3: + case NPCM7XX_FIU_CFG: + s->regs[reg] =3D value; + break; + + default: + qemu_log_mask(LOG_GUEST_ERROR, + "%s: write to invalid offset 0x%" PRIx64 "\n", + DEVICE(s)->canonical_path, addr); + return; + } +} + +static const MemoryRegionOps npcm7xx_fiu_ctrl_ops =3D { + .read =3D npcm7xx_fiu_ctrl_read, + .write =3D npcm7xx_fiu_ctrl_write, + .endianness =3D DEVICE_LITTLE_ENDIAN, + .valid =3D { + .min_access_size =3D 4, + .max_access_size =3D 4, + .unaligned =3D false, + }, +}; + +static void npcm7xx_fiu_enter_reset(Object *obj, ResetType type) +{ + NPCM7xxFIUState *s =3D NPCM7XX_FIU(obj); + + trace_npcm7xx_fiu_enter_reset(DEVICE(obj)->canonical_path, type); + + memset(s->regs, 0, sizeof(s->regs)); + + s->regs[NPCM7XX_FIU_DRD_CFG] =3D 0x0300100b; + s->regs[NPCM7XX_FIU_DWR_CFG] =3D 0x03000002; + s->regs[NPCM7XX_FIU_UMA_CFG] =3D 0x00000400; + s->regs[NPCM7XX_FIU_UMA_CTS] =3D 0x00010000; + s->regs[NPCM7XX_FIU_UMA_CMD] =3D 0x0000000b; + s->regs[NPCM7XX_FIU_PRT_CFG] =3D 0x00000400; + s->regs[NPCM7XX_FIU_CFG] =3D 0x0000000b; +} + +static void npcm7xx_fiu_hold_reset(Object *obj) +{ + NPCM7xxFIUState *s =3D NPCM7XX_FIU(obj); + int i; + + trace_npcm7xx_fiu_hold_reset(DEVICE(obj)->canonical_path); + + for (i =3D 0; i < s->cs_count; i++) { + qemu_irq_raise(s->cs_lines[i]); + } +} + +static void npcm7xx_fiu_realize(DeviceState *dev, Error **errp) +{ + NPCM7xxFIUState *s =3D NPCM7XX_FIU(dev); + SysBusDevice *sbd =3D &s->parent; + int i; + + if (s->cs_count <=3D 0) { + error_setg(errp, "%s: %d chip selects specified, need at least one= ", + dev->canonical_path, s->cs_count); + return; + } + + s->spi =3D ssi_create_bus(dev, "spi"); + s->cs_lines =3D g_new0(qemu_irq, s->cs_count); + qdev_init_gpio_out_named(DEVICE(s), s->cs_lines, "cs", s->cs_count); + s->flash =3D g_new0(NPCM7xxFIUFlash, s->cs_count); + + /* + * Register the control registers region first. It may be followed by = one + * or more direct flash access regions. + */ + memory_region_init_io(&s->mmio, OBJECT(s), &npcm7xx_fiu_ctrl_ops, s, "= ctrl", + NPCM7XX_FIU_CTRL_REGS_SIZE); + sysbus_init_mmio(sbd, &s->mmio); + + for (i =3D 0; i < s->cs_count; i++) { + NPCM7xxFIUFlash *flash =3D &s->flash[i]; + flash->fiu =3D s; + memory_region_init_io(&flash->direct_access, OBJECT(s), + &npcm7xx_fiu_flash_ops, &s->flash[i], "flash= ", + NPCM7XX_FIU_FLASH_WINDOW_SIZE); + sysbus_init_mmio(sbd, &flash->direct_access); + } +} + +static const VMStateDescription vmstate_npcm7xx_fiu =3D { + .name =3D "npcm7xx-fiu", + .version_id =3D 0, + .minimum_version_id =3D 0, + .fields =3D (VMStateField[]) { + VMSTATE_INT32(active_cs, NPCM7xxFIUState), + VMSTATE_UINT32_ARRAY(regs, NPCM7xxFIUState, NPCM7XX_FIU_NR_REGS), + VMSTATE_END_OF_LIST(), + }, +}; + +static Property npcm7xx_fiu_properties[] =3D { + DEFINE_PROP_INT32("cs-count", NPCM7xxFIUState, cs_count, 0), + DEFINE_PROP_END_OF_LIST(), +}; + +static void npcm7xx_fiu_class_init(ObjectClass *klass, void *data) +{ + ResettableClass *rc =3D RESETTABLE_CLASS(klass); + DeviceClass *dc =3D DEVICE_CLASS(klass); + + QEMU_BUILD_BUG_ON(NPCM7XX_FIU_REGS_END > NPCM7XX_FIU_NR_REGS); + + dc->desc =3D "NPCM7xx Flash Interface Unit"; + dc->realize =3D npcm7xx_fiu_realize; + dc->vmsd =3D &vmstate_npcm7xx_fiu; + rc->phases.enter =3D npcm7xx_fiu_enter_reset; + rc->phases.hold =3D npcm7xx_fiu_hold_reset; + device_class_set_props(dc, npcm7xx_fiu_properties); +} + +static const TypeInfo npcm7xx_fiu_types[] =3D { + { + .name =3D TYPE_NPCM7XX_FIU, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(NPCM7xxFIUState), + .class_init =3D npcm7xx_fiu_class_init, + }, +}; +DEFINE_TYPES(npcm7xx_fiu_types); diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig index cd74642034..f303c6bead 100644 --- a/hw/arm/Kconfig +++ b/hw/arm/Kconfig @@ -361,6 +361,7 @@ config NPCM7XX select ARM_GIC select PL310 # cache controller select SERIAL + select SSI select UNIMP =20 config FSL_IMX25 diff --git a/hw/ssi/meson.build b/hw/ssi/meson.build index f1f5c287d0..dee00c0da6 100644 --- a/hw/ssi/meson.build +++ b/hw/ssi/meson.build @@ -1,5 +1,6 @@ softmmu_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_smc.c')) softmmu_ss.add(when: 'CONFIG_MSF2', if_true: files('mss-spi.c')) +softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_fiu.c')) softmmu_ss.add(when: 'CONFIG_PL022', if_true: files('pl022.c')) softmmu_ss.add(when: 'CONFIG_SSI', if_true: files('ssi.c')) softmmu_ss.add(when: 'CONFIG_STM32F2XX_SPI', if_true: files('stm32f2xx_spi= .c')) diff --git a/hw/ssi/trace-events b/hw/ssi/trace-events index 0ea498de91..2f83ef833f 100644 --- a/hw/ssi/trace-events +++ b/hw/ssi/trace-events @@ -9,3 +9,14 @@ aspeed_smc_dma_checksum(uint32_t addr, uint32_t data) "0x%= 08x: 0x%08x" aspeed_smc_dma_rw(const char *dir, uint32_t flash_addr, uint32_t dram_addr= , uint32_t size) "%s flash:@0x%08x dram:@0x%08x size:0x%08x" aspeed_smc_write(uint64_t addr, uint32_t size, uint64_t data) "@0x%" PRIx= 64 " size %u: 0x%" PRIx64 aspeed_smc_flash_select(int cs, const char *prefix) "CS%d %sselect" + +# npcm7xx_fiu.c + +npcm7xx_fiu_enter_reset(const char *id, int reset_type) "%s reset type: %d" +npcm7xx_fiu_hold_reset(const char *id) "%s" +npcm7xx_fiu_select(const char *id, int cs) "%s select CS%d" +npcm7xx_fiu_deselect(const char *id, int cs) "%s deselect CS%d" +npcm7xx_fiu_ctrl_read(const char *id, uint64_t addr, uint32_t data) "%s of= fset: 0x%04" PRIx64 " value: 0x%08" PRIx32 +npcm7xx_fiu_ctrl_write(const char *id, uint64_t addr, uint32_t data) "%s o= ffset: 0x%04" PRIx64 " value: 0x%08" PRIx32 +npcm7xx_fiu_flash_read(const char *id, int cs, uint64_t addr, unsigned int= size, uint64_t value) "%s[%d] offset: 0x%08" PRIx64 " size: %u value: 0x%"= PRIx64 +npcm7xx_fiu_flash_write(const char *id, int cs, uint64_t addr, unsigned in= t size, uint64_t value) "%s[%d] offset: 0x%08" PRIx64 " size: %u value: 0x%= " PRIx64 --=20 2.28.0.297.g1956fa8f8d-goog From nobody Sun May 19 05:51:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=1598315246; cv=none; d=zohomail.com; s=zohoarc; b=J5vva7Jf98lcPA3UgfmWNb2hKOxhsGwkNQKQTU6FLmqjoWvQc38WK40Meve2yB0nqPjJ4TePVlP0nQyUgxNjGZeJw7MtuMNJWh8a8LQ0jeex3oHRPK57UYbmhQ3aqKtSGFldzam7ETxCbZon4kbZkVShfzMQXXIrxtS+jGzMLps= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598315246; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=rUEKve2Wm610Ab3YZTjgeg13+EN7IVaTgjJRV1dAi30=; b=BpMjy6wRIOlgEMCIh5SKeJZP9EM0GmRXr1VIDRGajLXkYNuGxZxJrpMJSvY0OCcDhUgBHRntvMHbxndvtmj6o+ZChDL3Sft2894MgGnrgdLapVCx/KbH0IhcTcFREOa+adxr6Q8THD8Cmfbqb00ohufHbUv+IsofYSqeLLhM4Tc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1598315246634899.5764659093501; Mon, 24 Aug 2020 17:27:26 -0700 (PDT) Received: from localhost ([::1]:36926 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kAMo9-0004Ax-FT for importer@patchew.org; Mon, 24 Aug 2020 20:27:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45428) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3plhEXwsKCmkOZRPUULTVLUNVVNSL.JVTXLTb-KLcLSUVUNUb.VYN@flex--hskinnemoen.bounces.google.com>) id 1kAMer-0004Tp-7A for qemu-devel@nongnu.org; Mon, 24 Aug 2020 20:17:49 -0400 Received: from mail-pf1-x44a.google.com ([2607:f8b0:4864:20::44a]:37492) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3plhEXwsKCmkOZRPUULTVLUNVVNSL.JVTXLTb-KLcLSUVUNUb.VYN@flex--hskinnemoen.bounces.google.com>) id 1kAMeo-00069K-8i for qemu-devel@nongnu.org; Mon, 24 Aug 2020 20:17:48 -0400 Received: by mail-pf1-x44a.google.com with SMTP id r25so7148155pfg.4 for ; Mon, 24 Aug 2020 17:17:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc:content-transfer-encoding; bh=rUEKve2Wm610Ab3YZTjgeg13+EN7IVaTgjJRV1dAi30=; b=eaBeM5FAdIxeoIk+u2nsWVVLQ9Y6q9BI8H73hYy0GFDFwDIc+aFQjVMILysLfcQGcI yqEo4FFgkbgOQjmKmwi/jaC9EHtHHWpFC4kbTDjEvown3U1S8+3cVPx0auUJBwSb8Qow sTq0kcVgrkUsvDafqMhVsyL6SQEP+vg5Ox9SqNzgsduDj+k1kFa1NwGEVhbqj1dtpaZW wyY2qKjcDvWQCne0Zk30RuhTpDVFcbC3d/et14szMRGqWpMUtDTenJx/h4GN6Cl+XdKJ 73L1a9ZrW5rAXPx8qukV+6MlzKBCeJLD97sPmnB0u+h95SPj+GCFBIrpTdCxQ1rPPVGr /+qQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=rUEKve2Wm610Ab3YZTjgeg13+EN7IVaTgjJRV1dAi30=; b=ChG5hNiVIkL03zBV1K/bxzTXfkI2PQdD5AZ4CUlinSt66WYHDxtuFQVAHccSfsFTTr bg6XFHCNQdxHYDxK/ceNGOuDS/OL4mTnaZgqYKszEmRQKvrdX9QHLvTjchgZW/sdxRhB m8JNLLj9E7EbRjg1PmcXA6baA5v7ngkR6xh6PUEgAuZ0zWsdMw2UrJ5ckc2lShJiUtDD Ss8OSzd0ze6Yh9EeA2nRoWi0TaGw1tnXICPh9Altcv9g2o/9WdexjXD10U8N6IuMuPsk dJm2qfAWZtfHGpzikG4Dcf/c1vxxz4W4WbHcxvorjb9ppEoTW3zB1rP27s6l6qrk2MDy jHxw== X-Gm-Message-State: AOAM532DdtyiaSXb0HgBNBWOFwzxLjzEtYZ2GXx1FwC2F1unvfYrb4TE MK0j/rr2bOffu2Shb+zBZlw1bItnOYip9/VPCQ== X-Google-Smtp-Source: ABdhPJyXKATQz5envJ95iECO18KZ3rjmNjvy4ZdFihaEp+YKTlWQzeZ/uxPtFOsPsInZv1HQR3kYyCjKRdbo9GqMQA== X-Received: from skybert.c.googlers.com ([fda3:e722:ac3:10:24:72f4:c0a8:3107]) (user=hskinnemoen job=sendgmr) by 2002:a17:902:6a88:: with SMTP id n8mr5816600plk.261.1598314662166; Mon, 24 Aug 2020 17:17:42 -0700 (PDT) Date: Mon, 24 Aug 2020 17:17:08 -0700 In-Reply-To: <20200825001711.1340443-1-hskinnemoen@google.com> Message-Id: <20200825001711.1340443-12-hskinnemoen@google.com> Mime-Version: 1.0 References: <20200825001711.1340443-1-hskinnemoen@google.com> X-Mailer: git-send-email 2.28.0.297.g1956fa8f8d-goog Subject: [PATCH v8 11/14] hw/arm: Wire up BMC boot flash for npcm750-evb and quanta-gsj To: peter.maydell@linaro.org, f4bug@amsat.org Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, Avi.Fishman@nuvoton.com, kfting@nuvoton.com, Havard Skinnemoen , "=?UTF-8?q?C=C3=A9dric=20Le=20Goater?=" 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::44a; envelope-from=3plhEXwsKCmkOZRPUULTVLUNVVNSL.JVTXLTb-KLcLSUVUNUb.VYN@flex--hskinnemoen.bounces.google.com; helo=mail-pf1-x44a.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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" Reply-to: Havard Skinnemoen From: Havard Skinnemoen via X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This allows these NPCM7xx-based boards to boot from a flash image, e.g. one built with OpenBMC. For example like this: IMAGE=3D${OPENBMC}/build/tmp/deploy/images/gsj/image-bmc qemu-system-arm -machine quanta-gsj -nographic \ -drive file=3D${IMAGE},if=3Dmtd,bus=3D0,unit=3D0,format=3Draw,snapshot=3Don Reviewed-by: Tyrone Ting Reviewed-by: C=C3=A9dric Le Goater Tested-by: C=C3=A9dric Le Goater Signed-off-by: Havard Skinnemoen Tested-by: Alexander Bulekov Tested-by: Philippe Mathieu-Daud=C3=A9 --- hw/arm/npcm7xx_boards.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/hw/arm/npcm7xx_boards.c b/hw/arm/npcm7xx_boards.c index b67e45e913..70e5c34216 100644 --- a/hw/arm/npcm7xx_boards.c +++ b/hw/arm/npcm7xx_boards.c @@ -19,6 +19,7 @@ #include "hw/arm/npcm7xx.h" #include "hw/core/cpu.h" #include "hw/loader.h" +#include "hw/qdev-properties.h" #include "qapi/error.h" #include "qemu-common.h" #include "qemu/units.h" @@ -55,6 +56,22 @@ static void npcm7xx_load_bootrom(MachineState *machine, = NPCM7xxState *soc) } } =20 +static void npcm7xx_connect_flash(NPCM7xxFIUState *fiu, int cs_no, + const char *flash_type, DriveInfo *dinfo) +{ + DeviceState *flash; + qemu_irq flash_cs; + + flash =3D qdev_new(flash_type); + if (dinfo) { + qdev_prop_set_drive(flash, "drive", blk_by_legacy_dinfo(dinfo)); + } + qdev_realize_and_unref(flash, BUS(fiu->spi), &error_fatal); + + flash_cs =3D qdev_get_gpio_in_named(flash, SSI_GPIO_CS, 0); + qdev_connect_gpio_out_named(DEVICE(fiu), "cs", cs_no, flash_cs); +} + static void npcm7xx_connect_dram(NPCM7xxState *soc, MemoryRegion *dram) { memory_region_add_subregion(get_system_memory(), NPCM7XX_DRAM_BA, dram= ); @@ -92,6 +109,7 @@ static void npcm750_evb_init(MachineState *machine) qdev_realize(DEVICE(soc), NULL, &error_fatal); =20 npcm7xx_load_bootrom(machine, soc); + npcm7xx_connect_flash(&soc->fiu[0], 0, "w25q256", drive_get(IF_MTD, 0,= 0)); npcm7xx_load_kernel(machine, soc); } =20 @@ -104,6 +122,8 @@ static void quanta_gsj_init(MachineState *machine) qdev_realize(DEVICE(soc), NULL, &error_fatal); =20 npcm7xx_load_bootrom(machine, soc); + npcm7xx_connect_flash(&soc->fiu[0], 0, "mx25l25635e", + drive_get(IF_MTD, 0, 0)); npcm7xx_load_kernel(machine, soc); } =20 --=20 2.28.0.297.g1956fa8f8d-goog From nobody Sun May 19 05:51:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=1598315054; cv=none; d=zohomail.com; s=zohoarc; b=Bc16yA/tv11CGYpTImOP87xFpdGvSqiUEVANoGlxVYjiVSaDkdo9nD/Ojz/8ZqQs2oZU5GlkdNTuIXNe9vGRBYJwydVjUAJVT3YTVHpk4r6GUK2Q4M9elaCZU/LZEREzifptlDYFePpwKhIoQzQZEC0mbweiGFBcGX9qFF3fI5o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598315054; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=1eUKc4mUKGxpAfRnn7edRuE+wT0NYPxDKPSyLd06AXc=; b=BOQARUehos0i9UsDmPGgEG+o8fj9lStKkdZ7XmUJgw5X/7TtBh1C7A63GGj9qtusuPuK/W32/0pq0e3YSyr4c1j4HTIa6r3hV3YcOklfkaE73Q6OQqJVwUWF2b+1mWzcxt5RP3zLDYBuBsfe6ndS4Y8hdNVlONsiXJjUzn1i8Ok= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1598315054156732.8444194714793; Mon, 24 Aug 2020 17:24:14 -0700 (PDT) Received: from localhost ([::1]:52760 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kAMl2-0007VN-J6 for importer@patchew.org; Mon, 24 Aug 2020 20:24:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45466) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3qFhEXwsKCmsQbTRWWNVXNWPXXPUN.LXVZNVd-MNeNUWXWPWd.XaP@flex--hskinnemoen.bounces.google.com>) id 1kAMes-0004Va-Vy for qemu-devel@nongnu.org; Mon, 24 Aug 2020 20:17:51 -0400 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]:38511) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3qFhEXwsKCmsQbTRWWNVXNWPXXPUN.LXVZNVd-MNeNUWXWPWd.XaP@flex--hskinnemoen.bounces.google.com>) id 1kAMep-00069Y-Q1 for qemu-devel@nongnu.org; Mon, 24 Aug 2020 20:17:50 -0400 Received: by mail-yb1-xb49.google.com with SMTP id l13so12783461ybf.5 for ; Mon, 24 Aug 2020 17:17:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=1eUKc4mUKGxpAfRnn7edRuE+wT0NYPxDKPSyLd06AXc=; b=i93oxQc97gPif+5l4MHVqnL0YPMUFlN8wvY3LI9yWOg2mHfMPjZqLRqsQqH2ZNGD53 uevKckWnlmqo2HG4m9p3FxLYYDgsBVFk9xZWf/KjF2fUZs5BsaAWOeV4lmHe6Gq0PIOl y6Veokzd3DM7fI5DO3EJks/63EmZLKJv3cqzXJgtrkQZiCw0Gprnq9eDBr9VoskVB/r0 Gx5cQilHKjRRZhTJU8mvC8ZRDoq+TERAdsnDFDiUBLK6dXDvenB55D3Uo6awa9Mc5O5M Hs14JjX+++uxtEQMY7VDFU9ZhHS1H39ct+JdyNTxAL1h7DlL0/4TStCHfNv8v5CwEbtF Vcxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=1eUKc4mUKGxpAfRnn7edRuE+wT0NYPxDKPSyLd06AXc=; b=DG6IyTmWVKlloM0kPsUCtD36PhAv0N4fLVxWw5zisma/mkCTv/qc1ESIk/l+JIuQ8Z Jef1zxeZ/Fn/SiRXJVYzv80Z1Kx571nM0hDdq1+ru6CPo+xzGiIRjQpv0DekepTAgtc7 r8B1Yq9fIlRWq8qUA2LKMRX/iBKxn3mIfTt5quWbwj/snIJhnVGynzdAZ/MIOikZlqx5 Fd+D0UBXsUOX3Lm71xDIypATj+7bzz93UIFHZvdUz+CIPYYDV52k5/VO9oLy42wc0LFE u4m6BcSeip9UjRS5m+X8f5opEmIDkT/zk7L0PvUA7kMya5gG7tYLP2BcLVmbge2bDIm+ 5dmQ== X-Gm-Message-State: AOAM530obiKZyslmqCKgNeKazk0qkqQCiYiZr/51L99pGW0lpDDG+d3i 3lQaGd1ajRs1EHPKsvRn3mMaNRwtntHbH5fPjQ== X-Google-Smtp-Source: ABdhPJzd9A40C16FQ7mckCF2szmBWC4wIp0sz2fyD7zOHFPIGpTyPZMmbiOUOa0VGQUEpRzvWd2lKxkp0bX+4XYlTg== X-Received: from skybert.c.googlers.com ([fda3:e722:ac3:10:24:72f4:c0a8:3107]) (user=hskinnemoen job=sendgmr) by 2002:a25:9004:: with SMTP id s4mr10468658ybl.247.1598314664144; Mon, 24 Aug 2020 17:17:44 -0700 (PDT) Date: Mon, 24 Aug 2020 17:17:09 -0700 In-Reply-To: <20200825001711.1340443-1-hskinnemoen@google.com> Message-Id: <20200825001711.1340443-13-hskinnemoen@google.com> Mime-Version: 1.0 References: <20200825001711.1340443-1-hskinnemoen@google.com> X-Mailer: git-send-email 2.28.0.297.g1956fa8f8d-goog Subject: [PATCH v8 12/14] hw/arm/npcm7xx: add board setup stub for CPU and UART clocks To: peter.maydell@linaro.org, f4bug@amsat.org Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, Avi.Fishman@nuvoton.com, kfting@nuvoton.com, Havard Skinnemoen 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::b49; envelope-from=3qFhEXwsKCmsQbTRWWNVXNWPXXPUN.LXVZNVd-MNeNUWXWPWd.XaP@flex--hskinnemoen.bounces.google.com; helo=mail-yb1-xb49.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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" Reply-to: Havard Skinnemoen From: Havard Skinnemoen via X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When booting directly into a kernel, bypassing the boot loader, the CPU and UART clocks are not set up correctly. This makes the system appear very slow, and causes the initrd boot test to fail when optimization is off. The UART clock must run at 24 MHz. The default 25 MHz reference clock cannot achieve this, so switch to PLL2/2 @ 480 MHz, which works perfectly with the default /20 divider. The CPU clock should run at 800 MHz, so switch it to PLL1/2. PLL1 runs at 800 MHz by default, so we need to double the feedback divider as well to make it run at 1600 MHz (so PLL1/2 runs at 800 MHz). We don't bother checking for PLL lock because we know our emulated PLLs lock instantly. Signed-off-by: Havard Skinnemoen Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Alexander Bulekov Tested-by: Philippe Mathieu-Daud=C3=A9 --- include/hw/arm/npcm7xx.h | 1 + hw/arm/npcm7xx.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h index 78d0d78c52..13106af215 100644 --- a/include/hw/arm/npcm7xx.h +++ b/include/hw/arm/npcm7xx.h @@ -37,6 +37,7 @@ #define NPCM7XX_SMP_LOADER_START (0xffff0000) /* Boot ROM */ #define NPCM7XX_SMP_BOOTREG_ADDR (0xf080013c) /* GCR.SCRPAD */ #define NPCM7XX_GIC_CPU_IF_ADDR (0xf03fe100) /* GIC within A9 */ +#define NPCM7XX_BOARD_SETUP_ADDR (0xffff1000) /* Boot ROM */ =20 typedef struct NPCM7xxMachine { MachineState parent; diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c index 7884b2b03d..037f3a26f2 100644 --- a/hw/arm/npcm7xx.c +++ b/hw/arm/npcm7xx.c @@ -55,6 +55,13 @@ #define NPCM7XX_ROM_BA (0xffff0000) #define NPCM7XX_ROM_SZ (64 * KiB) =20 +/* Clock configuration values to be fixed up when bypassing bootloader */ + +/* Run PLL1 at 1600 MHz */ +#define NPCM7XX_PLLCON1_FIXUP_VAL (0x00402101) +/* Run the CPU from PLL1 and UART from PLL2 */ +#define NPCM7XX_CLKSEL_FIXUP_VAL (0x004aaba9) + /* * Interrupt lines going into the GIC. This does not include internal Cort= ex-A9 * interrupts. @@ -132,6 +139,29 @@ static const struct { }, }; =20 +static void npcm7xx_write_board_setup(ARMCPU *cpu, + const struct arm_boot_info *info) +{ + uint32_t board_setup[] =3D { + 0xe59f0010, /* ldr r0, clk_base_addr */ + 0xe59f1010, /* ldr r1, pllcon1_value */ + 0xe5801010, /* str r1, [r0, #16] */ + 0xe59f100c, /* ldr r1, clksel_value */ + 0xe5801004, /* str r1, [r0, #4] */ + 0xe12fff1e, /* bx lr */ + NPCM7XX_CLK_BA, + NPCM7XX_PLLCON1_FIXUP_VAL, + NPCM7XX_CLKSEL_FIXUP_VAL, + }; + int i; + + for (i =3D 0; i < ARRAY_SIZE(board_setup); i++) { + board_setup[i] =3D tswap32(board_setup[i]); + } + rom_add_blob_fixed("board-setup", board_setup, sizeof(board_setup), + info->board_setup_addr); +} + static void npcm7xx_write_secondary_boot(ARMCPU *cpu, const struct arm_boot_info *info) { @@ -170,6 +200,8 @@ static struct arm_boot_info npcm7xx_binfo =3D { .gic_cpu_if_addr =3D NPCM7XX_GIC_CPU_IF_ADDR, .write_secondary_boot =3D npcm7xx_write_secondary_boot, .board_id =3D -1, + .board_setup_addr =3D NPCM7XX_BOARD_SETUP_ADDR, + .write_board_setup =3D npcm7xx_write_board_setup, }; =20 void npcm7xx_load_kernel(MachineState *machine, NPCM7xxState *soc) --=20 2.28.0.297.g1956fa8f8d-goog From nobody Sun May 19 05:51:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=1598314958; cv=none; d=zohomail.com; s=zohoarc; b=RgaOYpBZ4JfGbY4+2Lcj6zqqOfyEqszL8ThDtzpnHyjamygprDGz71K0KKebBLWWqUOAW+XglTqr2JR3P5c9ZHJNuVyj4K/7U66P/nQ36c5TqhktpHrVYGi5yhu8Obs1NOCrWDxpBOKMRsxls1n/QNkQ9cGgvcgkP2AvVzKjxYE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598314958; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=6eVxEPiI7t6I3JgtVPWz38hP0zfRd4fzJ+hFmyoviss=; b=cuoPmkJd3l0oyvTfLh0IDKshmBucXtU1EFPEydjEy81mzLmwcCxsvo20tWZI9EBm5WCB3OCUHE7k66Dfs1Si80+sHzpmhUZtPbCXze8fe0BNCU8jlW1lbM/fRnLBpd3cuknaa3SSdXQ+aD20TBtejpowTtLNGMFdV2lxIt2YWlM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 15983149583478.241575089043067; Mon, 24 Aug 2020 17:22:38 -0700 (PDT) Received: from localhost ([::1]:46462 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kAMjV-0004xq-4W for importer@patchew.org; Mon, 24 Aug 2020 20:22:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45464) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3qVhEXwsKCmwRcUSXXOWYOXQYYQVO.MYWaOWe-NOfOVXYXQXe.YbQ@flex--hskinnemoen.bounces.google.com>) id 1kAMes-0004VR-UH for qemu-devel@nongnu.org; Mon, 24 Aug 2020 20:17:50 -0400 Received: from mail-pj1-x1049.google.com ([2607:f8b0:4864:20::1049]:57368) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3qVhEXwsKCmwRcUSXXOWYOXQYYQVO.MYWaOWe-NOfOVXYXQXe.YbQ@flex--hskinnemoen.bounces.google.com>) id 1kAMeq-00069p-91 for qemu-devel@nongnu.org; Mon, 24 Aug 2020 20:17:50 -0400 Received: by mail-pj1-x1049.google.com with SMTP id mu14so428419pjb.7 for ; Mon, 24 Aug 2020 17:17:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc:content-transfer-encoding; bh=6eVxEPiI7t6I3JgtVPWz38hP0zfRd4fzJ+hFmyoviss=; b=BSOD3ErFS6kdwVi5lqh68vd3Zlv1IYLjYhCl8XMa6tDXzAiLe6ACTbxHgBh82PIeLc q19b1BSJIhvc6z4aRUdWKsbh6QrIILLYwhxvF4V0tcvBPbcH0q7h9QfXrPEb7xFTaUGC Kq/JrOTBPo6ps9KlN9bxmkPCPYmzw/qoiKyyVNU6fBWovOr7/Li2TdwiXlzJy77YQRSw vzBGjW7j0wqL65W//TGX5r8/TpZ/BswPvBJjSBj2/sh49y6+dRYHoBnJKA9beuBxBN9e /ZuKrYN2qAKu2D7z9UWfSROS08KD4DCP4KyFMW5xCvTRW34bTo5APL8i7u7h6o/75L6v Z5lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=6eVxEPiI7t6I3JgtVPWz38hP0zfRd4fzJ+hFmyoviss=; b=gzdiW7MjW4NenRtTPY4lTjgjSxAmGctSdzUlwpZ3RiKJQKHPsvw3eZvXC0PcHG7RPF 6tH7U7URMVupxDY0CKN9sjnSsImeD3SbcKZECtE2HH7lRH0+Df3fV3qcmagospy7JzDq sp34ELrkqgO+0oP3QwRlphTJhLmPcNJpiJACykvnuEFaqDZdZ9YalsnhWkUNVnLgTV3S G87OPraJHj3NyNgDa3og0B6FYSuqiTenp2yVD5Bqclm9Gy/3wVQhMqy0kVdHmjXdJGsP xMJtDk3NUjMddlZCciKt4iKL5gjzjCod6rD+FMCfxGkvZsB1JRxEyGePRIIs3ZwdO5RB F/GQ== X-Gm-Message-State: AOAM5321JmrDuY/cceWxwWiRXUmFX07x/UWVrJhXlUPrqwMaD/rS6TNK 8VMociqocR0y525fOPlTrU8b0rr8c99ZFsqnAA== X-Google-Smtp-Source: ABdhPJy/sNBG8taPcAEHdCs5BUaJG1Z24zzC6b+2aBIabjuiGSEZ6IOlNHwE9bAYM0bB6j5FepOlr0Xu5mYeb97zfw== X-Received: from skybert.c.googlers.com ([fda3:e722:ac3:10:24:72f4:c0a8:3107]) (user=hskinnemoen job=sendgmr) by 2002:a62:ed1a:: with SMTP id u26mr5991919pfh.121.1598314665854; Mon, 24 Aug 2020 17:17:45 -0700 (PDT) Date: Mon, 24 Aug 2020 17:17:10 -0700 In-Reply-To: <20200825001711.1340443-1-hskinnemoen@google.com> Message-Id: <20200825001711.1340443-14-hskinnemoen@google.com> Mime-Version: 1.0 References: <20200825001711.1340443-1-hskinnemoen@google.com> X-Mailer: git-send-email 2.28.0.297.g1956fa8f8d-goog Subject: [PATCH v8 13/14] docs/system: Add Nuvoton machine documentation To: peter.maydell@linaro.org, f4bug@amsat.org Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, Avi.Fishman@nuvoton.com, kfting@nuvoton.com, Havard Skinnemoen , "=?UTF-8?q?C=C3=A9dric=20Le=20Goater?=" 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::1049; envelope-from=3qVhEXwsKCmwRcUSXXOWYOXQYYQVO.MYWaOWe-NOfOVXYXQXe.YbQ@flex--hskinnemoen.bounces.google.com; helo=mail-pj1-x1049.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_PDS_OTHER_BAD_TLD=0.01, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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" Reply-to: Havard Skinnemoen From: Havard Skinnemoen via X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: Havard Skinnemoen Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Alexander Bulekov Tested-by: Philippe Mathieu-Daud=C3=A9 --- docs/system/arm/nuvoton.rst | 90 +++++++++++++++++++++++++++++++++++++ docs/system/target-arm.rst | 1 + 2 files changed, 91 insertions(+) create mode 100644 docs/system/arm/nuvoton.rst diff --git a/docs/system/arm/nuvoton.rst b/docs/system/arm/nuvoton.rst new file mode 100644 index 0000000000..36bf901122 --- /dev/null +++ b/docs/system/arm/nuvoton.rst @@ -0,0 +1,90 @@ +Nuvoton iBMC boards (``npcm750-evb``, ``quanta-gsj``) +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D + +The `Nuvoton iBMC`_ chips (NPCM7xx) are a family of ARM-based SoCs that are +designed to be used as Baseboard Management Controllers (BMCs) in various +servers. They all feature one or two ARM Cortex A9 CPU cores, as well as an +assortment of peripherals targeted for either Enterprise or Data Center / +Hyperscale applications. The former is a superset of the latter, so NPCM75= 0 has +all the peripherals of NPCM730 and more. + +.. _Nuvoton iBMC: https://www.nuvoton.com/products/cloud-computing/ibmc/ + +The NPCM750 SoC has two Cortex A9 cores and is targeted for the Enterprise +segment. The following machines are based on this chip : + +- ``npcm750-evb`` Nuvoton NPCM750 Evaluation board + +The NPCM730 SoC has two Cortex A9 cores and is targeted for Data Center and +Hyperscale applications. The following machines are based on this chip : + +- ``quanta-gsj`` Quanta GSJ server BMC + +There are also two more SoCs, NPCM710 and NPCM705, which are single-core +variants of NPCM750 and NPCM730, respectively. These are currently not +supported by QEMU. + +Supported devices +----------------- + + * SMP (Dual Core Cortex-A9) + * Cortex-A9MPCore built-in peripherals: SCU, GIC, Global Timer, Private T= imer + and Watchdog. + * SRAM, ROM and DRAM mappings + * System Global Control Registers (GCR) + * Clock and reset controller (CLK) + * Timer controller (TIM) + * Serial ports (16550-based) + * DDR4 memory controller (dummy interface indicating memory training is d= one) + * OTP controllers (no protection features) + * Flash Interface Unit (FIU; no protection features) + +Missing devices +--------------- + + * GPIO controller + * LPC/eSPI host-to-BMC interface, including + + * Keyboard and mouse controller interface (KBCI) + * Keyboard Controller Style (KCS) channels + * BIOS POST code FIFO + * System Wake-up Control (SWC) + * Shared memory (SHM) + * eSPI slave interface + + * Ethernet controllers (GMAC and EMC) + * USB host (USBH) + * USB device (USBD) + * SMBus controller (SMBF) + * Peripheral SPI controller (PSPI) + * Analog to Digital Converter (ADC) + * SD/MMC host + * Random Number Generator (RNG) + * PECI interface + * Pulse Width Modulation (PWM) + * Tachometer + * PCI and PCIe root complex and bridges + * VDM and MCTP support + * Serial I/O expansion + * LPC/eSPI host + * Coprocessor + * Graphics + * Video capture + * Encoding compression engine + * Security features + +Boot options +------------ + +The Nuvoton machines can boot from an OpenBMC firmware image, or directly = into +a kernel using the ``-kernel`` option. OpenBMC images for `quanta-gsj` and +possibly others can be downloaded from the OpenPOWER jenkins : + + https://openpower.xyz/ + +The firmware image should be attached as an MTD drive. Example : + +.. code-block:: bash + + $ qemu-system-arm -machine quanta-gsj -nographic \ + -drive file=3Dimage-bmc,if=3Dmtd,bus=3D0,unit=3D0,format=3Draw diff --git a/docs/system/target-arm.rst b/docs/system/target-arm.rst index afdb37e738..fdcf25c237 100644 --- a/docs/system/target-arm.rst +++ b/docs/system/target-arm.rst @@ -86,6 +86,7 @@ undocumented; you can get a complete list by running arm/musicpal arm/gumstix arm/nseries + arm/nuvoton arm/orangepi arm/palm arm/xscale --=20 2.28.0.297.g1956fa8f8d-goog From nobody Sun May 19 05:51:01 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=1598315071; cv=none; d=zohomail.com; s=zohoarc; b=DvQc9orySQBC0E27F04a3zjl9bDybIzw5IV/6P639+5ILHz9uMesZS0Nt43heIm7uo+VYLIzfH33ToMD3dTQyozCoRqXN2f1wLgTSOY+GhMmlQnT/CZIPd2pbU6/uq93rqowvY5LVQpb/6PzQEcwnTBWkKqyWTqBiOcOAAco6e4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598315071; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=Bm7spw+C0+41sKOlaxF7L66yvzmdTiJkotWkEKVYr68=; b=TXUtDxV2C6gR+XVKMJhSJVWS90y7vHgp3N/QypKjK37wbQSj0394qyzwc9v+Hm7IKlM/BDHShMhirih5b3/8yvKOHCBlhhFCxIvQemrMeBBYeHWQLgTWwVDXDtSZTEv1pK+SbsF8atvXP+iKqefq+i6/dAO4SGOGEzmzs4pVOVw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 1598315071801205.83280538095858; Mon, 24 Aug 2020 17:24:31 -0700 (PDT) Received: from localhost ([::1]:54284 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kAMlK-00089S-JN for importer@patchew.org; Mon, 24 Aug 2020 20:24:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45498) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3q1hEXwsKCm4TeWUZZQYaQZSaaSXQ.OaYcQYg-PQhQXZaZSZg.adS@flex--hskinnemoen.bounces.google.com>) id 1kAMeu-0004Wo-48 for qemu-devel@nongnu.org; Mon, 24 Aug 2020 20:17:52 -0400 Received: from mail-pj1-x1049.google.com ([2607:f8b0:4864:20::1049]:35267) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3q1hEXwsKCm4TeWUZZQYaQZSaaSXQ.OaYcQYg-PQhQXZaZSZg.adS@flex--hskinnemoen.bounces.google.com>) id 1kAMer-0006AB-FV for qemu-devel@nongnu.org; Mon, 24 Aug 2020 20:17:51 -0400 Received: by mail-pj1-x1049.google.com with SMTP id z8so446850pje.0 for ; Mon, 24 Aug 2020 17:17:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc:content-transfer-encoding; bh=Bm7spw+C0+41sKOlaxF7L66yvzmdTiJkotWkEKVYr68=; b=HPKYKVapabI3RLWrwYaXngmKudG+ym6kGklYWil1WrqfyvLjFt+AIbfoXq+g3WS8Mb yxrxKkPz75HRTyUpYcsX9dyHdLJJOFRHd1CYpBlHMVLR6TGIQkpsjmfG/GDSAa6hzC1J DagqdsWNyI+sLY8VkDcaQj+6pHJC+2eiXsXEAS+RG1IW03FHyNUw8pN8tz9Kudj6+hPr MBi9Pt5nGLXcPSVztd6cqnDkypFIgt3bZ4e0x7IBpjZDE1HA+nZh3z4moxy2AWTIosSh p4VbR/MDVZQv6H70w/n+AqIoZ7o4GUSut/3Ho/+s+KoZToxGuYS9DukS8RkqRH8c/z6p YWog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=Bm7spw+C0+41sKOlaxF7L66yvzmdTiJkotWkEKVYr68=; b=EhcXst1T9/YXKRRTtUCNgAGnzndOxxWxTmtQI3EUuO01xPZczSCSRSUpfzhZrdt3yV yPehdmevrTHKjMvED9PJzC4OJyUFNwZRtP2KrybLTxKBYr/HIRubq3ZM5h7YoCgOY6vF 6ZYvIgxBlu2+LfjBFfTx7GatvBCJOR9yInbr/7N6ZXj0RfM6pX+uDrsKKa7B0Yr2CRDL 3qXisxnNCO33PPgLWnfN/p5txlTrb2urJ/T2QyToswdfAMFkoelIhFvVPyL/1EAwBazT uJ31UJPfnXaSGmKplcaEB69lHjJul8BGdl0Vd6eFezLAOm2y44CgzsdnKG8Z8Vh0xk40 rSnw== X-Gm-Message-State: AOAM5322YhLG1MNYHS5IbSuWyeGjGTdGsBAX+w/w93j7vmEnc8V2w+Ze KRlTYdf3KvEOzJRDJHEZJQrN32QizPRgMP3MUA== X-Google-Smtp-Source: ABdhPJzIVap2ywO2wNYqR/Ui0TQX2EePssI+/SQ2oNOh0YvU9U18XZBDV+fwKerqkVONZ/ANaHI0fRD8xfnwv8hPgw== X-Received: from skybert.c.googlers.com ([fda3:e722:ac3:10:24:72f4:c0a8:3107]) (user=hskinnemoen job=sendgmr) by 2002:a62:7812:: with SMTP id t18mr5806056pfc.73.1598314667592; Mon, 24 Aug 2020 17:17:47 -0700 (PDT) Date: Mon, 24 Aug 2020 17:17:11 -0700 In-Reply-To: <20200825001711.1340443-1-hskinnemoen@google.com> Message-Id: <20200825001711.1340443-15-hskinnemoen@google.com> Mime-Version: 1.0 References: <20200825001711.1340443-1-hskinnemoen@google.com> X-Mailer: git-send-email 2.28.0.297.g1956fa8f8d-goog Subject: [PATCH v8 14/14] tests/acceptance: console boot tests for quanta-gsj To: peter.maydell@linaro.org, f4bug@amsat.org Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org, Avi.Fishman@nuvoton.com, kfting@nuvoton.com, Havard Skinnemoen 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::1049; envelope-from=3q1hEXwsKCm4TeWUZZQYaQZSaaSXQ.OaYcQYg-PQhQXZaZSZg.adS@flex--hskinnemoen.bounces.google.com; helo=mail-pj1-x1049.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -95 X-Spam_score: -9.6 X-Spam_bar: --------- X-Spam_report: (-9.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, USER_IN_DEF_DKIM_WL=-7.5 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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" Reply-to: Havard Skinnemoen From: Havard Skinnemoen via X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" This adds two acceptance tests for the quanta-gsj machine. One test downloads a lightly patched openbmc flash image from github and verifies that it boots all the way to the login prompt. The other test downloads a kernel, initrd and dtb built from the same openbmc source and verifies that the kernel detects all CPUs and boots to the point where it can't find the root filesystem (because we have no flash image in this case). Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Havard Skinnemoen Tested-by: Alexander Bulekov Tested-by: Philippe Mathieu-Daud=C3=A9 --- tests/acceptance/boot_linux_console.py | 83 ++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot= _linux_console.py index aaa781a581..4a366ce93e 100644 --- a/tests/acceptance/boot_linux_console.py +++ b/tests/acceptance/boot_linux_console.py @@ -568,6 +568,89 @@ class BootLinuxConsole(LinuxKernelTest): 'sda') # cubieboard's reboot is not functioning; omit reboot test. =20 + def test_arm_quanta_gsj(self): + """ + :avocado: tags=3Darch:arm + :avocado: tags=3Dmachine:quanta-gsj + """ + # 25 MiB compressed, 32 MiB uncompressed. + image_url =3D ( + 'https://github.com/hskinnemoen/openbmc/releases/download/' + '20200711-gsj-qemu-0/obmc-phosphor-image-gsj.static.mtd.gz= ') + image_hash =3D '14895e634923345cb5c8776037ff7876df96f6b1' + image_path_gz =3D self.fetch_asset(image_url, asset_hash=3Dimage_h= ash) + image_name =3D 'obmc.mtd' + image_path =3D os.path.join(self.workdir, image_name) + archive.gzip_uncompress(image_path_gz, image_path) + + self.vm.set_console() + drive_args =3D 'file=3D' + image_path + ',if=3Dmtd,bus=3D0,unit=3D= 0' + self.vm.add_args('-drive', drive_args) + self.vm.launch() + + # Disable drivers and services that stall for a long time during b= oot, + # to avoid running past the 90-second timeout. These may be removed + # as the corresponding device support is added. + kernel_command_line =3D self.KERNEL_COMMON_COMMAND_LINE + ( + 'console=3D${console} ' + 'mem=3D${mem} ' + 'initcall_blacklist=3Dnpcm_i2c_bus_driver_init ' + 'systemd.mask=3Dsystemd-random-seed.service ' + 'systemd.mask=3Ddropbearkey.service ' + ) + + self.wait_for_console_pattern('> BootBlock by Nuvoton') + self.wait_for_console_pattern('>Device: Poleg BMC NPCM730') + self.wait_for_console_pattern('>Skip DDR init.') + self.wait_for_console_pattern('U-Boot ') + interrupt_interactive_console_until_pattern( + self, 'Hit any key to stop autoboot:', 'U-Boot>') + exec_command_and_wait_for_pattern( + self, "setenv bootargs ${bootargs} " + kernel_command_line, + 'U-Boot>') + exec_command_and_wait_for_pattern( + self, 'run romboot', 'Booting Kernel from flash') + self.wait_for_console_pattern('Booting Linux on physical CPU 0x0') + self.wait_for_console_pattern('CPU1: thread -1, cpu 1, socket 0') + self.wait_for_console_pattern('OpenBMC Project Reference Distro') + self.wait_for_console_pattern('gsj login:') + + def test_arm_quanta_gsj_initrd(self): + """ + :avocado: tags=3Darch:arm + :avocado: tags=3Dmachine:quanta-gsj + """ + initrd_url =3D ( + 'https://github.com/hskinnemoen/openbmc/releases/download/' + '20200711-gsj-qemu-0/obmc-phosphor-initramfs-gsj.cpio.xz') + initrd_hash =3D '98fefe5d7e56727b1eb17d5c00311b1b5c945300' + initrd_path =3D self.fetch_asset(initrd_url, asset_hash=3Dinitrd_h= ash) + kernel_url =3D ( + 'https://github.com/hskinnemoen/openbmc/releases/download/' + '20200711-gsj-qemu-0/uImage-gsj.bin') + kernel_hash =3D 'fa67b2f141d56d39b3c54305c0e8a899c99eb2c7' + kernel_path =3D self.fetch_asset(kernel_url, asset_hash=3Dkernel_h= ash) + dtb_url =3D ( + 'https://github.com/hskinnemoen/openbmc/releases/download/' + '20200711-gsj-qemu-0/nuvoton-npcm730-gsj.dtb') + dtb_hash =3D '18315f7006d7b688d8312d5c727eecd819aa36a4' + dtb_path =3D self.fetch_asset(dtb_url, asset_hash=3Ddtb_hash) + + self.vm.set_console() + kernel_command_line =3D (self.KERNEL_COMMON_COMMAND_LINE + + 'console=3DttyS0,115200n8 ' + 'earlycon=3Duart8250,mmio32,0xf0001000') + self.vm.add_args('-kernel', kernel_path, + '-initrd', initrd_path, + '-dtb', dtb_path, + '-append', kernel_command_line) + self.vm.launch() + + self.wait_for_console_pattern('Booting Linux on physical CPU 0x0') + self.wait_for_console_pattern('CPU1: thread -1, cpu 1, socket 0') + self.wait_for_console_pattern( + 'Give root password for system maintenance') + def test_arm_orangepi(self): """ :avocado: tags=3Darch:arm --=20 2.28.0.297.g1956fa8f8d-goog