From nobody Tue Oct 28 02:16:08 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1516067030650423.8324019796455; Mon, 15 Jan 2018 17:43:50 -0800 (PST) Received: from localhost ([::1]:52042 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebGI1-0002j1-QV for importer@patchew.org; Mon, 15 Jan 2018 20:43:49 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38770) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebGC9-00068b-Pr for qemu-devel@nongnu.org; Mon, 15 Jan 2018 20:37:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ebGC8-0005MC-Gy for qemu-devel@nongnu.org; Mon, 15 Jan 2018 20:37:45 -0500 Received: from mail-pl0-x243.google.com ([2607:f8b0:400e:c01::243]:46322) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ebGC3-0005Gb-CE; Mon, 15 Jan 2018 20:37:39 -0500 Received: by mail-pl0-x243.google.com with SMTP id 66so4925490plc.13; Mon, 15 Jan 2018 17:37:39 -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.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 15 Jan 2018 17:37:37 -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=BmLi/VjzQJLUFwe9nfYaFxzC6/3Khd/n0uG5wWACSRk=; b=CMOp11ItRxWodZpzZIcPy6bz0JutpQns52SuzwnFgq98IbJBG/3HnziUz6wkd8ycls MwKdv9h8o79CHNAar/YffYD+33Tpm2Z+yot04paqxMQe+7O1MPV0Wk4atz2YgNWRzOn7 zm/myFLJrfTOVB9wRc90qgezw/BVlmOdK9T0mEfySfiRy9iyajNKWzMJua+GYcc+kx2y 26TXoMqFIlEkjyVTn4ljueGs84K8kdC8YGRxy49JY5jFjwNuvaF3xyXQLqBNhz4YaSP8 D2Ci+U8PiIGQGs5P9/tzRFu1RwqVxdrzXiCeRNef+8ER2d4F1SjKx0Sn3isRCUs4t8RD NGPg== 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=BmLi/VjzQJLUFwe9nfYaFxzC6/3Khd/n0uG5wWACSRk=; b=KO+Mo3QscHJS2TIo6GlA2R5hIuMHR7G5Zp1iS/6TXbTOlcc0w62apucO/M8lB9jF/D +AlVnQIkYoy2SGruu7kGuDjDtQ9QrVEKEA+X+EFJ/6+zzksH3t3JbbhOYrrQ062O9pqE YTuPcZ9DBIm5NVLPUqXHEP1/kAjI/IledPHJpyhhDn1o5k6GI1/WIN1e7CLrqS5ZGXpu 920S+uStTj9XKo00ej7LG+8NnFbNgulowaVvHqXfaxTqzukAv8UCEpRWTj84QyzmEGJy zoSolMOcw/rK9AIGjzwX1RRcc2L+LCqajWTc3YnfhgdaW25kunrXpkxx0FYQ6hxbNxeW zGCw== X-Gm-Message-State: AKwxytehiWDK3duuLkbwN0PeYGBY3Rw0PInMbAXmF35GPHRNtBr9lEB1 KorUIaal46HD5d0E6bn6dtE0QHGj X-Google-Smtp-Source: ACJfBotybQm3IJX1XjXSsqhg9fQ6+vyVizqpQneUarpMzrwBKRT4RX6L/sMTO8rVh16zXnKd3C/TEg== X-Received: by 10.159.204.129 with SMTP id t1mr558604plo.363.1516066658184; Mon, 15 Jan 2018 17:37:38 -0800 (PST) From: Andrey Smirnov To: qemu-arm@nongnu.org Date: Mon, 15 Jan 2018 17:37:01 -0800 Message-Id: <20180116013709.13830-7-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:c01::243 Subject: [Qemu-devel] [PATCH v4 06/14] i.MX: Add code to emulate GPCv2 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 minimal code needed to allow upstream Linux guest to boot. 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/intc/Makefile.objs | 2 +- hw/intc/imx_gpcv2.c | 125 ++++++++++++++++++++++++++++++++++++++++= ++++ include/hw/intc/imx_gpcv2.h | 22 ++++++++ 3 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 hw/intc/imx_gpcv2.c create mode 100644 include/hw/intc/imx_gpcv2.h diff --git a/hw/intc/Makefile.objs b/hw/intc/Makefile.objs index ae358569a1..2252181ac9 100644 --- a/hw/intc/Makefile.objs +++ b/hw/intc/Makefile.objs @@ -4,7 +4,7 @@ common-obj-$(CONFIG_PL190) +=3D pl190.o common-obj-$(CONFIG_PUV3) +=3D puv3_intc.o common-obj-$(CONFIG_XILINX) +=3D xilinx_intc.o common-obj-$(CONFIG_ETRAXFS) +=3D etraxfs_pic.o -common-obj-$(CONFIG_IMX) +=3D imx_avic.o +common-obj-$(CONFIG_IMX) +=3D imx_avic.o imx_gpcv2.o common-obj-$(CONFIG_LM32) +=3D lm32_pic.o common-obj-$(CONFIG_REALVIEW) +=3D realview_gic.o common-obj-$(CONFIG_SLAVIO) +=3D slavio_intctl.o diff --git a/hw/intc/imx_gpcv2.c b/hw/intc/imx_gpcv2.c new file mode 100644 index 0000000000..496ed31b78 --- /dev/null +++ b/hw/intc/imx_gpcv2.c @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2017, Impinj, Inc. + * + * i.MX7 GPCv2 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. + */ + +#include "qemu/osdep.h" +#include "hw/intc/imx_gpcv2.h" +#include "qemu/log.h" + +#define GPC_PU_PGC_SW_PUP_REQ 0x0f8 +#define GPC_PU_PGC_SW_PDN_REQ 0x104 + +#define USB_HSIC_PHY_SW_Pxx_REQ BIT(4) +#define USB_OTG2_PHY_SW_Pxx_REQ BIT(3) +#define USB_OTG1_PHY_SW_Pxx_REQ BIT(2) +#define PCIE_PHY_SW_Pxx_REQ BIT(1) +#define MIPI_PHY_SW_Pxx_REQ BIT(0) + + +static void imx_gpcv2_reset(DeviceState *dev) +{ + IMXGPCv2State *s =3D IMX_GPCV2(dev); + + memset(s->regs, 0, sizeof(s->regs)); +} + +static uint64_t imx_gpcv2_read(void *opaque, hwaddr offset, + unsigned size) +{ + IMXGPCv2State *s =3D opaque; + + return s->regs[offset / sizeof(uint32_t)]; +} + +static void imx_gpcv2_write(void *opaque, hwaddr offset, + uint64_t value, unsigned size) +{ + IMXGPCv2State *s =3D opaque; + const size_t idx =3D offset / sizeof(uint32_t); + + s->regs[idx] =3D value; + + /* + * Real HW will clear those bits once as a way to indicate that + * power up request is complete + */ + if (offset =3D=3D GPC_PU_PGC_SW_PUP_REQ || + offset =3D=3D GPC_PU_PGC_SW_PDN_REQ) { + s->regs[idx] &=3D ~(USB_HSIC_PHY_SW_Pxx_REQ | + USB_OTG2_PHY_SW_Pxx_REQ | + USB_OTG1_PHY_SW_Pxx_REQ | + PCIE_PHY_SW_Pxx_REQ | + MIPI_PHY_SW_Pxx_REQ); + } +} + +static const struct MemoryRegionOps imx_gpcv2_ops =3D { + .read =3D imx_gpcv2_read, + .write =3D imx_gpcv2_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 imx_gpcv2_init(Object *obj) +{ + SysBusDevice *sd =3D SYS_BUS_DEVICE(obj); + IMXGPCv2State *s =3D IMX_GPCV2(obj); + + memory_region_init_io(&s->iomem, + obj, + &imx_gpcv2_ops, + s, + TYPE_IMX_GPCV2 ".iomem", + sizeof(s->regs)); + sysbus_init_mmio(sd, &s->iomem); +} + +static const VMStateDescription vmstate_imx_gpcv2 =3D { + .name =3D TYPE_IMX_GPCV2, + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (VMStateField[]) { + VMSTATE_UINT32_ARRAY(regs, IMXGPCv2State, GPC_NUM), + VMSTATE_END_OF_LIST() + }, +}; + +static void imx_gpcv2_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + dc->reset =3D imx_gpcv2_reset; + dc->vmsd =3D &vmstate_imx_gpcv2; + dc->desc =3D "i.MX GPCv2 Module"; +} + +static const TypeInfo imx_gpcv2_info =3D { + .name =3D TYPE_IMX_GPCV2, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(IMXGPCv2State), + .instance_init =3D imx_gpcv2_init, + .class_init =3D imx_gpcv2_class_init, +}; + +static void imx_gpcv2_register_type(void) +{ + type_register_static(&imx_gpcv2_info); +} +type_init(imx_gpcv2_register_type) diff --git a/include/hw/intc/imx_gpcv2.h b/include/hw/intc/imx_gpcv2.h new file mode 100644 index 0000000000..ed978b24bb --- /dev/null +++ b/include/hw/intc/imx_gpcv2.h @@ -0,0 +1,22 @@ +#ifndef IMX_GPCV2_H +#define IMX_GPCV2_H + +#include "hw/sysbus.h" + +enum IMXGPCv2Registers { + GPC_NUM =3D 0xE00 / sizeof(uint32_t), +}; + +typedef struct IMXGPCv2State { + /*< private >*/ + SysBusDevice parent_obj; + + /*< public >*/ + MemoryRegion iomem; + uint32_t regs[GPC_NUM]; +} IMXGPCv2State; + +#define TYPE_IMX_GPCV2 "imx-gpcv2" +#define IMX_GPCV2(obj) OBJECT_CHECK(IMXGPCv2State, (obj), TYPE_IMX_GPCV2) + +#endif /* IMX_GPCV2_H */ --=20 2.14.3