github.com/nicocha30/gvisor-ligolo@v0.0.0-20230726075806-989fa2c0a413/pkg/abi/nvgpu/frontend.go (about)

     1  // Copyright 2023 The gVisor Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package nvgpu
    16  
    17  // NV_IOCTL_MAGIC is the "canonical" IOC_TYPE for frontend ioctls.
    18  // The driver ignores IOC_TYPE, allowing any value to be passed.
    19  const NV_IOCTL_MAGIC = uint32('F')
    20  
    21  // Frontend ioctl numbers.
    22  // Note that these are only the IOC_NR part of the ioctl command.
    23  const (
    24  	// From kernel-open/common/inc/nv-ioctl-numbers.h:
    25  	NV_IOCTL_BASE            = 200
    26  	NV_ESC_CARD_INFO         = NV_IOCTL_BASE + 0
    27  	NV_ESC_REGISTER_FD       = NV_IOCTL_BASE + 1
    28  	NV_ESC_ALLOC_OS_EVENT    = NV_IOCTL_BASE + 6
    29  	NV_ESC_FREE_OS_EVENT     = NV_IOCTL_BASE + 7
    30  	NV_ESC_CHECK_VERSION_STR = NV_IOCTL_BASE + 10
    31  	NV_ESC_SYS_PARAMS        = NV_IOCTL_BASE + 14
    32  
    33  	// From kernel-open/common/inc/nv-ioctl-numa.h:
    34  	NV_ESC_NUMA_INFO = NV_IOCTL_BASE + 15
    35  
    36  	// From src/nvidia/arch/nvalloc/unix/include/nv_escape.h:
    37  	NV_ESC_RM_ALLOC_MEMORY               = 0x27
    38  	NV_ESC_RM_FREE                       = 0x29
    39  	NV_ESC_RM_CONTROL                    = 0x2a
    40  	NV_ESC_RM_ALLOC                      = 0x2b
    41  	NV_ESC_RM_DUP_OBJECT                 = 0x34
    42  	NV_ESC_RM_SHARE                      = 0x35
    43  	NV_ESC_RM_VID_HEAP_CONTROL           = 0x4a
    44  	NV_ESC_RM_MAP_MEMORY                 = 0x4e
    45  	NV_ESC_RM_UNMAP_MEMORY               = 0x4f
    46  	NV_ESC_RM_UPDATE_DEVICE_MAPPING_INFO = 0x5e
    47  )
    48  
    49  // Frontend ioctl parameter structs, from src/common/sdk/nvidia/inc/nvos.h or
    50  // kernel-open/common/inc/nv-ioctl.h.
    51  
    52  // IoctlRegisterFD is nv_ioctl_register_fd_t, the parameter type for
    53  // NV_ESC_REGISTER_FD.
    54  //
    55  // +marshal
    56  type IoctlRegisterFD struct {
    57  	CtlFD int32
    58  }
    59  
    60  // IoctlAllocOSEvent is nv_ioctl_alloc_os_event_t, the parameter type for
    61  // NV_ESC_ALLOC_OS_EVENT.
    62  //
    63  // +marshal
    64  type IoctlAllocOSEvent struct {
    65  	HClient Handle
    66  	HDevice Handle
    67  	FD      uint32
    68  	Status  uint32
    69  }
    70  
    71  // IoctlFreeOSEvent is nv_ioctl_free_os_event_t, the parameter type for
    72  // NV_ESC_FREE_OS_EVENT.
    73  //
    74  // +marshal
    75  type IoctlFreeOSEvent struct {
    76  	HClient Handle
    77  	HDevice Handle
    78  	FD      uint32
    79  	Status  uint32
    80  }
    81  
    82  // RMAPIVersion is nv_rm_api_version_t, the parameter type for
    83  // NV_ESC_CHECK_VERSION_STR.
    84  //
    85  // +marshal
    86  type RMAPIVersion struct {
    87  	Cmd           uint32
    88  	Reply         uint32
    89  	VersionString [64]byte
    90  }
    91  
    92  // IoctlSysParams is nv_ioctl_sys_params_t, the parameter type for
    93  // NV_ESC_SYS_PARAMS.
    94  //
    95  // +marshal
    96  type IoctlSysParams struct {
    97  	MemblockSize uint64
    98  }
    99  
   100  // IoctlNVOS02ParametersWithFD is nv_ioctl_nvos2_parameters_with_fd, the
   101  // parameter type for NV_ESC_RM_ALLOC_MEMORY.
   102  //
   103  // +marshal
   104  type IoctlNVOS02ParametersWithFD struct {
   105  	Params NVOS02Parameters
   106  	FD     int32
   107  	Pad0   [4]byte
   108  }
   109  
   110  // +marshal
   111  type NVOS02Parameters struct {
   112  	HRoot         Handle
   113  	HObjectParent Handle
   114  	HObjectNew    Handle
   115  	HClass        uint32
   116  	Flags         uint32
   117  	Pad0          [4]byte
   118  	PMemory       P64 // address of application mapping, without indirection
   119  	Limit         uint64
   120  	Status        uint32
   121  	Pad1          [4]byte
   122  }
   123  
   124  // NVOS00Parameters is NVOS00_PARAMETERS, the parameter type for
   125  // NV_ESC_RM_FREE.
   126  //
   127  // +marshal
   128  type NVOS00Parameters struct {
   129  	HRoot         Handle
   130  	HObjectParent Handle
   131  	HObjectOld    Handle
   132  	Status        uint32
   133  }
   134  
   135  // NVOS21Parameters is NVOS21_PARAMETERS, one possible parameter type for
   136  // NV_ESC_RM_ALLOC.
   137  //
   138  // +marshal
   139  type NVOS21Parameters struct {
   140  	HRoot         Handle
   141  	HObjectParent Handle
   142  	HObjectNew    Handle
   143  	HClass        uint32
   144  	PAllocParms   P64
   145  	Status        uint32
   146  	Pad0          [4]byte
   147  }
   148  
   149  // NVOS55Parameters is NVOS55_PARAMETERS, the parameter type for
   150  // NV_ESC_RM_DUP_OBJECT.
   151  //
   152  // +marshal
   153  type NVOS55Parameters struct {
   154  	HClient    Handle
   155  	HParent    Handle
   156  	HObject    Handle
   157  	HClientSrc Handle
   158  	HObjectSrc Handle
   159  	Flags      uint32
   160  	Status     uint32
   161  }
   162  
   163  // NVOS57Parameters is NVOS57_PARAMETERS, the parameter type for
   164  // NV_ESC_RM_SHARE.
   165  //
   166  // +marshal
   167  type NVOS57Parameters struct {
   168  	HClient     Handle
   169  	HObject     Handle
   170  	SharePolicy RS_SHARE_POLICY
   171  	Status      uint32
   172  }
   173  
   174  // NVOS32Parameters is NVOS32_PARAMETERS, the parameter type for
   175  // NV_ESC_RM_VID_HEAP_CONTROL.
   176  //
   177  // +marshal
   178  type NVOS32Parameters struct {
   179  	HRoot         Handle
   180  	HObjectParent Handle
   181  	Function      uint32
   182  	HVASpace      Handle
   183  	IVCHeapNumber int16
   184  	Pad           [2]byte
   185  	Status        uint32
   186  	Total         uint64
   187  	Free          uint64
   188  	Data          [144]byte // union
   189  }
   190  
   191  // Possible values for NVOS32Parameters.Function:
   192  const (
   193  	NVOS32_FUNCTION_ALLOC_SIZE = 2
   194  )
   195  
   196  // NVOS32AllocSize is the type of NVOS32Parameters.Data for
   197  // NVOS32_FUNCTION_ALLOC_SIZE.
   198  type NVOS32AllocSize struct {
   199  	Owner           uint32
   200  	HMemory         Handle
   201  	Type            uint32
   202  	Flags           uint32
   203  	Attr            uint32
   204  	Format          uint32
   205  	ComprCovg       uint32
   206  	ZcullCovg       uint32
   207  	PartitionStride uint32
   208  	Width           uint32
   209  	Height          uint32
   210  	Pad0            [4]byte
   211  	Size            uint64
   212  	Alignment       uint64
   213  	Offset          uint64
   214  	Limit           uint64
   215  	Address         P64
   216  	RangeBegin      uint64
   217  	RangeEnd        uint64
   218  	Attr2           uint32
   219  	CtagOffset      uint32
   220  }
   221  
   222  // IoctlNVOS33ParametersWithFD is nv_ioctl_nvos33_parameters_with_fd, the
   223  // parameter type for NV_ESC_RM_MAP_MEMORY, from
   224  // src/nvidia/arch/nvalloc/unix/include/nv-unix-nvos-params-wrappers.h.
   225  //
   226  // +marshal
   227  type IoctlNVOS33ParametersWithFD struct {
   228  	Params NVOS33Parameters
   229  	FD     int32
   230  	Pad0   [4]byte
   231  }
   232  
   233  // +marshal
   234  type NVOS33Parameters struct {
   235  	HClient        Handle
   236  	HDevice        Handle
   237  	HMemory        Handle
   238  	Pad0           [4]byte
   239  	Offset         uint64
   240  	Length         uint64
   241  	PLinearAddress P64 // address of application mapping, without indirection
   242  	Status         uint32
   243  	Flags          uint32
   244  }
   245  
   246  // NVOS34Parameters is NVOS34_PARAMETERS, the parameter type for
   247  // NV_ESC_RM_UNMAP_MEMORY.
   248  //
   249  // +marshal
   250  type NVOS34Parameters struct {
   251  	HClient        Handle
   252  	HDevice        Handle
   253  	HMemory        Handle
   254  	Pad0           [4]byte
   255  	PLinearAddress P64 // address of application mapping, without indirection
   256  	Status         uint32
   257  	Flags          uint32
   258  }
   259  
   260  // NVOS54Parameters is NVOS54_PARAMETERS, the parameter type for
   261  // NV_ESC_RM_CONTROL.
   262  //
   263  // +marshal
   264  type NVOS54Parameters struct {
   265  	HClient    Handle
   266  	HObject    Handle
   267  	Cmd        uint32
   268  	Flags      uint32
   269  	Params     P64
   270  	ParamsSize uint32
   271  	Status     uint32
   272  }
   273  
   274  // NVOS56Parameters is NVOS56_PARAMETERS, the parameter type for
   275  // NV_ESC_RM_UPDATE_DEVICE_MAPPING_INFO.
   276  //
   277  // +marshal
   278  type NVOS56Parameters struct {
   279  	HClient        Handle
   280  	HDevice        Handle
   281  	HMemory        Handle
   282  	Pad0           [4]byte
   283  	POldCPUAddress P64
   284  	PNewCPUAddress P64
   285  	Status         uint32
   286  	Pad1           [4]byte
   287  }
   288  
   289  // NVOS64Parameters is NVOS64_PARAMETERS, one possible parameter type for
   290  // NV_ESC_RM_ALLOC.
   291  //
   292  // +marshal
   293  type NVOS64Parameters struct {
   294  	HRoot            Handle
   295  	HObjectParent    Handle
   296  	HObjectNew       Handle
   297  	HClass           uint32
   298  	PAllocParms      P64
   299  	PRightsRequested P64
   300  	Flags            uint32
   301  	Status           uint32
   302  }
   303  
   304  // Frontend ioctl parameter struct sizes.
   305  var (
   306  	SizeofIoctlRegisterFD             = uint32((*IoctlRegisterFD)(nil).SizeBytes())
   307  	SizeofIoctlAllocOSEvent           = uint32((*IoctlAllocOSEvent)(nil).SizeBytes())
   308  	SizeofIoctlFreeOSEvent            = uint32((*IoctlFreeOSEvent)(nil).SizeBytes())
   309  	SizeofRMAPIVersion                = uint32((*RMAPIVersion)(nil).SizeBytes())
   310  	SizeofIoctlSysParams              = uint32((*IoctlSysParams)(nil).SizeBytes())
   311  	SizeofIoctlNVOS02ParametersWithFD = uint32((*IoctlNVOS02ParametersWithFD)(nil).SizeBytes())
   312  	SizeofNVOS00Parameters            = uint32((*NVOS00Parameters)(nil).SizeBytes())
   313  	SizeofNVOS21Parameters            = uint32((*NVOS21Parameters)(nil).SizeBytes())
   314  	SizeofIoctlNVOS33ParametersWithFD = uint32((*IoctlNVOS33ParametersWithFD)(nil).SizeBytes())
   315  	SizeofNVOS55Parameters            = uint32((*NVOS55Parameters)(nil).SizeBytes())
   316  	SizeofNVOS57Parameters            = uint32((*NVOS57Parameters)(nil).SizeBytes())
   317  	SizeofNVOS32Parameters            = uint32((*NVOS32Parameters)(nil).SizeBytes())
   318  	SizeofNVOS34Parameters            = uint32((*NVOS34Parameters)(nil).SizeBytes())
   319  	SizeofNVOS54Parameters            = uint32((*NVOS54Parameters)(nil).SizeBytes())
   320  	SizeofNVOS56Parameters            = uint32((*NVOS56Parameters)(nil).SizeBytes())
   321  	SizeofNVOS64Parameters            = uint32((*NVOS64Parameters)(nil).SizeBytes())
   322  )