Interrupts

API for registering and manipulating interrupts.

Defines

for_each_metal_affinity(bit, metal_affinity)
metal_affinity_set_val(metal_affinity, val)
metal_affinity_set_bit(metal_affinity, bit, val)

Typedefs

typedef enum metal_interrupt_controller_ metal_intr_cntrl_type

Possible interrupt controllers.

typedef enum metal_vector_mode_ metal_vector_mode

Possible mode of interrupts to operate.

typedef enum metal_intr_priv_mode_ metal_intr_priv_mode

Possible mode of privilege interrupts to operate.

typedef struct metal_affinity_ metal_affinity

The bitmask of hart context.

typedef void (*metal_interrupt_handler_t)(int, void*)

Function signature for interrupt callback handlers.

typedef void (*metal_interrupt_vector_handler_t)(void)

Enums

enum metal_interrupt_controller_

Possible interrupt controllers.

Values:

enumerator METAL_CPU_CONTROLLER
enumerator METAL_CLINT_CONTROLLER
enumerator METAL_CLIC_CONTROLLER
enumerator METAL_PLIC_CONTROLLER
enum metal_vector_mode_

Possible mode of interrupts to operate.

Values:

enumerator METAL_DIRECT_MODE
enumerator METAL_VECTOR_MODE
enumerator METAL_SELECTIVE_NONVECTOR_MODE
enumerator METAL_SELECTIVE_VECTOR_MODE
enumerator METAL_HARDWARE_VECTOR_MODE
enum metal_intr_priv_mode_

Possible mode of privilege interrupts to operate.

Values:

enumerator METAL_INTR_PRIV_M_MODE
enumerator METAL_INTR_PRIV_MU_MODE
enumerator METAL_INTR_PRIV_MSU_MODE

Functions

__inline__ void metal_interrupt_init(struct metal_interrupt *controller)

Initialize a given interrupt controller.

Initialize a given interrupt controller. This function must be called before any interrupts are registered or enabled with the handler. It is invalid to initialize an interrupt controller more than once.

Parameters
  • controller: The handle for the interrupt controller

struct metal_interrupt *metal_interrupt_get_controller(metal_intr_cntrl_type cntrl, int id)

Get the handle for an given interrupt controller type.

Return

A handle to the interrupt controller (CLINT, CLIC, PLIC), or NULL if none is found for the requested label

Parameters
  • cntrl: The type ofinterrupt controller

  • id: The instance of the interrupt controller

__inline__ int metal_interrupt_set_vector_mode(struct metal_interrupt *controller, metal_vector_mode mode)

Configure vector mode for an interrupt controller.

Configure vector mode for an interrupt controller. This function must be called after initialization and before configuring individual interrupts, registering ISR.

Return

0 upon success

Parameters
  • controller: The handle for the interrupt controller

  • mode: The vector mode of the interrupt controller.

__inline__ metal_vector_mode metal_interrupt_get_vector_mode(struct metal_interrupt *controller)

Get vector mode of a given an interrupt controller.

Configure vector mode for an interrupt controller. This function must be called after initialization and before configuring individual interrupts, registering ISR.

Return

The interrupt vector mode

Parameters
  • controller: The handle for the interrupt controller

  • mode: The vector mode of the interrupt controller.

__inline__ int metal_interrupt_set_privilege(struct metal_interrupt *controller, metal_intr_priv_mode privilege)

Configure privilege mode a of given interrupt controller.

Configure privilege mode for a given interrupt controller. This function must be called after initialization and before configuring individual interrupts, registering ISR.

Return

0 upon success

Parameters
  • controller: The handle for the interrupt controller

  • privilege: The privilege mode of the interrupt controller.

__inline__ metal_intr_priv_mode metal_interrupt_get_privilege(struct metal_interrupt *controller)

Get privilege mode a of given interrupt controller.

Get privilege mode for a given interrupt controller. This function must be called after initialization and before configuring individual interrupts, registering ISR.

Return

The interrupt privilege mode

Parameters
  • controller: The handle for the interrupt controller

__inline__ int metal_interrupt_clear(struct metal_interrupt *controller, int id)

clear an interrupt

Return

0 upon success

Parameters
  • controller: The handle for the interrupt controller

  • id: The interrupt ID to trigger

__inline__ int metal_interrupt_set(struct metal_interrupt *controller, int id)

Set an interrupt.

Return

0 upon success

Parameters
  • controller: The handle for the interrupt controller

  • id: The interrupt ID to trigger

__inline__ int metal_interrupt_register_handler(struct metal_interrupt *controller, int id, metal_interrupt_handler_t handler, void *priv_data)

Register an interrupt handler.

Return

0 upon success

Parameters
  • controller: The handle for the interrupt controller

  • id: The interrupt ID to register

  • handler: The interrupt handler callback

  • priv_data: Private data for the interrupt handler

