1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
/**************************************************************************
*
* Copyright 2015 Collabora
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
**************************************************************************/
#ifdef HAVE_LIBUDEV
#include <dlfcn.h>
#include <libudev.h>
#endif
#include "egldevice.h"
#include "eglglobals.h"
#include "egllog.h"
#include "egltypedefs.h"
typedef struct {
/* device list */
_EGLDevice *devices;
} _EGLDeviceInfo;
static _EGLDeviceInfo *
_eglEnsureDeviceInfo(void)
{
_EGLDeviceInfo *info;
mtx_lock(_eglGlobal.Mutex);
info = _eglGlobal.DeviceInfo;
if (!info) {
info = calloc(1, sizeof(_EGLDeviceInfo));
if (!info)
goto out;
info->devices = NULL;
_eglGlobal.DeviceInfo = info;
}
out:
mtx_unlock(_eglGlobal.Mutex);
return info;
}
/* TODO: this is all copied from loader.c. it should probably be put somewhere
* common so both there and here can use the same source. also, if it remains
* here, it needs a mutex.*/
#ifdef HAVE_LIBUDEV
static void *udev_handle = NULL;
static void *
udev_dlopen_handle(void)
{
if (!udev_handle) {
udev_handle = dlopen("libudev.so.1", RTLD_LOCAL | RTLD_LAZY);
if (!udev_handle) {
/* libudev.so.1 changed the return types of the two unref functions
* from voids to pointers. We don't use those return values, and the
* only ABI I've heard that cares about this kind of change (calling
* a function with a void * return that actually only returns void)
* might be ia64.
*/
udev_handle = dlopen("libudev.so.0", RTLD_LOCAL | RTLD_LAZY);
if (!udev_handle) {
_eglLog(_EGL_WARNING, "Couldn't dlopen libudev.so.1 or "
"libudev.so.0, device detection may be broken.\n");
}
}
}
return udev_handle;
}
static int dlsym_failed = 0;
static void *
checked_dlsym(void *dlopen_handle, const char *name)
{
void *result = dlsym(dlopen_handle, name);
if (!result)
dlsym_failed = 1;
return result;
}
#define UDEV_SYMBOL(ret, name, args) \
ret (*name) args = checked_dlsym(udev_dlopen_handle(), #name);
#endif /* HAVE_LIBUDEV */
/**
* Finish device management.
*/
void
_eglFiniDeviceInfo(void)
{
_EGLDeviceInfo *info;
_EGLDevice *device_list, *device;
/* atexit function is called with global mutex locked */
info = _eglGlobal.DeviceInfo;
if (!info)
return;
device_list = info->devices;
while (device_list) {
/* pop list head */
device = device_list;
device_list = device_list->Next;
free(device);
}
free(info);
_eglGlobal.DeviceInfo = NULL;
}
|