nouveau/winsys: add the new winsys implementation
authorKarol Herbst <kherbst@redhat.com>
Tue, 17 May 2022 22:01:47 +0000 (00:01 +0200)
committerMarge Bot <emma+marge@anholt.net>
Fri, 4 Aug 2023 21:31:52 +0000 (21:31 +0000)
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24326>

src/nouveau/meson.build
src/nouveau/winsys/meson.build [new file with mode: 0644]
src/nouveau/winsys/nouveau_device.c [new file with mode: 0644]
src/nouveau/winsys/nouveau_device.h [new file with mode: 0644]
src/nouveau/winsys/nouveau_private.h [new file with mode: 0644]

index 07b914c..e8520b7 100644 (file)
 # SOFTWARE.
 
 subdir('compiler')
-if with_nouveau_vk
-  subdir('vulkan')
-endif
+subdir('winsys')
 if with_tools.contains('drm-shim')
   subdir('drm-shim')
 endif
 
 subdir('codegen')
+if with_nouveau_vk
+  subdir('vulkan')
+endif
diff --git a/src/nouveau/winsys/meson.build b/src/nouveau/winsys/meson.build
new file mode 100644 (file)
index 0000000..6204205
--- /dev/null
@@ -0,0 +1,23 @@
+libnouveau_ws = static_library(
+  'nouveau_ws',
+  [
+    'nouveau_device.h',
+    'nouveau_device.c',
+    'nouveau_private.h',
+  ],
+  include_directories : [
+    inc_include,
+    inc_src,
+  ],
+  c_args: [ '-Wno-gnu-variable-sized-type-not-at-end' ],
+  dependencies : [
+    dep_libdrm,
+    dep_libdrm_nouveau,
+  ],
+  gnu_symbol_visibility : 'hidden',
+)
+
+idep_nouveau_ws = declare_dependency(
+  link_with: libnouveau_ws,
+  include_directories : include_directories('.')
+)
diff --git a/src/nouveau/winsys/nouveau_device.c b/src/nouveau/winsys/nouveau_device.c
new file mode 100644 (file)
index 0000000..6e5da68
--- /dev/null
@@ -0,0 +1,80 @@
+#include "nouveau_device.h"
+
+#include <drm/drm.h>
+#include <nouveau/nouveau.h>
+#include <nouveau_drm.h>
+#include <nvif/cl0080.h>
+#include <nvif/class.h>
+
+#include <stddef.h>
+
+struct nouveau_ws_device_priv {
+   struct nouveau_ws_device base;
+   struct nouveau_drm *drm;
+   struct nouveau_device *dev;
+   int fd;
+};
+
+static struct nouveau_ws_device_priv *
+nouveau_ws_device(struct nouveau_ws_device *dev)
+{
+   return container_of(dev, struct nouveau_ws_device_priv, base);
+}
+
+struct nouveau_ws_device *
+nouveau_ws_device_new(int fd)
+{
+   struct nouveau_ws_device_priv *device = CALLOC_STRUCT(nouveau_ws_device_priv);
+   uint64_t device_id = 0;
+   struct nouveau_drm *drm;
+   struct nouveau_device *dev;
+
+   if (nouveau_drm_new(fd, &drm)) {
+      return NULL;
+   }
+
+   struct nv_device_v0 v0 = {
+      .device = ~0ULL,
+   };
+
+   if (nouveau_device_new(&drm->client, NV_DEVICE, &v0, sizeof(v0), &dev)) {
+      goto out_drm;
+   }
+
+   if (nouveau_getparam(dev, NOUVEAU_GETPARAM_PCI_DEVICE, &device_id)) {
+      goto out_dev;
+   }
+
+   device->base.vendor_id = 0x10de;
+   device->base.device_id = device_id;
+   device->base.chipset = dev->chipset;
+   device->base.vram_size = dev->vram_size;
+   device->base.gart_size = dev->gart_size;
+   device->base.is_integrated = dev->vram_size == 0;
+   device->drm = drm;
+   device->dev = dev;
+   device->fd = fd;
+
+   return &device->base;
+
+out_dev:
+   nouveau_device_del(&dev);
+out_drm:
+   nouveau_drm_del(&drm);
+   return NULL;
+}
+
+void
+nouveau_ws_device_destroy(struct nouveau_ws_device *device)
+{
+   if (!device)
+      return;
+
+   struct nouveau_ws_device_priv *priv = nouveau_ws_device(device);
+
+   nouveau_device_del(&priv->dev);
+   nouveau_drm_del(&priv->drm);
+   close(priv->fd);
+
+   FREE(priv);
+}
diff --git a/src/nouveau/winsys/nouveau_device.h b/src/nouveau/winsys/nouveau_device.h
new file mode 100644 (file)
index 0000000..2f0f522
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef NOUVEAU_DEVICE
+#define NOUVEAU_DEVICE 1
+
+#include "nouveau_private.h"
+
+struct nouveau_ws_device {
+   uint16_t vendor_id;
+   uint16_t device_id;
+   uint32_t chipset;
+   uint64_t vram_size;
+   uint64_t gart_size;
+   bool is_integrated;
+};
+
+struct nouveau_ws_device *nouveau_ws_device_new(int fd);
+void nouveau_ws_device_destroy(struct nouveau_ws_device *);
+
+#endif
diff --git a/src/nouveau/winsys/nouveau_private.h b/src/nouveau/winsys/nouveau_private.h
new file mode 100644 (file)
index 0000000..ec977d3
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef NOUVEAU_PRIVATE
+#define NOUVEAU_PRIVATE 1
+
+#include <stdint.h>
+
+#include "util/u_memory.h"
+
+#endif