[816175a2] | 1 | /*
|
---|
[c56dbe0] | 2 | * Copyright (c) 2011 Vojtech Horky, Jan Vesely
|
---|
[816175a2] | 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 | */
|
---|
[f123909] | 28 | /** @addtogroup drvusbuhcirh
|
---|
[c56dbe0] | 29 | * @{
|
---|
| 30 | */
|
---|
| 31 | /** @file
|
---|
[f123909] | 32 | * @brief UHCI root hub initialization routines
|
---|
[c56dbe0] | 33 | */
|
---|
[eb1a2f4] | 34 | #include <ddf/driver.h>
|
---|
[6cbe7dad] | 35 | #include <devman.h>
|
---|
| 36 | #include <device/hw_res.h>
|
---|
[275bf456] | 37 | #include <errno.h>
|
---|
[fbefd0e] | 38 | #include <str_error.h>
|
---|
[c56dbe0] | 39 | #include <usb_iface.h>
|
---|
[357a302] | 40 | #include <usb/ddfiface.h>
|
---|
[275bf456] | 41 | #include <usb/debug.h>
|
---|
[c56dbe0] | 42 |
|
---|
[1256a0a] | 43 | #include "root_hub.h"
|
---|
| 44 |
|
---|
[7ce0fe3] | 45 | #define NAME "uhci-rhd"
|
---|
[6cbe7dad] | 46 | static int hc_get_my_registers(ddf_dev_t *dev,
|
---|
| 47 | uintptr_t *io_reg_address, size_t *io_reg_size);
|
---|
[f123909] | 48 | #if 0
|
---|
[275bf456] | 49 | /*----------------------------------------------------------------------------*/
|
---|
[eb1a2f4] | 50 | static int usb_iface_get_hc_handle(ddf_fun_t *fun, devman_handle_t *handle)
|
---|
[1256a0a] | 51 | {
|
---|
[eb1a2f4] | 52 | assert(fun);
|
---|
| 53 | assert(fun->driver_data);
|
---|
[7ce0fe3] | 54 | assert(handle);
|
---|
| 55 |
|
---|
[eb1a2f4] | 56 | *handle = ((uhci_root_hub_t*)fun->driver_data)->hc_handle;
|
---|
[816175a2] | 57 |
|
---|
[1256a0a] | 58 | return EOK;
|
---|
| 59 | }
|
---|
[275bf456] | 60 | /*----------------------------------------------------------------------------*/
|
---|
[1256a0a] | 61 | static usb_iface_t uhci_rh_usb_iface = {
|
---|
[357a302] | 62 | .get_hc_handle = usb_iface_get_hc_handle,
|
---|
| 63 | .get_address = usb_iface_get_address_hub_impl
|
---|
[1256a0a] | 64 | };
|
---|
[275bf456] | 65 | /*----------------------------------------------------------------------------*/
|
---|
[eb1a2f4] | 66 | static ddf_dev_ops_t uhci_rh_ops = {
|
---|
[1256a0a] | 67 | .interfaces[USB_DEV_IFACE] = &uhci_rh_usb_iface,
|
---|
[816175a2] | 68 | };
|
---|
[f123909] | 69 | #endif
|
---|
[275bf456] | 70 | /*----------------------------------------------------------------------------*/
|
---|
[f123909] | 71 | /** Initialize a new ddf driver instance of UHCI root hub.
|
---|
[275bf456] | 72 | *
|
---|
| 73 | * @param[in] device DDF instance of the device to initialize.
|
---|
| 74 | * @return Error code.
|
---|
| 75 | */
|
---|
[eb1a2f4] | 76 | static int uhci_rh_add_device(ddf_dev_t *device)
|
---|
[1256a0a] | 77 | {
|
---|
| 78 | if (!device)
|
---|
| 79 | return ENOTSUP;
|
---|
[816175a2] | 80 |
|
---|
[7ce0fe3] | 81 | usb_log_debug2("%s called device %d\n", __FUNCTION__, device->handle);
|
---|
[eb1a2f4] | 82 |
|
---|
| 83 | //device->ops = &uhci_rh_ops;
|
---|
[f123909] | 84 | uintptr_t io_regs = 0;
|
---|
| 85 | size_t io_size = 0;
|
---|
| 86 |
|
---|
| 87 | int ret = hc_get_my_registers(device, &io_regs, &io_size);
|
---|
| 88 | if (ret != EOK) {
|
---|
[fbefd0e] | 89 | usb_log_error("Failed to get registers from parent HC: %s.\n",
|
---|
| 90 | str_error(ret));
|
---|
[f123909] | 91 | }
|
---|
[fbefd0e] | 92 | usb_log_debug("I/O regs at %#X (size %zu).\n", io_regs, io_size);
|
---|
[816175a2] | 93 |
|
---|
[1256a0a] | 94 | uhci_root_hub_t *rh = malloc(sizeof(uhci_root_hub_t));
|
---|
| 95 | if (!rh) {
|
---|
[f123909] | 96 | usb_log_error("Failed to allocate driver instance.\n");
|
---|
[1256a0a] | 97 | return ENOMEM;
|
---|
| 98 | }
|
---|
[7ce0fe3] | 99 |
|
---|
[6cbe7dad] | 100 | ret = uhci_root_hub_init(rh, (void*)io_regs, io_size, device);
|
---|
[1256a0a] | 101 | if (ret != EOK) {
|
---|
[fbefd0e] | 102 | usb_log_error("Failed to initialize driver instance: %s.\n",
|
---|
| 103 | str_error(ret));
|
---|
[1256a0a] | 104 | free(rh);
|
---|
| 105 | return ret;
|
---|
| 106 | }
|
---|
[7ce0fe3] | 107 |
|
---|
[1256a0a] | 108 | device->driver_data = rh;
|
---|
[fbefd0e] | 109 | usb_log_info("Controlling root hub `%s' (%llu).\n",
|
---|
| 110 | device->name, device->handle);
|
---|
[1256a0a] | 111 | return EOK;
|
---|
| 112 | }
|
---|
[275bf456] | 113 | /*----------------------------------------------------------------------------*/
|
---|
[1256a0a] | 114 | static driver_ops_t uhci_rh_driver_ops = {
|
---|
| 115 | .add_device = uhci_rh_add_device,
|
---|
| 116 | };
|
---|
[275bf456] | 117 | /*----------------------------------------------------------------------------*/
|
---|
[1256a0a] | 118 | static driver_t uhci_rh_driver = {
|
---|
| 119 | .name = NAME,
|
---|
| 120 | .driver_ops = &uhci_rh_driver_ops
|
---|
| 121 | };
|
---|
[6cbe7dad] | 122 | /*----------------------------------------------------------------------------*/
|
---|
[f123909] | 123 | /** Initialize global driver structures (NONE).
|
---|
[275bf456] | 124 | *
|
---|
| 125 | * @param[in] argc Nmber of arguments in argv vector (ignored).
|
---|
| 126 | * @param[in] argv Cmdline argument vector (ignored).
|
---|
| 127 | * @return Error code.
|
---|
| 128 | *
|
---|
| 129 | * Driver debug level is set here.
|
---|
| 130 | */
|
---|
[1256a0a] | 131 | int main(int argc, char *argv[])
|
---|
| 132 | {
|
---|
[fbefd0e] | 133 | printf(NAME ": HelenOS UHCI root hub driver.\n");
|
---|
| 134 |
|
---|
[215b001] | 135 | usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME);
|
---|
[fbefd0e] | 136 |
|
---|
[eb1a2f4] | 137 | return ddf_driver_main(&uhci_rh_driver);
|
---|
[1256a0a] | 138 | }
|
---|
[6cbe7dad] | 139 | /*----------------------------------------------------------------------------*/
|
---|
[275bf456] | 140 | /** Get address of I/O registers.
|
---|
| 141 | *
|
---|
| 142 | * @param[in] dev Device asking for the addresses.
|
---|
| 143 | * @param[out] io_reg_address Base address of the memory range.
|
---|
| 144 | * @param[out] io_reg_size Size of the memory range.
|
---|
| 145 | * @return Error code.
|
---|
| 146 | */
|
---|
| 147 | int hc_get_my_registers(
|
---|
| 148 | ddf_dev_t *dev, uintptr_t *io_reg_address, size_t *io_reg_size)
|
---|
[6cbe7dad] | 149 | {
|
---|
| 150 | assert(dev != NULL);
|
---|
| 151 |
|
---|
| 152 | int parent_phone = devman_parent_device_connect(dev->handle,
|
---|
| 153 | IPC_FLAG_BLOCKING);
|
---|
| 154 | if (parent_phone < 0) {
|
---|
| 155 | return parent_phone;
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 | int rc;
|
---|
| 159 |
|
---|
| 160 | hw_resource_list_t hw_resources;
|
---|
| 161 | rc = hw_res_get_resource_list(parent_phone, &hw_resources);
|
---|
| 162 | if (rc != EOK) {
|
---|
| 163 | goto leave;
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 | uintptr_t io_address = 0;
|
---|
| 167 | size_t io_size = 0;
|
---|
| 168 | bool io_found = false;
|
---|
| 169 |
|
---|
| 170 | size_t i;
|
---|
| 171 | for (i = 0; i < hw_resources.count; i++) {
|
---|
| 172 | hw_resource_t *res = &hw_resources.resources[i];
|
---|
[275bf456] | 173 | switch (res->type)
|
---|
| 174 | {
|
---|
| 175 | case IO_RANGE:
|
---|
| 176 | io_address = (uintptr_t) res->res.io_range.address;
|
---|
| 177 | io_size = res->res.io_range.size;
|
---|
| 178 | io_found = true;
|
---|
| 179 |
|
---|
| 180 | default:
|
---|
| 181 | break;
|
---|
[6cbe7dad] | 182 | }
|
---|
| 183 | }
|
---|
| 184 |
|
---|
| 185 | if (!io_found) {
|
---|
| 186 | rc = ENOENT;
|
---|
| 187 | goto leave;
|
---|
| 188 | }
|
---|
| 189 |
|
---|
| 190 | if (io_reg_address != NULL) {
|
---|
| 191 | *io_reg_address = io_address;
|
---|
| 192 | }
|
---|
| 193 | if (io_reg_size != NULL) {
|
---|
| 194 | *io_reg_size = io_size;
|
---|
| 195 | }
|
---|
| 196 | rc = EOK;
|
---|
[275bf456] | 197 |
|
---|
[6cbe7dad] | 198 | leave:
|
---|
| 199 | async_hangup(parent_phone);
|
---|
| 200 | return rc;
|
---|
| 201 | }
|
---|
[c56dbe0] | 202 | /**
|
---|
| 203 | * @}
|
---|
| 204 | */
|
---|