blob: 96ae563d67124db0be4a2ac748bc2a34e3e41f0f [file] [view]
---
name: use-pdev-dfv2
description: Use Platform Device (pdev) in DFv2 drivers.
---
# Using Platform Device (pdev) in DFv2
## Dependencies
**GN:**
```gn
deps = [
"//sdk/lib/driver/platform-device/cpp", # For fdf::PDev
]
```
**Bazel:**
```bazel
deps = [
"@fuchsia_sdk//pkg/driver_platform_device_cpp", # For fdf::PDev
]
```
## Implementation Steps
### 1. Component Manifest (.cml) Update
Declare that the driver uses the service in its `.cml` file:
```cml
use: [
{ service: "fuchsia.hardware.platform.device.Service" },
],
```
### 2. Code Implementation
Include the header:
```cpp
#include <lib/driver/platform-device/cpp/pdev.h>
```
To connect to `pdev` in your `Start()` method:
```cpp
zx::result pdev_client = incoming()->Connect<fuchsia_hardware_platform_device::Service::Device>();
if (pdev_client.is_error()) {
fdf::error("Failed to connect to pdev: {}", pdev_client.status_string());
return pdev_client.take_error();
}
fdf::PDev pdev(std::move(pdev_client.value()));
```
### Common Operations
* **Map MMIO**:
```cpp
zx::result mmio = pdev.MapMmio(0);
```
* **Get Interrupt**:
```cpp
zx::result irq = pdev.GetInterrupt(0);
```
* **Get BTI**:
```cpp
zx::result bti = pdev.GetBti(0);
```
## Further Reading
* For more information on FIDL usage, see the [Driver FIDL Usage Implementation
Skill
(C++)](/src/devices/skills/driver_fidl_usage/implementation/cpp/SKILL.md).