remote_pci.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2011 Jan Vesely
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00034 #include <assert.h>
00035 #include <async.h>
00036 #include <errno.h>
00037 
00038 #include "pci_dev_iface.h"
00039 #include "ddf/driver.h"
00040 
00041 static void remote_config_space_read_8(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
00042 static void remote_config_space_read_16(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
00043 static void remote_config_space_read_32(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
00044 
00045 static void remote_config_space_write_8(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
00046 static void remote_config_space_write_16(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
00047 static void remote_config_space_write_32(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
00048 
00050 static remote_iface_func_ptr_t remote_pci_iface_ops [] = {
00051         remote_config_space_read_8,
00052         remote_config_space_read_16,
00053         remote_config_space_read_32,
00054 
00055         remote_config_space_write_8,
00056         remote_config_space_write_16,
00057         remote_config_space_write_32
00058 };
00059 
00062 remote_iface_t remote_pci_iface = {
00063         .method_count = sizeof(remote_pci_iface_ops) /
00064             sizeof(remote_pci_iface_ops[0]),
00065         .methods = remote_pci_iface_ops
00066 };
00067 
00068 void remote_config_space_read_8(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
00069 {
00070         assert(iface);
00071         pci_dev_iface_t *pci_iface = (pci_dev_iface_t *)iface;
00072         if (pci_iface->config_space_read_8 == NULL) {
00073                 async_answer_0(callid, ENOTSUP);
00074                 return;
00075         }
00076         uint32_t address = DEV_IPC_GET_ARG1(*call);
00077         uint8_t value;
00078         int ret = pci_iface->config_space_read_8(fun, address, &value);
00079         if (ret != EOK) {
00080                 async_answer_0(callid, ret);
00081         } else {
00082                 async_answer_1(callid, EOK, value);
00083         }
00084 }
00085 
00086 void remote_config_space_read_16(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
00087 {
00088         assert(iface);
00089         pci_dev_iface_t *pci_iface = (pci_dev_iface_t *)iface;
00090         if (pci_iface->config_space_read_16 == NULL) {
00091                 async_answer_0(callid, ENOTSUP);
00092                 return;
00093         }
00094         uint32_t address = DEV_IPC_GET_ARG1(*call);
00095         uint16_t value;
00096         int ret = pci_iface->config_space_read_16(fun, address, &value);
00097         if (ret != EOK) {
00098                 async_answer_0(callid, ret);
00099         } else {
00100                 async_answer_1(callid, EOK, value);
00101         }
00102 }
00103 void remote_config_space_read_32(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
00104 {
00105         assert(iface);
00106         pci_dev_iface_t *pci_iface = (pci_dev_iface_t *)iface;
00107         if (pci_iface->config_space_read_32 == NULL) {
00108                 async_answer_0(callid, ENOTSUP);
00109                 return;
00110         }
00111         uint32_t address = DEV_IPC_GET_ARG1(*call);
00112         uint32_t value;
00113         int ret = pci_iface->config_space_read_32(fun, address, &value);
00114         if (ret != EOK) {
00115                 async_answer_0(callid, ret);
00116         } else {
00117                 async_answer_1(callid, EOK, value);
00118         }
00119 }
00120 
00121 void remote_config_space_write_8(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
00122 {
00123         assert(iface);
00124         pci_dev_iface_t *pci_iface = (pci_dev_iface_t *)iface;
00125         if (pci_iface->config_space_write_8 == NULL) {
00126                 async_answer_0(callid, ENOTSUP);
00127                 return;
00128         }
00129         uint32_t address = DEV_IPC_GET_ARG1(*call);
00130         uint8_t value = DEV_IPC_GET_ARG2(*call);
00131         int ret = pci_iface->config_space_write_8(fun, address, value);
00132         if (ret != EOK) {
00133                 async_answer_0(callid, ret);
00134         } else {
00135                 async_answer_0(callid, EOK);
00136         }
00137 }
00138 
00139 void remote_config_space_write_16(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
00140 {
00141         assert(iface);
00142         pci_dev_iface_t *pci_iface = (pci_dev_iface_t *)iface;
00143         if (pci_iface->config_space_write_16 == NULL) {
00144                 async_answer_0(callid, ENOTSUP);
00145                 return;
00146         }
00147         uint32_t address = DEV_IPC_GET_ARG1(*call);
00148         uint16_t value = DEV_IPC_GET_ARG2(*call);
00149         int ret = pci_iface->config_space_write_16(fun, address, value);
00150         if (ret != EOK) {
00151                 async_answer_0(callid, ret);
00152         } else {
00153                 async_answer_0(callid, EOK);
00154         }
00155 }
00156 
00157 void remote_config_space_write_32(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
00158 {
00159         assert(iface);
00160         pci_dev_iface_t *pci_iface = (pci_dev_iface_t *)iface;
00161         if (pci_iface->config_space_write_32 == NULL) {
00162                 async_answer_0(callid, ENOTSUP);
00163                 return;
00164         }
00165         uint32_t address = DEV_IPC_GET_ARG1(*call);
00166         uint32_t value = DEV_IPC_GET_ARG2(*call);
00167         int ret = pci_iface->config_space_write_32(fun, address, value);
00168         if (ret != EOK) {
00169                 async_answer_0(callid, ret);
00170         } else {
00171                 async_answer_0(callid, EOK);
00172         }
00173 }
00174 
00175 

Generated on Thu Jun 2 07:45:47 2011 for HelenOS/USB by  doxygen 1.4.7