xref: /linux/drivers/gpu/drm/i915/selftests/i915_random.h (revision 8dd06ef34b6e2f41b29fbf5fc1663780f2524285)
1953c7f82SChris Wilson /*
2953c7f82SChris Wilson  * Copyright © 2016 Intel Corporation
3953c7f82SChris Wilson  *
4953c7f82SChris Wilson  * Permission is hereby granted, free of charge, to any person obtaining a
5953c7f82SChris Wilson  * copy of this software and associated documentation files (the "Software"),
6953c7f82SChris Wilson  * to deal in the Software without restriction, including without limitation
7953c7f82SChris Wilson  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8953c7f82SChris Wilson  * and/or sell copies of the Software, and to permit persons to whom the
9953c7f82SChris Wilson  * Software is furnished to do so, subject to the following conditions:
10953c7f82SChris Wilson  *
11953c7f82SChris Wilson  * The above copyright notice and this permission notice (including the next
12953c7f82SChris Wilson  * paragraph) shall be included in all copies or substantial portions of the
13953c7f82SChris Wilson  * Software.
14953c7f82SChris Wilson  *
15953c7f82SChris Wilson  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16953c7f82SChris Wilson  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17953c7f82SChris Wilson  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18953c7f82SChris Wilson  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19953c7f82SChris Wilson  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20953c7f82SChris Wilson  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21953c7f82SChris Wilson  * IN THE SOFTWARE.
22953c7f82SChris Wilson  *
23953c7f82SChris Wilson  */
24953c7f82SChris Wilson 
25953c7f82SChris Wilson #ifndef __I915_SELFTESTS_RANDOM_H__
26953c7f82SChris Wilson #define __I915_SELFTESTS_RANDOM_H__
27953c7f82SChris Wilson 
28*ea38aa2eSYueHaibing #include <linux/math64.h>
29953c7f82SChris Wilson #include <linux/random.h>
30953c7f82SChris Wilson 
31953c7f82SChris Wilson #include "../i915_selftest.h"
32953c7f82SChris Wilson 
33953c7f82SChris Wilson #define I915_RND_STATE_INITIALIZER(x) ({				\
34953c7f82SChris Wilson 	struct rnd_state state__;					\
35953c7f82SChris Wilson 	prandom_seed_state(&state__, (x));				\
36953c7f82SChris Wilson 	state__;							\
37953c7f82SChris Wilson })
38953c7f82SChris Wilson 
39953c7f82SChris Wilson #define I915_RND_STATE(name__) \
40953c7f82SChris Wilson 	struct rnd_state name__ = I915_RND_STATE_INITIALIZER(i915_selftest.random_seed)
41953c7f82SChris Wilson 
42953c7f82SChris Wilson #define I915_RND_SUBSTATE(name__, parent__) \
43953c7f82SChris Wilson 	struct rnd_state name__ = I915_RND_STATE_INITIALIZER(prandom_u32_state(&(parent__)))
44953c7f82SChris Wilson 
4547979480SChris Wilson u64 i915_prandom_u64_state(struct rnd_state *rnd);
4647979480SChris Wilson 
i915_prandom_u32_max_state(u32 ep_ro,struct rnd_state * state)477ce5b685SChris Wilson static inline u32 i915_prandom_u32_max_state(u32 ep_ro, struct rnd_state *state)
487ce5b685SChris Wilson {
497ce5b685SChris Wilson 	return upper_32_bits(mul_u32_u32(prandom_u32_state(state), ep_ro));
507ce5b685SChris Wilson }
517ce5b685SChris Wilson 
52953c7f82SChris Wilson unsigned int *i915_random_order(unsigned int count,
53953c7f82SChris Wilson 				struct rnd_state *state);
54953c7f82SChris Wilson void i915_random_reorder(unsigned int *order,
55953c7f82SChris Wilson 			 unsigned int count,
56953c7f82SChris Wilson 			 struct rnd_state *state);
57953c7f82SChris Wilson 
588ba306a6SChris Wilson void i915_prandom_shuffle(void *arr, size_t elsz, size_t count,
598ba306a6SChris Wilson 			  struct rnd_state *state);
608ba306a6SChris Wilson 
61dfe324f3SChris Wilson u64 igt_random_offset(struct rnd_state *state,
62dfe324f3SChris Wilson 		      u64 start, u64 end,
63dfe324f3SChris Wilson 		      u64 len, u64 align);
64dfe324f3SChris Wilson 
65953c7f82SChris Wilson #endif /* !__I915_SELFTESTS_RANDOM_H__ */
66