From patchwork Tue Jan 16 01:37:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 10165647 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0F7D1601E7 for ; Tue, 16 Jan 2018 01:45:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F196F27F17 for ; Tue, 16 Jan 2018 01:45:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E45C927F3E; Tue, 16 Jan 2018 01:45:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 49DA827F17 for ; Tue, 16 Jan 2018 01:45:13 +0000 (UTC) Received: from localhost ([::1]:52068 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebGJK-0004PN-Jn for patchwork-qemu-devel@patchwork.kernel.org; Mon, 15 Jan 2018 20:45:10 -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) 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) 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) 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 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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é 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) += imx6_ccm.o obj-$(CONFIG_IMX) += imx6_src.o obj-$(CONFIG_IMX) += imx7_ccm.o obj-$(CONFIG_IMX) += imx2_wdt.o +obj-$(CONFIG_IMX) += imx7_snvs.o obj-$(CONFIG_MILKYMIST) += milkymist-hpdmc.o obj-$(CONFIG_MILKYMIST) += milkymist-pfpu.o obj-$(CONFIG_MAINSTONE) += 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 later. + * 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 = v; + const uint32_t mask = SNVS_LPCR_TOP | SNVS_LPCR_DP_EN; + + if (offset == SNVS_LPCR && ((value & mask) == mask)) { + qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); + } +} + +static const struct MemoryRegionOps imx7_snvs_ops = { + .read = imx7_snvs_read, + .write = imx7_snvs_write, + .endianness = DEVICE_NATIVE_ENDIAN, + .impl = { + /* + * 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 = 4, + .max_access_size = 4, + .unaligned = false, + }, +}; + +static void imx7_snvs_init(Object *obj) +{ + SysBusDevice *sd = SYS_BUS_DEVICE(obj); + IMX7SNVSState *s = 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 = DEVICE_CLASS(klass); + + dc->desc = "i.MX7 Secure Non-Volatile Storage Module"; +} + +static const TypeInfo imx7_snvs_info = { + .name = TYPE_IMX7_SNVS, + .parent = TYPE_SYS_BUS_DEVICE, + .instance_size = sizeof(IMX7SNVSState), + .instance_init = imx7_snvs_init, + .class_init = 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 later. + * 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 = 0x38, + SNVS_LPCR_TOP = BIT(6), + SNVS_LPCR_DP_EN = 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 */