openUBMC Chip Abstract Layer V0.1
载入中...
搜索中...
未找到
driver.h
浏览该文件的文档.
1/*
2 * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved.
3 *
4 * this file licensed under the Mulan PSL v2.
5 * You can use this software according to the terms and conditions of the Mulan PSL v2.
6 * You may obtain a copy of Mulan PSL v2 at:
7 * http://license.coscl.org.cn/MulanPSL2
8 *
9 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
10 * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
11 * PURPOSE.
12 * See the Mulan PSL v2 for more details.
13 *
14 * Create: 2022-06-08
15 */
20#ifndef DRIVER_H
21#define DRIVER_H
22
23#include <string>
24#include <vector>
25#include <unordered_map>
26#include <memory>
27#include <mutex>
28#include <chrono>
29#include <dlfcn.h>
30
31using string_t = std::string;
32using string_view_t = std::string_view;
33
34namespace bcal {
35
41class IDriver {
42public:
47 free();
48 }
49
53 virtual void free(void) {};
54
60 virtual void init(void *args, uint32_t size) = 0;
61
69 virtual void config(int32_t index, void *config, uint32_t size) = 0;
70
77 virtual void lock(int32_t index) = 0;
78
83 virtual void unlock(int32_t index) = 0;
84
89 virtual string_t get_version(void) = 0;
90};
91
97 string_t driver_name;
98 bool success;
99 double load_time_ms;
100 string_t error_msg;
101};
102
108public:
114 virtual void set_driver_path(const string_t& driver_path) = 0;
115
122 virtual IDriver& get_driver(const string_t& driver_name) = 0;
123
129 virtual std::vector<string_t> get_driver_list(void) = 0;
130
136 virtual std::vector<driver_load_info> get_driver_load_info(void) = 0;
137
143 virtual void remove_driver(const string_t& driver_name) = 0;
144
151};
152
158
163using destroy_driver_func = void (*)(IDriver*);
164} // namespace bcal
165
166#endif
BCAL层驱动工厂类
Definition driver.h:107
virtual void set_driver_path(const string_t &driver_path)=0
设置驱动加载路径
virtual std::vector< string_t > get_driver_list(void)=0
获取支持的驱动列表
virtual std::vector< driver_load_info > get_driver_load_info(void)=0
获取驱动加载信息
static IDriverFactory & get_instance()
获取驱动工厂实例单例
Definition driver.cpp:207
virtual IDriver & get_driver(const string_t &driver_name)=0
获取驱动实例 加载driver_path下的 lib{driver_name}.so,返回驱动实例
virtual void remove_driver(const string_t &driver_name)=0
卸载驱动实例
BCAL层驱动公共接口
Definition driver.h:41
virtual void config(int32_t index, void *config, uint32_t size)=0
驱动实例初始化配置
virtual void free(void)
BCAL驱动析构
Definition driver.h:53
~IDriver()
BCAL驱动析构
Definition driver.h:46
virtual string_t get_version(void)=0
获取驱动版本信息
virtual void unlock(int32_t index)=0
驱动实例解锁
virtual void init(void *args, uint32_t size)=0
BCAL驱动初始化接口
virtual void lock(int32_t index)=0
驱动实例加锁 读写锁
IDriver *(*)() create_driver_func
驱动模块创建接口
Definition driver.h:157
void(*)(IDriver *) destroy_driver_func
驱动模块资源销毁接口
Definition driver.h:163
驱动加载信息
Definition driver.h:96
bool success
Definition driver.h:98
string_t driver_name
Definition driver.h:97
string_t error_msg
Definition driver.h:100
double load_time_ms
Definition driver.h:99