You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.3 KiB

/*
* Copyright (c) Hisilicon Technologies Co., Ltd. 2014-2020. All rights reserved.
* Description: module init
* Author: SmartMedia_BSP
* Create: 2014-06-04
*/
#include <boot.h>
#include <compile.h>
#include <cpuinfo.h>
#include <linux/module.h>
#include <stdio.h>
static void for_init_data(int priority)
{
uint32 *ptr = NULL;
struct module_t *module = NULL;
unsigned int media_type = BOOT_MEDIA_EMMC;
if (get_cpuinfo()->boot_media != NULL) {
media_type = get_cpuinfo()->boot_media(NULL);
}
for (ptr = &__init_start; ptr < &__init_end; ptr++) {
module = (struct module_t *)(*ptr);
if (module->priority == priority && (module->init) && (module->media_type == media_type)) {
if (module->init()) {
printf("call module->init failed\n");
}
}
}
}
static void for_exit_data(int priority)
{
uint32 *ptr = NULL;
struct module_t *module = NULL;
unsigned int media_type = BOOT_MEDIA_EMMC;
if (get_cpuinfo()->boot_media != NULL) {
media_type = get_cpuinfo()->boot_media(NULL);
}
for (ptr = &__init_start; ptr < &__init_end; ptr++) {
module = (struct module_t *)(*ptr);
if (module->priority == priority && (module->exit) && (module->media_type == media_type)) {
if (module->exit()) {
printf("call module->exit failed\n");
}
}
}
}
static void for_reboot_data(int priority)
{
uint32 *ptr = NULL;
struct module_t *module = NULL;
unsigned int media_type = BOOT_MEDIA_EMMC;
if (get_cpuinfo()->boot_media != NULL) {
media_type = get_cpuinfo()->boot_media(NULL);
}
for (ptr = &__init_start; ptr < &__init_end; ptr++) {
module = (struct module_t *)(*ptr);
if (module->priority == priority && (module->reboot) && (module->media_type == media_type)) {
if (module->reboot()) {
printf("call module->reboot failed\n");
}
}
}
}
void module_init(void)
{
int ix;
for (ix = 0; ix < MODULE_PRI_MAX; ix++) {
for_init_data(ix);
}
}
void module_exit(void)
{
int ix;
for (ix = MODULE_PRI_MAX - 1; ix >= 0; ix--) {
for_exit_data(ix);
}
}
void modules_reboot(void)
{
int ix;
for (ix = MODULE_PRI_MAX - 1; ix >= 0; ix--) {
for_reboot_data(ix);
}
}