[d79a101f] | 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 | /** @addtogroup libdrv
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | */
|
---|
[afb8c84] | 34 |
|
---|
[d79a101f] | 35 | #include <assert.h>
|
---|
| 36 | #include <async.h>
|
---|
| 37 | #include <errno.h>
|
---|
[9be30cdf] | 38 | #include <macros.h>
|
---|
[d79a101f] | 39 |
|
---|
| 40 | #include "pci_dev_iface.h"
|
---|
| 41 | #include "ddf/driver.h"
|
---|
| 42 |
|
---|
[99e8fb7b] | 43 | typedef enum {
|
---|
| 44 | IPC_M_CONFIG_SPACE_READ_8,
|
---|
| 45 | IPC_M_CONFIG_SPACE_READ_16,
|
---|
| 46 | IPC_M_CONFIG_SPACE_READ_32,
|
---|
| 47 |
|
---|
| 48 | IPC_M_CONFIG_SPACE_WRITE_8,
|
---|
| 49 | IPC_M_CONFIG_SPACE_WRITE_16,
|
---|
| 50 | IPC_M_CONFIG_SPACE_WRITE_32
|
---|
| 51 | } pci_dev_iface_funcs_t;
|
---|
| 52 |
|
---|
[b7fd2a0] | 53 | errno_t pci_config_space_read_8(async_sess_t *sess, uint32_t address, uint8_t *val)
|
---|
[99e8fb7b] | 54 | {
|
---|
| 55 | sysarg_t res = 0;
|
---|
[a35b458] | 56 |
|
---|
[99e8fb7b] | 57 | async_exch_t *exch = async_exchange_begin(sess);
|
---|
[b7fd2a0] | 58 | errno_t rc = async_req_2_1(exch, DEV_IFACE_ID(PCI_DEV_IFACE),
|
---|
[99e8fb7b] | 59 | IPC_M_CONFIG_SPACE_READ_8, address, &res);
|
---|
| 60 | async_exchange_end(exch);
|
---|
[a35b458] | 61 |
|
---|
[99e8fb7b] | 62 | *val = (uint8_t) res;
|
---|
| 63 | return rc;
|
---|
| 64 | }
|
---|
| 65 |
|
---|
[b7fd2a0] | 66 | errno_t pci_config_space_read_16(async_sess_t *sess, uint32_t address,
|
---|
[99e8fb7b] | 67 | uint16_t *val)
|
---|
| 68 | {
|
---|
| 69 | sysarg_t res = 0;
|
---|
[a35b458] | 70 |
|
---|
[99e8fb7b] | 71 | async_exch_t *exch = async_exchange_begin(sess);
|
---|
[b7fd2a0] | 72 | errno_t rc = async_req_2_1(exch, DEV_IFACE_ID(PCI_DEV_IFACE),
|
---|
[99e8fb7b] | 73 | IPC_M_CONFIG_SPACE_READ_16, address, &res);
|
---|
| 74 | async_exchange_end(exch);
|
---|
[a35b458] | 75 |
|
---|
[99e8fb7b] | 76 | *val = (uint16_t) res;
|
---|
| 77 | return rc;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
[b7fd2a0] | 80 | errno_t pci_config_space_read_32(async_sess_t *sess, uint32_t address,
|
---|
[99e8fb7b] | 81 | uint32_t *val)
|
---|
| 82 | {
|
---|
| 83 | sysarg_t res = 0;
|
---|
[a35b458] | 84 |
|
---|
[99e8fb7b] | 85 | async_exch_t *exch = async_exchange_begin(sess);
|
---|
[b7fd2a0] | 86 | errno_t rc = async_req_2_1(exch, DEV_IFACE_ID(PCI_DEV_IFACE),
|
---|
[99e8fb7b] | 87 | IPC_M_CONFIG_SPACE_READ_32, address, &res);
|
---|
| 88 | async_exchange_end(exch);
|
---|
[a35b458] | 89 |
|
---|
[99e8fb7b] | 90 | *val = (uint32_t) res;
|
---|
| 91 | return rc;
|
---|
| 92 | }
|
---|
| 93 |
|
---|
[b7fd2a0] | 94 | errno_t pci_config_space_write_8(async_sess_t *sess, uint32_t address, uint8_t val)
|
---|
[99e8fb7b] | 95 | {
|
---|
| 96 | async_exch_t *exch = async_exchange_begin(sess);
|
---|
[b7fd2a0] | 97 | errno_t rc = async_req_3_0(exch, DEV_IFACE_ID(PCI_DEV_IFACE),
|
---|
[99e8fb7b] | 98 | IPC_M_CONFIG_SPACE_WRITE_8, address, val);
|
---|
| 99 | async_exchange_end(exch);
|
---|
[a35b458] | 100 |
|
---|
[99e8fb7b] | 101 | return rc;
|
---|
| 102 | }
|
---|
| 103 |
|
---|
[b7fd2a0] | 104 | errno_t pci_config_space_write_16(async_sess_t *sess, uint32_t address,
|
---|
[99e8fb7b] | 105 | uint16_t val)
|
---|
| 106 | {
|
---|
| 107 | async_exch_t *exch = async_exchange_begin(sess);
|
---|
[b7fd2a0] | 108 | errno_t rc = async_req_3_0(exch, DEV_IFACE_ID(PCI_DEV_IFACE),
|
---|
[99e8fb7b] | 109 | IPC_M_CONFIG_SPACE_WRITE_16, address, val);
|
---|
| 110 | async_exchange_end(exch);
|
---|
[a35b458] | 111 |
|
---|
[99e8fb7b] | 112 | return rc;
|
---|
| 113 | }
|
---|
| 114 |
|
---|
[b7fd2a0] | 115 | errno_t pci_config_space_write_32(async_sess_t *sess, uint32_t address,
|
---|
[99e8fb7b] | 116 | uint32_t val)
|
---|
| 117 | {
|
---|
| 118 | async_exch_t *exch = async_exchange_begin(sess);
|
---|
[b7fd2a0] | 119 | errno_t rc = async_req_3_0(exch, DEV_IFACE_ID(PCI_DEV_IFACE),
|
---|
[99e8fb7b] | 120 | IPC_M_CONFIG_SPACE_WRITE_32, address, val);
|
---|
| 121 | async_exchange_end(exch);
|
---|
[a35b458] | 122 |
|
---|
[99e8fb7b] | 123 | return rc;
|
---|
| 124 | }
|
---|
| 125 |
|
---|
[984a9ba] | 126 | static void remote_config_space_read_8(ddf_fun_t *, void *, ipc_call_t *);
|
---|
| 127 | static void remote_config_space_read_16(ddf_fun_t *, void *, ipc_call_t *);
|
---|
| 128 | static void remote_config_space_read_32(ddf_fun_t *, void *, ipc_call_t *);
|
---|
[d79a101f] | 129 |
|
---|
[984a9ba] | 130 | static void remote_config_space_write_8(ddf_fun_t *, void *, ipc_call_t *);
|
---|
| 131 | static void remote_config_space_write_16(ddf_fun_t *, void *, ipc_call_t *);
|
---|
| 132 | static void remote_config_space_write_32(ddf_fun_t *, void *, ipc_call_t *);
|
---|
[d79a101f] | 133 |
|
---|
| 134 | /** Remote USB interface operations. */
|
---|
[9be30cdf] | 135 | static const remote_iface_func_ptr_t remote_pci_iface_ops [] = {
|
---|
[9031228] | 136 | [IPC_M_CONFIG_SPACE_READ_8] = remote_config_space_read_8,
|
---|
| 137 | [IPC_M_CONFIG_SPACE_READ_16] = remote_config_space_read_16,
|
---|
| 138 | [IPC_M_CONFIG_SPACE_READ_32] = remote_config_space_read_32,
|
---|
[d79a101f] | 139 |
|
---|
[9031228] | 140 | [IPC_M_CONFIG_SPACE_WRITE_8] = remote_config_space_write_8,
|
---|
| 141 | [IPC_M_CONFIG_SPACE_WRITE_16] = remote_config_space_write_16,
|
---|
| 142 | [IPC_M_CONFIG_SPACE_WRITE_32] = remote_config_space_write_32
|
---|
[d79a101f] | 143 | };
|
---|
| 144 |
|
---|
| 145 | /** Remote USB interface structure.
|
---|
| 146 | */
|
---|
[7f80313] | 147 | const remote_iface_t remote_pci_iface = {
|
---|
[9be30cdf] | 148 | .method_count = ARRAY_SIZE(remote_pci_iface_ops),
|
---|
[d79a101f] | 149 | .methods = remote_pci_iface_ops
|
---|
| 150 | };
|
---|
| 151 |
|
---|
[984a9ba] | 152 | void remote_config_space_read_8(ddf_fun_t *fun, void *iface, ipc_call_t *call)
|
---|
[d79a101f] | 153 | {
|
---|
| 154 | assert(iface);
|
---|
| 155 | pci_dev_iface_t *pci_iface = (pci_dev_iface_t *)iface;
|
---|
| 156 | if (pci_iface->config_space_read_8 == NULL) {
|
---|
[984a9ba] | 157 | async_answer_0(call, ENOTSUP);
|
---|
[d79a101f] | 158 | return;
|
---|
| 159 | }
|
---|
| 160 | uint32_t address = DEV_IPC_GET_ARG1(*call);
|
---|
| 161 | uint8_t value;
|
---|
[b7fd2a0] | 162 | errno_t ret = pci_iface->config_space_read_8(fun, address, &value);
|
---|
[d79a101f] | 163 | if (ret != EOK) {
|
---|
[984a9ba] | 164 | async_answer_0(call, ret);
|
---|
[d79a101f] | 165 | } else {
|
---|
[984a9ba] | 166 | async_answer_1(call, EOK, value);
|
---|
[d79a101f] | 167 | }
|
---|
| 168 | }
|
---|
| 169 |
|
---|
[984a9ba] | 170 | void remote_config_space_read_16(ddf_fun_t *fun, void *iface, ipc_call_t *call)
|
---|
[d79a101f] | 171 | {
|
---|
| 172 | assert(iface);
|
---|
| 173 | pci_dev_iface_t *pci_iface = (pci_dev_iface_t *)iface;
|
---|
| 174 | if (pci_iface->config_space_read_16 == NULL) {
|
---|
[984a9ba] | 175 | async_answer_0(call, ENOTSUP);
|
---|
[d79a101f] | 176 | return;
|
---|
| 177 | }
|
---|
| 178 | uint32_t address = DEV_IPC_GET_ARG1(*call);
|
---|
| 179 | uint16_t value;
|
---|
[b7fd2a0] | 180 | errno_t ret = pci_iface->config_space_read_16(fun, address, &value);
|
---|
[d79a101f] | 181 | if (ret != EOK) {
|
---|
[984a9ba] | 182 | async_answer_0(call, ret);
|
---|
[d79a101f] | 183 | } else {
|
---|
[984a9ba] | 184 | async_answer_1(call, EOK, value);
|
---|
[d79a101f] | 185 | }
|
---|
| 186 | }
|
---|
[984a9ba] | 187 | void remote_config_space_read_32(ddf_fun_t *fun, void *iface, ipc_call_t *call)
|
---|
[d79a101f] | 188 | {
|
---|
| 189 | assert(iface);
|
---|
| 190 | pci_dev_iface_t *pci_iface = (pci_dev_iface_t *)iface;
|
---|
| 191 | if (pci_iface->config_space_read_32 == NULL) {
|
---|
[984a9ba] | 192 | async_answer_0(call, ENOTSUP);
|
---|
[d79a101f] | 193 | return;
|
---|
| 194 | }
|
---|
| 195 | uint32_t address = DEV_IPC_GET_ARG1(*call);
|
---|
| 196 | uint32_t value;
|
---|
[b7fd2a0] | 197 | errno_t ret = pci_iface->config_space_read_32(fun, address, &value);
|
---|
[d79a101f] | 198 | if (ret != EOK) {
|
---|
[984a9ba] | 199 | async_answer_0(call, ret);
|
---|
[d79a101f] | 200 | } else {
|
---|
[984a9ba] | 201 | async_answer_1(call, EOK, value);
|
---|
[d79a101f] | 202 | }
|
---|
| 203 | }
|
---|
| 204 |
|
---|
[984a9ba] | 205 | void remote_config_space_write_8(ddf_fun_t *fun, void *iface, ipc_call_t *call)
|
---|
[d79a101f] | 206 | {
|
---|
| 207 | assert(iface);
|
---|
| 208 | pci_dev_iface_t *pci_iface = (pci_dev_iface_t *)iface;
|
---|
| 209 | if (pci_iface->config_space_write_8 == NULL) {
|
---|
[984a9ba] | 210 | async_answer_0(call, ENOTSUP);
|
---|
[d79a101f] | 211 | return;
|
---|
| 212 | }
|
---|
| 213 | uint32_t address = DEV_IPC_GET_ARG1(*call);
|
---|
| 214 | uint8_t value = DEV_IPC_GET_ARG2(*call);
|
---|
[b7fd2a0] | 215 | errno_t ret = pci_iface->config_space_write_8(fun, address, value);
|
---|
[d79a101f] | 216 | if (ret != EOK) {
|
---|
[984a9ba] | 217 | async_answer_0(call, ret);
|
---|
[d79a101f] | 218 | } else {
|
---|
[984a9ba] | 219 | async_answer_0(call, EOK);
|
---|
[d79a101f] | 220 | }
|
---|
| 221 | }
|
---|
| 222 |
|
---|
[984a9ba] | 223 | void remote_config_space_write_16(ddf_fun_t *fun, void *iface, ipc_call_t *call)
|
---|
[d79a101f] | 224 | {
|
---|
| 225 | assert(iface);
|
---|
| 226 | pci_dev_iface_t *pci_iface = (pci_dev_iface_t *)iface;
|
---|
| 227 | if (pci_iface->config_space_write_16 == NULL) {
|
---|
[984a9ba] | 228 | async_answer_0(call, ENOTSUP);
|
---|
[d79a101f] | 229 | return;
|
---|
| 230 | }
|
---|
| 231 | uint32_t address = DEV_IPC_GET_ARG1(*call);
|
---|
| 232 | uint16_t value = DEV_IPC_GET_ARG2(*call);
|
---|
[b7fd2a0] | 233 | errno_t ret = pci_iface->config_space_write_16(fun, address, value);
|
---|
[d79a101f] | 234 | if (ret != EOK) {
|
---|
[984a9ba] | 235 | async_answer_0(call, ret);
|
---|
[d79a101f] | 236 | } else {
|
---|
[984a9ba] | 237 | async_answer_0(call, EOK);
|
---|
[d79a101f] | 238 | }
|
---|
| 239 | }
|
---|
| 240 |
|
---|
[984a9ba] | 241 | void remote_config_space_write_32(ddf_fun_t *fun, void *iface, ipc_call_t *call)
|
---|
[d79a101f] | 242 | {
|
---|
| 243 | assert(iface);
|
---|
| 244 | pci_dev_iface_t *pci_iface = (pci_dev_iface_t *)iface;
|
---|
| 245 | if (pci_iface->config_space_write_32 == NULL) {
|
---|
[984a9ba] | 246 | async_answer_0(call, ENOTSUP);
|
---|
[d79a101f] | 247 | return;
|
---|
| 248 | }
|
---|
| 249 | uint32_t address = DEV_IPC_GET_ARG1(*call);
|
---|
| 250 | uint32_t value = DEV_IPC_GET_ARG2(*call);
|
---|
[b7fd2a0] | 251 | errno_t ret = pci_iface->config_space_write_32(fun, address, value);
|
---|
[d79a101f] | 252 | if (ret != EOK) {
|
---|
[984a9ba] | 253 | async_answer_0(call, ret);
|
---|
[d79a101f] | 254 | } else {
|
---|
[984a9ba] | 255 | async_answer_0(call, EOK);
|
---|
[d79a101f] | 256 | }
|
---|
| 257 | }
|
---|
| 258 |
|
---|
| 259 | /**
|
---|
| 260 | * @}
|
---|
| 261 | */
|
---|