Skip to content

Commit

Permalink
core: interrupt: add interrupt_create_handler()
Browse files Browse the repository at this point in the history
Adds interrupt_create_handler() API function in interrupt framework.
The function is to be used with interrupt controls obtained
from the DT with  interrupt_dt_get() interrupt_dt_get_by_index() or
interrupt_dt_get_by_name().

The function differs from legacy interrupt_add_handler() in that
this latter always reconfigure the interrupt while new
interrupt_create_handler() function assumes the interrupt was configured
from interrupt_dt_get() or friends.

Acked-by: Jerome Forissier <[email protected]>
Acked-by: Jens Wiklander <[email protected]>
Signed-off-by: Etienne Carriere <[email protected]>
  • Loading branch information
etienne-lms committed Nov 8, 2023
1 parent 8155c2b commit ae4d363
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
19 changes: 19 additions & 0 deletions core/include/kernel/interrupt.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,25 @@ static inline TEE_Result interrupt_add_handler(struct itr_handler *hdl)
return interrupt_add_configure_handler(hdl, IRQ_TYPE_NONE, 0);
}

/*
* interrupt_create_handler() - Allocate/register an interrupt callback handler
* @itr_chip Interrupt chip obtained from dt_get_interrupt_by_*()
* @itr_num Interrupt number obtained from dt_get_interrupt_by_*()
* @callback Callback handler function
* @priv Private dat to pssa to @callback
* @flags INTERRUPT_FLAGS_* or 0
* @out_hdl Output allocated and registered handler or NULL
*
* This function differs from interrupt_add_handler() in that the
* interrupt is not reconfigured. interrupt_create_handler() expects
* @itr_desc was obtained from a call to dt_get_interrupt_by_index()
* or dt_get_interrupt_by_name(). That call configured the interrupt.
*/
TEE_Result interrupt_create_handler(struct itr_chip *itr_chip, size_t itr_num,
itr_handler_t callback, void *priv,
uint32_t flags,
struct itr_handler **out_hdl);

/*
* interrupt_add_handler_with_chip() - Register an interrupt handler providing
* the interrupt chip reference in specific argument @chip.
Expand Down
46 changes: 43 additions & 3 deletions core/kernel/interrupt.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ TEE_Result interrupt_configure(struct itr_chip *chip, size_t itr_num,
return TEE_SUCCESS;
}

TEE_Result interrupt_add_configure_handler(struct itr_handler *hdl,
uint32_t type, uint32_t prio)
static TEE_Result add_configure_handler(struct itr_handler *hdl,
uint32_t type, uint32_t prio,
bool configure)
{
struct itr_handler *h = NULL;

Expand All @@ -122,13 +123,52 @@ TEE_Result interrupt_add_configure_handler(struct itr_handler *hdl,
}
}

interrupt_configure(hdl->chip, hdl->it, type, prio);
if (configure)
interrupt_configure(hdl->chip, hdl->it, type, prio);

SLIST_INSERT_HEAD(&hdl->chip->handlers, hdl, link);

return TEE_SUCCESS;
}

TEE_Result interrupt_add_configure_handler(struct itr_handler *hdl,
uint32_t type, uint32_t prio)
{
return add_configure_handler(hdl, type, prio, true /* configure */);
}

TEE_Result interrupt_create_handler(struct itr_chip *itr_chip, size_t itr_num,
itr_handler_t callback, void *priv,
uint32_t flags,
struct itr_handler **out_hdl)
{
TEE_Result res = TEE_ERROR_GENERIC;
struct itr_handler *itr_hdl = NULL;

itr_hdl = calloc(1, sizeof(*itr_hdl));
if (!itr_hdl)
return TEE_ERROR_OUT_OF_MEMORY;

*itr_hdl = (struct itr_handler){
.chip = itr_chip,
.it = itr_num,
.flags = flags,
.handler = callback,
.data = priv,
};

res = add_configure_handler(itr_hdl, 0, 0, false /* configure */);
if (res) {
free(itr_hdl);
return res;
}

if (out_hdl)
*out_hdl = itr_hdl;

return TEE_SUCCESS;
}

void interrupt_remove_handler(struct itr_handler *hdl)
{
struct itr_handler *h = NULL;
Expand Down

0 comments on commit ae4d363

Please sign in to comment.