source: mainline/uspace/lib/virtio/virtio-pci.h@ 21ff054

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 21ff054 was 21ff054, checked in by Jakub Jermar <jakub@…>, 7 years ago

Make sure the PCI capability is big enough

  • Property mode set to 100644
File size: 3.4 KB
RevLine 
[00192cde]1/*
2 * Copyright (c) 2018 Jakub Jermar
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/** @file VIRTIO PCI definitions
30 */
31
[c72cd20]32#ifndef _VIRTIO_PCI_H_
33#define _VIRTIO_PCI_H_
[00192cde]34
35#include <ddf/driver.h>
[6ccc424]36#include <pci_dev_iface.h>
[00192cde]37#include <ddi.h>
38
[21ff054]39#define VIRTIO_PCI_CAP_CAP_LEN(c) ((c) + 2)
40#define VIRTIO_PCI_CAP_CFG_TYPE(c) ((c) + 3)
[00192cde]41#define VIRTIO_PCI_CAP_BAR(c) ((c) + 4)
42#define VIRTIO_PCI_CAP_OFFSET(c) ((c) + 8)
43#define VIRTIO_PCI_CAP_LENGTH(c) ((c) + 12)
[6ccc424]44#define VIRTIO_PCI_CAP_END(c) ((c) + 16)
[00192cde]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
[a38b705]52#define VIRTIO_DEV_STATUS_RESET 0
53#define VIRTIO_DEV_STATUS_ACKNOWLEDGE 1
54#define VIRTIO_DEV_STATUS_DRIVER 2
55#define VIRTIO_DEV_STATUS_DRIVER_OK 4
56#define VIRTIO_DEV_STATUS_FEATURES_OK 8
57#define VIRTIO_DEV_STATUS_DEVICE_NEEDS_RESET 64
58#define VIRTIO_DEV_STATUS_FAILED 128
59
[00192cde]60/** Common configuration structure layout according to VIRTIO v1. */
61typedef struct virtio_pci_common_cfg {
62 ioport32_t device_feature_select;
63 const ioport32_t device_feature;
64 ioport32_t driver_feature_select;
65 ioport32_t driver_feature;
66 ioport16_t msix_config;
67 const ioport16_t num_queues;
68 ioport8_t device_status;
69 const ioport8_t config_generation;
70 ioport16_t queue_select;
71 ioport16_t queue_size;
72 ioport16_t queue_msix_vector;
73 ioport16_t queue_enable;
74 const ioport16_t queue_notif_off;
75 ioport64_t queue_desc;
76 ioport64_t queue_avail;
77 ioport64_t queue_used;
78} virtio_pci_common_cfg_t;
79
80typedef struct {
[6ccc424]81 struct {
82 bool mapped;
83 void *mapped_base;
[d6c0016]84 size_t mapped_size;
[6ccc424]85 } bar[PCI_BAR_COUNT];
86
87 /** Commong configuration structure */
[00192cde]88 virtio_pci_common_cfg_t *common_cfg;
[6ccc424]89
90 /** Notification base address */
[a86174ec]91 ioport16_t *notify_base;
[6ccc424]92 /** Notification offset multiplier */
93 uint32_t notify_off_multiplier;
94
95 /** INT#x interrupt ISR register */
96 ioport8_t *isr;
97
98 /** Device-specific configuration */
99 void *device_cfg;
[00192cde]100} virtio_dev_t;
101
[d6f73b92]102extern errno_t virtio_pci_dev_initialize(ddf_dev_t *, virtio_dev_t *);
[1d0620b]103extern errno_t virtio_pci_dev_cleanup(virtio_dev_t *);
[00192cde]104
105#endif
106
107/** @}
108 */
Note: See TracBrowser for help on using the repository browser.