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 | */
|
---|
34 |
|
---|
35 | #include <assert.h>
|
---|
36 | #include <async.h>
|
---|
37 | #include <errno.h>
|
---|
38 | #include <macros.h>
|
---|
39 |
|
---|
40 | #include "pci_dev_iface.h"
|
---|
41 | #include "ddf/driver.h"
|
---|
42 |
|
---|
43 | static void remote_config_space_read_8(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
44 | static void remote_config_space_read_16(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
45 | static void remote_config_space_read_32(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
46 |
|
---|
47 | static void remote_config_space_write_8(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
48 | static void remote_config_space_write_16(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
49 | static void remote_config_space_write_32(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
50 |
|
---|
51 | /** Remote USB interface operations. */
|
---|
52 | static const remote_iface_func_ptr_t remote_pci_iface_ops [] = {
|
---|
53 | [IPC_M_CONFIG_SPACE_READ_8] = remote_config_space_read_8,
|
---|
54 | [IPC_M_CONFIG_SPACE_READ_16] = remote_config_space_read_16,
|
---|
55 | [IPC_M_CONFIG_SPACE_READ_32] = remote_config_space_read_32,
|
---|
56 |
|
---|
57 | [IPC_M_CONFIG_SPACE_WRITE_8] = remote_config_space_write_8,
|
---|
58 | [IPC_M_CONFIG_SPACE_WRITE_16] = remote_config_space_write_16,
|
---|
59 | [IPC_M_CONFIG_SPACE_WRITE_32] = remote_config_space_write_32
|
---|
60 | };
|
---|
61 |
|
---|
62 | /** Remote USB interface structure.
|
---|
63 | */
|
---|
64 | const remote_iface_t remote_pci_iface = {
|
---|
65 | .method_count = ARRAY_SIZE(remote_pci_iface_ops),
|
---|
66 | .methods = remote_pci_iface_ops
|
---|
67 | };
|
---|
68 |
|
---|
69 | void remote_config_space_read_8(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
|
---|
70 | {
|
---|
71 | assert(iface);
|
---|
72 | pci_dev_iface_t *pci_iface = (pci_dev_iface_t *)iface;
|
---|
73 | if (pci_iface->config_space_read_8 == NULL) {
|
---|
74 | async_answer_0(callid, ENOTSUP);
|
---|
75 | return;
|
---|
76 | }
|
---|
77 | uint32_t address = DEV_IPC_GET_ARG1(*call);
|
---|
78 | uint8_t value;
|
---|
79 | int ret = pci_iface->config_space_read_8(fun, address, &value);
|
---|
80 | if (ret != EOK) {
|
---|
81 | async_answer_0(callid, ret);
|
---|
82 | } else {
|
---|
83 | async_answer_1(callid, EOK, value);
|
---|
84 | }
|
---|
85 | }
|
---|
86 |
|
---|
87 | void remote_config_space_read_16(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
|
---|
88 | {
|
---|
89 | assert(iface);
|
---|
90 | pci_dev_iface_t *pci_iface = (pci_dev_iface_t *)iface;
|
---|
91 | if (pci_iface->config_space_read_16 == NULL) {
|
---|
92 | async_answer_0(callid, ENOTSUP);
|
---|
93 | return;
|
---|
94 | }
|
---|
95 | uint32_t address = DEV_IPC_GET_ARG1(*call);
|
---|
96 | uint16_t value;
|
---|
97 | int ret = pci_iface->config_space_read_16(fun, address, &value);
|
---|
98 | if (ret != EOK) {
|
---|
99 | async_answer_0(callid, ret);
|
---|
100 | } else {
|
---|
101 | async_answer_1(callid, EOK, value);
|
---|
102 | }
|
---|
103 | }
|
---|
104 | void remote_config_space_read_32(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
|
---|
105 | {
|
---|
106 | assert(iface);
|
---|
107 | pci_dev_iface_t *pci_iface = (pci_dev_iface_t *)iface;
|
---|
108 | if (pci_iface->config_space_read_32 == NULL) {
|
---|
109 | async_answer_0(callid, ENOTSUP);
|
---|
110 | return;
|
---|
111 | }
|
---|
112 | uint32_t address = DEV_IPC_GET_ARG1(*call);
|
---|
113 | uint32_t value;
|
---|
114 | int ret = pci_iface->config_space_read_32(fun, address, &value);
|
---|
115 | if (ret != EOK) {
|
---|
116 | async_answer_0(callid, ret);
|
---|
117 | } else {
|
---|
118 | async_answer_1(callid, EOK, value);
|
---|
119 | }
|
---|
120 | }
|
---|
121 |
|
---|
122 | void remote_config_space_write_8(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
|
---|
123 | {
|
---|
124 | assert(iface);
|
---|
125 | pci_dev_iface_t *pci_iface = (pci_dev_iface_t *)iface;
|
---|
126 | if (pci_iface->config_space_write_8 == NULL) {
|
---|
127 | async_answer_0(callid, ENOTSUP);
|
---|
128 | return;
|
---|
129 | }
|
---|
130 | uint32_t address = DEV_IPC_GET_ARG1(*call);
|
---|
131 | uint8_t value = DEV_IPC_GET_ARG2(*call);
|
---|
132 | int ret = pci_iface->config_space_write_8(fun, address, value);
|
---|
133 | if (ret != EOK) {
|
---|
134 | async_answer_0(callid, ret);
|
---|
135 | } else {
|
---|
136 | async_answer_0(callid, EOK);
|
---|
137 | }
|
---|
138 | }
|
---|
139 |
|
---|
140 | void remote_config_space_write_16(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
|
---|
141 | {
|
---|
142 | assert(iface);
|
---|
143 | pci_dev_iface_t *pci_iface = (pci_dev_iface_t *)iface;
|
---|
144 | if (pci_iface->config_space_write_16 == NULL) {
|
---|
145 | async_answer_0(callid, ENOTSUP);
|
---|
146 | return;
|
---|
147 | }
|
---|
148 | uint32_t address = DEV_IPC_GET_ARG1(*call);
|
---|
149 | uint16_t value = DEV_IPC_GET_ARG2(*call);
|
---|
150 | int ret = pci_iface->config_space_write_16(fun, address, value);
|
---|
151 | if (ret != EOK) {
|
---|
152 | async_answer_0(callid, ret);
|
---|
153 | } else {
|
---|
154 | async_answer_0(callid, EOK);
|
---|
155 | }
|
---|
156 | }
|
---|
157 |
|
---|
158 | void remote_config_space_write_32(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
|
---|
159 | {
|
---|
160 | assert(iface);
|
---|
161 | pci_dev_iface_t *pci_iface = (pci_dev_iface_t *)iface;
|
---|
162 | if (pci_iface->config_space_write_32 == NULL) {
|
---|
163 | async_answer_0(callid, ENOTSUP);
|
---|
164 | return;
|
---|
165 | }
|
---|
166 | uint32_t address = DEV_IPC_GET_ARG1(*call);
|
---|
167 | uint32_t value = DEV_IPC_GET_ARG2(*call);
|
---|
168 | int ret = pci_iface->config_space_write_32(fun, address, value);
|
---|
169 | if (ret != EOK) {
|
---|
170 | async_answer_0(callid, ret);
|
---|
171 | } else {
|
---|
172 | async_answer_0(callid, EOK);
|
---|
173 | }
|
---|
174 | }
|
---|
175 |
|
---|
176 |
|
---|
177 | /**
|
---|
178 | * @}
|
---|
179 | */
|
---|
180 |
|
---|