From 0d254831012a3d6e739eb097e0def026353942cf Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Mon, 30 Jan 2023 20:12:05 -0600 Subject: [PATCH] nouveau/winsys: Take a drmDevicePtr in nouveau_ws_device_new() Part-of: --- src/nouveau/mme/tests/mme_tu104_sim_hw_test.cpp | 11 +++------- src/nouveau/vulkan/nvk_physical_device.c | 26 +++--------------------- src/nouveau/winsys/nouveau_device.c | 27 +++++++++++++++---------- src/nouveau/winsys/nouveau_device.h | 4 +++- 4 files changed, 25 insertions(+), 43 deletions(-) diff --git a/src/nouveau/mme/tests/mme_tu104_sim_hw_test.cpp b/src/nouveau/mme/tests/mme_tu104_sim_hw_test.cpp index e01d2a1..01b12ae 100644 --- a/src/nouveau/mme/tests/mme_tu104_sim_hw_test.cpp +++ b/src/nouveau/mme/tests/mme_tu104_sim_hw_test.cpp @@ -40,7 +40,6 @@ public: uint32_t *data; private: - int fd; struct nouveau_ws_device *dev; struct nouveau_ws_context *ctx; struct nouveau_ws_bo *data_bo; @@ -50,7 +49,7 @@ private: }; mme_tu104_sim_test::mme_tu104_sim_test() : - data(NULL), fd(-1), dev(NULL), ctx(NULL), data_bo(NULL), push_bo(NULL) + data(NULL), dev(NULL), ctx(NULL), data_bo(NULL), push_bo(NULL) { memset(&push, 0, sizeof(push)); } @@ -65,7 +64,6 @@ mme_tu104_sim_test::~mme_tu104_sim_test() nouveau_ws_context_destroy(ctx); if (dev) nouveau_ws_device_destroy(dev); - close(fd); } #define PUSH_SIZE 64 * 4096 @@ -82,13 +80,10 @@ mme_tu104_sim_test::SetUp() if (devices[i]->available_nodes & 1 << DRM_NODE_RENDER && devices[i]->bustype == DRM_BUS_PCI && devices[i]->deviceinfo.pci->vendor_id == 0x10de) { - fd = open(devices[i]->nodes[DRM_NODE_RENDER], O_RDWR | O_CLOEXEC); - if (fd < 0) + dev = nouveau_ws_device_new(devices[i]); + if (dev == NULL) continue; - dev = nouveau_ws_device_new(fd); - ASSERT_TRUE(dev != NULL); - if (dev->cls_eng3d < TURING_A) { nouveau_ws_device_destroy(dev); dev = NULL; diff --git a/src/nouveau/vulkan/nvk_physical_device.c b/src/nouveau/vulkan/nvk_physical_device.c index 21929bf..9dea674 100644 --- a/src/nouveau/vulkan/nvk_physical_device.c +++ b/src/nouveau/vulkan/nvk_physical_device.c @@ -497,26 +497,11 @@ nvk_physical_device_try_create(struct nvk_instance *instance, drmDevicePtr drm_device, struct nvk_physical_device **device_out) { - // const char *primary_path = drm_device->nodes[DRM_NODE_PRIMARY]; - const char *path = drm_device->nodes[DRM_NODE_RENDER]; VkResult result; - int fd; - fd = open(path, O_RDWR | O_CLOEXEC); - if (fd < 0) { - if (errno == ENOMEM) { - return vk_errorf( - instance, VK_ERROR_OUT_OF_HOST_MEMORY, "Unable to open device %s: out of memory", path); - } - return vk_errorf( - instance, VK_ERROR_INCOMPATIBLE_DRIVER, "Unable to open device %s: %m", path); - } - - struct nouveau_ws_device *ndev = nouveau_ws_device_new(fd); - if (!ndev) { - result = vk_error(instance, VK_ERROR_INCOMPATIBLE_DRIVER); - goto fail_fd; - } + struct nouveau_ws_device *ndev = nouveau_ws_device_new(drm_device); + if (!ndev) + return vk_error(instance, VK_ERROR_INCOMPATIBLE_DRIVER); vk_warn_non_conformant_implementation("NVK"); @@ -596,7 +581,6 @@ nvk_physical_device_try_create(struct nvk_instance *instance, *device_out = device; - close(fd); return VK_SUCCESS; fail_init: @@ -606,10 +590,6 @@ fail_alloc: fail_dev_alloc: nouveau_ws_device_destroy(ndev); return result; - -fail_fd: - close(fd); - return result; } void diff --git a/src/nouveau/winsys/nouveau_device.c b/src/nouveau/winsys/nouveau_device.c index 9bb26fe..d509681 100644 --- a/src/nouveau/winsys/nouveau_device.c +++ b/src/nouveau/winsys/nouveau_device.c @@ -1,5 +1,7 @@ #include "nouveau_device.h" +#include +#include #include #include #include @@ -179,14 +181,17 @@ nouveau_ws_device_info(int fd, struct nouveau_ws_device *dev) } struct nouveau_ws_device * -nouveau_ws_device_new(int fd) +nouveau_ws_device_new(drmDevicePtr drm_device) { + const char *path = drm_device->nodes[DRM_NODE_RENDER]; struct nouveau_ws_device *device = CALLOC_STRUCT(nouveau_ws_device); uint64_t value = 0; - int dup_fd = os_dupfd_cloexec(fd); - drmVersionPtr ver; - ver = drmGetVersion(dup_fd); + int fd = open(path, O_RDWR | O_CLOEXEC); + if (fd < 0) + goto out_err; + + drmVersionPtr ver = drmGetVersion(fd); if (!ver) goto out_err; @@ -199,22 +204,22 @@ nouveau_ws_device_new(int fd) if (version < 0x01000301) goto out_err; - if (nouveau_ws_device_alloc(dup_fd, device)) + if (nouveau_ws_device_alloc(fd, device)) goto out_err; - if (nouveau_ws_device_info(dup_fd, device)) + if (nouveau_ws_device_info(fd, device)) goto out_err; - if (nouveau_ws_param(dup_fd, NOUVEAU_GETPARAM_PCI_DEVICE, &value)) + if (nouveau_ws_param(fd, NOUVEAU_GETPARAM_PCI_DEVICE, &value)) goto out_err; device->device_id = value; - if (nouveau_ws_param(dup_fd, NOUVEAU_GETPARAM_AGP_SIZE, &value)) + if (nouveau_ws_param(fd, NOUVEAU_GETPARAM_AGP_SIZE, &value)) goto out_err; os_get_available_system_memory(&device->gart_size); device->gart_size = MIN2(device->gart_size, value); - device->fd = dup_fd; + device->fd = fd; device->vendor_id = 0x10de; device->cm = sm_for_chipset(device->chipset); device->is_integrated = device->vram_size == 0; @@ -224,7 +229,7 @@ nouveau_ws_device_new(int fd) else device->local_mem_domain = NOUVEAU_GEM_DOMAIN_VRAM; - if (nouveau_ws_param(dup_fd, NOUVEAU_GETPARAM_GRAPH_UNITS, &value)) + if (nouveau_ws_param(fd, NOUVEAU_GETPARAM_GRAPH_UNITS, &value)) goto out_err; device->gpc_count = value & 0x000000ff; device->mp_count = value >> 8; @@ -247,7 +252,7 @@ nouveau_ws_device_new(int fd) out_err: FREE(device); - close(dup_fd); + close(fd); return NULL; } diff --git a/src/nouveau/winsys/nouveau_device.h b/src/nouveau/winsys/nouveau_device.h index 9833064..cfb04bd 100644 --- a/src/nouveau/winsys/nouveau_device.h +++ b/src/nouveau/winsys/nouveau_device.h @@ -5,6 +5,8 @@ #include +struct _drmDevice; + #ifdef __cplusplus extern "C" { #endif @@ -62,7 +64,7 @@ struct nouveau_ws_device { enum nvk_debug debug_flags; }; -struct nouveau_ws_device *nouveau_ws_device_new(int fd); +struct nouveau_ws_device *nouveau_ws_device_new(struct _drmDevice *drm_device); void nouveau_ws_device_destroy(struct nouveau_ws_device *); #ifdef __cplusplus -- 2.7.4