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

elfloader: Add generic-timer driver #168

Merged
merged 6 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions elfloader-tool/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,22 @@ elseif(KernelSel4ArchAarch32)
add_compile_options(-mno-unaligned-access)
endif()

if(KernelArchARM)
# Only the Arm arch uses extension drivers.
set(
driver_file_globs
src/drivers/*.c
src/drivers/smp/*.c
src/drivers/uart/*.c
src/drivers/timer/*.c
)
endif()

file(
GLOB
files
src/*.c
src/drivers/*.c
src/drivers/smp/*.c
src/drivers/uart/*.c
${driver_file_globs}
src/utils/*.c
src/arch-${KernelArch}/*.c
src/arch-${KernelArch}/*.S
Expand Down
1 change: 1 addition & 0 deletions elfloader-tool/include/drivers.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
#pragma once

int initialise_devices(void);
int initialise_devices_non_boot(void);
2 changes: 2 additions & 0 deletions elfloader-tool/include/drivers/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ enum driver_type {
DRIVER_INVALID = 0,
DRIVER_SMP,
DRIVER_UART,
DRIVER_TIMER,
DRIVER_MAX
};

struct elfloader_driver {
const struct dtb_match_table *match_table;
enum driver_type type;
driver_init_t init;
driver_init_t init_on_secondary_cores;
/* ops struct, type depends on driver type. */
const void *ops;
};
Expand Down
10 changes: 6 additions & 4 deletions elfloader-tool/src/arch-arm/smp_boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <autoconf.h>
#include <elfloader/gen_config.h>
#include <devices_gen.h>
#include <drivers.h>
#include <drivers/smp.h>

#include <printf.h>
Expand All @@ -25,8 +26,6 @@ void arm_disable_dcaches(void);
extern void const *dtb;
extern uint32_t dtb_size;

WEAK void non_boot_init(void) {}

/* Entry point for all CPUs other than the initial. */
void non_boot_main(void)
{
Expand All @@ -40,8 +39,11 @@ void non_boot_main(void)
#endif
}

/* Initialise any platform-specific per-core state */
non_boot_init();
/* Do any driver specific non_boot core init */
if (initialise_devices_non_boot()) {
printf("ERROR: Did not successfully return from initialise_devices_non_boot()\n");
abort();
}

#ifndef CONFIG_ARM_HYPERVISOR_SUPPORT
if (is_hyp_mode()) {
Expand Down
11 changes: 9 additions & 2 deletions elfloader-tool/src/arch-arm/sys_boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ void main(UNUSED void *arg)
void *bootloader_dtb = NULL;

/* initialize platform to a state where we can print to a UART */
initialise_devices();
if (initialise_devices()) {
printf("ERROR: Did not successfully return from initialise_devices()\n");
abort();
}

platform_init();

/* Print welcome message. */
Expand Down Expand Up @@ -175,7 +179,10 @@ void continue_boot(int was_relocated)
* driver model so all its pointers are set up properly.
*/
if (was_relocated) {
initialise_devices();
if (initialise_devices()) {
printf("ERROR: Did not successfully return from initialise_devices()\n");
abort();
}
}

#if (defined(CONFIG_ARCH_ARM_V7A) || defined(CONFIG_ARCH_ARM_V8A)) && !defined(CONFIG_ARM_HYPERVISOR_SUPPORT)
Expand Down
37 changes: 36 additions & 1 deletion elfloader-tool/src/drivers/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ static int init_device(struct elfloader_device *dev)
int ret = table_has_match(dev->compat, drv->match_table);
if (ret >= 0) {
dev->drv = drv;
drv->init(dev, drv->match_table[ret].match_data);
ret = drv->init(dev, drv->match_table[ret].match_data);
if (ret) {
return ret;
}
}
drvp++;
}
Expand All @@ -53,3 +56,35 @@ int initialise_devices(void)

return 0;
}

