1/* $NetBSD: nouveau_core_enum.c,v 1.1.1.1 2014/08/06 12:36:23 riastradh Exp $ */
2
3/*
4 * Copyright (C) 2010 Nouveau Project
5 *
6 * All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining
9 * a copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sublicense, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
15 *
16 * The above copyright notice and this permission notice (including the
17 * next paragraph) shall be included in all copies or substantial
18 * portions of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
24 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 *
28 */
29
30#include <sys/cdefs.h>
31__KERNEL_RCSID(0, "$NetBSD: nouveau_core_enum.c,v 1.1.1.1 2014/08/06 12:36:23 riastradh Exp $");
32
33#include <core/os.h>
34#include <core/enum.h>
35
36const struct nouveau_enum *
37nouveau_enum_find(const struct nouveau_enum *en, u32 value)
38{
39 while (en->name) {
40 if (en->value == value)
41 return en;
42 en++;
43 }
44
45 return NULL;
46}
47
48const struct nouveau_enum *
49nouveau_enum_print(const struct nouveau_enum *en, u32 value)
50{
51 en = nouveau_enum_find(en, value);
52 if (en)
53 pr_cont("%s", en->name);
54 else
55 pr_cont("(unknown enum 0x%08x)", value);
56 return en;
57}
58
59void
60nouveau_bitfield_print(const struct nouveau_bitfield *bf, u32 value)
61{
62 while (bf->name) {
63 if (value & bf->mask) {
64 pr_cont(" %s", bf->name);
65 value &= ~bf->mask;
66 }
67
68 bf++;
69 }
70
71 if (value)
72 pr_cont(" (unknown bits 0x%08x)", value);
73}
74