source: mainline/uspace/drv/ohci/pci.c@ 28d9c95

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

Further OHCI refactoring

  • Property mode set to 100644
File size: 4.0 KB
Line 
1/*
2 * Copyright (c) 2011 Jan Vesely
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 drvusbohci
30 * @{
31 */
32/**
33 * @file
34 * PCI related functions needed by the OHCI driver.
35 */
36#include <errno.h>
37#include <assert.h>
38#include <as.h>
39#include <devman.h>
40#include <ddi.h>
41#include <libarch/ddi.h>
42#include <device/hw_res.h>
43
44#include <usb/debug.h>
45#include <pci_dev_iface.h>
46
47#include "pci.h"
48
49/** Get address of registers and IRQ for given device.
50 *
51 * @param[in] dev Device asking for the addresses.
52 * @param[out] mem_reg_address Base address of the memory range.
53 * @param[out] mem_reg_size Size of the memory range.
54 * @param[out] irq_no IRQ assigned to the device.
55 * @return Error code.
56 */
57int pci_get_my_registers(ddf_dev_t *dev,
58 uintptr_t *mem_reg_address, size_t *mem_reg_size, int *irq_no)
59{
60 assert(dev);
61 assert(mem_reg_address);
62 assert(mem_reg_size);
63 assert(irq_no);
64
65 int parent_phone = devman_parent_device_connect(dev->handle,
66 IPC_FLAG_BLOCKING);
67 if (parent_phone < 0) {
68 return parent_phone;
69 }
70
71 int rc;
72
73 hw_resource_list_t hw_resources;
74 rc = hw_res_get_resource_list(parent_phone, &hw_resources);
75 if (rc != EOK) {
76 async_hangup(parent_phone);
77 return rc;
78 }
79
80 uintptr_t mem_address = 0;
81 size_t mem_size = 0;
82 bool mem_found = false;
83
84 int irq = 0;
85 bool irq_found = false;
86
87 size_t i;
88 for (i = 0; i < hw_resources.count; i++) {
89 hw_resource_t *res = &hw_resources.resources[i];
90 switch (res->type)
91 {
92 case INTERRUPT:
93 irq = res->res.interrupt.irq;
94 irq_found = true;
95 usb_log_debug2("Found interrupt: %d.\n", irq);
96 break;
97
98 case MEM_RANGE:
99 if (res->res.mem_range.address != 0
100 && res->res.mem_range.size != 0 ) {
101 mem_address = res->res.mem_range.address;
102 mem_size = res->res.mem_range.size;
103 usb_log_debug2("Found mem: %p %zu.\n",
104 (void *) mem_address, mem_size);
105 mem_found = true;
106 }
107 default:
108 break;
109 }
110 }
111
112 if (mem_found && irq_found) {
113 *mem_reg_address = mem_address;
114 *mem_reg_size = mem_size;
115 *irq_no = irq;
116 rc = EOK;
117 } else {
118 rc = ENOENT;
119 }
120
121 async_hangup(parent_phone);
122 return rc;
123}
124/*----------------------------------------------------------------------------*/
125/** Calls the PCI driver with a request to enable interrupts
126 *
127 * @param[in] device Device asking for interrupts
128 * @return Error code.
129 */
130int pci_enable_interrupts(ddf_dev_t *device)
131{
132 int parent_phone =
133 devman_parent_device_connect(device->handle, IPC_FLAG_BLOCKING);
134 if (parent_phone < 0) {
135 return parent_phone;
136 }
137 bool enabled = hw_res_enable_interrupt(parent_phone);
138 async_hangup(parent_phone);
139 return enabled ? EOK : EIO;
140}
141/**
142 * @}
143 */
144
145/**
146 * @}
147 */
Note: See TracBrowser for help on using the repository browser.