2 * Copyright (c) 2018 Jakub Jermar
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
29 /** @file VIRTIO support
32 #include "virtio-pci.h"
34 #include <ddf/driver.h>
35 #include <pci_dev_iface.h>
37 static void virtio_pci_common_cfg(virtio_dev_t
*vdev
, hw_resource_list_t
*res
,
38 uint8_t bar
, uint32_t offset
, uint32_t length
)
40 /* Proceed only if we don't have common config structure yet */
44 /* We must ignore the capability if bar is greater than 5 */
49 errno_t
virtio_pci_dev_init(ddf_dev_t
*dev
, virtio_dev_t
*vdev
)
51 async_sess_t
*pci_sess
= ddf_dev_parent_sess_get(dev
);
56 hw_resource_list_t hw_res
;
57 rc
= hw_res_get_resource_list(pci_sess
, &hw_res
);
62 * Find the VIRTIO PCI Capabilities
66 for (rc
= pci_config_space_cap_first(pci_sess
, &c
, &id
);
68 rc
= pci_config_space_cap_next(pci_sess
, &c
, &id
)) {
69 if (id
== PCI_CAP_VENDORSPECID
) {
71 rc
= pci_config_space_read_8(pci_sess
,
72 VIRTIO_PCI_CAP_TYPE(c
), &type
);
77 rc
= pci_config_space_read_8(pci_sess
,
78 VIRTIO_PCI_CAP_BAR(c
), &bar
);
83 rc
= pci_config_space_read_32(pci_sess
,
84 VIRTIO_PCI_CAP_OFFSET(c
), &offset
);
89 rc
= pci_config_space_read_32(pci_sess
,
90 VIRTIO_PCI_CAP_LENGTH(c
), &length
);
95 case VIRTIO_PCI_CAP_COMMON_CFG
:
96 virtio_pci_common_cfg(vdev
, &hw_res
, bar
,
99 case VIRTIO_PCI_CAP_NOTIFY_CFG
:
101 case VIRTIO_PCI_CAP_ISR_CFG
:
103 case VIRTIO_PCI_CAP_DEVICE_CFG
:
105 case VIRTIO_PCI_CAP_PCI_CFG
: