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.
209 lines
5.6 KiB
209 lines
5.6 KiB
/*
|
|
* Copyright (c) Hisilicon Technologies Co., Ltd. 2020-2020. All rights reserved.
|
|
* Description: driver
|
|
* Author:
|
|
* Create: 2020-10-12
|
|
*/
|
|
|
|
#include <linux/stddef.h> /* for NULL */
|
|
#include <linux/slab.h>
|
|
#include <linux/module.h>
|
|
#include "linux/huanglong/securec.h"
|
|
|
|
#define LOG_BUF_SIZE 1024
|
|
|
|
/*
|
|
* To solve the symbolic dependence of dftevent, the following weak symbol definition is provided.
|
|
*
|
|
* [WARNNING]
|
|
*/
|
|
|
|
struct dft_event;
|
|
int drv_event_create_impl(unsigned int eventid, struct dft_event **event);
|
|
int drv_event_report_impl(struct dft_event *event);
|
|
void drv_event_destroy_impl(struct dft_event *event);
|
|
int drv_event_put_integral_impl(struct dft_event *event, const char *key, long value);
|
|
int drv_event_put_string_impl(struct dft_event *event, const char *key, const char *value);
|
|
int drv_event_set_time_impl(struct dft_event *event, long long seconds);
|
|
int drv_event_add_file_path_impl(struct dft_event *event, const char *path);
|
|
int drv_hwlog_to_write_impl(int prio, int bufid, const char *tag, const char *msg);
|
|
|
|
int __weak drv_event_create_impl(unsigned int eventid, struct dft_event **event)
|
|
{
|
|
struct dft_event *phony_event = NULL;
|
|
unsigned long phony_size = sizeof(unsigned int);
|
|
|
|
if (event == NULL) {
|
|
printk("%s[%d]: invalid parameter!\n", __FUNCTION__, __LINE__);
|
|
return -1;
|
|
}
|
|
|
|
phony_event = kmalloc(phony_size, GFP_KERNEL);
|
|
if (phony_event == NULL) {
|
|
printk("%s[%d]: malloc memory failed\n", __FUNCTION__, __LINE__);
|
|
return -1;
|
|
}
|
|
|
|
*event = phony_event;
|
|
|
|
return 0;
|
|
}
|
|
|
|
int __weak drv_event_report_impl(struct dft_event *event)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
void __weak drv_event_destroy_impl(struct dft_event *event)
|
|
{
|
|
if (event == NULL) {
|
|
return;
|
|
}
|
|
kfree(event);
|
|
event = NULL;
|
|
}
|
|
|
|
int __weak drv_event_put_integral_impl(struct dft_event *event, const char *key, long value)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
int __weak drv_event_put_string_impl(struct dft_event *event, const char *key, const char *value)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
int __weak drv_event_set_time_impl(struct dft_event *event, long long seconds)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
int __weak drv_event_add_file_path_impl(struct dft_event *event, const char *path)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
int __weak drv_hwlog_to_write_impl(int prio, int bufid, const char *tag, const char *msg)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
static int system_state_is_running(void)
|
|
{
|
|
// [system_state] is a global var from kernel,
|
|
// valued {SYSTEM_BOOTING, SYSTEM_SCHEDULING, SYSTEM_RUNNING, SYSTEM_HALT, SYSTEM_POWER_OFF, SYSTEM_RESTART}.
|
|
if (system_state == SYSTEM_RUNNING) {
|
|
return 1;
|
|
}
|
|
|
|
switch (system_state) {
|
|
case SYSTEM_BOOTING:
|
|
printk("%s[%d]: system_state is SYSTEM_BOOTING\n", __FUNCTION__, __LINE__);
|
|
break;
|
|
case SYSTEM_SCHEDULING:
|
|
printk("%s[%d]: system_state is SYSTEM_SCHEDULING\n", __FUNCTION__, __LINE__);
|
|
break;
|
|
case SYSTEM_HALT:
|
|
printk("%s[%d]: system_state is SYSTEM_HALT\n", __FUNCTION__, __LINE__);
|
|
break;
|
|
case SYSTEM_POWER_OFF:
|
|
printk("%s[%d]: system_state is SYSTEM_POWER_OFF\n", __FUNCTION__, __LINE__);
|
|
break;
|
|
case SYSTEM_RESTART:
|
|
printk("%s[%d]: system_state is SYSTEM_RESTART\n", __FUNCTION__, __LINE__);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int drv_event_create(unsigned int eventid, struct dft_event **event)
|
|
{
|
|
return drv_event_create_impl(eventid, event);
|
|
}
|
|
EXPORT_SYMBOL(drv_event_create);
|
|
|
|
int drv_event_set_time(struct dft_event *event, long long seconds)
|
|
{
|
|
if (system_state_is_running() == 0) {
|
|
// todo: fault report through bbox
|
|
printk("%s[%d]: drv_event_set_time failed, seconds=%lld\n", __FUNCTION__, __LINE__, seconds);
|
|
return 0;
|
|
}
|
|
|
|
return drv_event_set_time_impl(event, seconds);
|
|
}
|
|
EXPORT_SYMBOL(drv_event_set_time);
|
|
|
|
int drv_event_put_integral(struct dft_event *event, const char *key, long value)
|
|
{
|
|
if (system_state_is_running() == 0) {
|
|
// todo: fault report through bbox
|
|
printk("%s[%d]: drv_event_put_integral failed, key=%s, value=%ld\n", __FUNCTION__, __LINE__, key, value);
|
|
return 0;
|
|
}
|
|
|
|
return drv_event_put_integral_impl(event, key, value);
|
|
}
|
|
EXPORT_SYMBOL(drv_event_put_integral);
|
|
|
|
int drv_event_put_string(struct dft_event *event, const char *key, const char *value)
|
|
{
|
|
if (system_state_is_running() == 0) {
|
|
// todo: fault report through bbox
|
|
printk("%s[%d]: drv_event_put_string failed, key=%s, value=%s\n", __FUNCTION__, __LINE__, key, value);
|
|
return 0;
|
|
}
|
|
|
|
return drv_event_put_string_impl(event, key, value);
|
|
}
|
|
EXPORT_SYMBOL(drv_event_put_string);
|
|
|
|
int drv_event_add_file_path(struct dft_event *event, const char *path)
|
|
{
|
|
if (system_state_is_running() == 0) {
|
|
// todo: fault report through bbox
|
|
printk("%s[%d]: drv_event_add_file_path failed, path=%s\n", __FUNCTION__, __LINE__, path);
|
|
return 0;
|
|
}
|
|
|
|
return drv_event_add_file_path_impl(event, path);
|
|
}
|
|
EXPORT_SYMBOL(drv_event_add_file_path);
|
|
|
|
int drv_event_report(struct dft_event *event)
|
|
{
|
|
if (system_state_is_running() == 0) {
|
|
// todo: fault report through bbox
|
|
printk("%s[%d]: drv_event_report failed\n", __FUNCTION__, __LINE__);
|
|
return 0;
|
|
}
|
|
|
|
return drv_event_report_impl(event);
|
|
}
|
|
EXPORT_SYMBOL(drv_event_report);
|
|
|
|
void drv_event_destroy(struct dft_event *event)
|
|
{
|
|
drv_event_destroy_impl(event);
|
|
event = NULL;
|
|
}
|
|
EXPORT_SYMBOL(drv_event_destroy);
|
|
|
|
int drv_hwlog_to_write(int prio, int bufid, const char *tag, const char *fmt, ...)
|
|
{
|
|
va_list ap;
|
|
char buff[LOG_BUF_SIZE];
|
|
va_start(ap, fmt);
|
|
if (vsnprintf_s(buff, LOG_BUF_SIZE, LOG_BUF_SIZE - 1, fmt, ap) < 0) {
|
|
printk("drv_hwlog_to_write error.\n");
|
|
va_end(ap);
|
|
return -1;
|
|
}
|
|
va_end(ap);
|
|
return drv_hwlog_to_write_impl(prio, bufid, tag, buff);
|
|
}
|
|
EXPORT_SYMBOL(drv_hwlog_to_write);
|