From nobody Mon Feb 9 15:46:02 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 1511738827644995.1702657527122; Sun, 26 Nov 2017 15:27:07 -0800 (PST) Received: from localhost ([::1]:58478 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eJ6K3-0004l3-IW for importer@patchew.org; Sun, 26 Nov 2017 18:26:51 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50249) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eJ6AQ-0004ab-7J for qemu-devel@nongnu.org; Sun, 26 Nov 2017 18:16:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eJ6AP-0000ty-3M for qemu-devel@nongnu.org; Sun, 26 Nov 2017 18:16:54 -0500 Received: from mail-lf0-x242.google.com ([2a00:1450:4010:c07::242]:44275) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eJ6AO-0000tL-NR for qemu-devel@nongnu.org; Sun, 26 Nov 2017 18:16:53 -0500 Received: by mail-lf0-x242.google.com with SMTP id w23so30632170lfd.11 for ; Sun, 26 Nov 2017 15:16:52 -0800 (PST) Received: from localhost.localdomain (host-90-232-123-128.mobileonline.telia.com. [90.232.123.128]) by smtp.gmail.com with ESMTPSA id j63sm2070285lfg.95.2017.11.26.15.16.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 26 Nov 2017 15:16:50 -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; bh=bdrjykzqXzKWm6F6HhMzlVMUTOERVvEewFrJlkNkkwc=; b=AVwhNQsQDoBn1U3LzF39gioM0hQE0LpKosNK9SX8OhvXn/jp8E9AVX520WV79/kUD3 BOMjd+QLGYEn4iNau89/ETJXiJF/+ZS5Oj5bWJw58h0O5as6PMDONMACfUC2EnOaHQJ+ 3Z5jC+dpfGkEfcKNV3AkDfagL6eZrno3ADKWJjZiE8DdyHi2Qc6WIFCR25lO7alPlPuF +UfazILsbL0qux3aggQ9aWgFgN0ruGWfsOm0tEH8SNJ5kzIbc1kOhwpUcE6/zFa+HGCu mAvACrOrKaDTkKATyD/IeKQvPvc0MumkvjAq8RXnfEI3lvwKZd3/leTT56qkde+dUkKX aEig== 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=bdrjykzqXzKWm6F6HhMzlVMUTOERVvEewFrJlkNkkwc=; b=aS0Alw/fmZQ+zmCYYkKZ0sNYuufNldQ9udzsicQ23Xt9PV6+F3XGRZC0+EGrx3zP0s KlFidhBA1VOh3ya+t7OnRmgZe4e/fsbtpg3HcmZFGy4AB94Q2N8OpSZ/WI9TGtfgcAII aWDrOELNPNUcirRkxWyyNGpcG+rp//U/20uJy8qU5hWq3QryU4hpLDBXGZpkgwL/VosZ 9K1x1UEc203bIVAVWgWCLuRPQ3NvkBHhPoJU+DoYnR4QAiqq2tj90dPDKfyzbz/fGP7R Wsqc6tOplhWgjzaOw9B2dooC6r4h8M7h0nPcz97y+CmHghSktk/GsWDB+34jXHGmRmbi gGQA== X-Gm-Message-State: AJaThX7dnQCA+h/aYKGWGPT0U1mw5m9BnHXJezVTUfIbURvmbK0RybDc pjDkqAqlgAt9HDjlJGfMebAdfg== X-Google-Smtp-Source: AGs4zMZyj9NOS3haD8CUOse1EqCES7QKdVL499GizqBvV3aqoekAv9ht/EGhPoiWahpuAxAeIvhTNg== X-Received: by 10.46.2.17 with SMTP id 17mr15175300ljc.67.1511738211186; Sun, 26 Nov 2017 15:16:51 -0800 (PST) From: Francisco Iglesias To: qemu-devel@nongnu.org Date: Mon, 27 Nov 2017 00:16:29 +0100 Message-Id: <20171126231634.9531-9-frasse.iglesias@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20171126231634.9531-1-frasse.iglesias@gmail.com> References: <20171126231634.9531-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::242 Subject: [Qemu-devel] [PATCH v9 08/13] xilinx_spips: Make tx/rx_data_bytes more generic and reusable 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@linaro.org, francisco.iglesias@feimtech.se, f4bug@amsat.org, edgari@xilinx.com, alistai@xilinx.com, mar.krzeminski@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 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Make tx/rx_data_bytes more generic so they can be reused (when adding support for the Zynqmp Generic QSPI). Signed-off-by: Francisco Iglesias Reviewed-by: Edgar E. Iglesias Tested-by: Edgar E. Iglesias --- hw/ssi/xilinx_spips.c | 64 +++++++++++++++++++++++++++++------------------= ---- 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/hw/ssi/xilinx_spips.c b/hw/ssi/xilinx_spips.c index 691d48d..4621dbb 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) @@ -450,13 +450,28 @@ static void xilinx_spips_flush_txfifo(XilinxSPIPS *s) } } =20 -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, boo= l be) { int i; + for (i =3D 0; i < num && !fifo8_is_full(fifo); ++i) { + if (be) { + fifo8_push(fifo, (uint8_t)(value >> 24)); + value <<=3D 8; + } else { + fifo8_push(fifo, (uint8_t)value); + value >>=3D 8; + } + } +} =20 - for (i =3D 0; i < max && !fifo8_is_empty(&s->rx_fifo); ++i) { - value[i] =3D fifo8_pop(&s->rx_fifo); +static inline int rx_data_bytes(Fifo8 *fifo, uint8_t *value, int max) +{ + int i; + + for (i =3D 0; i < max && !fifo8_is_empty(fifo); ++i) { + value[i] =3D fifo8_pop(fifo); } + return max - i; } =20 static uint64_t xilinx_spips_read(void *opaque, hwaddr addr, @@ -466,6 +481,7 @@ static uint64_t xilinx_spips_read(void *opaque, hwaddr = addr, uint32_t mask =3D ~0; uint32_t ret; uint8_t rx_buf[4]; + int shortfall; =20 addr >>=3D 2; switch (addr) { @@ -496,9 +512,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 =3D s->regs[R_CONFIG] & ENDIAN ? cpu_to_be32(*(uint32_t *)rx_b= uf) - : cpu_to_le32(*(uint32_t *)rx_buf); + shortfall =3D rx_data_bytes(&s->rx_fifo, rx_buf, s->num_txrx_bytes= ); + ret =3D 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 <<=3D 8 * shortfall; + } DB_PRINT_L(0, "addr=3D" TARGET_FMT_plx " =3D %x\n", addr * 4, ret); xilinx_spips_update_ixr(s); return ret; @@ -509,20 +529,6 @@ static uint64_t xilinx_spips_read(void *opaque, hwaddr= addr, =20 } =20 -static inline void tx_data_bytes(XilinxSPIPS *s, uint32_t value, int num) -{ - int i; - for (i =3D 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 <<=3D 8; - } else { - fifo8_push(&s->tx_fifo, (uint8_t)value); - value >>=3D 8; - } - } -} - static void xilinx_spips_write(void *opaque, hwaddr addr, uint64_t value, unsigned size) { @@ -563,16 +569,20 @@ static void xilinx_spips_write(void *opaque, hwaddr a= ddr, mask =3D 0; break; case R_TX_DATA: - tx_data_bytes(s, (uint32_t)value, s->num_txrx_bytes); + 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_TXD1: - tx_data_bytes(s, (uint32_t)value, 1); + tx_data_bytes(&s->tx_fifo, (uint32_t)value, 1, + s->regs[R_CONFIG] & R_CONFIG_ENDIAN); goto no_reg_update; case R_TXD2: - tx_data_bytes(s, (uint32_t)value, 2); + tx_data_bytes(&s->tx_fifo, (uint32_t)value, 2, + s->regs[R_CONFIG] & R_CONFIG_ENDIAN); goto no_reg_update; case R_TXD3: - tx_data_bytes(s, (uint32_t)value, 3); + tx_data_bytes(&s->tx_fifo, (uint32_t)value, 3, + s->regs[R_CONFIG] & R_CONFIG_ENDIAN); goto no_reg_update; } s->regs[addr] =3D (s->regs[addr] & ~mask) | (value & mask); @@ -682,11 +692,11 @@ static void lqspi_load_cache(void *opaque, hwaddr add= r) =20 while (cache_entry < LQSPI_CACHE_SIZE) { for (i =3D 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 =3D 0; i < 64; ++i) { - rx_data_bytes(s, &q->lqspi_buf[cache_entry++], 1); + rx_data_bytes(&s->rx_fifo, &q->lqspi_buf[cache_entry++], 1= ); } } =20 --=20 2.9.3