From patchwork Fri Apr 19 02:12:49 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Crosthwaite X-Patchwork-Id: 237818 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 5E1042C021A for ; Fri, 19 Apr 2013 12:15:26 +1000 (EST) Received: from localhost ([::1]:33586 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UT0rE-0001uh-IN for incoming@patchwork.ozlabs.org; Thu, 18 Apr 2013 22:15:24 -0400 Received: from eggs.gnu.org ([208.118.235.92]:59180) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UT0ql-0001Pe-Dk for qemu-devel@nongnu.org; Thu, 18 Apr 2013 22:14:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UT0qk-0005aF-8Z for qemu-devel@nongnu.org; Thu, 18 Apr 2013 22:14:55 -0400 Received: from mail-pa0-f50.google.com ([209.85.220.50]:40241) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UT0qk-0005a4-2T for qemu-devel@nongnu.org; Thu, 18 Apr 2013 22:14:54 -0400 Received: by mail-pa0-f50.google.com with SMTP id bg2so1932271pad.23 for ; Thu, 18 Apr 2013 19:14:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:sender:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state; bh=PeevNLm4oa4ByPDwo8oqvtW7llQfgv5qmdUj9bksYy4=; b=Ui8X+x0Uo+QWtf1X7+y2f0wYQqt3lYiqDHd9yd294Eb2Ez+iVOcQbw5bLYEmxVgA/5 wFK+QDj9RTP+a9JAIHhABsUSX+bNMNqA2RBfd6teZ9Eqz6Ldg/B0OfUvid24UXwL7eFm BEa53dHlNXYONKo/tSsxgpJ+T7667NPhzNExwc3JkFWmFp324XeNVRWIgN3Ulv1mb15V uPsoqWJlsfACoSJ9o9uq/pAJrA5ffyc9HYG+VSVQN2qLuiWWz6Ry2FeWMIClLWmLHQYN n3X9sbRAkGpd78KOhBkp7GcOKdtBV1RQxAogoAXkycQxwJu5KONdmsEojbr5arSf6L/H AE4w== X-Received: by 10.68.196.161 with SMTP id in1mr4370646pbc.106.1366337693319; Thu, 18 Apr 2013 19:14:53 -0700 (PDT) Received: from localhost ([149.199.62.254]) by mx.google.com with ESMTPS id sa6sm11599323pbb.26.2013.04.18.19.14.50 (version=TLSv1.1 cipher=RC4-SHA bits=128/128); Thu, 18 Apr 2013 19:14:52 -0700 (PDT) From: peter.crosthwaite@xilinx.com To: qemu-devel@nongnu.org Date: Fri, 19 Apr 2013 12:12:49 +1000 Message-Id: <1b913ae1971ab261d092e41dc82878c18dab91ce.1366335998.git.peter.crosthwaite@xilinx.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: References: X-Gm-Message-State: ALoCoQlKNcDROAQtBeFM41mRc+HSzFqx93yqVv0HfBRZuesZOHFt1P2d5hT4bWvPkeno03Bov/iv X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.220.50 Cc: peter.maydell@linaro.org Subject: [Qemu-devel] [PATCH for-1.5 v2 15/15] xilinx_spips: lqspi: Fix byte/misaligned access X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Peter Crosthwaite The LQSPI bus attachment supports byte/halfword and misaligned accesses. Fixed. Refactored the LQSPI cache to be byte-wise instead of word wise accordingly. Signed-off-by: Peter Crosthwaite --- hw/ssi/xilinx_spips.c | 31 +++++++++++++++++-------------- 1 files changed, 17 insertions(+), 14 deletions(-) diff --git a/hw/ssi/xilinx_spips.c b/hw/ssi/xilinx_spips.c index 68434f0..9971194 100644 --- a/hw/ssi/xilinx_spips.c +++ b/hw/ssi/xilinx_spips.c @@ -161,7 +161,7 @@ typedef struct { typedef struct { XilinxSPIPS parent_obj; - uint32_t lqspi_buf[LQSPI_CACHE_SIZE]; + uint8_t lqspi_buf[LQSPI_CACHE_SIZE]; hwaddr lqspi_cached_addr; } XilinxQSPIPS; @@ -391,14 +391,12 @@ static void xilinx_spips_flush_txfifo(XilinxSPIPS *s) } } -static inline void rx_data_bytes(XilinxSPIPS *s, uint32_t *value, int max) +static inline void rx_data_bytes(XilinxSPIPS *s, uint8_t *value, int max) { int i; - *value = 0; for (i = 0; i < max && !fifo8_is_empty(&s->rx_fifo); ++i) { - uint32_t next = fifo8_pop(&s->rx_fifo) & 0xFF; - *value |= next << 8 * (s->regs[R_CONFIG] & ENDIAN ? 3-i : i); + value[i] = fifo8_pop(&s->rx_fifo); } } @@ -408,6 +406,7 @@ static uint64_t xilinx_spips_read(void *opaque, hwaddr addr, XilinxSPIPS *s = opaque; uint32_t mask = ~0; uint32_t ret; + uint8_t rx_buf[4]; addr >>= 2; switch (addr) { @@ -437,7 +436,10 @@ static uint64_t xilinx_spips_read(void *opaque, hwaddr addr, mask = 0; break; case R_RX_DATA: - rx_data_bytes(s, &ret, s->num_txrx_bytes); + 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); DB_PRINT_L(0, "addr=" TARGET_FMT_plx " = %x\n", addr * 4, ret); xilinx_spips_update_ixr(s); return ret; @@ -563,7 +565,8 @@ lqspi_read(void *opaque, hwaddr addr, unsigned int size) if (addr >= q->lqspi_cached_addr && addr <= q->lqspi_cached_addr + LQSPI_CACHE_SIZE - 4) { - ret = q->lqspi_buf[(addr - q->lqspi_cached_addr) >> 2]; + uint8_t *retp = &q->lqspi_buf[addr - q->lqspi_cached_addr]; + ret = cpu_to_le32(*(uint32_t *)retp); DB_PRINT_L(1, "addr: %08x, data: %08x\n", (unsigned)addr, (unsigned)ret); return ret; @@ -609,13 +612,13 @@ lqspi_read(void *opaque, hwaddr addr, unsigned int size) DB_PRINT_L(0, "starting QSPI data read\n"); - while (cache_entry < LQSPI_CACHE_SIZE / 4) { - for (i = 0; i < 16; ++i) { - tx_data_bytes(s, 0, 4); + while (cache_entry < LQSPI_CACHE_SIZE) { + for (i = 0; i < 64; ++i) { + tx_data_bytes(s, 0, 1); } xilinx_spips_flush_txfifo(s); - for (i = 0; i < 16; ++i) { - rx_data_bytes(s, &q->lqspi_buf[cache_entry++], 4); + for (i = 0; i < 64; ++i) { + rx_data_bytes(s, &q->lqspi_buf[cache_entry++], 1); } } @@ -623,7 +626,7 @@ lqspi_read(void *opaque, hwaddr addr, unsigned int size) s->regs[R_LQSPI_STS] |= u_page_save; xilinx_spips_update_cs_lines(s); - q->lqspi_cached_addr = addr; + q->lqspi_cached_addr = flash_addr * num_effective_busses(s); return lqspi_read(opaque, addr, size); } } @@ -632,7 +635,7 @@ static const MemoryRegionOps lqspi_ops = { .read = lqspi_read, .endianness = DEVICE_NATIVE_ENDIAN, .valid = { - .min_access_size = 4, + .min_access_size = 1, .max_access_size = 4 } };