name: use-pdev-dfv2 description: Use Platform Device (pdev) in DFv2 drivers.

Using Platform Device (pdev) in DFv2

Dependencies

GN:

deps = [
  "//sdk/lib/driver/platform-device/cpp", # For fdf::PDev
]

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:

    use: [
        { service: "fuchsia.hardware.platform.device.Service" },
    ],

2. Code Implementation

Include the header:

#include <lib/driver/platform-device/cpp/pdev.h>

To connect to pdev in your Start() method:

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:
    zx::result mmio = pdev.MapMmio(0);
    
  • Get Interrupt:
    zx::result irq = pdev.GetInterrupt(0);
    
  • Get BTI:
    zx::result bti = pdev.GetBti(0);
    

Further Reading