Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: dma: Add Andestech atcdmac300 driver. #59041

Merged
merged 1 commit into from
Oct 20, 2023

Conversation

kevinwang821020
Copy link
Collaborator

Support the Andes atcdmac300 dma driver.
Also add the dma property in spi node.

@zephyrbot zephyrbot added area: DMA Direct Memory Access area: Devicetree Binding PR modifies or adds a Device Tree binding area: RISCV RISCV Architecture (32-bit & 64-bit) labels Jun 8, 2023
@kevinwang821020 kevinwang821020 force-pushed the dma_driver branch 5 times, most recently from ba8c995 to 7cd16d0 Compare June 9, 2023 01:37

cfg_blocks = cfg->head_block;
if (cfg_blocks == NULL) {
return -EINVAL;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the spinlock be unlocked in this - and all following - early returns?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes you are right.
It is early returns, we have update the source code for this request.
Thank you.

Copy link
Collaborator

@edersondisouza edersondisouza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems ok, just some nits. But it seems the build issues on CI are relevant - could you please take a look?

#define DMA_INT_STATUS_CH_MSK(ch) (0x111 << ch)

#define INWORD(x) sys_read32(x)
#define OUTWORD(x, d) sys_write32(d, x)
Copy link
Collaborator

@edersondisouza edersondisouza Jun 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why redefine these?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your remind, these macro is redundant.
We have update the source code for it.


return 0;
}
static int dma_atcdmac300_get_status(const struct device *dev,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: missing newline before this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, thank you, we have fixed this problem.

edersondisouza
edersondisouza previously approved these changes Jun 28, 2023
@edersondisouza edersondisouza dismissed their stale review June 28, 2023 19:40

My points were addressed, but not sure I can approve the whole PR.

Copy link
Collaborator

@teburd teburd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to use a simpler object pool here rather than a heap

#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(dma_andes_atcdmac300);

K_HEAP_DEFINE(dma_chain, 1024);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a pool of chain objects would be more sensible here than a heap and simpler, generally Zephyr drivers shouldn't be using a general purpose heap given the misra rules

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got it. We weren't aware of that.
We have update the source code.

Comment on lines 54 to 69
#define DMA_IDR (DEV_CFG(dev)->base + 0x00)
#define DMA_CFG (DEV_CFG(dev)->base + 0x10)
#define DMA_CTRL (DEV_CFG(dev)->base + 0x20)
#define DMA_ABORT (DEV_CFG(dev)->base + 0x24)
#define DMA_INT_STATUS (DEV_CFG(dev)->base + 0x30)
#define DMA_CH_ENABLE (DEV_CFG(dev)->base + 0x34)

#define DMA_CH_OFFSET(ch) (ch * 0x20)
#define DMA_CH_CTRL(ch) (DEV_CFG(dev)->base + 0x40 + DMA_CH_OFFSET(ch))
#define DMA_CH_TRANSIZE(ch) (DEV_CFG(dev)->base + 0x44 + DMA_CH_OFFSET(ch))
#define DMA_CH_SRC_ADDR_L(ch) (DEV_CFG(dev)->base + 0x48 + DMA_CH_OFFSET(ch))
#define DMA_CH_SRC_ADDR_H(ch) (DEV_CFG(dev)->base + 0x4C + DMA_CH_OFFSET(ch))
#define DMA_CH_DST_ADDR_L(ch) (DEV_CFG(dev)->base + 0x50 + DMA_CH_OFFSET(ch))
#define DMA_CH_DST_ADDR_H(ch) (DEV_CFG(dev)->base + 0x54 + DMA_CH_OFFSET(ch))
#define DMA_CH_LL_PTR_L(ch) (DEV_CFG(dev)->base + 0x58 + DMA_CH_OFFSET(ch))
#define DMA_CH_LL_PTR_H(ch) (DEV_CFG(dev)->base + 0x5C + DMA_CH_OFFSET(ch))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add an explicit (dev) parameter to all these macros.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for that we didn't notice that the macro like DEV_CFG is redundant now.
We have done the modification for it.

Comment on lines 51 to 52
#define DEV_CFG(dev) ((const struct dma_atcdmac300_cfg * const) (dev)->config)
#define DEV_DATA(dev) ((struct dma_atcdmac300_data *) (dev)->data)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We deprecated the usage of these macros.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for that we didn't notice that the macro like DEV_CFG is redundant now.
We have done the modification for it.

Comment on lines 155 to 156
#define INWORD(x) sys_read32(x)
#define OUTWORD(x, d) sys_write32(d, x)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed

@@ -0,0 +1 @@
CONFIG_CACHE_ENABLE=n
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uhm, it's a bit too late but having this symbol is wrong since it overlaps with the cache symbols we already have in place in Zephyr. Can you ask some Andes folk to remove it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got it!
We use the CONFIG_ICACHE and CONFIG_DCACHE to replace it now.

@kevinwang821020
Copy link
Collaborator Author

Sorry to bother you reviewers, I would like to know if there are any other parts of source code that I can improve/refined.

Thanks for helping us.

carlocaione
carlocaione previously approved these changes Jul 28, 2023
Copy link
Collaborator

@carlocaione carlocaione left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general LGTM, not vouching for the DMA bits.

@kevinwang821020
Copy link
Collaborator Author

Sorry to bother you reviewers, there are some build error in ci testing about qemu_x86_64 platform, it seems like we can't avoid it.
What can we do for it if we want to pass the ci tesing.
Thank you very much.

@carlocaione
Copy link
Collaborator

Sorry to bother you reviewers, there are some build error in ci testing about qemu_x86_64 platform, it seems like we can't avoid it. What can we do for it if we want to pass the ci tesing. Thank you very much.

That was recently fixed. Please rebase.

carlocaione
carlocaione previously approved these changes Sep 19, 2023
@@ -0,0 +1,12 @@
# Andestech ATCDMAC300 configuration options
# Copyright (c) 2021 Andes Technology Corporation.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2023

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh! Thank you for the reminder, and I'm sorry I overlooked it.

return -EINVAL;
}

key = k_spin_lock(&data->chan[channel].lock);
Copy link
Collaborator

@teburd teburd Sep 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a particular reason to have a per channel spin lock? The semantics of DMA in Zephyr are predominantly single owner, as in a single owner is responsible for each channel so no locking is needed.

If you need to have share a channel among call contexts its up to the caller to provide synchronization.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I got it.
We have removed the spin_lock for per channel.
Use the common spin_lock of dma driver to handle the critical section of dma common register of all channels.

Thanks a lot for this request.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like there's still a per channel spin lock in use, has the change been pushed?

* SPDX-License-Identifier: Apache-2.0
*/

#ifndef ZEPHYR_DRIVERS_DMA_ANDES_ATCDMAC300_H_
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there going to be other variants of this dma controller implemented? If not then the header file contents could be placed in the .c file directly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, there will only be this implemented.
We have update the source code to integrate them.

Thanks a lot.

#define DMA_CH_CTRL_DSTREQ_MASK (0x0F << DMA_CH_CTRL_DSTREQ_POS)
#define DMA_CH_CTRL_DSTREQ(n) \
(((n) << DMA_CH_CTRL_DSTREQ_POS) & DMA_CH_CTRL_DSTREQ_MASK)
#define DMA_CH_CTRL_INTABT (1 << 3)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BIT() macro could be used in place of these shifts

drivers/dma/dma_andes_atcdmac300.c Outdated Show resolved Hide resolved
return -EINVAL;
}

key = k_spin_lock(&data->chan[channel].lock);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like there's still a per channel spin lock in use, has the change been pushed?

@teburd
Copy link
Collaborator

teburd commented Sep 27, 2023

Looking pretty good! Usage of the FIELD_PREP/FIELD_GET/GENMASK/BIT macros is highly encouraged but not a requirement. The removal of the per channel spin lock to me is.

Support the Andes atcdmac300 dma driver.

Signed-off-by: Kevin Wang <[email protected]>
@kevinwang821020
Copy link
Collaborator Author

@teburd
I am so sorry for that, I lost a commit which is for removing channel spin_lock.
I apologize for the inconvenience.
We have update the source code for it(also handle the FIELD_PREP/FIELD_GET/GENMASK/BIT suggestion)

Thanks a lot.

@kevinwang821020
Copy link
Collaborator Author

kevinwang821020 commented Oct 13, 2023

Sorry for bothering the reviewers, we know that the version 3.5 is about to be released, and we look forward that this source code can be included in this release. Is there any good way to do this or any recommendations?

Thank you.

@fabiobaltieri fabiobaltieri added this to the v3.6.0 milestone Oct 13, 2023
@carlescufi carlescufi merged commit d3a73cd into zephyrproject-rtos:main Oct 20, 2023
19 checks passed
@kevinwang821020 kevinwang821020 deleted the dma_driver branch October 25, 2023 02:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Devicetree Binding PR modifies or adds a Device Tree binding area: DMA Direct Memory Access area: RISCV RISCV Architecture (32-bit & 64-bit)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants