The patch adds below functions. - qtest_read_pci_cfg - qtest_get_bar_addr - qtest_get_bar_size These are used for handling pci device information. It will be called by later patches.
Signed-off-by: Tetsuya Mukawa <mukawa at igel.co.jp> --- drivers/net/virtio/virtio_qtest/qtest_utils.c | 77 +++++++++++++++++++++++++++ drivers/net/virtio/virtio_qtest/qtest_utils.h | 56 +++++++++++++++++++ 2 files changed, 133 insertions(+) diff --git a/drivers/net/virtio/virtio_qtest/qtest_utils.c b/drivers/net/virtio/virtio_qtest/qtest_utils.c index 9bc1fca..27118fb 100644 --- a/drivers/net/virtio/virtio_qtest/qtest_utils.c +++ b/drivers/net/virtio/virtio_qtest/qtest_utils.c @@ -389,6 +389,83 @@ qtest_find_device(struct qtest_session *s, const char *name) return NULL; } +/* + * The function is used for reading pci configuration space of specifed device. + */ +int +qtest_read_pci_cfg(struct qtest_session *s, const char *name, + void *buf, size_t len, off_t offset) +{ + struct qtest_pci_device *dev; + uint32_t i; + uint8_t *p = buf; + + dev = qtest_find_device(s, name); + if (dev == NULL) { + PMD_DRV_LOG(ERR, "Cannot find specified device: %s", name); + return -1; + } + + for (i = 0; i < len; i++) { + *(p + i) = qtest_pci_inb(s, + dev->bus_addr, dev->device_addr, 0, offset + i); + } + + return 0; +} + +static struct qtest_pci_bar * +qtest_get_bar(struct qtest_session *s, const char *name, uint8_t bar) +{ + struct qtest_pci_device *dev; + + if (bar >= NB_BAR) { + PMD_DRV_LOG(ERR, "Invalid bar is specified: %u", bar); + return NULL; + } + + dev = qtest_find_device(s, name); + if (dev == NULL) { + PMD_DRV_LOG(ERR, "Cannot find specified device: %s", name); + return NULL; + } + + if (dev->bar[bar].type == QTEST_PCI_BAR_DISABLE) { + PMD_DRV_LOG(ERR, "Cannot find valid BAR(%s): %u", name, bar); + return NULL; + } + + return &dev->bar[bar]; +} + +int +qtest_get_bar_addr(struct qtest_session *s, const char *name, + uint8_t bar, uint64_t **addr) +{ + struct qtest_pci_bar *bar_ptr; + + bar_ptr = qtest_get_bar(s, name, bar); + if (bar_ptr == NULL) + return -1; + + *addr = (uint64_t *)bar_ptr->region_start; + return 0; +} + +int +qtest_get_bar_size(struct qtest_session *s, const char *name, + uint8_t bar, uint64_t *size) +{ + struct qtest_pci_bar *bar_ptr; + + bar_ptr = qtest_get_bar(s, name, bar); + if (bar_ptr == NULL) + return -1; + + *size = bar_ptr->region_size; + return 0; +} + static void qtest_event_send(struct qtest_session *s, char *buf) { diff --git a/drivers/net/virtio/virtio_qtest/qtest_utils.h b/drivers/net/virtio/virtio_qtest/qtest_utils.h index 6c70552..e41374f 100644 --- a/drivers/net/virtio/virtio_qtest/qtest_utils.h +++ b/drivers/net/virtio/virtio_qtest/qtest_utils.h @@ -218,6 +218,62 @@ void qtest_write(struct qtest_session *s, uint64_t addr, /** * @internal + * Read pci configuration space of QEMU guest. + * + * @param s + * The pointer to qtest session structure. + * @param name + * The name of pci device. + * @param buf + * The pointer to the buffer. + * @param len + * Length to read. + * @param offset + * Offset of pci configuration space. + * @return + * 0 on success, negative on error + */ +int qtest_read_pci_cfg(struct qtest_session *s, const char *name, + void *buf, size_t len, off_t offset); + +/** + * @internal + * Get BAR address of a specified pci device. + * + * @param s + * The pointer to qtest session structure. + * @param name + * The name of pci device. + * @param bar + * The index of BAR. Should be between 0 to 5. + * @param addr + * The pointer to store BAR address. + * @return + * 0 on success, negative on error + */ +int qtest_get_bar_addr(struct qtest_session *s, const char *name, + uint8_t bar, uint64_t **addr); + +/** + * @internal + * Get BAR size of a specified pci device. + * + * @param s + * The pointer to qtest session structure. + * @param name + * The name of pci device. + * @param bar + * The index of BAR. Should be between 0 to 5. + * @param size + * The pointer to store BAR size. + * @return + * 0 on success, negative on error + */ +int qtest_get_bar_size(struct qtest_session *s, const char *name, + uint8_t bar, uint64_t *size); + +/** + * @internal * Initialization function of general device. * * @param s -- 2.7.4