source: mainline/uspace/drv/uhci-hcd/pci.c@ 1a93bb0

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 1a93bb0 was 2d33eb5, checked in by Jan Vesely <jano.vesely@…>, 14 years ago

Use what we have found (even if it's 0)

add debug output

  • Property mode set to 100644
File size: 3.5 KB
Line 
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 */
36#include <errno.h>
37#include <assert.h>
38#include <devman.h>
39#include <device/hw_res.h>
40
41#include <usb/debug.h>
42
43#include "pci.h"
44
45/** Get address of registers and IRQ for given device.
46 *
47 * @param[in] dev Device asking for the addresses.
48 * @param[out] io_reg_address Base address of the I/O range.
49 * @param[out] io_reg_size Size of the I/O range.
50 * @param[out] irq_no IRQ assigned to the device.
51 * @return Error code.
52 */
53int pci_get_my_registers(ddf_dev_t *dev,
54 uintptr_t *io_reg_address, size_t *io_reg_size,
55 int *irq_no)
56{
57 assert(dev != NULL);
58
59 int parent_phone = devman_parent_device_connect(dev->handle,
60 IPC_FLAG_BLOCKING);
61 if (parent_phone < 0) {
62 return parent_phone;
63 }
64
65 int rc;
66
67 hw_resource_list_t hw_resources;
68 rc = hw_res_get_resource_list(parent_phone, &hw_resources);
69 if (rc != EOK) {
70 goto leave;
71 }
72
73 uintptr_t io_address = 0;
74 size_t io_size = 0;
75 bool io_found = false;
76
77 int irq = 0;
78 bool irq_found = false;
79
80 size_t i;
81 for (i = 0; i < hw_resources.count; i++) {
82 hw_resource_t *res = &hw_resources.resources[i];
83 switch (res->type) {
84 case INTERRUPT:
85 irq = res->res.interrupt.irq;
86 irq_found = true;
87 usb_log_debug("Found interrupt: %d.\n", irq);
88 break;
89 case IO_RANGE:
90 io_address = res->res.io_range.address;
91 io_size = res->res.io_range.size;
92 usb_log_debug("Found io: %x %d.\n",
93 res->res.io_range.address, res->res.io_range.size);
94 io_found = true;
95 break;
96 default:
97 break;
98 }
99 }
100
101 if (!io_found) {
102 rc = ENOENT;
103 goto leave;
104 }
105
106 if (!irq_found) {
107 rc = ENOENT;
108 goto leave;
109 }
110
111 *io_reg_address = io_address;
112 *io_reg_size = io_size;
113 *irq_no = irq;
114
115 rc = EOK;
116leave:
117 async_hangup(parent_phone);
118
119 return rc;
120}
121/*----------------------------------------------------------------------------*/
122int pci_enable_interrupts(ddf_dev_t *device)
123{
124 int parent_phone = devman_parent_device_connect(device->handle,
125 IPC_FLAG_BLOCKING);
126 bool enabled = hw_res_enable_interrupt(parent_phone);
127 return enabled ? EOK : EIO;
128}
129/**
130 * @}
131 */
132
133/**
134 * @}
135 */
Note: See TracBrowser for help on using the repository browser.