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