-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[DCD_DWC2][ESP32P4][HS] Added cache synchronization #2877
[DCD_DWC2][ESP32P4][HS] Added cache synchronization #2877
Conversation
a88dd32
to
2a56780
Compare
this is great, give me a bit of time, I am currently in the middle of refactoring dcd dwc2 https://github.com/hathach/tinyusb/tree/enhance-dwc2-dcd though we should name it dcd_dcache_clean/invalidate() https://github.com/hathach/tinyusb/blob/enhance-dwc2-dcd/src/device/dcd.h#L96 as other ports. |
@roma-jam just merged #2881 . It mostly clean up and move thing around without behavioral changes, could you mind updating this PR using latest master. Then I will check this out, I am still open to cache sync. FYI, chipidea hs https://github.com/hathach/tinyusb/blob/master/src/portable/chipidea/ci_hs/dcd_ci_hs.c (device) and ehci (host) are one of those port use dcache sync for imxrt (M7) for dtcm. Maybe you can take a peek at for reference. |
You haven't slept yet ? 🤣 I prefer to use non-cacheable memory since it's clear, less dependant to architecture (like RT1170 core M4 has home made cache) and more error proof. Also much easier to setup without alignment and size constraints. In #2865 I've converted to dcd_ci_hs to use MPU with updated BSP. |
I have just waked up, I have an early trip to visit relative today :). I still prefer to support both, once we got dcache sync work, there will be an CFG option to disble dcache function, user can then configure their own mpu as they prefer. Otherwise we will impose the mpu requirements on user, some may not be trivial for port such as ehci/ohci since it may also need virtual to physical as well since some of them are cpu |
2a56780
to
8af3402
Compare
#endif // DWC2_MEM_CACHE_LINE_SIZE | ||
|
||
CFG_TUD_MEM_SECTION struct { | ||
union { |
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.
This is a manual tweak to protect* memory after the aligned _setup_packet
buffer.
I have doubts, that __attribute__((aligned(x))
protects the memory after non-aligned variable, so I decided to solve it this way. At least there is nothing about that in the GCC doc.
Anyway, suggestions are welcome.
I referred to: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-aligned-variable-attribute
For class buffers (such as mscd cbw
and csw
, cdc epout
and epin
and so on, it is better to optimize in class driver code and different PR, IMHO). But anyway also should be done.
UPD:
*to protect from being vanished during cache sync operation
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.
Yeah, this will be a bit of an headache. gcc attribute alignment only ensure the variale alignement only, its size can be smaler, that would leave rom for other variable/data which can be corrupted when memroy to cache is called. I will try to figure out a way to address this.
@hathach Thanks, I will check the imxrt (M7) code. |
@roma-jam would you giving me the write permission to your fork's branch PR. I have made some updated to the PR to get it compiling and have the DMA somewhat working based on you cach hint. I think the only issue now is the class driver and the m2c that corrupt the data after variable e.g (64-8) after setup when we sync. (these space can be occuiped by other system variable). I think we can introduce an CFG DCACHE LINE SIZE and use that to make sure all buffer (dcd to class driver is place correctly).
|
8af3402
to
b8d31a5
Compare
I have renamed the calls, now they are |
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.
look good, thank you. However, I need to make a wider code to make dcache more generic and also add more CFG to make it easier for user to override it if needed. Since I cannot push to your fork directly, I push the changes to my repo and make an separate PR here #2883. When this is merge, gh is smaert enough to mark this as merged as well.
Hi all, seems that I'm late for the party, I prepared a sum-up of the discussion, I will leave it here if anyone is ever interested in this thread: Summary
|
Not at all, there is on-going follow up for dma (device stack), there will be a host PR afterwards
Yeah, we figure that out, it is similar to arm m7 dtcm, therefore we will follow that model. Note DMA is not enabled by default, it must be explicitly set with
explicit dache clean/invalidate is currently implemented. If user want to use non-cache, can simply override the |
Requirements
On ESP32P4 it is important to synchronize cache and memory during DMA transactions.
To use the DMA feature the following should be done:
.dram1
Thus, the values
CFG_TUSB_MEM_SECTION
andCFG_TUSB_MEM_ALIGN
should be provided, according to the target chip.Description
Added cache synchronization macroses during
xfer
preparation/completion:dsync_c2m(_addr, _size)
- Synchronizing cache to memorydsync_m2c(_addr, _size)
- Synchronizing memory to cacheRelated