[ea991e84] | 1 | /*
|
---|
| 2 | * Copyright (c) 2011 Vojtech Horky
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 | /**
|
---|
| 29 | * @addtogroup drvusbuhci
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /**
|
---|
| 33 | * @file
|
---|
| 34 | * PCI related functions needed by the UHCI driver.
|
---|
| 35 | */
|
---|
[1256a0a] | 36 | #include "pci.h"
|
---|
[ea991e84] | 37 | #include <errno.h>
|
---|
| 38 | #include <assert.h>
|
---|
| 39 | #include <devman.h>
|
---|
| 40 | #include <device/hw_res.h>
|
---|
| 41 |
|
---|
| 42 | /** Get address of registers and IRQ for given device.
|
---|
| 43 | *
|
---|
| 44 | * @param[in] dev Device asking for the addresses.
|
---|
| 45 | * @param[out] io_reg_address Base address of the I/O range.
|
---|
| 46 | * @param[out] io_reg_size Size of the I/O range.
|
---|
| 47 | * @param[out] irq_no IRQ assigned to the device.
|
---|
| 48 | * @return Error code.
|
---|
| 49 | */
|
---|
| 50 | int pci_get_my_registers(device_t *dev,
|
---|
| 51 | uintptr_t *io_reg_address, size_t *io_reg_size,
|
---|
| 52 | int *irq_no)
|
---|
| 53 | {
|
---|
| 54 | assert(dev != NULL);
|
---|
| 55 |
|
---|
| 56 | int parent_phone = devman_parent_device_connect(dev->handle,
|
---|
| 57 | IPC_FLAG_BLOCKING);
|
---|
| 58 | if (parent_phone < 0) {
|
---|
| 59 | return parent_phone;
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | int rc;
|
---|
| 63 |
|
---|
| 64 | hw_resource_list_t hw_resources;
|
---|
| 65 | rc = hw_res_get_resource_list(parent_phone, &hw_resources);
|
---|
| 66 | if (rc != EOK) {
|
---|
| 67 | goto leave;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | uintptr_t io_address = 0;
|
---|
| 71 | size_t io_size = 0;
|
---|
| 72 | bool io_found = false;
|
---|
| 73 |
|
---|
| 74 | int irq = 0;
|
---|
| 75 | bool irq_found = false;
|
---|
| 76 |
|
---|
| 77 | size_t i;
|
---|
| 78 | for (i = 0; i < hw_resources.count; i++) {
|
---|
| 79 | hw_resource_t *res = &hw_resources.resources[i];
|
---|
| 80 | switch (res->type) {
|
---|
| 81 | case INTERRUPT:
|
---|
| 82 | irq = res->res.interrupt.irq;
|
---|
| 83 | irq_found = true;
|
---|
| 84 | break;
|
---|
| 85 | case IO_RANGE:
|
---|
| 86 | io_address = (uintptr_t)
|
---|
| 87 | res->res.io_range.address;
|
---|
| 88 | io_size = res->res.io_range.size;
|
---|
| 89 | io_found = true;
|
---|
| 90 | break;
|
---|
| 91 | default:
|
---|
| 92 | break;
|
---|
| 93 | }
|
---|
| 94 | }
|
---|
| 95 |
|
---|
| 96 | if (!io_found) {
|
---|
| 97 | rc = ENOENT;
|
---|
| 98 | goto leave;
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | if (!irq_found) {
|
---|
| 102 | rc = ENOENT;
|
---|
| 103 | goto leave;
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | if (io_reg_address != NULL) {
|
---|
| 107 | *io_reg_address = io_address;
|
---|
| 108 | }
|
---|
| 109 | if (io_reg_size != NULL) {
|
---|
| 110 | *io_reg_size = io_size;
|
---|
| 111 | }
|
---|
| 112 | if (irq_no != NULL) {
|
---|
| 113 | *irq_no = irq;
|
---|
| 114 | }
|
---|
| 115 |
|
---|
| 116 | rc = EOK;
|
---|
| 117 | leave:
|
---|
| 118 | ipc_hangup(parent_phone);
|
---|
| 119 |
|
---|
| 120 | return rc;
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | /**
|
---|
| 124 | * @}
|
---|
| 125 | */
|
---|
| 126 |
|
---|