From nobody Sun Apr 28 16:09:30 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1594255067; cv=none; d=zohomail.com; s=zohoarc; b=YXart9qypk7g3cikFyWmrLnvCDc6XLlGxYYDXO9/tGbVFj+dF9EyJO5yK2/6zFb3zJmuFsnDV3gxUADMyOecYzroP+8gKdS7RKUuL1/7v0+mxx58xvHVPooLrsoaHsWJ73yc8bm7tsR8/YorCUP9a2UwN6lRlmugCyLNp/qontU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594255067; 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:References:Sender:Subject:To; bh=lrKRk7BwvWnw1gIsSVH7zHuPuTHTBnigFtRalcwc1Vg=; b=DEqy2hyXRLGG+OGvgVpadEUo5mXduDh4z449/4+YFoyCEvadf1MQHXxTAkyvKsNj+18FXhfBgoVt6EXYx9XMStz8N6CiGcPVRRPyyuag6o0mBw8HVEsMcC1NSqn3qLnoiQDdDL5qFquFBLzPIoaY3SSsebNCvORMalABpf+h2B0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1594255067737863.0773375381277; Wed, 8 Jul 2020 17:37:47 -0700 (PDT) Received: from localhost ([::1]:52022 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jtKZO-00080W-9v for importer@patchew.org; Wed, 08 Jul 2020 20:37:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48026) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3i2YGXwsKCnAVgYWbbSacSbUccUZS.QcaeSai-RSjSZbcbUbi.cfU@flex--hskinnemoen.bounces.google.com>) id 1jtKYC-0006G0-IG for qemu-devel@nongnu.org; Wed, 08 Jul 2020 20:36:32 -0400 Received: from mail-qt1-x849.google.com ([2607:f8b0:4864:20::849]:51887) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3i2YGXwsKCnAVgYWbbSacSbUccUZS.QcaeSai-RSjSZbcbUbi.cfU@flex--hskinnemoen.bounces.google.com>) id 1jtKY8-00010j-Go for qemu-devel@nongnu.org; Wed, 08 Jul 2020 20:36:32 -0400 Received: by mail-qt1-x849.google.com with SMTP id h24so395356qtk.18 for ; Wed, 08 Jul 2020 17:36:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc:content-transfer-encoding; bh=lrKRk7BwvWnw1gIsSVH7zHuPuTHTBnigFtRalcwc1Vg=; b=ZrzVp2f9XUpC7LjTlwPbgVRgAC+8e1LZw9yZgelEUpcYwe9sIXcmilqhKCP6dAazni z+p23RWkCXByxP44vkb7bgt5ceafPF47lVRFcxRug4OYzywsEzukN0CyOds1dmI/3wkH nns0NfwVBYo1jEkaQm3rspCaKwuasJzadytmdsa9aXsfP7PyE6oHmKZHnnPONBn9zVh7 0K/gj19oFozVw5XY2uZgLPgb6tu6G10ZJ6dAHqxtniu8BBaFR9q8sDTKV0jsT6Vm+j2m JKtx/jLYB7FHOpSQoyo/bqiW1rXwBAyDgc/lGSVXqX10aFyfcOanG1YQSBhUBYQMZmxy zTJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=lrKRk7BwvWnw1gIsSVH7zHuPuTHTBnigFtRalcwc1Vg=; b=d5SB4SMMaGp+uJ1fn+RiaP7AMPzYxuhXIKDADoHjiI2Tk5Xo/fcS6FZVsqoqC6EMn2 9avOz2A/H6FxI34xHAc6mGgZpT4ayIQFIzAVpsgwInlr/E5R9bVqSZs/UBgdTt4XkvE6 AOp5JVoKBPc+nbVUr0RO//tbA1GEpaSK0GqmhmfChdX5Undd+nS5/+CD0hfqL3n/w1oj F3w+uNJsBThzB6fAiUj46xloCqQd1MYb844b6+4JpeP43nGSf3WSZ7JJD7C69nLAIZgM lnZKUWoza9SMcKSK/7TrYd817XPG9sb7QYaefqmEFeXyNPH0s4Ws5AoqxxuNbXzqTw2Y S84w== X-Gm-Message-State: AOAM530HXhufkSb/DZ3jykztIP+yxSd0ssPxvPzN0IfTs6dpF/xsBEdU I2PlfwtVWUJWMdt0cYL8wwaiDRpOjuL/OWD1ow== X-Google-Smtp-Source: ABdhPJwn2Si39Ian/VBGWGBueofcimwtaMwHhIdr7lQUZ6nOKSbBId/Etpm80/IE2yt1muFqUEjcmSVcgUsLT5T7Gg== X-Received: by 2002:a05:6214:612:: with SMTP id z18mr59415479qvw.46.1594254987275; Wed, 08 Jul 2020 17:36:27 -0700 (PDT) Date: Wed, 8 Jul 2020 17:35:58 -0700 In-Reply-To: <20200709003608.3834629-1-hskinnemoen@google.com> Message-Id: <20200709003608.3834629-2-hskinnemoen@google.com> Mime-Version: 1.0 References: <20200709003608.3834629-1-hskinnemoen@google.com> X-Mailer: git-send-email 2.27.0.383.g050319c2ae-goog Subject: [PATCH v5 01/11] hw/misc: Add NPCM7xx System Global Control Registers device model From: Havard Skinnemoen 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::849; envelope-from=3i2YGXwsKCnAVgYWbbSacSbUccUZS.QcaeSai-RSjSZbcbUbi.cfU@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: -105 X-Spam_score: -10.6 X-Spam_bar: ---------- X-Spam_report: (-10.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-1, 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" X-ZohoMail-DKIM: pass (identity @google.com) 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 Signed-off-by: Havard Skinnemoen Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/hw/misc/npcm7xx_gcr.h | 76 ++++++++++++ hw/misc/npcm7xx_gcr.c | 226 ++++++++++++++++++++++++++++++++++ MAINTAINERS | 8 ++ hw/arm/Kconfig | 3 + hw/misc/Makefile.objs | 1 + hw/misc/trace-events | 4 + 6 files changed, 318 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..4884676be2 --- /dev/null +++ b/include/hw/misc/npcm7xx_gcr.h @@ -0,0 +1,76 @@ +/* + * 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" + +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_NR_REGS, +}; + +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..9934cd238d --- /dev/null +++ b/hw/misc/npcm7xx_gcr.c @@ -0,0 +1,226 @@ +/* + * 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/log.h" +#include "qemu/module.h" +#include "qemu/units.h" + +#include "trace.h" + +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%04x out of range\n", + __func__, (unsigned int)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%04x out of range\n", + __func__, (unsigned int)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%04x is read-only= \n", + __func__, (unsigned int)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) +{ + NPCM7xxGCRState *s =3D NPCM7XX_GCR(dev); + uint64_t dram_size; + Error *err =3D NULL; + Object *obj; + + obj =3D object_property_get_link(OBJECT(dev), "dram-mr", &err); + if (!obj) { + error_setg(errp, "%s: required dram-mr link not found: %s", + __func__, error_get_pretty(err)); + return; + } + dram_size =3D memory_region_size(MEMORY_REGION(obj)); + + /* 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 or + * more of DRAM will be interpreted as 128 MiB. + * + * https://github.com/Nuvoton-Israel/u-boot/blob/2aef993bd2aafeb5408db= aad0f3ce099ee40c4aa/board/nuvoton/poleg/poleg.c#L244 + */ + if (dram_size >=3D 2 * GiB) { + s->reset_intcr3 |=3D 4 << 8; + } else if (dram_size >=3D 1 * GiB) { + s->reset_intcr3 |=3D 3 << 8; + } else if (dram_size >=3D 512 * MiB) { + s->reset_intcr3 |=3D 2 << 8; + } else if (dram_size >=3D 256 * MiB) { + s->reset_intcr3 |=3D 1 << 8; + } else if (dram_size >=3D 128 * MiB) { + s->reset_intcr3 |=3D 0 << 8; + } else { + error_setg(errp, + "npcm7xx_gcr: DRAM size %" PRIu64 + " is too small (need 128 MiB minimum)", + dram_size); + return; + } +} + +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); + + 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 42388f1de2..43173a338a 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -723,6 +723,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 4a224a6351..192a8dec3b 100644 --- a/hw/arm/Kconfig +++ b/hw/arm/Kconfig @@ -354,6 +354,9 @@ config XLNX_VERSAL select VIRTIO_MMIO select UNIMP =20 +config NPCM7XX + bool + config FSL_IMX25 bool select IMX diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs index 5aaca8a039..40a9d1c01e 100644 --- a/hw/misc/Makefile.objs +++ b/hw/misc/Makefile.objs @@ -51,6 +51,7 @@ common-obj-$(CONFIG_IMX) +=3D imx_rngc.o common-obj-$(CONFIG_MILKYMIST) +=3D milkymist-hpdmc.o common-obj-$(CONFIG_MILKYMIST) +=3D milkymist-pfpu.o common-obj-$(CONFIG_MAINSTONE) +=3D mst_fpga.o +common-obj-$(CONFIG_NPCM7XX) +=3D npcm7xx_gcr.o common-obj-$(CONFIG_OMAP) +=3D omap_clk.o common-obj-$(CONFIG_OMAP) +=3D omap_gpmc.o common-obj-$(CONFIG_OMAP) +=3D omap_l4.o diff --git a/hw/misc/trace-events b/hw/misc/trace-events index ebea53735c..48e2d54c49 100644 --- a/hw/misc/trace-events +++ b/hw/misc/trace-events @@ -107,6 +107,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.27.0.383.g050319c2ae-goog From nobody Sun Apr 28 16:09:30 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1594255169; cv=none; d=zohomail.com; s=zohoarc; b=hFYMlU4l0onFQKK29oK09PMBT1gQ9XM2YLb7T31k+NQB0c82H2Em+tMmWJzy+/ibOK0skfrhDRYMJsjg0lS9OLvRz94FfrrdHbdQ/oXDX3SP/anPUu+9rrRoBdITYTo3CtSgb+UV0LBgm0gagyc2rnVJ5PoPIhjgwqi0jpp5gEc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594255169; 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:References:Sender:Subject:To; bh=Az5MEOyAnNR/YmrbmPiQd03NkdlXuDYzBYW/rSQos6o=; b=nBhIigC1gz37+TO26CjU8/rhlqMan/5MYv7xk6We1VAJpV5njAoQPqnJw1RIYKrk4bs30K5Lw00mfM74At4JY0ndY/CY4Ho6lAmlAZkS25rCkMl6SQ2vHtqlcV3NwC/FZ88nn5a2dZuL/BHv1iyEzcoU7Qj10qGqA6I2TFX3jcw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1594255169897205.37433257004875; Wed, 8 Jul 2020 17:39:29 -0700 (PDT) Received: from localhost ([::1]:59998 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jtKb1-0002pB-KE for importer@patchew.org; Wed, 08 Jul 2020 20:39:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48030) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3jGYGXwsKCnEWhZXccTbdTcVddVaT.RdbfTbj-STkTacdcVcj.dgV@flex--hskinnemoen.bounces.google.com>) id 1jtKYD-0006GV-2e for qemu-devel@nongnu.org; Wed, 08 Jul 2020 20:36:33 -0400 Received: from mail-qk1-x74a.google.com ([2607:f8b0:4864:20::74a]:49771) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3jGYGXwsKCnEWhZXccTbdTcVddVaT.RdbfTbj-STkTacdcVcj.dgV@flex--hskinnemoen.bounces.google.com>) id 1jtKYA-00010u-NQ for qemu-devel@nongnu.org; Wed, 08 Jul 2020 20:36:32 -0400 Received: by mail-qk1-x74a.google.com with SMTP id a205so503638qkc.16 for ; Wed, 08 Jul 2020 17:36:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc:content-transfer-encoding; bh=Az5MEOyAnNR/YmrbmPiQd03NkdlXuDYzBYW/rSQos6o=; b=PwHjqfqmb+QaW64EUPg7frQSprm7ndsFgJYOAFuD6VeoByDQPOTIMRgI8g1erZ49i/ U138d3k6Z9b8nX1f2kBfrFQqTxJjM6iZg9euoWpsM6w3qUugZKdoocJl+/Fsq/WsRvCP ivj9mEXenUUZRhJIaG3eGdwrnT0rosSN1P1oQzjY0A1CT/Qd93KkxtwlKwLDPUZwufVy 9cmHYShOQHvq3GtLvH9zimyfs9vnLkfmnD0LtEF4qJeCscIcEQxU+sFKkcSv18JCRyrw jF3DYc88BEOQ51xTsweOHYqrHV9WXiJXukQOvad3OzzwxJN7m5UyKEaCuGlT82mcgaLe vD9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=Az5MEOyAnNR/YmrbmPiQd03NkdlXuDYzBYW/rSQos6o=; b=cjGj6QPQ4LfrkFs59hpTAi/taLtc6R/fDSTFU9qpf86xMXgHcFcjRse7V5zRxtK0VC K6+u9saBKuRdFl6hBgLMGYr2BVNfhnIkWx203n1L+A3bymKtpAujwM100QcI0AVWjXO3 FTpkTTXdTiCrurc7W9AhSpY5gFOxUdgSHQ8Wz5dXwadJmOlyd+0AfxsSdj/ayPXn1y/D 2A+atnpxkmQ0+cwf43x8UsQFb7tgyEOXkDEbtRFuQ2OIYaCLxUo96wqtNfHImbGzYzrx Knx4RftXl5OLaGNXrIj/f54TrvCdCMubgN+++GBZ9HbObmfo1Poqhku7or7R4esv9ef6 Vmxg== X-Gm-Message-State: AOAM53335qoJAm3xqj5K0jVoELkTAFF3u7j6xUmisyMxSe2FEj4f2p4T c9wEjllWkggkx3bQWQN9thFYX7fHFa+VrMqRkw== X-Google-Smtp-Source: ABdhPJzEU6lqxFidAmDdfgrTs4p3bvPcE2IjG0vhnoaUMyrFZ5525NOv2fdiUCprj5DNRA8ayFIt1Vyio9vGYEkVXw== X-Received: by 2002:a0c:f842:: with SMTP id g2mr60990570qvo.181.1594254988960; Wed, 08 Jul 2020 17:36:28 -0700 (PDT) Date: Wed, 8 Jul 2020 17:35:59 -0700 In-Reply-To: <20200709003608.3834629-1-hskinnemoen@google.com> Message-Id: <20200709003608.3834629-3-hskinnemoen@google.com> Mime-Version: 1.0 References: <20200709003608.3834629-1-hskinnemoen@google.com> X-Mailer: git-send-email 2.27.0.383.g050319c2ae-goog Subject: [PATCH v5 02/11] hw/misc: Add NPCM7xx Clock Controller device model From: Havard Skinnemoen 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::74a; envelope-from=3jGYGXwsKCnEWhZXccTbdTcVddVaT.RdbfTbj-STkTacdcVcj.dgV@flex--hskinnemoen.bounces.google.com; helo=mail-qk1-x74a.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: -105 X-Spam_score: -10.6 X-Spam_bar: ---------- X-Spam_report: (-10.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-1, 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" X-ZohoMail-DKIM: pass (identity @google.com) 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 --- include/hw/misc/npcm7xx_clk.h | 66 ++++++++++ hw/misc/npcm7xx_clk.c | 230 ++++++++++++++++++++++++++++++++++ hw/misc/Makefile.objs | 1 + hw/misc/trace-events | 4 + 4 files changed, 301 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..44afa1b105 --- /dev/null +++ b/include/hw/misc/npcm7xx_clk.h @@ -0,0 +1,66 @@ +/* + * 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" + +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_NR_REGS, +}; + +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..9c34b12ea9 --- /dev/null +++ b/hw/misc/npcm7xx_clk.c @@ -0,0 +1,230 @@ +/* + * 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) + +/* + * 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%04x out of range\n", + __func__, (unsigned int)offset); + return 0; + } + + switch (reg) { + case NPCM7XX_CLK_SWRSTR: + qemu_log_mask(LOG_GUEST_ERROR, "%s: register @ 0x%04x is write-onl= y\n", + __func__, (unsigned int)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) % 25000000; + 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%04x out of range\n", + __func__, (unsigned int)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%04x is read-only= \n", + __func__, (unsigned int)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); + + 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/Makefile.objs b/hw/misc/Makefile.objs index 40a9d1c01e..2e74803005 100644 --- a/hw/misc/Makefile.objs +++ b/hw/misc/Makefile.objs @@ -51,6 +51,7 @@ common-obj-$(CONFIG_IMX) +=3D imx_rngc.o common-obj-$(CONFIG_MILKYMIST) +=3D milkymist-hpdmc.o common-obj-$(CONFIG_MILKYMIST) +=3D milkymist-pfpu.o common-obj-$(CONFIG_MAINSTONE) +=3D mst_fpga.o +common-obj-$(CONFIG_NPCM7XX) +=3D npcm7xx_clk.o common-obj-$(CONFIG_NPCM7XX) +=3D npcm7xx_gcr.o common-obj-$(CONFIG_OMAP) +=3D omap_clk.o common-obj-$(CONFIG_OMAP) +=3D omap_gpmc.o diff --git a/hw/misc/trace-events b/hw/misc/trace-events index 48e2d54c49..a531af5b79 100644 --- a/hw/misc/trace-events +++ b/hw/misc/trace-events @@ -107,6 +107,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.27.0.383.g050319c2ae-goog From nobody Sun Apr 28 16:09:30 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1594255073; cv=none; d=zohomail.com; s=zohoarc; b=jG+z91fm6uBhER/FqztRqbLGH4NvqyqBlWR1onne1qwtWhNpkfmiKMRtHNRJEAAThzVcfzVVnboEUdt3tUpA5HG6LvGdW0W52ENx1O170LP4J/hsnbxAxQ7ao5YcEa1O9KvE/jFUM8mDEnXoQ3rhqef/N4T+YIVHlk/cHtXbCtE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594255073; 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:References:Sender:Subject:To; bh=gQXKkrx2kXmWWQr3VUHVL8BwPnfFW7YkTDC2bKUG7Bw=; b=RjR67iGlRU8Pz7EMIvQsgGYP4c1U/s3B/YxgYVhDT/fHgFjmilpFisiZ9c+srx5MtdDMHxyXT11uZGc9SN9Ckq61D4IESIluDBp4bAyR8d59pM35cxyZuDLKnpi2jJkoebpNQLJpelV6fCzhnIWemfJN3VxUyzDrC/PMhisrmdE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1594255073585969.4114954429222; Wed, 8 Jul 2020 17:37:53 -0700 (PDT) Received: from localhost ([::1]:52540 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jtKZU-0008D5-21 for importer@patchew.org; Wed, 08 Jul 2020 20:37:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48078) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3j2YGXwsKCnQZkcaffWegWfYggYdW.UgeiWem-VWnWdfgfYfm.gjY@flex--hskinnemoen.bounces.google.com>) id 1jtKYG-0006Nr-PP for qemu-devel@nongnu.org; Wed, 08 Jul 2020 20:36:36 -0400 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]:39253) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3j2YGXwsKCnQZkcaffWegWfYggYdW.UgeiWem-VWnWdfgfYfm.gjY@flex--hskinnemoen.bounces.google.com>) id 1jtKYD-00011F-10 for qemu-devel@nongnu.org; Wed, 08 Jul 2020 20:36:36 -0400 Received: by mail-yb1-xb4a.google.com with SMTP id m81so781873ybf.6 for ; Wed, 08 Jul 2020 17:36:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=gQXKkrx2kXmWWQr3VUHVL8BwPnfFW7YkTDC2bKUG7Bw=; b=U3EVJvccvSJPcRqofjbEzxebm4RuZ6N2BOJDFyZgH+hopW5onFds6BNCHsQbpfefMD jmZAB1OXZnFiDTmEnzZ61IN2Rf2jU3AycsUE1kpzLvjYGIF7gOtqFMF3b4TzBMsZ948e Bn+csKn2rmohAZyXTwP85fcg2widhcROnGG4C8dSxIcBMfpqyifYwG4KQJ8IVoLbYAMd jSkD1TljQGsGrvzHFJ8K1bkVb50mO/+PENlN+Arze4dgWO/VAp0zSQco54z3zJjKWF7h 9tTtrzJILnbBDVTLVT2biaqSOemTlrVQZfNb/qyCo/bhOSDUDHOWfxd5dJhgze3qYsmy jKFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=gQXKkrx2kXmWWQr3VUHVL8BwPnfFW7YkTDC2bKUG7Bw=; b=PBf7mHjtnzJGKUTLsXnY/RROwhnwgReDBLKQpQCG4RJelOg+NQtyergMnIVS9ESCBK /76Z6AmBYhm760qgpA/OUYlBDO1/REQKMr6uC0adiOY41jq01SJ5MB76W0cfUlDH1kRF qHeJzY6Y6dRUWD432x9ZUceVQZ1SSFW7v5IvACXwJoiZrBKkdQn3gS5Y9dV6wOjfTZd9 wgK/FlI56lmCQ7H4vYmF/5SijGPmHGkQbc0KSVcwkSz9A/CwgnINerQ7DVY/MgN1snoH x7yGWGijBhQgW8jYrrHgGw2YTZHphM0qTIXo+bh7k0sHHy0f93zLnlSMKpJ0wl7WDt/O Eb9w== X-Gm-Message-State: AOAM533k3/1wlBBcYkMJMIiI2ULMQqxVWmcxmdeq/glvjMpCT3+B2WLZ AHLN8MSOtGsJMg3e0vvGG82UYYZi2qNWwGacTw== X-Google-Smtp-Source: ABdhPJxJI01QA9VcDfReL0BxSnEMpl9VKrbn29AJIsB2UvXhrmm3+UgASmWfrwT0fwW8rRC4a1P6yUyMCToVmvWN7g== X-Received: by 2002:a25:70c2:: with SMTP id l185mr39753573ybc.83.1594254991145; Wed, 08 Jul 2020 17:36:31 -0700 (PDT) Date: Wed, 8 Jul 2020 17:36:00 -0700 In-Reply-To: <20200709003608.3834629-1-hskinnemoen@google.com> Message-Id: <20200709003608.3834629-4-hskinnemoen@google.com> Mime-Version: 1.0 References: <20200709003608.3834629-1-hskinnemoen@google.com> X-Mailer: git-send-email 2.27.0.383.g050319c2ae-goog Subject: [PATCH v5 03/11] hw/timer: Add NPCM7xx Timer device model From: Havard Skinnemoen 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 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::b4a; envelope-from=3j2YGXwsKCnQZkcaffWegWfYggYdW.UgeiWem-VWnWdfgfYfm.gjY@flex--hskinnemoen.bounces.google.com; helo=mail-yb1-xb4a.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: -105 X-Spam_score: -10.6 X-Spam_bar: ---------- X-Spam_report: (-10.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-1, 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" X-ZohoMail-DKIM: pass (identity @google.com) Content-Transfer-Encoding: quoted-printable 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 Signed-off-by: Havard Skinnemoen --- include/hw/timer/npcm7xx_timer.h | 96 +++++++ hw/timer/npcm7xx_timer.c | 468 +++++++++++++++++++++++++++++++ hw/timer/Makefile.objs | 1 + hw/timer/trace-events | 5 + 4 files changed, 570 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..94900a7877 --- /dev/null +++ b/include/hw/timer/npcm7xx_timer.h @@ -0,0 +1,96 @@ +/* + * 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) + +/** + * enum NPCM7xxTimerRegisters - 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_NR_REGS, +}; + +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..b0a72aef75 --- /dev/null +++ b/hw/timer/npcm7xx_timer.c @@ -0,0 +1,468 @@ +/* + * 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/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" + +/* 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 + +/* The reference clock frequency is always 25 MHz. */ +#define NPCM7XX_TIMER_REF_HZ (25000000) + +/* 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; + /* Find the array index of this timer. */ + int index =3D t - tc->timer; + + g_assert(index >=3D 0 && index < NPCM7XX_TIMERS_PER_CTRL); + + if ((t->tcsr & NPCM7XX_TCSR_IE) && (tc->tisr & BIT(index))) { + qemu_irq_raise(t->irq); + trace_npcm7xx_timer_irq(DEVICE(tc)->canonical_path, index, 1); + } else { + qemu_irq_lower(t->irq); + trace_npcm7xx_timer_irq(DEVICE(tc)->canonical_path, index, 0); + } +} + +/* 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 t - tc->timer; + + g_assert(index >=3D 0 && index < NPCM7XX_TIMERS_PER_CTRL); + + 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; + if (t->remaining_ns <=3D 0) { + npcm7xx_timer_reached_zero(t); + } +} + +/* + * 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 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: + value =3D s->timer[0].tcsr; + break; + case NPCM7XX_TIMER_TCSR1: + value =3D s->timer[1].tcsr; + break; + case NPCM7XX_TIMER_TCSR2: + value =3D s->timer[2].tcsr; + break; + case NPCM7XX_TIMER_TCSR3: + value =3D s->timer[3].tcsr; + break; + case NPCM7XX_TIMER_TCSR4: + value =3D s->timer[4].tcsr; + break; + + case NPCM7XX_TIMER_TICR0: + value =3D s->timer[0].ticr; + break; + case NPCM7XX_TIMER_TICR1: + value =3D s->timer[1].ticr; + break; + case NPCM7XX_TIMER_TICR2: + value =3D s->timer[2].ticr; + break; + case NPCM7XX_TIMER_TICR3: + value =3D s->timer[3].ticr; + break; + case NPCM7XX_TIMER_TICR4: + value =3D s->timer[4].ticr; + break; + + case NPCM7XX_TIMER_TDR0: + value =3D npcm7xx_timer_read_tdr(&s->timer[0]); + break; + case NPCM7XX_TIMER_TDR1: + value =3D npcm7xx_timer_read_tdr(&s->timer[1]); + break; + case NPCM7XX_TIMER_TDR2: + value =3D npcm7xx_timer_read_tdr(&s->timer[2]); + break; + case NPCM7XX_TIMER_TDR3: + value =3D npcm7xx_timer_read_tdr(&s->timer[3]); + break; + case NPCM7XX_TIMER_TDR4: + value =3D npcm7xx_timer_read_tdr(&s->timer[4]); + 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%04x\n", + __func__, (unsigned int)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: + npcm7xx_timer_write_tcsr(&s->timer[0], value); + return; + case NPCM7XX_TIMER_TCSR1: + npcm7xx_timer_write_tcsr(&s->timer[1], value); + return; + case NPCM7XX_TIMER_TCSR2: + npcm7xx_timer_write_tcsr(&s->timer[2], value); + return; + case NPCM7XX_TIMER_TCSR3: + npcm7xx_timer_write_tcsr(&s->timer[3], value); + return; + case NPCM7XX_TIMER_TCSR4: + npcm7xx_timer_write_tcsr(&s->timer[4], value); + return; + + case NPCM7XX_TIMER_TICR0: + npcm7xx_timer_write_ticr(&s->timer[0], value); + return; + case NPCM7XX_TIMER_TICR1: + npcm7xx_timer_write_ticr(&s->timer[1], value); + return; + case NPCM7XX_TIMER_TICR2: + npcm7xx_timer_write_ticr(&s->timer[2], value); + return; + case NPCM7XX_TIMER_TICR3: + npcm7xx_timer_write_ticr(&s->timer[3], value); + return; + case NPCM7XX_TIMER_TICR4: + npcm7xx_timer_write_ticr(&s->timer[4], 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%04x is read-only= \n", + __func__, (unsigned int)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%04x\n", + __func__, (unsigned int)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); + + 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/Makefile.objs b/hw/timer/Makefile.objs index a39f6ec0c2..84c484dda8 100644 --- a/hw/timer/Makefile.objs +++ b/hw/timer/Makefile.objs @@ -14,6 +14,7 @@ common-obj-$(CONFIG_IMX) +=3D imx_epit.o common-obj-$(CONFIG_IMX) +=3D imx_gpt.o common-obj-$(CONFIG_LM32) +=3D lm32_timer.o common-obj-$(CONFIG_MILKYMIST) +=3D milkymist-sysctl.o +common-obj-$(CONFIG_NPCM7XX) +=3D npcm7xx_timer.o common-obj-$(CONFIG_NRF51_SOC) +=3D nrf51_timer.o =20 common-obj-$(CONFIG_ALTERA_TIMER) +=3D altera_timer.o diff --git a/hw/timer/trace-events b/hw/timer/trace-events index 866c9f546a..e2434ecf3f 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.27.0.383.g050319c2ae-goog From nobody Sun Apr 28 16:09:30 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1594255183; cv=none; d=zohomail.com; s=zohoarc; b=EOArhDSrHNorQzkjl0tbO1FV/ySHSdiOr1UCjPgLQ6uaHY5k5d6XXyvErn9MZSv0O3uhlC9uE3ozuqnEi8rntN3jXszHRJJJwoFfo/BGO4Ydxo2svR+EbfwN0x4OSc07WqC7P2VWgnEp54qRE8zJJbp4ne5xTsdaX//cqglgiXY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594255183; 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:References:Sender:Subject:To; bh=kUjLGlGRfY4ZEnF3LmiEvAI2436j9N2OxKzjYCw9Py4=; b=IoZD/DnnDgB4vjtk4TBZ1953ks90NRP48zS1gMkEgPeNhLIS9VgoKjcTLoC8PfOxHs6IgL8WpCLZIRuBkIkMd6l/9OvwN6Pkt4rr8oZDmEIW0w+L5r091jCMFH/K9lSUQS/mioyqI5vP9Wt66L6OeQebn6lCpD/keW0B/GU2jhQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1594255183080343.8192852676866; Wed, 8 Jul 2020 17:39:43 -0700 (PDT) Received: from localhost ([::1]:60836 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jtKbF-0003As-Rq for importer@patchew.org; Wed, 08 Jul 2020 20:39:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48094) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3kWYGXwsKCnYbmechhYgiYhaiiafY.WigkYgo-XYpYfhihaho.ila@flex--hskinnemoen.bounces.google.com>) id 1jtKYH-0006Ph-JS for qemu-devel@nongnu.org; Wed, 08 Jul 2020 20:36:37 -0400 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]:43933) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3kWYGXwsKCnYbmechhYgiYhaiiafY.WigkYgo-XYpYfhihaho.ila@flex--hskinnemoen.bounces.google.com>) id 1jtKYE-00011l-S5 for qemu-devel@nongnu.org; Wed, 08 Jul 2020 20:36:37 -0400 Received: by mail-yb1-xb4a.google.com with SMTP id s7so771778ybg.10 for ; Wed, 08 Jul 2020 17:36:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=kUjLGlGRfY4ZEnF3LmiEvAI2436j9N2OxKzjYCw9Py4=; b=Rszs39KGKpAQk4RqMSdBq3Z83TLzyLaEsEsDTU3mgcs52bThlutaeo+zbW1/8E5Yct zGlQiINGUMkry+RIGd4sCq8CLlpkZeD/FxkOMuBbaexED13dYjNtyAyqXECKDk8JYq4O 4IIZQORCQg1K5eBKgIj1HZwDo0wwYJjOqbBd4t6yRMUnMhORpslElVhJ7/beX1NUHgh3 i1GY9OmlISm9PGBbCmR2ca51drvSSSIHIEtvOFBW3KakGopB7qEjHIa6DQLgT+Wq78A4 pZ1DokfzNx6XEgBetIOgnce4BQ86yKNeX4LAo1hNVAvwvtPoItlJ0S5q9FFcoJvbUDjN exnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=kUjLGlGRfY4ZEnF3LmiEvAI2436j9N2OxKzjYCw9Py4=; b=YAt6NlD/3UUKrdSUj1QqFsks0qGHtnevVmNz/FcMX7kf5Xwvq9YLc9Q9Nt9blPcdvN R5V6AmceYQBgAG4k6lGhje0AQIzUl3P76bTeG/YpvjwWd1Az96Tb4fBrRISQDuLBvHYL zYJCv9BzpJ8Xiz0YkimVsDLjtJvyrtO1woCmXKTVtzwPyxPUiKUfSURurOplhdFstWtq Qi+ZJPvvmOtIvNPOkTMwJ2gJLSb7+5SHs5wV5SXtUkWj6pbrW94Gk65puTuXA2vQG29h uqVlbNNOXqiP/dOBTJONtOLSudpqIUZ4iZcj6Ptb2z+XriirAdqPa93neeXsF3X2ySDJ nTuQ== X-Gm-Message-State: AOAM531ZFe7KQg/DjACrZOzpfRIPJ1opKHaHFKl9l8AAbuKQgiHk4tyO 5yu0ThWruNqnCW6mwSquZEFa4MTcC6nL/n2bEQ== X-Google-Smtp-Source: ABdhPJxnr4Bh2aTKo51Fzs2IIbJnQ29tIrxKvhMAdasJ2H+biLaoBGcZQBSs+hl8kavg52cMU1++XYnlvoxF3eVPXQ== X-Received: by 2002:a05:6902:6a9:: with SMTP id j9mr40915894ybt.52.1594254993410; Wed, 08 Jul 2020 17:36:33 -0700 (PDT) Date: Wed, 8 Jul 2020 17:36:01 -0700 In-Reply-To: <20200709003608.3834629-1-hskinnemoen@google.com> Message-Id: <20200709003608.3834629-5-hskinnemoen@google.com> Mime-Version: 1.0 References: <20200709003608.3834629-1-hskinnemoen@google.com> X-Mailer: git-send-email 2.27.0.383.g050319c2ae-goog Subject: [PATCH v5 04/11] hw/arm: Add NPCM730 and NPCM750 SoC models From: Havard Skinnemoen 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 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::b4a; envelope-from=3kWYGXwsKCnYbmechhYgiYhaiiafY.WigkYgo-XYpYfhihaho.ila@flex--hskinnemoen.bounces.google.com; helo=mail-yb1-xb4a.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: -105 X-Spam_score: -10.6 X-Spam_bar: ---------- X-Spam_report: (-10.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-1, 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, URIBL_BLOCKED=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" X-ZohoMail-DKIM: pass (identity @google.com) Content-Transfer-Encoding: quoted-printable 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 Signed-off-by: Havard Skinnemoen Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/hw/arm/npcm7xx.h | 86 +++++++++ hw/arm/npcm7xx.c | 376 +++++++++++++++++++++++++++++++++++++++ hw/arm/Kconfig | 5 + hw/arm/Makefile.objs | 1 + 4 files changed, 468 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..95d9224f59 --- /dev/null +++ b/include/hw/arm/npcm7xx.h @@ -0,0 +1,86 @@ +/* + * 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_write_secondary_boot - Write stub for booting secondary CPU. + * @cpu: The CPU to be booted. + * @info: Boot info structure for the board. + * + * This will write a short code stub to the internal ROM that will keep the + * secondary CPU spinning until the primary CPU writes an address to the S= CRPAD + * register in the GCR, after which the secondary CPU will jump there. + */ +extern void npcm7xx_write_secondary_boot(ARMCPU *cpu, + const struct arm_boot_info *info); + +#endif /* NPCM7XX_H */ diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c new file mode 100644 index 0000000000..af45f3c716 --- /dev/null +++ b/hw/arm/npcm7xx.c @@ -0,0 +1,376 @@ +/* + * 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/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, +}; + +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 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; + + /* CPUs */ + for (i =3D 0; i < nc->num_cpus; i++) { + object_property_set_int(OBJECT(&s->cpu[i]), + arm_cpu_mp_affinity(i, NPCM7XX_MAX_NUM_CPU= S), + "mp-affinity", &error_abort); + object_property_set_int(OBJECT(&s->cpu[i]), NPCM7XX_GIC_CPU_IF_ADD= R, + "reset-cbar", &error_abort); + object_property_set_bool(OBJECT(&s->cpu[i]), true, + "reset-hivecs", &error_abort); + + /* Disable security extensions. */ + object_property_set_bool(OBJECT(&s->cpu[i]), false, "has_el3", + &error_abort); + + qdev_realize(DEVICE(&s->cpu[i]), NULL, &error_abort); + } + + /* A9MPCORE peripherals */ + object_property_set_int(OBJECT(&s->a9mpcore), nc->num_cpus, "num-cpu", + &error_abort); + object_property_set_int(OBJECT(&s->a9mpcore), NPCM7XX_NUM_IRQ, "num-ir= q", + &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) */ + object_property_set_int(OBJECT(&s->gcr), nc->disabled_modules, + "disabled-modules", &error_abort); + object_property_add_const_link(OBJECT(&s->gcr), "dram-mr", OBJECT(s->d= ram)); + sysbus_realize(SYS_BUS_DEVICE(&s->gcr), &error_abort); + sysbus_mmio_map(SYS_BUS_DEVICE(&s->gcr), 0, NPCM7XX_GCR_BA); + + /* Clock Control Registers (CLK) */ + sysbus_realize(SYS_BUS_DEVICE(&s->clk), &error_abort); + sysbus_mmio_map(SYS_BUS_DEVICE(&s->clk), 0, NPCM7XX_CLK_BA); + + /* Timer Modules (TIM) */ + 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 192a8dec3b..a31d0d282f 100644 --- a/hw/arm/Kconfig +++ b/hw/arm/Kconfig @@ -356,6 +356,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/Makefile.objs b/hw/arm/Makefile.objs index 534a6a119e..13d163a599 100644 --- a/hw/arm/Makefile.objs +++ b/hw/arm/Makefile.objs @@ -41,6 +41,7 @@ obj-$(CONFIG_STM32F205_SOC) +=3D stm32f205_soc.o obj-$(CONFIG_STM32F405_SOC) +=3D stm32f405_soc.o obj-$(CONFIG_XLNX_ZYNQMP_ARM) +=3D xlnx-zynqmp.o xlnx-zcu102.o obj-$(CONFIG_XLNX_VERSAL) +=3D xlnx-versal.o xlnx-versal-virt.o +obj-$(CONFIG_NPCM7XX) +=3D npcm7xx.o obj-$(CONFIG_FSL_IMX25) +=3D fsl-imx25.o imx25_pdk.o obj-$(CONFIG_FSL_IMX31) +=3D fsl-imx31.o kzm.o obj-$(CONFIG_FSL_IMX6) +=3D fsl-imx6.o --=20 2.27.0.383.g050319c2ae-goog From nobody Sun Apr 28 16:09:30 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1594255286; cv=none; d=zohomail.com; s=zohoarc; b=DR5Exhs32sHG8tpgTIEg/lpjI52LafbNbLxgsBImC9tx47GTDfNc69653uT0LCjEuARgIbStglNaBg43gGE5+ISK5aEsYpjF2HWLKQ+X7ztVC1SVroQHQRBaJDFZeUVQLhcJ0PIiNxwTYAFbD13ymy2hDMS1DG5j6gahr9r9GVM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594255286; 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:References:Sender:Subject:To; bh=bulMZdUMkkNdHSfTmTXx1wlxG6mAfX02SXjNqiyM2wg=; b=HQ8ROEBDp7oYS3KV/siCpgAJFNDjF4m85nWkxDSknViz4edF7/XIAYHzQYZGtFhbibKMAT1NcHCaiVd2JYa5tmvZz9lS/7cqVCxrQL1NCZpjFzmJ5QXhTgcdUtZQra5BJ9iUwOaHU939h2Jc4SDMKXmsKa0Ja2KyJwMcJ6ORLDg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1594255286484781.3392422922882; Wed, 8 Jul 2020 17:41:26 -0700 (PDT) Received: from localhost ([::1]:36366 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jtKcv-0004pJ-3N for importer@patchew.org; Wed, 08 Jul 2020 20:41:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48116) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3k2YGXwsKCngdogejjaikajckkcha.Ykimaiq-Zarahjkjcjq.knc@flex--hskinnemoen.bounces.google.com>) id 1jtKYI-0006T9-Vy for qemu-devel@nongnu.org; Wed, 08 Jul 2020 20:36:39 -0400 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]:46184) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3k2YGXwsKCngdogejjaikajckkcha.Ykimaiq-Zarahjkjcjq.knc@flex--hskinnemoen.bounces.google.com>) id 1jtKYG-000122-OT for qemu-devel@nongnu.org; Wed, 08 Jul 2020 20:36:38 -0400 Received: by mail-yb1-xb49.google.com with SMTP id u64so763764ybf.13 for ; Wed, 08 Jul 2020 17:36:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc:content-transfer-encoding; bh=bulMZdUMkkNdHSfTmTXx1wlxG6mAfX02SXjNqiyM2wg=; b=JmtCGNu0m7FbDL6PoiKZwr0uvGQOSPcHeul1dWmeNQchY3+35BZyhI2GE9oCGYIVX5 9ASiTv3SVXzEznqzMsozmR/atUuUMkbYLceUlBNecrrZTKNCK3HtyYtO0datDpE/ZYlX SA20dmelIM6tX9Jj66eqNqIxcgz1UOs6GqgWYnEfB7J00AN3FjFV50jE4FLf0ulfk0Aa k3jkamfwtSANRn7gWAWulim0wWiu/8i9xTB4ZbS6MypzLkyUkLtigz/dMOzIvpqCxDUv NzgNDiRGs8Du4uCEmnl6JPqTD8xNajeFNNOZIYmGvz4/Y8uAncYrxr3QfhzY3xoI+9Tl evXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=bulMZdUMkkNdHSfTmTXx1wlxG6mAfX02SXjNqiyM2wg=; b=gL9Pxto28YgqiRaPyXGAzd9LMmzgszf4OQQN5aWthEs7OvUZSuQuNoja1bra03HGlv zarMHCC/1v5Bmu5ifk2KkrmKNST2q5RGexLFygcyDdzDo9RfdSZDVWAXm/6k4jT16bfx jLvRGb9qEFSIjzZSez8VThrnNCz28gsAOszDNOBccD/tgbun3aVg+kUrw8TJEi93CN2A T91cggdERijjsI4C+wbHB0awNZPXZKBgyhUUDjascHrmIEzx0wV8QGaRblA+I0ZIjG1K 9pVQbg9/zJBiybTCuKJKpQLx4jpVN+z02bvYl7PDXGsldyolE/8cxz/f9ppqTvXZ1Pxy 46UQ== X-Gm-Message-State: AOAM530sZtvy/sNbmkcZXlDL59ojk9bZnpuY2s6dudKDiZH9GS9zucBZ VjxJH2XZd3FNZpDloO8WywH1u6qqMCLT2/bwog== X-Google-Smtp-Source: ABdhPJx5xtXr+VBDcJMj1O9yk+y7jJbVsQOoxhG2dm/ZBY3ItCwqEDiXtdykGIx1ugzjbdYEqmfpQI3SidKSvSZqZw== X-Received: by 2002:a5b:48f:: with SMTP id n15mr87834291ybp.115.1594254995291; Wed, 08 Jul 2020 17:36:35 -0700 (PDT) Date: Wed, 8 Jul 2020 17:36:02 -0700 In-Reply-To: <20200709003608.3834629-1-hskinnemoen@google.com> Message-Id: <20200709003608.3834629-6-hskinnemoen@google.com> Mime-Version: 1.0 References: <20200709003608.3834629-1-hskinnemoen@google.com> X-Mailer: git-send-email 2.27.0.383.g050319c2ae-goog Subject: [PATCH v5 05/11] hw/arm: Add two NPCM7xx-based machines From: Havard Skinnemoen 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::b49; envelope-from=3k2YGXwsKCngdogejjaikajckkcha.Ykimaiq-Zarahjkjcjq.knc@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: -105 X-Spam_score: -10.6 X-Spam_bar: ---------- X-Spam_report: (-10.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-1, 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" X-ZohoMail-DKIM: pass (identity @google.com) 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 Signed-off-by: Havard Skinnemoen Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- default-configs/arm-softmmu.mak | 1 + include/hw/arm/npcm7xx.h | 19 ++++ hw/arm/npcm7xx_boards.c | 156 ++++++++++++++++++++++++++++++++ hw/arm/Makefile.objs | 2 +- 4 files changed, 177 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 95d9224f59..b8b76bc07b 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..d78d9f991b --- /dev/null +++ b/hw/arm/npcm7xx_boards.c @@ -0,0 +1,156 @@ +/* + * 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/boot.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 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, +}; + +static 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 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), OBJECT(dram), "dram-mr", + &error_abort); +} + +static NPCM7xxState *npcm7xx_create_soc(MachineState *machine, + uint32_t hw_straps) +{ + NPCM7xxMachineClass *nmc =3D NPCM7XX_MACHINE_GET_CLASS(machine); + Object *obj; + + obj =3D object_new_with_props(nmc->soc_type, OBJECT(machine), "soc", + &error_abort, NULL); + object_property_set_uint(obj, hw_straps, "power-on-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_abort); + + 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_abort); + + 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"; +} + +/* + * 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/Makefile.objs b/hw/arm/Makefile.objs index 13d163a599..c333548ce1 100644 --- a/hw/arm/Makefile.objs +++ b/hw/arm/Makefile.objs @@ -41,7 +41,7 @@ obj-$(CONFIG_STM32F205_SOC) +=3D stm32f205_soc.o obj-$(CONFIG_STM32F405_SOC) +=3D stm32f405_soc.o obj-$(CONFIG_XLNX_ZYNQMP_ARM) +=3D xlnx-zynqmp.o xlnx-zcu102.o obj-$(CONFIG_XLNX_VERSAL) +=3D xlnx-versal.o xlnx-versal-virt.o -obj-$(CONFIG_NPCM7XX) +=3D npcm7xx.o +obj-$(CONFIG_NPCM7XX) +=3D npcm7xx.o npcm7xx_boards.o obj-$(CONFIG_FSL_IMX25) +=3D fsl-imx25.o imx25_pdk.o obj-$(CONFIG_FSL_IMX31) +=3D fsl-imx31.o kzm.o obj-$(CONFIG_FSL_IMX6) +=3D fsl-imx6.o --=20 2.27.0.383.g050319c2ae-goog From nobody Sun Apr 28 16:09:30 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1594255349; cv=none; d=zohomail.com; s=zohoarc; b=SPOZJVsEuZffek4anJbI+5UeYq9YzWAgv6deQtVSPga/SV6uw6wLrf/AdgENx9Px8zHU3KkF8MmhC18/cUt19hVA9Y64/LqkaNp1zC7dTiTabkG+OaGT45/eT5rc3wLnUro99EBXNiBkjiOnWW+Zx9haQB5bv9mjoaL/2Nk7kn4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594255349; 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:References:Sender:Subject:To; bh=eKgWkuM4GJmY6FctxrD+gBwcnEvk9udSz1JnbpjmKwI=; b=hWn4rUA/q5mfpSLih5sL5H1PD47Oo8DHhcwJIl8NBDb1s98xNlH75h30hM0ijbaazK/jGaJ2kdSYd8yU0udW+Jt3BZj7hDnO7rDyidOAygHhenjuXbes7WXqjvEqtPxJ7/K1DRTE1JtJyhKWj4x0D/5V6TSCMoQF1XPShpuViNY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1594255349942449.4065692257029; Wed, 8 Jul 2020 17:42:29 -0700 (PDT) Received: from localhost ([::1]:39056 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jtKdw-0005w0-Oh for importer@patchew.org; Wed, 08 Jul 2020 20:42:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48150) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3lWYGXwsKCnofqigllckmclemmejc.amkocks-bctcjlmlels.mpe@flex--hskinnemoen.bounces.google.com>) id 1jtKYL-0006Xo-1I for qemu-devel@nongnu.org; Wed, 08 Jul 2020 20:36:41 -0400 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]:54594) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3lWYGXwsKCnofqigllckmclemmejc.amkocks-bctcjlmlels.mpe@flex--hskinnemoen.bounces.google.com>) id 1jtKYJ-00012N-Ch for qemu-devel@nongnu.org; Wed, 08 Jul 2020 20:36:40 -0400 Received: by mail-yb1-xb4a.google.com with SMTP id p22so738448ybg.21 for ; Wed, 08 Jul 2020 17:36:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=eKgWkuM4GJmY6FctxrD+gBwcnEvk9udSz1JnbpjmKwI=; b=l2tFO5xAXT13KB64jcjFMa/PIoPH4gxP9fN0XyUA/KRNQflP8MMSRvjRCULDtB5k9k oZn+LDDyqLSmItjSb8eTK6/8kPIKQb3av6pOnYfj/rm/xcgVI+FkMPrH8qT6WP5B7Hwt kPTwPMJB9zDuR+PuX3lYlMmNxb3o2VB0toz6fVjeoyEmRIrOyOzFtaDH3wYK5Pi2G6/p 31RkAxVb1wbDkYm/vGW+cvm6Gr5/9l4fTtXoICFD6/CyBEL0w8ZTjLp4syNk73TMsbTt BdLIn/d6NTB5VdXZ7aOnkmxA6dpDpg/x2evQcO8oAPutUNq8f4lOUipqjzBH58V170mJ 0E1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=eKgWkuM4GJmY6FctxrD+gBwcnEvk9udSz1JnbpjmKwI=; b=Ay2dIqousfPFLKUK5s7oOXZwtuDvXoPVrExdeWA8oBFDqzvJQjKkqEcLMXF3ff9hiH J7u+FYK9ldWxO6IzqT3y9r5FNJbIEfK6/k+n6jYhKXyyrobiyTsBfipdZLYYX9xQ5Jz9 fS17lkth0xlGsDzcOca3REjWoTZ9/jsVvZPCY+ztfQ6ROH/BJcsmYawj7Z1eaHuMqsqd wFCzidn7PP60eKpioY27LlLoHoFtdKdfvAIyCvQGvdA7LNuDad/5XrvLmYpbdlXptPpA fgEzViY3+8zDcYnQu2XPKQW9mwUIC73P8N+HY45yulvIPgZZEXwZt/F8aE53escpgBzK aN+w== X-Gm-Message-State: AOAM530XhOIM3/a6+GReWYqGiTUW6sdKLHZZ+it2Fa92b/eVce0K8/mI C3/G3aKwk5l3SWS9euUPNKx1mA2wKMBs15eh+Q== X-Google-Smtp-Source: ABdhPJwavzoApTjzo0qmm5+olg6lYf04rb5LNbubrr7Mypxyzsor4gYMkUVDrK2kONtOkSznmnGcdlvlIdmpKrmPlg== X-Received: by 2002:a25:aa4b:: with SMTP id s69mr31135660ybi.502.1594254997250; Wed, 08 Jul 2020 17:36:37 -0700 (PDT) Date: Wed, 8 Jul 2020 17:36:03 -0700 In-Reply-To: <20200709003608.3834629-1-hskinnemoen@google.com> Message-Id: <20200709003608.3834629-7-hskinnemoen@google.com> Mime-Version: 1.0 References: <20200709003608.3834629-1-hskinnemoen@google.com> X-Mailer: git-send-email 2.27.0.383.g050319c2ae-goog Subject: [PATCH v5 06/11] hw/arm: Load -bios image as a boot ROM for npcm7xx From: Havard Skinnemoen 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::b4a; envelope-from=3lWYGXwsKCnofqigllckmclemmejc.amkocks-bctcjlmlels.mpe@flex--hskinnemoen.bounces.google.com; helo=mail-yb1-xb4a.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: -105 X-Spam_score: -10.6 X-Spam_bar: ---------- X-Spam_report: (-10.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-1, 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" X-ZohoMail-DKIM: pass (identity @google.com) Content-Transfer-Encoding: quoted-printable 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. A minimal Apache-2.0-licensed boot ROM can be found at https://github.com/google/vbootrom It is by no means feature complete, but it is enough to launch the Nuvoton bootblock[1] from offset 0 in the flash, which in turn will launch u-boot and finally the Linux kernel. [1] https://github.com/Nuvoton-Israel/bootblock Reviewed-by: Tyrone Ting Signed-off-by: Havard Skinnemoen --- hw/arm/npcm7xx_boards.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/hw/arm/npcm7xx_boards.c b/hw/arm/npcm7xx_boards.c index d78d9f991b..80cf1535f1 100644 --- a/hw/arm/npcm7xx_boards.c +++ b/hw/arm/npcm7xx_boards.c @@ -19,8 +19,11 @@ #include "hw/arm/boot.h" #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 @@ -34,6 +37,25 @@ static struct arm_boot_info npcm7xx_binfo =3D { .board_id =3D -1, }; =20 +static void npcm7xx_load_bootrom(NPCM7xxState *soc) +{ + if (bios_name) { + g_autofree char *filename =3D NULL; + int ret; + + 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_load_kernel(MachineState *machine, NPCM7xxState *soc) { NPCM7xxClass *sc =3D NPCM7XX_GET_CLASS(soc); @@ -73,6 +95,7 @@ static void npcm750_evb_init(MachineState *machine) npcm7xx_connect_dram(soc, machine->ram); qdev_realize(DEVICE(soc), NULL, &error_abort); =20 + npcm7xx_load_bootrom(soc); npcm7xx_load_kernel(machine, soc); } =20 @@ -84,6 +107,7 @@ static void quanta_gsj_init(MachineState *machine) npcm7xx_connect_dram(soc, machine->ram); qdev_realize(DEVICE(soc), NULL, &error_abort); =20 + npcm7xx_load_bootrom(soc); npcm7xx_load_kernel(machine, soc); } =20 --=20 2.27.0.383.g050319c2ae-goog From nobody Sun Apr 28 16:09:30 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1594255081; cv=none; d=zohomail.com; s=zohoarc; b=bq8Mpfn2+CyyVb/a+ypw2+v83elQP2y4mIeasPBBOvSIT5nNatI92mkT7BP+XbGEvxnVFc4DK4A3zX3tQgvykGa7wDIE9sYYZ4kBFZdhCke6OjXNXevk5WgpYzxjlzZvCypq/zqR5Ud2Svek/osvhieHwDRIFKsy5wLI824eys4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594255081; 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:References:Sender:Subject:To; bh=R+4Pq4OB/mowy7Hq3NMzbh84zd3pPAsqXlKlEWoNw4Q=; b=QRkaCW9w/fsw3oYuEh64tMORPsGr/gKYasd6xlXXu+e/mMBlUCyLJftM2FtxgM01ErLrqswv6laYKWHJR2Qcsmrpot5dTj5AFny7cWumV0tBOs4WdkD6qz2nPIsaYd/CfOfmdGb7NQnQdBt4HMjQ9c7UwZmbx4SCnpwjlCaEcGY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1594255081897358.99379548204024; Wed, 8 Jul 2020 17:38:01 -0700 (PDT) Received: from localhost ([::1]:53332 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jtKZc-0008WQ-II for importer@patchew.org; Wed, 08 Jul 2020 20:38:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48202) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3l2YGXwsKCnwmxpnssjrtjslttlqj.htrvjrz-ij0jqstslsz.twl@flex--hskinnemoen.bounces.google.com>) id 1jtKYO-0006g1-MY for qemu-devel@nongnu.org; Wed, 08 Jul 2020 20:36:44 -0400 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]:36009) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3l2YGXwsKCnwmxpnssjrtjslttlqj.htrvjrz-ij0jqstslsz.twl@flex--hskinnemoen.bounces.google.com>) id 1jtKYL-00012l-5I for qemu-devel@nongnu.org; Wed, 08 Jul 2020 20:36:44 -0400 Received: by mail-yb1-xb49.google.com with SMTP id x8so791480ybt.3 for ; Wed, 08 Jul 2020 17:36:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc:content-transfer-encoding; bh=R+4Pq4OB/mowy7Hq3NMzbh84zd3pPAsqXlKlEWoNw4Q=; b=TvKV6YtxgRmpiN8c7A+HzqgBBK4/MVrQJyYQGP1+NMPsx0R6zcpu2UjDF1UgVOcV0m U7wgCtdirvotz1WBnW2EqkttjRfd9ulLJl5GBXIbiDdnv1TCqlz48s9H+xB3oTNEkc3e zHxqX43ZSp/iNAwFYZVMBqxwh3M6Xx2y26YQXGPF5F1MfBDv+lVGq6bq9ebIzE88lDLn BnFViviOivRSW7tiW3g+CE5SOath1EMi+uUksu0WOhA0bUwp39TXYA3lwamLjKIjjnZi MW5RAvPQabTEqN69XAFc95EazxHqcPIKhmAzw0FjYNulVr60YXufkhD8xzJgVUWbDYqE fKXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=R+4Pq4OB/mowy7Hq3NMzbh84zd3pPAsqXlKlEWoNw4Q=; b=pp+DpFRFXpaz/85vPKMUOZ5b3CaTJjDYe1KJi0w5bz5C93EXTyQXpwa+lNk5l8N4Q5 FKYv5/dIyl5lbz323JxaI5l4xbXvbzXgmquHVipuLJ2rkrw/2bpXLIniLAVDRY6ob7Uz eram+DWYYMK89zSesd1o75ODT5ZKL5YTqjiuEIGw6C1DlAMx5CqShM5UJCH8pHoAbvp/ 5S3wExDGte1H9b2PTGWPZW5k/tO8cN44A9NgvcOYdv7KwRaJcyC50cQcbPVK0LuIweXz ihEKucaYmD1mVWXTHEOp0SXw75HKO1EA51bZAJ6Np3YFUZcXvR3A7vd3lAgMpo5eeGTc 8TnQ== X-Gm-Message-State: AOAM530caU55GpKTwdRH9uUz2hnDYnrXNDgYe/AL4knRX6aECluejtRs fDg/PWMNqp0th34cioHRcHsnvU0TD3qyP72zhQ== X-Google-Smtp-Source: ABdhPJwUg+U2/OpdyntuxAWZeqAPA62f0scGV5Moq+OMu03ll51fL5ovOcK8K3X/XXgLcBr09VU2c0Dx7Z8HUD9dgA== X-Received: by 2002:a25:f20d:: with SMTP id i13mr92851972ybe.366.1594254999355; Wed, 08 Jul 2020 17:36:39 -0700 (PDT) Date: Wed, 8 Jul 2020 17:36:04 -0700 In-Reply-To: <20200709003608.3834629-1-hskinnemoen@google.com> Message-Id: <20200709003608.3834629-8-hskinnemoen@google.com> Mime-Version: 1.0 References: <20200709003608.3834629-1-hskinnemoen@google.com> X-Mailer: git-send-email 2.27.0.383.g050319c2ae-goog Subject: [PATCH v5 07/11] hw/nvram: NPCM7xx OTP device model From: Havard Skinnemoen 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::b49; envelope-from=3l2YGXwsKCnwmxpnssjrtjslttlqj.htrvjrz-ij0jqstslsz.twl@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: -105 X-Spam_score: -10.6 X-Spam_bar: ---------- X-Spam_report: (-10.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-1, 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" X-ZohoMail-DKIM: pass (identity @google.com) 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 --- include/hw/arm/npcm7xx.h | 3 + include/hw/nvram/npcm7xx_otp.h | 88 +++++++ hw/arm/npcm7xx.c | 29 +++ hw/nvram/npcm7xx_otp.c | 424 +++++++++++++++++++++++++++++++++ hw/nvram/Makefile.objs | 1 + 5 files changed, 545 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 b8b76bc07b..0fd4ae4133 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..c4c1b751d4 --- /dev/null +++ b/include/hw/nvram/npcm7xx_otp.h @@ -0,0 +1,88 @@ +/* + * 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) + +/** + * enum NPCM7xxOTPRegister - 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_NR_REGS, +} NPCM7xxOTPRegister; + +/** + * 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 af45f3c716..70eaa2347f 100644 --- a/hw/arm/npcm7xx.c +++ b/hw/arm/npcm7xx.c @@ -33,6 +33,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) @@ -123,6 +127,20 @@ void npcm7xx_write_secondary_boot(ARMCPU *cpu, const s= truct arm_boot_info *info) NPCM7XX_SMP_LOADER_START); } =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); @@ -143,6 +161,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); @@ -201,6 +223,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 */ + 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) */ 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..b67d69fdf9 --- /dev/null +++ b/hw/nvram/npcm7xx_otp.c @@ -0,0 +1,424 @@ +/* + * 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) + +/* 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); + + 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/Makefile.objs b/hw/nvram/Makefile.objs index f3ad921382..0270f0bbf7 100644 --- a/hw/nvram/Makefile.objs +++ b/hw/nvram/Makefile.objs @@ -4,5 +4,6 @@ common-obj-$(CONFIG_AT24C) +=3D eeprom_at24c.o common-obj-y +=3D fw_cfg.o common-obj-$(CONFIG_CHRP_NVRAM) +=3D chrp_nvram.o common-obj-$(CONFIG_MAC_NVRAM) +=3D mac_nvram.o +common-obj-$(CONFIG_NPCM7XX) +=3D npcm7xx_otp.o common-obj-$(CONFIG_NRF51_SOC) +=3D nrf51_nvm.o obj-$(CONFIG_PSERIES) +=3D spapr_nvram.o --=20 2.27.0.383.g050319c2ae-goog From nobody Sun Apr 28 16:09:30 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1594255458; cv=none; d=zohomail.com; s=zohoarc; b=kzT1zgZWCfc67tR/bXp5UIay8yX33B+IFm6KX/F0HqJeJ1ltzccojPH6w0290vvSJQS4TlsUf0TKdWonX7R29oDVPH0oVwUj4a0m3Bj2oIPqQ539PyisTlgb/7unGS67DUEX3e8u1qDZqMjnQrGJNyyWoLT5BEpnKmQF+oL+guo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594255458; 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:References:Sender:Subject:To; bh=GbsHhbU+MBRirlIqPaGRSzfQ2oFvTqZhm+nXLxBNqhs=; b=BYI0tXv4BBBrI0mvXv8Rawr5MX3+ebbLj4K7xsCunzYfAcgAz5srvcIYE3jjppU4UAKPBUQXbX99VnwZzhseLMba91dyhRg92fpTeABRWYkb79CfzFfSyaN64EuD87lgbUaNwCMJjAOqd2rCBNl0XMPNoA57mL0edYkxPe7uZnw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1594255458545378.7496547892057; Wed, 8 Jul 2020 17:44:18 -0700 (PDT) Received: from localhost ([::1]:44050 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jtKfh-00081g-A2 for importer@patchew.org; Wed, 08 Jul 2020 20:44:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48214) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3mWYGXwsKCn4jumkppgoqgpiqqing.eqosgow-fgxgnpqpipw.qti@flex--hskinnemoen.bounces.google.com>) id 1jtKYQ-0006kx-Nu for qemu-devel@nongnu.org; Wed, 08 Jul 2020 20:36:46 -0400 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]:41897) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3mWYGXwsKCn4jumkppgoqgpiqqing.eqosgow-fgxgnpqpipw.qti@flex--hskinnemoen.bounces.google.com>) id 1jtKYN-00013A-DD for qemu-devel@nongnu.org; Wed, 08 Jul 2020 20:36:46 -0400 Received: by mail-yb1-xb4a.google.com with SMTP id 132so781767ybg.8 for ; Wed, 08 Jul 2020 17:36:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc:content-transfer-encoding; bh=GbsHhbU+MBRirlIqPaGRSzfQ2oFvTqZhm+nXLxBNqhs=; b=s1uUcltScFoKONI14mjDEQiY1Pg6pY3+ElN2rIbUodurYUsG/rek0i2hH1QlQ06lP4 gGTJlIterzu0Nv+dpqCFdGbx+pjKHNVH5596XWijsSE6bZgY11HV4VILSB0RmpPTZt9V IgBhJStzq5IuCsOlP3d5OH15BahQ/asIMsdwvhNUdit9zxYfu+I1oCBdQArO37uOO9Ax M9WX2H0Of6PUujcxRuM25g0gv9ap5x/seuWKhRfw7JH6qWgA1S+ZJEx9xtuIdgIMzBqQ Mls5V8Ar5KHDCKsDen3m00DtWek5jmYEI8HMaYUk6wNZ72eUzMc2TEPjpkVHpZ6S/PnT mijA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=GbsHhbU+MBRirlIqPaGRSzfQ2oFvTqZhm+nXLxBNqhs=; b=njVG8ffHzpFK5QYvs4MCoW0hmX7f7qMNxeiHHBXQHI88yscjP/v1CJyP7YUMaS39QH SOrAs0PhQ0y45hwLqPjBdAU89gKbdEXPpa8G4r1S/7Ptb/k9VgM9d8l1C6Fa04u1aBVh sF2ImuBjU1J0qZvAij0hZJUStp6y8qSFJLkbv3r20SEHYO05tZrLdDMsYljoxPbb1otd 1Lw07XLtL4WP0mISXPiCW3UxyU4TOCHuVIswQPzx7k2AYpzZqrNmNT5Uy+mpxmRttWWo mpW6/4aH0QxTYfpEtzBv4Ob8l1pmVTeHTQ/90cE7/WI/tAyrdZksv3EUE1ZKmxNEYYn1 iTdg== X-Gm-Message-State: AOAM532179DZwnTkrI4k6iYp2KMIKdWjDFP6uEIe9qqE0meLbGAlqLDY hpVLRd4vmiMyVVjd2AXFLS+VIFBT1BWv+zrcDA== X-Google-Smtp-Source: ABdhPJzlZzKXn96+GCQvzVf8G4Ve1FY/cZDrGMIWQxiBhQWAsNLnrtmM6Qs9bQSWhPd5ZVqX1OUra91IhXmmgoCkUA== X-Received: by 2002:a25:d4d6:: with SMTP id m205mr14968369ybf.7.1594255001399; Wed, 08 Jul 2020 17:36:41 -0700 (PDT) Date: Wed, 8 Jul 2020 17:36:05 -0700 In-Reply-To: <20200709003608.3834629-1-hskinnemoen@google.com> Message-Id: <20200709003608.3834629-9-hskinnemoen@google.com> Mime-Version: 1.0 References: <20200709003608.3834629-1-hskinnemoen@google.com> X-Mailer: git-send-email 2.27.0.383.g050319c2ae-goog Subject: [PATCH v5 08/11] hw/mem: Stubbed out NPCM7xx Memory Controller model From: Havard Skinnemoen 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::b4a; envelope-from=3mWYGXwsKCn4jumkppgoqgpiqqing.eqosgow-fgxgnpqpipw.qti@flex--hskinnemoen.bounces.google.com; helo=mail-yb1-xb4a.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: -105 X-Spam_score: -10.6 X-Spam_bar: ---------- X-Spam_report: (-10.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-1, 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" X-ZohoMail-DKIM: pass (identity @google.com) 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 Signed-off-by: Havard Skinnemoen Reviewed-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/Makefile.objs | 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 0fd4ae4133..3ae9e5dca2 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 70eaa2347f..4d227bb74b 100644 --- a/hw/arm/npcm7xx.c +++ b/hw/arm/npcm7xx.c @@ -42,6 +42,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) @@ -165,6 +166,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); @@ -230,6 +232,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) */ + sysbus_realize(SYS_BUS_DEVICE(&s->mc), &error_abort); + sysbus_mmio_map(SYS_BUS_DEVICE(&s->mc), 0, NPCM7XX_MC_BA); + /* Timer Modules (TIM) */ 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/Makefile.objs b/hw/mem/Makefile.objs index 56345befd0..9a33ef7b35 100644 --- a/hw/mem/Makefile.objs +++ b/hw/mem/Makefile.objs @@ -1,3 +1,4 @@ common-obj-$(CONFIG_DIMM) +=3D pc-dimm.o common-obj-y +=3D memory-device.o +common-obj-$(CONFIG_NPCM7XX) +=3D npcm7xx_mc.o common-obj-$(CONFIG_NVDIMM) +=3D nvdimm.o --=20 2.27.0.383.g050319c2ae-goog From nobody Sun Apr 28 16:09:30 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1594255553; cv=none; d=zohomail.com; s=zohoarc; b=HDlJB/5VbZYBV13KGs+jD+uRixiFqsddZg60LqCgCjYupyEep8IYwQ22LAMU36/io0gWgI2q0/RBD2u0O59AOvTrLhoOTO340E+vQtb66VeV+pwm+UTi6X9PcAsXzCYKnm7JKB6l5EeyLlIgm+YLb7npoBjaiZVvdIYIzxEalEE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594255553; 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:References:Sender:Subject:To; bh=Y0hfDRAheAq0F7gWtIiUIyRv6A6dMgnIM0MbofV26Yo=; b=TebblArDtle+CpEHkdWtsIlWtdHcPG30aVFEQFEJKPfE/DS2SwUHiyIKkdAYf7zMT3u/kVJixGCrvqzZFhhns2Aiw2Boab3aYUXLXjB9l5YRErP5fba0Xa6F6NNVbDaQhUz3iMtnXAKdOjIqJscaC5DHPVs85YxPfKciTLdc3TU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1594255553589958.7815421781746; Wed, 8 Jul 2020 17:45:53 -0700 (PDT) Received: from localhost ([::1]:48398 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jtKhE-0001Od-BF for importer@patchew.org; Wed, 08 Jul 2020 20:45:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48258) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3m2YGXwsKCoAlwomrriqsirksskpi.gsquiqy-hiziprsrkry.svk@flex--hskinnemoen.bounces.google.com>) id 1jtKYS-0006ow-Dd for qemu-devel@nongnu.org; Wed, 08 Jul 2020 20:36:48 -0400 Received: from mail-yb1-xb4a.google.com ([2607:f8b0:4864:20::b4a]:47605) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3m2YGXwsKCoAlwomrriqsirksskpi.gsquiqy-hiziprsrkry.svk@flex--hskinnemoen.bounces.google.com>) id 1jtKYP-00013T-8U for qemu-devel@nongnu.org; Wed, 08 Jul 2020 20:36:48 -0400 Received: by mail-yb1-xb4a.google.com with SMTP id j3so763417yba.14 for ; Wed, 08 Jul 2020 17:36:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc:content-transfer-encoding; bh=Y0hfDRAheAq0F7gWtIiUIyRv6A6dMgnIM0MbofV26Yo=; b=e/nfFgYwDtCrj88geZNyvsp6zoU1qpnG6agbkcQKz6MDmzgQarMB+XGZCv5f2SpeRW meZ82GvzG1bIaXiBjZVM+0bfnGYJius8D0+XMqZgBvSwwj8jwkzvXxhVLi6U5aW0LRA6 FjKYHoxGE+P+2TGZZlpwrMZ2/PZERdGIen4Nnql1HDQLJDEz+qIRln2VDa4/KUI0oSfn YhWTJHIwAJJhMMCGVEe7TSopqDq9Wbp78OHYXxPMAqp1vVvApf2zXKremSmhLyoprnAC oZn50ClAf0CNB+Da6biZ1JOGKo0gYgF8Rdf3I55L19JXQDrsEscEVp4vLJRXLHEWznJy kCRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=Y0hfDRAheAq0F7gWtIiUIyRv6A6dMgnIM0MbofV26Yo=; b=HgAXy09dT18nvKihLYVr/AmJqCDxzFaP0U5EFPRziCoyZ7yKryNnv0oSxMOkHFdWjT GcrvDclGNvsrf9kBVffG3M88+jUhcHTWhRaQa+GLLgQR6NNm/Ex0C2p3QeGZAbKmqddu AX0eqW3F2RIsf4srwzTflZdK4AsY6DNIKC3ogE5taT14zTd7I6oj5BzIknan6OhV72+T fsTGvzbdxGUN+xevk260maGu9vDNIGZoCpAPnn2nEuUP3lsffKNXfvmqwHhlHtuwfkIS HGSYkrzDcLOFibLggZBXWySC6no9GMS/75D1kVcGx2sGC/EkwzpSY5XPKoY1iq0C2W32 Kchg== X-Gm-Message-State: AOAM531dKArG5OKvmTTYWipTKZzI/jU/BN7j5aftsxXh4wXMqsR7WlOf iDnxBOwE97a2knQNEh+nP5lExcHf9Jr133/lcA== X-Google-Smtp-Source: ABdhPJxZdyZgvXC8ENXanIgqTssBM+O5bItFH6WQeiJXW5s69PRWLspVLG2rmO7We1YBVAdU+JorhD6DFR8D+6tuZQ== X-Received: by 2002:a05:6902:6c9:: with SMTP id m9mr101717227ybt.372.1594255003441; Wed, 08 Jul 2020 17:36:43 -0700 (PDT) Date: Wed, 8 Jul 2020 17:36:06 -0700 In-Reply-To: <20200709003608.3834629-1-hskinnemoen@google.com> Message-Id: <20200709003608.3834629-10-hskinnemoen@google.com> Mime-Version: 1.0 References: <20200709003608.3834629-1-hskinnemoen@google.com> X-Mailer: git-send-email 2.27.0.383.g050319c2ae-goog Subject: [PATCH v5 09/11] hw/ssi: NPCM7xx Flash Interface Unit device model From: Havard Skinnemoen 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::b4a; envelope-from=3m2YGXwsKCoAlwomrriqsirksskpi.gsquiqy-hiziprsrkry.svk@flex--hskinnemoen.bounces.google.com; helo=mail-yb1-xb4a.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: -105 X-Spam_score: -10.6 X-Spam_bar: ---------- X-Spam_report: (-10.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-1, 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" X-ZohoMail-DKIM: pass (identity @google.com) 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 Signed-off-by: Havard Skinnemoen Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/hw/arm/npcm7xx.h | 2 + include/hw/ssi/npcm7xx_fiu.h | 100 +++++++ hw/arm/npcm7xx.c | 53 ++++ hw/ssi/npcm7xx_fiu.c | 510 +++++++++++++++++++++++++++++++++++ hw/arm/Kconfig | 1 + hw/ssi/Makefile.objs | 1 + hw/ssi/trace-events | 9 + 7 files changed, 676 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 3ae9e5dca2..bc99f47286 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..b867bd0429 --- /dev/null +++ b/include/hw/ssi/npcm7xx_fiu.h @@ -0,0 +1,100 @@ +/* + * 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" + +/** + * enum NPCM7xxFIURegister - 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_NR_REGS, +}; + +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 4d227bb74b..c9ff3dab25 100644 --- a/hw/arm/npcm7xx.c +++ b/hw/arm/npcm7xx.c @@ -98,6 +98,37 @@ static const hwaddr npcm7xx_uart_addr[] =3D { 0xf0004000, }; =20 +static const hwaddr npcm7xx_fiu0_flash_addr[] =3D { + 0x80000000, + 0x88000000, +}; + +static const hwaddr npcm7xx_fiu3_flash_addr[] =3D { + 0xa0000000, + 0xa8000000, + 0xb0000000, + 0xb8000000, +}; + +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, + }, +}; + void npcm7xx_write_secondary_boot(ARMCPU *cpu, const struct arm_boot_info = *info) { /* @@ -171,6 +202,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) @@ -260,6 +297,22 @@ static void npcm7xx_realize(DeviceState *dev, Error **= errp) serial_hd(i), DEVICE_LITTLE_ENDIAN); } =20 + /* Flash Interface Unit (FIU) */ + 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), npcm7xx_fiu[i].cs_count, + "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..92ade709e8 --- /dev/null +++ b/hw/ssi/npcm7xx_fiu.c @@ -0,0 +1,510 @@ +/* + * 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) + +/* 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) + +/* 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; + int cs_id =3D f - fiu->flash; + uint64_t value =3D 0; + uint32_t drd_cfg; + int dummy_cycles; + int i; + + drd_cfg =3D fiu->regs[NPCM7XX_FIU_DRD_CFG]; + + qemu_irq_lower(fiu->cs_lines[cs_id]); + 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 ssi_transfer(fiu->spi, 0) << (8 * i); + } + + qemu_irq_raise(fiu->cs_lines[cs_id]); + + trace_npcm7xx_fiu_flash_read(DEVICE(fiu)->canonical_path, cs_id, addr,= size, + value); + + 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; + int cs_id =3D f - fiu->flash; + uint32_t dwr_cfg; + int i; + + trace_npcm7xx_fiu_flash_write(DEVICE(fiu)->canonical_path, cs_id, addr, + size, v); + + dwr_cfg =3D fiu->regs[NPCM7XX_FIU_DWR_CFG]; + + qemu_irq_lower(fiu->cs_lines[cs_id]); + 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, v & 0xff); + v >>=3D 8; + } + + qemu_irq_raise(fiu->cs_lines[cs_id]); +} + +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) +{ + /* All cases fall through */ + switch (addsiz) { + case 4: + ssi_transfer(spi, extract32(addr, 24, 8)); + case 3: + ssi_transfer(spi, extract32(addr, 16, 8)); + case 2: + ssi_transfer(spi, extract32(addr, 8, 8)); + case 1: + ssi_transfer(spi, extract32(addr, 0, 8)); + 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= )); + } + } +} + +/* Assert the chip select specified in the UMA Control/Status Register. */ +static void npcm7xx_fiu_select(NPCM7xxFIUState *s) +{ + int cs_id; + + cs_id =3D FIU_UMA_CTS_DEV_NUM(s->regs[NPCM7XX_FIU_UMA_CTS]); + 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; + } + + qemu_irq_raise(s->cs_lines[s->active_cs]); + s->active_cs =3D -1; +} + +/* 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) { + npcm7xx_fiu_select(s); + } + + /* 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 aummy 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 { + npcm7xx_fiu_select(s); + } + } + 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); + 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]; + sysbus_init_irq(sbd, &s->cs_lines[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); + + 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 a31d0d282f..8d0ef0593b 100644 --- a/hw/arm/Kconfig +++ b/hw/arm/Kconfig @@ -360,6 +360,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/Makefile.objs b/hw/ssi/Makefile.objs index 07a85f1967..cab48e72c9 100644 --- a/hw/ssi/Makefile.objs +++ b/hw/ssi/Makefile.objs @@ -5,6 +5,7 @@ common-obj-$(CONFIG_XILINX_SPIPS) +=3D xilinx_spips.o common-obj-$(CONFIG_ASPEED_SOC) +=3D aspeed_smc.o common-obj-$(CONFIG_STM32F2XX_SPI) +=3D stm32f2xx_spi.o common-obj-$(CONFIG_MSF2) +=3D mss-spi.o +common-obj-$(CONFIG_NPCM7XX) +=3D npcm7xx_fiu.o =20 common-obj-$(CONFIG_OMAP) +=3D omap_spi.o common-obj-$(CONFIG_IMX) +=3D imx_spi.o diff --git a/hw/ssi/trace-events b/hw/ssi/trace-events index 0ea498de91..8024253c1f 100644 --- a/hw/ssi/trace-events +++ b/hw/ssi/trace-events @@ -9,3 +9,12 @@ 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_ctrl_read(const char *id, uint64_t addr, uint32_t data) "%s of= fset: 0x%04" PRIx64 " value: 0x%08x" +npcm7xx_fiu_ctrl_write(const char *id, uint64_t addr, uint32_t data) "%s o= ffset: 0x%04" PRIx64 " value: 0x%08x" +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.27.0.383.g050319c2ae-goog From nobody Sun Apr 28 16:09:30 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1594255614; cv=none; d=zohomail.com; s=zohoarc; b=jTHiIDONtnsimEYlJKFLAuhl2jfkp7sywrsxTnYsKaucBblNzUBHLSjxxnCsOf+3EYuQg7Mgh+lC61azDmjuHzx41eZYBr4h/KRsA6rlRipWT1LBDvDWEfa65M2ZoKRAn9HeH+3k+IUmSy1cF7AChlfzoTzzgFDSNPmLsALxFcM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594255614; 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:References:Sender:Subject:To; bh=66PpJSiQbPbYGb1w141zWioPCpD9KVyXHJd+V0/BDS8=; b=NpYKo+ASr+0mMQ+y+e+rFPqaGp0tNKYYagSqlYvJSm9AgUbzBA9fCtqX0I0Jtj+bHKxwttZ4LVJmmMoxVMZ9oRFSTZzab1RT4mYICqz/kZqwKsgCqlv/s6DVTkFs809fW8s+s9bb+G4CGmPdsKPs5QULbkpECYLgVX+qwzISxeU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1594255614345593.5129861482131; Wed, 8 Jul 2020 17:46:54 -0700 (PDT) Received: from localhost ([::1]:50840 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jtKiD-0002Qh-4F for importer@patchew.org; Wed, 08 Jul 2020 20:46:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48272) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3nWYGXwsKCoInyqottksuktmuumrk.iuswks0-jk1krtutmt0.uxm@flex--hskinnemoen.bounces.google.com>) id 1jtKYT-0006qO-4u for qemu-devel@nongnu.org; Wed, 08 Jul 2020 20:36:49 -0400 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]:33639) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3nWYGXwsKCoInyqottksuktmuumrk.iuswks0-jk1krtutmt0.uxm@flex--hskinnemoen.bounces.google.com>) id 1jtKYQ-00013l-Kd for qemu-devel@nongnu.org; Wed, 08 Jul 2020 20:36:48 -0400 Received: by mail-yb1-xb49.google.com with SMTP id g10so807729ybd.0 for ; Wed, 08 Jul 2020 17:36:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=66PpJSiQbPbYGb1w141zWioPCpD9KVyXHJd+V0/BDS8=; b=dC4x0L5klf8D6cz5MiMhEuSUB/vbqCDRLLInigXUckzFEnx0OV0TZDtPSglPFtKVlw 8rboMOmC9GnQcb727mV7UZ8944KMV0JVE3IR2Xbhvc5hNnudGqLEZEpQbiPvxY8+S7da W0mIK51vKGBublsdPtkAnsxVlrDgyeWohSJKiMw4Q+s0A53D2TNVFa2tPpWtgPr0+4/R 5B5K8HIxpAFG8PHApTKxEDqXk49ag8if/aU0NoTC/S3JoKkuz8KcBd6anoAFo1XRogHC q0ja3zIdR/1pmpFv9R+pC/vXGL47NHNXokr2oNxSlrX73Nk9p//FiBdlTBfQYWG+m3mI Wo0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=66PpJSiQbPbYGb1w141zWioPCpD9KVyXHJd+V0/BDS8=; b=CMu73cnA25y17bxCSncmciwYmZ+P8WVrHqcwJnwSY7DS0PmpjH18VsCK7KrALlsbvh hPUPri9qRLT0qp06Umy2nONhP4LAziLX47lXBvBB7645+47r4oBKkFdnkHzM/CV3fClB ay3uwEdQQXM4nAF46GLlPj9eP/r07C11L2SX4skMLhByrAownaw0z8Q2F2sWQ814VkJo q8xRUzsk7bZJR8lSn12LdcCZ6gloGKiivl3Mv1oW7mQcNMQOLEPwaPZTh/mqSsBEt/Ln vIF4yTMpvaR7sCnfER9pDHSIvtnaG8t/M71bL642Tn6EWIjicb0Gr9n6gg4aITtkjv37 UDNw== X-Gm-Message-State: AOAM530+Mv2uRn53k4aL8a5g0KnFSr3rMRfWbiV9wzxc5nB6FVQcxG3V unIZaqFJAUZS48OwIE2QGPsTZl3aBI/IkKue5g== X-Google-Smtp-Source: ABdhPJzUTg0UAbKZ7UExzEGdP8KfFvZwgGQ6NWLEFrO2yrFYxn15CQoDdnDDEB19Vs516jdxj6tNVQbGjf8FJRYSew== X-Received: by 2002:a25:a301:: with SMTP id d1mr5259997ybi.449.1594255005229; Wed, 08 Jul 2020 17:36:45 -0700 (PDT) Date: Wed, 8 Jul 2020 17:36:07 -0700 In-Reply-To: <20200709003608.3834629-1-hskinnemoen@google.com> Message-Id: <20200709003608.3834629-11-hskinnemoen@google.com> Mime-Version: 1.0 References: <20200709003608.3834629-1-hskinnemoen@google.com> X-Mailer: git-send-email 2.27.0.383.g050319c2ae-goog Subject: [PATCH v5 10/11] hw/arm: Wire up BMC boot flash for npcm750-evb and quanta-gsj From: Havard Skinnemoen 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=3nWYGXwsKCoInyqottksuktmuumrk.iuswks0-jk1krtutmt0.uxm@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: -105 X-Spam_score: -10.6 X-Spam_bar: ---------- X-Spam_report: (-10.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-1, 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" X-ZohoMail-DKIM: pass (identity @google.com) Content-Transfer-Encoding: quoted-printable 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 \ -bios ~/qemu/bootrom/npcm7xx_bootrom.bin \ -drive file=3D${IMAGE},if=3Dmtd,bus=3D0,unit=3D0,format=3Draw,snapshot=3Don Reviewed-by: Tyrone Ting Signed-off-by: Havard Skinnemoen Reviewed-by: C=C3=A9dric Le Goater Tested-by: C=C3=A9dric Le Goater --- 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 80cf1535f1..cfb31ce6f5 100644 --- a/hw/arm/npcm7xx_boards.c +++ b/hw/arm/npcm7xx_boards.c @@ -20,6 +20,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" @@ -66,6 +67,22 @@ static void npcm7xx_load_kernel(MachineState *machine, N= PCM7xxState *soc) arm_load_kernel(&soc->cpu[0], machine, &npcm7xx_binfo); } =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); + sysbus_connect_irq(SYS_BUS_DEVICE(fiu), cs_no, flash_cs); +} + static void npcm7xx_connect_dram(NPCM7xxState *soc, MemoryRegion *dram) { memory_region_add_subregion(get_system_memory(), NPCM7XX_DRAM_BA, dram= ); @@ -96,6 +113,7 @@ static void npcm750_evb_init(MachineState *machine) qdev_realize(DEVICE(soc), NULL, &error_abort); =20 npcm7xx_load_bootrom(soc); + npcm7xx_connect_flash(&soc->fiu[0], 0, "w25q256", drive_get(IF_MTD, 0,= 0)); npcm7xx_load_kernel(machine, soc); } =20 @@ -108,6 +126,8 @@ static void quanta_gsj_init(MachineState *machine) qdev_realize(DEVICE(soc), NULL, &error_abort); =20 npcm7xx_load_bootrom(soc); + npcm7xx_connect_flash(&soc->fiu[0], 0, "mx25l25635e", + drive_get(IF_MTD, 0, 0)); npcm7xx_load_kernel(machine, soc); } =20 --=20 2.27.0.383.g050319c2ae-goog From nobody Sun Apr 28 16:09:30 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=reject dis=none) header.from=google.com ARC-Seal: i=1; a=rsa-sha256; t=1594255414; cv=none; d=zohomail.com; s=zohoarc; b=GbqOojyiXc03+FQpO+F4XF4Lamb+4otwtqTtLJtjl0hnQleYG2hBe0SuhRdKU7Mald50dcQyBs3dSoJeETaZRfPhTpQ9v0ERoZUwKNbKBLyxJVdFXIiuiqAutpRdcHaZFcY7JoXXjr5LCQcz2xBqthLUaymkEhGFAwIdryuf4GY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594255414; 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:References:Sender:Subject:To; bh=4kEgWgHbRpLkO6qJk1qfJXYTlwg9/1nOLKkMOgmQiJc=; b=FdSKNRH3lEEoK1UT9NN3K2xFkBvCJ8+c/98fgkb+gjLBZbSyTpe0vOmeTrLs/BMrr4k0v/FBD51Yi6IuC4xH8g00+XkDmqW31RhbcvgcDuEFN6GXIv8euzyvfrfgj+Lg3bp5Bn4qZHtwNaXMUF+LbQb0otCxoDE7AuqaGV1djzs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1594255414093454.33671265636906; Wed, 8 Jul 2020 17:43:34 -0700 (PDT) Received: from localhost ([::1]:42442 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jtKey-0007MI-Ja for importer@patchew.org; Wed, 08 Jul 2020 20:43:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48296) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3nmYGXwsKCoMozrpuultvlunvvnsl.jvtxlt1-kl2lsuvunu1.vyn@flex--hskinnemoen.bounces.google.com>) id 1jtKYU-0006uG-Tc for qemu-devel@nongnu.org; Wed, 08 Jul 2020 20:36:50 -0400 Received: from mail-qv1-xf4a.google.com ([2607:f8b0:4864:20::f4a]:56215) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <3nmYGXwsKCoMozrpuultvlunvvnsl.jvtxlt1-kl2lsuvunu1.vyn@flex--hskinnemoen.bounces.google.com>) id 1jtKYS-000141-GC for qemu-devel@nongnu.org; Wed, 08 Jul 2020 20:36:50 -0400 Received: by mail-qv1-xf4a.google.com with SMTP id a12so263550qvt.22 for ; Wed, 08 Jul 2020 17:36:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc:content-transfer-encoding; bh=4kEgWgHbRpLkO6qJk1qfJXYTlwg9/1nOLKkMOgmQiJc=; b=VtxO58gz8PNHQHMZwb1mlisFTYXbvxgG1/iBXGRGmMc0Qtkm2hvC540WlnPYgUjNOY VsNgPcL3q7kzfNxP6CAh9VaGaCRmzEoWje+7YJidBUB0jzd9WJ+fogrgz5JisB9zV8ME LNSrDLa1Kv270EkDU8tZTqzQjR81d65aHcIcmpzVSwuPUDuK1E7yN27Iy9clnswCWX8K ZoAtQzxLCSLZkxyiAfRqcHsyIT3rJR21fPg6W7Hwd7nHaNmgo0OoKhnrs23qMDB7Flee zEQWPBxlqWpXnVvtOoEUvULxWdPSVjQebqgCZWmHj8trp8938ROpYHkoN6jt/Y26GmH2 hGow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=4kEgWgHbRpLkO6qJk1qfJXYTlwg9/1nOLKkMOgmQiJc=; b=frSbNIH+aNGihibuhYPmckJY92LK8UA697DiS3X/NIAXDRFj/TikviROXOnapBlmeS jvLOCOZkvnELheGbD2AD3lo64utropA/ggJ6OjGr3UM9uTWjpcK1D0y4V1U3/6x9YX+K RWPNRNMI9yhBTlsvjOlW3OxHeKBi9tzuQuJHO9xI+zONNx/fptujvML9N45DMgWYivoB 6Vamo3GRrleV8myYo3oP++wuTMrZMQKuju/ee2MA18PaboRPerdDUzHPc2eKnhhZB+GG FPjRFQlR5aXo0a/Yfrda72W0w2gkEZI++YyeiW1RPPvmUNGV3Q7HpWO7xmpAcww6h++B yzXw== X-Gm-Message-State: AOAM530EDqSB1RU1TQZEa8eFxb74I4ZI0J5MeRsGFXYZ7l0kFnv6rvC3 ciVK10B7deA8n5slH40FEFE+jz+VrFQ6k8Auzg== X-Google-Smtp-Source: ABdhPJy8ZjBUgvySB4tP65LKCkKFh6zi/gRZZ0dlN3axqfbFSUL0YawLTgA+YJgpDhZXdlVW98bfRyBs2QwH4T4SSA== X-Received: by 2002:a0c:800e:: with SMTP id 14mr49947224qva.92.1594255006971; Wed, 08 Jul 2020 17:36:46 -0700 (PDT) Date: Wed, 8 Jul 2020 17:36:08 -0700 In-Reply-To: <20200709003608.3834629-1-hskinnemoen@google.com> Message-Id: <20200709003608.3834629-12-hskinnemoen@google.com> Mime-Version: 1.0 References: <20200709003608.3834629-1-hskinnemoen@google.com> X-Mailer: git-send-email 2.27.0.383.g050319c2ae-goog Subject: [PATCH v5 11/11] docs/system: Add Nuvoton machine documentation From: Havard Skinnemoen 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::f4a; envelope-from=3nmYGXwsKCoMozrpuultvlunvvnsl.jvtxlt1-kl2lsuvunu1.vyn@flex--hskinnemoen.bounces.google.com; helo=mail-qv1-xf4a.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=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_OTHER_BAD_TLD=1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=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" X-ZohoMail-DKIM: pass (identity @google.com) Content-Type: text/plain; charset="utf-8" Reviewed-by: C=C3=A9dric Le Goater Signed-off-by: Havard Skinnemoen --- docs/system/arm/nuvoton.rst | 92 +++++++++++++++++++++++++++++++++++++ docs/system/target-arm.rst | 1 + 2 files changed, 93 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..7384662d58 --- /dev/null +++ b/docs/system/arm/nuvoton.rst @@ -0,0 +1,92 @@ +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/ + +Booting a full firmware image requires a Boot ROM specified via the ``-bio= s`` +option to QEMU. The firmware image should be attached as an MTD drive. Exa= mple : + +.. code-block:: bash + + $ qemu-system-arm -machine quanta-gsj -nographic \ + -bios npcm7xx_bootrom.bin \ + -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 1bd477a293..38a9daa9b9 100644 --- a/docs/system/target-arm.rst +++ b/docs/system/target-arm.rst @@ -84,6 +84,7 @@ undocumented; you can get a complete list by running arm/aspeed arm/musicpal arm/nseries + arm/nuvoton arm/orangepi arm/palm arm/xscale --=20 2.27.0.383.g050319c2ae-goog