From patchwork Thu Dec 14 15:19:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 10112469 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 DD0E860327 for ; Thu, 14 Dec 2017 15:22:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE8DC290B4 for ; Thu, 14 Dec 2017 15:22:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C3406290C1; Thu, 14 Dec 2017 15:22:39 +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 AB7C9290B4 for ; Thu, 14 Dec 2017 15:22:38 +0000 (UTC) Received: from localhost ([::1]:41543 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ePVLJ-0002kd-Or for patchwork-qemu-devel@patchwork.kernel.org; Thu, 14 Dec 2017 10:22:37 -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) 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) 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) 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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) += imx7_ccm.o obj-$(CONFIG_IMX) += imx2_wdt.o obj-$(CONFIG_IMX) += imx7_snvs.o obj-$(CONFIG_IMX) += imx7_gpr.o +obj-y += xilinx_slave_serial.o obj-$(CONFIG_MILKYMIST) += milkymist-hpdmc.o obj-$(CONFIG_MILKYMIST) += milkymist-pfpu.o obj-$(CONFIG_MAINSTONE) += 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 later. + * 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 *xlnxss) +{ + qemu_set_irq(xlnxss->done, + xlnxss->state == XILINX_SLAVE_SERIAL_STATE_DONE); +} + +static void xilinx_slave_serial_reset(DeviceState *dev) +{ + XilinxSlaveSerialState *xlnxss = XILINX_SLAVE_SERIAL(dev); + + xlnxss->state = 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 = XILINX_SLAVE_SERIAL(opaque); + assert(n == 0); + + if (level) { + xlnxss->state = XILINX_SLAVE_SERIAL_STATE_RECONFIGURATION; + } + + xilinx_slave_serial_update_outputs(xlnxss); +} + +static void xilinx_slave_serial_realize(SSISlave *ss, Error **errp) +{ + DeviceState *dev = DEVICE(ss); + XilinxSlaveSerialState *xlnxss = 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 = XILINX_SLAVE_SERIAL(ss); + + if (xlnxss->state == XILINX_SLAVE_SERIAL_STATE_RECONFIGURATION) { + xlnxss->state = 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 = DEVICE_CLASS(klass); + SSISlaveClass *k = SSI_SLAVE_CLASS(klass); + + dc->reset = xilinx_slave_serial_reset; + dc->desc = "Xilinx Slave Serial"; + k->realize = xilinx_slave_serial_realize; + k->transfer = xilinx_slave_serial_transfer; + /* + * Slave Serial configuration is not technically SPI and there's + * no CS signal + */ + k->set_cs = NULL; + k->cs_polarity = SSI_CS_NONE; +} + +static const TypeInfo xilinx_slave_serial_info = { + .name = TYPE_XILINX_SLAVE_SERIAL, + .parent = TYPE_SSI_SLAVE, + .instance_size = sizeof(XilinxSlaveSerialState), + .class_init = 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 */