Path: blob/21.2-virgl/src/gbm/main/gbm_backend_abi.h
4564 views
/*1* Copyright © 2011 Intel Corporation2* Copyright © 2021 NVIDIA Corporation3*4* Permission is hereby granted, free of charge, to any person obtaining a5* copy of this software and associated documentation files (the "Software"),6* to deal in the Software without restriction, including without limitation7* the rights to use, copy, modify, merge, publish, distribute, sublicense,8* and/or sell copies of the Software, and to permit persons to whom the9* Software is furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice (including the next12* paragraph) shall be included in all copies or substantial portions of the13* Software.14*15* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,16* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF17* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND18* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT19* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,20* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,21* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER22* DEALINGS IN THE SOFTWARE.23*24* Authors:25* Benjamin Franzke <[email protected]>26* James Jones <[email protected]>27*/2829#ifndef GBM_BACKEND_ABI_H_30#define GBM_BACKEND_ABI_H_3132#include "gbm.h"3334/**35* \file gbm_backend_abi.h36* \brief ABI between the GBM loader and its backends37*/3839struct gbm_backend_desc;4041/**42* The GBM backend interface version defined by this file.43*44* The GBM device interface version must be incremented whenever the structures45* defined in this file are modified. To preserve ABI compatibility with46* backends that support only older versions, modifications to this file must47* consist only of appending new fields to the end of the structures defined in48* it, defining new structures, or declaring new exported functions or global49* variables.50*51* Note this version applies to ALL structures in this file, not just the core,52* backend, and device structures which contain it explicitly. Buffer objects,53* surfaces, and any other new structures introduced to this file are also part54* of the backend ABI. The ABI version of an instance of any object in this file55* is defined as the minimum of the version of the backend associated with the56* object instance and the loader's core object version. Hence, any new objects57* added to this file should contain either a reference to an existing object58* defined here, or an explicit version field.59*60* A few examples of object versions:61*62* Backend ABI version: 063* Core ABI version: 364* ABI version of a device created by the backend: 065*66* Backend ABI version: 267* Core ABI version: 168* ABI version of a surface created by a device from the backend: 169*70* Backend ABI version: 471* Core ABI version: 472* ABI version of a buffer object created by a device from the backend: 473*/74#define GBM_BACKEND_ABI_VERSION 07576/**77* GBM device interface corresponding to GBM_BACKEND_ABI_VERSION = 078*79* DO NOT MODIFY THIS STRUCT. Instead, introduce a gbm_bo_v1, increment80* GBM_BACKEND_ABI_VERSION, and append gbm_bo_v1 to gbm_bo.81*/82struct gbm_device_v0 {83const struct gbm_backend_desc *backend_desc;8485/**86* The version of the GBM backend interface supported by this device and its87* child objects. This may be less than the maximum version supported by the88* GBM loader if the device was created by an older backend, or less than the89* maximum version supported by the backend if the device was created by an90* older loader. In other words, this will be:91*92* MIN(backend GBM interface version, loader GBM interface version)93*94* It is the backend's responsibility to assign this field the value passed95* in by the GBM loader to the backend's create_device function. The GBM96* loader will pre-clamp the value based on the loader version and the97* version reported by the backend in its gbm_backend_v0::backend_version98* field. It is the loader's responsibility to respect this version when99* directly accessing a device instance or any child objects instantiated by100* a device instance.101*/102uint32_t backend_version;103104int fd;105const char *name;106107void (*destroy)(struct gbm_device *gbm);108int (*is_format_supported)(struct gbm_device *gbm,109uint32_t format,110uint32_t usage);111int (*get_format_modifier_plane_count)(struct gbm_device *device,112uint32_t format,113uint64_t modifier);114115struct gbm_bo *(*bo_create)(struct gbm_device *gbm,116uint32_t width, uint32_t height,117uint32_t format,118uint32_t usage,119const uint64_t *modifiers,120const unsigned int count);121struct gbm_bo *(*bo_import)(struct gbm_device *gbm, uint32_t type,122void *buffer, uint32_t usage);123void *(*bo_map)(struct gbm_bo *bo,124uint32_t x, uint32_t y,125uint32_t width, uint32_t height,126uint32_t flags, uint32_t *stride,127void **map_data);128void (*bo_unmap)(struct gbm_bo *bo, void *map_data);129int (*bo_write)(struct gbm_bo *bo, const void *buf, size_t data);130int (*bo_get_fd)(struct gbm_bo *bo);131int (*bo_get_planes)(struct gbm_bo *bo);132union gbm_bo_handle (*bo_get_handle)(struct gbm_bo *bo, int plane);133int (*bo_get_plane_fd)(struct gbm_bo *bo, int plane);134uint32_t (*bo_get_stride)(struct gbm_bo *bo, int plane);135uint32_t (*bo_get_offset)(struct gbm_bo *bo, int plane);136uint64_t (*bo_get_modifier)(struct gbm_bo *bo);137void (*bo_destroy)(struct gbm_bo *bo);138139struct gbm_surface *(*surface_create)(struct gbm_device *gbm,140uint32_t width, uint32_t height,141uint32_t format, uint32_t flags,142const uint64_t *modifiers,143const unsigned count);144struct gbm_bo *(*surface_lock_front_buffer)(struct gbm_surface *surface);145void (*surface_release_buffer)(struct gbm_surface *surface,146struct gbm_bo *bo);147int (*surface_has_free_buffers)(struct gbm_surface *surface);148void (*surface_destroy)(struct gbm_surface *surface);149};150151/**152* The device used for the memory allocation.153*154* The members of this structure should be not accessed directly155*156* To modify this structure, introduce a new gbm_device_v<N> structure, add it157* to the end of this structure, and increment GBM_BACKEND_ABI_VERSION.158*/159struct gbm_device {160/* Hack to make a gbm_device detectable by its first element. */161struct gbm_device *(*dummy)(int);162struct gbm_device_v0 v0;163};164165/**166* GBM buffer object interface corresponding to GBM_BACKEND_ABI_VERSION = 0167*168* DO NOT MODIFY THIS STRUCT. Instead, introduce a gbm_bo_v1, increment169* GBM_BACKEND_ABI_VERSION, and append gbm_bo_v1 to gbm_bo.170*/171struct gbm_bo_v0 {172uint32_t width;173uint32_t height;174uint32_t stride;175uint32_t format;176union gbm_bo_handle handle;177void *user_data;178void (*destroy_user_data)(struct gbm_bo *, void *);179};180181/**182* The allocated buffer object.183*184* The members in this structure should not be accessed directly.185*186* To modify this structure, introduce a new gbm_bo_v<N> structure, add it to187* the end of this structure, and increment GBM_BACKEND_ABI_VERSION.188*/189struct gbm_bo {190struct gbm_device *gbm;191struct gbm_bo_v0 v0;192};193194/**195* GBM surface interface corresponding to GBM_BACKEND_ABI_VERSION = 0196*197* DO NOT MODIFY THIS STRUCT. Instead, introduce a gbm_surface_v1, increment198* GBM_BACKEND_ABI_VERSION, and append gbm_surface_v1 to gbm_surface.199*/200struct gbm_surface_v0 {201uint32_t width;202uint32_t height;203uint32_t format;204uint32_t flags;205struct {206uint64_t *modifiers;207unsigned count;208};209};210211/**212* An allocated GBM surface.213*214* To modify this structure, introduce a new gbm_surface_v<N> structure, add it215* to the end of this structure, and increment GBM_BACKEND_ABI_VERSION.216*/217struct gbm_surface {218struct gbm_device *gbm;219struct gbm_surface_v0 v0;220};221222/**223* GBM backend interfaces corresponding to GBM_BACKEND_ABI_VERSION = 0224*225* DO NOT MODIFY THIS STRUCT. Instead, introduce a gbm_backend_v1, increment226* GBM_BACKEND_ABI_VERSION, append gbm_backend_v1 to gbm_backend.227*/228struct gbm_backend_v0 {229/**230* The version of the GBM backend interface supported by this backend. This231* is set by the backend itself, and may be greater or less than the version232* supported by the loader. It is the responsibility of the GBM loader to233* respect this version when accessing fields in this structure.234*/235uint32_t backend_version;236237const char *backend_name;238struct gbm_device *(*create_device)(int fd, uint32_t gbm_backend_version);239};240241/**242* The interface exposed by an external GBM backend.243*244* To modify this structure, introduce a new gbm_backend_v<N> structure, add it245* to the end of this structure, and increment GBM_BACKEND_ABI_VERSION.246*/247struct gbm_backend {248struct gbm_backend_v0 v0;249};250251/**252* GBM interfaces exposed to GBM backends at GBM_BACKEND_ABI_VERSION >= 0253*254* DO NOT MODIFY THIS STRUCT. Instead, introduce a gbm_core_v1, increment255* GBM_BACKEND_ABI_VERSION, and append gbm_core_v1 to gbm_backend.256*/257struct gbm_core_v0 {258/**259* The version of the GBM backend interface supported by the GBM loader. This260* is set by the loader, and may be greater or less than the version261* supported by a given backend. It is the responsibility of the backend to262* respect this version when accessing fields in this structure and other263* structures allocated or modified by the loader.264*/265uint32_t core_version;266267uint32_t (*format_canonicalize)(uint32_t gbm_format);268};269270/**271* The interface exposed by the GBM core/loader code to GBM backends.272*273* To modify this structure, introduce a new gbm_core_v<N> structure, add it274* to the end of this structure, and increment GBM_BACKEND_ABI_VERSION.275*/276struct gbm_core {277struct gbm_core_v0 v0;278};279280/**281* The entrypoint an external GBM backend exports.282*283* Prior to creating any devices using the backend, GBM will look up and call284* this function to request the backend's interface and convey the loader's285* version and exported interface to the backend.286*287* DO NOT MODIFY THIS FUNCTION NAME OR PROTOTYPE. It must remain unchanged to288* preserve backwards compatibility with existing GBM backends.289*/290#define GBM_GET_BACKEND_PROC gbmint_get_backend291#define _GBM_MKSTRX(s) _GBM_MKSTR(s)292#define _GBM_MKSTR(s) #s293#define GBM_GET_BACKEND_PROC_NAME _GBM_MKSTRX(GBM_GET_BACKEND_PROC)294typedef const struct gbm_backend *(*GBM_GET_BACKEND_PROC_PTR)(const struct gbm_core *gbm_core);295296#endif297298299