summaryrefslogtreecommitdiff
path: root/drivers/gpu/drm/xe/xe_args.h
blob: 4dbc7e53c624815727ed1e474bd47b31e31dc046 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/* SPDX-License-Identifier: MIT */
/*
 * Copyright © 2024 Intel Corporation
 */

#ifndef _XE_ARGS_H_
#define _XE_ARGS_H_

#include <linux/args.h>

/*
 * Why don't the following macros have the XE prefix?
 *
 * Once we find more potential users outside of the Xe driver, we plan to move
 * all of the following macros unchanged to linux/args.h.
 */

/**
 * CALL_ARGS - Invoke a macro, but allow parameters to be expanded beforehand.
 * @f: name of the macro to invoke
 * @args: arguments for the macro
 *
 * This macro allows calling macros which names might generated or we want to
 * make sure it's arguments will be correctly expanded.
 *
 * Example:
 *
 *	#define foo	X,Y,Z,Q
 *	#define bar	COUNT_ARGS(foo)
 *	#define buz	CALL_ARGS(COUNT_ARGS, foo)
 *
 *	With above definitions bar expands to 1 while buz expands to 4.
 */
#define CALL_ARGS(f, args...)		__CALL_ARGS(f, args)
#define __CALL_ARGS(f, args...)		f(args)

/**
 * DROP_FIRST_ARG - Returns all arguments except the first one.
 * @args: arguments
 *
 * This helper macro allows manipulation the argument list before passing it
 * to the next level macro.
 *
 * Example:
 *
 *	#define foo	X,Y,Z,Q
 *	#define bar	CALL_ARGS(COUNT_ARGS, DROP_FIRST_ARG(foo))
 *
 *	With above definitions bar expands to 3.
 */
#define DROP_FIRST_ARG(args...)		__DROP_FIRST_ARG(args)
#define __DROP_FIRST_ARG(a, b...)	b

/**
 * FIRST_ARG - Returns the first argument.
 * @args: arguments
 *
 * This helper macro allows manipulation the argument list before passing it
 * to the next level macro.
 *
 * Example:
 *
 *	#define foo	X,Y,Z,Q
 *	#define bar	FIRST_ARG(foo)
 *
 *	With above definitions bar expands to X.
 */
#define FIRST_ARG(args...)		__FIRST_ARG(args)
#define __FIRST_ARG(a, b...)		a

/**
 * LAST_ARG - Returns the last argument.
 * @args: arguments
 *
 * This helper macro allows manipulation the argument list before passing it
 * to the next level macro.
 *
 * Like COUNT_ARGS() this macro works up to 12 arguments.
 *
 * Example:
 *
 *	#define foo	X,Y,Z,Q
 *	#define bar	LAST_ARG(foo)
 *
 *	With above definitions bar expands to Q.
 */
#define LAST_ARG(args...)		__LAST_ARG(args)
#define __LAST_ARG(args...)		PICK_ARG(COUNT_ARGS(args), args)

/**
 * PICK_ARG - Returns the n-th argument.
 * @n: argument number to be returned
 * @args: arguments
 *
 * This helper macro allows manipulation the argument list before passing it
 * to the next level macro.
 *
 * Like COUNT_ARGS() this macro supports n up to 12.
 * Specialized macros PICK_ARG1() to PICK_ARG12() are also available.
 *
 * Example:
 *
 *	#define foo	X,Y,Z,Q
 *	#define bar	PICK_ARG(2, foo)
 *	#define buz	PICK_ARG3(foo)
 *
 *	With above definitions bar expands to Y and buz expands to Z.
 */
#define PICK_ARG(n, args...)		__PICK_ARG(n, args)
#define __PICK_ARG(n, args...)		CALL_ARGS(CONCATENATE(PICK_ARG, n), args)
#define PICK_ARG1(args...)		FIRST_ARG(args)
#define PICK_ARG2(args...)		PICK_ARG1(DROP_FIRST_ARG(args))
#define PICK_ARG3(args...)		PICK_ARG2(DROP_FIRST_ARG(args))
#define PICK_ARG4(args...)		PICK_ARG3(DROP_FIRST_ARG(args))
#define PICK_ARG5(args...)		PICK_ARG4(DROP_FIRST_ARG(args))
#define PICK_ARG6(args...)		PICK_ARG5(DROP_FIRST_ARG(args))
#define PICK_ARG7(args...)		PICK_ARG6(DROP_FIRST_ARG(args))
#define PICK_ARG8(args...)		PICK_ARG7(DROP_FIRST_ARG(args))
#define PICK_ARG9(args...)		PICK_ARG8(DROP_FIRST_ARG(args))
#define PICK_ARG10(args...)		PICK_ARG9(DROP_FIRST_ARG(args))
#define PICK_ARG11(args...)		PICK_ARG10(DROP_FIRST_ARG(args))
#define PICK_ARG12(args...)		PICK_ARG11(DROP_FIRST_ARG(args))

/**
 * ARGS_SEP_COMMA - Definition of a comma character.
 *
 * This definition can be used in cases where any intermediate macro expects
 * fixed number of arguments, but we want to pass more arguments which can
 * be properly evaluated only by the next level macro.
 *
 * Example:
 *
 *	#define foo(f)	f(X) f(Y) f(Z) f(Q)
 *	#define bar	DROP_FIRST_ARG(foo(ARGS_SEP_COMMA __stringify))
 *	#define buz	CALL_ARGS(COUNT_ARGS, DROP_FIRST_ARG(foo(ARGS_SEP_COMMA)))
 *
 *	With above definitions bar expands to
 *		"X", "Y", "Z", "Q"
 *	and buz expands to 4.
 */
#define ARGS_SEP_COMMA			,

#endif