[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 |
|
---|
| 32 | #ifndef __VIRTIO_PCI_H__
|
---|
| 33 | #define __VIRTIO_PCI_H__
|
---|
| 34 |
|
---|
| 35 | #include <ddf/driver.h>
|
---|
[6ccc424] | 36 | #include <pci_dev_iface.h>
|
---|
[00192cde] | 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)
|
---|
[6ccc424] | 43 | #define VIRTIO_PCI_CAP_END(c) ((c) + 16)
|
---|
[00192cde] | 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. */
|
---|
| 52 | typedef 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 |
|
---|
| 71 | typedef struct {
|
---|
[6ccc424] | 72 | struct {
|
---|
| 73 | bool mapped;
|
---|
| 74 | void *mapped_base;
|
---|
| 75 | } bar[PCI_BAR_COUNT];
|
---|
| 76 |
|
---|
| 77 | /** Commong configuration structure */
|
---|
[00192cde] | 78 | virtio_pci_common_cfg_t *common_cfg;
|
---|
[6ccc424] | 79 |
|
---|
| 80 | /** Notification base address */
|
---|
[a86174ec] | 81 | ioport16_t *notify_base;
|
---|
[6ccc424] | 82 | /** Notification offset multiplier */
|
---|
| 83 | uint32_t notify_off_multiplier;
|
---|
| 84 |
|
---|
| 85 | /** INT#x interrupt ISR register */
|
---|
| 86 | ioport8_t *isr;
|
---|
| 87 |
|
---|
| 88 | /** Device-specific configuration */
|
---|
| 89 | void *device_cfg;
|
---|
[00192cde] | 90 | } virtio_dev_t;
|
---|
| 91 |
|
---|
| 92 | errno_t virtio_pci_dev_init(ddf_dev_t *, virtio_dev_t *);
|
---|
| 93 |
|
---|
| 94 | #endif
|
---|
| 95 |
|
---|
| 96 | /** @}
|
---|
| 97 | */
|
---|