util: Add hda-decoder
[coreboot.git] / util / uio_usbdebug / uio_usbdebug.c
blob54b011990cf8e9d1d061dc52234f5742263fc403
1 /* uio_usbdebug - Run coreboot's usbdebug driver in userspace */
2 /* SPDX-License-Identifier: GPL-2.0-only */
4 #include <stdio.h>
5 #include <sys/stat.h>
6 #include <fcntl.h>
7 #include <unistd.h>
8 #include <sys/mman.h>
10 #include <pci/pci.h>
12 /* coreboot's arch/io.h conflicts with libc's sys/io.h, so declare this here: */
13 int ioperm(unsigned long from, unsigned long num, int turn_on);
15 #include <arch/io.h>
16 #include <console/usb.h>
18 void *ehci_bar;
19 struct pci_access *pci_access;
21 int main(int argc, char *argv[])
23 if (argc != 2) {
24 fprintf(stderr, "Usage: %s <uio-dev>\n", argv[0]);
25 return 1;
27 const int fd = open(argv[1], O_RDWR);
28 if (fd < 0) {
29 perror("Failed to open uio device");
30 return 2;
32 ehci_bar =
33 mmap(NULL, 1 << 8, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
34 if (MAP_FAILED == ehci_bar) {
35 perror("Failed to map ehci bar");
36 close(fd);
37 return 3;
40 ioperm(0x80, 1, 1);
42 pci_access = pci_alloc();
43 pci_init(pci_access);
45 usbdebug_init();
47 pci_cleanup(pci_access);
48 munmap(ehci_bar, 1 << 8);
49 close(fd);
50 return 0;