blob: 54b011990cf8e9d1d061dc52234f5742263fc403 [file] [log] [blame]
Patrick Georgiea063cb2020-05-08 19:28:13 +02001/* uio_usbdebug - Run coreboot's usbdebug driver in userspace */
Patrick Georgi7333a112020-05-08 20:48:04 +02002/* SPDX-License-Identifier: GPL-2.0-only */
Nico Huberb0f83262014-01-01 20:47:55 +01003
4#include <stdio.h>
5#include <sys/stat.h>
6#include <fcntl.h>
7#include <unistd.h>
8#include <sys/mman.h>
9
10#include <pci/pci.h>
11
12/* coreboot's arch/io.h conflicts with libc's sys/io.h, so declare this here: */
13int ioperm(unsigned long from, unsigned long num, int turn_on);
14
15#include <arch/io.h>
16#include <console/usb.h>
17
18void *ehci_bar;
19struct pci_access *pci_access;
20
21int main(int argc, char *argv[])
22{
23 if (argc != 2) {
24 fprintf(stderr, "Usage: %s <uio-dev>\n", argv[0]);
25 return 1;
26 }
27 const int fd = open(argv[1], O_RDWR);
28 if (fd < 0) {
29 perror("Failed to open uio device");
30 return 2;
31 }
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;
38 }
39
40 ioperm(0x80, 1, 1);
41
42 pci_access = pci_alloc();
43 pci_init(pci_access);
44
45 usbdebug_init();
46
47 pci_cleanup(pci_access);
48 munmap(ehci_bar, 1 << 8);
49 close(fd);
50 return 0;
51}