mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-06 11:38:05 +02:00
drmOpen/Close hacks to coalesce multiple drm opens
This commit is contained in:
parent
7e2e4a6b1a
commit
9621817253
2 changed files with 77 additions and 3 deletions
|
|
@ -687,4 +687,15 @@ extern int __glXGetInternalVersion(void);
|
|||
/* Get the unadjusted system time */
|
||||
extern int __glXGetUST( int64_t * ust );
|
||||
|
||||
/* KW: Temporary hacks to coalesce multiple opens of the same drm
|
||||
* instance. These should be renamed or moved to libdrm, or the
|
||||
* behaviour of drmOpen/drmClose should change.
|
||||
*/
|
||||
int drmOpenOnce(void *unused,
|
||||
const char *BusID,
|
||||
int *newlyopened);
|
||||
|
||||
void drmCloseOnce(int fd);
|
||||
|
||||
|
||||
#endif /* !__GLX_client_h__ */
|
||||
|
|
|
|||
|
|
@ -702,6 +702,68 @@ static const __DRIinterfaceMethods interface_methods = {
|
|||
glXGetMscRateOML,
|
||||
};
|
||||
|
||||
#define DRM_MAX_FDS 16
|
||||
static struct {
|
||||
char *BusID;
|
||||
int fd;
|
||||
int refcount;
|
||||
} connection[DRM_MAX_FDS];
|
||||
|
||||
static int nr_fds = 0;
|
||||
|
||||
int drmOpenOnce(void *unused,
|
||||
const char *BusID,
|
||||
int *newlyopened)
|
||||
{
|
||||
int i;
|
||||
int fd;
|
||||
|
||||
for (i = 0; i < nr_fds; i++)
|
||||
if (strcmp(BusID, connection[i].BusID) == 0) {
|
||||
connection[i].refcount++;
|
||||
*newlyopened = 0;
|
||||
return connection[i].fd;
|
||||
}
|
||||
|
||||
fd = drmOpen(unused, BusID);
|
||||
if (fd <= 0 || nr_fds == DRM_MAX_FDS)
|
||||
return fd;
|
||||
|
||||
connection[nr_fds].BusID = strdup(BusID);
|
||||
connection[nr_fds].fd = fd;
|
||||
connection[nr_fds].refcount = 1;
|
||||
*newlyopened = 1;
|
||||
|
||||
fprintf(stderr, "saved connection %d for %s %d\n",
|
||||
nr_fds, connection[nr_fds].BusID,
|
||||
strcmp(BusID, connection[nr_fds].BusID));
|
||||
|
||||
nr_fds++;
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
void drmCloseOnce(int fd)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
||||
|
||||
for (i = 0; i < nr_fds; i++) {
|
||||
if (fd == connection[i].fd) {
|
||||
if (--connection[i].refcount == 0) {
|
||||
drmClose(connection[i].fd);
|
||||
free(connection[i].BusID);
|
||||
|
||||
if (i < --nr_fds)
|
||||
connection[i] = connection[nr_fds];
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Perform the required libGL-side initialization and call the client-side
|
||||
|
|
@ -753,7 +815,8 @@ CallCreateNewScreen(Display *dpy, int scrn, __DRIscreen *psc,
|
|||
framebuffer.dev_priv = NULL;
|
||||
|
||||
if (XF86DRIOpenConnection(dpy, scrn, &hSAREA, &BusID)) {
|
||||
fd = drmOpen(NULL,BusID);
|
||||
int newlyopened;
|
||||
fd = drmOpenOnce(NULL,BusID, &newlyopened);
|
||||
Xfree(BusID); /* No longer needed */
|
||||
|
||||
err_msg = "open DRM";
|
||||
|
|
@ -780,7 +843,7 @@ CallCreateNewScreen(Display *dpy, int scrn, __DRIscreen *psc,
|
|||
}
|
||||
|
||||
err_msg = "XF86DRIAuthConnection";
|
||||
if (XF86DRIAuthConnection(dpy, scrn, magic)) {
|
||||
if (!newlyopened || XF86DRIAuthConnection(dpy, scrn, magic)) {
|
||||
char *driverName;
|
||||
|
||||
/*
|
||||
|
|
@ -884,7 +947,7 @@ CallCreateNewScreen(Display *dpy, int scrn, __DRIscreen *psc,
|
|||
}
|
||||
|
||||
if ( fd >= 0 ) {
|
||||
(void)drmClose(fd);
|
||||
(void)drmCloseOnce(fd);
|
||||
}
|
||||
|
||||
(void)XF86DRICloseConnection(dpy, scrn);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue