-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
drivers: dma: Add Andestech atcdmac300 driver. #59041
Conversation
ba8c995
to
7cd16d0
Compare
drivers/dma/dma_andes_atcdmac300.c
Outdated
|
||
cfg_blocks = cfg->head_block; | ||
if (cfg_blocks == NULL) { | ||
return -EINVAL; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
7cd16d0
to
089f9e6
Compare
089f9e6
to
2504e44
Compare
There was a problem hiding this 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?
drivers/dma/dma_andes_atcdmac300.h
Outdated
#define DMA_INT_STATUS_CH_MSK(ch) (0x111 << ch) | ||
|
||
#define INWORD(x) sys_read32(x) | ||
#define OUTWORD(x, d) sys_write32(d, x) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why redefine these?
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
My points were addressed, but not sure I can approve the whole PR.
There was a problem hiding this 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
drivers/dma/dma_andes_atcdmac300.c
Outdated
#include <zephyr/logging/log.h> | ||
LOG_MODULE_REGISTER(dma_andes_atcdmac300); | ||
|
||
K_HEAP_DEFINE(dma_chain, 1024); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
2504e44
to
4a03e25
Compare
drivers/dma/dma_andes_atcdmac300.h
Outdated
#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)) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
drivers/dma/dma_andes_atcdmac300.h
Outdated
#define DEV_CFG(dev) ((const struct dma_atcdmac300_cfg * const) (dev)->config) | ||
#define DEV_DATA(dev) ((struct dma_atcdmac300_data *) (dev)->data) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
drivers/dma/dma_andes_atcdmac300.h
Outdated
#define INWORD(x) sys_read32(x) | ||
#define OUTWORD(x, d) sys_write32(d, x) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
7400e52
to
6d35786
Compare
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. |
There was a problem hiding this 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.
6d35786
to
75aa78f
Compare
2b06fad
to
604b79b
Compare
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. |
That was recently fixed. Please rebase. |
604b79b
to
dd41701
Compare
drivers/dma/Kconfig.andes_atcdmac300
Outdated
@@ -0,0 +1,12 @@ | |||
# Andestech ATCDMAC300 configuration options | |||
# Copyright (c) 2021 Andes Technology Corporation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2023
There was a problem hiding this comment.
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.
drivers/dma/dma_andes_atcdmac300.c
Outdated
return -EINVAL; | ||
} | ||
|
||
key = k_spin_lock(&data->chan[channel].lock); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
drivers/dma/dma_andes_atcdmac300.h
Outdated
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#ifndef ZEPHYR_DRIVERS_DMA_ANDES_ATCDMAC300_H_ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
ed0abac
to
1499096
Compare
drivers/dma/dma_andes_atcdmac300.c
Outdated
#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) |
There was a problem hiding this comment.
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
return -EINVAL; | ||
} | ||
|
||
key = k_spin_lock(&data->chan[channel].lock); |
There was a problem hiding this comment.
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?
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]>
1499096
to
adf1c43
Compare
@teburd Thanks a lot. |
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. |
Support the Andes atcdmac300 dma driver.
Also add the dma property in spi node.