From patchwork Sat Oct 21 21:54:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Francisco Iglesias X-Patchwork-Id: 10021561 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 5500360381 for ; Sun, 22 Oct 2017 01:22:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A4EE287AE for ; Sun, 22 Oct 2017 01:22:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3F3B528925; Sun, 22 Oct 2017 01:22:57 +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 B8944287AE for ; Sun, 22 Oct 2017 01:22:56 +0000 (UTC) Received: from localhost ([::1]:59733 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e64yd-0002G3-Vs for patchwork-qemu-devel@patchwork.kernel.org; Sat, 21 Oct 2017 21:22:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47619) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e61j3-0000Pg-UN for qemu-devel@nongnu.org; Sat, 21 Oct 2017 17:54:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e61j2-0002ao-Ma for qemu-devel@nongnu.org; Sat, 21 Oct 2017 17:54:37 -0400 Received: from mail-lf0-x241.google.com ([2a00:1450:4010:c07::241]:48031) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e61j2-0002WJ-As for qemu-devel@nongnu.org; Sat, 21 Oct 2017 17:54:36 -0400 Received: by mail-lf0-x241.google.com with SMTP id k40so16444230lfi.4 for ; Sat, 21 Oct 2017 14:54:36 -0700 (PDT) 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; bh=1+aGvSo3KjhfS29Klr8ma/kIS45w4BzZZ4zxSIUUfNk=; b=jImdW+S45WcE2s9nWb7TuzfcCvZAK/Gv2eXArbgBoS/eHRy+d6wMLYpEuTqBdmbsfs w63qasVf+0nT3HEq52dStskYAcIUYkyBcufhtUdZQ53Dgm2keZ6+XFZepTJ3LFo4fkkr WkHduBMssh7G3Jrl6kD/afzsf6Z2uD+3Kxl6jcZdnQBWv98xzJZcW4JmMqwW5IvIf2L8 UGkNBy71Pd6SvNkneWIDc4ea3pSikiU1fidUSLkLslfHY6TUWPsMMICoeDl160MKQhTJ hFG5lYk7GNhmNDWRr1aMNljWtSaqih5DNnJtDrPnSOwWQltzpI7DWSw+lo9y6mUQOAPz sxbw== 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; bh=1+aGvSo3KjhfS29Klr8ma/kIS45w4BzZZ4zxSIUUfNk=; b=HOFdCyYf1tY1ANwRxND+ivZW6GIy+DxLB6utWQvyj+JREmBQIBZMhI01VzMhMqGfp+ +XNKJXyrc2FeSlAXJryWND2/oMMVcKfbX5L3q/wneUgBF5WkrAwrqEDaeE2x1Jgh5DwF HGu+OhpBTfiIJxXXVRHAhEbMs218ryWFaz83I3eiNzd9Du+gOtS9UwrJrPRgaG9Ct/i8 fXtJ6wPUIoY3JO7eyhpDyKwr0wiu20ckehMhZF1+r9p8vsYdx2f5pThD5Und/ac3PgHB 0Ld682KKyVMgGYowmbW/e+28mYj+1lwosCa4pvWyvOaCXdlKJxGUw8GhNaaLKzKiD2sL pMfQ== X-Gm-Message-State: AMCzsaUuXqWJyzrKxhVIiHFxnwBM0LU2glIqCCpSDfKoJcE37zso+bnj PJfJp9uebMeUxmuPoAChkse2sQWF X-Google-Smtp-Source: ABhQp+TV5WqdaOPquUquFaGbo/OCL2fMYpbxuzOBzl5SxhqM7YFxctZr8BHe7SyZPWuedbF/R8h4Pg== X-Received: by 10.46.42.194 with SMTP id q185mr3443960ljq.191.1508622874659; Sat, 21 Oct 2017 14:54:34 -0700 (PDT) Received: from localhost.localdomain (c83-254-152-225.bredband.comhem.se. [83.254.152.225]) by smtp.gmail.com with ESMTPSA id q87sm731173lfg.35.2017.10.21.14.54.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Oct 2017 14:54:33 -0700 (PDT) From: Francisco Iglesias To: qemu-devel@nongnu.org Date: Sat, 21 Oct 2017 23:54:16 +0200 Message-Id: <20171021215420.19787-9-frasse.iglesias@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20171021215420.19787-1-frasse.iglesias@gmail.com> References: <20171021215420.19787-1-frasse.iglesias@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4010:c07::241 X-Mailman-Approved-At: Sat, 21 Oct 2017 21:15:25 -0400 Subject: [Qemu-devel] [PATCH v2 08/12] xilinx_spips: Support configured endiannes of TX/RX registers 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: edgari@xilinx.com, alistai@xilinx.com, francisco.iglesias@feimtech.se Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Input into the transmition fifo (and output from the recieve fifo) according the configured endianess in the configuration register. Signed-off-by: Francisco Iglesias --- hw/ssi/xilinx_spips.c | 68 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 28 deletions(-) diff --git a/hw/ssi/xilinx_spips.c b/hw/ssi/xilinx_spips.c index 946df13..578ff8a 100644 --- a/hw/ssi/xilinx_spips.c +++ b/hw/ssi/xilinx_spips.c @@ -47,7 +47,7 @@ /* config register */ #define R_CONFIG (0x00 / 4) #define IFMODE (1U << 31) -#define ENDIAN (1 << 26) +#define R_CONFIG_ENDIAN (1 << 26) #define MODEFAIL_GEN_EN (1 << 17) #define MAN_START_COM (1 << 16) #define MAN_START_EN (1 << 15) @@ -447,13 +447,29 @@ static void xilinx_spips_flush_txfifo(XilinxSPIPS *s) } } -static inline void rx_data_bytes(XilinxSPIPS *s, uint8_t *value, int max) +static inline void tx_data_bytes(Fifo8 *fifo, uint32_t value, int num, bool be) +{ + int i; + for (i = 0; i < num && !fifo8_is_full(fifo); ++i) { + if (be) { + fifo8_push(fifo, (uint8_t)(value >> 24)); + value <<= 8; + } else { + fifo8_push(fifo, (uint8_t)value); + value >>= 8; + } + } +} + +static inline int rx_data_bytes(XilinxSPIPS *s, uint8_t *value, int max) { int i; for (i = 0; i < max && !fifo8_is_empty(&s->rx_fifo); ++i) { value[i] = fifo8_pop(&s->rx_fifo); } + + return max - i; } static uint64_t xilinx_spips_read(void *opaque, hwaddr addr, @@ -463,6 +479,9 @@ static uint64_t xilinx_spips_read(void *opaque, hwaddr addr, uint32_t mask = ~0; uint32_t ret; uint8_t rx_buf[4]; + int shortfall; + + memset(rx_buf, 0, sizeof(rx_buf)); addr >>= 2; switch (addr) { @@ -473,6 +492,7 @@ static uint64_t xilinx_spips_read(void *opaque, hwaddr addr, ret = s->regs[addr] & IXR_ALL; s->regs[addr] = 0; DB_PRINT_L(0, "addr=" TARGET_FMT_plx " = %x\n", addr * 4, ret); + xilinx_spips_update_ixr(s); return ret; case R_INTR_MASK: mask = IXR_ALL; @@ -493,9 +513,13 @@ static uint64_t xilinx_spips_read(void *opaque, hwaddr addr, break; case R_RX_DATA: memset(rx_buf, 0, sizeof(rx_buf)); - rx_data_bytes(s, rx_buf, s->num_txrx_bytes); - ret = s->regs[R_CONFIG] & ENDIAN ? cpu_to_be32(*(uint32_t *)rx_buf) - : cpu_to_le32(*(uint32_t *)rx_buf); + shortfall = rx_data_bytes(s, rx_buf, s->num_txrx_bytes); + ret = s->regs[R_CONFIG] & R_CONFIG_ENDIAN ? + cpu_to_be32(*(uint32_t *)rx_buf) : + cpu_to_le32(*(uint32_t *)rx_buf); + if (!(s->regs[R_CONFIG] & R_CONFIG_ENDIAN)) { + ret <<= 8 * shortfall; + } DB_PRINT_L(0, "addr=" TARGET_FMT_plx " = %x\n", addr * 4, ret); xilinx_spips_update_ixr(s); return ret; @@ -506,25 +530,12 @@ static uint64_t xilinx_spips_read(void *opaque, hwaddr addr, } -static inline void tx_data_bytes(XilinxSPIPS *s, uint32_t value, int num) -{ - int i; - for (i = 0; i < num && !fifo8_is_full(&s->tx_fifo); ++i) { - if (s->regs[R_CONFIG] & ENDIAN) { - fifo8_push(&s->tx_fifo, (uint8_t)(value >> 24)); - value <<= 8; - } else { - fifo8_push(&s->tx_fifo, (uint8_t)value); - value >>= 8; - } - } -} - static void xilinx_spips_write(void *opaque, hwaddr addr, uint64_t value, unsigned size) { int mask = ~0; int man_start_com = 0; + int tx_btt = 0; XilinxSPIPS *s = opaque; DB_PRINT_L(0, "addr=" TARGET_FMT_plx " = %x\n", addr, (unsigned)value); @@ -560,16 +571,17 @@ static void xilinx_spips_write(void *opaque, hwaddr addr, mask = 0; break; case R_TX_DATA: - tx_data_bytes(s, (uint32_t)value, s->num_txrx_bytes); - goto no_reg_update; - case R_TXD1: - tx_data_bytes(s, (uint32_t)value, 1); - goto no_reg_update; - case R_TXD2: - tx_data_bytes(s, (uint32_t)value, 2); + tx_data_bytes(&s->tx_fifo, (uint32_t)value, s->num_txrx_bytes, + s->regs[R_CONFIG] & R_CONFIG_ENDIAN); goto no_reg_update; case R_TXD3: - tx_data_bytes(s, (uint32_t)value, 3); + tx_btt++; + case R_TXD2: + tx_btt++; + case R_TXD1: + tx_btt++; + tx_data_bytes(&s->tx_fifo, (uint32_t)value, tx_btt, + s->regs[R_CONFIG] & R_CONFIG_ENDIAN); goto no_reg_update; } s->regs[addr] = (s->regs[addr] & ~mask) | (value & mask); @@ -679,7 +691,7 @@ static void lqspi_load_cache(void *opaque, hwaddr addr) while (cache_entry < LQSPI_CACHE_SIZE) { for (i = 0; i < 64; ++i) { - tx_data_bytes(s, 0, 1); + tx_data_bytes(&s->tx_fifo, 0, 1, false); } xilinx_spips_flush_txfifo(s); for (i = 0; i < 64; ++i) {