From nobody Mon Apr 29 19:05:09 2024 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 1513264990146160.49247544922662; Thu, 14 Dec 2017 07:23:10 -0800 (PST) Received: from localhost ([::1]:41543 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ePVLd-0002kd-9c for importer@patchew.org; Thu, 14 Dec 2017 10:22:57 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43524) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ePVIb-0000qi-4b for qemu-devel@nongnu.org; Thu, 14 Dec 2017 10:19:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ePVIW-0008HJ-Ja for qemu-devel@nongnu.org; Thu, 14 Dec 2017 10:19:49 -0500 Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]:41222) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ePVIW-0008GZ-By; Thu, 14 Dec 2017 10:19:44 -0500 Received: by mail-pg0-x243.google.com with SMTP id o2so3597854pgc.8; Thu, 14 Dec 2017 07:19: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 l80sm8680911pfk.67.2017.12.14.07.19.40 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Dec 2017 07:19:41 -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; bh=vRykh/JV35aiOBbn6Tp1ZdoMgudnPT5Ch7EtGRdCGuQ=; b=i+5kWkYtMDwBSNR7u10NugIfF0wq2cKmFwsvKnJV9CMf9/xQBe8mKuzGjAQ+jGe+u+ LDjiE5swdJBKmjWk1TKywXzHfCRJoOpwSyYpEukwh0HlMtkNsPfX3mwxjHYGfl0rSGAh +fOnayOM67aendRJGcK4Hm7Px5bwzqCMpJrQWKr3FhveGmSC2JinS3jxyLESrbVKVzgp hEedLwUBtPngNUs6qCdx8rIPyAd3YIS+/b+/pLwRYLvkWhiRb98v17uBDE2h1Srk/Smn S7PSirrs7yDeBgNz2lk12I/Sem2KogNAd8Zmz0RAdLeZoX7/vcpcWN0eQjvIIbw4LHzx 6btQ== 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; bh=vRykh/JV35aiOBbn6Tp1ZdoMgudnPT5Ch7EtGRdCGuQ=; b=H7qiNVf2C3YsDqoW0Ywp8RKZ4YE5qDHL+OwGLnyTrGsPN3K7rpYdc1W9JhPCu998o/ YAEtmMdHJrVA+YBcGSEoIIEBM+COfW5UFBX5p8x9rFycR7N5VxNlXgKiFfeSuQQoWPzW fAKrd1jklHyNbwQuJ/0EBB31p26df4yUI85JwlPdwEo9UgbgMVirldbz0hOD5Yao9WfF M2KFBt1/sJqf1Bo+rRD5hTn7W8yfAM9UeASoaojT4pSp/gdAZcswKMb8jWjClFOyvx8t nDzJeREy6neSnndjn5Xg8w9RpIVTptVnYNKN6eLhEHVmxp2y18RUJzciBpPUWgWWdkZO Oydw== X-Gm-Message-State: AKGB3mLjwU5Kw0Uyevq9jZ4ZwaX/HVjg74Dz7dC560tGL8otpqugYmvq M/Jeuvlo6jchXVqYUX5ZKKQXQ/zQ X-Google-Smtp-Source: ACJfBouRRFykB05YdlWRCWVn62zYW3M+C+HVr+4PKf1SJRoUiTzumcUDd1VJQ7JVxFwtIm/d4q74Fg== X-Received: by 10.99.133.200 with SMTP id u191mr8878375pgd.327.1513264783119; Thu, 14 Dec 2017 07:19:43 -0800 (PST) From: Andrey Smirnov To: qemu-devel@nongnu.org Date: Thu, 14 Dec 2017 07:19:34 -0800 Message-Id: <20171214151934.3647-1-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.14.3 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::243 Subject: [Qemu-devel] [PATCH] hw/misc: Add code to emulate Xilinx Slave Serial port 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: Andrey Smirnov , "Edgar E. Iglesias" , qemu-arm@nongnu.org, yurovsky@gmail.com, Alistair Francis 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 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add code to emulate Xilinx Slave Serial FPGA configuration port. Cc: "Edgar E. Iglesias" Cc: Alistair Francis Cc: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org Cc: yurovsky@gmail.com Signed-off-by: Andrey Smirnov --- Integrating this into a build system via "obj-y" might not be the best way. Does this code need a dedicated CONFIG_ symbol? Thanks, Andrey Smirnov hw/misc/Makefile.objs | 1 + hw/misc/xilinx_slave_serial.c | 105 ++++++++++++++++++++++++++++++= ++++ include/hw/misc/xilinx_slave_serial.h | 21 +++++++ 3 files changed, 127 insertions(+) create mode 100644 hw/misc/xilinx_slave_serial.c create mode 100644 include/hw/misc/xilinx_slave_serial.h diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs index a68a201083..4599288e55 100644 --- a/hw/misc/Makefile.objs +++ b/hw/misc/Makefile.objs @@ -38,6 +38,7 @@ obj-$(CONFIG_IMX) +=3D imx7_ccm.o obj-$(CONFIG_IMX) +=3D imx2_wdt.o obj-$(CONFIG_IMX) +=3D imx7_snvs.o obj-$(CONFIG_IMX) +=3D imx7_gpr.o +obj-y +=3D xilinx_slave_serial.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/xilinx_slave_serial.c b/hw/misc/xilinx_slave_serial.c new file mode 100644 index 0000000000..607674fb60 --- /dev/null +++ b/hw/misc/xilinx_slave_serial.c @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2017, Impinj, Inc. + * + * Code to emulate programming "port" of Xilinx FPGA in Slave Serial + * configuration connected via SPI, for more deatils see (p. 27): + * + * See https://www.xilinx.com/support/documentation/user_guides/ug380.pdf + * + * 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/misc/xilinx_slave_serial.h" +#include "qemu/log.h" + +enum { + XILINX_SLAVE_SERIAL_STATE_RESET, + XILINX_SLAVE_SERIAL_STATE_RECONFIGURATION, + XILINX_SLAVE_SERIAL_STATE_DONE, +}; + +static void xilinx_slave_serial_update_outputs(XilinxSlaveSerialState *xln= xss) +{ + qemu_set_irq(xlnxss->done, + xlnxss->state =3D=3D XILINX_SLAVE_SERIAL_STATE_DONE); +} + +static void xilinx_slave_serial_reset(DeviceState *dev) +{ + XilinxSlaveSerialState *xlnxss =3D XILINX_SLAVE_SERIAL(dev); + + xlnxss->state =3D XILINX_SLAVE_SERIAL_STATE_RESET; + + xilinx_slave_serial_update_outputs(xlnxss); +} + +static void xilinx_slave_serial_prog_b(void *opaque, int n, int level) +{ + XilinxSlaveSerialState *xlnxss =3D XILINX_SLAVE_SERIAL(opaque); + assert(n =3D=3D 0); + + if (level) { + xlnxss->state =3D XILINX_SLAVE_SERIAL_STATE_RECONFIGURATION; + } + + xilinx_slave_serial_update_outputs(xlnxss); +} + +static void xilinx_slave_serial_realize(SSISlave *ss, Error **errp) +{ + DeviceState *dev =3D DEVICE(ss); + XilinxSlaveSerialState *xlnxss =3D XILINX_SLAVE_SERIAL(ss); + + qdev_init_gpio_in_named(dev, + xilinx_slave_serial_prog_b, + XILINX_SLAVE_SERIAL_GPIO_PROG_B, + 1); + qdev_init_gpio_out_named(dev, &xlnxss->done, + XILINX_SLAVE_SERIAL_GPIO_DONE, 1); +} + +static uint32_t xilinx_slave_serial_transfer(SSISlave *ss, uint32_t tx) +{ + XilinxSlaveSerialState *xlnxss =3D XILINX_SLAVE_SERIAL(ss); + + if (xlnxss->state =3D=3D XILINX_SLAVE_SERIAL_STATE_RECONFIGURATION) { + xlnxss->state =3D XILINX_SLAVE_SERIAL_STATE_DONE; + } + + xilinx_slave_serial_update_outputs(xlnxss); + return 0; +} + +static void xilinx_slave_serial_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + SSISlaveClass *k =3D SSI_SLAVE_CLASS(klass); + + dc->reset =3D xilinx_slave_serial_reset; + dc->desc =3D "Xilinx Slave Serial"; + k->realize =3D xilinx_slave_serial_realize; + k->transfer =3D xilinx_slave_serial_transfer; + /* + * Slave Serial configuration is not technically SPI and there's + * no CS signal + */ + k->set_cs =3D NULL; + k->cs_polarity =3D SSI_CS_NONE; +} + +static const TypeInfo xilinx_slave_serial_info =3D { + .name =3D TYPE_XILINX_SLAVE_SERIAL, + .parent =3D TYPE_SSI_SLAVE, + .instance_size =3D sizeof(XilinxSlaveSerialState), + .class_init =3D xilinx_slave_serial_class_init, +}; + +static void xilinx_slave_serial_register_type(void) +{ + type_register_static(&xilinx_slave_serial_info); +} +type_init(xilinx_slave_serial_register_type) diff --git a/include/hw/misc/xilinx_slave_serial.h b/include/hw/misc/xilinx= _slave_serial.h new file mode 100644 index 0000000000..f7b2e22be3 --- /dev/null +++ b/include/hw/misc/xilinx_slave_serial.h @@ -0,0 +1,21 @@ +#ifndef XILINX_SLAVE_SERIAL_H +#define XILINX_SLAVE_SERIAL_H + +#include "hw/ssi/ssi.h" + +typedef struct XilinxSlaveSerialState { + /*< private >*/ + SSISlave parent_obj; + + qemu_irq done; + int state; +} XilinxSlaveSerialState; + +#define TYPE_XILINX_SLAVE_SERIAL "xilinx:slave-serial" +#define XILINX_SLAVE_SERIAL(obj) \ + OBJECT_CHECK(XilinxSlaveSerialState, (obj), TYPE_XILINX_SLAVE_SERIAL) + +#define XILINX_SLAVE_SERIAL_GPIO_DONE "xilinx:slave-serial:done" +#define XILINX_SLAVE_SERIAL_GPIO_PROG_B "xilinx:slave-serial:prog-b" + +#endif /* XILINX_SLAVE_SERIAL_H */ --=20 2.14.3