update openharmony 1.0.1

This commit is contained in:
mamingshuai 2021-03-11 18:38:32 +08:00
parent 5f5a1ec9fc
commit 699a347c20
84 changed files with 8070 additions and 65 deletions

13
Kconfig Executable file
View File

@ -0,0 +1,13 @@
config DRIVERS_HDF
bool "Enable HDF manager"
default y
help
Answer Y to enable Linux support HDF.
source "drivers/hdf/khdf/platform/Kconfig"
source "drivers/hdf/khdf/test/Kconfig"
source "drivers/hdf/khdf/model/display/Kconfig"
source "drivers/hdf/khdf/model/input/Kconfig"
source "drivers/hdf/khdf/model/network/wifi/Kconfig"
source "drivers/hdf/khdf/model/sensor/Kconfig"

359
LICENSE Normal file
View File

@ -0,0 +1,359 @@
Valid-License-Identifier: GPL-2.0
Valid-License-Identifier: GPL-2.0-only
Valid-License-Identifier: GPL-2.0+
Valid-License-Identifier: GPL-2.0-or-later
SPDX-URL: https://spdx.org/licenses/GPL-2.0.html
Usage-Guide:
To use this license in source code, put one of the following SPDX
tag/value pairs into a comment according to the placement
guidelines in the licensing rules documentation.
For 'GNU General Public License (GPL) version 2 only' use:
SPDX-License-Identifier: GPL-2.0
or
SPDX-License-Identifier: GPL-2.0-only
For 'GNU General Public License (GPL) version 2 or any later version' use:
SPDX-License-Identifier: GPL-2.0+
or
SPDX-License-Identifier: GPL-2.0-or-later
License-Text:
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.

32
Makefile Normal file
View File

@ -0,0 +1,32 @@
#
# Copyright (c) 2020-2021 Huawei Device Co., Ltd.
#
# This software is licensed under the terms of the GNU General Public
# License version 2, as published by the Free Software Foundation, and
# may be copied, distributed, and modified under those terms.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
export HDF_ROOT := drivers/hdf
obj-y += platform/pwm/driver/
obj-$(CONFIG_DRIVERS_HDF) += osal/
obj-$(CONFIG_DRIVERS_HDF) += network/
obj-$(CONFIG_DRIVERS_HDF) += config/
ifeq ($(CONFIG_DRIVERS_HDF_TEST), y)
obj-y += ../../../../$(PRODUCT_PATH)/config/hdf_test/
obj-y += test/
else
obj-$(CONFIG_DRIVERS_HDF) += ../../../../$(PRODUCT_PATH)/config/
endif
obj-$(CONFIG_DRIVERS_HDF) += manager/
obj-$(CONFIG_DRIVERS_HDF_PLATFORM) += platform/
obj-$(CONFIG_DRIVERS_HDF_DISP) += model/display/
obj-$(CONFIG_DRIVERS_HDF_INPUT) += model/input/
obj-$(CONFIG_DRIVERS_HDF_WIFI) += model/network/wifi/
obj-$(CONFIG_DRIVERS_HDF_SENSOR) += model/sensor/

View File

