-
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: esp32s3: Add DMA support for esp32s3 #57495
drivers: dma: esp32s3: Add DMA support for esp32s3 #57495
Conversation
f6a437d
to
a45d74a
Compare
tests/drivers/dma/chan_blen_transfer/boards/esp32s3_devkitm.conf
Outdated
Show resolved
Hide resolved
a45d74a
to
0d9ba76
Compare
maybe put files in |
0d9ba76
to
6801041
Compare
@marekmatej done ;) |
6801041
to
edd33a8
Compare
drivers/dma/dma_esp32_gdma.c
Outdated
static int dma_esp32_config_rx_descriptor(struct dma_esp32_channel *dma_channel, | ||
struct dma_block_config *block) | ||
{ | ||
memset(&dma_channel->desc, 0, sizeof(dma_channel->desc)); | ||
dma_channel->desc.buffer = (void *)block->dest_address; | ||
dma_channel->buf_original = (uint8_t *)block->dest_address; | ||
k_free(dma_channel->buf_temp); |
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.
You are freeing buf_temp
which is allocated in the dma_esp32_config_tx_descriptor
. Why cannot it be allocated for the driver lifetime?
@@ -577,7 +624,7 @@ DMA_ESP32_DEFINE_IRQ_HANDLER(4) | |||
}, \ | |||
}; \ | |||
\ | |||
DEVICE_DT_INST_DEFINE(idx, &dma_esp32_init, NULL, &dma_data_##idx, &dma_config_##idx, \ | |||
DEVICE_DT_INST_DEFINE(idx, &dma_esp32_init, NULL, &dma_data_##idx, &dma_config_##idx, \ |
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.
you add trailing space
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 think the tx_descriptor
func. needs to free the buf_temp
too
edd33a8
to
c54a1c6
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.
I missed that the heap is still being used here
static int dma_esp32_config_rx_descriptor(struct dma_esp32_channel *dma_channel, | ||
struct dma_block_config *block) | ||
{ | ||
memset(&dma_channel->desc, 0, sizeof(dma_channel->desc)); | ||
dma_channel->desc.buffer = (void *)block->dest_address; | ||
dma_channel->buf_original = (uint8_t *)block->dest_address; | ||
k_free(dma_channel->buf_temp); | ||
dma_channel->buf_temp = NULL; | ||
if (!esp_ptr_dma_capable((uint32_t *)block->dest_address)) { |
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 are we trying to allocate on behalf of callers here, if an invalid buffer for DMA is being provided this seems like a bug that should be asserted on.
I'm a little confused by the code here to malloc/free a temporary buffer when that's not the case. Is there a particular scenario esp32 expects this to occur?
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 are freeing the channel's temporary buffer every time a new descriptor needs to be created. In case the original buffer is in a valid DMA region, the k_free
can handle a NULL pointer without issue and no allocation is needed. In case it is in an invalid region, we create a temporary one to handle the transactions, freeing it and reallocating according the size required by the transactions. I'm trying to deal with both scenarios here, since the original buffer location depends on the application or driver using it.
Did I answer your question? I'm not shure haha
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 guess what I'm suggesting is this is a bug then in the driver or application that should be caught. There's an RFC for managing buffers #57602
At the moment this would be, to my best knowledge, the only DMA driver that attempts to fix the buffer you asked a copy to by allocating from the heap. I would suggest pushing that issue up the stack as this is a surprising place to have that happen.
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 nice! I will follow up this RFC and contribute in whatever way I can. But since it is an ongoing discussion, should we block the merge of this commit? This strategy of dealing with buffer is around for quite a while, this commit only add support for esp32s3 and small fixes.
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'd point out that generally Zephyr is trying to follow misra, and in misra-c "dynamic allocation is not allowed" See our guidelines https://docs.zephyrproject.org/latest/contribute/coding_guidelines/index.html#main-rules
So I think this is something that needs to be revisited but today should be considered a programming error trying to ask DMA to work with a buffer that doesn't conform to DMA requirements.
Add GDMA support for esp32s3. Remove suspend/resume since they are optional and do the same as start/stop. Fix possible null pointer derreference. Signed-off-by: Lucas Tamborrino <[email protected]>
c54a1c6
to
0728128
Compare
According to the coding guidelines "dynamic allocation is not allowed". This commit removes handling invalid DMA capable buffers by allocating temporary buffer in a valid memory region, considering them as errors. Signed-off-by: Lucas Tamborrino <[email protected]>
Add esp32s3 overlays for dma tests. Signed-off-by: Lucas Tamborrino <[email protected]>
0728128
to
4ecb7b2
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.
LGTM
Add GDMA support for esp32s3.
Remove suspend/resume since they are optional and do the same as start/stop.
Fix possible null pointer derreference.