1169691Skan/*
2169691Skan * Copyright �� 2016 Intel Corporation
3169691Skan *
4169691Skan * Permission is hereby granted, free of charge, to any person obtaining a
5169691Skan * copy of this software and associated documentation files (the "Software"),
6169691Skan * to deal in the Software without restriction, including without limitation
7169691Skan * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8169691Skan * and/or sell copies of the Software, and to permit persons to whom the
9169691Skan * Software is furnished to do so, subject to the following conditions:
10169691Skan *
11169691Skan * The above copyright notice and this permission notice (including the next
12169691Skan * paragraph) shall be included in all copies or substantial portions of the
13169691Skan * Software.
14169691Skan *
15169691Skan * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16169691Skan * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17169691Skan * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18169691Skan * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19169691Skan * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20169691Skan * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21169691Skan * IN THE SOFTWARE.
22169691Skan *
23169691Skan */
24169691Skan
25169691Skan#ifndef __I915_SELFTESTS_RANDOM_H__
26169691Skan#define __I915_SELFTESTS_RANDOM_H__
27169691Skan
28169691Skan#include <linux/math64.h>
29169691Skan#include <linux/random.h>
30169691Skan
31169691Skan#include "../i915_selftest.h"
32169691Skan
33169691Skan#define I915_RND_STATE_INITIALIZER(x) ({				\
34169691Skan	struct rnd_state state__;					\
35169691Skan	prandom_seed_state(&state__, (x));				\
36169691Skan	state__;							\
37169691Skan})
38169691Skan
39169691Skan#define I915_RND_STATE(name__) \
40169691Skan	struct rnd_state name__ = I915_RND_STATE_INITIALIZER(i915_selftest.random_seed)
41169691Skan
42169691Skan#define I915_RND_SUBSTATE(name__, parent__) \
43169691Skan	struct rnd_state name__ = I915_RND_STATE_INITIALIZER(prandom_u32_state(&(parent__)))
44169691Skan
45169691Skanu64 i915_prandom_u64_state(struct rnd_state *rnd);
46169691Skan
47169691Skanstatic inline u32 i915_prandom_u32_max_state(u32 ep_ro, struct rnd_state *state)
48169691Skan{
49169691Skan	return upper_32_bits(mul_u32_u32(prandom_u32_state(state), ep_ro));
50169691Skan}
51169691Skan
52169691Skanunsigned int *i915_random_order(unsigned int count,
53169691Skan				struct rnd_state *state);
54169691Skanvoid i915_random_reorder(unsigned int *order,
55169691Skan			 unsigned int count,
56169691Skan			 struct rnd_state *state);
57169691Skan
58169691Skanvoid i915_prandom_shuffle(void *arr, size_t elsz, size_t count,
59169691Skan			  struct rnd_state *state);
60169691Skan
61169691Skanu64 igt_random_offset(struct rnd_state *state,
62169691Skan		      u64 start, u64 end,
63169691Skan		      u64 len, u64 align);
64169691Skan
65169691Skan#endif /* !__I915_SELFTESTS_RANDOM_H__ */
66169691Skan