static int init_device_non_boot(struct elfloader_device *dev)
{
struct elfloader_driver **drvp = __start__driver_list;

while (drvp < __stop__driver_list) {
struct elfloader_driver *drv = *drvp;
if (drv->init_on_secondary_cores) {
int ret = table_has_match(dev->compat, drv->match_table);
if (ret >= 0) {
dev->drv = drv;
ret = drv->init_on_secondary_cores(dev, drv->match_table[ret].match_data);
if (ret) {
return ret;
}
}
}
drvp++;
}
return 0;
kent-mcleod marked this conversation as resolved.
Show resolved Hide resolved
}

int initialise_devices_non_boot(void)
{
for (unsigned int i = 0; i < ARRAY_SIZE(elfloader_devices); i++) {
int ret = init_device_non_boot(&elfloader_devices[i]);
if (ret) {
return ret;
}
}
return 0;
}
34 changes: 34 additions & 0 deletions elfloader-tool/src/drivers/timer/arm_generic_timer.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)
*
* SPDX-License-Identifier: GPL-2.0-only
*/

#include <devices_gen.h>
#include <drivers/common.h>
#include <mode/arm_generic_timer.h>

#include <elfloader_common.h>


static int generic_timer_init(UNUSED struct elfloader_device *dev, UNUSED void *match_data)
{
reset_cntvoff();
return 0;
}

static const struct dtb_match_table generic_timer_matches[] = {
{ .compatible = "arm,armv7-timer" },
{ .compatible = "arm,armv8-timer" },
{ .compatible = NULL /* sentinel */ },
};

static const struct elfloader_driver generic_timer = {
.match_table = generic_timer_matches,
.type = DRIVER_TIMER,
.init = &generic_timer_init,
.init_on_secondary_cores = &generic_timer_init,
.ops = NULL,
};

ELFLOADER_DRIVER(generic_timer);
21 changes: 0 additions & 21 deletions elfloader-tool/src/plat/apq8064/platform_init.c

This file was deleted.

21 changes: 0 additions & 21 deletions elfloader-tool/src/plat/bcm2711/platform_init.c

This file was deleted.

21 changes: 0 additions & 21 deletions elfloader-tool/src/plat/bcm2837/platform_init.c

This file was deleted.

12 changes: 0 additions & 12 deletions elfloader-tool/src/plat/exynos5/platform_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <printf.h>
#include <types.h>
#include <cpuid.h>
#include <mode/arm_generic_timer.h>

#include <elfloader.h>

Expand Down Expand Up @@ -92,15 +91,4 @@ void platform_init(void)
nsscode->cpu1_boot_reg = 0;
smc(SMC_DISABLE_TRUSTZONE, 0, 0, 0);
}

/* Reset the virtual offset for the platform timer to 0 */
reset_cntvoff();
}

#if CONFIG_MAX_NUM_NODES > 1
void non_boot_init(void)
{
/* Reset the virtual offset for the platform timer to 0 */
reset_cntvoff();
}
#endif
11 changes: 0 additions & 11 deletions elfloader-tool/src/plat/fvp/platform_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

#include <autoconf.h>
#include <mode/arm_generic_timer.h>

void platform_init(void)
{
Expand All @@ -21,14 +20,4 @@ void platform_init(void)
"msr tpidr_el0, x0\n"
::: "x0");

/* Reset the virtual offset for the platform timer to 0 */
reset_cntvoff();
}

#if CONFIG_MAX_NUM_NODES > 1
void non_boot_init(void)
{
/* Reset the virtual offset for the platform timer to 0 */
reset_cntvoff();
}
#endif
21 changes: 0 additions & 21 deletions elfloader-tool/src/plat/hikey/platform_init.c

This file was deleted.

21 changes: 0 additions & 21 deletions elfloader-tool/src/plat/imx7/platform_init.c

This file was deleted.

21 changes: 0 additions & 21 deletions elfloader-tool/src/plat/imx8m-evk/platform_init.c

This file was deleted.

22 changes: 0 additions & 22 deletions elfloader-tool/src/plat/maaxboard/platform_init.c

This file was deleted.

Loading