xref: /linux/drivers/gpu/drm/xe/display/xe_dsb_buffer.c (revision 90d32e92011eaae8e70a9169b4e7acf4ca8f9d3a)
1 // SPDX-License-Identifier: MIT
2 /*
3  * Copyright 2023, Intel Corporation.
4  */
5 
6 #include "i915_drv.h"
7 #include "i915_vma.h"
8 #include "intel_display_types.h"
9 #include "intel_dsb_buffer.h"
10 #include "xe_bo.h"
11 #include "xe_gt.h"
12 
13 u32 intel_dsb_buffer_ggtt_offset(struct intel_dsb_buffer *dsb_buf)
14 {
15 	return xe_bo_ggtt_addr(dsb_buf->vma->bo);
16 }
17 
18 void intel_dsb_buffer_write(struct intel_dsb_buffer *dsb_buf, u32 idx, u32 val)
19 {
20 	iosys_map_wr(&dsb_buf->vma->bo->vmap, idx * 4, u32, val);
21 }
22 
23 u32 intel_dsb_buffer_read(struct intel_dsb_buffer *dsb_buf, u32 idx)
24 {
25 	return iosys_map_rd(&dsb_buf->vma->bo->vmap, idx * 4, u32);
26 }
27 
28 void intel_dsb_buffer_memset(struct intel_dsb_buffer *dsb_buf, u32 idx, u32 val, size_t size)
29 {
30 	WARN_ON(idx > (dsb_buf->buf_size - size) / sizeof(*dsb_buf->cmd_buf));
31 
32 	iosys_map_memset(&dsb_buf->vma->bo->vmap, idx * 4, val, size);
33 }
34 
35 bool intel_dsb_buffer_create(struct intel_crtc *crtc, struct intel_dsb_buffer *dsb_buf, size_t size)
36 {
37 	struct drm_i915_private *i915 = to_i915(crtc->base.dev);
38 	struct drm_i915_gem_object *obj;
39 	struct i915_vma *vma;
40 
41 	vma = kzalloc(sizeof(*vma), GFP_KERNEL);
42 	if (!vma)
43 		return false;
44 
45 	obj = xe_bo_create_pin_map(i915, xe_device_get_root_tile(i915),
46 				   NULL, PAGE_ALIGN(size),
47 				   ttm_bo_type_kernel,
48 				   XE_BO_FLAG_VRAM_IF_DGFX(xe_device_get_root_tile(i915)) |
49 				   XE_BO_FLAG_GGTT);
50 	if (IS_ERR(obj)) {
51 		kfree(vma);
52 		return false;
53 	}
54 
55 	vma->bo = obj;
56 	dsb_buf->vma = vma;
57 	dsb_buf->buf_size = size;
58 
59 	return true;
60 }
61 
62 void intel_dsb_buffer_cleanup(struct intel_dsb_buffer *dsb_buf)
63 {
64 	xe_bo_unpin_map_no_vm(dsb_buf->vma->bo);
65 	kfree(dsb_buf->vma);
66 }
67 
68 void intel_dsb_buffer_flush_map(struct intel_dsb_buffer *dsb_buf)
69 {
70 	/* TODO: add xe specific flush_map() for dsb buffer object. */
71 }
72