source: mainline/uspace/drv/bus/usb/ohci/pci.c@ e882e3a

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since e882e3a was 8f5b4d44, checked in by Jan Vesely <jano.vesely@…>, 14 years ago

ohci: Use parsed variant of hw_resources.

  • Property mode set to 100644
File size: 3.4 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/**
30 * @addtogroup drvusbohci
31 * @{
32 */
33/**
34 * @file
35 * PCI related functions needed by the OHCI driver.
36 */
37
38#include <errno.h>
39#include <assert.h>
40#include <as.h>
41#include <devman.h>
42#include <ddi.h>
43#include <libarch/ddi.h>
44#include <device/hw_res_parsed.h>
45
46#include <usb/debug.h>
47#include <pci_dev_iface.h>
48
49#include "pci.h"
50
51/** Get address of registers and IRQ for given device.
52 *
53 * @param[in] dev Device asking for the addresses.
54 * @param[out] mem_reg_address Base address of the memory range.
55 * @param[out] mem_reg_size Size of the memory range.
56 * @param[out] irq_no IRQ assigned to the device.
57 * @return Error code.
58 */
59int pci_get_my_registers(ddf_dev_t *dev,
60 uintptr_t *mem_reg_address, size_t *mem_reg_size, int *irq_no)
61{
62 assert(dev);
63
64 async_sess_t *parent_sess =
65 devman_parent_device_connect(EXCHANGE_SERIALIZE, dev->handle,
66 IPC_FLAG_BLOCKING);
67 if (!parent_sess)
68 return ENOMEM;
69
70 hw_res_list_parsed_t hw_res;
71 hw_res_list_parsed_init(&hw_res);
72 const int ret = hw_res_get_list_parsed(parent_sess, &hw_res, 0);
73 async_hangup(parent_sess);
74 if (ret != EOK) {
75 return ret;
76 }
77
78 /* We want one irq and one mem range. */
79 if (hw_res.irqs.count != 1 || hw_res.mem_ranges.count != 1) {
80 hw_res_list_parsed_clean(&hw_res);
81 return EINVAL;
82 }
83
84 if (mem_reg_address)
85 *mem_reg_address = hw_res.mem_ranges.ranges[0].address;
86 if (mem_reg_size)
87 *mem_reg_size = hw_res.mem_ranges.ranges[0].size;
88 if (irq_no)
89 *irq_no = hw_res.irqs.irqs[0];
90
91 hw_res_list_parsed_clean(&hw_res);
92 return EOK;
93}
94
95/** Call the PCI driver with a request to enable interrupts
96 *
97 * @param[in] device Device asking for interrupts
98 * @return Error code.
99 */
100int pci_enable_interrupts(ddf_dev_t *device)
101{
102 async_sess_t *parent_sess =
103 devman_parent_device_connect(EXCHANGE_SERIALIZE, device->handle,
104 IPC_FLAG_BLOCKING);
105 if (!parent_sess)
106 return ENOMEM;
107
108 bool enabled = hw_res_enable_interrupt(parent_sess);
109 async_hangup(parent_sess);
110
111 return enabled ? EOK : EIO;
112}
113
114/**
115 * @}
116 */
Note: See TracBrowser for help on using the repository browser.