__inline__ int metal_interrupt_register_vector_handler(struct metal_interrupt *controller, int id, metal_interrupt_vector_handler_t handler, void *priv_data)

Register an interrupt vector handler.

Return

0 upon success

Parameters
  • controller: The handle for the interrupt controller

  • id: The interrupt ID to register

  • handler: The interrupt vector handler callback

  • priv_data: Private data for the interrupt handler

__inline__ int metal_interrupt_enable(struct metal_interrupt *controller, int id)

Enable an interrupt.

Return

0 upon success

Parameters
  • controller: The handle for the interrupt controller

  • id: The interrupt ID to enable

__inline__ int metal_interrupt_disable(struct metal_interrupt *controller, int id)

Disable an interrupt.

Return

0 upon success

Parameters
  • controller: The handle for the interrupt controller

  • id: The interrupt ID to disable

__inline__ int metal_interrupt_set_threshold(struct metal_interrupt *controller, unsigned int level)

Set interrupt threshold level.

Return

0 upon success

Parameters
  • controller: The handle for the interrupt controller

  • threshold: The interrupt threshold level

__inline__ unsigned int metal_interrupt_get_threshold(struct metal_interrupt *controller)

Get an interrupt threshold level.

Return

The interrupt threshold level

Parameters
  • controller: The handle for the interrupt controller

__inline__ int metal_interrupt_set_priority(struct metal_interrupt *controller, int id, unsigned int priority)

Set an interrupt priority level.

Return

0 upon success

Parameters
  • controller: The handle for the interrupt controller

  • id: The interrupt ID to enable

  • priority: The interrupt priority level

__inline__ unsigned int metal_interrupt_get_priority(struct metal_interrupt *controller, int id)

Get an interrupt priority level.

Return

The interrupt priority level

Parameters
  • controller: The handle for the interrupt controller

  • id: The interrupt ID to enable

__inline__ int metal_interrupt_set_preemptive_level(struct metal_interrupt *controller, int id, unsigned int level)

Set preemptive level and priority for a given interrupt ID.

Set the preemptive level and priority for a given interrupt ID.

Return

0 upon success

Parameters
  • controller: The handle for the interrupt controller

  • id: The interrupt ID to enable

  • level: The interrupt level and priority are encoded together

__inline__ unsigned int metal_interrupt_get_preemptive_level(struct metal_interrupt *controller, int id)

Get an interrupt preemptive level.

Return

The interrupt level

Parameters
  • controller: The handle for the interrupt controller

  • id: The interrupt ID to enable

__inline__ int metal_interrupt_vector_enable(struct metal_interrupt *controller, int id)

Enable an interrupt vector.

Return

0 upon success

Parameters
  • controller: The handle for the interrupt controller

  • id: The interrupt ID to enable

__inline__ int metal_interrupt_vector_disable(struct metal_interrupt *controller, int id)

Disable an interrupt vector.

Return

0 upon success

Parameters
  • controller: The handle for the interrupt controller

  • id: The interrupt ID to disable

__inline__ metal_affinity metal_interrupt_affinity_enable(struct metal_interrupt *controller, metal_affinity bitmask, int id)

Enable an interrupt for the hart contexts.

Return

The result of each hart context. 0 upon success at relevant bit.

Parameters
  • controller: The handle for the interrupt controller

  • bitmask: The bit mask of hart contexts to enable

  • id: The interrupt ID to enable

__inline__ metal_affinity metal_interrupt_affinity_disable(struct metal_interrupt *controller, metal_affinity bitmask, int id)

Disable an interrupt for the hart contexts.

Return

The result of each hart context. 0 upon success at relevant bit.

Parameters
  • controller: The handle for the interrupt controller

  • bitmask: The bit mask of hart contexts to disable

  • id: The interrupt ID to disable

__inline__ metal_affinity metal_interrupt_affinity_set_threshold(struct metal_interrupt *controller, metal_affinity bitmask, unsigned int level)

Set interrupt threshold level for the hart contexts.

Return

The result of each hart context. 0 upon success at relevant bit.

Parameters
  • controller: The handle for the interrupt controller

  • bitmask: The bit mask of hart contexts to set threshold

  • threshold: The interrupt threshold level

__inline__ unsigned int metal_interrupt_affinity_get_threshold(struct metal_interrupt *controller, int context_id)

Get an interrupt threshold level from the hart context.

Return

The interrupt threshold level

Parameters
  • controller: The handle for the interrupt controller

  • context_id: The hart context ID to get threshold

struct metal_affinity_
#include <interrupt.h>

The bitmask of hart context.

Public Members

unsigned long bitmask
struct metal_interrupt
#include <interrupt.h>

A handle for an interrupt.