blob: 5158503e32051bfc50eeef81c22a6325fe2202b2 [file] [log] [blame]
// Copyright 2018 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.
#include <lib/ddk/debug.h>
#include <lib/device-protocol/pdev-fidl.h>
#include <lib/mmio/mmio.h>
namespace ddk {
void PDev::ShowInfo() {
pdev_device_info_t info;
if (GetDeviceInfo(&info) == ZX_OK) {
zxlogf(INFO, "VID:PID:DID = %04x:%04x:%04x", info.vid, info.pid, info.did);
zxlogf(INFO, "mmio count = %d", info.mmio_count);
zxlogf(INFO, "irq count = %d", info.irq_count);
zxlogf(INFO, "bti count = %d", info.bti_count);
}
}
__WEAK zx_status_t PDev::MapMmio(uint32_t index, std::optional<fdf::MmioBuffer>* mmio,
uint32_t cache_policy) {
pdev_mmio_t pdev_mmio;
zx_status_t status = GetMmio(index, &pdev_mmio);
if (status != ZX_OK) {
return status;
}
return PDevMakeMmioBufferWeak(pdev_mmio, mmio, cache_policy);
}
// Regular implementation for drivers. Tests might override this.
[[gnu::weak]] zx_status_t PDevMakeMmioBufferWeak(const pdev_mmio_t& pdev_mmio,
std::optional<fdf::MmioBuffer>* mmio,
uint32_t cache_policy) {
zx::result<fdf::MmioBuffer> result =
MmioBuffer::Create(pdev_mmio.offset, pdev_mmio.size, zx::vmo(pdev_mmio.vmo), cache_policy);
if (result.is_ok()) {
*mmio = std::move(result.value());
}
return result.status_value();
}
} // namespace ddk