Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/drv/generic/remote_pci.c

    r9d58539 r99e8fb7b  
    3636#include <async.h>
    3737#include <errno.h>
     38#include <macros.h>
    3839
    3940#include "pci_dev_iface.h"
    4041#include "ddf/driver.h"
     42
     43typedef 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
     53int pci_config_space_read_8(async_sess_t *sess, uint32_t address, uint8_t *val)
     54{
     55        sysarg_t res = 0;
     56       
     57        async_exch_t *exch = async_exchange_begin(sess);
     58        int rc = async_req_2_1(exch, DEV_IFACE_ID(PCI_DEV_IFACE),
     59            IPC_M_CONFIG_SPACE_READ_8, address, &res);
     60        async_exchange_end(exch);
     61       
     62        *val = (uint8_t) res;
     63        return rc;
     64}
     65
     66int pci_config_space_read_16(async_sess_t *sess, uint32_t address,
     67    uint16_t *val)
     68{
     69        sysarg_t res = 0;
     70       
     71        async_exch_t *exch = async_exchange_begin(sess);
     72        int rc = async_req_2_1(exch, DEV_IFACE_ID(PCI_DEV_IFACE),
     73            IPC_M_CONFIG_SPACE_READ_16, address, &res);
     74        async_exchange_end(exch);
     75       
     76        *val = (uint16_t) res;
     77        return rc;
     78}
     79
     80int pci_config_space_read_32(async_sess_t *sess, uint32_t address,
     81    uint32_t *val)
     82{
     83        sysarg_t res = 0;
     84       
     85        async_exch_t *exch = async_exchange_begin(sess);
     86        int rc = async_req_2_1(exch, DEV_IFACE_ID(PCI_DEV_IFACE),
     87            IPC_M_CONFIG_SPACE_READ_32, address, &res);
     88        async_exchange_end(exch);
     89       
     90        *val = (uint32_t) res;
     91        return rc;
     92}
     93
     94int pci_config_space_write_8(async_sess_t *sess, uint32_t address, uint8_t val)
     95{
     96        async_exch_t *exch = async_exchange_begin(sess);
     97        int rc = async_req_3_0(exch, DEV_IFACE_ID(PCI_DEV_IFACE),
     98            IPC_M_CONFIG_SPACE_WRITE_8, address, val);
     99        async_exchange_end(exch);
     100       
     101        return rc;
     102}
     103
     104int pci_config_space_write_16(async_sess_t *sess, uint32_t address,
     105    uint16_t val)
     106{
     107        async_exch_t *exch = async_exchange_begin(sess);
     108        int rc = async_req_3_0(exch, DEV_IFACE_ID(PCI_DEV_IFACE),
     109            IPC_M_CONFIG_SPACE_WRITE_16, address, val);
     110        async_exchange_end(exch);
     111       
     112        return rc;
     113}
     114
     115int pci_config_space_write_32(async_sess_t *sess, uint32_t address,
     116    uint32_t val)
     117{
     118        async_exch_t *exch = async_exchange_begin(sess);
     119        int rc = async_req_3_0(exch, DEV_IFACE_ID(PCI_DEV_IFACE),
     120            IPC_M_CONFIG_SPACE_WRITE_32, address, val);
     121        async_exchange_end(exch);
     122       
     123        return rc;
     124}
    41125
    42126static void remote_config_space_read_8(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     
    49133
    50134/** Remote USB interface operations. */
    51 static remote_iface_func_ptr_t remote_pci_iface_ops [] = {
    52         remote_config_space_read_8,
    53         remote_config_space_read_16,
    54         remote_config_space_read_32,
    55 
    56         remote_config_space_write_8,
    57         remote_config_space_write_16,
    58         remote_config_space_write_32
     135static const remote_iface_func_ptr_t remote_pci_iface_ops [] = {
     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,
     139
     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
    59143};
    60144
    61145/** Remote USB interface structure.
    62146 */
    63 remote_iface_t remote_pci_iface = {
    64         .method_count = sizeof(remote_pci_iface_ops) /
    65             sizeof(remote_pci_iface_ops[0]),
     147const remote_iface_t remote_pci_iface = {
     148        .method_count = ARRAY_SIZE(remote_pci_iface_ops),
    66149        .methods = remote_pci_iface_ops
    67150};
Note: See TracChangeset for help on using the changeset viewer.