qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Cédric Le Goater" <clg@kaod.org>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: Andrew Jeffery <andrew@aj.id.au>, qemu-arm <qemu-arm@nongnu.org>,
	QEMU Developers <qemu-devel@nongnu.org>,
	Joel Stanley <joel@jms.id.au>
Subject: Re: [Qemu-devel] [PATCH v2 15/21] aspeed/smc: add support for DMAs
Date: Mon, 1 Jul 2019 15:50:25 +0200	[thread overview]
Message-ID: <6a826ad0-1830-a865-d267-80529ad27a84@kaod.org> (raw)
In-Reply-To: <CAFEAcA-J+bS2-EtX6pTFYJ1XMaNLx0roYEoQMxV_=-mwMSPDgg@mail.gmail.com>

On 01/07/2019 15:06, Peter Maydell wrote:
> On Tue, 18 Jun 2019 at 17:55, Cédric Le Goater <clg@kaod.org> wrote:
>>
>> The FMC controller on the Aspeed SoCs support DMA to access the flash
>> modules. It can operate in a normal mode, to copy to or from the flash
>> module mapping window, or in a checksum calculation mode, to evaluate
>> the best clock settings for reads.
>>
>> The model introduces two custom address spaces for DMAs: one for the
>> AHB window of the FMC flash devices and one for the DRAM. The latter
>> is populated using a "dram" link set from the machine with the RAM
>> container region.
>>
>> Signed-off-by: Cédric Le Goater <clg@kaod.org>
>> Acked-by: Joel Stanley <joel@jms.id.au>
>> +/*
>> + * Accumulate the result of the reads to provide a checksum that will
>> + * be used to validate the read timing settings.
>> + */
>> +static void aspeed_smc_dma_checksum(AspeedSMCState *s)
>> +{
>> +    MemTxResult result;
>> +    uint32_t data;
>> +
>> +    if (s->regs[R_DMA_CTRL] & DMA_CTRL_WRITE) {
>> +        qemu_log_mask(LOG_GUEST_ERROR,
>> +                      "%s: invalid direction for DMA checksum\n",  __func__);
>> +        return;
>> +    }
>> +
>> +    while (s->regs[R_DMA_LEN]) {
>> +        result = address_space_read(&s->flash_as, s->regs[R_DMA_FLASH_ADDR],
>> +                                    MEMTXATTRS_UNSPECIFIED,
>> +                                    (uint8_t *)&data, 4);
> 
> This does a byte-by-byte read into a local uint32_t...
> 
>> +        if (result != MEMTX_OK) {
>> +            qemu_log_mask(LOG_GUEST_ERROR, "%s: Flash read failed @%08x\n",
>> +                          __func__, s->regs[R_DMA_FLASH_ADDR]);
>> +            return;
>> +        }
>> +
>> +        /*
>> +         * When the DMA is on-going, the DMA registers are updated
>> +         * with the current working addresses and length.
>> +         */
>> +        s->regs[R_DMA_CHECKSUM] += data;
> 
> ...which we then use as a (host-endian) 32-bit value.
> 
> This will behave differently on big endian and little endian hosts.
> If the h/w behaviour is to to load a 32-bit data type you probably
> want address_space_ldl_le() (or _be() if it's doing a big-endian load).
> 
>> +        s->regs[R_DMA_FLASH_ADDR] += 4;
>> +        s->regs[R_DMA_LEN] -= 4;
>> +    }
>> +}
>> +
>> +static void aspeed_smc_dma_rw(AspeedSMCState *s)
>> +{
>> +    MemTxResult result;
>> +    uint32_t data;
>> +
>> +    while (s->regs[R_DMA_LEN]) {
>> +        if (s->regs[R_DMA_CTRL] & DMA_CTRL_WRITE) {
>> +            result = address_space_read(&s->dram_as, s->regs[R_DMA_DRAM_ADDR],
>> +                                        MEMTXATTRS_UNSPECIFIED,
>> +                                        (uint8_t *)&data, 4);
>> +            if (result != MEMTX_OK) {
>> +                qemu_log_mask(LOG_GUEST_ERROR, "%s: DRAM read failed @%08x\n",
>> +                              __func__, s->regs[R_DMA_DRAM_ADDR]);
>> +                return;
>> +            }
>> +
>> +            result = address_space_write(&s->flash_as,
>> +                                         s->regs[R_DMA_FLASH_ADDR],
>> +                                         MEMTXATTRS_UNSPECIFIED,
>> +                                         (uint8_t *)&data, 4);
>> +            if (result != MEMTX_OK) {
>> +                qemu_log_mask(LOG_GUEST_ERROR, "%s: Flash write failed @%08x\n",
>> +                              __func__, s->regs[R_DMA_FLASH_ADDR]);
>> +                return;
>> +            }
>> +        } else {
>> +            result = address_space_read(&s->flash_as, s->regs[R_DMA_FLASH_ADDR],
>> +                                        MEMTXATTRS_UNSPECIFIED,
>> +                                        (uint8_t *)&data, 4);
>> +            if (result != MEMTX_OK) {
>> +                qemu_log_mask(LOG_GUEST_ERROR, "%s: Flash read failed @%08x\n",
>> +                              __func__, s->regs[R_DMA_FLASH_ADDR]);
>> +                return;
>> +            }
>> +
>> +            result = address_space_write(&s->dram_as, s->regs[R_DMA_DRAM_ADDR],
>> +                                         MEMTXATTRS_UNSPECIFIED,
>> +                                         (uint8_t *)&data, 4);
>> +            if (result != MEMTX_OK) {
>> +                qemu_log_mask(LOG_GUEST_ERROR, "%s: DRAM write failed @%08x\n",
>> +                              __func__, s->regs[R_DMA_DRAM_ADDR]);
>> +                return;
>> +            }
>> +        }
> 
> Since the code here doesn't do anything with the data the
> address_space_read/write here aren't wrong, but you might
> prefer to use the ldl and stl functions to avoid the casts
> to uint8_t* and need to specify the length.

yes. I will check with the HW guys to know precisely how the values are
read and accumulated.

Thanks,

C. 


  reply	other threads:[~2019-07-01 14:42 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-18 16:52 [Qemu-devel] [PATCH v2 00/21] aspeed: machine extensions and fixes Cédric Le Goater
2019-06-18 16:52 ` [Qemu-devel] [PATCH v2 01/21] aspeed: add a per SoC mapping for the interrupt space Cédric Le Goater
2019-06-18 16:52 ` [Qemu-devel] [PATCH v2 02/21] aspeed: add a per SoC mapping for the memory space Cédric Le Goater
2019-06-18 16:52 ` [Qemu-devel] [PATCH v2 03/21] hw: timer: Add ASPEED RTC device Cédric Le Goater
2019-07-02 19:19   ` Peter Maydell
2019-07-04  7:49     ` Joel Stanley
2019-07-04 13:08       ` Peter Maydell
2019-06-18 16:52 ` [Qemu-devel] [PATCH v2 04/21] hw/arm/aspeed: Add RTC to SoC Cédric Le Goater
2019-06-18 16:52 ` [Qemu-devel] [PATCH v2 05/21] aspeed: introduce a configurable number of CPU per machine Cédric Le Goater
2019-06-19  2:10   ` Joel Stanley
2019-06-18 16:52 ` [Qemu-devel] [PATCH v2 06/21] aspeed: add support for multiple NICs Cédric Le Goater
2019-06-19  2:11   ` Joel Stanley
2019-06-18 16:52 ` [Qemu-devel] [PATCH v2 07/21] aspeed/timer: Fix behaviour running Linux Cédric Le Goater
2019-06-18 16:52 ` [Qemu-devel] [PATCH v2 08/21] aspeed/timer: Status register contains reload for stopped timer Cédric Le Goater
2019-06-19  2:12   ` Joel Stanley
2019-06-18 16:52 ` [Qemu-devel] [PATCH v2 09/21] aspeed/timer: Fix match calculations Cédric Le Goater
2019-06-18 16:53 ` [Qemu-devel] [PATCH v2 10/21] aspeed/timer: Provide back-pressure information for short periods Cédric Le Goater
2019-07-01 12:59   ` Peter Maydell
2019-07-01 13:38     ` Cédric Le Goater
2019-07-03  8:53     ` Cédric Le Goater
2019-06-18 16:53 ` [Qemu-devel] [PATCH v2 11/21] aspeed/timer: Ensure positive muldiv delta Cédric Le Goater
2019-06-19  2:15   ` Joel Stanley
2019-06-20  2:05   ` Andrew Jeffery
2019-06-18 16:53 ` [Qemu-devel] [PATCH v2 12/21] aspeed: remove the "ram" link Cédric Le Goater
2019-06-18 16:53 ` [Qemu-devel] [PATCH v2 13/21] aspeed: add a RAM memory region container Cédric Le Goater
2019-06-18 16:53 ` [Qemu-devel] [PATCH v2 14/21] aspeed/smc: add a 'sdram_base' property Cédric Le Goater
2019-06-18 16:53 ` [Qemu-devel] [PATCH v2 15/21] aspeed/smc: add support for DMAs Cédric Le Goater
2019-07-01 13:06   ` Peter Maydell
2019-07-01 13:50     ` Cédric Le Goater [this message]
2019-06-18 16:53 ` [Qemu-devel] [PATCH v2 16/21] aspeed/smc: add DMA calibration settings Cédric Le Goater
2019-07-01 13:19   ` Peter Maydell
2019-06-18 16:53 ` [Qemu-devel] [PATCH v2 17/21] aspeed/smc: inject errors in DMA checksum Cédric Le Goater
2019-06-18 16:53 ` [Qemu-devel] [PATCH v2 18/21] aspeed/smc: Calculate checksum on normal DMA Cédric Le Goater
2019-06-18 16:53 ` [Qemu-devel] [PATCH v2 19/21] aspeed: Add support for the swift-bmc board Cédric Le Goater
2019-06-19  2:24   ` Joel Stanley
2019-06-18 16:53 ` [Qemu-devel] [PATCH v2 20/21] hw/misc/aspeed_xdma: New device Cédric Le Goater
2019-06-18 16:53 ` [Qemu-devel] [PATCH v2 21/21] aspeed: vic: Add support for legacy register interface Cédric Le Goater
2019-06-19  2:08   ` Joel Stanley
2019-07-01 13:35 ` [Qemu-devel] [PATCH v2 00/21] aspeed: machine extensions and fixes Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6a826ad0-1830-a865-d267-80529ad27a84@kaod.org \
    --to=clg@kaod.org \
    --cc=andrew@aj.id.au \
    --cc=joel@jms.id.au \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).