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 dma_emul driver and test coverage #58375

Merged

Conversation

cfriedt
Copy link
Member

@cfriedt cfriedt commented May 28, 2023

4 commits (please see each commit message for details)

  • dts: bindings: dma: add bindings for an emulated dma controller
  • drivers: dma: add emulated dma driver
  • boards: posix: add dma support to native_posix boards
  • tests: drivers: dma: test dma_emul driver on native_posix boards

It's pretty basic right now, but the intention is to support interfaces other than simple memcpy() via a backend API. With that, we should be able to use e.g. TCP or UDP sockets, shared memory, etc.

Additionally, some drivers (such as PCIe) often depend on DMA to be present, so this has the potential to open up ZTest to areas that have traditionally not been very testable. This could, for example, pair pretty well with the recent NVMe API.

Fixes #57129

@cfriedt cfriedt requested review from teburd and jgl-meta May 28, 2023 16:47
@zephyrbot zephyrbot added area: Devicetree Binding PR modifies or adds a Device Tree binding area: DMA Direct Memory Access area: native port Host native arch port (native_posix) labels May 28, 2023
@cfriedt cfriedt force-pushed the issues/57129/drivers-dma-emul-driver branch from 88c8907 to 95fb399 Compare May 28, 2023 16:48
@cfriedt cfriedt added the area: Tests Issues related to a particular existing or missing test label May 28, 2023
@cfriedt cfriedt requested review from mgielda and pgielda May 28, 2023 16:50
@cfriedt cfriedt force-pushed the issues/57129/drivers-dma-emul-driver branch from 95fb399 to ffcd5fb Compare May 28, 2023 16:54
@cfriedt
Copy link
Member Author

cfriedt commented May 28, 2023

  • rebased to fix merge conflict
  • added license to drivers/dma/dma_emul.c

@cfriedt cfriedt force-pushed the issues/57129/drivers-dma-emul-driver branch from ffcd5fb to 5886891 Compare May 28, 2023 16:56
@cfriedt
Copy link
Member Author

cfriedt commented May 28, 2023

  • use CONFIG_DMA_LOG_LEVEL

@cfriedt
Copy link
Member Author

cfriedt commented May 28, 2023

I anticipate a few rounds to figure out any loose ends with the implementation. Additionally, I may have found a couple of gaps here and there with the current DMA API and testsuite that could be closed.

@cfriedt cfriedt force-pushed the issues/57129/drivers-dma-emul-driver branch 2 times, most recently from 2dcfaff to 4d462aa Compare May 28, 2023 21:59
@cfriedt
Copy link
Member Author

cfriedt commented May 28, 2023

  • disabled native_posix* for scatter_gather test
  • added missing dma-channels = <2> to native_posix.overlay

@cfriedt cfriedt force-pushed the issues/57129/drivers-dma-emul-driver branch 2 times, most recently from abfcc29 to b1a01d8 Compare May 29, 2023 11:47
@cfriedt
Copy link
Member Author

cfriedt commented May 29, 2023

  • increased dma-channels to 4 for scatter_gather tests
  • additional checks in dma_emul_config_valid() to verify availability of slots for chained transfers

@cfriedt cfriedt force-pushed the issues/57129/drivers-dma-emul-driver branch from b1a01d8 to 9ec357b Compare May 29, 2023 11:49
@cfriedt
Copy link
Member Author

cfriedt commented Jul 21, 2023

@teburd - thanks for taking another look.

In looking this over I think its pretty reasonable. It's in effect a software DMA controller.

Yes, exactly. There will be some flexibility in terms of backends and some customizable behaviour to an extent too.

how does DMA interact with a SPI peripheral? This varies wildly from what I've seen.

That's a good question, and to be honest, not one that I've considered yet, but definitely agree that it varies wildly.

