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

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

Factor our resource management, add cleanup

  • Property mode set to 100644
File size: 3.1 KB
Line 
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
32#ifndef __VIRTIO_PCI_H__
33#define __VIRTIO_PCI_H__
34
35#include <ddf/driver.h>
36#include <pci_dev_iface.h>
37#include <ddi.h>
38
39#define VIRTIO_PCI_CAP_TYPE(c) ((c) + 3)
40#define VIRTIO_PCI_CAP_BAR(c) ((c) + 4)
41#define VIRTIO_PCI_CAP_OFFSET(c) ((c) + 8)
42#define VIRTIO_PCI_CAP_LENGTH(c) ((c) + 12)
43#define VIRTIO_PCI_CAP_END(c) ((c) + 16)
44
45#define VIRTIO_PCI_CAP_COMMON_CFG 1
46#define VIRTIO_PCI_CAP_NOTIFY_CFG 2
47#define VIRTIO_PCI_CAP_ISR_CFG 3
48#define VIRTIO_PCI_CAP_DEVICE_CFG 4
49#define VIRTIO_PCI_CAP_PCI_CFG 5
50
51/** Common configuration structure layout according to VIRTIO v1. */
52typedef struct virtio_pci_common_cfg {
53 ioport32_t device_feature_select;
54 const ioport32_t device_feature;
55 ioport32_t driver_feature_select;
56 ioport32_t driver_feature;
57 ioport16_t msix_config;
58 const ioport16_t num_queues;
59 ioport8_t device_status;
60 const ioport8_t config_generation;
61 ioport16_t queue_select;
62 ioport16_t queue_size;
63 ioport16_t queue_msix_vector;
64 ioport16_t queue_enable;
65 const ioport16_t queue_notif_off;
66 ioport64_t queue_desc;
67 ioport64_t queue_avail;
68 ioport64_t queue_used;
69} virtio_pci_common_cfg_t;
70
71typedef struct {
72 struct {
73 bool mapped;
74 void *mapped_base;
75 size_t mapped_size;
76 } bar[PCI_BAR_COUNT];
77
78 /** Commong configuration structure */
79 virtio_pci_common_cfg_t *common_cfg;
80
81 /** Notification base address */
82 ioport16_t *notify_base;
83 /** Notification offset multiplier */
84 uint32_t notify_off_multiplier;
85
86 /** INT#x interrupt ISR register */
87 ioport8_t *isr;
88
89 /** Device-specific configuration */
90 void *device_cfg;
91} virtio_dev_t;
92
93errno_t virtio_pci_dev_init(ddf_dev_t *, virtio_dev_t *);
94
95#endif
96
97/** @}
98 */
Note: See TracBrowser for help on using the repository browser.