qed: Fix static checker warning
[linux/fpc-iii.git] / tools / perf / trace / beauty / ioctl.c
blob1be3b4cf082708194ca7c4c8403219eedb924c3d
1 /*
2 * trace/beauty/ioctl.c
4 * Copyright (C) 2017, Red Hat Inc, Arnaldo Carvalho de Melo <acme@redhat.com>
6 * Released under the GPL v2. (and only v2, not any later version)
7 */
9 #include "trace/beauty/beauty.h"
10 #include <linux/kernel.h>
13 * FIXME: to support all arches we have to improve this, for
14 * now, to build on older systems without things like TIOCGEXCL,
15 * get it directly from our copy.
17 * Right now only x86 is being supported for beautifying ioctl args
18 * in 'perf trace', see tools/perf/trace/beauty/Build and builtin-trace.c
20 #include <uapi/asm-generic/ioctls.h>
22 static size_t ioctl__scnprintf_tty_cmd(int nr, int dir, char *bf, size_t size)
24 static const char *ioctl_tty_cmd[] = {
25 "TCGETS", "TCSETS", "TCSETSW", "TCSETSF", "TCGETA", "TCSETA", "TCSETAW",
26 "TCSETAF", "TCSBRK", "TCXONC", "TCFLSH", "TIOCEXCL", "TIOCNXCL", "TIOCSCTTY",
27 "TIOCGPGRP", "TIOCSPGRP", "TIOCOUTQ", "TIOCSTI", "TIOCGWINSZ", "TIOCSWINSZ",
28 "TIOCMGET", "TIOCMBIS", "TIOCMBIC", "TIOCMSET", "TIOCGSOFTCAR", "TIOCSSOFTCAR",
29 "FIONREAD", "TIOCLINUX", "TIOCCONS", "TIOCGSERIAL", "TIOCSSERIAL", "TIOCPKT",
30 "FIONBIO", "TIOCNOTTY", "TIOCSETD", "TIOCGETD", "TCSBRKP",
31 [_IOC_NR(TIOCSBRK)] = "TIOCSBRK", "TIOCCBRK", "TIOCGSID", "TCGETS2", "TCSETS2",
32 "TCSETSW2", "TCSETSF2", "TIOCGRS48", "TIOCSRS485", "TIOCGPTN", "TIOCSPTLCK",
33 "TIOCGDEV", "TCSETX", "TCSETXF", "TCSETXW", "TIOCSIG", "TIOCVHANGUP", "TIOCGPKT",
34 "TIOCGPTLCK", [_IOC_NR(TIOCGEXCL)] = "TIOCGEXCL", "TIOCGPTPEER",
35 [_IOC_NR(FIONCLEX)] = "FIONCLEX", "FIOCLEX", "FIOASYNC", "TIOCSERCONFIG",
36 "TIOCSERGWILD", "TIOCSERSWILD", "TIOCGLCKTRMIOS", "TIOCSLCKTRMIOS",
37 "TIOCSERGSTRUCT", "TIOCSERGETLSR", "TIOCSERGETMULTI", "TIOCSERSETMULTI",
38 "TIOCMIWAIT", "TIOCGICOUNT", };
39 static DEFINE_STRARRAY(ioctl_tty_cmd);
41 if (nr < strarray__ioctl_tty_cmd.nr_entries && strarray__ioctl_tty_cmd.entries[nr] != NULL)
42 return scnprintf(bf, size, "%s", strarray__ioctl_tty_cmd.entries[nr]);
44 return scnprintf(bf, size, "(%#x, %#x, %#x)", 'T', nr, dir);
47 static size_t ioctl__scnprintf_drm_cmd(int nr, int dir, char *bf, size_t size)
49 #include "trace/beauty/generated/ioctl/drm_ioctl_array.c"
50 static DEFINE_STRARRAY(drm_ioctl_cmds);
52 if (nr < strarray__drm_ioctl_cmds.nr_entries && strarray__drm_ioctl_cmds.entries[nr] != NULL)
53 return scnprintf(bf, size, "DRM_%s", strarray__drm_ioctl_cmds.entries[nr]);
55 return scnprintf(bf, size, "(%#x, %#x, %#x)", 'd', nr, dir);
58 static size_t ioctl__scnprintf_sndrv_pcm_cmd(int nr, int dir, char *bf, size_t size)
60 #include "trace/beauty/generated/ioctl/sndrv_pcm_ioctl_array.c"
61 static DEFINE_STRARRAY(sndrv_pcm_ioctl_cmds);
63 if (nr < strarray__sndrv_pcm_ioctl_cmds.nr_entries && strarray__sndrv_pcm_ioctl_cmds.entries[nr] != NULL)
64 return scnprintf(bf, size, "SNDRV_PCM_%s", strarray__sndrv_pcm_ioctl_cmds.entries[nr]);
66 return scnprintf(bf, size, "(%#x, %#x, %#x)", 'A', nr, dir);
69 static size_t ioctl__scnprintf_sndrv_ctl_cmd(int nr, int dir, char *bf, size_t size)
71 #include "trace/beauty/generated/ioctl/sndrv_ctl_ioctl_array.c"
72 static DEFINE_STRARRAY(sndrv_ctl_ioctl_cmds);
74 if (nr < strarray__sndrv_ctl_ioctl_cmds.nr_entries && strarray__sndrv_ctl_ioctl_cmds.entries[nr] != NULL)
75 return scnprintf(bf, size, "SNDRV_CTL_%s", strarray__sndrv_ctl_ioctl_cmds.entries[nr]);
77 return scnprintf(bf, size, "(%#x, %#x, %#x)", 'U', nr, dir);
80 static size_t ioctl__scnprintf_kvm_cmd(int nr, int dir, char *bf, size_t size)
82 #include "trace/beauty/generated/ioctl/kvm_ioctl_array.c"
83 static DEFINE_STRARRAY(kvm_ioctl_cmds);
85 if (nr < strarray__kvm_ioctl_cmds.nr_entries && strarray__kvm_ioctl_cmds.entries[nr] != NULL)
86 return scnprintf(bf, size, "KVM_%s", strarray__kvm_ioctl_cmds.entries[nr]);
88 return scnprintf(bf, size, "(%#x, %#x, %#x)", 0xAE, nr, dir);
91 static size_t ioctl__scnprintf_vhost_virtio_cmd(int nr, int dir, char *bf, size_t size)
93 #include "trace/beauty/generated/ioctl/vhost_virtio_ioctl_array.c"
94 static DEFINE_STRARRAY(vhost_virtio_ioctl_cmds);
95 static DEFINE_STRARRAY(vhost_virtio_ioctl_read_cmds);
96 struct strarray *s = (dir & _IOC_READ) ? &strarray__vhost_virtio_ioctl_read_cmds : &strarray__vhost_virtio_ioctl_cmds;
98 if (nr < s->nr_entries && s->entries[nr] != NULL)
99 return scnprintf(bf, size, "VHOST_%s", s->entries[nr]);
101 return scnprintf(bf, size, "(%#x, %#x, %#x)", 0xAF, nr, dir);
104 static size_t ioctl__scnprintf_perf_cmd(int nr, int dir, char *bf, size_t size)
106 #include "trace/beauty/generated/ioctl/perf_ioctl_array.c"
107 static DEFINE_STRARRAY(perf_ioctl_cmds);
109 if (nr < strarray__perf_ioctl_cmds.nr_entries && strarray__perf_ioctl_cmds.entries[nr] != NULL)
110 return scnprintf(bf, size, "PERF_%s", strarray__perf_ioctl_cmds.entries[nr]);
112 return scnprintf(bf, size, "(%#x, %#x, %#x)", 0xAE, nr, dir);
115 static size_t ioctl__scnprintf_cmd(unsigned long cmd, char *bf, size_t size)
117 int dir = _IOC_DIR(cmd),
118 type = _IOC_TYPE(cmd),
119 nr = _IOC_NR(cmd),
120 sz = _IOC_SIZE(cmd);
121 int printed = 0;
122 static const struct ioctl_type {
123 int type;
124 size_t (*scnprintf)(int nr, int dir, char *bf, size_t size);
125 } ioctl_types[] = { /* Must be ordered by type */
126 { .type = '$', .scnprintf = ioctl__scnprintf_perf_cmd, },
127 ['A' - '$'] = { .type = 'A', .scnprintf = ioctl__scnprintf_sndrv_pcm_cmd, },
128 ['T' - '$'] = { .type = 'T', .scnprintf = ioctl__scnprintf_tty_cmd, },
129 ['U' - '$'] = { .type = 'U', .scnprintf = ioctl__scnprintf_sndrv_ctl_cmd, },
130 ['d' - '$'] = { .type = 'd', .scnprintf = ioctl__scnprintf_drm_cmd, },
131 [0xAE - '$'] = { .type = 0xAE, .scnprintf = ioctl__scnprintf_kvm_cmd, },
132 [0xAF - '$'] = { .type = 0xAF, .scnprintf = ioctl__scnprintf_vhost_virtio_cmd, },
134 const int nr_types = ARRAY_SIZE(ioctl_types);
136 if (type >= ioctl_types[0].type && type <= ioctl_types[nr_types - 1].type) {
137 const int index = type - ioctl_types[0].type;
139 if (ioctl_types[index].scnprintf != NULL)
140 return ioctl_types[index].scnprintf(nr, dir, bf, size);
143 printed += scnprintf(bf + printed, size - printed, "%c", '(');
145 if (dir == _IOC_NONE) {
146 printed += scnprintf(bf + printed, size - printed, "%s", "NONE");
147 } else {
148 if (dir & _IOC_READ)
149 printed += scnprintf(bf + printed, size - printed, "%s", "READ");
150 if (dir & _IOC_WRITE)
151 printed += scnprintf(bf + printed, size - printed, "%s%s", dir & _IOC_READ ? "|" : "", "WRITE");
154 return printed + scnprintf(bf + printed, size - printed, ", %#x, %#x, %#x)", type, nr, sz);
157 size_t syscall_arg__scnprintf_ioctl_cmd(char *bf, size_t size, struct syscall_arg *arg)
159 unsigned long cmd = arg->val;
161 return ioctl__scnprintf_cmd(cmd, bf, size);