23 Mar, 2020

1 commit

  • On new Spreadtrum platforms, when the CPU enters idle, it will close
    the DMA controllers' clock to save power if the DMA controller is not
    busy. Moreover the DMA controller's busy signal depends on the DMA
    enable flag and the request pending flag.

    When DMA controller starts to transfer data, which means we already
    set the DMA enable flag, but now we should also set the request pending
    flag, in case the DMA clock will be closed accidentally if the CPU
    can not detect the DMA controller's busy signal.

    Signed-off-by: Zhenfang Wang
    Signed-off-by: Baolin Wang
    Link: https://lore.kernel.org/r/02adbe4364ec436ec2c5bc8fd2386bab98edd884.1584019223.git.baolin.wang7@gmail.com
    Signed-off-by: Vinod Koul

    Zhenfang Wang
     

19 Feb, 2020

1 commit

  • The current codebase makes use of the zero-length array language
    extension to the C90 standard, but the preferred mechanism to declare
    variable-length types such as these ones is a flexible array member[1][2],
    introduced in C99:

    struct foo {
    int stuff;
    struct boo array[];
    };

    By making use of the mechanism above, we will get a compiler warning
    in case the flexible array does not occur last in the structure, which
    will help us prevent some kind of undefined behavior bugs from being
    inadvertently introduced[3] to the codebase from now on.

    Also, notice that, dynamic memory allocations won't be affected by
    this change:

    "Flexible array members have incomplete type, and so the sizeof operator
    may not be applied. As a quirk of the original implementation of
    zero-length arrays, sizeof evaluates to zero."[1]

    This issue was found with the help of Coccinelle.

    [1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
    [2] https://github.com/KSPP/linux/issues/21
    [3] commit 76497732932f ("cxgb3/l2t: Fix undefined behaviour")

    Signed-off-by: Gustavo A. R. Silva
    Reviewed-by: Baolin Wang
    Link: https://lore.kernel.org/r/20200214171536.GA24077@embeddedor
    Signed-off-by: Vinod Koul

    Gustavo A. R. Silva
     

14 Nov, 2019

2 commits

  • The Spreadtrum Audio compress offload mode will use 2-stage DMA transfer
    to save power. That means we can request 2 dma channels, one for source
    channel, and another one for destination channel. Once the source channel's
    transaction is done, it will trigger the destination channel's transaction
    automatically by hardware signal.

    In this case, the source channel will transfer data from IRAM buffer to
    the DSP fifo to decoding/encoding, once IRAM buffer is empty by transferring
    done, the destination channel will start to transfer data from DDR buffer
    to IRAM buffer. Since the destination channel will use link-list mode to
    fill the IRAM data, and IRAM buffer is allocated by 32K, and DDR buffer
    is larger to 2M, that means we need lots of link-list nodes to do a cyclic
    transfer, instead wasting lots of link-list memory, we can use wrap address
    support to reduce link-list node number, which means when the transfer
    address reaches the wrap address, the transfer address will jump to the
    wrap_to address specified by wrap_to register, and only 2 link-list nodes
    can do a cyclic transfer to transfer data from DDR to IRAM.

    Thus this patch adds wrap address to support this case.

    [Baolin Wang changes the commit message]
    Signed-off-by: Eric Long
    Signed-off-by: Baolin Wang
    Link: https://lore.kernel.org/r/85a5484bc1f3dd53ce6f92700ad8b35f30a0b096.1571812029.git.baolin.wang@linaro.org
    Signed-off-by: Vinod Koul

    Eric Long
     
  • Vinod Koul
     

15 Oct, 2019

2 commits

  • If we terminate the channel to free all descriptors associated with this
    channel, we will leak the memory of current descriptor if the current
    descriptor is not completed, since it had been deteled from the desc_issued
    list and have not been added into the desc_completed list.

    Thus we should check if current descriptor is completed or not, when freeing
    the descriptors associated with one channel, if not, we should free it to
    avoid this issue.

    Fixes: 9b3b8171f7f4 ("dmaengine: sprd: Add Spreadtrum DMA driver")
    Reported-by: Zhenfang Wang
    Tested-by: Zhenfang Wang
    Signed-off-by: Baolin Wang
    Link: https://lore.kernel.org/r/170dbbc6d5366b6fa974ce2d366652e23a334251.1570609788.git.baolin.wang@linaro.org
    Signed-off-by: Vinod Koul

    Baolin Wang
     
  • Use the new helper that wraps the calls to platform_get_resource()
    and devm_ioremap_resource() together, which can simpify the code.

    Signed-off-by: Baolin Wang
    Link: https://lore.kernel.org/r/1af3efdac3b217203cace090c8947386854c0144.1569554639.git.baolin.wang@linaro.org
    Signed-off-by: Vinod Koul

    Baolin Wang
     

14 Oct, 2019

1 commit

  • We will set the link-list pointer register point to next link-list
    configuration's physical address, which can load DMA configuration
    from the link-list node automatically.

    But the link-list node's physical address can be larger than 32bits,
    and now Spreadtrum DMA driver only supports 32bits physical address,
    which may cause loading a incorrect DMA configuration when starting
    the link-list transfer mode. According to the DMA datasheet, we can
    use SRC_BLK_STEP register (bit28 - bit31) to save the high bits of the
    link-list node's physical address to fix this issue.

    Fixes: 4ac695464763 ("dmaengine: sprd: Support DMA link-list mode")
    Signed-off-by: Zhenfang Wang
    Signed-off-by: Baolin Wang
    Link: https://lore.kernel.org/r/eadfe9295499efa003e1c344e67e2890f9d1d780.1568267061.git.baolin.wang@linaro.org
    Signed-off-by: Vinod Koul

    Zhenfang Wang
     

04 Sep, 2019

1 commit

  • For the Spreadtrum DMA link-list mode, when the DMA engine got a slave
    hardware request, which will trigger the DMA engine to load the DMA
    configuration from the link-list memory automatically. But before the
    slave hardware request, the slave will get an incorrect residue due
    to the first node used to trigger the link-list was configured as the
    last source address and destination address.

    Thus we should make sure the first node was configured the start source
    address and destination address, which can fix this issue.

    Fixes: 4ac695464763 ("dmaengine: sprd: Support DMA link-list mode")
    Signed-off-by: Baolin Wang
    Link: https://lore.kernel.org/r/77868edb7aff9d5cb12ac3af8827ef2e244441a6.1567150471.git.baolin.wang@linaro.org
    Signed-off-by: Vinod Koul

    Baolin Wang
     

21 May, 2019

6 commits

  • For 2-stage transfer, some users like Audio still need transaction interrupt
    to notify when the 2-stage transfer is completed. Thus we should enable
    2-stage transfer interrupt to support this feature.

    Signed-off-by: Baolin Wang
    Signed-off-by: Vinod Koul

    Baolin Wang
     
  • Move the 2-stage configuration before configuring the link-list mode,
    since we will use some 2-stage configuration to fill the link-list
    configuration.

    Signed-off-by: Eric Long
    Signed-off-by: Baolin Wang
    Signed-off-by: Vinod Koul

    Eric Long
     
  • The maximum value of block length is 0xffff, so if the configured transfer length
    is more than 0xffff, that will cause block length overflow to lead a configuration
    error.

    Thus we can set block length as the maximum burst length to avoid this issue, since
    the maximum burst length will not be a big value which is more than 0xffff.

    Signed-off-by: Eric Long
    Signed-off-by: Baolin Wang
    Signed-off-by: Vinod Koul

    Eric Long
     
  • The 2-stage destination channel will be triggered by source channel
    automatically, which means we should not trigger it by software request.

    Signed-off-by: Eric Long
    Signed-off-by: Baolin Wang
    Signed-off-by: Vinod Koul

    Eric Long
     
  • When user terminates one DMA channel to free all its descriptors, but
    at the same time one transaction interrupt was triggered possibly, now
    we should not handle this interrupt by validating if the 'schan->cur_desc'
    was set as NULL to avoid crashing the kernel.

    Signed-off-by: Baolin Wang
    Signed-off-by: Vinod Koul

    Baolin Wang
     
  • We will get a NULL virtual descriptor by vchan_find_desc() when the descriptor
    has been submitted, that will crash the kernel when getting the descriptor
    status.

    In this case, since the descriptor has been submitted to process, but it
    is not completed now, which means the descriptor is listed into the
    'vc->desc_submitted' list now. So we can not get current processing descriptor
    by vchan_find_desc(), but the pointer 'schan->cur_desc' will point to the
    current processing descriptor, then we can use 'schan->cur_desc' to get
    current processing descriptor's status to avoid this issue.

    Signed-off-by: Baolin Wang
    Signed-off-by: Vinod Koul

    Baolin Wang
     

25 Feb, 2019

1 commit


05 Dec, 2018

7 commits


03 Sep, 2018

1 commit

  • The Spreadtrum DMA can support the link-list transaction mode, which means
    DMA controller can do transaction one by one automatically once we linked
    these transaction by link-list register.

    Signed-off-by: Eric Long
    Signed-off-by: Baolin Wang
    Signed-off-by: Vinod Koul

    Eric Long
     

09 Jun, 2018

1 commit

  • Pull dmaengine updates from Vinod Koul:

    - updates to sprd, bam_dma, stm drivers

    - remove VLAs in dmatest

    - move TI drivers to their own subdir

    - switch to SPDX tags for ima/mxs dma drivers

    - simplify getting .drvdata on bunch of drivers by Wolfram Sang

    * tag 'dmaengine-4.18-rc1' of git://git.infradead.org/users/vkoul/slave-dma: (32 commits)
    dmaengine: sprd: Add Spreadtrum DMA configuration
    dmaengine: sprd: Optimize the sprd_dma_prep_dma_memcpy()
    dmaengine: imx-dma: Switch to SPDX identifier
    dmaengine: mxs-dma: Switch to SPDX identifier
    dmaengine: imx-sdma: Switch to SPDX identifier
    dmaengine: usb-dmac: Document R8A7799{0,5} bindings
    dmaengine: qcom: bam_dma: fix some doc warnings.
    dmaengine: qcom: bam_dma: fix invalid assignment warning
    dmaengine: sprd: fix an NULL vs IS_ERR() bug
    dmaengine: sprd: Use devm_ioremap_resource() to map memory
    dmaengine: sprd: Fix potential NULL dereference in sprd_dma_probe()
    dmaengine: pl330: flush before wait, and add dev burst support.
    dmaengine: axi-dmac: Request IRQ with IRQF_SHARED
    dmaengine: stm32-mdma: fix spelling mistake: "avalaible" -> "available"
    dmaengine: rcar-dmac: Document R-Car D3 bindings
    dmaengine: sprd: Move DMA request mode and interrupt type into head file
    dmaengine: sprd: Define the DMA data width type
    dmaengine: sprd: Define the DMA transfer step type
    dmaengine: ti: New directory for Texas Instruments DMA drivers
    dmaengine: shdmac: Change platform check to CONFIG_ARCH_RENESAS
    ...

    Linus Torvalds
     

07 Jun, 2018

1 commit

  • Replaces open-coded struct size calculations with struct_size() for
    devm_*, f2fs_*, and sock_* allocations. Automatically generated (and
    manually adjusted) from the following Coccinelle script:

    // Direct reference to struct field.
    @@
    identifier alloc =~ "devm_kmalloc|devm_kzalloc|sock_kmalloc|f2fs_kmalloc|f2fs_kzalloc";
    expression HANDLE;
    expression GFP;
    identifier VAR, ELEMENT;
    expression COUNT;
    @@

    - alloc(HANDLE, sizeof(*VAR) + COUNT * sizeof(*VAR->ELEMENT), GFP)
    + alloc(HANDLE, struct_size(VAR, ELEMENT, COUNT), GFP)

    // mr = kzalloc(sizeof(*mr) + m * sizeof(mr->map[0]), GFP_KERNEL);
    @@
    identifier alloc =~ "devm_kmalloc|devm_kzalloc|sock_kmalloc|f2fs_kmalloc|f2fs_kzalloc";
    expression HANDLE;
    expression GFP;
    identifier VAR, ELEMENT;
    expression COUNT;
    @@

    - alloc(HANDLE, sizeof(*VAR) + COUNT * sizeof(VAR->ELEMENT[0]), GFP)
    + alloc(HANDLE, struct_size(VAR, ELEMENT, COUNT), GFP)

    // Same pattern, but can't trivially locate the trailing element name,
    // or variable name.
    @@
    identifier alloc =~ "devm_kmalloc|devm_kzalloc|sock_kmalloc|f2fs_kmalloc|f2fs_kzalloc";
    expression HANDLE;
    expression GFP;
    expression SOMETHING, COUNT, ELEMENT;
    @@

    - alloc(HANDLE, sizeof(SOMETHING) + COUNT * sizeof(ELEMENT), GFP)
    + alloc(HANDLE, CHECKME_struct_size(&SOMETHING, ELEMENT, COUNT), GFP)

    Signed-off-by: Kees Cook

    Kees Cook
     

29 May, 2018

2 commits

  • This patch adds the 'device_config' and 'device_prep_slave_sg' interfaces
    for users to configure DMA, as well as adding one 'struct sprd_dma_config'
    structure to save Spreadtrum DMA configuration for each DMA channel.

    Signed-off-by: Eric Long
    Signed-off-by: Baolin Wang
    Signed-off-by: Vinod Koul

    Eric Long
     
  • This is one preparation patch, we can use default DMA configuration to
    implement the device_prep_dma_memcpy() interface instead of issuing
    sprd_dma_config().

    We will implement one new sprd_dma_config() function with introducing
    device_prep_slave_sg() interface in following patch. So we can remove
    the obsolete sprd_dma_config() firstly.

    Signed-off-by: Eric Long
    Signed-off-by: Baolin Wang
    Signed-off-by: Vinod Koul

    Eric Long
     

17 May, 2018

1 commit

  • We recently cleaned this code up but we need to update the error
    handling as well. The devm_ioremap_resource() returns error pointers on
    error, never NULL.

    Fixes: e7f063ae1a31 ("dmaengine: sprd: Use devm_ioremap_resource() to map memory")
    Signed-off-by: Dan Carpenter
    Reviewed-by: Baolin Wang
    Signed-off-by: Vinod Koul

    Dan Carpenter
     

09 May, 2018

1 commit


07 May, 2018

1 commit

  • platform_get_resource() may fail and return NULL, so we should
    better check it's return value to avoid a NULL pointer dereference
    a bit later in the code.

    This is detected by Coccinelle semantic patch.

    @@
    expression pdev, res, n, t, e, e1, e2;
    @@

    res = platform_get_resource(pdev, t, n);
    + if (!res)
    + return -EINVAL;
    ... when != res == NULL
    e = devm_ioremap_nocache(e1, res->start, e2);

    Fixes: 9b3b8171f7f4 ("dmaengine: sprd: Add Spreadtrum DMA driver")
    Signed-off-by: Wei Yongjun
    Reviewed-by: Baolin Wang
    Signed-off-by: Vinod Koul

    Wei Yongjun
     

27 Apr, 2018

3 commits


15 Jan, 2018

1 commit


24 Oct, 2017

1 commit