File Index
Files and directories
Sign in
FILE

drm_random.c

File preview with syntax highlighting.

linux-6.19.14/drivers/gpu/drm/lib/drm_random.c C
 1// SPDX-License-Identifier: GPL-2.0
 2#include <linux/bitops.h>
 3#include <linux/export.h>
 4#include <linux/kernel.h>
 5#include <linux/random.h>
 6#include <linux/slab.h>
 7#include <linux/types.h>
 8
 9#include "drm_random.h"
10
11u32 drm_prandom_u32_max_state(u32 ep_ro, struct rnd_state *state)
12{
13	return upper_32_bits((u64)prandom_u32_state(state) * ep_ro);
14}
15EXPORT_SYMBOL(drm_prandom_u32_max_state);
16
17void drm_random_reorder(unsigned int *order, unsigned int count,
18			struct rnd_state *state)
19{
20	unsigned int i, j;
21
22	for (i = 0; i < count; ++i) {
23		BUILD_BUG_ON(sizeof(unsigned int) > sizeof(u32));
24		j = drm_prandom_u32_max_state(count, state);
25		swap(order[i], order[j]);
26	}
27}
28EXPORT_SYMBOL(drm_random_reorder);
29
30unsigned int *drm_random_order(unsigned int count, struct rnd_state *state)
31{
32	unsigned int *order, i;
33
34	order = kmalloc_array(count, sizeof(*order), GFP_KERNEL);
35	if (!order)
36		return order;
37
38	for (i = 0; i < count; i++)
39		order[i] = i;
40
41	drm_random_reorder(order, count, state);
42	return order;
43}
44EXPORT_SYMBOL(drm_random_order);
~/ Read-only file preview.