Ignore:
Timestamp:
2018-05-22T19:06:49Z (6 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
00192cde
Parents:
e07257e
git-author:
Jakub Jermar <jakub@…> (2018-04-09 16:40:20)
git-committer:
Jakub Jermar <jakub@…> (2018-05-22 19:06:49)
Message:

Start parsing the Virtio PCI Capabilities

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/nic/virtio-net/virtio-net.c

    re07257e r69927fa  
    2828
    2929#include <stdio.h>
     30#include <stdint.h>
    3031
    3132#include <ddf/driver.h>
    3233#include <ddf/log.h>
    3334#include <ops/nic.h>
     35#include <pci_dev_iface.h>
    3436
    3537#include <nic.h>
     
    3739#define NAME    "virtio-net"
    3840
     41#define VIRTIO_PCI_CAP_TYPE(c)          ((c) + 3)
     42#define VIRTIO_PCI_CAP_BAR(c)           ((c) + 4)
     43#define VIRTIO_PCI_CAP_OFFSET(c)        ((c) + 8)
     44#define VIRTIO_PCI_CAP_LENGTH(c)        ((c) + 12)
     45
     46#define VIRTIO_PCI_CAP_COMMON_CFG       1
     47#define VIRTIO_PCI_CAP_NOTIFY_CFG       2
     48#define VIRTIO_PCI_CAP_ISR_CFG          3
     49#define VIRTIO_PCI_CAP_DEVICE_CFG       4
     50#define VIRTIO_PCI_CAP_PCI_CFG          5
     51
    3952static errno_t virtio_net_dev_add(ddf_dev_t *dev)
    4053{
    4154        ddf_msg(LVL_NOTE, "%s %s (handle = %zu)", __func__,
    4255            ddf_dev_get_name(dev), ddf_dev_get_handle(dev));
     56
     57        async_sess_t *pci_sess = ddf_dev_parent_sess_get(dev);
     58        if (!pci_sess)
     59                return ENOENT;
     60
     61        /*
     62         * Find the VIRTIO PCI Capabilities
     63         */
     64        errno_t rc;
     65        uint8_t c;
     66        uint8_t id;
     67        for (rc = pci_config_space_cap_first(pci_sess, &c, &id);
     68            (rc == EOK) && c;
     69            rc = pci_config_space_cap_next(pci_sess, &c, &id)) {
     70                if (id == PCI_CAP_VENDORSPECID) {
     71                        uint8_t type;
     72
     73                        rc = pci_config_space_read_8(pci_sess,
     74                            VIRTIO_PCI_CAP_TYPE(c), &type);
     75                        if (rc != EOK)
     76                                return rc;
     77
     78                        switch (type) {
     79                        case VIRTIO_PCI_CAP_COMMON_CFG:
     80                                break;
     81                        case VIRTIO_PCI_CAP_NOTIFY_CFG:
     82                                break;
     83                        case VIRTIO_PCI_CAP_ISR_CFG:
     84                                break;
     85                        case VIRTIO_PCI_CAP_DEVICE_CFG:
     86                                break;
     87                        case VIRTIO_PCI_CAP_PCI_CFG:
     88                                break;
     89                        default:
     90                                break;
     91                        }
     92                }
     93        }
     94        if (rc != EOK)
     95                return rc;
    4396
    4497        return ENOTSUP;
Note: See TracChangeset for help on using the changeset viewer.