Nico Huber | b0f8326 | 2014-01-01 20:47:55 +0100 | [diff] [blame] | 1 | /* |
| 2 | * uio_usbdebug - Run coreboot's usbdebug driver in userspace |
| 3 | * |
| 4 | * Copyright (C) 2013 Nico Huber <nico.h@gmx.de> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Nico Huber | b0f8326 | 2014-01-01 20:47:55 +0100 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <stdio.h> |
| 17 | #include <sys/stat.h> |
| 18 | #include <fcntl.h> |
| 19 | #include <unistd.h> |
| 20 | #include <sys/mman.h> |
| 21 | |
| 22 | #include <pci/pci.h> |
| 23 | |
| 24 | /* coreboot's arch/io.h conflicts with libc's sys/io.h, so declare this here: */ |
| 25 | int ioperm(unsigned long from, unsigned long num, int turn_on); |
| 26 | |
| 27 | #include <arch/io.h> |
| 28 | #include <console/usb.h> |
| 29 | |
| 30 | void *ehci_bar; |
| 31 | struct pci_access *pci_access; |
| 32 | |
| 33 | int main(int argc, char *argv[]) |
| 34 | { |
| 35 | if (argc != 2) { |
| 36 | fprintf(stderr, "Usage: %s <uio-dev>\n", argv[0]); |
| 37 | return 1; |
| 38 | } |
| 39 | const int fd = open(argv[1], O_RDWR); |
| 40 | if (fd < 0) { |
| 41 | perror("Failed to open uio device"); |
| 42 | return 2; |
| 43 | } |
| 44 | ehci_bar = |
| 45 | mmap(NULL, 1 << 8, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); |
| 46 | if (MAP_FAILED == ehci_bar) { |
| 47 | perror("Failed to map ehci bar"); |
| 48 | close(fd); |
| 49 | return 3; |
| 50 | } |
| 51 | |
| 52 | ioperm(0x80, 1, 1); |
| 53 | |
| 54 | pci_access = pci_alloc(); |
| 55 | pci_init(pci_access); |
| 56 | |
| 57 | usbdebug_init(); |
| 58 | |
| 59 | pci_cleanup(pci_access); |
| 60 | munmap(ehci_bar, 1 << 8); |
| 61 | close(fd); |
| 62 | return 0; |
| 63 | } |