forked from Mirrors/opensbi
lib: utils/timer: Use heap in ACLINT MTIMER driver
Let's use heap allocation in ACLINT MTIMER driver instead of using a fixed size global array. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
This commit is contained in:
@@ -9,44 +9,54 @@
|
|||||||
|
|
||||||
#include <libfdt.h>
|
#include <libfdt.h>
|
||||||
#include <sbi/sbi_error.h>
|
#include <sbi/sbi_error.h>
|
||||||
|
#include <sbi/sbi_heap.h>
|
||||||
|
#include <sbi/sbi_list.h>
|
||||||
#include <sbi_utils/fdt/fdt_helper.h>
|
#include <sbi_utils/fdt/fdt_helper.h>
|
||||||
#include <sbi_utils/timer/fdt_timer.h>
|
#include <sbi_utils/timer/fdt_timer.h>
|
||||||
#include <sbi_utils/timer/aclint_mtimer.h>
|
#include <sbi_utils/timer/aclint_mtimer.h>
|
||||||
|
|
||||||
#define MTIMER_MAX_NR 16
|
|
||||||
|
|
||||||
struct timer_mtimer_quirks {
|
struct timer_mtimer_quirks {
|
||||||
unsigned int mtime_offset;
|
unsigned int mtime_offset;
|
||||||
bool has_64bit_mmio;
|
bool has_64bit_mmio;
|
||||||
bool without_mtime;
|
bool without_mtime;
|
||||||
};
|
};
|
||||||
|
|
||||||
static unsigned long mtimer_count = 0;
|
struct timer_mtimer_node {
|
||||||
static struct aclint_mtimer_data mtimer[MTIMER_MAX_NR];
|
struct sbi_dlist head;
|
||||||
|
struct aclint_mtimer_data data;
|
||||||
|
};
|
||||||
|
static SBI_LIST_HEAD(mtn_list);
|
||||||
|
|
||||||
static struct aclint_mtimer_data *mt_reference = NULL;
|
static struct aclint_mtimer_data *mt_reference = NULL;
|
||||||
|
|
||||||
static int timer_mtimer_cold_init(void *fdt, int nodeoff,
|
static int timer_mtimer_cold_init(void *fdt, int nodeoff,
|
||||||
const struct fdt_match *match)
|
const struct fdt_match *match)
|
||||||
{
|
{
|
||||||
int i, rc;
|
int rc;
|
||||||
unsigned long addr[2], size[2];
|
unsigned long addr[2], size[2];
|
||||||
|
struct timer_mtimer_node *mtn, *n;
|
||||||
struct aclint_mtimer_data *mt;
|
struct aclint_mtimer_data *mt;
|
||||||
|
|
||||||
if (MTIMER_MAX_NR <= mtimer_count)
|
mtn = sbi_zalloc(sizeof(*mtn));
|
||||||
return SBI_ENOSPC;
|
if (!mtn)
|
||||||
mt = &mtimer[mtimer_count];
|
return SBI_ENOMEM;
|
||||||
|
mt = &mtn->data;
|
||||||
|
|
||||||
rc = fdt_parse_aclint_node(fdt, nodeoff, true,
|
rc = fdt_parse_aclint_node(fdt, nodeoff, true,
|
||||||
&addr[0], &size[0], &addr[1], &size[1],
|
&addr[0], &size[0], &addr[1], &size[1],
|
||||||
&mt->first_hartid, &mt->hart_count);
|
&mt->first_hartid, &mt->hart_count);
|
||||||
if (rc)
|
if (rc) {
|
||||||
|
sbi_free(mtn);
|
||||||
return rc;
|
return rc;
|
||||||
|
}
|
||||||
mt->has_64bit_mmio = true;
|
mt->has_64bit_mmio = true;
|
||||||
mt->has_shared_mtime = false;
|
mt->has_shared_mtime = false;
|
||||||
|
|
||||||
rc = fdt_parse_timebase_frequency(fdt, &mt->mtime_freq);
|
rc = fdt_parse_timebase_frequency(fdt, &mt->mtime_freq);
|
||||||
if (rc)
|
if (rc) {
|
||||||
|
sbi_free(mtn);
|
||||||
return rc;
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
if (match->data) { /* SiFive CLINT */
|
if (match->data) { /* SiFive CLINT */
|
||||||
const struct timer_mtimer_quirks *quirks = match->data;
|
const struct timer_mtimer_quirks *quirks = match->data;
|
||||||
@@ -77,8 +87,8 @@ static int timer_mtimer_cold_init(void *fdt, int nodeoff,
|
|||||||
/* Check if MTIMER device has shared MTIME address */
|
/* Check if MTIMER device has shared MTIME address */
|
||||||
if (mt->mtime_size) {
|
if (mt->mtime_size) {
|
||||||
mt->has_shared_mtime = false;
|
mt->has_shared_mtime = false;
|
||||||
for (i = 0; i < mtimer_count; i++) {
|
sbi_list_for_each_entry(n, &mtn_list, head) {
|
||||||
if (mtimer[i].mtime_addr == mt->mtime_addr) {
|
if (n->data.mtime_addr == mt->mtime_addr) {
|
||||||
mt->has_shared_mtime = true;
|
mt->has_shared_mtime = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -90,8 +100,10 @@ static int timer_mtimer_cold_init(void *fdt, int nodeoff,
|
|||||||
|
|
||||||
/* Initialize the MTIMER device */
|
/* Initialize the MTIMER device */
|
||||||
rc = aclint_mtimer_cold_init(mt, mt_reference);
|
rc = aclint_mtimer_cold_init(mt, mt_reference);
|
||||||
if (rc)
|
if (rc) {
|
||||||
|
sbi_free(mtn);
|
||||||
return rc;
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Select first MTIMER device with no associated HARTs as our
|
* Select first MTIMER device with no associated HARTs as our
|
||||||
@@ -106,16 +118,17 @@ static int timer_mtimer_cold_init(void *fdt, int nodeoff,
|
|||||||
* Set reference for already propbed MTIMER devices
|
* Set reference for already propbed MTIMER devices
|
||||||
* with non-shared MTIME
|
* with non-shared MTIME
|
||||||
*/
|
*/
|
||||||
for (i = 0; i < mtimer_count; i++)
|
sbi_list_for_each_entry(n, &mtn_list, head) {
|
||||||
if (!mtimer[i].has_shared_mtime)
|
if (!n->data.has_shared_mtime)
|
||||||
aclint_mtimer_set_reference(&mtimer[i], mt);
|
aclint_mtimer_set_reference(&n->data, mt);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Explicitly sync-up MTIMER devices not associated with any HARTs */
|
/* Explicitly sync-up MTIMER devices not associated with any HARTs */
|
||||||
if (!mt->hart_count)
|
if (!mt->hart_count)
|
||||||
aclint_mtimer_sync(mt);
|
aclint_mtimer_sync(mt);
|
||||||
|
|
||||||
mtimer_count++;
|
sbi_list_add_tail(&mtn->head, &mtn_list);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user