| // 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. |
| |
| #include "msd_img_device.h" |
| |
| extern "C" |
| { |
| #include "process_stats.h" |
| #include "pvrsrv.h" |
| #include "pvrsrv_error.h" |
| #include "rgxdevice.h" |
| #include "srvcore.h" |
| } |
| |
| |
| MsdImgDevice::MsdImgDevice(std::unique_ptr<magma::PlatformDevice> platform_device) |
| : platform_device_(std::move(platform_device)) |
| { |
| magic_ = kMagic; |
| } |
| |
| MsdImgDevice::~MsdImgDevice() |
| { |
| if (device_node_) |
| { |
| PVRSRVDeviceDestroy(device_node_); |
| } |
| } |
| |
| bool |
| MsdImgDevice::Init() |
| { |
| bti_ = platform_device_->GetBusTransactionInitiator(); |
| if (!bti_) |
| { |
| return DRETF(false, "Failed to create bus transaction initiator"); |
| } |
| |
| PVRSRV_ERROR srv_err; |
| srv_err = PVRSRVDeviceCreate(this, 1u, &device_node_); |
| if (srv_err != PVRSRV_OK) |
| { |
| return DRETF(false, "Failed to create device: %d", srv_err); |
| } |
| |
| srv_err = PVRSRVDeviceInitialise(device_node_); |
| if (srv_err != PVRSRV_OK) |
| { |
| return DRETF(false, "Failed to initialize device: %d", srv_err); |
| } |
| return true; |
| } |
| |
| // static |
| std::unique_ptr<MsdImgDevice> |
| MsdImgDevice::Create(msd_driver_t* drv, void* device) |
| { |
| auto platform_device = magma::PlatformDevice::Create(device); |
| if (!platform_device) |
| { |
| return DRETP(nullptr, "Failed to create platform device"); |
| } |
| |
| auto msd_device = std::unique_ptr<MsdImgDevice>(new MsdImgDevice(std::move(platform_device))); |
| if (!msd_device->Init()) |
| { |
| return DRETP(nullptr, "Failed to create msd device"); |
| } |
| return msd_device; |
| } |
| |
| // static |
| void |
| MsdImgDevice::Destroy(MsdImgDevice* device) |
| { |
| delete device; |
| } |