source: mainline/uspace/drv/bus/usb/uhcirh/main.c@ cf982ff

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since cf982ff was 5b89d43b, checked in by Jakub Jermar <jakub@…>, 12 years ago

Unbreak USB UHCI support.

  • Support PIO_WINDOW_DEV_IFACE in the uhci driver.
  • Do not base the UHCI RH resources on the address obtained from pio_enable_range().
  • Provide a restricted PIO window instead, based on the UHCI IO range. The UHCI RH resources are then relative to this window.
  • Property mode set to 100644
File size: 4.3 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 drvusbuhcirh
30 * @{
31 */
32/** @file
33 * @brief UHCI root hub initialization routines
34 */
35
36#include <ddf/driver.h>
37#include <devman.h>
38#include <device/hw_res_parsed.h>
39#include <errno.h>
40#include <str_error.h>
41
42#include <usb_iface.h>
43#include <usb/ddfiface.h>
44#include <usb/debug.h>
45
46#include "root_hub.h"
47
48#define NAME "uhcirh"
49
50static int hc_get_my_registers(ddf_dev_t *dev, addr_range_t *io_regs);
51
52static int uhci_rh_dev_add(ddf_dev_t *device);
53
54static driver_ops_t uhci_rh_driver_ops = {
55 .dev_add = uhci_rh_dev_add,
56};
57
58static driver_t uhci_rh_driver = {
59 .name = NAME,
60 .driver_ops = &uhci_rh_driver_ops
61};
62
63/** Initialize global driver structures (NONE).
64 *
65 * @param[in] argc Nmber of arguments in argv vector (ignored).
66 * @param[in] argv Cmdline argument vector (ignored).
67 * @return Error code.
68 *
69 * Driver debug level is set here.
70 */
71int main(int argc, char *argv[])
72{
73 printf(NAME ": HelenOS UHCI root hub driver.\n");
74 log_init(NAME);
75 return ddf_driver_main(&uhci_rh_driver);
76}
77
78/** Initialize a new ddf driver instance of UHCI root hub.
79 *
80 * @param[in] device DDF instance of the device to initialize.
81 * @return Error code.
82 */
83static int uhci_rh_dev_add(ddf_dev_t *device)
84{
85 if (!device)
86 return EINVAL;
87
88 usb_log_debug2("uhci_rh_dev_add(handle=%" PRIun ")\n",
89 ddf_dev_get_handle(device));
90
91 addr_range_t regs;
92 uhci_root_hub_t *rh = NULL;
93 int rc;
94
95 rc = hc_get_my_registers(device, &regs);
96 if (rc != EOK) {
97 usb_log_error( "Failed to get registers from HC: %s.\n",
98 str_error(rc));
99 return rc;
100 }
101
102 usb_log_debug("I/O regs at %p (size %zuB).\n",
103 RNGABSPTR(regs), RNGSZ(regs));
104
105 rh = ddf_dev_data_alloc(device, sizeof(uhci_root_hub_t));
106 if (rh == NULL) {
107 usb_log_error("Failed to allocate rh driver instance.\n");
108 return ENOMEM;
109 }
110
111 rc = uhci_root_hub_init(rh, &regs, device);
112 if (rc != EOK) {
113 usb_log_error("Failed(%d) to initialize rh driver instance: "
114 "%s.\n", rc, str_error(rc));
115 return rc;
116 }
117
118 usb_log_info("Controlling root hub '%s' (%" PRIun ").\n",
119 ddf_dev_get_name(device), ddf_dev_get_handle(device));
120
121 return EOK;
122}
123
124/** Get address of I/O registers.
125 *
126 * @param[in] dev Device asking for the addresses.
127 * @param[out] io_regs_p Pointer to the device's register range.
128 * @return Error code.
129 */
130int hc_get_my_registers(ddf_dev_t *dev, addr_range_t *io_regs_p)
131{
132 async_sess_t *parent_sess =
133 devman_parent_device_connect(EXCHANGE_SERIALIZE,
134 ddf_dev_get_handle(dev), IPC_FLAG_BLOCKING);
135 if (!parent_sess)
136 return ENOMEM;
137
138 hw_res_list_parsed_t hw_res;
139 hw_res_list_parsed_init(&hw_res);
140 const int ret = hw_res_get_list_parsed(parent_sess, &hw_res, 0);
141 async_hangup(parent_sess);
142 if (ret != EOK) {
143 return ret;
144 }
145
146 if (hw_res.io_ranges.count != 1) {
147 hw_res_list_parsed_clean(&hw_res);
148 return EINVAL;
149 }
150
151 if (io_regs_p != NULL)
152 *io_regs_p = hw_res.io_ranges.ranges[0];
153
154 hw_res_list_parsed_clean(&hw_res);
155 return EOK;
156}
157
158/**
159 * @}
160 */
Note: See TracBrowser for help on using the repository browser.