source: mainline/uspace/drv/uhci-hcd/pci.c@ 63862a0

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

Const, type-casting and other minor fixes

  • Property mode set to 100644
File size: 4.7 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 drvusbuhcihc
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#include <pci_dev_iface.h>
43
44#include "pci.h"
45
46/** Get I/O address of registers and IRQ for given device.
47 *
48 * @param[in] dev Device asking for the addresses.
49 * @param[out] io_reg_address Base address of the I/O range.
50 * @param[out] io_reg_size Size of the I/O range.
51 * @param[out] irq_no IRQ assigned to the device.
52 * @return Error code.
53 */
54int pci_get_my_registers(const ddf_dev_t *dev,
55 uintptr_t *io_reg_address, size_t *io_reg_size, int *irq_no)
56{
57 assert(dev);
58 assert(io_reg_address);
59 assert(io_reg_size);
60 assert(irq_no);
61
62 int parent_phone =
63 devman_parent_device_connect(dev->handle, IPC_FLAG_BLOCKING);
64 if (parent_phone < 0) {
65 return parent_phone;
66 }
67
68 hw_resource_list_t hw_resources;
69 int rc = hw_res_get_resource_list(parent_phone, &hw_resources);
70 if (rc != EOK) {
71 async_hangup(parent_phone);
72 return rc;
73 }
74
75 uintptr_t io_address = 0;
76 size_t io_size = 0;
77 bool io_found = false;
78
79 int irq = 0;
80 bool irq_found = false;
81
82 size_t i;
83 for (i = 0; i < hw_resources.count; i++) {
84 const hw_resource_t *res = &hw_resources.resources[i];
85 switch (res->type)
86 {
87 case INTERRUPT:
88 irq = res->res.interrupt.irq;
89 irq_found = true;
90 usb_log_debug2("Found interrupt: %d.\n", irq);
91 break;
92
93 case IO_RANGE:
94 io_address = res->res.io_range.address;
95 io_size = res->res.io_range.size;
96 usb_log_debug2("Found io: %" PRIx64" %zu.\n",
97 res->res.io_range.address, res->res.io_range.size);
98 io_found = true;
99 break;
100
101 default:
102 break;
103 }
104 }
105 async_hangup(parent_phone);
106
107 if (!io_found || !irq_found)
108 return ENOENT;
109
110 *io_reg_address = io_address;
111 *io_reg_size = io_size;
112 *irq_no = irq;
113
114 return EOK;
115}
116/*----------------------------------------------------------------------------*/
117/** Call the PCI driver with a request to enable interrupts
118 *
119 * @param[in] device Device asking for interrupts
120 * @return Error code.
121 */
122int pci_enable_interrupts(const ddf_dev_t *device)
123{
124 const int parent_phone =
125 devman_parent_device_connect(device->handle, IPC_FLAG_BLOCKING);
126 if (parent_phone < 0) {
127 return parent_phone;
128 }
129 const bool enabled = hw_res_enable_interrupt(parent_phone);
130 async_hangup(parent_phone);
131 return enabled ? EOK : EIO;
132}
133/*----------------------------------------------------------------------------*/
134/** Call the PCI driver with a request to clear legacy support register
135 *
136 * @param[in] device Device asking to disable interrupts
137 * @return Error code.
138 */
139int pci_disable_legacy(const ddf_dev_t *device)
140{
141 assert(device);
142 const int parent_phone =
143 devman_parent_device_connect(device->handle, IPC_FLAG_BLOCKING);
144 if (parent_phone < 0) {
145 return parent_phone;
146 }
147
148 /* See UHCI design guide for these values p.45,
149 * write all WC bits in USB legacy register */
150 const sysarg_t address = 0xc0;
151 const sysarg_t value = 0xaf00;
152
153 const int rc = async_req_3_0(parent_phone, DEV_IFACE_ID(PCI_DEV_IFACE),
154 IPC_M_CONFIG_SPACE_WRITE_16, address, value);
155 async_hangup(parent_phone);
156
157 return rc;
158}
159/*----------------------------------------------------------------------------*/
160/**
161 * @}
162 */
163
164/**
165 * @}
166 */
Note: See TracBrowser for help on using the repository browser.