source: mainline/uspace/lib/drv/generic/remote_pci.c@ d79a101f

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

Add pci device interface

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