From nobody Mon Feb 9 18:46:23 2026 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 1509983876884525.7573977981473; Mon, 6 Nov 2017 07:57:56 -0800 (PST) Received: from localhost ([::1]:48816 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBjmY-0006P1-VN for importer@patchew.org; Mon, 06 Nov 2017 10:57:50 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33697) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBjdr-0007Ik-A8 for qemu-devel@nongnu.org; Mon, 06 Nov 2017 10:48:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eBjdo-0000ZT-G6 for qemu-devel@nongnu.org; Mon, 06 Nov 2017 10:48:51 -0500 Received: from mail-pg0-x241.google.com ([2607:f8b0:400e:c05::241]:43186) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eBjdl-0000Wa-44; Mon, 06 Nov 2017 10:48:45 -0500 Received: by mail-pg0-x241.google.com with SMTP id s75so8526974pgs.0; Mon, 06 Nov 2017 07:48:44 -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 x1sm22719590pfh.113.2017.11.06.07.48.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 06 Nov 2017 07:48:43 -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=rsMVyPJUtI8oymIlYkW5SpJ7ZuWF6SM2y9b3ocv3upo=; b=uAdQVDorO5n2hFfZxmry24mMVZJ57pAcI6nAow8lYvMOlf3bZMrUgaTntRxUXZjCm5 L5Fao3Om1VzQXwE3FL/qrTftZBB9EyZso07D3K/PXtcCFhvtGdWD2Kl6HU3UAJrQgzFJ 2iEHE8MDgGhftf/vlSPverJ1oS7HZRX0AZ3GFqCGVF+QL+eufvNEifkQF5wT7z7FTgfF 0mCpR6OEWOkOn7POARE+z4EG4zjnul8dRRgvSgJkclH1I6dFc6o39tjLGU8eHclIb+Jg 0U62OtWZpVIYcSCTGOOZX8cL30n2FI8QFi5THu/djis2fcXFEd2batDkLzPwep15BMqT mlTg== 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=rsMVyPJUtI8oymIlYkW5SpJ7ZuWF6SM2y9b3ocv3upo=; b=qv8e7r6tqypl4tg4xIX5O4smGvhh3cKFgwWr+lxWio/QsreA4H97jt+UC2K0OpQDzo JIguHrE0vNSxsLToBoNsgGt8boJbCtj7FHHMXASsooWZo4bd29dHz1oXWghARbzBnQUs zDO8xCDzRSoE12B/MLHMz0/TK3y829ElxLetVL+mFSXXCc+e15KAqKYdlg4zLhUkMAvR QTAL2XxAK4RtVe+CtM9K6w83UaeGx4qyGIsErO1tphn8/HqvUiu/C/OX240TcHcjSiU2 H3CpbU3ufkEngKk0rXk4Chck7LNCBPlODlekCKcjcF+ni20pQBL8mMI2P+sBoU4seg85 bh4Q== X-Gm-Message-State: AMCzsaX8lGAOPtaRiHp9ZsbZJULeEWdI2VGDyYbBTXlrNKxpn7DZhfW9 DzL9dRJtYrPFgg0q8v9KwJp8eLGbsQk= X-Google-Smtp-Source: ABhQp+RgQ2iyELs9MZZc2c6IF8gWvm6fjTo5kKBJAwq4peAD0o9670mBMRVxP12RhXWX2hdnVsY3LA== X-Received: by 10.98.223.131 with SMTP id d3mr17344928pfl.38.1509983323869; Mon, 06 Nov 2017 07:48:43 -0800 (PST) From: Andrey Smirnov To: qemu-arm@nongnu.org Date: Mon, 6 Nov 2017 07:47:57 -0800 Message-Id: <20171106154813.19936-15-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171106154813.19936-1-andrew.smirnov@gmail.com> References: <20171106154813.19936-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:c05::241 Subject: [Qemu-devel] [PATCH v3 14/30] i.MX: Add code to emulate i.MX2 watchdog 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 enough code to emulate i.MX2 watchdog IP block so it would be possible to reboot the machine running Linux Guest. 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 Signed-off-by: Andrey Smirnov Reviewed-by: Peter Maydell --- hw/misc/Makefile.objs | 1 + hw/misc/imx2_wdt.c | 88 ++++++++++++++++++++++++++++++++++++++++++= ++++ include/hw/misc/imx2_wdt.h | 34 ++++++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 hw/misc/imx2_wdt.c create mode 100644 include/hw/misc/imx2_wdt.h diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs index ac1be05a03..c393a93456 100644 --- a/hw/misc/Makefile.objs +++ b/hw/misc/Makefile.objs @@ -35,6 +35,7 @@ obj-$(CONFIG_IMX) +=3D imx25_ccm.o 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_MILKYMIST) +=3D milkymist-hpdmc.o obj-$(CONFIG_MILKYMIST) +=3D milkymist-pfpu.o obj-$(CONFIG_MAINSTONE) +=3D mst_fpga.o diff --git a/hw/misc/imx2_wdt.c b/hw/misc/imx2_wdt.c new file mode 100644 index 0000000000..3a1c33aa51 --- /dev/null +++ b/hw/misc/imx2_wdt.c @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2017, Impinj, Inc. + * + * i.MX2 Watchdog IP block + * + * 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. + */ + +#include "qemu/osdep.h" +#include "sysemu/watchdog.h" + +#include "hw/misc/imx2_wdt.h" + +#define IMX2_WDT_WCR_WDA BIT(5) /* -> External Reset WDOG_B */ +#define IMX2_WDT_WCR_SRS BIT(4) /* -> Software Reset Signal */ + +static uint64_t imx2_wdt_read(void *opaque, hwaddr addr, + unsigned int size) +{ + return 0; +} + +static void imx2_wdt_write(void *opaque, hwaddr addr, + uint64_t value, unsigned int size) +{ + if (addr =3D=3D IMX2_WDT_WCR && + (value & (IMX2_WDT_WCR_WDA | IMX2_WDT_WCR_SRS))) { + watchdog_perform_action(); + } +} + +static const MemoryRegionOps imx2_wdt_ops =3D { + .read =3D imx2_wdt_read, + .write =3D imx2_wdt_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 imx2_wdt_realize(DeviceState *dev, Error **errp) +{ + IMX2WdtState *s =3D IMX2_WDT(dev); + + memory_region_init_io(&s->mmio, OBJECT(dev), + &imx2_wdt_ops, s, + TYPE_IMX2_WDT".mmio", + IMX2_WDT_REG_NUM * sizeof(uint16_t)); + sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->mmio); +} + +static void imx2_wdt_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + dc->realize =3D imx2_wdt_realize; + set_bit(DEVICE_CATEGORY_MISC, dc->categories); +} + +static const TypeInfo imx2_wdt_info =3D { + .name =3D TYPE_IMX2_WDT, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(IMX2WdtState), + .class_init =3D imx2_wdt_class_init, +}; + +static WatchdogTimerModel model =3D { + .wdt_name =3D "imx2-watchdog", + .wdt_description =3D "i.MX2 Watchdog", +}; + +static void imx2_wdt_register_type(void) +{ + watchdog_add_model(&model); + type_register_static(&imx2_wdt_info); +} +type_init(imx2_wdt_register_type) diff --git a/include/hw/misc/imx2_wdt.h b/include/hw/misc/imx2_wdt.h new file mode 100644 index 0000000000..e67ac6939d --- /dev/null +++ b/include/hw/misc/imx2_wdt.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2017, Impinj, Inc. + * + * i.MX2 Watchdog IP block + * + * 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 IMX2_WDT_H +#define IMX2_WDT_H + +#include "qemu/bitops.h" +#include "hw/sysbus.h" + +#define TYPE_IMX2_WDT "imx2.wdt" +#define IMX2_WDT(obj) OBJECT_CHECK(IMX2WdtState, (obj), TYPE_IMX2_WDT) + +enum IMX2WdtRegisters { + IMX2_WDT_WCR =3D 0x0000, + IMX2_WDT_REG_NUM =3D 0x0008 / sizeof(uint16_t) + 1, +}; + + +typedef struct IMX2WdtState { + /* */ + SysBusDevice parent_obj; + + MemoryRegion mmio; +} IMX2WdtState; + +#endif /* IMX7_SNVS_H */ --=20 2.13.6