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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since eb1a2f4 was eb1a2f4, checked in by Vojtech Horky <vojtechhorky@…>, 14 years ago

Merge mainline changes (DDF refactoring)

This merge includes DDF refactoring that brought multifunctional devices
(i.e. ddf_dev_t and ddf_fun_t). Please, see ticket #295 at HelenOS
upstream Trac.

The conflicts themselves were easy to solve (merely several renamings).

Changes to USB subsystem:

  • drivers uses ddf_dev_t and ddf_fun_t
  • different signatures of many library functions
  • several hacks around communication with parent device (now the communication is clearer and somehow what we have now is hack about other hacks)
    • will repair and clean later
  • maybe added some extra debugging messages (the diff has about 240K, and I admit I have no energy to double check that)

WARNING:

  • the diff is VERY long, recommended is viewing partial diffs of the merge (i.e. merges in mainline branch that lead to the parent one)
  • merging with your branches might involve huge renamings, sorry, no other way is possible

BUGS:

  • hub driver will not work (no function created)

GOOD NEWS:

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