Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright © 2016 Intel Corporation
0003  *
0004  * Permission is hereby granted, free of charge, to any person obtaining a
0005  * copy of this software and associated documentation files (the "Software"),
0006  * to deal in the Software without restriction, including without limitation
0007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0008  * and/or sell copies of the Software, and to permit persons to whom the
0009  * Software is furnished to do so, subject to the following conditions:
0010  *
0011  * The above copyright notice and this permission notice (including the next
0012  * paragraph) shall be included in all copies or substantial portions of the
0013  * Software.
0014  *
0015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0016  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0017  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0018  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
0019  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
0020  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
0021  * IN THE SOFTWARE.
0022  *
0023  */
0024 
0025 #ifndef __I915_SELFTESTS_RANDOM_H__
0026 #define __I915_SELFTESTS_RANDOM_H__
0027 
0028 #include <linux/math64.h>
0029 #include <linux/random.h>
0030 
0031 #include "../i915_selftest.h"
0032 
0033 #define I915_RND_STATE_INITIALIZER(x) ({                \
0034     struct rnd_state state__;                   \
0035     prandom_seed_state(&state__, (x));              \
0036     state__;                            \
0037 })
0038 
0039 #define I915_RND_STATE(name__) \
0040     struct rnd_state name__ = I915_RND_STATE_INITIALIZER(i915_selftest.random_seed)
0041 
0042 #define I915_RND_SUBSTATE(name__, parent__) \
0043     struct rnd_state name__ = I915_RND_STATE_INITIALIZER(prandom_u32_state(&(parent__)))
0044 
0045 u64 i915_prandom_u64_state(struct rnd_state *rnd);
0046 
0047 static inline u32 i915_prandom_u32_max_state(u32 ep_ro, struct rnd_state *state)
0048 {
0049     return upper_32_bits(mul_u32_u32(prandom_u32_state(state), ep_ro));
0050 }
0051 
0052 unsigned int *i915_random_order(unsigned int count,
0053                 struct rnd_state *state);
0054 void i915_random_reorder(unsigned int *order,
0055              unsigned int count,
0056              struct rnd_state *state);
0057 
0058 void i915_prandom_shuffle(void *arr, size_t elsz, size_t count,
0059               struct rnd_state *state);
0060 
0061 u64 igt_random_offset(struct rnd_state *state,
0062               u64 start, u64 end,
0063               u64 len, u64 align);
0064 
0065 #endif /* !__I915_SELFTESTS_RANDOM_H__ */