1 #include "pipe/p_defines.h"
2 #include "pipe/p_screen.h"
3 #include "pipe/p_state.h"
5 #include "util/u_memory.h"
6 #include "util/u_inlines.h"
7 #include "util/u_format.h"
8 #include "util/u_format_s3tc.h"
9 #include "util/u_string.h"
11 #include "os/os_time.h"
17 #include <nouveau_drm.h>
19 #include "nouveau_winsys.h"
20 #include "nouveau_screen.h"
21 #include "nouveau_context.h"
22 #include "nouveau_fence.h"
23 #include "nouveau_mm.h"
24 #include "nouveau_buffer.h"
26 /* XXX this should go away */
27 #include "state_tracker/drm_driver.h"
29 int nouveau_mesa_debug
= 0;
32 nouveau_screen_get_name(struct pipe_screen
*pscreen
)
34 struct nouveau_device
*dev
= nouveau_screen(pscreen
)->device
;
35 static char buffer
[128];
37 util_snprintf(buffer
, sizeof(buffer
), "NV%02X", dev
->chipset
);
42 nouveau_screen_get_vendor(struct pipe_screen
*pscreen
)
48 nouveau_screen_get_device_vendor(struct pipe_screen
*pscreen
)
54 nouveau_screen_get_timestamp(struct pipe_screen
*pscreen
)
56 int64_t cpu_time
= os_time_get() * 1000;
58 /* getparam of PTIMER_TIME takes about x10 as long (several usecs) */
60 return cpu_time
+ nouveau_screen(pscreen
)->cpu_gpu_time_delta
;
64 nouveau_screen_fence_ref(struct pipe_screen
*pscreen
,
65 struct pipe_fence_handle
**ptr
,
66 struct pipe_fence_handle
*pfence
)
68 nouveau_fence_ref(nouveau_fence(pfence
), (struct nouveau_fence
**)ptr
);
72 nouveau_screen_fence_finish(struct pipe_screen
*screen
,
73 struct pipe_fence_handle
*pfence
,
77 return nouveau_fence_signalled(nouveau_fence(pfence
));
79 return nouveau_fence_wait(nouveau_fence(pfence
), NULL
);
84 nouveau_screen_bo_from_handle(struct pipe_screen
*pscreen
,
85 struct winsys_handle
*whandle
,
88 struct nouveau_device
*dev
= nouveau_screen(pscreen
)->device
;
89 struct nouveau_bo
*bo
= 0;
92 if (whandle
->type
!= DRM_API_HANDLE_TYPE_SHARED
&&
93 whandle
->type
!= DRM_API_HANDLE_TYPE_FD
) {
94 debug_printf("%s: attempt to import unsupported handle type %d\n",
95 __FUNCTION__
, whandle
->type
);
99 if (whandle
->type
== DRM_API_HANDLE_TYPE_SHARED
)
100 ret
= nouveau_bo_name_ref(dev
, whandle
->handle
, &bo
);
102 ret
= nouveau_bo_prime_handle_ref(dev
, whandle
->handle
, &bo
);
105 debug_printf("%s: ref name 0x%08x failed with %d\n",
106 __FUNCTION__
, whandle
->handle
, ret
);
110 *out_stride
= whandle
->stride
;
116 nouveau_screen_bo_get_handle(struct pipe_screen
*pscreen
,
117 struct nouveau_bo
*bo
,
119 struct winsys_handle
*whandle
)
121 whandle
->stride
= stride
;
123 if (whandle
->type
== DRM_API_HANDLE_TYPE_SHARED
) {
124 return nouveau_bo_name_get(bo
, &whandle
->handle
) == 0;
125 } else if (whandle
->type
== DRM_API_HANDLE_TYPE_KMS
) {
126 whandle
->handle
= bo
->handle
;
128 } else if (whandle
->type
== DRM_API_HANDLE_TYPE_FD
) {
129 return nouveau_bo_set_prime(bo
, (int *)&whandle
->handle
) == 0;
136 nouveau_screen_init(struct nouveau_screen
*screen
, struct nouveau_device
*dev
)
138 struct pipe_screen
*pscreen
= &screen
->base
;
139 struct nv04_fifo nv04_data
= { .vram
= 0xbeef0201, .gart
= 0xbeef0202 };
140 struct nvc0_fifo nvc0_data
= { };
144 union nouveau_bo_config mm_config
;
146 char *nv_dbg
= getenv("NOUVEAU_MESA_DEBUG");
148 nouveau_mesa_debug
= atoi(nv_dbg
);
151 * this is initialized to 1 in nouveau_drm_screen_create after screen
152 * is fully constructed and added to the global screen list.
154 screen
->refcount
= -1;
156 if (dev
->chipset
< 0xc0) {
158 size
= sizeof(nv04_data
);
161 size
= sizeof(nvc0_data
);
165 * Set default VRAM domain if not overridden
167 if (!screen
->vram_domain
) {
168 if (dev
->vram_size
> 0)
169 screen
->vram_domain
= NOUVEAU_BO_VRAM
;
171 screen
->vram_domain
= NOUVEAU_BO_GART
;
174 ret
= nouveau_object_new(&dev
->object
, 0, NOUVEAU_FIFO_CHANNEL_CLASS
,
175 data
, size
, &screen
->channel
);
178 screen
->device
= dev
;
180 ret
= nouveau_client_new(screen
->device
, &screen
->client
);
183 ret
= nouveau_pushbuf_new(screen
->client
, screen
->channel
,
189 /* getting CPU time first appears to be more accurate */
190 screen
->cpu_gpu_time_delta
= os_time_get();
192 ret
= nouveau_getparam(dev
, NOUVEAU_GETPARAM_PTIMER_TIME
, &time
);
194 screen
->cpu_gpu_time_delta
= time
- screen
->cpu_gpu_time_delta
* 1000;
196 pscreen
->get_name
= nouveau_screen_get_name
;
197 pscreen
->get_vendor
= nouveau_screen_get_vendor
;
198 pscreen
->get_device_vendor
= nouveau_screen_get_device_vendor
;
200 pscreen
->get_timestamp
= nouveau_screen_get_timestamp
;
202 pscreen
->fence_reference
= nouveau_screen_fence_ref
;
203 pscreen
->fence_finish
= nouveau_screen_fence_finish
;
205 util_format_s3tc_init();
207 screen
->lowmem_bindings
= PIPE_BIND_GLOBAL
; /* gallium limit */
208 screen
->vidmem_bindings
=
209 PIPE_BIND_RENDER_TARGET
| PIPE_BIND_DEPTH_STENCIL
|
210 PIPE_BIND_DISPLAY_TARGET
| PIPE_BIND_SCANOUT
|
212 PIPE_BIND_SAMPLER_VIEW
|
213 PIPE_BIND_SHADER_BUFFER
| PIPE_BIND_SHADER_IMAGE
|
214 PIPE_BIND_COMPUTE_RESOURCE
|
216 screen
->sysmem_bindings
=
217 PIPE_BIND_SAMPLER_VIEW
| PIPE_BIND_STREAM_OUTPUT
|
218 PIPE_BIND_COMMAND_ARGS_BUFFER
;
220 memset(&mm_config
, 0, sizeof(mm_config
));
222 screen
->mm_GART
= nouveau_mm_create(dev
,
223 NOUVEAU_BO_GART
| NOUVEAU_BO_MAP
,
225 screen
->mm_VRAM
= nouveau_mm_create(dev
, NOUVEAU_BO_VRAM
, &mm_config
);
230 nouveau_screen_fini(struct nouveau_screen
*screen
)
232 nouveau_mm_destroy(screen
->mm_GART
);
233 nouveau_mm_destroy(screen
->mm_VRAM
);
235 nouveau_pushbuf_del(&screen
->pushbuf
);
237 nouveau_client_del(&screen
->client
);
238 nouveau_object_del(&screen
->channel
);
240 nouveau_device_del(&screen
->device
);
244 nouveau_set_debug_callback(struct pipe_context
*pipe
,
245 const struct pipe_debug_callback
*cb
)
247 struct nouveau_context
*context
= nouveau_context(pipe
);
250 context
->debug
= *cb
;
252 memset(&context
->debug
, 0, sizeof(context
->debug
));
256 nouveau_context_init(struct nouveau_context
*context
)
258 context
->pipe
.set_debug_callback
= nouveau_set_debug_callback
;