Skip to content

Commit

Permalink
refactor(imsic): update IMSIC drivers
Browse files Browse the repository at this point in the history
- Add get_aplic_data() function to both Aplic Direct and Aplic MSI drivers
- Update Imsic driver to use Aplic driver functions
- Update Imsic initialization to link with Aplic driver
- Modify Aplic Priv header to include get_aplic_data() prototype
  • Loading branch information
HuangBorong committed Feb 21, 2025
1 parent ae8b182 commit 99e2277
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
5 changes: 5 additions & 0 deletions core/drivers/aplic_direct.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,8 @@ void aplic_it_handle(void)
void aplic_dump_state(void)
{
}

void* get_aplic_data(void)
{
return NULL;
}
9 changes: 6 additions & 3 deletions core/drivers/aplic_msi.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
#include <types_ext.h>
#include <util.h>

#define APLIC_DEFAULT_EIID 2

static struct aplic_data aplic_data __nex_bss;

static void aplic_set_target(struct aplic_data *aplic, uint32_t source,
Expand Down Expand Up @@ -86,7 +84,7 @@ static void aplic_op_add(struct itr_chip *chip, size_t it, uint32_t type,
if (aplic_set_source_mode(aplic, it, type))
panic();

aplic_set_target(aplic, it, hartid, 0, APLIC_DEFAULT_EIID);
aplic_set_target(aplic, it, hartid, 0, it);
}

static void aplic_op_enable(struct itr_chip *chip, size_t it)
Expand Down Expand Up @@ -158,3 +156,8 @@ void aplic_it_handle(void)
void aplic_dump_state(void)
{
}

struct aplic_data* get_aplic_data(void)
{
return &aplic_data;
}
8 changes: 7 additions & 1 deletion core/drivers/imsic.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,14 @@ static bool imsic_is_bad_it(struct imsic_data *imsic, size_t it)
}

static void imsic_op_add(struct itr_chip *chip, size_t it,
uint32_t type __unused, uint32_t prio __unused)
uint32_t type, uint32_t prio __unused)
{
struct imsic_data *imsic = container_of(chip, struct imsic_data, chip);

if (imsic_is_bad_it(imsic, it))
panic();

interrupt_configure(&imsic->aplic->chip, it, type, prio);
imsic_it_disable(it);
imsic_it_clear_pending(it);
}
Expand All @@ -181,6 +182,7 @@ static void imsic_op_enable(struct itr_chip *chip, size_t it)
if (imsic_is_bad_it(imsic, it))
panic();

interrupt_enable(&imsic->aplic->chip, it);
imsic_it_enable(it);
}

Expand All @@ -191,6 +193,7 @@ static void imsic_op_disable(struct itr_chip *chip, size_t it)
if (imsic_is_bad_it(imsic, it))
panic();

interrupt_disable(&imsic->aplic->chip, it);
imsic_it_disable(it);
}

Expand All @@ -201,6 +204,7 @@ static void imsic_op_raise_pi(struct itr_chip *chip, size_t it)
if (imsic_is_bad_it(imsic, it))
panic();

interrupt_raise_pi(&imsic->aplic->chip, it);
imsic_it_set_pending(it);
}

Expand Down Expand Up @@ -380,5 +384,7 @@ void imsic_init(paddr_t imsic_base_pa)

imsic_init_per_hart();

imsic->aplic = get_aplic_data();

interrupt_main_init(&imsic->chip);
}
2 changes: 2 additions & 0 deletions core/include/drivers/aplic_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,6 @@ TEE_Result aplic_init_from_device_tree(struct aplic_data *aplic);
TEE_Result aplic_set_source_mode(struct aplic_data *aplic, uint32_t source,
uint32_t type);

struct aplic_data* get_aplic_data(void);

#endif /* __DRIVERS_APLIC_PRIV_H */
2 changes: 2 additions & 0 deletions core/include/drivers/imsic.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#ifndef __DRIVERS_IMSIC_H
#define __DRIVERS_IMSIC_H

#include <drivers/aplic_priv.h>
#include <kernel/interrupt.h>
#include <tee_api_defines.h>
#include <types_ext.h>
Expand All @@ -25,6 +26,7 @@ struct imsic_data {
uint32_t hart_index_bits;
uint32_t group_index_bits;
uint32_t group_index_shift;
struct aplic_data* aplic;
struct itr_chip chip;
};

Expand Down

0 comments on commit 99e2277

Please sign in to comment.