source: mainline/uspace/drv/bus/usb/uhci/res.c@ 8486c07

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 8486c07 was d92c1ca, checked in by Martin Decky <martin@…>, 13 years ago

cstyle (no change in functionality)

  • Property mode set to 100644
File size: 3.9 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 drvusbuhcihc
30 * @{
31 */
32/**
33 * @file
34 * PCI related functions needed by the UHCI driver.
35 */
36
37#include <errno.h>
38#include <assert.h>
39#include <devman.h>
40#include <device/hw_res_parsed.h>
41#include <device/pci.h>
42
43#include "res.h"
44
45/** Get I/O address of registers and IRQ for given device.
46 *
47 * @param[in] dev Device asking for the addresses.
48 * @param[out] io_reg_address Base address of the I/O range.
49 * @param[out] io_reg_size Size of the I/O range.
50 * @param[out] irq_no IRQ assigned to the device.
51 * @return Error code.
52 */
53int get_my_registers(const ddf_dev_t *dev,
54 uintptr_t *io_reg_address, size_t *io_reg_size, int *irq_no)
55{
56 assert(dev);
57
58 async_sess_t *parent_sess =
59 devman_parent_device_connect(EXCHANGE_SERIALIZE, dev->handle,
60 IPC_FLAG_BLOCKING);
61 if (!parent_sess)
62 return ENOMEM;
63
64 hw_res_list_parsed_t hw_res;
65 hw_res_list_parsed_init(&hw_res);
66 const int ret = hw_res_get_list_parsed(parent_sess, &hw_res, 0);
67 async_hangup(parent_sess);
68 if (ret != EOK) {
69 return ret;
70 }
71
72 /* We want one irq and one io range. */
73 if (hw_res.irqs.count != 1 || hw_res.io_ranges.count != 1) {
74 hw_res_list_parsed_clean(&hw_res);
75 return EINVAL;
76 }
77
78 if (io_reg_address)
79 *io_reg_address = hw_res.io_ranges.ranges[0].address;
80 if (io_reg_size)
81 *io_reg_size = hw_res.io_ranges.ranges[0].size;
82 if (irq_no)
83 *irq_no = hw_res.irqs.irqs[0];
84
85 hw_res_list_parsed_clean(&hw_res);
86 return EOK;
87}
88
89/** Call the PCI driver with a request to enable interrupts
90 *
91 * @param[in] device Device asking for interrupts
92 * @return Error code.
93 */
94int enable_interrupts(const ddf_dev_t *device)
95{
96 async_sess_t *parent_sess =
97 devman_parent_device_connect(EXCHANGE_SERIALIZE, device->handle,
98 IPC_FLAG_BLOCKING);
99 if (!parent_sess)
100 return ENOMEM;
101
102 const bool enabled = hw_res_enable_interrupt(parent_sess);
103 async_hangup(parent_sess);
104
105 return enabled ? EOK : EIO;
106}
107
108/** Call the PCI driver with a request to clear legacy support register
109 *
110 * @param[in] device Device asking to disable interrupts
111 * @return Error code.
112 */
113int disable_legacy(const ddf_dev_t *device)
114{
115 assert(device);
116
117 async_sess_t *parent_sess = devman_parent_device_connect(
118 EXCHANGE_SERIALIZE, device->handle, IPC_FLAG_BLOCKING);
119 if (!parent_sess)
120 return ENOMEM;
121
122 /* See UHCI design guide page 45 for these values.
123 * Write all WC bits in USB legacy register */
124 const int rc = pci_config_space_write_16(parent_sess, 0xc0, 0xaf00);
125
126 async_hangup(parent_sess);
127 return rc;
128}
129
130/**
131 * @}
132 */
Note: See TracBrowser for help on using the repository browser.