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: building exchange api #58

Merged
merged 14 commits into from
Oct 1, 2024

Conversation

pthierry-ledger
Copy link
Member

@pthierry-ledger pthierry-ledger commented Sep 30, 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:

{
    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:

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:
       //
    }
}
  • push DMA event type to uapi types.h header
  • add support for DMA event queue in task context
  • add support for DMA event queue push interface
  • make DMA IRQn handler pushing the event to the corresponding stream owner
  • Add DMA event to the wait_for_event() events list
  • add support for DMA event pull interface from task context
  • add support for DMA event at wait_for_event() syscall level
  • update autotest to support this new API

depends on #44
closes #60

@pthierry-ledger pthierry-ledger marked this pull request as draft September 30, 2024 08:09
@pthierry-ledger pthierry-ledger requested review from iartemov-ledger and fvalette-ledger and removed request for iartemov-ledger September 30, 2024 08:10
@pthierry-ledger pthierry-ledger added api impact the external API of the component feature New feature added test test or test suite related labels Sep 30, 2024
@pthierry-ledger pthierry-ledger added this to the Sentry-v0.3.0 milestone Sep 30, 2024
@pthierry-ledger pthierry-ledger changed the title DMA: building exchange api dma: building exchange api Sep 30, 2024
@pthierry-ledger pthierry-ledger marked this pull request as ready for review September 30, 2024 13:59
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.

1st pass

update autotest to support this new API

I didn't find the auto-test update.

kernel/src/drivers/usart/stm32-lpuart.c Show resolved Hide resolved
kernel/src/managers/task/task_core.c Outdated Show resolved Hide resolved
uapi/include/uapi/types.h Show resolved Hide resolved
kernel/src/managers/task/task_core.c Outdated Show resolved Hide resolved
kernel/src/managers/task/task_core.c Outdated Show resolved Hide resolved
kernel/src/managers/task/task_core.c Outdated Show resolved Hide resolved
kernel/src/managers/task/task_core.h Show resolved Hide resolved
@pthierry-ledger
Copy link
Member Author

I didn't find the auto-test update.

Hem yes 👍 I havent pushed that last commit :) done now.

@pthierry-ledger pthierry-ledger merged commit 76bf28b into outpost-os:main Oct 1, 2024
37 checks passed
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 feature New feature added test test or test suite related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dma: using consolidated events instead of IRQn
3 participants