freedreno/drm: Add fd_device_open() helper

Signed-off-by: Rob Clark <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14900>
This commit is contained in:
Rob Clark 2022-02-02 09:46:55 -08:00 committed by Marge Bot
parent 2bc815878c
commit 9ea36968d3
4 changed files with 19 additions and 9 deletions

View File

@ -236,11 +236,7 @@ main(int argc, char **argv)
}
}
int fd = drmOpenWithType("msm", NULL, DRM_NODE_RENDER);
if (fd < 0)
err(1, "could not open drm device");
struct fd_device *dev = fd_device_new(fd);
struct fd_device *dev = fd_device_open();
struct fd_pipe *pipe = fd_pipe_new(dev, FD_PIPE_3D);
const struct fd_dev_id *dev_id = fd_pipe_dev_id(pipe);

View File

@ -106,6 +106,20 @@ fd_device_new_dup(int fd)
return dev;
}
/* Convenience helper to open the drm device and return new fd_device:
*/
struct fd_device *
fd_device_open(void)
{
int fd;
fd = drmOpenWithType("msm", NULL, DRM_NODE_RENDER);
if (fd < 0)
return NULL;
return fd_device_new(fd);
}
struct fd_device *
fd_device_ref(struct fd_device *dev)
{

View File

@ -115,6 +115,7 @@ struct fd_fence {
struct fd_device *fd_device_new(int fd);
struct fd_device *fd_device_new_dup(int fd);
struct fd_device *fd_device_open(void);
struct fd_device *fd_device_ref(struct fd_device *dev);
void fd_device_purge(struct fd_device *dev);
void fd_device_del(struct fd_device *dev);

View File

@ -118,13 +118,12 @@ delta(uint32_t a, uint32_t b)
static void
find_device(void)
{
int ret, fd;
int ret;
fd = drmOpenWithType("msm", NULL, DRM_NODE_RENDER);
if (fd < 0)
dev.dev = fd_device_open();
if (!dev.dev)
err(1, "could not open drm device");
dev.dev = fd_device_new(fd);
dev.pipe = fd_pipe_new(dev.dev, FD_PIPE_3D);
uint64_t val;