@ -18,9 +18,16 @@ public:
}
} ;
class nvmap : public nvdevice {
public :
u32 ioctl ( u32 command , const std : : vector < u8 > & input , std : : vector < u8 > & output ) override {
VAddr nvmap : : GetObjectAddress ( u32 handle ) const {
auto itr = handles . find ( handle ) ;
ASSERT ( itr ! = handles . end ( ) ) ;
auto object = itr - > second ;
ASSERT ( object - > status = = Object : : Status : : Allocated ) ;
return object - > addr ;
}
u32 nvmap : : ioctl ( u32 command , const std : : vector < u8 > & input , std : : vector < u8 > & output ) {
switch ( command ) {
case IocCreateCommand :
return IocCreate ( input , output ) ;
@ -37,72 +44,7 @@ public:
ASSERT ( false , " Unimplemented " ) ;
}
private :
// Represents an nvmap object.
struct Object {
enum class Status { Created , Allocated } ;
u32 id ;
u32 size ;
u32 flags ;
u32 align ;
u8 kind ;
u64 addr ;
Status status ;
} ;
u32 next_handle = 1 ;
u32 next_id = 1 ;
std : : unordered_map < u32 , std : : shared_ptr < Object > > handles ;
enum IoctlCommands {
IocCreateCommand = 0xC0080101 ,
IocFromIdCommand = 0xC0080103 ,
IocAllocCommand = 0xC0200104 ,
IocParamCommand = 0xC00C0109 ,
IocGetIdCommand = 0xC008010E
} ;
struct IocCreateParams {
// Input
u32_le size ;
// Output
u32_le handle ;
} ;
struct IocAllocParams {
// Input
u32_le handle ;
u32_le heap_mask ;
u32_le flags ;
u32_le align ;
u8 kind ;
INSERT_PADDING_BYTES ( 7 ) ;
u64_le addr ;
} ;
struct IocGetIdParams {
// Output
u32_le id ;
// Input
u32_le handle ;
} ;
struct IocFromIdParams {
// Input
u32_le id ;
// Output
u32_le handle ;
} ;
struct IocParamParams {
// Input
u32_le handle ;
u32_le type ;
// Output
u32_le value ;
} ;
u32 IocCreate ( const std : : vector < u8 > & input , std : : vector < u8 > & output ) {
u32 nvmap : : IocCreate ( const std : : vector < u8 > & input , std : : vector < u8 > & output ) {
IocCreateParams params ;
std : : memcpy ( & params , input . data ( ) , sizeof ( params ) ) ;
@ -123,7 +65,7 @@ private:
return 0 ;
}
u32 IocAlloc( const std : : vector < u8 > & input , std : : vector < u8 > & output ) {
u32 nvmap : : IocAlloc( const std : : vector < u8 > & input , std : : vector < u8 > & output ) {
IocAllocParams params ;
std : : memcpy ( & params , input . data ( ) , sizeof ( params ) ) ;
@ -143,7 +85,7 @@ private:
return 0 ;
}
u32 IocGetId( const std : : vector < u8 > & input , std : : vector < u8 > & output ) {
u32 nvmap : : IocGetId( const std : : vector < u8 > & input , std : : vector < u8 > & output ) {
IocGetIdParams params ;
std : : memcpy ( & params , input . data ( ) , sizeof ( params ) ) ;
@ -158,7 +100,7 @@ private:
return 0 ;
}
u32 IocFromId( const std : : vector < u8 > & input , std : : vector < u8 > & output ) {
u32 nvmap : : IocFromId( const std : : vector < u8 > & input , std : : vector < u8 > & output ) {
IocFromIdParams params ;
std : : memcpy ( & params , input . data ( ) , sizeof ( params ) ) ;
@ -178,7 +120,7 @@ private:
return 0 ;
}
u32 IocParam( const std : : vector < u8 > & input , std : : vector < u8 > & output ) {
u32 nvmap : : IocParam( const std : : vector < u8 > & input , std : : vector < u8 > & output ) {
enum class ParamTypes { Size = 1 , Alignment = 2 , Base = 3 , Heap = 4 , Kind = 5 , Compr = 6 } ;
IocParamParams params ;
@ -213,7 +155,19 @@ private:
std : : memcpy ( output . data ( ) , & params , sizeof ( params ) ) ;
return 0 ;
}
} ;
u32 nvdisp_disp0 : : ioctl ( u32 command , const std : : vector < u8 > & input , std : : vector < u8 > & output ) {
ASSERT ( false , " Unimplemented " ) ;
return 0 ;
}
void nvdisp_disp0 : : flip ( u32 buffer_handle , u32 offset , u32 format , u32 width , u32 height ,
u32 stride ) {
VAddr addr = nvmap_dev - > GetObjectAddress ( buffer_handle ) ;
LOG_WARNING ( Service ,
" Drawing from address %llx offset %08X Width %u Height %u Stride %u Format %u " ,
addr , offset , width , height , stride , format ) ;
}
void NVDRV_A : : Open ( Kernel : : HLERequestContext & ctx ) {
LOG_WARNING ( Service , " (STUBBED) called " ) ;
@ -275,8 +229,10 @@ NVDRV_A::NVDRV_A() : ServiceFramework("nvdrv:a") {
} ;
RegisterHandlers ( functions ) ;
auto nvmap_dev = std : : make_shared < nvmap > ( ) ;
devices [ " /dev/nvhost-as-gpu " ] = std : : make_shared < nvhost_as_gpu > ( ) ;
devices [ " /dev/nvmap " ] = std : : make_shared < nvmap > ( ) ;
devices [ " /dev/nvmap " ] = nvmap_dev ;
devices [ " /dev/nvdisp_disp0 " ] = std : : make_shared < nvdisp_disp0 > ( nvmap_dev ) ;
}
} // namespace NVDRV