-
-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
102 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# This file is part of Xpra. | ||
# Copyright (C) 2022 Antoine Martin <antoine@xpra.org> | ||
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any | ||
# later version. See the file COPYING for details. | ||
|
||
#cython: wraparound=False | ||
|
||
from xpra.os_util import bytestostr | ||
|
||
from xpra.log import Logger | ||
log = Logger("encoder", "evdi") | ||
|
||
cdef extern from "drm/drm.h": | ||
ctypedef unsigned int __kernel_size_t | ||
ctypedef struct drm_version: | ||
int version_major | ||
int version_minor | ||
int version_patchlevel | ||
__kernel_size_t name_len | ||
char *name | ||
__kernel_size_t date_len | ||
char *date | ||
__kernel_size_t desc_len | ||
char *desc | ||
ctypedef drm_version* drmVersionPtr | ||
|
||
cdef extern from "xf86drm.h": | ||
int DRM_NODE_PRIMARY | ||
ctypedef struct drmDevice: | ||
char **nodes #DRM_NODE_MAX sized array | ||
int available_nodes #DRM_NODE_* bitmask | ||
int bustype | ||
#union { | ||
#drmPciBusInfoPtr pci | ||
#drmUsbBusInfoPtr usb | ||
#drmPlatformBusInfoPtr platform | ||
#drmHost1xBusInfoPtr host1x | ||
#} businfo; | ||
#union { | ||
#drmPciDeviceInfoPtr pci | ||
#drmUsbDeviceInfoPtr usb | ||
#drmPlatformDeviceInfoPtr platform | ||
#drmHost1xDeviceInfoPtr host1x | ||
#} deviceinfo; | ||
ctypedef drmDevice* drmDevicePtr | ||
|
||
drmVersionPtr drmGetVersion(int fd) | ||
void drmFreeVersion(drmVersionPtr ver) | ||
|
||
int drmGetDevices(drmDevicePtr devices[], int max_devices) | ||
void drmFreeDevices(drmDevicePtr devices[], int count) | ||
|
||
cdef extern from "xf86drmMode.h": | ||
#drmModeResPtr drmModeGetResources(int fd) | ||
int drmIsKMS(int fd) | ||
|
||
def query(): | ||
info = {} | ||
cdef int count = drmGetDevices(NULL, 16) | ||
if count<0: | ||
log.error(f"Error querying drm devices: {count}") | ||
return info | ||
if count==0: | ||
log.warn("Warning: no drm devices found") | ||
return info | ||
cdef drmDevicePtr[16] devices | ||
count = drmGetDevices(devices, 16) | ||
assert 0<count<16 | ||
log(f"{count} drm devices found") | ||
cdef char *path | ||
cdef int fd | ||
cdef drmVersionPtr version | ||
for i in range(count): | ||
if not devices[i].available_nodes & (1 << DRM_NODE_PRIMARY): | ||
log(f"{i} is not primary") | ||
continue | ||
dev_info = info.setdefault(i, {}) | ||
path = devices[i].nodes[DRM_NODE_PRIMARY] | ||
log(f"{i} at {path}") | ||
dev_info["path"] = bytestostr(path) | ||
with open(path, "rb") as drm_device: | ||
fd = drm_device.fileno() | ||
kms = bool(drmIsKMS(fd)) | ||
dev_info["kms"] = kms | ||
version = drmGetVersion(fd) | ||
if version: | ||
dev_info.update({ | ||
"version" : (version.version_major, version.version_minor, version.version_patchlevel), | ||
"name" : bytestostr(version.name[:version.name_len]), | ||
"date" : bytestostr(version.date[:version.date_len]), | ||
"desc" : bytestostr(version.desc[:version.desc_len]), | ||
}) | ||
drmFreeVersion(version) | ||
#drmModeGetResources | ||
drmFreeDevices(devices, count) | ||
return info |