1bf215546Sopenharmony_ci#include "pipe/p_defines.h"
2bf215546Sopenharmony_ci#include "pipe/p_screen.h"
3bf215546Sopenharmony_ci#include "pipe/p_state.h"
4bf215546Sopenharmony_ci
5bf215546Sopenharmony_ci#include "util/u_memory.h"
6bf215546Sopenharmony_ci#include "util/u_inlines.h"
7bf215546Sopenharmony_ci#include "util/format/u_format.h"
8bf215546Sopenharmony_ci#include "util/format/u_format_s3tc.h"
9bf215546Sopenharmony_ci#include "util/u_string.h"
10bf215546Sopenharmony_ci
11bf215546Sopenharmony_ci#include "os/os_mman.h"
12bf215546Sopenharmony_ci#include "util/os_time.h"
13bf215546Sopenharmony_ci
14bf215546Sopenharmony_ci#include <stdio.h>
15bf215546Sopenharmony_ci#include <errno.h>
16bf215546Sopenharmony_ci#include <stdlib.h>
17bf215546Sopenharmony_ci
18bf215546Sopenharmony_ci#include <nouveau_drm.h>
19bf215546Sopenharmony_ci#include <xf86drm.h>
20bf215546Sopenharmony_ci
21bf215546Sopenharmony_ci#include "nouveau_winsys.h"
22bf215546Sopenharmony_ci#include "nouveau_screen.h"
23bf215546Sopenharmony_ci#include "nouveau_context.h"
24bf215546Sopenharmony_ci#include "nouveau_fence.h"
25bf215546Sopenharmony_ci#include "nouveau_mm.h"
26bf215546Sopenharmony_ci#include "nouveau_buffer.h"
27bf215546Sopenharmony_ci
28bf215546Sopenharmony_ci#include <compiler/glsl_types.h>
29bf215546Sopenharmony_ci
30bf215546Sopenharmony_ci/* XXX this should go away */
31bf215546Sopenharmony_ci#include "frontend/drm_driver.h"
32bf215546Sopenharmony_ci
33bf215546Sopenharmony_ci/* Even though GPUs might allow addresses with more bits, some engines do not.
34bf215546Sopenharmony_ci * Stick with 40 for compatibility.
35bf215546Sopenharmony_ci */
36bf215546Sopenharmony_ci#define NV_GENERIC_VM_LIMIT_SHIFT 39
37bf215546Sopenharmony_ci
38bf215546Sopenharmony_ciint nouveau_mesa_debug = 0;
39bf215546Sopenharmony_ci
40bf215546Sopenharmony_cistatic const char *
41bf215546Sopenharmony_cinouveau_screen_get_name(struct pipe_screen *pscreen)
42bf215546Sopenharmony_ci{
43bf215546Sopenharmony_ci   struct nouveau_screen *screen = nouveau_screen(pscreen);
44bf215546Sopenharmony_ci   return screen->chipset_name;
45bf215546Sopenharmony_ci}
46bf215546Sopenharmony_ci
47bf215546Sopenharmony_cistatic const char *
48bf215546Sopenharmony_cinouveau_screen_get_vendor(struct pipe_screen *pscreen)
49bf215546Sopenharmony_ci{
50bf215546Sopenharmony_ci   return "nouveau";
51bf215546Sopenharmony_ci}
52bf215546Sopenharmony_ci
53bf215546Sopenharmony_cistatic const char *
54bf215546Sopenharmony_cinouveau_screen_get_device_vendor(struct pipe_screen *pscreen)
55bf215546Sopenharmony_ci{
56bf215546Sopenharmony_ci   return "NVIDIA";
57bf215546Sopenharmony_ci}
58bf215546Sopenharmony_ci
59bf215546Sopenharmony_cistatic uint64_t
60bf215546Sopenharmony_cinouveau_screen_get_timestamp(struct pipe_screen *pscreen)
61bf215546Sopenharmony_ci{
62bf215546Sopenharmony_ci   int64_t cpu_time = os_time_get() * 1000;
63bf215546Sopenharmony_ci
64bf215546Sopenharmony_ci   /* getparam of PTIMER_TIME takes about x10 as long (several usecs) */
65bf215546Sopenharmony_ci
66bf215546Sopenharmony_ci   return cpu_time + nouveau_screen(pscreen)->cpu_gpu_time_delta;
67bf215546Sopenharmony_ci}
68bf215546Sopenharmony_ci
69bf215546Sopenharmony_cistatic struct disk_cache *
70bf215546Sopenharmony_cinouveau_screen_get_disk_shader_cache(struct pipe_screen *pscreen)
71bf215546Sopenharmony_ci{
72bf215546Sopenharmony_ci   return nouveau_screen(pscreen)->disk_shader_cache;
73bf215546Sopenharmony_ci}
74bf215546Sopenharmony_ci
75bf215546Sopenharmony_cistatic void
76bf215546Sopenharmony_cinouveau_screen_fence_ref(struct pipe_screen *pscreen,
77bf215546Sopenharmony_ci                         struct pipe_fence_handle **ptr,
78bf215546Sopenharmony_ci                         struct pipe_fence_handle *pfence)
79bf215546Sopenharmony_ci{
80bf215546Sopenharmony_ci   nouveau_fence_ref(nouveau_fence(pfence), (struct nouveau_fence **)ptr);
81bf215546Sopenharmony_ci}
82bf215546Sopenharmony_ci
83bf215546Sopenharmony_cistatic bool
84bf215546Sopenharmony_cinouveau_screen_fence_finish(struct pipe_screen *screen,
85bf215546Sopenharmony_ci                            struct pipe_context *ctx,
86bf215546Sopenharmony_ci                            struct pipe_fence_handle *pfence,
87bf215546Sopenharmony_ci                            uint64_t timeout)
88bf215546Sopenharmony_ci{
89bf215546Sopenharmony_ci   if (!timeout)
90bf215546Sopenharmony_ci      return nouveau_fence_signalled(nouveau_fence(pfence));
91bf215546Sopenharmony_ci
92bf215546Sopenharmony_ci   return nouveau_fence_wait(nouveau_fence(pfence), NULL);
93bf215546Sopenharmony_ci}
94bf215546Sopenharmony_ci
95bf215546Sopenharmony_ci
96bf215546Sopenharmony_cistruct nouveau_bo *
97bf215546Sopenharmony_cinouveau_screen_bo_from_handle(struct pipe_screen *pscreen,
98bf215546Sopenharmony_ci                              struct winsys_handle *whandle,
99bf215546Sopenharmony_ci                              unsigned *out_stride)
100bf215546Sopenharmony_ci{
101bf215546Sopenharmony_ci   struct nouveau_device *dev = nouveau_screen(pscreen)->device;
102bf215546Sopenharmony_ci   struct nouveau_bo *bo = NULL;
103bf215546Sopenharmony_ci   int ret;
104bf215546Sopenharmony_ci
105bf215546Sopenharmony_ci   if (whandle->offset != 0) {
106bf215546Sopenharmony_ci      debug_printf("%s: attempt to import unsupported winsys offset %d\n",
107bf215546Sopenharmony_ci                   __FUNCTION__, whandle->offset);
108bf215546Sopenharmony_ci      return NULL;
109bf215546Sopenharmony_ci   }
110bf215546Sopenharmony_ci
111bf215546Sopenharmony_ci   if (whandle->type != WINSYS_HANDLE_TYPE_SHARED &&
112bf215546Sopenharmony_ci       whandle->type != WINSYS_HANDLE_TYPE_FD) {
113bf215546Sopenharmony_ci      debug_printf("%s: attempt to import unsupported handle type %d\n",
114bf215546Sopenharmony_ci                   __FUNCTION__, whandle->type);
115bf215546Sopenharmony_ci      return NULL;
116bf215546Sopenharmony_ci   }
117bf215546Sopenharmony_ci
118bf215546Sopenharmony_ci   if (whandle->type == WINSYS_HANDLE_TYPE_SHARED)
119bf215546Sopenharmony_ci      ret = nouveau_bo_name_ref(dev, whandle->handle, &bo);
120bf215546Sopenharmony_ci   else
121bf215546Sopenharmony_ci      ret = nouveau_bo_prime_handle_ref(dev, whandle->handle, &bo);
122bf215546Sopenharmony_ci
123bf215546Sopenharmony_ci   if (ret) {
124bf215546Sopenharmony_ci      debug_printf("%s: ref name 0x%08x failed with %d\n",
125bf215546Sopenharmony_ci                   __FUNCTION__, whandle->handle, ret);
126bf215546Sopenharmony_ci      return NULL;
127bf215546Sopenharmony_ci   }
128bf215546Sopenharmony_ci
129bf215546Sopenharmony_ci   *out_stride = whandle->stride;
130bf215546Sopenharmony_ci   return bo;
131bf215546Sopenharmony_ci}
132bf215546Sopenharmony_ci
133bf215546Sopenharmony_ci
134bf215546Sopenharmony_cibool
135bf215546Sopenharmony_cinouveau_screen_bo_get_handle(struct pipe_screen *pscreen,
136bf215546Sopenharmony_ci                             struct nouveau_bo *bo,
137bf215546Sopenharmony_ci                             unsigned stride,
138bf215546Sopenharmony_ci                             struct winsys_handle *whandle)
139bf215546Sopenharmony_ci{
140bf215546Sopenharmony_ci   whandle->stride = stride;
141bf215546Sopenharmony_ci
142bf215546Sopenharmony_ci   if (whandle->type == WINSYS_HANDLE_TYPE_SHARED) {
143bf215546Sopenharmony_ci      return nouveau_bo_name_get(bo, &whandle->handle) == 0;
144bf215546Sopenharmony_ci   } else if (whandle->type == WINSYS_HANDLE_TYPE_KMS) {
145bf215546Sopenharmony_ci      whandle->handle = bo->handle;
146bf215546Sopenharmony_ci      return true;
147bf215546Sopenharmony_ci   } else if (whandle->type == WINSYS_HANDLE_TYPE_FD) {
148bf215546Sopenharmony_ci      return nouveau_bo_set_prime(bo, (int *)&whandle->handle) == 0;
149bf215546Sopenharmony_ci   } else {
150bf215546Sopenharmony_ci      return false;
151bf215546Sopenharmony_ci   }
152bf215546Sopenharmony_ci}
153bf215546Sopenharmony_ci
154bf215546Sopenharmony_cistatic void
155bf215546Sopenharmony_cinouveau_disk_cache_create(struct nouveau_screen *screen)
156bf215546Sopenharmony_ci{
157bf215546Sopenharmony_ci   struct mesa_sha1 ctx;
158bf215546Sopenharmony_ci   unsigned char sha1[20];
159bf215546Sopenharmony_ci   char cache_id[20 * 2 + 1];
160bf215546Sopenharmony_ci   uint64_t driver_flags = 0;
161bf215546Sopenharmony_ci
162bf215546Sopenharmony_ci   _mesa_sha1_init(&ctx);
163bf215546Sopenharmony_ci   if (!disk_cache_get_function_identifier(nouveau_disk_cache_create,
164bf215546Sopenharmony_ci                                           &ctx))
165bf215546Sopenharmony_ci      return;
166bf215546Sopenharmony_ci
167bf215546Sopenharmony_ci   _mesa_sha1_final(&ctx, sha1);
168bf215546Sopenharmony_ci   disk_cache_format_hex_id(cache_id, sha1, 20 * 2);
169bf215546Sopenharmony_ci
170bf215546Sopenharmony_ci   if (screen->prefer_nir)
171bf215546Sopenharmony_ci      driver_flags |= NOUVEAU_SHADER_CACHE_FLAGS_IR_NIR;
172bf215546Sopenharmony_ci   else
173bf215546Sopenharmony_ci      driver_flags |= NOUVEAU_SHADER_CACHE_FLAGS_IR_TGSI;
174bf215546Sopenharmony_ci
175bf215546Sopenharmony_ci   screen->disk_shader_cache =
176bf215546Sopenharmony_ci      disk_cache_create(nouveau_screen_get_name(&screen->base),
177bf215546Sopenharmony_ci                        cache_id, driver_flags);
178bf215546Sopenharmony_ci}
179bf215546Sopenharmony_ci
180bf215546Sopenharmony_cistatic void*
181bf215546Sopenharmony_cireserve_vma(uintptr_t start, uint64_t reserved_size)
182bf215546Sopenharmony_ci{
183bf215546Sopenharmony_ci   void *reserved = os_mmap((void*)start, reserved_size, PROT_NONE,
184bf215546Sopenharmony_ci                            MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
185bf215546Sopenharmony_ci   if (reserved == MAP_FAILED)
186bf215546Sopenharmony_ci      return NULL;
187bf215546Sopenharmony_ci   return reserved;
188bf215546Sopenharmony_ci}
189bf215546Sopenharmony_ci
190bf215546Sopenharmony_ciint
191bf215546Sopenharmony_cinouveau_screen_init(struct nouveau_screen *screen, struct nouveau_device *dev)
192bf215546Sopenharmony_ci{
193bf215546Sopenharmony_ci   struct pipe_screen *pscreen = &screen->base;
194bf215546Sopenharmony_ci   struct nv04_fifo nv04_data = { .vram = 0xbeef0201, .gart = 0xbeef0202 };
195bf215546Sopenharmony_ci   struct nvc0_fifo nvc0_data = { };
196bf215546Sopenharmony_ci   uint64_t time;
197bf215546Sopenharmony_ci   int size, ret;
198bf215546Sopenharmony_ci   void *data;
199bf215546Sopenharmony_ci   union nouveau_bo_config mm_config;
200bf215546Sopenharmony_ci
201bf215546Sopenharmony_ci   char *nv_dbg = getenv("NOUVEAU_MESA_DEBUG");
202bf215546Sopenharmony_ci   if (nv_dbg)
203bf215546Sopenharmony_ci      nouveau_mesa_debug = atoi(nv_dbg);
204bf215546Sopenharmony_ci
205bf215546Sopenharmony_ci   screen->prefer_nir = !debug_get_bool_option("NV50_PROG_USE_TGSI", false);
206bf215546Sopenharmony_ci
207bf215546Sopenharmony_ci   screen->force_enable_cl = debug_get_bool_option("NOUVEAU_ENABLE_CL", false);
208bf215546Sopenharmony_ci   if (screen->force_enable_cl)
209bf215546Sopenharmony_ci      glsl_type_singleton_init_or_ref();
210bf215546Sopenharmony_ci
211bf215546Sopenharmony_ci   screen->disable_fences = debug_get_bool_option("NOUVEAU_DISABLE_FENCES", false);
212bf215546Sopenharmony_ci
213bf215546Sopenharmony_ci   /* These must be set before any failure is possible, as the cleanup
214bf215546Sopenharmony_ci    * paths assume they're responsible for deleting them.
215bf215546Sopenharmony_ci    */
216bf215546Sopenharmony_ci   screen->drm = nouveau_drm(&dev->object);
217bf215546Sopenharmony_ci   screen->device = dev;
218bf215546Sopenharmony_ci
219bf215546Sopenharmony_ci   /*
220bf215546Sopenharmony_ci    * this is initialized to 1 in nouveau_drm_screen_create after screen
221bf215546Sopenharmony_ci    * is fully constructed and added to the global screen list.
222bf215546Sopenharmony_ci    */
223bf215546Sopenharmony_ci   screen->refcount = -1;
224bf215546Sopenharmony_ci
225bf215546Sopenharmony_ci   if (dev->chipset < 0xc0) {
226bf215546Sopenharmony_ci      data = &nv04_data;
227bf215546Sopenharmony_ci      size = sizeof(nv04_data);
228bf215546Sopenharmony_ci   } else {
229bf215546Sopenharmony_ci      data = &nvc0_data;
230bf215546Sopenharmony_ci      size = sizeof(nvc0_data);
231bf215546Sopenharmony_ci   }
232bf215546Sopenharmony_ci
233bf215546Sopenharmony_ci   bool enable_svm = debug_get_bool_option("NOUVEAU_SVM", false);
234bf215546Sopenharmony_ci   screen->has_svm = false;
235bf215546Sopenharmony_ci   /* we only care about HMM with OpenCL enabled */
236bf215546Sopenharmony_ci   if (dev->chipset > 0x130 && screen->force_enable_cl && enable_svm) {
237bf215546Sopenharmony_ci      /* Before being able to enable SVM we need to carve out some memory for
238bf215546Sopenharmony_ci       * driver bo allocations. Let's just base the size on the available VRAM.
239bf215546Sopenharmony_ci       *
240bf215546Sopenharmony_ci       * 40 bit is the biggest we care about and for 32 bit systems we don't
241bf215546Sopenharmony_ci       * want to allocate all of the available memory either.
242bf215546Sopenharmony_ci       *
243bf215546Sopenharmony_ci       * Also we align the size we want to reserve to the next POT to make use
244bf215546Sopenharmony_ci       * of hugepages.
245bf215546Sopenharmony_ci       */
246bf215546Sopenharmony_ci      const int vram_shift = util_logbase2_ceil64(dev->vram_size);
247bf215546Sopenharmony_ci      const int limit_bit =
248bf215546Sopenharmony_ci         MIN2(sizeof(void*) * 8 - 1, NV_GENERIC_VM_LIMIT_SHIFT);
249bf215546Sopenharmony_ci      screen->svm_cutout_size =
250bf215546Sopenharmony_ci         BITFIELD64_BIT(MIN2(sizeof(void*) == 4 ? 26 : NV_GENERIC_VM_LIMIT_SHIFT, vram_shift));
251bf215546Sopenharmony_ci
252bf215546Sopenharmony_ci      size_t start = screen->svm_cutout_size;
253bf215546Sopenharmony_ci      do {
254bf215546Sopenharmony_ci         screen->svm_cutout = reserve_vma(start, screen->svm_cutout_size);
255bf215546Sopenharmony_ci         if (!screen->svm_cutout) {
256bf215546Sopenharmony_ci            start += screen->svm_cutout_size;
257bf215546Sopenharmony_ci            continue;
258bf215546Sopenharmony_ci         }
259bf215546Sopenharmony_ci
260bf215546Sopenharmony_ci         struct drm_nouveau_svm_init svm_args = {
261bf215546Sopenharmony_ci            .unmanaged_addr = (uintptr_t)screen->svm_cutout,
262bf215546Sopenharmony_ci            .unmanaged_size = screen->svm_cutout_size,
263bf215546Sopenharmony_ci         };
264bf215546Sopenharmony_ci
265bf215546Sopenharmony_ci         ret = drmCommandWrite(screen->drm->fd, DRM_NOUVEAU_SVM_INIT,
266bf215546Sopenharmony_ci                               &svm_args, sizeof(svm_args));
267bf215546Sopenharmony_ci         screen->has_svm = !ret;
268bf215546Sopenharmony_ci         if (!screen->has_svm)
269bf215546Sopenharmony_ci            os_munmap(screen->svm_cutout, screen->svm_cutout_size);
270bf215546Sopenharmony_ci         break;
271bf215546Sopenharmony_ci      } while ((start + screen->svm_cutout_size) < BITFIELD64_MASK(limit_bit));
272bf215546Sopenharmony_ci   }
273bf215546Sopenharmony_ci
274bf215546Sopenharmony_ci   switch (dev->chipset) {
275bf215546Sopenharmony_ci   case 0x0ea: /* TK1, GK20A */
276bf215546Sopenharmony_ci   case 0x12b: /* TX1, GM20B */
277bf215546Sopenharmony_ci   case 0x13b: /* TX2, GP10B */
278bf215546Sopenharmony_ci      screen->tegra_sector_layout = true;
279bf215546Sopenharmony_ci      break;
280bf215546Sopenharmony_ci   default:
281bf215546Sopenharmony_ci      /* Xavier's GPU and everything else */
282bf215546Sopenharmony_ci      screen->tegra_sector_layout = false;
283bf215546Sopenharmony_ci      break;
284bf215546Sopenharmony_ci   }
285bf215546Sopenharmony_ci
286bf215546Sopenharmony_ci   /*
287bf215546Sopenharmony_ci    * Set default VRAM domain if not overridden
288bf215546Sopenharmony_ci    */
289bf215546Sopenharmony_ci   if (!screen->vram_domain) {
290bf215546Sopenharmony_ci      if (dev->vram_size > 0)
291bf215546Sopenharmony_ci         screen->vram_domain = NOUVEAU_BO_VRAM;
292bf215546Sopenharmony_ci      else
293bf215546Sopenharmony_ci         screen->vram_domain = NOUVEAU_BO_GART;
294bf215546Sopenharmony_ci   }
295bf215546Sopenharmony_ci
296bf215546Sopenharmony_ci   ret = nouveau_object_new(&dev->object, 0, NOUVEAU_FIFO_CHANNEL_CLASS,
297bf215546Sopenharmony_ci                            data, size, &screen->channel);
298bf215546Sopenharmony_ci   if (ret)
299bf215546Sopenharmony_ci      goto err;
300bf215546Sopenharmony_ci
301bf215546Sopenharmony_ci   ret = nouveau_client_new(screen->device, &screen->client);
302bf215546Sopenharmony_ci   if (ret)
303bf215546Sopenharmony_ci      goto err;
304bf215546Sopenharmony_ci   ret = nouveau_pushbuf_new(screen->client, screen->channel,
305bf215546Sopenharmony_ci                             4, 512 * 1024, 1,
306bf215546Sopenharmony_ci                             &screen->pushbuf);
307bf215546Sopenharmony_ci   if (ret)
308bf215546Sopenharmony_ci      goto err;
309bf215546Sopenharmony_ci
310bf215546Sopenharmony_ci   /* getting CPU time first appears to be more accurate */
311bf215546Sopenharmony_ci   screen->cpu_gpu_time_delta = os_time_get();
312bf215546Sopenharmony_ci
313bf215546Sopenharmony_ci   ret = nouveau_getparam(dev, NOUVEAU_GETPARAM_PTIMER_TIME, &time);
314bf215546Sopenharmony_ci   if (!ret)
315bf215546Sopenharmony_ci      screen->cpu_gpu_time_delta = time - screen->cpu_gpu_time_delta * 1000;
316bf215546Sopenharmony_ci
317bf215546Sopenharmony_ci   snprintf(screen->chipset_name, sizeof(screen->chipset_name), "NV%02X", dev->chipset);
318bf215546Sopenharmony_ci   pscreen->get_name = nouveau_screen_get_name;
319bf215546Sopenharmony_ci   pscreen->get_vendor = nouveau_screen_get_vendor;
320bf215546Sopenharmony_ci   pscreen->get_device_vendor = nouveau_screen_get_device_vendor;
321bf215546Sopenharmony_ci   pscreen->get_disk_shader_cache = nouveau_screen_get_disk_shader_cache;
322bf215546Sopenharmony_ci
323bf215546Sopenharmony_ci   pscreen->get_timestamp = nouveau_screen_get_timestamp;
324bf215546Sopenharmony_ci
325bf215546Sopenharmony_ci   pscreen->fence_reference = nouveau_screen_fence_ref;
326bf215546Sopenharmony_ci   pscreen->fence_finish = nouveau_screen_fence_finish;
327bf215546Sopenharmony_ci
328bf215546Sopenharmony_ci   nouveau_disk_cache_create(screen);
329bf215546Sopenharmony_ci
330bf215546Sopenharmony_ci   screen->transfer_pushbuf_threshold = 192;
331bf215546Sopenharmony_ci   screen->lowmem_bindings = PIPE_BIND_GLOBAL; /* gallium limit */
332bf215546Sopenharmony_ci   screen->vidmem_bindings =
333bf215546Sopenharmony_ci      PIPE_BIND_RENDER_TARGET | PIPE_BIND_DEPTH_STENCIL |
334bf215546Sopenharmony_ci      PIPE_BIND_DISPLAY_TARGET | PIPE_BIND_SCANOUT |
335bf215546Sopenharmony_ci      PIPE_BIND_CURSOR |
336bf215546Sopenharmony_ci      PIPE_BIND_SAMPLER_VIEW |
337bf215546Sopenharmony_ci      PIPE_BIND_SHADER_BUFFER | PIPE_BIND_SHADER_IMAGE |
338bf215546Sopenharmony_ci      PIPE_BIND_COMPUTE_RESOURCE |
339bf215546Sopenharmony_ci      PIPE_BIND_GLOBAL;
340bf215546Sopenharmony_ci   screen->sysmem_bindings =
341bf215546Sopenharmony_ci      PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_STREAM_OUTPUT |
342bf215546Sopenharmony_ci      PIPE_BIND_COMMAND_ARGS_BUFFER;
343bf215546Sopenharmony_ci
344bf215546Sopenharmony_ci   memset(&mm_config, 0, sizeof(mm_config));
345bf215546Sopenharmony_ci
346bf215546Sopenharmony_ci   screen->mm_GART = nouveau_mm_create(dev,
347bf215546Sopenharmony_ci                                       NOUVEAU_BO_GART | NOUVEAU_BO_MAP,
348bf215546Sopenharmony_ci                                       &mm_config);
349bf215546Sopenharmony_ci   screen->mm_VRAM = nouveau_mm_create(dev, NOUVEAU_BO_VRAM, &mm_config);
350bf215546Sopenharmony_ci   return 0;
351bf215546Sopenharmony_ci
352bf215546Sopenharmony_cierr:
353bf215546Sopenharmony_ci   if (screen->svm_cutout)
354bf215546Sopenharmony_ci      os_munmap(screen->svm_cutout, screen->svm_cutout_size);
355bf215546Sopenharmony_ci   return ret;
356bf215546Sopenharmony_ci}
357bf215546Sopenharmony_ci
358bf215546Sopenharmony_civoid
359bf215546Sopenharmony_cinouveau_screen_fini(struct nouveau_screen *screen)
360bf215546Sopenharmony_ci{
361bf215546Sopenharmony_ci   int fd = screen->drm->fd;
362bf215546Sopenharmony_ci
363bf215546Sopenharmony_ci   if (screen->force_enable_cl)
364bf215546Sopenharmony_ci      glsl_type_singleton_decref();
365bf215546Sopenharmony_ci   if (screen->has_svm)
366bf215546Sopenharmony_ci      os_munmap(screen->svm_cutout, screen->svm_cutout_size);
367bf215546Sopenharmony_ci
368bf215546Sopenharmony_ci   nouveau_mm_destroy(screen->mm_GART);
369bf215546Sopenharmony_ci   nouveau_mm_destroy(screen->mm_VRAM);
370bf215546Sopenharmony_ci
371bf215546Sopenharmony_ci   nouveau_pushbuf_del(&screen->pushbuf);
372bf215546Sopenharmony_ci
373bf215546Sopenharmony_ci   nouveau_client_del(&screen->client);
374bf215546Sopenharmony_ci   nouveau_object_del(&screen->channel);
375bf215546Sopenharmony_ci
376bf215546Sopenharmony_ci   nouveau_device_del(&screen->device);
377bf215546Sopenharmony_ci   nouveau_drm_del(&screen->drm);
378bf215546Sopenharmony_ci   close(fd);
379bf215546Sopenharmony_ci
380bf215546Sopenharmony_ci   disk_cache_destroy(screen->disk_shader_cache);
381bf215546Sopenharmony_ci}
382bf215546Sopenharmony_ci
383bf215546Sopenharmony_cistatic void
384bf215546Sopenharmony_cinouveau_set_debug_callback(struct pipe_context *pipe,
385bf215546Sopenharmony_ci                           const struct util_debug_callback *cb)
386bf215546Sopenharmony_ci{
387bf215546Sopenharmony_ci   struct nouveau_context *context = nouveau_context(pipe);
388bf215546Sopenharmony_ci
389bf215546Sopenharmony_ci   if (cb)
390bf215546Sopenharmony_ci      context->debug = *cb;
391bf215546Sopenharmony_ci   else
392bf215546Sopenharmony_ci      memset(&context->debug, 0, sizeof(context->debug));
393bf215546Sopenharmony_ci}
394bf215546Sopenharmony_ci
395bf215546Sopenharmony_civoid
396bf215546Sopenharmony_cinouveau_context_init(struct nouveau_context *context)
397bf215546Sopenharmony_ci{
398bf215546Sopenharmony_ci   context->pipe.set_debug_callback = nouveau_set_debug_callback;
399bf215546Sopenharmony_ci}
400