blob: 9c266dcdb62371bb19f7e910f37eeb375bfe4704 [file] [log] [blame]
// Copyright 2019 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SRC_DEVICES_BIN_DRIVER_HOST_COMPOSITE_DEVICE_H_
#define SRC_DEVICES_BIN_DRIVER_HOST_COMPOSITE_DEVICE_H_
#include <ddk/driver.h>
#include <fbl/array.h>
#include <fbl/ref_counted.h>
#include <fbl/ref_ptr.h>
#include "zx_device.h"
struct CompositeFragment {
std::string name;
fbl::RefPtr<zx_device> device;
};
typedef fbl::Array<CompositeFragment> CompositeFragments;
// Modifies |device| to have the appropriate protocol_id, ctx, and ops tables
// for a composite device
zx_status_t InitializeCompositeDevice(const fbl::RefPtr<zx_device>& device,
CompositeFragments&& fragments);
// Returns a zx_driver instance for composite devices
fbl::RefPtr<zx_driver> GetCompositeDriver(DriverHostContext* ctx);
// These objects are state shared by all fragments of the composite device that
// enables one of them (the first to try) to begin teardown of the composite
// device. This is used for implementing unbind.
class CompositeDevice : public fbl::RefCounted<CompositeDevice> {
public:
explicit CompositeDevice(fbl::RefPtr<zx_device> device) : device_(std::move(device)) {}
~CompositeDevice();
fbl::RefPtr<zx_device> Detach() { return std::move(device_); }
private:
fbl::RefPtr<zx_device> device_;
};
#endif // SRC_DEVICES_BIN_DRIVER_HOST_COMPOSITE_DEVICE_H_