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