source: mainline/uspace/drv/uhci-hcd/main.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: 4.4 KB
Line 
1/*
2 * Copyright (c) 2011 Vojtech Horky, 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/** @addtogroup usb
29 * @{
30 */
31/** @file
32 * @brief UHCI driver
33 */
34#include <ddf/driver.h>
35#include <ddf/interrupt.h>
36#include <usb_iface.h>
37#include <usb/ddfiface.h>
38#include <device/hw_res.h>
39
40#include <errno.h>
41
42#include <usb/debug.h>
43
44#include "iface.h"
45#include "pci.h"
46#include "root_hub.h"
47#include "uhci.h"
48
49#define NAME "uhci-hcd"
50
51static int uhci_add_device(ddf_dev_t *device);
52
53/*----------------------------------------------------------------------------*/
54static driver_ops_t uhci_driver_ops = {
55 .add_device = uhci_add_device,
56};
57/*----------------------------------------------------------------------------*/
58static driver_t uhci_driver = {
59 .name = NAME,
60 .driver_ops = &uhci_driver_ops
61};
62/*----------------------------------------------------------------------------*/
63static void irq_handler(ddf_dev_t *dev, ipc_callid_t iid, ipc_call_t *call)
64{
65 assert(dev);
66 uhci_t *hc = dev_to_uhci(dev);
67 uint16_t status = IPC_GET_ARG1(*call);
68 assert(hc);
69 uhci_interrupt(hc, status);
70}
71/*----------------------------------------------------------------------------*/
72#define CHECK_RET_RETURN(ret, message...) \
73if (ret != EOK) { \
74 usb_log_error(message); \
75 return ret; \
76}
77
78static int uhci_add_device(ddf_dev_t *device)
79{
80 assert(device);
81
82 usb_log_info("uhci_add_device() called\n");
83
84
85 uintptr_t io_reg_base;
86 size_t io_reg_size;
87 int irq;
88
89 int ret =
90 pci_get_my_registers(device, &io_reg_base, &io_reg_size, &irq);
91
92 CHECK_RET_RETURN(ret,
93 "Failed(%d) to get I/O addresses:.\n", ret, device->handle);
94 usb_log_info("I/O regs at 0x%X (size %zu), IRQ %d.\n",
95 io_reg_base, io_reg_size, irq);
96
97 ret = pci_enable_interrupts(device);
98 CHECK_RET_RETURN(ret, "Failed(%d) to get enable interrupts:\n", ret);
99
100 uhci_t *uhci_hc = malloc(sizeof(uhci_t));
101 ret = (uhci_hc != NULL) ? EOK : ENOMEM;
102 CHECK_RET_RETURN(ret, "Failed to allocate memory for uhci hcd driver.\n");
103
104 ret = uhci_init(uhci_hc, device, (void*)io_reg_base, io_reg_size);
105 if (ret != EOK) {
106 usb_log_error("Failed to init uhci-hcd.\n");
107 free(uhci_hc);
108 return ret;
109 }
110
111 /*
112 * We might free uhci_hc, but that does not matter since no one
113 * else would access driver_data anyway.
114 */
115 device->driver_data = uhci_hc;
116
117 ret = register_interrupt_handler(device, irq, irq_handler,
118 &uhci_hc->interrupt_code);
119 if (ret != EOK) {
120 usb_log_error("Failed to register interrupt handler.\n");
121 uhci_fini(uhci_hc);
122 free(uhci_hc);
123 return ret;
124 }
125
126 ddf_fun_t *rh;
127 ret = setup_root_hub(&rh, device);
128 if (ret != EOK) {
129 usb_log_error("Failed to setup uhci root hub.\n");
130 uhci_fini(uhci_hc);
131 free(uhci_hc);
132 return ret;
133 }
134 rh->driver_data = uhci_hc->ddf_instance;
135
136 ret = ddf_fun_bind(rh);
137 if (ret != EOK) {
138 usb_log_error("Failed to register root hub.\n");
139 uhci_fini(uhci_hc);
140 free(uhci_hc);
141 free(rh);
142 return ret;
143 }
144
145 return EOK;
146}
147/*----------------------------------------------------------------------------*/
148int main(int argc, char *argv[])
149{
150 sleep(3);
151 usb_log_enable(USB_LOG_LEVEL_INFO, NAME);
152
153 return ddf_driver_main(&uhci_driver);
154}
155/**
156 * @}
157 */
Note: See TracBrowser for help on using the repository browser.