feat: normalize drivers framework component and repos

Signed-off-by: yuanbo <yuanbo@huawei.com>
This commit is contained in:
yuanbo 2022-06-16 09:28:43 +08:00
parent b68d9f5491
commit e6122dcd42
1977 changed files with 73660 additions and 137 deletions

219
LICENSE
View File

@ -1,26 +1,15 @@
HDF - Hardware Driver Foundation
Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
HDF is dual licensed: you can use it either under the terms of
The framework directory is dual licensed: you can use it either under the terms of
the GPL V2, or the BSD3 license, at your option.
a) GNU General Public License version 2, (https://opensource.org/licenses/GPL-2.0)
This library 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.
The adapter/khdf/liteos and khdf/liteos_m subdirectories are licensed under 3-Clause BSD License.
The adapter/khdf/linux subdirectory is licensed under the GPL V2 License.
The adapter/platform subdirectory is is dual licensed: you can use it either under the terms of
the GPL V2, or the 3-Clause BSD License, at your option.
The adapter/uhdf and adapter/uhdf2 and others subdirectories are licensed under Apache License, Version 2.0.
This library 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 library; if not, write to the Free
Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
MA 02110-1301 USA
Alternatively,
b) The BSD3 License, (https://opensource.org/licenses/BSD-3-Clause)
a) The 3-Clause BSD License, (https://opensource.org/licenses/BSD-3-Clause)
Redistribution and use in source and binary forms, with or
without modification, are permitted provided that the following
conditions are met:
@ -49,3 +38,197 @@ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
b) The Apache License, Version 2.0, (https://www.apache.org/licenses/LICENSE-2.0)
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
c) GNU General Public License version 2, (https://opensource.org/licenses/GPL-2.0)
This library 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 library 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 library; if not, write to the Free
Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
MA 02110-1301 USA

35
OAT.xml
View File

@ -1,9 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (c) 2021-2022 Huawei Device Co., Ltd.
The framework directory is dual licensed: you can use it either under the terms of
the GPL V2, or the BSD3 license, at your option.
The adapter/khdf/liteos and khdf/liteos_m subdirectories are licensed under 3-Clause BSD License.
The adapter/khdf/linux subdirectory is licensed under the GPL V2 License.
The adapter/platform subdirectory is is dual licensed: you can use it either under the terms of
the GPL V2, or the 3-Clause BSD License, at your option.
The adapter/uhdf and adapter/uhdf2 and others subdirectories are licensed under Apache License, Version 2.0.
HDF is dual licensed: you can use it either under the terms of
the GPL, or the BSD license, at your option.
See the LICENSE file in the root of this repository for complete details.
See the LICENSE file in the root of this repository for complete details.
-->
<!-- OAT(OSS Audit Tool) configuration guide:
basedir: Root dir, the basedir + project path is the real source file location.
@ -52,30 +57,47 @@ Note:If the text contains special characters, please escape them according to th
<policyitem type="license" name="BSD" path=".*" desc="huawei codes"/>
<policyitem type="copyright" name="Chipsea Technologies (Shenzhen) Corp., Ltd." path=".*" rule="may" group="defaultGroup" filefilter="copyrightPolicyFilter" desc="kaihong codes"/>
<policyitem type="copyright" name="Shenzhen Kaihong Digital" path=".*" rule="may" group="defaultGroup" filefilter="copyrightPolicyFilter" desc="kaihong codes"/>
<!--policyitem type="compatibility" name="GPL" path=".*" desc="linux kernel adapter codes"/-->
<!--policyitem type="compatibility" name="GPL-2.0+" path=".*" desc="linux kernel adapter codes"/-->
<policyitem type="copyright" name="Bestechnic (Shanghai) Co., Ltd." path=".*" rule="may" group="defaultGroup" filefilter="copyrightPolicyFilter" desc="Developed by Bestechnic"/>
<policyitem type="copyright" name="GOODIX." path=".*" rule="may" group="defaultGroup" filefilter="copyrightPolicyFilter" desc="Developed by Goodix"/>
<policyitem type="copyright" name="ASR Microelectronics (Shanghai) Co., Ltd." path=".*" rule="may" group="defaultGroup" filefilter="copyrightPolicyFilter" desc="Developed by asr"/>
<policyitem type="copyright" name="Talkweb Co., Ltd." path=".*" rule="may" group="defaultGroup" filefilter="copyrightPolicyFilter" desc="Developed by Talkweb"/>
<policyitem type="copyright" name="Jiangsu Hoperun Software Co., Ltd." path=".*" rule="may" group="defaultGroup" filefilter="copyrightPolicyFilter" desc="Developed By Hoperun"/>
<policyitem type="copyright" name="Samsung Electronics Co.," path=".*" rule="may" group="defaultGroup" filefilter="copyrightPolicyFilter" desc="kernel codes"/>
<policyitem type="copyright" name="Samsung Electronics" path=".*" rule="may" group="defaultGroup" filefilter="copyrightPolicyFilter" desc="kernel codes"/>
<policyitem type="copyright" name="David Brownell" path=".*" rule="may" group="defaultGroup" filefilter="copyrightPolicyFilter" desc="kernel codes"/>
<policyitem type="copyright" name="Agilent Technologies" path=".*" rule="may" group="defaultGroup" filefilter="copyrightPolicyFilter" desc="kernel codes"/>
</policy>
</policylist>
<filefilterlist>
<filefilter name="defaultFilter" desc="Files not to check">
<filteritem type="filename" name="*.lds|*.pod"/>
<filteritem type="filename" name="*.a|*.d|*.o|*.cmd|*.hcb|*.swp|hc-gen"/>
<filteritem type="filename" name="*.a|*.d|*.o|*.so|*.cmd|*.hcb|*.swp"/>
<filteritem type="filename" name="*.clang-format"/>
<filteritem type="filepath" name="dir name underproject/.*" desc="Describe the reason for filtering scan results"/>
<filteritem type="filename" name="*.lds|*.pod" desc="Building scripts"/>
<filteritem type="filename" name="*.a|*.d|*.o|*.cmd|*.hcb|*.swp" desc="Intermediate products"/>
</filefilter>
<filefilter name="defaultPolicyFilter" desc="Filters for compatibilitylicense header policies">
<filteritem type="filename" name="README.OpenSource"/>
<filteritem type="filename" name="README"/>
<filteritem type="filename" name="BUILD.gn"/>
<filteritem type="filename" name="*.gni"/>
<filteritem type="filepath" name="dir name underproject/.*" desc="Describe the reason for filtering scan results"/>
</filefilter>
<filefilter name="copyrightPolicyFilter" desc="Filters for copyright header policies" >
<filteritem type="filename" name="README.OpenSource"/>
<filteritem type="filename" name="README"/>
<filteritem type="filename" name="BUILD.gn"/>
<filteritem type="filename" name="*.gni"/>
<filteritem type="filepath" name="dir name underproject/.*" desc="Describe the reason for filtering scan results"/>
</filefilter>
<filefilter name="licenseFileNamePolicyFilter" desc="Filters for LICENSE file policies" >
<filteritem type="filepath" name="dir name underproject/.*" desc="Describe the reason for filtering scan results"/>
<filteritem type="filepath" name="core/adapter/.*" desc="it's not a repo"/>
<filteritem type="filepath" name="framework/core/adapter/.*" desc="it's not a repo"/>
<filteritem type="filename" name="BUILD.gn"/>
<filteritem type="filename" name="*.gni"/>
</filefilter>
<filefilter name="readmeFileNamePolicyFilter" desc="Filters for README file policies" >
<filteritem type="filepath" name="dir name underproject/.*" desc="Describe the reason for filtering scan results"/>
@ -85,6 +107,7 @@ Note:If the text contains special characters, please escape them according to th
</filefilter>
<filefilter name="binaryFileTypePolicyFilter" desc="Filters for binary file policies" >
<filteritem type="filepath" name="figures/.*.png" desc="driver framework architecture diagram"/>
<filteritem type="filepath" name="adapter/uhdf2/test/resource/audio/audiofile/audiorendertest.wav" desc="Self-developed voice files are used for testing"/>
</filefilter>
</filefilterlist>
</oatconfig>

View File

@ -21,7 +21,7 @@ This repository stores the core source code information of the OpenHarmony drive
## Directory Structure<a name="section161941989596"></a>
```
/drivers/framework
/drivers/hdf_core/framework
├── core # Core code for implementing the HDF
│ ├── adapter # Kernel adaptation layer
│ ├── common # Common basic code

View File

@ -21,7 +21,7 @@
## 目录<a name="section161941989596"></a>
```
/drivers/framework
/drivers/hdf_core/framework
├── core #实现驱动框架的核心代码
│ ├── adapter #实现对内核操作接口适配,提供抽象化的接口供开发者使用
│ ├── common #驱动框架公共基础代码

1
adapter/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
hdf_config_gen*

57
adapter/BUILD.gn Normal file
View File

@ -0,0 +1,57 @@
# Copyright (c) 2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
if (defined(ohos_lite)) {
group("uhdf_entry") {
deps = [
"//drivers/hdf_core/adapter/uhdf/manager:hdf_core",
"//drivers/hdf_core/adapter/uhdf/platform:hdf_platform",
"//drivers/hdf_core/adapter/uhdf/posix:hdf_posix_osal",
"//drivers/hdf_core/adapter/uhdf/posix/old:hdf_posix",
]
}
group("uhdf_test_entry") {
deps = [
"//drivers/hdf_core/adapter/build/test_common:libhdf_test_common",
"//drivers/hdf_core/adapter/uhdf/test:hdf_test_uhdf",
]
}
} else {
group("uhdf_entry") {
deps = [
"//drivers/hdf_core/adapter/uhdf2/hcs:hdf_default.hcb",
"//drivers/hdf_core/adapter/uhdf2/hcs:hdf_devhost.cfg",
"//drivers/hdf_core/adapter/uhdf2/hdi:libhdi",
"//drivers/hdf_core/adapter/uhdf2/host:hdf_devhost",
"//drivers/hdf_core/adapter/uhdf2/host:libhdf_host",
"//drivers/hdf_core/adapter/uhdf2/host/test/unittest/sample_driver:libsample_driver",
"//drivers/hdf_core/adapter/uhdf2/ipc:libhdf_ipc_adapter",
"//drivers/hdf_core/adapter/uhdf2/manager:hdf_devmgr",
"//drivers/hdf_core/adapter/uhdf2/manager:hdf_devmgr.cfg",
"//drivers/hdf_core/adapter/uhdf2/platform:libhdf_platform",
"//drivers/hdf_core/adapter/uhdf2/utils:libhdf_utils",
"//drivers/hdf_core/framework/tools/hdf_dbg:hdf_dbg",
"//drivers/peripheral/base:hdf_peripheral.cfg",
]
}
group("uhdf_test_entry") {
testonly = true
deps = [
"//drivers/hdf_core/adapter/build/test_common:libhdf_test_common",
"//drivers/hdf_core/adapter/uhdf2/hdi/test:unittest",
"//drivers/hdf_core/adapter/uhdf2/host/test:unittest",
"//drivers/hdf_core/adapter/uhdf2/osal/test:unittest",
"//drivers/hdf_core/adapter/uhdf2/test:hdf_test_uhdf",
]
}
}

228
adapter/LICENSE Normal file
View File

@ -0,0 +1,228 @@
The khdf/liteos and khdf/liteos_m subdirectories are licensed under 3-Clause BSD License.
The uhdf and uhdf2 subdirectories are licensed under Apache License, Version 2.0.
The platform subdirectory is is dual licensed: you can use it either under the terms of
the GPL V2, or the 3-Clause BSD Licens, at your option.
a) The 3-Clause BSD License, (https://opensource.org/licenses/BSD-3-Clause)
Redistribution and use in source and binary forms, with or
without modification, are permitted provided that the following
conditions are met:
1. Redistributions of source code must retain the above
copyright notice, this list of conditions and the following
disclaimer.
2. Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials
provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
b) The Apache License, Version 2.0, (https://www.apache.org/licenses/LICENSE-2.0)
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
c) GNU General Public License version 2, (https://opensource.org/licenses/GPL-2.0)
This library 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 library 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 library; if not, write to the Free
Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
MA 02110-1301 USA

104
adapter/OAT.xml Normal file
View File

@ -0,0 +1,104 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (c) 2021-2022 Huawei Device Co., Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- OAT(OSS Audit Tool) configuration guide:
basedir: Root dir, the basedir + project path is the real source file location.
licensefile:
1.If the project don't have "LICENSE" in root dir, please define all the license files in this project in , OAT will check license files according to this rule.
tasklist(only for batch mode):
1. task: Define oat check thread, each task will start a new thread.
2. task name: Only an name, no practical effect.
3. task policy: Default policy for projects under this task, this field is required and the specified policy must defined in policylist.
4. task filter: Default filefilter for projects under this task, this field is required and the specified filefilter must defined in filefilterlist.
5. task project: Projects to be checked, the path field define the source root dir of the project.
policyList:
1. policy: All policyitems will be merged to default OAT.xml rules, the name of policy doesn't affect OAT check process.
2. policyitem: The fields type, name, path, desc is required, and the fields rule, group, filefilter is optional,the default value is:
<policyitem type="" name="" path="" desc="" rule="may" group="defaultGroup" filefilter="defaultPolicyFilter"/>
3. policyitem type:
"compatibility" is used to check license compatibility in the specified path;
"license" is used to check source license header in the specified path;
"copyright" is used to check source copyright header in the specified path;
"import" is used to check source dependency in the specified path, such as import ... ,include ...
"filetype" is used to check file type in the specified path, supported file types: archive, binary
"filename" is used to check whether the specified file exists in the specified path(support projectroot in default OAT.xml), supported file names: LICENSE, README, README.OpenSource
4. policyitem name: This field is used for define the license, copyright, "*" means match all, the "!" prefix means could not match this value. For example, "!GPL" means can not use GPL license.
5. policyitem path: This field is used for define the source file scope to apply this policyitem, the "!" prefix means exclude the files. For example, "!.*/lib/.*" means files in lib dir will be exclude while process this policyitem.
6. policyitem rule and group: These two fields are used together to merge policy results. "may" policyitems in the same group means any one in this group passed, the result will be passed.
7. policyitem filefilter: Used to bind filefilter which define filter rules.
8. filefilter: Filter rules, the type filename is used to filter file name, the type filepath is used to filter file path.
Note:If the text contains special characters, please escape them according to the following rules:
" == &gt;
& == &gt;
' == &gt;
< == &gt;
> == &gt;
-->
<configuration>
<oatconfig>
<licensefile></licensefile>
<policylist>
<policy name="projectPolicy" desc="">
<policyitem type="license" name="BSD" path=".*" desc="codes"/>
<policyitem type="license" name="GPL" path=".*" desc="linux kernel adapter codes"/>
<policyitem type="copyright" name="Bestechnic (Shanghai) Co., Ltd." path=".*" rule="may" group="defaultGroup" filefilter="copyrightPolicyFilter" desc="Developed by Bestechnic"/>
<policyitem type="copyright" name="GOODIX." path=".*" rule="may" group="defaultGroup" filefilter="copyrightPolicyFilter" desc="Developed by Goodix"/>
<policyitem type="copyright" name="ASR Microelectronics (Shanghai) Co., Ltd." path=".*" rule="may" group="defaultGroup" filefilter="copyrightPolicyFilter" desc="Developed by asr"/>
<policyitem type="copyright" name="Talkweb Co., Ltd." path=".*" rule="may" group="defaultGroup" filefilter="copyrightPolicyFilter" desc="Developed by Talkweb"/>
<policyitem type="copyright" name="Jiangsu Hoperun Software Co., Ltd." path=".*" rule="may" group="defaultGroup" filefilter="copyrightPolicyFilter" desc="Developed By Hoperun"/>
</policy>
</policylist>
<filefilterlist>
<filefilter name="defaultFilter" desc="Files not to check">
<filteritem type="filename" name="*.lds|*.pod"/>
<filteritem type="filename" name="*.a|*.d|*.o|*.so|*.cmd|*.hcb|*.swp"/>
<filteritem type="filename" name="*.clang-format"/>
<filteritem type="filepath" name="dir name underproject/.*" desc="Describe the reason for filtering scan results"/>
</filefilter>
<filefilter name="defaultPolicyFilter" desc="Filters for compatibilitylicense header policies">
<filteritem type="filename" name="README.OpenSource"/>
<filteritem type="filename" name="README"/>
<filteritem type="filename" name="BUILD.gn"/>
<filteritem type="filename" name="*.gni"/>
<filteritem type="filepath" name="dir name underproject/.*" desc="Describe the reason for filtering scan results"/>
</filefilter>
<filefilter name="copyrightPolicyFilter" desc="Filters for copyright header policies" >
<filteritem type="filename" name="README.OpenSource"/>
<filteritem type="filename" name="README"/>
<filteritem type="filename" name="BUILD.gn"/>
<filteritem type="filename" name="*.gni"/>
<filteritem type="filepath" name="dir name underproject/.*" desc="Describe the reason for filtering scan results"/>
</filefilter>
<filefilter name="licenseFileNamePolicyFilter" desc="Filters for LICENSE file policies" >
<filteritem type="filepath" name="dir name underproject/.*" desc="Describe the reason for filtering scan results"/>
<filteritem type="filename" name="BUILD.gn"/>
<filteritem type="filename" name="*.gni"/>
</filefilter>
<filefilter name="readmeFileNamePolicyFilter" desc="Filters for README file policies" >
<filteritem type="filepath" name="dir name underproject/.*" desc="Describe the reason for filtering scan results"/>
</filefilter>
<filefilter name="readmeOpenSourcefileNamePolicyFilter" desc="Filters for README.OpenSource file policies" >
<filteritem type="filepath" name="dir name underproject/.*" desc="Describe the reason for filtering scan results"/>
</filefilter>
<filefilter name="binaryFileTypePolicyFilter" desc="Filters for binary file policies" >
<filteritem type="filepath" name="uhdf2/test/resource/audio/audiofile/audiorendertest.wav" desc="Self-developed voice files are used for testing"/>
</filefilter>
</filefilterlist>
</oatconfig>
</configuration>

30
adapter/README.md Normal file
View File

@ -0,0 +1,30 @@
# HDF Adapter<a name="EN-US_TOPIC_0000001138458641"></a>
- [Introduction](#section11660541593)
- [Directory Structure](#section161941989596)
- [Repositories Involved](#section1371113476307)
## Introduction<a name="section11660541593"></a>
This repository stores the code and compilation scripts for the kerner or user-mode Hardware Driver Foundation \(HDF\) of the OpenHarmony driver subsystem and provides basic capabilities for the HDF.
## Directory Structure<a name="section161941989596"></a>
```
/drivers/hdf_core/adapter
├── khdf/liteos # HDF dependent adapter for LiteOS-A kernel
├── khdf/liteos_m # HDF dependent adapter for LiteOS-M kernel
├── uhdf # HDF user mode interface dependent adapter
└── uhdf2 # HDF user mode dependent adapter
```
## Repositories Involved<a name="section1371113476307"></a>
[Driver subsystem](https://gitee.com/openharmony/docs/blob/master/en/readme/driver-subsystem.md)
[drivers\_framework](https://gitee.com/openharmony/drivers_framework/blob/master/README.md)
[drivers\_adapter](https://gitee.com/openharmony/drivers_adapter/blob/master/README.md)
[drivers\_adapter\_khdf\_linux](https://gitee.com/openharmony/drivers_adapter_khdf_linux/blob/master/README.md)

30
adapter/README_zh.md Normal file
View File

@ -0,0 +1,30 @@
# HDF适配<a name="ZH-CN_TOPIC_0000001138458641"></a>
- [简介](#section11660541593)
- [目录](#section161941989596)
- [相关仓](#section1371113476307)
## 简介<a name="section11660541593"></a>
该目录主要存放OpenHarmony驱动子系统内核或用户态驱动框架的代码和编译脚本提供驱动框架的能力。
## 目录<a name="section161941989596"></a>
```
/drivers/hdf_core/adapter
├── khdf/liteos #提供驱动框架对LiteOS-A内核依赖适配
├── khdf/liteos_m #提供驱动框架对LiteOS-M内核依赖适配
├── uhdf #提供用户态驱动接口对系统依赖适配
└── uhdf2 #提供用户态驱动框架对系统依赖适配
```
## 相关仓<a name="section1371113476307"></a>
[驱动子系统](https://gitee.com/openharmony/docs/blob/master/zh-cn/readme/%E9%A9%B1%E5%8A%A8%E5%AD%90%E7%B3%BB%E7%BB%9F.md)
[drivers\_framework](https://gitee.com/openharmony/drivers_framework/blob/master/README_zh.md)
[drivers\_adapter](https://gitee.com/openharmony/drivers_adapter/blob/master/README_zh.md)
[drivers\_adapter\_khdf\_linux](https://gitee.com/openharmony/drivers_adapter_khdf_linux/blob/master/README_zh.md)

View File

@ -0,0 +1,91 @@
# Copyright (c) 2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/ohos.gni")
import("//drivers/hdf_core/adapter/uhdf2/uhdf.gni")
config("hdf_test_common_pub_config") {
visibility = [ ":*" ]
include_dirs = [ "//drivers/hdf_core/framework/test/unittest/include" ]
}
if (defined(ohos_lite)) {
ohos_shared_library("libhdf_test_common") {
output_extension = "z.so"
sources = [
"//drivers/hdf_core/framework/test/unittest/common/hdf_common_test.c",
]
include_dirs = [
"//third_party/bounds_checking_function/include",
"//drivers/hdf_core/framework/include/platform",
"//drivers/hdf_core/framework/include/core",
"//drivers/hdf_core/framework/include/osal",
"//drivers/hdf_core/framework/include/utils",
"//drivers/hdf_core/adapter/uhdf/posix/include",
"//drivers/hdf_core/framework/test/unittest/include",
]
ldflags = [
"-lstdc++",
"-lm",
"-pthread",
]
deps = [
"//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared",
"//drivers/hdf_core/adapter/uhdf/manager:hdf_core",
"//drivers/hdf_core/adapter/uhdf/posix:hdf_posix_osal",
]
public_deps = [ "//third_party/bounds_checking_function:libsec_shared" ]
cflags = [
"-Wall",
"-Wextra",
"-Werror",
"-fsigned-char",
"-fno-common",
"-fno-strict-aliasing",
]
}
} else {
ohos_shared_library("libhdf_test_common") {
public_configs = [ ":hdf_test_common_pub_config" ]
sources = [
"//drivers/hdf_core/framework/test/unittest/common/hdf_common_test.c",
]
include_dirs = [ "//drivers/hdf_core/framework/test/unittest/include" ]
deps = [ "//drivers/hdf_core/adapter/uhdf2/utils:libhdf_utils" ]
defines = [ "__OHOS__USER__" ]
cflags = [
"-Wall",
"-Wextra",
"-Werror",
"-fsigned-char",
"-fno-common",
"-fno-strict-aliasing",
]
install_images = [ chipset_base_dir ]
subsystem_name = "hdf"
part_name = "hdf_core"
if (is_standard_system) {
external_deps = [
"hiviewdfx_hilog_native:libhilog",
"utils_base:utils",
]
} else {
external_deps = [ "hilog:libhilog" ]
}
}
}

1
adapter/khdf/linux/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.hcb

View File

@ -0,0 +1,32 @@
menuconfig DRIVERS_HDF
bool "HDF driver framework support"
default n
help
Answer Y to enable Linux support HDF.
if DRIVERS_HDF
config HDF_SUPPORT_LEVEL
int "Set HDF support level"
default 2
range 0 5
depends on DRIVERS_HDF
help
Answer 1 on small OHOS, 2 on standard OHOS
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/network/bluetooth/Kconfig"
source "drivers/hdf/khdf/model/sensor/Kconfig"
source "drivers/hdf/khdf/model/storage/Kconfig"
source "drivers/hdf/khdf/model/usb/host/Kconfig"
source "drivers/hdf/khdf/model/usb/device/Kconfig"
source "drivers/hdf/khdf/model/audio/Kconfig"
source "drivers/hdf/khdf/model/misc/vibrator/Kconfig"
source "drivers/hdf/khdf/model/misc/dsoftbus/Kconfig"
source "drivers/hdf/khdf/model/misc/light/Kconfig"
endif

359
adapter/khdf/linux/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.

View File

@ -0,0 +1,58 @@
#
# 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.
#
#
CURRENT_DIR := $(abspath $(dir $(realpath $(lastword $(MAKEFILE_LIST)))))
obj-$(CONFIG_DRIVERS_HDF) += osal/
obj-$(CONFIG_DRIVERS_HDF) += network/
obj-$(CONFIG_DRIVERS_HDF) += utils/
$(warning PRODUCT_PATH=$(PRODUCT_PATH))
ifeq ($(PRODUCT_PATH),)
$(error PRODUCT_PATH is not set)
endif
HCS_DIR := ../../../../../$(PRODUCT_PATH)/hdf_config/khdf
ifeq ($(wildcard $(CURRENT_DIR)/$(HCS_DIR)),)
HCS_DIR := ../../../../../$(PRODUCT_PATH)/hdf_config
endif
ifeq ($(CONFIG_DRIVERS_HDF), y)
ifeq ($(wildcard $(CURRENT_DIR)/$(HCS_DIR)),)
HCS_ABS_DIR := $(abspath $(CURRENT_DIR)/$(HCS_DIR))
$(error miss hcs config in $(HCS_ABS_DIR) for small system\
or $(HCS_ABS_DIR)/khdf for standrad system)
endif
ifeq ($(CONFIG_DRIVERS_HDF_TEST), y)
obj-$(CONFIG_DRIVERS_HDF_TEST) += test/
obj-$(CONFIG_DRIVERS_HDF_TEST) += $(HCS_DIR)/hdf_test/
else
obj-$(CONFIG_DRIVERS_HDF) += $(HCS_DIR)/
endif
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_USB_PNP_NOTIFY) += model/usb/host/
obj-$(CONFIG_DRIVERS_HDF_USB_F_GENERIC) += model/usb/device/
obj-$(CONFIG_DRIVERS_HDF_SENSOR) += model/sensor/
obj-$(CONFIG_DRIVERS_HDF_STORAGE) += model/storage/
obj-$(CONFIG_DRIVERS_HDF_BT) += model/network/bluetooth/
obj-$(CONFIG_DRIVERS_HDF_LIGHT) += model/misc/light/
obj-$(CONFIG_DRIVERS_HDF_VIBRATOR) += model/misc/vibrator/
obj-$(CONFIG_DRIVERS_HDF_AUDIO) += model/audio/
obj-$(CONFIG_DRIVERS_HDF_DSOFTBUS) += model/misc/dsoftbus/

View File

@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright (c) 2021-2022 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.
-->
<!-- OAT(OSS Audit Tool) configuration guide:
basedir: Root dir, the basedir + project path is the real source file location.
licensefile:
1.If the project don't have "LICENSE" in root dir, please define all the license files in this project in , OAT will check license files according to this rule.
tasklist(only for batch mode):
1. task: Define oat check thread, each task will start a new thread.
2. task name: Only an name, no practical effect.
3. task policy: Default policy for projects under this task, this field is required and the specified policy must defined in policylist.
4. task filter: Default filefilter for projects under this task, this field is required and the specified filefilter must defined in filefilterlist.
5. task project: Projects to be checked, the path field define the source root dir of the project.
policyList:
1. policy: All policyitems will be merged to default OAT.xml rules, the name of policy doesn't affect OAT check process.
2. policyitem: The fields type, name, path, desc is required, and the fields rule, group, filefilter is optional,the default value is:
<policyitem type="" name="" path="" desc="" rule="may" group="defaultGroup" filefilter="defaultPolicyFilter"/>
3. policyitem type:
"compatibility" is used to check license compatibility in the specified path;
"license" is used to check source license header in the specified path;
"copyright" is used to check source copyright header in the specified path;
"import" is used to check source dependency in the specified path, such as import ... ,include ...
"filetype" is used to check file type in the specified path, supported file types: archive, binary
"filename" is used to check whether the specified file exists in the specified path(support projectroot in default OAT.xml), supported file names: LICENSE, README, README.OpenSource
4. policyitem name: This field is used for define the license, copyright, "*" means match all, the "!" prefix means could not match this value. For example, "!GPL" means can not use GPL license.
5. policyitem path: This field is used for define the source file scope to apply this policyitem, the "!" prefix means exclude the files. For example, "!.*/lib/.*" means files in lib dir will be exclude while process this policyitem.
6. policyitem rule and group: These two fields are used together to merge policy results. "may" policyitems in the same group means any one in this group passed, the result will be passed.
7. policyitem filefilter: Used to bind filefilter which define filter rules.
8. filefilter: Filter rules, the type filename is used to filter file name, the type filepath is used to filter file path.
Note:If the text contains special characters, please escape them according to the following rules:
" == &gt;
& == &gt;
' == &gt;
< == &gt;
> == &gt;
-->
<configuration>
<oatconfig>
<licensefile></licensefile>
<policylist>
<policy name="projectPolicy" desc="">
<policyitem type="license" name="GPL" path=".*" desc="linux kernel adapter codes"/>
<policyitem type="copyright" name="Samsung Electronics Co.," path=".*" rule="may" group="defaultGroup" filefilter="copyrightPolicyFilter" desc="kernel codes"/>
<policyitem type="copyright" name="Samsung Electronics" path=".*" rule="may" group="defaultGroup" filefilter="copyrightPolicyFilter" desc="kernel codes"/>
<policyitem type="copyright" name="David Brownell" path=".*" rule="may" group="defaultGroup" filefilter="copyrightPolicyFilter" desc="kernel codes"/>
<policyitem type="copyright" name="Agilent Technologies" path=".*" rule="may" group="defaultGroup" filefilter="copyrightPolicyFilter" desc="kernel codes"/>
</policy>
</policylist>
<filefilterlist>
<filefilter name="defaultFilter" desc="Files not to check">
<filteritem type="filename" name="*.lds|*.pod" desc="Building scripts"/>
<filteritem type="filename" name="*.a|*.d|*.o|*.cmd|*.hcb|*.swp" desc="Intermediate products"/>
</filefilter>
</filefilterlist>
</oatconfig>
</configuration>

View File

@ -0,0 +1,57 @@
# linux\_khdf<a name="EN-US_TOPIC_0000001078489630"></a>
- [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>
```
/drivers/hdf_core/adapter/khdf/linux
├── utils # Compilation scripts for building and configuring the parsing code
├── manager # Code for starting and adapting to the HDF
├── model # Code for adapting to Linux
│ ├── audio # Audio driver model
│ ├── display # Display driver model
│ ├── input # Input driver model
│ ├── misc # Misc driver model, including dsoftbus, light, vibrator
│ ├── network # WLAN driver model
│ ├── sensor # Sensor driver model
│ ├── storage # Storage driver model
│ ├── usb # USB 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
│ ├── adc # ADC APIs
│ ├── emmc # EMMC APIs
│ ├── gpio # GPIO APIs
│ ├── i2c # I2C APIs
│ ├── mipi_csi # MIPI CSI APIs
│ ├── mipi_dsi # MIPI DSI APIs
│ ├── mmc # MMC APIs
│ ├── pwm # PWM APIs
│ ├── regulator # Regulator APIs
│ ├── rtc # RTC APIs
│ ├── sdio # SDIO APIs
│ ├── spi # SPI APIs
│ ├── uart # UART APIs
│ └── watchdog # WATCHDOG APIs
├── test # Testcase for testing the Linux kernel driver
```
## Repositories Involved<a name="section1371113476307"></a>
[Driver subsystem](https://gitee.com/openharmony/docs/blob/master/en/readme/driver-subsystem.md)
[drivers\_framework](https://gitee.com/openharmony/drivers_framework/blob/master/README.md)
[drivers\_adapter](https://gitee.com/openharmony/drivers_adapter/blob/master/README.md)
[drivers\_adapter\_khdf\_linux](https://gitee.com/openharmony/drivers_adapter_khdf_linux/blob/master/README.md)
[drivers\_peripheral](https://gitee.com/openharmony/drivers_peripheral/blob/master/README.md)

View File

@ -0,0 +1,57 @@
# linux\_khdf<a name="ZH-CN_TOPIC_0000001078489630"></a>
- [简介](#section11660541593)
- [目录](#section161941989596)
- [相关仓](#section1371113476307)
## 简介<a name="section11660541593"></a>
该目录主要存放OpenHarmony驱动子系统适配linux内核的代码和编译脚本在linux内核中部署OpenHarmony驱动框架。
## 目录<a name="section161941989596"></a>
```
/drivers/hdf_core/adapter/khdf/linux
├── utils #linux内核下编译配置解析代码的编译脚本
├── manager #linux内核下启动适配启动HDF框架代码
├── model #驱动模型适配linux代码
│ ├── audio #音频驱动模型
│ ├── display #显示驱动模型
│ ├── input #输入驱动模型
│ ├── misc #杂项驱动模型包括dsoftbus、light、vibrator
│ ├── network #wifi驱动模型
│ └── sensor #传感器驱动模型
│ └── storage #存储驱动模型
│ └── usb #USB驱动模型
├── network #适配linux内核网络代码
├── osal #适配linux内核的posix接口
├── platform #平台设备接口适配linux内核代码
│ ├── adc #adc接口
│ ├── emmc #emmc操作接口
│ ├── gpio #gpio接口
│ ├── i2c #i2c接口
│ ├── mipi_csi #mipi csi接口
│ ├── mipi_dsi #mipi dsi接口
│ ├── mmc #mmc接口
│ ├── pwm #pwm接口
│ ├── regulator #regulator接口
│ ├── rtc #rtc接口
│ ├── sdio #sdio接口
│ ├── spi #spi接口
│ ├── uart #uart接口
│ └── watchdog #watchdog接口
├── test #linux内核测试用例
```
## 相关仓<a name="section1371113476307"></a>
[驱动子系统](https://gitee.com/openharmony/docs/blob/master/zh-cn/readme/%E9%A9%B1%E5%8A%A8%E5%AD%90%E7%B3%BB%E7%BB%9F.md)
[drivers\_framework](https://gitee.com/openharmony/drivers_framework/blob/master/README_zh.md)
[drivers\_adapter](https://gitee.com/openharmony/drivers_adapter/blob/master/README_zh.md)
[drivers\_adapter\_khdf\_linux](https://gitee.com/openharmony/drivers_adapter_khdf_linux/blob/master/README_zh.md)
[drivers\_peripheral](https://gitee.com/openharmony/drivers_peripheral/blob/master/README_zh.md)

View File

@ -0,0 +1,41 @@
/*
* hdf_driver_module.h
*
* osal driver
*
* Copyright (c) 2022 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_DRIVER_MODULE_H
#define HDF_DRIVER_MODULE_H
#include <linux/kernel.h>
#include <linux/module.h>
#include "hdf_driver.h"
#define HDF_DRIVER_MODULE(module) \
static int __init hdf_driver_init(void) \
{ \
HDF_LOGI("hdf driver " #module " register"); \
return HdfRegisterDriverEntry(&module); \
} \
static void __exit hdf_driver_exit(void) \
{ \
HDF_LOGI("hdf driver " #module " unregister"); \
HdfUnregisterDriverEntry(&module); \
} \
module_init(hdf_driver_init); \
module_exit(hdf_driver_exit);
#endif // HDF_DRIVER_MODULE_H

View File

@ -0,0 +1,87 @@
#
# 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.
#
#
OHOS_SOURCE_ROOT := ../../../../../../
HDF_FRAMEWORK_SRC_DIR := ../../../../
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_FUNCTION_OBJECTS := $(patsubst %.c,%.o,$(SEC_LIB_SOURCES))
SEC_FUNCTION_OBJECTS := $(addprefix $(OHOS_SOURCE_ROOT)/third_party/bounds_checking_function/src/,${SEC_FUNCTION_OBJECTS})
obj-y += \
$(HDF_FRAMEWORK_SRC_DIR)/framework/utils/src/hdf_cstring.o \
$(HDF_FRAMEWORK_SRC_DIR)/framework/utils/src/hdf_slist.o \
$(HDF_FRAMEWORK_SRC_DIR)/framework/utils/src/hdf_sref.o \
$(HDF_FRAMEWORK_SRC_DIR)/framework/utils/src/hdf_map.o \
$(HDF_FRAMEWORK_SRC_DIR)/framework/utils/src/hdf_sbuf.o \
$(HDF_FRAMEWORK_SRC_DIR)/framework/utils/src/hdf_sbuf_impl_raw.o \
$(HDF_FRAMEWORK_SRC_DIR)/framework/utils/src/hdf_task_queue.o \
$(HDF_FRAMEWORK_SRC_DIR)/framework/core/host/src/devhost_service.o \
$(HDF_FRAMEWORK_SRC_DIR)/framework/core/host/src/devmgr_service_clnt.o \
$(HDF_FRAMEWORK_SRC_DIR)/framework/core/host/src/devsvc_manager_clnt.o \
$(HDF_FRAMEWORK_SRC_DIR)/framework/core/host/src/hdf_device.o \
$(HDF_FRAMEWORK_SRC_DIR)/framework/core/host/src/hdf_device_node.o \
$(HDF_FRAMEWORK_SRC_DIR)/framework/core/host/src/hdf_device_token.o \
$(HDF_FRAMEWORK_SRC_DIR)/framework/core/host/src/hdf_driver_loader.o \
$(HDF_FRAMEWORK_SRC_DIR)/framework/core/host/src/hdf_observer_record.o \
$(HDF_FRAMEWORK_SRC_DIR)/framework/core/host/src/hdf_service_subscriber.o \
$(HDF_FRAMEWORK_SRC_DIR)/framework/core/host/src/hdf_device_object.o \
$(HDF_FRAMEWORK_SRC_DIR)/framework/core/host/src/hdf_power_manager.o \
$(HDF_FRAMEWORK_SRC_DIR)/framework/core/host/src/hdf_service_observer.o \
$(HDF_FRAMEWORK_SRC_DIR)/framework/core/host/src/power_state_token.o \
$(HDF_FRAMEWORK_SRC_DIR)/framework/core/manager/src/devhost_service_clnt.o \
$(HDF_FRAMEWORK_SRC_DIR)/framework/core/manager/src/device_token_clnt.o \
$(HDF_FRAMEWORK_SRC_DIR)/framework/core/manager/src/devmgr_service.o \
$(HDF_FRAMEWORK_SRC_DIR)/framework/core/manager/src/devsvc_manager.o \
$(HDF_FRAMEWORK_SRC_DIR)/framework/core/manager/src/devsvc_manager_ext.o \
$(HDF_FRAMEWORK_SRC_DIR)/framework/core/manager/src/servstat_listener_holder.o \
$(HDF_FRAMEWORK_SRC_DIR)/framework/core/manager/src/hdf_driver_installer.o \
$(HDF_FRAMEWORK_SRC_DIR)/framework/core/manager/src/hdf_host_info.o \
$(HDF_FRAMEWORK_SRC_DIR)/framework/core/manager/src/power_state_token_clnt.o \
$(HDF_FRAMEWORK_SRC_DIR)/framework/core/manager/src/driver_manager.o \
$(HDF_FRAMEWORK_SRC_DIR)/framework/core/shared/src/hdf_service_record.o \
$(HDF_FRAMEWORK_SRC_DIR)/framework/core/shared/src/hdf_device_info.o \
$(HDF_FRAMEWORK_SRC_DIR)/framework/core/shared/src/hdf_object_manager.o \
$(HDF_FRAMEWORK_SRC_DIR)/framework/core/shared/src/hdf_io_service.o \
$(HDF_FRAMEWORK_SRC_DIR)/framework/core/shared/src/service_status.o \
$(HDF_FRAMEWORK_SRC_DIR)/framework/core/common/src/devlite_object_config.o \
$(HDF_FRAMEWORK_SRC_DIR)/framework/core/common/src/hdf_attribute.o \
$(HDF_FRAMEWORK_SRC_DIR)/framework/core/common/src/devmgr_service_start.o \
$(HDF_FRAMEWORK_SRC_DIR)/framework/core/common/src/hdf_device_node_ext.o \
$(HDF_FRAMEWORK_SRC_DIR)/framework/core/common/src/buildin_config_entry.o \
$(HDF_FRAMEWORK_SRC_DIR)/framework/core/adapter/vnode/src/hdf_vnode_adapter.o \
./src/devmgr_load.o \
./src/devmgr_pm_reg.o \
./src/sym_export.o \
./src/hdf_kevent.o \
$(SEC_FUNCTION_OBJECTS)
ccflags-y += \
-I$(srctree)/drivers/hdf/framework/include \
-I$(srctree)/drivers/hdf/framework/include/osal \
-I$(srctree)/drivers/hdf/framework/include/utils \
-I$(srctree)/drivers/hdf/framework/include \
-I$(srctree)/drivers/hdf/framework/utils/include \
-I$(srctree)/drivers/hdf/framework/include/core \
-I$(srctree)/drivers/hdf/framework/core/host/include \
-I$(srctree)/drivers/hdf/framework/core/manager/include \
-I$(srctree)/drivers/hdf/framework/core/shared/include \
-I$(srctree)/drivers/hdf/framework/core/common/include/host \
-I$(srctree)/drivers/hdf/framework/core/common/include/manager \
-I$(srctree)/drivers/hdf/framework/core/adapter/vnode/include \
-I$(srctree)/drivers/hdf/framework/include/config \
-I$(srctree)/drivers/hdf/khdf/osal/include \
-I$(srctree)/include/uapi/linux \
-I$(srctree)/bounds_checking_function/include

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;
}
late_initcall(DeviceManagerInit);

View File

@ -0,0 +1,89 @@
/*
* devmgr_pm.c
*
* HDF power manager of linux
*
* 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 <linux/notifier.h>
#include <linux/suspend.h>
#include "devmgr_service.h"
#include "hdf_base.h"
#include "hdf_log.h"
#define HDF_LOG_TAG devmgr_pm
static int DevmgrPmSuspend(void)
{
HDF_LOGD("%s enter", __func__);
struct IDevmgrService *devmgrService = DevmgrServiceGetInstance();
if (devmgrService == NULL) {
return HDF_FAILURE;
}
if (devmgrService->PowerStateChange(devmgrService, POWER_STATE_SUSPEND) != HDF_SUCCESS) {
HDF_LOGE("%s drivers suspend failed", __func__);
devmgrService->PowerStateChange(devmgrService, POWER_STATE_RESUME);
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
static int DevmgrPmResume(void)
{
HDF_LOGD("%s enter", __func__);
struct IDevmgrService *devmgrService = DevmgrServiceGetInstance();
if (devmgrService == NULL) {
return HDF_FAILURE;
}
devmgrService->PowerStateChange(devmgrService, POWER_STATE_RESUME);
HDF_LOGD("%s resume done", __func__);
return HDF_SUCCESS;
}
static int DevmgrPmNotifier(struct notifier_block *nb, unsigned long mode, void *data)
{
int ret = HDF_SUCCESS;
switch (mode) {
case PM_SUSPEND_PREPARE:
ret = DevmgrPmSuspend();
break;
case PM_POST_SUSPEND:
ret = DevmgrPmResume();
break;
default:
break;
}
return ret;
}
static struct notifier_block PmNotifier = {
.notifier_call = DevmgrPmNotifier,
};
int DevMgrPmRegister(void)
{
int ret;
HDF_LOGD("%s enter", __func__);
ret = register_pm_notifier(&PmNotifier);
if (ret) {
HDF_LOGE("%s register_pm_notifier failed", __func__);
}
return ret;
}
EXPORT_SYMBOL(DevMgrPmRegister);

View File

@ -0,0 +1,467 @@
/*
*
* hdf_kevent.c
*
* HDF kevent implement for linux
*
* Copyright (c) 2022 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/completion.h>
#include <linux/fb.h>
#include <linux/notifier.h>
#include <linux/suspend.h>
#include "devmgr_service_clnt.h"
#include "hdf_device_desc.h"
#include "hdf_dlist.h"
#include "hdf_log.h"
#include "hdf_power_state.h"
#include "hdf_sbuf.h"
#include "osal_mem.h"
#include "osal_mutex.h"
#include "osal_sysevent.h"
#define HDF_LOG_TAG kevent
#define EVENT_TIMEOUT_JIFFIES 5
#define EVENT_DEFAULT_SIZE 64
#define KEVENT_COMPLETE_EVENT 1
struct HdfKeventWait {
struct completion comp;
struct DListHead listNode;
uint32_t waitCount;
};
struct HdfKeventClient {
struct HdfDeviceIoClient *ioClient;
struct DListHead listNode;
};
struct HdfKeventModule {
struct HdfDeviceObject *devObj;
struct notifier_block keventPmNotifier;
struct notifier_block fbNotifier;
struct DListHead waitList;
struct OsalMutex mutex;
struct OsalMutex clientMutex;
struct DListHead clientList;
int32_t clientCount;
};
static struct HdfKeventModule *g_keventModule = NULL;
static struct HdfKeventWait *HdfKeventWaitAlloc(void)
{
struct HdfKeventWait *wait = OsalMemAlloc(sizeof(struct HdfKeventWait));
if (wait != NULL) {
init_completion(&wait->comp);
}
return wait;
}
static void HdfKeventWaitFree(struct HdfKeventWait *wait)
{
if (wait != NULL) {
OsalMemFree(wait);
}
}
static struct HdfSBuf *PrepareEvent(
struct HdfKeventWait **wait, uint64_t class, int32_t eventId, const char *content, bool sync)
{
struct HdfSBuf *eventBuf = NULL;
struct HdfSysEvent sysEvent;
struct HdfKeventWait *eventWait = NULL;
eventBuf = HdfSbufObtain(EVENT_DEFAULT_SIZE);
if (eventBuf == NULL) {
HDF_LOGE("%s: failed to obtain sbuf", __func__);
return NULL;
}
sysEvent.eventClass = class;
sysEvent.eventid = eventId;
sysEvent.syncToken = 0;
if (sync) {
eventWait = HdfKeventWaitAlloc();
if (eventWait == NULL) {
HdfSbufRecycle(eventBuf);
return NULL;
}
sysEvent.syncToken = (uint64_t)eventWait;
}
if (!HdfSbufWriteBuffer(eventBuf, &sysEvent, sizeof(sysEvent))) {
HdfSbufRecycle(eventBuf);
return NULL;
}
if (!HdfSbufWriteString(eventBuf, content)) {
HdfSbufRecycle(eventBuf);
return NULL;
}
*wait = eventWait;
return eventBuf;
}
static int SendKevent(
struct HdfKeventModule *keventModule, uint16_t class, int32_t event, const char *content, bool sync)
{
struct HdfSBuf *eventBuf = NULL;
struct HdfKeventWait *wait = NULL;
struct HdfKeventClient *client = NULL;
int ret;
if (keventModule->clientCount <= 0) {
return 0;
}
eventBuf = PrepareEvent(&wait, class, event, content, sync);
if (eventBuf == NULL) {
return HDF_FAILURE;
}
OsalMutexLock(&keventModule->mutex);
if (sync) {
DListInsertTail(&wait->listNode, &keventModule->waitList);
}
OsalMutexLock(&keventModule->clientMutex);
if (sync) {
wait->waitCount = keventModule->clientCount;
}
DLIST_FOR_EACH_ENTRY(client, &keventModule->clientList, struct HdfKeventClient, listNode) {
ret = HdfDeviceSendEventToClient(client->ioClient, HDF_SYSEVENT, eventBuf);
if (ret) {
HDF_LOGE("%s: failed to send device event, %d", __func__, ret);
}
}
OsalMutexUnlock(&keventModule->clientMutex);
if (sync) {
OsalMutexUnlock(&keventModule->mutex);
if (wait_for_completion_timeout(&wait->comp, EVENT_TIMEOUT_JIFFIES * HZ) == 0) {
HDF_LOGE("%s:send kevent timeout, class=%d, event=%d", __func__, class, event);
ret = HDF_ERR_TIMEOUT;
}
OsalMutexLock(&keventModule->mutex);
DListRemove(&wait->listNode);
HdfKeventWaitFree(wait);
}
OsalMutexUnlock(&keventModule->mutex);
HdfSbufRecycle(eventBuf);
return ret;
}
int32_t HdfSysEventSend(uint64_t eventClass, uint32_t event, const char *content, bool sync)
{
struct HdfKeventModule *keventmodule = g_keventModule;
if (keventmodule == NULL) {
return HDF_DEV_ERR_OP;
}
return SendKevent(keventmodule, eventClass, event, content, sync);
}
static int32_t KernalSpacePmNotify(int32_t powerEvent)
{
uint32_t pmStatus = POWER_STATE_MAX;
struct DevmgrServiceClnt *devmgrClnt = NULL;
switch (powerEvent) {
case KEVENT_POWER_SUSPEND:
pmStatus = POWER_STATE_SUSPEND;
break;
case KEVENT_POWER_DISPLAY_OFF:
pmStatus = POWER_STATE_DOZE_SUSPEND;
break;
case KEVENT_POWER_RESUME:
pmStatus = POWER_STATE_RESUME;
break;
case KEVENT_POWER_DISPLAY_ON:
pmStatus = POWER_STATE_DOZE_RESUME;
break;
default:
return HDF_ERR_INVALID_PARAM;
}
devmgrClnt = DevmgrServiceClntGetInstance();
if (devmgrClnt == NULL || devmgrClnt->devMgrSvcIf == NULL) {
return HDF_FAILURE;
}
return devmgrClnt->devMgrSvcIf->PowerStateChange(devmgrClnt->devMgrSvcIf, pmStatus);
}
static int32_t KeventPmNotifierFn(struct notifier_block *nb, unsigned long action, void *dummy)
{
struct HdfKeventModule *keventModule = NULL;
int32_t powerEvent;
bool sync = false;
int ret = 0;
keventModule = CONTAINER_OF(nb, struct HdfKeventModule, keventPmNotifier);
HDF_LOGI("%s:action=%d", __func__, action);
switch (action) {
case PM_SUSPEND_PREPARE:
HDF_LOGI("%s:receive suspend event", __func__);
powerEvent = KEVENT_POWER_SUSPEND;
sync = true;
break;
case PM_POST_SUSPEND:
HDF_LOGI("%s:receive resume event", __func__);
powerEvent = KEVENT_POWER_RESUME;
break;
default:
return 0;
}
ret = SendKevent(keventModule, HDF_SYSEVENT_CLASS_POWER, powerEvent, NULL, sync);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: failed to notify userspace pm status");
}
return KernalSpacePmNotify(powerEvent);
}
static int32_t KeventFbNotifierFn(struct notifier_block *nb, unsigned long event, void *data)
{
int *blank = NULL;
struct fb_event *fbEvent = data;
struct HdfKeventModule *keventModule = NULL;
int32_t powerEvent;
bool sync = false;
int ret = 0;
if (event != FB_EVENT_BLANK) {
return 0;
}
if (fbEvent == NULL || fbEvent->data == NULL) {
return 0;
}
keventModule = CONTAINER_OF(nb, struct HdfKeventModule, fbNotifier);
blank = fbEvent->data;
HDF_LOGI("%s:blank=%d", __func__, *blank);
switch (*blank) {
case FB_BLANK_UNBLANK:
HDF_LOGI("%s:receive display on event", __func__);
powerEvent = KEVENT_POWER_DISPLAY_ON;
break;
default:
HDF_LOGI("%s:receive display off event", __func__);
powerEvent = KEVENT_POWER_DISPLAY_OFF;
sync = true;
break;
}
ret = SendKevent(keventModule, HDF_SYSEVENT_CLASS_POWER, powerEvent, NULL, sync);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: failed to notify userspace pm status");
}
return KernalSpacePmNotify(powerEvent);
}
void CompleteKevent(struct HdfKeventModule *keventModule, struct HdfSBuf *tokenBuffer)
{
uint64_t token = 0;
struct HdfKeventWait *wait = NULL;
if (tokenBuffer == NULL || !HdfSbufReadUint64(tokenBuffer, &token)) {
return;
}
OsalMutexLock(&keventModule->mutex);
DLIST_FOR_EACH_ENTRY(wait, &keventModule->waitList, struct HdfKeventWait, listNode) {
if (token == (uint64_t)wait) {
wait->waitCount--;
if (wait->waitCount == 0) {
complete(&wait->comp);
}
}
}
OsalMutexUnlock(&keventModule->mutex);
}
static int32_t HdfKeventIoServiceDispatch(
struct HdfDeviceIoClient *client, int id, struct HdfSBuf *data, struct HdfSBuf *reply)
{
struct HdfKeventModule *keventModule;
(void)reply;
keventModule = (struct HdfKeventModule *)client->device->priv;
if (keventModule == NULL) {
return HDF_ERR_INVALID_PARAM;
}
switch (id) {
case KEVENT_COMPLETE_EVENT: {
CompleteKevent(keventModule, data);
break;
}
default:
break;
}
return 0;
}
static int32_t HdfKeventDriverOpen(struct HdfDeviceIoClient *client)
{
struct HdfKeventModule *keventModule = NULL;
struct HdfKeventClient *kClient = NULL;
if (client == NULL || client->device == NULL || client->device->priv == NULL) {
return HDF_ERR_INVALID_PARAM;
}
keventModule = (struct HdfKeventModule *)client->device->priv;
kClient = OsalMemCalloc(sizeof(struct HdfKeventClient));
if (kClient == NULL) {
return HDF_ERR_MALLOC_FAIL;
}
kClient->ioClient = client;
client->priv = kClient;
OsalMutexLock(&keventModule->clientMutex);
DListInsertTail(&kClient->listNode, &keventModule->clientList);
keventModule->clientCount++;
OsalMutexUnlock(&keventModule->clientMutex);
HDF_LOGI("%s:kevnet usecount=%d", __func__, keventModule->clientCount);
return 0;
}
static void HdfKeventDriverClose(struct HdfDeviceIoClient *client)
{
struct HdfKeventClient *kClient = NULL;
struct HdfKeventModule *keventModule;
keventModule = (struct HdfKeventModule *)client->device->priv;
if (keventModule == NULL) {
return;
}
kClient = (struct HdfKeventClient *)client->priv;
if (kClient == NULL) {
return;
}
OsalMutexLock(&keventModule->clientMutex);
DListRemove(&kClient->listNode);
keventModule->clientCount--;
OsalMemFree(kClient);
client->priv = NULL;
OsalMutexUnlock(&keventModule->clientMutex);
HDF_LOGI("%s:kevnet usecount=%d", __func__, keventModule->clientCount);
}
static void HdfKeventDriverRelease(struct HdfDeviceObject *object)
{
struct HdfKeventModule *keventModule = (struct HdfKeventModule *)object->priv;
if (keventModule == NULL) {
return;
}
unregister_pm_notifier(&keventModule->keventPmNotifier);
fb_unregister_client(&keventModule->keventPmNotifier);
OsalMutexDestroy(&keventModule->mutex);
OsalMutexDestroy(&keventModule->clientMutex);
OsalMemFree(keventModule);
object->priv = NULL;
return;
}
static int32_t HdfKeventDriverBind(struct HdfDeviceObject *dev)
{
static struct IDeviceIoService keventService = {
.Open = HdfKeventDriverOpen,
.Dispatch = HdfKeventIoServiceDispatch,
.Release = HdfKeventDriverClose,
};
struct HdfKeventModule *keventModule = NULL;
if (dev == NULL) {
return HDF_ERR_INVALID_PARAM;
}
keventModule = (struct HdfKeventModule *)OsalMemCalloc(sizeof(struct HdfKeventModule));
if (keventModule == NULL) {
return HDF_ERR_MALLOC_FAIL;
}
if (OsalMutexInit(&keventModule->mutex) != HDF_SUCCESS) {
OsalMemFree(keventModule);
return HDF_FAILURE;
}
if (OsalMutexInit(&keventModule->clientMutex) != HDF_SUCCESS) {
OsalMutexDestroy(&keventModule->mutex);
OsalMemFree(keventModule);
return HDF_FAILURE;
}
DListHeadInit(&keventModule->waitList);
DListHeadInit(&keventModule->clientList);
keventModule->devObj = dev;
dev->priv = keventModule;
dev->service = &keventService;
return HDF_SUCCESS;
}
static int32_t HdfKeventDriverInit(struct HdfDeviceObject *dev)
{
int32_t ret;
struct HdfKeventModule *keventModule = (struct HdfKeventModule *)dev->priv;
keventModule->keventPmNotifier.notifier_call = KeventPmNotifierFn;
ret = register_pm_notifier(&keventModule->keventPmNotifier);
if (ret != 0) {
HDF_LOGE("%s:failed to register pm notifier %d", __func__, ret);
} else {
HDF_LOGI("%s:register pm notifier success", __func__);
}
keventModule->fbNotifier.notifier_call = KeventFbNotifierFn;
ret = fb_register_client(&keventModule->fbNotifier);
if (ret != 0) {
HDF_LOGE("%s:failed to register fb notifier %d", __func__, ret);
unregister_pm_notifier(&keventModule->keventPmNotifier);
} else {
HDF_LOGI("%s:register fb notifier success", __func__);
}
g_keventModule = keventModule;
return ret;
}
static struct HdfDriverEntry g_hdfKeventDriverEntry = {
.moduleVersion = 1,
.moduleName = "HDF_KEVENT",
.Bind = HdfKeventDriverBind,
.Init = HdfKeventDriverInit,
.Release = HdfKeventDriverRelease,
};
HDF_INIT(g_hdfKeventDriverEntry);

View File

@ -0,0 +1,45 @@
/*
* sym_export.c
*
* HDF symbol export file
*
* Copyright (c) 2022 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/kernel.h>
#include <linux/module.h>
#include <devmgr_service.h>
#include <hdf_base.h>
#include <hdf_device_desc.h>
#include <hdf_device_object.h>
#include <hdf_driver.h>
#include <hdf_pm.h>
#include <hdf_sbuf.h>
EXPORT_SYMBOL(HdfDeviceSendEvent);
EXPORT_SYMBOL(HdfDeviceSendEventToClient);
EXPORT_SYMBOL(HdfDeviceGetServiceName);
EXPORT_SYMBOL(HdfPmRegisterPowerListener);
EXPORT_SYMBOL(HdfDeviceObjectAlloc);
EXPORT_SYMBOL(HdfDeviceObjectRelease);
EXPORT_SYMBOL(HdfDeviceObjectRegister);
EXPORT_SYMBOL(HdfDeviceObjectPublishService);
EXPORT_SYMBOL(HdfDeviceObjectSetServInfo);
EXPORT_SYMBOL(HdfDeviceObjectUpdate);
EXPORT_SYMBOL(DevmgrServiceGetInstance);
EXPORT_SYMBOL(HdfSbufWriteInt32);
EXPORT_SYMBOL(HdfSbufReadUint32);
EXPORT_SYMBOL(HdfSbufReadString);
EXPORT_SYMBOL(HdfUnregisterDriverEntry);
EXPORT_SYMBOL(HdfRegisterDriverEntry);
EXPORT_SYMBOL(HdfSbufReadInt32);

View File

@ -0,0 +1,35 @@
config DRIVERS_HDF_AUDIO
bool "Enable HDF Audio driver"
default n
depends on DRIVERS_HDF
help
Answer Y to choice HDF Audio driver.
config DRIVERS_HDF_AUDIO_HI3516CODEC
bool "Enable HDF Audio Codec driver"
default n
depends on DRIVERS_HDF_AUDIO
help
Answer Y to choice HDF Audio Codec driver.
config DRIVERS_HDF_AUDIO_RK3568
bool "Enable HDF Audio Codec driver"
default n
depends on DRIVERS_HDF_AUDIO
help
Answer Y to choice HDF Audio Codec driver.
config DRIVERS_HDF_AUDIO_ANA_HEADSET
bool "Audio Headset support"
default n
depends on DRIVERS_HDF_AUDIO_RK3568
help
Audio Headset support:
support hook interrupt mode.
support hook adc mode.
config DRIVERS_HDF_AUDIO_TEST
bool "Enable HDF Audio driver Test"
default n
depends on DRIVERS_HDF_AUDIO
help
Answer Y to choice HDF Audio driver Test.

View File

@ -0,0 +1,101 @@
#
# 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.
#
#
KHDF_AUDIO_BASE_ROOT_DIR = ../../../../../../..
KHDF_AUDIO_KHDF_ROOT_DIR = drivers/hdf/khdf
KHDF_FRAMEWORK_ROOT_DIR = drivers/hdf/framework
KHDF_AUDIO_ROOT_DIR = ../../../../../framework/model/audio
KHDF_AUDIO_HI3516DV300_DIR = $(KHDF_AUDIO_BASE_ROOT_DIR)/device/board/hisilicon/hispark_taurus/audio_drivers
KHDF_AUDIO_HI3516DV300_INC_DIR = drivers/hdf/framework/../../../device/board/hisilicon/hispark_taurus/audio_drivers
KHDF_AUDIO_RK3568_DIR = $(KHDF_AUDIO_BASE_ROOT_DIR)/device/board/hihope/$(DEVICE_NAME)/audio_drivers
KHDF_AUDIO_RK3568_INC_DIR = drivers/hdf/framework/../../../device/board/hihope/$(DEVICE_NAME)/audio_drivers
obj-$(CONFIG_DRIVERS_HDF_AUDIO) += \
$(KHDF_AUDIO_ROOT_DIR)/core/src/audio_core.o \
$(KHDF_AUDIO_ROOT_DIR)/core/src/audio_host.o \
$(KHDF_AUDIO_ROOT_DIR)/core/src/audio_parse.o \
$(KHDF_AUDIO_ROOT_DIR)/common/src/audio_codec_base.o \
$(KHDF_AUDIO_ROOT_DIR)/common/src/audio_dsp_base.o \
$(KHDF_AUDIO_ROOT_DIR)/common/src/audio_dai_base.o \
$(KHDF_AUDIO_ROOT_DIR)/common/src/audio_platform_base.o \
$(KHDF_AUDIO_ROOT_DIR)/common/src/audio_dma_base.o \
$(KHDF_AUDIO_ROOT_DIR)/sapm/src/audio_sapm.o \
$(KHDF_AUDIO_ROOT_DIR)/dispatch/src/audio_stream_dispatch.o \
$(KHDF_AUDIO_ROOT_DIR)/dispatch/src/audio_control_dispatch.o
obj-$(CONFIG_DRIVERS_HDF_AUDIO_HI3516CODEC) += \
$(KHDF_AUDIO_HI3516DV300_DIR)/codec/tfa9879/src/tfa9879_codec_adapter.o \
$(KHDF_AUDIO_HI3516DV300_DIR)/codec/tfa9879/src/tfa9879_codec_ops.o \
$(KHDF_AUDIO_HI3516DV300_DIR)/codec/hi3516/src/hi3516_codec_adapter.o \
$(KHDF_AUDIO_HI3516DV300_DIR)/codec/hi3516/src/hi3516_codec_impl.o \
$(KHDF_AUDIO_HI3516DV300_DIR)/codec/hi3516/src/hi3516_codec_ops.o \
$(KHDF_AUDIO_HI3516DV300_DIR)/dsp/src/dsp_adapter.o \
$(KHDF_AUDIO_HI3516DV300_DIR)/dsp/src/dsp_ops.o \
$(KHDF_AUDIO_HI3516DV300_DIR)/soc/src/hi3516_dai_adapter.o \
$(KHDF_AUDIO_HI3516DV300_DIR)/soc/src/hi3516_dai_ops.o \
$(KHDF_AUDIO_HI3516DV300_DIR)/soc/src/hi3516_aiao_impl.o \
$(KHDF_AUDIO_HI3516DV300_DIR)/soc/src/hi3516_dma_ops.o \
$(KHDF_AUDIO_HI3516DV300_DIR)/soc/src/hi3516_dma_adapter.o
obj-$(CONFIG_DRIVERS_HDF_AUDIO_RK3568) += \
$(KHDF_AUDIO_RK3568_DIR)/codec/rk809_codec/src/rk809_codec_adapter.o \
$(KHDF_AUDIO_RK3568_DIR)/codec/rk809_codec/src/rk809_codec_impl.o \
$(KHDF_AUDIO_RK3568_DIR)/codec/rk809_codec/src/rk809_codec_linux_driver.o \
$(KHDF_AUDIO_RK3568_DIR)/dsp/src/rk3568_dsp_adapter.o \
$(KHDF_AUDIO_RK3568_DIR)/dsp/src/rk3568_dsp_ops.o \
$(KHDF_AUDIO_RK3568_DIR)/dai/src/rk3568_dai_adapter.o \
$(KHDF_AUDIO_RK3568_DIR)/dai/src/rk3568_dai_ops.o \
$(KHDF_AUDIO_RK3568_DIR)/dai/src/rk3568_dai_linux_driver.o \
$(KHDF_AUDIO_RK3568_DIR)/soc/src/rk3568_dma_adapter.o \
$(KHDF_AUDIO_RK3568_DIR)/soc/src/rk3568_dma_ops.o
obj-$(CONFIG_DRIVERS_HDF_AUDIO_ANA_HEADSET) += \
$(KHDF_AUDIO_RK3568_DIR)/headset_monitor/src/analog_headset_base.o \
$(KHDF_AUDIO_RK3568_DIR)/headset_monitor/src/analog_headset_core.o \
$(KHDF_AUDIO_RK3568_DIR)/headset_monitor/src/analog_headset_gpio.o \
$(KHDF_AUDIO_RK3568_DIR)/headset_monitor/src/analog_headset_adc.o
ccflags-$(CONFIG_DRIVERS_HDF_AUDIO) += -lm -lc -lgcc -std=gnu99 -Werror\
-I$(srctree)/$(KHDF_AUDIO_KHDF_ROOT_DIR)/osal/include \
-I$(srctree)/$(KHDF_FRAMEWORK_ROOT_DIR)/include/core \
-I$(srctree)/$(KHDF_FRAMEWORK_ROOT_DIR)/include/utils \
-I$(srctree)/$(KHDF_FRAMEWORK_ROOT_DIR)/include/osal \
-I$(srctree)/$(KHDF_FRAMEWORK_ROOT_DIR)/include/platform \
-I$(srctree)/$(KHDF_FRAMEWORK_ROOT_DIR)/include/config \
-I$(srctree)/$(KHDF_FRAMEWORK_ROOT_DIR)/include/audio \
-I$(srctree)/$(KHDF_FRAMEWORK_ROOT_DIR)/ability/sbuf/include \
-I$(srctree)/$(KHDF_FRAMEWORK_ROOT_DIR)/core/common/include/host \
-I$(srctree)/$(KHDF_FRAMEWORK_ROOT_DIR)/core/host/include \
-I$(srctree)/$(KHDF_FRAMEWORK_ROOT_DIR)/model/audio/core/include \
-I$(srctree)/$(KHDF_FRAMEWORK_ROOT_DIR)/model/audio/sapm/include \
-I$(srctree)/$(KHDF_FRAMEWORK_ROOT_DIR)/model/audio/dispatch/include \
-I$(srctree)/$(KHDF_FRAMEWORK_ROOT_DIR)/model/audio/common/include \
-I$(srctree)/bounds_checking_function/include
ccflags-$(CONFIG_DRIVERS_HDF_AUDIO_HI3516CODEC) += \
-I$(srctree)/$(KHDF_AUDIO_HI3516DV300_INC_DIR)/codec/hi3516/include \
-I$(srctree)/$(KHDF_AUDIO_HI3516DV300_INC_DIR)/soc/include \
-I$(srctree)/$(KHDF_AUDIO_HI3516DV300_INC_DIR)/dsp/include \
-I$(srctree)/$(KHDF_AUDIO_HI3516DV300_INC_DIR)/codec/tfa9879/include
ccflags-$(CONFIG_DRIVERS_HDF_AUDIO_RK3568) += \
-I$(srctree)/$(KHDF_AUDIO_RK3568_INC_DIR)/soc/include \
-I$(srctree)/$(KHDF_AUDIO_RK3568_INC_DIR)/dai/include \
-I$(srctree)/$(KHDF_AUDIO_RK3568_INC_DIR)/dsp/include \
-I$(srctree)/$(KHDF_AUDIO_RK3568_INC_DIR)/codec/rk809_codec/include \
-I$(srctree)/$(KHDF_AUDIO_RK3568_INC_DIR)/include
ccflags-$(CONFIG_DRIVERS_HDF_AUDIO_ANA_HEADSET) += \
-I$(srctree)/$(KHDF_FRAMEWORK_ROOT_DIR)/model/input/driver \
-I$(srctree)/drivers/hdf/evdev \
-I$(srctree)/$(KHDF_AUDIO_RK3568_INC_DIR)/headset_monitor/include

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.

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.
#
#
DISPLAY_ROOT_DIR = ../../../../../framework/model/display/driver
ifeq ($(CONFIG_DRIVERS_HDF_DISP), y)
obj-y += \
$(DISPLAY_ROOT_DIR)/hdf_disp.o \
$(DISPLAY_ROOT_DIR)/backlight/hdf_bl.o
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0))
ifeq ($(CONFIG_ARCH_ROCKCHIP), y)
obj-y += $(DISPLAY_ROOT_DIR)/hdf_drm_panel.o
endif
#endif
obj-$(CONFIG_DRIVERS_HDF_PLATFORM_PWM) += \
$(DISPLAY_ROOT_DIR)/backlight/pwm_bl.o
obj-$(CONFIG_ARCH_SPRD) += \
$(DISPLAY_ROOT_DIR)/panel/ili9881c_boe.o
obj-$(CONFIG_ARCH_HI3516DV300) += \
$(DISPLAY_ROOT_DIR)/adapter_soc/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
obj-$(CONFIG_ARCH_ROCKCHIP) += \
$(DISPLAY_ROOT_DIR)/panel/ili9881_st_5p5.o
ccflags-y += -lm -lc -lgcc \
-I$(srctree)/drivers/hdf/framework/model/display/driver \
-I$(srctree)/drivers/hdf/framework/model/display/driver/adapter_soc \
-I$(srctree)/drivers/hdf/framework/include/utils \
-I$(srctree)/drivers/hdf/framework/model/display/driver/backlight \
-I$(srctree)/drivers/hdf/framework/include/core \
-I$(srctree)/drivers/hdf/framework/core/common/include/host \
-I$(srctree)/drivers/hdf/framework/include \
-I$(srctree)/drivers/hdf/framework/include/osal \
-I$(srctree)/drivers/hdf/framework/include/platform \
-I$(srctree)/drivers/hdf/framework/include/config \
-I$(srctree)/drivers/hdf/khdf/osal/include \
-I$(srctree)/include/linux \
-I$(srctree)/include/drm
ccflags-y +=-I$(srctree)/bounds_checking_function/include
endif

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.

View File

@ -0,0 +1,44 @@
#
# 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.
#
#
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_adapter.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 +=-I$(srctree)/drivers/hdf/framework/model/input/driver \
-I$(srctree)/drivers/hdf/framework/model/input/driver/input_bus_ops \
-I$(srctree)/drivers/hdf/framework/include/core \
-I$(srctree)/drivers/hdf/framework/core/common/include/host \
-I$(srctree)/drivers/hdf/framework/include/utils \
-I$(srctree)/drivers/hdf/framework/include/osal \
-I$(srctree)/drivers/hdf/framework/include/platform \
-I$(srctree)/drivers/hdf/framework/include/config \
-I$(srctree)/drivers/hdf/framework/core/host/include \
-I$(srctree)/drivers/hdf/framework/core/shared/include \
-I$(srctree)/drivers/hdf/framework/utils/include \
-I$(srctree)/drivers/hdf/khdf/osal/include
ccflags-y +=-I$(srctree)/bounds_checking_function/include \
-I$(srctree)/drivers/hdf/evdev

View File

@ -0,0 +1,24 @@
# 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_DSOFTBUS
bool "Enable HDF dsoftbus driver"
default n
depends on DRIVERS_HDF
help
control HDF dsoftbus driver capability.
config DSOFTBUS_WLAN_PARAM_MONITOR
bool "enable dsoftbus wlan parameter monitor"
default n
depends on DRIVERS_HDF_DSOFTBUS
help
control hdf dsoftbus wlan parameter monitor capability.

View File

@ -0,0 +1,36 @@
#
# 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.
#
#
DSOFTBUS_ROOT_DIR = ../../../../../../framework/model/misc/dsoftbus
obj-$(CONFIG_DRIVERS_HDF_DSOFTBUS) += \
$(DSOFTBUS_ROOT_DIR)/src/hdf_dsoftbus_driver.o \
$(DSOFTBUS_ROOT_DIR)/src/module_manager.o
ifeq ($(CONFIG_DSOFTBUS_WLAN_PARAM_MONITOR), y)
obj-$(CONFIG_DRIVERS_HDF_DSOFTBUS) += $(DSOFTBUS_ROOT_DIR)/src/wlan_param_monitor.o
ccflags-$(CONFIG_DRIVERS_HDF_DSOFTBUS) +=-DENABLE_WLAN_PARAM_MONITOR
endif
ccflags-y +=-I$(srctree)/drivers/hdf/framework/model/misc/dsoftbus/include \
-I$(srctree)/drivers/hdf/framework/core/common/include/host \
-I$(srctree)/drivers/hdf/framework/include/core \
-I$(srctree)/drivers/hdf/framework/include/osal \
-I$(srctree)/drivers/hdf/framework/include/utils \
-I$(srctree)/drivers/hdf/framework/include/platform \
-I$(srctree)/drivers/hdf/framework/include/config \
-I$(srctree)/drivers/hdf/framework/core/host/include \
-I$(srctree)/drivers/hdf/framework/core/shared/include \
-I$(srctree)/drivers/hdf/framework/utils/include \
-I$(srctree)/drivers/hdf/khdf/osal/include \
-I$(srctree)/bounds_checking_function/include

View File

@ -0,0 +1,17 @@
# Copyright (c) 2022 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_LIGHT
bool "Enable HDF light driver"
default n
depends on DRIVERS_HDF
help
Answer Y to enable HDF light driver.

View File

@ -0,0 +1,31 @@
#
# Copyright (c) 2022 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.
#
#
LIGHT_ROOT_DIR = ../../../../../../framework/model/misc/light/driver
obj-$(CONFIG_DRIVERS_HDF_LIGHT) += \
$(LIGHT_ROOT_DIR)/src/light_driver.o
ccflags-y +=-I$(srctree)/drivers/hdf/framework/model/misc/light/driver/include \
-I$(srctree)/drivers/hdf/framework/include/core \
-I$(srctree)/drivers/hdf/framework/core/common/include/host \
-I$(srctree)/drivers/hdf/framework/include/utils \
-I$(srctree)/drivers/hdf/framework/include/osal \
-I$(srctree)/drivers/hdf/framework/include/platform \
-I$(srctree)/drivers/hdf/framework/include/config \
-I$(srctree)/drivers/hdf/framework/core/host/include \
-I$(srctree)/drivers/hdf/framework/core/shared/include \
-I$(srctree)/drivers/hdf/framework/utils/include \
-I$(srctree)/drivers/hdf/khdf/osal/include \
-I$(srctree)/bounds_checking_function/include

View File

@ -0,0 +1,25 @@
# 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_VIBRATOR
bool "Enable HDF vibrator driver"
default n
depends on DRIVERS_HDF
help
Answer Y to enable HDF vibrator driver.
config DRIVERS_HDF_VIBRATOR_LINEAR
bool "Enable HDF linear vibrator driver"
default n
depends on DRIVERS_HDF_VIBRATOR
help
Answer Y to enable HDF linear vibrator driver.

View File

@ -0,0 +1,37 @@
#
# Copyright (c) 2022 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.
#
#
VIBRATOR_ROOT_DIR = ../../../../../../../hdf_core/framework/model/misc/vibrator/driver
VIBRATOR_ROOT_CHIPSET = ../../../../../../../peripheral/misc/vibrator
obj-$(CONFIG_DRIVERS_HDF_VIBRATOR) += \
$(VIBRATOR_ROOT_DIR)/src/vibrator_driver.o \
$(VIBRATOR_ROOT_DIR)/src/vibrator_haptic.o
obj-$(CONFIG_DRIVERS_HDF_VIBRATOR_LINEAR) += \
$(VIBRATOR_ROOT_CHIPSET)/chipset/vibrator_linear_driver.o
ccflags-y +=-I$(srctree)/drivers/hdf/framework/model/misc/vibrator/driver/include \
-I$(srctree)/drivers/hdf/peripheral/misc/vibrator/chipset \
-I$(srctree)/drivers/hdf/framework/include/core \
-I$(srctree)/drivers/hdf/framework/core/common/include/host \
-I$(srctree)/drivers/hdf/framework/include/utils \
-I$(srctree)/drivers/hdf/framework/include/osal \
-I$(srctree)/drivers/hdf/framework/include/platform \
-I$(srctree)/drivers/hdf/framework/include/config \
-I$(srctree)/drivers/hdf/framework/core/host/include \
-I$(srctree)/drivers/hdf/framework/core/shared/include \
-I$(srctree)/drivers/hdf/framework/utils/include \
-I$(srctree)/drivers/hdf/khdf/osal/include \
-I$(srctree)/bounds_checking_function/include

View File

@ -0,0 +1,7 @@
config DRIVERS_HDF_BT
bool "Enable HDF Bluetooth"
default n
depends on DRIVERS_HDF
help
Answer Y to enable HDF bluetooth.

View File

@ -0,0 +1,31 @@
#
# 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.
#
#
MODULE_NAME := hdf_bt_model
include drivers/hdf/khdf/model/network/bluetooth/env_config.mk
HDF_BT_FRAMEWORKS_ROOT := ../../../../../../framework/model/network/bluetooth
obj-$(CONFIG_DRIVERS_HDF_BT) += $(MODULE_NAME).o
$(MODULE_NAME)-objs := $(HDF_BT_FRAMEWORKS_ROOT)/hdf_bt_core.o \
$(HDF_BT_FRAMEWORKS_ROOT)/hdf_chip.o \
$(HDF_BT_FRAMEWORKS_ROOT)/hdf_reset.o \
$(HDF_BT_FRAMEWORKS_ROOT)/hdf_power.o
ccflags-$(CONFIG_DRIVERS_HDF_BT) += \
$(HDF_FRAMEWORKS_INC) \
$(HDF_BT_FRAMEWORKS_INC) \
$(SECURE_LIB_INC)

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.
#
#
HDF_FRAMEWORKS_INC := \
-I$(srctree)/./ \
-I$(srctree)/drivers/hdf/framework/core/common/include/host \
-I$(srctree)/drivers/hdf/framework/core/host/include \
-I$(srctree)/drivers/hdf/framework/core/manager/include \
-I$(srctree)/drivers/hdf/framework/core/shared/include \
-I$(srctree)/drivers/hdf/framework/include \
-I$(srctree)/drivers/hdf/framework/include/config \
-I$(srctree)/drivers/hdf/framework/include/core \
-I$(srctree)/drivers/hdf/framework/include/platform \
-I$(srctree)/drivers/hdf/framework/include/utils \
-I$(srctree)/drivers/hdf/framework/support/platform/include \
-I$(srctree)/drivers/hdf/framework/support/platform/include/platform \
-I$(srctree)/drivers/hdf/framework/utils/include \
-I$(srctree)/drivers/hdf/khdf/osal/include \
-I$(srctree)/drivers/hdf/khdf/config/include \
-I$(srctree)/include/hdf \
-I$(srctree)/include/hdf/osal \
-I$(srctree)/include/hdf/utils \
-I$(srctree)/drivers/hdf/framework/include/bluetooth
HDF_BT_FRAMEWORKS_INC := \
-I$(srctree)/drivers/hdf/framework/model/network/bluetooth
SECURE_LIB_INC := \
-I$(srctree)/bounds_checking_function/include

View File

@ -0,0 +1,53 @@
config DRIVERS_HDF_WIFI
bool "Enable HDF wifi"
default n
depends on DRIVERS_HDF && DRIVERS_HDF_PLATFORM_SDIO
help
Answer Y to enable HDF wifi.
config DRIVERS_HDF_WLAN_SDIO
bool "Enable HDF wlan sdio bus"
default n
depends on DRIVERS_HDF_WIFI
help
Answer Y to support HDF wlan sdio bus
config DRIVERS_HDF_WLAN_USB
bool "Enable HDF wlan usb bus"
default n
depends on DRIVERS_HDF_WIFI
help
Answer Y to support HDF wlan usb bus
config DRIVERS_HI3881
bool "Enable hi3881"
default n
depends on DRIVERS_HDF_WIFI
help
Answer Y to enable hi3881 wifi chip driver.
config DRIVERS_HDF_NETDEV_EXT
bool "Get Linux net device from HDF"
default n
help
Get Linux net device from HDF
config DRIVERS_RTL8723DU
bool "Enable Realtek 8723D USB WiFi(rtl8723du)"
default n
depends on DRIVERS_HDF_WIFI
select DRIVERS_HDF_WLAN_USB
select DRIVERS_HDF_NETDEV_EXT
help
Answer Y to enable rtl8723du wifi chip driver.
config AP6XXX_WIFI6_HDF
tristate "support ap6xxx wifi6(80211ax) HDF"
depends on DRIVERS_HDF_WIFI
select CFG80211
select MAC80211
select DRIVERS_HDF_NETDEV_EXT
help
This driver supports wifi6 for ap6xxx HDF chipset.
This driver uses the kernel's wireless extensions subsystem.
If you choose to build a module, it'll be called dhd. Say M if unsure.

View File

@ -0,0 +1,76 @@
#
# Copyright (c) 2020-2022 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/components/softap
WSTA_PATH := core/components/sta
WP2P_PATH := core/components/p2p
WEAPOL_PATH := core/components/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
IBUS_PATH := bus
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)/$(WP2P_PATH)/p2p.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 \
$(HDF_WIFI_FRAMEWORKS_ROOT)/$(IBUS_PATH)/hdf_ibus_intf.o \
$(MODULE_NAME)-$(CONFIG_DRIVERS_HDF_WLAN_SDIO) += $(HDF_WIFI_FRAMEWORKS_ROOT)/$(IBUS_PATH)/hdf_sdio_intf.o
$(MODULE_NAME)-$(CONFIG_DRIVERS_HDF_WLAN_USB) += $(HDF_WIFI_FRAMEWORKS_ROOT)/$(IBUS_PATH)/hdf_usb_intf.o
ccflags-$(CONFIG_DRIVERS_HDF_WIFI) += \
$(HDF_FRAMEWORKS_INC) \
$(HDF_WIFI_FRAMEWORKS_INC) \
$(HDF_WIFI_ADAPTER_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_HDF_WIFI) += vendor/

View File

@ -0,0 +1,59 @@
#
# 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_FRAMEWORKS_INC := \
-I$(srctree)/drivers/hdf/framework/core/common/include/host \
-I$(srctree)/drivers/hdf/framework/core/host/include \
-I$(srctree)/drivers/hdf/framework/core/manager/include \
-I$(srctree)/drivers/hdf/framework/core/shared/include \
-I$(srctree)/drivers/hdf/framework/include \
-I$(srctree)/drivers/hdf/framework/include/config \
-I$(srctree)/drivers/hdf/framework/include/core \
-I$(srctree)/drivers/hdf/framework/include/platform \
-I$(srctree)/drivers/hdf/framework/include/utils \
-I$(srctree)/drivers/hdf/framework/support/platform/include \
-I$(srctree)/drivers/hdf/framework/support/platform/include/platform \
-I$(srctree)/drivers/hdf/framework/utils/include \
-I$(srctree)/drivers/hdf/khdf/osal/include \
-I$(srctree)/drivers/hdf/khdf/config/include \
-I$(srctree)/include/hdf \
-I$(srctree)/include/hdf/osal \
-I$(srctree)/include/hdf/utils
HDF_WIFI_FRAMEWORKS_INC := \
-I$(srctree)/drivers/hdf/framework/model/network/wifi/core/components/eapol \
-I$(srctree)/drivers/hdf/framework/model/network/wifi/core/components/softap \
-I$(srctree)/drivers/hdf/framework/model/network/wifi/core/components/sta \
-I$(srctree)/drivers/hdf/framework/model/network/wifi/core/components/p2p \
-I$(srctree)/drivers/hdf/framework/model/network/wifi/include \
-I$(srctree)/drivers/hdf/framework/model/network/wifi/core \
-I$(srctree)/drivers/hdf/framework/model/network/wifi/core/module \
-I$(srctree)/drivers/hdf/framework/model/network/common/netdevice \
-I$(srctree)/drivers/hdf/framework/model/network/wifi/platform/include \
-I$(srctree)/drivers/hdf/framework/model/network/wifi/platform/include/message \
-I$(srctree)/drivers/hdf/framework/model/network/wifi/client/include \
-I$(srctree)/drivers/hdf/framework/include/wifi \
-I$(srctree)/drivers/hdf/framework/include/net \
-I$(srctree)/drivers/hdf/frameworks/model/network/wifi/bus
HDF_WIFI_ADAPTER_INC := \
-I$(srctree)/drivers/hdf/khdf/network/include
HDF_WIFI_VENDOR_INC := \
-I$(srctree)/drivers/hdf/wifi
SECURE_LIB_INC := \
-I$(srctree)/bounds_checking_function/include

View File

@ -0,0 +1,136 @@
/*
* 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 = NULL;
if (queue == NULL) {
return;
}
impl = (HdfWlanQueueImpl *)queue;
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 = NULL;
void *result = NULL;
if (queue == NULL) {
return NULL;
}
impl = (HdfWlanQueueImpl *)queue;
if (queue == NULL) {
return NULL;
}
ret = OsalMutexLock(&impl->lock);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s:Get lock failed!ret=%d", __func__, ret);
return NULL;
}
if (impl->elementCount > 0) {
uint16_t headIndex = impl->headIndex;
result = impl->elements[headIndex++];
impl->headIndex = ((headIndex >= impl->maxElements) ? 0 : headIndex);
impl->elementCount--;
}
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 = NULL;
uint16_t tailIndex;
if (queue == NULL) {
return HDF_FAILURE;
}
impl = (HdfWlanQueueImpl *)queue;
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;
}
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;
}

View File

@ -0,0 +1,30 @@
#
# Copyright (c) 2020-2022 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_HI3881) += hi3881/
ifneq ($(CONFIG_AP6XXX_WIFI6_HDF),)
RKWIFI_PATH := $(HDF_VENDOR_PREFIX)/device/board/$(PRODUCT_COMPANY)/$(DEVICE_NAME)/wifi
obj-$(CONFIG_AP6XXX_WIFI6_HDF) += $(RKWIFI_PATH)/
endif
ifneq ($(CONFIG_DRIVERS_RTL8723DU),)
obj-$(CONFIG_DRIVERS_RTL8723DU) += $(HDF_VENDOR_PREFIX)/$(KERNEL_SRC_DIR)/drivers/net/wireless/rtl/
endif

View File

@ -0,0 +1,122 @@
#
# 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 := drivers/hdf/wifi/hi3881v100/
VENDOR_WIFI_PATH := device/soc/hisilicon/common/platform/wifi/hi3881v100
WIFI_DRIVER_DIR := driver
HDF_WIFI_VENDOR_ROOT = $(HDF_VENDOR_PREFIX)/device/soc/hisilicon/common/platform/wifi/hi3881v100
##################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)/hi3881v100/adapter \
-I$(srctree)/$(INC_TOP_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
$(MODULE_NAME)-objs := $(HDF_WIFI_VENDOR_ROOT)/adapter/hdf_wlan_sdio_adapt.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_vap.o \
hmac_main.o
ifeq ($(CFG_EDCA_OPT_AP), y)
hmac-objs += hmac_edca_opt.o
endif
ifeq ($(CFG_P2P), y)
hmac-objs += hmac_p2p.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,297 @@
#
# 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 = y
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
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$(srctree)/$(INC_TOP_PATH)/$(WIFI_DRIVER_DIR)/wal
HI1131_WIFI_CFLAGS +=-I$(srctree)/$(INC_TOP_PATH)/$(WIFI_DRIVER_DIR)/oam
HI1131_WIFI_CFLAGS +=-I$(srctree)/$(INC_TOP_PATH)/$(WIFI_DRIVER_DIR)/mac/hmac
HI1131_WIFI_CFLAGS +=-I$(srctree)/$(INC_TOP_PATH)/$(WIFI_DRIVER_DIR)/mac/common
HI1131_WIFI_CFLAGS +=-I$(srctree)/$(INC_TOP_PATH)/$(WIFI_DRIVER_DIR)/hcc
HI1131_WIFI_CFLAGS +=-I$(srctree)/$(INC_TOP_PATH)/$(WIFI_DRIVER_DIR)/frw
HI1131_WIFI_CFLAGS +=-I$(srctree)/$(INC_TOP_PATH)/$(WIFI_DRIVER_DIR)/oal
HI1131_WIFI_CFLAGS +=-I$(srctree)/$(INC_TOP_PATH)/$(WIFI_DRIVER_DIR)/include
################################device##############################
HI1131_WIFI_CFLAGS +=-I$(srctree)/$(INC_TOP_PATH)/$(WIFI_DRIVER_DIR)/hdfadapt
ifeq ($(LOSCFG_PLATFORM_HI3516EV300), y)
HI1131_WIFI_CFLAGS +=-DHISI_WIFI_PLATFORM_HI3516EV300
endif

View File

@ -0,0 +1,138 @@
# 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_ACCEL_BMI160
bool "Enable HDF accel bmi160 sensor driver"
default n
depends on DRIVERS_HDF_SENSOR_ACCEL
help
Answer Y to enable HDF accel bmi160 sensor driver.
config DRIVERS_HDF_SENSOR_ACCEL_MXC6655XA
bool "Enable HDF accel mxc6655xa sensor driver"
default n
depends on DRIVERS_HDF_SENSOR_ACCEL
help
Answer Y to enable HDF accel mxc6655xa sensor driver.
config DRIVERS_HDF_SENSOR_PPG
bool "Enable HDF ppg sensor driver"
default n
depends on DRIVERS_HDF_SENSOR
help
Answer Y to enable HDF ppg sensor driver.
config DRIVERS_HDF_SENSOR_PPG_CS1262
bool "Enable HDF ppg ppg cs1262 sensor driver"
default n
depends on DRIVERS_HDF_SENSOR_PPG
help
Answer Y to enable HDF ppg ppg cs1262 sensor driver.
config DRIVERS_HDF_SENSOR_ALS
bool "Enable HDF als sensor driver"
default n
depends on DRIVERS_HDF_SENSOR
help
Answer Y to enable HDF als sensor driver.
config DRIVERS_HDF_SENSOR_ALS_BH1745
bool "Enable HDF als bh1745 sensor driver"
default n
depends on DRIVERS_HDF_SENSOR_ALS
help
Answer Y to enable HDF als bh1745 sensor driver.
config DRIVERS_HDF_SENSOR_GRAVITY
bool "Enable HDF gravity sensor driver"
default n
depends on DRIVERS_HDF_SENSOR_ACCEL
help
Answer Y to enable HDF gravity 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.
config DRIVERS_HDF_SENSOR_GYRO_BMI160
bool "Enable HDF gyro bmi160 sensor driver"
default n
depends on DRIVERS_HDF_SENSOR_GYRO
help
Answer Y to enable HDF gyro bmi160 sensor driver.
config DRIVERS_HDF_SENSOR_PEDOMETER
bool "Enable HDF pedometer sensor driver"
default n
depends on DRIVERS_HDF_SENSOR
help
Answer Y to enable HDF pedometer sensor driver.
config DRIVERS_HDF_SENSOR_PEDOMETER_BMI160
bool "Enable HDF pedometer bmi160 sensor driver"
default n
depends on DRIVERS_HDF_SENSOR_PEDOMETER
help
Answer Y to enable HDF pedometer bmi160 sensor driver.
config DRIVERS_HDF_SENSOR_BAROMETER
bool "Enable HDF barometer sensor driver"
default n
depends on DRIVERS_HDF_SENSOR
help
Answer Y to enable HDF barometer sensor driver.
config DRIVERS_HDF_SENSOR_BAROMETER_BMP180
bool "Enable HDF barometer bmp180 sensor driver"
default n
depends on DRIVERS_HDF_SENSOR_BAROMETER
help
Answer Y to enable HDF barometer bmp180 sensor driver.
config DRIVERS_HDF_SENSOR_HALL
bool "Enable HDF hall sensor driver"
default n
depends on DRIVERS_HDF_SENSOR
help
Answer Y to enable HDF hall sensor driver.
config DRIVERS_HDF_SENSOR_HALL_AK8789
bool "Enable HDF hall ak8789 sensor driver"
default n
depends on DRIVERS_HDF_SENSOR_HALL
help
Answer Y to enable HDF hall ak8789 sensor driver.
config DRIVERS_HDF_SENSOR_MAGNETIC
bool "Enable HDF magnetic sensor driver"
default n
depends on DRIVERS_HDF_SENSOR
help
Answer Y to enable HDF magnetic sensor driver.
config DRIVERS_HDF_SENSOR_MAGNETIC_LSM303
bool "Enable HDF magnetic lsm303 sensor driver"
default n
depends on DRIVERS_HDF_SENSOR_MAGNETIC
help
Answer Y to enable HDF magnetic lsm303 sensor driver.
config DRIVERS_HDF_SENSOR_PROXIMITY
bool "Enable HDF proximity sensor driver"
default n
depends on DRIVERS_HDF_SENSOR
help
Answer Y to enable HDF proximity sensor driver.
config DRIVERS_HDF_SENSOR_PROXIMITY_APDS9960
bool "Enable HDF proximity adps9960 sensor driver"
default n
depends on DRIVERS_HDF_SENSOR_PROXIMITY
help
Answer Y to enable HDF proximity apds9960 sensor driver.

View File

@ -0,0 +1,92 @@
# Copyright (c) 2022 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.
SENSOR_ROOT_DIR = ../../../../../../hdf_core/framework/model/sensor/driver
SENSOR_ROOT_CHIPSET = ../../../../../../peripheral/sensor
obj-$(CONFIG_DRIVERS_HDF_SENSOR) += \
$(SENSOR_ROOT_DIR)/common/src/sensor_config_controller.o \
$(SENSOR_ROOT_DIR)/common/src/sensor_config_parser.o \
$(SENSOR_ROOT_DIR)/common/src/sensor_device_manager.o \
$(SENSOR_ROOT_DIR)/common/src/sensor_platform_if.o
obj-$(CONFIG_DRIVERS_HDF_SENSOR_ACCEL) += $(SENSOR_ROOT_DIR)/accel/sensor_accel_driver.o
obj-$(CONFIG_DRIVERS_HDF_SENSOR_ACCEL_BMI160) += $(SENSOR_ROOT_CHIPSET)/chipset/accel/accel_bmi160.o
obj-$(CONFIG_DRIVERS_HDF_SENSOR_ACCEL_MXC6655XA) += $(SENSOR_ROOT_CHIPSET)/chipset/accel/accel_mxc6655xa.o
obj-$(CONFIG_DRIVERS_HDF_SENSOR_PPG) += $(SENSOR_ROOT_DIR)/ppg/sensor_ppg_driver.o \
$(SENSOR_ROOT_DIR)/ppg/sensor_ppg_config.o
obj-$(CONFIG_DRIVERS_HDF_SENSOR_PPG_CS1262) += $(SENSOR_ROOT_CHIPSET)/chipset/ppg/ppg_cs1262_spi.o \
$(SENSOR_ROOT_CHIPSET)/chipset/ppg/ppg_cs1262.o \
$(SENSOR_ROOT_CHIPSET)/chipset/ppg/ppg_cs1262_fw.o
obj-$(CONFIG_DRIVERS_HDF_SENSOR_ALS) += $(SENSOR_ROOT_DIR)/als/sensor_als_driver.o
obj-$(CONFIG_DRIVERS_HDF_SENSOR_ALS_BH1745) += $(SENSOR_ROOT_CHIPSET)/chipset/als/als_bh1745.o
obj-$(CONFIG_DRIVERS_HDF_SENSOR_PROXIMITY) += $(SENSOR_ROOT_DIR)/proximity/sensor_proximity_driver.o
obj-$(CONFIG_DRIVERS_HDF_SENSOR_PROXIMITY_APDS9960) += $(SENSOR_ROOT_CHIPSET)/chipset/proximity/proximity_apds9960.o
obj-$(CONFIG_DRIVERS_HDF_SENSOR_GYRO) += $(SENSOR_ROOT_DIR)/gyro/sensor_gyro_driver.o
obj-$(CONFIG_DRIVERS_HDF_SENSOR_GYRO_BMI160) += $(SENSOR_ROOT_CHIPSET)/chipset/gyro/gyro_bmi160.o
obj-$(CONFIG_DRIVERS_HDF_SENSOR_BAROMETER) += $(SENSOR_ROOT_DIR)/barometer/sensor_barometer_driver.o
obj-$(CONFIG_DRIVERS_HDF_SENSOR_BAROMETER_BMP180) += $(SENSOR_ROOT_CHIPSET)/chipset/barometer/barometer_bmp180.o
obj-$(CONFIG_DRIVERS_HDF_SENSOR_HALL) += $(SENSOR_ROOT_DIR)/hall/sensor_hall_driver.o
obj-$(CONFIG_DRIVERS_HDF_SENSOR_HALL_AK8789) += $(SENSOR_ROOT_CHIPSET)/chipset/hall/hall_ak8789.o
obj-$(CONFIG_DRIVERS_HDF_SENSOR_MAGNETIC) += $(SENSOR_ROOT_DIR)/magnetic/sensor_magnetic_driver.o
obj-$(CONFIG_DRIVERS_HDF_SENSOR_MAGNETIC_LSM303) += $(SENSOR_ROOT_CHIPSET)/chipset/magnetic/magnetic_lsm303.o
obj-$(CONFIG_DRIVERS_HDF_SENSOR_GRAVITY) += $(SENSOR_ROOT_DIR)/accel/sensor_gravity_driver.o
obj-$(CONFIG_DRIVERS_HDF_SENSOR_PEDOMETER) += $(SENSOR_ROOT_DIR)/pedometer/sensor_pedometer_driver.o
obj-$(CONFIG_DRIVERS_HDF_SENSOR_PEDOMETER_BMI160) += $(SENSOR_ROOT_CHIPSET)/chipset/pedometer/pedometer_bmi160.o
ccflags-y += -I$(srctree)/drivers/hdf/framework/model/sensor/driver/include \
-I$(srctree)/drivers/hdf/framework/model/sensor/driver/common/include \
-I$(srctree)/drivers/hdf/peripheral/sensor/chipset/accel \
-I$(srctree)/drivers/hdf/framework/model/sensor/driver/accel \
-I$(srctree)/drivers/hdf/peripheral/sensor/chipset/ppg \
-I$(srctree)/drivers/hdf/framework/model/sensor/driver/ppg \
-I$(srctree)/drivers/hdf/framework/model/sensor/driver/als \
-I$(srctree)/drivers/hdf/peripheral/sensor/chipset/als \
-I$(srctree)/drivers/hdf/framework/model/sensor/driver/gyro \
-I$(srctree)/drivers/hdf/peripheral/sensor/chipset/gyro \
-I$(srctree)/drivers/hdf/framework/model/sensor/driver/pedometer \
-I$(srctree)/drivers/hdf/peripheral/sensor/chipset/pedometer \
-I$(srctree)/drivers/hdf/framework/model/sensor/driver/barometer \
-I$(srctree)/drivers/hdf/peripheral/sensor/chipset/barometer \
-I$(srctree)/drivers/hdf/framework/model/sensor/driver/hall \
-I$(srctree)/drivers/hdf/peripheral/sensor/chipset/hall \
-I$(srctree)/drivers/hdf/peripheral/sensor/chipset/magnetic \
-I$(srctree)/drivers/hdf/framework/model/sensor/driver/magnetic \
-I$(srctree)/drivers/hdf/framework/model/sensor/driver/proximity \
-I$(srctree)/drivers/hdf/peripheral/sensor/chipset/proximity \
-I$(srctree)/drivers/hdf/framework/include/core \
-I$(srctree)/drivers/hdf/framework/core/common/include/host \
-I$(srctree)/drivers/hdf/framework/include/utils \
-I$(srctree)/drivers/hdf/framework/include/osal \
-I$(srctree)/drivers/hdf/framework/include/platform \
-I$(srctree)/drivers/hdf/framework/include/config \
-I$(srctree)/drivers/hdf/khdf/osal/include \
-I$(srctree)/bounds_checking_function/include

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_STORAGE
bool "Enable HDF storage driver"
default n
depends on DRIVERS_HDF
help
Answer Y to enable HDF storage driver.

View File

@ -0,0 +1,51 @@
# 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/platform/platform.mk
STORAGE_ROOT_DIR = ../../../../../framework/model/storage
ccflags-y +=-I$(srctree)/drivers/hdf/framework/model/storage/include/mmc \
-I$(srctree)/drivers/hdf/framework/model/storage/include/mtd \
-I$(srctree)/drivers/hdf/framework/include/core \
-I$(srctree)/drivers/hdf/framework/core/common/include/host \
-I$(srctree)/drivers/hdf/framework/include/utils \
-I$(srctree)/drivers/hdf/framework/utils/include \
-I$(srctree)/drivers/hdf/framework/include/osal \
-I$(srctree)/drivers/hdf/framework/include/platform \
-I$(srctree)/drivers/hdf/framework/support/platform/include/fwk \
-I$(srctree)/drivers/hdf/framework/model/storage/include/mmc \
-I$(srctree)/drivers/hdf/framework/include/config \
-I$(srctree)/drivers/hdf/khdf/osal/include \
-I$(srctree)/bounds_checking_function/include
obj-$(CONFIG_DRIVERS_HDF_STORAGE) += \
./mmc_block_linux.o \
$(STORAGE_ROOT_DIR)/src/mmc/mmc_block.o \
$(STORAGE_ROOT_DIR)/src/mmc/mmc_core.o \
$(STORAGE_ROOT_DIR)/src/mmc/mmc_emmc.o \
$(STORAGE_ROOT_DIR)/src/mmc/mmc_sdio.o \
$(STORAGE_ROOT_DIR)/src/mmc/mmc_dispatch.o \
$(STORAGE_ROOT_DIR)/src/mmc/mmc_if.o \
$(STORAGE_ROOT_DIR)/src/mmc/mmc_protocol.o
obj-y += $(STORAGE_ROOT_DIR)/src/mmc/emmc_if.o \
$(STORAGE_ROOT_DIR)/src/mmc/sdio_if.o \
./emmc_adapter.o \
./sdio_adapter.o
ifeq ($(CONFIG_ARCH_HI3516DV300), y)
obj-y += \
./vendor_adapter/hi35xx_mmc_adapter.o
else
obj-y += \
./mmc_adapter.o
endif

View File

@ -0,0 +1,187 @@
/*
* emmc_adapter.c
*
* 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 <securec.h>
#include <linux/mmc/card.h>
#include <linux/mmc/host.h>
#include "device_resource_if.h"
#include "hdf_log.h"
#include "emmc_if.h"
#include "mmc_corex.h"
#include "mmc_emmc.h"
#define HDF_LOG_TAG emmc_adapter_c
struct mmc_host *GetMmcHost(int32_t slot);
int32_t LinuxEmmcGetCid(struct EmmcDevice *dev, uint8_t *cid, uint32_t size)
{
struct mmc_host *mmcHost = NULL;
struct MmcCntlr *cntlr = NULL;
if (dev == NULL || dev->mmc.cntlr == NULL) {
HDF_LOGE("LinuxEmmcGetCid: dev or cntlr is null.");
return HDF_ERR_INVALID_OBJECT;
}
if (cid == NULL || size < EMMC_CID_LEN) {
HDF_LOGE("LinuxEmmcGetCid: cid is null or size is invalid.");
return HDF_ERR_INVALID_PARAM;
}
cntlr = dev->mmc.cntlr;
mmcHost = (struct mmc_host *)cntlr->priv;
if (mmcHost == NULL) {
HDF_LOGE("LinuxEmmcGetCid: mmcHost is NULL!");
return HDF_ERR_NOT_SUPPORT;
}
if (mmcHost->card == NULL) {
HDF_LOGE("LinuxEmmcGetCid: 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("LinuxEmmcGetCid: memcpy_s fail!");
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
static struct EmmcDeviceOps g_emmcMethod = {
.getCid = LinuxEmmcGetCid,
};
static void LinuxEmmcDeleteCntlr(struct MmcCntlr *cntlr)
{
if (cntlr == NULL) {
return;
}
if (cntlr->curDev != NULL) {
MmcDeviceRemove(cntlr->curDev);
OsalMemFree(cntlr->curDev);
}
MmcCntlrRemove(cntlr);
OsalMemFree(cntlr);
}
static int32_t LinuxEmmcCntlrParse(struct MmcCntlr *cntlr, struct HdfDeviceObject *obj)
{
const struct DeviceResourceNode *node = NULL;
struct DeviceResourceIface *drsOps = NULL;
int32_t ret;
if (obj == NULL || cntlr == NULL) {
HDF_LOGE("LinuxEmmcCntlrParse: input para is NULL.");
return HDF_FAILURE;
}
node = obj->property;
if (node == NULL) {
HDF_LOGE("LinuxEmmcCntlrParse: drs node is NULL.");
return HDF_FAILURE;
}
drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
if (drsOps == NULL || drsOps->GetUint16 == NULL || drsOps->GetUint32 == NULL) {
HDF_LOGE("LinuxEmmcCntlrParse: invalid drs ops fail!");
return HDF_FAILURE;
}
ret = drsOps->GetUint16(node, "hostId", &(cntlr->index), 0);
if (ret != HDF_SUCCESS) {
HDF_LOGE("LinuxEmmcCntlrParse: read hostIndex fail!");
return ret;
}
ret = drsOps->GetUint32(node, "devType", &(cntlr->devType), 0);
if (ret != HDF_SUCCESS) {
HDF_LOGE("LinuxEmmcCntlrParse: read devType fail!");
return ret;
}
return HDF_SUCCESS;
}
static int32_t LinuxEmmcBind(struct HdfDeviceObject *obj)
{
struct MmcCntlr *cntlr = NULL;
int32_t ret;
if (obj == NULL) {
HDF_LOGE("LinuxEmmcBind: Fail, obj is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
cntlr = (struct MmcCntlr *)OsalMemCalloc(sizeof(struct MmcCntlr));
if (cntlr == NULL) {
HDF_LOGE("LinuxEmmcBind: no mem for MmcCntlr.");
return HDF_ERR_MALLOC_FAIL;
}
cntlr->ops = NULL;
cntlr->hdfDevObj = obj;
obj->service = &cntlr->service;
ret = LinuxEmmcCntlrParse(cntlr, obj);
if (ret != HDF_SUCCESS) {
HDF_LOGE("LinuxEmmcBind: cntlr parse fail.");
goto _ERR;
}
cntlr->priv = (void *)GetMmcHost((int32_t)cntlr->index);
ret = MmcCntlrAdd(cntlr, false);
if (ret != HDF_SUCCESS) {
HDF_LOGE("LinuxEmmcBind: cntlr add fail.");
goto _ERR;
}
ret = MmcCntlrAllocDev(cntlr, (enum MmcDevType)cntlr->devType);
if (ret != HDF_SUCCESS) {
HDF_LOGE("LinuxEmmcBind: alloc dev fail.");
goto _ERR;
}
MmcDeviceAddOps(cntlr->curDev, &g_emmcMethod);
HDF_LOGD("LinuxEmmcBind: Success!");
return HDF_SUCCESS;
_ERR:
LinuxEmmcDeleteCntlr(cntlr);
HDF_LOGE("LinuxEmmcBind: Fail!");
return HDF_FAILURE;
}
static int32_t LinuxEmmcInit(struct HdfDeviceObject *obj)
{
(void)obj;
HDF_LOGD("LinuxEmmcInit: Success!");
return HDF_SUCCESS;
}
static void LinuxEmmcRelease(struct HdfDeviceObject *obj)
{
if (obj == NULL) {
return;
}
LinuxEmmcDeleteCntlr((struct MmcCntlr *)obj->service);
}
struct HdfDriverEntry g_emmcDriverEntry = {
.moduleVersion = 1,
.Bind = LinuxEmmcBind,
.Init = LinuxEmmcInit,
.Release = LinuxEmmcRelease,
.moduleName = "HDF_PLATFORM_EMMC",
};
HDF_INIT(g_emmcDriverEntry);

View File

@ -0,0 +1,37 @@
/*
* mmc_adapter.c
*
* linux mmc driver implement.
*
* Copyright (c) 2022 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/host.h>
#include "hdf_base.h"
#include "hdf_log.h"
#define HDF_LOG_TAG mmc_adapter_c
struct mmc_host *GetMmcHost(int32_t slot)
{
(void)slot;
HDF_LOGE("Vendor need to adapter GetMmcHost");
return NULL;
}
void SdioRescan(int32_t slot)
{
(void)slot;
HDF_LOGE("Vendor need to adapter SdioRescan");
return;
}

View File

@ -0,0 +1,30 @@
/*
* storage_block_linux.c
*
* storage block 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 "mmc_block.h"
int32_t MmcBlockOsInit(struct MmcDevice *mmcDevice)
{
(void)mmcDevice;
return HDF_SUCCESS;
}
void MmcBlockOsUninit(struct MmcDevice *mmcDevice)
{
(void)mmcDevice;
}

View File

@ -0,0 +1,601 @@
/*
* sdio_adapter.c
*
* 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 "device_resource_if.h"
#include "mmc_corex.h"
#include "mmc_sdio.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
#define SDIO_RESCAN_WAIT_TIME 40
struct mmc_host *GetMmcHost(int32_t slot);
void SdioRescan(int32_t slot);
enum SleepTime {
MS_10 = 10,
MS_50 = 50,
};
static struct sdio_func *LinuxSdioGetFunc(struct SdioDevice *dev)
{
if (dev == NULL) {
HDF_LOGE("LinuxSdioGetFunc: dev is null.");
return NULL;
}
return (struct sdio_func *)dev->sd.mmc.priv;
}
static int32_t LinuxSdioIncrAddrReadBytes(struct SdioDevice *dev,
uint8_t *data, uint32_t addr, uint32_t size)
{
struct sdio_func *func = LinuxSdioGetFunc(dev);
int32_t ret = HDF_SUCCESS;
uint16_t *output16 = NULL;
uint32_t *output32 = NULL;
if (func == NULL) {
HDF_LOGE("LinuxSdioIncrAddrReadBytes: func is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
if ((data == NULL) || (size == 0)) {
HDF_LOGE("LinuxSdioIncrAddrReadBytes: data or size is invalid.");
return HDF_ERR_INVALID_PARAM;
}
if (size == DATA_LEN_ONE_BYTE) {
*data = sdio_readb(func, addr, &ret);
return ret;
}
if (size == DATA_LEN_TWO_BYTES) {
output16 = (uint16_t *)data;
*output16 = sdio_readw(func, addr, &ret);
return ret;
}
if (size == DATA_LEN_FOUR_BYTES) {
output32 = (uint32_t *)data;
*output32 = sdio_readl(func, addr, &ret);
return ret;
}
return sdio_memcpy_fromio(func, data, addr, size);
}
static int32_t LinuxSdioIncrAddrWriteBytes(struct SdioDevice *dev,
uint8_t *data, uint32_t addr, uint32_t size)
{
int32_t ret = HDF_SUCCESS;
struct sdio_func *func = LinuxSdioGetFunc(dev);
if (func == NULL) {
HDF_LOGE("LinuxSdioIncrAddrWriteBytes: func is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
if ((data == NULL) || (size == 0)) {
HDF_LOGE("LinuxSdioIncrAddrWriteBytes: data or size is invalid.");
return HDF_ERR_INVALID_PARAM;
}
if (size == DATA_LEN_ONE_BYTE) {
sdio_writeb(func, *data, addr, &ret);
return ret;
}
if (size == DATA_LEN_TWO_BYTES) {
sdio_writew(func, *(uint16_t *)data, addr, &ret);
return ret;
}
if (size == DATA_LEN_FOUR_BYTES) {
sdio_writel(func, *(uint32_t *)data, addr, &ret);
return ret;
}
return sdio_memcpy_toio(func, addr, data, size);
}
static int32_t LinuxSdioFixedAddrReadBytes(struct SdioDevice *dev,
uint8_t *data, uint32_t addr, uint32_t size, uint32_t scatterLen)
{
struct sdio_func *func = LinuxSdioGetFunc(dev);
if (func == NULL) {
HDF_LOGE("LinuxSdioFixedAddrReadBytes: func is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
if ((data == NULL) || (size == 0)) {
HDF_LOGE("LinuxSdioFixedAddrReadBytes: data or size is invalid.");
return HDF_ERR_INVALID_PARAM;
}
if (scatterLen > 0) {
HDF_LOGE("LinuxSdioFixedAddrReadBytes: not support!");
return HDF_ERR_NOT_SUPPORT;
}
return sdio_readsb(func, data, addr, size);
}
static int32_t LinuxSdioFixedAddrWriteBytes(struct SdioDevice *dev,
uint8_t *data, uint32_t addr, uint32_t size, uint32_t scatterLen)
{
struct sdio_func *func = LinuxSdioGetFunc(dev);
if (func == NULL) {
HDF_LOGE("LinuxSdioFixedAddrWriteBytes: func is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
if ((data == NULL) || (size == 0)) {
HDF_LOGE("LinuxSdioFixedAddrReadBytes: data or size is invalid.");
return HDF_ERR_INVALID_PARAM;
}
if (scatterLen > 0) {
HDF_LOGE("LinuxSdioFixedAddrWriteBytes: not support!");
return HDF_ERR_NOT_SUPPORT;
}
return sdio_writesb(func, addr, data, size);
}
static int32_t LinuxSdioFunc0ReadBytes(struct SdioDevice *dev,
uint8_t *data, uint32_t addr, uint32_t size)
{
int32_t ret = HDF_SUCCESS;
struct sdio_func *func = LinuxSdioGetFunc(dev);
if (func == NULL) {
HDF_LOGE("LinuxSdioFunc0ReadBytes: func is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
if ((data == NULL) || (size == 0)) {
HDF_LOGE("LinuxSdioFunc0ReadBytes: data or size is invalid.");
return HDF_ERR_INVALID_PARAM;
}
*data = sdio_f0_readb(func, addr, &ret);
return ret;
}
static int32_t LinuxSdioFunc0WriteBytes(struct SdioDevice *dev,
uint8_t *data, uint32_t addr, uint32_t size)
{
int32_t ret = HDF_SUCCESS;
struct sdio_func *func = LinuxSdioGetFunc(dev);
if (func == NULL) {
HDF_LOGE("LinuxSdioFunc0WriteBytes: func is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
if ((data == NULL) || (size == 0)) {
HDF_LOGE("LinuxSdioFunc0WriteBytes: data or size is invalid.");
return HDF_ERR_INVALID_PARAM;
}
sdio_f0_writeb(func, *data, addr, &ret);
return ret;
}
static int32_t LinuxSdioSetBlockSize(struct SdioDevice *dev, uint32_t blockSize)
{
struct sdio_func *func = LinuxSdioGetFunc(dev);
if (func == NULL) {
HDF_LOGE("LinuxSdioSetBlockSize, func is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
return sdio_set_block_size(func, blockSize);
}
static int32_t LinuxSdioGetCommonInfo(struct SdioDevice *dev,
SdioCommonInfo *info, uint32_t infoType)
{
struct sdio_func *func = LinuxSdioGetFunc(dev);
if (func == NULL) {
HDF_LOGE("LinuxSdioGetCommonInfo: func is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
if (info == NULL) {
HDF_LOGE("LinuxSdioGetCommonInfo: info is null.");
return HDF_ERR_INVALID_PARAM;
}
if (infoType != SDIO_FUNC_INFO) {
HDF_LOGE("LinuxSdioGetCommonInfo: cur type %u is not support.", infoType);
return HDF_ERR_NOT_SUPPORT;
}
if (func->card == NULL) {
HDF_LOGE("LinuxSdioGetCommonInfo fail, card is null.");
return HDF_ERR_INVALID_PARAM;
}
if (func->card->host == NULL) {
HDF_LOGE("LinuxSdioGetCommonInfo 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;
return HDF_SUCCESS;
}
static int32_t LinuxSdioSetCommonInfo(struct SdioDevice *dev,
SdioCommonInfo *info, uint32_t infoType)
{
struct sdio_func *func = LinuxSdioGetFunc(dev);
if (func == NULL) {
HDF_LOGE("LinuxSdioSetCommonInfo: func is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
if (info == NULL) {
HDF_LOGE("LinuxSdioSetCommonInfo: info is null.");
return HDF_ERR_INVALID_PARAM;
}
if (infoType != SDIO_FUNC_INFO) {
HDF_LOGE("LinuxSdioSetCommonInfo: cur type %u is not support.", infoType);
return HDF_ERR_NOT_SUPPORT;
}
if (func->card == NULL) {
HDF_LOGE("LinuxSdioSetCommonInfo fail, card is null.");
return HDF_ERR_INVALID_PARAM;
}
if (func->card->host == NULL) {
HDF_LOGE("LinuxSdioSetCommonInfo 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;
return HDF_SUCCESS;
}
static int32_t LinuxSdioFlushData(struct SdioDevice *dev)
{
struct sdio_func *func = LinuxSdioGetFunc(dev);
if (func == NULL) {
HDF_LOGE("LinuxSdioFlushData: func is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
if (func->card == NULL) {
HDF_LOGE("LinuxSdioFlushData: card is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
return mmc_sw_reset(func->card->host);
}
static int32_t LinuxSdioClaimHost(struct SdioDevice *dev)
{
struct sdio_func *func = LinuxSdioGetFunc(dev);
if (func == NULL) {
HDF_LOGE("LinuxSdioClaimHost: func is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
sdio_claim_host(func);
return HDF_SUCCESS;
}
static int32_t LinuxSdioReleaseHost(struct SdioDevice *dev)
{
struct sdio_func *func = LinuxSdioGetFunc(dev);
if (func == NULL) {
HDF_LOGE("LinuxSdioReleaseHost: func is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
sdio_release_host(func);
return HDF_SUCCESS;
}
static int32_t LinuxSdioEnableFunc(struct SdioDevice *dev)
{
struct sdio_func *func = LinuxSdioGetFunc(dev);
if (func == NULL) {
HDF_LOGE("LinuxSdioEnableFunc: func is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
return sdio_enable_func(func);
}
static int32_t LinuxSdioDisableFunc(struct SdioDevice *dev)
{
struct sdio_func *func = LinuxSdioGetFunc(dev);
if (func == NULL) {
HDF_LOGE("LinuxSdioDisableFunc: func is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
return sdio_disable_func(func);
}
static int32_t LinuxSdioClaimIrq(struct SdioDevice *dev, SdioIrqHandler *handler)
{
struct sdio_func *func = LinuxSdioGetFunc(dev);
if (func == NULL) {
HDF_LOGE("LinuxSdioClaimIrq: func is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
if (handler == NULL) {
HDF_LOGE("LinuxSdioClaimIrq: handler is null.");
return HDF_ERR_INVALID_PARAM;
}
return sdio_claim_irq(func, (sdio_irq_handler_t *)handler);
}
static int32_t LinuxSdioReleaseIrq(struct SdioDevice *dev)
{
struct sdio_func *func = LinuxSdioGetFunc(dev);
if (func == NULL) {
HDF_LOGE("LinuxSdioReleaseIrq: func is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
return sdio_release_irq(func);
}
static struct sdio_func *LinuxSdioSearchFunc(uint32_t funcNum, uint16_t vendorId, uint16_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 = GetMmcHost(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)) {
HDF_LOGD("LinuxSdioSearchFunc: find func!");
return func;
}
}
}
HDF_LOGE("LinuxSdioSearchFunc: get sdio func fail!");
return NULL;
}
static int32_t LinuxSdioFindFunc(struct SdioDevice *dev, struct SdioFunctionConfig *configData)
{
if (dev == NULL || configData == NULL) {
HDF_LOGE("LinuxSdioFindFunc: dev or configData is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
dev->sd.mmc.priv = LinuxSdioSearchFunc(configData->funcNr, configData->vendorId, configData->deviceId);
if (dev->sd.mmc.priv == NULL) {
HDF_LOGE("LinuxSdioFindFunc: LinuxSdioSearchFunc fail.");
return HDF_ERR_NOT_SUPPORT;
}
return HDF_SUCCESS;
}
static struct SdioDeviceOps g_sdioDeviceOps = {
.incrAddrReadBytes = LinuxSdioIncrAddrReadBytes,
.incrAddrWriteBytes = LinuxSdioIncrAddrWriteBytes,
.fixedAddrReadBytes = LinuxSdioFixedAddrReadBytes,
.fixedAddrWriteBytes = LinuxSdioFixedAddrWriteBytes,
.func0ReadBytes = LinuxSdioFunc0ReadBytes,
.func0WriteBytes = LinuxSdioFunc0WriteBytes,
.setBlockSize = LinuxSdioSetBlockSize,
.getCommonInfo = LinuxSdioGetCommonInfo,
.setCommonInfo = LinuxSdioSetCommonInfo,
.flushData = LinuxSdioFlushData,
.enableFunc = LinuxSdioEnableFunc,
.disableFunc = LinuxSdioDisableFunc,
.claimIrq = LinuxSdioClaimIrq,
.releaseIrq = LinuxSdioReleaseIrq,
.findFunc = LinuxSdioFindFunc,
.claimHost = LinuxSdioClaimHost,
.releaseHost = LinuxSdioReleaseHost,
};
static bool LinuxSdioRescanFinish(struct MmcCntlr *cntlr)
{
struct mmc_host *host = NULL;
struct mmc_card *card = NULL;
host = GetMmcHost(cntlr->index);
if (host == NULL) {
return false;
}
card = host->card;
if (card == NULL) {
return false;
}
if (card->sdio_funcs > 0) {
return true;
}
return false;
}
static int32_t LinuxSdioRescan(struct MmcCntlr *cntlr)
{
bool rescanFinish = false;
uint32_t count = 0;
if (cntlr == NULL) {
HDF_LOGE("LinuxSdioRescan: cntlr is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
SdioRescan(cntlr->index);
while (rescanFinish == false && count < SDIO_RESCAN_WAIT_TIME) {
OsalMSleep(MS_50);
count++;
rescanFinish = LinuxSdioRescanFinish(cntlr);
}
if (rescanFinish == false) {
HDF_LOGE("LinuxSdioRescan: fail!");
return HDF_FAILURE;
}
OsalMSleep(MS_10);
return HDF_SUCCESS;
}
struct MmcCntlrOps g_sdioCntlrOps = {
.rescanSdioDev = LinuxSdioRescan,
};
static void LinuxSdioDeleteCntlr(struct MmcCntlr *cntlr)
{
if (cntlr == NULL) {
return;
}
if (cntlr->curDev != NULL) {
MmcDeviceRemove(cntlr->curDev);
OsalMemFree(cntlr->curDev);
}
MmcCntlrRemove(cntlr);
OsalMemFree(cntlr);
}
static int32_t LinuxSdioCntlrParse(struct MmcCntlr *cntlr, struct HdfDeviceObject *obj)
{
const struct DeviceResourceNode *node = NULL;
struct DeviceResourceIface *drsOps = NULL;
int32_t ret;
if (obj == NULL || cntlr == NULL) {
HDF_LOGE("LinuxSdioCntlrParse: input para is NULL.");
return HDF_FAILURE;
}
node = obj->property;
if (node == NULL) {
HDF_LOGE("LinuxSdioCntlrParse: drs node is NULL.");
return HDF_FAILURE;
}
drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
if (drsOps == NULL || drsOps->GetUint16 == NULL || drsOps->GetUint32 == NULL) {
HDF_LOGE("LinuxSdioCntlrParse: invalid drs ops fail!");
return HDF_FAILURE;
}
ret = drsOps->GetUint16(node, "hostId", &(cntlr->index), 0);
if (ret != HDF_SUCCESS) {
HDF_LOGE("LinuxSdioCntlrParse: read hostIndex fail!");
return ret;
}
ret = drsOps->GetUint32(node, "devType", &(cntlr->devType), 0);
if (ret != HDF_SUCCESS) {
HDF_LOGE("LinuxSdioCntlrParse: read devType fail!");
return ret;
}
HDF_LOGD("LinuxSdioCntlrParse: hostIndex = %d, devType = %d.", cntlr->index, cntlr->devType);
return HDF_SUCCESS;
}
static int32_t LinuxSdioBind(struct HdfDeviceObject *obj)
{
struct MmcCntlr *cntlr = NULL;
int32_t ret;
if (obj == NULL) {
HDF_LOGE("LinuxSdioBind: Fail, obj is NULL.");
return HDF_ERR_INVALID_OBJECT;
}
cntlr = (struct MmcCntlr *)OsalMemCalloc(sizeof(struct MmcCntlr));
if (cntlr == NULL) {
HDF_LOGE("LinuxSdioBind: no mem for MmcCntlr.");
return HDF_ERR_MALLOC_FAIL;
}
cntlr->ops = &g_sdioCntlrOps;
cntlr->hdfDevObj = obj;
obj->service = &cntlr->service;
/* init cntlr. */
ret = LinuxSdioCntlrParse(cntlr, obj);
if (ret != HDF_SUCCESS) {
HDF_LOGE("LinuxSdioBind: cntlr parse fail.");
goto _ERR;
}
ret = MmcCntlrAdd(cntlr, false);
if (ret != HDF_SUCCESS) {
HDF_LOGE("LinuxSdioBind: cntlr add fail.");
goto _ERR;
}
ret = MmcCntlrAllocDev(cntlr, (enum MmcDevType)cntlr->devType);
if (ret != HDF_SUCCESS) {
HDF_LOGE("LinuxSdioBind: alloc dev fail.");
goto _ERR;
}
MmcDeviceAddOps(cntlr->curDev, &g_sdioDeviceOps);
HDF_LOGD("LinuxSdioBind: Success!");
return HDF_SUCCESS;
_ERR:
LinuxSdioDeleteCntlr(cntlr);
HDF_LOGE("LinuxSdioBind: Fail!");
return HDF_FAILURE;
}
static int32_t LinuxSdioInit(struct HdfDeviceObject *obj)
{
(void)obj;
HDF_LOGD("LinuxSdioInit: Success!");
return HDF_SUCCESS;
}
static void LinuxSdioRelease(struct HdfDeviceObject *obj)
{
if (obj == NULL) {
return;
}
LinuxSdioDeleteCntlr((struct MmcCntlr *)obj->service);
}
struct HdfDriverEntry g_sdioDriverEntry = {
.moduleVersion = 1,
.Bind = LinuxSdioBind,
.Init = LinuxSdioInit,
.Release = LinuxSdioRelease,
.moduleName = "HDF_PLATFORM_SDIO",
};
HDF_INIT(g_sdioDriverEntry);

View File

@ -0,0 +1,38 @@
/*
* hi35xx_mmc_adapter.c
*
* hi35xx linux mmc driver implement.
*
* Copyright (c) 2022 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/host.h>
#include "hdf_base.h"
#include "hdf_log.h"
#define HDF_LOG_TAG hi35xx_mmc_adapter_c
struct mmc_host *himci_get_mmc_host(int32_t slot);
void hisi_sdio_rescan(int slot);
struct mmc_host *GetMmcHost(int32_t slot)
{
HDF_LOGD("hi35xx GetMmcHost entry");
return himci_get_mmc_host(slot);
}
void SdioRescan(int slot)
{
HDF_LOGD("hi35xx SdioRescan entry");
hisi_sdio_rescan(slot);
}

View File

@ -0,0 +1,6 @@
config DRIVERS_HDF_USB_F_GENERIC
bool "Enable F_GENERIC driver"
default n
depends on DRIVERS_HDF
help
Answer Y to choice HDF USB F_GENERIC driver.

View File

@ -0,0 +1,14 @@
obj-$(CONFIG_DRIVERS_HDF_USB_F_GENERIC) += f_generic.o
ccflags-y += -lm -lc -lgcc \
-I$(srctree)/drivers/hdf/framework/include/utils \
-I$(srctree)/drivers/hdf/khdf/osal/include \
-I$(srctree)/drivers/hdf/framework/include/core \
-I$(srctree)/drivers/hdf/framework/core/common/include/host \
-I$(srctree)/drivers/hdf/framework/include \
-I$(srctree)/drivers/hdf/framework/include/osal \
-I$(srctree)/drivers/hdf/framework/include/platform \
-I$(srctree)/drivers/hdf/framework/include/config \
-I$(srctree)/bounds_checking_function/include

View File

@ -0,0 +1,38 @@
/*
* configfs.h
*
* usb configfs 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 USB__GADGET__CONFIGFS__H
#define USB__GADGET__CONFIGFS__H
#include <linux/configfs.h>
void unregister_gadget_item(struct config_item *item);
struct config_group *usb_os_desc_prepare_interf_dir(
struct config_group *parent,
int n_interf,
struct usb_os_desc **desc,
char **names,
struct module *owner);
static inline struct usb_os_desc *to_usb_os_desc(struct config_item *item)
{
return container_of(to_config_group(item), struct usb_os_desc, group);
}
#endif /* USB__GADGET__CONFIGFS__H */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,70 @@
// SPDX-License-Identifier: GPL-2.0
/*
* u_f.h
*
* Utility definitions for USB functions
*
* Copyright (c) 2013 Samsung Electronics Co., Ltd.
* http://www.samsung.com
*
* Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
*/
#ifndef __U_F_H__
#define __U_F_H__
#include <linux/usb/gadget.h>
/* Variable Length Array Macros **********************************************/
#define vla_group(groupname) size_t groupname##__next = 0
#define vla_group_size(groupname) groupname##__next
#define vla_item(groupname, type, name, n) \
size_t groupname##_##name##__offset = ({ \
size_t align_mask = __alignof__(type) - 1; \
size_t offset = (groupname##__next + align_mask) & ~align_mask;\
size_t size = (n) * sizeof(type); \
groupname##__next = offset + size; \
offset; \
})
#define vla_item_with_sz(groupname, type, name, n) \
size_t groupname##_##name##__sz = (n) * sizeof(type); \
size_t groupname##_##name##__offset = ({ \
size_t align_mask = __alignof__(type) - 1; \
size_t offset = (groupname##__next + align_mask) & ~align_mask;\
size_t size = groupname##_##name##__sz; \
groupname##__next = offset + size; \
offset; \
})
#define vla_ptr(ptr, groupname, name) \
((void *) ((char *)ptr + groupname##_##name##__offset))
struct usb_ep;
struct usb_request;
/**
* alloc_ep_req - returns a usb_request allocated by the gadget driver and
* allocates the request's buffer.
*
* @ep: the endpoint to allocate a usb_request
* @len: usb_requests's buffer suggested size
*
* In case @ep direction is OUT, the @len will be aligned to ep's
* wMaxPacketSize. In order to avoid memory leaks or drops, *always* use
* usb_requests's length (req->length) to refer to the allocated buffer size.
* Requests allocated via alloc_ep_req() *must* be freed by free_ep_req().
*/
struct usb_request *alloc_ep_req(struct usb_ep *ep, size_t len);
/* Frees a usb_request previously allocated by alloc_ep_req() */
static inline void free_ep_req(struct usb_ep *ep, struct usb_request *req)
{
WARN_ON(req->buf == NULL);
kfree(req->buf);
req->buf = NULL;
usb_ep_free_request(ep, req);
}
#endif /* __U_F_H__ */

View File

@ -0,0 +1,356 @@
// SPDX-License-Identifier: GPL-2.0
/*
* u_fs.h
*
* Utility definitions for the FunctionFS
*
* Copyright (c) 2013 Samsung Electronics Co., Ltd.
* http://www.samsung.com
*
* Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
*/
#ifndef U_GENERIC_H
#define U_GENERIC_H
#include <linux/usb/composite.h>
#include <linux/list.h>
#include <linux/mutex.h>
#include <linux/workqueue.h>
#include <linux/refcount.h>
#include <linux/cdev.h>
#ifdef VERBOSE_DEBUG
#ifndef pr_vdebug
# define pr_vdebug pr_debug
#endif /* pr_vdebug */
# define ffs_dump_mem(prefix, ptr, len) \
print_hex_dump_bytes(pr_fmt(prefix ": "), DUMP_PREFIX_NONE, ptr, len)
#else
#ifndef pr_vdebug
# define pr_vdebug(...) do { } while (0)
#endif /* pr_vdebug */
# define ffs_dump_mem(prefix, ptr, len) do { } while (0)
#endif /* VERBOSE_DEBUG */
#define ENTER() pr_vdebug("%s()\n", __func__)
#define MAX_REQUEST 64
#define MAX_NAMELEN 64
#define FUNCTION_GENERIC "f_generic"
struct FuncNew {
uint32_t nameLen;
char name[MAX_NAMELEN];
};
struct IoData {
uint32_t aio;
uint32_t read;
uint32_t len;
uint32_t timeout;
uint64_t buf;
};
struct UsbFnReqEvent {
uint64_t buf;
uint32_t actual;
int status;
};
struct ffs_memory{
uint64_t mem;
uint64_t vm_start;
uint32_t size;
struct list_head memlist;
};
struct generic_memory{
uint32_t size;
uint64_t buf;
};
#define FUNCTIONFS_NEWFN _IOW('g', 60, struct FuncNew)
#define FUNCTIONFS_DELFN _IOW('g', 61, struct FuncNew)
#define FUNCTIONFS_ENDPOINT_GET_REQ_STATUS _IOW('g', 48, struct IoData)
#define FUNCTIONFS_ENDPOINT_WRITE _IOW('g', 49, struct IoData)
#define FUNCTIONFS_ENDPOINT_READ _IOW('g', 50, struct IoData)
#define FUNCTIONFS_ENDPOINT_RW_CANCEL _IOW('g', 51, struct IoData)
#define FUNCTIONFS_ENDPOINT_QUEUE_INIT _IO('g', 52)
#define FUNCTIONFS_ENDPOINT_QUEUE_DEL _IO('g', 53)
#define FUNCTIONFS_ENDPOINT_RELEASE_BUF _IOR('g', 54, struct generic_memory)
#define FUNCTIONFS_ENDPOINT_GET_EP0_EVENT _IOR('g', 56, struct UsbFnReqEvent)
struct f_fs_opts;
struct ffs_dev {
struct ffs_data *ffs_data;
struct f_fs_opts *opts;
struct list_head entry;
char name[MAX_NAMELEN];
bool mounted;
bool desc_ready;
bool single;
int (*ffs_ready_callback)(struct ffs_data *ffs);
void (*ffs_closed_callback)(struct ffs_data *ffs);
void *(*ffs_acquire_dev_callback)(struct ffs_dev *dev);
void (*ffs_release_dev_callback)(struct ffs_dev *dev);
};
extern struct mutex ffs_lock_adapter;
static inline void ffs_dev_lock(void)
{
mutex_lock(&ffs_lock_adapter);
}
static inline void ffs_dev_unlock(void)
{
mutex_unlock(&ffs_lock_adapter);
}
int ffs_name_dev_adapter(struct ffs_dev *dev, const char *name);
int ffs_single_dev_adapter(struct ffs_dev *dev);
struct ffs_epfile;
struct ffs_function;
enum ffs_state {
/*
* Waiting for descriptors and strings.
*
* In this state no open(2), read(2) or write(2) on epfiles
* may succeed (which should not be the problem as there
* should be no such files opened in the first place).
*/
FFS_READ_DESCRIPTORS,
FFS_READ_STRINGS,
/*
* We've got descriptors and strings. We are or have called
* functionfs_ready_callback(). functionfs_bind() may have
* been called but we don't know.
*
* This is the only state in which operations on epfiles may
* succeed.
*/
FFS_ACTIVE,
/*
* Function is visible to host, but it's not functional. All
* setup requests are stalled and transfers on another endpoints
* are refused. All epfiles, except ep0, are deleted so there
* is no way to perform any operations on them.
*
* This state is set after closing all functionfs files, when
* mount parameter "no_disconnect=1" has been set. Function will
* remain in deactivated state until filesystem is umounted or
* ep0 is opened again. In the second case functionfs state will
* be reset, and it will be ready for descriptors and strings
* writing.
*
* This is useful only when functionfs is composed to gadget
* with another function which can perform some critical
* operations, and it's strongly desired to have this operations
* completed, even after functionfs files closure.
*/
FFS_DEACTIVATED,
/*
* All endpoints have been closed. This state is also set if
* we encounter an unrecoverable error. The only
* unrecoverable error is situation when after reading strings
* from user space we fail to initialise epfiles or
* functionfs_ready_callback() returns with error (<0).
*
* In this state no open(2), read(2) or write(2) (both on ep0
* as well as epfile) may succeed (at this point epfiles are
* unlinked and all closed so this is not a problem; ep0 is
* also closed but ep0 file exists and so open(2) on ep0 must
* fail).
*/
FFS_CLOSING
};
enum ffs_setup_state {
/* There is no setup request pending. */
FFS_NO_SETUP,
/*
* User has read events and there was a setup request event
* there. The next read/write on ep0 will handle the
* request.
*/
FFS_SETUP_PENDING,
/*
* There was event pending but before user space handled it
* some other event was introduced which canceled existing
* setup. If this state is set read/write on ep0 return
* -EIDRM. This state is only set when adding event.
*/
FFS_SETUP_CANCELLED
};
struct ffs_data {
struct usb_gadget *gadget;
struct list_head entry;
struct list_head memory_list;
/*
* Protect access read/write operations, only one read/write
* at a time. As a consequence protects ep0req and company.
* While setup request is being processed (queued) this is
* held.
*/
struct mutex mutex;
/*
* Protect access to endpoint related structures (basically
* usb_ep_queue(), usb_ep_dequeue(), etc. calls) except for
* endpoint zero.
*/
spinlock_t eps_lock;
spinlock_t mem_lock;
/*
* XXX REVISIT do we need our own request? Since we are not
* handling setup requests immediately user space may be so
* slow that another setup will be sent to the gadget but this
* time not to us but another function and then there could be
* a race. Is that the case? Or maybe we can use cdev->req
* after all, maybe we just need some spinlock for that?
*/
struct usb_request *ep0req; /* P: mutex */
struct completion ep0req_completion; /* P: mutex */
/* reference counter */
refcount_t ref;
/* how many files are opened (EP0 and others) */
atomic_t opened;
/* EP0 state */
enum ffs_state state;
/*
* Possible transitions:
* + FFS_NO_SETUP -> FFS_SETUP_PENDING -- P: ev.waitq.lock
* happens only in ep0 read which is P: mutex
* + FFS_SETUP_PENDING -> FFS_NO_SETUP -- P: ev.waitq.lock
* happens only in ep0 i/o which is P: mutex
* + FFS_SETUP_PENDING -> FFS_SETUP_CANCELLED -- P: ev.waitq.lock
* + FFS_SETUP_CANCELLED -> FFS_NO_SETUP -- cmpxchg
*
* This field should never be accessed directly and instead
* ffs_setup_state_clear_cancelled function should be used.
*/
enum ffs_setup_state setup_state;
/* Events & such. */
struct {
u8 types[4];
unsigned short count;
/* XXX REVISIT need to update it in some places, or do we? */
unsigned short can_stall;
struct usb_ctrlrequest setup;
wait_queue_head_t waitq;
} ev; /* the whole structure, P: ev.waitq.lock */
/* Flags */
unsigned long flags;
#define FFS_FL_CALL_CLOSED_CALLBACK 0
#define FFS_FL_BOUND 1
/* For waking up blocked threads when function is enabled. */
wait_queue_head_t wait;
/* Active function */
struct ffs_function *func;
char dev_name[MAX_NAMELEN];
struct cdev cdev;
dev_t devno;
struct device *fn_device;
struct kfifo reqEventFifo;
wait_queue_head_t wait_que;
/* Private data for our user (ie. gadget). Managed by user. */
void *private_data;
/* filled by __ffs_data_got_descs() */
/*
* raw_descs is what you kfree, real_descs points inside of raw_descs,
* where full speed, high speed and super speed descriptors start.
* real_descs_length is the length of all those descriptors.
*/
const void *raw_descs_data;
const void *raw_descs;
unsigned raw_descs_length;
unsigned fs_descs_count;
unsigned hs_descs_count;
unsigned ss_descs_count;
unsigned ms_os_descs_count;
unsigned ms_os_descs_ext_prop_count;
unsigned ms_os_descs_ext_prop_name_len;
unsigned ms_os_descs_ext_prop_data_len;
void *ms_os_descs_ext_prop_avail;
void *ms_os_descs_ext_prop_name_avail;
void *ms_os_descs_ext_prop_data_avail;
unsigned user_flags;
#define FFS_MAX_EPS_COUNT 31
u8 eps_addrmap[FFS_MAX_EPS_COUNT];
unsigned short strings_count;
unsigned short interfaces_count;
unsigned short eps_count;
unsigned short _pad1;
/* filled by __ffs_data_got_strings() */
/* ids in stringtabs are set in functionfs_bind() */
const void *raw_strings;
struct usb_gadget_strings **stringtabs;
/*
* File system's super block, write once when file system is
* mounted.
*/
struct super_block *sb;
/* File permissions, written once when fs is mounted */
struct ffs_file_perms {
umode_t mode;
kuid_t uid;
kgid_t gid;
} file_perms;
struct eventfd_ctx *ffs_eventfd;
struct workqueue_struct *io_completion_wq;
bool no_disconnect;
struct work_struct reset_work;
/*
* The endpoint files, filled by ffs_epfiles_create(),
* destroyed by ffs_epfiles_destroy().
*/
struct ffs_epfile *epfiles;
struct ffs_ep *eps;
enum usb_device_speed speed;
};
struct f_fs_opts {
struct usb_function_instance func_inst;
struct ffs_dev *dev;
unsigned refcnt;
bool no_configfs;
};
static inline struct f_fs_opts *to_f_fs_opts(struct usb_function_instance *fi)
{
return container_of(fi, struct f_fs_opts, func_inst);
}
#endif /* U_GENERIC_H */

View File

@ -0,0 +1,121 @@
// SPDX-License-Identifier: GPL-2.0
/*
* u_os_desc.h
*
* Utility definitions for "OS Descriptors" support
*
* Copyright (c) 2014 Samsung Electronics Co., Ltd.
* http://www.samsung.com
*
* Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
*/
#ifndef __U_OS_DESC_H__
#define __U_OS_DESC_H__
#include <asm/unaligned.h>
#include <linux/nls.h>
#include "securec.h"
#include "hdf_log.h"
#define USB_EXT_PROP_DW_SIZE 0
#define USB_EXT_PROP_DW_PROPERTY_DATA_TYPE 4
#define USB_EXT_PROP_W_PROPERTY_NAME_LENGTH 8
#define USB_EXT_PROP_B_PROPERTY_NAME 10
#define USB_EXT_PROP_DW_PROPERTY_DATA_LENGTH 10
#define USB_EXT_PROP_B_PROPERTY_DATA 14
#define USB_EXT_PROP_RESERVED 0
#define USB_EXT_PROP_UNICODE 1
#define USB_EXT_PROP_UNICODE_ENV 2
#define USB_EXT_PROP_BINARY 3
#define USB_EXT_PROP_LE32 4
#define USB_EXT_PROP_BE32 5
#define USB_EXT_PROP_UNICODE_LINK 6
#define USB_EXT_PROP_UNICODE_MULTI 7
static inline u8 *__usb_ext_prop_ptr(u8 *buf, size_t offset)
{
return buf + offset;
}
static inline u8 *usb_ext_prop_size_ptr(u8 *buf)
{
return __usb_ext_prop_ptr(buf, USB_EXT_PROP_DW_SIZE);
}
static inline u8 *usb_ext_prop_type_ptr(u8 *buf)
{
return __usb_ext_prop_ptr(buf, USB_EXT_PROP_DW_PROPERTY_DATA_TYPE);
}
static inline u8 *usb_ext_prop_name_len_ptr(u8 *buf)
{
return __usb_ext_prop_ptr(buf, USB_EXT_PROP_W_PROPERTY_NAME_LENGTH);
}
static inline u8 *usb_ext_prop_name_ptr(u8 *buf)
{
return __usb_ext_prop_ptr(buf, USB_EXT_PROP_B_PROPERTY_NAME);
}
static inline u8 *usb_ext_prop_data_len_ptr(u8 *buf, size_t off)
{
return __usb_ext_prop_ptr(buf, USB_EXT_PROP_DW_PROPERTY_DATA_LENGTH + off);
}
static inline u8 *usb_ext_prop_data_ptr(u8 *buf, size_t off)
{
return __usb_ext_prop_ptr(buf, USB_EXT_PROP_B_PROPERTY_DATA + off);
}
static inline void usb_ext_prop_put_size(u8 *buf, int dw_size)
{
put_unaligned_le32(dw_size, usb_ext_prop_size_ptr(buf));
}
static inline void usb_ext_prop_put_type(u8 *buf, int type)
{
put_unaligned_le32(type, usb_ext_prop_type_ptr(buf));
}
static inline int usb_ext_prop_put_name(u8 *buf, const char *name, int pnl)
{
int result;
put_unaligned_le16(pnl, usb_ext_prop_name_len_ptr(buf));
result = utf8s_to_utf16s(name, strlen(name), UTF16_LITTLE_ENDIAN,
(wchar_t *) usb_ext_prop_name_ptr(buf), pnl - 2);
if (result < 0)
return result;
put_unaligned_le16(0, &buf[USB_EXT_PROP_B_PROPERTY_NAME + pnl - 2]);
return pnl;
}
static inline void usb_ext_prop_put_binary(u8 *buf, int pnl, const u8 *data, int data_len)
{
int32_t ret;
put_unaligned_le32(data_len, usb_ext_prop_data_len_ptr(buf, pnl));
ret = memcpy_s(usb_ext_prop_data_ptr(buf, pnl), data_len, data, data_len);
if (ret != EOK) {
HDF_LOGE("%{public}s: %{public}d memset_s failed", __func__, __LINE__);
}
}
static inline int usb_ext_prop_put_unicode(u8 *buf, int pnl, const char *string, int data_len)
{
int result;
put_unaligned_le32(data_len, usb_ext_prop_data_len_ptr(buf, pnl));
result = utf8s_to_utf16s(string, data_len >> 1, UTF16_LITTLE_ENDIAN,
(wchar_t *) usb_ext_prop_data_ptr(buf, pnl), data_len - 2);
if (result < 0)
return result;
put_unaligned_le16(0, &buf[USB_EXT_PROP_B_PROPERTY_DATA + pnl + data_len - 2]);
return data_len;
}
#endif /* __U_OS_DESC_H__ */

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_USB_PNP_NOTIFY
bool "Enable HDF USB PNP Notify driver"
default n
depends on DRIVERS_HDF
help
Answer Y to choice HDF USB PNP Notify driver.

View File

@ -0,0 +1,28 @@
# 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.
USB_PNP_NOTIFY_ROOT_DIR = ./
obj-$(CONFIG_DRIVERS_HDF_USB_PNP_NOTIFY) += \
$(USB_PNP_NOTIFY_ROOT_DIR)/src/usb_pnp_notify.o
ccflags-y += -lm -lc -lgcc \
-I$(srctree)/drivers/hdf/khdf/model/usb/host/include \
-I$(srctree)/drivers/hdf/framework/include/utils \
-I$(srctree)/drivers/hdf/framework/utils/include \
-I$(srctree)/drivers/hdf/khdf/osal/include \
-I$(srctree)/drivers/hdf/framework/include/core \
-I$(srctree)/drivers/hdf/framework/core/common/include/host \
-I$(srctree)/drivers/hdf/framework/core/shared/include \
-I$(srctree)/drivers/hdf/framework/include \
-I$(srctree)/drivers/hdf/framework/include/osal \
-I$(srctree)/drivers/hdf/framework/include/platform \
-I$(srctree)/drivers/hdf/framework/include/config \
-I$(srctree)/bounds_checking_function/include

View File

@ -0,0 +1,84 @@
/*
* usb_pnp_notify.h
*
* usb pnp notify 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 USB_PNP_NOTIFY_H
#define USB_PNP_NOTIFY_H
#include "hdf_base.h"
#include "hdf_dlist.h"
#include "hdf_usb_pnp_manage.h"
#include "osal_mutex.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif /* __cplusplus */
#define USB_PNP_NOTIFY_MSLEEP_TIME (10)
#ifndef INT32_MAX
#define INT32_MAX 0x7fffffff
#endif
typedef enum {
USB_INFO_NORMAL_TYPE,
USB_INFO_ID_TYPE,
USB_INFO_DEVICE_ADDRESS_TYPE,
} UsbInfoQueryParaType;
typedef enum {
USB_PNP_DEVICE_INIT_STATUS,
USB_PNP_DEVICE_ADD_STATUS,
USB_PNP_DEVICE_REMOVE_STATUS,
USB_PNP_DEVICE_INTERFACE_STATUS,
} UsbPnpDeviceStatus;
struct UsbPnpDeviceInfo {
int32_t id;
struct OsalMutex lock;
UsbPnpDeviceStatus status;
struct DListHead list;
bool interfaceRemoveStatus[USB_PNP_INFO_MAX_INTERFACES];
struct UsbPnpNotifyMatchInfoTable info;
};
struct UsbInfoQueryPara {
UsbInfoQueryParaType type;
union {
int32_t id;
uint64_t usbDevAddr;
struct {
int32_t devNum;
int32_t busNum;
};
};
};
union UsbPnpDeviceInfoData {
struct usb_device *usbDev;
struct UsbPnpAddRemoveInfo *infoData;
};
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */
#endif /* USB_PNP_NOTIFY_H */

View File

@ -0,0 +1,928 @@
/*
* usb_pnp_notify.c
*
* usb pnp notify 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 "usb_pnp_notify.h"
#include <linux/delay.h>
#include <linux/kthread.h>
#include <linux/notifier.h>
#include <linux/usb.h>
#include "hdf_device_desc.h"
#include "hdf_log.h"
#include "osal_mem.h"
#include "securec.h"
#define HDF_LOG_TAG USB_PNP_NOTIFY
#ifndef USB_GADGET_ADD
#define USB_GADGET_ADD 0x0005
#endif
#ifndef USB_GADGET_REMOVE
#define USB_GADGET_REMOVE 0x0006
#endif
static wait_queue_head_t g_usbPnpNotifyReportWait;
static wait_queue_head_t g_gadgetPnpNotifyReportWait;
static struct task_struct *g_usbPnpNotifyReportThread = NULL;
static struct task_struct *g_gadgetPnpNotifyReportThread = NULL;
static enum UsbPnpNotifyServiceCmd g_usbPnpNotifyCmdType = USB_PNP_NOTIFY_ADD_INTERFACE;
static enum UsbPnpNotifyRemoveType g_usbPnpNotifyRemoveType = USB_PNP_NOTIFY_REMOVE_BUS_DEV_NUM;
static uint8_t g_gadgetPnpNotifyType = 0;
static uint64_t g_preAcion = 0;
struct OsalMutex g_usbSendEventLock;
struct OsalMutex g_gadgetSendEventLock;
struct usb_device *g_usbDevice = NULL;
struct UsbPnpAddRemoveInfo g_usbPnpInfo;
struct DListHead g_usbPnpInfoListHead;
#if USB_PNP_NOTIFY_TEST_MODE == true
struct UsbPnpNotifyMatchInfoTable *g_testUsbPnpInfo = NULL;
#endif
static struct UsbPnpDeviceInfo *UsbPnpNotifyCreateInfo(void)
{
struct UsbPnpDeviceInfo *infoTemp = NULL;
static int32_t idNum = 1;
int32_t ret;
infoTemp = (struct UsbPnpDeviceInfo *)OsalMemCalloc(sizeof(struct UsbPnpDeviceInfo));
if (infoTemp == NULL) {
HDF_LOGE("%s:%d OsalMemAlloc failed", __func__, __LINE__);
return NULL;
}
if (idNum == INT32_MAX) {
idNum = 1;
}
infoTemp->id = idNum;
OsalMutexInit(&infoTemp->lock);
infoTemp->status = USB_PNP_DEVICE_INIT_STATUS;
DListHeadInit(&infoTemp->list);
DListInsertTail(&infoTemp->list, &g_usbPnpInfoListHead);
idNum++;
return infoTemp;
}
static struct UsbPnpDeviceInfo *UsbPnpNotifyFindInfo(struct UsbInfoQueryPara queryPara)
{
struct UsbPnpDeviceInfo *infoPos = NULL;
struct UsbPnpDeviceInfo *infoTemp = NULL;
bool findFlag = false;
if (DListIsEmpty(&g_usbPnpInfoListHead)) {
HDF_LOGE("%s:%d usb pnp list head is empty.", __func__, __LINE__);
return NULL;
}
DLIST_FOR_EACH_ENTRY_SAFE(infoPos, infoTemp, &g_usbPnpInfoListHead, struct UsbPnpDeviceInfo, list) {
switch (queryPara.type) {
case USB_INFO_NORMAL_TYPE:
if ((infoPos->info.devNum == queryPara.devNum) && (infoPos->info.busNum == queryPara.busNum)) {
findFlag = true;
}
break;
case USB_INFO_ID_TYPE:
if (infoPos->id == queryPara.id) {
findFlag = true;
}
break;
case USB_INFO_DEVICE_ADDRESS_TYPE:
if (infoPos->info.usbDevAddr == queryPara.usbDevAddr) {
findFlag = true;
}
break;
default:
break;
}
if (findFlag) {
break;
}
}
if (!findFlag) {
HDF_LOGE("%s:%d the usb pnp info to be find does not exist.", __func__, __LINE__);
return NULL;
}
return infoPos;
}
static HDF_STATUS UsbPnpNotifyDestroyInfo(struct UsbPnpDeviceInfo *deviceInfo)
{
HDF_STATUS ret = HDF_SUCCESS;
struct UsbPnpDeviceInfo *infoPos = NULL;
struct UsbPnpDeviceInfo *infoTemp = NULL;
bool findFlag = false;
if (deviceInfo == NULL) {
ret = HDF_FAILURE;
HDF_LOGE("%s:%d the deviceInfo is NULL, ret=%d ", __func__, __LINE__, ret);
return ret;
}
if (DListIsEmpty(&g_usbPnpInfoListHead)) {
HDF_LOGI("%s:%d the g_usbPnpInfoListHead is empty.", __func__, __LINE__);
return HDF_SUCCESS;
}
DLIST_FOR_EACH_ENTRY_SAFE(infoPos, infoTemp, &g_usbPnpInfoListHead, struct UsbPnpDeviceInfo, list) {
if (infoPos->id == deviceInfo->id) {
findFlag = true;
DListRemove(&infoPos->list);
OsalMemFree((void *)infoPos);
infoPos = NULL;
break;
}
}
if (!findFlag) {
ret = HDF_FAILURE;
HDF_LOGE("%s:%d the deviceInfoto be destroyed does not exist, ret=%d ", __func__, __LINE__, ret);
}
return ret;
}
static int32_t UsbPnpNotifyAddInitInfo(struct UsbPnpDeviceInfo *deviceInfo, union UsbPnpDeviceInfoData infoData)
{
int32_t ret = HDF_SUCCESS;
uint8_t i;
deviceInfo->info.usbDevAddr = (uint64_t)infoData.usbDev;
deviceInfo->info.devNum = infoData.usbDev->devnum;
if (infoData.usbDev->bus == NULL) {
HDF_LOGE("%s infoData.usbDev->bus is NULL", __func__);
ret = HDF_ERR_INVALID_PARAM;
goto OUT;
}
deviceInfo->info.busNum = infoData.usbDev->bus->busnum;
deviceInfo->info.deviceInfo.vendorId = le16_to_cpu(infoData.usbDev->descriptor.idVendor);
deviceInfo->info.deviceInfo.productId = le16_to_cpu(infoData.usbDev->descriptor.idProduct);
deviceInfo->info.deviceInfo.bcdDeviceLow = le16_to_cpu(infoData.usbDev->descriptor.bcdDevice);
deviceInfo->info.deviceInfo.bcdDeviceHigh = le16_to_cpu(infoData.usbDev->descriptor.bcdDevice);
deviceInfo->info.deviceInfo.deviceClass = infoData.usbDev->descriptor.bDeviceClass;
deviceInfo->info.deviceInfo.deviceSubClass = infoData.usbDev->descriptor.bDeviceSubClass;
deviceInfo->info.deviceInfo.deviceProtocol = infoData.usbDev->descriptor.bDeviceProtocol;
if (infoData.usbDev->actconfig == NULL) {
HDF_LOGE("%s infoData.usbDev->actconfig is NULL", __func__);
ret = HDF_ERR_INVALID_PARAM;
goto OUT;
}
deviceInfo->info.numInfos = infoData.usbDev->actconfig->desc.bNumInterfaces;
for (i = 0; i < deviceInfo->info.numInfos; i++) {
if ((infoData.usbDev->actconfig->interface[i] == NULL) ||
(infoData.usbDev->actconfig->interface[i]->cur_altsetting == NULL)) {
HDF_LOGE("%{public}s interface[%{public}hhu] or interface[%{public}hhu]->cur_altsetting is NULL",
__func__, i, i);
ret = HDF_ERR_INVALID_PARAM;
goto OUT;
}
deviceInfo->info.interfaceInfo[i].interfaceClass =
infoData.usbDev->actconfig->interface[i]->cur_altsetting->desc.bInterfaceClass;
deviceInfo->info.interfaceInfo[i].interfaceSubClass =
infoData.usbDev->actconfig->interface[i]->cur_altsetting->desc.bInterfaceSubClass;
deviceInfo->info.interfaceInfo[i].interfaceProtocol =
infoData.usbDev->actconfig->interface[i]->cur_altsetting->desc.bInterfaceProtocol;
deviceInfo->info.interfaceInfo[i].interfaceNumber =
infoData.usbDev->actconfig->interface[i]->cur_altsetting->desc.bInterfaceNumber;
HDF_LOGI("%s:%d i=%d, interfaceInfo=0x%x-0x%x-0x%x-0x%x",
__func__, __LINE__, i, deviceInfo->info.interfaceInfo[i].interfaceClass,
deviceInfo->info.interfaceInfo[i].interfaceSubClass,
deviceInfo->info.interfaceInfo[i].interfaceProtocol,
deviceInfo->info.interfaceInfo[i].interfaceNumber);
}
OUT:
return ret;
}
static void UsbPnpNotifyAddInterfaceInitInfo(struct UsbPnpDeviceInfo *deviceInfo,
union UsbPnpDeviceInfoData infoData, struct UsbPnpNotifyMatchInfoTable *infoTable)
{
uint8_t i;
uint8_t j;
for (i = 0; i < deviceInfo->info.numInfos; i++) {
if ((infoData.infoData->interfaceClass == deviceInfo->info.interfaceInfo[i].interfaceClass)
&& (infoData.infoData->interfaceSubClass == deviceInfo->info.interfaceInfo[i].interfaceSubClass)
&& (infoData.infoData->interfaceProtocol == deviceInfo->info.interfaceInfo[i].interfaceProtocol)
&& (infoData.infoData->interfaceNumber == deviceInfo->info.interfaceInfo[i].interfaceNumber)) {
if (g_usbPnpNotifyCmdType == USB_PNP_NOTIFY_REMOVE_INTERFACE) {
deviceInfo->interfaceRemoveStatus[i] = true;
} else if (g_usbPnpNotifyCmdType == USB_PNP_NOTIFY_ADD_INTERFACE) {
deviceInfo->interfaceRemoveStatus[i] = false;
}
}
}
if (g_usbPnpNotifyCmdType == USB_PNP_NOTIFY_REMOVE_INTERFACE) {
infoTable->numInfos = 1;
infoTable->interfaceInfo[0].interfaceClass = infoData.infoData->interfaceClass;
infoTable->interfaceInfo[0].interfaceSubClass = infoData.infoData->interfaceSubClass;
infoTable->interfaceInfo[0].interfaceProtocol = infoData.infoData->interfaceProtocol;
infoTable->interfaceInfo[0].interfaceNumber = infoData.infoData->interfaceNumber;
} else {
for (i = 0, j = 0; i < deviceInfo->info.numInfos; i++) {
if (deviceInfo->interfaceRemoveStatus[i] == true) {
HDF_LOGI("%s:%d j=%hhu deviceInfo->interfaceRemoveStatus[%hhu] is true!", __func__, __LINE__, j, i);
continue;
}
infoTable->interfaceInfo[j].interfaceClass = deviceInfo->info.interfaceInfo[i].interfaceClass;
infoTable->interfaceInfo[j].interfaceSubClass = deviceInfo->info.interfaceInfo[i].interfaceSubClass;
infoTable->interfaceInfo[j].interfaceProtocol = deviceInfo->info.interfaceInfo[i].interfaceProtocol;
infoTable->interfaceInfo[j].interfaceNumber = deviceInfo->info.interfaceInfo[i].interfaceNumber;
j++;
HDF_LOGI("%s:%d i=%hhu, j=%hhu, interfaceInfo=0x%x-0x%x-0x%x-0x%x",
__func__, __LINE__, i, j - 1, infoTable->interfaceInfo[j - 1].interfaceClass,
infoTable->interfaceInfo[j - 1].interfaceSubClass,
infoTable->interfaceInfo[j - 1].interfaceProtocol,
infoTable->interfaceInfo[j - 1].interfaceNumber);
}
infoTable->numInfos = j;
}
}
static int32_t UsbPnpNotifyInitInfo(
struct HdfSBuf *sbuf, struct UsbPnpDeviceInfo *deviceInfo, union UsbPnpDeviceInfoData infoData)
{
int32_t ret = HDF_SUCCESS;
const void *data = NULL;
if ((g_usbPnpNotifyCmdType == USB_PNP_NOTIFY_ADD_INTERFACE) ||
(g_usbPnpNotifyCmdType == USB_PNP_NOTIFY_REMOVE_INTERFACE)) {
static struct UsbPnpNotifyMatchInfoTable infoTable;
infoTable.usbDevAddr = deviceInfo->info.usbDevAddr;
infoTable.devNum = deviceInfo->info.devNum;
infoTable.busNum = deviceInfo->info.busNum;
infoTable.deviceInfo.vendorId = deviceInfo->info.deviceInfo.vendorId;
infoTable.deviceInfo.productId = deviceInfo->info.deviceInfo.productId;
infoTable.deviceInfo.bcdDeviceLow = deviceInfo->info.deviceInfo.bcdDeviceLow;
infoTable.deviceInfo.bcdDeviceHigh = deviceInfo->info.deviceInfo.bcdDeviceHigh;
infoTable.deviceInfo.deviceClass = deviceInfo->info.deviceInfo.deviceClass;
infoTable.deviceInfo.deviceSubClass = deviceInfo->info.deviceInfo.deviceSubClass;
infoTable.deviceInfo.deviceProtocol = deviceInfo->info.deviceInfo.deviceProtocol;
infoTable.removeType = g_usbPnpNotifyRemoveType;
UsbPnpNotifyAddInterfaceInitInfo(deviceInfo, infoData, &infoTable);
data = (const void *)(&infoTable);
} else if (g_usbPnpNotifyCmdType == USB_PNP_NOTIFY_REPORT_INTERFACE) {
ret = UsbPnpNotifyAddInitInfo(deviceInfo, infoData);
if (ret != HDF_SUCCESS) {
goto OUT;
}
data = (const void *)(&deviceInfo->info);
} else {
data = (const void *)(&deviceInfo->info);
}
if (!HdfSbufWriteBuffer(sbuf, data, sizeof(struct UsbPnpNotifyMatchInfoTable))) {
HDF_LOGE("%s:%d sbuf write data failed", __func__, __LINE__);
ret = HDF_FAILURE;
goto OUT;
}
OUT:
return ret;
}
static int32_t UsbPnpNotifyGetDeviceInfo(void *eventData, union UsbPnpDeviceInfoData *pnpInfoData,
struct UsbPnpDeviceInfo **deviceInfo)
{
struct UsbInfoQueryPara infoQueryPara;
if ((g_usbPnpNotifyCmdType == USB_PNP_NOTIFY_ADD_INTERFACE)
|| (g_usbPnpNotifyCmdType == USB_PNP_NOTIFY_REMOVE_INTERFACE)) {
pnpInfoData->infoData = (struct UsbPnpAddRemoveInfo *)eventData;
} else {
pnpInfoData->usbDev = (struct usb_device *)eventData;
}
if ((g_usbPnpNotifyCmdType == USB_PNP_NOTIFY_ADD_INTERFACE)
|| (g_usbPnpNotifyCmdType == USB_PNP_NOTIFY_REMOVE_INTERFACE)) {
infoQueryPara.type = USB_INFO_NORMAL_TYPE;
infoQueryPara.devNum = pnpInfoData->infoData->devNum;
infoQueryPara.busNum = pnpInfoData->infoData->busNum;
*deviceInfo = UsbPnpNotifyFindInfo(infoQueryPara);
} else if ((g_usbPnpNotifyCmdType == USB_PNP_NOTIFY_ADD_DEVICE)
|| (g_usbPnpNotifyCmdType == USB_PNP_NOTIFY_REMOVE_DEVICE)) {
infoQueryPara.type = USB_INFO_DEVICE_ADDRESS_TYPE;
infoQueryPara.usbDevAddr = (uint64_t)pnpInfoData->usbDev;
*deviceInfo = UsbPnpNotifyFindInfo(infoQueryPara);
} else {
*deviceInfo = UsbPnpNotifyCreateInfo();
}
if (*deviceInfo == NULL) {
HDF_LOGE("%s:%d create or find info failed", __func__, __LINE__);
return HDF_FAILURE;
}
(*deviceInfo)->info.removeType = g_usbPnpNotifyRemoveType;
return HDF_SUCCESS;
}
static int32_t UsbPnpNotifyHdfSendEvent(const struct HdfDeviceObject *deviceObject,
void *eventData)
{
int32_t ret;
struct UsbPnpDeviceInfo *deviceInfo = NULL;
struct HdfSBuf *data = NULL;
union UsbPnpDeviceInfoData pnpInfoData;
if ((deviceObject == NULL) || (eventData == NULL)) {
HDF_LOGE("%s deviceObject=%p or eventData=%p is NULL", __func__, deviceObject, eventData);
return HDF_ERR_INVALID_PARAM;
}
data = HdfSbufObtainDefaultSize();
if (data == NULL) {
HDF_LOGE("%s:%d InitDataBlock failed", __func__, __LINE__);
return HDF_FAILURE;
}
ret = UsbPnpNotifyGetDeviceInfo(eventData, &pnpInfoData, &deviceInfo);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s:%d UsbPnpNotifyGetDeviceInfo failed, ret=%d", __func__, __LINE__, ret);
goto ERROR_DEVICE_INFO;
}
ret = UsbPnpNotifyInitInfo(data, deviceInfo, pnpInfoData);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s:%d UsbPnpNotifyInitInfo failed, ret=%d", __func__, __LINE__, ret);
goto OUT;
}
HDF_LOGI("%s:%d report one device information, %d usbDevAddr=%llu, devNum=%d, busNum=%d, infoTable=%d-0x%x-0x%x!",
__func__, __LINE__, g_usbPnpNotifyCmdType, deviceInfo->info.usbDevAddr, deviceInfo->info.devNum,
deviceInfo->info.busNum, deviceInfo->info.numInfos, deviceInfo->info.deviceInfo.vendorId,
deviceInfo->info.deviceInfo.productId);
OsalMutexLock(&deviceInfo->lock);
if (deviceInfo->status == USB_PNP_DEVICE_INIT_STATUS) {
ret = HdfDeviceSendEvent(deviceObject, g_usbPnpNotifyCmdType, data);
if (ret != HDF_SUCCESS) {
OsalMutexUnlock(&deviceInfo->lock);
HDF_LOGE("%s:%d HdfDeviceSendEvent ret=%d", __func__, __LINE__, ret);
goto OUT;
}
deviceInfo->status = USB_PNP_DEVICE_ADD_STATUS;
} else {
ret = HDF_ERR_INVALID_OBJECT;
}
OsalMutexUnlock(&deviceInfo->lock);
OUT:
if ((ret != HDF_SUCCESS) || (g_usbPnpNotifyCmdType == USB_PNP_NOTIFY_REMOVE_DEVICE)) {
if (UsbPnpNotifyDestroyInfo(deviceInfo) != HDF_SUCCESS) {
HDF_LOGE("%s:%d UsbPnpNotifyDestroyInfo fail", __func__, __LINE__);
}
}
ERROR_DEVICE_INFO:
HdfSbufRecycle(data);
return ret;
}
#if USB_PNP_NOTIFY_TEST_MODE == true
static void TestReadPnpInfo(struct HdfSBuf *data)
{
uint32_t infoSize;
bool flag;
flag = HdfSbufReadBuffer(data, (const void **)(&g_testUsbPnpInfo), &infoSize);
if ((!flag) || (g_testUsbPnpInfo == NULL)) {
HDF_LOGE("%s: fail to read g_testUsbPnpInfo, flag=%d", __func__, flag);
return;
}
HDF_LOGI("%s:%d infoSize=%d read success!", __func__, __LINE__, infoSize);
}
static void TestPnpNotifyFillInfoTable(struct UsbPnpNotifyMatchInfoTable *infoTable)
{
int8_t i;
infoTable->usbDevAddr = g_testUsbPnpInfo->usbDevAddr;
infoTable->devNum = g_testUsbPnpInfo->devNum;
if (g_usbPnpNotifyCmdType == USB_PNP_NOTIFY_REMOVE_TEST) {
infoTable->busNum = -1;
} else {
infoTable->busNum = g_testUsbPnpInfo->busNum;
}
infoTable->deviceInfo.vendorId = g_testUsbPnpInfo->deviceInfo.vendorId;
infoTable->deviceInfo.productId = g_testUsbPnpInfo->deviceInfo.productId;
infoTable->deviceInfo.bcdDeviceLow = g_testUsbPnpInfo->deviceInfo.bcdDeviceLow;
infoTable->deviceInfo.bcdDeviceHigh = g_testUsbPnpInfo->deviceInfo.bcdDeviceHigh;
infoTable->deviceInfo.deviceClass = g_testUsbPnpInfo->deviceInfo.deviceClass;
infoTable->deviceInfo.deviceSubClass = g_testUsbPnpInfo->deviceInfo.deviceSubClass;
infoTable->deviceInfo.deviceProtocol = g_testUsbPnpInfo->deviceInfo.deviceProtocol;
infoTable->removeType = g_usbPnpNotifyRemoveType;
if (g_usbPnpNotifyCmdType != USB_PNP_NOTIFY_REMOVE_TEST) {
infoTable->numInfos = g_testUsbPnpInfo->numInfos;
for (i = 0; i < infoTable->numInfos; i++) {
infoTable->interfaceInfo[i].interfaceClass = g_testUsbPnpInfo->interfaceInfo[i].interfaceClass;
infoTable->interfaceInfo[i].interfaceSubClass = g_testUsbPnpInfo->interfaceInfo[i].interfaceSubClass;
infoTable->interfaceInfo[i].interfaceProtocol = g_testUsbPnpInfo->interfaceInfo[i].interfaceProtocol;
infoTable->interfaceInfo[i].interfaceNumber = g_testUsbPnpInfo->interfaceInfo[i].interfaceNumber;
}
}
}
static int32_t TestPnpNotifyHdfSendEvent(const struct HdfDeviceObject *deviceObject)
{
struct UsbPnpNotifyMatchInfoTable infoTable;
struct HdfSBuf *data = NULL;
if ((deviceObject == NULL) || (g_testUsbPnpInfo == NULL)) {
HDF_LOGE("%s deviceObject=%px or g_testUsbPnpInfo=%px is NULL", __func__, deviceObject, g_testUsbPnpInfo);
return HDF_ERR_INVALID_PARAM;
}
data = HdfSbufObtainDefaultSize();
if (data == NULL) {
HDF_LOGE("%s InitDataBlock failed", __func__);
return HDF_FAILURE;
}
TestPnpNotifyFillInfoTable(&infoTable);
if (!HdfSbufWriteBuffer(data, (const void *)(&infoTable), sizeof(struct UsbPnpNotifyMatchInfoTable))) {
HDF_LOGE("%s: sbuf write infoTable failed", __func__);
goto OUT;
}
HDF_LOGI("%s: report one device information, %d usbDev=%llu, devNum=%d, busNum=%d, infoTable=%d-0x%x-0x%x!", \
__func__, g_usbPnpNotifyCmdType, infoTable.usbDevAddr, infoTable.devNum, infoTable.busNum, \
infoTable.numInfos, infoTable.deviceInfo.vendorId, infoTable.deviceInfo.productId);
int32_t ret = HdfDeviceSendEvent(deviceObject, g_usbPnpNotifyCmdType, data);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: HdfDeviceSendEvent error=%d", __func__, ret);
goto OUT;
}
HdfSbufRecycle(data);
return ret;
OUT:
HdfSbufRecycle(data);
return HDF_FAILURE;
}
#endif
static int32_t GadgetPnpNotifyHdfSendEvent(const struct HdfDeviceObject *deviceObject)
{
if (deviceObject == NULL) {
HDF_LOGE("%s deviceObject is null", __func__);
return HDF_ERR_INVALID_PARAM;
}
struct HdfSBuf *data = NULL;
data = HdfSbufObtainDefaultSize();
if (data == NULL) {
HDF_LOGE("%s:%d InitDataBlock failed", __func__, __LINE__);
return HDF_FAILURE;
}
if (!HdfSbufWriteUint8(data, g_gadgetPnpNotifyType)) {
HDF_LOGE("%s, UsbEcmRead HdfSbufWriteInt8 error", __func__);
HdfSbufRecycle(data);
return HDF_FAILURE;
}
int32_t ret = HdfDeviceSendEvent(deviceObject, g_gadgetPnpNotifyType, data);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s:%d HdfDeviceSendEvent ret = %d", __func__, __LINE__, ret);
}
HdfSbufRecycle(data);
return ret;
}
static int32_t UsbPnpNotifyFirstReport(struct usb_device *usbDev, void *data)
{
int32_t ret;
if (data == NULL) {
HDF_LOGE("%{pubilc}s:%{pubilc}d data is NULL", __func__, __LINE__);
return HDF_FAILURE;
}
struct HdfDeviceIoClient *client = (struct HdfDeviceIoClient *)data;
ret = UsbPnpNotifyHdfSendEvent(client->device, usbDev);
HDF_LOGI("%s: report all device information!", __func__);
return ret;
}
static int32_t UsbPnpNotifyReportThread(void* arg)
{
int32_t ret;
struct HdfDeviceObject *deviceObject = (struct HdfDeviceObject *)arg;
while (!kthread_should_stop()) {
#if USB_PNP_NOTIFY_TEST_MODE == false
ret = wait_event_interruptible(g_usbPnpNotifyReportWait, g_usbDevice != NULL);
#else
ret = wait_event_interruptible(g_usbPnpNotifyReportWait,
((g_usbDevice != NULL) || (g_testUsbPnpInfo != NULL)));
#endif
if (!ret) {
HDF_LOGI("%s: UsbPnpNotifyReportThread start!", __func__);
}
OsalMutexLock(&g_usbSendEventLock);
#if USB_PNP_NOTIFY_TEST_MODE == true
if ((g_usbPnpNotifyCmdType == USB_PNP_NOTIFY_ADD_TEST) || \
(g_usbPnpNotifyCmdType == USB_PNP_NOTIFY_REMOVE_TEST)) {
ret = TestPnpNotifyHdfSendEvent(deviceObject);
} else {
#endif
if ((g_usbPnpNotifyCmdType == USB_PNP_NOTIFY_ADD_INTERFACE)
|| (g_usbPnpNotifyCmdType == USB_PNP_NOTIFY_REMOVE_INTERFACE)) {
ret = UsbPnpNotifyHdfSendEvent(deviceObject, &g_usbPnpInfo);
} else {
ret = UsbPnpNotifyHdfSendEvent(deviceObject, g_usbDevice);
}
#if USB_PNP_NOTIFY_TEST_MODE == true
}
#endif
if (ret != HDF_SUCCESS) {
HDF_LOGI("%s: UsbPnpNotifyHdfSendEvent error=%d!", __func__, ret);
}
g_usbDevice = NULL;
#if USB_PNP_NOTIFY_TEST_MODE == true
g_testUsbPnpInfo = NULL;
#endif
OsalMutexUnlock(&g_usbSendEventLock);
msleep(USB_PNP_NOTIFY_MSLEEP_TIME);
}
HDF_LOGI("%s: usb pnp notify handle kthread exiting!", __func__);
return 0;
}
static int32_t GadgetPnpNotifyReportThread(void* arg)
{
int32_t ret;
struct HdfDeviceObject *deviceObject = (struct HdfDeviceObject *)arg;
while (!kthread_should_stop()) {
ret = wait_event_interruptible(g_gadgetPnpNotifyReportWait,
(g_gadgetPnpNotifyType != 0));
if (!ret) {
HDF_LOGI("%s: GadgetPnpNotifyReportThread start!", __func__);
}
OsalMutexLock(&g_gadgetSendEventLock);
ret = GadgetPnpNotifyHdfSendEvent(deviceObject);
if (ret != HDF_SUCCESS) {
HDF_LOGI("%s: UsbPnpNotifyHdfSendEvent error=%d!", __func__, ret);
}
g_gadgetPnpNotifyType = 0;
OsalMutexUnlock(&g_gadgetSendEventLock);
msleep(USB_PNP_NOTIFY_MSLEEP_TIME);
}
HDF_LOGI("%s: gadget pnp notify handle kthread exiting!", __func__);
return 0;
}
static int32_t UsbPnpNotifyCallback(struct notifier_block *self, unsigned long action, void *dev)
{
int32_t ret;
struct UsbInfoQueryPara infoQueryPara;
struct UsbPnpDeviceInfo *deviceInfo = NULL;
union UsbPnpDeviceInfoData pnpInfoData;
HDF_LOGI("%s: action=0x%lx", __func__, action);
switch (action) {
case USB_DEVICE_ADD:
pnpInfoData.usbDev = dev;
deviceInfo = UsbPnpNotifyCreateInfo();
if (deviceInfo == NULL) {
HDF_LOGE("%s:%d USB_DEVICE_ADD create info failed", __func__, __LINE__);
} else {
ret = UsbPnpNotifyAddInitInfo(deviceInfo, pnpInfoData);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s:%d USB_DEVICE_ADD UsbPnpNotifyAddInitInfo error", __func__, __LINE__);
} else {
OsalMutexLock(&g_usbSendEventLock);
g_usbDevice = dev;
g_usbPnpNotifyCmdType = USB_PNP_NOTIFY_ADD_DEVICE;
OsalMutexUnlock(&g_usbSendEventLock);
wake_up_interruptible(&g_usbPnpNotifyReportWait);
}
}
break;
case USB_DEVICE_REMOVE:
infoQueryPara.type = USB_INFO_DEVICE_ADDRESS_TYPE;
infoQueryPara.usbDevAddr = (uint64_t)dev;
deviceInfo = UsbPnpNotifyFindInfo(infoQueryPara);
if (deviceInfo == NULL) {
HDF_LOGE("%s:%d USB_DEVICE_REMOVE find info failed", __func__, __LINE__);
} else {
OsalMutexLock(&deviceInfo->lock);
if (deviceInfo->status != USB_PNP_DEVICE_INIT_STATUS) {
deviceInfo->status = USB_PNP_DEVICE_INIT_STATUS;
} else {
deviceInfo->status = USB_PNP_DEVICE_REMOVE_STATUS;
}
OsalMutexUnlock(&deviceInfo->lock);
OsalMutexLock(&g_usbSendEventLock);
g_usbDevice = dev;
g_usbPnpNotifyCmdType = USB_PNP_NOTIFY_REMOVE_DEVICE;
g_usbPnpNotifyRemoveType = USB_PNP_NOTIFY_REMOVE_BUS_DEV_NUM;
OsalMutexUnlock(&g_usbSendEventLock);
wake_up_interruptible(&g_usbPnpNotifyReportWait);
}
break;
case USB_GADGET_ADD:
case USB_GADGET_REMOVE:
OsalMutexLock(&g_gadgetSendEventLock);
if (g_preAcion == action) {
OsalMutexUnlock(&g_gadgetSendEventLock);
break;
}
if (action == USB_GADGET_ADD) {
g_gadgetPnpNotifyType = USB_PNP_DRIVER_GADGET_ADD;
} else {
g_gadgetPnpNotifyType = USB_PNP_DRIVER_GADGET_REMOVE;
}
OsalMutexUnlock(&g_gadgetSendEventLock);
HDF_LOGI("%s:%d g_gadgetPnpNotifyType = %hhu", __func__, __LINE__, g_gadgetPnpNotifyType);
wake_up_interruptible(&g_gadgetPnpNotifyReportWait);
g_preAcion = action;
break;
default:
HDF_LOGI("%s: the action = 0x%lx is not defined!", __func__, action);
break;
}
return NOTIFY_OK;
}
static struct notifier_block g_usbPnpNotifyNb = {
.notifier_call = UsbPnpNotifyCallback,
};
static void UsbPnpNotifyReadPnpInfo(struct HdfSBuf *data)
{
struct UsbInfoQueryPara infoQueryPara;
struct UsbPnpDeviceInfo *deviceInfo = NULL;
struct UsbPnpAddRemoveInfo *usbPnpInfo = NULL;
uint32_t infoSize;
bool flag;
flag = HdfSbufReadBuffer(data, (const void **)(&usbPnpInfo), &infoSize);
if ((!flag) || (usbPnpInfo == NULL)) {
HDF_LOGE("%s: fail to read g_usbPnpInfo, flag=%d", __func__, flag);
return;
}
g_usbPnpInfo.devNum = usbPnpInfo->devNum;
g_usbPnpInfo.busNum = usbPnpInfo->busNum;
g_usbPnpInfo.interfaceNumber = usbPnpInfo->interfaceNumber;
g_usbPnpInfo.interfaceClass = usbPnpInfo->interfaceClass;
g_usbPnpInfo.interfaceSubClass = usbPnpInfo->interfaceSubClass;
g_usbPnpInfo.interfaceProtocol = usbPnpInfo->interfaceProtocol;
g_usbDevice = (struct usb_device *)&g_usbPnpInfo;
infoQueryPara.type = USB_INFO_NORMAL_TYPE;
infoQueryPara.devNum = usbPnpInfo->devNum;
infoQueryPara.busNum = usbPnpInfo->busNum;
deviceInfo = UsbPnpNotifyFindInfo(infoQueryPara);
if (deviceInfo == NULL) {
HDF_LOGE("%s:%d add or remove interface find info failed", __func__, __LINE__);
} else {
OsalMutexLock(&deviceInfo->lock);
if (deviceInfo->status != USB_PNP_DEVICE_INIT_STATUS) {
deviceInfo->status = USB_PNP_DEVICE_INIT_STATUS;
} else {
deviceInfo->status = USB_PNP_DEVICE_INTERFACE_STATUS;
}
OsalMutexUnlock(&deviceInfo->lock);
}
HDF_LOGI("%s:%d infoSize=%d g_usbPnpInfo=%px-%d-%d-%d-%d-%d-%d read success!",
__func__, __LINE__, infoSize, &g_usbPnpInfo, g_usbPnpInfo.devNum, g_usbPnpInfo.busNum,
g_usbPnpInfo.interfaceNumber, g_usbPnpInfo.interfaceClass, g_usbPnpInfo.interfaceSubClass,
g_usbPnpInfo.interfaceProtocol);
}
static int32_t UsbPnpGetDevices(struct HdfSBuf *reply)
{
int32_t ret = HDF_SUCCESS;
struct UsbPnpDeviceInfo *infoPos = NULL;
struct UsbPnpDeviceInfo *infoTemp = NULL;
if (DListIsEmpty(&g_usbPnpInfoListHead)) {
return ret;
}
DLIST_FOR_EACH_ENTRY_SAFE(infoPos, infoTemp, &g_usbPnpInfoListHead, struct UsbPnpDeviceInfo, list){
if (!HdfSbufWriteInt32(reply, infoPos->info.busNum)) {
break;
}
if (!HdfSbufWriteInt32(reply, infoPos->info.devNum)) {
break;
}
if (!HdfSbufWriteUint8(reply, infoPos->info.deviceInfo.deviceClass)) {
break;
}
if (!HdfSbufWriteUint8(reply, infoPos->info.deviceInfo.deviceSubClass)) {
break;
}
if (!HdfSbufWriteUint8(reply, infoPos->info.deviceInfo.deviceProtocol)) {
break;
}
if (!HdfSbufWriteUint8(reply, infoPos->status)) {
break;
}
}
return ret;
}
static int32_t UsbPnpNotifyDispatch(struct HdfDeviceIoClient *client, int32_t cmd,
struct HdfSBuf *data, struct HdfSBuf *reply)
{
int32_t ret = HDF_SUCCESS;
HDF_LOGI("%s: received cmd = %d", __func__, cmd);
OsalMutexLock(&g_usbSendEventLock);
if (USB_PNP_DRIVER_GETDEVICES != cmd) {
g_usbPnpNotifyCmdType = cmd;
}
switch (cmd) {
case USB_PNP_NOTIFY_ADD_INTERFACE:
UsbPnpNotifyReadPnpInfo(data);
wake_up_interruptible(&g_usbPnpNotifyReportWait);
break;
case USB_PNP_NOTIFY_REMOVE_INTERFACE:
UsbPnpNotifyReadPnpInfo(data);
g_usbPnpNotifyRemoveType = USB_PNP_NOTIFY_REMOVE_INTERFACE_NUM;
wake_up_interruptible(&g_usbPnpNotifyReportWait);
break;
case USB_PNP_NOTIFY_REPORT_INTERFACE:
usb_for_each_dev((void *)client, UsbPnpNotifyFirstReport);
break;
#if USB_PNP_NOTIFY_TEST_MODE == true
case USB_PNP_NOTIFY_ADD_TEST:
TestReadPnpInfo(data);
wake_up_interruptible(&g_usbPnpNotifyReportWait);
break;
case USB_PNP_NOTIFY_REMOVE_TEST:
TestReadPnpInfo(data);
g_usbPnpNotifyRemoveType = g_testUsbPnpInfo->removeType;
wake_up_interruptible(&g_usbPnpNotifyReportWait);
break;
#endif
case USB_PNP_DRIVER_GETDEVICES:
UsbPnpGetDevices(reply);
break;
default:
ret = HDF_ERR_NOT_SUPPORT;
break;
}
OsalMutexUnlock(&g_usbSendEventLock);
if (!HdfSbufWriteInt32(reply, INT32_MAX)) {
HDF_LOGE("%s: reply int32 fail", __func__);
}
return ret;
}
static int32_t UsbPnpNotifyBind(struct HdfDeviceObject *device)
{
static struct IDeviceIoService pnpNotifyService = {
.Dispatch = UsbPnpNotifyDispatch,
};
HDF_LOGI("%s: Enter!", __func__);
if (device == NULL) {
HDF_LOGE("%s: device is NULL!", __func__);
return HDF_ERR_INVALID_OBJECT;
}
device->service = &pnpNotifyService;
return HDF_SUCCESS;
}
static int32_t UsbPnpNotifyInit(struct HdfDeviceObject *device)
{
static bool firstInitFlag = true;
HDF_LOGI("%s: Enter!", __func__);
if (device == NULL) {
HDF_LOGE("%s: device is NULL", __func__);
return HDF_ERR_INVALID_OBJECT;
}
if (firstInitFlag) {
firstInitFlag = false;
DListHeadInit(&g_usbPnpInfoListHead);
}
init_waitqueue_head(&g_usbPnpNotifyReportWait);
init_waitqueue_head(&g_gadgetPnpNotifyReportWait);
OsalMutexInit(&g_usbSendEventLock);
OsalMutexInit(&g_gadgetSendEventLock);
/* Add a new notify for usb pnp notify module. */
usb_register_notify(&g_usbPnpNotifyNb);
/* Create thread to handle send usb interface information. */
if (NULL == g_usbPnpNotifyReportThread) {
g_usbPnpNotifyReportThread = kthread_run(UsbPnpNotifyReportThread,
(void *)device, "usb pnp notify handle kthread");
if (g_usbPnpNotifyReportThread == NULL) {
HDF_LOGE("%s: kthread_run g_usbPnpNotifyReportThread is NULL", __func__);
}
} else {
HDF_LOGI("%s: g_usbPnpNotifyReportThread is already running!", __func__);
}
/* Create thread to handle gadeget information. */
if (NULL == g_gadgetPnpNotifyReportThread) {
g_gadgetPnpNotifyReportThread = kthread_run(GadgetPnpNotifyReportThread,
(void *)device, "gadget pnp notify handle kthread");
if (g_usbPnpNotifyReportThread == NULL) {
HDF_LOGE("%s: kthread_run g_usbPnpNotifyReportThread is NULL", __func__);
}
} else {
HDF_LOGI("%s: g_devPnpNotifyReportThread is already running!", __func__);
}
return HDF_SUCCESS;
}
static void UsbPnpNotifyRelease(struct HdfDeviceObject *device)
{
if (device == NULL) {
HDF_LOGI("%s: device is null", __func__);
return;
}
if (g_usbPnpNotifyReportThread == NULL) {
HDF_LOGI("%s: g_usbPnpNotifyReportThread is not running!", __func__);
} else {
kthread_stop(g_usbPnpNotifyReportThread);
}
if (g_gadgetPnpNotifyReportThread == NULL) {
HDF_LOGI("%s: g_usbPnpNotifyReportThread is not running!", __func__);
} else {
kthread_stop(g_gadgetPnpNotifyReportThread);
}
usb_unregister_notify(&g_usbPnpNotifyNb);
OsalMutexDestroy(&g_usbSendEventLock);
OsalMutexDestroy(&g_gadgetSendEventLock);
HDF_LOGI("%s: release done!", __func__);
return;
}
struct HdfDriverEntry g_usbPnpNotifyEntry = {
.moduleVersion = 1,
.Bind = UsbPnpNotifyBind,
.Init = UsbPnpNotifyInit,
.Release = UsbPnpNotifyRelease,
.moduleName = "HDF_USB_PNP_NOTIFY",
};
HDF_INIT(g_usbPnpNotifyEntry);

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_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.
*
*/
/**
* @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
/** @} */

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) += \
-I$(srctree)/drivers/hdf/framework/model/network/common/netdevice \
-I$(srctree)/drivers/hdf/framework/include/net\
-I$(srctree)/drivers/hdf/khdf/network/include \
-I$(srctree)/drivers/hdf/khdf/osal/include \
-I$(srctree)/include/hdf/wifi \
-I$(srctree)/include/hdf/utils \
-I$(srctree)/include/hdf/osal \
-I$(srctree)/bounds_checking_function/include

View File

@ -0,0 +1,341 @@
/*
* 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 <linux/version.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 = dev;
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(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)
{
struct net_device *dev = NULL;
int ret;
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) {
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,0,0)
ret = dev_open(dev, NULL);
#else
ret = dev_open(dev);
#endif
} 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.c
*
* 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;
}

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,55 @@
/*
* 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_LOG_BUF_SIZE 256
bool deal_format(const char *fmt, char *str, size_t size);
#define HDF_LOG_WRAPPER(fmt, args...) \
do { \
char tmp_fmt[HDF_LOG_BUF_SIZE] = {0}; \
if (deal_format(fmt, tmp_fmt, sizeof(tmp_fmt))) \
printk(tmp_fmt, ##args); \
} while (0)
#define HDF_LOGV_WRAPPER(fmt, args...) HDF_LOG_WRAPPER(KERN_DEBUG HDF_FMT_TAG(HDF_LOG_TAG, V) fmt "\r\n", ## args)
#define HDF_LOGD_WRAPPER(fmt, args...) HDF_LOG_WRAPPER(KERN_DEBUG HDF_FMT_TAG(HDF_LOG_TAG, D) fmt "\r\n", ## args)
#define HDF_LOGI_WRAPPER(fmt, args...) HDF_LOG_WRAPPER(KERN_INFO HDF_FMT_TAG(HDF_LOG_TAG, I) fmt "\r\n", ## args)
#define HDF_LOGW_WRAPPER(fmt, args...) HDF_LOG_WRAPPER(KERN_WARNING HDF_FMT_TAG(HDF_LOG_TAG, W) fmt "\r\n", ## args)
#define HDF_LOGE_WRAPPER(fmt, args...) HDF_LOG_WRAPPER(KERN_ERR HDF_FMT_TAG(HDF_LOG_TAG, E) fmt "\r\n", ## args)
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* HDF_LOG_ADAPTER_H */

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 */

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 */

View File

@ -0,0 +1,22 @@
#
# 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 osal_deal_log_format.o
ccflags-y +=-I$(srctree)/include/hdf \
-I$(srctree)/include/hdf/osal \
-I$(srctree)/include/hdf/utils \
-I$(srctree)/drivers/hdf/framework/utils/include \
-I$(srctree)/drivers/hdf/khdf/osal/include \
-I$(srctree)/bounds_checking_function/include

View File

@ -0,0 +1,269 @@
/*
* 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)
{
(void)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("failed 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);
return ret;
}
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;
int ret;
(void)mode;
if (cdev == NULL || name == NULL) {
return HDF_ERR_INVALID_PARAM;
}
lastSlash = StringRfindChar(name, '/');
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;
}

View File

@ -0,0 +1,70 @@
/*
* osal_deal_log_format.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/printk.h>
#include "securec.h"
#define NUMBER 2
static const char *g_property[NUMBER] = { "%{private}", "%{public}" };
static size_t g_property_len[NUMBER] = { 10, 9 };
/* remove "{private}" and "{public}" from fmt and copy the rest to dest */
bool deal_format(const char *fmt, char *dest, size_t size)
{
const char *ptr = fmt;
const char *ptr_cur = ptr;
errno_t ret;
size_t index = 0;
size_t i;
if (fmt == NULL || dest == NULL || size == 0 || strlen(fmt) >= (size - 1)) {
printk("%s invalid para", __func__);
return false;
}
while (ptr_cur != NULL && *ptr_cur != '\0') {
if (*ptr_cur != '%') {
ptr_cur++;
continue;
}
for (i = 0; i < NUMBER; i++) {
if (strncmp(ptr_cur, g_property[i], g_property_len[i]) != 0)
continue;
/* add 1 is for to copy char '%' */
ret = strncpy_s(&dest[index], size - index, ptr, ptr_cur - ptr + 1);
if (ret != EOK) {
printk("%s strncpy_s error %d", __func__, ret);
return false;
}
index += (ptr_cur - ptr + 1);
ptr = ptr_cur + g_property_len[i];
ptr_cur = ptr;
break;
}
if (i == NUMBER)
ptr_cur++;
}
ret = strcat_s(&dest[index], size - index, ptr);
if (ret != EOK) {
printk("%s strcat_s error %d", __func__, ret);
return false;
}
return true;
}
EXPORT_SYMBOL(deal_format);

View File

@ -0,0 +1,125 @@
/*
* 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 %u", __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;
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;
ret = kernel_write(fp, string, length, &pos);
if (ret < 0) {
HDF_LOGE("%s write file length %u 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;
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;
pos = fp->f_pos;
ret = kernel_read(fp, buf, length, &pos);
if (ret < 0) {
HDF_LOGE("%s read file length %u 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);

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);

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 %u", __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);

View File

@ -0,0 +1,167 @@
/*
* 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 > (SIZE_MAX - mng_size)) {
HDF_LOGE("%s invalid param %zu", __func__, size);
return NULL;
}
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:%zu,size:%zu", __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) {
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 %u fail", __func__, type);
}
EXPORT_SYMBOL(OsalMemFree);

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);

View File

@ -0,0 +1,105 @@
/*
* 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) {
do {
ret = down_interruptible((struct semaphore *)sem->realSemaphore);
} while (ret == -EINTR);
} 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 %u %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);

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);

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);

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/timekeeping.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 timespec64 ts;
if (time == NULL) {
HDF_LOGE("%s invalid para", __func__);
return HDF_ERR_INVALID_PARAM;
}
(void)memset_s(&ts, sizeof(ts), 0, sizeof(ts));
ktime_get_ts64(&ts);
time->sec = ts.tv_sec;
time->usec = ts.tv_nsec / HDF_KILO_UNIT;
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);

View File

@ -0,0 +1,184 @@
/*
* 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 {
uintptr_t arg;
struct timer_list timer;
OsalTimerFunc func;
uint32_t msec;
struct OsalMutex mutex;
OsalTimerMode mode;
bool stop_flag;
};
static void osal_timer_callback(struct timer_list *arg)
{
struct osal_ktimer *ktimer = NULL;
uint32_t msec;
OsalTimerMode mode;
bool stop_flag = false;
if (arg == NULL) {
HDF_LOGI("%s timer is stopped", __func__);
return;
}
ktimer = from_timer(ktimer, arg, timer);
OsalMutexTimedLock(&ktimer->mutex, HDF_WAIT_FOREVER);
mode = ktimer->mode;
stop_flag = ktimer->stop_flag;
OsalMutexUnlock(&ktimer->mutex);
if (!stop_flag) {
ktimer->func(ktimer->arg);
OsalMutexTimedLock(&ktimer->mutex, HDF_WAIT_FOREVER);
msec = ktimer->msec;
OsalMutexUnlock(&ktimer->mutex);
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;
ktimer->stop_flag = false;
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->stop_flag = true;
OsalMutexUnlock(&ktimer->mutex);
if (ktimer->mode == OSAL_TIMER_ONCE)
mod_timer(&ktimer->timer, ktimer->timer.expires);
timer->realTimer = NULL;
return HDF_SUCCESS;
}
EXPORT_SYMBOL(OsalTimerDelete);

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, uint32_t 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((unsigned long)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);

61
adapter/khdf/linux/patch_hdf.sh Executable file
View File

@ -0,0 +1,61 @@
#!/bin/bash
#
# 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.
#
#
set -e
OHOS_SOURCE_ROOT=$1
KERNEL_BUILD_ROOT=$2
HDF_PATCH_FILE=$3
ln_list=(
$OHOS_SOURCE_ROOT/drivers/hdf_core/adapter/khdf/linux drivers/hdf/khdf
$OHOS_SOURCE_ROOT/drivers/hdf_core/framework drivers/hdf/framework
$OHOS_SOURCE_ROOT/drivers/hdf_core/framework/include include/hdf
)
cp_list=(
$OHOS_SOURCE_ROOT/third_party/bounds_checking_function ./
$OHOS_SOURCE_ROOT/device/soc/hisilicon/common/platform/wifi drivers/hdf/
$OHOS_SOURCE_ROOT/third_party/FreeBSD/sys/dev/evdev drivers/hdf/
)
function copy_external_compents()
{
for ((i=0; i<${#cp_list[*]}; i+=2))
do
dst_dir=${cp_list[$(expr $i + 1)]}/${cp_list[$i]##*/}
mkdir -p $dst_dir
[ -d ${cp_list[$i]}/ ] && cp -arfL ${cp_list[$i]}/* $dst_dir/
done
}
function ln_hdf_repos()
{
for ((i=0; i<${#ln_list[*]}; i+=2))
do
ln -sf ${ln_list[$i]} ${ln_list[$(expr $i + 1)]}
done
}
function main()
{
cd $KERNEL_BUILD_ROOT
patch -p1 < $HDF_PATCH_FILE
ln_hdf_repos
copy_external_compents
cd -
}
main

View File

@ -0,0 +1,115 @@
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_MIPI_CSI
bool "Enable HDF platform mipi csi driver"
default n
depends on DRIVERS_HDF_PLATFORM
help
Answer Y to enable HDF platform mipi csi 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 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 && DRIVERS_HDF_PLATFORM_MMC
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_MMC
bool "Enable HDF platform mmc driver"
default n
depends on DRIVERS_HDF_PLATFORM
help
Answer Y to enable HDF platform mmc 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.
config PWM_HI35XX
bool "hi35xx pwm driver"
depends on PWM
help
Answer Y to enable hi35xx pwm driver
config DRIVERS_HDF_PLATFORM_REGULATOR
bool "Enable HDF platform regulator driver"
default n
depends on DRIVERS_HDF_PLATFORM
help
Answer Y to enable HDF platform regulator driver.
config DRIVERS_HDF_PLATFORM_ADC
bool "Enable HDF platform adc driver"
default n
depends on DRIVERS_HDF_PLATFORM
help
Answer Y to enable HDF platform adc driver.
config DRIVERS_HDF_PLATFORM_TRACE
bool "Enable HDF platform trace driver"
default n
depends on DRIVERS_HDF_PLATFORM
help
Answer Y to enable HDF platform trace driver.

View File

@ -0,0 +1,26 @@
#
# 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) += fwk/
obj-$(CONFIG_DRIVERS_HDF_PLATFORM_MIPI_DSI) += mipi_dsi/
obj-$(CONFIG_DRIVERS_HDF_PLATFORM_MIPI_CSI) += mipi_csi/
obj-$(CONFIG_DRIVERS_HDF_PLATFORM_GPIO) += gpio/
obj-$(CONFIG_DRIVERS_HDF_PLATFORM_I2C) += i2c/
obj-$(CONFIG_DRIVERS_HDF_PLATFORM_WATCHDOG) += watchdog/
obj-$(CONFIG_DRIVERS_HDF_PLATFORM_PWM) += pwm/
obj-$(CONFIG_DRIVERS_HDF_PLATFORM_UART) += uart/
obj-$(CONFIG_DRIVERS_HDF_PLATFORM_SPI) += spi/
obj-$(CONFIG_DRIVERS_HDF_PLATFORM_RTC) += rtc/
obj-$(CONFIG_DRIVERS_HDF_PLATFORM_ADC) += adc/
obj-$(CONFIG_DRIVERS_HDF_PLATFORM_REGULATOR) += regulator/

View File

@ -0,0 +1,19 @@
#
# Copyright (c) 2022 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/adc/adc_core.o \
$(HDF_PLATFORM_FRAMEWORKS_ROOT)/src/adc/adc_if.o \
./adc_iio_adapter.o

View File

@ -0,0 +1,226 @@
/*
* adc driver adapter of linux
*
* Copyright (c) 2022 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/fs.h>
#include <linux/kernel.h>
#include "device_resource_if.h"
#include "hdf_base.h"
#include "hdf_device_desc.h"
#include "hdf_log.h"
#include "osal_mem.h"
#include "securec.h"
#include "adc_core.h"
#define ADC_STRING_VALUE_LEN 15
#define ADC_DRIVER_PATHNAME_LEN 128
#define INT_MAX_VALUE 2147483647
#define FILE_MODE 0600
#define DECIMAL_SHIFT_LEFT 10
static char g_driverPathname[ADC_DRIVER_PATHNAME_LEN] = {0};
struct AdcIioDevice {
struct AdcDevice device;
volatile unsigned char *regBase;
volatile unsigned char *pinCtrlBase;
uint32_t regBasePhy;
uint32_t regSize;
uint32_t deviceNum;
uint32_t dataWidth;
uint32_t validChannel;
uint32_t scanMode;
uint32_t delta;
uint32_t deglitch;
uint32_t glitchSample;
uint32_t rate;
};
static int32_t AdcIioRead(struct AdcDevice *device, uint32_t channel, uint32_t *val)
{
int ret;
loff_t pos = 0;
struct file *fp = NULL;
unsigned char strValue[ADC_STRING_VALUE_LEN] = {0};
if (device == NULL || device->priv == NULL) {
HDF_LOGE("%s: Illegal object", __func__);
return HDF_ERR_INVALID_OBJECT;
}
if (val == NULL) {
HDF_LOGE("%s: Illegal parameter", __func__);
return HDF_ERR_INVALID_PARAM;
}
fp = (struct file *)device->priv;
ret = kernel_read(fp, strValue, ADC_STRING_VALUE_LEN, &pos);
if (ret < 0) {
HDF_LOGE("%s: kernel_read fail %d", __func__, ret);
return HDF_PLT_ERR_OS_API;
}
*val = simple_strtoul(strValue, NULL, 0);
return HDF_SUCCESS;
}
static int32_t AdcIioStop(struct AdcDevice *device)
{
int ret;
struct file *fp = NULL;
ret = HDF_FAILURE;
if (device == NULL || device->priv == NULL) {
HDF_LOGE("%s: Illegal object", __func__);
return HDF_ERR_INVALID_OBJECT;
}
fp = (struct file *)device->priv;
if (!IS_ERR(fp)) {
ret = filp_close(fp, NULL);
}
return ret;
}
static int32_t AdcIioStart(struct AdcDevice *device)
{
struct file *fp = NULL;
if (device == NULL) {
HDF_LOGE("%s: device is NULL", __func__);
return HDF_ERR_INVALID_OBJECT;
}
fp = filp_open(g_driverPathname, O_RDWR | O_NOCTTY | O_NDELAY, FILE_MODE);
if (IS_ERR(fp)) {
HDF_LOGE("filp open fail");
return HDF_PLT_ERR_OS_API;
}
device->priv = fp;
return HDF_SUCCESS;
}
static const struct AdcMethod g_method = {
.read = AdcIioRead,
.stop = AdcIioStop,
.start = AdcIioStart,
};
static int32_t AdcIioReadDrs(struct AdcIioDevice *adcDevice, const struct DeviceResourceNode *node)
{
int32_t ret;
const char *drName = NULL;
int32_t drNameLen;
struct DeviceResourceIface *drsOps = NULL;
drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
if (drsOps == NULL || drsOps->GetUint32 == NULL || drsOps->GetString == NULL) {
HDF_LOGE("%s: invalid drs ops", __func__);
return HDF_ERR_NOT_SUPPORT;
}
ret = drsOps->GetString(node, "driver_name", &drName, "/sys/bus/iio/devices/iio:device0/in_voltage0-voltage0_raw");
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: read driver_name failed", __func__);
return ret;
}
drNameLen = strlen(drName);
if (drNameLen > (ADC_DRIVER_PATHNAME_LEN - 1)) {
HDF_LOGE("%s: Illegal length of drName", __func__);
return HDF_FAILURE;
}
ret = memcpy_s(g_driverPathname, ADC_DRIVER_PATHNAME_LEN, drName, drNameLen);
if (ret != 0) {
HDF_LOGE("%s: memcpy drName fail", __func__);
return HDF_FAILURE;
}
ret = drsOps->GetUint32(node, "deviceNum", &adcDevice->deviceNum, 0);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: read deviceNum failed", __func__);
return ret;
}
ret = drsOps->GetUint32(node, "scanMode", &adcDevice->scanMode, 0);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: read scanMode failed", __func__);
return ret;
}
ret = drsOps->GetUint32(node, "rate", &adcDevice->rate, 0);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: read rate failed", __func__);
return ret;
}
return HDF_SUCCESS;
}
static int32_t LinuxAdcInit(struct HdfDeviceObject *device)
{
int32_t ret;
struct AdcIioDevice *adcDevice = NULL;
if (device == NULL) {
HDF_LOGE("%s: device is NULL", __func__);
return HDF_ERR_INVALID_OBJECT;
}
if (device->property == NULL) {
HDF_LOGE("%s: property of device is NULL", __func__);
return HDF_ERR_INVALID_OBJECT;
}
adcDevice = (struct AdcIioDevice *)OsalMemCalloc(sizeof(*adcDevice));
if (adcDevice == NULL) {
HDF_LOGE("%s: alloc adcDevice failed", __func__);
return HDF_ERR_MALLOC_FAIL;
}
device->priv = adcDevice;
ret = AdcIioReadDrs(adcDevice, device->property);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: read drs failed:%d", __func__, ret);
OsalMemFree(adcDevice);
return ret;
}
adcDevice->device.devNum = adcDevice->deviceNum;
adcDevice->device.ops = &g_method;
ret = AdcDeviceAdd(&adcDevice->device);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: add adc device:%u failed", __func__, adcDevice->deviceNum);
OsalMemFree(adcDevice);
return ret;
}
return HDF_SUCCESS;
}
static void LinuxAdcRelease(struct HdfDeviceObject *device)
{
if (device == NULL || device->priv == NULL) {
HDF_LOGE("%s: Illegal parameter", __func__);
return;
}
AdcDeviceRemove(device->priv);
OsalMemFree(device->priv);
}
struct HdfDriverEntry g_adcLinuxDriverEntry = {
.moduleVersion = 1,
.Bind = NULL,
.Init = LinuxAdcInit,
.Release = LinuxAdcRelease,
.moduleName = "linux_adc_adapter",
};
HDF_INIT(g_adcLinuxDriverEntry);

Some files were not shown because too many files have changed in this diff Show More