4 #include <dev/pci/pciio.h>
8 #include <minix/keymap.h>
9 #include <minix/sound.h>
11 #include <sys/fcntl.h>
12 #include <sys/ioctl.h>
13 #include <sys/kbdio.h>
14 #include <sys/termios.h>
18 char_ioctl_name(unsigned long req
)
22 NAME(MINIX_I2C_IOCTL_EXEC
);
23 NAME(FBIOGET_VSCREENINFO
);
24 NAME(FBIOPUT_VSCREENINFO
);
25 NAME(FBIOGET_FSCREENINFO
); /* TODO: print argument */
26 NAME(FBIOPAN_DISPLAY
);
33 NAME(DSPIORESET
); /* no argument */
35 NAME(DSPIOSAMPLESINBUF
);
36 NAME(DSPIOPAUSE
); /* no argument */
37 NAME(DSPIORESUME
); /* no argument */
39 NAME(MIXIOGETINPUTLEFT
);
40 NAME(MIXIOGETINPUTRIGHT
);
43 NAME(MIXIOSETINPUTLEFT
);
44 NAME(MIXIOSETINPUTRIGHT
);
46 NAME(TIOCEXCL
); /* no argument */
47 NAME(TIOCNXCL
); /* no argument */
57 NAME(TIOCSBRK
); /* no argument */
58 NAME(TIOCCBRK
); /* no argument */
59 NAME(TIOCSDTR
); /* no argument */
60 NAME(TIOCCDTR
); /* no argument */
65 NAME(TIOCNOTTY
); /* no argument */
67 NAME(TIOCSTOP
); /* no argument */
68 NAME(TIOCSTART
); /* no argument */
69 NAME(TIOCMSET
); /* TODO: print argument */
70 NAME(TIOCMBIS
); /* TODO: print argument */
71 NAME(TIOCMBIC
); /* TODO: print argument */
72 NAME(TIOCMGET
); /* TODO: print argument */
80 NAME(TIOCSCTTY
); /* no argument */
82 NAME(TIOCSIG
); /* no argument */
83 NAME(TIOCDRAIN
); /* no argument */
84 NAME(TIOCGFLAGS
); /* TODO: print argument */
85 NAME(TIOCSFLAGS
); /* TODO: print argument */
86 NAME(TIOCDCDTIMESTAMP
); /* TODO: print argument */
87 NAME(TIOCRCVFRAME
); /* TODO: print argument */
88 NAME(TIOCXMTFRAME
); /* TODO: print argument */
89 NAME(TIOCPTMGET
); /* TODO: print argument */
90 NAME(TIOCGRANTPT
); /* no argument */
91 NAME(TIOCPTSNAME
); /* TODO: print argument */
94 NAME(TIOCSFON
); /* big IOCTL, not printing argument */
97 NAME(KIOCSMAP
); /* not worth interpreting */
98 NAME(PCI_IOC_CFGREAD
);
99 NAME(PCI_IOC_CFGWRITE
);
100 NAME(PCI_IOC_BDF_CFGREAD
);
101 NAME(PCI_IOC_BDF_CFGWRITE
);
102 NAME(PCI_IOC_BUSINFO
);
105 NAME(PCI_IOC_RESERVE
);
106 NAME(PCI_IOC_RELEASE
);
113 put_i2c_op(struct trace_proc
* proc
, const char *name
, i2c_op_t op
)
115 const char *text
= NULL
;
120 TEXT(I2C_OP_READ_WITH_STOP
);
122 TEXT(I2C_OP_WRITE_WITH_STOP
);
123 TEXT(I2C_OP_READ_BLOCK
);
124 TEXT(I2C_OP_WRITE_BLOCK
);
129 put_field(proc
, name
, text
);
131 put_value(proc
, name
, "%d", op
);
135 put_sound_device(struct trace_proc
* proc
, const char * name
, int device
)
137 const char *text
= NULL
;
154 put_field(proc
, name
, text
);
156 put_value(proc
, name
, "%d", device
);
160 put_sound_state(struct trace_proc
* proc
, const char * name
, int state
)
163 if (!valuesonly
&& state
== ON
)
164 put_field(proc
, name
, "ON");
165 else if (!valuesonly
&& state
== OFF
)
166 put_field(proc
, name
, "OFF");
168 put_value(proc
, name
, "%d", state
);
171 static const struct flags flush_flags
[] = {
176 static const struct flags tc_iflags
[] = {
192 static const struct flags tc_oflags
[] = {
202 static const struct flags tc_cflags
[] = {
204 FLAG_MASK(CSIZE
, CS5
),
205 FLAG_MASK(CSIZE
, CS6
),
206 FLAG_MASK(CSIZE
, CS7
),
207 FLAG_MASK(CSIZE
, CS8
),
219 static const struct flags tc_lflags
[] = {
240 put_tty_disc(struct trace_proc
* proc
, const char * name
, int disc
)
242 const char *text
= NULL
;
256 put_field(proc
, name
, text
);
258 put_value(proc
, name
, "%d", disc
);
261 static const struct flags kbd_leds
[] = {
264 FLAG(KBD_LEDS_SCROLL
),
268 char_ioctl_arg(struct trace_proc
* proc
, unsigned long req
, void * ptr
,
271 minix_i2c_ioctl_exec_t
*iie
;
272 struct fb_var_screeninfo
*fbvs
;
273 struct volume_level
*level
;
274 struct inout_ctrl
*inout
;
278 struct kio_bell
*bell
;
279 struct kio_leds
*leds
;
280 struct pciio_cfgreg
*pci_cfgreg
;
281 struct pciio_bdf_cfgreg
*pci_bdf_cfgreg
;
282 struct pciio_businfo
*pci_businfo
;
283 struct pciio_map
*pci_iomap
;
284 struct pciio_acl
*pci_acl
;
287 case MINIX_I2C_IOCTL_EXEC
:
288 if ((iie
= (minix_i2c_ioctl_exec_t
*)ptr
) == NULL
)
289 return IF_OUT
; /* we print only the request for now */
291 put_i2c_op(proc
, "iie_op", iie
->iie_op
);
292 put_value(proc
, "iie_addr", "0x%04x", iie
->iie_addr
);
293 return 0; /* TODO: print command/data/result */
295 case FBIOGET_VSCREENINFO
:
296 if ((fbvs
= (struct fb_var_screeninfo
*)ptr
) == NULL
)
299 put_value(proc
, "xres", "%"PRIu32
, fbvs
->xres
);
300 put_value(proc
, "yres", "%"PRIu32
, fbvs
->yres
);
301 put_value(proc
, "xres_virtual", "%"PRIu32
, fbvs
->xres_virtual
);
302 put_value(proc
, "yres_virtual", "%"PRIu32
, fbvs
->yres_virtual
);
303 put_value(proc
, "xoffset", "%"PRIu32
, fbvs
->xoffset
);
304 put_value(proc
, "yoffset", "%"PRIu32
, fbvs
->yoffset
);
305 put_value(proc
, "bits_per_pixel", "%"PRIu32
,
306 fbvs
->bits_per_pixel
);
309 case FBIOPUT_VSCREENINFO
:
310 case FBIOPAN_DISPLAY
:
311 if ((fbvs
= (struct fb_var_screeninfo
*)ptr
) == NULL
)
314 put_value(proc
, "xoffset", "%"PRIu32
, fbvs
->xoffset
);
315 put_value(proc
, "yoffset", "%"PRIu32
, fbvs
->yoffset
);
325 case DSPIOSAMPLESINBUF
:
329 put_value(proc
, NULL
, "%u", *(unsigned int *)ptr
);
333 if ((level
= (struct volume_level
*)ptr
) == NULL
)
337 put_sound_device(proc
, "device", level
->device
);
339 put_value(proc
, "left", "%d", level
->left
);
340 put_value(proc
, "right", "%d", level
->right
);
345 /* Print the corrected volume levels only with verbosity on. */
346 if ((level
= (struct volume_level
*)ptr
) == NULL
)
347 return IF_OUT
| ((verbose
> 0) ? IF_IN
: 0);
350 put_sound_device(proc
, "device", level
->device
);
351 put_value(proc
, "left", "%d", level
->left
);
352 put_value(proc
, "right", "%d", level
->right
);
355 case MIXIOGETINPUTLEFT
:
356 case MIXIOGETINPUTRIGHT
:
358 if ((inout
= (struct inout_ctrl
*)ptr
) == NULL
)
362 put_sound_device(proc
, "device", inout
->device
);
364 put_sound_state(proc
, "left", inout
->left
);
365 put_sound_state(proc
, "right", inout
->right
);
369 case MIXIOSETINPUTLEFT
:
370 case MIXIOSETINPUTRIGHT
:
372 if ((inout
= (struct inout_ctrl
*)ptr
) == NULL
)
375 put_sound_device(proc
, "device", inout
->device
);
376 put_sound_state(proc
, "left", inout
->left
);
377 put_sound_state(proc
, "right", inout
->right
);
384 put_flags(proc
, NULL
, flush_flags
, COUNT(flush_flags
), "0x%x",
392 if ((tc
= (struct termios
*)ptr
) == NULL
)
396 * These are fairly common IOCTLs, so printing everything by
397 * default would create a lot of noise. By default we limit
398 * ourselves to printing the field that contains what I
399 * consider to be the most important flag: ICANON.
400 * TODO: see if we can come up with a decent format for
401 * selectively printing (relatively important) flags.
404 put_flags(proc
, "c_iflag", tc_iflags
, COUNT(tc_iflags
),
405 "0x%x", tc
->c_iflag
);
406 put_flags(proc
, "c_oflag", tc_oflags
, COUNT(tc_oflags
),
407 "0x%x", tc
->c_oflag
);
408 put_flags(proc
, "c_cflag", tc_cflags
, COUNT(tc_cflags
),
409 "0x%x", tc
->c_cflag
);
411 put_flags(proc
, "c_lflag", tc_lflags
, COUNT(tc_lflags
), "0x%x",
414 put_value(proc
, "c_ispeed", "%d", tc
->c_ispeed
);
415 put_value(proc
, "c_ospeed", "%d", tc
->c_ospeed
);
417 return 0; /* TODO: print the c_cc fields */
424 put_tty_disc(proc
, NULL
, *(int *)ptr
);
432 put_buf(proc
, NULL
, PF_LOCADDR
| PF_STRING
, (vir_bytes
)ptr
,
442 case TIOCSTAT
: /* argument seems unused? */
444 case TIOCCONS
: /* argument seems unused? */
448 /* Print a simple integer. */
452 put_value(proc
, NULL
, "%d", *(int *)ptr
);
456 if ((pm
= (struct ptmget
*)ptr
) == NULL
)
459 put_buf(proc
, "sn", PF_LOCADDR
| PF_STRING
, (vir_bytes
)pm
->sn
,
468 put_value(proc
, NULL
, "'%s'",
469 get_escape(*(char *)ptr
));
471 put_value(proc
, NULL
, "%u", *(char *)ptr
);
476 if ((ws
= (struct winsize
*)ptr
) == NULL
)
479 /* This is a stupid order, but we follow the struct layout. */
480 put_value(proc
, "ws_row", "%u", ws
->ws_row
);
481 put_value(proc
, "ws_col", "%u", ws
->ws_col
);
483 put_value(proc
, "ws_xpixel", "%u", ws
->ws_xpixel
);
484 put_value(proc
, "ws_ypixel", "%u", ws
->ws_ypixel
);
486 return (verbose
> 0) ? IF_ALL
: 0;
489 if ((bell
= (struct kio_bell
*)ptr
) == NULL
)
492 put_value(proc
, "kb_pitch", "%u", bell
->kb_pitch
);
493 put_value(proc
, "kb_volume", "%lu", bell
->kb_volume
);
494 put_struct_timeval(proc
, "kb_duration", PF_LOCADDR
,
495 (vir_bytes
)&bell
->kb_duration
);
500 if ((leds
= (struct kio_leds
*)ptr
) == NULL
)
503 put_flags(proc
, "kl_bits", kbd_leds
, COUNT(kbd_leds
), "0x%x",
507 case PCI_IOC_CFGREAD
:
508 if ((pci_cfgreg
= (struct pciio_cfgreg
*)ptr
) == NULL
)
511 put_ptr(proc
, "reg", (vir_bytes
)pci_cfgreg
->reg
);
512 put_value(proc
, "val", "%08x", pci_cfgreg
->val
);
515 case PCI_IOC_CFGWRITE
:
516 if ((pci_cfgreg
= (struct pciio_cfgreg
*)ptr
) == NULL
)
519 put_ptr(proc
, "reg", (vir_bytes
)pci_cfgreg
->reg
);
520 put_value(proc
, "val", "%08x", pci_cfgreg
->val
);
523 case PCI_IOC_BDF_CFGREAD
:
524 if ((pci_bdf_cfgreg
= (struct pciio_bdf_cfgreg
*)ptr
) == NULL
)
527 put_value(proc
, "bus", "%u", pci_bdf_cfgreg
->bus
);
528 put_value(proc
, "device", "%u", pci_bdf_cfgreg
->device
);
529 put_value(proc
, "function", "%u", pci_bdf_cfgreg
->function
);
530 put_ptr(proc
, "cfgreg.reg", (vir_bytes
)pci_bdf_cfgreg
->cfgreg
.reg
);
531 put_value(proc
, "cfgreg.val", "%08x", pci_bdf_cfgreg
->cfgreg
.val
);
534 case PCI_IOC_BDF_CFGWRITE
:
535 if ((pci_bdf_cfgreg
= (struct pciio_bdf_cfgreg
*)ptr
) == NULL
)
538 put_value(proc
, "bus", "%u", pci_bdf_cfgreg
->bus
);
539 put_value(proc
, "device", "%u", pci_bdf_cfgreg
->device
);
540 put_value(proc
, "function", "%u", pci_bdf_cfgreg
->function
);
541 put_ptr(proc
, "cfgreg.reg", (vir_bytes
)pci_bdf_cfgreg
->cfgreg
.reg
);
542 put_value(proc
, "cfgreg.val", "%08x", pci_bdf_cfgreg
->cfgreg
.val
);
545 case PCI_IOC_BUSINFO
:
546 if ((pci_businfo
= (struct pciio_businfo
*)ptr
) == NULL
)
549 put_value(proc
, "busno", "%u", pci_businfo
->busno
);
550 put_value(proc
, "maxdevs", "%u", pci_businfo
->maxdevs
);
554 if ((pci_iomap
= (struct pciio_map
*)ptr
) == NULL
)
557 put_value(proc
, "flags", "%x", pci_iomap
->flags
);
558 put_value(proc
, "phys_offset", "%08x", pci_iomap
->phys_offset
);
559 put_value(proc
, "size", "%zu", pci_iomap
->size
);
560 put_value(proc
, "readonly", "%x", pci_iomap
->readonly
);
563 put_ptr(proc
, "vaddr_ret", (vir_bytes
)pci_iomap
->vaddr_ret
);
568 if ((pci_iomap
= (struct pciio_map
*)ptr
) == NULL
)
571 put_ptr(proc
, "vaddr", (vir_bytes
)pci_iomap
->vaddr
);
575 case PCI_IOC_RESERVE
:
576 if ((pci_acl
= (struct pciio_acl
*)ptr
) == NULL
)
579 put_value(proc
, "domain", "%u", pci_acl
->domain
);
580 put_value(proc
, "bus", "%u", pci_acl
->bus
);
581 put_value(proc
, "device", "%u", pci_acl
->device
);
582 put_value(proc
, "function", "%u", pci_acl
->function
);
585 case PCI_IOC_RELEASE
:
586 if ((pci_acl
= (struct pciio_acl
*)ptr
) == NULL
)
589 put_value(proc
, "domain", "%u", pci_acl
->domain
);
590 put_value(proc
, "bus", "%u", pci_acl
->bus
);
591 put_value(proc
, "device", "%u", pci_acl
->device
);
592 put_value(proc
, "function", "%u", pci_acl
->function
);