| // 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 MSD_IMG_DEVICE_H |
| #define MSD_IMG_DEVICE_H |
| |
| #include <memory> |
| |
| #include "img-sys-device.h" |
| #include "magma_util/macros.h" |
| #include "msd.h" |
| #include "msd_img_connection.h" |
| #include "platform_bus_mapper.h" |
| #include "platform_device.h" |
| |
| typedef struct _PVRSRV_DEVICE_NODE_ PVRSRV_DEVICE_NODE; |
| typedef void* IMG_HANDLE; |
| |
| struct FuchsiaSysInfo; |
| |
| class MsdImgDevice : public msd_device_t, public MsdImgConnection::Owner |
| { |
| public: |
| virtual ~MsdImgDevice(); |
| |
| static std::unique_ptr<MsdImgDevice> Create(struct msd_driver_t* drv, void* device); |
| |
| bool Init(); |
| |
| static void Destroy(MsdImgDevice* drv); |
| |
| static MsdImgDevice* cast(msd_device_t* drv) |
| { |
| DASSERT(drv); |
| DASSERT(drv->magic_ == kMagic); |
| return static_cast<MsdImgDevice*>(drv); |
| } |
| |
| static MsdImgDevice* cast(void* dev) |
| { |
| DASSERT(dev); |
| auto msd_device = static_cast<MsdImgDevice*>(dev); |
| DASSERT(msd_device->magic_ == kMagic); |
| return msd_device; |
| } |
| |
| magma::PlatformDevice* platform_device() { return platform_device_.get(); } |
| magma::PlatformBusMapper* bus_mapper() { return bus_mapper_.get(); } |
| |
| magma::PlatformMmio* mmio() { return mmio_.get(); } |
| std::unique_ptr<magma::PlatformInterrupt> interrupt(); |
| |
| FuchsiaSysInfo* sys_info() { return sys_info_.get(); } |
| |
| // MsdImgConnection::Owner implementation. |
| PVRSRV_DEVICE_NODE* device_node() override { return device_node_; } |
| |
| void DumpStatus(uint32_t dump_state); |
| zx_status_t PowerUp(); |
| zx_status_t PowerDown(); |
| |
| // Used to retrieve the globally-accessible address of the mmio region. This is |
| // needed so OSMapPhysToLin can determine the virtual address of the MMIO |
| // registers when given physical address. |
| static uint64_t GetRegistersPhysicalAddress(); |
| static void* GetRegistersCpuAddress(); |
| |
| private: |
| MsdImgDevice(std::unique_ptr<magma::PlatformDevice>, |
| ImgSysDevice* sys_device); |
| |
| static const uint32_t kMagic = 'idev'; |
| |
| ImgSysDevice* sys_device_; |
| |
| std::unique_ptr<magma::PlatformDevice> platform_device_; |
| std::unique_ptr<magma::PlatformBusMapper> bus_mapper_; |
| std::unique_ptr<magma::PlatformMmio> mmio_; |
| PVRSRV_DEVICE_NODE* device_node_ = nullptr; |
| #if !defined(NO_HARDWARE) |
| IMG_HANDLE stats_user_ = nullptr; |
| #endif |
| |
| std::unique_ptr<FuchsiaSysInfo> sys_info_; |
| }; |
| |
| #endif // MSD_IMG_DEVICE_H |