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

dma: Add support for DMA API: IRQ+assign/startup part #44

Merged
merged 8 commits into from
Sep 30, 2024

Conversation

pthierry-ledger
Copy link
Member

@pthierry-ledger pthierry-ledger commented Sep 18, 2024

  • Add UAPI part of DMA syscalls
  • implement support for IRQ to stream owner DMA manager API
  • Update or fix any of the manager-level dependencies for DMA gate
  • make syscall LUT pointing invalid while gate not written
  • Validate and complete if needed autotest-based DMA checks, ensure tests results for both successflul and failures

Note: missing DMA features:

  • DMA gate implementation
  • DMA get_info support at manager level
  • DMA termination (stop/unassign) related manager implementation

Note2: this PR do not impact in any way the kernel behavior for any of the other usages than DMA. autotest must pass for all tests except DMA ones

@pthierry-ledger pthierry-ledger marked this pull request as draft September 18, 2024 09:24
@pthierry-ledger pthierry-ledger added api impact the external API of the component documentation Improvements or additions to documentation test test or test suite related labels Sep 18, 2024
@pthierry-ledger pthierry-ledger removed the documentation Improvements or additions to documentation label Sep 24, 2024
@pthierry-ledger pthierry-ledger added this to the Sentry-v0.3.0 milestone Sep 24, 2024
@pthierry-ledger pthierry-ledger marked this pull request as ready for review September 24, 2024 12:24
@pthierry-ledger pthierry-ledger changed the title dma: Add support for DMA API dma: Add support for DMA API: IRQ+assign/startup part Sep 24, 2024
Copy link
Contributor

@iartemov-ledger iartemov-ledger left a comment

Choose a reason for hiding this comment

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

A couple of comments so far ...

uapi/include/uapi/uapi.h Show resolved Hide resolved
kernel/src/drivers/dma/stm32-gpdma-dt.c.in Outdated Show resolved Hide resolved
@pthierry-ledger pthierry-ledger merged commit b8ee53a into outpost-os:main Sep 30, 2024
37 checks passed
pthierry-ledger added a commit that referenced this pull request Oct 1, 2024
As defined in DMA wiki, adding a new event queue specific to DMA streams
vents.
As DMA streams events are specific, consolidated, events types, they
should be pushed up to userspace tasks as such, instead of pushing bare
IRQn.
Bare IRQn are useless to userspace, as DMA IRQ acknowledge is under the
kernel control. Instead pushing consolidated event is useful for user
task, as they can directly manipulate such event for functional
implementation.

A DMA event is then received as a specific event of the
`wait_for_event()` syscall. In that case, the event received looks like
the following tuple:
```
typedef enum dma_chan_state {
    GPDMA_STATE_IDLE                    = 1, /**< DMA channel idle (not set or unused) */
    GPDMA_STATE_RUNNING                 = 2, /**< DMA channel is running */
    GPDMA_STATE_ABORTED                 = 3, /**< DMA stream aborted on SW request */
    GPDMA_STATE_SUSPENDED               = 4, /**< DMA stream suspended on SW request*/
    GPDMA_STATE_TRANSMISSION_FAILURE    = 5, /**< DMA transmission failure */
    GPDMA_STATE_CONFIGURATION_FAILURE   = 6, /**< DMA channel configuration failure */
    GPDMA_STATE_OVERRUN                 = 7, /**< DMA transmission overrun */
    GPDMA_STATE_TRANSFER_COMPLETE       = 8, /**< DMA transfer complete for this channel */
    GPDMA_STATE_HALF_TRANSFER           = 9, /**< DMA transfer half-complete for this channel */
} dma_chan_state_t;

{ dma_handle, dma_event_state }
```
This tuple allows to directly associate the handle with a userspace
context, and the DMA event type used to react to various events as
required.

The DMA event structure pushed by the kernel is the following,
respecting the exchange_event_t standard Sentry header:

```c
{
    header.type = EVENT_TYPE_DMA, 
    header.length = 1, /* 1 data byte: the DMA event type */
    header.magic = 0x4242, /* hardcoded by now */
    header.source = dma_stream_handle,
    header.data[0] = dma_stream_event;  
}
```

This allows such a usage:

```c
uint8_t dma_event_buf[sizeof(exchange_event_t)+sizeof(uint8_t)];

sys_dma_start(dmah);
if (sys_wait_for_event(EVENT_TYPE_DMA, WAIT_FOREVER) == STATUS_OKAY) {
     copy_to_user(dma_event_buf, sizeof(exchange_event_t)+sizeof(uint8_t));

    /* manipulate dma event info locally */
    exchange_event_t *event = &dma_event_buf[0];
    printf("dma event %d, from handle %lx\n", event->data[0], event->source);
    switch (event->data[0]) {
      case GPDMA_STATE_TRANSMISSION_FAILURE:
        //
      case GPDMA_STATE_USER_FAILURE:
       //
      case GPDMA_STATE_TRANSFER_COMPLETE:
       //
    }
}
```

- [x] push DMA event type to uapi types.h header
- [x] add support for DMA event queue in task context
- [x] add support for DMA event queue push interface
- [x] make DMA IRQn handler pushing the event to the corresponding
stream owner
- [x] Add DMA event to the `wait_for_event()` events list
- [x] add support for DMA event pull interface from task context
- [x] add support for DMA event at `wait_for_event()` syscall level
- [x] update autotest to support this new API

depends on #44 
closes #60
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api impact the external API of the component test test or test suite related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants