gbm: Version the GBM backend interface
Define a version number for the interface GBM uses to offload work to its backends/drivers. Store the version in the backend interface structs provided to the loader by backends, as well as in the core interface struct provided to backends by the GBM loader code to backends. The backend can create structures of any version it supports, which can be greater or less than the interface version specified by GBM in the core interface structure. Hence, GBM will need to take care to check the backend version before accessing any members added to structs defined in gbm_backend_abi.h after this change. Similarly, the backend may need to check the interface version supported by the GBM library before passing back data in any structure members that require the GBM library to interact with them for correct operation. For example, if for some reason a structure defined in gbm_backend_abi.h gained a field which was a pointer to memory allocated by the backend and freed by GBM, the backend should avoid allocating this memory if the GBM library did not specify an interface version new enough to indicate that it was aware of the new structure member. Signed-off-by: James Jones <jajones@nvidia.com> Reviewed-by: Michel Dänzer <mdaenzer@redhat.com> Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9902>
This commit is contained in:
@@ -30,10 +30,12 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "backend.h"
|
||||
|
||||
#define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
|
||||
#define VER_MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
|
||||
extern const struct gbm_backend gbm_dri_backend;
|
||||
|
||||
@@ -51,15 +53,19 @@ find_backend(const char *name, int fd)
|
||||
{
|
||||
struct gbm_device *dev = NULL;
|
||||
unsigned i;
|
||||
uint32_t abi_ver;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(backends); ++i) {
|
||||
if (name && strcmp(backends[i].name, name))
|
||||
continue;
|
||||
|
||||
dev = backends[i].backend->create_device(fd);
|
||||
abi_ver = VER_MIN(GBM_BACKEND_ABI_VERSION,
|
||||
backends[i].backend->v0.backend_version);
|
||||
dev = backends[i].backend->v0.create_device(fd, abi_ver);
|
||||
|
||||
if (dev) {
|
||||
dev->backend_desc = &backends[i];
|
||||
assert(abi_ver == dev->v0.backend_version);
|
||||
dev->v0.backend_desc = &backends[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -96,5 +102,5 @@ _gbm_create_device(int fd)
|
||||
void
|
||||
_gbm_device_destroy(struct gbm_device *gbm)
|
||||
{
|
||||
gbm->destroy(gbm);
|
||||
gbm->v0.destroy(gbm);
|
||||
}
|
||||
|
Reference in New Issue
Block a user