1/* SPDX-License-Identifier: MIT */
2/*
3 * Copyright �� 2023 Intel Corporation
4 */
5
6#include <linux/types.h>
7#include <linux/build_bug.h>
8
9/* XX: Figure out how to handle this vma mapping in xe */
10struct intel_remapped_plane_info {
11	/* in gtt pages */
12	u32 offset:31;
13	u32 linear:1;
14	union {
15		/* in gtt pages for !linear */
16		struct {
17			u16 width;
18			u16 height;
19			u16 src_stride;
20			u16 dst_stride;
21		};
22
23		/* in gtt pages for linear */
24		u32 size;
25	};
26} __packed;
27
28struct intel_remapped_info {
29	struct intel_remapped_plane_info plane[4];
30	/* in gtt pages */
31	u32 plane_alignment;
32} __packed;
33
34struct intel_rotation_info {
35	struct intel_remapped_plane_info plane[2];
36} __packed;
37
38enum i915_gtt_view_type {
39	I915_GTT_VIEW_NORMAL = 0,
40	I915_GTT_VIEW_ROTATED = sizeof(struct intel_rotation_info),
41	I915_GTT_VIEW_REMAPPED = sizeof(struct intel_remapped_info),
42};
43
44static inline void assert_i915_gem_gtt_types(void)
45{
46	BUILD_BUG_ON(sizeof(struct intel_rotation_info) != 2 * sizeof(u32) + 8 * sizeof(u16));
47	BUILD_BUG_ON(sizeof(struct intel_remapped_info) != 5 * sizeof(u32) + 16 * sizeof(u16));
48
49	/* Check that rotation/remapped shares offsets for simplicity */
50	BUILD_BUG_ON(offsetof(struct intel_remapped_info, plane[0]) !=
51		     offsetof(struct intel_rotation_info, plane[0]));
52	BUILD_BUG_ON(offsetofend(struct intel_remapped_info, plane[1]) !=
53		     offsetofend(struct intel_rotation_info, plane[1]));
54
55	/* As we encode the size of each branch inside the union into its type,
56	 * we have to be careful that each branch has a unique size.
57	 */
58	switch ((enum i915_gtt_view_type)0) {
59	case I915_GTT_VIEW_NORMAL:
60	case I915_GTT_VIEW_ROTATED:
61	case I915_GTT_VIEW_REMAPPED:
62		/* gcc complains if these are identical cases */
63		break;
64	}
65}
66
67struct i915_gtt_view {
68	enum i915_gtt_view_type type;
69	union {
70		/* Members need to contain no holes/padding */
71		struct intel_rotation_info rotated;
72		struct intel_remapped_info remapped;
73	};
74};
75