blob: 2d0a8aa1e989f0e1ea2c2014dd4d8de806dda214 [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 MSD_IMG_DEVICE_H
#define MSD_IMG_DEVICE_H
#include <memory>
#include "magma_util/macros.h"
#include "msd.h"
#include "platform_device.h"
typedef struct _PVRSRV_DEVICE_NODE_ PVRSRV_DEVICE_NODE;
struct FuchsiaSysInfo;
class MsdImgDevice : public msd_device_t
{
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::PlatformHandle* bti() { return bti_.get(); }
magma::PlatformMmio* mmio() { return mmio_.get(); }
FuchsiaSysInfo* sys_info() { return sys_info_.get(); }
// 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>);
static const uint32_t kMagic = 'idev';
std::unique_ptr<magma::PlatformDevice> platform_device_;
std::unique_ptr<magma::PlatformHandle> bti_;
std::unique_ptr<magma::PlatformMmio> mmio_;
PVRSRV_DEVICE_NODE* device_node_ = nullptr;
std::unique_ptr<FuchsiaSysInfo> sys_info_;
};
#endif // MSD_IMG_DEVICE_H