[ea991e84] | 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 | /**
|
---|
[17ceb72] | 29 | * @addtogroup drvusbuhcihc
|
---|
[ea991e84] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /**
|
---|
| 33 | * @file
|
---|
| 34 | * PCI related functions needed by the UHCI driver.
|
---|
| 35 | */
|
---|
[79ae36dd] | 36 |
|
---|
[ea991e84] | 37 | #include <errno.h>
|
---|
| 38 | #include <assert.h>
|
---|
| 39 | #include <devman.h>
|
---|
[266976f] | 40 | #include <device/hw_res_parsed.h>
|
---|
[795448f] | 41 | #include <device/pci.h>
|
---|
[ea991e84] | 42 |
|
---|
[795448f] | 43 | #include "res.h"
|
---|
[c56dbe0] | 44 |
|
---|
[ea993d18] | 45 | /** Get I/O address of registers and IRQ for given device.
|
---|
[ea991e84] | 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 | */
|
---|
[56fd7cf] | 53 | int get_my_registers(ddf_dev_t *dev,
|
---|
[ea993d18] | 54 | uintptr_t *io_reg_address, size_t *io_reg_size, int *irq_no)
|
---|
[ea991e84] | 55 | {
|
---|
[e247d83] | 56 | assert(dev);
|
---|
[5d915b7] | 57 |
|
---|
[79ae36dd] | 58 | async_sess_t *parent_sess =
|
---|
[56fd7cf] | 59 | devman_parent_device_connect(EXCHANGE_SERIALIZE,
|
---|
| 60 | ddf_dev_get_handle(dev), IPC_FLAG_BLOCKING);
|
---|
[79ae36dd] | 61 | if (!parent_sess)
|
---|
| 62 | return ENOMEM;
|
---|
[5d915b7] | 63 |
|
---|
[266976f] | 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);
|
---|
[45a9cf4] | 67 | async_hangup(parent_sess);
|
---|
[266976f] | 68 | if (ret != EOK) {
|
---|
| 69 | return ret;
|
---|
[ea991e84] | 70 | }
|
---|
[5d915b7] | 71 |
|
---|
[266976f] | 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;
|
---|
[ea991e84] | 76 | }
|
---|
[5d915b7] | 77 |
|
---|
[266976f] | 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];
|
---|
[5d915b7] | 84 |
|
---|
[266976f] | 85 | hw_res_list_parsed_clean(&hw_res);
|
---|
[e247d83] | 86 | return EOK;
|
---|
[ea991e84] | 87 | }
|
---|
[d92c1ca] | 88 |
|
---|
[17ceb72] | 89 | /** Call the PCI driver with a request to enable interrupts
|
---|
[a7e2f0d] | 90 | *
|
---|
| 91 | * @param[in] device Device asking for interrupts
|
---|
| 92 | * @return Error code.
|
---|
| 93 | */
|
---|
[56fd7cf] | 94 | int enable_interrupts(ddf_dev_t *device)
|
---|
[fb78ae72] | 95 | {
|
---|
[79ae36dd] | 96 | async_sess_t *parent_sess =
|
---|
[56fd7cf] | 97 | devman_parent_device_connect(EXCHANGE_SERIALIZE,
|
---|
| 98 | ddf_dev_get_handle(device), IPC_FLAG_BLOCKING);
|
---|
[79ae36dd] | 99 | if (!parent_sess)
|
---|
| 100 | return ENOMEM;
|
---|
[5d915b7] | 101 |
|
---|
[79ae36dd] | 102 | const bool enabled = hw_res_enable_interrupt(parent_sess);
|
---|
| 103 | async_hangup(parent_sess);
|
---|
[5d915b7] | 104 |
|
---|
[fb78ae72] | 105 | return enabled ? EOK : EIO;
|
---|
| 106 | }
|
---|
[d92c1ca] | 107 |
|
---|
[17ceb72] | 108 | /** Call the PCI driver with a request to clear legacy support register
|
---|
[a7e2f0d] | 109 | *
|
---|
| 110 | * @param[in] device Device asking to disable interrupts
|
---|
| 111 | * @return Error code.
|
---|
| 112 | */
|
---|
[56fd7cf] | 113 | int disable_legacy(ddf_dev_t *device)
|
---|
[ab414a6] | 114 | {
|
---|
| 115 | assert(device);
|
---|
[3afb758] | 116 |
|
---|
[795448f] | 117 | async_sess_t *parent_sess = devman_parent_device_connect(
|
---|
[56fd7cf] | 118 | EXCHANGE_SERIALIZE, ddf_dev_get_handle(device), IPC_FLAG_BLOCKING);
|
---|
[79ae36dd] | 119 | if (!parent_sess)
|
---|
| 120 | return ENOMEM;
|
---|
[3afb758] | 121 |
|
---|
[795448f] | 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);
|
---|
[3afb758] | 125 |
|
---|
[79ae36dd] | 126 | async_hangup(parent_sess);
|
---|
[4b4e163] | 127 | return rc;
|
---|
[ab414a6] | 128 | }
|
---|
[ea991e84] | 129 |
|
---|
[c56dbe0] | 130 | /**
|
---|
| 131 | * @}
|
---|
| 132 | */
|
---|