It might be easiest to tackle specific peripherals / interconnects on a case-by-case basis. SPI is on the radar, but my MVP in the next while will be PCIe DMA (host to device, device to host, memory to memory), and I would be looking to emulate something close to the "edu" device in Qemu. It was touched upon in Zephyr here, with additional info here and here.

The "edu" device mainly has a host-side specification, so there is some flexibility for device-side (where Zephyr would mainly be "running").

It will be a fair bit of work to get there, but we will have additional collaboration within the community (I added a bunch of AntMicro folks to review very deliberately 😁, cc @mgielda)

@cfriedt
Copy link
Member Author

cfriedt commented Sep 12, 2023

I'll rebase this just to make sure it gets back into a mergeable state. We may be able to begin working on it in the near term again.

@cfriedt
Copy link
Member Author

cfriedt commented Oct 4, 2023

  • rebased

@cfriedt cfriedt force-pushed the issues/57129/drivers-dma-emul-driver branch from c11652a to 0865979 Compare October 4, 2023 15:23
@MaureenHelm
Copy link
Member

Needs a rebase

@cfriedt cfriedt force-pushed the issues/57129/drivers-dma-emul-driver branch from 0865979 to c412e77 Compare November 14, 2023 16:25
@cfriedt
Copy link
Member Author

cfriedt commented Nov 14, 2023

Screenshot 2023-11-14 at 11 27 06 AM

@cfriedt cfriedt force-pushed the issues/57129/drivers-dma-emul-driver branch from c412e77 to f358a23 Compare November 20, 2023 18:03
@cfriedt
Copy link
Member Author

cfriedt commented Nov 20, 2023

rebased again

@teburd
Copy link
Collaborator

teburd commented Nov 20, 2023

I think I've covered the topic of how the DMA API isn't necessarily meant to be a common behavioral abstraction but a union of functionality in the DMA API docs now, so approving

teburd
teburd previously approved these changes Nov 20, 2023
Many driver APIs are opting to provide an `emul` driver
implementation that can be used for a number of purposes.

- providing an ideal / model driver for reference
- configurable backends
- seamless integration with device tree
- support for native posix, qemu, and any other board
- fast regression testing of app and library code

Provide an initial set of bindings for `zephyr,dma-emul` devices.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
@cfriedt
Copy link
Member Author

cfriedt commented Nov 30, 2023

  • fixed merge conflicts

@teburd - can you please re-ack?

drivers/dma/dma_emul.c Outdated Show resolved Hide resolved
teburd
teburd previously approved these changes Dec 1, 2023
Add an emulated DMA driver. Emulation drivers are great to have
for each driver API for multiple reasons:

- providing an ideal / model driver for reference
- potential for configurable backend support
- seamless integration with device tree
- multi-instance, etc, for all supported boards
- fast regression testing of app and library code

Since many other drivers and lbraries depend on DMA, this might
help us to increase test coverage.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Like other driver APIs, we can add an `emul` variant to
`native_posix` and `native_posix_64` that should allow us to
simplify applilcation and library development and to also
increase test coverage in CI.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
Add support for testing the `dma_emul` driver which simply uses
software emulation (i.e. asynchronous memcpy in a workqueue) for
performing DMA operations.

Signed-off-by: Christopher Friedt <cfriedt@meta.com>
@cfriedt
Copy link
Member Author

cfriedt commented Dec 1, 2023

  • renamed reserved to _reserved

@cfriedt cfriedt requested review from ycsin and teburd December 1, 2023 17:32
@cfriedt
Copy link
Member Author

cfriedt commented Dec 3, 2023

@teburd - should be good to go now if you have a moment. Minor correction necessary found by @ycsin

@cfriedt cfriedt merged commit 88425fe into zephyrproject-rtos:main Dec 4, 2023
25 checks passed
@cfriedt cfriedt deleted the issues/57129/drivers-dma-emul-driver branch December 4, 2023 00:22
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: native port Host native arch port (native_posix) area: Tests Issues related to a particular existing or missing test
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

drivers: dma: emul driver
5 participants