@ -1,36 +0,0 @@
# drivers_adapter_khdf_linux
#### Description
{**When you're done, you can delete the content in this README and update the file with details for others getting started with your repository**}
#### Software Architecture
Software architecture description
#### Installation
1. xxxx
2. xxxx
3. xxxx
#### Instructions
1. xxxx
2. xxxx
3. xxxx
#### Contribution
1. Fork the repository
2. Create Feat_xxx branch
3. Commit your code
4. Create Pull Request
#### Gitee Feature
1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
4. The most valuable open source project [GVP](https://gitee.com/gvp)
5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)

View File

@ -1,39 +1,46 @@
# drivers_adapter_khdf_linux
# linux\_khdf<a name="EN-US_TOPIC_0000001078489630"></a>
#### 介绍
{**以下是 Gitee 平台说明,您可以替换此简介**
Gitee 是 OSCHINA 推出的基于 Git 的代码托管平台(同时支持 SVN。专为开发者提供稳定、高效、安全的云端软件开发协作平台
无论是个人、团队、或是企业,都能够用 Gitee 实现代码托管、项目管理、协作开发。企业项目请看 [https://gitee.com/enterprises](https://gitee.com/enterprises)}
- [Introduction](#section11660541593)
- [Directory Structure](#section161941989596)
- [Repositories Involved](#section1371113476307)
#### 软件架构
软件架构说明
## Introduction<a name="section11660541593"></a>
This repository stores the code and compilation scripts for the OpenHarmony driver subsystem to adapt to the Linux kernel and to deploy the hardware driver foundation \(HDF\).
#### 安装教程
## Directory Structure<a name="section161941989596"></a>
1. xxxx
2. xxxx
3. xxxx
```
/drivers/adapter/khdf/linux
├── config # Compilation scripts for building and configuring the parsing code
├── hcs # HDF configuration and management
├── manager # Code for starting and adapting to the HDF
├── model # Code for adapting to the Linux
│ ├── display # Display driver model
│ ├── input # Input driver model
│ ├── network # WLAN driver model
│ ├── sensor # Sensor driver model
├── network # Code for adapting to the Linux kernel network
├── osal # POSIX APIs for adapting to the Linux kernel
├── platform # Code for adapting the platform APIs to the Linux kernel
│ ├── emmc # EMMC APIs
│ ├── gpio # GPIO APIs
│ ├── i2c # I2C APIs
│ ├── mipi_dsi # MIPI DSI APIs
│ ├── pwm # PWM APIs
│ ├── rtc # RTC APIs
│ ├── sdio # SDIO APIs
│ ├── spi # SPI APIs
│ ├── uart # UART APIs
│ └── watchdog # WATCHDOG APIs
```
#### 使用说明
## Repositories Involved<a name="section1371113476307"></a>
1. xxxx
2. xxxx
3. xxxx
hmf/drivers/framework
#### 参与贡献
hmf/drivers/adapter\_uhdf
1. Fork 本仓库
2. 新建 Feat_xxx 分支
3. 提交代码
4. 新建 Pull Request
hmf/drivers/adapter\_khdf\_linux
#### 特技
1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
hmf/drivers/adapter\_khdf\_liteos

46
README_zh.md Normal file
View File

@ -0,0 +1,46 @@
# linux\_khdf<a name="ZH-CN_TOPIC_0000001078489630"></a>
- [简介](#section11660541593)
- [目录](#section161941989596)
- [相关仓](#section1371113476307)
## 简介<a name="section11660541593"></a>
该仓主要存放OpenHarmony驱动子系统适配linux内核的代码和编译脚本在linux内核中部署鸿蒙驱动框架。
## 目录<a name="section161941989596"></a>
```
/drivers/adapter/khdf/linux
├── config #linux内核下编译配置解析代码的编译脚本
├── hcs #linux内核下HDF的配置管理目录
├── manager #linux内核下启动适配启动HDF框架代码
├── model #驱动模型适配linux代码
│ ├── display #显示驱动模型
│ ├── input #输入驱动模型
│ ├── network #wifi驱动模型
│ └── sensor #传感器驱动模型
├── network #适配linux内核网络代码
├── osal #适配linux内核的posix接口
├── platform #平台设备接口适配linux内核代码
│ ├── emmc #emmc操作接口
│ ├── gpio #gpio接口
│ ├── i2c #i2c接口
│ ├── mipi_dsi #mipi dsi接口
│ ├── pwm #pwm接口
│ ├── rtc #rtc接口
│ ├── sdio #sdio接口
│ ├── spi #spi接口
│ ├── uart #uart接口
│ └── watchdog #watchdog接口
```
## 相关仓<a name="section1371113476307"></a>
hmf/drivers/framework
hmf/drivers/adapter\_uhdf
hmf/drivers/adapter\_khdf\_linux
hmf/drivers/adapter\_khdf\_liteos

27
config/Makefile Executable file
View File

@ -0,0 +1,27 @@
#
# Copyright (c) 2020-2021 Huawei Device Co., Ltd.
#
# This software is licensed under the terms of the GNU General Public
# License version 2, as published by the Free Software Foundation, and
# may be copied, distributed, and modified under those terms.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
obj-y += ../../../../framework/ability/config/device_resource_if.o \
../../../../framework/ability/config/hcs_parser/src/hcs_blob_if.o \
../../../../framework/ability/config/hcs_parser/src/hcs_generate_tree.o \
../../../../framework/ability/config/hcs_parser/src/hcs_parser.o \
../../../../framework/ability/config/hcs_parser/src/hcs_tree_if.o
ccflags-y += -Iinclude/hdf \
-Iinclude/hdf/osal \
-Iinclude/hdf/utils \
-Idrivers/hdf/khdf/osal/include \
-Idrivers/hdf/framework/include \
-Idrivers/hdf/framework/include/utils \
-Idrivers/hdf/framework/include/config \
-Idrivers/hdf/framework/ability/config/hcs_parser/include

55
hcs/Makefile Executable file
View File

@ -0,0 +1,55 @@
#
# Copyright (c) 2020-2021 Huawei Device Co., Ltd.
#
# This software is licensed under the terms of the GNU General Public
# License version 2, as published by the Free Software Foundation, and
# may be copied, distributed, and modified under those terms.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
ifneq ($(findstring $(shell uname),Linux),)
HCGEN_PATH := linux-x86/bin/hc-gen
else
HCGEN_PATH := win-x86/bin/hc-gen.exe
endif
SOURCE_ROOT:=$(HDF_PROJECT_ROOT)
HC_GEN := hc-gen
BUILD_IN_HC_GEN := $(SOURCE_ROOT)/prebuilts/build-tools/$(HCGEN_PATH)
ifneq ($(wildcard $(BUILD_IN_HC_GEN)),)
HC_GEN := $(BUILD_IN_HC_GEN)
endif
LOCAL_HCS_ROOT := $(abspath $(dir $(realpath $(lastword $(MAKEFILE_LIST)))))
HCS_DIR := $(SOURCE_ROOT)/$(product_path)
HCB_FLAGS := -b -i -a
HCS_OBJ := hdf_hcs_hex.o
HCS_OBJ_SRC := $(subst .o,.c,$(notdir $(HCS_OBJ)))
CONFIG_GEN_HEX_SRC := $(addprefix $(LOCAL_HCS_ROOT)/, $(HCS_OBJ_SRC))
CONFIG_HCS_SRC := $(subst _hcs_hex.o,.hcs,$(addprefix $(HCS_DIR)/, $(HCS_OBJ)))
$(obj)/$(HCS_OBJ): $(CONFIG_GEN_HEX_SRC)
$(Q)$(CC) $(c_flags) -c -o $@ $<
$(Q)rm -f $<
$(CONFIG_GEN_HEX_SRC): $(LOCAL_HCS_ROOT)/%_hcs_hex.c: $(HCS_DIR)/%.hcs
$(Q)echo gen hdf built-in config
$(Q)if [ ! -d $(dir $@) ]; then mkdir -p $(dir $@); fi
$(Q)$(HC_GEN) $(HCB_FLAGS) -o $(subst _hex.c,,$(@)) $<
$(CONFIG_GEN_SRCS): $(CONFIG_OUT_DIR)%.c: $(HCS_DIR)/%.hcs
$(Q)echo gen hdf driver config
$(Q)if [ ! -d $(dir $@) ]; then mkdir -p $(dir $@); fi
$(Q)$(HC_GEN) -t -o $@ $<
obj-$(CONFIG_DRIVERS_HDF) += $(HCS_OBJ)

79
manager/Makefile Normal file
View File

@ -0,0 +1,79 @@
#
# Copyright (c) 2020-2021 Huawei Device Co., Ltd.
#
# This software is licensed under the terms of the GNU General Public
# License version 2, as published by the Free Software Foundation, and
# may be copied, distributed, and modified under those terms.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
#SOURCES=$(wildcard *.c)
SEC_LIB_SOURCES = memcpy_s.c memmove_s.c memset_s.c securecutil.c secureinput_a.c secureprintoutput_a.c snprintf_s.c sprintf_s.c strcat_s.c strcpy_s.c strncat_s.c strncpy_s.c strtok_s.c vsnprintf_s.c vsprintf_s.c
#SEC_LIB_SOURCES += fwscanf_s.c secureinput_w.c secureprintoutput_w.c swprintf_s.c swscanf_s.c vfwscanf_s.c vswprintf_s.c vswscanf_s.c vwscanf_s.c wcscat_s.c wcscpy_s.c wcsncat_s.c wcsncpy_s.c wcstok_s.c wmemcpy_s.c wmemmove_s.c wscanf_s.c
#SEC_LIB_SOURCES:=$(wildcard ../../framework/libc_sec/src/*.c)
#$(warning SEC_LIB_SOURCES $(SEC_LIB_SOURCES))
PWD:=$(shell pwd)
SEC_OBJECTS:=$(patsubst %.c,%.o,$(SEC_LIB_SOURCES))
OBJECTS:=$(addprefix ../../../../../third_party/bounds_checking_function/src/,${SEC_OBJECTS})
obj-y += \
../../../../framework/utils/src/hdf_cstring.o \
../../../../framework/utils/src/hdf_slist.o \
../../../../framework/utils/src/hdf_sref.o \
../../../../framework/ability/sbuf/src/hdf_sbuf.o \
../../../../framework/core/host/src/devhost_service.o \
../../../../framework/core/host/src/devmgr_service_clnt.o \
../../../../framework/core/host/src/devsvc_manager_clnt.o \
../../../../framework/core/host/src/hdf_device.o \
../../../../framework/core/host/src/hdf_device_node.o \
../../../../framework/core/host/src/hdf_device_token.o \
../../../../framework/core/host/src/hdf_driver_loader.o \
../../../../framework/core/host/src/hdf_observer_record.o \
../../../../framework/core/host/src/hdf_service_subscriber.o \
../../../../framework/core/host/src/hdf_device_object.o \
../../../../framework/core/host/src/hdf_service_observer.o \
../../../../framework/core/host/src/power_state_token.o \
../../../../framework/core/manager/src/devhost_service_clnt.o \
../../../../framework/core/manager/src/device_token_clnt.o \
../../../../framework/core/manager/src/devmgr_service.o \
../../../../framework/core/manager/src/devsvc_manager.o \
../../../../framework/core/manager/src/hdf_driver_installer.o \
../../../../framework/core/manager/src/hdf_host_info.o \
../../../../framework/core/manager/src/power_state_manager.o \
../../../../framework/core/manager/src/power_state_token_clnt.o \
../../../../framework/core/shared/src/hdf_service_record.o \
../../../../framework/core/shared/src/hdf_device_info.o \
../../../../framework/core/shared/src/hdf_object_manager.o \
../../../../framework/core/shared/src/hdf_io_service.o \
../../../../framework/core/common/src/devlite_object_config.o \
../../../../framework/core/common/src/hdf_attribute.o \
../../../../framework/core/common/src/load_driver_entry.o \
../../../../framework/core/common/src/devmgr_service_start.o \
../../../../framework/core/common/src/hdf_device_node_ext.o \
../../../../framework/core/adapter/vnode/src/hdf_vnode_adapter.o \
./src/devmgr_load.o \
$(OBJECTS)
ccflags-y += -Iinclude/../drivers/hdf/framework/include \
-Iinclude/../drivers/hdf/framework/include/osal \
-Iinclude/../drivers/hdf/framework/include/utils \
-Iinclude/../drivers/hdf/framework/include \
-Iinclude/../drivers/hdf/framework/utils/include \
-Iinclude/../drivers/hdf/framework/include/core \
-Iinclude/../drivers/hdf/framework/ability/sbuf/include \
-Iinclude/../drivers/hdf/framework/core/host/include \
-Iinclude/../drivers/hdf/framework/core/manager/include \
-Iinclude/../drivers/hdf/framework/core/shared/include \
-Iinclude/../drivers/hdf/framework/core/common/include/host \
-Iinclude/../drivers/hdf/framework/core/common/include/manager \
-Iinclude/../drivers/hdf/framework/core/adapter/vnode/include \
-Iinclude/../drivers/hdf/../../../../../../../../../../../../../third_party/bounds_checking_function/include \
-Iinclude/../drivers/hdf/framework/ability/config/hcs_parser/include \
-Iinclude/../drivers/hdf/framework/include/config \
-Iinclude/../drivers/hdf/framework/ability/config/hcs_parser/include \
-Iinclude/../drivers/hdf/khdf/osal/include

40
manager/src/devmgr_load.c Normal file
View File

@ -0,0 +1,40 @@
/*
* devmgr_load.c
*
* device manager loader of linux
*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/of_device.h>
#include "devmgr_service_start.h"
#include "hdf_log.h"
static int __init DeviceManagerInit(void)
{
int ret;
HDF_LOGD("%s enter", __func__);
ret = DeviceManagerStart();
if (ret < 0) {
HDF_LOGE("%s start failed %d", __func__, ret);
} else {
HDF_LOGD("%s start success", __func__);
}
return ret;
}
module_init(DeviceManagerInit);

24
model/display/Kconfig Executable file
View File

@ -0,0 +1,24 @@
config DRIVERS_HDF_DISP
bool "Enable HDF Display driver"
default n
depends on DRIVERS_HDF
help
Answer Y to choice HDF Display driver.
config DRIVERS_HDF_LCDKIT
bool "Enable HDF Lcdkit driver"
default n
depends on DRIVERS_HDF_DISP
help
Answer Y to enable HDF Lcdkit driver.
config DRIVERS_HDF_LCD_ICN9700
bool "Enable HDF Icn9700 driver"
default n
depends on DRIVERS_HDF_DISP
help
Answer Y to enable HDF Icn9700 driver.
config DRIVERS_HDF_LCD_ST7789
bool "Enable HDF St7789 driver"
default n
depends on DRIVERS_HDF_DISP
help
Answer Y to enable HDF St7789 driver.

41
model/display/Makefile Executable file
View File

@ -0,0 +1,41 @@
#
# Copyright (c) 2020-2021 Huawei Device Co., Ltd.
#
# This software is licensed under the terms of the GNU General Public
# License version 2, as published by the Free Software Foundation, and
# may be copied, distributed, and modified under those terms.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
DISPLAY_ROOT_DIR = ../../../../../framework/model/display/driver
obj-y += \
$(DISPLAY_ROOT_DIR)/hdf_disp.o \
$(DISPLAY_ROOT_DIR)/lcd_abs_if.o
obj-$(CONFIG_ARCH_HI3516DV300) += \
$(DISPLAY_ROOT_DIR)/hi35xx_disp.o
obj-$(CONFIG_DRIVERS_HDF_LCDKIT) += \
$(DISPLAY_ROOT_DIR)/lcdkit/lite_lcdkit.o \
$(DISPLAY_ROOT_DIR)/lcdkit/lcdkit_parse_config.o
obj-$(CONFIG_DRIVERS_HDF_LCD_ICN9700) += \
$(DISPLAY_ROOT_DIR)/panel/mipi_icn9700.o
obj-$(CONFIG_DRIVERS_HDF_LCD_ST7789) += \
$(DISPLAY_ROOT_DIR)/panel/ssp_st7789.o
ccflags-y += -lm -lc -lgcc \
-Idrivers/hdf/framework/model/display/driver \
-Idrivers/hdf/framework/include/utils \
-Idrivers/hdf/khdf/osal/include \
-Idrivers/hdf/framework/include/core \
-Idrivers/hdf/framework/core/common/include/host \
-Idrivers/hdf/framework/ability/sbuf/include \
-Idrivers/hdf/../../../../../../../../../../../../../third_party/bounds_checking_function/include \
-Idrivers/hdf/framework/include \
-Idrivers/hdf/framework/include/osal \
-Idrivers/hdf/framework/include/platform \
-Idrivers/hdf/framework/include/config

20
model/input/Kconfig Executable file
View File

@ -0,0 +1,20 @@
config DRIVERS_HDF_INPUT
bool "Enable HDF input driver"
default n
depends on DRIVERS_HDF
help
Answer Y to enable HDF input driver.
config DRIVERS_HDF_TP_5P5_GT911
bool "Enable HDF tp 5P5 GT911 driver"
default n
depends on DRIVERS_HDF_INPUT
help
Answer Y to enable HDF TP 5P5 GT911 driver.
config DRIVERS_HDF_TP_2P35_FT6236
bool "Enable HDF tp 2P35 FT6236 driver"
default n
depends on DRIVERS_HDF_INPUT
help
Answer Y to enable HDF TP 2P35 FT6236 driver.

49
model/input/Makefile Executable file
View File

@ -0,0 +1,49 @@
#
# Copyright (c) 2020-2021 Huawei Device Co., Ltd.
#
# This software is licensed under the terms of the GNU General Public
# License version 2, as published by the Free Software Foundation, and
# may be copied, distributed, and modified under those terms.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
SEC_LIB_SOURCES = memcpy_s.c memmove_s.c memset_s.c securecutil.c secureinput_a.c secureprintoutput_a.c snprintf_s.c sprintf_s.c strcat_s.c strcpy_s.c strncat_s.c strncpy_s.c strtok_s.c vsnprintf_s.c vsprintf_s.c
PWD:=$(shell pwd)
SEC_OBJECTS:=$(patsubst %.c,%.o,$(SEC_LIB_SOURCES))
INPUT_ROOT_DIR = ../../../../../framework/model/input/driver
obj-$(CONFIG_DRIVERS_HDF_INPUT) += \
$(INPUT_ROOT_DIR)/input_bus_ops/input_i2c_ops.o \
$(INPUT_ROOT_DIR)/hdf_input_device_manager.o \
$(INPUT_ROOT_DIR)/input_config_parser.o \
$(INPUT_ROOT_DIR)/event_hub.o \
$(INPUT_ROOT_DIR)/hdf_touch.o \
$(INPUT_ROOT_DIR)/hdf_key.o \
$(INPUT_ROOT_DIR)/hdf_hid.o
obj-$(CONFIG_DRIVERS_HDF_TP_5P5_GT911) += \
$(INPUT_ROOT_DIR)/touchscreen/touch_gt911.o
obj-$(CONFIG_DRIVERS_HDF_TP_2P35_FT6236) += \
$(INPUT_ROOT_DIR)/touchscreen/touch_ft6336.o
ccflags-y += -Iinclude/../drivers/hdf/framework/model/input/driver \
-Iinclude/../drivers/hdf/framework/model/input/driver/input_bus_ops \
-Iinclude/../drivers/hdf/framework/include/core \
-Iinclude/../drivers/hdf/framework/core/common/include/host \
-Iinclude/../drivers/hdf/framework/include/utils \
-Iinclude/../drivers/hdf/framework/include/osal \
-Iinclude/../drivers/hdf/framework/ability/sbuf/include \
-Iinclude/../drivers/hdf/framework/include/platform \
-Iinclude/../drivers/hdf/framework/include/config \
-Iinclude/../drivers/hdf/framework/core/host/include \
-Iinclude/../drivers/hdf/framework/core/shared/include \
-Iinclude/../drivers/hdf/khdf/osal/include \
-Iinclude/../drivers/hdf/../../../../../../../../../../../../../third_party/bounds_checking_function/include \
-Iinclude/../drivers/hdf/../../../../../../../../../../../../../third_party/FreeBSD/sys/dev/evdev

13
model/network/wifi/Kconfig Executable file
View File

@ -0,0 +1,13 @@
config DRIVERS_HDF_WIFI
bool "Enable HDF wifi"
default n
depends on DRIVERS_HDF
help
Answer Y to enable HDF wifi.
config DRIVERS_HI3881
bool "Enable hi3881"
default n
depends on DRIVERS_HDF_WIFI
help
Answer Y to enable hi3881 wifi chip driver.

63
model/network/wifi/Makefile Executable file
View File

@ -0,0 +1,63 @@
#
# Copyright (c) 2020-2021 Huawei Device Co., Ltd.
#
# This software is licensed under the terms of the GNU General Public
# License version 2, as published by the Free Software Foundation, and
# may be copied, distributed, and modified under those terms.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
MODULE_NAME := hdf_wifi_model
HDF_DIR_PREFIX := ../../../../../../
include drivers/hdf/khdf/model/network/wifi/hdfwifi.mk
WAP_PATH := core/compoments/softap
WSTA_PATH := core/compoments/sta
WEAPOL_PATH := core/compoments/eapol
NETDEV_PATH := ../common/netdevice
MODULE_PATH := core/module
QOS_PATH := platform/src/qos
MESSAGE_PATH := platform/src/message
PLATFORM_PATH := platform/src
CORE_PATH := core
obj-$(CONFIG_DRIVERS_HDF_WIFI) += $(MODULE_NAME).o
$(MODULE_NAME)-objs := $(HDF_WIFI_FRAMEWORKS_ROOT)/$(WAP_PATH)/ap.o \
$(HDF_WIFI_FRAMEWORKS_ROOT)/$(WEAPOL_PATH)/eapol.o \
$(HDF_WIFI_FRAMEWORKS_ROOT)/$(WSTA_PATH)/sta.o \
$(HDF_WIFI_FRAMEWORKS_ROOT)/$(NETDEV_PATH)/net_device.o \
$(HDF_WIFI_FRAMEWORKS_ROOT)/$(MODULE_PATH)/wifi_module.o \
$(HDF_WIFI_FRAMEWORKS_ROOT)/$(MODULE_PATH)/wifi_base.o \
$(HDF_WIFI_FRAMEWORKS_ROOT)/$(MODULE_PATH)/wifi_feature.o \
$(HDF_WIFI_FRAMEWORKS_ROOT)/$(CORE_PATH)/hdf_wifi_core.o \
$(HDF_WIFI_FRAMEWORKS_ROOT)/$(QOS_PATH)/flow_control.o \
$(HDF_WIFI_FRAMEWORKS_ROOT)/$(QOS_PATH)/flow_control_task.o \
$(HDF_WIFI_FRAMEWORKS_ROOT)/$(MESSAGE_PATH)/nodes/local_node.o \
$(HDF_WIFI_FRAMEWORKS_ROOT)/$(MESSAGE_PATH)/message_dispatcher.o \
$(HDF_WIFI_FRAMEWORKS_ROOT)/$(MESSAGE_PATH)/message_router.o \
$(HDF_WIFI_FRAMEWORKS_ROOT)/$(MESSAGE_PATH)/sidecar.o \
$(HDF_WIFI_KHDF_FRAMEWORKS_ROOT)/$(PLATFORM_PATH)/hdf_wlan_queue.o \
$(HDF_WIFI_FRAMEWORKS_ROOT)/$(PLATFORM_PATH)/hdf_wlan_priority_queue.o \
$(HDF_WIFI_FRAMEWORKS_ROOT)/$(PLATFORM_PATH)/hdf_wifi_event.o \
$(HDF_WIFI_FRAMEWORKS_ROOT)/$(PLATFORM_PATH)/hdf_wlan_chipdriver_manager.o \
$(HDF_WIFI_FRAMEWORKS_ROOT)/$(PLATFORM_PATH)/hdf_wlan_config_parser.o \
$(HDF_WIFI_FRAMEWORKS_ROOT)/$(PLATFORM_PATH)/hdf_wlan_power_manager.o \
$(HDF_WIFI_FRAMEWORKS_ROOT)/$(PLATFORM_PATH)/hdf_wlan_product.o \
$(HDF_WIFI_FRAMEWORKS_ROOT)/$(PLATFORM_PATH)/hdf_wlan_reset_manager.o \
$(HDF_WIFI_FRAMEWORKS_ROOT)/$(PLATFORM_PATH)/hdf_wlan_utils.o \
ccflags-$(CONFIG_DRIVERS_HDF_WIFI) += \
$(HDF_FRAMEWORKS_INC) \
$(HDF_WIFI_FRAMEWORKS_INC) \
$(HDF_WIFI_ADAPTER_INC) \
$(SECURE_LIB_INC)
obj-$(CONFIG_DRIVERS_HDF_WIFI) += vendor/

60
model/network/wifi/hdfwifi.mk Executable file
View File

@ -0,0 +1,60 @@
#
# Copyright (c) 2020-2021 Huawei Device Co., Ltd.
#
# This software is licensed under the terms of the GNU General Public
# License version 2, as published by the Free Software Foundation, and
# may be copied, distributed, and modified under those terms.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
HDF_WIFI_FRAMEWORKS_ROOT = $(HDF_DIR_PREFIX)/framework/model/network/wifi
HDF_WIFI_KHDF_FRAMEWORKS_ROOT = $(HDF_DIR_PREFIX)/adapter/khdf/linux/model/network/wifi
HDF_WIFI_VENDOR_ROOT = $(HDF_VENDOR_PREFIX)/device/hisilicon/drivers/huawei_proprietary/wifi/driver
HDF_FRAMEWORKS_INC := \
-Idrivers/hdf/framework/ability/sbuf/include \
-Idrivers/hdf/framework/core/common/include/host \
-Idrivers/hdf/framework/core/host/include \
-Idrivers/hdf/framework/core/manager/include \
-Idrivers/hdf/framework/core/shared/include \
-Idrivers/hdf/framework/include \
-Idrivers/hdf/framework/include/config \
-Idrivers/hdf/framework/include/core \
-Idrivers/hdf/framework/include/platform \
-Idrivers/hdf/framework/include/utils \
-Idrivers/hdf/framework/support/platform/include \
-Idrivers/hdf/framework/support/platform/include/platform \
-Idrivers/hdf/framework/utils/include \
-Idrivers/hdf/khdf/osal/include \
-Idrivers/hdf/khdf/config/include \
-Iinclude/hdf \
-Iinclude/hdf/osal \
-Iinclude/hdf/utils
HDF_WIFI_FRAMEWORKS_INC := \
-Idrivers/hdf/framework/model/network/wifi/core/compoments/eapol \
-Idrivers/hdf/framework/model/network/wifi/core/compoments/softap \
-Idrivers/hdf/framework/model/network/wifi/core/compoments/sta \
-Idrivers/hdf/framework/model/network/wifi/include \
-Idrivers/hdf/framework/model/network/wifi/core \
-Idrivers/hdf/framework/model/network/wifi/core/module \
-Idrivers/hdf/framework/model/network/common/netdevice \
-Idrivers/hdf/framework/model/network/wifi/platform/include \
-Idrivers/hdf/framework/model/network/wifi/platform/include/message \
-Idrivers/hdf/framework/model/network/wifi/client/include \
-Idrivers/hdf/framework/include/wifi \
-Idrivers/hdf/framework/include/net
HDF_WIFI_ADAPTER_INC := \
-Idrivers/hdf/khdf/network/include
HDF_WIFI_VENDOR_INC := \
-I../../../../../../../../../../../device/hisilicon/drivers/huawei_proprietary/wifi/driver/core
SECURE_LIB_INC := \
-Iinclude/../drivers/hdf/../../../../../../../../../../../../../third_party/bounds_checking_function/include

View File

@ -0,0 +1,131 @@
/*
* hdf_wlan_queue.c
*
* wlan queue of linux
*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include "hdf_wlan_queue.h"
#include "hdf_base.h"
#include "hdf_log.h"
#include "osal_mem.h"
#include "osal_mutex.h"
typedef struct {
HdfWlanQueue base;
OSAL_DECLARE_MUTEX(lock);
uint16_t elementCount;
uint16_t maxElements;
uint16_t tailIndex;
uint16_t headIndex;
void *elements[0];
} HdfWlanQueueImpl;
#define MAX_QUEUE_SIZE 30000
HdfWlanQueue *CreateQueue(uint16_t maxQueueSize)
{
int32_t ret;
HdfWlanQueueImpl *impl = NULL;
if (maxQueueSize > MAX_QUEUE_SIZE) {
HDF_LOGE("%s:Max queue size is %d", __func__, MAX_QUEUE_SIZE);
return NULL;
}
impl = OsalMemCalloc(sizeof(HdfWlanQueueImpl) + (sizeof(void *) * maxQueueSize));
if (impl == NULL) {
HDF_LOGE("%s:oom", __func__);
return NULL;
}
impl->maxElements = maxQueueSize;
ret = OsalMutexInit(&impl->lock);
if (ret != HDF_SUCCESS) {
OsalMemFree(impl);
return NULL;
}
return (HdfWlanQueue*)impl;
}
void DestroyQueue(HdfWlanQueue *queue)
{
int32_t ret;
HdfWlanQueueImpl *impl = (HdfWlanQueueImpl *)queue;
if (queue == NULL) {
return;
}
ret = OsalMutexDestroy(&impl->lock);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: OsalSpinDestroy failed!ret=%d", __func__, ret);
}
OsalMemFree(impl);
}
void *PopQueue(HdfWlanQueue *queue)
{
int32_t ret;
HdfWlanQueueImpl *impl = (HdfWlanQueueImpl *)queue;
void *result = NULL;
if (queue == NULL) {
return;
}
ret = OsalMutexLock(&impl->lock);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s:Get lock failed!ret=%d", __func__, ret);
return NULL;
}
do {
if (impl->elementCount > 0) {
uint16_t headIndex = impl->headIndex;
result = impl->elements[headIndex++];
impl->headIndex = ((headIndex >= impl->maxElements) ? 0 : headIndex);
impl->elementCount--;
}
} while (false);
ret = OsalMutexUnlock(&impl->lock);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s:Release lock failed!ret=%d", __func__, ret);
}
return result;
}
int32_t PushQueue(HdfWlanQueue *queue, void *context)
{
int32_t ret;
HdfWlanQueueImpl *impl = (HdfWlanQueueImpl *)queue;
if (queue == NULL) {
return HDF_FAILURE;
}
ret = OsalMutexLock(&impl->lock);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s:Get lock failed!ret=%d", __func__, ret);
return HDF_FAILURE;
}
do {
if (impl->elementCount >= impl->maxElements) {
HDF_LOGE("%s:queue full!", __func__);
ret = HDF_FAILURE;
break;
}
uint16_t tailIndex = impl->tailIndex;
/* Saves the address of the element in the queue */
impl->elements[tailIndex++] = context;
impl->tailIndex = ((tailIndex >= impl->maxElements) ? 0 : tailIndex);
impl->elementCount++;
} while (false);
ret = OsalMutexUnlock(&impl->lock);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s:Release lock failed!ret=%d", __func__, ret);
}
return ret;
}

37
model/network/wifi/vendor/Makefile vendored Executable file
View File

@ -0,0 +1,37 @@
#
# Copyright (c) 2020-2021 Huawei Device Co., Ltd.
#
# This software is licensed under the terms of the GNU General Public
# License version 2, as published by the Free Software Foundation, and
# may be copied, distributed, and modified under those terms.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
MODULE_NAME := hdf_vendor_wifi
HDF_VENDOR_PREFIX := ../../../../../../../../
include drivers/hdf/khdf/model/network/wifi/hdfwifi.mk
obj-$(CONFIG_DRIVERS_HDF_WIFI) += $(MODULE_NAME).o
$(MODULE_NAME)-objs := $(HDF_WIFI_VENDOR_ROOT)/core/hdf_wlan_sdio_adapt.o
ccflags-$(CONFIG_DRIVERS_HDF_WIFI) += \
$(HDF_FRAMEWORKS_INC) \
$(HDF_WIFI_FRAMEWORKS_INC) \
$(HDF_WIFI_ADAPTER_INC) \
$(HDF_WIFI_VENDOR_INC) \
$(SECURE_LIB_INC)
HDF_WIFI_FLAGS +=-D_PRE_OS_VERSION_LINUX=1
HDF_WIFI_FLAGS +=-D_PRE_OS_VERSION_LITEOS=2
HDF_WIFI_FLAGS +=-D_PRE_OS_VERSION=_PRE_OS_VERSION_LINUX
ccflags-$(CONFIG_DRIVERS_HDF_WIFI) += $(HDF_WIFI_FLAGS)
obj-$(CONFIG_DRIVERS_HI3881) += hi3881/

117
model/network/wifi/vendor/hi3881/Makefile vendored Executable file
View File

@ -0,0 +1,117 @@
#
# Copyright (c) 2020-2021 Huawei Device Co., Ltd.
#
# This software is licensed under the terms of the GNU General Public
# License version 2, as published by the Free Software Foundation, and
# may be copied, distributed, and modified under those terms.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
MODULE_NAME := hi3881
HDF_VENDOR_PREFIX := ../../../../../../../../../
include drivers/hdf/khdf/model/network/wifi/hdfwifi.mk
INC_TOP_PATH := ../../../../../../../../../../../
VENDOR_WIFI_PATH := device/hisilicon/drivers/huawei_proprietary/wifi/driver
WIFI_DRIVER_DIR := hi3881
##################path of compile file :start###############
#####wifi#####
OAL_PATH := $(HDF_WIFI_VENDOR_ROOT)/$(WIFI_DRIVER_DIR)/oal/
OAM_PATH := $(HDF_WIFI_VENDOR_ROOT)/$(WIFI_DRIVER_DIR)/oam/
FRW_PATH := $(HDF_WIFI_VENDOR_ROOT)/$(WIFI_DRIVER_DIR)/frw/
MAC_PATH := $(HDF_WIFI_VENDOR_ROOT)/$(WIFI_DRIVER_DIR)/mac/common/
HMAC_PATH := $(HDF_WIFI_VENDOR_ROOT)/$(WIFI_DRIVER_DIR)/mac/hmac/
HCC_PATH := $(HDF_WIFI_VENDOR_ROOT)/$(WIFI_DRIVER_DIR)/hcc/
WAL_PATH := $(HDF_WIFI_VENDOR_ROOT)/$(WIFI_DRIVER_DIR)/wal/
ADPATER_PATH := $(HDF_WIFI_VENDOR_ROOT)/$(WIFI_DRIVER_DIR)/hdfadapt/
##################path of compile file :end###############
ccflags-$(CONFIG_DRIVERS_HDF_WIFI) += \
$(HDF_FRAMEWORKS_INC) \
$(HDF_WIFI_FRAMEWORKS_INC) \
$(HDF_WIFI_ADAPTER_INC) \
$(HDF_WIFI_VENDOR_INC) \
-I$(INC_TOP_PATH)/$(VENDOR_WIFI_PATH)/$(WIFI_DRIVER_DIR)/linuxkpi/include \
$(SECURE_LIB_INC)
include drivers/hdf/khdf/model/network/wifi/vendor/hi3881/env_config.mk
HI1131_HOST_CFLAGS += -Wextra -fsigned-char -fno-strict-aliasing -Wdate-time \
-Wformat=2 -Wshadow -fvisibility=hidden -fno-common -fstack-protector-strong
HI1131_HOST_CFLAGS += -Wall
HI1131_HOST_CFLAGS += $(HI1131_WIFI_CFLAGS)
obj-$(CONFIG_DRIVERS_HI3881) += $(MODULE_NAME).o
####################################### platform module start #########################################
oal-objs := oal_util.o oal_net.o oal_main.o oal_mem.o
oal-objs += oal_cfg80211.o oal_sdio_host.o oal_kernel_file.o exception_rst.o \
plat_firmware.o plat_pm.o plat_pm_wlan.o plat_sdio.o oal_chr.o
oal-objs := $(addprefix $(OAL_PATH),$(oal-objs))
adapter-objs := hdfinit_3881.o net_adpater.o hdf_driver_register.o
adapter-objs := $(addprefix $(ADPATER_PATH),$(adapter-objs))
oam-objs := oam_main.o oam_log.o
oam-objs := $(addprefix $(OAM_PATH),$(oam-objs))
board-objs := plat_board_common_sdio.o
board-objs := $(addprefix $(OAL_PATH),$(board-objs))
frw-objs += frw_event.o frw_event_sched.o frw_main.o frw_task.o frw_timer.o
frw-objs := $(addprefix $(FRW_PATH),$(frw-objs))
plat-objs = $(oal-objs) $(oam-objs) $(board-objs) $(frw-objs) $(adapter-objs)
####################################### platform module end #########################################
####################################### wifi module start #########################################
hmac-objs := hmac_11i.o hmac_blockack.o hmac_chan_mgmt.o hmac_config.o hmac_crypto_tkip.o hmac_event.o hmac_uapsd.o \
hmac_device.o hmac_encap_frame.o hmac_encap_frame_ap.o hmac_encap_frame_sta.o hmac_frag.o hmac_fsm.o \
hmac_mgmt_ap.o hmac_mgmt_bss_comm.o hmac_mgmt_classifier.o hmac_mgmt_sta.o hmac_protection.o hmac_user.o \
hmac_rx_data.o hmac_tx_data.o hmac_rx_filter.o hmac_scan.o hmac_sme_sta.o hmac_tx_amsdu.o hmac_vap.o \
hmac_main.o
ifeq ($(CFG_EDCA_OPT_AP), y)
hmac-objs += hmac_edca_opt.o
endif
ifeq ($(CFG_TCP_OPT), y)
hmac-objs += hmac_tcp_opt.o
endif
ifeq ($(CFG_TX_CLASSIFY_LAN_TO_WLAN), y)
hmac-objs += hmac_traffic_classify.o
endif
ifeq ($(CFG_WOW), y)
hmac-objs += hmac_wow.o
endif
ifeq ($(CFG_ANY), y)
hmac-objs += hmac_any.o
endif
ifeq ($(CFG_WAPI), y)
hmac-objs += hmac_wapi.o hmac_wapi_wpi.o hmac_wapi_sms4.o
endif
hmac-objs := $(addprefix $(HMAC_PATH),$(hmac-objs))
wal-objs := wal_customize.o wal_cfg80211.o wal_11d.o wal_hipriv.o wal_event_msg.o hi_wifi_driver_api.o wal_linux_flowctl.o wal_ioctl.o wal_event.o wal_scan.o wal_main.o wal_regdb.o wal_mac80211.o
wal-objs := $(addprefix $(WAL_PATH),$(wal-objs))
mac-objs := mac_data.o mac_device.o mac_frame.o mac_ie.o mac_user.o mac_vap.o mac_mib.o mac_resource.o mac_regdomain.o mac_pm_driver.o
mac-objs := $(addprefix $(MAC_PATH),$(mac-objs))
hcc-objs := hcc_comm.o hcc_task.o hcc_host.o hcc_hmac.o hmac_hcc_adapt.o
hcc-objs := $(addprefix $(HCC_PATH),$(hcc-objs))
wifi-objs += $(mac-objs) $(hmac-objs) $(wal-objs) $(hcc-objs)
####################################### wifi module end #########################################
$(MODULE_NAME)-objs := $(wifi-objs) $(plat-objs)
ccflags-$(CONFIG_DRIVERS_HI3881) += $(HI1131_HOST_CFLAGS)

View File

@ -0,0 +1,299 @@
#
# Copyright (c) 2020-2021 Huawei Device Co., Ltd.
#
# This software is licensed under the terms of the GNU General Public
# License version 2, as published by the Free Software Foundation, and
# may be copied, distributed, and modified under those terms.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
#####################################WiFi config######################################
CFG_ANTI_INTERF = y
CFG_CCA_OPT = y
CFG_DBAC = y
CFG_EDCA_OPT = y
CFG_EDCA_OPT_AP = y
CFG_SCHEDULE = y
CFG_TRAFFIC_CTL = n
CFG_TPC = y
CFG_RF_1102CALI = y
CFG_RF_110X_CALI_DPD = n
CFG_NEW_IQ = y
CFG_ALG_CFG = n
CFG_HCC_TASK = y
########################flash cut begin########################
######## CFG_XXX_ROM can't be set to n ########
CFG_P2P = n
CFG_P2P_ROM = y
CFG_WAPI = n
CFG_WAPI_ROM = y
CFG_WOW = y
CFG_WOW_ROM = y
CFG_REKEY_OFFLOAD = n
CFG_REKEY_OFFLOAD_ROM = y
CFG_PROMIS = y
CFG_PROMIS_ROM = y
CFG_MFG_TEST = y
CFG_CE_MODE = y
CFG_FCC_MODE = n
CFG_MFG_FW = n
########################flash cut end##########################
CFG_BTCOEX_ROM = y
CFG_ANY = n
CFG_STA_PM = y
CFG_MESH = n
CFG_TCP_OPT = n
CFG_TX_CLASSIFY_LAN_TO_WLAN = n
CFG_UAPSD = y
CFG_ARP_OFFLOAD = y
CFG_DHCP_OFFLOAD = y
CFG_LITEOS = n
CFG_SIGMA = y
CFG_HIPRIV = y
######################################################################################
HI1131_WIFI_CFLAGS +=-D_PRE_OS_VERSION_LINUX=1
HI1131_WIFI_CFLAGS +=-D_PRE_OS_VERSION_LITEOS=2
ifeq ($(CFG_LITEOS), y)
HI1131_WIFI_CFLAGS +=-D_PRE_OS_VERSION=_PRE_OS_VERSION_LITEOS
else
HI1131_WIFI_CFLAGS +=-D_PRE_OS_VERSION=_PRE_OS_VERSION_LINUX
endif
HI1131_WIFI_CFLAGS +=-D_PRE_HDF_LINUX
HI1131_WIFI_CFLAGS +=-D_PRE_FRW_FEATURE_PROCESS_ENTITY_THREAD=0
HI1131_WIFI_CFLAGS +=-D_PRE_FRW_FEATURE_PROCESS_ENTITY_TASKLET=1
HI1131_WIFI_CFLAGS +=-D_PRE_FRW_FEATURE_PROCESS_ENTITY_TYPE=_PRE_FRW_FEATURE_PROCESS_ENTITY_THREAD
#######################################HI1131#########################################
HI1131_WIFI_CFLAGS +=-D_PRE_MULTI_CORE_MODE_SMP=1
HI1131_WIFI_CFLAGS +=-D_PRE_MULTI_CORE_MODE_OFFLOAD_HMAC=2
HI1131_WIFI_CFLAGS +=-D_PRE_MULTI_CORE_MODE_OFFLOAD_DMAC=3
ifeq ($(LOSCFG_COMPILER_HI3861_FLASH), y)
HI1131_WIFI_CFLAGS +=-D_PRE_MULTI_CORE_MODE=_PRE_MULTI_CORE_MODE_SMP
else
HI1131_WIFI_CFLAGS +=-D_PRE_MULTI_CORE_MODE=_PRE_MULTI_CORE_MODE_OFFLOAD_DMAC
endif
HI1131_WIFI_CFLAGS +=-D_PRE_BIG_CPU_ENDIAN=0
HI1131_WIFI_CFLAGS +=-D_PRE_LITTLE_CPU_ENDIAN=1
HI1131_WIFI_CFLAGS +=-D_PRE_CPU_ENDIAN=_PRE_LITTLE_CPU_ENDIAN
HI1131_WIFI_CFLAGS +=-D_HI_BOARD_FPGA=1
HI1131_WIFI_CFLAGS +=-D_HI_BOARD_ASIC=2
ifeq ($(LOSCFG_COMPILER_HI3861_ASIC), y)
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_CHIP_VERSION=_HI_BOARD_ASIC
else
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_CHIP_VERSION=_HI_BOARD_FPGA
endif
ifeq ($(QUICK_START),y)
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_QUICK_START
endif
ifeq ($(NO_32K),y)
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_NO_32K
endif
ifeq ($(BOARD_FUNC), DG)
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FPGA_DIGITAL
endif
################################################################################
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_PMF
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_AUTORATE
ifeq ($(CFG_SCHEDULE), y)
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_SCHEDULE
endif
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_PERFORM_TPC
ifeq ($(CFG_TPC), y)
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_TPC
endif
ifeq ($(CFG_DBAC), y)
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_DBAC
endif
HI1131_WIFI_CFLAGS +=-D_PRE_DBAC_DYNAMIC_POLICY
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_AGGR_OPTIMIZE
ifeq ($(CFG_CCA_OPT), y)
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_CCA_OPT
endif
ifeq ($(CFG_EDCA_OPT), y)
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_EDCA_OPT
endif
ifeq ($(CFG_EDCA_OPT_AP), y)
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_EDCA_OPT_AP
endif
ifeq ($(CFG_ANTI_INTERF), y)
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_ANTI_INTERF
endif
ifeq ($(CFG_TRAFFIC_CTL), y)
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_TRAFFIC_CTL
endif
ifeq ($(CFG_ALG_CFG),y)
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_ALG_CFG
endif
ifeq ($(CFG_ALG_INTRF_MODE),y)
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_INTRF_MODE
endif
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_ALG_CFG_ROM
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_FLOWCTRL
ifeq ($(CFG_TX_CLASSIFY_LAN_TO_WLAN), y)
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_TX_CLASSIFY_LAN_TO_WLAN
endif
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_CLASSIFY
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_ALWAYS_TX
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_WPA
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_WPA2
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_AMPDU
ifeq ($(CFG_ARP_OFFLOAD), y)
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_ARP_OFFLOAD
endif
ifeq ($(CFG_DHCP_OFFLOAD), y)
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_DHCP_OFFLOAD
endif
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_DHCP_OFFLOAD_ROM
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_PKT_MEM_OPT
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_PM_FEATURE_FORCESLP_RESUME
HI1131_WIFI_CFLAGS +=-D__BITS_PER_OAL_LONG=32
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_11D
ifeq ($(CFG_NEW_IQ), y)
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_NEW_IQ
endif
ifeq ($(CFG_P2P), y)
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_P2P
endif
ifeq ($(CFG_P2P_ROM), y)
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_P2P_ROM
endif
ifeq ($(CFG_ANY), y)
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_ANY
endif
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_ANY_ROM
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_CSI
ifeq ($(CFG_STA_PM), y)
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_STA_PM
endif
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_STA_UAPSD
ifeq ($(CFG_MESH), y)
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_MESH
endif
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_MESH_ROM
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_BW_HIEX
ifeq ($(CFG_BTCOEX), y)
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_BTCOEX
endif
ifeq ($(CFG_BTCOEX_ROM), y)
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_BTCOEX_ROM
endif
#HI1131_WIFI_CFLAGS +=-D_PRE_PSM_DEBUG_MODE
ifeq ($(CFG_RF_110X_CALI_DPD), y)
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_RF_110X_CALI_DPD
endif
ifeq ($(CFG_RF_1102CALI), y)
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_RF_1102CALI
endif
ifeq ($(CFG_UAPSD), y)
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_UAPSD
endif
ifeq ($(CFG_WAPI), y)
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_WAPI
endif
ifeq ($(CFG_WAPI_ROM), y)
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_WAPI_ROM
endif
ifeq ($(CFG_TCP_OPT), y)
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_TCP_OPT
endif
HI1131_WIFI_CFLAGS +=-D_PRE_XTAL_FREQUENCY_COMPESATION_ENABLE
################################SDIO MMC CONFIG#############################
HI1131_WIFI_CFLAGS +=-DCONFIG_MMC
HI1131_WIFI_CFLAGS +=-DCONFIG_PRINTK
HI1131_WIFI_CFLAGS +=-D_PRE_FEATURE_NO_GPIO
ifeq ($(CFG_REKEY_OFFLOAD), y)
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_REKEY_OFFLOAD
endif
ifeq ($(CFG_REKEY_OFFLOAD_ROM), y)
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_REKEY_OFFLOAD_ROM
endif
ifeq ($(CFG_WOW), y)
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_WOW
endif
ifeq ($(CFG_WOW_ROM), y)
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_WOW_ROM
endif
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_HILINK
ifeq ($(CFG_PROMIS), y)
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_PROMIS
endif
ifeq ($(CFG_PROMIS_ROM), y)
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_PROMIS_ROM
endif
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_SMARTCONFIG_APP
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_TEMP_PROTECT
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_SINGLE_DEVICE
ifeq ($(CFG_SIGMA), y)
#sigma tool support
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_SIGMA
endif
ifeq ($(CFG_MFG_TEST), y)
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_MFG_TEST
endif
ifeq ($(CFG_MFG_FW), y)
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_MFG_FW
endif
ifeq ($(CFG_CE_MODE), y)
HI1131_WIFI_CFLAGS +=-D_PRE_CE_INITIAL_PARAMS_MODE
endif
ifeq ($(CFG_FCC_MODE), y)
HI1131_WIFI_CFLAGS +=-D_PRE_FCC_INITIAL_PARAMS_MODE
endif
ifeq ($(CFG_HIPRIV), y)
#sdv test support
HI1131_WIFI_CFLAGS +=-D_PRE_WLAN_FEATURE_HIPRIV
ifeq ($(CFG_LITEOS), n)
HI1131_WIFI_CFLAGS +=-D_PRE_CONFIG_CONN_HISI_SYSFS_SUPPORT
else
HI1131_WIFI_CFLAGS +=-DAT_DEBUG_CMD_SUPPORT
endif
endif
################################WAIT MODIFIED SDIO##############################
HI1131_WIFI_CFLAGS +=-D_PRE_FEATURE_SDIO=1
HI1131_WIFI_CFLAGS +=-D_PRE_FEATURE_USB=2
HI1131_WIFI_CFLAGS +=-D_PRE_FEATURE_CHANNEL_TYPE=_PRE_FEATURE_SDIO
HI1131_WIFI_CFLAGS +=-DCONFIG_HI110X_SDIO_STD_CARD_SUPPORT
################################HCC_TASK##############################
ifeq ($(CFG_HCC_TASK), y)
HI1131_WIFI_CFLAGS +=-D_PRE_FEATURE_HCC_TASK
endif
################################WIFI_DRIVER_DIR##############################
HI1131_WIFI_CFLAGS += -I$(INC_TOP_PATH)/$(VENDOR_WIFI_PATH)/$(WIFI_DRIVER_DIR)/wal
HI1131_WIFI_CFLAGS += -I$(INC_TOP_PATH)/$(VENDOR_WIFI_PATH)/$(WIFI_DRIVER_DIR)/oam
HI1131_WIFI_CFLAGS += -I$(INC_TOP_PATH)/$(VENDOR_WIFI_PATH)/$(WIFI_DRIVER_DIR)/mac/hmac
HI1131_WIFI_CFLAGS += -I$(INC_TOP_PATH)/$(VENDOR_WIFI_PATH)/$(WIFI_DRIVER_DIR)/mac/common
HI1131_WIFI_CFLAGS += -I$(INC_TOP_PATH)/$(VENDOR_WIFI_PATH)/$(WIFI_DRIVER_DIR)/hcc
HI1131_WIFI_CFLAGS += -I$(INC_TOP_PATH)/$(VENDOR_WIFI_PATH)/$(WIFI_DRIVER_DIR)/frw
HI1131_WIFI_CFLAGS += -I$(INC_TOP_PATH)/$(VENDOR_WIFI_PATH)/$(WIFI_DRIVER_DIR)/oal
HI1131_WIFI_CFLAGS += -I$(INC_TOP_PATH)/$(VENDOR_WIFI_PATH)/$(WIFI_DRIVER_DIR)/include
################################device##############################
HI1131_WIFI_CFLAGS += -I$(INC_TOP_PATH)/$(VENDOR_WIFI_PATH)/$(WIFI_DRIVER_DIR)/hdfadapt
ifeq ($(LOSCFG_PLATFORM_HI3516EV300), y)
HI1131_WIFI_CFLAGS +=-DHISI_WIFI_PLATFORM_HI3516EV300
endif

30
model/sensor/Kconfig Normal file
View File

@ -0,0 +1,30 @@
# Copyright (c) 2021 Huawei Device Co., Ltd.
#
# This software is licensed under the terms of the GNU General Public
# License version 2, as published by the Free Software Foundation, and
# may be copied, distributed, and modified under those terms.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
config DRIVERS_HDF_SENSOR
bool "Enable HDF sensor driver"
default n
depends on DRIVERS_HDF
help
Answer Y to enable HDF sensor driver.
config DRIVERS_HDF_SENSOR_ACCEL
bool "Enable HDF accel sensor driver"
default n
depends on DRIVERS_HDF_SENSOR
help
Answer Y to enable HDF accel sensor driver.
config DRIVERS_HDF_SENSOR_GYRO
bool "Enable HDF gyro sensor driver"
default n
depends on DRIVERS_HDF_SENSOR
help
Answer Y to enable HDF gyro sensor driver.

40
model/sensor/Makefile Normal file
View File

@ -0,0 +1,40 @@
# Copyright (c) 2021 Huawei Device Co., Ltd.
#
# This software is licensed under the terms of the GNU General Public
# License version 2, as published by the Free Software Foundation, and
# may be copied, distributed, and modified under those terms.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
SEC_LIB_SOURCES = memcpy_s.c memmove_s.c memset_s.c securecutil.c secureinput_a.c secureprintoutput_a.c snprintf_s.c sprintf_s.c strcat_s.c strcpy_s.c strncat_s.c strncpy_s.c strtok_s.c vsnprintf_s.c vsprintf_s.c
PWD:=$(shell pwd)
SEC_OBJECTS:=$(patsubst %.c,%.o,$(SEC_LIB_SOURCES))
SENSOR_ROOT_DIR = ../../../../../framework/model/sensor/driver
obj-$(CONFIG_DRIVERS_HDF_SENSOR) += \
$(SENSOR_ROOT_DIR)/common/src/sensor_common.o \
$(SENSOR_ROOT_DIR)/common/src/sensor_device_common.o \
$(SENSOR_ROOT_DIR)/common/src/sensor_device_manager.o \
$(SENSOR_ROOT_DIR)/common/src/sensor_parser.o
obj-$(CONFIG_DRIVERS_HDF_SENSOR_ACCEL) += $(SENSOR_ROOT_DIR)/accel/sensor_accel_driver.o \
$(SENSOR_ROOT_DIR)/chipset/accel/accel_bmi160.o
ccflags-y += -Idrivers/hdf/framework/model/sensor/driver/include \
-Idrivers/hdf/framework/model/sensor/driver/common/include \
-Idrivers/hdf/framework/model/sensor/driver/chipset/accel \
-Idrivers/hdf/framework/model/sensor/driver/accel \
-Idrivers/hdf/framework/include/core \
-Idrivers/hdf/framework/core/common/include/host \
-Idrivers/hdf/framework/include/utils \
-Idrivers/hdf/framework/include/osal \
-Idrivers/hdf/framework/ability/sbuf/include \
-Idrivers/hdf/framework/include/platform \
-Idrivers/hdf/framework/include/config \
-Idrivers/hdf/khdf/osal/include \
-Idrivers/hdf/../../../../../../../../../../../../../third_party/bounds_checking_function/include

15
network/Makefile Normal file
View File

@ -0,0 +1,15 @@
#
# Copyright (c) 2020-2021 Huawei Device Co., Ltd.
#
# This software is licensed under the terms of the GNU General Public
# License version 2, as published by the Free Software Foundation, and
# may be copied, distributed, and modified under those terms.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
obj-$(CONFIG_DRIVERS_HDF_WIFI) += src/

View File

@ -0,0 +1,41 @@
/*
* net_device_adapter.h
*
* net device adapter of linux
*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef HDF_NET_DEVICE_ADAPTER_FULL_H
#define HDF_NET_DEVICE_ADAPTER_FULL_H
#include <linux/netdevice.h>
#include <uapi/linux/if.h>
#include "net_device_impl.h"
/**
* data sending results, just define locked here, ok and busy reference linux definition for enum netdev_tx.
*/
#define NETDEV_TX_LOCKED 0x20
int32_t RegisterNetDeviceImpl(struct NetDeviceImpl *ndImpl);
int32_t UnRegisterNetDeviceImpl(struct NetDeviceImpl *ndImpl);
struct FullNetDevicePriv {
struct net_device *dev;
struct NetDeviceImpl *impl;
};
#endif /* HDF_NET_DEVICE_ADAPTER_FULL_H */

View File

@ -0,0 +1,32 @@
/*
* net_device_types_adapter.h
*
* net device types adapter of linux
*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef HDF_NET_DEVICE_TYPTES_ADAPTER_FULL_H
#define HDF_NET_DEVICE_TYPTES_ADAPTER_FULL_H
#include <linux/netdevice.h>
#include <linux/types.h>
typedef int32_t NetDevTxResult;
/**
* data sending results, just define locked here, ok and busy reference linux definition for enum netdev_tx.
*/
#define NETDEV_TX_LOCKED 0x20
#endif /* HDF_NET_DEVICE_TYPTES_ADAPTER_FULL_H */

View File

@ -0,0 +1,69 @@
/*
* netbuf_adatper.h
*
* net buffer adapter of linux
*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
/**
* @addtogroup WLAN
* @{
*
* @brief Provides cross-OS migration, component adaptation, and modular assembly and compilation.
*
* Based on the unified APIs provided by the WLAN module, developers of the Hardware Driver Interface
* (HDI) are capable of creating, disabling, scanning for, and connecting to WLAN hotspots, managing WLAN chips,
* network devices, and power, and applying for, releasing, and moving network data buffers.
*
* @since 1.0
* @version 1.0
*/
#ifndef _HDF_NETBUF_ADAPTER_H
#define _HDF_NETBUF_ADAPTER_H
#include <linux/skbuff.h>
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif /* __cplusplus */
/**
* @brief Enumerates the segments of a network data buffer.
*
* The entire network data buffer is divided into three segments: a header, data, and a tail.
* The header and tail are used to extend both ends of the data segment.
*
* @since 1.0
*/
enum {
E_HEAD_BUF, /**< Header buffer segment */
E_DATA_BUF, /**< Data segment */
E_TAIL_BUF, /**< Tail buffer segment */
MAX_BUF_NUM /**< Maximum number of buffer segments */
};
typedef struct sk_buff NetBuf;
typedef struct sk_buff_head NetBufQueue;
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */
#endif
/** @} */

25
network/src/Makefile Executable file
View File

@ -0,0 +1,25 @@
#
# Copyright (c) 2020-2021 Huawei Device Co., Ltd.
#
# This software is licensed under the terms of the GNU General Public
# License version 2, as published by the Free Software Foundation, and
# may be copied, distributed, and modified under those terms.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
obj-$(CONFIG_DRIVERS_HDF_WIFI) += net_device_adapter.o netbuf_adapter.o
ccflags-$(CONFIG_DRIVERS_HDF_WIFI) += \
-Idrivers/hdf/framework/model/network/common/netdevice \
-Idrivers/hdf/framework/include/net\
-Idrivers/hdf/khdf/network/include \
-Idrivers/hdf/khdf/osal/include \
-Iinclude/hdf/wifi \
-Iinclude/hdf/utils \
-Iinclude/hdf/osal \
-Iinclude/../drivers/hdf/../../../../../../../../../../../../../third_party/bounds_checking_function/include

View File

@ -0,0 +1,339 @@
/*
* net_device_adapter.c
*
* net device adapter of linux
*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include "net_device_adapter.h"
#include <linux/etherdevice.h>
#include <linux/rtnetlink.h>
#include "net_device.h"
#include "net_device_impl.h"
#include "osal_mem.h"
#include "securec.h"
#define HDF_LOG_TAG NetDeviceFull
static int32_t NetDevXmitCheck(struct sk_buff *skb, struct net_device *dev)
{
struct FullNetDevicePriv *priv = NULL;
if (dev == NULL || skb == NULL) {
HDF_LOGE("%s : dev = NUll or skb = NULL!", __func__);
return HDF_ERR_INVALID_PARAM;
}
priv = (struct FullNetDevicePriv *)netdev_priv(dev);
if (priv == NULL || priv->dev == NULL || priv->impl == NULL) {
HDF_LOGE("%s fail : priv NULL!", __func__);
return HDF_ERR_INVALID_PARAM;
}
return HDF_SUCCESS;
}
static netdev_tx_t NetDevXmit(struct sk_buff *skb, struct net_device *dev)
{
struct FullNetDevicePriv *priv = NULL;
struct NetDevice *netDev = NULL;
struct NetDeviceInterFace *netDevIf = NULL;
if (NetDevXmitCheck(skb, dev) != HDF_SUCCESS) {
NetBufFree(skb);
return NETDEV_TX_OK;
}
priv = (struct FullNetDevicePriv *)netdev_priv(dev);
netDev = priv->impl->netDevice;
skb->dev = (struct net_device *)netDev;
netDevIf = netDev->netDeviceIf;
if (netDevIf != NULL && netDevIf->xmit != NULL) {
netDevIf->xmit(netDev, skb);
} else {
HDF_LOGE("%s fail : netdevIf = null or xmit = null!", __func__);
NetBufFree(skb);
}
return NETDEV_TX_OK;
}
static int NetDevChangeMtu(struct net_device *dev, int mtu)
{
if (mtu > WLAN_MAX_MTU || mtu < WLAN_MIN_MTU || dev == NULL) {
return -EINVAL;
}
dev->mtu = (uint32_t)mtu;
return HDF_SUCCESS;
}
static int NetDevOpen(struct net_device *dev)
{
if (dev == NULL) {
return -EINVAL;
}
netif_start_queue(dev);
return HDF_SUCCESS;
}
static int NetDevStop(struct net_device *dev)
{
if (dev == NULL) {
return -EINVAL;
}
netif_stop_queue(dev);
return HDF_SUCCESS;
}
static struct net_device_ops g_netDeviceOps = {
.ndo_start_xmit = NetDevXmit,
.ndo_change_mtu = NetDevChangeMtu,
.ndo_open = NetDevOpen,
.ndo_stop = NetDevStop
};
static struct net_device *CreateNetDevice(const struct NetDevice *hdfDev)
{
struct net_device *dev = NULL;
dev = alloc_etherdev(sizeof(struct FullNetDevicePriv));
if (dev == NULL) {
return NULL;
}
if (memcpy_s(dev->name, IFNAMSIZ, hdfDev->name, IFNAMSIZ) != EOK) {
free_netdev(dev);
return NULL;
}
dev->mtu = DEFAULT_MTU;
dev->netdev_ops = &g_netDeviceOps;
return dev;
}
static void DestroyNetDevice(struct net_device *dev)
{
free_netdev(dev);
}
static struct net_device *GetDevFromDevImpl(const struct NetDeviceImpl *impl)
{
struct FullNetDevicePriv *priv = NULL;
if (impl == NULL || impl->osPrivate == NULL) {
return NULL;
}
priv = (struct FullNetDevicePriv *)impl->osPrivate;
return priv->dev;
}
static int32_t NetDevInit(struct NetDeviceImpl *impl)
{
struct FullNetDevicePriv *priv = NULL;
struct net_device *dev = NULL;
if (impl == NULL || impl->netDevice == NULL) {
HDF_LOGE("%s fail: impl null , netDevice null", __func__);
return HDF_ERR_INVALID_PARAM;
}
dev = CreateNetDevice(impl->netDevice);
if (dev == NULL) {
HDF_LOGE("%s fail : CreateNetDevice fail!", __func__);
return HDF_FAILURE;
}
priv = (struct FullNetDevicePriv *)netdev_priv(dev);
priv->dev = dev;
priv->impl = impl;
impl->osPrivate = (void *)priv;
HDF_LOGI("%s Success!", __func__);
return HDF_SUCCESS;
}
static int32_t NetDevDeInit(struct NetDeviceImpl *impl)
{
struct FullNetDevicePriv *priv = NULL;
if (impl == NULL) {
HDF_LOGE("netdevice linux deinit already free.");
return HDF_SUCCESS;
}
if (impl->osPrivate != NULL) {
priv = (struct FullNetDevicePriv *)impl->osPrivate;
DestroyNetDevice(priv->dev);
impl->osPrivate = NULL;
}
HDF_LOGI("net device linux deinit success!");
return HDF_SUCCESS;
}
static int32_t NetDevAdd(struct NetDeviceImpl *impl,
Protocol80211IfType ifType)
{
struct net_device *dev = NULL;
int ret = 0;
if ((dev = GetDevFromDevImpl(impl)) == NULL) {
return HDF_ERR_INVALID_PARAM;
}
if (impl->netDevice == NULL) {
return HDF_ERR_INVALID_PARAM;
}
if (memcpy_s(dev->dev_addr, ETH_ALEN, impl->netDevice->macAddr,
MAC_ADDR_SIZE) != EOK) {
HDF_LOGE("%s : memcpy fail!", __func__);
return HDF_ERR_INVALID_PARAM;
}
dev->needed_headroom = impl->netDevice->neededHeadRoom;
dev->needed_tailroom = impl->netDevice->neededTailRoom;
if ((ret = register_netdev(dev)) < 0) {
HDF_LOGE("%s : register_netdev fail!,ret=%d", __func__, ret);
return HDF_FAILURE;
}
HDF_LOGI("%s success!!", __func__);
return HDF_SUCCESS;
}
static int32_t NetDevDelete(struct NetDeviceImpl *impl)
{
struct FullNetDevicePriv *priv = NULL;
struct net_device *dev = NULL;
if (impl == NULL || impl->osPrivate == NULL) {
HDF_LOGE("%s fail : impl = null or osPrivate = null!", __func__);
return HDF_ERR_INVALID_PARAM;
}
priv = (struct FullNetDevicePriv *)impl->osPrivate;
dev = priv->dev;
if (dev != NULL) {
unregister_netdev(dev);
}
HDF_LOGI("%s success!", __func__);
return HDF_SUCCESS;
}
static int32_t NetDevSetStatus(struct NetDeviceImpl *impl,
NetIfStatus status)
{
struct net_device *dev = GetDevFromDevImpl(impl);
int32_t ret;
if (dev == NULL) {
HDF_LOGE("%s fail : net dev null!", __func__);
return HDF_ERR_INVALID_PARAM;
}
rtnl_lock();
if (status == NETIF_DOWN) {
dev_close(dev);
ret = HDF_SUCCESS;
} else if (status == NETIF_UP) {
ret = dev_open(dev);
} else {
HDF_LOGE("%s fail : status error!", __func__);
rtnl_unlock();
return HDF_ERR_INVALID_PARAM;
}
rtnl_unlock();
if (!ret) {
return HDF_SUCCESS;
}
HDF_LOGE("%s fail ret = %d!", __func__, ret);
return HDF_FAILURE;
}
static int32_t NetDevReceive(struct NetDeviceImpl *impl,
NetBuf *buff, ReceiveFlag flag)
{
struct net_device *dev = GetDevFromDevImpl(impl);
if (dev == NULL) {
HDF_LOGE("%s fail : dev = null!", __func__);
return HDF_ERR_INVALID_PARAM;
}
if (flag >= MAX_RECEIVE_FLAG || buff == NULL) {
HDF_LOGE("%s fail : flag = %d or buff = null!", __func__, flag);
return HDF_ERR_INVALID_PARAM;
}
buff->dev = dev;
buff->protocol = eth_type_trans(buff, dev);
if (flag & IN_INTERRUPT) {
netif_rx(buff);
} else {
netif_rx_ni(buff);
}
return HDF_SUCCESS;
}
int32_t NetDevChangeMacAddr(struct NetDeviceImpl *impl)
{
struct net_device *dev = NULL;
if ((dev = GetDevFromDevImpl(impl)) == NULL) {
return HDF_ERR_INVALID_PARAM;
}
if (impl->netDevice == NULL) {
return HDF_ERR_INVALID_PARAM;
}
if (memcpy_s(dev->dev_addr, ETH_ALEN, impl->netDevice->macAddr, MAC_ADDR_SIZE) != EOK) {
HDF_LOGE("%s : memcpy fail!", __func__);
return HDF_ERR_INVALID_PARAM;
}
return HDF_SUCCESS;
}
static struct NetDeviceImplOp g_ndImplOps = {
.init = NetDevInit,
.deInit = NetDevDeInit,
.add = NetDevAdd,
.delete = NetDevDelete,
.setStatus = NetDevSetStatus,
.receive = NetDevReceive,
.changeMacAddr = NetDevChangeMacAddr,
};
int32_t RegisterNetDeviceImpl(struct NetDeviceImpl *ndImpl)
{
if (ndImpl == NULL) {
HDF_LOGE("%s fail : impl = null!", __func__);
return HDF_ERR_INVALID_PARAM;
}
ndImpl->interFace = &g_ndImplOps;
HDF_LOGI("register full netdevice impl success.");
return HDF_SUCCESS;
}
int32_t UnRegisterNetDeviceImpl(struct NetDeviceImpl *ndImpl)
{
if (ndImpl == NULL) {
HDF_LOGI("%s already unregister!", __func__);
return HDF_SUCCESS;
}
ndImpl->interFace = NULL;
HDF_LOGI("%s success.", __func__);
return HDF_SUCCESS;
}

View File

@ -0,0 +1,441 @@
/*
* netbuf_adapter.h
*
* net buffer adapter of linux
*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include "netbuf_adapter.h"
#include "hdf_base.h"
#include "hdf_netbuf.h"
#include "securec.h"
/**
* @brief Initializes a network data buffer queue.
*
* @param q Indicates the pointer to the network data buffer queue.
*
* @since 1.0
*/
void NetBufQueueInit(NetBufQueue *q)
{
skb_queue_head_init(q);
}
/**
* @brief Obtains the size of a network data buffer queue.
*
* @param q Indicates the pointer to the network data buffer queue.
*
* @return Returns the size of the network data buffer queue.
*
* @since 1.0
*/
uint32_t NetBufQueueSize(const NetBufQueue *q)
{
return skb_queue_len(q);
}
/**
* @brief Checks whether the network data buffer queue is empty.
*
* @param q Indicates the pointer to the network data buffer queue.
*
* @return Returns <b>true</b> if the queue is empty; returns <b>false</b> otherwise.
*
* @since 1.0
*/
bool NetBufQueueIsEmpty(const NetBufQueue *q)
{
return skb_queue_empty(q);
}
/**
* @brief Adds a network data buffer to the tail of a queue.
*
* @param q Indicates the pointer to the network data buffer queue.
* @param nb Indicates the pointer to the network data buffer.
*
* @since 1.0
*/
void NetBufQueueEnqueue(NetBufQueue *q, NetBuf *nb)
{
skb_queue_tail(q, nb);
}
/**
* @brief Adds a network data buffer to the header of a queue.
*
* @param q Indicates the pointer to the network data buffer queue.
* @param nb Indicates the pointer to the network data buffer.
*
* @since 1.0
*/
void NetBufQueueEnqueueHead(NetBufQueue *q, NetBuf *nb)
{
skb_queue_head(q, nb);
}
/**
* @brief Obtains a network data buffer from the header of a queue and deletes it from the queue.
*
* @param q Indicates the pointer to the network data buffer queue.
*
* @return Returns the pointer to the first network data buffer if the queue is not empty;
* returns <b>NULL</b> otherwise.
*
* @since 1.0
*/
NetBuf *NetBufQueueDequeue(NetBufQueue *q)
{
return skb_dequeue(q);
}
/**
* @brief Obtains a network data buffer from the tail of a queue and deletes it from the queue.
*
* @param q Indicates the pointer to the network data buffer queue.
*
* @return Returns the pointer to the last network data buffer if the queue is not empty;
* returns <b>NULL</b> otherwise.
*
* @since 1.0
*/
NetBuf *NetBufQueueDequeueTail(NetBufQueue *q)
{
return skb_dequeue_tail(q);
}
/**
* @brief Obtains the network data buffer from the header of a queue, without deleting it from the queue.
*
* @param q Indicates the pointer to the network data buffer queue.
*
* @return Returns the pointer to the first network data buffer if the queue is not empty;
* returns <b>NULL</b> otherwise.
*
* @since 1.0
*/
NetBuf *NetBufQueueAtHead(const NetBufQueue *q)
{
return skb_peek(q);
}
/**
* @brief Obtains the network data buffer from the tail of a queue, without deleting it from the queue.
*
* @param q Indicates the pointer to the network data buffer queue.
*
* @return Returns the pointer to the last network data buffer if the queue is not empty;
* returns <b>NULL</b> otherwise.
*
* @since 1.0
*/
NetBuf *NetBufQueueAtTail(const NetBufQueue *q)
{
return skb_peek_tail(q);
}
/**
* @brief Clears a network data buffer queue and releases the network data buffer in the queue.
*
* @param q Indicates the pointer to the network data buffer queue.
*
* @since 1.0
*/
void NetBufQueueClear(NetBufQueue *q)
{
skb_queue_purge(q);
}
/**
* @brief Moves all network data buffers from one queue to another and clears the source queue.
*
* @param q Indicates the pointer to the target network data buffer queue.
* @param add Indicates the pointer to the source network data buffer queue.
*
* @since 1.0
*/
void NetBufQueueConcat(NetBufQueue *q, NetBufQueue *add)
{
skb_queue_splice_init(add, q);
}
/**
* @brief Applies for a network data buffer.
*
* @param size Indicates the size of the network data buffer.
*
* @return Returns the pointer to the network data buffer if the operation is successful;
* returns <b>NULL</b> otherwise.
*
* @since 1.0
*/
NetBuf *NetBufAlloc(uint32_t size)
{
return dev_alloc_skb(size);
}
/**
* @brief Releases a network data buffer.
*
* @param nb Indicates the pointer to the network data buffer.
*
* @since 1.0
*/
void NetBufFree(NetBuf *nb)
{
kfree_skb(nb);
}
/**
* @brief Obtains the actual data length of the data segment of a network data buffer.
*
* @param nb Indicates the pointer to the network data buffer.
*
* @return Returns the actual data length of the data segment.
*
* @since 1.0
*/
uint32_t NetBufGetDataLen(const NetBuf *nb)
{
if (nb == NULL) {
return 0;
}
return nb->len;
}
/**
* @brief Adjusts the size of a network data buffer space.
*
* This function is used to apply for a new network data buffer based on the configured reserved space and
* the size of the source network data buffer, and copy the actual data to the new network data buffer.
*
* @param nb Indicates the pointer to the network data buffer.
* @param head Indicates the size of the header buffer segment reserved.
* @param tail Indicates the size of the tail buffer segment reserved.
*
* @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
*
* @since 1.0
*/
int32_t NetBufResizeRoom(NetBuf *nb, uint32_t head, uint32_t tail)
{
return pskb_expand_head(nb, head, tail, GFP_ATOMIC);
}
/**
* @brief Performs operations based on the segment ID of a network data buffer.
* The function is opposite to that of {@link NetBufPop}.
*
* Description:
* ID Type | Result
* -------|---------
* E_HEAD_BUF | The length of the header buffer segment is increased and the length of the data segment is reduced.
* E_DATA_BUF | The length of the data segment is increased and the length of the tail buffer segment is reduced.
* E_TAIL_BUF | The length of the tail buffer segment is increased and the length of the data segment is reduced.
*
* @param nb Indicates the pointer to the network data buffer.
* @param id Indicates the buffer segment ID.
* @param len Indicates the operation length.
*
* @return Returns the start address of the data segment if the operation is successful;
* returns <b>NULL</b> if the operation length exceeds the space of a specified buffer segment.
*
* @since 1.0
*/
void *NetBufPush(NetBuf *nb, uint32_t id, uint32_t len)
{
if (nb == NULL) {
return NULL;
}
switch (id) {
case E_HEAD_BUF:
nb->data += len;
break;
case E_DATA_BUF:
nb->tail += len;
nb->len += len;
break;
case E_TAIL_BUF:
if (unlikely(len > nb->len) || unlikely(len > nb->tail)) {
return NULL;
}
nb->tail -= len;
nb->len -= len;
break;
default:
break;
}
return nb->data;
}
/**
* @brief Performs operations based on the segment ID of a network data buffer.
* The function is opposite to that of {@link NetBufPush}.
*
* Description:
* ID Type | Result
* -------|---------
* E_HEAD_BUF | The length of the header buffer segment is reduced and the length of the data segment is increased.
* E_DATA_BUF| The length of the data segment is reduced and the length of the tail buffer segment is increased.
* E_TAIL_BUF | The length of the tail buffer segment is reduced and the length of the data segment is increased.
*
* @param nb Indicates the pointer to the network data buffer.
* @param id Indicates the buffer segment ID.
* @param len Indicates the operation length.
*
* @return Returns the start address of the data segment if the operation is successful;
* returns <b>NULL</b> if the operation length exceeds the space of a specified buffer segment.
*
* @since 1.0
*/
void *NetBufPop(NetBuf *nb, uint32_t id, uint32_t len)
{
if (nb == NULL) {
return NULL;
}
switch (id) {
case E_HEAD_BUF:
if (unlikely(len > nb->data)) {
return NULL;
}
nb->data -= len;
nb->len += len;
break;
case E_DATA_BUF:
if (unlikely(len > nb->len)) {
return NULL;
}
nb->data += len;
nb->len -= len;
break;
case E_TAIL_BUF:
nb->tail += len;
nb->len += len;
break;
default:
break;
}
return nb->data;
}
/**
* @brief Obtains the address of a specified buffer segment in a network data buffer.
*
* @param nb Indicates the pointer to the network data buffer.
* @param id Indicates the buffer segment ID.
*
* @return Returns the address of the specified buffer segment if the operation is successful;
* returns <b>NULL</b> if the buffer segment ID is invalid.
*
* @since 1.0
*/
uint8_t *NetBufGetAddress(const NetBuf *nb, uint32_t id)
{
uint8_t *addr = NULL;
if (nb == NULL) {
return addr;
}
switch (id) {
case E_HEAD_BUF:
addr = nb->head;
break;
case E_DATA_BUF:
addr = nb->data;
break;
case E_TAIL_BUF:
addr = skb_tail_pointer(nb);
break;
default:
break;
}
return addr;
}
/**
* @brief Obtains the size of a specified buffer segment space in a network data buffer.
*
* @param nb Indicates the pointer to the network data buffer.
* @param id Indicates the buffer segment ID.
*
* @return Returns the size of the specified buffer segment space if the operation is successful;
* returns <b>NULL</b> if the buffer segment ID is invalid.
*
* @since 1.0
*/
uint32_t NetBufGetRoom(const NetBuf *nb, uint32_t id)
{
uint32_t size = 0;
if (nb == NULL) {
return size;
}
switch (id) {
case E_HEAD_BUF:
size = skb_headroom(nb);
break;
case E_DATA_BUF:
size = skb_is_nonlinear(nb) ?
0 : (skb_tail_pointer(nb) - nb->data);
break;
case E_TAIL_BUF:
size = skb_tailroom(nb);
break;
default:
break;
}
return size;
}
/**
* @brief Copies data in a network data buffer to another network data buffer.
*
* @param nb Indicates the pointer to the network data buffer.
* @param cnb Indicates the pointer to the target network data buffer.
*
* @return Returns <b>0</b> if the operation is successful; returns a non-zero value otherwise.
*
* @since 1.0
*/
int32_t NetBufConcat(NetBuf *nb, NetBuf *cnb)
{
uint32_t tailroom = skb_tailroom(nb) < 0 ? 0 : skb_tailroom(nb);
if (cnb == NULL) {
return HDF_ERR_INVALID_PARAM;
}
if (tailroom < cnb->len) {
return HDF_FAILURE;
}
if (memcpy_s(skb_tail_pointer(nb), tailroom, cnb->data, cnb->len) != EOK) {
return HDF_FAILURE;
}
skb_put(nb, cnb->len);
NetBufFree(cnb);
return HDF_SUCCESS;
}

15
osal/Makefile Normal file
View File

@ -0,0 +1,15 @@
#
# Copyright (c) 2020-2021 Huawei Device Co., Ltd.
#
# This software is licensed under the terms of the GNU General Public
# License version 2, as published by the Free Software Foundation, and
# may be copied, distributed, and modified under those terms.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
obj-y += src/

View File

@ -0,0 +1,45 @@
/*
* hdf_log_adapter.h
*
* osal driver
*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef HDF_LOG_ADAPTER_H
#define HDF_LOG_ADAPTER_H
#include <linux/printk.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#define _HDF_FMT_TAG(TAG, LEVEL) "[" #LEVEL "/" #TAG "] "
#define HDF_FMT_TAG(TAG, LEVEL) _HDF_FMT_TAG(TAG, LEVEL)
#define HDF_LOGV_WRAPPER(fmt, args...) printk(KERN_DEBUG HDF_FMT_TAG(HDF_LOG_TAG, V) fmt "\r\n", ## args)
#define HDF_LOGD_WRAPPER(fmt, args...) printk(KERN_DEBUG HDF_FMT_TAG(HDF_LOG_TAG, D) fmt "\r\n", ## args)
#define HDF_LOGI_WRAPPER(fmt, args...) printk(KERN_INFO HDF_FMT_TAG(HDF_LOG_TAG, I) fmt "\r\n", ## args)
#define HDF_LOGW_WRAPPER(fmt, args...) printk(KERN_WARNING HDF_FMT_TAG(HDF_LOG_TAG, W) fmt "\r\n", ## args)
#define HDF_LOGE_WRAPPER(fmt, args...) printk(KERN_ERR HDF_FMT_TAG(HDF_LOG_TAG, E) fmt "\r\n", ## args)
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* HDF_LOG_ADAPTER_H */

25
osal/include/hdf_types.h Normal file
View File

@ -0,0 +1,25 @@
/*
* hdf_types.h
*
* osal driver
*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef HDF_TYPE_H
#define HDF_TYPE_H
#include <linux/string.h>
#include <linux/types.h>
#endif /* HDF_TYPE_H */

View File

@ -0,0 +1,45 @@
/*
* osal_atomic_def.h
*
* osal driver
*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef OSAL_ATOMIC_DEF_H
#define OSAL_ATOMIC_DEF_H
#include <linux/atomic.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#define OsalAtomicReadWrapper(v) atomic_read((const atomic_t *)(v))
#define OsalAtomicSetWrapper(v, value) atomic_set((atomic_t *)(v), value)
#define OsalAtomicIncWrapper(v) atomic_inc((atomic_t *)(v))
#define OsalAtomicIncRetWrapper(v) atomic_inc_return((atomic_t *)(v))
#define OsalAtomicDecWrapper(v) atomic_dec((atomic_t *)(v))
#define OsalAtomicDecRetWrapper(v) atomic_dec_return((atomic_t *)(v))
#define OsalTestBitWrapper(nr, addr) test_bit(nr, addr)
#define OsalTestSetBitWrapper(nr, addr) test_and_change_bit(nr, addr)
#define OsalTestClearBitWrapper(nr, addr) test_and_clear_bit(nr, addr)
#define OsalClearBitWrapper(nr, addr) clear_bit(nr, addr)
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* OSAL_ATOMIC_DEF_H */

View File

@ -0,0 +1,29 @@
/*
* osal_cdev_adapter.h
*
* osal driver
*
* Copyright (c) 2021 Huawei Device Co., Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef OSAL_CDEV_ADAPTER_DEF_H
#define OSAL_CDEV_ADAPTER_DEF_H
#include <linux/ioctl.h>
#include <linux/kernel.h>
#include <linux/poll.h>
#include <linux/fs.h>
#include <linux/cdev.h>
#endif /* OSAL_CDEV_ADAPTER_DEF_H */

View File

@ -0,0 +1,26 @@
/*
* osal_io.h
*
* osal driver
*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef OSAL_LINUX_IO_ADAPTER_H
#define OSAL_LINUX_IO_ADAPTER_H
#include <linux/io.h>
#include <linux/kernel.h>
#endif /* OSAL_LINUX_IO_ADAPTER_H */

39
osal/include/osal_math.h Normal file
View File

@ -0,0 +1,39 @@
/*
* osal_math.h
*
* osal mathematics
*
* Copyright (c) 2021 Huawei Device Co., Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef OSAL_MATH_H
#define OSAL_MATH_H
#include <linux/math64.h>
#include "hdf_base.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
static inline int64_t OsalDivS64(int64_t dividend, int32_t divisor)
{
return (int64_t)div_s64(dividend, divisor);
}
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* OSAL_MATH_H */

View File

@ -0,0 +1,44 @@
/*
* osal_uaccess.h
*
* osal driver
*
* Copyright (c) 2021 Huawei Device Co., Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef OSAL_UACCESS_DEF_H
#define OSAL_UACCESS_DEF_H
#include <linux/kernel.h>
#include <linux/uaccess.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
static inline size_t CopyToUser (void __user *to, const void *from, size_t len)
{
return (size_t)copy_to_user(to, from, (unsigned long)len);
}
static inline size_t CopyFromUser (void *to, const void __user *from, size_t len)
{
return (size_t)copy_from_user(to, from, (unsigned long)len);
}
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* OSAL_UACCESS_DEF_H */

21
osal/src/Makefile Normal file
View File

@ -0,0 +1,21 @@
#
# Copyright (c) 2020-2021 Huawei Device Co., Ltd.
#
# This software is licensed under the terms of the GNU General Public
# License version 2, as published by the Free Software Foundation, and
# may be copied, distributed, and modified under those terms.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
obj-y += osal_workqueue.o osal_thread.o osal_firmware.o osal_irq.o osal_mem.o osal_mutex.o osal_sem.o osal_spinlock.o \
osal_time.o osal_file.o osal_timer.o osal_cdev.o
ccflags-y += -Iinclude/hdf \
-Iinclude/hdf/osal \
-Iinclude/hdf/utils \
-Idrivers/hdf/khdf/osal/include \
-Iinclude/../drivers/hdf/../../../../../../../../../../../../../third_party/bounds_checking_function/include

266
osal/src/osal_cdev.c Normal file
View File

@ -0,0 +1,266 @@
/*
* osal_cdev.c
*
* osal driver
*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <linux/cdev.h>
#include <linux/device.h>
#include <linux/fs.h>
#include "osal_cdev.h"
#include "hdf_log.h"
#include "osal_file.h"
#include "osal_mem.h"
#include "osal_uaccess.h"
#define HDF_LOG_TAG osal_cdev
#define HDF_MAJOR 231
#define HDF_MINOR_START 0
#define HDF_MAX_CHAR_DEVICES 1024
static DEFINE_IDA(hdf_vnode_ids);
struct OsalCdev {
struct device dev;
struct cdev cdev;
struct file_operations fops;
const struct OsalCdevOps* opsImpl;
void* priv;
};
static const char* StringRfindChar(const char* str, char chr)
{
const char* p = NULL;
if (str == NULL) {
return NULL;
}
p = str + strlen(str);
while (p >= str) {
if (*p == chr) {
return p;
}
p--;
}
return NULL;
}
static char* hdfDevnode(struct device* dev, umode_t* mode)
{
return kasprintf(GFP_KERNEL, "hdf/%s", dev_name(dev));
}
static bool g_hdfClassInitted = false;
struct class g_hdfClass = {
.name = "hdf",
.devnode = hdfDevnode,
};
static dev_t g_hdfDevt = 0;
static int HdfClassInit(void)
{
int ret;
if (g_hdfClassInitted) {
return HDF_SUCCESS;
}
ret = class_register(&g_hdfClass);
if (ret) {
HDF_LOGE("fail to register hdf class");
return ret;
}
HDF_LOGI("register hdf class success");
ret = alloc_chrdev_region(&g_hdfDevt, HDF_MINOR_START, HDF_MAX_CHAR_DEVICES, "hdf");
if (ret) {
HDF_LOGE("failed to alloc hdf char major");
class_unregister(&g_hdfClass);
return ret;
}
g_hdfClassInitted = true;
return HDF_SUCCESS;
}
static void HdfVnodeDevRelease(struct device* dev)
{
(void)dev;
}
static int RegisterDev(struct OsalCdev* cdev, const char* devName)
{
int devMinor;
int ret;
ret = HdfClassInit();
if (ret != HDF_SUCCESS) {
return ret;
}
devMinor = ida_simple_get(&hdf_vnode_ids, HDF_MINOR_START, HDF_MAX_CHAR_DEVICES, GFP_KERNEL);
if (devMinor < 0) {
HDF_LOGE("failed to get hdf dev minor");
return HDF_DEV_ERR_NO_DEVICE;
}
dev_set_name(&cdev->dev, "%s", devName);
cdev->dev.devt = MKDEV(MAJOR(g_hdfDevt), devMinor);
cdev->dev.class = &g_hdfClass;
cdev->dev.parent = NULL;
cdev->dev.release = HdfVnodeDevRelease;
device_initialize(&cdev->dev);
cdev_init(&cdev->cdev, &cdev->fops);
ret = cdev_add(&cdev->cdev, cdev->dev.devt, 1);
if (ret) {
ida_simple_remove(&hdf_vnode_ids, devMinor);
HDF_LOGE("failed to add hdf cdev(%s)\n", devName);
}
ret = device_add(&cdev->dev);
if (ret) {
HDF_LOGE("device(%s) add failed\n", devName);
cdev_del(&cdev->cdev);
ida_simple_remove(&hdf_vnode_ids, devMinor);
return ret;
}
HDF_LOGI("add cdev %s success\n", devName);
return 0;
}
static loff_t OsalCdevSeek(struct file* filep, loff_t offset, int whence)
{
struct OsalCdev* dev = container_of(filep->f_inode->i_cdev, struct OsalCdev, cdev);
return dev->opsImpl->seek(filep, offset, whence);
}
static ssize_t OsalCdevRead(struct file* filep, char __user* buf, size_t buflen, loff_t* offset)
{
struct OsalCdev* dev = container_of(filep->f_inode->i_cdev, struct OsalCdev, cdev);
return dev->opsImpl->read(filep, buf, buflen, offset);
}
static ssize_t OsalCdevWrite(struct file* filep, const char __user* buf, size_t buflen, loff_t* offset)
{
struct OsalCdev* dev = container_of(filep->f_inode->i_cdev, struct OsalCdev, cdev);
return dev->opsImpl->write(filep, buf, buflen, offset);
}
static unsigned int OsalCdevPoll(struct file* filep, struct poll_table_struct* pollTable)
{
struct OsalCdev* dev = container_of(filep->f_inode->i_cdev, struct OsalCdev, cdev);
return dev->opsImpl->poll(filep, pollTable);
}
static long OsalCdevIoctl(struct file* filep, unsigned int cmd, unsigned long arg)
{
struct OsalCdev* dev = container_of(filep->f_inode->i_cdev, struct OsalCdev, cdev);
return dev->opsImpl->ioctl(filep, cmd, arg);
}
static int OsalCdevOpen(struct inode* inode, struct file* filep)
{
struct OsalCdev* dev = container_of(inode->i_cdev, struct OsalCdev, cdev);
return dev->opsImpl->open(dev, filep);
}
static int OsalCdevRelease(struct inode* inode, struct file* filep)
{
struct OsalCdev* dev = container_of(inode->i_cdev, struct OsalCdev, cdev);
return dev->opsImpl->release(dev, filep);
}
static void AssignFileOps(struct file_operations* fops, const struct OsalCdevOps* src)
{
fops->llseek = src->seek != NULL ? OsalCdevSeek : NULL;
fops->read = src->read != NULL ? OsalCdevRead : NULL;
fops->write = src->write != NULL ? OsalCdevWrite : NULL;
fops->poll = src->poll != NULL ? OsalCdevPoll : NULL;
fops->unlocked_ioctl = src->ioctl != NULL ? OsalCdevIoctl : NULL;
fops->open = src->open != NULL ? OsalCdevOpen : NULL;
fops->release = src->release != NULL ? OsalCdevRelease : NULL;
#ifdef CONFIG_COMPAT
fops->compat_ioctl = src->ioctl != NULL ? OsalCdevIoctl : NULL;
#endif
}
struct OsalCdev* OsalAllocCdev(const struct OsalCdevOps* fops)
{
struct OsalCdev* cdev = OsalMemCalloc(sizeof(struct OsalCdev));
if (cdev == NULL) {
return NULL;
}
AssignFileOps(&cdev->fops, fops);
cdev->opsImpl = fops;
return cdev;
}
int OsalRegisterCdev(struct OsalCdev* cdev, const char* name, unsigned int mode, void* priv)
{
const char* lastSlash;
(void)mode;
if (cdev == NULL || name == NULL) {
return HDF_ERR_INVALID_PARAM;
}
lastSlash = StringRfindChar(name, '/');
int ret = RegisterDev(cdev, lastSlash == NULL ? name : lastSlash + 1);
if (ret == HDF_SUCCESS) {
cdev->priv = priv;
}
return ret;
}
void OsalUnregisterCdev(struct OsalCdev* cdev)
{
if (cdev == NULL) {
return;
}
device_del(&cdev->dev);
cdev_del(&cdev->cdev);
ida_simple_remove(&hdf_vnode_ids, MINOR(cdev->dev.devt));
}
void OsalFreeCdev(struct OsalCdev* cdev)
{
if (cdev != NULL) {
OsalMemFree(cdev);
}
}
void* OsalGetCdevPriv(struct OsalCdev* cdev)
{
return cdev != NULL ? cdev->priv : NULL;
}
void OsalSetFilePriv(struct file* filep, void* priv)
{
if (filep != NULL) {
filep->private_data = priv;
}
}
void* OsalGetFilePriv(struct file* filep)
{
return filep != NULL ? filep->private_data : NULL;
}

135
osal/src/osal_file.c Normal file
View File

@ -0,0 +1,135 @@
/*
* osal_file.c
*
* osal driver
*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include "osal_file.h"
#include <linux/fs.h>
#include <asm/uaccess.h>
#include "hdf_log.h"
#define HDF_LOG_TAG osal_file
int32_t OsalFileOpen(OsalFile *file, const char *path, int flags, uint32_t rights)
{
struct file *fp = NULL;
if (file == NULL || path == NULL) {
HDF_LOGE("%s invalid param", __func__);
return HDF_ERR_INVALID_PARAM;
}
file->realFile = (void *)fp;
fp = filp_open(path, flags, rights);
if (IS_ERR_OR_NULL(fp)) {
HDF_LOGE("%s open file fail %d %d", __func__, flags, rights);
return HDF_FAILURE;
}
file->realFile = (void *)fp;
return HDF_SUCCESS;
}
EXPORT_SYMBOL(OsalFileOpen);
ssize_t OsalFileWrite(OsalFile *file, const void *string, uint32_t length)
{
ssize_t ret;
loff_t pos;
mm_segment_t org_fs;
struct file *fp = NULL;
if (file == NULL || IS_ERR_OR_NULL(file->realFile) || string == NULL) {
HDF_LOGE("%s invalid param", __func__);
return HDF_ERR_INVALID_PARAM;
}
fp = (struct file *)file->realFile;
pos = fp->f_pos;
org_fs = get_fs();
set_fs(KERNEL_DS);
ret = vfs_write(fp, string, length, &pos);
set_fs(org_fs);
if (ret < 0) {
HDF_LOGE("%s write file length %d fail %d", __func__, length, ret);
return HDF_FAILURE;
}
return ret;
}
EXPORT_SYMBOL(OsalFileWrite);
void OsalFileClose(OsalFile *file)
{
struct file *fp = NULL;
if (file == NULL || IS_ERR_OR_NULL(file->realFile)) {
HDF_LOGE("%s invalid param", __func__);
return;
}
fp = (struct file *)file->realFile;
filp_close(fp, NULL);
file->realFile = NULL;
}
EXPORT_SYMBOL(OsalFileClose);
ssize_t OsalFileRead(OsalFile *file, void *buf, uint32_t length)
{
ssize_t ret;
mm_segment_t org_fs;
loff_t pos;
struct file *fp = NULL;
if (file == NULL || IS_ERR_OR_NULL(file->realFile) || buf == NULL) {
HDF_LOGE("%s invalid param", __func__);
return HDF_ERR_INVALID_PARAM;
}
fp = (struct file *)file->realFile;
org_fs = get_fs();
set_fs(KERNEL_DS);
pos = fp->f_pos;
ret = vfs_read(fp, buf, length, &pos);
set_fs(org_fs);
if (ret < 0) {
HDF_LOGE("%s read file length %d fail %d", __func__, length, ret);
return HDF_FAILURE;
}
return ret;
}
EXPORT_SYMBOL(OsalFileRead);
off_t OsalFileLseek(OsalFile *file, off_t offset, int32_t whence)
{
off_t ret;
struct file *fp = NULL;
if (file == NULL || IS_ERR_OR_NULL(file->realFile)) {
HDF_LOGE("%s invalid param", __func__);
return HDF_ERR_INVALID_PARAM;
}
fp = (struct file *)file->realFile;
ret = vfs_llseek(fp, offset, whence);
if (ret < 0) {
HDF_LOGE("%s lseek file fail %ld %d", __func__, offset, whence);
return HDF_FAILURE;
}
return ret;
}
EXPORT_SYMBOL(OsalFileLseek);

91
osal/src/osal_firmware.c Normal file
View File

@ -0,0 +1,91 @@
/*
* osal_firmware.c
*
* osal driver
*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include "osal_firmware.h"
#include <linux/export.h>
#include <linux/firmware.h>
#include <linux/string.h>
#include "hdf_log.h"
#define HDF_LOG_TAG osal_fw
int32_t OsalRequestFirmware(struct OsalFirmware *fwPara,
const char *fwName, void *device)
{
const struct firmware *fw = NULL;
int ret;
if (fwPara == NULL || fwName == NULL) {
HDF_LOGE("%s invalid param", __func__);
return HDF_ERR_INVALID_PARAM;
}
ret = request_firmware(&fw, fwName, device);
if (ret < 0) {
fwPara->fwSize = 0;
fwPara->para = NULL;
HDF_LOGE("%s failure to request firmware file", __func__);
return HDF_FAILURE;
}
fwPara->fwSize = fw->size;
fwPara->para = (void *)fw;
return HDF_SUCCESS;
}
EXPORT_SYMBOL(OsalRequestFirmware);
int32_t OsalSeekFirmware(struct OsalFirmware *fwPara, uint32_t offset)
{
(void)fwPara;
(void)offset;
return HDF_SUCCESS;
}
EXPORT_SYMBOL(OsalSeekFirmware);
int32_t OsalReadFirmware(struct OsalFirmware *fwPara, struct OsalFwBlock *block)
{
struct firmware *fw = NULL;
if (fwPara == NULL || fwPara->para == NULL || block == NULL) {
HDF_LOGE("%s invalid param", __func__);
return HDF_ERR_INVALID_PARAM;
}
fw = (struct firmware *)fwPara->para;
block->data = (uint8_t *)fw->data;
block->dataSize = fwPara->fwSize;
block->curOffset = 0;
block->endFlag = true;
return HDF_SUCCESS;
}
EXPORT_SYMBOL(OsalReadFirmware);
int32_t OsalReleaseFirmware(struct OsalFirmware *fwPara)
{
if (fwPara == NULL || fwPara->para == NULL) {
HDF_LOGE("%s invalid param", __func__);
return HDF_ERR_INVALID_PARAM;
}
release_firmware((struct firmware *)fwPara->para);
fwPara->para = NULL;
return HDF_SUCCESS;
}
EXPORT_SYMBOL(OsalReleaseFirmware);

70
osal/src/osal_irq.c Normal file
View File

@ -0,0 +1,70 @@
/*
* osal_irq.c
*
* osal driver
*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include "osal_irq.h"
#include <linux/export.h>
#include <linux/interrupt.h>
#include "hdf_log.h"
#define HDF_LOG_TAG osal_irq
int32_t OsalRegisterIrq(uint32_t irq,
uint32_t config, OsalIRQHandle handle, const char *name, void *data)
{
uint32_t ret;
const char *irq_name = NULL;
irq_name = (name != NULL) ? name : "hdf_irq";
ret = request_threaded_irq(irq, NULL, (irq_handler_t)handle,
config | IRQF_ONESHOT | IRQF_NO_SUSPEND, irq_name, data);
if (ret != 0) {
HDF_LOGE("%s fail %d", __func__, ret);
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
EXPORT_SYMBOL(OsalRegisterIrq);
int32_t OsalUnregisterIrq(uint32_t irq, void *dev)
{
disable_irq(irq);
free_irq(irq, dev);
return HDF_SUCCESS;
}
EXPORT_SYMBOL(OsalUnregisterIrq);
int32_t OsalEnableIrq(uint32_t irq)
{
enable_irq(irq);
return HDF_SUCCESS;
}
EXPORT_SYMBOL(OsalEnableIrq);
int32_t OsalDisableIrq(uint32_t irq)
{
disable_irq(irq);
return HDF_SUCCESS;
}
EXPORT_SYMBOL(OsalDisableIrq);

164
osal/src/osal_mem.c Normal file
View File

@ -0,0 +1,164 @@
/*
* osal_mem.c
*
* osal driver
*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include "osal_mem.h"
#include <linux/export.h>
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/vmalloc.h>
#include "hdf_log.h"
#include "securec.h"
#define HDF_LOG_TAG osal_mem
#define KMALLOC_SIZE 0x20000
struct mem_hdr {
uint32_t type;
uint32_t offset;
};
struct mem_block {
struct mem_hdr hdr;
uint8_t mem[0];
};
enum {
TYPE_KMALLOC = 0xa5a5a5a1,
TYPE_VMALLOC = 0xa5a5a5a2,
};
static void *osal_mem_alloc(size_t size, uint32_t *type)
{
char *base = NULL;
const uint32_t mng_size = sizeof(struct mem_block);
if (size > (KMALLOC_SIZE - mng_size)) {
base = (char *)vmalloc(size + mng_size);
*type = TYPE_VMALLOC;
} else {
base = (char *)kmalloc(size + mng_size, GFP_KERNEL);
*type = TYPE_KMALLOC;
}
return base;
}
void *OsalMemAlloc(size_t size)
{
void *buf = NULL;
char *base = NULL;
struct mem_block *block = NULL;
const uint32_t mng_size = sizeof(*block);
uint32_t type;
if (size == 0) {
HDF_LOGE("%s invalid param", __func__);
return NULL;
}
base = osal_mem_alloc(size, &type);
if (base == NULL) {
HDF_LOGE("%s malloc fail %d", __func__, size);
return NULL;
}
block = (struct mem_block *)base;
block->hdr.type = type;
block->hdr.offset = 0;
buf = (void *)(base + mng_size);
return buf;
}
EXPORT_SYMBOL(OsalMemAlloc);
void *OsalMemCalloc(size_t size)
{
void *buf = NULL;
if (size == 0) {
HDF_LOGE("%s invalid param", __func__);
return NULL;
}
buf = OsalMemAlloc(size);
if (buf != NULL)
(void)memset_s(buf, size, 0, size);
return buf;
}
EXPORT_SYMBOL(OsalMemCalloc);
void *OsalMemAllocAlign(size_t alignment, size_t size)
{
char *base = NULL;
char *buf = NULL;
struct mem_block *block = NULL;
const uint32_t mng_size = sizeof(*block);
uint32_t type;
uint32_t offset;
char *aligned_ptr = NULL;
if (size == 0 || (alignment == 0) || ((alignment & (alignment - 1)) != 0) ||
((alignment % sizeof(void *)) != 0) || size > (SIZE_MAX - alignment)) {
HDF_LOGE("%s invalid param align:%d,size:%d", __func__, alignment, size);
return NULL;
}
base = osal_mem_alloc(size + alignment, &type);
if (base == NULL) {
HDF_LOGE("%s malloc fail %d", __func__, size);
return NULL;
}
buf = base + mng_size;
aligned_ptr = (char *)(uintptr_t)(((size_t)(uintptr_t)buf + alignment - 1) & ~(alignment - 1));
offset = aligned_ptr - buf;
block = (struct mem_block *)(base + offset);
block->hdr.type = type;
block->hdr.offset = offset;
return aligned_ptr;
}
EXPORT_SYMBOL(OsalMemAllocAlign);
void OsalMemFree(void *buf)
{
uint32_t type;
char *base = NULL;
struct mem_block *block = NULL;
if (buf == NULL) {
HDF_LOGE("%s try to free null", __func__);
return;
}
block = (struct mem_block *)((char *)buf - (char *)&((struct mem_block *)0)->mem);
type = block->hdr.type;
base = (char *)block - block->hdr.offset;
if (type == TYPE_KMALLOC)
kfree(base);
else if (type == TYPE_VMALLOC)
vfree(base);
else
HDF_LOGE("%s block : type %d fail", __func__, type);
}
EXPORT_SYMBOL(OsalMemFree);

102
osal/src/osal_mutex.c Normal file
View File

@ -0,0 +1,102 @@
/*
* osal_mutex.c
*
* osal driver
*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include "osal_mutex.h"
#include <linux/export.h>
#include <linux/mutex.h>
#include "hdf_log.h"
#include "osal_mem.h"
#define HDF_LOG_TAG osal_mutex
int32_t OsalMutexInit(struct OsalMutex *mutex)
{
struct mutex *mutex_tmp = NULL;
if (mutex == NULL) {
HDF_LOGE("%s invalid param", __func__);
return HDF_ERR_INVALID_PARAM;
}
mutex_tmp = (struct mutex *)OsalMemCalloc(sizeof(*mutex_tmp));
if (mutex_tmp == NULL) {
HDF_LOGE("malloc fail");
return HDF_ERR_MALLOC_FAIL;
}
mutex_init(mutex_tmp);
mutex->realMutex = (void *)mutex_tmp;
return HDF_SUCCESS;
}
EXPORT_SYMBOL(OsalMutexInit);
int32_t OsalMutexDestroy(struct OsalMutex *mutex)
{
if (mutex == NULL || mutex->realMutex == NULL) {
HDF_LOGE("%s invalid param", __func__);
return HDF_ERR_INVALID_PARAM;
}
mutex_destroy((struct mutex *)mutex->realMutex);
OsalMemFree(mutex->realMutex);
mutex->realMutex = NULL;
return HDF_SUCCESS;
}
EXPORT_SYMBOL(OsalMutexDestroy);
int32_t OsalMutexLock(struct OsalMutex *mutex)
{
if (mutex == NULL || mutex->realMutex == NULL) {
HDF_LOGE("%s invalid param", __func__);
return HDF_ERR_INVALID_PARAM;
}
mutex_lock((struct mutex *)mutex->realMutex);
return HDF_SUCCESS;
}
EXPORT_SYMBOL(OsalMutexLock);
int32_t OsalMutexTimedLock(struct OsalMutex *mutex, uint32_t mSec)
{
if (mutex == NULL || mutex->realMutex == NULL) {
HDF_LOGE("%s invalid param", __func__);
return HDF_ERR_INVALID_PARAM;
}
(void)mSec;
mutex_lock((struct mutex *)mutex->realMutex);
return HDF_SUCCESS;
}
EXPORT_SYMBOL(OsalMutexTimedLock);
int32_t OsalMutexUnlock(struct OsalMutex *mutex)
{
if (mutex == NULL || mutex->realMutex == NULL) {
HDF_LOGE("%s invalid param", __func__);
return HDF_ERR_INVALID_PARAM;
}
mutex_unlock((struct mutex *)mutex->realMutex);
return HDF_SUCCESS;
}
EXPORT_SYMBOL(OsalMutexUnlock);

103
osal/src/osal_sem.c Normal file
View File

@ -0,0 +1,103 @@
/*
* osal_sem.c
*
* osal driver
*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include "osal_sem.h"
#include <linux/errno.h>
#include <linux/export.h>
#include <linux/semaphore.h>
#include <linux/timer.h>
#include "hdf_log.h"
#include "osal_mem.h"
#define HDF_LOG_TAG osal_sem
int32_t OsalSemInit(struct OsalSem *sem, uint32_t value)
{
struct semaphore *sem_tmp = NULL;
if (sem == NULL) {
HDF_LOGE("%s invalid param", __func__);
return HDF_ERR_INVALID_PARAM;
}
sem_tmp = (struct semaphore *)OsalMemCalloc(sizeof(*sem_tmp));
if (sem_tmp == NULL) {
HDF_LOGE("%s malloc fail", __func__);
return HDF_ERR_MALLOC_FAIL;
}
sema_init(sem_tmp, value);
sem->realSemaphore = (void *)sem_tmp;
return HDF_SUCCESS;
}
EXPORT_SYMBOL(OsalSemInit);
int32_t OsalSemWait(struct OsalSem *sem, uint32_t millisec)
{
int32_t ret;
if (sem == NULL || sem->realSemaphore == NULL) {
HDF_LOGE("%s invalid param", __func__);
return HDF_ERR_INVALID_PARAM;
}
if (millisec == HDF_WAIT_FOREVER) {
down((struct semaphore *)sem->realSemaphore);
} else {
ret = down_timeout((struct semaphore *)sem->realSemaphore, msecs_to_jiffies(millisec));
if (ret != 0) {
if (ret == -ETIME) {
return HDF_ERR_TIMEOUT;
} else {
HDF_LOGE("%s time_out %d %d", __func__, millisec, ret);
return HDF_FAILURE;
}
}
}
return HDF_SUCCESS;
}
EXPORT_SYMBOL(OsalSemWait);
int32_t OsalSemPost(struct OsalSem *sem)
{
if (sem == NULL || sem->realSemaphore == NULL) {
HDF_LOGE("%s invalid param", __func__);
return HDF_ERR_INVALID_PARAM;
}
up((struct semaphore *)sem->realSemaphore);
return HDF_SUCCESS;
}
EXPORT_SYMBOL(OsalSemPost);
int32_t OsalSemDestroy(struct OsalSem *sem)
{
if (sem == NULL || sem->realSemaphore == NULL) {
HDF_LOGE("%s invalid param", __func__);
return HDF_ERR_INVALID_PARAM;
}
OsalMemFree(sem->realSemaphore);
sem->realSemaphore = NULL;
return HDF_SUCCESS;
}
EXPORT_SYMBOL(OsalSemDestroy);

143
osal/src/osal_spinlock.c Normal file
View File

@ -0,0 +1,143 @@
/*
* osal_spinlock.c
*
* osal driver
*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include "osal_spinlock.h"
#include <linux/export.h>
#include <linux/spinlock.h>
#include "hdf_log.h"
#include "osal_mem.h"
#define HDF_LOG_TAG osal_spinlock
int32_t OsalSpinInit(OsalSpinlock *spinlock)
{
spinlock_t *spin_tmp = NULL;
if (spinlock == NULL) {
HDF_LOGE("%s invalid param", __func__);
return HDF_ERR_INVALID_PARAM;
}
spin_tmp = (spinlock_t *)OsalMemCalloc(sizeof(*spin_tmp));
if (spin_tmp == NULL) {
HDF_LOGE("malloc fail");
spinlock->realSpinlock = NULL;
return HDF_ERR_MALLOC_FAIL;
}
spin_lock_init(spin_tmp);
spinlock->realSpinlock = (void *)spin_tmp;
return HDF_SUCCESS;
}
EXPORT_SYMBOL(OsalSpinInit);
int32_t OsalSpinDestroy(OsalSpinlock *spinlock)
{
if (spinlock == NULL || spinlock->realSpinlock == NULL) {
HDF_LOGE("%s invalid param", __func__);
return HDF_ERR_INVALID_PARAM;
}
OsalMemFree(spinlock->realSpinlock);
spinlock->realSpinlock = NULL;
return HDF_SUCCESS;
}
EXPORT_SYMBOL(OsalSpinDestroy);
int32_t OsalSpinLock(OsalSpinlock *spinlock)
{
if (spinlock == NULL || spinlock->realSpinlock == NULL) {
HDF_LOGE("%s invalid param", __func__);
return HDF_ERR_INVALID_PARAM;
}
spin_lock((spinlock_t *)spinlock->realSpinlock);
return HDF_SUCCESS;
}
EXPORT_SYMBOL(OsalSpinLock);
int32_t OsalSpinUnlock(OsalSpinlock *spinlock)
{
if (spinlock == NULL || spinlock->realSpinlock == NULL) {
HDF_LOGE("%s invalid param", __func__);
return HDF_ERR_INVALID_PARAM;
}
spin_unlock((spinlock_t *)spinlock->realSpinlock);
return HDF_SUCCESS;
}
EXPORT_SYMBOL(OsalSpinUnlock);
int32_t OsalSpinLockIrq(OsalSpinlock *spinlock)
{
if (spinlock == NULL || spinlock->realSpinlock == NULL) {
HDF_LOGE("%s invalid param", __func__);
return HDF_ERR_INVALID_PARAM;
}
spin_lock_irq((spinlock_t *)spinlock->realSpinlock);
return HDF_SUCCESS;
}
EXPORT_SYMBOL(OsalSpinLockIrq);
int32_t OsalSpinUnlockIrq(OsalSpinlock *spinlock)
{
if (spinlock == NULL || spinlock->realSpinlock == NULL) {
HDF_LOGE("%s invalid param", __func__);
return HDF_ERR_INVALID_PARAM;
}
spin_unlock_irq((spinlock_t *)spinlock->realSpinlock);
return HDF_SUCCESS;
}
EXPORT_SYMBOL(OsalSpinUnlockIrq);
int32_t OsalSpinLockIrqSave(OsalSpinlock *spinlock, uint32_t *flags)
{
unsigned long temp = 0;
if (spinlock == NULL || spinlock->realSpinlock == NULL || flags == NULL) {
HDF_LOGE("%s invalid param %d", __func__, __LINE__);
return HDF_ERR_INVALID_PARAM;
}
spin_lock_irqsave((spinlock_t *)spinlock->realSpinlock, temp);
*flags = temp;
return HDF_SUCCESS;
}
EXPORT_SYMBOL(OsalSpinLockIrqSave);
int32_t OsalSpinUnlockIrqRestore(OsalSpinlock *spinlock, uint32_t *flags)
{
if (spinlock == NULL || spinlock->realSpinlock == NULL || flags == NULL) {
HDF_LOGE("%s invalid param %d", __func__, __LINE__);
return HDF_ERR_INVALID_PARAM;
}
spin_unlock_irqrestore((spinlock_t *)spinlock->realSpinlock, *flags);
return HDF_SUCCESS;
}
EXPORT_SYMBOL(OsalSpinUnlockIrqRestore);

177
osal/src/osal_thread.c Normal file
View File

@ -0,0 +1,177 @@
/*
* osal_thread.c
*
* osal driver
*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include "osal_thread.h"
#include <linux/errno.h>
#include <linux/export.h>
#include <linux/kernel.h>
#include <linux/kthread.h>
#include <linux/string.h>
#include <linux/types.h>
#include <uapi/linux/sched.h>
#include <uapi/linux/sched/types.h>
#include "hdf_log.h"
#include "osal_mem.h"
#include "securec.h"
#define HDF_LOG_TAG osal_thread
#define OSAL_INVALID_CPU_ID UINT_MAX
struct thread_wrapper {
OsalThreadEntry thread_entry;
void *entry_para;
struct task_struct *task;
uint32_t cpu_id;
};
enum {
OSAL_PRIORITY_MIDDLE = 50,
OSAL_PRIORITY_HIGH = 90,
OSAL_PRIORITY_HIGHEST = 99,
};
static int osal_thread_entry(void *para)
{
int ret = -1;
struct thread_wrapper *wrapper = (struct thread_wrapper *)para;
if (wrapper == NULL || wrapper->thread_entry == NULL) {
HDF_LOGE("%s invalid param", __func__);
} else {
ret = wrapper->thread_entry(wrapper->entry_para);
}
do_exit(ret);
return ret;
}
int32_t OsalThreadCreate(struct OsalThread *thread, OsalThreadEntry thread_entry, void *entry_para)
{
struct thread_wrapper *wrapper = NULL;
if (thread == NULL || thread_entry == NULL) {
HDF_LOGE("%s invalid param", __func__);
return HDF_ERR_INVALID_PARAM;
}
thread->realThread = NULL;
wrapper = (struct thread_wrapper *)OsalMemCalloc(sizeof(*wrapper));
if (wrapper == NULL) {
HDF_LOGE("%s malloc fail", __func__);
return HDF_ERR_MALLOC_FAIL;
}
wrapper->entry_para = entry_para;
wrapper->thread_entry = thread_entry;
wrapper->cpu_id = OSAL_INVALID_CPU_ID;
thread->realThread = wrapper;
return HDF_SUCCESS;
}
EXPORT_SYMBOL(OsalThreadCreate);
int32_t OsalThreadBind(struct OsalThread *thread, unsigned int cpu_id)
{
struct thread_wrapper *wrapper = NULL;
if (thread == NULL || thread->realThread == NULL) {
HDF_LOGE("%s invalid parameter %d\n", __func__, __LINE__);
return HDF_ERR_INVALID_PARAM;
}
wrapper = (struct thread_wrapper *)thread->realThread;
wrapper->cpu_id = cpu_id;
return HDF_SUCCESS;
}
EXPORT_SYMBOL(OsalThreadBind);
int32_t OsalThreadStart(struct OsalThread *thread, const struct OsalThreadParam *param)
{
int32_t ret;
struct sched_param sched_para;
int32_t policy = SCHED_FIFO;
struct task_struct *task = NULL;
struct thread_wrapper *wrapper = NULL;
if (thread == NULL || thread->realThread == NULL || param == NULL || param->name == NULL) {
HDF_LOGE("%s invalid parameter\n", __func__);
return HDF_ERR_INVALID_PARAM;
}
(void)memset_s(&sched_para, sizeof(sched_para), 0, sizeof(sched_para));
if (param->priority == OSAL_THREAD_PRI_HIGHEST)
sched_para.sched_priority = OSAL_PRIORITY_HIGHEST;
else if (param->priority == OSAL_THREAD_PRI_HIGH)
sched_para.sched_priority = OSAL_PRIORITY_HIGH;
else if (param->priority == OSAL_THREAD_PRI_DEFAULT)
sched_para.sched_priority = OSAL_PRIORITY_MIDDLE;
else
policy = SCHED_NORMAL;
wrapper = (struct thread_wrapper *)thread->realThread;
task = kthread_create(osal_thread_entry, wrapper, param->name);
if (IS_ERR(task)) {
ret = PTR_ERR(task);
HDF_LOGE("%s kthread_create fail %d", __func__, ret);
return HDF_FAILURE;
}
if (wrapper->cpu_id != OSAL_INVALID_CPU_ID) {
kthread_bind(task, wrapper->cpu_id);
}
wake_up_process(task);
if (policy == SCHED_FIFO) {
if (sched_setscheduler(task, policy, &sched_para)) {
HDF_LOGE("%s sched_setscheduler fail", __func__);
kthread_stop(task);
return HDF_FAILURE;
}
}
wrapper->task = task;
return HDF_SUCCESS;
}
EXPORT_SYMBOL(OsalThreadStart);
int32_t OsalThreadSuspend(struct OsalThread *thread)
{
return HDF_ERR_NOT_SUPPORT;
}
EXPORT_SYMBOL(OsalThreadSuspend);
int32_t OsalThreadDestroy(struct OsalThread *thread)
{
if (thread == NULL || thread->realThread == NULL) {
HDF_LOGE("%s invalid parameter\n", __func__);
return HDF_ERR_INVALID_PARAM;
}
OsalMemFree(thread->realThread);
thread->realThread = NULL;
return HDF_SUCCESS;
}
EXPORT_SYMBOL(OsalThreadDestroy);
int32_t OsalThreadResume(struct OsalThread *thread)
{
return HDF_ERR_NOT_SUPPORT;
}
EXPORT_SYMBOL(OsalThreadResume);

110
osal/src/osal_time.c Executable file
View File

@ -0,0 +1,110 @@
/*
* osal_time.c
*
* osal driver
*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include "osal_time.h"
#include <linux/delay.h>
#include <linux/export.h>
#include <linux/rtc.h>
#include <linux/string.h>
#include <linux/time.h>
#include "hdf_log.h"
#include "osal_math.h"
#include "securec.h"
#define HDF_LOG_TAG osal_time
#define TM_SINCE_YEAR 1900
#define TM_MINUTE_UNIT 60
int32_t OsalGetTime(OsalTimespec *time)
{
struct timeval tv;
if (time == NULL) {
HDF_LOGE("%s invalid para", __func__);
return HDF_ERR_INVALID_PARAM;
}
(void)memset_s(&tv, sizeof(tv), 0, sizeof(tv));
do_gettimeofday(&tv);
time->sec = tv.tv_sec;
time->usec = tv.tv_usec;
return HDF_SUCCESS;
}
EXPORT_SYMBOL(OsalGetTime);
int32_t OsalDiffTime(const OsalTimespec *start, const OsalTimespec *end, OsalTimespec *diff)
{
uint32_t usec = 0;
uint32_t sec = 0;
if (start == NULL || end == NULL || diff == NULL) {
HDF_LOGE("%s invalid para", __func__);
return HDF_ERR_INVALID_PARAM;
}
if (start->sec > end->sec) {
HDF_LOGE("%s start time later then end time", __func__);
return HDF_ERR_INVALID_PARAM;
}
if (end->usec < start->usec) {
usec = (HDF_KILO_UNIT * HDF_KILO_UNIT);
sec = 1;
}
diff->usec = usec + end->usec - start->usec;
diff->sec = end->sec - start->sec - sec;
return HDF_SUCCESS;
}
EXPORT_SYMBOL(OsalDiffTime);
void OsalSleep(uint32_t sec)
{
msleep(sec * HDF_KILO_UNIT);
}
EXPORT_SYMBOL(OsalSleep);
void OsalMSleep(uint32_t mSec)
{
msleep(mSec);
}
EXPORT_SYMBOL(OsalMSleep);
void OsalUDelay(uint32_t us)
{
udelay(us);
}
EXPORT_SYMBOL(OsalUDelay);
void OsalMDelay(uint32_t ms)
{
mdelay(ms);
}
EXPORT_SYMBOL(OsalMDelay);
uint64_t OsalGetSysTimeMs()
{
OsalTimespec time;
(void)memset_s(&time, sizeof(time), 0, sizeof(time));
(void)OsalGetTime(&time);
return (time.sec * HDF_KILO_UNIT + OsalDivS64(time.usec, HDF_KILO_UNIT));
}
EXPORT_SYMBOL(OsalGetSysTimeMs);

178
osal/src/osal_timer.c Normal file
View File

@ -0,0 +1,178 @@
/*
* osal_timer.c
*
* osal driver
*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include "osal_timer.h"
#include <linux/errno.h>
#include <linux/export.h>
#include <linux/signal.h>
#include <linux/timer.h>
#include "hdf_log.h"
#include "osal_mem.h"
#include "osal_mutex.h"
#define HDF_LOG_TAG osal_timer
typedef enum {
OSAL_TIMER_ONCE,
OSAL_TIMER_LOOP,
} OsalTimerMode;
struct osal_ktimer {
unsigned long arg;
struct timer_list timer;
OsalTimerFunc func;
uint32_t msec;
struct OsalMutex mutex;
OsalTimerMode mode;
};
static void osal_timer_callback(struct timer_list *arg)
{
struct osal_ktimer *ktimer = NULL;
uint32_t msec;
OsalTimerMode mode;
if (arg == NULL) {
HDF_LOGI("%s timer is stopped", __func__);
return;
}
ktimer = from_timer(ktimer, arg, timer);
OsalMutexTimedLock(&ktimer->mutex, HDF_WAIT_FOREVER);
msec = ktimer->msec;
mode = ktimer->mode;
OsalMutexUnlock(&ktimer->mutex);
if (msec != 0) {
ktimer->func(ktimer->arg);
if (mode == OSAL_TIMER_LOOP) {
ktimer->timer.expires = jiffies + msecs_to_jiffies(msec);
mod_timer(&ktimer->timer, ktimer->timer.expires);
}
} else {
del_timer(&ktimer->timer);
OsalMutexDestroy(&ktimer->mutex);
OsalMemFree(ktimer);
HDF_LOGI("%s timer is stop", __func__);
}
}
int32_t OsalTimerCreate(OsalTimer *timer, uint32_t interval, OsalTimerFunc func, uintptr_t arg)
{
struct osal_ktimer *ktimer = NULL;
if (func == NULL || timer == NULL || interval == 0) {
HDF_LOGE("%s invalid para", __func__);
return HDF_ERR_INVALID_PARAM;
}
ktimer = (struct osal_ktimer *)OsalMemCalloc(sizeof(*ktimer));
if (ktimer == NULL) {
HDF_LOGE("%s malloc fail", __func__);
timer->realTimer = NULL;
return HDF_ERR_MALLOC_FAIL;
}
ktimer->arg = arg;
ktimer->func = func;
ktimer->msec = interval;
OsalMutexInit(&ktimer->mutex);
timer->realTimer = (void *)ktimer;
return HDF_SUCCESS;
}
EXPORT_SYMBOL(OsalTimerCreate);
static int32_t OsalTimerStart(OsalTimer *timer, OsalTimerMode mode)
{
struct osal_ktimer *ktimer = NULL;
struct timer_list *timer_id = NULL;
if (timer == NULL || timer->realTimer == NULL) {
HDF_LOGE("%s invalid para", __func__);
return HDF_ERR_INVALID_PARAM;
}
ktimer = (struct osal_ktimer *)timer->realTimer;
timer_id = &ktimer->timer;
timer_setup(timer_id, osal_timer_callback, 0);
ktimer->mode = mode;
timer_id->expires = jiffies + msecs_to_jiffies(ktimer->msec);
add_timer(timer_id);
return HDF_SUCCESS;
}
int32_t OsalTimerStartOnce(OsalTimer *timer)
{
return OsalTimerStart(timer, OSAL_TIMER_ONCE);
}
EXPORT_SYMBOL(OsalTimerStartOnce);
int32_t OsalTimerStartLoop(OsalTimer *timer)
{
return OsalTimerStart(timer, OSAL_TIMER_LOOP);
}
EXPORT_SYMBOL(OsalTimerStartLoop);
int32_t OsalTimerSetTimeout(OsalTimer *timer, uint32_t interval)
{
struct osal_ktimer *ktimer = NULL;
if (timer == NULL || timer->realTimer == NULL || interval == 0) {
HDF_LOGE("%s invalid para", __func__);
return HDF_ERR_INVALID_PARAM;
}
ktimer = (struct osal_ktimer *)timer->realTimer;
if (ktimer->msec == interval)
return HDF_SUCCESS;
OsalMutexTimedLock(&ktimer->mutex, HDF_WAIT_FOREVER);
ktimer->msec = interval;
OsalMutexUnlock(&ktimer->mutex);
return HDF_SUCCESS;
}
EXPORT_SYMBOL(OsalTimerSetTimeout);
int32_t OsalTimerDelete(OsalTimer *timer)
{
struct osal_ktimer *ktimer = NULL;
if (timer == NULL || timer->realTimer == NULL) {
HDF_LOGE("%s invalid para", __func__);
return HDF_ERR_INVALID_PARAM;
}
ktimer = (struct osal_ktimer *)timer->realTimer;
OsalMutexTimedLock(&ktimer->mutex, HDF_WAIT_FOREVER);
ktimer->msec = 0;
OsalMutexUnlock(&ktimer->mutex);
if (ktimer->mode == OSAL_TIMER_ONCE)
add_timer(&ktimer->timer);
timer->realTimer = NULL;
return HDF_SUCCESS;
}
EXPORT_SYMBOL(OsalTimerDelete);

213
osal/src/osal_workqueue.c Normal file
View File

@ -0,0 +1,213 @@
/*
* osal_workqueue.c
*
* osal driver
*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include "hdf_workqueue.h"
#include <linux/workqueue.h>
#include "hdf_log.h"
#include "osal_mem.h"
#define HDF_LOG_TAG hdf_workqueue
struct WorkWrapper {
struct delayed_work work;
HdfWorkFunc workFunc;
void *para;
};
int32_t HdfWorkQueueInit(HdfWorkQueue *queue, char *name)
{
HDF_LOGD("%s entry", __func__);
if (queue == NULL || name == NULL) {
HDF_LOGE("%s invalid para", __func__);
return HDF_ERR_INVALID_PARAM;
}
queue->realWorkQueue = create_singlethread_workqueue(name);
if (queue->realWorkQueue == NULL) {
HDF_LOGE("%s create queue fail", __func__);
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
EXPORT_SYMBOL(HdfWorkQueueInit);
static void WorkEntry(struct work_struct *work)
{
struct WorkWrapper *wrapper = NULL;
if (work != NULL) {
wrapper = (struct WorkWrapper *)work;
if (wrapper->workFunc != NULL)
wrapper->workFunc(wrapper->para);
else
HDF_LOGE("%s routine null", __func__);
} else {
HDF_LOGE("%s work null", __func__);
}
}
int32_t HdfWorkInit(HdfWork *work, HdfWorkFunc func, void *para)
{
struct work_struct *realWork = NULL;
struct WorkWrapper *wrapper = NULL;
if (work == NULL || func == NULL) {
HDF_LOGE("%s invalid para", __func__);
return HDF_ERR_INVALID_PARAM;
}
work->realWork = NULL;
wrapper = (struct WorkWrapper *)OsalMemCalloc(sizeof(*wrapper));
if (wrapper == NULL) {
HDF_LOGE("%s malloc fail", __func__);
return HDF_ERR_MALLOC_FAIL;
}
realWork = &(wrapper->work.work);
wrapper->workFunc = func;
wrapper->para = para;
INIT_WORK(realWork, WorkEntry);
work->realWork = wrapper;
return HDF_SUCCESS;
}
EXPORT_SYMBOL(HdfWorkInit);
int32_t HdfDelayedWorkInit(HdfWork *work, HdfWorkFunc func, void *para)
{
struct delayed_work *realWork = NULL;
struct WorkWrapper *wrapper = NULL;
if (work == NULL || func == NULL) {
HDF_LOGE("%s invalid para", __func__);
return HDF_ERR_INVALID_PARAM;
}
work->realWork = NULL;
wrapper = (struct WorkWrapper *)OsalMemCalloc(sizeof(*wrapper));
if (wrapper == NULL) {
HDF_LOGE("%s malloc fail", __func__);
return HDF_ERR_MALLOC_FAIL;
}
realWork = &(wrapper->work);
wrapper->workFunc = func;
wrapper->para = para;
INIT_DELAYED_WORK(realWork, WorkEntry);
work->realWork = wrapper;
return HDF_SUCCESS;
}
EXPORT_SYMBOL(HdfDelayedWorkInit);
void HdfWorkDestroy(HdfWork *work)
{
if (work == NULL || work->realWork == NULL) {
HDF_LOGE("%s invalid para", __func__);
return;
}
OsalMemFree(work->realWork);
work->realWork = NULL;
return;
}
EXPORT_SYMBOL(HdfWorkDestroy);
void HdfDelayedWorkDestroy(HdfWork *work)
{
if (work == NULL || work->realWork == NULL) {
HDF_LOGE("%s invalid para", __func__);
return;
}
return HdfWorkDestroy(work);
}
EXPORT_SYMBOL(HdfDelayedWorkDestroy);
void HdfWorkQueueDestroy(HdfWorkQueue *queue)
{
if (queue == NULL || queue->realWorkQueue == NULL) {
HDF_LOGE("%s invalid para", __func__);
return;
}
destroy_workqueue(queue->realWorkQueue);
return;
}
EXPORT_SYMBOL(HdfWorkQueueDestroy);
bool HdfAddWork(HdfWorkQueue *queue, HdfWork *work)
{
if (queue == NULL || queue->realWorkQueue == NULL || work == NULL || work->realWork == NULL) {
HDF_LOGE("%s invalid para", __func__);
return false;
}
return queue_work(queue->realWorkQueue, &((struct WorkWrapper *)work->realWork)->work.work);
}
EXPORT_SYMBOL(HdfAddWork);
bool HdfAddDelayedWork(HdfWorkQueue *queue, HdfWork *work, unsigned long ms)
{
if (queue == NULL || queue->realWorkQueue == NULL || work == NULL || work->realWork == NULL) {
HDF_LOGE("%s invalid para", __func__);
return false;
}
return queue_delayed_work(queue->realWorkQueue, &((struct WorkWrapper *)work->realWork)->work,
msecs_to_jiffies(ms));
}
EXPORT_SYMBOL(HdfAddDelayedWork);
unsigned int HdfWorkBusy(HdfWork *work)
{
if (work == NULL || work->realWork == NULL) {
HDF_LOGE("%s invalid para", __func__);
return 0;
}
return work_busy(&((struct WorkWrapper *)work->realWork)->work.work);
}
EXPORT_SYMBOL(HdfWorkBusy);
bool HdfCancelWorkSync(HdfWork *work)
{
if (work == NULL || work->realWork == NULL) {
HDF_LOGE("%s invalid para", __func__);
return false;
}
return cancel_work_sync(&((struct WorkWrapper *)work->realWork)->work.work);
}
EXPORT_SYMBOL(HdfCancelWorkSync);
bool HdfCancelDelayedWorkSync(HdfWork *work)
{
if (work == NULL || work->realWork == NULL) {
HDF_LOGE("%s invalid para", __func__);
return false;
}
return cancel_delayed_work_sync(&((struct WorkWrapper *)work->realWork)->work);
}
EXPORT_SYMBOL(HdfCancelDelayedWorkSync);

80
platform/Kconfig Normal file
View File

@ -0,0 +1,80 @@
config DRIVERS_HDF_PLATFORM
bool "Enable HDF platform driver"
default n
depends on DRIVERS_HDF
help
Answer Y to enable HDF platform driver.
config DRIVERS_HDF_PLATFORM_MIPI_DSI
bool "Enable HDF platform mipi dsi driver"
default n
depends on DRIVERS_HDF_PLATFORM
help
Answer Y to enable HDF platform mipi dsi driver.
config DRIVERS_HDF_PLATFORM_GPIO
bool "Enable HDF platform gpio driver"
default n
depends on DRIVERS_HDF_PLATFORM
help
Answer Y to enable HDF platform gpio driver.
config DRIVERS_HDF_PLATFORM_I2C
bool "Enable HDF platform i2c driver"
default n
depends on DRIVERS_HDF_PLATFORM
help
Answer Y to enable HDF platform i2c driver.
config DRIVERS_HDF_PLATFORM_WATCHDOG
bool "Enable HDF platform watchdog driver"
default n
depends on DRIVERS_HDF_PLATFORM
help
Answer Y to enable HDF platform watchdog driver.
config PWM_HI35XX
bool "hi35xx pwm driver"
depends on PWM
help
Answer Y to enable hi35xx pwm driver
config DRIVERS_HDF_PLATFORM_PWM
bool "Enable HDF platform pwm driver"
depends on DRIVERS_HDF_PLATFORM
help
Answer Y to enable HDF platform pwm driver.
config DRIVERS_HDF_PLATFORM_UART
bool "Enable HDF platform uart driver"
depends on DRIVERS_HDF_PLATFORM
help
Answer Y to enable HDF platform uart driver.
config DRIVERS_HDF_PLATFORM_SDIO
bool "Enable HDF platform sdio driver"
default n
depends on DRIVERS_HDF_PLATFORM
help
Answer Y to enable HDF platform sdio driver.
config DRIVERS_HDF_PLATFORM_EMMC
bool "Enable HDF platform emmc driver"
default n
depends on DRIVERS_HDF_PLATFORM
help
Answer Y to enable HDF platform emmc driver.
config DRIVERS_HDF_PLATFORM_SPI
bool "Enable HDF platform spi driver"
default n
depends on DRIVERS_HDF_PLATFORM
help
Answer Y to enable HDF platform spi driver.
config DRIVERS_HDF_PLATFORM_RTC
bool "Enable HDF platform rtc driver"
default n
depends on DRIVERS_HDF_PLATFORM
help
Answer Y to enable HDF platform rtc driver.

25
platform/Makefile Normal file
View File

@ -0,0 +1,25 @@
#
# Copyright (c) 2020-2021 Huawei Device Co., Ltd.
#
# This software is licensed under the terms of the GNU General Public
# License version 2, as published by the Free Software Foundation, and
# may be copied, distributed, and modified under those terms.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
obj-$(CONFIG_DRIVERS_HDF_PLATFORM) += common/
obj-$(CONFIG_DRIVERS_HDF_PLATFORM_MIPI_DSI) += mipi_dsi/
obj-$(CONFIG_DRIVERS_HDF_PLATFORM_GPIO) += gpio/
obj-$(CONFIG_DRIVERS_HDF_PLATFORM_I2C) += i2c/
obj-$(CONFIG_DRIVERS_HDF_PLATFORM_WATCHDOG) += watchdog/
obj-y += pwm/
obj-$(CONFIG_DRIVERS_HDF_PLATFORM_UART) += uart/
obj-$(CONFIG_DRIVERS_HDF_PLATFORM_SDIO) += sdio/
obj-$(CONFIG_DRIVERS_HDF_PLATFORM_EMMC) += emmc/
obj-$(CONFIG_DRIVERS_HDF_PLATFORM_SPI) += spi/
obj-$(CONFIG_DRIVERS_HDF_PLATFORM_RTC) += rtc/

17
platform/common/Makefile Normal file
View File

@ -0,0 +1,17 @@
#
# Copyright (c) 2020-2021 Huawei Device Co., Ltd.
#
# This software is licensed under the terms of the GNU General Public
# License version 2, as published by the Free Software Foundation, and
# may be copied, distributed, and modified under those terms.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
include drivers/hdf/khdf/platform/platform.mk
obj-y += ./plat_common.o

View File

@ -0,0 +1,26 @@
/*
* plat_common.c
*
* platform common utils on linux
*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include "plat_common.h"
#include <linux/sched.h>
bool PlatInIrqContext(void)
{
return (in_irq() || in_nmi() || in_serving_softirq());
}

19
platform/emmc/Makefile Normal file
View File

@ -0,0 +1,19 @@
#
# Copyright (c) 2020-2021 Huawei Device Co., Ltd.
#
# This software is licensed under the terms of the GNU General Public
# License version 2, as published by the Free Software Foundation, and
# may be copied, distributed, and modified under those terms.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
include drivers/hdf/khdf/platform/platform.mk
obj-y += $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/emmc_core.o \
$(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/emmc_if.o \
./emmc_adapter.o

View File

@ -0,0 +1,142 @@
/*
* emmc_adatper.c
*
* hi35xx linux emmc driver implement.
*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <linux/mmc/card.h>
#include <linux/mmc/host.h>
#include <securec.h>
#include "emmc_core.h"
#include "hdf_log.h"
#define HDF_LOG_TAG emmc_adapter_c
struct mmc_host *himci_get_mmc_host(int slot);
int32_t Hi35xxLinuxEmmcGetCid(struct EmmcCntlr *cntlr, uint8_t *cid, uint32_t size)
{
struct mmc_host *mmcHost = NULL;
if (cntlr == NULL) {
HDF_LOGE("Hi35xxLinuxEmmcGetCid: cntlr is null.");
return HDF_ERR_INVALID_OBJECT;
}
if (cid == NULL || size < EMMC_CID_LEN) {
HDF_LOGE("Hi35xxLinuxEmmcGetCid: cid is null or size is invalid.");
return HDF_ERR_INVALID_PARAM;
}
mmcHost = (struct mmc_host *)cntlr->priv;
if (mmcHost == NULL) {
mmcHost = himci_get_mmc_host(cntlr->configData.hostId);
if (mmcHost == NULL) {
HDF_LOGE("Hi35xxLinuxEmmcGetCid: get_mmc_host fail again!");
return HDF_ERR_NOT_SUPPORT;
}
cntlr->priv = (void *)mmcHost;
}
if (mmcHost->card == NULL) {
HDF_LOGE("Hi35xxLinuxEmmcGetCid: card is null.");
return HDF_ERR_NOT_SUPPORT;
}
if (memcpy_s(cid, sizeof(uint8_t) * size, (uint8_t *)(mmcHost->card->raw_cid),
sizeof(mmcHost->card->raw_cid)) != EOK) {
HDF_LOGE("Hi35xxLinuxEmmcGetCid: memcpy_s fail!");
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
int32_t Hi35xxLinuxEmmcFindHost(struct EmmcCntlr *cntlr, struct EmmcConfigData *data)
{
if (cntlr == NULL || data == NULL) {
HDF_LOGE("Hi35xxLinuxEmmcFindHost: cntlr or data is null.");
return HDF_ERR_INVALID_OBJECT;
}
cntlr->priv = (void *)himci_get_mmc_host(data->hostId);
if (cntlr->priv == NULL) {
HDF_LOGE("Hi35xxLinuxEmmcFindHost: get_mmc_host fail!");
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
static struct EmmcMethod g_emmcMethod = {
.getCid = Hi35xxLinuxEmmcGetCid,
.findHost = Hi35xxLinuxEmmcFindHost,
};
static int32_t Hi35xxLinuxEmmcBind(struct HdfDeviceObject *device)
{
if (device == NULL) {
HDF_LOGE("Hi35xxLinuxEmmcBind: Fail, device is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
HDF_LOGD("Hi35xxLinuxEmmcBind: Success.");
return (EmmcCntlrCreateAndBind(device) == NULL) ? HDF_FAILURE : HDF_SUCCESS;
}
static int32_t Hi35xxLinuxEmmcInit(struct HdfDeviceObject *device)
{
struct EmmcCntlr *cntlr = NULL;
int32_t ret;
if (device == NULL) {
HDF_LOGE("Hi35xxLinuxEmmcInit: device is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
cntlr = EmmcCntlrFromDevice(device);
if (cntlr == NULL) {
HDF_LOGE("Hi35xxLinuxEmmcInit: EmmcCntlrFromDevice fail.");
return HDF_ERR_IO;
}
ret = EmmcFillConfigData(device, &(cntlr->configData));
if (ret != HDF_SUCCESS) {
HDF_LOGE("Hi35xxLinuxEmmcInit: EmmcFillConfigData fail.");
return HDF_ERR_IO;
}
cntlr->priv = (void *)himci_get_mmc_host(cntlr->configData.hostId);
cntlr->method = &g_emmcMethod;
HDF_LOGD("Hi35xxLinuxEmmcInit: Success!");
return HDF_SUCCESS;
}
static void Hi35xxLinuxEmmcRelease(struct HdfDeviceObject *device)
{
struct EmmcCntlr *cntlr = NULL;
cntlr = EmmcCntlrFromDevice(device);
if (cntlr == NULL) {
HDF_LOGE("Hi35xxLinuxEmmcRelease: Fail, cntlr is NULL.");
return;
}
EmmcCntlrDestroy(cntlr);
HDF_LOGD("Hi35xxLinuxEmmcRelease: Success.");
}
struct HdfDriverEntry g_emmcDriverEntry = {
.moduleVersion = 1,
.Bind = Hi35xxLinuxEmmcBind,
.Init = Hi35xxLinuxEmmcInit,
.Release = Hi35xxLinuxEmmcRelease,
.moduleName = "HDF_PLATFORM_EMMC",
};
HDF_INIT(g_emmcDriverEntry);

19
platform/gpio/Makefile Normal file
View File

@ -0,0 +1,19 @@
#
# Copyright (c) 2020-2021 Huawei Device Co., Ltd.
#
# This software is licensed under the terms of the GNU General Public
# License version 2, as published by the Free Software Foundation, and
# may be copied, distributed, and modified under those terms.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
include drivers/hdf/khdf/platform/platform.mk
obj-y += $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/gpio_core.o \
$(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/gpio_if.o \
./gpio_adapter.o

View File

@ -0,0 +1,234 @@
/*
* gpio_adatper.h
*
* gpio driver adapter of linux
*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <linux/gpio.h>
#include <linux/interrupt.h>
#include "device_resource_if.h"
#include "gpio_core.h"
#include "hdf_base.h"
#include "hdf_device_desc.h"
#include "hdf_dlist.h"
#include "hdf_log.h"
#include "osal_mem.h"
#include "osal_mutex.h"
#define HDF_LOG_TAG linux_gpio_adapter
static int32_t LinuxGpioWrite(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t val)
{
(void)cntlr;
gpio_set_value(gpio, val);
return HDF_SUCCESS;
}
static int32_t LinuxGpioRead(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *val)
{
(void)cntlr;
if (val != NULL) {
*val = (gpio_get_value(gpio) == 0) ?
GPIO_VAL_LOW : GPIO_VAL_HIGH;
return HDF_SUCCESS;
}
HDF_LOGE("%s: val is NULL!\n", __func__);
return HDF_ERR_BSP_PLT_API_ERR;
}
static int32_t LinuxGpioSetDir(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t dir)
{
int32_t ret;
int val;
switch (dir) {
case GPIO_DIR_IN:
ret = gpio_direction_input(gpio);
break;
case GPIO_DIR_OUT:
val = gpio_get_value(gpio);
if (val < 0) {
ret = HDF_ERR_BSP_PLT_API_ERR;
} else {
ret = gpio_direction_output(gpio, val);
}
break;
default:
HDF_LOGE("%s: invalid dir:%d\n", __func__, dir);
ret = HDF_ERR_INVALID_PARAM;
break;
}
return ret;
}
static int32_t LinuxGpioGetDir(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t *dir)
{
int dirGet;
dirGet = gpiod_get_direction(gpio_to_desc(gpio));
if (dirGet < 0) {
return HDF_ERR_BSP_PLT_API_ERR;
}
*dir = (dirGet == GPIOF_DIR_IN) ? GPIO_DIR_IN : GPIO_DIR_OUT;
return HDF_SUCCESS;
}
static irqreturn_t LinuxGpioIrqBridge(int irq, void *data)
{
int gpio = (int)(uintptr_t)data;
GpioCntlrIrqCallback(GpioGetCntlr(gpio), gpio);
return IRQ_HANDLED;
}
static int32_t LinuxGpioSetIrq(struct GpioCntlr *cntlr, uint16_t gpio, uint16_t mode,
GpioIrqFunc func, void *arg)
{
int ret, irq;
unsigned long flags = 0;
irq = gpio_to_irq(gpio);
if (irq < 0) {
HDF_LOGE("%s: gpio(%u) to irq fail:%d", __func__, gpio, irq);
return HDF_ERR_BSP_PLT_API_ERR;
}
flags |= (mode & GPIO_IRQ_TRIGGER_RISING) == 0 ? 0 : IRQF_TRIGGER_RISING;
flags |= (mode & GPIO_IRQ_TRIGGER_FALLING) == 0 ? 0 : IRQF_TRIGGER_FALLING;
flags |= (mode & GPIO_IRQ_TRIGGER_HIGH) == 0 ? 0 : IRQF_TRIGGER_HIGH;
flags |= (mode & GPIO_IRQ_TRIGGER_LOW) == 0 ? 0 : IRQF_TRIGGER_LOW;
if ((mode & GPIO_IRQ_USING_THREAD) == 0) {
ret = request_irq(irq, LinuxGpioIrqBridge, flags,
"LinuxIrqBridge", (void *)(uintptr_t)gpio);
} else {
flags |= IRQF_ONESHOT; // one shot needed for linux thread irq
ret = request_threaded_irq(irq, NULL, LinuxGpioIrqBridge, flags,
"LinuxIrqBridge", (void *)(uintptr_t)gpio);
}
if (ret == 0) {
disable_irq(irq); // disable on set
}
return (ret == 0) ? HDF_SUCCESS : HDF_ERR_BSP_PLT_API_ERR;
}
static int32_t LinuxGpioUnsetIrq(struct GpioCntlr *cntlr, uint16_t gpio)
{
int irq;
irq = gpio_to_irq(gpio);
if (irq < 0) {
HDF_LOGE("%s: gpio(%u) to irq fail:%d", __func__, gpio, irq);
return HDF_ERR_BSP_PLT_API_ERR;
}
HDF_LOGE("%s: gona free irq:%d\n", __func__, irq);
free_irq(irq, (void *)(uintptr_t)gpio);
return HDF_SUCCESS;
}
static inline int32_t LinuxGpioEnableIrq(struct GpioCntlr *cntlr, uint16_t gpio)
{
int irq;
irq = gpio_to_irq(gpio);
if (irq < 0) {
HDF_LOGE("%s: gpio(%u) to irq fail:%d", __func__, gpio, irq);
return HDF_ERR_BSP_PLT_API_ERR;
}
enable_irq(irq);
return HDF_SUCCESS;
}
static inline int32_t LinuxGpioDisableIrq(struct GpioCntlr *cntlr, uint16_t gpio)
{
int irq;
irq = gpio_to_irq(gpio);
if (irq < 0) {
HDF_LOGE("%s: gpio(%u) to irq fail:%d", __func__, gpio, irq);
return HDF_ERR_BSP_PLT_API_ERR;
}
disable_irq_nosync(irq); // nosync default in case used in own irq
return HDF_SUCCESS;
}
static struct GpioMethod g_method = {
.write = LinuxGpioWrite,
.read = LinuxGpioRead,
.setDir = LinuxGpioSetDir,
.getDir = LinuxGpioGetDir,
.setIrq = LinuxGpioSetIrq,
.unsetIrq = LinuxGpioUnsetIrq,
.enableIrq = LinuxGpioEnableIrq,
.disableIrq = LinuxGpioDisableIrq,
};
static int32_t LinuxGpioBind(struct HdfDeviceObject *device)
{
(void)device;
return HDF_SUCCESS;
}
static int32_t LinuxGpioInit(struct HdfDeviceObject *device)
{
int32_t ret;
struct GpioCntlr *cntlr = NULL;
HDF_LOGI("%s: Enter", __func__);
if (device == NULL) {
HDF_LOGE("%s: Fail, device is NULL.", __func__);
return HDF_ERR_INVALID_OBJECT;
}
cntlr = (struct GpioCntlr *)OsalMemCalloc(sizeof(*cntlr));
if (cntlr == NULL) {
HDF_LOGE("%s: malloc cntlr fail!", __func__);
return HDF_ERR_MALLOC_FAIL;
}
cntlr->device = device;
cntlr->ops = &g_method;
cntlr->count = GPIO_NUM_DEFAULT;
ret = GpioCntlrAdd(cntlr);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: add gpio controller fail:%d!", __func__, ret);
OsalMemFree(cntlr);
return ret;
}
HDF_LOGI("%s: dev service:%s init success!", __func__, HdfDeviceGetServiceName(device));
return HDF_SUCCESS;
}
static void LinuxGpioRelease(struct HdfDeviceObject *device)
{
struct GpioCntlr *cntlr = NULL;
if (device == NULL) {
HDF_LOGE("%s: device is null!", __func__);
return;
}
cntlr = GpioCntlrFromDevice(device);
if (cntlr == NULL) {
HDF_LOGE("%s: no service binded!", __func__);
return;
}
OsalMemFree(cntlr);
}
struct HdfDriverEntry g_gpioLinuxDriverEntry = {
.moduleVersion = 1,
.Bind = LinuxGpioBind,
.Init = LinuxGpioInit,
.Release = LinuxGpioRelease,
.moduleName = "linux_gpio_adapter",
};
HDF_INIT(g_gpioLinuxDriverEntry);

19
platform/i2c/Makefile Normal file
View File

@ -0,0 +1,19 @@
#
# Copyright (c) 2020-2021 Huawei Device Co., Ltd.
#
# This software is licensed under the terms of the GNU General Public
# License version 2, as published by the Free Software Foundation, and
# may be copied, distributed, and modified under those terms.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
include drivers/hdf/khdf/platform/platform.mk
obj-y += $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/i2c_core.o \
$(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/i2c_if.o \
./i2c_adapter.o

219
platform/i2c/i2c_adapter.c Normal file
View File

@ -0,0 +1,219 @@
/*
* i2c_adatper.h
*
* i2c driver adapter of linux
*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <linux/i2c.h>
#include "device_resource_if.h"
#include "hdf_device_desc.h"
#include "hdf_log.h"
#include "i2c_core.h"
#include "osal_mem.h"
#define HDF_LOG_TAG i2c_linux_adapter
static struct i2c_msg *CreateLinuxI2cMsgs(struct I2cMsg *msgs, int16_t count)
{
int16_t i;
struct i2c_msg *linuxMsgs = NULL;
linuxMsgs = (struct i2c_msg *)OsalMemCalloc(sizeof(*linuxMsgs) * count);
if (linuxMsgs == NULL) {
HDF_LOGE("%s: malloc linux msgs fail!", __func__);
return NULL;
}
for (i = 0; i < count; i++) {
linuxMsgs[i].addr = msgs[i].addr;
linuxMsgs[i].buf = msgs[i].buf;
linuxMsgs[i].len = msgs[i].len;
linuxMsgs[i].flags = msgs[i].flags;
}
return linuxMsgs;
}
static inline void FreeLinxI2cMsgs(struct i2c_msg *msgs, int16_t count)
{
OsalMemFree(msgs);
(void)count;
}
static int32_t LinuxI2cTransfer(struct I2cCntlr *cntlr, struct I2cMsg *msgs, int16_t count)
{
int32_t ret;
struct i2c_msg *linuxMsgs = NULL;
if (cntlr == NULL || cntlr->priv == NULL) {
HDF_LOGE("%s: cntlr or priv is null!", __func__);
return HDF_ERR_INVALID_OBJECT;
}
if (msgs == NULL || count <= 0) {
HDF_LOGE("%s: err parms! count:%d", __func__, count);
return HDF_ERR_INVALID_PARAM;
}
linuxMsgs = CreateLinuxI2cMsgs(msgs, count);
if (linuxMsgs == NULL) {
return HDF_ERR_MALLOC_FAIL;
}
ret = i2c_transfer((struct i2c_adapter *)cntlr->priv, linuxMsgs, count);
FreeLinxI2cMsgs(linuxMsgs, count);
return ret;
}
static struct I2cMethod g_method = {
.transfer = LinuxI2cTransfer,
};
static int32_t LinuxI2cReadDrs(struct I2cCntlr *cntlr, const struct DeviceResourceNode *node)
{
int32_t ret;
struct DeviceResourceIface *drsOps = NULL;
drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
if (drsOps == NULL || drsOps->GetUint32 == NULL) {
HDF_LOGE("%s: invalid drs ops fail!", __func__);
return HDF_FAILURE;
}
ret = drsOps->GetUint16(node, "bus", (uint16_t *)&cntlr->busId, 0);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: read bus fail!", __func__);
return ret;
}
return HDF_SUCCESS;
}
static int32_t LinuxI2cBind(struct HdfDeviceObject *device)
{
(void)device;
return HDF_SUCCESS;
}
static int32_t LinuxI2cParseAndInit(struct HdfDeviceObject *device, const struct DeviceResourceNode *node)
{
int32_t ret;
struct I2cCntlr *cntlr = NULL;
struct i2c_adapter *adapter = NULL;
HDF_LOGI("%s: Enter", __func__);
(void)device;
cntlr = (struct I2cCntlr *)OsalMemCalloc(sizeof(*cntlr));
if (cntlr == NULL) {
HDF_LOGE("%s: malloc cntlr fail!", __func__);
return HDF_ERR_MALLOC_FAIL;
}
ret = LinuxI2cReadDrs(cntlr, node);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: read drs fail! ret:%d", __func__, ret);
goto __ERR__;
}
adapter = i2c_get_adapter(cntlr->busId);
if (adapter == NULL) {
HDF_LOGE("%s: i2c_get_adapter fail!", __func__);
goto __ERR__;
}
cntlr->priv = adapter;
cntlr->ops = &g_method;
ret = I2cCntlrAdd(cntlr);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: add i2c controller fail:%d!", __func__, ret);
goto __ERR__;
}
return HDF_SUCCESS;
__ERR__:
OsalMemFree(cntlr);
return ret;
}
static int32_t LinuxI2cInit(struct HdfDeviceObject *device)
{
int32_t ret;
const struct DeviceResourceNode *childNode = NULL;
HDF_LOGI("%s: Enter", __func__);
if (device == NULL || device->property == NULL) {
HDF_LOGE("%s: device or property is NULL", __func__);
return HDF_ERR_INVALID_OBJECT;
}
ret = HDF_SUCCESS;
DEV_RES_NODE_FOR_EACH_CHILD_NODE(device->property, childNode) {
ret = LinuxI2cParseAndInit(device, childNode);
if (ret != HDF_SUCCESS) {
break;
}
}
return ret;
}
static void LinuxI2cRemoveByNode(const struct DeviceResourceNode *node)
{
int32_t ret;
int16_t bus;
struct I2cCntlr *cntlr = NULL;
struct DeviceResourceIface *drsOps = NULL;
drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
if (drsOps == NULL || drsOps->GetUint32 == NULL) {
HDF_LOGE("%s: invalid drs ops fail!", __func__);
return;
}
ret = drsOps->GetUint16(node, "bus", (uint16_t *)&bus, 0);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: read bus fail!", __func__);
return;
}
cntlr = I2cCntlrGet(bus);
if (cntlr != NULL && cntlr->priv == node) {
I2cCntlrPut(cntlr);
I2cCntlrRemove(cntlr);
OsalMemFree(cntlr);
}
return;
}
static void LinuxI2cRelease(struct HdfDeviceObject *device)
{
const struct DeviceResourceNode *childNode = NULL;
HDF_LOGI("%s: enter", __func__);
if (device == NULL || device->property == NULL) {
HDF_LOGE("%s: device or property is NULL", __func__);
return;
}
DEV_RES_NODE_FOR_EACH_CHILD_NODE(device->property, childNode) {
LinuxI2cRemoveByNode(childNode);
}
}
struct HdfDriverEntry g_i2cLinuxDriverEntry = {
.moduleVersion = 1,
.Bind = LinuxI2cBind,
.Init = LinuxI2cInit,
.Release = LinuxI2cRelease,
.moduleName = "linux_i2c_adapter",
};
HDF_INIT(g_i2cLinuxDriverEntry);

View File

@ -0,0 +1,23 @@
#
# Copyright (c) 2020-2021 Huawei Device Co., Ltd.
#
# This software is licensed under the terms of the GNU General Public
# License version 2, as published by the Free Software Foundation, and
# may be copied, distributed, and modified under those terms.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
include drivers/hdf/khdf/platform/platform.mk
obj-y += mipi_dsi_adapter.o \
$(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/mipi_dsi_core.o \
$(HDF_PLATFORM_VENDOR_ROOT)/mipi_dsi/mipi_tx_dev.o \
$(HDF_PLATFORM_VENDOR_ROOT)/mipi_dsi/mipi_tx_hi35xx.o
ccflags-y += -I$(HDF_PLATFORM_VENDOR_ROOT)/mipi_dsi \
-Idrivers/hdf/khdf/platform/mipi_dsi
EXTRA_CFLAGS += -Wno-error=date-time

View File

@ -0,0 +1,147 @@
/*
* mipi_dsi_adapter.c
*
* Mipi dsi adapter driver.
*
* Copyright (C) Huawei Device Co., Ltd. 2020-2021. All rights reserved.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include "hdf_base.h"
#include "osal_mem.h"
#include "mipi_dsi_core.h"
#include "mipi_dsi_adapter.h"
#include <asm/io.h>
#include <asm/uaccess.h>
#include <linux/cdev.h>
#include <linux/device.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/kdev_t.h>
#include <linux/miscdevice.h>
#include <linux/module.h>
#include <linux/proc_fs.h>
#include "securec.h"
#define NAME_LEN 20
static struct miscdevice *g_mipiDsiMiscdev[MAX_CNTLR_CNT];
int MipiDsiRegisterDevice(const char *name, uint32_t id, unsigned short mode, struct file_operations *ops)
{
int error;
struct miscdevice *dev = NULL;
if (name == NULL || ops == NULL || id >= MAX_CNTLR_CNT) {
return -1;
}
dev = OsalMemCalloc(sizeof(struct miscdevice));
if (dev == NULL) {
return -1;
}
dev->fops = ops;
dev->name = OsalMemCalloc(NAME_LEN + 1);
if (dev->name == NULL) {
OsalMemFree(dev);
return -1;
}
if (id != 0) { /* 0 : id */
if (snprintf_s((char *)dev->name, NAME_LEN + 1, NAME_LEN, "%s%u", name, id) < 0) {
OsalMemFree((char *)dev->name);
OsalMemFree(dev);
return -1;
}
} else {
if (memcpy_s((char *)dev->name, NAME_LEN, name, strlen(name)) != EOK) {
OsalMemFree((char *)dev->name);
OsalMemFree(dev);
return -1;
}
}
ops->owner = THIS_MODULE;
dev->minor = MISC_DYNAMIC_MINOR;
dev->mode = mode;
error = misc_register(dev);
if (error < 0) {
printk("%s: id %u cannot register miscdev on minor=%d (err=%d)\n",
__func__, id, MISC_DYNAMIC_MINOR, error);
OsalMemFree((char *)dev->name);
OsalMemFree(dev);
return error;
}
g_mipiDsiMiscdev[id] = dev;
printk("mipi_dsi:create inode ok %s %d\n", dev->name, dev->minor);
return 0;
}
int MipiDsiProcRegister(const char *name, uint32_t id, unsigned short mode, const struct file_operations *ops)
{
char procName[NAME_LEN + 1];
struct proc_dir_entry* err = NULL;
int ret;
if (name == NULL || ops == NULL || id >= MAX_CNTLR_CNT) {
return -1;
}
if (memset_s(procName, NAME_LEN + 1, 0, NAME_LEN + 1) != EOK) {
return -1;
}
if (id != 0) {
ret = snprintf_s(procName, NAME_LEN + 1, NAME_LEN, "%s%u", name, id);
} else {
ret = snprintf_s(procName, NAME_LEN + 1, NAME_LEN, "%s", name);
}
if (ret < 0) {
printk(KERN_ERR "%s: procName %s snprintf_s fail\n", __func__, procName);
return -1;
}
err = proc_create(procName, mode, NULL, ops);
if (err == NULL) {
printk(KERN_ERR "%s: proc_create name %s fail\n", __func__, procName);
return -1;
}
return 0;
}
void MipiDsiUnregisterDevice(uint32_t id)
{
if (id >= MAX_CNTLR_CNT) {
return;
}
misc_deregister(g_mipiDsiMiscdev[id]);
OsalMemFree((void *)g_mipiDsiMiscdev[id]->name);
g_mipiDsiMiscdev[id]->name = NULL;
OsalMemFree(g_mipiDsiMiscdev[id]);
g_mipiDsiMiscdev[id] = NULL;
}
void MipiDsiProcUnregister(const char *name, uint32_t id)
{
char procName[NAME_LEN + 1];
int ret;
if (id >= MAX_CNTLR_CNT) {
return;
}
memset_s(procName, NAME_LEN + 1, 0, NAME_LEN + 1);
if (id != 0) {
ret = snprintf_s(procName, NAME_LEN + 1, NAME_LEN, "%s%u", name, id);
} else {
ret = snprintf_s(procName, NAME_LEN + 1, NAME_LEN, "%s", name);
}
if (ret < 0) {
printk(KERN_ERR "%s: procName %s snprintf_s fail\n", __func__, procName);
return;
}
remove_proc_entry(procName, NULL);
}

View File

@ -0,0 +1,28 @@
/*
* mipi_dsi_adapter.h
*
* Mipi dsi adapter driver.
*
* Copyright (C) Huawei Device Co., Ltd. 2020-2021. All rights reserved.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef MIPI_DSI_ADAPTER_H
#define MIPI_DSI_ADAPTER_H
#include <linux/fs.h>
int MipiDsiRegisterDevice(const char *name, uint32_t id, unsigned short mode, struct file_operations *ops);
void MipiDsiUnregisterDevice(uint32_t id);
int MipiDsiProcRegister(const char *name, uint32_t id, unsigned short mode, const struct file_operations *ops);
void MipiDsiProcUnregister(const char *name, uint32_t id);
#endif // MIPI_DSI_ADAPTER_H

34
platform/platform.mk Normal file
View File

@ -0,0 +1,34 @@
#
# Copyright (c) 2020-2021 Huawei Device Co., Ltd.
#
# This software is licensed under the terms of the GNU General Public
# License version 2, as published by the Free Software Foundation, and
# may be copied, distributed, and modified under those terms.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
HDF_PLATFORM_FRAMEWORKS_ROOT = ../../../../../framework/support/platform
HDF_PLATFORM_VENDOR_ROOT = ../../../../../../device/hisilicon/drivers/huawei_proprietary
ccflags-$(CONFIG_DRIVERS_HDF_PLATFORM) += -Idrivers/hdf/framework/include/platform \
-Idrivers/hdf/framework/support/platform/include \
-Iinclude/hdf \
-Iinclude/hdf/osal \
-Iinclude/hdf/utils \
-Idrivers/hdf/khdf/osal/include \
-Idrivers/hdf/framework/include \
-Idrivers/hdf/framework/include/utils \
-Idrivers/hdf/framework/include/config \
-Idrivers/hdf/khdf/config/include \
-Idrivers/hdf/framework/core/manager/include \
-Idrivers/hdf/framework/core/host/include \
-Idrivers/hdf/framework/core/shared/include \
-Idrivers/hdf/framework/include/core \
-Idrivers/hdf/framework/core/common/include/host \
-Idrivers/hdf/framework/ability/sbuf/include \
-Idrivers/hdf/framework/utils/include \
-Iinclude/../drivers/hdf/../../../../../../../../../../../../../third_party/bounds_checking_function/include

15
platform/pwm/Makefile Normal file
View File

@ -0,0 +1,15 @@
#
# Copyright (c) 2020-2021 Huawei Device Co., Ltd.
#
# This software is licensed under the terms of the GNU General Public
# License version 2, as published by the Free Software Foundation, and
# may be copied, distributed, and modified under those terms.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
obj-y += adapter/

View File

@ -0,0 +1,18 @@
#
# Copyright (c) 2020-2021 Huawei Device Co., Ltd.
#
# This software is licensed under the terms of the GNU General Public
# License version 2, as published by the Free Software Foundation, and
# may be copied, distributed, and modified under those terms.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
include drivers/hdf/khdf/platform/platform.mk
obj-$(CONFIG_DRIVERS_HDF_PLATFORM_PWM) += ../$(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/pwm_core.o \
pwm_adapter.o

View File

@ -0,0 +1,153 @@
/*
* pwm_adapter.c
*
* pwm driver adapter of linux
*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <linux/pwm.h>
#include "device_resource_if.h"
#include "hdf_base.h"
#include "hdf_log.h"
#include "osal_io.h"
#include "osal_mem.h"
#include "pwm_core.h"
#include "pwm_if.h"
#define HDF_LOG_TAG HDF_PWM_LINUX_ADAPTER
int32_t HdfPwmOpen(struct PwmDev *pwm)
{
struct pwm_device *device = NULL;
if (pwm == NULL) {
HDF_LOGE("%s: pwm is null", __func__);
return HDF_ERR_INVALID_PARAM;
}
device = pwm_request(pwm->num, NULL);
if (IS_ERR(device)) {
HDF_LOGE("%s: pwm_request pwm%d fail", __func__, pwm->num);
return HDF_FAILURE;
}
pwm->cfg.period = device->state.period;
pwm->cfg.duty = device->state.duty_cycle;
pwm->cfg.polarity = device->state.polarity;
pwm->cfg.status = device->state.enabled ? PWM_ENABLE_STATUS : PWM_DISABLE_STATUS;
pwm->priv = device;
return HDF_SUCCESS;
}
int32_t HdfPwmClose(struct PwmDev *pwm)
{
if (pwm == NULL) {
HDF_LOGE("%s: pwm is null", __func__);
return HDF_ERR_INVALID_PARAM;
}
pwm_free((struct pwm_device *)pwm->priv);
return HDF_SUCCESS;
}
int32_t HdfPwmSetConfig(struct PwmDev *pwm, struct PwmConfig *config)
{
struct pwm_state state;
if (pwm == NULL || pwm->priv == NULL || config == NULL) {
HDF_LOGE("%s: hp reg or config is null", __func__);
return HDF_ERR_INVALID_PARAM;
}
state.duty_cycle = config->duty;
state.enabled = (config->status == PWM_ENABLE_STATUS) ? true : false;
state.period = config->period;
state.polarity = config->polarity;
return pwm_apply_state(pwm->priv, &state);
}
struct PwmMethod g_pwmOps = {
.setConfig = HdfPwmSetConfig,
.open = HdfPwmOpen,
.close = HdfPwmClose,
};
static int32_t HdfPwmBind(struct HdfDeviceObject *obj)
{
(void)obj;
return HDF_SUCCESS;
}
static int32_t HdfPwmInit(struct HdfDeviceObject *obj)
{
int32_t ret;
uint32_t num;
struct PwmDev *pwm = NULL;
struct DeviceResourceIface *iface = NULL;
HDF_LOGI("%s: entry", __func__);
if (obj == NULL) {
HDF_LOGE("%s: obj is null", __func__);
return HDF_ERR_INVALID_OBJECT;
}
iface = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
if (iface == NULL || iface->GetUint32 == NULL) {
HDF_LOGE("%s: face is invalid", __func__);
return HDF_FAILURE;
}
if (iface->GetUint32(obj->property, "num", &num, 0) != HDF_SUCCESS) {
HDF_LOGE("%s: read num fail", __func__);
return HDF_FAILURE;
}
pwm = (struct PwmDev *)OsalMemCalloc(sizeof(*pwm));
if (pwm == NULL) {
HDF_LOGE("%s: OsalMemCalloc pwm error", __func__);
return HDF_ERR_MALLOC_FAIL;
}
pwm->cfg.number = 0;
pwm->num = num;
pwm->method = &g_pwmOps;
pwm->busy = false;
ret = PwmDeviceAdd(obj, pwm);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: error probe, ret is %d", __func__, ret);
OsalMemFree(pwm);
}
return ret;
}
static void HdfPwmRelease(struct HdfDeviceObject *obj)
{
struct PwmDev *pwm = NULL;
HDF_LOGI("%s: entry", __func__);
if (obj == NULL) {
HDF_LOGE("%s: obj is null", __func__);
return;
}
pwm = (struct PwmDev *)obj->service;
if (pwm == NULL) {
HDF_LOGE("%s: pwm is null", __func__);
return;
}
PwmDeviceRemove(obj, pwm);
OsalMemFree(pwm);
}
struct HdfDriverEntry g_hdfPwm = {
.moduleVersion = 1,
.moduleName = "HDF_PLATFORM_PWM",
.Bind = HdfPwmBind,
.Init = HdfPwmInit,
.Release = HdfPwmRelease,
};
HDF_INIT(g_hdfPwm);

View File

@ -0,0 +1,5 @@
config PWM_HI35XX
bool "hi35xx pwm driver"
depends on PWM
help
Answer Y to enable hi35xx pwm driver.

View File

@ -0,0 +1,17 @@
#
# Copyright (c) 2020-2021 Huawei Device Co., Ltd.
#
# This software is licensed under the terms of the GNU General Public
# License version 2, as published by the Free Software Foundation, and
# may be copied, distributed, and modified under those terms.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
include drivers/hdf/khdf/platform/platform.mk
obj-$(CONFIG_PWM_HI35XX) += ../$(HDF_PLATFORM_VENDOR_ROOT)/pwm/pwm_hi35xx_linux.o

20
platform/rtc/Makefile Normal file
View File

@ -0,0 +1,20 @@
#
# Copyright (c) 2020-2021 Huawei Device Co., Ltd.
#
# This software is licensed under the terms of the GNU General Public
# License version 2, as published by the Free Software Foundation, and
# may be copied, distributed, and modified under those terms.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
include drivers/hdf/khdf/platform/platform.mk
obj-y += $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/rtc_core.o \
$(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/rtc_if.o \
$(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/rtc_base.o \
rtc_adapter.o

233
platform/rtc/rtc_adapter.c Normal file
View File

@ -0,0 +1,233 @@
/*
* rtc_adapter.c
*
* rtc driver adapter of linux
*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <linux/rtc.h>
#include "device_resource_if.h"
#include "hdf_device_desc.h"
#include "hdf_log.h"
#include "rtc_core.h"
#define HDF_LOG_TAG RTC_ADAPTER
#define MONTH_DIFF 1
#define YEAR_BASE 1900
static inline void HdfTimeToLinuxTime(const struct RtcTime *hdfTime, struct rtc_time *linuxTime)
{
linuxTime->tm_sec = hdfTime->second;
linuxTime->tm_min = hdfTime->minute;
linuxTime->tm_hour = hdfTime->hour;
linuxTime->tm_mday = hdfTime->day;
linuxTime->tm_mon = hdfTime->month - MONTH_DIFF;
linuxTime->tm_year = hdfTime->year - YEAR_BASE;
linuxTime->tm_wday = hdfTime->weekday;
linuxTime->tm_yday = rtc_year_days(linuxTime->tm_mday, linuxTime->tm_mon, linuxTime->tm_year);
}
static inline void LinuxTimeToHdfTime(struct RtcTime *hdfTime, const struct rtc_time *linuxTime)
{
hdfTime->second = linuxTime->tm_sec;
hdfTime->minute = linuxTime->tm_min;
hdfTime->hour = linuxTime->tm_hour;
hdfTime->day = linuxTime->tm_mday;
hdfTime->month = linuxTime->tm_mon + MONTH_DIFF;
hdfTime->year = linuxTime->tm_year + YEAR_BASE;
hdfTime->weekday = linuxTime->tm_wday;
}
static inline struct rtc_device *HdfGetRtcDevice(void)
{
struct rtc_device *dev = rtc_class_open(CONFIG_RTC_SYSTOHC_DEVICE);
if (dev == NULL) {
HDF_LOGE("%s: failed to get rtc device", __func__);
}
return dev;
}
static inline void HdfPutRtcDevice(struct rtc_device *dev)
{
rtc_class_close(dev);
}
static int32_t HiRtcReadTime(struct RtcHost *host, struct RtcTime *hdfTime)
{
int32_t ret;
struct rtc_time linuxTime = {0};
struct rtc_device *dev = HdfGetRtcDevice();
if (dev == NULL) {
return HDF_FAILURE;
}
ret = rtc_read_time(dev, &linuxTime);
if (ret < 0) {
HDF_LOGE("%s: rtc_read_time error, ret is %d", __func__, ret);
return ret;
}
HdfPutRtcDevice(dev);
LinuxTimeToHdfTime(hdfTime, &linuxTime);
return HDF_SUCCESS;
}
static int32_t HiRtcWriteTime(struct RtcHost *host, const struct RtcTime *hdfTime)
{
int32_t ret;
struct rtc_time linuxTime = {0};
struct rtc_device *dev = HdfGetRtcDevice();
if (dev == NULL) {
return HDF_FAILURE;
}
HdfTimeToLinuxTime(hdfTime, &linuxTime);
ret = rtc_set_time(dev, &linuxTime);
if (ret < 0) {
HDF_LOGE("%s: rtc_set_time error, ret is %d", __func__, ret);
return ret;
}
HdfPutRtcDevice(dev);
return HDF_SUCCESS;
}
static int32_t HiReadAlarm(struct RtcHost *host, enum RtcAlarmIndex alarmIndex, struct RtcTime *hdfTime)
{
int32_t ret;
struct rtc_wkalrm alarm = {0};
struct rtc_device *dev = HdfGetRtcDevice();
(void)alarmIndex;
if (dev == NULL) {
return HDF_FAILURE;
}
ret = rtc_read_alarm(dev, &alarm);
if (ret < 0) {
HDF_LOGE("%s: rtc_read_alarm error, ret is %d", __func__, ret);
return ret;
}
LinuxTimeToHdfTime(hdfTime, &(alarm.time));
HdfPutRtcDevice(dev);
return HDF_SUCCESS;
}
static int32_t HiWriteAlarm(struct RtcHost *host, enum RtcAlarmIndex alarmIndex, const struct RtcTime *hdfTime)
{
int32_t ret;
struct rtc_wkalrm alarm = {0};
struct rtc_device *dev = HdfGetRtcDevice();
(void)alarmIndex;
if (dev == NULL) {
return HDF_FAILURE;
}
HdfTimeToLinuxTime(hdfTime, &(alarm.time));
alarm.enabled = 0;
ret = rtc_set_alarm(dev, &alarm);
if (ret < 0) {
HDF_LOGE("%s: rtc_read_alarm error, ret is %d", __func__, ret);
return ret;
}
HdfPutRtcDevice(dev);
return HDF_SUCCESS;
}
static int32_t HiAlarmInterruptEnable(struct RtcHost *host, enum RtcAlarmIndex alarmIndex, uint8_t enable)
{
int32_t ret;
struct rtc_device *dev = HdfGetRtcDevice();
(void)alarmIndex;
if (dev == NULL) {
return HDF_FAILURE;
}
ret = rtc_alarm_irq_enable(dev, enable);
if (ret < 0) {
HDF_LOGE("%s: rtc_read_alarm error, ret is %d", __func__, ret);
return ret;
}
HdfPutRtcDevice(dev);
return HDF_SUCCESS;
}
static struct RtcMethod g_method = {
.ReadTime = HiRtcReadTime,
.WriteTime = HiRtcWriteTime,
.ReadAlarm = HiReadAlarm,
.WriteAlarm = HiWriteAlarm,
.RegisterAlarmCallback = NULL,
.AlarmInterruptEnable = HiAlarmInterruptEnable,
.GetFreq = NULL,
.SetFreq = NULL,
.Reset = NULL,
.ReadReg = NULL,
.WriteReg = NULL,
};
static int32_t HiRtcBind(struct HdfDeviceObject *device)
{
struct RtcHost *host = NULL;
host = RtcHostCreate(device);
if (host == NULL) {
HDF_LOGE("%s: create host fail", __func__);
return HDF_ERR_INVALID_OBJECT;
}
host->device = device;
device->service = &host->service;
return HDF_SUCCESS;
}
static int32_t HiRtcInit(struct HdfDeviceObject *device)
{
struct RtcHost *host = NULL;
if (device == NULL) {
HDF_LOGE("%s: err, device is null", __func__);
return HDF_ERR_INVALID_OBJECT;
}
host = RtcHostFromDevice(device);
host->method = &g_method;
HDF_LOGI("%s: Hdf dev service:%s init success", __func__, HdfDeviceGetServiceName(device));
return HDF_SUCCESS;
}
static void HiRtcRelease(struct HdfDeviceObject *device)
{
struct RtcHost *host = NULL;
if (device == NULL) {
return;
}
host = RtcHostFromDevice(device);
RtcHostDestroy(host);
}
struct HdfDriverEntry g_rtcDriverEntry = {
.moduleVersion = 1,
.Bind = HiRtcBind,
.Init = HiRtcInit,
.Release = HiRtcRelease,
.moduleName = "HDF_PLATFORM_RTC",
};
HDF_INIT(g_rtcDriverEntry);

19
platform/sdio/Makefile Normal file
View File

@ -0,0 +1,19 @@
#
# Copyright (c) 2020-2021 Huawei Device Co., Ltd.
#
# This software is licensed under the terms of the GNU General Public
# License version 2, as published by the Free Software Foundation, and
# may be copied, distributed, and modified under those terms.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
include drivers/hdf/khdf/platform/platform.mk
obj-y += $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/sdio_core.o \
$(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/sdio_if.o \
./sdio_adapter.o

View File

@ -0,0 +1,520 @@
/*
* sdio_adatper.c
*
* hi35xx linux sdio driver implement.
*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <linux/mmc/card.h>
#include <linux/mmc/core.h>
#include <linux/mmc/host.h>
#include <linux/mmc/sdio_func.h>
#include "plat_log.h"
#include "sdio_core.h"
#define HDF_LOG_TAG sdio_adapter_c
#define DATA_LEN_ONE_BYTE 1
#define DATA_LEN_TWO_BYTES 2
#define DATA_LEN_FOUR_BYTES 4
#define MMC_SLOT_NUM 3
struct mmc_host *himci_get_mmc_host(int slot);
static struct sdio_func *Hi35xxLinuxSdioGetFunc(struct SdioCntlr *cntlr)
{
if (cntlr == NULL) {
HDF_LOGE("Hi35xxLinuxSdioGetFunc: cntlr is null.");
return NULL;
}
return (struct sdio_func *)cntlr->priv;
}
static int32_t Hi35xxLinuxSdioIncrAddrReadBytes(struct SdioCntlr *cntlr,
uint8_t *data, uint32_t addr, uint32_t size, uint32_t timeOut)
{
struct sdio_func *func = Hi35xxLinuxSdioGetFunc(cntlr);
int32_t ret = HDF_SUCCESS;
uint16_t *output16 = NULL;
uint32_t *output32 = NULL;
if (func == NULL) {
HDF_LOGE("Hi35xxLinuxSdioIncrAddrReadBytes: func is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
if ((data == NULL) || (size == 0)) {
HDF_LOGE("Hi35xxLinuxSdioIncrAddrReadBytes: data or size is invalid.");
return HDF_ERR_INVALID_PARAM;
}
if (timeOut > 0) {
PLAT_LOGV("Hi35xxLinuxSdioIncrAddrReadBytes: use current timeOut value.");
func->enable_timeout = timeOut;
}
if (size == DATA_LEN_ONE_BYTE) {
PLAT_LOGV("Hi35xxLinuxSdioIncrAddrReadBytes: Read one byte Success!");
*data = sdio_readb(func, addr, &ret);
return ret;
}
if (size == DATA_LEN_TWO_BYTES) {
PLAT_LOGV("Hi35xxLinuxSdioIncrAddrReadBytes: Read two bytes Success!");
output16 = (uint16_t *)data;
*output16 = sdio_readw(func, addr, &ret);
return ret;
}
if (size == DATA_LEN_FOUR_BYTES) {
PLAT_LOGV("Hi35xxLinuxSdioIncrAddrReadBytes: Read four bytes Success!");
output32 = (uint32_t *)data;
*output32 = sdio_readl(func, addr, &ret);
return ret;
}
PLAT_LOGV("Hi35xxLinuxSdioIncrAddrReadBytes: Success!");
return sdio_memcpy_fromio(func, data, addr, size);
}
static int32_t Hi35xxLinuxSdioIncrAddrWriteBytes(struct SdioCntlr *cntlr,
uint8_t *data, uint32_t addr, uint32_t size, uint32_t timeOut)
{
int32_t ret = HDF_SUCCESS;
struct sdio_func *func = Hi35xxLinuxSdioGetFunc(cntlr);
if (func == NULL) {
HDF_LOGE("Hi35xxLinuxSdioIncrAddrWriteBytes: func is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
if ((data == NULL) || (size == 0)) {
HDF_LOGE("Hi35xxLinuxSdioIncrAddrWriteBytes: data or size is invalid.");
return HDF_ERR_INVALID_PARAM;
}
if (timeOut > 0) {
PLAT_LOGV("Hi35xxLinuxSdioIncrAddrWriteBytes: use current timeOut value.");
func->enable_timeout = timeOut;
}
if (size == DATA_LEN_ONE_BYTE) {
PLAT_LOGV("Hi35xxLinuxSdioIncrAddrWriteBytes: write one byte Success!");
sdio_writeb(func, *data, addr, &ret);
return ret;
}
if (size == DATA_LEN_TWO_BYTES) {
PLAT_LOGV("Hi35xxLinuxSdioIncrAddrWriteBytes: write two bytes Success!");
sdio_writew(func, *(uint16_t *)data, addr, &ret);
return ret;
}
if (size == DATA_LEN_FOUR_BYTES) {
PLAT_LOGV("Hi35xxLinuxSdioIncrAddrWriteBytes: write four bytes Success!");
sdio_writel(func, *(uint32_t *)data, addr, &ret);
return ret;
}
PLAT_LOGV("Hi35xxLinuxSdioIncrAddrWriteBytes: Success!");
return sdio_memcpy_toio(func, addr, data, size);
}
static int32_t Hi35xxLinuxSdioFixedAddrReadBytes(struct SdioCntlr *cntlr,
uint8_t *data, uint32_t addr, uint32_t size, uint32_t timeOut)
{
struct sdio_func *func = Hi35xxLinuxSdioGetFunc(cntlr);
if (func == NULL) {
HDF_LOGE("Hi35xxLinuxSdioFixedAddrReadBytes: func is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
if ((data == NULL) || (size == 0)) {
HDF_LOGE("Hi35xxLinuxSdioFixedAddrReadBytes: data or size is invalid.");
return HDF_ERR_INVALID_PARAM;
}
if (timeOut > 0) {
PLAT_LOGV("Hi35xxLinuxSdioFixedAddrReadBytes: use current timeOut value.");
func->enable_timeout = timeOut;
}
PLAT_LOGV("Hi35xxLinuxSdioFixedAddrReadBytes: Success!");
return sdio_readsb(func, data, addr, size);
}
static int32_t Hi35xxLinuxSdioFixedAddrWriteBytes(struct SdioCntlr *cntlr,
uint8_t *data, uint32_t addr, uint32_t size, uint32_t timeOut)
{
struct sdio_func *func = Hi35xxLinuxSdioGetFunc(cntlr);
if (func == NULL) {
HDF_LOGE("Hi35xxLinuxSdioFixedAddrWriteBytes: func is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
if ((data == NULL) || (size == 0)) {
HDF_LOGE("Hi35xxLinuxSdioFixedAddrReadBytes: data or size is invalid.");
return HDF_ERR_INVALID_PARAM;
}
if (timeOut > 0) {
PLAT_LOGV("Hi35xxLinuxSdioFixedAddrWriteBytes: use current timeOut value.");
func->enable_timeout = timeOut;
}
PLAT_LOGV("Hi35xxLinuxSdioFixedAddrWriteBytes: Success!");
return sdio_writesb(func, addr, data, size);
}
static int32_t Hi35xxLinuxSdioFunc0ReadBytes(struct SdioCntlr *cntlr,
uint8_t *data, uint32_t addr, uint32_t size, uint32_t timeOut)
{
int32_t ret = HDF_SUCCESS;
struct sdio_func *func = Hi35xxLinuxSdioGetFunc(cntlr);
if (func == NULL) {
HDF_LOGE("Hi35xxLinuxSdioFunc0ReadBytes: func is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
if ((data == NULL) || (size == 0)) {
HDF_LOGE("Hi35xxLinuxSdioFunc0ReadBytes: data or size is invalid.");
return HDF_ERR_INVALID_PARAM;
}
if (timeOut > 0) {
PLAT_LOGV("Hi35xxLinuxSdioFunc0ReadBytes: use current timeOut value.");
func->enable_timeout = timeOut;
}
*data = sdio_f0_readb(func, addr, &ret);
PLAT_LOGV("Hi35xxLinuxSdioFunc0ReadBytes: Success!");
return ret;
}
static int32_t Hi35xxLinuxSdioFunc0WriteBytes(struct SdioCntlr *cntlr,
uint8_t *data, uint32_t addr, uint32_t size, uint32_t timeOut)
{
int32_t ret = HDF_SUCCESS;
struct sdio_func *func = Hi35xxLinuxSdioGetFunc(cntlr);
if (func == NULL) {
HDF_LOGE("Hi35xxLinuxSdioFunc0WriteBytes: func is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
if ((data == NULL) || (size == 0)) {
HDF_LOGE("Hi35xxLinuxSdioFunc0WriteBytes: data or size is invalid.");
return HDF_ERR_INVALID_PARAM;
}
if (timeOut > 0) {
PLAT_LOGV("Hi35xxLinuxSdioFunc0WriteBytes: use current timeOut value.");
func->enable_timeout = timeOut;
}
sdio_f0_writeb(func, *data, addr, &ret);
PLAT_LOGV("Hi35xxLinuxSdioFunc0WriteBytes: Success!");
return ret;
}
static int32_t Hi35xxLinuxSdioSetBlockSize(struct SdioCntlr *cntlr, uint32_t blockSize)
{
struct sdio_func *func = Hi35xxLinuxSdioGetFunc(cntlr);
if (func == NULL) {
HDF_LOGE("Hi35xxLinuxSdioSetBlockSize, func is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
PLAT_LOGV("Hi35xxLinuxSdioSetBlockSize: Success!");
return sdio_set_block_size(func, blockSize);
}
static int32_t Hi35xxLinuxSdioGetCommonInfo(struct SdioCntlr *cntlr,
SdioCommonInfo *info, uint32_t infoType)
{
struct sdio_func *func = Hi35xxLinuxSdioGetFunc(cntlr);
if (func == NULL) {
HDF_LOGE("Hi35xxLinuxSdioGetCommonInfo: func is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
if (info == NULL) {
HDF_LOGE("Hi35xxLinuxSdioGetCommonInfo: info is null.");
return HDF_ERR_INVALID_PARAM;
}
if (infoType != SDIO_FUNC_INFO) {
HDF_LOGE("Hi35xxLinuxSdioGetCommonInfo: cur type %d is not support.", infoType);
return HDF_ERR_NOT_SUPPORT;
}
if (func->card == NULL) {
HDF_LOGE("Hi35xxLinuxSdioGetCommonInfo fail, card is null.");
return HDF_ERR_INVALID_PARAM;
}
if (func->card->host == NULL) {
HDF_LOGE("Hi35xxLinuxSdioGetCommonInfo fail, host is null.");
return HDF_ERR_INVALID_PARAM;
}
info->funcInfo.enTimeout = func->enable_timeout;
info->funcInfo.maxBlockNum = func->card->host->max_blk_count;
info->funcInfo.maxBlockSize = func->card->host->max_blk_size;
info->funcInfo.maxRequestSize = func->card->host->max_req_size;
info->funcInfo.funcNum = func->num;
info->funcInfo.irqCap = func->card->host->caps & MMC_CAP_SDIO_IRQ;
info->funcInfo.data = func;
PLAT_LOGV("Hi35xxLinuxSdioGetCommonInfo: get %d info Success!", infoType);
return HDF_SUCCESS;
}
static int32_t Hi35xxLinuxSdioSetCommonInfo(struct SdioCntlr *cntlr,
SdioCommonInfo *info, uint32_t infoType)
{
struct sdio_func *func = Hi35xxLinuxSdioGetFunc(cntlr);
if (func == NULL) {
HDF_LOGE("Hi35xxLinuxSdioSetCommonInfo: func is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
if (info == NULL) {
HDF_LOGE("Hi35xxLinuxSdioSetCommonInfo: info is null.");
return HDF_ERR_INVALID_PARAM;
}
if (infoType != SDIO_FUNC_INFO) {
HDF_LOGE("Hi35xxLinuxSdioSetCommonInfo: cur type %d is not support.", infoType);
return HDF_ERR_NOT_SUPPORT;
}
if (func->card == NULL) {
HDF_LOGE("Hi35xxLinuxSdioSetCommonInfo fail, card is null.");
return HDF_ERR_INVALID_PARAM;
}
if (func->card->host == NULL) {
HDF_LOGE("Hi35xxLinuxSdioSetCommonInfo fail, host is null.");
return HDF_ERR_INVALID_PARAM;
}
func->enable_timeout = info->funcInfo.enTimeout;
func->card->host->max_blk_count = info->funcInfo.maxBlockNum;
func->card->host->max_blk_size = info->funcInfo.maxBlockSize;
func->card->host->max_req_size = info->funcInfo.maxRequestSize;
func->num = info->funcInfo.funcNum;
PLAT_LOGV("Hi35xxLinuxSdioSetCommonInfo: set %d info Success!", infoType);
return HDF_SUCCESS;
}
static int32_t Hi35xxLinuxSdioFlushData(struct SdioCntlr *cntlr)
{
struct sdio_func *func = Hi35xxLinuxSdioGetFunc(cntlr);
if (func == NULL) {
HDF_LOGE("Hi35xxLinuxSdioFlushData: func is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
if (func->card == NULL) {
HDF_LOGE("Hi35xxLinuxSdioFlushData: card is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
return mmc_sw_reset(func->card->host);
}
static void Hi35xxLinuxSdioClaimHost(struct SdioCntlr *cntlr)
{
struct sdio_func *func = Hi35xxLinuxSdioGetFunc(cntlr);
if (func == NULL) {
HDF_LOGE("Hi35xxLinuxSdioClaimHost: func is NULL.");
return;
}
PLAT_LOGV("Hi35xxLinuxSdioClaimHost: Success!");
sdio_claim_host(func);
}
static void Hi35xxLinuxSdioReleaseHost(struct SdioCntlr *cntlr)
{
struct sdio_func *func = Hi35xxLinuxSdioGetFunc(cntlr);
if (func == NULL) {
HDF_LOGE("Hi35xxLinuxSdioReleaseHost: func is NULL.");
return;
}
PLAT_LOGV("Hi35xxLinuxSdioReleaseHost: Success!");
sdio_release_host(func);
}
static int32_t Hi35xxLinuxSdioEnableFunc(struct SdioCntlr *cntlr)
{
struct sdio_func *func = Hi35xxLinuxSdioGetFunc(cntlr);
if (func == NULL) {
HDF_LOGE("Hi35xxLinuxSdioEnableFunc: func is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
PLAT_LOGV("Hi35xxLinuxSdioEnableFunc: Success!");
return sdio_enable_func(func);
}
static int32_t Hi35xxLinuxSdioDisableFunc(struct SdioCntlr *cntlr)
{
struct sdio_func *func = Hi35xxLinuxSdioGetFunc(cntlr);
if (func == NULL) {
HDF_LOGE("Hi35xxLinuxSdioDisableFunc: func is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
PLAT_LOGV("Hi35xxLinuxSdioDisableFunc: Success!");
return sdio_disable_func(func);
}
static int32_t Hi35xxLinuxSdioClaimIrq(struct SdioCntlr *cntlr, SdioIrqHandler *handler)
{
struct sdio_func *func = Hi35xxLinuxSdioGetFunc(cntlr);
if (func == NULL) {
HDF_LOGE("Hi35xxLinuxSdioClaimIrq: func is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
if (handler == NULL) {
HDF_LOGE("Hi35xxLinuxSdioClaimIrq: handler is null.");
return HDF_ERR_INVALID_PARAM;
}
PLAT_LOGV("Hi35xxLinuxSdioClaimIrq: Success!");
return sdio_claim_irq(func, (sdio_irq_handler_t *)handler);
}
static int32_t Hi35xxLinuxSdioReleaseIrq(struct SdioCntlr *cntlr)
{
struct sdio_func *func = Hi35xxLinuxSdioGetFunc(cntlr);
if (func == NULL) {
HDF_LOGE("Hi35xxLinuxSdioReleaseIrq: func is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
PLAT_LOGV("Hi35xxLinuxSdioReleaseIrq: Success!");
return sdio_release_irq(func);
}
static struct sdio_func *Hi35xxLinuxSdioSearchFunc(uint32_t funcNum, uint32_t vendorId, uint32_t deviceId)
{
struct mmc_card *card = NULL;
struct mmc_host *host = NULL;
struct sdio_func *func = NULL;
uint32_t i, j;
for (i = 0; i < MMC_SLOT_NUM; i++) {
host = himci_get_mmc_host(i);
if (host == NULL) {
continue;
}
card = host->card;
if (card == NULL) {
continue;
}
for (j = 0; j <= card->sdio_funcs; j++) {
func = card->sdio_func[j];
if ((func != NULL) &&
(func->num == funcNum) &&
(func->vendor == vendorId) &&
(func->device == deviceId)) {
return func;
}
}
}
HDF_LOGE("Hi35xxLinuxSdioSearchFunc: get sdio func fail!");
return NULL;
}
static int32_t Hi35xxLinuxSdioFindFunc(struct SdioCntlr *cntlr, struct SdioConfigData *configData)
{
if (cntlr == NULL || configData == NULL) {
HDF_LOGE("Hi35xxLinuxSdioFindFunc: cntlr or configData is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
cntlr->priv = Hi35xxLinuxSdioSearchFunc(configData->funcNum, configData->vendorId, configData->deviceId);
if (cntlr->priv == NULL) {
HDF_LOGE("Hi35xxLinuxSdioFindFunc: Hi35xxLinuxSdioSearchFunc fail.");
return HDF_ERR_NOT_SUPPORT;
}
PLAT_LOGV("Hi35xxLinuxSdioFindFunc: Success.");
return HDF_SUCCESS;
}
static struct SdioMethod g_method = {
.incrAddrReadBytes = Hi35xxLinuxSdioIncrAddrReadBytes,
.incrAddrWriteBytes = Hi35xxLinuxSdioIncrAddrWriteBytes,
.fixedAddrReadBytes = Hi35xxLinuxSdioFixedAddrReadBytes,
.fixedAddrWriteBytes = Hi35xxLinuxSdioFixedAddrWriteBytes,
.func0ReadBytes = Hi35xxLinuxSdioFunc0ReadBytes,
.func0WriteBytes = Hi35xxLinuxSdioFunc0WriteBytes,
.setBlockSize = Hi35xxLinuxSdioSetBlockSize,
.getCommonInfo = Hi35xxLinuxSdioGetCommonInfo,
.setCommonInfo = Hi35xxLinuxSdioSetCommonInfo,
.flushData = Hi35xxLinuxSdioFlushData,
.claimHost = Hi35xxLinuxSdioClaimHost,
.releaseHost = Hi35xxLinuxSdioReleaseHost,
.enableFunc = Hi35xxLinuxSdioEnableFunc,
.disableFunc = Hi35xxLinuxSdioDisableFunc,
.claimIrq = Hi35xxLinuxSdioClaimIrq,
.releaseIrq = Hi35xxLinuxSdioReleaseIrq,
.findFunc = Hi35xxLinuxSdioFindFunc,
};
static int32_t Hi35xxLinuxSdioBind(struct HdfDeviceObject *device)
{
PLAT_LOGV("Hi35xxLinuxSdioBind: entry.");
if (device == NULL) {
HDF_LOGE("Hi35xxLinuxSdioBind: Fail, device is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
PLAT_LOGV("Hi35xxLinuxSdioBind: Success.");
return (SdioCntlrCreateAndBind(device) == NULL) ? HDF_FAILURE : HDF_SUCCESS;
}
static int32_t Hi35xxLinuxSdioInit(struct HdfDeviceObject *device)
{
struct SdioCntlr *cntlr = NULL;
int32_t ret;
PLAT_LOGV("Hi35xxLinuxSdioInit: entry!");
if (device == NULL) {
HDF_LOGE("Hi35xxLinuxSdioInit: device is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
cntlr = SdioCntlrFromDevice(device);
if (cntlr == NULL) {
HDF_LOGE("Hi35xxLinuxSdioInit: SdioHostFromDevice fail.");
return HDF_ERR_IO;
}
ret = SdioFillConfigData(device, &(cntlr->configData));
if (ret != HDF_SUCCESS) {
HDF_LOGE("Hi35xxLinuxSdioInit: SdioFillConfigData fail.");
return HDF_ERR_IO;
}
cntlr->method = &g_method;
PLAT_LOGV("Hi35xxLinuxSdioInit: Success!");
return HDF_SUCCESS;
}
static void Hi35xxLinuxSdioRelease(struct HdfDeviceObject *device)
{
struct SdioCntlr *cntlr = NULL;
PLAT_LOGV("Hi35xxLinuxSdioRelease: entry!");
cntlr = SdioCntlrFromDevice(device);
if (cntlr == NULL) {
HDF_LOGE("Hi35xxLinuxSdioRelease: Fail, cntlr is NULL.");
return;
}
SdioCntlrDestroy(cntlr);
PLAT_LOGV("Hi35xxLinuxSdioRelease: Success.");
}
struct HdfDriverEntry g_sdioDriverEntry = {
.moduleVersion = 1,
.Bind = Hi35xxLinuxSdioBind,
.Init = Hi35xxLinuxSdioInit,
.Release = Hi35xxLinuxSdioRelease,
.moduleName = "HDF_PLATFORM_SDIO",
};
HDF_INIT(g_sdioDriverEntry);

20
platform/spi/Makefile Normal file
View File

@ -0,0 +1,20 @@
#
# Copyright (c) 2020-2021 Huawei Device Co., Ltd.
#
# This software is licensed under the terms of the GNU General Public
# License version 2, as published by the Free Software Foundation, and
# may be copied, distributed, and modified under those terms.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
include drivers/hdf/khdf/platform/platform.mk
obj-y += $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/spi_core.o \
$(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/spi_if.o \
hi35xx_spi_adapter.o

View File

@ -0,0 +1,392 @@
/*
* spi_adapter.c
*
* spi driver adapter of linux
*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <linux/spi/spi.h>
#include "device_resource_if.h"
#include "hdf_base.h"
#include "hdf_dlist.h"
#include "hdf_log.h"
#include "osal_io.h"
#include "osal_mem.h"
#include "osal_time.h"
#include "spi_core.h"
#include "spi_if.h"
#define HDF_LOG_TAG HDF_SPI_LINUX_ADAPTER
#define SPI_DEV_NEED_FIND_NEXT 0
#define SPI_DEV_CREAT_FAILURE 1
#define SPI_DEV_FIND_SUCCESS 2
static uint16_t HdfSpiModeToLinuxMode(uint16_t mode)
{
return ((!!(mode & SPI_CLK_PHASE) ? SPI_CPHA : 0) |
(!!(mode & SPI_CLK_POLARITY) ? SPI_CPOL : 0) |
(!!(mode & SPI_MODE_CS_HIGH) ? SPI_CS_HIGH : 0) |
(!!(mode & SPI_MODE_LSBFE) ? SPI_LSB_FIRST : 0) |
(!!(mode & SPI_MODE_3WIRE) ? SPI_3WIRE : 0) |
(!!(mode & SPI_MODE_LOOP) ? SPI_LOOP : 0) |
(!!(mode & SPI_MODE_NOCS) ? SPI_NO_CS : 0) |
(!!(mode & SPI_MODE_READY) ? SPI_READY : 0));
}
static uint16_t LinuxSpiModeToHdfMode(uint16_t mode)
{
return ((!!(mode & SPI_CPHA) ? SPI_CLK_PHASE : 0) |
(!!(mode & SPI_CPOL) ? SPI_CLK_POLARITY : 0) |
(!!(mode & SPI_CS_HIGH) ? SPI_MODE_CS_HIGH : 0) |
(!!(mode & SPI_LSB_FIRST) ? SPI_MODE_LSBFE : 0) |
(!!(mode & SPI_3WIRE) ? SPI_MODE_3WIRE : 0) |
(!!(mode & SPI_LOOP) ? SPI_MODE_LOOP : 0) |
(!!(mode & SPI_NO_CS) ? SPI_MODE_NOCS : 0) |
(!!(mode & SPI_READY) ? SPI_MODE_READY : 0));
}
static struct SpiDev *SpiFindDeviceByCsNum(const struct SpiCntlr *cntlr, uint32_t cs)
{
struct SpiDev *dev = NULL;
struct SpiDev *tmpDev = NULL;
if (cntlr->numCs <= cs) {
HDF_LOGE("%s: invalid cs %u", __func__, cs);
return NULL;
}
DLIST_FOR_EACH_ENTRY_SAFE(dev, tmpDev, &(cntlr->list), struct SpiDev, list) {
if (dev->csNum == cs) {
return dev;
}
}
return NULL;
}
static int32_t SpiAdatperSetCfg(struct SpiCntlr *cntlr, struct SpiCfg *cfg)
{
int32_t ret;
struct SpiDev *dev = NULL;
struct spi_device *spidev = NULL;
if (cntlr == NULL || cfg == NULL) {
HDF_LOGE("%s: invalid parameter", __func__);
return HDF_ERR_INVALID_PARAM;
}
dev = SpiFindDeviceByCsNum(cntlr, cntlr->curCs);
if (dev == NULL || dev->priv == NULL) {
HDF_LOGE("%s: dev is invalid", __func__);
return HDF_FAILURE;
}
spidev = (struct spi_device *)dev->priv;
spidev->bits_per_word = cfg->bitsPerWord;
spidev->max_speed_hz = cfg->maxSpeedHz;
spidev->mode = HdfSpiModeToLinuxMode(cfg->mode);
ret = spi_setup(spidev);
if (ret != 0) {
HDF_LOGE("%s: spi_setup fail, ret is %d", __func__, ret);
return HDF_FAILURE;
}
dev->cfg = *cfg;
return HDF_SUCCESS;
}
static int32_t SpiAdatperGetCfg(struct SpiCntlr *cntlr, struct SpiCfg *cfg)
{
struct SpiDev *dev = NULL;
if (cntlr == NULL || cfg == NULL) {
HDF_LOGE("%s: invalid parameter", __func__);
return HDF_ERR_INVALID_PARAM;
}
dev = SpiFindDeviceByCsNum(cntlr, cntlr->curCs);
if (dev == NULL || dev->priv == NULL) {
HDF_LOGE("%s: fail, dev is invalid", __func__);
return HDF_FAILURE;
}
*cfg = dev->cfg;
return HDF_SUCCESS;
}
static int32_t SpiAdatperTransfer(struct SpiCntlr *cntlr, struct SpiMsg *msg, uint32_t count)
{
int32_t ret;
uint32_t i;
struct spi_message xfer;
struct SpiDev *dev = NULL;
struct spi_transfer *transfer = NULL;
if (cntlr == NULL || msg == NULL || count == 0) {
HDF_LOGE("%s: invalid parameter", __func__);
return HDF_ERR_INVALID_PARAM;
}
dev = SpiFindDeviceByCsNum(cntlr, cntlr->curCs);
if (dev == NULL || dev->priv == NULL) {
HDF_LOGE("%s fail, spidev is null\n", __func__);
return HDF_FAILURE;
}
transfer = kcalloc(count, sizeof(*transfer), GFP_KERNEL);
if (transfer == NULL) {
HDF_LOGE("%s: transfer alloc memory failed", __func__);
return HDF_ERR_MALLOC_FAIL;
}
spi_message_init(&xfer);
for (i = 0; i < count; i++) {
transfer[i].tx_buf = msg[i].wbuf;
transfer[i].rx_buf = msg[i].rbuf;
transfer[i].len = msg[i].len;
if (msg[i].speed != 0)
transfer[i].speed_hz = msg[i].speed;
if (msg[i].csChange != 0)
transfer[i].cs_change = msg[i].csChange;
if (msg[i].delayUs != 0)
transfer[i].delay_usecs = msg[i].delayUs;
spi_message_add_tail(&transfer[i], &xfer);
}
ret = spi_sync(dev->priv, &xfer);
kfree(transfer);
return ret;
}
static const char *GetSpiDevName(const struct device *dev)
{
if (dev->init_name) {
return dev->init_name;
}
return kobject_name(&dev->kobj);
}
static void SpiDevInit(struct SpiDev *dev, const struct spi_device *spidev)
{
dev->cfg.bitsPerWord = spidev->bits_per_word;
dev->cfg.maxSpeedHz = spidev->max_speed_hz;
dev->cfg.mode = LinuxSpiModeToHdfMode(spidev->mode);
dev->cfg.transferMode = SPI_INTERRUPT_TRANSFER;
dev->priv = (struct spi_device *)spidev;
}
static struct SpiDev *SpiDevCreat(struct SpiCntlr *cntlr)
{
struct SpiDev *dev = NULL;
dev = (struct SpiDev *)OsalMemCalloc(sizeof(*dev));
if (dev == NULL) {
HDF_LOGE("%s: OsalMemCalloc dev error", __func__);
return NULL;
}
DListHeadInit(&dev->list);
DListInsertTail(&dev->list, &cntlr->list);
return dev;
}
static int32_t SpiFindDeviceFromBus(struct device *dev, void *para)
{
struct spi_device *spidev = NULL;
struct SpiDev *spi = NULL;
struct SpiCntlr *cntlr = (struct SpiCntlr *)para;
if (dev == NULL || cntlr == NULL) {
HDF_LOGE("%s: invalid parameter", __func__);
return HDF_ERR_INVALID_PARAM;
}
spidev = CONTAINER_OF(dev, struct spi_device, dev);
get_device(&spidev->dev);
if (spidev->master == NULL) {
put_device(&spidev->dev);
HDF_LOGE("%s: spi_device %s -> master is NULL", __func__, GetSpiDevName(&spidev->dev));
return HDF_ERR_INVALID_PARAM;
}
HDF_LOGI("%s: spi_device %s, find success", __func__, GetSpiDevName(&spidev->dev));
HDF_LOGI("%s: spi_device bus_num %d, chip_select %d", __func__,
spidev->master->bus_num, spidev->chip_select);
if (spidev->master->bus_num == cntlr->busNum && spidev->chip_select == cntlr->curCs) {
spi = SpiFindDeviceByCsNum(cntlr, cntlr->curCs);
if (spi == NULL) {
spi = SpiDevCreat(cntlr);
}
if (spi == NULL) {
put_device(&spidev->dev);
return SPI_DEV_CREAT_FAILURE;
}
SpiDevInit(spi, spidev);
return SPI_DEV_FIND_SUCCESS;
} else {
put_device(&spidev->dev);
return SPI_DEV_NEED_FIND_NEXT;
}
}
static int32_t SpiAdatperOpen(struct SpiCntlr *cntlr)
{
int32_t ret;
if (cntlr == NULL) {
HDF_LOGE("%s: fail, cntlr is NULL", __func__);
return HDF_ERR_INVALID_PARAM;
}
ret = bus_for_each_dev(&spi_bus_type, NULL, (void *)cntlr, SpiFindDeviceFromBus);
if (ret != SPI_DEV_FIND_SUCCESS) {
HDF_LOGE("%s: spidev find fail, ret is %d", __func__, ret);
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
static int32_t SpiAdatperClose(struct SpiCntlr *cntlr)
{
struct SpiDev *dev = NULL;
struct spi_device *spidev = NULL;
if (cntlr == NULL) {
HDF_LOGE("%s: fail, cntlr is NULL", __func__);
return HDF_FAILURE;
}
dev = SpiFindDeviceByCsNum(cntlr, cntlr->curCs);
if (dev == NULL) {
HDF_LOGE("%s fail, dev is NULL", __func__);
return HDF_FAILURE;
}
spidev = (struct spi_device *)dev->priv;
if (spidev == NULL) {
HDF_LOGE("%s fail, spidev is NULL", __func__);
return HDF_FAILURE;
}
put_device(&spidev->dev);
return HDF_SUCCESS;
}
struct SpiCntlrMethod g_method = {
.Transfer = SpiAdatperTransfer,
.SetCfg = SpiAdatperSetCfg,
.GetCfg = SpiAdatperGetCfg,
.Open = SpiAdatperOpen,
.Close = SpiAdatperClose,
};
static int32_t SpiGetBaseCfgFromHcs(struct SpiCntlr *cntlr, const struct DeviceResourceNode *node)
{
struct DeviceResourceIface *iface = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
if (iface == NULL || iface->GetUint32 == NULL) {
HDF_LOGE("%s: face is invalid", __func__);
return HDF_FAILURE;
}
if (iface->GetUint32(node, "busNum", &cntlr->busNum, 0) != HDF_SUCCESS) {
HDF_LOGE("%s: read busNum fail", __func__);
return HDF_FAILURE;
}
if (iface->GetUint32(node, "numCs", &cntlr->numCs, 0) != HDF_SUCCESS) {
HDF_LOGE("%s: read numCs fail", __func__);
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
static int SpiCntlrInit(struct SpiCntlr *cntlr, const struct HdfDeviceObject *device)
{
int ret;
if (device->property == NULL) {
HDF_LOGE("%s: property is NULL", __func__);
return HDF_ERR_INVALID_PARAM;
}
ret = SpiGetBaseCfgFromHcs(cntlr, device->property);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: SpiGetBaseCfgFromHcs error", __func__);
return HDF_FAILURE;
}
cntlr->method = &g_method;
return 0;
}
static int32_t HdfSpiDeviceBind(struct HdfDeviceObject *device)
{
HDF_LOGI("%s: entry", __func__);
if (device == NULL) {
return HDF_ERR_INVALID_OBJECT;
}
return (SpiCntlrCreate(device) == NULL) ? HDF_FAILURE : HDF_SUCCESS;
}
static int32_t HdfSpiDeviceInit(struct HdfDeviceObject *device)
{
int ret;
struct SpiCntlr *cntlr = NULL;
HDF_LOGI("%s: entry", __func__);
if (device == NULL) {
HDF_LOGE("%s: device is NULL", __func__);
return HDF_ERR_INVALID_OBJECT;
}
cntlr = SpiCntlrFromDevice(device);
if (cntlr == NULL) {
HDF_LOGE("%s: cntlr is NULL", __func__);
return HDF_FAILURE;
}
ret = SpiCntlrInit(cntlr, device);
if (ret != 0) {
HDF_LOGE("%s: SpiCntlrInit error", __func__);
return HDF_FAILURE;
}
return ret;
}
static void HdfSpiDeviceRelease(struct HdfDeviceObject *device)
{
struct SpiCntlr *cntlr = NULL;
struct SpiDev *dev = NULL;
struct SpiDev *tmpDev = NULL;
HDF_LOGI("%s: entry", __func__);
if (device == NULL) {
HDF_LOGE("%s: device is NULL", __func__);
return;
}
cntlr = SpiCntlrFromDevice(device);
if (cntlr == NULL) {
HDF_LOGE("%s: cntlr is NULL", __func__);
return;
}
DLIST_FOR_EACH_ENTRY_SAFE(dev, tmpDev, &(cntlr->list), struct SpiDev, list) {
DListRemove(&(dev->list));
OsalMemFree(dev);
}
SpiCntlrDestroy(cntlr);
}
struct HdfDriverEntry g_hdfSpiDevice = {
.moduleVersion = 1,
.moduleName = "HDF_PLATFORM_SPI",
.Bind = HdfSpiDeviceBind,
.Init = HdfSpiDeviceInit,
.Release = HdfSpiDeviceRelease,
};
HDF_INIT(g_hdfSpiDevice);

19
platform/uart/Makefile Normal file
View File

@ -0,0 +1,19 @@
#
# Copyright (c) 2020-2021 Huawei Device Co., Ltd.
#
# This software is licensed under the terms of the GNU General Public
# License version 2, as published by the Free Software Foundation, and
# may be copied, distributed, and modified under those terms.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
include drivers/hdf/khdf/platform/platform.mk
obj-y += $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/uart_core.o \
$(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/uart_if.o \
uart_adapter.o

View File

@ -0,0 +1,497 @@
/*
* uart_adatper.c
*
* linux uart driver adapter.
*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <linux/termios.h>
#include <asm/ioctls.h>
#include <linux/serial.h>
#include <linux/fs.h>
#include "device_resource_if.h"
#include "hdf_base.h"
#include "hdf_log.h"
#include "osal_io.h"
#include "osal_mem.h"
#include "osal_time.h"
#include "securec.h"
#include "uart_if.h"
#include "uart_core.h"
#define HDF_LOG_TAG hdf_uart_adapter
#define UART_NAME_LEN 20
extern ssize_t __vfs_write(struct file *, const char __user *, size_t, loff_t *);
static char g_driverName[UART_NAME_LEN];
static int32_t UartAdapterInit(struct UartHost *host)
{
char name[UART_NAME_LEN] = {0};
struct file *fp = NULL;
mm_segment_t oldfs;
if (host == NULL) {
return HDF_FAILURE;
}
if (sprintf_s(name, UART_NAME_LEN - 1, "/dev/%s%d", g_driverName, host->num) < 0) {
return HDF_FAILURE;
}
oldfs = get_fs();
set_fs(KERNEL_DS);
fp = filp_open(name, O_RDWR | O_NOCTTY | O_NDELAY, 0600); /* 0600 : file mode */
if (IS_ERR(fp)) {
HDF_LOGE("filp_open %s fail", name);
set_fs(oldfs);
return HDF_FAILURE;
}
set_fs(oldfs);
host->priv = fp;
return HDF_SUCCESS;
}
static int32_t UartAdapterDeInit(struct UartHost *host)
{
int32_t ret = HDF_SUCCESS;
struct file *fp = (struct file *)host->priv;
mm_segment_t oldfs;
oldfs = get_fs();
set_fs(KERNEL_DS);
if (!IS_ERR(fp) && fp) {
ret = filp_close(fp, NULL);
}
set_fs(oldfs);
return ret;
}
static int32_t UartAdapterRead(struct UartHost *host, uint8_t *data, uint32_t size)
{
loff_t pos = 0;
int ret;
struct file *fp = (struct file *)host->priv;
char __user *p = (__force char __user *)data;
mm_segment_t oldfs;
uint32_t tmp = 0;
if (data == NULL || size == 0) {
return HDF_FAILURE;
}
oldfs = get_fs();
set_fs(KERNEL_DS);
while (size >= tmp) {
ret = __vfs_read(fp, p + tmp, 1, &pos);
if (ret < 0) {
HDF_LOGE("__vfs_read fail %d", ret);
break;
}
tmp++;
}
set_fs(oldfs);
return tmp;
}
static int32_t UartAdapterWrite(struct UartHost *host, uint8_t *data, uint32_t size)
{
loff_t pos = 0;
int ret;
struct file *fp = (struct file *)host->priv;
char __user *p = (__force char __user *)data;
mm_segment_t oldfs;
if (data == NULL || size == 0) {
return HDF_FAILURE;
}
oldfs = get_fs();
set_fs(KERNEL_DS);
ret = __vfs_write(fp, p, size, &pos);
if (ret < 0) {
HDF_LOGE("__vfs_write fail %d", ret);
set_fs(oldfs);
return HDF_FAILURE;
}
set_fs(oldfs);
return HDF_SUCCESS;
}
static int UartAdapterIoctlInner(struct file *fp, unsigned cmd, unsigned long arg)
{
int ret = HDF_FAILURE;
mm_segment_t oldfs;
oldfs = get_fs();
set_fs(KERNEL_DS);
if (fp->f_op->unlocked_ioctl) {
ret = fp->f_op->unlocked_ioctl(fp, cmd, arg);
}
set_fs(oldfs);
return ret;
}
static uint32_t CflagToBaudRate(unsigned short flag)
{
uint32_t baud;
switch ((flag | CBAUD)) {
case B1800:
baud = 1800; /* 1800 : baudrate */
break;
case B2400:
baud = 2400; /* 2400 : baudrate */
break;
case B4800:
baud = 4800; /* 4800 : baudrate */
break;
case B9600:
baud = 9600; /* 9600 : baudrate */
break;
case B19200:
baud = 19200; /* 19200 : baudrate */
break;
case B38400:
baud = 38400; /* 38400 : baudrate */
break;
case B57600:
baud = 57600; /* 57600 : baudrate */
break;
case B115200:
baud = 115200; /* 115200 : baudrate */
break;
case B230400:
baud = 230400; /* 230400: baudrate */
break;
case B460800:
baud = 460800; /* 460800: baudrate */
break;
case B500000:
baud = 500000; /* 500000: baudrate */
break;
case B576000:
baud = 576000; /* 576000: baudrate */
break;
case B921600:
baud = 921600; /* 921600: baudrate */
break;
default:
baud = 9600; /* 9600 : baudrate on default */
break;
}
return baud;
}
static int32_t UartAdapterGetBaud(struct UartHost *host, uint32_t *baudRate)
{
struct termios termios;
struct file *fp = (struct file *)host->priv;
if (baudRate == NULL) {
return HDF_FAILURE;
}
if (UartAdapterIoctlInner(fp, TCGETS, (unsigned long)&termios) < 0) {
HDF_LOGE("tcgets fail");
return HDF_FAILURE;
}
*baudRate = CflagToBaudRate(termios.c_cflag);
return HDF_SUCCESS;
}
static unsigned short BaudRateToCflag(uint32_t baudRate)
{
unsigned short ret;
switch (baudRate) {
case 1800: /* 1800 : baudrate */
ret = B1800;
break;
case 2400: /* 2400 : baudrate */
ret = B2400;
break;
case 4800: /* 4800 : baudrate */
ret = B4800;
break;
case 9600: /* 9600 : baudrate */
ret = B9600;
break;
case 19200: /* 19200 : baudrate */
ret = B19200;
break;
case 38400: /* 38400 : baudrate */
ret = B38400;
break;
case 57600: /* 57600 : baudrate */
ret = B57600;
break;
case 115200: /* 115200 : baudrate */
ret = B115200;
break;
case 230400: /* 230400 : baudrate */
ret = B230400;
break;
case 460800: /* 460800 : baudrate */
ret = B460800;
break;
case 500000: /* 500000 : baudrate */
ret = B500000;
break;
case 576000: /* 576000 : baudrate */
ret = B576000;
break;
case 921600: /* 921600 : baudrate */
ret = B921600;
break;
default:
ret = B9600;
break;
}
return ret;
}
static int32_t UartAdapterSetBaud(struct UartHost *host, uint32_t baudRate)
{
struct termios termios;
struct serial_struct serial;
struct file *fp = NULL;
int ret;
if (host == NULL) {
return HDF_ERR_INVALID_OBJECT;
}
fp = (struct file *)host->priv;
if (UartAdapterIoctlInner(fp, TCGETS, (unsigned long)&termios) < 0) {
HDF_LOGE("tcgets fail");
return HDF_FAILURE;
}
termios.c_cflag &= ~CBAUD;
termios.c_cflag |= BaudRateToCflag(baudRate);
termios.c_cc[VMIN] = 0;
termios.c_cc[VTIME] = 0;
ret = UartAdapterIoctlInner(fp, TCSETS, (unsigned long)&termios);
/* Set low latency */
if (UartAdapterIoctlInner(fp, TIOCGSERIAL, (unsigned long)&serial) < 0) {
HDF_LOGE("tiocgserial fail");
return HDF_FAILURE;
}
serial.flags |= ASYNC_LOW_LATENCY;
ret = UartAdapterIoctlInner(fp, TIOCSSERIAL, (unsigned long)&serial);
return ret;
}
static unsigned char CSToAttr(unsigned short cs)
{
unsigned short t = cs & ~CSIZE;
if (t == CS7) {
return UART_ATTR_DATABIT_7;
} else if (t == CS8) {
return UART_ATTR_DATABIT_8;
} else if (t == CS6) {
return UART_ATTR_DATABIT_6;
} else if (t == CS5) {
return UART_ATTR_DATABIT_5;
} else {
/* defaule value */
return UART_ATTR_DATABIT_8;
}
}
static unsigned short AttrToCs(unsigned char attr)
{
if (attr == UART_ATTR_DATABIT_7) {
return CS7;
} else if (attr == UART_ATTR_DATABIT_8) {
return CS8;
} else if (attr == UART_ATTR_DATABIT_6) {
return CS6;
} else if (attr == UART_ATTR_DATABIT_5) {
return CS5;
} else {
/* defaule value */
return CS8;
}
}
static unsigned char PariTyToAttr(unsigned short ps)
{
if (ps & (PARENB | PARODD)) {
return UART_ATTR_PARITY_ODD;
} else if (!(ps & PARODD) && (ps & PARENB)) {
return UART_ATTR_PARITY_EVEN;
} else if (!(ps & (PARENB | PARODD))) {
return UART_ATTR_PARITY_NONE;
} else {
/* defaule value */
return UART_ATTR_PARITY_NONE;
}
}
static unsigned char StopBitToAttr(unsigned short st)
{
if (!(st & CSTOPB)) {
return UART_ATTR_STOPBIT_1;
} else if (st & CSTOPB) {
return UART_ATTR_STOPBIT_2;
} else {
/* defaule value */
return UART_ATTR_STOPBIT_1;
}
}
static unsigned char CtsRtsToAttr(unsigned short cr)
{
if (cr & CRTSCTS) {
return UART_ATTR_RTS_EN;
}
return UART_ATTR_RTS_DIS;
}
static int32_t UartAdapterGetAttribute(struct UartHost *host, struct UartAttribute *attribute)
{
struct termios termios;
struct file *fp = (struct file *)host->priv;
int ret;
if (attribute == NULL) {
return HDF_FAILURE;
}
ret = UartAdapterIoctlInner(fp, TCGETS, (unsigned long)&termios);
if (ret < 0) {
return HDF_FAILURE;
}
attribute->dataBits = CSToAttr(termios.c_cflag);
attribute->parity = PariTyToAttr(termios.c_cflag);
attribute->stopBits = StopBitToAttr(termios.c_cflag);
attribute->cts = CtsRtsToAttr(termios.c_cflag);
attribute->rts = CtsRtsToAttr(termios.c_cflag);
return HDF_SUCCESS;
}
static int32_t UartAdapterSetAttribute(struct UartHost *host, struct UartAttribute *attribute)
{
struct termios termios;
struct file *fp = (struct file *)host->priv;
int ret;
if (attribute == NULL) {
return HDF_FAILURE;
}
ret = UartAdapterIoctlInner(fp, TCGETS, (unsigned long)&termios);
if (ret < 0) {
return HDF_FAILURE;
}
termios.c_cflag |= CLOCAL | CREAD;
termios.c_cflag &= ~CSIZE;
termios.c_cflag |= AttrToCs(attribute->dataBits);
if (attribute->cts || attribute->rts) {
termios.c_cflag |= CRTSCTS;
} else {
termios.c_cflag &= ~CRTSCTS;
}
if (attribute->parity == UART_ATTR_PARITY_ODD) {
termios.c_cflag |= (PARODD | PARENB);
} else if (attribute->parity == UART_ATTR_PARITY_EVEN) {
termios.c_cflag |= PARENB;
termios.c_cflag &= ~PARODD;
} else if (attribute->parity == UART_ATTR_PARITY_NONE) {
termios.c_cflag &= ~(PARENB | PARODD);
} else { /* defaule value */
termios.c_cflag &= ~(PARENB | PARODD);
}
if (attribute->stopBits == UART_ATTR_STOPBIT_1) {
termios.c_cflag &= ~CSTOPB;
} else if (attribute->stopBits == UART_ATTR_STOPBIT_2) {
termios.c_cflag |= CSTOPB;
} else {
/* defaule value */
termios.c_cflag &= ~CSTOPB;
}
ret = UartAdapterIoctlInner(fp, TCSETS, (unsigned long)&termios);
return ret;
}
static struct UartHostMethod g_uartHostMethod = {
.Init = UartAdapterInit,
.Deinit = UartAdapterDeInit,
.Read = UartAdapterRead,
.Write = UartAdapterWrite,
.SetBaud = UartAdapterSetBaud,
.GetBaud = UartAdapterGetBaud,
.SetAttribute = UartAdapterSetAttribute,
.GetAttribute = UartAdapterGetAttribute,
};
static int32_t HdfUartBind(struct HdfDeviceObject *obj)
{
HDF_LOGI("%s: entry", __func__);
if (obj == NULL) {
return HDF_ERR_INVALID_OBJECT;
}
return (UartHostCreate(obj) == NULL) ? HDF_FAILURE : HDF_SUCCESS;
}
static int32_t HdfUartInit(struct HdfDeviceObject *obj)
{
int32_t ret;
struct DeviceResourceIface *iface = NULL;
struct UartHost *host = NULL;
const char *drName = NULL;
HDF_LOGI("%s: entry", __func__);
if (obj == NULL) {
HDF_LOGE("%s: device is null", __func__);
return HDF_ERR_INVALID_OBJECT;
}
host = UartHostFromDevice(obj);
if (host == NULL) {
HDF_LOGE("%s: host is null", __func__);
return HDF_FAILURE;
}
iface = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
if (iface == NULL || iface->GetUint32 == NULL) {
HDF_LOGE("%s: face is invalid", __func__);
return HDF_FAILURE;
}
if (iface->GetUint32(obj->property, "num", &host->num, 0) != HDF_SUCCESS) {
HDF_LOGE("%s: read num fail", __func__);
return HDF_FAILURE;
}
if (iface->GetString(obj->property, "driver_name", &drName, "ttyAMA") != HDF_SUCCESS) {
HDF_LOGE("%s: read driver_name fail", __func__);
return HDF_FAILURE;
}
g_driverName[UART_NAME_LEN - 1] = 0;
ret = memcpy_s(g_driverName, UART_NAME_LEN - 1, drName, strlen(drName));
if (ret != EOK) {
return HDF_FAILURE;
}
host->method = &g_uartHostMethod;
return HDF_SUCCESS;
}
static void HdfUartRelease(struct HdfDeviceObject *obj)
{
struct UartHost *host = NULL;
HDF_LOGI("%s: entry", __func__);
if (obj == NULL) {
HDF_LOGE("%s: obj is null", __func__);
return;
}
host = UartHostFromDevice(obj);
UartHostDestroy(host);
}
struct HdfDriverEntry g_hdfUartchdog = {
.moduleVersion = 1,
.moduleName = "HDF_PLATFORM_UART",
.Bind = HdfUartBind,
.Init = HdfUartInit,
.Release = HdfUartRelease,
};
HDF_INIT(g_hdfUartchdog);

View File

@ -0,0 +1,20 @@
#
# Copyright (c) 2020-2021 Huawei Device Co., Ltd.
#
# This software is licensed under the terms of the GNU General Public
# License version 2, as published by the Free Software Foundation, and
# may be copied, distributed, and modified under those terms.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
#
include drivers/hdf/khdf/platform/platform.mk
obj-y += $(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/watchdog_core.o \
$(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/watchdog_if.o \
watchdog_adapter.o

View File

@ -0,0 +1,291 @@
/*
* watchdog_adapter.c
*
* linux watchdog driver adapter.
*
* Copyright (c) 2020-2021 Huawei Device Co., Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <asm/uaccess.h>
#include <asm/ioctls.h>
#include <linux/watchdog.h>
#include <linux/fs.h>
#include "device_resource_if.h"
#include "hdf_base.h"
#include "hdf_log.h"
#include "osal_io.h"
#include "osal_mem.h"
#include "osal_time.h"
#include "securec.h"
#include "watchdog_if.h"
#include "watchdog_core.h"
#define HDF_LOG_TAG hdf_watchdog_adapter
#define UART_NAME_LEN 20
static int WdtAdapterIoctlInner(struct file *fp, unsigned cmd, unsigned long arg)
{
int ret = HDF_FAILURE;
mm_segment_t oldfs;
oldfs = get_fs();
set_fs(KERNEL_DS);
if (fp->f_op->unlocked_ioctl) {
ret = fp->f_op->unlocked_ioctl(fp, cmd, arg);
}
set_fs(oldfs);
return ret;
}
static int32_t WdtOpenFile(struct WatchdogCntlr *wdt)
{
char name[UART_NAME_LEN] = {0};
struct file *fp = NULL;
mm_segment_t oldfs;
if (wdt == NULL) {
return HDF_FAILURE;
}
if (sprintf_s(name, UART_NAME_LEN - 1, "/dev/watchdog%d", wdt->wdtId) < 0) {
return HDF_FAILURE;
}
oldfs = get_fs();
set_fs(KERNEL_DS);
fp = filp_open(name, O_RDWR, 0600); /* 0600 : for open mode */
if (IS_ERR(fp)) {
HDF_LOGE("filp_open %s fail", name);
set_fs(oldfs);
return HDF_FAILURE;
}
set_fs(oldfs);
wdt->priv = fp;
return HDF_SUCCESS;
}
static void WdtAdapterClose(struct WatchdogCntlr *wdt)
{
int32_t ret;
mm_segment_t oldfs;
struct file *fp = (struct file *)wdt->priv;
oldfs = get_fs();
set_fs(KERNEL_DS);
if (!IS_ERR(fp) && fp) {
ret = filp_close(fp, NULL);
}
set_fs(oldfs);
wdt->priv = NULL;
}
static int32_t WdtAdapterStart(struct WatchdogCntlr *wdt)
{
struct file *fp = NULL;
unsigned long arg = WDIOS_ENABLECARD;
if (wdt == NULL) {
return HDF_FAILURE;
}
if (wdt->priv == NULL) {
HDF_LOGE("cntlr is not opened");
return HDF_FAILURE;
}
fp = wdt->priv;
if (WdtAdapterIoctlInner(fp, WDIOC_SETOPTIONS, (unsigned long)&arg) != 0) {
HDF_LOGE("WDIOC_SETOPTIONS WDIOS_ENABLECARD fail");
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
static int32_t WdtAdapterStop(struct WatchdogCntlr *wdt)
{
struct file *fp = (struct file *)wdt->priv;
unsigned long arg = WDIOS_DISABLECARD;
if (fp == NULL) {
return HDF_FAILURE;
}
if (WdtAdapterIoctlInner(fp, WDIOC_SETOPTIONS, (unsigned long)&arg) != 0) {
HDF_LOGE("%s WDIOC_SETOPTIONS WDIOS_DISABLECARD fail", __func__);
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
static int32_t WdtAdapterFeed(struct WatchdogCntlr *wdt)
{
struct file *fp = NULL;
if (wdt->priv == NULL) {
return HDF_FAILURE;
}
fp = (struct file *)wdt->priv;
if (WdtAdapterIoctlInner(fp, WDIOC_KEEPALIVE, 0) != 0) {
HDF_LOGE("WDIOC_KEEPALIVE fail");
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
static struct watchdog_device *WdtCoreDataToWdd(void *wdCoreData)
{
/*
* defined in watchdog_dev.c
* struct watchdog_core_data {
* struct kref kref;
* struct cdev cdev;
* struct watchdog_device *wdd;
* ...
* }
*/
struct WdtCoreDataHead {
struct kref kref;
struct cdev cdev;
struct watchdog_device *wdd;
};
return ((struct WdtCoreDataHead *)wdCoreData)->wdd;
}
static int32_t WdtAdapterGetStatus(struct WatchdogCntlr *wdt, int32_t *status)
{
struct file *fp = (struct file *)wdt->priv;
struct watchdog_device *wdd = NULL;
if (fp == NULL || fp->private_data == NULL) {
return HDF_FAILURE;
}
wdd = WdtCoreDataToWdd(fp->private_data);
if (wdd == NULL) {
return HDF_FAILURE;
}
if (watchdog_active(wdd)) {
HDF_LOGE("WDT is ACTIVE");
*status = (int32_t)WATCHDOG_START;
} else {
HDF_LOGE("WDT is not ACTIVE");
*status = (int32_t)WATCHDOG_STOP;
}
return HDF_SUCCESS;
}
static int32_t WdtAdapterSetTimeout(struct WatchdogCntlr *wdt, uint32_t seconds)
{
struct file *fp = NULL;
unsigned long arg;
if (wdt->priv == NULL) {
return HDF_FAILURE;
}
fp = (struct file *)wdt->priv;
arg = seconds;
if (WdtAdapterIoctlInner(fp, WDIOC_SETTIMEOUT, (unsigned long)&arg) != 0) {
HDF_LOGE("WDIOC_SETTIMEOUT fail");
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
static int32_t WdtAdapterGetTimeout(struct WatchdogCntlr *wdt, uint32_t *seconds)
{
struct file *fp = NULL;
unsigned long arg;
if (wdt->priv == NULL) {
return HDF_FAILURE;
}
fp = (struct file *)wdt->priv;
if (WdtAdapterIoctlInner(fp, WDIOC_GETTIMEOUT, (unsigned long)&arg) != 0) {
HDF_LOGE("WDIOC_GETTIMEOUT fail");
return HDF_FAILURE;
}
*seconds = arg;
return HDF_SUCCESS;
}
static struct WatchdogMethod g_wdtMethod = {
.getStatus = WdtAdapterGetStatus,
.start = WdtAdapterStart,
.stop = WdtAdapterStop,
.setTimeout = WdtAdapterSetTimeout,
.getTimeout = WdtAdapterGetTimeout,
.feed = WdtAdapterFeed,
.getPriv = WdtOpenFile,
.releasePriv = WdtAdapterClose,
};
static int32_t HdfWdtBind(struct HdfDeviceObject *obj)
{
struct WatchdogCntlr *wdt = NULL;
struct DeviceResourceIface *drsOps = NULL;
int32_t ret;
HDF_LOGI("%s: entry", __func__);
if (obj == NULL || obj->property == NULL) {
return HDF_ERR_INVALID_OBJECT;
}
wdt = (struct WatchdogCntlr *)OsalMemCalloc(sizeof(*wdt));
if (wdt == NULL) {
HDF_LOGE("%s: malloc wdt fail!", __func__);
return HDF_ERR_MALLOC_FAIL;
}
drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
if (drsOps == NULL || drsOps->GetUint32 == NULL) {
HDF_LOGE("%s: invalid drs ops!", __func__);
return HDF_FAILURE;
}
ret = drsOps->GetUint16(obj->property, "id", &wdt->wdtId, 0);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: read wdtId fail, ret %d!", __func__, ret);
}
wdt->ops = &g_wdtMethod;
wdt->device = obj;
ret = WatchdogCntlrAdd(wdt);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: err add watchdog:%d", __func__, ret);
OsalMemFree(wdt);
return ret;
}
HDF_LOGI("%s: dev service %s init success!", __func__, HdfDeviceGetServiceName(obj));
return HDF_SUCCESS;
}
static int32_t HdfWdtInit(struct HdfDeviceObject *obj)
{
(void)obj;
return HDF_SUCCESS;
}
static void HdfWdtRelease(struct HdfDeviceObject *obj)
{
struct WatchdogCntlr *wdt = NULL;
HDF_LOGI("%s: enter", __func__);
if (obj == NULL) {
return;
}
wdt = WatchdogCntlrFromDevice(obj);
if (wdt == NULL) {
return;
}
WatchdogCntlrRemove(wdt);
OsalMemFree(wdt);
}
struct HdfDriverEntry g_hdfWdtchdog = {
.moduleVersion = 1,
.moduleName = "HDF_PLATFORM_WATCHDOG",
.Bind = HdfWdtBind,
.Init = HdfWdtInit,
.Release = HdfWdtRelease,
};
HDF_INIT(g_hdfWdtchdog);

17
test/Kconfig Normal file
View File

@ -0,0 +1,17 @@
# Copyright (c) 2021 Huawei Device Co., Ltd.
#
# This software is licensed under the terms of the GNU General Public
# License version 2, as published by the Free Software Foundation, and
# may be copied, distributed, and modified under those terms.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
config DRIVERS_HDF_TEST
bool "Enable HDF linux test"
default y
depends on DRIVERS_HDF
help
Answer Y to enable linux support HDF test.

77
test/Makefile Normal file
View File

@ -0,0 +1,77 @@
# Copyright (c) 2021 Huawei Device Co., Ltd.
#
# This software is licensed under the terms of the GNU General Public
# License version 2, as published by the Free Software Foundation, and
# may be copied, distributed, and modified under those terms.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
include drivers/hdf/khdf/test/test_khdf.mk
HDF_FRAMWORK_TEST_ROOT = ../../../../framework/test/unittest
obj-y += $(HDF_FRAMWORK_TEST_ROOT)/common/hdf_main_test.o \
$(HDF_FRAMWORK_TEST_ROOT)/osal/osal_test_entry.o \
$(HDF_FRAMWORK_TEST_ROOT)/osal/osal_all_test.o \
$(HDF_FRAMWORK_TEST_ROOT)/osal/osal_list_test.o \
$(HDF_FRAMWORK_TEST_ROOT)/osal/osal_file_test.o \
$(HDF_FRAMWORK_TEST_ROOT)/osal/osal_work_test.o \
$(HDF_FRAMWORK_TEST_ROOT)/osal/osal_get_case_test.o \
$(HDF_FRAMWORK_TEST_ROOT)/manager/sample_driver_test.o \
$(HDF_FRAMWORK_TEST_ROOT)/ability/config/hcs_parser/unittest/hcs_config_test.o \
$(HDF_FRAMWORK_TEST_ROOT)/config/hdf_config_test.o
obj-$(CONFIG_DRIVERS_HDF_PLATFORM_GPIO) += $(HDF_FRAMWORK_TEST_ROOT)/platform/common/gpio_test.o \
$(HDF_FRAMWORK_TEST_ROOT)/platform/hdf_gpio_entry_test.o
obj-$(CONFIG_DRIVERS_HDF_PLATFORM_I2C) += $(HDF_FRAMWORK_TEST_ROOT)/platform/common/i2c_test.o \
$(HDF_FRAMWORK_TEST_ROOT)/platform/common/i2c_driver_test.o \
$(HDF_FRAMWORK_TEST_ROOT)/platform/hdf_i2c_entry_test.o
obj-$(CONFIG_DRIVERS_HDF_PLATFORM_PWM) += $(HDF_FRAMWORK_TEST_ROOT)/platform/common/pwm_test.o \
$(HDF_FRAMWORK_TEST_ROOT)/platform/hdf_pwm_entry_test.o
obj-$(CONFIG_DRIVERS_HDF_PLATFORM_RTC) += $(HDF_FRAMWORK_TEST_ROOT)/platform/hdf_rtc_entry_test.o
obj-$(CONFIG_DRIVERS_HDF_PLATFORM_SPI) += $(HDF_FRAMWORK_TEST_ROOT)/platform/common/spi_test.o \
$(HDF_FRAMWORK_TEST_ROOT)/platform/hdf_spi_entry_test.o
obj-$(CONFIG_DRIVERS_HDF_PLATFORM_SDIO) += $(HDF_FRAMWORK_TEST_ROOT)/platform/common/sdio_test.o \
$(HDF_FRAMWORK_TEST_ROOT)/platform/hdf_sdio_entry_test.o
obj-$(CONFIG_DRIVERS_HDF_PLATFORM_EMMC) += $(HDF_FRAMWORK_TEST_ROOT)/platform/common/emmc_test.o \
$(HDF_FRAMWORK_TEST_ROOT)/platform/hdf_emmc_entry_test.o
obj-$(CONFIG_DRIVERS_HDF_PLATFORM_UART) += $(HDF_FRAMWORK_TEST_ROOT)/platform/common/uart_test.o \
$(HDF_FRAMWORK_TEST_ROOT)/platform/hdf_uart_entry_test.o
obj-$(CONFIG_DRIVERS_HDF_PLATFORM_WATCHDOG) += $(HDF_FRAMWORK_TEST_ROOT)/platform/common/watchdog_test.o \
$(HDF_FRAMWORK_TEST_ROOT)/platform/hdf_watchdog_entry_test.o
obj-$(CONFIG_DRIVERS_HDF_PLATFORM_MIPI_DSI) += $(HDF_FRAMWORK_TEST_ROOT)/platform/common/mipi_dsi_test.o \
$(HDF_FRAMWORK_TEST_ROOT)/platform/hdf_mipi_dsi_entry_test.o
obj-$(CONFIG_DRIVERS_HDF_WIFI) += $(HDF_FRAMWORK_TEST_ROOT)/wifi/hdf_wifi_test.o \
$(HDF_FRAMWORK_TEST_ROOT)/model/network/wifi/unittest/netdevice/net_device_test.o \
$(HDF_FRAMWORK_TEST_ROOT)/model/network/wifi/unittest/module/hdf_module_test.o \
$(HDF_FRAMWORK_TEST_ROOT)/model/network/wifi/unittest/net/hdf_netbuf_test.o \
$(HDF_FRAMWORK_TEST_ROOT)/model/network/wifi/unittest/qos/flow_control_test.o \
$(HDF_FRAMWORK_TEST_ROOT)/model/network/wifi/unittest/message/hdf_queue_test.o \
$(HDF_FRAMWORK_TEST_ROOT)/model/network/wifi/unittest/message/hdf_single_node_message_test.o
obj-$(CONFIG_DRIVERS_HDF_SENSOR) += $(HDF_FRAMWORK_TEST_ROOT)/sensor/hdf_sensor_test.o
ccflags-y += -Idrivers/hdf/framework/include \
-Idrivers/hdf/framework/include/osal \
-Idrivers/hdf/framework/include/utils \
-Idrivers/hdf/framework/include \
-Idrivers/hdf/framework/utils/include \
-Idrivers/hdf/framework/include/core \
-Idrivers/hdf/framework/ability/sbuf/include \
-Idrivers/hdf/framework/core/host/include \
-Idrivers/hdf/framework/core/manager/include \
-Idrivers/hdf/framework/core/shared/include \
-Idrivers/hdf/framework/core/common/include/host \
-Idrivers/hdf/framework/core/common/include/manager \
-Idrivers/hdf/framework/core/adapter/vnode/include \
-Idrivers/hdf/../../../../../../../../../../../../../third_party/bounds_checking_function/include \
-Idrivers/hdf/framework/ability/config/hcs_parser/include \
-Idrivers/hdf/framework/test/unittest/config \
-Idrivers/hdf/framework/test/unittest/ability/config/hcs_parser/unittest \
-Idrivers/hdf/framework/include/config \
-Idrivers/hdf/framework/ability/config/hcs_parser/include \
-Idrivers/hdf/framework/test/unittest/osal \
-Idrivers/hdf/khdf/osal/include

View File

@ -0,0 +1,21 @@
/*
* Copyright (c) 2020-2021 Huawei Technologies Co., Ltd.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef OSAL_TEST_TYPE_H
#define OSAL_TEST_TYPE_H
#include <asm/uaccess.h>
#include <linux/fs.h>
#endif /* OSAL_TEST_TYPE_H */

70
test/test_khdf.mk Normal file
View File

@ -0,0 +1,70 @@
#
# Copyright (c) 2020-2021 Huawei Technologies Co., Ltd.
#
# This software is licensed under the terms of the GNU General Public
# License version 2, as published by the Free Software Foundation, and
# may be copied, distributed, and modified under those terms.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
HDF_FRAMEWORK_TEST_ROOT = drivers/hdf/framework/test/unittest
HDF_FRAMEWORK_ROOT = drivers/hdf/framework
#$(error HDF_FRAMEWORK_ROOT is $(HDF_FRAMEWORK_ROOT))
ccflags-$(CONFIG_DRIVERS_HDF_TEST) += -Idrivers/hdf/framework/include/platform \
-I$(HDF_FRAMEWORK_ROOT)/support/platform/include \
-I$(HDF_FRAMEWORK_ROOT)/support/platform/include/platform \
-Iinclude/hdf \
-Iinclude/hdf/osal \
-Iinclude/hdf/utils \
-I$(HDF_FRAMEWORK_TEST_ROOT)/common \
-I$(HDF_FRAMEWORK_TEST_ROOT)/manager \
-I$(HDF_FRAMEWORK_TEST_ROOT)/osal \
-Idrivers/hdf/khdf/test/adapter/osal/include \
-I$(HDF_FRAMEWORK_TEST_ROOT)/osal \
-I$(HDF_FRAMEWORK_TEST_ROOT)/wifi \
-I$(HDF_FRAMEWORK_TEST_ROOT)/model/network/wifi/unittest/netdevice \
-I$(HDF_FRAMEWORK_TEST_ROOT)/model/network/wifi/unittest/module \
-I$(HDF_FRAMEWORK_TEST_ROOT)/model/network/wifi/unittest/net \
-I$(HDF_FRAMEWORK_TEST_ROOT)/model/network/wifi/unittest/qos \
-I$(HDF_FRAMEWORK_TEST_ROOT)/model/network/wifi/unittest/message \
-Idrivers/hdf/khdf/network/include \
-Idrivers/hdf/khdf/osal/include \
-Idrivers/hdf/khdf/test/osal/include \
-I$(HDF_FRAMEWORK_ROOT)/include \
-I$(HDF_FRAMEWORK_ROOT)/include/utils \
-I$(HDF_FRAMEWORK_ROOT)/include/config \
-Idrivers/hdf/khdf/config/include \
-I$(HDF_FRAMEWORK_ROOT)/core/manager/include \
-I$(HDF_FRAMEWORK_ROOT)/core/host/include \
-I$(HDF_FRAMEWORK_ROOT)/core/shared/include \
-I$(HDF_FRAMEWORK_ROOT)/include/core \
-I$(HDF_FRAMEWORK_ROOT)/core/common/include/host \
-I$(HDF_FRAMEWORK_ROOT)/ability/sbuf/include \
-I$(HDF_FRAMEWORK_ROOT)/ability/config/hcs_parser/include \
-I$(HDF_FRAMEWORK_ROOT)/utils/include \
-I$(HDF_FRAMEWORK_ROOT)/include/wifi \
-I$(HDF_FRAMEWORK_ROOT)/include/net \
-I$(HDF_FRAMEWORK_ROOT)/model/network/wifi/include \
-I$(HDF_FRAMEWORK_ROOT)/model/network/common/netdevice \
-I$(HDF_FRAMEWORK_ROOT)/model/network/wifi/core/module \
-I$(HDF_FRAMEWORK_ROOT)/model/network/wifi/platfrom/src/qos \
-I$(HDF_FRAMEWORK_ROOT)/model/network/wifi/core/compoments/softap \
-I$(HDF_FRAMEWORK_ROOT)/model/network/wifi/core/compoments/sta \
-I$(HDF_FRAMEWORK_ROOT)/model/network/wifi/platform/include \
-Iinclude/../drivers/hdf/../../../../../../../../../../../../../third_party/bounds_checking_function/include \
-I$(HDF_FRAMEWORK_TEST_ROOT)/platform \
-I$(HDF_FRAMEWORK_TEST_ROOT)/wifi \
-I$(HDF_FRAMEWORK_TEST_ROOT)/platform/common \
-I$(HDF_FRAMEWORK_TEST_ROOT)/model/network/wifi/unittest/netdevice \
-I$(HDF_FRAMEWORK_TEST_ROOT)/model/network/wifi/unittest/module \
-I$(HDF_FRAMEWORK_TEST_ROOT)/model/network/wifi/unittest/net \
-I$(HDF_FRAMEWORK_TEST_ROOT)/model/network/wifi/unittest/qos \
-I$(HDF_FRAMEWORK_TEST_ROOT)/model/network/wifi/unittest/message \
-I$(HDF_FRAMEWORK_TEST_ROOT)/sensor \
-I$(HDF_FRAMEWORK_ROOT)/model/sensor/driver/include \
-I$(HDF_FRAMEWORK_ROOT)/model/sensor/driver/common/include