Path: blob/21.2-virgl/src/gallium/winsys/kmsro/drm/kmsro_drm_winsys.c
4566 views
/*1* Copyright (C) 2016 Christian Gmeiner <[email protected]>2* Copyright (C) 2017 Broadcom3*4* Permission is hereby granted, free of charge, to any person obtaining a5* copy of this software and associated documentation files (the "Software"),6* to deal in the Software without restriction, including without limitation7* the rights to use, copy, modify, merge, publish, distribute, sublicense,8* and/or sell copies of the Software, and to permit persons to whom the9* Software is furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice (including the next12* paragraph) shall be included in all copies or substantial portions of the13* Software.14*15* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL18* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER19* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,20* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE21* SOFTWARE.22*/2324#include <fcntl.h>25#include <unistd.h>2627#include "kmsro_drm_public.h"28#include "v3d/drm/v3d_drm_public.h"29#include "vc4/drm/vc4_drm_public.h"30#include "etnaviv/drm/etnaviv_drm_public.h"31#include "freedreno/drm/freedreno_drm_public.h"32#include "panfrost/drm/panfrost_drm_public.h"33#include "lima/drm/lima_drm_public.h"34#include "xf86drm.h"3536#include "pipe/p_screen.h"37#include "renderonly/renderonly.h"38#include "util/u_memory.h"3940static void kmsro_ro_destroy(struct renderonly *ro)41{42if (ro->gpu_fd >= 0)43close(ro->gpu_fd);4445FREE(ro);46}4748struct pipe_screen *kmsro_drm_screen_create(int fd,49const struct pipe_screen_config *config)50{51struct pipe_screen *screen = NULL;52struct renderonly *ro = CALLOC_STRUCT(renderonly);5354if (!ro)55return NULL;5657ro->kms_fd = fd;58ro->gpu_fd = -1;59ro->destroy = kmsro_ro_destroy;6061#if defined(GALLIUM_VC4)62ro->gpu_fd = drmOpenWithType("vc4", NULL, DRM_NODE_RENDER);63if (ro->gpu_fd >= 0) {64/* Passes the vc4-allocated BO through to the KMS-only DRM device using65* PRIME buffer sharing. The VC4 BO must be linear, which the SCANOUT66* flag on allocation will have ensured.67*/68ro->create_for_resource = renderonly_create_gpu_import_for_resource;69screen = vc4_drm_screen_create_renderonly(ro, config);70if (!screen)71goto out_free;7273return screen;74}75#endif7677#if defined(GALLIUM_ETNAVIV)78ro->gpu_fd = drmOpenWithType("etnaviv", NULL, DRM_NODE_RENDER);79if (ro->gpu_fd >= 0) {80ro->create_for_resource = renderonly_create_kms_dumb_buffer_for_resource;81screen = etna_drm_screen_create_renderonly(ro);82if (!screen)83goto out_free;8485return screen;86}87#endif8889#if defined(GALLIUM_FREEDRENO)90ro->gpu_fd = drmOpenWithType("msm", NULL, DRM_NODE_RENDER);91if (ro->gpu_fd >= 0) {92ro->create_for_resource = renderonly_create_kms_dumb_buffer_for_resource;93screen = fd_drm_screen_create(ro->gpu_fd, ro);94if (!screen)95goto out_free;9697return screen;98}99#endif100101#if defined(GALLIUM_PANFROST)102ro->gpu_fd = drmOpenWithType("panfrost", NULL, DRM_NODE_RENDER);103104if (ro->gpu_fd >= 0) {105ro->create_for_resource = renderonly_create_kms_dumb_buffer_for_resource;106screen = panfrost_drm_screen_create_renderonly(ro);107if (!screen)108goto out_free;109110return screen;111}112#endif113114#if defined(GALLIUM_LIMA)115ro->gpu_fd = drmOpenWithType("lima", NULL, DRM_NODE_RENDER);116if (ro->gpu_fd >= 0) {117ro->create_for_resource = renderonly_create_kms_dumb_buffer_for_resource;118screen = lima_drm_screen_create_renderonly(ro);119if (!screen)120goto out_free;121122return screen;123}124#endif125126#if defined(GALLIUM_V3D)127ro->gpu_fd = drmOpenWithType("v3d", NULL, DRM_NODE_RENDER);128if (ro->gpu_fd >= 0) {129ro->create_for_resource = renderonly_create_kms_dumb_buffer_for_resource;130screen = v3d_drm_screen_create_renderonly(ro, config);131if (!screen)132goto out_free;133134return screen;135}136#endif137138return screen;139140out_free:141if (ro->gpu_fd >= 0)142close(ro->gpu_fd);143FREE(ro);144145return NULL;146}147148149