From nobody Tue Oct 28 02:06:26 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 15160671565561023.258583714631; Mon, 15 Jan 2018 17:45:56 -0800 (PST) Received: from localhost ([::1]:52068 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebGJu-0004PN-UX for importer@patchew.org; Mon, 15 Jan 2018 20:45:47 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38736) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebGC8-00066r-7Y for qemu-devel@nongnu.org; Mon, 15 Jan 2018 20:37:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ebGC7-0005KK-0K for qemu-devel@nongnu.org; Mon, 15 Jan 2018 20:37:44 -0500 Received: from mail-pf0-x241.google.com ([2607:f8b0:400e:c00::241]:36327) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ebGC2-0005FV-9i; Mon, 15 Jan 2018 20:37:38 -0500 Received: by mail-pf0-x241.google.com with SMTP id 23so8866265pfp.3; Mon, 15 Jan 2018 17:37:38 -0800 (PST) Received: from squirtle.lan (c-24-22-235-96.hsd1.wa.comcast.net. [24.22.235.96]) by smtp.gmail.com with ESMTPSA id s65sm1023795pfk.7.2018.01.15.17.37.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 15 Jan 2018 17:37:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XqOkBUrQilW0D3F2qgmewwsjlOkAbHj39O/o+o2TGDw=; b=eZWNVnIHmUJryFOK1JofoYgHGPaANj5OEMm9+5IKXcRTxry9B58woZIb+oJEp9sseh k24EjiEp104e16F1mePpE1kNBtw2q7SHOCW3oncsDBHatSQALKN4vMi+pE0bcCT41VMp Vveb0HSy6WqabRsDR0G6Vc6UE0Ps6TKZsgoUo/z5jfgz9cQaRwgoih1uxv6jyquKAucJ HtW8wsPtYIdW42EFczN5vPbYZ9a6+6HN1DmOfwhm1V0QBSQ5aXnDfg+NjxEG2AKFFTTo yrhiqpPBg3Wq76iWhg/otj4tgEXSP5g90jBIiO6SbJ8udXvJkFyg/3oELVT2wB7Arp99 wqZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XqOkBUrQilW0D3F2qgmewwsjlOkAbHj39O/o+o2TGDw=; b=ZhWmY5AhfXq56UU6qP1FMSgzfybmOEYlUrIJP/iz/b/kBRqODaDcaQOlT61VTZMg0T vBKRwi61kbIQ+9x4uuuLFuEspOwEBFdaSh023WoyJRDBK+u/gzyRLiI6FjEnMjqNwyRr CH7OHVmkmgu6wM3FnDquMh20YC9U6Umno8Fe/9NPdsQdK37AyQh412rrzupFes8S+F86 eR7g48pmPvpEkotrU1DVyoxTit3L7AYZsnx/55BsgYXVufQM67In+CQeWiWonCSa6t3l nuhDGw/p8M6uKhv6FL7ZQv5qzeLg5Ziyh9JW+4h3WYgvUIv+2YGlZg/rNTD1KgMLcdkO 8DeA== X-Gm-Message-State: AKGB3mIN7ulWqoZXZCh2kTaHXrUwmVKmnPbNJw4oXA2kvgCWeXF8KVuN cJuFCpoGbabAzOKoaclZzOXQ2a2P X-Google-Smtp-Source: ACJfBouwiH1wc3KNMMHT3EQH1+53byT6DOLuPBauWfv3fIwBOyW3wOB98bajwHqKyuif5vRHnHK7PA== X-Received: by 10.98.245.214 with SMTP id b83mr23304961pfm.85.1516066657071; Mon, 15 Jan 2018 17:37:37 -0800 (PST) From: Andrey Smirnov To: qemu-arm@nongnu.org Date: Mon, 15 Jan 2018 17:37:00 -0800 Message-Id: <20180116013709.13830-6-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180116013709.13830-1-andrew.smirnov@gmail.com> References: <20180116013709.13830-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c00::241 Subject: [Qemu-devel] [PATCH v4 05/14] i.MX: Add code to emulate i.MX7 SNVS IP-block X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Andrey Smirnov , Jason Wang , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org, yurovsky@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Add code to emulate SNVS IP-block. Currently only the bits needed to be able to emulate machine shutdown are implemented. Cc: Peter Maydell Cc: Jason Wang Cc: Philippe Mathieu-Daud=C3=A9 Cc: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Cc: yurovsky@gmail.com Reviewed-by: Peter Maydell Signed-off-by: Andrey Smirnov --- hw/misc/Makefile.objs | 1 + hw/misc/imx7_snvs.c | 83 +++++++++++++++++++++++++++++++++++++++++= ++++ include/hw/misc/imx7_snvs.h | 35 +++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 hw/misc/imx7_snvs.c create mode 100644 include/hw/misc/imx7_snvs.h diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs index 4b2b705a6c..019886912c 100644 --- a/hw/misc/Makefile.objs +++ b/hw/misc/Makefile.objs @@ -35,6 +35,7 @@ obj-$(CONFIG_IMX) +=3D imx6_ccm.o obj-$(CONFIG_IMX) +=3D imx6_src.o obj-$(CONFIG_IMX) +=3D imx7_ccm.o obj-$(CONFIG_IMX) +=3D imx2_wdt.o +obj-$(CONFIG_IMX) +=3D imx7_snvs.o obj-$(CONFIG_MILKYMIST) +=3D milkymist-hpdmc.o obj-$(CONFIG_MILKYMIST) +=3D milkymist-pfpu.o obj-$(CONFIG_MAINSTONE) +=3D mst_fpga.o diff --git a/hw/misc/imx7_snvs.c b/hw/misc/imx7_snvs.c new file mode 100644 index 0000000000..670b9f4639 --- /dev/null +++ b/hw/misc/imx7_snvs.c @@ -0,0 +1,83 @@ +/* + * IMX7 Secure Non-Volatile Storage + * + * Copyright (c) 2017, Impinj, Inc. + * + * Author: Andrey Smirnov + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + * Bare minimum emulation code needed to support being able to shut + * down linux guest gracefully. + */ + +#include "qemu/osdep.h" +#include "hw/misc/imx7_snvs.h" +#include "qemu/log.h" +#include "sysemu/sysemu.h" + +static uint64_t imx7_snvs_read(void *opaque, hwaddr offset, unsigned size) +{ + return 0; +} + +static void imx7_snvs_write(void *opaque, hwaddr offset, + uint64_t v, unsigned size) +{ + const uint32_t value =3D v; + const uint32_t mask =3D SNVS_LPCR_TOP | SNVS_LPCR_DP_EN; + + if (offset =3D=3D SNVS_LPCR && ((value & mask) =3D=3D mask)) { + qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); + } +} + +static const struct MemoryRegionOps imx7_snvs_ops =3D { + .read =3D imx7_snvs_read, + .write =3D imx7_snvs_write, + .endianness =3D DEVICE_NATIVE_ENDIAN, + .impl =3D { + /* + * Our device would not work correctly if the guest was doing + * unaligned access. This might not be a limitation on the real + * device but in practice there is no reason for a guest to access + * this device unaligned. + */ + .min_access_size =3D 4, + .max_access_size =3D 4, + .unaligned =3D false, + }, +}; + +static void imx7_snvs_init(Object *obj) +{ + SysBusDevice *sd =3D SYS_BUS_DEVICE(obj); + IMX7SNVSState *s =3D IMX7_SNVS(obj); + + memory_region_init_io(&s->mmio, obj, &imx7_snvs_ops, s, + TYPE_IMX7_SNVS, 0x1000); + + sysbus_init_mmio(sd, &s->mmio); +} + +static void imx7_snvs_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + dc->desc =3D "i.MX7 Secure Non-Volatile Storage Module"; +} + +static const TypeInfo imx7_snvs_info =3D { + .name =3D TYPE_IMX7_SNVS, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(IMX7SNVSState), + .instance_init =3D imx7_snvs_init, + .class_init =3D imx7_snvs_class_init, +}; + +static void imx7_snvs_register_type(void) +{ + type_register_static(&imx7_snvs_info); +} +type_init(imx7_snvs_register_type) diff --git a/include/hw/misc/imx7_snvs.h b/include/hw/misc/imx7_snvs.h new file mode 100644 index 0000000000..255f8f26f9 --- /dev/null +++ b/include/hw/misc/imx7_snvs.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2017, Impinj, Inc. + * + * i.MX7 SNVS block emulation code + * + * Author: Andrey Smirnov + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#ifndef IMX7_SNVS_H +#define IMX7_SNVS_H + +#include "qemu/bitops.h" +#include "hw/sysbus.h" + + +enum IMX7SNVSRegisters { + SNVS_LPCR =3D 0x38, + SNVS_LPCR_TOP =3D BIT(6), + SNVS_LPCR_DP_EN =3D BIT(5) +}; + +#define TYPE_IMX7_SNVS "imx7.snvs" +#define IMX7_SNVS(obj) OBJECT_CHECK(IMX7SNVSState, (obj), TYPE_IMX7_SNVS) + +typedef struct IMX7SNVSState { + /* */ + SysBusDevice parent_obj; + + MemoryRegion mmio; +} IMX7SNVSState; + +#endif /* IMX7_SNVS_H */ --=20 2.14.3