Hardware Device Interfaces (HDI) in OpenHarmony Systems
An essential function of the HDI driver framework is to provide a stable and unified hardware interface for system services, ensuring their compatibility across different hardware platforms without the need for additional adaptations. HDI, which stands for Hardware Device Interfaces, serves this purpose effectively.
HDI functions as a high-level abstract interface for hardware operations. By defining the HDI interface, peripherals can be modified within the boundaries of HDI compatibility rules, guaranteeing interface stability. Driver implementations do not have to redefine the HDI interface; they only need to be tailored as per requirements to access system functions.
On various scales of OpenHarmony systems, HDI operates in two deployment modes: IPC mode and pass-through mode.
In the lightweight OpenHarmony system, HDI is configured as a user mode shared library to alleviate system performance burden. This library is directly loaded by system services into their respective processes for function execution. The HDI implementation encapsulates the specific user-kernel interaction process. When driver access is required, the IO Service Request is utilized to communicate with the kernel driver through system calls.
In the OpenHarmony system, HDI is deployed as an independent service process. The system service loads only the HDI client into its process, while the actual operations run in a separate process. Interactions between the client and server occur through IPC, promoting architectural decoupling and streamlined permission management.
HDI Interface Implementation
The pass-through mode is a self-sufficient function implementation mode that does not rely on external components for calling or implementation. Here, we will focus on the IPC mode implementation.
HDI Release
The HDI IPC mode aligns with the general model of the OpenHarmony system’s communication framework. Due to the involvement of low-level operations and multi-system migration scenarios, the driver is predominantly written in C language. Consequently, the driver framework furnishes fundamental components of the HDI service in C language, while the implementation primarily utilizes system communication framework components.
HDI service publication is based on UHDF (user mode HDF driver framework). The standard service publication process is as follows:
- Drive entrance
- Implement the service response interface
When an HDI call is received, the service response interface “SampleServiceDispatch” is invoked to handle the request.
Understanding Client Caller Object in User Mode Driver
The client caller object is a fundamental concept in user mode driver development. The CmdId plays a crucial role in distinguishing different API calls. In the context of IPC calls, the data call input parameter serialization object is encapsulated within the parcel object written in the C language.
Key Points:
- UHDF Drive Configuration: When configuring UHDF drives, ensure the following parameters are set:
Platform Host:
- HostName: “sample_host”
- Priority: 50
Sample Device:
- DeviceNode:
- Policy: 2 (Service publishing policy for HDI service)
- Priority: 100
- ModuleName: “libsample_driver.z.so” (Driver Implementation Library Name)
- ServiceName: “sample_driver_service” (Globally unique service name)
Additional Information:
- Host Node: Represents an independent process.
- Policy: Refers to the service publishing policy, with HDI service set to 2.
- ModuleName: Indicates the name of the Driver Implementation Library.
- ServiceName: Should be globally unique to avoid conflicts.
In the context of HDI Service C and C++ implementations, differences exist in IPC components and object-oriented approaches. The UHDF framework offers essential components to support HDI implementation, particularly for C language HDI implementation.
SBuf: This tool object facilitates the serialization of IoService messages in both KHDF and UHDF. In UHDF IPC communication scenarios, SBuf plays a crucial role in converting with the system IPC framework serialization object MessageParcel object (limited to C++ support). This conversion enables seamless IPC interworking between C and C++.
Common APIs:
struct HdfSBuf;
struct HdfSbufImpl;
struct HdfRemoteService;
All the aforementioned IPC interfaces offer corresponding write interfaces. For detailed information, please consult the official HDI reference document available on the website.